From db11805d2209fd37b24037fce159c7d5a39d8177 Mon Sep 17 00:00:00 2001
From: dubin <bindu_bean@163.com>
Date: 星期六, 20 十二月 2025 14:40:41 +0800
Subject: [PATCH] #1

---
 src/main/java/com/zy/common/service/CommonService.java |  353 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 176 insertions(+), 177 deletions(-)

diff --git a/src/main/java/com/zy/common/service/CommonService.java b/src/main/java/com/zy/common/service/CommonService.java
index 25abe1d..fbb3a0a 100644
--- a/src/main/java/com/zy/common/service/CommonService.java
+++ b/src/main/java/com/zy/common/service/CommonService.java
@@ -417,11 +417,11 @@
         return getLocNoEmpty(whsType, staDescId, sourceStaNo, matnr, batch, grade, 0, locTypeDto, 0);
     }
 
-//    @Transactional
-//    public StartupDto getLocNoEmptyNew(Integer whsType, Integer staDescId, Integer sourceStaNo,LocTypeDto locTypeDto,String barcode) {
-//        whsType = Utils.GetWhsType(sourceStaNo);
-//        return getLocNoEmptyNew(whsType, staDescId, sourceStaNo,locTypeDto,barcode,0,0);
-//    }
+    @Transactional
+    public StartupDto getLocNoEmptyNew(Integer whsType, Integer staDescId, Integer sourceStaNo,LocTypeDto locTypeDto,String barcode) {
+        whsType = Utils.GetWhsType(sourceStaNo);
+        return getLocNoEmptyNew(whsType, staDescId, sourceStaNo,locTypeDto,barcode,0,0);
+    }
 
     @Transactional
     public StartupDto getLocNoEmpty(Integer whsType, Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
@@ -729,176 +729,175 @@
         return startupDto;
     }
 
-//    @Transactional
-//    public StartupDto getLocNoEmptyNew(Integer whsType, Integer staDescId, Integer sourceStaNo,LocTypeDto locTypeDto,String barcode,int  times, Integer moveCrnNo) {
-//        // 鍒濆鍖栧弬鏁�
-//        int crnNo = 0;      //鍫嗗灈鏈哄彿
-//        int nearRow = 0;    //鏈�娴呭簱浣嶆帓
-//        int curRow = 0;     //鏈�娣卞簱浣嶆帓
-//        int rowCount = 0;   //杞杞
-//        LocMast locMast = null;     // 鐩爣搴撲綅
-//
-//        StartupDto startupDto = new StartupDto();
-//        RowLastno rowLastno = rowLastnoService.selectById(whsType);
-//        int sRow = rowLastno.getsRow();
-//        int eRow = rowLastno.geteRow();
-//        int crnNumber = rowLastno.getCrnQty();
-//
-//        if (Cools.isEmpty(rowLastno)) {
-//            throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛�");
-//        }
-//        // ===============>>>> 寮�濮嬫墽琛�
-//        curRow = rowLastno.getCurrentRow();
-//
-//        if (!Cools.isEmpty(moveCrnNo) && moveCrnNo != 0) {
-//            crnNumber = moveCrnNo;
-//            if (times == 0) {
-//                curRow = moveCrnNo * 4 - 1;
-//            } else {
-//                curRow = moveCrnNo * 4 - 2;
-//            }
-//        }
-//
-//        //姝ょ▼搴忕敤浜庝紭鍖栧爢鍨涙満寮傚父鏃剁殑杩愯鏃堕棿
-//        for (int i = times; i < crnNumber; i++) {
-//            int[] locNecessaryParameters = Utils.LocNecessaryParameters(whsType, curRow, crnNumber);
-//            curRow = locNecessaryParameters[1];
-//            crnNo = locNecessaryParameters[2];
-//            if (basCrnpService.checkSiteError(crnNo, true)) {
-//                rowCount = locNecessaryParameters[0];
-//                nearRow = locNecessaryParameters[3];
-//                break;
-//            } else {
-//                times++;
-//            }
-//        }
-//        if (nearRow == 0) {
-//            throw new CoolException("鏃犲彲鐢ㄥ爢鍨涙満");
-//        }
-//
-//        Wrapper<StaDesc> wrapper = null;
-//        StaDesc staDesc = null;
-//        BasDevp staNo = null;
-//
-//        if (Utils.BooleanWhsTypeSta(whsType, staDescId)) {
-//            // 鑾峰彇鐩爣绔�
-//            wrapper = new EntityWrapper<StaDesc>()
-//                    .eq("type_no", staDescId)
-//                    .eq("stn_no", sourceStaNo)
-//                    .eq("crn_no", crnNo);
-//            staDesc = staDescService.selectOne(wrapper);
-//            if (Cools.isEmpty(staDesc)) {
-//                log.error("type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo);
-//                crnNo = 0;
-//            }
-//            staNo = basDevpService.selectById(staDesc.getCrnStn());
-//            if (!staNo.getAutoing().equals("Y")) {
-//                crnNo = 0;
-//            }
-//            startupDto.setStaNo(staNo.getDevNo());
-//        }
-//
-//        // 鏇存柊搴撲綅鎺掑彿
-//        if (Utils.BooleanWhsTypeSta(whsType, staDescId)) {
-//            rowLastno.setCurrentRow(curRow);
-//            rowLastnoService.updateById(rowLastno);
-//        }
-//
-//        // 1.鎸夎鍒欐煡鎵惧簱浣�
-//        if (Cools.isEmpty(locMast) && crnNo != 0) {
-//            List<LocMast> locMasts = new ArrayList<>();
-//            if (barcode.startsWith("6")){
-//                locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
-//                        .eq("loc_sts","O")
-//                        .in("row1",2,3)
-//                        .in("lev1",1,2,3,4,5,6,7)
-//                        .orderBy("row1",true)
-//                        .orderBy("lev1",true)
-//                );
-//            }else if (barcode.startsWith("7")){
-//                locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
-//                        .eq("loc_sts","O")
-//                        .in("row1",2,3)
-//                        .in("lev1",8,9,10,11,12)
-//                        .orderBy("row1",true)
-//                        .orderBy("lev1",true)
-//                );
-//            }else if (barcode.startsWith("8")){
-//                locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
-//                        .eq("loc_sts","O")
-//                        .eq("lev1",13)
-//                        .in("row1",2,3)
-//                        .orderBy("row1",true)
-//                        .orderBy("lev1",true)
-//                );
-//            }
-//
-//            if (locMasts.size() <= 7){
-//                throw new CoolException("鏃犵┖搴撲綅鍙敤");
-//            }
-//
-//            locMasts.sort(new Comparator<LocMast>() {
-//                @Override
-//                public int compare(LocMast o1, LocMast o2) {
-//                    int b1 = o1.getBay1();
-//                    int b2 = o2.getBay1();
-//                    if (o1.getBay1() >= 15) {
-//                        b1 = Math.abs(15 - o1.getBay1());
-//                    }
-//                    if (o2.getBay1() >= 15) {
-//                        b2 = Math.abs(15 - o2.getBay1());
-//                    }
-//                    return b2 - b1;
-//                }
-//            });
-//
-//            for (LocMast locMast1 : locMasts) {
-//                if (Utils.isDeepLoc(slaveProperties,locMast1.getLocNo())){
-//                    continue;
-//                }
-//                String deepLoc = Utils.getDeepLoc(slaveProperties, locMast1.getLocNo());
-//                LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", deepLoc));
-//                if (Cools.isEmpty(locMast2)){
-//                    continue;
-//                }
-//                if (locMast2.getLocSts().equals("P")||locMast2.getLocSts().equals("Q")||locMast2.getLocSts().equals("R")||locMast2.getLocSts().equals("S")){
-//                    continue;
-//                }
-//                if (!Cools.isEmpty(locMast2)&&locMast2.getLocSts().equals("O")){
-//                    locMast = locMast2;
-//                    break;
-//                }
-//                if (!Cools.isEmpty(locMast2)&&(locMast2.getLocSts().equals("F")||locMast2.getLocSts().equals("D"))){
-//                    locMast = locMast1;
-//                    break;
-//                }
-//            }
-//        }
-//
-//        if (!Cools.isEmpty(locMast) && !basCrnpService.checkSiteError(crnNo, true)) {
-//            locMast = null;
-//        }
-//
-//        // 閫掑綊鏌ヨ
-//        if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) {
-//            // 褰撳墠宸烽亾鏃犵┖搴撲綅鏃讹紝閫掑綊璋冩暣鑷充笅涓�宸烽亾锛屾绱㈠叏閮ㄥ贩閬撴棤鏋滃悗锛岃烦鍑洪�掑綊
-//            if (times < rowCount) {
-//                times = times + 1;
-//                return getLocNoEmptyNew(1, staDescId, sourceStaNo,locTypeDto,barcode);
-//            }
-//            log.error("绯荤粺娌℃湁绌哄簱浣嶏紒锛侊紒 灏哄瑙勬牸锛� {}锛� 杞娆℃暟锛歿}", JSON.toJSONString(locTypeDto), times);
-//            throw new CoolException("娌℃湁绌哄簱浣�");
-//        }
-//        String locNo = locMast.getLocNo();
-//
-//        // 鐢熸垚宸ヤ綔鍙�
-//        int workNo = getWorkNo(0);
-//        // 杩斿洖dto
-//        startupDto.setWorkNo(workNo);
-//        startupDto.setCrnNo(crnNo);
-//        startupDto.setSourceStaNo(sourceStaNo);
-//        startupDto.setLocNo(locNo);
-//        return startupDto;
-//
-//    }
+    @Transactional
+    public StartupDto getLocNoEmptyNew(Integer whsType, Integer staDescId, Integer sourceStaNo,LocTypeDto locTypeDto,String barcode,int  times, Integer moveCrnNo) {
+        // 鍒濆鍖栧弬鏁�
+        int crnNo = 0;      //鍫嗗灈鏈哄彿
+        int nearRow = 0;    //鏈�娴呭簱浣嶆帓
+        int curRow = 0;     //鏈�娣卞簱浣嶆帓
+        int rowCount = 0;   //杞杞
+        LocMast locMast = null;     // 鐩爣搴撲綅
+
+        StartupDto startupDto = new StartupDto();
+        RowLastno rowLastno = rowLastnoService.selectById(whsType);
+        int sRow = rowLastno.getsRow();
+        int eRow = rowLastno.geteRow();
+        int crnNumber = rowLastno.getCrnQty();
+
+        if (Cools.isEmpty(rowLastno)) {
+            throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛�");
+        }
+        // ===============>>>> 寮�濮嬫墽琛�
+        curRow = rowLastno.getCurrentRow();
+
+        if (!Cools.isEmpty(moveCrnNo) && moveCrnNo != 0) {
+            crnNumber = moveCrnNo;
+            if (times == 0) {
+                curRow = moveCrnNo * 4 - 1;
+            } else {
+                curRow = moveCrnNo * 4 - 2;
+            }
+        }
+
+        //姝ょ▼搴忕敤浜庝紭鍖栧爢鍨涙満寮傚父鏃剁殑杩愯鏃堕棿
+        for (int i = times; i < crnNumber; i++) {
+            int[] locNecessaryParameters = Utils.LocNecessaryParameters(whsType, curRow, crnNumber);
+            curRow = locNecessaryParameters[1];
+            crnNo = locNecessaryParameters[2];
+            if (basCrnpService.checkSiteError(crnNo, true)) {
+                rowCount = locNecessaryParameters[0];
+                nearRow = locNecessaryParameters[3];
+                break;
+            } else {
+                times++;
+            }
+        }
+        if (nearRow == 0) {
+            throw new CoolException("鏃犲彲鐢ㄥ爢鍨涙満");
+        }
+
+        Wrapper<StaDesc> wrapper = null;
+        StaDesc staDesc = null;
+        BasDevp staNo = null;
+
+        if (Utils.BooleanWhsTypeSta(whsType, staDescId)) {
+            // 鑾峰彇鐩爣绔�
+            wrapper = new EntityWrapper<StaDesc>()
+                    .eq("type_no", staDescId)
+                    .eq("stn_no", sourceStaNo)
+                    .eq("crn_no", crnNo);
+            staDesc = staDescService.selectOne(wrapper);
+            if (Cools.isEmpty(staDesc)) {
+                log.error("type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo);
+                crnNo = 0;
+            }
+            staNo = basDevpService.selectById(staDesc.getCrnStn());
+            if (!staNo.getAutoing().equals("Y")) {
+                crnNo = 0;
+            }
+            startupDto.setStaNo(staNo.getDevNo());
+        }
+
+        // 鏇存柊搴撲綅鎺掑彿
+        if (Utils.BooleanWhsTypeSta(whsType, staDescId)) {
+            rowLastno.setCurrentRow(curRow);
+            rowLastnoService.updateById(rowLastno);
+        }
+
+        // 1.鎸夎鍒欐煡鎵惧簱浣�
+        if (Cools.isEmpty(locMast) && crnNo != 0) {
+            List<LocMast> locMasts = new ArrayList<>();
+            if (barcode.startsWith("6")){
+                locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
+                        .eq("loc_sts","O")
+                        .in("row1",2,3)
+                        .in("lev1",1,2,3,4,5,6,7)
+                        .orderBy("row1",true)
+                        .orderBy("lev1",true)
+                );
+            }else if (barcode.startsWith("7")){
+                locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
+                        .eq("loc_sts","O")
+                        .in("row1",2,3)
+                        .in("lev1",8,9,10,11,12)
+                        .orderBy("row1",true)
+                        .orderBy("lev1",true)
+                );
+            }else if (barcode.startsWith("8")){
+                locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
+                        .eq("loc_sts","O")
+                        .eq("lev1",13)
+                        .in("row1",2,3)
+                        .orderBy("row1",true)
+                        .orderBy("lev1",true)
+                );
+            }
+
+            if (locMasts.size() <= 7){
+                throw new CoolException("鏃犵┖搴撲綅鍙敤");
+            }
+
+            locMasts.sort(new Comparator<LocMast>() {
+                @Override
+                public int compare(LocMast o1, LocMast o2) {
+                    int b1 = o1.getBay1();
+                    int b2 = o2.getBay1();
+                    if (o1.getBay1() >= 15) {
+                        b1 = Math.abs(15 - o1.getBay1());
+                    }
+                    if (o2.getBay1() >= 15) {
+                        b2 = Math.abs(15 - o2.getBay1());
+                    }
+                    return b2 - b1;
+                }
+            });
+
+            for (LocMast locMast1 : locMasts) {
+                if (Utils.isDeepLoc(slaveProperties,locMast1.getLocNo())){
+                    continue;
+                }
+                String deepLoc = Utils.getDeepLoc(slaveProperties, locMast1.getLocNo());
+                LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", deepLoc));
+                if (Cools.isEmpty(locMast2)){
+                    continue;
+                }
+                if (locMast2.getLocSts().equals("P")||locMast2.getLocSts().equals("Q")||locMast2.getLocSts().equals("R")||locMast2.getLocSts().equals("S")){
+                    continue;
+                }
+                if (!Cools.isEmpty(locMast2)&&locMast2.getLocSts().equals("O")){
+                    locMast = locMast2;
+                    break;
+                }
+                if (!Cools.isEmpty(locMast2)&&(locMast2.getLocSts().equals("F")||locMast2.getLocSts().equals("D"))){
+                    locMast = locMast1;
+                    break;
+                }
+            }
+        }
+
+        if (!Cools.isEmpty(locMast) && !basCrnpService.checkSiteError(crnNo, true)) {
+            locMast = null;
+        }
+
+        // 閫掑綊鏌ヨ
+        if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) {
+            // 褰撳墠宸烽亾鏃犵┖搴撲綅鏃讹紝閫掑綊璋冩暣鑷充笅涓�宸烽亾锛屾绱㈠叏閮ㄥ贩閬撴棤鏋滃悗锛岃烦鍑洪�掑綊
+            if (times < rowCount) {
+                times = times + 1;
+                return getLocNoEmptyNew(1, staDescId, sourceStaNo,locTypeDto,barcode);
+            }
+            log.error("绯荤粺娌℃湁绌哄簱浣嶏紒锛侊紒 灏哄瑙勬牸锛� {}锛� 杞娆℃暟锛歿}", JSON.toJSONString(locTypeDto), times);
+            throw new CoolException("娌℃湁绌哄簱浣�");
+        }
+        String locNo = locMast.getLocNo();
+
+        // 鐢熸垚宸ヤ綔鍙�
+        int workNo = getWorkNo(0);
+        // 杩斿洖dto
+        startupDto.setWorkNo(workNo);
+        startupDto.setCrnNo(crnNo);
+        startupDto.setSourceStaNo(sourceStaNo);
+        startupDto.setLocNo(locNo);
+        return startupDto;
+    }
 }

--
Gitblit v1.9.1