|  |  |  | 
|---|
|  |  |  | 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 java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class CommonService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final List<Integer> FIRST_GROUP_ROW_LIST = new ArrayList<Integer>() {{ | 
|---|
|  |  |  | add(2);add(3);add(4);add(5);add(6);add(7);add(8);add(9);add(10); | 
|---|
|  |  |  | add(11);add(12);add(13);add(14);add(15);add(16);add(17); | 
|---|
|  |  |  | }}; | 
|---|
|  |  |  | public static final List<Integer> SECOND_GROUP_ROW_LIST = new ArrayList<Integer>() {{ | 
|---|
|  |  |  | add(18);add(19);add(20); | 
|---|
|  |  |  | add(21);add(22);add(23);add(24);add(25);add(26);add(27);add(28);add(29);add(30); | 
|---|
|  |  |  | }}; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WrkMastService wrkMastService; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto, LocTypeDto oldLocType, int times) { | 
|---|
|  |  |  | StartupDto startupDto = new StartupDto(); | 
|---|
|  |  |  | if (sourceStaNo == 100) { // 轻货信号 | 
|---|
|  |  |  | whsType = 1;    // 1 - 11 左 | 
|---|
|  |  |  | } else if (sourceStaNo == 200) { // 重货信号 | 
|---|
|  |  |  | whsType = 2;    // 12 - 21 右 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | whsType = 1; | 
|---|
|  |  |  | // 生成工作号 | 
|---|
|  |  |  | int workNo = getWorkNo(0); | 
|---|
|  |  |  | RowLastno rowLastno = rowLastnoService.selectById(whsType); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 如果没有相近物料,则按规则轮询货架 | 
|---|
|  |  |  | if (null == locMast) { | 
|---|
|  |  |  | int t = 0; | 
|---|
|  |  |  | boolean execute = true; | 
|---|
|  |  |  | int crnNo1; | 
|---|
|  |  |  | // 1 - 11排 | 
|---|
|  |  |  | if (whsType == 1) { | 
|---|
|  |  |  | while (execute && t < 4) { | 
|---|
|  |  |  | t++; | 
|---|
|  |  |  | switch (curRow) { | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | curRow = 11; | 
|---|
|  |  |  | crnNo1 = 2; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 11: | 
|---|
|  |  |  | curRow = 4; | 
|---|
|  |  |  | crnNo1 = 1; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 4: | 
|---|
|  |  |  | curRow = 12; | 
|---|
|  |  |  | crnNo1 = 2; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | curRow = 3; | 
|---|
|  |  |  | crnNo1 = 1; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (basCrnpService.checkSiteError(crnNo1, true)) { | 
|---|
|  |  |  | crnNo = crnNo1; | 
|---|
|  |  |  | execute = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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("检索库位失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 12 - 21排 | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | while (execute && t < 4) { | 
|---|
|  |  |  | t++; | 
|---|
|  |  |  | switch (curRow) { | 
|---|
|  |  |  | case 11: | 
|---|
|  |  |  | curRow = 18; | 
|---|
|  |  |  | crnNo1 = 3; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 18: | 
|---|
|  |  |  | curRow = 12; | 
|---|
|  |  |  | crnNo1 = 2; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 12: | 
|---|
|  |  |  | curRow = 19; | 
|---|
|  |  |  | crnNo1 = 3; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | curRow = 11; | 
|---|
|  |  |  | crnNo1 = 2; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (basCrnpService.checkSiteError(crnNo1, true)) { | 
|---|
|  |  |  | crnNo = crnNo1; | 
|---|
|  |  |  | execute = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer crnNo1 = shelves.get(curRow); | 
|---|
|  |  |  | if (basCrnpService.checkSiteError(crnNo1, true)) { | 
|---|
|  |  |  | crnNo = crnNo1; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 1.当检索库排为浅库位排时,优先寻找当前库排的深库位排 | 
|---|
|  |  |  | if (locMast == null) { | 
|---|
|  |  |  | locMast = locMastService.queryFreeLocMast(curRow, locTypeDto.getLocType1()); | 
|---|
|  |  |  | // 因库位移转、需预留空库位 | 
|---|
|  |  |  | if (!locMastService.checkEmptyCount(locMast)) { | 
|---|
|  |  |  | locMast = null; | 
|---|
|  |  |  | List<Integer> rows; | 
|---|
|  |  |  | switch (curRow) { | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | rows = FIRST_GROUP_ROW_LIST; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | rows = SECOND_GROUP_ROW_LIST; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | throw new CoolException("入库逻辑故障【" + curRow + "】"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | locMast = locMastService.queryFreeLocMast(curRow, rows, locTypeDto.getLocType1()); | 
|---|
|  |  |  | // 因库位移转、需预留空库位 | 
|---|
|  |  |  | //            if (!locMastService.checkEmptyCount(locMast)) { | 
|---|
|  |  |  | //                locMast = null; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 2.库位当前所属尺寸无空库位时,调整尺寸参数,向上兼容检索库位 | 
|---|
|  |  |  | 
|---|
|  |  |  | if (times < rowCount) { | 
|---|
|  |  |  | times = times + 1; | 
|---|
|  |  |  | return getLocNo(whsType, staDescId, sourceStaNo, matNos, locTypeDto, oldLocType, times); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | times = 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            // 货物检索低库位仓失败,兼容高库位仓后继续执行 | 
|---|
|  |  |  | //            if (locTypeDto.getLocType1() == 1) { | 
|---|
|  |  |  | //                locTypeDto.setLocType1((short) 2); | 
|---|
|  |  |  | //                return getLocNo(1, staDescId, sourceStaNo, emptyMk, matNos, locTypeDto, oldLocType, times); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // 货物检索低库位仓失败,兼容高库位仓后继续执行 | 
|---|
|  |  |  | if (locTypeDto.getLocType1() == 1) { | 
|---|
|  |  |  | locTypeDto.setLocType1((short) 2); | 
|---|
|  |  |  | return getLocNo(1, staDescId, sourceStaNo, matNos, locTypeDto, oldLocType, times); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times); | 
|---|
|  |  |  | throw new CoolException("没有空库位"); | 
|---|
|  |  |  | } | 
|---|