|
@@ -29,6 +29,9 @@ import org.springframework.stereotype.Service;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.format.DateTimeParseException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.IntStream;
|
|
@@ -36,7 +39,7 @@ import java.util.stream.IntStream;
|
|
|
/**
|
|
|
* @Description: 峰平谷模型
|
|
|
* @Author: jeecg-boot
|
|
|
- * @Date: 2024-10-31
|
|
|
+ * @Date: 2024-10-31
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
@Slf4j
|
|
@@ -57,15 +60,15 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
FpgLeanModelResult fpgLeanModelResult = new FpgLeanModelResult();
|
|
|
fpgLeanModelResult.setFpgLeanModelId(id);
|
|
|
FpgLeanModel fpgLeanModel = baseMapper.selectById(id);
|
|
|
- if (fpgLeanModel == null){
|
|
|
+ if (fpgLeanModel == null) {
|
|
|
return fpgLeanModelResult;
|
|
|
}
|
|
|
- if (oConvertUtils.isEmpty(fpgLeanModel.getDeviceInformationIds())){
|
|
|
+ if (oConvertUtils.isEmpty(fpgLeanModel.getDeviceInformationIds())) {
|
|
|
return fpgLeanModelResult;
|
|
|
}
|
|
|
List<String> deviceInformationIds = Arrays.asList(fpgLeanModel.getDeviceInformationIds().split(","));
|
|
|
List<DeviceInformation> deviceInformations = deviceInformationMapper.selectBatchIds(deviceInformationIds);
|
|
|
- if (!oConvertUtils.isNotEmpty(deviceInformations)){
|
|
|
+ if (!oConvertUtils.isNotEmpty(deviceInformations)) {
|
|
|
return fpgLeanModelResult;
|
|
|
}
|
|
|
fpgLeanModelResult.setDeviceInformationList(deviceInformations);
|
|
@@ -86,18 +89,18 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
|
|
|
// 执行查询
|
|
|
List<DeviceStatiscsModelMongodb> fpgStatiscsModelDataList = mongoTemplate.find(query, DeviceStatiscsModelMongodb.class, "total_startstop");
|
|
|
- if (oConvertUtils.listIsEmpty(fpgStatiscsModelDataList)){
|
|
|
+ if (oConvertUtils.listIsEmpty(fpgStatiscsModelDataList)) {
|
|
|
log.info("{}{}", "total_startstop峰平谷大屏查询设备模型历史记录-为空", query);
|
|
|
return leanModelDeviceHistoryInfoIPage;
|
|
|
}
|
|
|
|
|
|
List<LeanModelDeviceHistoryInfo> leanModelDeviceHistoryInfoList = new ArrayList<>();
|
|
|
- fpgStatiscsModelDataList.forEach(x ->{
|
|
|
+ fpgStatiscsModelDataList.forEach(x -> {
|
|
|
LeanModelDeviceHistoryInfo leanModelDeviceHistoryInfo = new LeanModelDeviceHistoryInfo();
|
|
|
BeanUtils.copyProperties(x, leanModelDeviceHistoryInfo);
|
|
|
leanModelDeviceHistoryInfoList.add(leanModelDeviceHistoryInfo);
|
|
|
});
|
|
|
- leanModelDeviceHistoryInfoList.forEach(y ->{
|
|
|
+ leanModelDeviceHistoryInfoList.forEach(y -> {
|
|
|
LambdaQueryWrapper<LeanEventWarnInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(LeanEventWarnInfo::getDeviceInformationId, y.getDeviceInformationId());
|
|
|
queryWrapper.between(LeanEventWarnInfo::getCreateTime, DateUtils.str2Date(y.getDeviceStartTime(), DateUtils.datetimeFormat.get()), DateUtils.str2Date(y.getDeviceStopTime(), DateUtils.datetimeFormat.get()));
|
|
@@ -132,16 +135,45 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
// calendar2.setTime(endTime);
|
|
|
// Date specifiedTimePlus8HoursStartEndTime = calendar2.getTime();
|
|
|
// query.addCriteria(Criteria.where("createTime").gte(specifiedTimePlus8HoursStartEndTime).lt(specifiedTimePlus8HoursStartTime));
|
|
|
+
|
|
|
+ // 获取当前时间和两天前的时间
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime twoDaysAgo = now.minusDays(2);
|
|
|
+
|
|
|
+ // 定义日期格式器,用于解析 datestr 字符串
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
// 执行查询
|
|
|
List<DeviceStatiscsModelMongodb> deviceStatiscsModelMongodbList = mongoTemplate.find(query, DeviceStatiscsModelMongodb.class, "leanmodel_run_realtime");
|
|
|
if (oConvertUtils.listIsEmpty(deviceStatiscsModelMongodbList)){
|
|
|
log.info("{}{}", "leanmodel_run_realtime折线图峰平谷大屏通过设备id查询实时功率和电流为空", deviceInformationId);
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
- return deviceStatiscsModelMongodbList;
|
|
|
+
|
|
|
+ // 使用 Stream 过滤出当前时间到两天前的数据
|
|
|
+ List<DeviceStatiscsModelMongodb> filteredList = deviceStatiscsModelMongodbList.stream()
|
|
|
+ .filter(item -> {
|
|
|
+ // 获取 datestr 并转换为 LocalDateTime
|
|
|
+ String dateStr = item.getDatestr(); // 假设 datestr 字段是 String 类型
|
|
|
+ try {
|
|
|
+ // 将 datestr 转换为 LocalDateTime
|
|
|
+ LocalDateTime createTime = LocalDateTime.parse(dateStr, formatter);
|
|
|
+
|
|
|
+ // 比较是否在当前时间和两天前时间之间
|
|
|
+ return !createTime.isBefore(twoDaysAgo) && !createTime.isAfter(now);
|
|
|
+ } catch (DateTimeParseException e) {
|
|
|
+ log.error("日期格式解析错误: {}", dateStr, e);
|
|
|
+ return false; // 如果解析失败,排除该记录
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return filteredList;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 龙钢峰平谷积木报表导出逻辑处理
|
|
|
+ *
|
|
|
* @param leanModelCode
|
|
|
* @return JSONObject
|
|
|
*/
|
|
@@ -150,7 +182,7 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
List<DeviceStatiscsModelMongodb> fpgStatiscsModelDataList = queryByTimeRanges(mongoTemplate, leanModelCode, null, null, null, null, null);
|
|
|
- if (oConvertUtils.listIsEmpty(fpgStatiscsModelDataList)){
|
|
|
+ if (oConvertUtils.listIsEmpty(fpgStatiscsModelDataList)) {
|
|
|
log.info("{}{}", "mongo数据查询为空,峰平谷报表导出失败!", leanModelCode);
|
|
|
result.put("data", new JSONArray());
|
|
|
return result;
|
|
@@ -180,20 +212,20 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
return null;
|
|
|
}).filter(x -> x != null).collect(Collectors.toList());
|
|
|
JSONArray jsonResult = new JSONArray();
|
|
|
- if ("total_day_eu_report".equals(leanModelCode)){
|
|
|
+ if ("total_day_eu_report".equals(leanModelCode)) {
|
|
|
// 总用电量报表
|
|
|
List<ModelDataResult> modelDataResults = generateModelDataResults(combinedList);
|
|
|
jsonResult = JSON.parseArray(JSON.toJSONString(modelDataResults));
|
|
|
} else if ("total_day_ec_report".equals(leanModelCode)) {
|
|
|
// 峰平谷用电控制日报报表
|
|
|
jsonResult = JSON.parseArray(JSON.toJSONString(combinedList));
|
|
|
- }else if ("total_day_dn_report".equals(leanModelCode)) {
|
|
|
+ } else if ("total_day_dn_report".equals(leanModelCode)) {
|
|
|
// 线路峰平谷日报
|
|
|
jsonResult = JSON.parseArray(JSON.toJSONString(combinedList));
|
|
|
- }else if ("total_day_ds_report".equals(leanModelCode)) {
|
|
|
+ } else if ("total_day_ds_report".equals(leanModelCode)) {
|
|
|
// 谷峰差统计报表
|
|
|
jsonResult = JSON.parseArray(JSON.toJSONString(combinedList));
|
|
|
- }else if ("total_day_wp_report".equals(leanModelCode)) {
|
|
|
+ } else if ("total_day_wp_report".equals(leanModelCode)) {
|
|
|
|
|
|
// 龙钢变各工序报表
|
|
|
List<ModelDataResult> modelDataResults = new ArrayList<>();
|
|
@@ -208,47 +240,47 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
String createTime = modelReportFormResult.getCreateTime();
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
ModelDataResult modelDataResult = new ModelDataResult();
|
|
|
- if (i == 0){
|
|
|
+ if (i == 0) {
|
|
|
modelDataResult.setKey("尖");
|
|
|
modelDataResult.setKey1("尖");
|
|
|
modelDataResult.setValue(modelReportFormResult.getTopsPower());
|
|
|
}
|
|
|
- if (i == 1){
|
|
|
+ if (i == 1) {
|
|
|
modelDataResult.setKey("尖");
|
|
|
modelDataResult.setKey1("尖(%)");
|
|
|
modelDataResult.setValue(modelReportFormResult.getTopsPower().divide(sum, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
}
|
|
|
- if (i == 2){
|
|
|
+ if (i == 2) {
|
|
|
modelDataResult.setKey("峰");
|
|
|
modelDataResult.setKey1("峰");
|
|
|
modelDataResult.setValue(modelReportFormResult.getPeaksPower());
|
|
|
}
|
|
|
- if (i == 3){
|
|
|
+ if (i == 3) {
|
|
|
modelDataResult.setKey("峰");
|
|
|
modelDataResult.setKey1("峰(%)");
|
|
|
modelDataResult.setValue(modelReportFormResult.getPeaksPower().divide(sum, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
}
|
|
|
- if (i == 4){
|
|
|
+ if (i == 4) {
|
|
|
modelDataResult.setKey("平");
|
|
|
modelDataResult.setKey1("平");
|
|
|
modelDataResult.setValue(modelReportFormResult.getFlatPower());
|
|
|
}
|
|
|
- if (i == 5){
|
|
|
+ if (i == 5) {
|
|
|
modelDataResult.setKey("平");
|
|
|
modelDataResult.setKey1("平(%)");
|
|
|
modelDataResult.setValue(modelReportFormResult.getFlatPower().divide(sum, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
}
|
|
|
- if (i == 6){
|
|
|
+ if (i == 6) {
|
|
|
modelDataResult.setKey("谷");
|
|
|
modelDataResult.setKey1("谷");
|
|
|
modelDataResult.setValue(modelReportFormResult.getValleysPower());
|
|
|
}
|
|
|
- if (i == 7){
|
|
|
+ if (i == 7) {
|
|
|
modelDataResult.setKey("谷");
|
|
|
modelDataResult.setKey1("谷(%)");
|
|
|
modelDataResult.setValue(modelReportFormResult.getValleysPower().add(modelReportFormResult.getPeaksPower()).add(modelReportFormResult.getFlatPower()).add(modelReportFormResult.getValleysPower()));
|
|
|
}
|
|
|
- if (i == 8){
|
|
|
+ if (i == 8) {
|
|
|
modelDataResult.setKey("反有总");
|
|
|
modelDataResult.setKey1("反有总");
|
|
|
modelDataResult.setValue(modelReportFormResult.getTopsPower().add(modelReportFormResult.getPeaksPower()).add(modelReportFormResult.getFlatPower()).add(modelReportFormResult.getValleysPower()));
|
|
@@ -269,28 +301,29 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
|
|
|
/**
|
|
|
* 基于模型编码、采集点ID、设备ID、区域ID、峰平谷配置时间范围 动态查询mongoDB
|
|
|
+ *
|
|
|
* @param mongoTemplate
|
|
|
* @param devicePointId
|
|
|
* @param deviceInformationId
|
|
|
* @param deviceRegionId
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<DeviceStatiscsModelMongodb> queryByTimeRanges(MongoTemplate mongoTemplate, String leanModeCode, String startTimeParam, String endTimeParam, String devicePointId, String deviceInformationId, String deviceRegionId) {
|
|
|
+ public List<DeviceStatiscsModelMongodb> queryByTimeRanges(MongoTemplate mongoTemplate, String leanModeCode, String startTimeParam, String endTimeParam, String devicePointId, String deviceInformationId, String deviceRegionId) {
|
|
|
Query query = new Query();
|
|
|
query.with(Sort.by(Sort.Direction.ASC, "createTime"));
|
|
|
- if (oConvertUtils.isNotEmpty(devicePointId)){
|
|
|
+ if (oConvertUtils.isNotEmpty(devicePointId)) {
|
|
|
// 设备采集点
|
|
|
query.addCriteria(Criteria.where("devicePointId").is(devicePointId));
|
|
|
}
|
|
|
- if (oConvertUtils.isNotEmpty(devicePointId)){
|
|
|
+ if (oConvertUtils.isNotEmpty(devicePointId)) {
|
|
|
// 虚拟设备
|
|
|
query.addCriteria(Criteria.where("deviceInformationId").is(deviceInformationId));
|
|
|
}
|
|
|
- if (oConvertUtils.isNotEmpty(devicePointId)){
|
|
|
+ if (oConvertUtils.isNotEmpty(devicePointId)) {
|
|
|
// 虚拟设备区域
|
|
|
query.addCriteria(Criteria.where("deviceRegionId").is(deviceRegionId));
|
|
|
}
|
|
|
- if (oConvertUtils.isNotEmpty(startTimeParam) && oConvertUtils.isNotEmpty(endTimeParam)){
|
|
|
+ if (oConvertUtils.isNotEmpty(startTimeParam) && oConvertUtils.isNotEmpty(endTimeParam)) {
|
|
|
// 使用Criteria添加多个时间范围条件
|
|
|
// DateUtils.date2Str(startTime, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")) 毫秒
|
|
|
Date startTime = DateUtils.str2Date(startTimeParam, DateUtils.datetimeFormat.get());
|
|
@@ -312,6 +345,7 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
|
|
|
/**
|
|
|
* 转为流处理模型数据、5次循环操作
|
|
|
+ *
|
|
|
* @param combinedList
|
|
|
* @return
|
|
|
*/
|
|
@@ -327,7 +361,8 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 不同类型的key/value进行赋值操作
|
|
|
+ * 不同类型的key/value进行赋值操作
|
|
|
+ *
|
|
|
* @param modelDataResult
|
|
|
* @param i
|
|
|
* @param modelReportFormResult
|
|
@@ -362,6 +397,7 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
|
|
|
/**
|
|
|
* 公共属性赋值
|
|
|
+ *
|
|
|
* @param modelDataResult
|
|
|
* @param modelReportFormResult
|
|
|
*/
|