Pārlūkot izejas kodu

峰平谷 数据统计

guoqiang 6 mēneši atpakaļ
vecāks
revīzija
8104320e74

+ 6 - 0
jeecg-module-gather/src/main/java/org/jeecg/modules/device/entity/DeviceInformation.java

@@ -69,6 +69,12 @@ public class DeviceInformation implements Serializable {
     @Excel(name = "备注", width = 15)
     @ApiModelProperty(value = "备注")
     private String deviceRemark;
+    /**
+     * 设备类型(1棒一2棒二3棒三4高线5板带)
+     * */
+    @Excel(name = "设备类型 ", width = 15)
+    @ApiModelProperty(value = "设备类型")
+    private String deviceType;
     /**运行状态
      * RUNNING: '0', STOPPED: '1', ABNORMAL: '2'
      * */

+ 125 - 6
jeecg-module-gather/src/main/java/org/jeecg/modules/fpgJob/LeanModelStatistics.java

@@ -192,7 +192,7 @@ public class LeanModelStatistics {
                         }
                     });
                     // 功率
-                    BigDecimal runPower = fpgGatherData.getActivePower().compareTo(new BigDecimal("0.00")) > 0 ? fpgGatherData.getActivePower().divide(new BigDecimal(12), 6, RoundingMode.HALF_UP) : fpgGatherData.getActivePower();
+                    BigDecimal runPower = fpgGatherData.getActivePower().compareTo(new BigDecimal("0.00")) > 0 ? fpgGatherData.getActivePower().divide(new BigDecimal(12), 8, RoundingMode.HALF_UP) : fpgGatherData.getActivePower();
                     // 运行时常
                     BigDecimal runTime = new BigDecimal("300");
                     // 电流
@@ -207,6 +207,7 @@ public class LeanModelStatistics {
                     // 查找设备运行记录
                     DeviceStatiscsModelMongodb startStopMongo = mongoTemplate.findOne(queryStartStop, DeviceStatiscsModelMongodb.class, startStopMonKey);
                     if(startStopMongo != null){
+                        // 验证两个时间是否相等
                         int timeRes = compareDatesByTimeStamp(DateUtils.str2Date(startStopMongo.getDeviceStartTime(), DateUtils.datetimeFormat.get()), DateUtils.str2Date(startStopMongo.getDeviceStopTimeBank(), DateUtils.datetimeFormat.get()));
                         Date deviceStopTimeEnd = DateUtils.addHours(fpgGatherData.getCreateTime(), 8);
                         if (fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) < 0) { // 设备停止运行 直接更新停止时间结束不用统计任何东西
@@ -280,6 +281,16 @@ public class LeanModelStatistics {
                             if(topsPower.compareTo(new BigDecimal("0.00")) > 0) {
                                 ((Update) update).set("topsProportion", topsPower.divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
                             }
+                            // 其他三个重新核算
+                            if(dayPowerproportioncurrentMongo.getFlatPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("flatProportion", dayPowerproportioncurrentMongo.getFlatPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
+                            if(dayPowerproportioncurrentMongo.getPeaksPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("peaksProportion", dayPowerproportioncurrentMongo.getPeaksPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
+                            if(dayPowerproportioncurrentMongo.getTopsPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("topsProportion", dayPowerproportioncurrentMongo.getTopsPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
                         } else if("peaks".equals(jfpgStr.get())){ // 峰
                             // 功率处理
                             BigDecimal oldpeaksPower = dayPowerproportioncurrentMongo.getPeaksPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getPeaksPower();
@@ -292,6 +303,16 @@ public class LeanModelStatistics {
                             if(peaksPower.compareTo(new BigDecimal("0.00")) > 0) {
                                 ((Update) update).set("peaksProportion", peaksPower.divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
                             }
+                            // 其他三个重新核算
+                            if(dayPowerproportioncurrentMongo.getValleysPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("valleysProportion", dayPowerproportioncurrentMongo.getValleysPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
+                            if(dayPowerproportioncurrentMongo.getPeaksPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("peaksProportion", dayPowerproportioncurrentMongo.getPeaksPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
+                            if(dayPowerproportioncurrentMongo.getTopsPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("topsProportion", dayPowerproportioncurrentMongo.getTopsPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
                         } else if("flat".equals(jfpgStr.get())){ // 平
                             // 功率处理
                             BigDecimal oldflatPower = dayPowerproportioncurrentMongo.getFlatPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getFlatPower();
@@ -299,11 +320,21 @@ public class LeanModelStatistics {
                             ((Update) update).set("flatPower", flatPower);
                             // 运行时常处理
                             BigDecimal oldflatIngTime = dayPowerproportioncurrentMongo.getFlatIngTime() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getFlatIngTime();
-                            ((Update) update).set("topsIngTime", oldflatIngTime.add(runTime));
+                            ((Update) update).set("flatIngTime", oldflatIngTime.add(runTime));
                             // 占比
                             if(flatPower.compareTo(new BigDecimal("0.00")) > 0) {
                                 ((Update) update).set("flatProportion", flatPower.divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
                             }
+                            // 其他三个重新核算
+                            if(dayPowerproportioncurrentMongo.getValleysPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("valleysProportion", dayPowerproportioncurrentMongo.getValleysPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
+                            if(dayPowerproportioncurrentMongo.getPeaksPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("peaksProportion", dayPowerproportioncurrentMongo.getPeaksPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
+                            if(dayPowerproportioncurrentMongo.getTopsPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("topsProportion", dayPowerproportioncurrentMongo.getTopsPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
                         } else if("valleys".equals(jfpgStr.get())){ // 谷
                             // 功率处理
                             BigDecimal oldvalleysPower = dayPowerproportioncurrentMongo.getValleysPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getValleysPower();
@@ -312,10 +343,20 @@ public class LeanModelStatistics {
                             // 运行时常处理
                             BigDecimal oldvalleysIngTime = dayPowerproportioncurrentMongo.getValleysIngTime() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getValleysIngTime();
                             ((Update) update).set("valleysIngTime", oldvalleysIngTime.add(runTime));
-                            // 占比
+                            // 占比核算
                             if(valleysPower.compareTo(new BigDecimal("0.00")) > 0) {
                                 ((Update) update).set("valleysProportion", valleysPower.divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
                             }
+                            // 其他三个重新核算
+                            if(dayPowerproportioncurrentMongo.getFlatPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("flatProportion", dayPowerproportioncurrentMongo.getFlatPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
+                            if(dayPowerproportioncurrentMongo.getPeaksPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("peaksProportion", dayPowerproportioncurrentMongo.getPeaksPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
+                            if(dayPowerproportioncurrentMongo.getTopsPower().compareTo(new BigDecimal("0.00")) > 0) {
+                                ((Update) update).set("topsProportion", dayPowerproportioncurrentMongo.getTopsPower().divide(runNewPower, 2, RoundingMode.HALF_UP).multiply(zb));
+                            }
                         }
                         mongoTemplate.updateFirst(queryDayPowerproportioncurrentRun, update, DeviceStatiscsModelMongodb.class, dayPowerproportioncurrentRunMonKey);
                     } else { // 为空直接插入
@@ -483,14 +524,16 @@ public class LeanModelStatistics {
                         query.addCriteria(Criteria.where("classs").is(classs));
                     }
                     FpgStatiscsModelMongodb fpgStatiscsModelMongo = mongoTemplate.findOne(query, FpgStatiscsModelMongodb.class, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
+                    // 功率
+                    BigDecimal activePower = fpgGatherData.getActivePower().divide(new BigDecimal("12"), 8, RoundingMode.HALF_UP);
+                    // 电流
+                    BigDecimal selectricCurrent = fpgGatherData.getRunCurrent() == null ? new BigDecimal("0.00") : fpgGatherData.getRunCurrent();
                     if(fpgStatiscsModelMongo != null){ // 不为空处理
                         // 基础数据变更不受条件影响
                         UpdateDefinition update = new Update();
                         ((Update) update).set("updateTime", curentDate);
                         // 功率 5 分钟上报一次  除以 12
-                        BigDecimal activePower = fpgGatherData.getActivePower() == null ? new BigDecimal("0.00") : fpgGatherData.getActivePower().divide(new BigDecimal("12"), 6, RoundingMode.HALF_UP);
-                        // 电流
-                        BigDecimal selectricCurrent = fpgGatherData.getRunCurrent() == null ? new BigDecimal("0.00") : fpgGatherData.getRunCurrent();
+                        activePower = fpgGatherData.getActivePower() == null ? new BigDecimal("0.00") : activePower;
                         BigDecimal oldPower = fpgStatiscsModelMongo.getPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getPower();
                         BigDecimal oldingTime = fpgStatiscsModelMongo.getIngTime() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getIngTime();
                         // 总运行时间处理
@@ -585,6 +628,75 @@ public class LeanModelStatistics {
                         mongoTemplate.updateFirst(query, update, FpgStatiscsModelMongodb.class, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
                     } else { // 为空直接插入
                         fpgGatherUpdateList.add(fpgGatherData);
+                        fpgStatiscsModelData.setPower(activePower); // 总功率处理
+                        if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1) { // 运行时长统计
+                            fpgStatiscsModelData.setIngTime(runTime);   // 运行时常
+                        }
+                        // 电流处理
+                        if(fpgLeanModeInfo.getElectricCurrent() != null && fpgLeanModeInfo.getElectricCurrent() == 1){
+                            if("tops".equals(jfpgStr.get())) { // 尖
+                                fpgStatiscsModelData.setTopSelectricCurrent(selectricCurrent);
+                            } else if("peaks".equals(jfpgStr.get())){ // 峰
+                                fpgStatiscsModelData.setPeaksSelectricCurrent(selectricCurrent);
+                            } else if("flat".equals(jfpgStr.get())) { // 平
+                                fpgStatiscsModelData.setFlatSelectricCurrent(selectricCurrent);
+                            } else if("valleys".equals(jfpgStr.get())) { // 谷
+                                fpgStatiscsModelData.setValleysSelectricCurrent(selectricCurrent);
+                            }
+                        }
+                        // 尖峰平谷判定
+                        if("tops".equals(jfpgStr.get())){ // 尖
+                            fpgStatiscsModelData.setTopsPower(activePower); // 功率
+                            // 运行时常处理
+                            if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){ // 运行时长统计
+                                fpgStatiscsModelData.setTopsPower(runTime);
+                            }
+                            // 金额处理
+                            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())){ // 峰
+                            // 功率处理
+                            fpgStatiscsModelData.setPeaksPower(activePower); // 功率
+                            // 运行时常处理
+                            if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){ // 运行时长统计
+                                fpgStatiscsModelData.setPeaksIngTime(runTime);
+                            }
+                            // 金额处理
+                            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())){ // 平
+                            // 功率处理
+                            fpgStatiscsModelData.setFlatPower(activePower); // 功率
+                            // 运行时常处理
+                            if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){ // 运行时长统计
+                                fpgStatiscsModelData.setFlatIngTime(runTime);
+                            }
+                            // 金额处理
+                            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())){ // 谷
+                            // 功率处理
+                            fpgStatiscsModelData.setValleysPower(activePower); // 功率
+                            // 运行时常处理
+                            if(fpgLeanModeInfo.getRunTime() != null && fpgLeanModeInfo.getRunTime() == 1){ // 运行时长统计
+                                fpgStatiscsModelData.setValleysIngTime(runTime);
+                            }
+                            // 金额处理
+                            if(fpgLeanModeInfo.getValleysPrice() != null && fpgLeanModeInfo.getValleysPrice().compareTo(new BigDecimal("0.00")) > 0) {
+                                BigDecimal amount = activePower.multiply(fpgLeanModeInfo.getValleysPrice()); // 金额处理
+                                fpgStatiscsModelData.setAmount(amount);
+                                fpgStatiscsModelData.setValleysAmount(amount);
+                            }
+                        }
                         // 将点位数据存入mongo中
                         mongoTemplate.insert(fpgStatiscsModelData, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
                     }
@@ -608,6 +720,13 @@ public class LeanModelStatistics {
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         LocalDateTime start_time = LocalDateTime.parse(startTime, formatter);
         LocalDateTime end_time = LocalDateTime.parse(endTime, formatter);
+
+        // 判断是否跨天
+        if (end_time.isBefore(start_time)) {
+            end_time = end_time.plusDays(1);  // 跨天时,结束时间加1天
+        }
+
+        // 检查createTime是否在区间内
         return createTime!= null && (createTime.isAfter(start_time) || createTime.equals(start_time)) &&
                 (createTime.isBefore(end_time) || createTime.equals(end_time));
     }

+ 0 - 4
jeecg-module-gather/src/main/java/org/jeecg/modules/watch/PostgreSQLWatch.java

@@ -130,8 +130,6 @@ public class PostgreSQLWatch {
                         log.info(JSON.toJSONString(fpgGatherInsert));
                         fpgGatherDataMapper.insert(fpgGatherInsert);
                     } else { // 编辑处理
-                        log.info("修改---前数据----数据处理---" + value);
-                        log.info(JSON.toJSONString(fpgGatherData));
                         // 处理数据点类型和值的累计
                         if ("Ia".equals(point.getCurrentPower())) {
                             BigDecimal runCurrent = fpgGatherData.getRunCurrent() == null ? value : fpgGatherData.getRunCurrent().add(value);
@@ -141,8 +139,6 @@ public class PostgreSQLWatch {
                             fpgGatherData.setActivePower(activePower);
                         }
                         fpgGatherData.setId(fpgGatherData.getId());
-                        log.info("修改---后数据----数据处理---");
-                        log.info(JSON.toJSONString(fpgGatherData));
                         fpgGatherDataMapper.updateById(fpgGatherData);
                     }
                     // 如果 systemVariable 为空,则不执行后续操作 更新设备状态