feat(device): 新增趋势数据查询功能- 在CsGroupController中增加/trendData接口,支持查询趋势数据-

fix(device): 完善监测点相关接口与实体字段

- 在CsLinePO实体中新增monitorObj和govern字段
- 补充getLineByName和list接口,增强监测点查询能力
This commit is contained in:
贾同学
2025-11-13 08:58:43 +08:00
parent 2fb11ecaaf
commit ce0b9892c2
11 changed files with 271 additions and 20 deletions

View File

@@ -35,12 +35,6 @@
<artifactId>common-microservice</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>cs-warn-api</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>user-api</artifactId>
@@ -59,6 +53,12 @@
<artifactId>common-device-biz</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>4.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@@ -50,6 +50,10 @@ public interface CsLineFeignClient {
@PostMapping("/updateLineDataByList")
HttpResult<String> updateDataByList(@RequestParam("list") List<String> list, @RequestParam("id") String id, @RequestParam("setId") String setId);
@PostMapping("/getLineByName")
HttpResult<List<CsLinePO>> getLineByName(@RequestParam("lineName") String lineName);
@PostMapping("/getAllLine")
HttpResult<List<String>> getAllLine();

View File

@@ -99,6 +99,11 @@ public class CsLineClientFallbackFactory implements FallbackFactory<CsLineFeignC
log.error("{}异常,降级处理,异常为:{}","根据监测点id集合获取国标限值异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<CsLinePO>> getLineByName(String lineName) {
log.error("{}异常,降级处理,异常为:{}","根据名称查询监测点异常",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -122,4 +122,14 @@ public class CsLinePO extends BaseEntity {
*/
@TableField(value = "line_no")
private Integer lineNo;
}
/**
* 监测对象类型
*/
@TableField(value = "monitor_obj")
private String monitorObj;
/**
* 是否治理(0:未治理 1:已治理)
*/
@TableField(value = "is_govern")
private Integer govern;
}

View File

@@ -1,7 +1,6 @@
package com.njcn.csdevice.pojo.vo;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.cswarn.pojo.vo.CsEquipmentAlarmVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

View File

@@ -88,11 +88,6 @@
<artifactId>hutool-all</artifactId>
<version>5.8.5</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>cs-warn-api</artifactId>
<version>${project.version}</version>
</dependency>
<!-- zxing生成二维码 -->
<dependency>
@@ -153,12 +148,21 @@
<artifactId>access-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-mq</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-mq</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.njcn.platform</groupId>
<artifactId>message-api</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>

View File

@@ -12,7 +12,9 @@ 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.TrendDataQueryParam;
import com.njcn.csharmonic.pojo.vo.ThdDataTdVO;
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
import com.njcn.system.pojo.po.EleEpdPqd;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
@@ -21,6 +23,7 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -143,5 +146,15 @@ public class CsGroupController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/trendData")
@ApiOperation("查询趋势数据")
@ApiImplicitParam(name = "param",required = true)
public HttpResult<List<ThdDataVO>> trendData(@RequestBody @Validated TrendDataQueryParam param){
String methodDescribe = getMethodDescribe("trendData");
List<ThdDataVO> list = csGroupService.trendData(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
}

View File

@@ -229,4 +229,24 @@ public class CslineController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getLineByName")
@ApiOperation("根据名称获取监测点")
@ApiImplicitParam(name = "lineName", value = "监测点名称", required = true)
public HttpResult<List<CsLinePO>> getLineByName(@RequestParam("lineName") String lineName) {
String methodDescribe = getMethodDescribe("getLineByName");
List<CsLinePO> list = csLinePOService.getLineByName(lineName);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/list")
@ApiOperation("查询监测点列表")
public HttpResult<List<CsLinePO>> list() {
String methodDescribe = getMethodDescribe("list");
List<CsLinePO> list = csLinePOService.list(new LambdaQueryWrapper<CsLinePO>().orderByAsc(CsLinePO::getName));
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
}

View File

@@ -7,10 +7,10 @@ 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.TrendDataQueryParam;
import com.njcn.csharmonic.pojo.vo.ThdDataTdVO;
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
import com.njcn.system.pojo.po.EleEpdPqd;
import com.njcn.system.pojo.vo.EleEpdPqdListVO;
import java.util.List;
@@ -78,4 +78,11 @@ public interface ICsGroupService extends IService<CsGroup> {
*/
void deleteGroup(String groupId);
/**
* 查询趋势数据
* @return
*/
List<ThdDataVO> trendData(TrendDataQueryParam trendDataQueryParam);
}

View File

@@ -33,6 +33,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.TrendDataQueryParam;
import com.njcn.csharmonic.pojo.vo.ThdDataTdVO;
import com.njcn.csharmonic.pojo.vo.ThdDataVO;
import com.njcn.device.biz.pojo.po.Overlimit;
@@ -784,6 +785,154 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
}
}
@Override
public List<ThdDataVO> trendData(TrendDataQueryParam trendDataQueryParam) {
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())){
throw new BusinessException("当前测点数据集主要信息缺失,请联系管理员排查(测点表里面数据集id缺失)");
}
Double ct = finalCsLinePO.getCtRatio();
Double pt = finalCsLinePO.getPtRatio();
if(CollectionUtil.isNotEmpty(trendDataQueryParam.getList())) {
for (TrendDataQueryParam param : trendDataQueryParam.getList()) {
List<EleEpdPqd> eleEpdPqds = csStatisticalSetFeignClient.queryStatisticalSelect(param.getStatisticalId()).getData();
eleEpdPqds.forEach(epdPqd -> {
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(trendDataQueryParam.getSearchBeginTime(), DatePattern.NORM_DATE_PATTERN), DatePattern.NORM_DATETIME_PATTERN));
commonQueryParam.setEndTime(DateUtil.format(DateUtil.endOfDay(DateUtil.parse(trendDataQueryParam.getSearchEndTime(), DatePattern.NORM_DATE_PATTERN)), DatePattern.NORM_DATETIME_PATTERN));
commonQueryParam.setDataType(trendDataQueryParam.getValueType());
commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(finalCsLinePO.getLineId()));
List<StatisticalDataDTO> deviceRtData = commonService.getDeviceRtDataByTime(Collections.singletonList(commonQueryParam));
List<ThdDataVO> collect1 = deviceRtData.stream().map(temp -> {
String unit;
ThdDataVO vo = new ThdDataVO();
vo.setLineId(temp.getLineId());
vo.setPhase(Objects.equals("M", temp.getPhaseType()) ? null : temp.getPhaseType());
String position = finalCsLinePO.getPosition();
vo.setPosition(position);
vo.setTime(temp.getTime());
vo.setStatMethod(temp.getValueType());
vo.setStatisticalData(Double.valueOf(df.format(temp.getValue())));
if (temp.getValue() != null) {
double re = 0;
if (Objects.equals("Primary", trendDataQueryParam.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", trendDataQueryParam.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.setAnotherName(epdPqd.getShowName());
return vo;
}).collect(Collectors.toList());
result.addAll(collect1);
});
}
}
return result;
}
private List<EnergyTemplateVO> getChildren(String tabId, List<EnergyTemplateVO> all) {
return all.stream().filter(item -> item.getPid().equals(tabId)).collect(Collectors.toList());
}

View File

@@ -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 TrendDataQueryParam {
@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<TrendDataQueryParam> list;
@ApiModelProperty(value = "指标组id")
private String statisticalId;
@ApiModelProperty(value = "取值类型MaxMincp95avg")
private String valueType;
@ApiModelProperty(value = "一次值Primary;二次值Secondary")
private String dataLevel;
@ApiModelProperty(value = "频次2-50")
private String frequency;
}