瀏覽代碼

精益模块

guoqiang 7 月之前
父節點
當前提交
750fed9240

+ 58 - 7
jeecg-module-gather/src/main/java/org/jeecg/modules/fpgJob/LeanModelStatistics.java

@@ -22,6 +22,7 @@ import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.time.*;
 import java.time.format.DateTimeFormatter;
@@ -50,19 +51,68 @@ public class LeanModelStatistics {
     @Autowired
     RedisTemplate redisTemplate;
 
+    // 每日3点执行 测试期间1ms一次
+//    @Scheduled(cron = "0 0 03 * * *")
+    @Scheduled(fixedDelay = 1000)
+    public void t2(){
+        changeProportion("1000");
+    } // 1ms
+    public void changeProportion(String freq){
+        log.info("变更占比");
+        // 峰平谷精益模型配置获取
+        LambdaQueryWrapper<FpgLeanModel> leanmodelQuery = new LambdaQueryWrapper<FpgLeanModel>().eq(FpgLeanModel::getStatus, "1");
+        List<FpgLeanModel> fpgLeanModellist = fpgLeanModelService.list(leanmodelQuery);
+        LocalDate today = LocalDate.now(); // 获取今天的日期
+        LocalDate yesterday = today.minusDays(1); // 减去一天,得到昨天的日期
+       /* Criteria criteria = new Criteria();
+        criteria.orOperator(Criteria.where("status").is(0),
+                Criteria.where("status").is(1));*/
+        // 处理数据业务逻辑
+        fpgLeanModellist.stream().filter(fpgLeanModeInfo -> fpgLeanModeInfo.getProportion() != null && fpgLeanModeInfo.getProportion() == 1).forEach(fpgLeanModeInfo -> {
+            Query query = new Query();
+            query.addCriteria(Criteria.where("proportion").is(1)).addCriteria(Criteria.where("dates").is(String.valueOf(yesterday)));
+            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();
+                BigDecimal peaksProportion = fpgStatiscsModelMongoInfo.getPeaksPower();
+                BigDecimal flatProportion = fpgStatiscsModelMongoInfo.getFlatPower();
+                BigDecimal valleysProportion = fpgStatiscsModelMongoInfo.getValleysPower();
+                // 核算占比
+                UpdateDefinition update = new Update();
+                ((Update) update).set("proportion", 2);
+                if(topsProportion.compareTo(new BigDecimal("0.00")) > 0) { // 尖
+                    ((Update) update).set("topsProportion", topsProportion.divide(proportion, 2, RoundingMode.HALF_UP).multiply(zb));
+                }
+                if(peaksProportion.compareTo(new BigDecimal("0.00")) > 0) { // 峰
+                    ((Update) update).set("peaksProportion", peaksProportion.divide(proportion, 2, RoundingMode.HALF_UP).multiply(zb));
+                }
+                if(flatProportion.compareTo(new BigDecimal("0.00")) > 0) { // 平
+                    ((Update) update).set("flatProportion", flatProportion.divide(proportion, 2, RoundingMode.HALF_UP).multiply(zb));
+                }
+                if(valleysProportion.compareTo(new BigDecimal("0.00")) > 0) { // 谷
+                    ((Update) update).set("valleysProportion", valleysProportion.divide(proportion, 2, RoundingMode.HALF_UP).multiply(zb));
+                }
+                // 保存
+                mongoTemplate.updateFirst(query, update, FpgStatiscsModelMongodb.class, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
+            });
+        });
+    }
+
     @Scheduled(fixedDelay = 1000)
     public void t1(){
-        opc("1000");
+        leanModel("1000");
     } // 1ms
 
     // 精益模型统计数据
-    public void opc(String freq){
+    public void leanModel(String freq){
         // 峰平谷精益模型配置获取
         LambdaQueryWrapper<FpgLeanModel> leanmodelQuery = new LambdaQueryWrapper<FpgLeanModel>().eq(FpgLeanModel::getStatus, "1");
         List<FpgLeanModel> fpgLeanModellist = fpgLeanModelService.list(leanmodelQuery);
         log.info("峰平谷模型");
         // 获取当前时间
-        Date curentDate = new Date();
+        Date curentDate = new Date(new Date().getTime() + 8 * 60 * 60 * 1000);
         // 尖峰平谷时段配置
         List<PeaksAndValleysTimeConfig>  peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
         //遍历设备集合
@@ -73,20 +123,21 @@ public class LeanModelStatistics {
                 fpgGatherList.forEach(fpgGatherData -> { // 循环处理采集数据处理
                     try {
                         // 变更记录状态
-                        fpgGatherDataService.updateById(fpgGatherData.getId());
+                        fpgGatherData.setFpgModelState("1");
+                        fpgGatherDataService.updateById(fpgGatherData);
                         String finalDatestr = "";
                         // 统计单位
                         if("minute". equals(fpgLeanModeInfo.getTotalUnit())){ // 分钟
                             finalDatestr = new SimpleDateFormat("HH:mm").format(fpgGatherData.getCreateTime());
                         } else if("hour". equals(fpgLeanModeInfo.getTotalUnit())){ // 小时
-                            finalDatestr = new SimpleDateFormat("HH").format(fpgGatherData.getCreateTime());
+                            finalDatestr = new SimpleDateFormat("HH:00").format(fpgGatherData.getCreateTime());
                         } else if("day". equals(fpgLeanModeInfo.getTotalUnit())){ //
-                            finalDatestr = new SimpleDateFormat("dd").format(fpgGatherData.getCreateTime());
+                            finalDatestr = new SimpleDateFormat("yyyy-MM-dd").format(fpgGatherData.getCreateTime());
                         } 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())){ //
-                            finalDatestr = new SimpleDateFormat("MM").format(fpgGatherData.getCreateTime());
+                            finalDatestr = new SimpleDateFormat("yyyy-MM").format(fpgGatherData.getCreateTime());
                         }
                         String dayDate = new SimpleDateFormat("yyyy-MM-dd").format(fpgGatherData.getCreateTime());
                         String classs = "";

+ 4 - 0
jeecg-module-gather/src/main/java/org/jeecg/modules/gatherData/entity/FpgStatiscsModelData.java

@@ -96,6 +96,9 @@ public class FpgStatiscsModelData{
     /**谷占比%*/
     @ApiModelProperty(value = "谷占比%")
     private BigDecimal valleysProportion;
+    /**占比处理%*/
+    @ApiModelProperty(value = "占比处理")
+    private Integer proportion;
     /**班次*/
     @ApiModelProperty(value = "班次")
     private String classs;
@@ -125,6 +128,7 @@ public class FpgStatiscsModelData{
             this.classs = classs;
         }
         if(fpgLeanModel.getProportion() != null && fpgLeanModel.getProportion() == 1){ // 占比统计
+            this.proportion = 1;
             this.topsProportion = new BigDecimal("0.00");
             this.peaksProportion = new BigDecimal("0.00");
             this.flatProportion = new BigDecimal("0.00");

+ 3 - 0
jeecg-module-gather/src/main/java/org/jeecg/modules/gatherData/entity/FpgStatiscsModelMongodb.java

@@ -96,6 +96,9 @@ public class FpgStatiscsModelMongodb {
     /**谷占比%*/
     @ApiModelProperty(value = "谷占比%")
     private BigDecimal valleysProportion;
+    /**占比处理%*/
+    @ApiModelProperty(value = "占比处理")
+    private Integer proportion;
     /**班次*/
     @ApiModelProperty(value = "班次")
     private String classs;