|
@@ -1,5 +1,8 @@
|
|
|
package org.jeecg.modules.leanEventWarn.service.impl;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.modules.common.enums.EDeviceInformationType;
|
|
|
import org.jeecg.modules.events.entity.LeanEventsHost;
|
|
|
import org.jeecg.modules.gatherData.entity.FpgStatiscsModelMongodb;
|
|
@@ -23,6 +26,7 @@ import org.springframework.data.mongodb.core.query.Query;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
@@ -32,10 +36,7 @@ import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -44,6 +45,7 @@ import java.util.stream.Collectors;
|
|
|
* @Date: 2024-10-29
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoMapper, LeanEventWarnInfo> implements ILeanEventWarnInfoService {
|
|
|
|
|
@@ -60,6 +62,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
ISystemVariableService systemVariableService;
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void openDeviceTriggerWarnInfo(FpgGatherData fpgGatherData) {
|
|
|
LeanEventWarnInfo leanEventWarnInfo = new LeanEventWarnInfo();
|
|
|
leanEventWarnInfo.setDeviceRegionId(fpgGatherData.getDeviceRegionId());
|
|
@@ -73,6 +76,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
queryWrapper.eq("status", 0);
|
|
|
SystemVariable systemVariable = systemVariableService.getOne(queryWrapper);
|
|
|
if (systemVariable == null){
|
|
|
+ log.info("{}{}", "host_open系统变量未配置正常状态的运行电流限制!", JSON.toJSON(fpgGatherData));
|
|
|
return;
|
|
|
}
|
|
|
BigDecimal limitCurrent = new BigDecimal(systemVariable.getDefaultValue());
|
|
@@ -88,6 +92,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void stopDeviceTriggerWarnInfo(FpgGatherData fpgGatherData) {
|
|
|
LeanEventWarnInfo leanEventWarnInfo = new LeanEventWarnInfo();
|
|
|
leanEventWarnInfo.setDeviceRegionId(fpgGatherData.getDeviceRegionId());
|
|
@@ -100,6 +105,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
queryWrapper.eq("status", 0);
|
|
|
SystemVariable systemVariable = systemVariableService.getOne(queryWrapper);
|
|
|
if (systemVariable == null){
|
|
|
+ log.info("{}{}", "host_stop系统变量未配置正常状态的运行电流限制!", JSON.toJSON(fpgGatherData));
|
|
|
return;
|
|
|
}
|
|
|
BigDecimal limitCurrent = new BigDecimal(systemVariable.getDefaultValue());
|
|
@@ -114,6 +120,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void openFpgTriggerWarnInfo(FpgGatherData fpgGatherData) {
|
|
|
LeanEventWarnInfo leanEventWarnInfo = new LeanEventWarnInfo();
|
|
|
leanEventWarnInfo.setDeviceRegionId(fpgGatherData.getDeviceRegionId());
|
|
@@ -135,6 +142,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
queryWrapper.eq("status", 0);
|
|
|
SystemVariable systemVariable = systemVariableService.getOne(queryWrapper);
|
|
|
if (systemVariable == null){
|
|
|
+ log.info("{}{}", "fpg_open系统变量未配置正常状态的运行电流限制!", JSON.toJSON(fpgGatherData));
|
|
|
return;
|
|
|
}
|
|
|
BigDecimal limitCurrent = new BigDecimal(systemVariable.getDefaultValue());
|
|
@@ -202,6 +210,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void closeFpgTriggerWarnInfo(FpgGatherData fpgGatherData) {
|
|
|
LeanEventWarnInfo leanEventWarnInfo = new LeanEventWarnInfo();
|
|
|
leanEventWarnInfo.setDeviceRegionId(fpgGatherData.getDeviceRegionId());
|
|
@@ -225,6 +234,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
queryWrapper.eq("status", 0);
|
|
|
SystemVariable systemVariable = systemVariableService.getOne(queryWrapper);
|
|
|
if (systemVariable == null){
|
|
|
+ log.info("{}{}", "fpg_close系统变量未配置正常状态的运行电流限制!", JSON.toJSON(fpgGatherData));
|
|
|
return;
|
|
|
}
|
|
|
BigDecimal limitCurrent = new BigDecimal(systemVariable.getDefaultValue());
|
|
@@ -270,6 +280,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void runTimeTriggerWarnInfo(FpgGatherData fpgGatherData, LeanEventsHost leanEventsHost) {
|
|
|
LeanEventWarnInfo leanEventWarnInfo = new LeanEventWarnInfo();
|
|
|
leanEventWarnInfo.setDeviceRegionId(fpgGatherData.getDeviceRegionId());
|
|
@@ -283,6 +294,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
.eq(LeanEventsHostConfig::getEventsId, leanEventsHost.getEventsId()).eq(LeanEventsHostConfig::getLimitType, "0");
|
|
|
LeanEventsHostConfig leanEventsHostConfig = leanEventsHostConfigService.list(queryWrapper).stream().findFirst().orElse(null);
|
|
|
if (leanEventsHostConfig == null){
|
|
|
+ log.info("{}{}", "fpg_ing_time精益事件配置关联表查询为空!", "设备ID:" +fpgGatherData.getDeviceInformationId() + "事件ID:" + leanEventsHost.getEventsId());
|
|
|
return;
|
|
|
}
|
|
|
// 获取峰平谷配置的时段
|
|
@@ -301,6 +313,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
// 根据类型、采集点ID、设备ID、区域ID、峰平谷配置时间范围查询mongoDB
|
|
|
List<FpgStatiscsModelMongodb> fpgStatiscsModelDataList = queryByTimeRanges(mongoTemplate, timeRanges, fpgGatherData.getDevicePointId(), fpgGatherData.getDeviceInformationId(), fpgGatherData.getDeviceRegionId());
|
|
|
if (oConvertUtils.listIsEmpty(fpgStatiscsModelDataList) ){
|
|
|
+ log.info("{}{}", "fpg_ing_time峰平谷数据采集FpgStatiscsModelMongodb查询为空!", "设备ID:" +fpgGatherData.getDeviceInformationId() + "采集点ID:" + fpgGatherData.getDevicePointId()+ "区域ID:" + fpgGatherData.getDevicePointId());
|
|
|
return;
|
|
|
}
|
|
|
// 判断MongoDB中的累加运行时长是否大于 LeanEventsHostConfig中的尖峰平谷运行限制时长
|
|
@@ -353,6 +366,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void powerLimitTriggerWarnInfo(FpgGatherData fpgGatherData, LeanEventsHost leanEventsHost) {
|
|
|
LeanEventWarnInfo leanEventWarnInfo = new LeanEventWarnInfo();
|
|
|
leanEventWarnInfo.setDeviceRegionId(fpgGatherData.getDeviceRegionId());
|
|
@@ -366,6 +380,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
.eq(LeanEventsHostConfig::getEventsId, leanEventsHost.getEventsId()).eq(LeanEventsHostConfig::getLimitType, "1");
|
|
|
LeanEventsHostConfig leanEventsHostConfig = leanEventsHostConfigService.list(queryWrapper).stream().findFirst().orElse(null);
|
|
|
if (leanEventsHostConfig == null){
|
|
|
+ log.info("{}{}", "fpg_power_limit精益事件配置关联表查询为空!", "设备ID:" +fpgGatherData.getDeviceInformationId() + "事件ID:" + leanEventsHost.getEventsId());
|
|
|
return;
|
|
|
}
|
|
|
// 获取峰平谷配置的时段
|
|
@@ -384,6 +399,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
// 根据类型、采集点ID、设备ID、区域ID、峰平谷配置时间范围查询mongoDB
|
|
|
List<FpgStatiscsModelMongodb> fpgStatiscsModelDataList = queryByTimeRanges(mongoTemplate, timeRanges, fpgGatherData.getDevicePointId(), fpgGatherData.getDeviceInformationId(), fpgGatherData.getDeviceRegionId());
|
|
|
if (oConvertUtils.listIsEmpty(fpgStatiscsModelDataList) ){
|
|
|
+ log.info("{}{}", "fpg_power_limit峰平谷数据采集FpgStatiscsModelMongodb查询为空!", "设备ID:" +fpgGatherData.getDeviceInformationId() + "采集点ID:" + fpgGatherData.getDevicePointId()+ "区域ID:" + fpgGatherData.getDevicePointId());
|
|
|
return;
|
|
|
}
|
|
|
// 判断MongoDB中的累加运行时长是否大于 LeanEventsHostConfig中的尖峰平谷运行限制时长
|
|
@@ -446,29 +462,25 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
|
|
|
*/
|
|
|
public List<FpgStatiscsModelMongodb> queryByTimeRanges(MongoTemplate mongoTemplate, List<Date[]> timeRanges, String devicePointId, String deviceInformationId, String deviceRegionId) {
|
|
|
Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("devicePointId").is(devicePointId));
|
|
|
+ String devicePointIds = Arrays.stream(devicePointId.split(",")).collect(Collectors.joining("|"));
|
|
|
+ // 设置devicePointId的查询条件,使用正则表达式
|
|
|
+ query.addCriteria(Criteria.where("devicePointId").regex(devicePointIds));
|
|
|
query.addCriteria(Criteria.where("deviceInformationId").is(deviceInformationId));
|
|
|
query.addCriteria(Criteria.where("deviceRegionId").is(deviceRegionId));
|
|
|
// 使用Criteria添加多个时间范围条件
|
|
|
for (int i = 0; i < timeRanges.size(); i++) {
|
|
|
Date startTime = timeRanges.get(i)[0];
|
|
|
- // 加8小时
|
|
|
- Calendar calendar1 = Calendar.getInstance();
|
|
|
- calendar1.setTime(startTime);
|
|
|
- calendar1.add(Calendar.HOUR, 8);
|
|
|
- Date specifiedTimePlus8HoursStartTime = calendar1.getTime();
|
|
|
Date endTime = timeRanges.get(i)[1];
|
|
|
- Calendar calendar2 = Calendar.getInstance();
|
|
|
- calendar2.setTime(endTime);
|
|
|
- calendar2.add(Calendar.HOUR, 8);
|
|
|
- Date specifiedTimePlus8HoursStartEndTime = calendar2.getTime();
|
|
|
+ // 加8小时
|
|
|
+ Date specifiedTimePlus8HoursStartTime = DateUtils.addHours(startTime, 8);
|
|
|
+ Date specifiedTimePlus8HoursStartEndTime = DateUtils.addHours(endTime, 8);
|
|
|
query.addCriteria(Criteria.where("createTime").gte(specifiedTimePlus8HoursStartTime).lt(specifiedTimePlus8HoursStartEndTime));
|
|
|
}
|
|
|
+ log.info("{}{}", "查询FpgStatiscsModelMongodb模型参数:", query);
|
|
|
// 执行查询
|
|
|
List<FpgStatiscsModelMongodb> fpgStatiscsModelDataList = mongoTemplate.find(query, FpgStatiscsModelMongodb.class, "leanmodel_run_power_current_minute");
|
|
|
return fpgStatiscsModelDataList;
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 处理峰平谷的配置,并拼接开始时间和结束时间
|
|
|
* @param peaksAndValleysTimeConfigParam
|