Bladeren bron

搞定 印花机稼动率

wukai 1 week geleden
bovenliggende
commit
5f8becf48c

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

@@ -64,8 +64,8 @@ public class YhjTaskTest {
     @Test
     @Test
     public void test() {
     public void test() {
         iotService.setToken();
         iotService.setToken();
-        String st = "2025-05-28";
-        String ed = "2025-05-30";
+        String st = "2026-01-01";
+        String ed = "2026-01-05";
         LocalDate localDate = LocalDate.parse(st);
         LocalDate localDate = LocalDate.parse(st);
         LocalDate endDate = LocalDate.parse(ed);
         LocalDate endDate = LocalDate.parse(ed);
         LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(7);
         LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(7);

+ 13 - 0
jjt-biz/src/main/java/com/jjt/calc/domain/TwinCalcDayYhj.java

@@ -99,6 +99,19 @@ public class TwinCalcDayYhj extends BaseEntity {
     @ApiModelProperty("B班重量")
     @ApiModelProperty("B班重量")
     @Excel(name = "B班重量")
     @Excel(name = "B班重量")
     private BigDecimal weightB;
     private BigDecimal weightB;
+    /**
+     * 开机时间(秒)
+     */
+    @ApiModelProperty("开机时间(秒)")
+    @Excel(name = "开机时间(秒)")
+    private Long openTime;
+
+    /**
+     * 关机时间(秒)
+     */
+    @ApiModelProperty("关机时间(秒)")
+    @Excel(name = "关机时间(秒)")
+    private Long closeTime;
 
 
     public void setLength(Integer lengthA, Integer lengthB) {
     public void setLength(Integer lengthA, Integer lengthB) {
         this.lengthA = lengthA == null ? 0 : lengthA;
         this.lengthA = lengthA == null ? 0 : lengthA;

+ 34 - 0
jjt-biz/src/main/java/com/jjt/calc/domain/TwinCalcHourYhj.java

@@ -72,6 +72,24 @@ public class TwinCalcHourYhj extends BaseEntity {
     @ApiModelProperty("班组")
     @ApiModelProperty("班组")
     private String team;
     private String team;
 
 
+    /**
+     * 开机时间(秒)
+     */
+    @ApiModelProperty("开机时间(秒)")
+    @Excel(name = "开机时间(秒)")
+    private Long openTime;
+
+    /**
+     * 关机时间(秒)
+     */
+    @ApiModelProperty("关机时间(秒)")
+    @Excel(name = "关机时间(秒)")
+    private Long closeTime;
+
+    @ApiModelProperty("工作天")
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private Date workDay;
+
     public void setTeam() {
     public void setTeam() {
         if (this.hour >= 7 && this.hour < 19) {
         if (this.hour >= 7 && this.hour < 19) {
             //A班
             //A班
@@ -81,4 +99,20 @@ public class TwinCalcHourYhj extends BaseEntity {
             this.team = "B";
             this.team = "B";
         }
         }
     }
     }
+
+    public void addOpenTime(Long time) {
+        if (this.openTime == null) {
+            this.openTime = 0L;
+        }
+        // 转换为秒
+        this.openTime += time / 1000;
+    }
+
+    public void addCloseTime(Long time) {
+        if (this.closeTime == null) {
+            this.closeTime = 0L;
+        }
+        // 转换为秒
+        this.closeTime += time / 1000;
+    }
 }
 }

+ 4 - 0
jjt-biz/src/main/java/com/jjt/calc/service/impl/TwinCalcDayYhjServiceImpl.java

@@ -133,11 +133,15 @@ public class TwinCalcDayYhjServiceImpl implements ITwinCalcDayYhjService {
             //按班组统计
             //按班组统计
             Map<String, Integer> calcLength = calcMap.get(deviceId).stream().collect(Collectors.groupingBy(TwinCalcHourYhj::getTeam, Collectors.reducing(0, TwinCalcHourYhj::getLength, Integer::sum)));
             Map<String, Integer> calcLength = calcMap.get(deviceId).stream().collect(Collectors.groupingBy(TwinCalcHourYhj::getTeam, Collectors.reducing(0, TwinCalcHourYhj::getLength, Integer::sum)));
             Map<String, BigDecimal> calcWeight = calcMap.get(deviceId).stream().collect(Collectors.groupingBy(TwinCalcHourYhj::getTeam, Collectors.mapping(item -> item.getWeight() == null ? BigDecimal.ZERO : item.getWeight(), Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
             Map<String, BigDecimal> calcWeight = calcMap.get(deviceId).stream().collect(Collectors.groupingBy(TwinCalcHourYhj::getTeam, Collectors.mapping(item -> item.getWeight() == null ? BigDecimal.ZERO : item.getWeight(), Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
+            Long openTime = calcMap.get(deviceId).stream().mapToLong(TwinCalcHourYhj::getOpenTime).sum();
+            Long closeTime = calcMap.get(deviceId).stream().mapToLong(TwinCalcHourYhj::getCloseTime).sum();
             TwinCalcDayYhj calc = new TwinCalcDayYhj();
             TwinCalcDayYhj calc = new TwinCalcDayYhj();
             calc.setDeviceId(deviceId);
             calc.setDeviceId(deviceId);
             calc.setTime(DateUtils.toDate(localDate));
             calc.setTime(DateUtils.toDate(localDate));
             calc.setLength(calcLength.get("A"), calcLength.get("B"));
             calc.setLength(calcLength.get("A"), calcLength.get("B"));
             calc.setWeight(calcWeight.get("A"), calcWeight.get("B"));
             calc.setWeight(calcWeight.get("A"), calcWeight.get("B"));
+            calc.setOpenTime(openTime);
+            calc.setCloseTime(closeTime);
             resultMap.put(deviceId, calc);
             resultMap.put(deviceId, calc);
         }
         }
 
 

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

@@ -83,7 +83,9 @@ public class AsyncYhjService {
         Long startTime = start.toInstant(ZoneOffset.of("+8")).toEpochMilli();
         Long startTime = start.toInstant(ZoneOffset.of("+8")).toEpochMilli();
         Long endTime = end.toInstant(ZoneOffset.of("+8")).toEpochMilli();
         Long endTime = end.toInstant(ZoneOffset.of("+8")).toEpochMilli();
         TwinCalcHourYhj calcYhj = new TwinCalcHourYhj();
         TwinCalcHourYhj calcYhj = new TwinCalcHourYhj();
-        String[] fields = {"Formula_data_set_1", "Formula_data_act_5"};
+        calcYhj.setCloseTime(0L);
+        calcYhj.setOpenTime(0L);
+        String[] fields = {"Formula_data_set_1", "Formula_data_act_5", "Formula_data_act_2"};
 
 
         String sql = "select %s from " + yhj.getDevicePath() + " where time>%s and time <=%s";
         String sql = "select %s from " + yhj.getDevicePath() + " where time>%s and time <=%s";
 
 
@@ -114,15 +116,16 @@ public class AsyncYhjService {
             }
             }
             for (int j = 0; j < columnNames.size(); j++) {
             for (int j = 0; j < columnNames.size(); j++) {
                 String name = columnNames.getStr(j);
                 String name = columnNames.getStr(j);
-                if (name.contains("Formula_data_set_1")) {
-                    //如果是版距,则需要记录变化
-                    if (curr[j] != null && last[j] != null && curr[j].intValue() != last[j].intValue()) {
-                        //这里要用j+1才行
-                        calcLength(j + 1, last, first, total);
-                        combo(calcYhj, start, yhj, last[j], total[j + 1]);
-                        total[j + 1] = 0;
-                    }
-                }
+//                版距暂时没用,取消掉
+//                if (name.contains("Formula_data_set_1")) {
+//                    //如果是版距,则需要记录变化
+//                    if (curr[j] != null && last[j] != null && curr[j].intValue() != last[j].intValue()) {
+//                        //这里要用j+1才行
+//                        calcLength(j + 1, last, first, total);
+//                        combo(calcYhj, start, yhj, last[j], total[j + 1]);
+//                        total[j + 1] = 0;
+//                    }
+//                }
                 if (name.contains("Formula_data_act_5")) {
                 if (name.contains("Formula_data_act_5")) {
                     //如果是米长,则需要记录是否清0
                     //如果是米长,则需要记录是否清0
                     //如果当前值为小于上一个,且上一个值不为0,则计算
                     //如果当前值为小于上一个,且上一个值不为0,则计算
@@ -132,6 +135,33 @@ public class AsyncYhjService {
                         cloneArray(curr, first);
                         cloneArray(curr, first);
                     }
                     }
                 }
                 }
+                if (name.contains("Formula_data_act_2")) {
+                    //如果是速度,则需要判断是否为0
+                    //这里稍微有点复杂,需要根据 curr[j]=0 则判断是close,否则为open,统计数据需要存 timestamps.get(i)-timestamps.get(i-1)
+                    if (curr[j] != null && last[j] != null) {
+                        // 计算时间差(毫秒)
+                        Long timeDiff = timestamps.getLong(i) - timestamps.getLong(i - 1);
+                        if (last[j] > 0) {
+                            // 上一时刻是开启状态
+                            if (curr[j] > 0) {
+                                // 保持开启状态,统计运行时间
+                                calcYhj.addOpenTime(timeDiff);
+                            } else {
+                                // 从开启切换到关闭,统计运行时间
+                                calcYhj.addOpenTime(timeDiff);
+                            }
+                        } else {
+                            // 上一时刻是关闭状态
+                            if (curr[j] > 0) {
+                                // 从关闭切换到开启,统计关机时间(从上次关机到这次启动的时间)
+                                calcYhj.addCloseTime(timeDiff);
+                            } else {
+                                // 保持关闭状态,统计关机时间
+                                calcYhj.addCloseTime(timeDiff);
+                            }
+                        }
+                    }
+                }
             }
             }
             //将本次的值,设为上一条记录了
             //将本次的值,设为上一条记录了
             cloneArray(curr, last);
             cloneArray(curr, last);
@@ -144,8 +174,24 @@ public class AsyncYhjService {
                 calcLength(j + 1, over, first, total);
                 calcLength(j + 1, over, first, total);
                 combo(calcYhj, start, yhj, over[j], total[j + 1]);
                 combo(calcYhj, start, yhj, over[j], total[j + 1]);
             }
             }
+            // 处理速度的最后运行时间或关机时间统计
+            if (name.contains("Formula_data_act_2")) {
+                // 根据最后状态统计运行时间或关机时间
+                if (over[j] != null && timestamps.size() >= 2) {
+                    // 计算最后两个时间点之间的差值
+                    Long lastTimeDiff = timestamps.getLong(timestamps.size() - 1) - timestamps.getLong(timestamps.size() - 2);
+                    if (over[j] > 0) {
+                        // 如果最后时刻设备在运行,则统计运行时间
+                        calcYhj.addOpenTime(lastTimeDiff);
+                    } else {
+                        // 如果最后时刻设备在停止状态,则统计关机时间
+                        calcYhj.addCloseTime(lastTimeDiff);
+                    }
+                }
+            }
         }
         }
 
 
+
         return new AsyncResult<>(calcYhj);
         return new AsyncResult<>(calcYhj);
     }
     }
 
 

+ 11 - 1
jjt-biz/src/main/resources/mapper/calc/TwinCalcDayYhjMapper.xml

@@ -17,6 +17,8 @@
         <result property="lengthB" column="LENGTH_B"/>
         <result property="lengthB" column="LENGTH_B"/>
         <result property="weightB" column="WEIGHT_B"/>
         <result property="weightB" column="WEIGHT_B"/>
         <result property="remark" column="REMARK"/>
         <result property="remark" column="REMARK"/>
+        <result property="openTime" column="OPEN_TIME"/>
+        <result property="closeTime" column="CLOSE_TIME"/>
     </resultMap>
     </resultMap>
 
 
     <sql id="selectTwinCalcDayYhjVo">
     <sql id="selectTwinCalcDayYhjVo">
@@ -31,7 +33,9 @@
                WEIGHT_A,
                WEIGHT_A,
                LENGTH_B,
                LENGTH_B,
                WEIGHT_B,
                WEIGHT_B,
-               REMARK
+               REMARK,
+               OPEN_TIME,
+               CLOSE_TIME
         from TWIN_CALC_DAY_YHJ
         from TWIN_CALC_DAY_YHJ
     </sql>
     </sql>
 
 
@@ -71,6 +75,8 @@
             <if test="lengthB != null">LENGTH_B,</if>
             <if test="lengthB != null">LENGTH_B,</if>
             <if test="weightB != null">WEIGHT_B,</if>
             <if test="weightB != null">WEIGHT_B,</if>
             <if test="remark != null">REMARK,</if>
             <if test="remark != null">REMARK,</if>
+            <if test="openTime != null">OPEN_TIME,</if>
+            <if test="closeTime != null">CLOSE_TIME,</if>
         </trim>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="time != null">#{time},</if>
             <if test="time != null">#{time},</if>
@@ -84,6 +90,8 @@
             <if test="lengthB != null">#{lengthB},</if>
             <if test="lengthB != null">#{lengthB},</if>
             <if test="weightB != null">#{weightB},</if>
             <if test="weightB != null">#{weightB},</if>
             <if test="remark != null">#{remark},</if>
             <if test="remark != null">#{remark},</if>
+            <if test="openTime != null">#{openTime},</if>
+            <if test="closeTime != null">#{closeTime},</if>
         </trim>
         </trim>
     </insert>
     </insert>
 
 
@@ -101,6 +109,8 @@
             <if test="lengthB != null">LENGTH_B = #{lengthB},</if>
             <if test="lengthB != null">LENGTH_B = #{lengthB},</if>
             <if test="weightB != null">WEIGHT_B = #{weightB},</if>
             <if test="weightB != null">WEIGHT_B = #{weightB},</if>
             <if test="remark != null">REMARK = #{remark},</if>
             <if test="remark != null">REMARK = #{remark},</if>
+            <if test="openTime != null">OPEN_TIME = #{openTime},</if>
+            <if test="closeTime != null">CLOSE_TIME = #{closeTime},</if>
         </trim>
         </trim>
         where ID = #{id}
         where ID = #{id}
     </update>
     </update>

+ 18 - 5
jjt-biz/src/main/resources/mapper/calc/TwinCalcHourYhjMapper.xml

@@ -10,9 +10,12 @@
         <result property="hour" column="HOUR"/>
         <result property="hour" column="HOUR"/>
         <result property="deviceId" column="DEVICE_ID"/>
         <result property="deviceId" column="DEVICE_ID"/>
         <result property="length" column="LENGTH"/>
         <result property="length" column="LENGTH"/>
-        <result property="weight" column="WEIGHT"/>
         <result property="distance" column="DISTANCE"/>
         <result property="distance" column="DISTANCE"/>
         <result property="remark" column="REMARK"/>
         <result property="remark" column="REMARK"/>
+        <result property="weight" column="WEIGHT"/>
+        <result property="openTime" column="OPEN_TIME"/>
+        <result property="closeTime" column="CLOSE_TIME"/>
+        <result property="workDay" column="WORK_DAY"/>
     </resultMap>
     </resultMap>
 
 
     <sql id="selectTwinCalcHourYhjVo">
     <sql id="selectTwinCalcHourYhjVo">
@@ -21,9 +24,12 @@
                HOUR,
                HOUR,
                DEVICE_ID,
                DEVICE_ID,
                LENGTH,
                LENGTH,
-               WEIGHT,
                DISTANCE,
                DISTANCE,
-               REMARK
+               REMARK,
+               WEIGHT,
+               OPEN_TIME,
+               CLOSE_TIME,
+               WORK_DAY
         from TWIN_CALC_HOUR_YHJ
         from TWIN_CALC_HOUR_YHJ
     </sql>
     </sql>
 
 
@@ -34,6 +40,7 @@
                 and DATA_DATE between #{params.beginDataDate} and #{params.endDataDate}
                 and DATA_DATE between #{params.beginDataDate} and #{params.endDataDate}
             </if>
             </if>
             <if test="dataDate != null ">and DATA_DATE = #{dataDate}</if>
             <if test="dataDate != null ">and DATA_DATE = #{dataDate}</if>
+            <if test="workDay != null ">and WORK_DAY = #{workDay}</if>
             <if test="hour != null ">and HOUR = #{hour}</if>
             <if test="hour != null ">and HOUR = #{hour}</if>
             <if test="deviceId != null ">and DEVICE_ID = #{deviceId}</if>
             <if test="deviceId != null ">and DEVICE_ID = #{deviceId}</if>
             <if test="length != null ">and LENGTH = #{length}</if>
             <if test="length != null ">and LENGTH = #{length}</if>
@@ -64,18 +71,22 @@
             <if test="hour != null">HOUR,</if>
             <if test="hour != null">HOUR,</if>
             <if test="deviceId != null">DEVICE_ID,</if>
             <if test="deviceId != null">DEVICE_ID,</if>
             <if test="length != null">LENGTH,</if>
             <if test="length != null">LENGTH,</if>
-            <if test="weight != null">WEIGHT,</if>
             <if test="distance != null">DISTANCE,</if>
             <if test="distance != null">DISTANCE,</if>
             <if test="remark != null">REMARK,</if>
             <if test="remark != null">REMARK,</if>
+            <if test="weight != null">WEIGHT,</if>
+            <if test="openTime != null">OPEN_TIME,</if>
+            <if test="closeTime != null">CLOSE_TIME,</if>
         </trim>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="dataDate != null">#{dataDate},</if>
             <if test="dataDate != null">#{dataDate},</if>
             <if test="hour != null">#{hour},</if>
             <if test="hour != null">#{hour},</if>
             <if test="deviceId != null">#{deviceId},</if>
             <if test="deviceId != null">#{deviceId},</if>
             <if test="length != null">#{length},</if>
             <if test="length != null">#{length},</if>
-            <if test="weight != null">#{weight},</if>
             <if test="distance != null">#{distance},</if>
             <if test="distance != null">#{distance},</if>
             <if test="remark != null">#{remark},</if>
             <if test="remark != null">#{remark},</if>
+            <if test="weight != null">#{weight},</if>
+            <if test="openTime != null">#{openTime},</if>
+            <if test="closeTime != null">#{closeTime},</if>
         </trim>
         </trim>
     </insert>
     </insert>
 
 
@@ -89,6 +100,8 @@
             <if test="weight != null">WEIGHT = #{weight},</if>
             <if test="weight != null">WEIGHT = #{weight},</if>
             <if test="distance != null">DISTANCE = #{distance},</if>
             <if test="distance != null">DISTANCE = #{distance},</if>
             <if test="remark != null">REMARK = #{remark},</if>
             <if test="remark != null">REMARK = #{remark},</if>
+            <if test="openTime != null">OPEN_TIME = #{openTime},</if>
+            <if test="closeTime != null">CLOSE_TIME = #{closeTime},</if>
         </trim>
         </trim>
         where ID = #{id}
         where ID = #{id}
     </update>
     </update>