feat(device): 新增指标拟合图数据查询功能
This commit is contained in:
@@ -12,6 +12,7 @@ import com.njcn.csdevice.pojo.vo.CsGroupVO;
|
||||
import com.njcn.csdevice.pojo.vo.DataGroupTemplateVO;
|
||||
import com.njcn.csdevice.service.ICsGroupService;
|
||||
import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
|
||||
import com.njcn.csharmonic.param.FittingDataQueryParam;
|
||||
import com.njcn.csharmonic.param.TrendDataQueryParam;
|
||||
import com.njcn.csharmonic.pojo.vo.ThdDataTdVO;
|
||||
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
|
||||
@@ -148,7 +149,7 @@ public class CsGroupController extends BaseController {
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/trendData")
|
||||
@ApiOperation("查询趋势数据")
|
||||
@ApiOperation("查询指标趋势图数据")
|
||||
@ApiImplicitParam(name = "param",required = true)
|
||||
public HttpResult<List<ThdDataVO>> trendData(@RequestBody @Validated TrendDataQueryParam param){
|
||||
String methodDescribe = getMethodDescribe("trendData");
|
||||
@@ -156,5 +157,16 @@ public class CsGroupController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/fittingData")
|
||||
@ApiOperation("查询指标拟合图数据")
|
||||
@ApiImplicitParam(name = "param",required = true)
|
||||
public HttpResult<List<ThdDataVO>> fittingData(@RequestBody @Validated FittingDataQueryParam param){
|
||||
String methodDescribe = getMethodDescribe("fittingData");
|
||||
List<ThdDataVO> list = csGroupService.fittingData(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.njcn.csdevice.pojo.po.CsGroup;
|
||||
import com.njcn.csdevice.pojo.vo.CsGroupVO;
|
||||
import com.njcn.csdevice.pojo.vo.DataGroupTemplateVO;
|
||||
import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
|
||||
import com.njcn.csharmonic.param.FittingDataQueryParam;
|
||||
import com.njcn.csharmonic.param.TrendDataQueryParam;
|
||||
import com.njcn.csharmonic.pojo.vo.ThdDataTdVO;
|
||||
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
|
||||
@@ -84,5 +85,10 @@ public interface ICsGroupService extends IService<CsGroup> {
|
||||
* @return
|
||||
*/
|
||||
List<ThdDataVO> trendData(TrendDataQueryParam trendDataQueryParam);
|
||||
/**
|
||||
* 查询指标拟合图数据
|
||||
* @return
|
||||
*/
|
||||
List<ThdDataVO> fittingData(FittingDataQueryParam fittingDataQueryParam);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.njcn.csdevice.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
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 cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@@ -33,6 +36,7 @@ import com.njcn.csharmonic.api.EventFeignClient;
|
||||
import com.njcn.csharmonic.constant.HarmonicConstant;
|
||||
import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
|
||||
import com.njcn.csharmonic.param.CsEventUserQueryPage;
|
||||
import com.njcn.csharmonic.param.FittingDataQueryParam;
|
||||
import com.njcn.csharmonic.param.TrendDataQueryParam;
|
||||
import com.njcn.csharmonic.pojo.vo.ThdDataTdVO;
|
||||
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
|
||||
@@ -43,7 +47,7 @@ import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
import com.njcn.influx.service.CommonService;
|
||||
import com.njcn.influx.service.EvtDataService;
|
||||
import com.njcn.system.api.CsStatisticalSetFeignClient;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.api.EleEvtFeignClient;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
@@ -60,6 +64,7 @@ import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
@@ -86,7 +91,6 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final ICsLedgerService iCsLedgerService;
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final CsStatisticalSetFeignClient csStatisticalSetFeignClient;
|
||||
private final EvtDataService evtDataService;
|
||||
@@ -96,6 +100,7 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
|
||||
private final CsDataSetMapper csDataSetMapper;
|
||||
private final EventFeignClient eventFeignClient;
|
||||
private final InfluxDbParamUtil influxDbParamUtil;
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -787,7 +792,7 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
|
||||
|
||||
@Override
|
||||
public List<ThdDataVO> trendData(TrendDataQueryParam trendDataQueryParam) {
|
||||
List<ThdDataVO> result = new ArrayList();
|
||||
List<ThdDataVO> result = new ArrayList<>();
|
||||
CsLinePO finalCsLinePO = csLineFeignClient.getById(trendDataQueryParam.getLineId()).getData();
|
||||
CsDataSet csDataSet = csDataSetMapper.selectOne(new LambdaQueryWrapper<CsDataSet>().eq(CsDataSet::getId,finalCsLinePO.getDataSetId()));
|
||||
if(Objects.isNull(csDataSet) || StrUtil.isBlank(csDataSet.getDataLevel())){
|
||||
@@ -932,6 +937,199 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThdDataVO> fittingData(FittingDataQueryParam fittingDataQueryParam) {
|
||||
List<ThdDataVO> result = new ArrayList<>();
|
||||
CsLinePO finalCsLinePO = csLineFeignClient.getById(fittingDataQueryParam.getLineId()).getData();
|
||||
CsDataSet csDataSet = csDataSetMapper.selectOne(new LambdaQueryWrapper<CsDataSet>().eq(CsDataSet::getId,finalCsLinePO.getDataSetId()));
|
||||
if(Objects.isNull(csDataSet) || StrUtil.isBlank(csDataSet.getDataLevel())){
|
||||
throw new BusinessException("当前测点数据集主要信息缺失,请联系管理员排查(测点表里面数据集id缺失)");
|
||||
}
|
||||
Double ct = finalCsLinePO.getCtRatio();
|
||||
Double pt = finalCsLinePO.getPtRatio();
|
||||
// String position = finalCsLinePO.getPosition();
|
||||
Overlimit overlimit = overlimitMapper.selectById(finalCsLinePO.getLineId());
|
||||
JSONObject entries = JSONUtil.parseObj(overlimit);
|
||||
if(CollectionUtil.isNotEmpty(fittingDataQueryParam.getList())) {
|
||||
for (FittingDataQueryParam param : fittingDataQueryParam.getList()) {
|
||||
String dictCode = dictTreeFeignClient.queryById(param.getStatisticalId()).getData().getCode();
|
||||
List<EleEpdPqd> eleEpdPqds = csStatisticalSetFeignClient.queryStatisticalSelect(param.getStatisticalId()).getData();
|
||||
List<ThdDataVO> dataList = new ArrayList<>();
|
||||
for (EleEpdPqd epdPqd : eleEpdPqds) {
|
||||
CommonQueryParam commonQueryParam = new CommonQueryParam();
|
||||
commonQueryParam.setLineId(finalCsLinePO.getLineId());
|
||||
commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(epdPqd.getClassId()));
|
||||
commonQueryParam.setColumnName(epdPqd.getName() + (StringUtils.isEmpty(param.getFrequency()) ? "" : "_" + param.getFrequency()));
|
||||
commonQueryParam.setPhasic(epdPqd.getPhase());
|
||||
|
||||
commonQueryParam.setStartTime(DateUtil.format(DateUtil.parse(fittingDataQueryParam.getSearchBeginTime(), DatePattern.NORM_DATE_PATTERN), DatePattern.NORM_DATETIME_PATTERN));
|
||||
commonQueryParam.setEndTime(DateUtil.format(DateUtil.endOfDay(DateUtil.parse(fittingDataQueryParam.getSearchEndTime(), DatePattern.NORM_DATE_PATTERN)), DatePattern.NORM_DATETIME_PATTERN));
|
||||
// 兼容用户功率需要该参数过滤
|
||||
String dataType = param.getValueType();
|
||||
if (StrUtil.isEmpty(dataType)) {
|
||||
// 电能质量指标,取限值计算类型,判断是否越限
|
||||
dataType = epdPqd.getFormula();
|
||||
}
|
||||
commonQueryParam.setDataType(dataType);
|
||||
|
||||
commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(finalCsLinePO.getLineId()));
|
||||
|
||||
List<StatisticalDataDTO> deviceRtData = commonService.getNewDeviceRtDataByTime(Collections.singletonList(commonQueryParam));
|
||||
dataList = deviceRtData.stream().map(temp -> {
|
||||
String unit;
|
||||
ThdDataVO vo = new ThdDataVO();
|
||||
vo.setLineId(temp.getLineId());
|
||||
// vo.setLineName(finalCsLinePO.getName());
|
||||
vo.setPhase(Objects.equals("M", temp.getPhaseType()) ? null : temp.getPhaseType());
|
||||
// vo.setPosition(position);
|
||||
vo.setTime(temp.getTime());
|
||||
vo.setStatMethod(commonQueryParam.getDataType());
|
||||
vo.setStatisticalData(Double.valueOf(df.format(temp.getValue())));
|
||||
if (temp.getValue() != null) {
|
||||
double re;
|
||||
if (Objects.equals("Primary", fittingDataQueryParam.getDataLevel())) {
|
||||
if (Objects.equals("Primary", csDataSet.getDataLevel())) {
|
||||
if (HarmonicConstant.POWER_LIST.contains(epdPqd.getShowName())) {
|
||||
re = Objects.isNull(temp.getValue()) ? 3.14159 : Double.parseDouble(df.format(temp.getValue() / 1000));
|
||||
vo.setStatisticalData(re);
|
||||
unit = "k" + epdPqd.getUnit();
|
||||
} else {
|
||||
vo.setStatisticalData(Objects.isNull(temp.getValue()) ? 3.14159 : Double.parseDouble(df.format(temp.getValue())));
|
||||
unit = epdPqd.getUnit();
|
||||
}
|
||||
} else {
|
||||
if (Objects.nonNull(epdPqd.getPrimaryFormula())) {
|
||||
switch (epdPqd.getPrimaryFormula()) {
|
||||
case "*PT":
|
||||
re = temp.getValue() * pt / 1000;
|
||||
unit = "k" + epdPqd.getUnit();
|
||||
break;
|
||||
case "*CT":
|
||||
re = temp.getValue() * ct;
|
||||
unit = epdPqd.getUnit();
|
||||
break;
|
||||
case "*PT*CT":
|
||||
re = temp.getValue() * pt * ct / 1000;
|
||||
unit = "k" + epdPqd.getUnit();
|
||||
break;
|
||||
default:
|
||||
re = temp.getValue();
|
||||
unit = epdPqd.getUnit();
|
||||
break;
|
||||
}
|
||||
vo.setStatisticalData(Double.valueOf(df.format(re)));
|
||||
} else {
|
||||
re = temp.getValue();
|
||||
unit = epdPqd.getUnit();
|
||||
vo.setStatisticalData(Double.valueOf(df.format(re)));
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (Objects.equals("Primary", csDataSet.getDataLevel())) {
|
||||
if (Objects.nonNull(epdPqd.getPrimaryFormula())) {
|
||||
switch (epdPqd.getPrimaryFormula()) {
|
||||
case "*PT":
|
||||
re = temp.getValue() / pt;
|
||||
break;
|
||||
case "*CT":
|
||||
re = temp.getValue() / ct;
|
||||
break;
|
||||
case "*PT*CT":
|
||||
re = temp.getValue() / pt / ct;
|
||||
break;
|
||||
default:
|
||||
re = temp.getValue();
|
||||
break;
|
||||
}
|
||||
vo.setStatisticalData(Double.valueOf(df.format(re)));
|
||||
} else {
|
||||
re = temp.getValue();
|
||||
vo.setStatisticalData(Double.valueOf(df.format(re)));
|
||||
}
|
||||
} else {
|
||||
vo.setStatisticalData(Double.valueOf(df.format(temp.getValue())));
|
||||
}
|
||||
unit = epdPqd.getUnit();
|
||||
}
|
||||
} else {
|
||||
vo.setStatisticalData(null);
|
||||
if (Objects.equals("Primary", fittingDataQueryParam.getDataLevel())) {
|
||||
if (Objects.equals("Primary", csDataSet.getDataLevel())) {
|
||||
unit = epdPqd.getUnit();
|
||||
} else {
|
||||
if (Objects.nonNull(epdPqd.getPrimaryFormula())) {
|
||||
switch (epdPqd.getPrimaryFormula()) {
|
||||
case "*PT":
|
||||
unit = "k" + epdPqd.getUnit();
|
||||
break;
|
||||
case "*CT":
|
||||
unit = epdPqd.getUnit();
|
||||
break;
|
||||
case "*PT*CT":
|
||||
unit = "k" + epdPqd.getUnit();
|
||||
break;
|
||||
default:
|
||||
unit = epdPqd.getUnit();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
unit = epdPqd.getUnit();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unit = epdPqd.getUnit();
|
||||
}
|
||||
}
|
||||
vo.setUnit(unit);
|
||||
// vo.setStatisticalIndex(epdPqd.getId());
|
||||
// vo.setStatisticalName(epdPqd.getName());
|
||||
vo.setStatisticalIndex(param.getStatisticalId());
|
||||
vo.setAnotherName(epdPqd.getShowName());
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
// 电能质量指标(越限为1,不越限为0)
|
||||
List<String> hasKeys = entries.keySet().stream().filter(key -> key.startsWith(dictCode)).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(hasKeys)) {
|
||||
List<ThdDataVO> limitDataList = new ArrayList<>();
|
||||
Map<Instant, List<ThdDataVO>> timeMap = dataList.stream().collect(Collectors.groupingBy(ThdDataVO::getTime));
|
||||
// 限值
|
||||
ThdDataVO data;
|
||||
for (Map.Entry<Instant, List<ThdDataVO>> entry: timeMap.entrySet()) {
|
||||
data = new ThdDataVO();
|
||||
List<ThdDataVO> list = entry.getValue();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
ThdDataVO thdDataVO = list.get(0);
|
||||
// data.setPosition(thdDataVO.getPosition());
|
||||
data.setLineId(thdDataVO.getLineId());
|
||||
// data.setLineName(thdDataVO.getLineName());
|
||||
data.setFrequency(param.getFrequency());
|
||||
data.setStatMethod(thdDataVO.getStatMethod());
|
||||
data.setUnit(thdDataVO.getUnit());
|
||||
data.setAnotherName(thdDataVO.getAnotherName());
|
||||
data.setStatisticalIndex(param.getStatisticalId());
|
||||
}
|
||||
Instant time = entry.getKey();
|
||||
data.setTime(time);
|
||||
|
||||
double limitValue = entries.getDouble(dictCode + (StringUtils.isEmpty(param.getFrequency()) ? "" : param.getFrequency()));
|
||||
double maxValue = list.stream().filter(v -> ObjectUtil.isNotEmpty(v.getStatisticalData())).mapToDouble(ThdDataVO::getStatisticalData).max().orElse(0.0);
|
||||
// 越限为1,不越限为0
|
||||
data.setStatisticalData(maxValue > limitValue ? 1.0 : 0.0);
|
||||
limitDataList.add(data);
|
||||
}
|
||||
limitDataList.sort(Comparator.comparing(ThdDataVO::getTime));
|
||||
result.addAll(limitDataList);
|
||||
} else {
|
||||
result.addAll(dataList);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<EnergyTemplateVO> getChildren(String tabId, List<EnergyTemplateVO> all) {
|
||||
return all.stream().filter(item -> item.getPid().equals(tabId)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.njcn.csharmonic.param;
|
||||
|
||||
|
||||
import com.njcn.web.pojo.annotation.DateTimeStrValid;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class FittingDataQueryParam {
|
||||
|
||||
@ApiModelProperty(value = "监测点")
|
||||
@NotBlank(message = "监测点ID不可为空")
|
||||
private String lineId;
|
||||
|
||||
@ApiModelProperty(name = "searchBeginTime", value = "开始时间")
|
||||
@NotBlank(message = "起始时间不可为空")
|
||||
@DateTimeStrValid(message = "起始时间格式出错")
|
||||
private String searchBeginTime;
|
||||
|
||||
@ApiModelProperty(name = "searchEndTime", value = "结束时间")
|
||||
@NotBlank(message = "结束时间不可为空")
|
||||
private String searchEndTime;
|
||||
|
||||
@ApiModelProperty(value = "用于选择多个指标及谐波次数")
|
||||
List<FittingDataQueryParam> list;
|
||||
@ApiModelProperty(value = "指标组id")
|
||||
private String statisticalId;
|
||||
@ApiModelProperty(value = "一次值:Primary;二次值:Secondary")
|
||||
private String dataLevel;
|
||||
|
||||
@ApiModelProperty(value = "取值类型:Max,Min,cp95,avg(用户功率专用)")
|
||||
private String valueType;
|
||||
|
||||
@ApiModelProperty(value = "频次2-50(谐波电压、谐波电流专用)")
|
||||
private String frequency;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user