| | |
| | | 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.FindLocNoAttributeVo; |
| | | 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 com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | 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; |
| | | |
| | |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private WrkDetlService wrkDetlService; |
| | | @Autowired |
| | | private ConfigService configService; |
| | | |
| | | /** |
| | | * 生成工作号 |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | Config crnSearchListConfig = configService.selectConfigByCode("123CrnSearchList"); |
| | | int crnSearchList = Integer.parseInt(crnSearchListConfig.getValue()); |
| | | |
| | | //此程序用于优化堆垛机异常时的运行时间 |
| | | for (int i = times; i < crnNumber * 2; i++) { |
| | | int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRow, crnNumber); |
| | |
| | | times++; |
| | | } |
| | | } |
| | | |
| | | //优化系统,提高搜索1号堆垛机次数 |
| | | if (crnNo == 2 || crnNo == 3) { |
| | | if (crnSearchList >= 2) { |
| | | //尝试找1号弯轨堆垛机库位 |
| | | crnNo = 1; |
| | | if (basCrnpService.checkSiteError(crnNo, true)) { |
| | | List<Integer> nearRowList = new ArrayList<Integer>() {{ |
| | | add(4); |
| | | add(6); |
| | | add(3); |
| | | add(1); |
| | | }}; |
| | | for (Integer near : nearRowList) { |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("row1", near) |
| | | .eq("loc_sts", "O") |
| | | .eq("whs_type", rowLastnoType.getType().longValue()) |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | .eq("loc_type2", locTypeDto.getLocType2()) |
| | | ); |
| | | int crnCountO = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", crnNo).le("io_type", 100)); |
| | | if (locMasts.size() - crnCountO <= 2) { |
| | | log.error(crnNo + "号堆垛机没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times); |
| | | } else { |
| | | nearRow = near; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (nearRow == 0) { |
| | | throw new CoolException("无可用堆垛机"); |
| | | if (locTypeDto.getLocType2() == 2) { |
| | | //尝试找1号弯轨堆垛机库位 |
| | | crnNo = 1; |
| | | if (basCrnpService.checkSiteError(crnNo, true)) { |
| | | List<Integer> nearRowList = new ArrayList<Integer>() {{ |
| | | add(4); |
| | | add(6); |
| | | add(3); |
| | | add(1); |
| | | }}; |
| | | for (Integer near : nearRowList) { |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("row1", near) |
| | | .eq("loc_sts", "O") |
| | | .eq("whs_type", rowLastnoType.getType().longValue()) |
| | | .eq("loc_type1", locTypeDto.getLocType1()) |
| | | .eq("loc_type2", locTypeDto.getLocType2()) |
| | | ); |
| | | int crnCountO = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", crnNo).le("io_type", 100)); |
| | | if (locMasts.size() - crnCountO <= 2) { |
| | | log.error(crnNo + "号堆垛机没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times); |
| | | } else { |
| | | nearRow = near; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (nearRow == 0) { |
| | | throw new CoolException("无可用堆垛机"); |
| | | } |
| | | } |
| | | // else { |
| | | // throw new CoolException("无可用堆垛机"); |
| | | // } |
| | | } |
| | | |
| | | boolean signRule1 = false; |
| | |
| | | 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()); |
| | | if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { |
| | | continue; |
| | | } |
| | | |
| | | if (crnNo == 1) { |
| | | if (locMast1.getRow1() == 1 || locMast1.getRow1() == 6) { |
| | | locMast = locMast1;//单深库位直接使用 |
| | | break; |
| | | } |
| | | |
| | | //获取目标库位所在巷道最浅非空库位 |
| | | List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("whs_type", rowLastnoType.getType().longValue()) |
| | | .eq("crn_no", locMast1.getCrnNo()) |
| | | .eq("bay1", locMast1.getBay1()) |
| | | .notIn("loc_sts", "O") |
| | | .orderBy("row1", false) |
| | | ); |
| | | if (locMastList.isEmpty()) { |
| | | locMast = locMast1; |
| | | break; |
| | | } |
| | | |
| | | LocMast locMastF = locMastList.get(0); |
| | | if (!slaveProperties.getDoubleLocs().contains(locMastF.getRow1())) { |
| | | continue; |
| | | } |
| | | |
| | | LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", locMastF.getLocNo())); |
| | | if (!Cools.isEmpty(locDetl) && findLocNoAttributeVo.beSimilar(locDetl)) { |
| | | String shallowLoc = Utils.getShallowLoc(slaveProperties, locMastF.getLocNo()); |
| | | LocMast shallowLocMast = locMastService.selectOne(new EntityWrapper<LocMast>() |
| | | .eq("loc_no", shallowLoc) |
| | | .eq("loc_sts", "O") |
| | | ); |
| | | if (shallowLocMast != null) { |
| | | locMast = shallowLocMast; |
| | | break; |
| | | } |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | //获取目标库位所在巷道最浅非空库位 |
| | | LocMast locMastF = locMastService.selectLocByLocStsPakInF(curRow, nearRow, locMast1, rowLastnoType.getType().longValue()); |
| | | if (!Cools.isEmpty(locMastF) && locMastF.getLocSts().equals("F")) { |
| | |
| | | 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 = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | .eq("row1", nearRow) |
| | | .eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue()) |
| | | .eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue()).ne("inv_wh",1) |
| | | .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()); |
| | | String shallowLoc = Utils.getShallowLoc(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)) { |
| | |
| | | // locTypeDto.setLocType1((short)i); |
| | | // return getLocNo(1, staDescId, sourceStaNo, matnr,batch,grade, locTypeDto, 0); |
| | | // } |
| | | log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times); |
| | | log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{},{}", JSON.toJSONString(locTypeDto), times,moveCrnNo); |
| | | throw new CoolException("没有空库位"); |
| | | } |
| | | String locNo = locMast.getLocNo(); |
| | | |
| | | if (crnNo == 2 || crnNo == 3) { |
| | | crnSearchList++; |
| | | configService.updateValue("123CrnSearchList", String.valueOf(crnSearchList)); |
| | | } |
| | | |
| | | if (crnNo == 1) { |
| | | configService.updateValue("123CrnSearchList", String.valueOf(0)); |
| | | } |
| | | //针对1号堆垛机打的补丁,防止找到库位时,找到最浅库位 |
| | | String deepLoc2 = Utils.getDeepLoc2(slaveProperties, locMast.getLocNo()); |
| | | if (!Cools.isEmpty(deepLoc2)) { |
| | | LocMast locMastNew = locMastService.selectOne(new EntityWrapper<LocMast>().eq("crn_no",locMast.getCrnNo()) |
| | | .eq("loc_no", deepLoc2).eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue())); |
| | | if (!Cools.isEmpty(locMastNew)) { |
| | | locMast = locMastNew; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // 获取目标站 |
| | | wrapper = new EntityWrapper<StaDesc>() |
| | | .eq("type_no", staDescId) |
| | | .eq("stn_no", sourceStaNo) |
| | | .eq("crn_no", locMast.getCrnNo()); |
| | | 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()); |
| | | } |
| | | String locNo = locMast.getLocNo(); |
| | | // 生成工作号 |
| | | int workNo = getWorkNo(0); |
| | | // 返回dto |
| | | startupDto.setWorkNo(workNo); |
| | | startupDto.setCrnNo(crnNo); |
| | | startupDto.setCrnNo(locMast.getCrnNo()); |
| | | startupDto.setSourceStaNo(sourceStaNo); |
| | | startupDto.setLocNo(locNo); |
| | | return startupDto; |
| | |
| | | .eq("row1", nearRow) |
| | | .eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue()) |
| | | .orderBy("lev1", true).orderBy("bay1", true));//最浅库位 |
| | | //System.out.println(nearRow); |
| | | //System.out.println(curRow); |
| | | for (LocMast locMast1 : locMasts) { |
| | | if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) { |
| | | continue; |