Browse Source

染整米长和开动产线使用真实数据

wukai 1 week ago
parent
commit
bf9bb6f273

+ 11 - 1
jjt-admin/src/test/java/com/jjt/task/YhjTaskTest.java

@@ -4,6 +4,7 @@ import com.jjt.JjtApplication;
 import com.jjt.calc.service.ITwinCalcDayYhjService;
 import com.jjt.calc.service.ITwinCalcHourYhjService;
 import com.jjt.utils.IotService;
+import com.jjt.ws.service.ITwinWorkshopCalcService;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 
@@ -28,6 +29,15 @@ public class YhjTaskTest {
     @Resource
     private ITwinCalcHourYhjService yhjService;
 
+    @Resource
+    private ITwinWorkshopCalcService wsCalcService;
+
+    @Test
+    public void calc() {
+        String st = "2025-05-28";
+        LocalDate localDate = LocalDate.parse(st);
+        wsCalcService.calc(localDate);
+    }
 
     @Test
     public void last() {
@@ -47,7 +57,7 @@ public class YhjTaskTest {
     public void test() {
         iotService.setToken();
         String st = "2025-05-28";
-        String ed = "2025-05-28";
+        String ed = "2025-05-30";
         LocalDate localDate = LocalDate.parse(st);
         LocalDate endDate = LocalDate.parse(ed);
         LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(7);

+ 1 - 0
jjt-biz/src/main/java/com/jjt/biz/service/impl/ApiAllServiceImpl.java

@@ -350,6 +350,7 @@ public class ApiAllServiceImpl implements IApiAllService {
         CurrYieldVO currYieldVO = currYield();
         CurrYieldVO.RZ rz = currYieldVO.getRz();
         rz.setYield(rzVO.getStatus().getLength());
+        rz.setOpenLine(rzVO.getStatus().getOpenProd());
         rz.setYieldMax(BigDecimal.valueOf(200000));
         vo.setCurrYield(currYieldVO);
         vo.setProdTrade(prodTrade());

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

@@ -2,6 +2,7 @@ package com.jjt.biz.service.impl;
 
 import com.jjt.biz.service.IApiYrService;
 import com.jjt.biz.vo.*;
+import com.jjt.calc.domain.TwinCalcHourYhj;
 import com.jjt.common.constant.CacheConstants;
 import com.jjt.common.core.redis.RedisCache;
 import com.jjt.common.utils.DateUtils;
@@ -15,6 +16,8 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDate;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 /**
  * 首页统计数据
@@ -57,8 +60,56 @@ public class ApiYrServiceImpl implements IApiYrService {
             arr[i] = vo;
         }
         YrProdEfficiencyVO line0 = new YrProdEfficiencyVO(0);
-        for (int i = 1; i < 9; i++) {
-            YrProdEfficiencyVO vo = arr[i];
+//        for (int i = 1; i < 9; i++) {
+//            YrProdEfficiencyVO vo = arr[i];
+//            line0.setEffA(line0.getEffA().add(vo.getEffA()));
+//            line0.setEffB(line0.getEffB().add(vo.getEffB()));
+//            line0.setTimeA(line0.getTimeA().add(vo.getTimeA()));
+//            line0.setTimeB(line0.getTimeB().add(vo.getTimeB()));
+//            line0.setLengthA(line0.getLengthA().add(vo.getLengthA()));
+//            line0.setLengthB(line0.getLengthB().add(vo.getLengthB()));
+//            line0.setWeightA(line0.getWeightA().add(vo.getWeightA()));
+//            line0.setWeightB(line0.getWeightB().add(vo.getWeightB()));
+//            line0.setWeight(line0.getWeight().add(vo.getWeight()));
+//            line0.setLength(line0.getLength().add(vo.getLength()));
+//
+//        }
+
+        List<TwinCalcHourYhj> calcList = redisCache.getCacheObject(CacheConstants.YHJ_TODAY);
+        Map<Long, Map<String, Integer>> sumByDeviceAndTeam = calcList.stream()
+                .collect(Collectors.groupingBy(
+                        TwinCalcHourYhj::getDeviceId,
+                        Collectors.groupingBy(
+                                TwinCalcHourYhj::getTeam,
+                                Collectors.summingInt(TwinCalcHourYhj::getLength)
+                        )
+                ));
+        AtomicInteger openTimes = new AtomicInteger(0);
+        sumByDeviceAndTeam.forEach((deviceId, teamMap) -> {
+            Integer lengthA = teamMap.get("A");
+            Integer lengthB = teamMap.get("B");
+            Integer length = lengthA + lengthB;
+            YrProdEfficiencyVO vo = arr[deviceId.intValue()];
+            if (length > 0) {
+                openTimes.incrementAndGet();
+            } else {
+                vo.setOpen(0);
+                vo.setRatio(BigDecimal.ZERO);
+                vo.setTimeA(BigDecimal.ZERO);
+                vo.setTimeB(BigDecimal.ZERO);
+                vo.setEffA(BigDecimal.ZERO);
+                vo.setEffB(BigDecimal.ZERO);
+            }
+            BigDecimal weightA = BigDecimal.valueOf(lengthA).divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP);
+            BigDecimal weightB = BigDecimal.valueOf(lengthB).divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP);
+            BigDecimal weight = BigDecimal.valueOf(length).divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP);
+            vo.setLengthA(BigDecimal.valueOf(lengthA));
+            vo.setLengthB(BigDecimal.valueOf(lengthB));
+            vo.setWeightA(weightA);
+            vo.setWeightB(weightB);
+            vo.setWeight(weight);
+            vo.setLength(BigDecimal.valueOf(length));
+
             line0.setEffA(line0.getEffA().add(vo.getEffA()));
             line0.setEffB(line0.getEffB().add(vo.getEffB()));
             line0.setTimeA(line0.getTimeA().add(vo.getTimeA()));
@@ -69,8 +120,7 @@ public class ApiYrServiceImpl implements IApiYrService {
             line0.setWeightB(line0.getWeightB().add(vo.getWeightB()));
             line0.setWeight(line0.getWeight().add(vo.getWeight()));
             line0.setLength(line0.getLength().add(vo.getLength()));
-
-        }
+        });
 
         line0.setEffA(line0.getEffA().divide(BigDecimal.valueOf(8), 2, RoundingMode.HALF_UP));
         line0.setEffB(line0.getEffB().divide(BigDecimal.valueOf(8), 2, RoundingMode.HALF_UP));
@@ -148,6 +198,7 @@ public class ApiYrServiceImpl implements IApiYrService {
         YrProdLineStatusVO status = status();
         vo.setStatus(status);
         List<YrProdEfficiencyVO> effList = eff();
+        int open = 0;
         for (YrProdEfficiencyVO eff : effList) {
             if (eff.getLine() == 0) {
                 status.setWeight(eff.getWeight().setScale(0, RoundingMode.HALF_UP));
@@ -155,8 +206,13 @@ public class ApiYrServiceImpl implements IApiYrService {
                 Random random = new Random();
                 BigDecimal baiPi = eff.getLength().multiply(BigDecimal.valueOf(0.5 + random.nextDouble())).setScale(0, RoundingMode.HALF_UP);
                 status.setBaiPei(baiPi);
+            } else {
+                if (eff.getLength().compareTo(BigDecimal.ZERO) > 0) {
+                    open++;
+                }
             }
         }
+        status.setOpenProd(open);
         vo.setEff(effList);
         TwinRzCalcMonth calcMonth = new TwinRzCalcMonth();
         Map<String, Object> params = new HashMap<>(16);

+ 1 - 4
jjt-biz/src/main/java/com/jjt/calc/service/ITwinCalcHourYhjService.java

@@ -4,7 +4,6 @@ import com.jjt.calc.domain.TwinCalcHourYhj;
 
 import java.time.LocalDateTime;
 import java.util.List;
-import java.util.Map;
 
 /**
  * 印花机1小时统计数据Service接口
@@ -81,10 +80,8 @@ public interface ITwinCalcHourYhjService {
 
     /**
      * 统计当日数据
-     *
-     * @return 结果
      */
-    Map<Long, Integer> today();
+    void today();
 
     /**
      * 按指定时间统计

+ 7 - 7
jjt-biz/src/main/java/com/jjt/calc/service/impl/TwinCalcHourYhjServiceImpl.java

@@ -6,6 +6,8 @@ import com.jjt.calc.domain.TwinCalcHourYhj;
 import com.jjt.calc.mapper.TwinCalcHourYhjMapper;
 import com.jjt.calc.service.ITwinCalcDayYhjService;
 import com.jjt.calc.service.ITwinCalcHourYhjService;
+import com.jjt.common.constant.CacheConstants;
+import com.jjt.common.core.redis.RedisCache;
 import com.jjt.common.utils.DateUtils;
 import com.jjt.utils.AsyncYhjService;
 import com.jjt.utils.IotService;
@@ -49,6 +51,8 @@ public class TwinCalcHourYhjServiceImpl implements ITwinCalcHourYhjService {
     private ITwinCalcDayYhjService dayYhjService;
     @Resource
     private AsyncYhjService asyncYhjService;
+    @Resource
+    private RedisCache redisCache;
 
     /**
      * 查询印花机1小时统计数据
@@ -157,7 +161,7 @@ public class TwinCalcHourYhjServiceImpl implements ITwinCalcHourYhjService {
      * 统计当日数据
      */
     @Override
-    public Map<Long, Integer> today() {
+    public void today() {
         //计算统计时间
         Pair<Date, Date> pair = Tools.calcToday();
         Date sTime = pair.getKey();
@@ -173,13 +177,9 @@ public class TwinCalcHourYhjServiceImpl implements ITwinCalcHourYhjService {
         LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(lastRecord.getHour() + 1);
         List<TwinCalcHourYhj> calcList = process(start, LocalDateTime.now());
         hourList.addAll(calcList);
-        Map<Long, Integer> sumByDevice = calcList.stream()
-                .collect(Collectors.groupingBy(
-                        TwinCalcHourYhj::getDeviceId,
-                        Collectors.summingInt(TwinCalcHourYhj::getLength)
-                ));
+        hourList.forEach(TwinCalcHourYhj::setTeam);
 
-        return sumByDevice;
+        redisCache.setCacheObject(CacheConstants.YHJ_TODAY, hourList);
     }
 
     /**

+ 1 - 1
jjt-biz/src/main/java/com/jjt/rz/domain/TwinDeviceRz.java

@@ -45,7 +45,7 @@ public class TwinDeviceRz extends BaseEntity{
     /** 设备类型名称 */
     @ApiModelProperty("设备类型名称")
     @Excel(name = "设备类型名称")
-    private String deviceType;
+    private String typeName;
 
     /** 设备编码 */
     @ApiModelProperty("设备编码")

+ 9 - 0
jjt-biz/src/main/java/com/jjt/task/IndexTask.java

@@ -3,6 +3,7 @@ package com.jjt.task;
 import com.jjt.biz.service.IApiAllService;
 import com.jjt.biz.service.IApiService;
 import com.jjt.biz.service.IApiYrService;
+import com.jjt.calc.service.ITwinCalcHourYhjService;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
@@ -18,6 +19,8 @@ public class IndexTask {
     @Resource
     private IApiService apiService;
     @Resource
+    private ITwinCalcHourYhjService yhjService;
+    @Resource
     private IApiAllService apiAllService;
     @Resource
     private IApiYrService apiYrService;
@@ -27,6 +30,7 @@ public class IndexTask {
      */
     public void curr() {
         apiService.curr();
+        yhjService.curr();
     }
 
     /**
@@ -35,6 +39,11 @@ public class IndexTask {
 
     public void today() {
         try {
+            yhjService.today();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        try {
             apiYrService.mock();
         } catch (Exception e) {
             e.printStackTrace();

+ 1 - 1
jjt-biz/src/main/java/com/jjt/utils/AsyncYhjService.java

@@ -88,7 +88,7 @@ public class AsyncYhjService {
         String sql = "select %s from " + yhj.getDevicePath() + " where time>%s and time <=%s";
 
         sql = String.format(sql, String.join(",", fields), startTime, endTime);
-        JSONObject jsonObject = iotService.query(sql);
+            JSONObject jsonObject = iotService.query(sql);
         JSONObject data = jsonObject.getJSONObject("data");
         JSONArray columnNames = data.getJSONArray("columnNames");
         JSONArray values = data.getJSONArray("values");

+ 1 - 1
jjt-biz/src/main/java/com/jjt/utils/IotTools.java

@@ -36,7 +36,7 @@ public class IotTools {
                 break; // 退出循环
             } catch (Exception e) {
                 e.printStackTrace();
-                log.error("接口返回数据失败,正在第{}次重新请求!!!", times++);
+                log.error("接口返回数据失败,正在第{}次重新请求!!!,请求体:{}", times++,request);
                 if (times > 5) {
                     log.error("重新5次未获取到数据!!!");
                     throw new RuntimeException("重试5次未获取到数据!!!");

+ 11 - 11
jjt-biz/src/main/resources/mapper/rz/TwinDeviceRzMapper.xml

@@ -3,13 +3,13 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.jjt.rz.mapper.TwinDeviceRzMapper">
-    
+
     <resultMap type="TwinDeviceRz" id="TwinDeviceRzResult">
         <result property="deviceId"    column="DEVICE_ID"    />
         <result property="wsName"    column="WS_NAME"    />
         <result property="line"    column="LINE"    />
         <result property="typeId"    column="TYPE_ID"    />
-        <result property="deviceType"    column="DEVICE_TYPE"    />
+        <result property="typeName"    column="TYPE_NAME"    />
         <result property="deviceCode"    column="DEVICE_CODE"    />
         <result property="deviceName"    column="DEVICE_NAME"    />
         <result property="devicePath"    column="DEVICE_PATH"    />
@@ -21,16 +21,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectTwinDeviceRzVo">
-        select DEVICE_ID, WS_NAME, LINE, TYPE_ID, DEVICE_TYPE, DEVICE_CODE, DEVICE_NAME, DEVICE_PATH, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME, REMARK from TWIN_DEVICE_RZ
+        select DEVICE_ID, WS_NAME, LINE, TYPE_ID, TYPE_NAME, DEVICE_CODE, DEVICE_NAME, DEVICE_PATH, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME, REMARK from TWIN_DEVICE_RZ
     </sql>
 
     <select id="selectTwinDeviceRzList" parameterType="TwinDeviceRz" resultMap="TwinDeviceRzResult">
         <include refid="selectTwinDeviceRzVo"/>
-        <where>  
+        <where>
             <if test="wsName != null  and wsName != ''"> and WS_NAME like concat('%', #{wsName}, '%')</if>
             <if test="line != null  and line != ''"> and LINE = #{line}</if>
             <if test="typeId != null "> and TYPE_ID = #{typeId}</if>
-            <if test="deviceType != null  and deviceType != ''"> and DEVICE_TYPE = #{deviceType}</if>
+            <if test="typeName != null  and typeName != ''"> and TYPE_NAME = #{typeName}</if>
             <if test="deviceCode != null  and deviceCode != ''"> and DEVICE_CODE = #{deviceCode}</if>
             <if test="deviceName != null  and deviceName != ''"> and DEVICE_NAME like concat('%', #{deviceName}, '%')</if>
             <if test="devicePath != null  and devicePath != ''"> and DEVICE_PATH = #{devicePath}</if>
@@ -41,7 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="remark != null  and remark != ''"> and REMARK = #{remark}</if>
         </where>
     </select>
-    
+
     <select id="selectTwinDeviceRzByDeviceId" parameterType="Long" resultMap="TwinDeviceRzResult">
         <include refid="selectTwinDeviceRzVo"/>
         where DEVICE_ID = #{deviceId}
@@ -53,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="wsName != null">WS_NAME,</if>
             <if test="line != null">LINE,</if>
             <if test="typeId != null">TYPE_ID,</if>
-            <if test="deviceType != null">DEVICE_TYPE,</if>
+            <if test="typeName != null">TYPE_NAME,</if>
             <if test="deviceCode != null">DEVICE_CODE,</if>
             <if test="deviceName != null">DEVICE_NAME,</if>
             <if test="devicePath != null">DEVICE_PATH,</if>
@@ -67,7 +67,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="wsName != null">#{wsName},</if>
             <if test="line != null">#{line},</if>
             <if test="typeId != null">#{typeId},</if>
-            <if test="deviceType != null">#{deviceType},</if>
+            <if test="typeName != null">#{typeName},</if>
             <if test="deviceCode != null">#{deviceCode},</if>
             <if test="deviceName != null">#{deviceName},</if>
             <if test="devicePath != null">#{devicePath},</if>
@@ -85,7 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="wsName != null">WS_NAME = #{wsName},</if>
             <if test="line != null">LINE = #{line},</if>
             <if test="typeId != null">TYPE_ID = #{typeId},</if>
-            <if test="deviceType != null">DEVICE_TYPE = #{deviceType},</if>
+            <if test="typeName != null">TYPE_NAME = #{typeName},</if>
             <if test="deviceCode != null">DEVICE_CODE = #{deviceCode},</if>
             <if test="deviceName != null">DEVICE_NAME = #{deviceName},</if>
             <if test="devicePath != null">DEVICE_PATH = #{devicePath},</if>
@@ -103,9 +103,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteTwinDeviceRzByDeviceIds" parameterType="String">
-        delete from TWIN_DEVICE_RZ where DEVICE_ID in 
+        delete from TWIN_DEVICE_RZ where DEVICE_ID in
         <foreach item="deviceId" collection="array" open="(" separator="," close=")">
             #{deviceId}
         </foreach>
     </delete>
-</mapper>
+</mapper>

+ 4 - 0
jjt-common/src/main/java/com/jjt/common/constant/CacheConstants.java

@@ -116,4 +116,8 @@ public class CacheConstants {
      * 设备缓存
      */
     public static final String DEVICE_ALL = TWIN + "deviceAll";
+    /**
+     * 印花机今日数据
+     */
+    public static final String YHJ_TODAY = "yhjToday";
 }