数据添加单位显示
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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":
|
||||
data = data * pt;
|
||||
break;
|
||||
case "*CT":
|
||||
data = data * ct;
|
||||
break;
|
||||
case "*PT*CT":
|
||||
data = data * pt * ct;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import com.njcn.csdevice.pojo.vo.EnergyTemplateVO;
|
||||
import com.njcn.csdevice.service.ICsDataArrayService;
|
||||
import com.njcn.csdevice.service.ICsGroupService;
|
||||
import com.njcn.csdevice.util.InfluxDbParamUtil;
|
||||
import com.njcn.csdevice.utils.DataChangeUtil;
|
||||
import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
|
||||
import com.njcn.csharmonic.pojo.vo.ThdDataTdVO;
|
||||
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
|
||||
@@ -113,6 +114,7 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
|
||||
|
||||
private final InfluxDbParamUtil influxDbParamUtil;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<CsGroupVO> getGroupData(String dataSet) {
|
||||
@@ -128,6 +130,7 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IPage<DataGroupTemplateVO> getDeviceRtData(String id, Integer pageNum, Integer pageSize, String lineId, String searchValue, String dataLevel) {
|
||||
IPage<DataGroupTemplateVO> pageTurn = new Page<>();
|
||||
@@ -141,6 +144,7 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
|
||||
//获取所有字典指标
|
||||
List<EleEpdPqd> epdPqdList = epdFeignClient.selectByIds(list.stream().map(EnergyTemplateVO::getDataId).distinct().collect(Collectors.toList())).getData();
|
||||
Map<String, EleEpdPqd> eventTypeMap = epdPqdList.stream().collect(Collectors.toMap(EleEpdPqd::getId, Function.identity()));
|
||||
getUnit(list,epdPqdList,groupList);
|
||||
//根据lineId获取监测点pt、ct变比
|
||||
CsLinePO csLinePO = csLineFeignClient.queryLineById(Collections.singletonList(lineId)).getData().get(0);
|
||||
for (EnergyTemplateVO item : list) {
|
||||
@@ -154,7 +158,7 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
|
||||
vo.setTime(statisticalDataDTO.getTime());
|
||||
//判断监测点类型 针对治理设备 模块数据是一次值、电能质量设备是二次值
|
||||
if (csLinePO.getClDid() != 0 && Objects.equals("Primary",dataLevel) && ObjectUtil.isNotNull(eleEpdPqd.getPrimaryFormula())) {
|
||||
double secondaryData = secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getValue(), csLinePO.getPtRatio(), csLinePO.getCtRatio());
|
||||
double secondaryData = DataChangeUtil.secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getValue(), csLinePO.getPtRatio(), csLinePO.getCtRatio());
|
||||
vo.setDataValue(BigDecimal.valueOf(secondaryData).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
} else {
|
||||
vo.setDataValue(BigDecimal.valueOf(statisticalDataDTO.getValue()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
@@ -195,12 +199,16 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
|
||||
//获取所有字典指标
|
||||
List<EleEpdPqd> epdPqdList = epdFeignClient.selectByIds(list.stream().map(EnergyTemplateVO::getDataId).distinct().collect(Collectors.toList())).getData();
|
||||
Map<String, EleEpdPqd> eventTypeMap = epdPqdList.stream().collect(Collectors.toMap(EleEpdPqd::getId, Function.identity()));
|
||||
getUnit(list,epdPqdList,groupList);
|
||||
//根据lineId获取监测点pt、ct变比
|
||||
CsLinePO po = csLineFeignClient.queryLineById(Collections.singletonList(energyBaseParam.getLineId())).getData().get(0);
|
||||
for (EnergyTemplateVO item : list) {
|
||||
EnergyTemplateVO vo = new EnergyTemplateVO();
|
||||
BeanUtils.copyProperties(item,vo);
|
||||
EleEpdPqd eleEpdPqd = eventTypeMap.get(item.getDataId());
|
||||
if (Objects.nonNull(eleEpdPqd.getUnit())){
|
||||
vo.setAnotherName(vo.getAnotherName()+"("+eleEpdPqd.getUnit()+")");
|
||||
}
|
||||
vo.setClassId(eleEpdPqd.getClassId());
|
||||
vo.setUnit(eleEpdPqd.getUnit());
|
||||
StatisticalDataDTO statisticalDataDTO = commonService.getLineHistoryData(energyBaseParam.getLineId(),influxDbParamUtil.getTableNameByClassId(eleEpdPqd.getClassId()),item.getName(),energyBaseParam.getStartTime() + " 00:00:00",energyBaseParam.getEndTime() + " 23:59:59",influxDbParamUtil.getClDidByLineId(energyBaseParam.getLineId()));
|
||||
@@ -208,9 +216,9 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
|
||||
vo.setTime(statisticalDataDTO.getTime());
|
||||
//判断监测点类型 针对治理设备 模块数据是一次值、电能质量设备是二次值
|
||||
if (po.getClDid() != 0 && Objects.equals("Primary",energyBaseParam.getDataLevel()) && ObjectUtil.isNotNull(eleEpdPqd.getPrimaryFormula())) {
|
||||
double secondaryData1 = secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getMaxValue(), po.getPtRatio(), po.getCtRatio());
|
||||
double secondaryData2 = secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getMinValue(), po.getPtRatio(), po.getCtRatio());
|
||||
double secondaryData3 = secondaryToPrimary(eleEpdPqd.getPrimaryFormula(), statisticalDataDTO.getAvgValue(), po.getPtRatio(), po.getCtRatio());
|
||||
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());
|
||||
vo.setMaxValue(BigDecimal.valueOf(secondaryData1).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
vo.setMinValue(BigDecimal.valueOf(secondaryData2).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
vo.setAvgValue(BigDecimal.valueOf(secondaryData3).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
@@ -683,27 +691,35 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 二次值换算成一次值
|
||||
*/
|
||||
public double secondaryToPrimary(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/1000":
|
||||
data = data * pt * ct / 1000;
|
||||
break;
|
||||
case "*PT/1000":
|
||||
data = data * pt / 1000;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
//单位处理
|
||||
public void getUnit(List<EnergyTemplateVO> energyTemplates, List<EleEpdPqd> eleEpdPqds, List<DataGroupTemplateVO> dataGroupTemplates) {
|
||||
// 使用Map来存储EleEpdPqd的ID和Unit,以便快速查找
|
||||
Map<String, String> unitMap = new HashMap<>();
|
||||
for (EleEpdPqd item : eleEpdPqds) {
|
||||
unitMap.put(item.getId(), item.getUnit());
|
||||
}
|
||||
|
||||
// 遍历EnergyTemplateVO,设置Unit
|
||||
for (EnergyTemplateVO energyTemplate : energyTemplates) {
|
||||
String unit = unitMap.get(energyTemplate.getDataId());
|
||||
if (unit != null) {
|
||||
energyTemplate.setUnit(unit);
|
||||
}
|
||||
}
|
||||
|
||||
// 使用Map来存储DataGroupTemplateVO的ID和对应的EnergyTemplateVO(如果存在)
|
||||
Map<String, EnergyTemplateVO> energyTemplateMap = new HashMap<>();
|
||||
for (EnergyTemplateVO energyTemplate : energyTemplates) {
|
||||
energyTemplateMap.put(energyTemplate.getPid(), energyTemplate);
|
||||
}
|
||||
|
||||
// 遍历DataGroupTemplateVO,更新Name
|
||||
for (DataGroupTemplateVO dataGroupTemplate : dataGroupTemplates) {
|
||||
EnergyTemplateVO energyTemplate = energyTemplateMap.get(dataGroupTemplate.getId());
|
||||
if (energyTemplate != null && energyTemplate.getUnit() != null) {
|
||||
dataGroupTemplate.setName(dataGroupTemplate.getName() + "(" + energyTemplate.getUnit() + ")");
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user