From 851294b0a501b25065c20bc5e8be5bf783c71a45 Mon Sep 17 00:00:00 2001
From: LSH
Date: 星期五, 08 九月 2023 14:24:51 +0800
Subject: [PATCH] #出库优化

---
 src/main/java/com/zy/common/service/CommonService.java |  164 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 110 insertions(+), 54 deletions(-)

diff --git a/src/main/java/com/zy/common/service/CommonService.java b/src/main/java/com/zy/common/service/CommonService.java
index c8ff3bc..6b10fe2 100644
--- a/src/main/java/com/zy/common/service/CommonService.java
+++ b/src/main/java/com/zy/common/service/CommonService.java
@@ -7,6 +7,7 @@
 import com.core.common.Cools;
 import com.core.exception.CoolException;
 import com.zy.asrs.entity.*;
+import com.zy.asrs.entity.result.KeyValueVo;
 import com.zy.asrs.service.*;
 import com.zy.asrs.utils.Utils;
 import com.zy.asrs.utils.VersionUtils;
@@ -87,19 +88,36 @@
         return workNo;
     }
 
+    //鎷嗙洏鏈哄绌烘澘鎵爜锛岄┍鍔ㄦ墭鐩樺悜鐮佸灈浣嶏紝涓嶅叆搴�
+    @Transactional
+    public StartupDto getScanBarcodeEmptyBoard(){
+        StartupDto startupDto = new StartupDto();
+        Integer staNo = 0;
+        if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 201).eq("staNo", 216))<2){
+            staNo=216;
+        }
+        if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 201).eq("staNo", 220))<2){
+            staNo=220;
+        }
+
+        startupDto.setStaNo(staNo);
+        return startupDto;
+    }
+
     /**
      * 妫�绱㈠簱浣嶅彿
      * @param whsType 绫诲瀷 1:鍙屾繁寮忚揣鏋�
      * @param staDescId 璺緞宸ヤ綔绫诲瀷
      * @param sourceStaNo 婧愮珯
-     * @param matNos 鍟嗗搧缂栧彿闆嗗悎
+     * @param list 鍟嗗搧缂栧彿闆嗗悎
      * @return locNo 妫�绱㈠埌鐨勫簱浣嶅彿
      */
     @Transactional
-    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto, int times) {
+    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<KeyValueVo> list, LocTypeDto locTypeDto, int times) {
         whsType = 1;
         StartupDto startupDto = new StartupDto();
-
+        // 鐢熸垚宸ヤ綔鍙�
+        int workNo = getWorkNo(0);
         RowLastno rowLastno = rowLastnoService.selectById(whsType);
         if (Cools.isEmpty(rowLastno)) {
             throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛�");
@@ -111,29 +129,50 @@
         int eRow = rowLastno.geteRow();
         int crn_qty = rowLastno.getCrnQty();
         int rowCount = eRow - sRow + 1;
-
+        // 鐩爣鍫嗗灈鏈哄彿
+        int crnNo = 0;
         // 鐩爣搴撲綅
         LocMast locMast = null;
 
         // 闈犺繎鎽嗘斁瑙勫垯 --- 鍚屽ぉ鍚岃鏍肩墿鏂�
-        if (!Cools.isEmpty(matNos)) {
-            List<String> locNos = locDetlService.getSameDetlToday(matNos.get(0), sRow, eRow);
-            for (String locNo : locNos) {
-                if (Utils.isShallowLoc(slaveProperties, locNo)) {
-                    continue;
+        if (!Cools.isEmpty(list)) {
+            boolean sameMatnr = true;
+            String matnr = "";
+            String batch = "";
+            for (KeyValueVo vo : list) {
+                if (Cools.isEmpty(matnr)) {
+                    matnr = vo.getName();
+                } else {
+                    if (!matnr.equals(vo.getName())) {
+                        sameMatnr = false;
+                        break;
+                    }
                 }
-                String shallowLocNo = Utils.getShallowLoc(slaveProperties, locNo);
-                // 妫�娴嬬洰鏍囧簱浣嶆槸鍚︿负绌哄簱浣�
-                LocMast shallowLoc = locMastService.selectById(shallowLocNo);
-                if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
-                    if (VersionUtils.locMoveCheckLocType(shallowLoc, locTypeDto)) {
-                        if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) {
-                            locMast = shallowLoc;
-                            break;
+            }
+            if (sameMatnr) {
+                List<String> locNos = locDetlService.getSameDetlToday(matnr, sRow, eRow);
+                for (String locNo : locNos) {
+                    if (Utils.isShallowLoc(slaveProperties, locNo)) {
+                        continue;
+                    }
+                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, locNo);
+                    // 妫�娴嬬洰鏍囧簱浣嶆槸鍚︿负绌哄簱浣�
+                    LocMast shallowLoc = locMastService.selectById(shallowLocNo);
+                    if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
+                        if (VersionUtils.locMoveCheckLocType(shallowLoc, locTypeDto)) {
+                            // 鍥犲簱浣嶇Щ杞�侀渶棰勭暀绌哄簱浣�
+                            if (locMastService.checkEmptyCount(shallowLoc)) {
+                                if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) {
+                                    locMast = shallowLoc;
+                                    crnNo = locMast.getCrnNo();
+                                    break;
+                                }
+                            }
                         }
                     }
                 }
             }
+
         }
 
         // 闈犺繎鎽嗘斁瑙勫垯 --- 绌烘墭
@@ -148,9 +187,13 @@
                     // 妫�娴嬬洰鏍囧簱浣嶆槸鍚︿负绌哄簱浣�
                     LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                     if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
-                        if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) {
-                            locMast = shallowLoc;
-                            break;
+                        // 鍥犲簱浣嶇Щ杞�侀渶棰勭暀绌哄簱浣�
+                        if (locMastService.checkEmptyCount(shallowLoc)) {
+                            if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) {
+                                locMast = shallowLoc;
+                                crnNo = locMast.getCrnNo();
+                                break;
+                            }
                         }
                     }
                 }
@@ -158,10 +201,41 @@
         }
 
         // 濡傛灉娌℃湁鐩歌繎鐗╂枡锛屽垯鎸夎鍒欒疆璇㈣揣鏋�
-        if (null == locMast){
-            curRow = getCurRow(curRow);
+        if (null == locMast) {
+            Shelves shelves = new Shelves(rowCount, crn_qty);
+            for (int i = 0; i < shelves.group; i ++) {
+                curRow = shelves.start(curRow);
+                if (curRow < 0) {
+                    throw new CoolException("妫�绱㈠簱浣嶅け璐ワ紝璇疯仈绯荤鐞嗗憳");
+                }
+                Integer crnNo1 = shelves.get(curRow);
+                if (basCrnpService.checkSiteError(crnNo1, true)) {
+                    crnNo = crnNo1;
+                    break;
+                }
+            }
         }
 
+        if (crnNo == 0) {
+            throw new CoolException("娌℃湁鍙敤鐨勫爢鍨涙満");
+        }
+        // 鑾峰彇鐩爣绔�
+        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
+                .eq("type_no", staDescId)
+                .eq("stn_no", sourceStaNo)
+                .eq("crn_no", crnNo);
+        StaDesc staDesc = staDescService.selectOne(wrapper);
+        if (Cools.isEmpty(staDesc)) {
+            log.error("type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo);
+            throw new CoolException("鍏ュ簱璺緞涓嶅瓨鍦�");
+        }
+        BasDevp staNo = basDevpService.selectById(staDesc.getCrnStn());
+        boolean sign = true;
+        if (!staNo.getAutoing().equals("Y")) {
+//            throw new CoolException("鐩爣绔�"+staDesc.getCrnStn()+"涓嶅彲鐢�");
+            log.error("鐩爣绔�"+staDesc.getCrnStn()+"涓嶅彲鐢�");
+            sign = false;
+        }
         // 鏇存柊搴撲綅鎺掑彿
         rowLastno.setCurrentRow(curRow);
         rowLastnoService.updateById(rowLastno);
@@ -169,22 +243,24 @@
         // 寮�濮嬫煡鎵惧簱浣� ==============================>>
 
         // 1.褰撴绱㈠簱鎺掍负娴呭簱浣嶆帓鏃讹紝浼樺厛瀵绘壘褰撳墠搴撴帓鐨勬繁搴撲綅鎺�
-        if (locMast == null) {
+        if (locMast == null && sign) {
             if (Utils.isShallowLoc(slaveProperties, curRow)) {
                 Integer deepRow = Utils.getDeepRow(slaveProperties, curRow);
                 locMast = locMastService.queryFreeLocMast(deepRow, locTypeDto.getLocType1());
                 // todo:luxiaotao 濡傛灉鐢ㄦ祬鎺掓壘鍒扮殑娣卞簱浣嶏紝閭d箞鍒欓渶瑕佸垽鏂繖涓繁搴撲綅瀵瑰簲鐨勬祬搴撲綅鏄惁鏈夎揣锛團銆乆銆丏锛�
                 // 鍥犲簱浣嶇Щ杞�侀渶棰勭暀绌哄簱浣�
-                if (!locMastService.checkEmptyCount(locMast)) {
+                if (locMast !=null && !locMastService.checkEmptyCount(locMast)) {
                     locMast = null;
                 }
             }
+
             if (Cools.isEmpty(locMast)) {
                 locMast = locMastService.queryFreeLocMast(curRow, locTypeDto.getLocType1());
                 // 鍥犲簱浣嶇Щ杞�侀渶棰勭暀绌哄簱浣�
                 if (!locMastService.checkEmptyCount(locMast)) {
                     locMast = null;
                 }
+
                 // 鐩爣搴撲綅 ===>> 娴呭簱浣嶏紝 鍒欐牎楠屽叾娣卞簱浣嶆槸鍚︿负 F D X
                 if (null != locMast && Utils.isShallowLoc(slaveProperties, locMast.getLocNo())) {
                     LocMast deepLoc = locMastService.selectById(Utils.getDeepLoc(slaveProperties, locMast.getLocNo()));
@@ -201,51 +277,30 @@
                 }
             }
         }
-        Integer crnNo = 0;
-        BasDevp staNo =null;
-        boolean sign=false;
-        if (!Cools.isEmpty(locMast)){
-            try{
-                crnNo = locMast.getCrnNo();
-                // 鑾峰彇鐩爣绔�
-                Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
-                        .eq("type_no", staDescId)
-                        .eq("stn_no", sourceStaNo)
-                        .eq("crn_no", crnNo);
-                StaDesc staDesc = staDescService.selectOne(wrapper);
-                if (Cools.isEmpty(staDesc)) {
-                    log.error("type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo);
-                    throw new CoolException("鍏ュ簱璺緞涓嶅瓨鍦�");
-                }
-                staNo = basDevpService.selectById(staDesc.getCrnStn());
-                if (!staNo.getAutoing().equals("Y")) {
-                    throw new CoolException("鐩爣绔�"+staDesc.getCrnStn()+"涓嶅彲鐢�");
-                }
-            }catch (Exception e){
-                sign=true;
-            }
-        }
 
         // 2.搴撲綅褰撳墠鎵�灞炲昂瀵告棤绌哄簱浣嶆椂锛岃皟鏁村昂瀵稿弬鏁帮紝鍚戜笂鍏煎妫�绱㈠簱浣�
-        if (Cools.isEmpty(locMast) || sign) {
+        if (Cools.isEmpty(locMast)) {
             // 褰撳墠宸烽亾鏃犵┖搴撲綅鏃讹紝閫掑綊璋冩暣鑷充笅涓�宸烽亾锛屾绱㈠叏閮ㄥ贩閬撴棤鏋滃悗锛岃烦鍑洪�掑綊
             if (times < rowCount) {
                 times = times + 1;
-                return getLocNo(1, staDescId, sourceStaNo, matNos, locTypeDto, times);
+                return getLocNo(1, staDescId, sourceStaNo, list, locTypeDto, times);
+            } else {
+                times = 0;
             }
 
             // 杞昏揣鐗╂壘杞诲簱浣嶄负绌烘椂锛屽彲浠ュ幓鎵鹃噸搴撲綅浠�
             if (locTypeDto.getLocType1() == 1) {
                 locTypeDto.setLocType1((short) 2);
-                return getLocNo(1, staDescId, sourceStaNo, matNos, locTypeDto, times);
+                return getLocNo(1, staDescId, sourceStaNo, list, locTypeDto, times);
+            }
+            if (!sign){
+                throw new CoolException("鐩爣绔�"+staDesc.getCrnStn()+"涓嶅彲鐢�");
             }
             log.error("绯荤粺娌℃湁绌哄簱浣嶏紒锛侊紒 灏哄瑙勬牸锛� {}锛� 杞娆℃暟锛歿}", JSON.toJSONString(locTypeDto), times);
             throw new CoolException("娌℃湁绌哄簱浣�");
         }
         String locNo = locMast.getLocNo();
 
-        // 鐢熸垚宸ヤ綔鍙�
-        int workNo = getWorkNo(0);
         // 杩斿洖dto
         startupDto.setWorkNo(workNo);
         startupDto.setCrnNo(crnNo);
@@ -254,6 +309,7 @@
         startupDto.setLocNo(locNo);
         return startupDto;
     }
+
 
 
     public static String zerofill(String msg, Integer count) {
@@ -274,7 +330,7 @@
      * 鏍规嵁鍏ュ簱绔欒幏鍙栧簱浣嶆帓鍙峰垎閰�
      */
     private Integer getCurRow(Integer curRow) {
-        if (Utils.isDeepLocLeft(slaveProperties,curRow)){
+        if (Utils.isDeepLocLeft(slaveProperties,curRow)){ //鍒ゆ柇鏄惁涓哄乏娣卞簱浣�
             curRow=curRow+3;
         }else if (Utils.isDeepLocLeft(slaveProperties,curRow-1)){
             curRow=curRow+1;

--
Gitblit v1.9.1