|  |  | 
 |  |  | package com.zy.common.service; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSON; | 
 |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
 |  |  | import com.baomidou.mybatisplus.mapper.Wrapper; | 
 |  |  | import com.core.common.Arith; | 
 |  |  | 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; | 
 |  |  | import com.zy.common.model.LocTypeDto; | 
 |  |  | import com.zy.common.model.Shelves; | 
 |  |  | import com.zy.common.model.StartupDto; | 
 |  |  | import com.zy.common.properties.SlaveProperties; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  |  | 
 |  |  | import java.time.LocalDate; | 
 |  |  | import java.time.format.DateTimeFormatter; | 
 |  |  | import java.time.temporal.ChronoUnit; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 货架核心功能 | 
 |  |  |  * Created by vincent on 2020/6/11 | 
 |  |  |  */ | 
 |  |  | @Slf4j | 
 |  |  | @Service | 
 |  |  | public class CommonService { | 
 |  |  |  | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private RowLastnoService rowLastnoService; | 
 |  |  |     @Autowired | 
 |  |  |     private RowLastnoTypeService rowLastnoTypeService; | 
 |  |  |     @Autowired | 
 |  |  |     private BasCrnpService basCrnpService; | 
 |  |  |     @Autowired | 
 |  |  |     private StaDescService staDescService; | 
 |  |  | 
 |  |  |     private LocMastService locMastService; | 
 |  |  |     @Autowired | 
 |  |  |     private LocDetlService locDetlService; | 
 |  |  |     @Autowired | 
 |  |  |     private SlaveProperties slaveProperties; | 
 |  |  |     @Autowired | 
 |  |  |     private WrkDetlService wrkDetlService; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 生成工作号 | 
 |  |  |      * @param wrkMk 0:入出库 ; 1:其他 | 
 |  |  |      * @param wrkMk | 
 |  |  |      * @return workNo(工作号) | 
 |  |  |      */ | 
 |  |  |     public int getWorkNo(Integer wrkMk) { | 
 |  |  | 
 |  |  |         if (Cools.isEmpty(wrkLastno)) { | 
 |  |  |             throw new CoolException("数据异常,请联系管理员"); | 
 |  |  |         } | 
 |  |  |         int workNo = 0; | 
 |  |  |         // 入出库类型 | 
 |  |  |         if (wrkLastno.getWrkMk() == 0) { | 
 |  |  |             workNo = wrkLastno.getWrkNo(); | 
 |  |  |             int sNo = wrkLastno.getSNo(); | 
 |  |  |             int eNo = wrkLastno.getENo(); | 
 |  |  |  | 
 |  |  |             workNo = workNo>=eNo ? sNo : workNo+1; | 
 |  |  |  | 
 |  |  |             while (true) { | 
 |  |  |                 WrkMast wrkMast = wrkMastService.selectById(workNo); | 
 |  |  |                 if (null != wrkMast) { | 
 |  |  |                     workNo = workNo>=eNo ? sNo : workNo+1; | 
 |  |  |                 } else { | 
 |  |  |                     break; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             if (workNo > 0){ | 
 |  |  |                 wrkLastno.setWrkNo(workNo); | 
 |  |  |                 wrkLastnoService.updateById(wrkLastno); | 
 |  |  |         int workNo = wrkLastno.getWrkNo(); | 
 |  |  |         int sNo = wrkLastno.getSNo(); | 
 |  |  |         int eNo = wrkLastno.getENo(); | 
 |  |  |         workNo = workNo>=eNo ? sNo : workNo+1; | 
 |  |  |         while (true) { | 
 |  |  |             WrkMast wrkMast = wrkMastService.selectById(workNo); | 
 |  |  |             if (null != wrkMast) { | 
 |  |  |                 workNo = workNo>=eNo ? sNo : workNo+1; | 
 |  |  |             } else { | 
 |  |  |                 break; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         // 修改序号记录 | 
 |  |  |         if (workNo > 0){ | 
 |  |  |             wrkLastno.setWrkNo(workNo); | 
 |  |  |             wrkLastnoService.updateById(wrkLastno); | 
 |  |  |         } | 
 |  |  |         // 检验 | 
 |  |  |         if (workNo == 0) { | 
 |  |  |             throw new CoolException("生成工作号失败,请联系管理员"); | 
 |  |  |         } else { | 
 |  |  | 
 |  |  |         return workNo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 检索库位号 | 
 |  |  |      * @param whsType 类型 1:双深式货架 | 
 |  |  |      * @param staDescId 路径ID | 
 |  |  |      * @param sourceStaNo 源站 | 
 |  |  |      * @param matNos 物料号集合 | 
 |  |  |      * @return locNo 检索到的库位号 | 
 |  |  |      */ | 
 |  |  |     public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos) { | 
 |  |  |     //拆盘机处空板扫码,驱动托盘向码垛位,不入库 | 
 |  |  |     @Transactional | 
 |  |  |     public StartupDto getScanBarcodeEmptyBoard(){ | 
 |  |  |         StartupDto startupDto = new StartupDto(); | 
 |  |  |         RowLastno rowLastno = rowLastnoService.selectById(whsType); | 
 |  |  |         if (Cools.isEmpty(rowLastno)) { | 
 |  |  |             throw new CoolException("数据异常,请联系管理员"); | 
 |  |  |         Integer staNo = 0; | 
 |  |  |         if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 201).eq("staNo", 216))<2){ | 
 |  |  |             staNo=216; | 
 |  |  |         } | 
 |  |  |         if (rowLastno.getWhsType() == 1){ | 
 |  |  |             int curRow = rowLastno.getCurrentRow(); | 
 |  |  |             int sRow = rowLastno.getsRow(); | 
 |  |  |             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)); | 
 |  |  |                 for (String locNo : locNos) { | 
 |  |  |                     // 获取排 | 
 |  |  |                     int row = Integer.parseInt(locNo.substring(0, 2)); | 
 |  |  |                     // 判断是否为深库位 | 
 |  |  |                     double remainder = Arith.remainder(row, rowCount / crn_qty); | 
 |  |  |                     int targetRow; | 
 |  |  |                     if (remainder == 1) { | 
 |  |  |                         // 得到当前库位的外围库位 | 
 |  |  |                         targetRow =  row + 1; | 
 |  |  |                     } else if (remainder == 0) { | 
 |  |  |                         // 得到当前库位的内围库位 | 
 |  |  |                         targetRow =  row - 1; | 
 |  |  |                     } else { | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  |                     String targetLocNo = zerofill(String.valueOf(targetRow), 2)+locNo.substring(2); | 
 |  |  |                     // 检测目标库位是否为空库位 | 
 |  |  |                     LocMast targetLocMast = locMastService.selectById(targetLocNo); | 
 |  |  |                     if (targetLocMast != null && targetLocMast.getLocSts().equals("O")) { | 
 |  |  |                         locMast = targetLocMast; | 
 |  |  |                         crnNo = locMast.getCrnNo(); | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             // 如果没有相近物料,则按规则轮询货架 | 
 |  |  |             if (null == locMast) { | 
 |  |  |                 // 获取目标站所在货架排号 | 
 |  |  |                 Shelves shelves = new Shelves(rowCount, crn_qty); | 
 |  |  |                 curRow = shelves.start(curRow); | 
 |  |  |                 if (curRow < 0) { | 
 |  |  |                     throw new CoolException("检索库位失败,请联系管理员"); | 
 |  |  |                 } | 
 |  |  |                 for (List<Integer> node : shelves.nodes){ | 
 |  |  |                     if (node.contains(curRow)) { | 
 |  |  |                         crnNo = shelves.nodes.indexOf(node) + 1; | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             basCrnpService.checkSiteStatus(crnNo); | 
 |  |  |             // 获取目标站 | 
 |  |  |             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)) { | 
 |  |  |                 throw new CoolException("入库路径不存在"); | 
 |  |  |             } | 
 |  |  |             BasDevp staNo = basDevpService.selectById(staDesc.getCrnStn()); | 
 |  |  |             int inQty = staNo.getInQty()==null?0:staNo.getInQty(); | 
 |  |  |             if (staNo.getAutoing().equals("Y") && inQty<2) { | 
 |  |  |                 // 查找库位 | 
 |  |  |                 if (locMast == null) { | 
 |  |  |                     locMast = locMastService.queryFreeLocMast(curRow); | 
 |  |  |                 } | 
 |  |  |                 if (Cools.isEmpty(locMast)) { | 
 |  |  |                     throw new CoolException("没有空库位"); | 
 |  |  |                 } | 
 |  |  |                 String locNo = locMast.getLocNo(); | 
 |  |  |  | 
 |  |  |                 // 更新库位排号 | 
 |  |  |                 rowLastno.setCurrentRow(curRow); | 
 |  |  |                 rowLastnoService.updateById(rowLastno); | 
 |  |  |  | 
 |  |  |                 // 返回dto | 
 |  |  |                 startupDto.setCrnNo(crnNo); | 
 |  |  |                 startupDto.setSourceStaNo(sourceStaNo); | 
 |  |  |                 startupDto.setStaNo(staNo.getDevNo()); | 
 |  |  |                 startupDto.setLocNo(locNo); | 
 |  |  |             } else { | 
 |  |  |                 throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用"); | 
 |  |  |             } | 
 |  |  |         } else { | 
 |  |  |             throw new CoolException(rowLastno.getWhsType()+"号库位排号分配规则不可用"); | 
 |  |  |         if (wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("io_type", 201).eq("staNo", 220))<2){ | 
 |  |  |             staNo=220; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         startupDto.setStaNo(staNo); | 
 |  |  |         return startupDto; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public static void main(String[] args) { | 
 |  |  |         System.out.println(Arith.remainder(1, 4)); | 
 |  |  |         System.out.println("0200201".substring(0, 2)); | 
 |  |  |         String locNo = "0800201"; | 
 |  |  |         int row = Integer.parseInt(locNo.substring(0, 2)); | 
 |  |  |         double remainder = Arith.remainder(row, 4); | 
 |  |  |         int targetRow; | 
 |  |  |         if (remainder == 1) { | 
 |  |  |             // 得到当前库位的外围库位 | 
 |  |  |             targetRow =  row + 1; | 
 |  |  |         } else if (remainder == 0) { | 
 |  |  |             // 得到当前库位的内围库位 | 
 |  |  |             targetRow =  row - 1; | 
 |  |  |         } else { | 
 |  |  |             return; | 
 |  |  |     /** | 
 |  |  |      * 检索库位号 | 
 |  |  |      * | 
 |  |  |      * @param staDescId   路径ID | 
 |  |  |      * @param sourceStaNo 源站 | 
 |  |  |      * @param matnr       物料号集合 | 
 |  |  |      * @return locNo 检索到的库位号 | 
 |  |  |      */ | 
 |  |  |     @Transactional | 
 |  |  |     public StartupDto getLocNo( Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, LocTypeDto locTypeDto,boolean mixture) { | 
 |  |  |         try{ | 
 |  |  |             Integer whsType = Utils.GetWhsType(sourceStaNo); | 
 |  |  |             RowLastno rowLastno = rowLastnoService.selectById(whsType); | 
 |  |  |             RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId()); | 
 |  |  |             /** | 
 |  |  |              * 库型 1: 标准堆垛机库  2: 平库  3: 穿梭板  4: 四向车  5: AGV  0: 未知 | 
 |  |  |              */ | 
 |  |  |             switch (rowLastnoType.getType()){ | 
 |  |  |                 case 1: | 
 |  |  |                     return getLocNoRun(whsType,staDescId,sourceStaNo,matnr,batch,grade,0,locTypeDto,0); | 
 |  |  |                 case 2: | 
 |  |  |                     log.error("站点={} 未查询到对应的规则",sourceStaNo); | 
 |  |  |                     break; | 
 |  |  |                 case 3: | 
 |  |  |                     log.error("站点={} 未查询到对应的规则",sourceStaNo); | 
 |  |  |                     break; | 
 |  |  |                 case 4: | 
 |  |  |                     return getLocNoRun4(whsType,staDescId,sourceStaNo,matnr,batch,grade,4,locTypeDto,0,mixture); | 
 |  |  |                 case 5: | 
 |  |  |                     return getLocNoRun5(whsType,staDescId,sourceStaNo,matnr,batch,grade,0,locTypeDto,0); | 
 |  |  |                 default: | 
 |  |  |                     log.error("站点={} 未查询到对应的规则",sourceStaNo); | 
 |  |  |                     break; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         }catch (Exception e){ | 
 |  |  |             log.error("站点={} 未查询到对应的规则",sourceStaNo); | 
 |  |  |         } | 
 |  |  |         String zerofill = zerofill(String.valueOf(targetRow), 2)+locNo.substring(2); | 
 |  |  |         System.out.println(zerofill); | 
 |  |  |         return null; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 检索库位号 | 
 |  |  |      * | 
 |  |  |      * @param whsType     类型 1:双深式货架 | 
 |  |  |      * @param staDescId   路径ID | 
 |  |  |      * @param sourceStaNo 源站 | 
 |  |  |      * @param matnr       物料号集合 | 
 |  |  |      * @return locNo 检索到的库位号 | 
 |  |  |      */ | 
 |  |  |     @Transactional | 
 |  |  |     public StartupDto getLocNoRun(Integer whsType, Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, Integer moveCrnNo, LocTypeDto locTypeDto, int times) { | 
 |  |  |         if (Cools.isEmpty(matnr)) {  //物料号 | 
 |  |  |             matnr = ""; | 
 |  |  |         } | 
 |  |  |         if (Cools.isEmpty(batch)) {  //批次 | 
 |  |  |             batch = ""; | 
 |  |  |         } | 
 |  |  |         if (Cools.isEmpty(grade)) {  //备用 | 
 |  |  |             grade = ""; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 初始化参数 | 
 |  |  |         int crnNo = 0;      //堆垛机号 | 
 |  |  |         int nearRow = 0;    //最浅库位排 | 
 |  |  |         int curRow = 0;     //最深库位排 | 
 |  |  |         int rowCount = 0;   //轮询轮次 | 
 |  |  |         LocMast locMast = null;     // 目标库位 | 
 |  |  |  | 
 |  |  |         StartupDto startupDto = new StartupDto(); | 
 |  |  |         RowLastno rowLastno = rowLastnoService.selectById(whsType); | 
 |  |  |         if (Cools.isEmpty(rowLastno)) { | 
 |  |  |             throw new CoolException("数据异常,请联系管理员===>库位规则未知"); | 
 |  |  |         } | 
 |  |  |         RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId()); | 
 |  |  |         if (Cools.isEmpty(rowLastnoType)) { | 
 |  |  |             throw new CoolException("数据异常,请联系管理员===》库位规则类型未知"); | 
 |  |  |         } | 
 |  |  |         int sRow = rowLastno.getsRow(); | 
 |  |  |         int eRow = rowLastno.geteRow(); | 
 |  |  |         int crnNumber = rowLastno.getCrnQty(); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         // ===============>>>> 开始执行 | 
 |  |  |         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*2; i++) { | 
 |  |  |             int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRow, crnNumber,whsType); | 
 |  |  |             curRow = locNecessaryParameters[1]; | 
 |  |  |             crnNo = locNecessaryParameters[2]; | 
 |  |  |             if (basCrnpService.checkSiteError(crnNo, true)) { | 
 |  |  |                 rowCount =  locNecessaryParameters[0]; | 
 |  |  |                 nearRow = locNecessaryParameters[3]; | 
 |  |  |                 List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                         .eq("row1", nearRow).eq("loc_sts", "O").eq("whs_type",rowLastnoType.getType().longValue())); | 
 |  |  |                 int crnCountO = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", crnNo).le("io_type",100)); | 
 |  |  |                 if (locMasts.size()-crnCountO<=2){ | 
 |  |  |                     times++; | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 break; | 
 |  |  |             } else { | 
 |  |  |                 times++; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         if (nearRow == 0) { | 
 |  |  |             throw new CoolException("无可用堆垛机"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         boolean signRule1 = false; | 
 |  |  |         boolean signRule2 = false; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         if (Utils.BooleanWhsTypeStaIoType(rowLastno)){ | 
 |  |  |             // 靠近摆放规则 --- 同天同规格物料 //分离版 | 
 |  |  |             if (!Cools.isEmpty(matnr) &&  staDescId == 1){ | 
 |  |  |                 signRule1 = true; | 
 |  |  |             } | 
 |  |  |             // 靠近摆放规则 --- 同天同规格物料 //互通版 | 
 |  |  |             if (!Cools.isEmpty(matnr) && staDescId == 1) { | 
 |  |  |                 signRule2 = true; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             if (!Cools.isEmpty(matnr) &&  (staDescId == 11 || staDescId == 111)) { | 
 |  |  |                 signRule1 = true; | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (signRule1){ | 
 |  |  |             if (nearRow!=curRow){ | 
 |  |  |                 List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                         .eq("row1", nearRow).eq("loc_sts", "O").eq("whs_type",rowLastnoType.getType().longValue())); | 
 |  |  |                 for (LocMast locMast1:locMasts){ | 
 |  |  |                     //获取巷道 | 
 |  |  | //                    List<String> groupOutsideLocCrn = Utils.getGroupOutLocCrn(curRow,nearRow,locMast1.getLocNo(), curRow>nearRow); | 
 |  |  | //                    LocMast locMastGro = locMastService.selectById(wrkMast.getLocNo()); | 
 |  |  |                     //获取目标库位所在巷道最浅非空库位 | 
 |  |  |                     LocMast locMastF = locMastService.selectLocByLocStsPakInF(curRow,nearRow,locMast1,rowLastnoType.getType().longValue()); | 
 |  |  |                     if (!Cools.isEmpty(locMastF) && locMastF.getLocSts().equals("F")){ | 
 |  |  |                         LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", locMastF.getLocNo())); | 
 |  |  |                         if (!Cools.isEmpty(locDetl) && matnr.equals(locDetl.getMatnr()) | 
 |  |  |                                 && batch.equals(batch.isEmpty() ? "" : locDetl.getBatch()) | 
 |  |  |                                 && grade.equals(grade.isEmpty() ? "" : locDetl.getBrand())) { | 
 |  |  |                             //获取目标库位所在巷道最深空库位 | 
 |  |  |                             locMast = locMastService.selectLocByLocStsPakInO(curRow,nearRow,locMast1,rowLastnoType.getType().longValue()); | 
 |  |  |                             break; | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         }else if (signRule2){ | 
 |  |  |             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.locMoveCheckLocTypeComplete(shallowLoc, locTypeDto)) { | 
 |  |  |                         if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) { | 
 |  |  |                             locMast = shallowLoc; | 
 |  |  |                             crnNo = locMast.getCrnNo(); | 
 |  |  |                             break; | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  | //        // 靠近摆放规则 --- 空托  //分离版 | 
 |  |  | //        if (staDescId == 10 && Utils.BooleanWhsTypeStaIoType(whsType)) { | 
 |  |  | //            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("row1", nearRow).eq("loc_sts", "O")); | 
 |  |  | //            for (LocMast locMast1:locMasts){ | 
 |  |  | //                if (VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { | 
 |  |  | //                    continue; | 
 |  |  | //                } | 
 |  |  | //                String shallowLoc = Utils.getDeepLoc(slaveProperties,locMast1.getLocNo()); | 
 |  |  | //                LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no",shallowLoc)); | 
 |  |  | //                if (!Cools.isEmpty(locMast2) && locMast2.getLocSts().equals("D")){ | 
 |  |  | //                    locMast = locMast1; | 
 |  |  | //                    break; | 
 |  |  | //                } | 
 |  |  | //            } | 
 |  |  | //        } | 
 |  |  |  | 
 |  |  |         // 靠近摆放规则 --- 空托 //互通版 | 
 |  |  |         if (staDescId == 10  && Utils.BooleanWhsTypeStaIoType(rowLastno)) { | 
 |  |  |             List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                     .eq("loc_sts", "D").ge("row1", sRow).le("row1", eRow).eq("whs_type",rowLastnoType.getType().longValue())); | 
 |  |  |             if (!locMasts.isEmpty()) { | 
 |  |  |                 for (LocMast loc : locMasts) { | 
 |  |  |                     if (Utils.isShallowLoc(slaveProperties, loc.getLocNo())) { | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  |                     String shallowLocNo = Utils.getShallowLoc(slaveProperties, loc.getLocNo()); | 
 |  |  |                     // 检测目标库位是否为空库位 | 
 |  |  |                     LocMast shallowLoc = locMastService.selectById(shallowLocNo); | 
 |  |  |                     if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) { | 
 |  |  |                         if (VersionUtils.locMoveCheckLocTypeComplete(shallowLoc, locTypeDto)) { | 
 |  |  |                             if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) { | 
 |  |  |                                 locMast = shallowLoc; | 
 |  |  |                                 crnNo = locMast.getCrnNo(); | 
 |  |  |                                 break; | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Wrapper<StaDesc> wrapper = null; | 
 |  |  |         StaDesc staDesc = null; | 
 |  |  |         BasDevp staNo = null; | 
 |  |  |  | 
 |  |  |         if (Utils.BooleanWhsTypeSta(rowLastno, 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); | 
 |  |  | //                throw new CoolException("入库路径不存在"); | 
 |  |  |                 crnNo = 0; | 
 |  |  |             }else { | 
 |  |  |                 staNo = basDevpService.selectById(staDesc.getCrnStn()); | 
 |  |  |                 if (!staNo.getAutoing().equals("Y")) { | 
 |  |  |                     log.error("目标站"+staDesc.getCrnStn()+"不可用"); | 
 |  |  | //                throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用"); | 
 |  |  |                     crnNo = 0; | 
 |  |  |                 } | 
 |  |  |                 startupDto.setStaNo(staNo.getDevNo()); | 
 |  |  |             } | 
 |  |  |             // 更新库位排号 | 
 |  |  |             if (Cools.isEmpty(locMast)){ | 
 |  |  |                 rowLastno.setCurrentRow(curRow); | 
 |  |  |                 rowLastnoService.updateById(rowLastno); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 开始查找库位 ==============================>> | 
 |  |  |  | 
 |  |  |         // 1.按规则查找库位 | 
 |  |  |         if (Cools.isEmpty(locMast) && crnNo != 0) { | 
 |  |  |             List<LocMast> locMasts = null; | 
 |  |  |             if (Utils.isNorth(sourceStaNo)){ | 
 |  |  |                 locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                         .eq("row1", nearRow) | 
 |  |  |                         .eq("loc_sts", "O").eq("whs_type",rowLastnoType.getType().longValue()) | 
 |  |  |                         .orderBy("lev1",true).orderBy("bay1",false)); | 
 |  |  |             }else { | 
 |  |  |                 locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                         .eq("row1", nearRow) | 
 |  |  |                         .eq("loc_sts", "O").eq("whs_type",rowLastnoType.getType().longValue()) | 
 |  |  |                         .orderBy("lev1",true).orderBy("bay1",true)); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             for (LocMast locMast1 : locMasts) { | 
 |  |  |                 if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 if (Utils.BooleanWhsTypeStaIoType(rowLastno)){ | 
 |  |  |                     String shallowLoc = Utils.getDeepLoc(slaveProperties, locMast1.getLocNo()); | 
 |  |  |                     LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>() | 
 |  |  |                             .eq("loc_no", shallowLoc).eq("loc_sts", "O").eq("whs_type",rowLastnoType.getType().longValue())); | 
 |  |  |                     if (!Cools.isEmpty(locMast2)) { | 
 |  |  |                         locMast = locMast2; | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                 } else { | 
 |  |  |                     if (!Cools.isEmpty(locMast1)) { | 
 |  |  |                         locMast = locMast1; | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             if (Cools.isEmpty(locMast) && Utils.BooleanWhsTypeStaIoType(rowLastno)){ | 
 |  |  |                 for (LocMast locMast1 : locMasts) { | 
 |  |  |                     if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  |                     if (Utils.BooleanWhsTypeStaIoType(rowLastno)){ | 
 |  |  |                         String shallowLoc = Utils.getDeepLoc(slaveProperties, locMast1.getLocNo()); | 
 |  |  |                         LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>() | 
 |  |  |                                 .eq("loc_no", shallowLoc).eq("loc_sts", "O").eq("whs_type",rowLastnoType.getType().longValue())); | 
 |  |  |                         if (!Cools.isEmpty(locMast2)) { | 
 |  |  |                             locMast = locMast2; | 
 |  |  |                             break; | 
 |  |  |                         } else { | 
 |  |  |                             locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>() | 
 |  |  |                                     .eq("loc_no", shallowLoc).eq("loc_sts", "F").eq("whs_type",rowLastnoType.getType().longValue())); | 
 |  |  |                             if (!Cools.isEmpty(locMast2)) { | 
 |  |  |                                 locMast = locMast1; | 
 |  |  |                                 break; | 
 |  |  |                             } else { | 
 |  |  |                                 locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>() | 
 |  |  |                                         .eq("loc_no", shallowLoc).eq("loc_sts", "D").eq("whs_type",rowLastnoType.getType().longValue())); | 
 |  |  |                                 if (!Cools.isEmpty(locMast2)) { | 
 |  |  |                                     locMast = locMast1; | 
 |  |  |                                     break; | 
 |  |  |                                 } | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                     } else { | 
 |  |  |                         if (!Cools.isEmpty(locMast1)) { | 
 |  |  |                             locMast = locMast1; | 
 |  |  |                             break; | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (!Cools.isEmpty(locMast) && !basCrnpService.checkSiteError(crnNo, true)) { | 
 |  |  |             locMast = null; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 递归查询 | 
 |  |  |         if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) { | 
 |  |  |             // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归 | 
 |  |  |             if (times < rowCount*2) { | 
 |  |  |                 times = times + 1; | 
 |  |  |                 return getLocNoRun(whsType, staDescId, sourceStaNo, matnr, batch, grade,moveCrnNo, locTypeDto, times); | 
 |  |  |             } | 
 |  |  | //            // 2.库位当前所属尺寸无空库位时,调整尺寸参数,向上兼容检索库位 | 
 |  |  | //            if (locTypeDto.getLocType1() < 2) { | 
 |  |  | //                int i = locTypeDto.getLocType1() + 1; | 
 |  |  | //                locTypeDto.setLocType1((short)i); | 
 |  |  | //                return getLocNo(1, staDescId, sourceStaNo, matnr,batch,grade, locTypeDto, 0); | 
 |  |  | //            } | 
 |  |  |             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; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public StartupDto getLocNoRun4(Integer whsType, Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, Integer moveCrnNo, LocTypeDto locTypeDto, int times,boolean mixture) { | 
 |  |  |         if (Cools.isEmpty(matnr)) {  //物料号 | 
 |  |  |             matnr = ""; | 
 |  |  |         } | 
 |  |  |         if (Cools.isEmpty(batch)) {  //批次 | 
 |  |  |             batch = ""; | 
 |  |  |         } | 
 |  |  |         if (Cools.isEmpty(grade)) {  //备用 | 
 |  |  |             grade = ""; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 初始化参数 | 
 |  |  |         int crnNo = 0;      //堆垛机号 | 
 |  |  |         int nearRow = 0;    //最浅库位排 | 
 |  |  |         int curRow = 0;     //最深库位排 | 
 |  |  |         int rowCount = 0;   //轮询轮次 | 
 |  |  |         LocMast locMast = null;     // 目标库位 | 
 |  |  |  | 
 |  |  |         StartupDto startupDto = new StartupDto(); | 
 |  |  |         RowLastno rowLastno = rowLastnoService.selectById(whsType); | 
 |  |  |         if (Cools.isEmpty(rowLastno)) { | 
 |  |  |             throw new CoolException("数据异常,请联系管理员===>库位规则未知"); | 
 |  |  |         } | 
 |  |  |         RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId()); | 
 |  |  |         if (Cools.isEmpty(rowLastnoType)) { | 
 |  |  |             throw new CoolException("数据异常,请联系管理员===》库位规则类型未知"); | 
 |  |  |         } | 
 |  |  |         int sRow = rowLastno.getsRow(); | 
 |  |  |         int eRow = rowLastno.geteRow(); | 
 |  |  |         int crnNumber = rowLastno.getCrnQty(); | 
 |  |  |  | 
 |  |  |         // ===============>>>> 开始执行 | 
 |  |  |         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*2; i++) { | 
 |  |  |             int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRow, crnNumber,whsType); | 
 |  |  |             rowCount =  locNecessaryParameters[0]; | 
 |  |  |             curRow = locNecessaryParameters[1]; | 
 |  |  |             crnNo = locNecessaryParameters[2]; | 
 |  |  |             nearRow = locNecessaryParameters[3]; | 
 |  |  |             List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                     .eq("crn_no", crnNo).eq("loc_sts", "O").eq("whs_type",rowLastnoType.getType().longValue())); | 
 |  |  |             if (locMasts.size()<=5){ | 
 |  |  |                 times++; | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |             break; | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |         if (crnNo == 0) { | 
 |  |  |             throw new CoolException("无可用库位"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         // 相似工作档案 --- 同天同规格物料 | 
 |  |  |         if (!Cools.isEmpty(matnr) && (staDescId == 1 || staDescId == 11 || staDescId == 111) && !mixture ) { | 
 |  |  |             //查询相似工作档案 | 
 |  |  |             List<WrkMast> wrkMasts = wrkMastService.selectWrkMastWrkDetlMatnrBatch(staDescId, matnr, batch,grade, crnNo); | 
 |  |  |             int nearbay = 0;    //相似工作档案 目标库位列 | 
 |  |  |             int nearlev = 0;    //相似工作档案 目标库位层 | 
 |  |  |             for (WrkMast wrkMast:wrkMasts){ | 
 |  |  |                 LocMast locMastWrk = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", wrkMast.getLocNo())); | 
 |  |  |                 List<LocMast> locMasts = new ArrayList<>(); | 
 |  |  |                 if (locMastWrk.getBay1() >=1 && locMastWrk.getBay1()<=2){ | 
 |  |  |                     locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                             .eq("gro1", locMastWrk.getGro1()) | 
 |  |  |                             .eq("crn_no", 7) | 
 |  |  |                             .eq("loc_type1",locTypeDto.getLocType1()) | 
 |  |  |                             .orderBy("bay1", true)); | 
 |  |  |                 }else if (locMastWrk.getBay1() >=4 && locMastWrk.getBay1()<=12){ | 
 |  |  |                     locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                             .eq("gro1", locMastWrk.getGro1()) | 
 |  |  |                             .eq("crn_no", 7) | 
 |  |  |                             .eq("loc_type1",locTypeDto.getLocType1()) | 
 |  |  |                             .orderBy("bay1", false)); | 
 |  |  |                 }else { | 
 |  |  |                     locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                             .eq("gro1", locMastWrk.getGro1()) | 
 |  |  |                             .eq("crn_no", 7) | 
 |  |  |                             .eq("loc_type1",locTypeDto.getLocType1()) | 
 |  |  |                             .orderBy("bay1", true)); | 
 |  |  |                 } | 
 |  |  |                 if (Cools.isEmpty(locMasts)) { | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 for (LocMast locMastGro1 : locMasts) { | 
 |  |  |  | 
 |  |  |                     if (locMastGro1.getBay1() == 2){ //wcs问题限制 | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  |                     if (locMastGro1.getLocSts().equals("P") || locMastGro1.getLocSts().equals("Q")) { | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                     if (locMastGro1.getLocSts().equals("O")){ | 
 |  |  |                         locMast = locMastGro1; | 
 |  |  |                         break; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Wrapper<StaDesc> wrapper = null; | 
 |  |  |         StaDesc staDesc = null; | 
 |  |  |         BasDevp staNo = null; | 
 |  |  |  | 
 |  |  |         if (Utils.BooleanWhsTypeSta(rowLastno, 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; | 
 |  |  |             }else { | 
 |  |  |                 staNo = basDevpService.selectById(staDesc.getCrnStn()); | 
 |  |  |                 if (!staNo.getAutoing().equals("Y")) { | 
 |  |  |                     log.error("目标站"+staDesc.getCrnStn()+"不可用"); | 
 |  |  |                     crnNo = 0; | 
 |  |  |                 } | 
 |  |  |                 startupDto.setStaNo(staNo.getDevNo()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 更新库位排号 | 
 |  |  |         if (Utils.BooleanWhsTypeSta(rowLastno, staDescId) && Cools.isEmpty(locMast)) { | 
 |  |  |             rowLastno.setCurrentRow(curRow); | 
 |  |  |             rowLastnoService.updateById(rowLastno); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 开始查找库位 ==============================>> | 
 |  |  |  | 
 |  |  |         // 1.按规则查找库位 | 
 |  |  |         if (Cools.isEmpty(locMast) && crnNo != 0) { | 
 |  |  |             List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                     .eq("bay1", nearRow) | 
 |  |  |                     .in("loc_sts", "O","X").eq("whs_type",rowLastnoType.getType().longValue()) | 
 |  |  |                     .eq("crn_no",7) | 
 |  |  |                     .eq("loc_type1",locTypeDto.getLocType1()) | 
 |  |  |                     .orderBy("lev1",true).orderBy("row1",false));//最浅库位 | 
 |  |  |  | 
 |  |  |             for (LocMast locMast1 : locMasts) { | 
 |  |  |                 if (locMast != null){ | 
 |  |  |                     break; | 
 |  |  |                 } | 
 |  |  |                 if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 if (Utils.BooleanWhsTypeStaIoType(rowLastno)){ | 
 |  |  |                     //获取目标库位所在巷道最深空库位 | 
 |  |  | //                    LocMast locMast2 = locMastService.selectLocByLocStsPakInO(curRow,nearRow,locMast1,rowLastnoType.getType().longValue()); | 
 |  |  | //                    if (!Cools.isEmpty(locMast2) && locMast2.getBay1()==curRow) { | 
 |  |  | //                        locMast = locMast2; | 
 |  |  | //                        break; | 
 |  |  | //                    } | 
 |  |  |                     List<LocMast> locMasts1 = null; | 
 |  |  |                     if (curRow < nearRow){ | 
 |  |  |                         locMasts1 = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                                 .eq("gro1", locMast1.getGro1()) | 
 |  |  |                                 .eq("crn_no",7) | 
 |  |  |                                 .eq("loc_type1",locTypeDto.getLocType1()) | 
 |  |  |                                 .orderBy("bay1",true)); | 
 |  |  |                         if(locMast1.getBay1()>= 4 && locMast1.getBay1()<=12){ | 
 |  |  |                             locMasts1 = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                                     .eq("gro1", locMast1.getGro1()) | 
 |  |  |                                     .eq("crn_no",7) | 
 |  |  |                                     .eq("loc_type1",locTypeDto.getLocType1()) | 
 |  |  |                                     .orderBy("bay1",false)); | 
 |  |  |                         } | 
 |  |  |                     }else { | 
 |  |  |                         locMasts1 = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                                 .eq("gro1", locMast1.getGro1()) | 
 |  |  |                                 .eq("crn_no",7) | 
 |  |  |                                 .eq("loc_type1",locTypeDto.getLocType1()) | 
 |  |  |                                 .orderBy("bay1",false)); | 
 |  |  |                     } | 
 |  |  |                     if (Cools.isEmpty(locMasts1)) { | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  |                     for (LocMast locMastGro1 : locMasts1) { | 
 |  |  |                         if (mixture){ //混料只允许放 7 12 14 | 
 |  |  |                             if (locMastGro1.getBay1() != 7 && locMastGro1.getBay1() != 12 && locMastGro1.getBay1() != 14){ | 
 |  |  |                                 continue; | 
 |  |  |                             } | 
 |  |  |                         }else { //不混料不允许放 7 12 14 | 
 |  |  |                             if (locMastGro1.getBay1() == 7 || locMastGro1.getBay1() == 12 || locMastGro1.getBay1() == 14){ | 
 |  |  |                                 continue; | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                         if (locMastGro1.getLocSts().equals("F")){ | 
 |  |  |                             LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_No", locMastGro1.getLocNo())); | 
 |  |  |                             if (!locDetl.getMatnr().equals(matnr) || !locDetl.getBatch().equals(batch)){ | 
 |  |  |                                 break; | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                         if (locMastGro1.getLocSts().equals("P") || locMastGro1.getLocSts().equals("Q") || locMastGro1.getLocSts().equals("R")) { | 
 |  |  |                             break; | 
 |  |  |                         } | 
 |  |  |                         if (locMastGro1.getLocSts().equals("O")){ | 
 |  |  |                             locMast = locMastGro1; | 
 |  |  |                             break; | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 递归查询 | 
 |  |  |         if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) { | 
 |  |  |             // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归 | 
 |  |  |             if (times < rowCount*2) { | 
 |  |  |                 times = times + 1; | 
 |  |  |                 return getLocNoRun4(whsType, staDescId, sourceStaNo, matnr, batch, grade,moveCrnNo, locTypeDto, times,mixture); | 
 |  |  |             } | 
 |  |  |             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; | 
 |  |  |     } | 
 |  |  |     public StartupDto getLocNoRun5(Integer whsType, Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, Integer moveCrnNo, LocTypeDto locTypeDto, int times) { | 
 |  |  |         if (Cools.isEmpty(matnr)) {  //物料号 | 
 |  |  |             matnr = ""; | 
 |  |  |         } | 
 |  |  |         if (Cools.isEmpty(batch)) {  //批次 | 
 |  |  |             batch = ""; | 
 |  |  |         } | 
 |  |  |         if (Cools.isEmpty(grade)) {  //备用 | 
 |  |  |             grade = ""; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 初始化参数 | 
 |  |  |         int crnNo = 0;      //堆垛机号 | 
 |  |  |         int nearRow = 0;    //最浅库位排 | 
 |  |  |         int curRow = 0;     //最深库位排 | 
 |  |  |         int rowCount = 0;   //轮询轮次 | 
 |  |  |         LocMast locMast = null;     // 目标库位 | 
 |  |  |  | 
 |  |  |         StartupDto startupDto = new StartupDto(); | 
 |  |  |         RowLastno rowLastno = rowLastnoService.selectById(whsType); | 
 |  |  |         if (Cools.isEmpty(rowLastno)) { | 
 |  |  |             throw new CoolException("数据异常,请联系管理员===>库位规则未知"); | 
 |  |  |         } | 
 |  |  |         RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId()); | 
 |  |  |         if (Cools.isEmpty(rowLastnoType)) { | 
 |  |  |             throw new CoolException("数据异常,请联系管理员===》库位规则类型未知"); | 
 |  |  |         } | 
 |  |  |         int sRow = rowLastno.getsRow(); | 
 |  |  |         int eRow = rowLastno.geteRow(); | 
 |  |  |         int crnNumber = eRow-sRow+1; | 
 |  |  |  | 
 |  |  |         // ===============>>>> 开始执行 | 
 |  |  |         curRow = rowLastno.getCurrentRow(); | 
 |  |  |  | 
 |  |  |         if (!Cools.isEmpty(moveCrnNo) && moveCrnNo!=0){ | 
 |  |  |             crnNumber = moveCrnNo; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //此程序用于优化堆垛机异常时的运行时间 | 
 |  |  |         int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRow, crnNumber,whsType); | 
 |  |  |         curRow = locNecessaryParameters[1]; | 
 |  |  |         crnNo = locNecessaryParameters[2]; | 
 |  |  |         rowCount =  locNecessaryParameters[0]; | 
 |  |  |         nearRow = locNecessaryParameters[3]; | 
 |  |  |  | 
 |  |  |         Wrapper<StaDesc> wrapper = null; | 
 |  |  |         StaDesc staDesc = null; | 
 |  |  |         BasDevp staNo = null; | 
 |  |  |  | 
 |  |  |         if (Utils.BooleanWhsTypeSta(rowLastno, staDescId)) { | 
 |  |  |  | 
 |  |  |             LocMast locMast1 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("row1", curRow).eq("bay1", 2).eq("lev1", 1)); | 
 |  |  |             crnNo = locMast1.getCrnNo(); | 
 |  |  |             // 获取目标站 | 
 |  |  |             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); | 
 |  |  | //                throw new CoolException("入库路径不存在"); | 
 |  |  |                 crnNo = 0; | 
 |  |  |             }else { | 
 |  |  |                 staNo = basDevpService.selectById(staDesc.getCrnStn()); | 
 |  |  |                 if (!staNo.getAutoing().equals("Y")) { | 
 |  |  |                     log.error("目标站"+staDesc.getCrnStn()+"不可用"); | 
 |  |  | //                throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用"); | 
 |  |  |                     crnNo = 0; | 
 |  |  |                 } | 
 |  |  |                 startupDto.setStaNo(staNo.getDevNo()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 更新库位排号 | 
 |  |  |         if (Utils.BooleanWhsTypeSta(rowLastno, staDescId) && Cools.isEmpty(locMast)) { | 
 |  |  |             rowLastno.setCurrentRow(curRow); | 
 |  |  |             rowLastnoService.updateById(rowLastno); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 开始查找库位 ==============================>> | 
 |  |  |  | 
 |  |  |         // 1.按规则查找库位 | 
 |  |  |         if (Cools.isEmpty(locMast) && crnNo != 0) { | 
 |  |  |             List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() | 
 |  |  |                     .eq("row1", nearRow) | 
 |  |  |                     .eq("loc_sts", "O").eq("whs_type",rowLastnoType.getType().longValue()) | 
 |  |  |                     .orderBy("lev1",true).orderBy("bay1",true));//最浅库位 | 
 |  |  |             for (LocMast locMast1 : locMasts) { | 
 |  |  |                 if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  | //                if (Utils.BooleanWhsTypeStaIoType(rowLastno)){ | 
 |  |  | //                    //获取目标库位所在巷道最深空库位 | 
 |  |  | //                    LocMast locMast2 = locMastService.selectLocByLocStsPakInO(curRow,nearRow,locMast1,rowLastnoType.getType().longValue()); | 
 |  |  | //                    if (!Cools.isEmpty(locMast2) && locMast2.getBay1()==curRow) { | 
 |  |  |                         locMast = locMast1; | 
 |  |  |                         break; | 
 |  |  | //                    } | 
 |  |  | //                } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 递归查询 | 
 |  |  |         if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) { | 
 |  |  |             // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归 | 
 |  |  |             if (times < rowCount*2) { | 
 |  |  |                 times = times + 1; | 
 |  |  |  | 
 |  |  |                 return getLocNoRun5(whsType, staDescId, sourceStaNo, matnr, batch, grade,moveCrnNo, locTypeDto, times); | 
 |  |  |             } | 
 |  |  |             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; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public static String zerofill(String msg, Integer count) { | 
 |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } | 
 |  |  | } |