From 23ffcbc16fd92043aaaac784ad770c5cccb36b55 Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期六, 29 六月 2024 22:07:30 +0800
Subject: [PATCH] 下片任务自测完成50%,已完成基本进片出片,复杂逻辑为测试

---
 hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/downstorage/service/impl/DownStorageCageServiceImpl.java |  324 +++++++++++++++++++++--------------------------------
 1 files changed, 130 insertions(+), 194 deletions(-)

diff --git a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/downstorage/service/impl/DownStorageCageServiceImpl.java b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/downstorage/service/impl/DownStorageCageServiceImpl.java
index a3976f0..07dbd63 100644
--- a/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/downstorage/service/impl/DownStorageCageServiceImpl.java
+++ b/hangzhoumesParent/moduleService/UnLoadGlassModule/src/main/java/com/mes/downstorage/service/impl/DownStorageCageServiceImpl.java
@@ -1,13 +1,13 @@
 package com.mes.downstorage.service.impl;
 
-import com.github.yulichang.query.MPJQueryWrapper;
-import com.mes.common.PLCAutoMes;
-import com.mes.common.S7control;
-import com.mes.device.PlcParameterObject;
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.yulichang.toolkit.JoinWrappers;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.mes.common.config.Const;
 import com.mes.downglassinfo.entity.DownGlassTask;
 import com.mes.downglassinfo.service.DownGlassTaskService;
 import com.mes.downstorage.entity.DownStorageCage;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.mes.downstorage.entity.DownStorageCageDetails;
 import com.mes.downstorage.mapper.DownStorageCageDetailsMapper;
 import com.mes.downstorage.mapper.DownStorageCageMapper;
@@ -15,8 +15,8 @@
 import com.mes.downstorage.service.DownStorageCageService;
 import com.mes.glassinfo.entity.GlassInfo;
 import com.mes.glassinfo.service.GlassInfoService;
-import com.mes.tools.WebSocketServer;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -25,7 +25,7 @@
 
 /**
  * <p>
- *  鏈嶅姟瀹炵幇绫�
+ * 鏈嶅姟瀹炵幇绫�
  * </p>
  *
  * @author zhoush
@@ -34,7 +34,7 @@
 @Slf4j
 @Service
 public class DownStorageCageServiceImpl extends ServiceImpl<DownStorageCageMapper, DownStorageCage> implements DownStorageCageService {
-    @Autowired
+    @Autowired(required = false)
     private DownStorageCageMapper downStorageCageMapper;
 
     @Autowired
@@ -44,212 +44,148 @@
     private DownGlassTaskService downGlassTaskService;
     @Autowired
     private DownStorageCageDetailsService downStorageCageDetailsService;
-    @Override
-    public List<Map> gettask(){
-        downStorageCageMapper.selectList(null);
-//        downStorageCageMapper.selectJoin();
-        return null;
-    };
-
+    @Autowired
+    private DownStorageCageDetailsMapper downStorageCageDetailsMapper;
 
     @Override
-    public List<Map> selectCacheEmpty(){
-        return baseMapper.selectJoinList(
-                Map.class,new MPJQueryWrapper<DownStorageCage>().selectAll(DownStorageCage.class)
-                        .select("escd.glass_id","escd.flow_card_id","escd.width","escd.height")
-                        .leftJoin("down_storage_cage_details escd on t.device_id=escd.device_id and t.slot=escd.slot")
-                        .isNull("escd.slot")
+    public DownGlassTask createDownGlassTask(GlassInfo glassInfo, Integer startCell, Integer endCell, String taskType) {
+        DownGlassTask downGlassTask = new DownGlassTask();
+
+        BeanUtils.copyProperties(glassInfo, downGlassTask);
+
+        downGlassTask.setStartCell(startCell);
+        downGlassTask.setTaskType(taskType);
+        downGlassTask.setEndCell(endCell);
+        return downGlassTask;
+    }
+
+    @Override
+    public DownGlassTask createDownGlassTask(DownStorageCageDetails glassInfo, Integer startCell, Integer endCell, String taskType) {
+        DownGlassTask downGlassTask = new DownGlassTask();
+
+        BeanUtils.copyProperties(glassInfo, downGlassTask);
+        downGlassTask.setStartCell(startCell);
+        downGlassTask.setTaskType(taskType);
+        downGlassTask.setEndCell(endCell);
+        return downGlassTask;
+    }
+
+
+    //鎵惧埌绌烘牸瀛�
+    @Override
+    public List<DownStorageCageDetails> selectCacheEmpty() {
+        return this.selectJoinList(DownStorageCageDetails.class,
+                JoinWrappers.lambda(DownStorageCage.class)
+                        .selectAll(DownStorageCage.class)
+                        .leftJoin(DownStorageCageDetails.class, on -> on
+                                .eq(DownStorageCageDetails::getDeviceId, DownStorageCage::getDeviceId)
+                                .eq(DownStorageCageDetails::getSlot, DownStorageCage::getSlot)
+                                .eq(DownStorageCageDetails::getState, Const.GLASS_STATE_IN))
+                        .isNull(DownStorageCageDetails::getSlot)
+        );
+    }
+
+    //鎵惧埌绌烘牸瀛�
+    @Override
+    public DownStorageCage selectCacheEmpty(int currentSlot, boolean flag) {
+        List<DownStorageCage> emptyList = this.selectJoinList(DownStorageCage.class,
+                JoinWrappers.lambda(DownStorageCage.class)
+                        .selectAll(DownStorageCage.class)
+                        .leftJoin(DownStorageCageDetails.class, on -> on
+                                .eq(DownStorageCageDetails::getSlot, DownStorageCage::getSlot)
+                                .eq(DownStorageCageDetails::getState, Const.GLASS_STATE_IN))
+                        .isNull(DownStorageCageDetails::getSlot)
+                        .last("order by abs(t.slot - " + currentSlot + ")  asc limit 2")
+        );
+        if (flag && CollectionUtil.isNotEmpty(emptyList)) {
+            return emptyList.get(0);
+        }
+        if (CollectionUtil.isEmpty(emptyList) || emptyList.size() == 1) {
+            return null;
+        }
+        return emptyList.get(0);
+    }
+
+    @Override
+    public List<DownStorageCageDetails> selectCacheMax() {
+        return baseMapper.selectJoinList(DownStorageCageDetails.class,
+                JoinWrappers.lambda(DownStorageCage.class)
+                        // 娣诲姞 DownStorageCage 鐨� enableState 涓� 1 鐨勬潯浠�
+                        .select(DownStorageCageDetails::getFlowCardId)
+                        .leftJoin(DownStorageCageDetails.class, on -> on
+                                .eq(DownStorageCageDetails::getDeviceId, DownStorageCage::getDeviceId)
+                                .eq(DownStorageCageDetails::getSlot, DownStorageCage::getSlot)
+                                .eq(DownStorageCageDetails::getState, Const.GLASS_STATE_IN))
+                        .isNull(DownStorageCageDetails::getSlot)
+                        .eq(DownStorageCage::getEnableState, 1)
+                        .groupBy(DownStorageCageDetails::getFlowCardId) // 鏍规嵁 flowCardId 鍒嗙粍
+                        // 浣跨敤瀛愭煡璇㈠拰鎺掑簭鏉ヨ幏鍙栫浉鍚� FlowCardId 涓殑鏈�澶氳褰�
+                        .having("count(*) = (select max(cnt) from (select count(*) as cnt from down_storage_cage_details group by flow_card_id) as temp)")
+
         );
     }
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-    public DownGlassTask createDownGlassTask(GlassInfo glassInfo, String startCell, String endCell,String taskType ) {
-        DownGlassTask downGlassTask = new DownGlassTask();
-        downGlassTask.setId(glassInfo.getId());
-        downGlassTask.setStartCell(startCell);
-        downGlassTask.setTaskType(taskType);
-        downGlassTask.setEndCell(endCell);
-        downGlassTask.setWidth(glassInfo.getWidth());
-        downGlassTask.setHeight(glassInfo.getHeight());
-        downGlassTask.setFilmsid(String.valueOf(glassInfo.getFilmsid()));
-        downGlassTask.setThickness(glassInfo.getThickness());
-        downGlassTask.setFlowCardId(glassInfo.getFlowcardId());
-
-        return downGlassTask;
-    }
-
-
-    public DownGlassTask createDownGlassTask(DownStorageCageDetails glassInfo, String startCell, String endCell,String taskType ) {
-        DownGlassTask downGlassTask = new DownGlassTask();
-        downGlassTask.setId(glassInfo.getId());
-        downGlassTask.setStartCell(startCell);
-        downGlassTask.setTaskType(taskType);
-        downGlassTask.setEndCell(endCell);
-        downGlassTask.setWidth(glassInfo.getWidth());
-        downGlassTask.setHeight(glassInfo.getHeight());
-        downGlassTask.setFilmsid(String.valueOf(glassInfo.getFilmsid()));
-        downGlassTask.setThickness(glassInfo.getThickness());
-        downGlassTask.setFlowCardId(glassInfo.getFlowCardId());
-
-        return downGlassTask;
-    }
-
-
     @Override
-    public boolean processInto(String Number) {
+    public List<Map<String, Object>> selectDownStorageCages() {
+        return baseMapper.selectJoinMaps(JoinWrappers.lambda(DownStorageCage.class)
+                .selectAll(DownStorageCage.class)
+                .selectAs(DownStorageCageDetails::getId, "esdId")
+                .select(DownStorageCageDetails::getGlassId, DownStorageCageDetails::getWidth, DownStorageCageDetails::getHeight, DownStorageCageDetails::getId)
+                .leftJoin(DownStorageCageDetails.class, on -> on
+                        .eq(DownStorageCageDetails::getDeviceId, DownStorageCage::getDeviceId)
+                        .eq(DownStorageCageDetails::getSlot, DownStorageCage::getSlot)
+                        .eq(DownStorageCageDetails::getState, Const.GLASS_STATE_IN))
+        );
 
-        //鎸塱d鏌ヨ鐜荤拑淇℃伅琛ㄩ噷鐨勭幓鐠�
-        GlassInfo GlassInfo = glassInfoService.selectGlassId(Number);
-     PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
-        //瀛樺湪姝ょ幓鐠冪紪鍙�
-        if (GlassInfo != null) {
-            //鍚屾壘鍒板悓娴佺▼鍗¢檮杩戠┖鏍�
-            List<DownStorageCageDetails> list = downStorageCageDetailsService.getIsExistIntoCacheByflowcardid(GlassInfo.getFlowcardId(),  GlassInfo.getWidth());
-
-            List<Map> selectCacheEmpty=selectCacheEmpty();
-
-            //            list<Map> list=selectCacheEmpty();
-//            list<Map> = downStorageCageService.selectCacheEmpty();
-            if (selectCacheEmpty.size() > 0) {
-                //瀛樺湪绌烘牸
-                //1.鐢熸垚浠诲姟锛�  璧峰浣嶇疆0   缁撴潫浣嶇疆this.slot  浠诲姟绫诲瀷 1   锛堣繘鐗囦换鍔★級
-                //2.鍥炲 1杩涚墖
-                DownStorageCageDetails item = list.get(0);
-
-                //selectInfo.insertCacheTask(GlassInfo.getId() + "", "0", item.getSlot() + "", "1", GlassInfo.getWidth(), GlassInfo.getHeight(), GlassInfo.getFilmsid(), GlassInfo.getThickness(), GlassInfo.getFlowcardId());
-
-                DownGlassTask downGlassTask =   createDownGlassTask(GlassInfo,"0",item.getSlot()+"","1");
-
-                downGlassTaskService.insertCacheTask(downGlassTask);
-
-               S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToGaStatus").getAddress(), (short) 1);
-
-
-                //瀹屾垚鍚庢彃鍏ュ皬鐗囨暟鎹埌缂撳瓨琛�
-                return true;
-            }
-
-        } else {
-            // ID缂栧彿涓嶅瓨鍦�   涓嶅鐞�/鍥炲PLC  杩涜鎶ヨ鎻愮ず
-        }
-        //杩斿洖缁撴灉
-        return false;
     }
-
 
     /**
-     * 鐞嗙墖 鍑�
+     * 淇敼鐞嗙墖绗间俊鎭� 鍔熻兘锛氬绗煎唴鏍呮牸鐜荤拑 銆愬惎鐢�/绂佺敤銆�
+     *
+     * @param downStorageCage
      * @return
      */
-    //
     @Override
-    public boolean processOut() {
-        // 鏌ヨ浠诲姟
+    public boolean updateDownStorageCage(DownStorageCage downStorageCage) {
+        DownStorageCage downItem = baseMapper.selectById(downStorageCage.getId());
+        downItem.setEnableState(downStorageCage.getEnableState());
+        baseMapper.updateById(downItem);
+        return true;
+    }
 
-
-        PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
-
-        List<DownStorageCageDetails> list = downStorageCageDetailsService.CacheOut(1, 5);
-        List<DownStorageCageDetails> list2 = downStorageCageDetailsService.CacheOut(6, 10);
-        List<DownStorageCageDetails> list3 = downStorageCageDetailsService.CacheOut(1, 10);
-        //鑷姩缁戝畾鏋跺瓙
-
-
-
-
-        // 浼樺厛 瓒呭嚭灏哄浼樺厛浜哄伐鍑虹墖 浜哄伐澶勭悊
-
-        if (!list3.isEmpty()) {
-            DownStorageCageDetails item3 = list3.get(0);
-            if (item3.getHeight() >= 1 && item3.getWidth() >= 1) {
-
-                String endcell = "13";
-                String SendEndcell = "1";
-
-//                selectInfo.insertCacheTask(item3.getGlassId() + "", "0", endcell, "2", item3.getWidth(), item3.getHeight(), item3.getFilmsid(), item3.getThickness(), item3.getFlowCardId());
-
-                DownGlassTask downGlassTask =createDownGlassTask(item3,"0",endcell,"2");
-
-                downGlassTaskService.insertCacheTask(downGlassTask);
-                S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.28").getAddress(), SendEndcell);
-                S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.20").getAddress(), "1");
-                return true;
+    /**
+     * 淇敼鐞嗙墖绗间俊鎭� 鍔熻兘锛氬绗煎唴鏍呮牸鐜荤拑 銆愭坊鍔�/鍒犻櫎/鏇存崲銆�
+     *
+     * @param downStorageCageId
+     * @param downStorageCageDetails
+     * @return
+     */
+    @Override
+    public boolean updateDownStorageCageDetails(int downStorageCageId, DownStorageCageDetails downStorageCageDetails) {
+        DownStorageCage downItem = baseMapper.selectById(downStorageCageId);
+        log.info("姝e父" + downItem);
+        if (downStorageCageDetails != null) {
+            DownStorageCageDetails edgDItem = downStorageCageDetailsMapper.selectById(downStorageCageDetails.getId());
+            //娣诲姞
+            if (edgDItem != null) {
+                //鍙紶鏍煎瓙  锛氱Щ闄ょ幓鐠�
+                DownStorageCageDetails newresult = downStorageCageDetailsMapper.selectById(downStorageCageDetails.getId());
+                newresult.setSlot(downItem.getSlot());
+                downStorageCageDetailsMapper.updateById(newresult);
             }
         }
 
-
-        //濡傛灉鍚屾椂鍓嶅悗绔兘绌洪棽 浼樺厛鍚庣鍑虹墖骞朵笖浼樺厛婊℃灦
-        else if (!list2.isEmpty()&&!list3.isEmpty()) {
-
-            DownStorageCageDetails item3 = list2.get(0);
-            String endcell = "11";
-            String SendEndcell = "1";
-            // selectInfo.insertCacheTask(item3.getGlassId() + "", "0", endcell, "2", item3.getWidth(), item3.getHeight(), item3.getFilmsid(), item3.getThickness(), item3.getFlowCardId());
-            DownGlassTask downGlassTask =createDownGlassTask(item3,"0",endcell,"2");
-            downGlassTaskService.insertCacheTask(downGlassTask);
-
-            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.28").getAddress(), SendEndcell);
-            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.20").getAddress(), "1");
-            return true;
+        if (downItem != null) {
+            //绉婚櫎
+            DownStorageCageDetails result = downStorageCageDetailsMapper.selectOne(new MPJLambdaWrapper<DownStorageCageDetails>().eq(DownStorageCageDetails::getSlot, downStorageCageId));
+            if (result != null) {
+                result.setSlot(0);
+                downStorageCageDetailsMapper.updateById(result);
+            }
 
         }
-        // 鎸夌収澶у皬绗﹀悎鍓嶇鍑虹墖
-        else if (!list.isEmpty()) {
-            DownStorageCageDetails item = list.get(0);
-
-            // 鍑哄埌 G06
-            //selectInfo.insertCacheTask(item.getGlassId() + "", "0", "06", "2", item.getWidth(), item.getHeight(), item.getFilmsid(), item.getThickness(), item.getFlowCardId());
-
-            DownGlassTask downGlassTask =createDownGlassTask(item,"0","06","2");
-            downGlassTaskService.insertCacheTask(downGlassTask);
-            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.28").getAddress(), "1");
-            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.20").getAddress(), "1");
-            return true;
-
-            // 鎸夌収澶у皬绗﹀悎鍚庣鍑虹墖
-        } else if (!list2.isEmpty()) {
-            DownStorageCageDetails item2 = list2.get(0);
-
-            // 鍑哄埌 G11
-            // selectInfo.insertCacheTask(item2.getGlassId() + "", "0", "11", "2", item2.getWidth(), item2.getHeight(), item2.getFilmsid(), item2.getThickness(), item2.getFlowCardId());
-            DownGlassTask downGlassTask =createDownGlassTask(item2,"0","11","2");
-            downGlassTaskService.insertCacheTask(downGlassTask);
-
-            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.28").getAddress(), "2");
-            S7control.getinstance().writeString(plcmes.getPlcParameter("DB14.20").getAddress(), "1");
-            return true;
-
-
-        }
-
-
-
-        // 杩斿洖缁撴灉
-        return false;
+        return true;
     }
-
-
-
-
-
 
 }

--
Gitblit v1.8.0