Browse Source

解决单产线数据不是实际数据

wukai 1 month ago
parent
commit
d8b5d87640

+ 14 - 4
jjt-biz/src/main/java/com/jjt/biz/service/impl/ApiYrServiceImpl.java

@@ -2,7 +2,9 @@ package com.jjt.biz.service.impl;
 
 import com.jjt.biz.service.IApiYrService;
 import com.jjt.biz.vo.*;
+import com.jjt.calc.domain.TwinCalcDayYhj;
 import com.jjt.calc.domain.TwinCalcHourYhj;
+import com.jjt.calc.service.ITwinCalcDayYhjService;
 import com.jjt.common.constant.CacheConstants;
 import com.jjt.common.core.redis.RedisCache;
 import com.jjt.common.utils.DateUtils;
@@ -32,6 +34,8 @@ public class ApiYrServiceImpl implements IApiYrService {
     private RedisCache redisCache;
     @Resource
     private ITwinRzCalcMonthService rzCalcMonthService;
+    @Resource
+    private ITwinCalcDayYhjService calcDayYhjService;
 
     /**
      * 获取产线状态
@@ -179,14 +183,16 @@ public class ApiYrServiceImpl implements IApiYrService {
      *
      * @return 结果
      */
-    public List<YrProdTradeVO> prodTrade(List<TwinRzCalcMonth> list) {
+    public List<YrProdTradeVO> prodTrade(List<TwinRzCalcMonth> list, List<TwinCalcDayYhj> yhjList) {
+        Map<Date, List<TwinCalcDayYhj>> yhjMap = yhjList.stream().collect(Collectors.groupingBy(TwinCalcDayYhj::getTime));
         List<YrProdTradeVO> result = new ArrayList<>();
         for (TwinRzCalcMonth cm : list) {
             YrProdTradeVO vo = new YrProdTradeVO();
             LocalDate ldt = DateUtils.toLocalDate(cm.getDataDate());
+            List<TwinCalcDayYhj> yhjs = yhjMap.get(cm.getDataDate());
             vo.setDate(ldt.getDayOfMonth() + "");
             vo.setTips(ldt.toString());
-            vo.split(cm.getLength(), cm.getWeight());
+            vo.split(yhjs, cm.getLength(), cm.getWeight());
             result.add(vo);
         }
         return result;
@@ -219,10 +225,14 @@ public class ApiYrServiceImpl implements IApiYrService {
         vo.setEff(effList);
         TwinRzCalcMonth calcMonth = new TwinRzCalcMonth();
         Map<String, Object> params = new HashMap<>(16);
-        params.put("start", LocalDate.now().minusDays(30));
+        params.put("start", LocalDate.now().minusDays(30).toString());
+        calcMonth.setParams(params);
         List<TwinRzCalcMonth> list = rzCalcMonthService.selectTwinRzCalcMonthList(calcMonth);
+        TwinCalcDayYhj yhj = new TwinCalcDayYhj();
+        yhj.setParams(params);
+        List<TwinCalcDayYhj> yhjList = calcDayYhjService.selectTwinCalcDayYhjList(yhj);
         calcMonth.setParams(params);
-        vo.setProdTrade(prodTrade(list));
+        vo.setProdTrade(prodTrade(list, yhjList));
         vo.setEnergyTrade(energyTrade(list));
         redisCache.setCacheObject(CacheConstants.RZ_MOCK, vo);
     }

+ 25 - 11
jjt-biz/src/main/java/com/jjt/biz/vo/YrProdTradeVO.java

@@ -1,16 +1,14 @@
 package com.jjt.biz.vo;
 
-import com.jjt.utils.Tools;
+import com.jjt.calc.domain.TwinCalcDayYhj;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 生产趋势视图
@@ -39,23 +37,39 @@ public class YrProdTradeVO {
         }
     }
 
-    public void split(BigDecimal length, BigDecimal weight) {
-        BigDecimal[] avg = Tools.balancedRandomSplit(8);
+    public void split(List<TwinCalcDayYhj> yhjList, BigDecimal length, BigDecimal weight) {
+        Map<Long, TwinCalcDayYhj> yhjMap = new HashMap<>();
+        if (yhjList != null) {
+            yhjMap = yhjList.stream()
+                    .collect(Collectors.toMap(
+                            TwinCalcDayYhj::getDeviceId,
+                            item -> item,
+                            (existing, replacement) -> existing
+                    ));
+        }
         this.line = new ArrayList<>();
         Line line = new Line(0);
         line.setLength(isNull(length));
         line.setWeight(isNull(weight));
         this.line.add(line);
-        for (int i = 0; i < avg.length; i++) {
-            Line line1 = new Line(i);
-            line1.setLength(isNull(length).multiply(avg[i]).setScale(2, RoundingMode.HALF_UP));
-            line1.setWeight(isNull(weight).multiply(avg[i]).setScale(2, RoundingMode.HALF_UP));
+        for (long i = 1; i <= 8; i++) {
+            Line line1 = new Line((int) i);
+            TwinCalcDayYhj yhj = yhjMap.get(i);
+            if (yhj != null) {
+                line1.setLength(BigDecimal.valueOf(yhj.getLength()));
+                line1.setWeight(yhj.getWeight());
+            } else {
+                line1.setLength(BigDecimal.ZERO);
+                line1.setWeight(BigDecimal.ZERO);
+            }
             this.line.add(line1);
         }
     }
+
     private BigDecimal isNull(BigDecimal v) {
         return v != null ? v : BigDecimal.ZERO;
     }
+
     @Data
     @NoArgsConstructor
     public static class Line {

+ 3 - 0
jjt-biz/src/main/resources/mapper/calc/TwinCalcDayYhjMapper.xml

@@ -44,6 +44,9 @@
             <if test="deviceId != null ">and DEVICE_ID = #{deviceId}</if>
             <if test="dayLength != null ">and DAY_LENGTH = #{dayLength}</if>
             <if test="dayWeight != null ">and DAY_WEIGHT = #{dayWeight}</if>
+            <if test="params.start != null and params.start != ''">
+                and TIME >= #{params.start}
+            </if>
         </where>
         order by time desc
     </select>