diff --git a/cs-device/cs-device-api/pom.xml b/cs-device/cs-device-api/pom.xml
index 8caabcb..c3b9ca2 100644
--- a/cs-device/cs-device-api/pom.xml
+++ b/cs-device/cs-device-api/pom.xml
@@ -53,6 +53,12 @@
1.0.0
compile
+
+
+ com.njcn
+ common-device-biz
+ 1.0.0
+
UTF-8
diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/CsCommTerminalFeignClient.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/CsCommTerminalFeignClient.java
new file mode 100644
index 0000000..7fd0e9a
--- /dev/null
+++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/CsCommTerminalFeignClient.java
@@ -0,0 +1,25 @@
+package com.njcn.csdevice.api;
+
+import com.njcn.common.pojo.constant.ServerInfo;
+import com.njcn.common.pojo.response.HttpResult;
+import com.njcn.csdevice.api.fallback.CsCommTerminalFeignClientFallbackFactory;
+import com.njcn.csdevice.api.fallback.CsDeviceUserClientFallbackFactory;
+import com.njcn.csdevice.pojo.po.CsDeviceUserPO;
+import com.njcn.device.biz.pojo.po.PqsDeviceUnit;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.List;
+
+/**
+ * @author xy
+ */
+@FeignClient(value = ServerInfo.CS_DEVICE_BOOT, path = "/commTerminal", fallbackFactory = CsCommTerminalFeignClientFallbackFactory.class,contextId = "deviceUser")
+public interface CsCommTerminalFeignClient {
+
+ @GetMapping("lineUnitDetail")
+ HttpResult lineUnitDetail(@RequestParam("lineId") String lineId);
+}
diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/DataSetFeignClient.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/DataSetFeignClient.java
index 8f2774c..661d0be 100644
--- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/DataSetFeignClient.java
+++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/DataSetFeignClient.java
@@ -7,6 +7,7 @@ import com.njcn.csdevice.pojo.po.CsDataSet;
import com.njcn.csdevice.pojo.vo.LineTargetVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@@ -27,4 +28,8 @@ public interface DataSetFeignClient {
@PostMapping("/getModuleDataSet")
HttpResult> getModuleDataSet(@RequestParam("modelId") String modelId);
+ @PostMapping("/getDataSetBySetIds")
+ HttpResult> getDataSetBySetIds(@RequestBody List lineIds);
+
+
}
diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/CsCommTerminalFeignClientFallbackFactory.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/CsCommTerminalFeignClientFallbackFactory.java
new file mode 100644
index 0000000..5cc865a
--- /dev/null
+++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/CsCommTerminalFeignClientFallbackFactory.java
@@ -0,0 +1,36 @@
+package com.njcn.csdevice.api.fallback;
+
+import com.njcn.common.pojo.enums.response.CommonResponseEnum;
+import com.njcn.common.pojo.exception.BusinessException;
+import com.njcn.common.pojo.response.HttpResult;
+import com.njcn.csdevice.api.CsCommTerminalFeignClient;
+import com.njcn.device.biz.pojo.po.PqsDeviceUnit;
+import feign.hystrix.FallbackFactory;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author xy
+ */
+@Slf4j
+@Component
+public class CsCommTerminalFeignClientFallbackFactory implements FallbackFactory {
+ @Override
+ public CsCommTerminalFeignClient create(Throwable cause) {
+ //判断抛出异常是否为解码器抛出的业务异常
+ Enum> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
+ if (cause.getCause() instanceof BusinessException) {
+ BusinessException businessException = (BusinessException) cause.getCause();
+ }
+ Enum> finalExceptionEnum = exceptionEnum;
+ return new CsCommTerminalFeignClient() {
+
+
+ @Override
+ public HttpResult lineUnitDetail(String lineId) {
+ log.error("{}异常,降级处理,异常为:{}","查询分组",cause.toString());
+ throw new BusinessException(finalExceptionEnum);
+ }
+ };
+ }
+}
diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/DataSetFeignClientFallbackFactory.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/DataSetFeignClientFallbackFactory.java
index 1d1b3bf..b315e16 100644
--- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/DataSetFeignClientFallbackFactory.java
+++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/api/fallback/DataSetFeignClientFallbackFactory.java
@@ -50,6 +50,12 @@ public class DataSetFeignClientFallbackFactory implements FallbackFactory> getDataSetBySetIds(List lineIds) {
+ log.error("{}异常,降级处理,异常为:{}","根据数据集ids获取数据集",cause.toString());
+ throw new BusinessException(finalExceptionEnum);
+ }
};
}
}
diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsLinePO.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsLinePO.java
index 07d97fd..46322d7 100644
--- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsLinePO.java
+++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/pojo/po/CsLinePO.java
@@ -44,6 +44,16 @@ public class CsLinePO extends BaseEntity {
@TableField(value = "`position`")
private String position;
+ /**
+ * 数据集id
+ */
+ private String dataSetId;
+
+ /**
+ * 模板id
+ */
+ private String dataModelId;
+
/**
* 电压等级
*/
diff --git a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/utils/DataChangeUtil.java b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/utils/DataChangeUtil.java
index 4e525f5..40d1673 100644
--- a/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/utils/DataChangeUtil.java
+++ b/cs-device/cs-device-api/src/main/java/com/njcn/csdevice/utils/DataChangeUtil.java
@@ -1,12 +1,15 @@
package com.njcn.csdevice.utils;
/**
- * 类的介绍:用来将二次值转成一次值
+ * 类的介绍:
* @author xuyang
* @version 1.0.0
*/
public class DataChangeUtil {
+ /**
+ * 用来将二次值转成一次值
+ */
public static double secondaryToPrimary(String formula, Double data,Double pt, Double ct) {
switch (formula) {
case "*PT":
@@ -23,4 +26,24 @@ public class DataChangeUtil {
}
return data;
}
+
+ /**
+ * 用来将一次值转成二次值
+ */
+ public static double primaryToSecondary(String formula, Double data,Double pt, Double ct) {
+ switch (formula) {
+ case "*PT":
+ data = data / pt;
+ break;
+ case "*CT":
+ data = data / ct;
+ break;
+ case "*PT*CT":
+ data = data / pt / ct;
+ break;
+ default:
+ break;
+ }
+ return data;
+ }
}
diff --git a/cs-device/cs-device-boot/pom.xml b/cs-device/cs-device-boot/pom.xml
index d6a711d..c15fd07 100644
--- a/cs-device/cs-device-boot/pom.xml
+++ b/cs-device/cs-device-boot/pom.xml
@@ -163,11 +163,7 @@
-
- com.njcn
- common-device-biz
- 1.0.0
-
+
diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/CsDataSetController.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/CsDataSetController.java
index 99dcb04..28c3ea8 100644
--- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/CsDataSetController.java
+++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/equipment/CsDataSetController.java
@@ -16,10 +16,7 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -76,5 +73,15 @@ public class CsDataSetController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
+ @OperateInfo(info = LogEnum.BUSINESS_COMMON)
+ @PostMapping("/getDataSetBySetIds")
+ @ApiOperation("根据测点获取数据集")
+ @ApiImplicitParam(name = "lineIds", value = "监测点ids", required = true)
+ public HttpResult> getDataSetBySetIds(@RequestBody List lineIds){
+ String methodDescribe = getMethodDescribe("getDataSetBySetIds");
+ List list = csDataSetService.getDataSetBySetIds(lineIds);
+ return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
+ }
+
}
diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/ledger/CommTerminalController.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/ledger/CsCommTerminalController.java
similarity index 96%
rename from cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/ledger/CommTerminalController.java
rename to cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/ledger/CsCommTerminalController.java
index 64a5318..41c4822 100644
--- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/ledger/CommTerminalController.java
+++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/controller/ledger/CsCommTerminalController.java
@@ -30,7 +30,7 @@ import java.util.Objects;
@RequiredArgsConstructor
@Slf4j
@Api(tags = "通用台账查询")
-public class CommTerminalController extends BaseController {
+public class CsCommTerminalController extends BaseController {
private final PqsDeviceUnitMapper pqsDeviceUnitMapper;
diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/ICsDataSetService.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/ICsDataSetService.java
index feac202..4ea65ce 100644
--- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/ICsDataSetService.java
+++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/ICsDataSetService.java
@@ -45,4 +45,11 @@ public interface ICsDataSetService extends IService {
* @return
*/
List getModuleDataSet(String modelId);
+
+ /**
+ * 根据测点id获取数据集
+ * @param setIds 监测点id
+ * @return
+ */
+ List getDataSetBySetIds(List setIds);
}
diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsDataSetServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsDataSetServiceImpl.java
index 2b222b3..3996262 100644
--- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsDataSetServiceImpl.java
+++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsDataSetServiceImpl.java
@@ -8,6 +8,7 @@ import com.njcn.csdevice.service.ICsDataSetService;
import org.springframework.stereotype.Service;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
/**
@@ -41,4 +42,9 @@ public class CsDataSetServiceImpl extends ServiceImpl getDataSetBySetIds(List setIds) {
+ return this.lambdaQuery().in(CsDataSet::getId,setIds).list();
+ }
+
}
diff --git a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsGroupServiceImpl.java b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsGroupServiceImpl.java
index c1aab85..3ce0db3 100644
--- a/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsGroupServiceImpl.java
+++ b/cs-device/cs-device-boot/src/main/java/com/njcn/csdevice/service/impl/CsGroupServiceImpl.java
@@ -5,10 +5,12 @@ import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.csdevice.api.CsLineFeignClient;
@@ -16,20 +18,15 @@ import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.constant.DataParam;
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
import com.njcn.csdevice.enums.LineBaseEnum;
-import com.njcn.csdevice.mapper.CsDataArrayMapper;
-import com.njcn.csdevice.mapper.CsGroArrMapper;
-import com.njcn.csdevice.mapper.CsGroupMapper;
-import com.njcn.csdevice.mapper.OverlimitMapper;
+import com.njcn.csdevice.mapper.*;
import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO;
import com.njcn.csdevice.pojo.param.EnergyBaseParam;
-import com.njcn.csdevice.pojo.po.CsDataArray;
-import com.njcn.csdevice.pojo.po.CsGroArr;
-import com.njcn.csdevice.pojo.po.CsGroup;
-import com.njcn.csdevice.pojo.po.CsLinePO;
+import com.njcn.csdevice.pojo.po.*;
import com.njcn.csdevice.pojo.vo.CsGroupVO;
import com.njcn.csdevice.pojo.vo.DataGroupEventVO;
import com.njcn.csdevice.pojo.vo.DataGroupTemplateVO;
import com.njcn.csdevice.pojo.vo.EnergyTemplateVO;
+import com.njcn.csdevice.service.CsDevModelRelationService;
import com.njcn.csdevice.service.ICsDataArrayService;
import com.njcn.csdevice.service.ICsGroupService;
import com.njcn.csdevice.util.InfluxDbParamUtil;
@@ -110,6 +107,8 @@ public class CsGroupServiceImpl extends ServiceImpl impl
private final OverlimitMapper overlimitMapper;
+ private final CsDataSetMapper csDataSetMapper;
+
private final EventFeignClient eventFeignClient;
private final InfluxDbParamUtil influxDbParamUtil;
@@ -155,6 +154,10 @@ public class CsGroupServiceImpl extends ServiceImpl impl
getUnit(list,epdPqdList,groupList,dataLevel);
//根据lineId获取监测点pt、ct变比
CsLinePO csLinePO = csLineFeignClient.queryLineById(Collections.singletonList(lineId)).getData().get(0);
+ CsDataSet csDataSet = csDataSetMapper.selectOne(new LambdaQueryWrapper().eq(CsDataSet::getId,csLinePO.getDataSetId()));
+ if(Objects.isNull(csDataSet) || StrUtil.isBlank(csDataSet.getDataLevel())){
+ throw new BusinessException("当前测点数据集主要信息缺失,请联系管理员排查(测点表里面数据集id缺失)");
+ }
//获取测点模板
for (EnergyTemplateVO item : list) {
EnergyTemplateVO vo = new EnergyTemplateVO();
@@ -166,12 +169,17 @@ public class CsGroupServiceImpl extends ServiceImpl impl
if (Objects.nonNull(statisticalDataDTO)) {
vo.setTime(statisticalDataDTO.getTime());
//判断监测点类型 针对治理设备 模块数据是一次值、电能质量设备是二次值
- if (csLinePO.getClDid() != 0 && Objects.equals("Primary",dataLevel) && ObjectUtil.isNotNull(eleEpdPqd.getPrimaryFormula())) {
- double secondaryData = DataChangeUtil.secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getValue(), csLinePO.getPtRatio(), csLinePO.getCtRatio());
+ if (ObjectUtil.isNotNull(eleEpdPqd.getPrimaryFormula()) && !Objects.equals(csDataSet.getDataLevel(),dataLevel)) {
+ double re;
+ if("Primary".equals(csDataSet.getDataLevel())){
+ re = DataChangeUtil.primaryToSecondary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getValue(), csLinePO.getPtRatio(), csLinePO.getCtRatio());
+ }else {
+ re = DataChangeUtil.secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getValue(), csLinePO.getPtRatio(), csLinePO.getCtRatio());
+ }
if (changePower(vo.getAnotherName())) {
- vo.setDataValue(Double.valueOf(df.format(BigDecimal.valueOf(secondaryData / 1000).setScale(2, RoundingMode.HALF_UP).doubleValue())));
+ vo.setDataValue(Double.valueOf(df.format(BigDecimal.valueOf(re / 1000).setScale(2, RoundingMode.HALF_UP).doubleValue())));
} else {
- vo.setDataValue(Double.valueOf(df.format(BigDecimal.valueOf(secondaryData).setScale(2, RoundingMode.HALF_UP).doubleValue())));
+ vo.setDataValue(Double.valueOf(df.format(BigDecimal.valueOf(re).setScale(2, RoundingMode.HALF_UP).doubleValue())));
}
} else {
if (changePower(vo.getAnotherName())) {
@@ -222,6 +230,11 @@ public class CsGroupServiceImpl extends ServiceImpl impl
getUnit(list,epdPqdList,groupList,energyBaseParam.getDataLevel());
//根据lineId获取监测点pt、ct变比
CsLinePO po = csLineFeignClient.queryLineById(Collections.singletonList(energyBaseParam.getLineId())).getData().get(0);
+ CsDataSet csDataSet = csDataSetMapper.selectOne(new LambdaQueryWrapper().eq(CsDataSet::getId,po.getDataSetId()));
+ if(Objects.isNull(csDataSet) || StrUtil.isBlank(csDataSet.getDataLevel())){
+ throw new BusinessException("当前测点数据集主要信息缺失,请联系管理员排查(测点表里面数据集id缺失)");
+ }
+
for (EnergyTemplateVO item : list) {
EnergyTemplateVO vo = new EnergyTemplateVO();
BeanUtils.copyProperties(item,vo);
@@ -235,10 +248,20 @@ public class CsGroupServiceImpl extends ServiceImpl impl
if (Objects.nonNull(statisticalDataDTO)) {
vo.setTime(statisticalDataDTO.getTime());
//判断监测点类型 针对治理设备 模块数据是一次值、电能质量设备是二次值
- if (po.getClDid() != 0 && Objects.equals("Primary",energyBaseParam.getDataLevel()) && ObjectUtil.isNotNull(eleEpdPqd.getPrimaryFormula())) {
- double secondaryData1 = DataChangeUtil.secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getMaxValue(), po.getPtRatio(), po.getCtRatio());
- double secondaryData2 = DataChangeUtil.secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getMinValue(), po.getPtRatio(), po.getCtRatio());
- double secondaryData3 = DataChangeUtil.secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getAvgValue(), po.getPtRatio(), po.getCtRatio());
+ if (ObjectUtil.isNotNull(eleEpdPqd.getPrimaryFormula()) && !Objects.equals(csDataSet.getDataLevel(),energyBaseParam.getDataLevel()) ) {
+ double secondaryData1;
+ double secondaryData2;
+ double secondaryData3;
+ if("Primary".equals(csDataSet.getDataLevel())){
+ secondaryData1 = DataChangeUtil.primaryToSecondary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getMaxValue(), po.getPtRatio(), po.getCtRatio());
+ secondaryData2 = DataChangeUtil.primaryToSecondary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getMinValue(), po.getPtRatio(), po.getCtRatio());
+ secondaryData3 = DataChangeUtil.primaryToSecondary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getAvgValue(), po.getPtRatio(), po.getCtRatio());
+ }else {
+ secondaryData1 = DataChangeUtil.secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getMaxValue(), po.getPtRatio(), po.getCtRatio());
+ secondaryData2 = DataChangeUtil.secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getMinValue(), po.getPtRatio(), po.getCtRatio());
+ secondaryData3 = DataChangeUtil.secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getAvgValue(), po.getPtRatio(), po.getCtRatio());
+ }
+
if (changePower(vo.getAnotherName())) {
vo.setMaxValue(Double.valueOf(df.format(BigDecimal.valueOf(secondaryData1/1000).setScale(2, RoundingMode.HALF_UP).doubleValue())));
vo.setMinValue(Double.valueOf(df.format(BigDecimal.valueOf(secondaryData2/1000).setScale(2, RoundingMode.HALF_UP).doubleValue())));
diff --git a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/DeviceDataTrendServiceImpl.java b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/DeviceDataTrendServiceImpl.java
index 5c90d27..ab932f9 100644
--- a/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/DeviceDataTrendServiceImpl.java
+++ b/cs-harmonic/cs-harmonic-boot/src/main/java/com/njcn/csharmonic/service/impl/DeviceDataTrendServiceImpl.java
@@ -1,11 +1,17 @@
package com.njcn.csharmonic.service.impl;
+import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.CsLedgerFeignClient;
import com.njcn.csdevice.api.CsLineFeignClient;
+import com.njcn.csdevice.api.DataSetFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO;
import com.njcn.csdevice.pojo.dto.LineParamDTO;
+import com.njcn.csdevice.pojo.po.CsDataSet;
import com.njcn.csdevice.pojo.po.CsLedger;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.utils.DataChangeUtil;
@@ -49,6 +55,8 @@ public class DeviceDataTrendServiceImpl implements DeviceDataTrendService {
private final EquipmentFeignClient equipmentFeignClient;
private final InfluxDbParamUtil influxDbParamUtil;
private final EpdFeignClient epdFeignClient;
+ private final DataSetFeignClient dataSetFeignClient;
+
@Override
public List> queryDataTrend(DevicDataTrendQueryParam devicDataTrendQueryParam) {
List> result = new ArrayList<>();
@@ -62,7 +70,10 @@ public class DeviceDataTrendServiceImpl implements DeviceDataTrendService {
List data1 = equipmentFeignClient.queryDeviceById(Stream.of((data == null || data.isEmpty()) ? devicDataTrendQueryParam.getDevId() : data.get(0).getPid()).collect(Collectors.toList())).getData();
//根据lineId获取监测点pt、ct变比
CsLinePO linePo = csLineFeignClient.queryLineById(Collections.singletonList(devicDataTrendQueryParam.getLineId())).getData().get(0);
-
+ List csDataSetList = dataSetFeignClient.getDataSetBySetIds(Stream.of(linePo.getDataSetId()).collect(Collectors.toList())).getData();
+ if(CollUtil.isEmpty(csDataSetList) || StrUtil.isBlank(csDataSetList.get(0).getDataLevel())){
+ throw new BusinessException("当前测点数据集主要信息缺失,请联系管理员排查(测点表里面数据集id缺失)");
+ }
devicDataTrendQueryParam.getStatisticalParams().forEach(temp->{
CommonQueryParam commonQueryParam = new CommonQueryParam();
commonQueryParam.setLineId(devicDataTrendQueryParam.getLineId());
@@ -83,19 +94,21 @@ public class DeviceDataTrendServiceImpl implements DeviceDataTrendService {
vo.setTime(statisticalDataDTO.getTime());
vo.setStatMethod(statisticalDataDTO.getValueType());
//判断监测点类型 针对治理设备 模块数据是一次值、电能质量设备是二次值
- if (linePo.getClDid() != 0 && Objects.equals(devicDataTrendQueryParam.getDataLevel(),"Primary") && ObjectUtil.isNotNull(epdPqd.getPrimaryFormula())) {
- double secondaryData = DataChangeUtil.secondaryToPrimary(epdPqd.getPrimaryFormula(), statisticalDataDTO.getValue(), linePo.getPtRatio(), linePo.getCtRatio());
- if (changePower(epdPqd.getShowName())) {
- secondaryData = secondaryData/1000;
+ double value;
+ if (ObjectUtil.isNotNull(epdPqd.getPrimaryFormula()) && !Objects.equals(devicDataTrendQueryParam.getDataLevel(),csDataSetList.get(0).getDataLevel())) {
+ if("Primary".equals(csDataSetList.get(0).getDataLevel())){
+ value = DataChangeUtil.primaryToSecondary(epdPqd.getPrimaryFormula(), statisticalDataDTO.getValue(), linePo.getPtRatio(), linePo.getCtRatio());
+ }else {
+ value = DataChangeUtil.secondaryToPrimary(epdPqd.getPrimaryFormula(), statisticalDataDTO.getValue(), linePo.getPtRatio(), linePo.getCtRatio());
}
- vo.setStatisticalData(BigDecimal.valueOf(secondaryData).setScale(4, RoundingMode.HALF_UP).doubleValue());
} else {
- Double temVal = statisticalDataDTO.getValue();
- if (changePower(epdPqd.getShowName())) {
- temVal = temVal/1000;
- }
- vo.setStatisticalData(BigDecimal.valueOf(temVal).setScale(4, RoundingMode.HALF_UP).doubleValue());
+ value= statisticalDataDTO.getValue();
}
+ if (changePower(epdPqd.getShowName())) {
+ value = value/1000;
+ }
+ vo.setStatisticalData(BigDecimal.valueOf(value).setScale(4, RoundingMode.HALF_UP).doubleValue());
+
vo.setStatisticalIndex(temp.getDataId());
vo.setStatisticalName(temp.getName());