|
|
@@ -0,0 +1,940 @@
|
|
|
+package com.energy.manage.analyse.service.anomaly.impl;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
+import com.energy.manage.analyse.constant.AnomalySensorType;
|
|
|
+import com.energy.manage.analyse.constant.DetectorTableEnum;
|
|
|
+import com.energy.manage.analyse.constant.DetectorType;
|
|
|
+import com.energy.manage.analyse.domain.dto.AnomalyDTO;
|
|
|
+import com.energy.manage.analyse.domain.dto.AnomalyModelDTO;
|
|
|
+import com.energy.manage.analyse.domain.vo.anomaly.*;
|
|
|
+import com.energy.manage.analyse.mappers.anomaly.AnomalyWindfarmMapper;
|
|
|
+import com.energy.manage.analyse.mappers.windenginegroup.WindEngineGroupMapper;
|
|
|
+import com.energy.manage.analyse.mappers.windfield.WindFieldMapper;
|
|
|
+import com.energy.manage.analyse.po.anomaly.*;
|
|
|
+import com.energy.manage.analyse.po.windenginegroup.WindEngineGroupPO;
|
|
|
+import com.energy.manage.analyse.po.windfield.WindFieldPO;
|
|
|
+import com.energy.manage.analyse.service.anomaly.AnomalyService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import tk.mybatis.mapper.entity.Example;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class AnomalyServiceImpl implements AnomalyService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AnomalyWindfarmMapper anomalyWindfarmMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WindFieldMapper windFieldMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WindEngineGroupMapper windEngineGroupMapper;
|
|
|
+
|
|
|
+ // 通用日期格式化器(线程安全,可全局复用)
|
|
|
+ private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+
|
|
|
+ private static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ // 分表前缀
|
|
|
+ private static final String TABLE_PREFIX = "analyse.anomaly_model_";
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AnomalyOverviewVO getAnomalyOverview(AnomalyDTO anomalyDTO) {
|
|
|
+
|
|
|
+ String fieldId = null;
|
|
|
+ WindFieldPO windFieldPO = getWindField(anomalyDTO.getFieldCode());
|
|
|
+ if (windFieldPO != null) {
|
|
|
+ fieldId = windFieldPO.getFieldId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fieldId == null) {
|
|
|
+ log.warn(" 健康检测大唐内部风场编号没有对应台账fieldId ");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ String beginTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ if (!StringUtils.isEmpty(anomalyDTO.getDatatime())) {
|
|
|
+ beginTime = appendTimeToString(anomalyDTO.getDatatime(), 00, 00, 00);
|
|
|
+ endTime = appendTimeToString(anomalyDTO.getDatatime(), 23, 59, 59);
|
|
|
+ } else {
|
|
|
+ beginTime = getYesterdayStartStr();
|
|
|
+ endTime = getYesterdayEnd().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清除当前
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ // 切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("slave");
|
|
|
+ return anomalyWindfarmMapper.selectAnomalyWindfarmAndFieldId(fieldId, beginTime, endTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询风场信息
|
|
|
+ *
|
|
|
+ * @param fieldCode
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private WindFieldPO getWindField(String fieldCode) {
|
|
|
+ // 清除当前
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ // 切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("master");
|
|
|
+ WindFieldPO windFieldPO = null;
|
|
|
+ if (!StringUtils.isEmpty(fieldCode)) {
|
|
|
+ WindFieldPO po = new WindFieldPO();
|
|
|
+ po.setFieldCode(fieldCode);
|
|
|
+ windFieldPO = windFieldMapper.selectOne(po);
|
|
|
+ }
|
|
|
+ return windFieldPO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询风机对象集合
|
|
|
+ * @param eids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, String> getWindEngineGroupMap(Set<String> eids) {
|
|
|
+ // 清除当前
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ // 切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("master");
|
|
|
+ // 查询平台风机模块
|
|
|
+ Example example = new Example(WindEngineGroupPO.class);
|
|
|
+ Example.Criteria criteria = example.createCriteria();
|
|
|
+ criteria.andIn("engineId", eids);
|
|
|
+ List<WindEngineGroupPO> list = windEngineGroupMapper.selectByExample(example);
|
|
|
+ // key为String时
|
|
|
+ Map<String, String> windEngineMap = list.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ WindEngineGroupPO::getEngineId,
|
|
|
+ WindEngineGroupPO::getEngineName,
|
|
|
+ (oldValue, newValue) -> oldValue
|
|
|
+ ));
|
|
|
+
|
|
|
+ return windEngineMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BarChartVO getBarChartStats(AnomalyDTO anomalyDTO) {
|
|
|
+
|
|
|
+ String fieldId = null;
|
|
|
+ WindFieldPO windFieldPO = getWindField(anomalyDTO.getFieldCode());
|
|
|
+ if (windFieldPO != null) {
|
|
|
+ fieldId = windFieldPO.getFieldId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fieldId == null) {
|
|
|
+ log.warn(" 健康检测大唐内部风场编号没有对应台账fieldId ");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ String beginTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ if (!StringUtils.isEmpty(anomalyDTO.getDatatime())) {
|
|
|
+ beginTime = appendTimeToString(anomalyDTO.getDatatime(), 00, 00, 00);
|
|
|
+ endTime = appendTimeToString(anomalyDTO.getDatatime(), 23, 59, 59);
|
|
|
+ } else {
|
|
|
+ beginTime = getYesterdayStartStr();
|
|
|
+ endTime = getYesterdayEnd().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+ String year = String.valueOf(LocalDate.now().getYear());
|
|
|
+
|
|
|
+ // 清除当前
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ // 切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("slave");
|
|
|
+ return anomalyWindfarmMapper.selectAnomalyModelCount(fieldId, year, beginTime, endTime);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AnomalyModelVO> getAnomalyModel(AnomalyDTO anomalyDTO) {
|
|
|
+
|
|
|
+ AnomalyChartVO anomalyChartVO = new AnomalyChartVO();
|
|
|
+ String fieldId = null;
|
|
|
+ WindFieldPO windFieldPO = getWindField(anomalyDTO.getFieldCode());
|
|
|
+ if (windFieldPO != null) {
|
|
|
+ fieldId = windFieldPO.getFieldId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fieldId == null) {
|
|
|
+ log.warn(" 大唐内部风场编号没有对应台账fieldId ");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ String beginTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ if (!StringUtils.isEmpty(anomalyDTO.getDatatime())) {
|
|
|
+ beginTime = appendTimeToString(anomalyDTO.getDatatime(), 00, 00, 00);
|
|
|
+ endTime = appendTimeToString(anomalyDTO.getDatatime(), 23, 59, 59);
|
|
|
+ } else {
|
|
|
+ beginTime = getYesterdayStartStr();
|
|
|
+ endTime = getYesterdayEnd().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+ String year = String.valueOf(LocalDate.now().getYear());
|
|
|
+
|
|
|
+ // 清除当前
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ // 切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("slave");
|
|
|
+ List<AnomalyModelPO> getAnomalyModelList = anomalyWindfarmMapper.selectAllAnomalyModel(fieldId, year, beginTime, endTime);
|
|
|
+ if (CollectionUtil.isEmpty(getAnomalyModelList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 复制对象集合
|
|
|
+ List<AnomalyModelVO> anomalyModelVOS = getAnomalyModelList.stream()
|
|
|
+ // 逐个复制对象属性:源对象 → 目标类的新对象
|
|
|
+ .map(source -> BeanUtil.copyProperties(source, AnomalyModelVO.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return anomalyModelVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AnomalyChartVO getAnomalyModelMap(AnomalyDTO anomalyDTO){
|
|
|
+
|
|
|
+ AnomalyChartVO anomalyChartVO = new AnomalyChartVO();
|
|
|
+ String fieldId = null;
|
|
|
+ WindFieldPO windFieldPO = getWindField(anomalyDTO.getFieldCode());
|
|
|
+ if (windFieldPO != null) {
|
|
|
+ fieldId = windFieldPO.getFieldId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fieldId == null) {
|
|
|
+ log.warn(" 健康检测大唐内部风场编号没有对应台账fieldId ");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ String beginTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ if (!StringUtils.isEmpty(anomalyDTO.getDatatime())) {
|
|
|
+ beginTime = appendTimeToString(anomalyDTO.getDatatime(), 00, 00, 00);
|
|
|
+ endTime = appendTimeToString(anomalyDTO.getDatatime(), 23, 59, 59);
|
|
|
+ } else {
|
|
|
+ beginTime = getYesterdayStartStr();
|
|
|
+ endTime = getYesterdayEnd().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+ String year = String.valueOf(LocalDate.now().getYear());
|
|
|
+
|
|
|
+ // 清除当前
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ // 切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("slave");
|
|
|
+ List<AnomalyModelPO> getAnomalyModelList = anomalyWindfarmMapper.selectAllAnomalyModel(fieldId, year, beginTime, endTime);
|
|
|
+ if (CollectionUtil.isEmpty(getAnomalyModelList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取风机id集合
|
|
|
+ Set<String> eids = getAnomalyModelList.parallelStream().map(AnomalyModelPO::getEngineId).collect(Collectors.toSet());
|
|
|
+ Map<String, String> engineMap = getWindEngineGroupMap(eids);
|
|
|
+
|
|
|
+ Map<String, List<AnomalyThermodynamicDiagramVO>> anomalyChartMap = getAnomalyThermodynamicDiagramMap(getAnomalyModelList,engineMap);
|
|
|
+ Map<String, List<AnomalyThermodynamicDiagramVO>> anomalySensorMap = getAnomalySensorMap(getAnomalyModelList,engineMap);
|
|
|
+
|
|
|
+ anomalyChartVO.setAnomalyChartMap(anomalyChartMap);
|
|
|
+ anomalyChartVO.setAnomalySensorMap(anomalySensorMap);
|
|
|
+
|
|
|
+ return anomalyChartVO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 整合数据检测器map
|
|
|
+ * @param getAnomalyModelList
|
|
|
+ * @param engineMap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, List<AnomalyThermodynamicDiagramVO>> getAnomalyThermodynamicDiagramMap(List<AnomalyModelPO> getAnomalyModelList,Map<String, String> engineMap){
|
|
|
+
|
|
|
+ Map<String, List<AnomalyThermodynamicDiagramVO>> map = new HashMap<>();
|
|
|
+ // 模块1:风速功率检测器
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model1PowercurveList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model1ScatterList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model1SimulinkList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 模块2:偏航检测器
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model2StaticyawList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model2CabletwistList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 模块3:变桨检测器
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model3PitchregulationList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model3PitchcoordList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model3MinpitchList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 模块4:运行状态检测器
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model4PowerqualityList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model4OperationstateList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model4CtrlparamDeloadList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 模块5:气动性能
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model5CPList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model5TSRList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> model5CPTSRList = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ // 模块1:风速功率检测器
|
|
|
+ AnomalyThermodynamicDiagramVO model1Powercurve = null;
|
|
|
+ AnomalyThermodynamicDiagramVO model1Scatter = null;
|
|
|
+ AnomalyThermodynamicDiagramVO model1Simulink = null;
|
|
|
+ // 模块2:偏航检测器
|
|
|
+ AnomalyThermodynamicDiagramVO model2Staticyaw = null;
|
|
|
+ AnomalyThermodynamicDiagramVO model2Cabletwist = null;
|
|
|
+ // 模块3:变桨检测器
|
|
|
+ AnomalyThermodynamicDiagramVO model3Pitchregulation = null;
|
|
|
+ AnomalyThermodynamicDiagramVO model3Pitchcoord = null;
|
|
|
+ AnomalyThermodynamicDiagramVO model3Minpitch = null;
|
|
|
+ // 模块4:运行状态检测器
|
|
|
+ AnomalyThermodynamicDiagramVO model4Powerquality = null;
|
|
|
+ AnomalyThermodynamicDiagramVO model4Operationstate = null;
|
|
|
+ AnomalyThermodynamicDiagramVO model4CtrlparamDeload = null;
|
|
|
+ // 模块5:气动性能
|
|
|
+ AnomalyThermodynamicDiagramVO model5CP = null;
|
|
|
+ AnomalyThermodynamicDiagramVO model5TSR = null;
|
|
|
+ AnomalyThermodynamicDiagramVO model5CPTSR = null;
|
|
|
+
|
|
|
+ for (AnomalyModelPO anomalyModelPO : getAnomalyModelList) {
|
|
|
+
|
|
|
+ // 模块1:风速功率检测器
|
|
|
+ model1Powercurve = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model1Powercurve.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model1Powercurve.setIfAbnorma(anomalyModelPO.getModel1WindpwrPowercurve());
|
|
|
+ model1Powercurve.setRatio(anomalyModelPO.getModel1WindpwrPowercurveRatio());
|
|
|
+ model1PowercurveList.add(model1Powercurve);
|
|
|
+
|
|
|
+ model1Scatter = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model1Scatter.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model1Scatter.setIfAbnorma(anomalyModelPO.getModel1WindpwrScatter());
|
|
|
+ model1Scatter.setRatio(anomalyModelPO.getModel1WindpwrScatterRatio());
|
|
|
+ model1ScatterList.add(model1Scatter);
|
|
|
+
|
|
|
+ model1Simulink = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model1Simulink.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model1Simulink.setIfAbnorma(anomalyModelPO.getModel1WindpwrSimulink());
|
|
|
+ model1SimulinkList.add(model1Simulink);
|
|
|
+
|
|
|
+ // 模块2:偏航检测器
|
|
|
+ model2Staticyaw = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model2Staticyaw.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model2Staticyaw.setIfAbnorma(anomalyModelPO.getModel2YawStaticyaw());
|
|
|
+ model2Staticyaw.setRatio(anomalyModelPO.getModel2YawStaticyawRatio());
|
|
|
+ model2StaticyawList.add(model2Staticyaw);
|
|
|
+
|
|
|
+ model2Cabletwist = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model2Cabletwist.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model2Cabletwist.setIfAbnorma(anomalyModelPO.getModel2YawCabletwist());
|
|
|
+ model2Staticyaw.setRatio(anomalyModelPO.getModel2YawStaticyawRatio());
|
|
|
+ model2CabletwistList.add(model2Cabletwist);
|
|
|
+
|
|
|
+ // 模块3:变桨检测器
|
|
|
+ model3Pitchregulation = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model3Pitchregulation.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model3Pitchregulation.setIfAbnorma(anomalyModelPO.getModel3PitchPitchregulation());
|
|
|
+ model3Pitchregulation.setRatio(anomalyModelPO.getModel3PitchPitchregulationRatio());
|
|
|
+ model3PitchregulationList.add(model3Pitchregulation);
|
|
|
+
|
|
|
+ model3Pitchcoord = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model3Pitchcoord.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model3Pitchcoord.setIfAbnorma(anomalyModelPO.getModel3PitchPitchcoord());
|
|
|
+ model3Pitchcoord.setRatio(anomalyModelPO.getModel3PitchPitchcoordRatio());
|
|
|
+ model3PitchcoordList.add(model3Pitchcoord);
|
|
|
+
|
|
|
+ model3Minpitch = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model3Minpitch.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model3Minpitch.setIfAbnorma(anomalyModelPO.getModel3PitchMinpitch());
|
|
|
+ model3MinpitchList.add(model3Minpitch);
|
|
|
+
|
|
|
+ // 模块4:运行状态检测器
|
|
|
+ model4Powerquality = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model4Powerquality.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model4Powerquality.setIfAbnorma(anomalyModelPO.getModel4CtrlparamPowerquality());
|
|
|
+ model4Powerquality.setRatio(anomalyModelPO.getModel4CtrlparamPowerqualityRatio());
|
|
|
+ model4PowerqualityList.add(model4Powerquality);
|
|
|
+
|
|
|
+ model4Operationstate = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model4Operationstate.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model4Operationstate.setIfAbnorma(anomalyModelPO.getModel4CtrlparamOperationstate());
|
|
|
+ model4Operationstate.setRatio(anomalyModelPO.getModel4CtrlparamOperationstateRatio());
|
|
|
+ model4OperationstateList.add(model4Operationstate);
|
|
|
+
|
|
|
+ model4CtrlparamDeload = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model4CtrlparamDeload.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model4CtrlparamDeload.setRatio(anomalyModelPO.getModel4CtrlparamPowerqualityRatio());
|
|
|
+ model4CtrlparamDeloadList.add(model4CtrlparamDeload);
|
|
|
+
|
|
|
+ // 模块5:气动性能
|
|
|
+ model5CP = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model5CP.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model5CP.setRatio(anomalyModelPO.getModel5AerodynamicsCpRatio());
|
|
|
+ model5CPList.add(model5CP);
|
|
|
+
|
|
|
+ model5TSR = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model5TSR.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model5TSR.setRatio(anomalyModelPO.getModel5AerodynamicsTsrRatio());
|
|
|
+ model5TSRList.add(model5TSR);
|
|
|
+
|
|
|
+ model5CPTSR = new AnomalyThermodynamicDiagramVO();
|
|
|
+ model5CPTSR.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ model5CPTSR.setRatio(anomalyModelPO.getModel5AerodynamicsCpTsrRatio());
|
|
|
+ model5CPTSRList.add(model5CPTSR);
|
|
|
+
|
|
|
+ }
|
|
|
+ // 模块1:风速功率检测器
|
|
|
+ map.put(DetectorType.MODEL1_POWERCURVE.getCode(),model1PowercurveList);
|
|
|
+ map.put(DetectorType.MODEL1_SCATTER.getCode(),model1ScatterList);
|
|
|
+ map.put(DetectorType.MODEL1_SIMULINK.getCode(),model1SimulinkList);
|
|
|
+ // 模块2:偏航检测器
|
|
|
+ map.put(DetectorType.MODEL2_STATICYAW.getCode(),model2StaticyawList);
|
|
|
+ map.put(DetectorType.MODEL2_CABLETWIST.getCode(),model2CabletwistList);
|
|
|
+ // 模块3:变桨检测器
|
|
|
+ map.put(DetectorType.MODEL3_PITCHREGULATION.getCode(),model3PitchregulationList);
|
|
|
+ map.put(DetectorType.MODEL3_PITCHCOORD.getCode(),model3PitchcoordList);
|
|
|
+ map.put(DetectorType.MODEL3_MINPITCH.getCode(),model3MinpitchList);
|
|
|
+ // 模块4:运行状态检测器
|
|
|
+ map.put(DetectorType.MODEL4_POWERQUALITY.getCode(),model4PowerqualityList);
|
|
|
+ map.put(DetectorType.MODEL4_OPERATIONSTATE.getCode(),model4OperationstateList);
|
|
|
+ map.put(DetectorType.MODEL4_DELOAD.getCode(),model4CtrlparamDeloadList);
|
|
|
+ // 模块5:气动性能
|
|
|
+ map.put(DetectorType.MODEL5_CP.getCode(),model5CPList);
|
|
|
+ map.put(DetectorType.MODEL5_TSR.getCode(),model5TSRList);
|
|
|
+ map.put(DetectorType.MODEL5_CP_TSR.getCode(),model5CPTSRList);
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Map<String, List<AnomalyThermodynamicDiagramVO>> getAnomalySensorMap(List<AnomalyModelPO> getAnomalyModelList,Map<String, String> engineMap){
|
|
|
+
|
|
|
+ Map<String, List<AnomalyThermodynamicDiagramVO>> map = new HashMap<>();
|
|
|
+
|
|
|
+ // 物理传感器异常列表
|
|
|
+ List<AnomalyThermodynamicDiagramVO> powerSensorAnomalyList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> windSpeedSensorAnomalyList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> pitchSensorAnomalyList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> rotationSpeedSensorAnomalyList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> torqueSensorAnomalyList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 逻辑关联异常列表
|
|
|
+ List<AnomalyThermodynamicDiagramVO> windPowerLogicAnomalyList = new ArrayList<>();
|
|
|
+ List<AnomalyThermodynamicDiagramVO> speedTorqueLogicAnomalyList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 物理传感器异常列表
|
|
|
+ AnomalyThermodynamicDiagramVO powerSensorAnomaly = null;
|
|
|
+ AnomalyThermodynamicDiagramVO windSpeedSensorAnomaly = null;
|
|
|
+ AnomalyThermodynamicDiagramVO pitchSensorAnomaly = null;
|
|
|
+ AnomalyThermodynamicDiagramVO rotationSpeedSensorAnomaly = null;
|
|
|
+ AnomalyThermodynamicDiagramVO torqueSensorAnomaly = null;
|
|
|
+
|
|
|
+ // 逻辑关联异常列表
|
|
|
+ AnomalyThermodynamicDiagramVO windPowerLogicAnomaly = null;
|
|
|
+ AnomalyThermodynamicDiagramVO speedTorqueLogicAnomaly = null;
|
|
|
+
|
|
|
+
|
|
|
+ for (AnomalyModelPO anomalyModelPO : getAnomalyModelList) {
|
|
|
+
|
|
|
+ powerSensorAnomaly = new AnomalyThermodynamicDiagramVO();
|
|
|
+ powerSensorAnomaly.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ powerSensorAnomaly.setIfAbnorma(anomalyModelPO.getSensorAnomalyPower());
|
|
|
+ powerSensorAnomaly.setRatio(anomalyModelPO.getSensorAnomalyPowerRatio());
|
|
|
+ powerSensorAnomalyList.add(powerSensorAnomaly);
|
|
|
+
|
|
|
+ windSpeedSensorAnomaly = new AnomalyThermodynamicDiagramVO();
|
|
|
+ windSpeedSensorAnomaly.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ windSpeedSensorAnomaly.setIfAbnorma(anomalyModelPO.getSensorAnomalyWind());
|
|
|
+ windSpeedSensorAnomaly.setRatio(anomalyModelPO.getSensorAnomalyWindRatio());
|
|
|
+ windSpeedSensorAnomalyList.add(windSpeedSensorAnomaly);
|
|
|
+
|
|
|
+ pitchSensorAnomaly = new AnomalyThermodynamicDiagramVO();
|
|
|
+ pitchSensorAnomaly.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ pitchSensorAnomaly.setIfAbnorma(anomalyModelPO.getSensorAnomalyPitch());
|
|
|
+ pitchSensorAnomaly.setRatio(anomalyModelPO.getSensorAnomalyPitchRatio());
|
|
|
+ pitchSensorAnomalyList.add(pitchSensorAnomaly);
|
|
|
+
|
|
|
+ rotationSpeedSensorAnomaly = new AnomalyThermodynamicDiagramVO();
|
|
|
+ rotationSpeedSensorAnomaly.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ rotationSpeedSensorAnomaly.setIfAbnorma(anomalyModelPO.getSensorAnomalySpeed());
|
|
|
+ rotationSpeedSensorAnomaly.setRatio(anomalyModelPO.getSensorAnomalySpeedRatio());
|
|
|
+ rotationSpeedSensorAnomalyList.add(rotationSpeedSensorAnomaly);
|
|
|
+
|
|
|
+ torqueSensorAnomaly = new AnomalyThermodynamicDiagramVO();
|
|
|
+ torqueSensorAnomaly.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ torqueSensorAnomaly.setIfAbnorma(anomalyModelPO.getSensorAnomalyTorque());
|
|
|
+ torqueSensorAnomaly.setRatio(anomalyModelPO.getSensorAnomalyTorqueRatio());
|
|
|
+ torqueSensorAnomalyList.add(torqueSensorAnomaly);
|
|
|
+
|
|
|
+ windPowerLogicAnomaly = new AnomalyThermodynamicDiagramVO();
|
|
|
+ windPowerLogicAnomaly.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ windPowerLogicAnomaly.setIfAbnorma(anomalyModelPO.getSensorAnomalyWindPwr());
|
|
|
+ windPowerLogicAnomaly.setRatio(anomalyModelPO.getSensorAnomalyWindPwrRatio());
|
|
|
+ windPowerLogicAnomalyList.add(windPowerLogicAnomaly);
|
|
|
+
|
|
|
+ speedTorqueLogicAnomaly = new AnomalyThermodynamicDiagramVO();
|
|
|
+ speedTorqueLogicAnomaly.setEngineName(engineMap.get(anomalyModelPO.getEngineId()));
|
|
|
+ speedTorqueLogicAnomaly.setIfAbnorma(anomalyModelPO.getSensorAnomalySpeed());
|
|
|
+ speedTorqueLogicAnomaly.setRatio(anomalyModelPO.getSensorAnomalySpeedRatio());
|
|
|
+ speedTorqueLogicAnomalyList.add(speedTorqueLogicAnomaly);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put(AnomalySensorType.POWER_SENSOR.getFieldName(),powerSensorAnomalyList);
|
|
|
+ map.put(AnomalySensorType.WIND_SENSOR.getFieldName(),windSpeedSensorAnomalyList);
|
|
|
+ map.put(AnomalySensorType.PITCH_SENSOR.getFieldName(),pitchSensorAnomalyList);
|
|
|
+ map.put(AnomalySensorType.SPEED_SENSOR.getFieldName(),rotationSpeedSensorAnomalyList);
|
|
|
+ map.put(AnomalySensorType.TORQUE_SENSOR.getFieldName(),torqueSensorAnomalyList);
|
|
|
+ map.put(AnomalySensorType.WIND_POWER_LOGIC.getFieldName(),windPowerLogicAnomalyList);
|
|
|
+ map.put(AnomalySensorType.SPEED_TORQUE_LOGIC.getFieldName(),speedTorqueLogicAnomalyList);
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取变桨模块异常趋势(支持年度分表+跨年跨表)
|
|
|
+ * @param anomalyModelDTO 7/30天
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<AnomalyDailyVO> getPitchAnomalyTrend(AnomalyModelDTO anomalyModelDTO) {
|
|
|
+
|
|
|
+ // 1. 计算日期范围(自动跨年)
|
|
|
+ LocalDate endDate = LocalDate.parse(anomalyModelDTO.getDatatime());
|
|
|
+ LocalDate startDate = endDate.minusDays(anomalyModelDTO.getTimeRange() - 1);
|
|
|
+
|
|
|
+ // 2. 自动查询:单表 / 跨表
|
|
|
+ List<AnomalyDailyVO> dbData = getUnionAnomalyData(startDate, endDate,anomalyModelDTO);
|
|
|
+
|
|
|
+ // 3. 补全缺失日期(图表无断层)
|
|
|
+ List<AnomalyDailyVO> fullData = fillMissingDate(startDate, endDate, dbData);
|
|
|
+
|
|
|
+ return fullData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AnomalySensorCountVO getAnomalySensorCount(AnomalyDTO anomalyDTO) {
|
|
|
+
|
|
|
+ String fieldId = null;
|
|
|
+ WindFieldPO windFieldPO = getWindField(anomalyDTO.getFieldCode());
|
|
|
+ if (windFieldPO != null) {
|
|
|
+ fieldId = windFieldPO.getFieldId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fieldId == null) {
|
|
|
+ log.warn(" 健康检测大唐内部风场编号没有对应台账fieldId ");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ String beginTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ if (!StringUtils.isEmpty(anomalyDTO.getDatatime())) {
|
|
|
+ beginTime = appendTimeToString(anomalyDTO.getDatatime(), 00, 00, 00);
|
|
|
+ endTime = appendTimeToString(anomalyDTO.getDatatime(), 23, 59, 59);
|
|
|
+ } else {
|
|
|
+ beginTime = getYesterdayStartStr();
|
|
|
+ endTime = getYesterdayEnd().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+ String year = String.valueOf(LocalDate.now().getYear());
|
|
|
+
|
|
|
+ AnomalySensorCountVO anomalySensorCountVO = anomalyWindfarmMapper.selectAnomalySensorCountVO(fieldId,year,beginTime,endTime);
|
|
|
+
|
|
|
+ return anomalySensorCountVO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AnomalyCount getAnomalyModelCount(AnomalyDTO anomalyDTO) {
|
|
|
+
|
|
|
+ String fieldId = null;
|
|
|
+ WindFieldPO windFieldPO = getWindField(anomalyDTO.getFieldCode());
|
|
|
+ if (windFieldPO != null) {
|
|
|
+ fieldId = windFieldPO.getFieldId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fieldId == null) {
|
|
|
+ log.warn(" 健康检测大唐内部风场编号没有对应台账fieldId ");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ String beginTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ if (!StringUtils.isEmpty(anomalyDTO.getDatatime())) {
|
|
|
+ beginTime = appendTimeToString(anomalyDTO.getDatatime(), 00, 00, 00);
|
|
|
+ endTime = appendTimeToString(anomalyDTO.getDatatime(), 23, 59, 59);
|
|
|
+ } else {
|
|
|
+ beginTime = getYesterdayStartStr();
|
|
|
+ endTime = getYesterdayEnd().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+ String year = String.valueOf(LocalDate.now().getYear());
|
|
|
+
|
|
|
+ AnomalyCount anomalyCount = anomalyWindfarmMapper.selectModeCount(fieldId,year,beginTime,endTime);
|
|
|
+
|
|
|
+ return anomalyCount;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 核心:自动判断 单表/跨表 查询
|
|
|
+ */
|
|
|
+ private List<AnomalyDailyVO> getUnionAnomalyData(LocalDate start, LocalDate end, AnomalyModelDTO anomalyModelDTO) {
|
|
|
+ int startYear = start.getYear();
|
|
|
+ int endYear = end.getYear();
|
|
|
+
|
|
|
+ // 场景1:同一年 → 查询单张分表
|
|
|
+ if (startYear == endYear) {
|
|
|
+ String tableName = TABLE_PREFIX + startYear;
|
|
|
+ return anomalyWindfarmMapper.selectBySingleTable(anomalyModelDTO.getFieldId(),anomalyModelDTO.getEngineId(),
|
|
|
+ tableName, start.toString(), end.toString());
|
|
|
+ }
|
|
|
+ // 场景2:跨年份 → 查询两张分表(UNION ALL)
|
|
|
+ else {
|
|
|
+ String table1 = TABLE_PREFIX + startYear;
|
|
|
+ String table2 = TABLE_PREFIX + endYear;
|
|
|
+ return anomalyWindfarmMapper.selectByUnionTables(anomalyModelDTO.getFieldId(),anomalyModelDTO.getEngineId(),
|
|
|
+ table1,table2, start.toString(), end.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 补全无数据日期(赋值0)
|
|
|
+ */
|
|
|
+ private List<AnomalyDailyVO> fillMissingDate(LocalDate start, LocalDate end, List<AnomalyDailyVO> data) {
|
|
|
+ Map<Date, AnomalyDailyVO> dataMap = data.stream().collect(Collectors.toMap(AnomalyDailyVO::getCreateTime, dto -> dto));
|
|
|
+
|
|
|
+ List<AnomalyDailyVO> result = new ArrayList<>();
|
|
|
+
|
|
|
+ for (LocalDate date = start; !date.isAfter(end); date = date.plusDays(1)) {
|
|
|
+
|
|
|
+ result.add(dataMap.getOrDefault(Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()),
|
|
|
+ new AnomalyDailyVO(Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()),
|
|
|
+ new BigDecimal(0), new BigDecimal(0), new BigDecimal(0),new BigDecimal(0),new BigDecimal(0))));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 风速功率模块模块
|
|
|
+ * @param anomalyModelDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AnomalyWindpwrVO getAnomalyWindpwr(AnomalyModelDTO anomalyModelDTO){
|
|
|
+
|
|
|
+ String beginTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ if (!StringUtils.isEmpty(anomalyModelDTO.getDatatime())) {
|
|
|
+ beginTime = appendTimeToString(anomalyModelDTO.getDatatime(), 00, 00, 00);
|
|
|
+ endTime = appendTimeToString(anomalyModelDTO.getDatatime(), 23, 59, 59);
|
|
|
+ } else {
|
|
|
+ beginTime = getYesterdayStartStr();
|
|
|
+ endTime = getYesterdayEnd().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+ String year = String.valueOf(LocalDate.now().getYear());
|
|
|
+
|
|
|
+ // 清除当前
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ // 切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("slave");
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO powerPO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.POWER_CURVE.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyPowercurvePO anomalyPowercurvePO = new AnomalyPowercurvePO();
|
|
|
+ BeanUtil.copyProperties(powerPO,anomalyPowercurvePO);
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO scatterPO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.SCATTER.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyScatterPO anomalyScatterPO = new AnomalyScatterPO();
|
|
|
+ BeanUtil.copyProperties(scatterPO,anomalyScatterPO);
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO simulinkPO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.SIMULINK.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalySimulinkPO anomalySimulinkPO = new AnomalySimulinkPO();
|
|
|
+ BeanUtil.copyProperties(simulinkPO,anomalySimulinkPO);
|
|
|
+
|
|
|
+ AnomalyWindpwrVO anomalyWindpwrVO = new AnomalyWindpwrVO();
|
|
|
+ anomalyWindpwrVO.setAnomalyPowercurvePO(anomalyPowercurvePO);
|
|
|
+ anomalyWindpwrVO.setAnomalyScatterPO(anomalyScatterPO);
|
|
|
+ anomalyWindpwrVO.setAnomalySimulinkPO(anomalySimulinkPO);
|
|
|
+
|
|
|
+ return anomalyWindpwrVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 偏航模块模块
|
|
|
+ * @param anomalyModelDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AnomalyYawVO geAnomalyYaw(AnomalyModelDTO anomalyModelDTO){
|
|
|
+
|
|
|
+ String beginTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ if (!StringUtils.isEmpty(anomalyModelDTO.getDatatime())) {
|
|
|
+ beginTime = appendTimeToString(anomalyModelDTO.getDatatime(), 00, 00, 00);
|
|
|
+ endTime = appendTimeToString(anomalyModelDTO.getDatatime(), 23, 59, 59);
|
|
|
+ } else {
|
|
|
+ beginTime = getYesterdayStartStr();
|
|
|
+ endTime = getYesterdayEnd().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+ String year = String.valueOf(LocalDate.now().getYear());
|
|
|
+
|
|
|
+ // 清除当前
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ // 切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("slave");
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO staticyaw= anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.CABLE_TWIST.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyStaticyawPO anomalyStaticyawPO = new AnomalyStaticyawPO();
|
|
|
+ BeanUtil.copyProperties(staticyaw,anomalyStaticyawPO);
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO cabletwistPO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.STATIC_YAW.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyCabletwistPO anomalyCabletwistPO = new AnomalyCabletwistPO();
|
|
|
+ BeanUtil.copyProperties(cabletwistPO,anomalyCabletwistPO);
|
|
|
+
|
|
|
+ AnomalyYawVO anomalyYawVO = new AnomalyYawVO();
|
|
|
+ anomalyYawVO.setAnomalyStaticyawPO(anomalyStaticyawPO);
|
|
|
+ anomalyYawVO.setAnomalyCabletwistPO(anomalyCabletwistPO);
|
|
|
+
|
|
|
+ return anomalyYawVO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 变桨模块模块
|
|
|
+ * @param anomalyModelDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AnomalyPitchVO getAnomalyPitch(AnomalyModelDTO anomalyModelDTO){
|
|
|
+
|
|
|
+ String beginTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ if (!StringUtils.isEmpty(anomalyModelDTO.getDatatime())) {
|
|
|
+ beginTime = appendTimeToString(anomalyModelDTO.getDatatime(), 00, 00, 00);
|
|
|
+ endTime = appendTimeToString(anomalyModelDTO.getDatatime(), 23, 59, 59);
|
|
|
+ } else {
|
|
|
+ beginTime = getYesterdayStartStr();
|
|
|
+ endTime = getYesterdayEnd().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+ String year = String.valueOf(LocalDate.now().getYear());
|
|
|
+
|
|
|
+ // 清除当前
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ // 切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("slave");
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO pitchregulationPO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.PITCH_REGULATION.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyPitchregulationPO anomalyPitchregulationPO = new AnomalyPitchregulationPO();
|
|
|
+ BeanUtil.copyProperties(pitchregulationPO,anomalyPitchregulationPO);
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO pitchcoordPO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.PITCH_COORD.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyPitchcoordPO anomalyPitchcoordPO = new AnomalyPitchcoordPO();
|
|
|
+ BeanUtil.copyProperties(pitchcoordPO,anomalyPitchcoordPO);
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO minpitchPO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.MIN_PITCH.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyMinpitchPO anomalyMinpitchPO = new AnomalyMinpitchPO();
|
|
|
+ BeanUtil.copyProperties(minpitchPO,anomalyMinpitchPO);
|
|
|
+
|
|
|
+ AnomalyPitchVO anomalyPitchVO = new AnomalyPitchVO();
|
|
|
+ anomalyPitchVO.setAnomalyPitchregulationPO (anomalyPitchregulationPO);
|
|
|
+ anomalyPitchVO.setAnomalyPitchcoordPO(anomalyPitchcoordPO);
|
|
|
+ anomalyPitchVO.setAnomalyMinpitchPO(anomalyMinpitchPO);
|
|
|
+
|
|
|
+ return anomalyPitchVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运行状态模块模块
|
|
|
+ * @param anomalyModelDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AnomalyCtrlParamVO getAnomalyCtrlParam(AnomalyModelDTO anomalyModelDTO){
|
|
|
+
|
|
|
+ String beginTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ if (!StringUtils.isEmpty(anomalyModelDTO.getDatatime())) {
|
|
|
+ beginTime = appendTimeToString(anomalyModelDTO.getDatatime(), 00, 00, 00);
|
|
|
+ endTime = appendTimeToString(anomalyModelDTO.getDatatime(), 23, 59, 59);
|
|
|
+ } else {
|
|
|
+ beginTime = getYesterdayStartStr();
|
|
|
+ endTime = getYesterdayEnd().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+ String year = String.valueOf(LocalDate.now().getYear());
|
|
|
+
|
|
|
+ // 清除当前
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ // 切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("slave");
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO powerqualityPO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.POWER_QUALITY.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyPowerqualityPO anomalyPowerqualityPO = new AnomalyPowerqualityPO();
|
|
|
+ BeanUtil.copyProperties(powerqualityPO,anomalyPowerqualityPO);
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO operationPO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.OPERATION.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyOperationPO anomalyOperationPO = new AnomalyOperationPO();
|
|
|
+ BeanUtil.copyProperties(operationPO,anomalyOperationPO);
|
|
|
+
|
|
|
+ AnomalyCtrlParamVO anomalyCtrlParamVO = new AnomalyCtrlParamVO();
|
|
|
+ anomalyCtrlParamVO.setAnomalyPowerqualityPO (anomalyPowerqualityPO);
|
|
|
+ anomalyCtrlParamVO.setAnomalyOperationPO(anomalyOperationPO);
|
|
|
+
|
|
|
+ return anomalyCtrlParamVO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 气动性能
|
|
|
+ * @param anomalyModelDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AnomalyAerodynamicsVO getAerodynamics(AnomalyModelDTO anomalyModelDTO){
|
|
|
+
|
|
|
+ String beginTime = null;
|
|
|
+ String endTime = null;
|
|
|
+ if (!StringUtils.isEmpty(anomalyModelDTO.getDatatime())) {
|
|
|
+ beginTime = appendTimeToString(anomalyModelDTO.getDatatime(), 00, 00, 00);
|
|
|
+ endTime = appendTimeToString(anomalyModelDTO.getDatatime(), 23, 59, 59);
|
|
|
+ } else {
|
|
|
+ beginTime = getYesterdayStartStr();
|
|
|
+ endTime = getYesterdayEnd().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+ String year = String.valueOf(LocalDate.now().getYear());
|
|
|
+
|
|
|
+ // 清除当前
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ // 切换数据源
|
|
|
+ DynamicDataSourceContextHolder.push("slave");
|
|
|
+
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO anomalyCpBasePO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.CP_DETECTOR.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyCpPO anomalyCpPO = new AnomalyCpPO();
|
|
|
+ BeanUtil.copyProperties(anomalyCpBasePO,anomalyCpPO);
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO anomalyTsrBasePO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.TSR_DETECTOR.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyTsrPO anomalyTsrPO = new AnomalyTsrPO();
|
|
|
+ BeanUtil.copyProperties(anomalyTsrBasePO,anomalyTsrPO);
|
|
|
+
|
|
|
+ BaseAnomalyDetectorPO anomalyCpTsrBasePO = anomalyWindfarmMapper.selectAnomalyDetectorAll(anomalyModelDTO.getFieldId(),
|
|
|
+ DetectorTableEnum.CP_TSR_DETECTOR.getFullTableName(year),
|
|
|
+ anomalyModelDTO.getEngineId(),beginTime,endTime);
|
|
|
+ AnomalyCpTsrPO anomalyCpTsrPO = new AnomalyCpTsrPO();
|
|
|
+ BeanUtil.copyProperties(anomalyCpTsrBasePO,anomalyCpTsrPO);
|
|
|
+
|
|
|
+
|
|
|
+ AnomalyAerodynamicsVO anomalyAerodynamicsVO = new AnomalyAerodynamicsVO();
|
|
|
+ anomalyAerodynamicsVO.setAnomalyCpPO(anomalyCpPO);
|
|
|
+ anomalyAerodynamicsVO.setAnomalyCpTsrPO(anomalyCpTsrPO);
|
|
|
+ anomalyAerodynamicsVO.setAnomalyTsrPO(anomalyTsrPO);
|
|
|
+
|
|
|
+ return anomalyAerodynamicsVO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分隔符
|
|
|
+ * ==============================================================================================================================
|
|
|
+ */
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 给String类型的年月日拼接时分秒
|
|
|
+ *
|
|
|
+ * @param dateStr 年月日字符串(如 "2026-03-02")
|
|
|
+ * @param hour 小时
|
|
|
+ * @param minute 分钟
|
|
|
+ * @param second 秒
|
|
|
+ * @return 带时分秒的字符串(如 "2026-03-02 15:30:00")
|
|
|
+ */
|
|
|
+ private String appendTimeToString(String dateStr, int hour, int minute, int second) {
|
|
|
+ // 1. 解析为LocalDate(校验日期合法性)
|
|
|
+ LocalDate localDate = LocalDate.parse(dateStr, DATE_FORMATTER);
|
|
|
+ // 2. 拼接时分秒为LocalDateTime
|
|
|
+ LocalDateTime localDateTime = localDate.atTime(hour, minute, second);
|
|
|
+ // 3. 格式化为字符串
|
|
|
+ return localDateTime.format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重载:获取昨天开始/结束时间的字符串格式
|
|
|
+ */
|
|
|
+ private String getYesterdayStartStr() {
|
|
|
+ return getYesterdayStart().format(DATETIME_FORMATTER);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getYesterdayEndStr() {
|
|
|
+ // 严格格式化为 23:59:59(去掉纳秒)
|
|
|
+ return getYesterdayEnd().format(DATETIME_FORMATTER).substring(0, 19);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取昨天的开始时间(yyyy-MM-dd 00:00:00)
|
|
|
+ *
|
|
|
+ * @return LocalDateTime
|
|
|
+ */
|
|
|
+ private LocalDateTime getYesterdayStart() {
|
|
|
+ // 1. 获取昨天的日期
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
+ // 2. 拼接 00:00:00 等价于 yesterday.atTime(0, 0, 0)
|
|
|
+ return yesterday.atStartOfDay();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取昨天的结束时间(yyyy-MM-dd 23:59:59)
|
|
|
+ *
|
|
|
+ * @return LocalDateTime
|
|
|
+ */
|
|
|
+ private LocalDateTime getYesterdayEnd() {
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
+ // 拼接 23:59:59
|
|
|
+ return yesterday.atTime(23, 59, 59);
|
|
|
+ // 若需严格的23:59:59,用:yesterday.atTime(23, 59, 59)
|
|
|
+ }
|
|
|
+}
|