feat(data): 添加InfluxDB存储名称映射功能

- 在CsDataArray实体类中新增influxDbName字段用于存储InfluxDB名称
- 集成字典数据和EPD服务实现数据映射逻辑
- 修改多个服务类中的数据查询逻辑以支持别名映射
- 统一数据类型转换为大写格式提升数据一致性
- 优化时间范围计算逻辑并移除无效的数据处理代码
- 清理无用的导入包和服务依赖项
This commit is contained in:
xy
2026-05-18 18:35:40 +08:00
parent aa36c077f2
commit 16724d7d79
8 changed files with 113 additions and 43 deletions

View File

@@ -1,5 +1,6 @@
package com.njcn.csdevice.pojo.po;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.bo.BaseEntity;
import lombok.Data;
@@ -43,6 +44,12 @@ public class CsDataArray extends BaseEntity {
*/
private String anotherName;
/**
* influxdb 存储的名称
*/
@TableField(exist = false)
private String influxDbName;
/**
* 字典序号
*/

View File

@@ -1,22 +1,26 @@
package com.njcn.csdevice.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
import com.njcn.csdevice.mapper.CsDataArrayMapper;
import com.njcn.csdevice.pojo.dto.DataArrayDTO;
import com.njcn.csdevice.pojo.param.DataArrayParam;
import com.njcn.csdevice.pojo.po.CsDataArray;
import com.njcn.csdevice.pojo.po.CsDataSet;
import com.njcn.csdevice.pojo.vo.DataArrayTreeVO;
import com.njcn.csdevice.pojo.vo.DeviceManagerDetailVO;
import com.njcn.csdevice.service.ICsDataArrayService;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.EpdFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.DictData;
import com.njcn.system.pojo.po.EleEpdPqd;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -33,6 +37,7 @@ import java.util.stream.Collectors;
public class CsDataArrayServiceImpl extends ServiceImpl<CsDataArrayMapper, CsDataArray> implements ICsDataArrayService {
private final EpdFeignClient epdFeignClient;
private final DicDataFeignClient dicDataFeignClient;
@Override
public List<CsDataArray> getArrayBySet(String dataSet) {
@@ -173,7 +178,34 @@ public class CsDataArrayServiceImpl extends ServiceImpl<CsDataArrayMapper, CsDat
@Override
public List<CsDataArray> findListByParam(DataArrayParam param) {
return this.baseMapper.findListByParam(param);
List<CsDataArray> list = this.baseMapper.findListByParam(param);
if (!CollectionUtils.isEmpty(list)) {
DictData pqd = dicDataFeignClient.getDicDataByCode(DicDataEnum.PQD.getCode()).getData();
if (ObjectUtil.isNotNull(pqd) && ObjectUtil.isNotNull(pqd.getId())) {
List<EleEpdPqd> epdList = epdFeignClient.dictMarkByDataType(pqd.getId()).getData();
if (!CollectionUtils.isEmpty(epdList)) {
Map<String, EleEpdPqd> epdPqdMap = epdList.stream().collect(Collectors.toMap(EleEpdPqd::getId, Function.identity()));
list.forEach(item->{
EleEpdPqd epdPqd = epdPqdMap.get(item.getDataId());
if (!Objects.isNull(epdPqd)) {
if (epdPqd.getOtherName() == null || epdPqd.getOtherName().isEmpty()) {
item.setInfluxDbName(epdPqd.getName());
} else {
String[] parts = item.getName().split("_");
String lastPart = parts[parts.length - 1];
boolean isLastNumeric = lastPart.matches("\\d+");
if (isLastNumeric) {
item.setInfluxDbName(epdPqd.getOtherName() + "_" + lastPart);
} else {
item.setInfluxDbName(epdPqd.getOtherName());
}
}
}
});
}
}
}
return list;
}
@Override

View File

@@ -327,13 +327,17 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
CommonQueryParam commonQueryParam = new CommonQueryParam();
commonQueryParam.setLineId(temp.getLineId());
commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(epdPqd.getClassId()));
commonQueryParam.setColumnName(epdPqd.getName()+ (StringUtils.isEmpty(param.getFrequency()) ? "":"_"+param.getFrequency()));
if (epdPqd.getName() == null || epdPqd.getName().isEmpty()) {
commonQueryParam.setColumnName(epdPqd.getName()+ (StringUtils.isEmpty(param.getFrequency()) ? "":"_"+param.getFrequency()));
} else {
commonQueryParam.setColumnName(epdPqd.getOtherName()+ (StringUtils.isEmpty(param.getFrequency()) ? "":"_"+param.getFrequency()));
}
commonQueryParam.setPhasic(epdPqd.getPhase());
commonQueryParam.setStartTime(DateUtil.format(DateUtil.parse(commonStatisticalQueryParam.getStartTime(),DatePattern.NORM_DATE_PATTERN), DatePattern.NORM_DATETIME_PATTERN));
commonQueryParam.setEndTime(DateUtil.format(DateUtil.endOfDay(DateUtil.parse(commonStatisticalQueryParam.getEndTime(),DatePattern.NORM_DATE_PATTERN)), DatePattern.NORM_DATETIME_PATTERN));
commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType());
commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType().toUpperCase());
commonQueryParam.setProcess(data1.get(0).getProcess()+"");
commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(temp.getLineId()));
return commonQueryParam;
@@ -493,8 +497,13 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
commonQueryParam.setLineId(temp.getLineId());
commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(epdPqd.getClassId()));
commonQueryParam.setColumnName(epdPqd.getName()+ finalFrequency);
if (epdPqd.getName() == null || epdPqd.getName().isEmpty()) {
commonQueryParam.setColumnName(epdPqd.getName()+ finalFrequency);
} else {
commonQueryParam.setColumnName(epdPqd.getOtherName()+ finalFrequency);
}
commonQueryParam.setPhasic(epdPqd.getPhase());
commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType() == null ? DataParam.portableDevStatisticalMethods:commonStatisticalQueryParam.getValueType());
commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType() == null ? DataParam.portableDevStatisticalMethods.toUpperCase():commonStatisticalQueryParam.getValueType().toUpperCase());
commonQueryParam.setProcess(data1.get(0).getProcess()+"");
commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(temp.getLineId()));
return commonQueryParam;
@@ -587,11 +596,10 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
List<Instant> instants = new ArrayList<>();
LocalDate startDate = LocalDate.parse(startDateStr, DATE_FORMATTER);
LocalDate endDate = LocalDate.parse(endDateStr, DATE_FORMATTER);
// 转换为指定时区的 ZonedDateTime
ZonedDateTime current = startDate.atStartOfDay(zone);
ZonedDateTime endDateTime = endDate.atTime(23, 59, 59).atZone(zone);
while (!current.isAfter(endDateTime)) {
instants.add(current.toInstant());
ZonedDateTime endDateTime = endDate.plusDays(1).atStartOfDay(zone);
while (current.isBefore(endDateTime)) {
instants.add(current.toInstant().plusSeconds(zone.getRules().getOffset(current.toInstant()).getTotalSeconds()));
current = current.plus(interval, unit);
}
return instants;
@@ -847,14 +855,16 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
CommonQueryParam commonQueryParam = new CommonQueryParam();
commonQueryParam.setLineId(finalCsLinePO.getLineId());
commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(epdPqd.getClassId()));
commonQueryParam.setColumnName(epdPqd.getName() + (StringUtils.isEmpty(param.getFrequency()) ? "" : "_" + param.getFrequency()));
if (epdPqd.getName() == null || epdPqd.getName().isEmpty()) {
commonQueryParam.setColumnName(epdPqd.getName()+ (StringUtils.isEmpty(param.getFrequency()) ? "":"_"+param.getFrequency()));
} else {
commonQueryParam.setColumnName(epdPqd.getOtherName()+ (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.setDataType(trendDataQueryParam.getValueType().toUpperCase());
commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(finalCsLinePO.getLineId()));
List<StatisticalDataDTO> deviceRtData = commonService.getNewDeviceRtDataByTime(Collections.singletonList(commonQueryParam));
@@ -1208,7 +1218,7 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
TrendDataQueryParam trendDataQueryParam = new TrendDataQueryParam();
trendDataQueryParam.setSearchBeginTime(param.getSearchBeginTime());
trendDataQueryParam.setSearchEndTime(param.getSearchEndTime());
trendDataQueryParam.setValueType(param.getValueType());
trendDataQueryParam.setValueType(param.getValueType().toUpperCase());
trendDataQueryParam.setDataLevel(param.getDataLevel());
List<SensitiveUserTrendDataQueryParam> paramList = param.getList();
List<TrendDataQueryParam> indexList = paramList.stream().map(item -> {

View File

@@ -132,7 +132,8 @@ public class RStatOnlineRateDServiceImpl extends MppServiceImpl<RStatOnlineRateD
}
}
} else {
onlineMinutes = 0;
//如果设备连一条记录没有,那就根本没接入,不需要统计
continue;
}
}

View File

@@ -482,11 +482,15 @@ public class WlRecordServiceImpl extends ServiceImpl<WlRecordMapper, WlRecord> i
CommonQueryParam commonQueryParam = new CommonQueryParam();
commonQueryParam.setLineId(temp.getLineId());
commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(epdPqd.getClassId()));
commonQueryParam.setColumnName(epdPqd.getName()+ (param.getFrequency() == null ? "":"_"+param.getFrequency()));
if (epdPqd.getName() == null || epdPqd.getName().isEmpty()) {
commonQueryParam.setColumnName(epdPqd.getName()+ (param.getFrequency() == null ? "":"_"+param.getFrequency()));
} else {
commonQueryParam.setColumnName(epdPqd.getOtherName()+ (param.getFrequency() == null ? "":"_"+param.getFrequency()));
}
commonQueryParam.setPhasic(epdPqd.getPhase());
commonQueryParam.setStartTime(LocalDateTimeUtil.format(wl.getStartTime(), DateTimeFormatter.ofPattern(DataParam.timeFormat)));
commonQueryParam.setEndTime(LocalDateTimeUtil.format(wl.getEndTime(), DateTimeFormatter.ofPattern(DataParam.timeFormat)));
commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType());
commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType().toUpperCase());
commonQueryParam.setProcess(data1.get(0).getProcess()+"");
commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(temp.getLineId()));
return commonQueryParam;

View File

@@ -33,6 +33,7 @@ import com.njcn.csharmonic.pojo.vo.RealTimeDataVo;
import com.njcn.csharmonic.service.CsEventPOService;
import com.njcn.csharmonic.service.IDataService;
import com.njcn.csharmonic.util.InfluxDbParamUtil;
import com.njcn.influx.constant.InfluxDbSqlConstant;
import com.njcn.influx.pojo.bo.CommonQueryParam;
import com.njcn.influx.pojo.dto.EventDataSetDTO;
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
@@ -510,7 +511,12 @@ public class DataServiceImpl implements IDataService {
double re;
vo.setId(item2.getId());
vo.setName(item2.getName());
StatisticalDataDTO statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getName(),item2.getPhase(),"avg",influxDbParamUtil.getClDidByLineId(lineId));
StatisticalDataDTO statisticalDataDTO;
if (item2.getOtherName() == null || item2.getOtherName().isEmpty()) {
statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getName(),item2.getPhase(), InfluxDbSqlConstant.AVG_WEB,influxDbParamUtil.getClDidByLineId(lineId));
} else {
statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getOtherName(),item2.getPhase(), InfluxDbSqlConstant.AVG_WEB,influxDbParamUtil.getClDidByLineId(lineId));
}
if (Objects.nonNull(statisticalDataDTO)) {
vo.setTime(statisticalDataDTO.getTime());
vo.setAvgValue(statisticalDataDTO.getValue());
@@ -600,7 +606,12 @@ public class DataServiceImpl implements IDataService {
RealTimeDataVo vo = new RealTimeDataVo();
vo.setId(item2.getId());
vo.setName(item2.getName().concat("_").concat(Integer.toString(i)));
StatisticalDataDTO statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getName().concat("_").concat(Integer.toString(i)),item2.getPhase(),"avg",influxDbParamUtil.getClDidByLineId(lineId));
StatisticalDataDTO statisticalDataDTO;
if (item2.getOtherName() == null || item2.getOtherName().isEmpty()) {
statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getName().concat("_").concat(Integer.toString(i)),item2.getPhase(),InfluxDbSqlConstant.AVG_WEB,influxDbParamUtil.getClDidByLineId(lineId));
} else {
statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getOtherName().concat("_").concat(Integer.toString(i)),item2.getPhase(),InfluxDbSqlConstant.AVG_WEB,influxDbParamUtil.getClDidByLineId(lineId));
}
double re;
String unit;
if (Objects.equals("Primary",dataLevel)) {
@@ -679,7 +690,12 @@ public class DataServiceImpl implements IDataService {
RealTimeDataVo vo = new RealTimeDataVo();
vo.setId(item2.getId());
vo.setName(item2.getName().concat("_").concat(Integer.toString(i)));
StatisticalDataDTO statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getName().concat("_").concat(Integer.toString(i)),item2.getPhase(),"avg",influxDbParamUtil.getClDidByLineId(lineId));
StatisticalDataDTO statisticalDataDTO;
if (item2.getOtherName() == null || item2.getOtherName().isEmpty()) {
statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getName().concat("_").concat(Integer.toString(i)),item2.getPhase(),InfluxDbSqlConstant.AVG_WEB,influxDbParamUtil.getClDidByLineId(lineId));
} else {
statisticalDataDTO = commonService.getLineRtData(lineId,influxDbParamUtil.getTableNameByClassId(item2.getClassId()),item2.getOtherName().concat("_").concat(Integer.toString(i)),item2.getPhase(),InfluxDbSqlConstant.AVG_WEB,influxDbParamUtil.getClDidByLineId(lineId));
}
double re;
String unit;
if (Objects.equals("Primary",dataLevel)) {
@@ -759,16 +775,16 @@ public class DataServiceImpl implements IDataService {
time.set(item.getTime());
}
});
if (Objects.nonNull(time.get())) {
list.forEach(item->{
if (ObjectUtil.isNotNull(item.getTime()) && item.getTime().isBefore(time.get())) {
item.setAvgValue(3.14159);
item.setValueA(3.14159);
item.setValueB(3.14159);
item.setValueC(3.14159);
}
});
}
// if (Objects.nonNull(time.get())) {
// list.forEach(item->{
// if (ObjectUtil.isNotNull(item.getTime()) && item.getTime().isBefore(time.get())) {
// item.setAvgValue(3.14159);
// item.setValueA(3.14159);
// item.setValueB(3.14159);
// item.setValueC(3.14159);
// }
// });
// }
List<RealTimeDataVo> result = new ArrayList<>();
//将list 排序,并按照排序后的结果进行有序分组

View File

@@ -7,8 +7,6 @@ import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO;
import com.njcn.csdevice.pojo.dto.LineParamDTO;
import com.njcn.csdevice.pojo.po.CsLedger;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.utils.ReflectUtils;
import com.njcn.csharmonic.param.CommonStatisticalQueryParam;
@@ -30,7 +28,6 @@ import com.njcn.system.api.CsStatisticalSetFeignClient;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.EpdFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.DictData;
import com.njcn.system.pojo.po.EleEpdPqd;
import lombok.RequiredArgsConstructor;
import org.influxdb.dto.QueryResult;
@@ -39,7 +36,6 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.text.DecimalFormat;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -211,11 +207,13 @@ public class StableDataServiceImpl implements StableDataService {
CommonQueryParam commonQueryParam = new CommonQueryParam();
commonQueryParam.setLineId(temp.getLineId());
commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(data.getClassId()));
commonQueryParam.setColumnName(data.getName()+ finalFrequency1);
if (data.getName() == null || data.getName().isEmpty()) {
commonQueryParam.setColumnName(data.getName()+ finalFrequency1);
} else {
commonQueryParam.setColumnName(data.getOtherName()+ finalFrequency1);
}
commonQueryParam.setPhasic(data.getPhase());
// commonQueryParam.setStartTime();
// commonQueryParam.setEndTime();
commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType());
commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType().toUpperCase());
commonQueryParam.setProcess(data1.get(0).getProcess()+"");
commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(temp.getLineId()));
@@ -284,11 +282,15 @@ public class StableDataServiceImpl implements StableDataService {
CommonQueryParam commonQueryParam = new CommonQueryParam();
commonQueryParam.setLineId(temp.getLineId());
commonQueryParam.setTableName(influxDbParamUtil.getTableNameByClassId(epdPqd.getClassId()));
commonQueryParam.setColumnName(epdPqd.getName()+ finalFrequency1);
if (epdPqd.getName() == null || epdPqd.getName().isEmpty()) {
commonQueryParam.setColumnName(epdPqd.getName()+ finalFrequency1);
} else {
commonQueryParam.setColumnName(epdPqd.getOtherName()+ finalFrequency1);
}
commonQueryParam.setPhasic(epdPqd.getPhase());
commonQueryParam.setStartTime(commonStatisticalQueryParam.getStartTime() + " 00:00:00");
commonQueryParam.setEndTime(commonStatisticalQueryParam.getEndTime() + " 23:59:59");
commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType());
commonQueryParam.setDataType(commonStatisticalQueryParam.getValueType().toUpperCase());
commonQueryParam.setProcess(data1.get(0).getProcess()+"");
commonQueryParam.setClDid(influxDbParamUtil.getClDidByLineId(temp.getLineId()));

View File

@@ -2,7 +2,6 @@ package com.njcn.cssystem.task;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
import com.njcn.cssystem.service.IDataTaskService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -20,7 +19,6 @@ import org.springframework.stereotype.Component;
public class DataTask {
private final IDataTaskService taskService;
private final CsDeviceUserFeignClient csDeviceUserFeignClient;
//每天4点计算稳态越限数据
@Scheduled(cron = "0 0 4 * * ?")
@@ -33,7 +31,7 @@ public class DataTask {
@Scheduled(cron = "0 0 5 * * ?")
public void csAlarmJob() {
String date = DateUtil.yesterday().toString(DatePattern.NORM_DATE_PATTERN);
taskService.channelRunAlarm(date);
taskService.channelRunDataAlarm(date);
}
//每天10点推送App消息 (稳态事件 告警数据)