From 4e3b8155722b66e25df3c6fd42cc586b68dea391 Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期五, 06 六月 2025 13:55:39 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassTask.java |  165 ++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 103 insertions(+), 62 deletions(-)

diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassTask.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassTask.java
index 51d94ae..8cba008 100644
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassTask.java
+++ b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/OpcCacheGlassTask.java
@@ -26,8 +26,6 @@
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
@@ -51,20 +49,10 @@
     @Autowired(required = false)
     MiloService miloService;
 
-
-//    @Resource(name = "cacheGlassStartCallback")
-//    SubscriptionCallback cacheGlassStartCallback;
-//
-//    @Resource(name = "cacheGlassTestCallback")
-//    SubscriptionCallback cacheGlassTestCallback;
-
     @Resource
     EdgStorageDeviceTaskService edgStorageDeviceTaskService;
-    //    @Resource
-//    EdgGlassTaskQueueInfoService edgGlassTaskQueueInfoService;
     @Autowired
     EdgGlassTaskInfoService edgGlassTaskInfoService;
-
     @Resource
     GlassInfoService glassInfoService;
     @Resource
@@ -76,25 +64,25 @@
     @Resource
     DamageService damageService;
 
-    @Value("${mes.glassGap}")
+//    @Value("${mes.glassGap}")
     private int glassGap;
-    @Value("${mes.threshold}")
+    //    @Value("${mes.threshold}")
     private int threshold;
-    @Value("${mes.cellLength}")
+    //    @Value("${mes.cellLength}")
     private int cellLength;
-    @Value("${mes.ratio}")
+    //    @Value("${mes.ratio}")
     private int ratio;
 
-    @Value("${mes.min.one.firstLength}")
+    //    @Value("${mes.min.one.firstLength}")
     private int minOneFirstLength;
 
-    @Value("${mes.min.one.secondLength}")
+    //    @Value("${mes.min.one.secondLength}")
     private int minOneSecondLength;
 
-    @Value("${mes.min.two.firstLength}")
+    //    @Value("${mes.min.two.firstLength}")
     private int minTwoFirstLength;
 
-    @Value("${mes.min.two.secondLength}")
+    //    @Value("${mes.min.two.secondLength}")
     private int minTwoSecondLength;
 
     private String glassInIdOne = "";
@@ -102,22 +90,12 @@
     private String glassIdOne = "";
     private String glassIdTwo = "";
 
-    //    @Scheduled(fixedDelay = Long.MAX_VALUE)
-//    public void startOneOpcTask() throws Exception {
-//        miloService.subscriptionFromOpcUa(Arrays.asList("mes.WL1.edg_storage_device_one_task[1].task_state"), cacheGlassStartCallback);
-//    }
-//
-//    @Scheduled(fixedDelay = Long.MAX_VALUE)
-//    public void startTwoOpcTask() throws Exception {
-//        miloService.subscriptionFromOpcUa(Arrays.asList("mes.WL2.edg_storage_device_two_task[1].task_state"), cacheGlassStartCallback);
-//    }
-
-    @Scheduled(fixedDelay = 1000)
+//    @Scheduled(fixedDelay = 1000)
     public void startOneOpcTask() {
         startOneOpcTaskChild(EDG_STORAGE_DEVICE_ONE_TASK, 1);
     }
 
-    @Scheduled(fixedDelay = 1000)
+    //    @Scheduled(fixedDelay = 1000)
     public void startTwoOpcTask() {
         startOneOpcTaskChild(EDG_STORAGE_DEVICE_TWO_TASK, 2);
     }
@@ -158,9 +136,12 @@
             log.info("灏嗗惎鍔ㄥ瓙鏀逛负4");
             task.setTaskRunning(Const.GLASS_CACHE_TYPE_RUNNING);
             edgStorageDeviceTaskService.updateTaskMessage(tableName, task);
-        } else {
+        } else if (request == 5) {
             log.info("璁惧锛歿}鐘舵�侊細{}", device, request);
             finishTask(task, tableName);
+        } else {
+            log.info("鐜荤拑寮傚父澶勭悊");
+            damageTask(task, tableName);
         }
 //        } catch (Exception e) {
 //            log.info("鎵ц浠诲姟杩囩▼涓彂鐢熷紓甯革紝浠诲姟瀛梴}锛寋}", task.getTaskState(), e.getMessage());
@@ -171,7 +152,7 @@
     }
 
 
-    @Scheduled(fixedDelay = 1000)
+    //    @Scheduled(fixedDelay = 1000)
     public void edgOneOpcTask() throws Exception {
         EdgStorageDeviceTask task = edgStorageDeviceTaskService.queryTaskMessage(EDG_STORAGE_DEVICE_ONE_TASK);
         String glassId = task.getGlassId();
@@ -182,7 +163,7 @@
         edgTaskChild(glassId, 1);
     }
 
-    @Scheduled(fixedDelay = 1000)
+    //    @Scheduled(fixedDelay = 1000)
     public void edgTwoOpcTask() throws Exception {
         EdgStorageDeviceTask task = edgStorageDeviceTaskService.queryTaskMessage(EDG_STORAGE_DEVICE_TWO_TASK);
         String glassId = task.getGlassId();
@@ -351,7 +332,7 @@
             if (null != edgeData) {
                 GlassInfo glassOutInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, edgeData.getGlassIdOut()));
                 //绗煎唴鐨勭幓鐠冪殑灏哄鏄惁鍜屼笂涓�娆′换鍔′竴鑷�
-                edgStorageCageDetails = edgStorageCageDetailsService.queryEdgStorageDetailsBySize(deviceId, task.getCurrentCell(), glassOutInfo.getWidth(), glassOutInfo.getHeight());
+                edgStorageCageDetails = edgStorageCageDetailsService.queryEdgStorageDetailsBySize(deviceId, task.getCurrentCell(), glassOutInfo.getWidth(), glassOutInfo.getHeight(), 0, 0);
                 if (null == edgStorageCageDetails && StringUtils.isNotBlank(task.getGlassIdIn())) {
                     GlassInfo glassInInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>()
                             .eq(GlassInfo::getGlassId, task.getGlassIdIn())
@@ -365,7 +346,7 @@
             }
         }
         if (null == edgStorageCageDetails) {
-            edgStorageCageDetails = edgStorageCageDetailsService.queryEdgStorageDetailsBySize(deviceId, task.getCurrentCell(), 0, 0);
+            edgStorageCageDetails = edgStorageCageDetailsService.queryEdgStorageDetailsBySize(deviceId, task.getCurrentCell(), 0, 0, 0, 0);
         }
         if (edgStorageCageDetails == null && StringUtils.isNotBlank(task.getGlassIdIn())) {
             //鍜屼笂娆′换鍔′笉瀛樺湪鐩稿悓灏哄
@@ -481,7 +462,6 @@
         Date startDate = new Date();
         log.info("寮�濮嬫墽琛屽畬鎴愪换鍔″悗娓呴櫎鍔ㄤ綔锛屼换鍔′俊鎭负锛歿},琛ㄥ悕涓猴細{},寮�濮嬫椂闂达細{}", task, tableName, startDate);
         Integer cell = task.getStartCell();
-        Integer state = task.getTaskState();
         task.setTaskRunning(Const.GLASS_CACHE_TYPE_EMPTY);
         task.setGlassIdOut("");
         task.setStartCell(0);
@@ -492,20 +472,65 @@
                 .orderByDesc(EdgStorageDeviceTaskHistory::getCreateTime).last("limit 1"));
         //濡傛灉浠诲姟绫诲瀷涓�1锛�3锛屽皢鍒囧壊瀹屾垚鐨勭幓鐠冭嚜鍔ㄦ姤宸�
         if (Const.GLASS_CACHE_TYPE_IN_ALL.contains(taskHistory.getTaskType())) {
-            damageService.autoSubmitReport(taskHistory.getGlassIdIn(), taskHistory.getDeviceId(),"鍒囧壊","杩涘崸鐞�");
+            damageService.autoSubmitReport(taskHistory.getGlassIdIn(), taskHistory.getDeviceId(), "鍒囧壊", "杩涘崸鐞�", 1);
         }
         updateCellRemainWidth(cell, device, taskHistory);
         edgStorageDeviceTaskHistoryService.update(new LambdaUpdateWrapper<EdgStorageDeviceTaskHistory>()
                 .eq(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_NEW)
                 .eq(EdgStorageDeviceTaskHistory::getDeviceId, device)
-                .set(EdgStorageDeviceTaskHistory::getTaskState,
-                        Const.GLASS_CACHE_TYPE_FINISH.equals(state) ? Const.RAW_GLASS_TASK_SUCCESS : Const.RAW_GLASS_TASK_FAILURE)
+                .set(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_SUCCESS)
         );
         //鏈�鍚庢洿鏂颁换鍔★紝淇濊瘉浠诲姟鍓嶇殑鍔ㄤ綔閮藉仛瀹�
         edgStorageDeviceTaskService.updateTaskMessage(tableName, task);
         Date endDate = new Date();
         log.info("缁撴潫瀹屾垚浠诲姟鍚庢竻闄ゅ姩浣滐紝琛ㄥ悕涓猴細{},缁撴潫鏃堕棿涓猴細{}锛屽叡鑰楁椂锛歿}ms", tableName, endDate, endDate.getTime() - startDate.getTime());
         return Boolean.TRUE;
+    }
+
+    private boolean damageTask(EdgStorageDeviceTask task, String tableName) {
+        if (task.getTaskState() <= 5) {
+            log.info("浠诲姟鏈彂鐢熷紓甯告竻绌猴紝浠诲姟缁撴潫锛岀數姘旂姸鎬亄},mes鐘舵�亄}", task.getTaskState(), task.getTaskRunning());
+            return Boolean.FALSE;
+        }
+        Date startDate = new Date();
+        log.info("寮�濮嬫墽琛屽紓甯稿鐞嗕换鍔″悗娓呴櫎鍔ㄤ綔锛屼换鍔′俊鎭负锛歿},琛ㄥ悕涓猴細{},寮�濮嬫椂闂达細{}", task, tableName, startDate);
+        int device = tableName.equals("edg_storage_device_one_task") ? 1 : 2;
+        EdgStorageDeviceTaskHistory taskHistory = edgStorageDeviceTaskHistoryService.getOne(new LambdaQueryWrapper<EdgStorageDeviceTaskHistory>()
+                .eq(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_NEW)
+                .eq(EdgStorageDeviceTaskHistory::getDeviceId, device)
+                .orderByDesc(EdgStorageDeviceTaskHistory::getCreateTime).last("limit 1"));
+        Integer cell = taskHistory.getStartCell();
+        Integer taskType = taskHistory.getTaskType();
+        if (Const.GLASS_CACHE_TYPE_IN_ALL.contains(taskType)) {
+            String glassId = taskHistory.getGlassIdIn();
+            edgStorageCageDetailsService.remove(new LambdaQueryWrapper<EdgStorageCageDetails>()
+                    .eq(EdgStorageCageDetails::getDeviceId, device)
+                    .eq(EdgStorageCageDetails::getSlot, cell)
+                    .eq(EdgStorageCageDetails::getGlassId, glassId));
+        } else {
+            String glassId = taskHistory.getGlassIdOut();
+            edgStorageCageDetailsService.update(new LambdaUpdateWrapper<EdgStorageCageDetails>()
+                    .set(EdgStorageCageDetails::getState, Const.GLASS_STATE_IN)
+                    .eq(EdgStorageCageDetails::getDeviceId, device)
+                    .eq(EdgStorageCageDetails::getSlot, cell)
+                    .eq(EdgStorageCageDetails::getGlassId, glassId));
+        }
+
+        updateCellRemainWidth(cell, device, taskHistory);
+        edgStorageDeviceTaskHistoryService.update(new LambdaUpdateWrapper<EdgStorageDeviceTaskHistory>()
+                .eq(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_NEW)
+                .eq(EdgStorageDeviceTaskHistory::getDeviceId, device)
+                .set(EdgStorageDeviceTaskHistory::getTaskState, Const.RAW_GLASS_TASK_FAILURE)
+        );
+        //鏈�鍚庢洿鏂颁换鍔★紝淇濊瘉浠诲姟鍓嶇殑鍔ㄤ綔閮藉仛瀹�
+        task.setTaskRunning(Const.GLASS_CACHE_TYPE_EMPTY);
+        task.setGlassIdOut("");
+        task.setStartCell(0);
+        edgStorageDeviceTaskService.updateTaskMessage(tableName, task);
+        Date endDate = new Date();
+        log.info("瀹屾垚鎵ц寮傚父澶勭悊浠诲姟鍚庢竻闄ゅ姩浣滐紝琛ㄥ悕涓猴細{},缁撴潫鏃堕棿涓猴細{}锛屽叡鑰楁椂锛歿}ms", tableName, endDate, endDate.getTime() - startDate.getTime());
+        return Boolean.TRUE;
+
     }
 
     /**
@@ -535,26 +560,43 @@
                 .last("Limit 1");
         GlassInfo swapGlassInfo = glassInfoService.getOne(queryWrapper);
         if (swapGlassInfo != null && !glassInfo.getGlassId().equals(swapGlassInfo.getGlassId())) {
+            //寰呮浛鎹㈢殑鐜荤拑淇℃伅
+            Integer ishorizontal = glassInfo.getIshorizontal();
+            Integer temperingLayoutId = glassInfo.getTemperingLayoutId();
+            Integer temperingFeedSequence = glassInfo.getTemperingFeedSequence();
+            Integer xCoordinate = glassInfo.getXCoordinate();
+            Integer yCoordinate = glassInfo.getYCoordinate();
+            double angle = glassInfo.getAngle();
+            Integer ruleId = glassInfo.getRuleId();
+            //鏇挎崲鍚庣殑鐜荤拑淇℃伅
+            Integer swapIshorizontal = swapGlassInfo.getIshorizontal();
+            Integer swapTemperingLayoutId = swapGlassInfo.getTemperingLayoutId();
+            Integer swapTemperingFeedSequence = swapGlassInfo.getTemperingFeedSequence();
+            Integer swapXCoordinate = swapGlassInfo.getXCoordinate();
+            Integer swapYCoordinate = swapGlassInfo.getYCoordinate();
+            double swapAngle = swapGlassInfo.getAngle();
+            Integer swapRuleId = swapGlassInfo.getRuleId();
+            //鏇挎崲鐜荤拑淇℃伅
+            glassInfo.setIshorizontal(swapIshorizontal);
+            glassInfo.setTemperingLayoutId(swapTemperingLayoutId);
+            glassInfo.setTemperingFeedSequence(swapTemperingFeedSequence);
+            glassInfo.setXCoordinate(swapXCoordinate);
+            glassInfo.setYCoordinate(swapYCoordinate);
+            glassInfo.setAngle(swapAngle);
+            glassInfo.setRuleId(swapRuleId);
 
-            int patternSequence = glassInfo.getPatternSequence();
-            int xAxis = glassInfo.getXAxis();
-            int yAxis = glassInfo.getYAxis();
-            String swapGlassId = swapGlassInfo.getGlassId();
-            int swapPatternSequence = swapGlassInfo.getPatternSequence();
-            int swapXAxis = swapGlassInfo.getXAxis();
-            int swapYAxis = swapGlassInfo.getYAxis();
-            swapGlassInfo.setGlassId(glassId);
-            swapGlassInfo.setPatternSequence(patternSequence);
-            swapGlassInfo.setXAxis(xAxis);
-            swapGlassInfo.setYAxis(yAxis);
-            glassInfo.setGlassId(swapGlassId);
-            glassInfo.setPatternSequence(swapPatternSequence);
-            glassInfo.setXAxis(swapXAxis);
-            glassInfo.setYAxis(swapYAxis);
+            swapGlassInfo.setIshorizontal(ishorizontal);
+            swapGlassInfo.setTemperingLayoutId(temperingLayoutId);
+            swapGlassInfo.setTemperingFeedSequence(temperingFeedSequence);
+            swapGlassInfo.setXCoordinate(xCoordinate);
+            swapGlassInfo.setYCoordinate(yCoordinate);
+            swapGlassInfo.setAngle(angle);
+            swapGlassInfo.setRuleId(ruleId);
+
             log.info("灏嗙幓鐠儃}鍜岀幓鐠儃}锛屼俊鎭簰鎹�(鍘熺墖搴忓彿鍙婂潗鏍囬櫎澶�),杩涚幓鐠� {}", glassInfo, swapGlassInfo, swapGlassInfo);
             glassInfoService.updateById(swapGlassInfo);
             glassInfoService.updateById(glassInfo);
-            return swapGlassId;
+            return swapGlassInfo.getGlassId();
         }
         return "";
     }
@@ -635,7 +677,7 @@
         return Boolean.TRUE;
     }
 
-    private boolean updateCellRemainWidth(int slot, int device, EdgStorageDeviceTaskHistory taskHistory) {
+    public boolean updateCellRemainWidth(int slot, int device, EdgStorageDeviceTaskHistory taskHistory) {
         List<EdgStorageCageDetails> list = edgStorageCageDetailsService.list(new LambdaQueryWrapper<EdgStorageCageDetails>().eq(EdgStorageCageDetails::getSlot, slot)
                 .eq(EdgStorageCageDetails::getState, Const.GLASS_STATE_IN));
         int remainWidth = cellLength;
@@ -643,10 +685,9 @@
             if (2 == taskHistory.getTaskType()) {
                 remainWidth = 0;
             } else {
-                EdgStorageCage storageCage = edgStorageCageService.getOne(new LambdaQueryWrapper<EdgStorageCage>()
-                        .eq(EdgStorageCage::getDeviceId, device).eq(EdgStorageCage::getSlot, slot));
-                EdgStorageCageDetails bigDetails = list.stream().filter(e -> e.getGlassId().equals(taskHistory.getGlassIdIn())).findFirst().orElse(null);
-                remainWidth = storageCage.getRemainWidth() - glassGap - (int) Math.max(bigDetails.getWidth(), bigDetails.getHeight());
+                for (EdgStorageCageDetails item : list) {
+                    remainWidth = remainWidth - glassGap - (int) Math.max(item.getWidth(), item.getHeight());
+                }
                 if (remainWidth <= 0) {
                     remainWidth = 0;
                 }

--
Gitblit v1.8.0