|
@@ -1,5 +1,7 @@
|
|
|
package org.jeecg.modules.fpgJob;
|
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -38,7 +40,6 @@ import java.time.*;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
@@ -47,6 +48,8 @@ import java.util.stream.Collectors;
|
|
|
@EnableScheduling
|
|
|
public class LeanModelStatistics {
|
|
|
|
|
|
+ private static final String WEBHOOK_URL = "https://oapi.dingtalk.com/robot/send?access_token=11065895a52e659bc789a84ae9a81483e2eb9f02c4611ceacb9865f4e51fa2df";
|
|
|
+
|
|
|
@Autowired
|
|
|
IFpgLeanModelService fpgLeanModelService;
|
|
|
|
|
@@ -77,18 +80,18 @@ public class LeanModelStatistics {
|
|
|
*/
|
|
|
|
|
|
@Scheduled(fixedDelay = 2000 * 60)
|
|
|
- public void t1(){
|
|
|
+ public void t1() {
|
|
|
leanModel();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 变更占比
|
|
|
- * 0 0 03 * * * 每日3点执行 测试期间1ms一次
|
|
|
+ * 0 0 03 * * * 每日3点执行 测试期间1ms一次
|
|
|
*/
|
|
|
@Async
|
|
|
@Scheduled(cron = "0 0 03 * * *")
|
|
|
// @Scheduled(fixedDelay = 1000)
|
|
|
- public void t2(){
|
|
|
+ public void t2() {
|
|
|
changeProportion();
|
|
|
}
|
|
|
|
|
@@ -97,49 +100,84 @@ public class LeanModelStatistics {
|
|
|
*/
|
|
|
|
|
|
@Scheduled(fixedDelay = 1000 * 60)
|
|
|
- public void t3(){
|
|
|
+ public void t3() {
|
|
|
deviceStatistics();
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void changeProportion(){
|
|
|
+ public void changeProportion() {
|
|
|
log.info("变更占比");
|
|
|
- // 峰平谷精益模型配置获取
|
|
|
- LambdaQueryWrapper<FpgLeanModel> leanmodelQuery = new LambdaQueryWrapper<FpgLeanModel>().eq(FpgLeanModel::getStatus, "1");
|
|
|
- List<FpgLeanModel> fpgLeanModellist = fpgLeanModelService.list(leanmodelQuery);
|
|
|
- LocalDate yesterday = LocalDate.now().minusDays(1); // 获取今天的日期 减去一天,得到昨天的日期
|
|
|
- // 处理数据业务逻辑
|
|
|
- fpgLeanModellist.forEach(fpgLeanModeInfo -> {
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("proportion").is(1))
|
|
|
- .addCriteria(Criteria.where("dates").is(yesterday.toString()));
|
|
|
- List<FpgStatiscsModelMongodb> fpgStatiscsModelMongoList = mongoTemplate.find(query, FpgStatiscsModelMongodb.class, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
|
|
|
- BigDecimal zb = new BigDecimal("100");
|
|
|
- fpgStatiscsModelMongoList.forEach(fpgStatiscsModelMongoInfo -> { // 循环处理采集数据处理
|
|
|
- BigDecimal proportion = fpgStatiscsModelMongoInfo.getPower();
|
|
|
- BigDecimal topsProportion = fpgStatiscsModelMongoInfo.getTopsPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongoInfo.getTopsPower();
|
|
|
- BigDecimal peaksProportion = fpgStatiscsModelMongoInfo.getPeaksPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongoInfo.getPeaksPower();
|
|
|
- BigDecimal flatProportion = fpgStatiscsModelMongoInfo.getFlatPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongoInfo.getPeaksPower();
|
|
|
- BigDecimal valleysProportion = fpgStatiscsModelMongoInfo.getValleysPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongoInfo.getPeaksPower();
|
|
|
- // 核算占比
|
|
|
- UpdateDefinition update = new Update();
|
|
|
- ((Update) update).set("proportion", 2);
|
|
|
- if(topsProportion.compareTo(new BigDecimal("0.00")) > 0) { // 尖
|
|
|
- ((Update) update).set("topsProportion", topsProportion.divide(proportion, 4, RoundingMode.HALF_UP).multiply(zb));
|
|
|
- }
|
|
|
- if(peaksProportion.compareTo(new BigDecimal("0.00")) > 0) { // 峰
|
|
|
- ((Update) update).set("peaksProportion", peaksProportion.divide(proportion, 4, RoundingMode.HALF_UP).multiply(zb));
|
|
|
- }
|
|
|
- if(flatProportion.compareTo(new BigDecimal("0.00")) > 0) { // 平
|
|
|
- ((Update) update).set("flatProportion", flatProportion.divide(proportion, 4, RoundingMode.HALF_UP).multiply(zb));
|
|
|
- }
|
|
|
- if(valleysProportion.compareTo(new BigDecimal("0.00")) > 0) { // 谷
|
|
|
- ((Update) update).set("valleysProportion", valleysProportion.divide(proportion, 4, RoundingMode.HALF_UP).multiply(zb));
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 峰平谷精益模型配置获取
|
|
|
+ LambdaQueryWrapper<FpgLeanModel> leanmodelQuery = new LambdaQueryWrapper<FpgLeanModel>().eq(FpgLeanModel::getStatus, "1");
|
|
|
+ List<FpgLeanModel> fpgLeanModellist = fpgLeanModelService.list(leanmodelQuery);
|
|
|
+ LocalDate yesterday = LocalDate.now().minusDays(1); // 获取今天的日期 减去一天,得到昨天的日期
|
|
|
+ // 处理数据业务逻辑
|
|
|
+ fpgLeanModellist.forEach(fpgLeanModeInfo -> {
|
|
|
+ try {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("proportion").is(1))
|
|
|
+ .addCriteria(Criteria.where("dates").is(yesterday.toString()));
|
|
|
+ List<FpgStatiscsModelMongodb> fpgStatiscsModelMongoList = mongoTemplate.find(query, FpgStatiscsModelMongodb.class, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
|
|
|
+ BigDecimal zb = new BigDecimal("100");
|
|
|
+ fpgStatiscsModelMongoList.forEach(fpgStatiscsModelMongoInfo -> { // 循环处理采集数据处理
|
|
|
+ try {
|
|
|
+ BigDecimal proportion = fpgStatiscsModelMongoInfo.getPower();
|
|
|
+ BigDecimal topsProportion = fpgStatiscsModelMongoInfo.getTopsPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongoInfo.getTopsPower();
|
|
|
+ BigDecimal peaksProportion = fpgStatiscsModelMongoInfo.getPeaksPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongoInfo.getPeaksPower();
|
|
|
+ BigDecimal flatProportion = fpgStatiscsModelMongoInfo.getFlatPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongoInfo.getPeaksPower();
|
|
|
+ BigDecimal valleysProportion = fpgStatiscsModelMongoInfo.getValleysPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongoInfo.getPeaksPower();
|
|
|
+ // 核算占比
|
|
|
+ UpdateDefinition update = new Update();
|
|
|
+ ((Update) update).set("proportion", 2);
|
|
|
+ if (topsProportion.compareTo(new BigDecimal("0.00")) > 0) { // 尖
|
|
|
+ ((Update) update).set("topsProportion", topsProportion.divide(proportion, 4, RoundingMode.HALF_UP).multiply(zb));
|
|
|
+ }
|
|
|
+ if (peaksProportion.compareTo(new BigDecimal("0.00")) > 0) { // 峰
|
|
|
+ ((Update) update).set("peaksProportion", peaksProportion.divide(proportion, 4, RoundingMode.HALF_UP).multiply(zb));
|
|
|
+ }
|
|
|
+ if (flatProportion.compareTo(new BigDecimal("0.00")) > 0) { // 平
|
|
|
+ ((Update) update).set("flatProportion", flatProportion.divide(proportion, 4, RoundingMode.HALF_UP).multiply(zb));
|
|
|
+ }
|
|
|
+ if (valleysProportion.compareTo(new BigDecimal("0.00")) > 0) { // 谷
|
|
|
+ ((Update) update).set("valleysProportion", valleysProportion.divide(proportion, 4, RoundingMode.HALF_UP).multiply(zb));
|
|
|
+ }
|
|
|
+ // 保存
|
|
|
+ mongoTemplate.updateFirst(query, update, FpgStatiscsModelMongodb.class, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("处理统计数据异常,模型代码: {}, 统计ID: {}, 错误: {}",
|
|
|
+ fpgLeanModeInfo.getLeanModelCode(), fpgStatiscsModelMongoInfo.get_id(), e.getMessage(), e);
|
|
|
+ String errorMessage = String.format("【告警】峰平谷MongoDB 统计数据处理异常!\n" +
|
|
|
+ "**模型代码**: %s\n" +
|
|
|
+ "**统计ID**: %s\n" +
|
|
|
+ "**错误信息**: %s\n",
|
|
|
+ fpgLeanModeInfo.getLeanModelCode(),
|
|
|
+ fpgStatiscsModelMongoInfo.get_id(),
|
|
|
+ e.getMessage());
|
|
|
+ sendDingMessage(errorMessage);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询 MongoDB 统计数据异常,模型代码: {}, 错误: {}", fpgLeanModeInfo.getLeanModelCode(), e.getMessage(), e);
|
|
|
+ String errorMessage = String.format("【告警】峰平谷MongoDB 查询统计数据异常!\n" +
|
|
|
+ "**模型代码**: %s\n" +
|
|
|
+ "**错误信息**: %s\n",
|
|
|
+ fpgLeanModeInfo.getLeanModelCode(),
|
|
|
+ e.getMessage());
|
|
|
+ sendDingMessage(errorMessage);
|
|
|
}
|
|
|
- // 保存
|
|
|
- mongoTemplate.updateFirst(query, update, FpgStatiscsModelMongodb.class, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
|
|
|
});
|
|
|
- });
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("变更占比任务异常,错误: {}", e.getMessage(), e);
|
|
|
+ String errorMessage = String.format("【告警】峰平谷变更占比任务异常!\n" +
|
|
|
+ "**错误信息**: %s\n",
|
|
|
+ e.getMessage());
|
|
|
+ sendDingMessage(errorMessage);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 设备启停统计数据
|
|
@@ -153,12 +191,12 @@ public class LeanModelStatistics {
|
|
|
LambdaQueryWrapper<DeviceInformation> objectLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
List<DeviceInformation> deviceInformationllist = deviceInformationService.list(objectLambdaQueryWrapper);
|
|
|
// 尖峰平谷时段配置
|
|
|
- List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
|
|
|
+ List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
|
|
|
BigDecimal zb = new BigDecimal("100");
|
|
|
// 系统变量查询
|
|
|
QueryWrapper<SystemVariable> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("variable_address", "sys_run_current_limit");
|
|
|
- queryWrapper.eq("status", 0);
|
|
|
+ queryWrapper.eq("status", 0);
|
|
|
SystemVariable systemVariable = systemVariableService.getOne(queryWrapper);
|
|
|
//遍历设备集合
|
|
|
deviceInformationllist.forEach(deviceInformationlinfo -> {
|
|
@@ -172,7 +210,7 @@ public class LeanModelStatistics {
|
|
|
int result = compareStringWithBigDecimal(systemVariable.getDefaultValue(), fpgGatherData.getRunCurrent()); // > 0 启动, < 0 停止
|
|
|
String deviceStatus = result > 0 ? "1" : "0"; // 1:停止 0:正常
|
|
|
if (!deviceStatus.equals(deviceInformationlinfo.getStatus())) { // 状态变更处理
|
|
|
- deviceOperationLogService.logDeviceOperation(deviceInformationlinfo.getDeviceTitle()+" ", result > 0 ? "启动" : "停止", fpgGatherData.getCreateTime());
|
|
|
+ deviceOperationLogService.logDeviceOperation(deviceInformationlinfo.getDeviceTitle() + " ", result > 0 ? "启动" : "停止", fpgGatherData.getCreateTime());
|
|
|
// 变更状态
|
|
|
deviceInformationlinfo.setStatus(deviceStatus);
|
|
|
deviceInformationlinfo.setId(deviceInformationlinfo.getId());
|
|
@@ -219,7 +257,7 @@ public class LeanModelStatistics {
|
|
|
.with(Sort.by(Sort.Order.desc("deviceStartTime"))).limit(1);
|
|
|
// 查找设备运行记录
|
|
|
DeviceStatiscsModelMongodb startStopMongo = mongoTemplate.findOne(queryStartStop, DeviceStatiscsModelMongodb.class, startStopMonKey);
|
|
|
- if(startStopMongo != null){ // 存在该设备记录
|
|
|
+ if (startStopMongo != null) { // 存在该设备记录
|
|
|
Date deviceStopTimeEnd = DateUtils.addHours(fpgGatherData.getCreateTime(), 0);
|
|
|
if (fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) < 0 && "1".equals(startStopMongo.getDeviceStopTimeBank())) {
|
|
|
// 设备正常运行的 直接停止更新启停时间
|
|
@@ -240,7 +278,7 @@ public class LeanModelStatistics {
|
|
|
.addCriteria(Criteria.where("deviceInformationId").is(fpgGatherData.getDeviceInformationId()))
|
|
|
.addCriteria(Criteria.where("_id").is(startStopMongo.get_id()));
|
|
|
mongoTemplate.findAndModify(modifyStartStop, updateStartStop, DeviceStatiscsModelMongodb.class, startStopMonKey);
|
|
|
- } else if(fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) > 0 && "1".equals(startStopMongo.getDeviceStopTimeBank())){
|
|
|
+ } else if (fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) > 0 && "1".equals(startStopMongo.getDeviceStopTimeBank())) {
|
|
|
// 设备运行累加运行记录
|
|
|
BigDecimal oldPower = startStopMongo.getPower() == null ? new BigDecimal("0.00") : startStopMongo.getPower();
|
|
|
BigDecimal oldSelectricCurrent = startStopMongo.getSelectricCurrent() == null ? new BigDecimal("0.00") : startStopMongo.getSelectricCurrent();
|
|
@@ -267,7 +305,7 @@ public class LeanModelStatistics {
|
|
|
.addCriteria(Criteria.where("_id").is(startStopMongo.get_id()));
|
|
|
mongoTemplate.findAndModify(modifyStartStop, updateStartStop, DeviceStatiscsModelMongodb.class, startStopMonKey);
|
|
|
mongoTemplate.updateFirst(modifyStartStop, updateStartStop, FpgStatiscsModelMongodb.class, startStopMonKey);
|
|
|
- } else if(fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) > 0 && "2".equals(startStopMongo.getDeviceStopTimeBank())){
|
|
|
+ } else if (fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) > 0 && "2".equals(startStopMongo.getDeviceStopTimeBank())) {
|
|
|
// 上一个设备停止,重新记录启停记录
|
|
|
startStopStatiscsData.setPower(runPower);
|
|
|
startStopStatiscsData.setIngTime(runTime);
|
|
@@ -275,7 +313,7 @@ public class LeanModelStatistics {
|
|
|
mongoTemplate.insert(startStopStatiscsData, startStopMonKey);
|
|
|
}
|
|
|
} else { // 直接插入
|
|
|
- if(fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) > 0){ // 运行中计入启停记录
|
|
|
+ if (fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) > 0) { // 运行中计入启停记录
|
|
|
startStopStatiscsData.setPower(runPower);
|
|
|
startStopStatiscsData.setIngTime(runTime);
|
|
|
startStopStatiscsData.setSelectricCurrent(selectricCurrent);
|
|
@@ -290,14 +328,14 @@ public class LeanModelStatistics {
|
|
|
fpgGatherDataService.updateById(fpgGatherData);
|
|
|
return;
|
|
|
}
|
|
|
- // 日统计尖峰平谷数据(功率+占比+电流+运行时长) start
|
|
|
+ // 日统计尖峰平谷数据(功率+占比+电流+运行时长) start
|
|
|
String dayPowerproportioncurrentRunMonKey = "total_day_powerproportioncurrent";
|
|
|
DeviceStatiscsModelData dayPowerproportioncurrentRunData = new DeviceStatiscsModelData(fpgGatherData, dayPowerproportioncurrentRunMonKey, dayDate, classs, curentDate, curentDate);
|
|
|
// 组合mongodb条件
|
|
|
Query queryDayPowerproportioncurrentRun = new Query()
|
|
|
.addCriteria(Criteria.where("deviceRegionId").is(fpgGatherData.getDeviceRegionId())).addCriteria(Criteria.where("deviceInformationId").is(fpgGatherData.getDeviceInformationId())).addCriteria(Criteria.where("dates").is(dayDate));
|
|
|
DeviceStatiscsModelMongodb dayPowerproportioncurrentMongo = mongoTemplate.findOne(queryDayPowerproportioncurrentRun, DeviceStatiscsModelMongodb.class, dayPowerproportioncurrentRunMonKey);
|
|
|
- if(dayPowerproportioncurrentMongo != null){ // 不为空更新
|
|
|
+ if (dayPowerproportioncurrentMongo != null) { // 不为空更新
|
|
|
// 历史数据
|
|
|
BigDecimal runNewPower = dayPowerproportioncurrentMongo.getPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getPower().add(runPower);
|
|
|
BigDecimal oldRunTime = dayPowerproportioncurrentMongo.getIngTime() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getIngTime();
|
|
@@ -315,7 +353,7 @@ public class LeanModelStatistics {
|
|
|
BigDecimal peaksProportion = dayPowerproportioncurrentMongo.getPeaksPower().compareTo(new BigDecimal("0.00")) > 0 ? dayPowerproportioncurrentMongo.getPeaksPower().divide(runNewPower, 4, RoundingMode.HALF_UP).multiply(zb) : proportion;
|
|
|
BigDecimal valleysProportion = dayPowerproportioncurrentMongo.getValleysPower().compareTo(new BigDecimal("0.00")) > 0 ? dayPowerproportioncurrentMongo.getValleysPower().divide(runNewPower, 4, RoundingMode.HALF_UP).multiply(zb) : proportion;
|
|
|
// 尖峰平谷判定
|
|
|
- if("tops".equals(jfpgStr.get())){ // 尖
|
|
|
+ if ("tops".equals(jfpgStr.get())) { // 尖
|
|
|
// 功率处理
|
|
|
BigDecimal oldtopsPower = dayPowerproportioncurrentMongo.getTopsPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getTopsPower();
|
|
|
BigDecimal topsPower = oldtopsPower.add(runPower);
|
|
@@ -325,7 +363,7 @@ public class LeanModelStatistics {
|
|
|
((Update) update).set("topsIngTime", oldtopsIngTime.add(runTime));
|
|
|
// 占比
|
|
|
topsProportion = topsPower.compareTo(new BigDecimal("0.00")) > 0 ? topsPower.divide(runNewPower, 4, RoundingMode.HALF_UP).multiply(zb) : topsProportion;
|
|
|
- } else if("peaks".equals(jfpgStr.get())){ // 峰
|
|
|
+ } else if ("peaks".equals(jfpgStr.get())) { // 峰
|
|
|
// 功率处理
|
|
|
BigDecimal oldpeaksPower = dayPowerproportioncurrentMongo.getPeaksPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getPeaksPower();
|
|
|
BigDecimal peaksPower = oldpeaksPower.add(runPower);
|
|
@@ -335,7 +373,7 @@ public class LeanModelStatistics {
|
|
|
((Update) update).set("peaksIngTime", oldpeaksIngTime.add(runTime));
|
|
|
// 占比
|
|
|
peaksProportion = peaksPower.compareTo(new BigDecimal("0.00")) > 0 ? peaksPower.divide(runNewPower, 4, RoundingMode.HALF_UP).multiply(zb) : peaksProportion;
|
|
|
- } else if("flat".equals(jfpgStr.get())){ // 平
|
|
|
+ } else if ("flat".equals(jfpgStr.get())) { // 平
|
|
|
// 功率处理
|
|
|
BigDecimal oldflatPower = dayPowerproportioncurrentMongo.getFlatPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getFlatPower();
|
|
|
BigDecimal flatPower = oldflatPower.add(runPower);
|
|
@@ -345,7 +383,7 @@ public class LeanModelStatistics {
|
|
|
((Update) update).set("flatIngTime", oldflatIngTime.add(runTime));
|
|
|
// 占比
|
|
|
flatProportion = flatPower.compareTo(new BigDecimal("0.00")) > 0 ? flatPower.divide(runNewPower, 4, RoundingMode.HALF_UP).multiply(zb) : flatProportion;
|
|
|
- } else if("valleys".equals(jfpgStr.get())){ // 谷
|
|
|
+ } else if ("valleys".equals(jfpgStr.get())) { // 谷
|
|
|
// 功率处理
|
|
|
BigDecimal oldvalleysPower = dayPowerproportioncurrentMongo.getValleysPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getValleysPower();
|
|
|
BigDecimal valleysPower = oldvalleysPower.add(runPower);
|
|
@@ -364,19 +402,19 @@ public class LeanModelStatistics {
|
|
|
mongoTemplate.updateFirst(queryDayPowerproportioncurrentRun, update, DeviceStatiscsModelMongodb.class, dayPowerproportioncurrentRunMonKey);
|
|
|
} else { // 为空直接插入
|
|
|
// 尖峰平谷判定
|
|
|
- if("tops".equals(jfpgStr.get())){ // 尖
|
|
|
+ if ("tops".equals(jfpgStr.get())) { // 尖
|
|
|
// 功率处理
|
|
|
dayPowerproportioncurrentRunData.setTopsPower(runPower);
|
|
|
dayPowerproportioncurrentRunData.setTopsIngTime(runTime);
|
|
|
- } else if("peaks".equals(jfpgStr.get())){ // 峰
|
|
|
+ } else if ("peaks".equals(jfpgStr.get())) { // 峰
|
|
|
// 功率处理
|
|
|
dayPowerproportioncurrentRunData.setPeaksPower(runPower);
|
|
|
dayPowerproportioncurrentRunData.setPeaksIngTime(runTime);
|
|
|
- } else if("flat".equals(jfpgStr.get())){ // 平
|
|
|
+ } else if ("flat".equals(jfpgStr.get())) { // 平
|
|
|
// 功率处理
|
|
|
dayPowerproportioncurrentRunData.setFlatPower(runPower);
|
|
|
dayPowerproportioncurrentRunData.setFlatIngTime(runTime);
|
|
|
- } else if("valleys".equals(jfpgStr.get())){ // 谷
|
|
|
+ } else if ("valleys".equals(jfpgStr.get())) { // 谷
|
|
|
dayPowerproportioncurrentRunData.setValleysPower(runPower);
|
|
|
dayPowerproportioncurrentRunData.setValleysIngTime(runTime);
|
|
|
}
|
|
@@ -388,8 +426,16 @@ public class LeanModelStatistics {
|
|
|
// 执行完成数据 标记已处理
|
|
|
fpgGatherData.setId(fpgGatherData.getId());
|
|
|
fpgGatherDataService.updateById(fpgGatherData);
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
+ String errorMessage = String.format("【告警】峰平谷设备启停统计数据异常!\n" +
|
|
|
+ "**错误信息**: %s\n",
|
|
|
+ e.getMessage());
|
|
|
+
|
|
|
+ sendDingMessage(errorMessage);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
});
|
|
|
});
|
|
@@ -397,7 +443,7 @@ public class LeanModelStatistics {
|
|
|
|
|
|
|
|
|
//精益模型统计数据
|
|
|
- public void leanModel(){
|
|
|
+ public void leanModel() {
|
|
|
log.info("峰平谷模型");
|
|
|
// 峰平谷精益模型配置获取
|
|
|
LambdaQueryWrapper<FpgLeanModel> leanmodelQuery = new LambdaQueryWrapper<FpgLeanModel>().eq(FpgLeanModel::getStatus, "1");
|
|
@@ -406,21 +452,21 @@ public class LeanModelStatistics {
|
|
|
LocalDateTime newTime = LocalDateTime.now().plusHours(8);
|
|
|
|
|
|
// 尖峰平谷时段配置
|
|
|
- List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
|
|
|
+ List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
|
|
|
// 存储fpgGather数据id集合
|
|
|
- List<FpgGatherData> fpgGatherUpdateList= new ArrayList<>();
|
|
|
+ List<FpgGatherData> fpgGatherUpdateList = new ArrayList<>();
|
|
|
|
|
|
// 系统变量查询
|
|
|
QueryWrapper<SystemVariable> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("variable_address", "sys_run_current_limit");
|
|
|
- queryWrapper.eq("status", 0);
|
|
|
+ queryWrapper.eq("status", 0);
|
|
|
SystemVariable systemVariable = systemVariableService.getOne(queryWrapper);
|
|
|
|
|
|
// 遍历设备集合
|
|
|
fpgLeanModellist.forEach(fpgLeanModeInfo -> {
|
|
|
LambdaQueryWrapper<FpgGatherData> fpgGatherQuery = new LambdaQueryWrapper<FpgGatherData>().isNull(FpgGatherData::getFpgModelUpdatetime).isNotNull(FpgGatherData::getRunCurrent).isNotNull(FpgGatherData::getActivePower).orderByAsc(FpgGatherData::getCreateTime);
|
|
|
// 检测是否配置设备特殊条件
|
|
|
- if(oConvertUtils.isNotEmpty(fpgLeanModeInfo.getDeviceInformationIds()) && oConvertUtils.isNotEmpty(fpgLeanModeInfo.getDeviceInformationIds())){
|
|
|
+ if (oConvertUtils.isNotEmpty(fpgLeanModeInfo.getDeviceInformationIds()) && oConvertUtils.isNotEmpty(fpgLeanModeInfo.getDeviceInformationIds())) {
|
|
|
fpgGatherQuery.in(FpgGatherData::getDeviceInformationId, Arrays.asList(fpgLeanModeInfo.getDeviceInformationIds().split(",")));
|
|
|
}
|
|
|
fpgGatherQuery.orderByAsc(FpgGatherData::getCreateTime).last("limit 1000");
|
|
@@ -431,18 +477,18 @@ public class LeanModelStatistics {
|
|
|
try {
|
|
|
String finalDatestr = "";
|
|
|
// 统计单位
|
|
|
- if("minute".equals(fpgLeanModeInfo.getTotalUnit())){ // 分钟
|
|
|
+ if ("minute".equals(fpgLeanModeInfo.getTotalUnit())) { // 分钟
|
|
|
finalDatestr = new SimpleDateFormat("HH:mm").format(fpgGatherData.getCreateTime());
|
|
|
- } else if("hour".equals(fpgLeanModeInfo.getTotalUnit())){ // 小时
|
|
|
+ } else if ("hour".equals(fpgLeanModeInfo.getTotalUnit())) { // 小时
|
|
|
finalDatestr = new SimpleDateFormat("HH:00").format(fpgGatherData.getCreateTime());
|
|
|
- } else if("day".equals(fpgLeanModeInfo.getTotalUnit())){ //
|
|
|
+ } else if ("day".equals(fpgLeanModeInfo.getTotalUnit())) { //
|
|
|
finalDatestr = new SimpleDateFormat("yyyy-MM-dd").format(fpgGatherData.getCreateTime());
|
|
|
- }else if("week".equals(fpgLeanModeInfo.getTotalUnit())){ //
|
|
|
+ } else if ("week".equals(fpgLeanModeInfo.getTotalUnit())) { //
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
finalDatestr = String.valueOf(calendar.get(Calendar.WEEK_OF_MONTH));
|
|
|
- } else if("month".equals(fpgLeanModeInfo.getTotalUnit())){ //
|
|
|
+ } else if ("month".equals(fpgLeanModeInfo.getTotalUnit())) { //
|
|
|
finalDatestr = new SimpleDateFormat("yyyy-MM").format(fpgGatherData.getCreateTime());
|
|
|
- } else if("real_time". equals(fpgLeanModeInfo.getTotalUnit())){ // 实时
|
|
|
+ } else if ("real_time".equals(fpgLeanModeInfo.getTotalUnit())) { // 实时
|
|
|
fpgLeanModeInfo.setProportion(2);
|
|
|
fpgLeanModeInfo.setElectricCurrent(2);
|
|
|
fpgLeanModeInfo.setRunTime(2);
|
|
@@ -467,7 +513,7 @@ public class LeanModelStatistics {
|
|
|
// 重组对象
|
|
|
FpgStatiscsModelData fpgStatiscsModelData = new FpgStatiscsModelData(fpgGatherData, fpgLeanModeInfo, finalDatestr, dayDate, classs, curentDate, curentDate);
|
|
|
// 实时统计直接插入
|
|
|
- if("real_time". equals(fpgLeanModeInfo.getTotalUnit())){
|
|
|
+ if ("real_time".equals(fpgLeanModeInfo.getTotalUnit())) {
|
|
|
fpgStatiscsModelData.setSelectricCurrent(fpgGatherData.getRunCurrent());
|
|
|
fpgStatiscsModelData.setPower(fpgGatherData.getActivePower());
|
|
|
fpgStatiscsModelData.setIngTime(new BigDecimal("300"));
|
|
@@ -492,18 +538,18 @@ public class LeanModelStatistics {
|
|
|
// 组合mongodb条件
|
|
|
Query query = new Query();
|
|
|
// 是否已区域为维度
|
|
|
- if(fpgLeanModeInfo.getDeviceRegionStatus() == 1){
|
|
|
+ if (fpgLeanModeInfo.getDeviceRegionStatus() == 1) {
|
|
|
query.addCriteria(Criteria.where("deviceRegionId").is(fpgGatherData.getDeviceRegionId()))
|
|
|
.addCriteria(Criteria.where("dates").is(dayDate))
|
|
|
.addCriteria(Criteria.where("datestr").is(finalDatestr));
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
query.addCriteria(Criteria.where("deviceRegionId").is(fpgGatherData.getDeviceRegionId()))
|
|
|
.addCriteria(Criteria.where("deviceInformationId").is(fpgGatherData.getDeviceInformationId()))
|
|
|
.addCriteria(Criteria.where("dates").is(dayDate))
|
|
|
.addCriteria(Criteria.where("datestr").is(finalDatestr));
|
|
|
}
|
|
|
|
|
|
- if(!classs.isEmpty()){ // 增加班次条件
|
|
|
+ if (!classs.isEmpty()) { // 增加班次条件
|
|
|
query.addCriteria(Criteria.where("classs").is(classs));
|
|
|
}
|
|
|
|
|
@@ -518,12 +564,12 @@ public class LeanModelStatistics {
|
|
|
}
|
|
|
FpgStatiscsModelMongodb fpgStatiscsModelMongo = mongoTemplate.findOne(query, FpgStatiscsModelMongodb.class, collectionName);
|
|
|
// 功率 5 分钟上报一次 除以 12
|
|
|
- BigDecimal activePower = fpgGatherData.getActivePower().compareTo(new BigDecimal("0.00")) > 0 ? fpgGatherData.getActivePower().divide(new BigDecimal("12"), 12, RoundingMode.HALF_UP) : new BigDecimal("0.00");
|
|
|
+ BigDecimal activePower = fpgGatherData.getActivePower().compareTo(new BigDecimal("0.00")) > 0 ? fpgGatherData.getActivePower().divide(new BigDecimal("12"), 12, RoundingMode.HALF_UP) : new BigDecimal("0.00");
|
|
|
// 电流
|
|
|
BigDecimal selectricCurrent = fpgGatherData.getRunCurrent() == null ? new BigDecimal("0.00") : fpgGatherData.getRunCurrent();
|
|
|
// 运行时常
|
|
|
BigDecimal runTime = new BigDecimal("300");
|
|
|
- if(fpgStatiscsModelMongo != null){ // 不为空处理
|
|
|
+ if (fpgStatiscsModelMongo != null) { // 不为空处理
|
|
|
// 基础数据变更不受条件影响
|
|
|
UpdateDefinition update = new Update();
|
|
|
((Update) update).set("updateTime", curentDate);
|
|
@@ -531,21 +577,21 @@ public class LeanModelStatistics {
|
|
|
BigDecimal oldingTime = fpgStatiscsModelMongo.getIngTime() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getIngTime();
|
|
|
BigDecimal oldSelectricCurrent = fpgStatiscsModelMongo.getSelectricCurrent() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getSelectricCurrent();
|
|
|
// 总运行时间处理
|
|
|
- if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) { // 运行时长统计
|
|
|
- (( Update) update).set("ingTime", oldingTime.add(runTime));
|
|
|
+ if (fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) { // 运行时长统计
|
|
|
+ ((Update) update).set("ingTime", oldingTime.add(runTime));
|
|
|
}
|
|
|
// 电流处理
|
|
|
- if(fpgLeanModeInfo.getElectricCurrent() != null && fpgLeanModeInfo.getElectricCurrent() == 1){
|
|
|
- if("tops".equals(jfpgStr.get())) { // 尖
|
|
|
+ if (fpgLeanModeInfo.getElectricCurrent() != null && fpgLeanModeInfo.getElectricCurrent() == 1) {
|
|
|
+ if ("tops".equals(jfpgStr.get())) { // 尖
|
|
|
BigDecimal oldtopsSelectricCurrent = fpgStatiscsModelMongo.getTopsSelectricCurrent() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getTopsSelectricCurrent();
|
|
|
((Update) update).set("topSelectricCurrent", oldtopsSelectricCurrent.add(selectricCurrent));
|
|
|
- } else if("peaks".equals(jfpgStr.get())){ // 峰
|
|
|
+ } else if ("peaks".equals(jfpgStr.get())) { // 峰
|
|
|
BigDecimal oldpeaksSelectricCurrent = fpgStatiscsModelMongo.getPeaksSelectricCurrent() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getPeaksSelectricCurrent();
|
|
|
((Update) update).set("peaksSelectricCurrent", oldpeaksSelectricCurrent.add(selectricCurrent));
|
|
|
- } else if("flat".equals(jfpgStr.get())) { // 平
|
|
|
+ } else if ("flat".equals(jfpgStr.get())) { // 平
|
|
|
BigDecimal oldtflatSelectricCurrent = fpgStatiscsModelMongo.getFlatSelectricCurrent() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getFlatSelectricCurrent();
|
|
|
((Update) update).set("flatSelectricCurrent", oldtflatSelectricCurrent.add(selectricCurrent));
|
|
|
- } else if("valleys".equals(jfpgStr.get())) { // 谷
|
|
|
+ } else if ("valleys".equals(jfpgStr.get())) { // 谷
|
|
|
BigDecimal oldvalleysSelectricCurrent = fpgStatiscsModelMongo.getValleysSelectricCurrent() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getValleysSelectricCurrent();
|
|
|
((Update) update).set("valleysSelectricCurrent", oldvalleysSelectricCurrent.add(selectricCurrent));
|
|
|
}
|
|
@@ -557,7 +603,7 @@ public class LeanModelStatistics {
|
|
|
//总电流处理
|
|
|
((Update) update).set("selectricCurrent", oldSelectricCurrent.add(selectricCurrent));
|
|
|
// 尖峰平谷判定
|
|
|
- if("tops".equals(jfpgStr.get())){ // 尖
|
|
|
+ if ("tops".equals(jfpgStr.get())) { // 尖
|
|
|
// 功率处理
|
|
|
BigDecimal oldtopsPower = fpgStatiscsModelMongo.getTopsPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getTopsPower();
|
|
|
BigDecimal oldPeaksPower = fpgStatiscsModelMongo.getPeaksPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getPeaksPower();
|
|
@@ -565,7 +611,7 @@ public class LeanModelStatistics {
|
|
|
BigDecimal oldValleysPower = fpgStatiscsModelMongo.getValleysPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getValleysPower();
|
|
|
((Update) update).set("topsPower", oldtopsPower.add(activePower));
|
|
|
// 运行时常处理
|
|
|
- if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){ // 运行时长统计
|
|
|
+ if (fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) { // 运行时长统计
|
|
|
BigDecimal oldtopsIngTime = fpgStatiscsModelMongo.getTopsIngTime() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getTopsIngTime();
|
|
|
BigDecimal newTopsIngTime = oldtopsIngTime.add(runTime).stripTrailingZeros();
|
|
|
DecimalFormat df = new DecimalFormat("0.##################");
|
|
@@ -573,30 +619,30 @@ public class LeanModelStatistics {
|
|
|
((Update) update).set("topsIngTime", new BigDecimal(topFormatted));
|
|
|
}
|
|
|
// 金额处理
|
|
|
- if(fpgLeanModeInfo.getTopsPrice() != null && fpgLeanModeInfo.getTopsPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgLeanModeInfo.getTopsPrice() != null && fpgLeanModeInfo.getTopsPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
// 总金额
|
|
|
BigDecimal totalAmount = fpgStatiscsModelMongo.getAmount() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getAmount();
|
|
|
((Update) update).set("amount", activePower.multiply(fpgLeanModeInfo.getTopsPrice()).add(totalAmount));
|
|
|
((Update) update).set("topsAmount", oldtopsPower.add(activePower).multiply(fpgLeanModeInfo.getTopsPrice()));
|
|
|
}
|
|
|
- if(fpgLeanModeInfo.getProportion() !=null && fpgLeanModeInfo.getProportion() == 1){ //占比统计
|
|
|
+ if (fpgLeanModeInfo.getProportion() != null && fpgLeanModeInfo.getProportion() == 1) { //占比统计
|
|
|
|
|
|
((Update) update).set("topsProportion", oldtopsPower.add(activePower).divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
|
|
|
- if(fpgStatiscsModelMongo.getPeaksPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getPeaksPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("peaksProportion", oldPeaksPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
}
|
|
|
- if(fpgStatiscsModelMongo.getFlatPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getFlatPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("flatProportion", oldFlatPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
}
|
|
|
|
|
|
- if(fpgStatiscsModelMongo.getValleysPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getValleysPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("valleysProportion", oldValleysPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
- } else if("peaks".equals(jfpgStr.get())){ // 峰
|
|
|
+ } else if ("peaks".equals(jfpgStr.get())) { // 峰
|
|
|
// 功率处理
|
|
|
BigDecimal oldpeaksPower = fpgStatiscsModelMongo.getPeaksPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getPeaksPower();
|
|
|
BigDecimal oldtopsPower = fpgStatiscsModelMongo.getTopsPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getTopsPower();
|
|
@@ -604,7 +650,7 @@ public class LeanModelStatistics {
|
|
|
BigDecimal oldValleysPower = fpgStatiscsModelMongo.getValleysPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getValleysPower();
|
|
|
((Update) update).set("peaksPower", oldpeaksPower.add(activePower));
|
|
|
// 运行时常处理
|
|
|
- if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){ // 运行时长统计
|
|
|
+ if (fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) { // 运行时长统计
|
|
|
BigDecimal oldpeaksIngTime = fpgStatiscsModelMongo.getPeaksIngTime() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getPeaksIngTime();
|
|
|
BigDecimal newPeaksIngTime = oldpeaksIngTime.add(runTime).stripTrailingZeros();
|
|
|
DecimalFormat df = new DecimalFormat("0.##################");
|
|
@@ -612,28 +658,28 @@ public class LeanModelStatistics {
|
|
|
((Update) update).set("peaksIngTime", new BigDecimal(peaksFormatted));
|
|
|
}
|
|
|
// 金额处理
|
|
|
- if(fpgLeanModeInfo.getPeaksPrice() != null && fpgLeanModeInfo.getPeaksPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgLeanModeInfo.getPeaksPrice() != null && fpgLeanModeInfo.getPeaksPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
// 总金额
|
|
|
BigDecimal totalAmount = fpgStatiscsModelMongo.getAmount() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getAmount();
|
|
|
((Update) update).set("amount", activePower.multiply(fpgLeanModeInfo.getPeaksPrice()).add(totalAmount));
|
|
|
((Update) update).set("peaksAmount", oldpeaksPower.add(activePower).multiply(fpgLeanModeInfo.getPeaksPrice()));
|
|
|
}
|
|
|
- if(fpgLeanModeInfo.getProportion() !=null && fpgLeanModeInfo.getProportion() == 1){ //占比统计
|
|
|
+ if (fpgLeanModeInfo.getProportion() != null && fpgLeanModeInfo.getProportion() == 1) { //占比统计
|
|
|
|
|
|
((Update) update).set("peaksProportion", oldpeaksPower.add(activePower).divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
|
|
|
- if(fpgStatiscsModelMongo.getTopsPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getTopsPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("topsProportion", oldtopsPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
}
|
|
|
- if(fpgStatiscsModelMongo.getFlatPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getFlatPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("flatProportion", oldFlatPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
}
|
|
|
- if(fpgStatiscsModelMongo.getValleysPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getValleysPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("valleysProportion", oldValleysPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- } else if("flat".equals(jfpgStr.get())){ // 平
|
|
|
+ } else if ("flat".equals(jfpgStr.get())) { // 平
|
|
|
// 功率处理
|
|
|
BigDecimal oldflatPower = fpgStatiscsModelMongo.getFlatPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getFlatPower();
|
|
|
BigDecimal oldpeaksPower = fpgStatiscsModelMongo.getPeaksPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getPeaksPower();
|
|
@@ -641,7 +687,7 @@ public class LeanModelStatistics {
|
|
|
BigDecimal oldValleysPower = fpgStatiscsModelMongo.getValleysPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getValleysPower();
|
|
|
((Update) update).set("flatPower", oldflatPower.add(activePower));
|
|
|
// 运行时常处理
|
|
|
- if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){
|
|
|
+ if (fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) {
|
|
|
BigDecimal oldflatIngTime = fpgStatiscsModelMongo.getFlatIngTime() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getFlatIngTime();
|
|
|
BigDecimal newFlatIngTime = oldflatIngTime.add(runTime).stripTrailingZeros();
|
|
|
DecimalFormat df = new DecimalFormat("0.##################");
|
|
@@ -649,31 +695,31 @@ public class LeanModelStatistics {
|
|
|
((Update) update).set("flatIngTime", new BigDecimal(formatted));
|
|
|
}
|
|
|
// 金额处理
|
|
|
- if(fpgLeanModeInfo.getFlatPrice() != null && fpgLeanModeInfo.getFlatPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgLeanModeInfo.getFlatPrice() != null && fpgLeanModeInfo.getFlatPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
// 总金额
|
|
|
BigDecimal totalAmount = fpgStatiscsModelMongo.getAmount() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getAmount();
|
|
|
((Update) update).set("amount", activePower.multiply(fpgLeanModeInfo.getFlatPrice()).add(totalAmount));
|
|
|
((Update) update).set("flatAmount", oldflatPower.add(activePower).multiply(fpgLeanModeInfo.getFlatPrice()));
|
|
|
}
|
|
|
- if(fpgLeanModeInfo.getProportion() !=null && fpgLeanModeInfo.getProportion() == 1){ //占比统计
|
|
|
+ if (fpgLeanModeInfo.getProportion() != null && fpgLeanModeInfo.getProportion() == 1) { //占比统计
|
|
|
|
|
|
((Update) update).set("flatProportion", oldflatPower.add(activePower).divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
|
|
|
- if(fpgStatiscsModelMongo.getTopsPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getTopsPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("topsProportion", oldtopsPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
|
|
|
}
|
|
|
- if(fpgStatiscsModelMongo.getPeaksPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getPeaksPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("peaksProportion", oldpeaksPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
|
|
|
}
|
|
|
- if(fpgStatiscsModelMongo.getValleysPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getValleysPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("valleysProportion", oldValleysPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- } else if("valleys".equals(jfpgStr.get())){ // 谷
|
|
|
+ } else if ("valleys".equals(jfpgStr.get())) { // 谷
|
|
|
// 功率处理
|
|
|
BigDecimal oldvalleysPower = fpgStatiscsModelMongo.getValleysPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getValleysPower();
|
|
|
BigDecimal oldflatPower = fpgStatiscsModelMongo.getFlatPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getFlatPower();
|
|
@@ -682,7 +728,7 @@ public class LeanModelStatistics {
|
|
|
|
|
|
((Update) update).set("valleysPower", oldvalleysPower.add(activePower));
|
|
|
// 运行时常处理
|
|
|
- if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){
|
|
|
+ if (fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) {
|
|
|
BigDecimal oldvalleysIngTime = fpgStatiscsModelMongo.getValleysIngTime() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getValleysIngTime();
|
|
|
BigDecimal newValleysIngTime = oldvalleysIngTime.add(runTime).stripTrailingZeros();
|
|
|
DecimalFormat df = new DecimalFormat("0.##################");
|
|
@@ -690,26 +736,26 @@ public class LeanModelStatistics {
|
|
|
((Update) update).set("valleysIngTime", new BigDecimal(valleysFormatted));
|
|
|
}
|
|
|
// 金额处理
|
|
|
- if(fpgLeanModeInfo.getValleysPrice() != null && fpgLeanModeInfo.getValleysPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgLeanModeInfo.getValleysPrice() != null && fpgLeanModeInfo.getValleysPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
// 总金额
|
|
|
BigDecimal totalAmount = fpgStatiscsModelMongo.getAmount() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getAmount();
|
|
|
((Update) update).set("amount", activePower.multiply(fpgLeanModeInfo.getValleysPrice()).add(totalAmount));
|
|
|
((Update) update).set("valleysAmount", oldvalleysPower.add(activePower).multiply(fpgLeanModeInfo.getValleysPrice()));
|
|
|
}
|
|
|
|
|
|
- if(fpgLeanModeInfo.getProportion() !=null && fpgLeanModeInfo.getProportion() == 1){ //占比统计
|
|
|
+ if (fpgLeanModeInfo.getProportion() != null && fpgLeanModeInfo.getProportion() == 1) { //占比统计
|
|
|
|
|
|
((Update) update).set("valleysProportion", oldvalleysPower.add(activePower).divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
|
|
|
- if(fpgStatiscsModelMongo.getTopsPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getTopsPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("topsProportion", oldtopsPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
|
|
|
}
|
|
|
- if(fpgStatiscsModelMongo.getPeaksPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getPeaksPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("peaksProportion", oldpeaksPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
|
|
|
}
|
|
|
- if(fpgStatiscsModelMongo.getFlatPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgStatiscsModelMongo.getFlatPower().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
((Update) update).set("flatProportion", oldflatPower.divide(fpgStatiscsModelMongo.getPower().add(activePower), 2, RoundingMode.HALF_UP).multiply(zb));
|
|
|
|
|
|
}
|
|
@@ -724,74 +770,74 @@ public class LeanModelStatistics {
|
|
|
fpgGatherUpdateList.add(fpgGatherData);
|
|
|
fpgStatiscsModelData.setPower(activePower); // 总功率处理
|
|
|
fpgStatiscsModelData.setSelectricCurrent(selectricCurrent); // 总电流处理
|
|
|
- if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) { // 运行时长统计
|
|
|
+ if (fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) { // 运行时长统计
|
|
|
fpgStatiscsModelData.setIngTime(runTime); // 运行时常
|
|
|
}
|
|
|
// 电流处理
|
|
|
- if(fpgLeanModeInfo.getElectricCurrent() != null && fpgLeanModeInfo.getElectricCurrent() == 1){
|
|
|
- if("tops".equals(jfpgStr.get())) { // 尖
|
|
|
+ if (fpgLeanModeInfo.getElectricCurrent() != null && fpgLeanModeInfo.getElectricCurrent() == 1) {
|
|
|
+ if ("tops".equals(jfpgStr.get())) { // 尖
|
|
|
fpgStatiscsModelData.setTopSelectricCurrent(selectricCurrent);
|
|
|
- } else if("peaks".equals(jfpgStr.get())){ // 峰
|
|
|
+ } else if ("peaks".equals(jfpgStr.get())) { // 峰
|
|
|
fpgStatiscsModelData.setPeaksSelectricCurrent(selectricCurrent);
|
|
|
- } else if("flat".equals(jfpgStr.get())) { // 平
|
|
|
+ } else if ("flat".equals(jfpgStr.get())) { // 平
|
|
|
fpgStatiscsModelData.setFlatSelectricCurrent(selectricCurrent);
|
|
|
- } else if("valleys".equals(jfpgStr.get())) { // 谷
|
|
|
+ } else if ("valleys".equals(jfpgStr.get())) { // 谷
|
|
|
fpgStatiscsModelData.setValleysSelectricCurrent(selectricCurrent);
|
|
|
}
|
|
|
}
|
|
|
// 尖峰平谷判定
|
|
|
- if("tops".equals(jfpgStr.get())){ // 尖
|
|
|
+ if ("tops".equals(jfpgStr.get())) { // 尖
|
|
|
fpgStatiscsModelData.setTopsPower(activePower);
|
|
|
fpgStatiscsModelData.setTopsProportion(new BigDecimal("100"));// 功率
|
|
|
// 运行时常处理
|
|
|
- if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){ // 运行时长统计
|
|
|
+ if (fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) { // 运行时长统计
|
|
|
fpgStatiscsModelData.setTopsPower(runTime);
|
|
|
}
|
|
|
// 金额处理
|
|
|
- if(fpgLeanModeInfo.getTopsPrice() != null && fpgLeanModeInfo.getTopsPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgLeanModeInfo.getTopsPrice() != null && fpgLeanModeInfo.getTopsPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
BigDecimal amount = activePower.multiply(fpgLeanModeInfo.getTopsPrice()); // 金额处理
|
|
|
fpgStatiscsModelData.setAmount(amount);
|
|
|
fpgStatiscsModelData.setTopsAmount(amount);
|
|
|
}
|
|
|
- } else if("peaks".equals(jfpgStr.get())){ // 峰
|
|
|
+ } else if ("peaks".equals(jfpgStr.get())) { // 峰
|
|
|
// 功率处理
|
|
|
fpgStatiscsModelData.setPeaksPower(activePower); // 功率
|
|
|
fpgStatiscsModelData.setPeaksProportion(new BigDecimal("100"));
|
|
|
// 运行时常处理
|
|
|
- if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){ // 运行时长统计
|
|
|
+ if (fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) { // 运行时长统计
|
|
|
fpgStatiscsModelData.setPeaksIngTime(runTime);
|
|
|
}
|
|
|
// 金额处理
|
|
|
- if(fpgLeanModeInfo.getPeaksPrice() != null && fpgLeanModeInfo.getPeaksPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgLeanModeInfo.getPeaksPrice() != null && fpgLeanModeInfo.getPeaksPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
BigDecimal amount = activePower.multiply(fpgLeanModeInfo.getPeaksPrice()); // 金额处理
|
|
|
fpgStatiscsModelData.setAmount(amount);
|
|
|
fpgStatiscsModelData.setPeaksAmount(amount);
|
|
|
}
|
|
|
- } else if("flat".equals(jfpgStr.get())){ // 平
|
|
|
+ } else if ("flat".equals(jfpgStr.get())) { // 平
|
|
|
// 功率处理
|
|
|
fpgStatiscsModelData.setFlatPower(activePower); // 功率
|
|
|
fpgStatiscsModelData.setFlatProportion(new BigDecimal("100"));
|
|
|
// 运行时常处理
|
|
|
- if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){ // 运行时长统计
|
|
|
+ if (fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) { // 运行时长统计
|
|
|
fpgStatiscsModelData.setFlatIngTime(runTime);
|
|
|
}
|
|
|
// 金额处理
|
|
|
- if(fpgLeanModeInfo.getFlatPrice() != null && fpgLeanModeInfo.getFlatPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgLeanModeInfo.getFlatPrice() != null && fpgLeanModeInfo.getFlatPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
BigDecimal amount = activePower.multiply(fpgLeanModeInfo.getFlatPrice()); // 金额处理
|
|
|
fpgStatiscsModelData.setAmount(amount);
|
|
|
fpgStatiscsModelData.setFlatAmount(amount);
|
|
|
}
|
|
|
- } else if("valleys".equals(jfpgStr.get())){ // 谷
|
|
|
+ } else if ("valleys".equals(jfpgStr.get())) { // 谷
|
|
|
// 功率处理
|
|
|
fpgStatiscsModelData.setValleysPower(activePower); // 功率
|
|
|
fpgStatiscsModelData.setValleysProportion(new BigDecimal("100"));
|
|
|
|
|
|
// 运行时常处理
|
|
|
- if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){ // 运行时长统计
|
|
|
+ if (fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) { // 运行时长统计
|
|
|
fpgStatiscsModelData.setValleysIngTime(runTime);
|
|
|
}
|
|
|
// 金额处理
|
|
|
- if(fpgLeanModeInfo.getValleysPrice() != null && fpgLeanModeInfo.getValleysPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
+ if (fpgLeanModeInfo.getValleysPrice() != null && fpgLeanModeInfo.getValleysPrice().compareTo(new BigDecimal("0.00")) > 0) {
|
|
|
BigDecimal amount = activePower.multiply(fpgLeanModeInfo.getValleysPrice()); // 金额处理
|
|
|
fpgStatiscsModelData.setAmount(amount);
|
|
|
fpgStatiscsModelData.setValleysAmount(amount);
|
|
@@ -800,8 +846,15 @@ public class LeanModelStatistics {
|
|
|
// 将点位数据存入mongo中
|
|
|
mongoTemplate.insert(fpgStatiscsModelData, collectionName);
|
|
|
}
|
|
|
- }catch (Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
+
|
|
|
+ String errorMessage = String.format("【告警】峰平谷精益模型统计数据异常!\n" +
|
|
|
+ "**错误信息**: %s\n",
|
|
|
+ e.getMessage());
|
|
|
+
|
|
|
+ sendDingMessage(errorMessage);
|
|
|
+
|
|
|
}
|
|
|
});
|
|
|
});
|
|
@@ -811,6 +864,7 @@ public class LeanModelStatistics {
|
|
|
|
|
|
/**
|
|
|
* 判断创建时间是否在开始时间和结束时间范围内
|
|
|
+ *
|
|
|
* @param createTime
|
|
|
* @param startTime
|
|
|
* @param endTime
|
|
@@ -851,4 +905,16 @@ public class LeanModelStatistics {
|
|
|
return strAsBigDecimal.compareTo(bd);
|
|
|
}
|
|
|
|
|
|
+ public static void sendDingMessage(String content) {
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.set("msgtype", "text");
|
|
|
+
|
|
|
+ JSONObject text = new JSONObject();
|
|
|
+ text.set("content", content);
|
|
|
+ json.set("text", text);
|
|
|
+
|
|
|
+ String response = HttpUtil.post(WEBHOOK_URL, json.toString());
|
|
|
+ log.info("钉钉消息发送结果:{}", response);
|
|
|
+ }
|
|
|
+
|
|
|
}
|