From f3f2c64ad502c054a996cff6ec9a0a091f54e8a8 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期日, 17 八月 2025 10:36:09 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  136 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 106 insertions(+), 30 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index 7a71fb3..6edd73e 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -62,7 +62,6 @@
  */
 @Slf4j
 @Service("mainService")
-@Transactional
 public class MainServiceImpl {
 
     public static final long COMMAND_TIMEOUT = 5 * 1000;
@@ -234,6 +233,12 @@
                                     .eq("loc_no", dto.getLocNo()));
 
                             short staNo = dto.getStaNo().shortValue();
+
+                            int sourceStaNo = dto.getSourceStaNo();
+                            if (sourceStaNo == 1007) {
+                                staNo = 2002;
+                            }
+
                             if (inSta.getStaNo() == 1002) {
                                 staNo = 2002;
                             }
@@ -684,7 +689,7 @@
                 staProtocol = staProtocol.clone();
             }
 
-            if (staProtocol.isAutoing() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
+            if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
                 CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, wrkMast.getCrnNo());
                 CrnProtocol crnProtocol = crnThread.getCrnProtocol();
 
@@ -742,6 +747,12 @@
 //            if(crnThread.isBackHpFlag()){
 //                continue;
 //            }
+
+            //鍫嗗灈鏈哄洖鍘熺偣浠诲姟涓�
+            Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK);
+            if (object != null) {
+                continue;
+            }
 
             // 鍙湁褰撳爢鍨涙満绌洪棽 骞朵笖 鏃犱换鍔℃椂鎵嶇户缁墽琛�
             if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO
@@ -842,7 +853,7 @@
                     News.error("鍫嗗灈鏈虹Щ鍔ㄥ懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
                 }
                 crnThread.setBackHpFlag(true);
-                redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60);
+                redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 10);
                 try {
                     Thread.sleep(500);
                 } catch (Exception e) {
@@ -914,7 +925,7 @@
                     News.error("鍫嗗灈鏈虹Щ鍔ㄥ懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand));
                 }
                 crnThread.setBackHpFlag(true);
-                redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60);
+                redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 10);
                 try {
                     Thread.sleep(500);
                 } catch (Exception e) {
@@ -1202,8 +1213,7 @@
 //                    continue;
                 }
                 // 鍒ゆ柇鍫嗗灈鏈哄嚭搴撶珯鐘舵��
-                if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")
-                        && staProtocol.getWorkNo() == 0) {
+                if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() != null && staDetl.getCanouting().equals("Y")) {
 
                     //鏍规嵁鍙傛暟鍒ゆ柇鏄惁鏍¢獙鍙嚭淇″彿
                     String crnOutVerifyOut = "Y";
@@ -1215,6 +1225,10 @@
 
                     if (crnOutVerifyOut.equals("Y")) {
                         if (!staProtocol.isOutEnable()) {
+                            continue;
+                        }
+
+                        if (staProtocol.getWorkNo() > 0) {
                             continue;
                         }
                     }
@@ -1229,12 +1243,22 @@
                     }
 
                     if (crnProtocol.getCrnNo() == 1) {
-                        //鍒ゆ柇鍫嗗灈鏈哄拰褰撳墠浠诲姟鏄惁澶勪簬涓�涓贩閬�
-                        if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) {
-                            //鍒ゆ柇鍫嗗灈鏈烘墍鍦ㄥ贩閬撴槸鍚﹀瓨鍦ㄥ叾浠栦换鍔★紝濡傚瓨鍦ㄥ垯浼樺厛鎵ц
-                            List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false);
-                            if (!currentWrkMasts.isEmpty()) {
-                                continue;//褰撳墠鍫嗗灈鏈烘墍鍦ㄥ贩閬撳瓨鍦ㄤ换鍔�
+                        String turnCrnExecuteCurrentChannel = "Y";
+                        Config turnCrnExecuteCurrentChannelConfig = configService.selectOne(new EntityWrapper<Config>()
+                                .eq("code", "turnCrnExecuteCurrentChannel")
+                        );
+                        if (turnCrnExecuteCurrentChannelConfig != null) {
+                            turnCrnExecuteCurrentChannel = turnCrnExecuteCurrentChannelConfig.getValue();
+                        }
+
+                        if(turnCrnExecuteCurrentChannel.equals("Y")) {
+                            //鍒ゆ柇鍫嗗灈鏈哄拰褰撳墠浠诲姟鏄惁澶勪簬涓�涓贩閬�
+                            if (Utils.getLaneByLocNo(wrkMast.getSourceLocNo()) != crnProtocol.getCrnLane()) {
+                                //鍒ゆ柇鍫嗗灈鏈烘墍鍦ㄥ贩閬撴槸鍚﹀瓨鍦ㄥ叾浠栦换鍔★紝濡傚瓨鍦ㄥ垯浼樺厛鎵ц
+                                List<WrkMast> currentWrkMasts = wrkMastService.selectLaneWrkMast(crnProtocol.getCrnLane(), false);
+                                if (!currentWrkMasts.isEmpty()) {
+                                    continue;//褰撳墠鍫嗗灈鏈烘墍鍦ㄥ贩閬撳瓨鍦ㄤ换鍔�
+                                }
                             }
                         }
                     }
@@ -1520,6 +1544,7 @@
             if (wrkMastMapper.updateById(wrkMast) == 0) {
                 News.error("" + mark + " - 3" + " - 5" + " - 銆愬簱浣嶇Щ杞�� 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
             }
+            crnProtocol.setLastIo("I");
         }
         News.infoNoLog("" + mark + " - 3" + " - 0" + " - 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂锛氬簱浣嶇Щ杞畬鎴�");
 
@@ -1625,6 +1650,7 @@
                 if (crnProtocol.getTaskNo() == 9999) {
                     // 鍫嗗灈鏈哄浣�
                     crnThread.setResetFlag(true);
+                    redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 8);//闃叉鍥炲師鐐瑰悗涓嬪彂鎸囦护杩囧揩
                     continue;
                 }
 
@@ -1653,7 +1679,10 @@
                         crnThread.setResetFlag(true);
                     }
                 }else {
-                    if (wrkMast.getWrkSts() != 14) {
+                    List<Long> list = new ArrayList<>();
+                    list.add(14L);
+                    list.add(15L);
+                    if (!list.contains(wrkMast.getWrkSts())) {
                         News.error("" + mark + " - 1" + " - 鍫嗗灈鏈哄浜庣瓑寰呯‘璁や絾宸ヤ綔妗g姸鎬佹湭瀹屾垚銆傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", crn.getId(), crnProtocol.getTaskNo());
                         continue;
                     }
@@ -1877,9 +1906,13 @@
                         if (jsonObject.getInteger("code").equals(200)) {
                             StartupDto dto = jsonObject.getObject("data", StartupDto.class);
 
+                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
+                                    .eq("loc_no", dto.getLocNo()));
+
                             // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
                             staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                             staProtocol.setStaNo(dto.getStaNo().shortValue());
+                            staProtocol.setPalletSize(locMast.getLocType2());
                             devpThread.setPakMk(staProtocol.getSiteId(), false);
                             boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                             if (!result) {
@@ -1987,7 +2020,7 @@
                     wrkMast1.setIoType(3); // 鍏ュ嚭搴撶姸鎬侊細3.绔欏埌绔�
                     wrkMast1.setIoPri(13D); // 浼樺厛绾�
                     wrkMast1.setSourceStaNo(emptyInSta.getStaNo());
-                    wrkMast1.setStaNo(1007);
+                    wrkMast1.setStaNo(1004);
                     wrkMast1.setBarcode(barcode);
                     // 鎿嶄綔浜哄憳鏁版嵁
                     wrkMast1.setAppeTime(new Date());
@@ -2000,6 +2033,7 @@
                     // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
                     staProtocol.setWorkNo((short) workNo);
                     staProtocol.setStaNo((short) 2003);
+                    staProtocol.setPalletSize((short) 1);
                     devpThread.setPakMk(staProtocol.getSiteId(), false);
                     boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                     if (!result) {
@@ -2106,22 +2140,64 @@
 //                    }catch (Exception e){
 //                        log.error("宸ヤ綔妗f鏄庣粏杈撳叆鐢佃鏈哄け璐�1锛氬紓甯镐俊鎭�==銆�"+e);
 //                    }
-                    wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(
-                            wrkDetl.getMatnr()
-                            , wrkDetl.getMaktx()
-                            , wrkDetl.getAnfme()
-                            , wrkDetl.getWeight()
-                            , wrkDetl.getStockNum()
-                            , wrkDetl.getStockNum2()
-                            , wrkDetl.getSpecs()
-                            , wrkDetl.getSku()
-                            , wrkDetl.getZpallet()
-                            , wrkDetl.getModel()
-                            , wrkDetl.getSupp()
-                            , wrkDetl.getKpCstmrName()
-                            , wrkDetl.getOrderNo()
-                            , wrkDetl.getCstateid$()
-                    )));
+
+                    if (!wrkDetls.isEmpty()) {
+                        WrkDetl wrkDetl = wrkDetls.get(0);
+                        double anfme = 0D;
+                        double weight = 0D;
+                        for (WrkDetl detl : wrkDetls) {
+                            anfme += detl.getAnfme();
+                            weight += detl.getWeight();
+                            wrkDetl.setAnfme(anfme);
+                            wrkDetl.setWeight(weight);
+                        }
+
+                        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>()
+                                .eq("loc_no", wrkMast.getSourceLocNo()));
+                        double totalAnfme = 0D;
+                        double totalWeight = 0D;
+                        for (LocDetl locDetl : locDetls) {
+                            totalAnfme += locDetl.getAnfme();
+                            totalWeight += locDetl.getWeight();
+                        }
+                        wrkDetl.setStockNum(totalAnfme);
+                        wrkDetl.setStockNum2(totalWeight);
+
+                        ledCommand.getMatDtos().add(new MatDto(
+                                wrkDetl.getMatnr()
+                                , wrkDetl.getMaktx()
+                                , wrkDetl.getAnfme()
+                                , wrkDetl.getWeight()
+                                , wrkDetl.getStockNum()
+                                , wrkDetl.getStockNum2()
+                                , wrkDetl.getSpecs()
+                                , wrkDetl.getSku()
+                                , wrkDetl.getZpallet()
+                                , wrkDetl.getModel()
+                                , wrkDetl.getSupp()
+                                , wrkDetl.getKpCstmrName()
+                                , wrkDetl.getOrderNo()
+                                , wrkDetl.getCstateid$()
+                        ));
+
+//                        wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(
+//                                wrkDetl.getMatnr()
+//                                , wrkDetl.getMaktx()
+//                                , wrkDetl.getAnfme()
+//                                , wrkDetl.getWeight()
+//                                , wrkDetl.getStockNum()
+//                                , wrkDetl.getStockNum2()
+//                                , wrkDetl.getSpecs()
+//                                , wrkDetl.getSku()
+//                                , wrkDetl.getZpallet()
+//                                , wrkDetl.getModel()
+//                                , wrkDetl.getSupp()
+//                                , wrkDetl.getKpCstmrName()
+//                                , wrkDetl.getOrderNo()
+//                                , wrkDetl.getCstateid$()
+//                        )));
+                    }
+
                 }
                 commands.add(ledCommand);
             }

--
Gitblit v1.9.1