From e555f50e1bb0cb6b8facca208c70df4dcce06b80 Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期五, 21 六月 2024 14:45:57 +0800
Subject: [PATCH] 大理片笼进出片任务bug修复完毕,自测已完成,待联调

---
 hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java |  177 ++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 104 insertions(+), 73 deletions(-)

diff --git a/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java
index 01aa22e..aebf46d 100644
--- a/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java
+++ b/hangzhoumesParent/moduleService/CacheVerticalGlassModule/src/main/java/com/mes/job/PlcStorageCageTask.java
@@ -5,6 +5,8 @@
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.github.yulichang.toolkit.JoinWrappers;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.mes.base.entity.BigStorageCageBaseInfo;
 import com.mes.bigstorage.entity.BigStorageCage;
 import com.mes.bigstorage.entity.BigStorageCageDetails;
 import com.mes.bigstorage.entity.BigStorageDTO;
@@ -16,7 +18,9 @@
 import com.mes.bigstoragetask.entity.BigStorageCageOutTask;
 import com.mes.bigstoragetask.service.BigStorageCageFeedTaskService;
 import com.mes.bigstoragetask.service.BigStorageCageOutTaskService;
+import com.mes.common.S7object;
 import com.mes.common.config.Const;
+import com.mes.device.PlcParameterObject;
 import com.mes.edgglasstask.entity.EdgGlassTaskInfo;
 import com.mes.edgglasstask.service.EdgGlassTaskInfoService;
 import com.mes.glassinfo.entity.GlassInfo;
@@ -27,13 +31,11 @@
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -63,26 +65,28 @@
     @Value("${mes.sequence.order}")
     private boolean sequenceOrder;
 
+    @Value("${mes.carWidth}")
+    private Integer carWidth;
+
     @Value("${mes.slotWidth}")
     private Integer slotWidth;
 
-    //    @Scheduled(fixedDelay = 5000)
-    public void plcToHomeEdgScan(String d01Id) {
-//        PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
-//        String d01Request = plcParameterObject.getPlcParameter("D01Request").getValue();
-//        String d01Id = plcParameterObject.getPlcParameter("D01ID1").getValue();
-//        String d02SitState = plcParameterObject.getPlcParameter("D02SitState").getValue();
-//        String d04Request = plcParameterObject.getPlcParameter("D04Request").getValue();
-//        String d04Id = plcParameterObject.getPlcParameter("D04ID1").getValue();
-//        String d05SitState = plcParameterObject.getPlcParameter("D05SitState").getValue();
+    @Value("${mes.carMaxSize}")
+    private Integer carMaxSize;
 
-        String d01Request = "1";
-        String d02SitState = "0";
-//        String d01Id = "P24060403|3|6";
-        String d04Request = "0";
-        String d05SitState = "0";
-//        String d04Id = "P24060403|4|3";
-        String d04Id = "P24060403|5|4";
+    @Value("${mes.galssGap}")
+    private Integer galssGap;
+
+    @Scheduled(fixedDelay = 5000)
+    public void plcToHomeEdgScan() {
+        PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
+        String d01Request = plcParameterObject.getPlcParameter("D01Request").getValue();
+        String d01Id = plcParameterObject.getPlcParameter("D01ID1").getValue();
+        String d02SitState = plcParameterObject.getPlcParameter("D02SitState").getValue();
+        String d04Request = plcParameterObject.getPlcParameter("D04Request").getValue();
+        String d04Id = plcParameterObject.getPlcParameter("D04ID1").getValue();
+        String d05SitState = plcParameterObject.getPlcParameter("D05SitState").getValue();
+
         log.info("1銆佽幏鍙栧埌鐨勮姹傚瓧d01涓猴細{}锛岃幏鍙栧埌鐨勬壂鎻廔D涓猴細{};鑾峰彇鍒扮殑璇锋眰瀛梔04涓猴細{}锛岃幏鍙栧埌鐨勬壂鎻廔D涓猴細{};",
                 d01Request, d01Id, d04Request, d04Id);
         if (!REQUEST_WORD.equals(d01Request) && !REQUEST_WORD.equals(d04Request)) {
@@ -116,23 +120,18 @@
         }
     }
 
-    //    @Scheduled(fixedDelay = 5000)
+    @Scheduled(fixedDelay = 5000)
     public void plcToHomeEdgFreeCarTask() {
-//        PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
-//        String e01Status = plcParameterObject.getPlcParameter("E01Status").getValue();
-        String e01Status = "0";
+        PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
+        String e01Status = plcParameterObject.getPlcParameter("E01Status").getValue();
         if (REQUEST_WORD.equals(e01Status)) {
             log.info("杩涚墖澶ц溅闈炵┖闂�");
             return;
         }
-//        String d01Request = plcParameterObject.getPlcParameter("D01Request").getValue();
-//        String d01Id = plcParameterObject.getPlcParameter("D01ID1").getValue();
-//        String d04Request = plcParameterObject.getPlcParameter("D04Request").getValue();
-//        String d04Id = plcParameterObject.getPlcParameter("D04ID1").getValue();
-        String d01Request = "";
-        String d01Id = "";
-        String d04Request = "1";
-        String d04Id = "";
+        String d01Request = plcParameterObject.getPlcParameter("D01Request").getValue();
+        String d01Id = plcParameterObject.getPlcParameter("D01ID1").getValue();
+        String d04Request = plcParameterObject.getPlcParameter("D04Request").getValue();
+        String d04Id = plcParameterObject.getPlcParameter("D04ID1").getValue();
         log.info("1銆佽幏鍙栧埌鐨勮姹傚瓧d01涓猴細{}锛岃幏鍙栧埌鐨勬壂鎻廔D涓猴細{};鑾峰彇鍒扮殑璇锋眰瀛梔04涓猴細{}锛岃幏鍙栧埌鐨勬壂鎻廔D涓猴細{};",
                 d01Request, d01Id, d04Request, d04Id);
         //涓ゆ潯绾块兘鏈夎繘鍗ц浆绔嬩换鍔★紝鐩存帴缁撴潫
@@ -168,43 +167,29 @@
         computeTargetByLine(outLine);
     }
 
-    //    @Scheduled(fixedDelay = 5000)
+    @Scheduled(fixedDelay = 5000)
     public void plcToHomeEdgOutTask() {
-        //浠诲姟鏁版嵁  鑾峰彇杞﹀瓙瀛樻斁鐜荤拑鏈�澶ф暟閲�  鐜荤拑闂撮殧
-        List<BigStorageCageOutTask> bigStorageCageOutTaskList = new ArrayList<>();
+
+        List<BigStorageCageOutTask> outingList = bigStorageCageOutTaskService.list(new LambdaQueryWrapper<BigStorageCageOutTask>().eq(BigStorageCageOutTask::getTaskState, Const.BIG_STORAGE_OUT_NEW));
+        Assert.isTrue(CollectionUtils.isEmpty(outingList), "鏈夋鍦ㄦ墽琛屽嚭鐗囩殑浠诲姟锛岀粨鏉熷綋鍓嶅嚭鐗囩嚎绋�");
+
         //鏄惁鏈夋鍦ㄩ挗鍖栫殑鐜荤拑
-        List<TemperingGlassInfo> temperingGlassInfoList = temperingGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>()
+        List<TemperingGlassInfo> temperingGlassInfoList = temperingGlassInfoService.selectJoinList(TemperingGlassInfo.class, new MPJLambdaWrapper<TemperingGlassInfo>()
+                .selectAll(TemperingGlassInfo.class)
+                .leftJoin(BigStorageCageOutTask.class, BigStorageCageOutTask::getGlassId, TemperingGlassInfo::getGlassId)
                 .eq(TemperingGlassInfo::getState, Const.TEMPERING_NEW)
+                .isNull(BigStorageCageOutTask::getGlassId)
                 .orderBy(Boolean.TRUE, sequenceOrder, TemperingGlassInfo::getTemperingFeedSequence));
         if (CollectionUtils.isNotEmpty(temperingGlassInfoList)) {
             log.info("鏈夋鍦ㄥ嚭鐗囩殑閽㈠寲浠诲姟");
-            //鎵撹溅鍓╀綑灏哄
-            Integer remainWidth = Const.BIG_STORAGE_WIDTH;
-            for (TemperingGlassInfo e : temperingGlassInfoList) {
-                if (bigStorageCageOutTaskList.size() > 5 || e.getWidth() > remainWidth) {
-                    break;
-                }
-                remainWidth = remainWidth - e.getWidth().intValue() - Const.BIG_STORAGE_GAP;
-                bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getState(), Const.A09_OUT_TARGET_POSITION,
-                        e.getWidth().intValue(), 0, 0, 1));
-            }
-            bigStorageCageOutTaskService.saveBatch(bigStorageCageOutTaskList);
+            computeOutGlassInfo(temperingGlassInfoList);
             return;
         }
         //鏄惁鏈変汉宸ヤ笅鐗囦换鍔�   鏈夌洿鎺ュ嚭
         List<BigStorageCageDetails> artificialList = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>()
                 .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_ARTIFICIAL).orderByDesc(BigStorageCageDetails::getWidth));
         if (CollectionUtils.isNotEmpty(artificialList)) {
-            Integer remainWidth = Const.BIG_STORAGE_WIDTH;
-            for (BigStorageCageDetails e : artificialList) {
-                if (remainWidth < e.getWidth().intValue()) {
-                    break;
-                }
-                bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getSlot(), Const.A10_OUT_TARGET_POSITION,
-                        e.getWidth().intValue(), 0, 0, 1));
-                remainWidth = remainWidth - e.getWidth().intValue() - Const.BIG_STORAGE_GAP;
-            }
-            bigStorageCageOutTaskService.saveBatch(bigStorageCageOutTaskList);
+            computeOutGlassInfo(temperingGlassInfoList);
             return;
         }
         //閽㈠寲浼樺厛锛氳幏鍙栫悊鐗囩  鐜荤拑灏忕墖  鐮存崯琛� 鏁伴噺   鍒ゆ柇绗煎唴鐗堝浘鏄惁鍒伴綈
@@ -214,24 +199,14 @@
             //鍒伴綈锛屽皢鐜荤拑灏忕墖鏁版嵁瀛樺叆閽㈠寲灏忕墖琛紝閫昏緫鐢熸垚鍑虹墖浠诲姟  缁撴潫
             List<TemperingGlassInfo> temperingGlassInfos = glassInfoService.selectJoinList(TemperingGlassInfo.class, JoinWrappers.lambda(GlassInfo.class)
                     .selectAll(GlassInfo.class)
+                    .select("-1 as state")
                     .selectAs(BigStorageCageDetails::getSlot, TemperingGlassInfo::getSlot)
                     .innerJoin(BigStorageCageDetails.class, BigStorageCageDetails::getGlassId, GlassInfo::getGlassId)
                     .eq(BigStorageCageDetails::getState, Const.GLASS_STATE_IN)
                     .eq(GlassInfo::getTemperingLayoutId, temperingLayoutDTO.getTemperingLayoutId())
                     .eq(GlassInfo::getEngineerId, temperingLayoutDTO.getEngineerId()));
             temperingGlassInfoService.saveBatch(temperingGlassInfos);
-
-            //澶ц溅鍓╀綑灏哄
-            Integer remainWidth = Const.BIG_STORAGE_WIDTH;
-            for (TemperingGlassInfo e : temperingGlassInfos) {
-                if (bigStorageCageOutTaskList.size() > 5 || e.getWidth() > remainWidth) {
-                    break;
-                }
-                remainWidth = remainWidth - e.getWidth().intValue() - Const.BIG_STORAGE_GAP;
-                bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getState(), Const.A09_OUT_TARGET_POSITION,
-                        e.getWidth().intValue(), 0, 0, 1));
-            }
-            bigStorageCageOutTaskService.saveBatch(bigStorageCageOutTaskList);
+            computeOutGlassInfo(temperingGlassInfoList);
             return;
         }
         //鏈埌榻� 鎵ц鍐呴儴璋冨害浠诲姟
@@ -241,7 +216,7 @@
             for (int i = 0; i < slotSequenceList.size() - 1; i++) {
                 SlotSequenceDTO first = slotSequenceList.get(i);
                 SlotSequenceDTO second = slotSequenceList.get(i + 1);
-                int slotWidth = Const.BIG_STORAGE_WIDTH - first.getRemainWidth() - Const.BIG_STORAGE_GAP;
+                int slotWidth = carWidth - first.getRemainWidth() - galssGap;
                 if (first.getMinSequence() == second.getMaxSequence() + 1
                         && second.getRemainWidth() > slotWidth) {
                     List<BigStorageCageDetails> list = bigStorageCageDetailsService.list(new LambdaQueryWrapper<BigStorageCageDetails>()
@@ -271,7 +246,7 @@
         Integer remainWidth;
         Integer glassCount;
         if (0 == sitToUpRemainWidth.getGlassCount()) {
-            remainWidth = Const.BIG_STORAGE_WIDTH;
+            remainWidth = carWidth;
             glassCount = 0;
         } else {
             remainWidth = sitToUpRemainWidth.getWidth();
@@ -292,8 +267,8 @@
         } else {
             Integer widthSecond = edgGlassTaskInfoList.get(1).getWidth();
             if (remainWidth >= widthFirst) {
-                if (remainWidth - widthFirst - Const.BIG_STORAGE_GAP >= widthSecond) {
-                    if (glassCount <= 5) {
+                if (remainWidth - widthFirst - galssGap >= widthSecond) {
+                    if (glassCount <= carMaxSize - 1) {
                         addFeedTask(glassId, line, Const.BIG_STORAGE_IN_WAIT, widthFirst);
                         return Boolean.FALSE;
                     } else {
@@ -392,4 +367,60 @@
         }
         return Boolean.TRUE;
     }
+
+    private <T extends BigStorageCageBaseInfo> Boolean computeOutGlassInfo(List<T> list) {
+        //浠诲姟鏁版嵁  鑾峰彇杞﹀瓙瀛樻斁鐜荤拑鏈�澶ф暟閲�  鐜荤拑闂撮殧
+        List<BigStorageCageOutTask> bigStorageCageOutTaskList = new ArrayList<>();
+        //鎵撹溅鍓╀綑灏哄
+        Integer remainWidth = carWidth;
+        for (T e : list) {
+            if (bigStorageCageOutTaskList.size() > carMaxSize || e.getWidth() > remainWidth) {
+                break;
+            }
+            remainWidth = remainWidth - e.getWidth().intValue() - galssGap;
+            bigStorageCageOutTaskList.add(new BigStorageCageOutTask(e.getGlassId(), e.getSlot(), Const.A09_OUT_TARGET_POSITION,
+                    e.getWidth().intValue(), 0, 0, 1));
+        }
+        Assert.isFalse(CollectionUtils.isEmpty(bigStorageCageOutTaskList), "鏈幏鍙栧嚭鐗囨暟鎹紝缁撴潫鍑虹墖浠诲姟");
+        log.info("鑾峰彇鍑虹墖浠诲姟鏁版嵁{}鏉★紝鎵ц淇濆瓨", bigStorageCageOutTaskList.size());
+        bigStorageCageOutTaskService.saveBatch(bigStorageCageOutTaskList);
+        List<String> glassIds = bigStorageCageOutTaskList.stream().map(BigStorageCageOutTask::getGlassId).collect(Collectors.toList());
+        log.info("灏嗗嚭鐗囩幓鐠儃}鐜荤拑鐘舵�佹敼涓哄凡鍑虹墖", glassIds);
+        bigStorageCageDetailsService.update(new LambdaUpdateWrapper<BigStorageCageDetails>()
+                .set(BigStorageCageDetails::getState, Const.GLASS_STATE_OUT)
+                .in(BigStorageCageDetails::getGlassId, glassIds));
+        //鏇存柊绗煎瓙鍐呮牸瀛愮殑鍓╀綑灏哄
+        updateSlotRemain(list, glassIds);
+        return Boolean.TRUE;
+    }
+
+    /**
+     * 鏇存柊绗煎瓙鍐呮牸瀛愮殑鍓╀綑灏哄
+     *
+     * @param list
+     * @param taskGlassIds
+     * @param <T>
+     */
+    public <T extends BigStorageCageBaseInfo> void updateSlotRemain(List<T> list, List<String> taskGlassIds) {
+        //鑾峰彇闇�瑕佸嚭鍘伙紙鍖呮嫭寰呭嚭鍘荤殑锛夌殑鎵�鏈夌幓鐠冩牸瀛愬彿
+        List<Integer> slotList = list.stream().map(T::getSlot).distinct().collect(Collectors.toList());
+        //鑾峰彇寰呭嚭鍘荤殑鐜荤拑淇℃伅锛堢瓑涓嬭溅鍑哄幓鐨勭幓鐠冿級
+        Map<Integer, Double> slotRemainMap = list.stream().filter(e -> !taskGlassIds.contains(e.getGlassId()))
+                .collect(Collectors.groupingBy(T::getSlot, Collectors.summingDouble(item -> item.getWidth() + galssGap)));
+        if (CollectionUtils.isNotEmpty(slotRemainMap)) {
+            //鎸夌収鏍煎瓙鍙锋洿鏂板墿浣欏昂瀵�
+            slotRemainMap.forEach((e, v) -> {
+                bigStorageCageService.update(new LambdaUpdateWrapper<BigStorageCage>().set(BigStorageCage::getRemainWidth, slotWidth - v)
+                        .eq(BigStorageCage::getSlot, e));
+            });
+        }
+        Set<Integer> remainSlotList = slotRemainMap.keySet();
+        slotList.removeAll(remainSlotList);
+        if (CollectionUtils.isNotEmpty(slotList)) {
+            bigStorageCageService.update(new LambdaUpdateWrapper<BigStorageCage>().set(BigStorageCage::getRemainWidth, slotWidth)
+                    .in(BigStorageCage::getSlot, slotList));
+        }
+
+
+    }
 }
\ No newline at end of file

--
Gitblit v1.8.0