5 Commits b7476ffaef ... b20658e74f

Author SHA1 Message Date
  wukai b20658e74f 修改染整接口请求方式 2 days ago
  wukai dba2bd35a7 加入印花产量 2 days ago
  wukai 75057bae45 解决act name问题 2 days ago
  wukai 89cc522325 修复中亚蒸汽计算BUG 2 days ago
  wukai 582782a902 添加部分注释 2 days ago

+ 8 - 3
jjt-admin/src/test/java/com/jjt/data/ElecTest.java

@@ -7,6 +7,7 @@ import com.jjt.ws.service.ITwinWorkshopCalcService;
 import javafx.util.Pair;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
@@ -17,6 +18,7 @@ import java.util.Map;
  * 印花机
  */
 @SpringBootTest(classes = JjtApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("devp")
 public class ElecTest {
     @Resource
     private ITwinWorkshopCalcService calcService;
@@ -27,10 +29,13 @@ public class ElecTest {
 
     @Test
     void test() {
-        String st = "2025-03-07";
+        String st = "2025-06-03";
         LocalDate localDate = LocalDate.parse(st);
-        Map<Integer, Pair<String, BigDecimal>> result = priceService.getPrice(localDate);
-        System.err.println(result);
+
+        calcService.calc(localDate);
+
+//        Map<Integer, Pair<String, BigDecimal>> result = priceService.getPrice(localDate);
+//        System.err.println(result);
     }
 
 }

+ 14 - 14
jjt-admin/src/test/java/com/jjt/task/RzTest.java

@@ -128,22 +128,22 @@ public class RzTest {
     public void hour() {
         iotService.setToken();
         String st = "2025-06-01";
-        String ed = "2025-06-03";
+        String ed = "2025-06-06";
         LocalDate localDate = LocalDate.parse(st);
         LocalDate endDate = LocalDate.parse(ed);
         LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(7);
-        hourRzService.hour(start, start.plusHours(1));
-//        LocalDateTime end = LocalDateTime.of(endDate.plusDays(1), LocalTime.MIN).plusHours(6);
-//        LocalDateTime curr = LocalDateTime.now();
-//        if (end.isAfter(curr)) {
-//            end = curr.minusHours(1);
-//        }
-//        do {
-//            int i = start.getHour();
-//            System.err.println(start.toLocalDate().toString() + "\t" + i);
-//            hourRzService.hour(start, start.plusHours(1));
-//            start = start.plusHours(1);
-//        } while (!start.isAfter(end));
+//        hourRzService.hour(start, start.plusHours(1));
+        LocalDateTime end = LocalDateTime.of(endDate.plusDays(1), LocalTime.MIN).plusHours(6);
+        LocalDateTime curr = LocalDateTime.now();
+        if (end.isAfter(curr)) {
+            end = curr.minusHours(1);
+        }
+        do {
+            int i = start.getHour();
+            System.err.println(start.toLocalDate().toString() + "\t" + i);
+            hourRzService.hour(start, start.plusHours(1));
+            start = start.plusHours(1);
+        } while (!start.isAfter(end));
     }
 
     @Test
@@ -203,7 +203,7 @@ public class RzTest {
         req.setEnd(end);
         list.add(req);
 
-        List<CompareVO> vos = apiYrService.compare(list);
+        List<CompareVO> vos = apiYrService.compare(list,true);
         System.err.println(vos.size());
     }
 }

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

@@ -21,7 +21,7 @@ import java.time.LocalTime;
  * @date 2024/5/7 11:49
  */
 @SpringBootTest(classes = JjtApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
-@ActiveProfiles("devp")
+//@ActiveProfiles("devp")
 public class YhjTaskTest {
     @Resource
     private ITwinCalcDayYhjService dayService;

+ 16 - 9
jjt-biz/src/main/java/com/jjt/biz/controller/ApiYrController.java

@@ -1,6 +1,5 @@
 package com.jjt.biz.controller;
 
-import cn.hutool.json.JSONUtil;
 import com.jjt.biz.service.IApiYrService;
 import com.jjt.biz.vo.YrCompareBackReq;
 import com.jjt.biz.vo.YrCompareReq;
@@ -16,9 +15,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -50,17 +47,27 @@ public class ApiYrController extends BaseController {
     @RequestMapping("/api/yr/compare")
     @CrossOrigin(origins = "*")
     @ResponseBody
-    public R<?> compare(@RequestBody YrCompareReq vo) throws IOException {
-        String str = new String(Files.readAllBytes(Paths.get(path)));
-        return R.ok(JSONUtil.parseArray(str));
+    public R<?> compare(@RequestBody YrCompareReq req) {
+        List<YrCompareBackReq> list = new ArrayList<>();
+        YrCompareBackReq req1 = new YrCompareBackReq();
+        req1.setLine(req.getLine1());
+        req1.setStart(req.getS1());
+        req1.setEnd(req.getE1());
+        list.add(req1);
+        YrCompareBackReq req2 = new YrCompareBackReq();
+        req2.setLine(req.getLine2());
+        req2.setStart(req.getS2());
+        req2.setEnd(req.getE2());
+        list.add(req2);
+        return R.ok(service.compare(list, false));
     }
 
     @ApiOperation("后台工艺比对")
     @RequestMapping("/api/yr/compare/back")
     @CrossOrigin(origins = "*")
     @ResponseBody
-    public R<?> compareBack(@RequestBody List<YrCompareBackReq> list)  {
-        return R.ok( service.compare(list));
+    public R<?> compareBack(@RequestBody List<YrCompareBackReq> list) {
+        return R.ok(service.compare(list, true));
     }
 
 

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

@@ -23,7 +23,7 @@ public class TwinDeviceYhj extends BaseEntity{
     /** ID */
     @ApiModelProperty("ID")
     @TableId
-    private Long deviceId;
+    private Integer deviceId;
 
     /** 设备名称 */
     @ApiModelProperty("设备名称")

+ 2 - 1
jjt-biz/src/main/java/com/jjt/biz/service/IApiYrService.java

@@ -48,7 +48,8 @@ public interface IApiYrService {
      * 工艺对比
      *
      * @param list 输入参数
+     * @param flag 是否返回明细参数
      * @return 结果集
      */
-    List<CompareVO> compare(List<YrCompareBackReq> list);
+    List<CompareVO> compare(List<YrCompareBackReq> list,boolean flag);
 }

+ 168 - 114
jjt-biz/src/main/java/com/jjt/biz/service/impl/ApiYrServiceImpl.java

@@ -6,11 +6,11 @@ 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.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.rz.domain.TwinCalcHourRz;
-import com.jjt.rz.domain.TwinDeviceTypeData;
 import com.jjt.rz.service.ITwinCalcHourRzService;
 import com.jjt.rz.service.ITwinDeviceRzService;
 import com.jjt.rz.service.ITwinDeviceTypeService;
@@ -95,7 +95,7 @@ public class ApiYrServiceImpl implements IApiYrService {
 //        }
 
         List<TwinCalcHourYhj> calcList = redisCache.getCacheObject(CacheConstants.YHJ_TODAY);
-        Map<Long, Map<String, Integer>> sumByDeviceAndTeam = calcList.stream()
+        Map<Integer, Map<String, Integer>> sumByDeviceAndTeam = calcList.stream()
                 .collect(Collectors.groupingBy(
                         TwinCalcHourYhj::getDeviceId,
                         Collectors.groupingBy(
@@ -111,7 +111,7 @@ public class ApiYrServiceImpl implements IApiYrService {
                 lengthB = 0;
             }
             Integer length = lengthA + lengthB;
-            YrProdEfficiencyVO vo = arr[deviceId.intValue()];
+            YrProdEfficiencyVO vo = arr[deviceId];
             if (length > 0) {
                 openTimes.incrementAndGet();
             } else {
@@ -284,6 +284,9 @@ public class ApiYrServiceImpl implements IApiYrService {
 
     }
 
+    @Resource
+    private ITwinCalcHourYhjService yhjService;
+
     /**
      * 工艺对比
      *
@@ -291,122 +294,173 @@ public class ApiYrServiceImpl implements IApiYrService {
      * @return 结果集
      */
     @Override
-    public List<CompareVO> compare(List<YrCompareBackReq> reqs) {
+    public List<CompareVO> compare(List<YrCompareBackReq> reqs, boolean flag) {
         List<CompareVO> result = new ArrayList<>();
-        List<TwinDeviceTypeData> all = typeService.selectTwinDeviceTypeDataAll();
-        Map<Long, TwinDeviceTypeData> dataMap = all.stream()
-                .collect(Collectors.toMap(
-                        TwinDeviceTypeData::getDataId,
-                        item -> item,
-                        (existing, replacement) -> existing
-                ));
         for (YrCompareBackReq req : reqs) {
-            CompareVO vo = new CompareVO();
-            vo.setLine(req.getLine());
-            vo.setStart(req.getStart());
-            vo.setEnd(req.getEnd());
-            vo.setYh(10);
-            CompareVO.Qz qz = vo.getQz();
-            CompareVO.Hz hz = vo.getHz();
-            LocalDateTime ldt = req.getEnd().minusHours(1);
-            Date date = Date.from(ldt.toLocalDate().atStartOfDay(ZoneOffset.of("+8")).toInstant());
-            TwinCalcHourRz search = new TwinCalcHourRz();
-            search.setDataDate(date);
-            search.setHour(ldt.getHour());
-            search.setLine(req.getLine());
-            List<TwinCalcHourRz> list = hourRzService.selectTwinCalcHourRzList(search);
-            list.forEach(item -> {
-                Map<String, Object> map = JSON.parseObject(item.getData(), Map.class);
-                map.put("device", item.getDeviceName());
-                map.put("online", item.getOnline());
-
-                if (item.getWsName().equals("Forward")) {
-                    //前整
-                    switch (item.getTypeId()) {
-                        case 2:
-                            //四节定型机
-                            if ("Y".equals(item.getOnline())) {
-                                qz.setDx(qz.getDx() + 1);
-                            }
-                            qz.addDxPara(map);
-                            break;
-                        case 3:
-                            //双棍烫光机
-                            if ("Y".equals(item.getOnline())) {
-                                qz.setTg(qz.getTg() + 1);
-                            }
-                            qz.addTgPara(map);
-                            break;
-                        case 4:
-                            //高梳机
-                            if ("Y".equals(item.getOnline())) {
-                                qz.setGs(qz.getGs() + 1);
-                            }
-                            qz.addGsPara(map);
-                            break;
-                        case 5:
-                            //双棍刷毛
-                            if ("Y".equals(item.getOnline())) {
-                                qz.setSm(qz.getSm() + 1);
-                            }
-                            qz.addSmPara(map);
-                            break;
-                        default:
-                            break;
-                    }
-                } else if (item.getWsName().equals("Back")) {
-                    //后整
-                    switch (item.getTypeId()) {
-                        case 6:
-                            //六节定型机
-                            if ("Y".equals(item.getOnline())) {
-                                hz.setDx(hz.getDx() + 1);
-                            }
-                            hz.addDxPara(map);
-                            break;
-                        case 3:
-                            //双棍烫光机
-                            if ("Y".equals(item.getOnline())) {
-                                hz.setTg(hz.getTg() + 1);
-                            }
-                            hz.addTgPara(map);
-                            break;
-                        case 4:
-                            //高梳机
-                            if ("Y".equals(item.getOnline())) {
-                                hz.setGs(hz.getGs() + 1);
-                            }
-                            hz.addGsPara(map);
-                            break;
-                        case 5:
-                            //双棍刷毛
-                            if ("Y".equals(item.getOnline())) {
-                                hz.setSm(hz.getSm() + 1);
-                            }
-                            hz.addSmPara(map);
-                            break;
-                        case 7:
-                            //起毛机
-                            if ("Y".equals(item.getOnline())) {
-                                hz.setQm(hz.getQm() + 1);
-                            }
-                            hz.addQmPara(map);
-                            break;
-                        case 9:
-                            //烫剪机
-                            if ("Y".equals(item.getOnline())) {
-                                hz.setTj(hz.getTj() + 1);
-                            }
-                            hz.addTjPara(map);
-                            break;
-                        default:
-                            break;
-                    }
-                }
-            });
+            CompareVO vo = itemProcessor(req, flag);
+            int totalLength = getTotalLength(req);
+            vo.setLength(totalLength);
             result.add(vo);
         }
         return result;
     }
 
+    /**
+     * 获取印花产量数据
+     *
+     * @param req 请求
+     * @return 结果
+     */
+    private Integer getTotalLength(YrCompareBackReq req) {
+        //获取印花产量数据
+        TwinCalcHourYhj yhjSearch = new TwinCalcHourYhj();
+        yhjSearch.setDeviceId(req.getLine());
+        Map<String, Object> params = new HashMap<>(16);
+        params.put("sTime", DateUtils.toDate(req.getStart()));
+        params.put("eTime", DateUtils.toDate(req.getEnd()));
+        yhjSearch.setParams(params);
+        List<TwinCalcHourYhj> yhjList = yhjService.selectTwinCalcHourYhjList(yhjSearch);
+        int totalLength = yhjList.stream()
+                .mapToInt(TwinCalcHourYhj::getLength)
+                .sum();
+        return totalLength;
+    }
+
+    private CompareVO itemProcessor(YrCompareBackReq req, boolean flag) {
+        CompareVO vo = new CompareVO();
+        vo.setLine(req.getLine());
+        vo.setStart(req.getStart());
+        vo.setEnd(req.getEnd());
+        vo.setYh(10);
+        CompareVO.Qz qz = vo.getQz();
+        CompareVO.Hz hz = vo.getHz();
+        LocalDateTime ldt = req.getEnd().minusHours(1);
+        Date date = Date.from(ldt.toLocalDate().atStartOfDay(ZoneOffset.of("+8")).toInstant());
+        TwinCalcHourRz search = new TwinCalcHourRz();
+        search.setDataDate(date);
+        search.setHour(ldt.getHour());
+        search.setLine(req.getLine());
+        List<TwinCalcHourRz> list = hourRzService.selectTwinCalcHourRzList(search);
+        list.forEach(item -> {
+            Map<String, Object> map = JSON.parseObject(item.getData(), Map.class);
+            map.put("device", item.getDeviceName());
+            map.put("online", item.getOnline());
+
+            if ("Forward".equals(item.getWsName())) {
+                qzProcessor(qz, item, flag, map);
+            } else if ("Back".equals(item.getWsName())) {
+                hzProcessor(hz, item, flag, map);
+            } else {
+                //留给烘固机
+            }
+        });
+        return vo;
+    }
+
+    private void qzProcessor(CompareVO.Qz qz, TwinCalcHourRz item, boolean flag, Map<String, Object> map) {
+        //前整
+        switch (item.getTypeId()) {
+            case 2:
+                //四节定型机
+                if ("Y".equals(item.getOnline())) {
+                    qz.setDx(qz.getDx() + 1);
+                }
+                if (flag) {
+                    qz.addDxPara(map);
+                }
+                break;
+            case 3:
+                //双棍烫光机
+                if ("Y".equals(item.getOnline())) {
+                    qz.setTg(qz.getTg() + 1);
+                }
+                if (flag) {
+                    qz.addTgPara(map);
+                }
+                break;
+            case 4:
+                //高梳机
+                if ("Y".equals(item.getOnline())) {
+                    qz.setGs(qz.getGs() + 1);
+                }
+                if (flag) {
+                    qz.addGsPara(map);
+                }
+                break;
+            case 5:
+                //双棍刷毛
+                if ("Y".equals(item.getOnline())) {
+                    qz.setSm(qz.getSm() + 1);
+                }
+                if (flag) {
+                    qz.addSmPara(map);
+                }
+                break;
+            default:
+                break;
+        }
+    }
+
+    private void hzProcessor(CompareVO.Hz hz, TwinCalcHourRz item, boolean flag, Map<String, Object> map) {
+        //后整
+        switch (item.getTypeId()) {
+            case 6:
+                //六节定型机
+                if ("Y".equals(item.getOnline())) {
+                    hz.setDx(hz.getDx() + 1);
+                }
+                if (flag) {
+                    hz.addDxPara(map);
+                }
+                break;
+            case 3:
+                //双棍烫光机
+                if ("Y".equals(item.getOnline())) {
+                    hz.setTg(hz.getTg() + 1);
+                }
+                if (flag) {
+                    hz.addTgPara(map);
+                }
+                break;
+            case 4:
+                //高梳机
+                if ("Y".equals(item.getOnline())) {
+                    hz.setGs(hz.getGs() + 1);
+                }
+                if (flag) {
+                    hz.addGsPara(map);
+                }
+                break;
+            case 5:
+                //双棍刷毛
+                if ("Y".equals(item.getOnline())) {
+                    hz.setSm(hz.getSm() + 1);
+                }
+                if (flag) {
+                    hz.addSmPara(map);
+                }
+                break;
+            case 7:
+                //起毛机
+                if ("Y".equals(item.getOnline())) {
+                    hz.setQm(hz.getQm() + 1);
+                }
+                if (flag) {
+                    hz.addQmPara(map);
+                }
+                break;
+            case 9:
+                //烫剪机
+                if ("Y".equals(item.getOnline())) {
+                    hz.setTj(hz.getTj() + 1);
+                }
+                if (flag) {
+                    hz.addTjPara(map);
+                }
+                break;
+            default:
+                break;
+        }
+    }
+
 }

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

@@ -38,7 +38,7 @@ public class YrProdTradeVO {
     }
 
     public void split(List<TwinCalcDayYhj> yhjList, BigDecimal length, BigDecimal weight) {
-        Map<Long, TwinCalcDayYhj> yhjMap = new HashMap<>();
+        Map<Integer, TwinCalcDayYhj> yhjMap = new HashMap<>();
         if (yhjList != null) {
             yhjMap = yhjList.stream()
                     .collect(Collectors.toMap(

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

@@ -43,7 +43,7 @@ public class TwinCalcDayYhj extends BaseEntity {
      */
     @ApiModelProperty("设备ID")
     @Excel(name = "设备ID")
-    private Long deviceId;
+    private Integer deviceId;
 
     /**
      * 自然天统计长度

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

@@ -48,7 +48,7 @@ public class TwinCalcHourYhj extends BaseEntity {
      */
     @ApiModelProperty("设备ID")
     @Excel(name = "设备ID")
-    private Long deviceId;
+    private Integer deviceId;
 
     /**
      * 织造米数

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

@@ -121,9 +121,9 @@ public class TwinCalcDayYhjServiceImpl implements ITwinCalcDayYhjService {
         //设置班组
         list.forEach(TwinCalcHourYhj::setTeam);
         //先按ID分组
-        Map<Long, List<TwinCalcHourYhj>> calcMap = list.stream().collect(Collectors.groupingBy(TwinCalcHourYhj::getDeviceId, LinkedHashMap::new, Collectors.toList()));
-        Map<Long, TwinCalcDayYhj> resultMap = new HashMap<>(16);
-        for (Long deviceId : calcMap.keySet()) {
+        Map<Integer, List<TwinCalcHourYhj>> calcMap = list.stream().collect(Collectors.groupingBy(TwinCalcHourYhj::getDeviceId, LinkedHashMap::new, Collectors.toList()));
+        Map<Integer, TwinCalcDayYhj> resultMap = new HashMap<>(16);
+        for (Integer deviceId : calcMap.keySet()) {
             //按班组统计
             Map<String, Integer> calcTeam = calcMap.get(deviceId).stream().collect(Collectors.groupingBy(TwinCalcHourYhj::getTeam, Collectors.reducing(0, TwinCalcHourYhj::getLength, Integer::sum)));
             TwinCalcDayYhj calc = new TwinCalcDayYhj();
@@ -142,8 +142,8 @@ public class TwinCalcDayYhjServiceImpl implements ITwinCalcDayYhjService {
         list = hourYhjMapper.selectTwinCalcHourYhjList(search);
         List<TwinCalcDayYhj> yhjList = new ArrayList<>();
         //按ID分组统计
-        Map<Long, Integer> calcDay = list.stream().collect(Collectors.groupingBy(TwinCalcHourYhj::getDeviceId, Collectors.reducing(0, TwinCalcHourYhj::getLength, Integer::sum)));
-        for (Long deviceId : calcMap.keySet()) {
+        Map<Integer, Integer> calcDay = list.stream().collect(Collectors.groupingBy(TwinCalcHourYhj::getDeviceId, Collectors.reducing(0, TwinCalcHourYhj::getLength, Integer::sum)));
+        for (Integer deviceId : calcMap.keySet()) {
             TwinCalcDayYhj calc = resultMap.get(deviceId);
             calc.setDayLength(calcDay.get(deviceId));
             yhjList.add(calc);

+ 61 - 35
jjt-biz/src/main/java/com/jjt/rz/service/impl/TwinCalcHourRzServiceImpl.java

@@ -131,60 +131,82 @@ public class TwinCalcHourRzServiceImpl implements ITwinCalcHourRzService {
      */
     @Override
     public void hour(LocalDateTime start, LocalDateTime end) {
+        // 将开始时间转换为Date类型,用于后续查询
         Date date = Date.from(start.toLocalDate().atStartOfDay(ZoneOffset.of("+8")).toInstant());
+        // 将开始和结束时间转换为毫秒,用于后续查询
         Long startTime = start.toInstant(ZoneOffset.of("+8")).toEpochMilli();
         Long endTime = end.toInstant(ZoneOffset.of("+8")).toEpochMilli();
+
+        // 删除已存在的小时级计算结果,避免重复计算
         deleteTwinCalcHourRz(start.toLocalDate(), start.getHour());
+
+        // 获取设备列表
         List<TwinDeviceRz> list = rzService.selectTwinDeviceRzList(new TwinDeviceRz());
+        // 获取设备类型列表
         List<TwinDeviceType> typeList = typeService.selectTwinDeviceTypeAll();
+        // 使用设备类型ID作为键,设备类型作为值,创建设备类型映射
         Map<Long, TwinDeviceType> typeMap = new HashMap<>(16);
-        //存明细数据,key用deviceCode+dataCode
+        // 存储明细数据,使用设备代码和数据代码作为键
         Map<String, TwinDeviceTypeData> detailMap = new HashMap<>(16);
         typeList.forEach(item -> typeMap.put(item.getTypeId(), item));
+
+        // 初始化存储查询结果的列表和映射
         List<String> strList = new ArrayList<>();
         Map<String, TwinDeviceRz> rzMap = new HashMap<>(16);
 
-        //这个集合用来保存数据是属于 设定值 还是mes 还是实际值
+        // 这个映射用于保存数据是属于 设定值 还是mes 还是实际值
         Map<String, Pair<String, String>> clsMap = new HashMap<>(16);
-        //查询状态结尾部分
+        // 查询状态结尾部分
         String statusSuffix = ".Capacity_data_1";
         list.forEach(item -> {
-            String str = item.getDeviceCode() + statusSuffix;
+            String deviceCode = item.getDeviceCode();
+            String str = deviceCode + statusSuffix;
             item.setOnline(false);
-            rzMap.put(item.getDeviceCode(), item);
+            rzMap.put(deviceCode, item);
             strList.add(str);
 
             TwinDeviceType type = typeMap.get(item.getTypeId());
-            type.getTwinDeviceTypeDataList().forEach(detail -> {
-                String suffix1 = "." + detail.getDataCode();
-                strList.add(item.getDeviceCode() + suffix1);
-                clsMap.put(item.getDeviceCode() + suffix1, new Pair<>("set", detail.getDataName()));
-                detailMap.put(item.getDeviceCode() + suffix1, detail);
-                if (StringUtils.isNotEmpty(detail.getMesCode())) {
-                    suffix1 = "." + detail.getMesCode();
-                    strList.add(item.getDeviceCode() + suffix1);
-                    clsMap.put(item.getDeviceCode() + suffix1, new Pair<>("mes", detail.getDataName()));
-                    detailMap.put(item.getDeviceCode() + suffix1, detail);
-                }
+            if (type != null && type.getTwinDeviceTypeDataList() != null) {
+                type.getTwinDeviceTypeDataList().forEach(detail -> {
+                    String suffix1 = "." + detail.getDataCode();
+                    String key1 = deviceCode + suffix1;
+                    strList.add(key1);
+                    clsMap.put(key1, new Pair<>("set", detail.getDataName()));
+                    detailMap.put(key1, detail);
+
+                    if (StringUtils.isNotEmpty(detail.getMesCode())) {
+                        suffix1 = "." + detail.getMesCode();
+                        String key2 = deviceCode + suffix1;
+                        strList.add(key2);
+                        clsMap.put(key2, new Pair<>("mes", detail.getDataName()));
+                        detailMap.put(key2, detail);
+                    }
 
-                if (StringUtils.isNotEmpty(detail.getActCode())) {
-                    JSONArray array = JSONUtil.parseArray(detail.getActCode());
-                    for (int j = 0; j < array.size(); j++) {
-                        JSONObject jsonObject = array.getJSONObject(j);
-                        String suffix2 = "." + jsonObject.getStr("code");
-                        String name = jsonObject.getStr("name");
-                        if (StringUtils.isEmpty(name)) {
-                            name = detail.getDataName();
+                    if (StringUtils.isNotEmpty(detail.getActCode())) {
+                        JSONArray array = JSONUtil.parseArray(detail.getActCode());
+                        for (int j = 0; j < array.size(); j++) {
+                            JSONObject jsonObject = array.getJSONObject(j);
+                            String code = jsonObject.getStr("code");
+                            String name = jsonObject.getStr("name");
+//                            if (StringUtils.isEmpty(name)) {
+//                            name = detail.getDataName();
+//                            }
+                            String suffix2 = "." + code;
+                            String key3 = deviceCode + suffix2;
+                            strList.add(key3);
+                            clsMap.put(key3, new Pair<>("act", name));
+                            detailMap.put(key3, detail);
                         }
-                        strList.add(item.getDeviceCode() + suffix2);
-                        clsMap.put(item.getDeviceCode() + suffix2, new Pair<>("act", name));
-                        detailMap.put(item.getDeviceCode() + suffix2, detail);
                     }
-                }
-            });
+                });
+            }
         });
+
+        // 构建查询SQL
         String sql = "select last %s from root.tl.suxi where time>%s and time <=%s";
         sql = String.format(sql, String.join(",", strList), startTime, endTime);
+
+        // 执行查询并处理结果
         JSONObject jsonObject = iotService.query(sql);
         JSONObject data = jsonObject.getJSONObject("data");
         JSONArray values = data.getJSONArray("values");
@@ -204,20 +226,20 @@ public class TwinCalcHourRzServiceImpl implements ITwinCalcHourRzService {
                     params = new HashMap<>();
                     rz.setParams(params);
                 }
-                //判断状态
+                // 判断状态
                 if (type.contains(statusSuffix)) {
                     if (rz.getTypeId() == 3 || rz.getTypeId() == 5 || rz.getTypeId() == 9) {
-                        //双棍烫光和两棍刷毛需要按照机器状态来判断是否开机
-                        //=1 设备故障停机  ,=2 人工停机 ,=3是缺布/断布停机 ,=4满布停机,=5设备上电待机中  =6设备自动运行中,=7设备过站中
-                        if (value.equals("6")) {
+                        // 双棍烫光和两棍刷毛需要按照机器状态来判断是否开机
+                        //=1 设备故障停机  ,=2 人工停机 ,=3是缺布/断布停机 ,=4满布停机,=5设备上电待机中  =6设备自动运行中,=7设备过站中
+                        if ("6".equals(value)) {
                             rz.setOnline(true);
                         }
                     } else {
-                        //其他类型只需要有值就表示开机
+                        // 其他类型只需要有值就表示开机
                         rz.setOnline(true);
                     }
                 } else {
-                    //工艺参数数据获取
+                    // 工艺参数数据获取
                     String key = deviceCode + "." + dataCode;
                     TwinDeviceTypeData detail = detailMap.get(key);
                     Pair<String, String> clsPair = clsMap.get(key);
@@ -244,6 +266,8 @@ public class TwinCalcHourRzServiceImpl implements ITwinCalcHourRzService {
                 }
             }
         }
+
+        // 构建最终结果列表
         List<TwinCalcHourRz> rzList = new ArrayList<>();
         list.forEach(item -> {
             TwinCalcHourRz calc = new TwinCalcHourRz();
@@ -259,6 +283,7 @@ public class TwinCalcHourRzServiceImpl implements ITwinCalcHourRzService {
             rzList.add(calc);
         });
 
+        // 批量插入计算结果
         try (SqlSession sqlSession = factory.openSession(ExecutorType.BATCH, false)) {
             if (rzList.size() > 0) {
                 TwinCalcHourRzMapper mapper = sqlSession.getMapper(TwinCalcHourRzMapper.class);
@@ -268,6 +293,7 @@ public class TwinCalcHourRzServiceImpl implements ITwinCalcHourRzService {
         }
     }
 
+
     /**
      * 按日期和时间删除数据
      *

+ 4 - 4
jjt-biz/src/main/java/com/jjt/ws/service/impl/TwinRzCalcMonthServiceImpl.java

@@ -183,10 +183,10 @@ public class TwinRzCalcMonthServiceImpl implements ITwinRzCalcMonthService {
                     vo.setQLowUse(calc.getTotalValue());
                     break;
                 case "WS03-Q-ZY":
-                    if (vo.getQMidUse() != null && vo.getQMidUse().intValue() != 0) {
-                        vo.setQMidPrice(calc.getTotalPrice());
-                        vo.setQMidUse(calc.getTotalValue());
-                    }
+//                    if (vo.getQMidUse() != null && vo.getQMidUse().intValue() != 0) {
+                    vo.setQMidPrice(calc.getTotalPrice());
+                    vo.setQMidUse(calc.getTotalValue());
+//                    }
                     break;
                 default:
             }