| | |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.result.FindLocNoAttributeVo; |
| | | import com.zy.asrs.mapper.LocMastMapper; |
| | | import com.zy.asrs.mapper.WrkMastMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.Utils; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 货架核心功能 |
| | |
| | | @Resource |
| | | private WrkMastMapper wrkMastMapper; |
| | | |
| | | /** |
| | | * 罐装线号映射目标站点 下标:目标站点 |
| | | */ |
| | | private static final int[] fillingLineMappingSite = {0,1079,1065,1072}; |
| | | @Resource |
| | | private LocMastMapper locMastMapper; |
| | | |
| | | /** |
| | | * 生成工作号 |
| | |
| | | |
| | | // 入空桶库 |
| | | if (staDescId == 1 && locArea == 2) { |
| | | String model = findLocNoAttributeVo.getModel(); // 当前桶类型 |
| | | List<WrkMast> wrkMastList = wrkMastMapper.selectLastInEmptyLoc(); // 前面入空桶库的任务(未执行堆垛机入库) |
| | | |
| | | if (wrkMastList.size() == 0) { |
| | | // 取新库位组的第一个库位 |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_sts", 'O').in("row1", 9, 11).orderBy("lev1").orderBy("bay1").orderBy("row1")); |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("crn_no", 4).eq("loc_sts", "O")); |
| | | List<LocMast> collect = locMasts.stream().filter(locMast1 -> locMast1.getRow1() == 9 || locMast1.getRow1() == 11).collect(Collectors.toList()); |
| | | List<LocMast> collect1 = locMasts.stream().filter(locMast1 -> locMast1.getRow1() == 10 || locMast1.getRow1() == 12).collect(Collectors.toList()); // 第一个先放这两排 |
| | | if (collect.size() == 0 || collect1.size() == 0) { |
| | | log.error("-----空桶库无空库位----"); |
| | | throw new CoolException("空桶库无空库位"); |
| | | } |
| | | // 可用库位组 |
| | | List<LocMast> locMastList = new ArrayList<>(); |
| | | for(LocMast locMast1:collect) { |
| | | Optional<LocMast> first = collect1.stream().filter(locMast2 -> locMast1.getRow1() + 1 == locMast2.getRow1() && Objects.equals(locMast1.getLev1(), locMast2.getLev1()) |
| | | && Objects.equals(locMast1.getBay1(), locMast2.getBay1())).findFirst(); |
| | | first.ifPresent(locMastList::add); |
| | | } |
| | | |
| | | if (locMastList.size() == 0) { |
| | | log.error("-----空桶库无对应空空桶组----"); |
| | | throw new CoolException("空桶库无对应空空桶组"); |
| | | } |
| | | String model = findLocNoAttributeVo.getModel(); // 当前桶类型 |
| | | if (model.equals("208L") && locMastList.size() <= 40 * 2 * 2) { // 最上面一层只能放208L,库位剩余量不多时,如果是208L桶入库,则先从最顶层放 |
| | | locMastList = locMastList.stream().sorted(Comparator.comparing(LocMast::getLev1).reversed().thenComparing(LocMast::getBay1).thenComparing(LocMast::getRow1)).collect(Collectors.toList()); |
| | | } else { |
| | | locMastList = locMastList.stream().sorted(Comparator.comparing(LocMast::getLev1).thenComparing(LocMast::getBay1).thenComparing(LocMast::getRow1)).collect(Collectors.toList()); |
| | | } |
| | | locMast = locMastList.get(0); |
| | | |
| | | } else { |
| | | WrkMast wrkMast = wrkMastList.get(0); // 最后一个入空桶库任务 |
| | | // 前一个任务明细 |
| | | WrkDetl wrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no",wrkMast.getWrkNo())); |
| | | // 前一个任务桶类型 |
| | | String oldModel = wrkDetl.getModel(); |
| | | String oldModel = wrkMast.getPdcType(); |
| | | // 前一个任务尾托标识 |
| | | Integer oldCtnType = wrkMast.getCtnType(); |
| | | if(model.equals(oldModel)) { // 当前桶与前桶是一种类型 |
| | | // 当前桶类型 |
| | | String matnr = findLocNoAttributeVo.getMatnr(); |
| | | if(findLocNoAttributeVo.getMatnr().equals(wrkMast.getPdcType())) { // 当前桶与前桶是一种类型 |
| | | // 当前桶类型的任务有几个 |
| | | long count = wrkMastList.stream().filter(wrkMast1 -> wrkMast1.getPdcType().equals(oldModel)).count(); |
| | | long count = wrkMastList.stream().filter(wrkMast1 -> wrkMast1.getPdcType().equals(matnr)).count(); |
| | | if (count % 2 == 0) { // 偶数,取一组新库位 |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_sts", 'O').in("row1", 9, 11).orderBy("lev1").orderBy("bay1").orderBy("row1")); |
| | | // 取新库位组的第一个库位 |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("crn_no", 4).eq("loc_sts", "O")); |
| | | List<LocMast> collect = locMasts.stream().filter(locMast1 -> locMast1.getRow1() == 9 || locMast1.getRow1() == 11).collect(Collectors.toList()); |
| | | List<LocMast> collect1 = locMasts.stream().filter(locMast1 -> locMast1.getRow1() == 10 || locMast1.getRow1() == 12).collect(Collectors.toList()); // 第一个先放这两排 |
| | | if (collect.size() == 0 || collect1.size() == 0) { |
| | | log.error("-----空桶库无空库位----"); |
| | | throw new CoolException("空桶库无空库位"); |
| | | } |
| | | // 可用库位组 |
| | | List<LocMast> locMastList = new ArrayList<>(); |
| | | for(LocMast locMast1:collect) { |
| | | Optional<LocMast> first = collect1.stream().filter(locMast2 -> locMast1.getRow1() + 1 == locMast2.getRow1() && Objects.equals(locMast1.getLev1(), locMast2.getLev1()) |
| | | && Objects.equals(locMast1.getBay1(), locMast2.getBay1())).findFirst(); |
| | | first.ifPresent(locMastList::add); |
| | | } |
| | | |
| | | if (locMastList.size() == 0) { |
| | | log.error("-----空桶库无对应空空桶组----"); |
| | | throw new CoolException("空桶库无对应空空桶组"); |
| | | } |
| | | String model = findLocNoAttributeVo.getModel(); // 当前桶类型 |
| | | if (model.equals("208L") && locMastList.size() <= 40 * 2 * 2) { // 最上面一层只能放208L,库位剩余量不多时,如果是208L桶入库,则先从最顶层放 |
| | | locMastList = locMastList.stream().sorted(Comparator.comparing(LocMast::getLev1).reversed().thenComparing(LocMast::getBay1).thenComparing(LocMast::getRow1)).collect(Collectors.toList()); |
| | | } else { |
| | | locMastList = locMastList.stream().sorted(Comparator.comparing(LocMast::getLev1).thenComparing(LocMast::getBay1).thenComparing(LocMast::getRow1)).collect(Collectors.toList()); |
| | | } |
| | | locMast = locMastList.get(0); |
| | | } else { // 奇数,取前一库位对应的空库位 |
| | | String locNo = wrkMast.getLocNo(); |
| | | int row = Integer.parseInt(locNo.substring(0, 2)); |
| | | if(row == 9 || row == 11) { |
| | | String newLocNo = (row + 1) + locNo.substring(2); |
| | | if(row == 10 || row == 12) { |
| | | String newLocNo =(row == 10 ? "09" : "11") + locNo.substring(2); |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no", newLocNo).eq("loc_sts","O")); |
| | | if (locMast == null) { |
| | | log.error("-----与前面桶类型一样,前面该桶类型任务数是奇数,是9,11排,但是对应库位不为空----"); |
| | | throw new CoolException("与前面桶类型一样,前面该桶类型任务数是奇数,是9,11排,但是对应库位不为空"); |
| | | log.error("-----与前面桶类型一样,前面该桶类型任务数是奇数,10,12排,但是对应库位不为空----"); |
| | | throw new CoolException("与前面桶类型一样,前面该桶类型任务数是奇数,是10,12排,但是对应库位不为空"); |
| | | } |
| | | } else { |
| | | log.error("-----与前面桶类型一样,前面该桶类型任务数是奇数,但是不是9,11排----"); |
| | | throw new CoolException("与前面桶类型一样,前面该桶类型任务数是奇数,但是不是9,11排"); |
| | | log.error("-----与前面桶类型一样,前面该桶类型任务数是奇数,但是不是10,12排----"); |
| | | throw new CoolException("与前面桶类型一样,前面该桶类型任务数是奇数,但是不是10,12排"); |
| | | } |
| | | } |
| | | } else { // 当前桶与前桶不是一种类型 |
| | | if(oldCtnType == 1) { // 前面是尾桶 |
| | | // 取新库位组的第一个库位 |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_sts", 'O').in("row1", 9, 11).orderBy("lev1").orderBy("bay1").orderBy("row1")); |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("crn_no", 4).eq("loc_sts", "O")); |
| | | List<LocMast> collect = locMasts.stream().filter(locMast1 -> locMast1.getRow1() == 9 || locMast1.getRow1() == 11).collect(Collectors.toList()); |
| | | List<LocMast> collect1 = locMasts.stream().filter(locMast1 -> locMast1.getRow1() == 10 || locMast1.getRow1() == 12).collect(Collectors.toList()); // 第一个先放这两排 |
| | | if (collect.size() == 0 || collect1.size() == 0) { |
| | | log.error("-----空桶库无空库位----"); |
| | | throw new CoolException("空桶库无空库位"); |
| | | } |
| | | // 可用库位组 |
| | | List<LocMast> locMastList = new ArrayList<>(); |
| | | for(LocMast locMast1:collect) { |
| | | Optional<LocMast> first = collect1.stream().filter(locMast2 -> locMast1.getRow1() + 1 == locMast2.getRow1() && Objects.equals(locMast1.getLev1(), locMast2.getLev1()) |
| | | && Objects.equals(locMast1.getBay1(), locMast2.getBay1())).findFirst(); |
| | | first.ifPresent(locMastList::add); |
| | | } |
| | | |
| | | if (locMastList.size() == 0) { |
| | | log.error("-----空桶库无对应空空桶组----"); |
| | | throw new CoolException("空桶库无对应空空桶组"); |
| | | } |
| | | String model = findLocNoAttributeVo.getModel(); // 当前桶类型 |
| | | if (model.equals("208L") && locMastList.size() <= 40 * 2 * 2) { // 最上面一层只能放208L,库位剩余量不多时,如果是208L桶入库,则先从最顶层放 |
| | | locMastList = locMastList.stream().sorted(Comparator.comparing(LocMast::getLev1).reversed().thenComparing(LocMast::getBay1).thenComparing(LocMast::getRow1)).collect(Collectors.toList()); |
| | | } else { |
| | | locMastList = locMastList.stream().sorted(Comparator.comparing(LocMast::getLev1).thenComparing(LocMast::getBay1).thenComparing(LocMast::getRow1)).collect(Collectors.toList()); |
| | | } |
| | | locMast = locMastList.get(0); |
| | | } else { // 前面不是尾桶 |
| | | // 判断前面入空桶库任务数量(未执行堆垛机入库) |
| | | long count = wrkMastList.stream().filter(wrkMast1 -> wrkMast1.getPdcType().equals(oldModel)).count(); |
| | | if (count % 2 == 0) { // 偶数,可以入库 |
| | | // 取新库位组的第一个库位 |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_sts", 'O').in("row1", 9, 11).orderBy("lev1").orderBy("bay1").orderBy("row1")); |
| | | List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("crn_no", 4).eq("loc_sts", "O")); |
| | | List<LocMast> collect = locMasts.stream().filter(locMast1 -> locMast1.getRow1() == 9 || locMast1.getRow1() == 11).collect(Collectors.toList()); |
| | | List<LocMast> collect1 = locMasts.stream().filter(locMast1 -> locMast1.getRow1() == 10 || locMast1.getRow1() == 12).collect(Collectors.toList()); // 第一个先放这两排 |
| | | if (collect.size() == 0 || collect1.size() == 0) { |
| | | log.error("-----空桶库无空库位----"); |
| | | throw new CoolException("空桶库无空库位"); |
| | | } |
| | | // 可用库位组 |
| | | List<LocMast> locMastList = new ArrayList<>(); |
| | | for(LocMast locMast1:collect) { |
| | | Optional<LocMast> first = collect1.stream().filter(locMast2 -> locMast1.getRow1() + 1 == locMast2.getRow1() && Objects.equals(locMast1.getLev1(), locMast2.getLev1()) |
| | | && Objects.equals(locMast1.getBay1(), locMast2.getBay1())).findFirst(); |
| | | first.ifPresent(locMastList::add); |
| | | } |
| | | |
| | | if (locMastList.size() == 0) { |
| | | log.error("-----空桶库无对应空空桶组----"); |
| | | throw new CoolException("空桶库无对应空空桶组"); |
| | | } |
| | | String model = findLocNoAttributeVo.getModel(); // 当前桶类型 |
| | | if (model.equals("208L") && locMastList.size() <= 40 * 2 * 2) { // 最上面一层只能放208L,库位剩余量不多时,如果是208L桶入库,则先从最顶层放 |
| | | locMastList = locMastList.stream().sorted(Comparator.comparing(LocMast::getLev1).reversed().thenComparing(LocMast::getBay1).thenComparing(LocMast::getRow1)).collect(Collectors.toList()); |
| | | } else { |
| | | locMastList = locMastList.stream().sorted(Comparator.comparing(LocMast::getLev1).thenComparing(LocMast::getBay1).thenComparing(LocMast::getRow1)).collect(Collectors.toList()); |
| | | } |
| | | locMast = locMastList.get(0); |
| | | } else { // 奇数,不可以入库 |
| | | log.error("-----与前面桶类型不一样,前面桶不是尾桶,前面该桶类型任务数不是偶数,不能入库----"); |
| | | throw new CoolException("与前面桶类型不一样,前面桶不是尾桶,前面该桶类型任务数不是偶数,不能入库"); |
| | |
| | | } |
| | | |
| | | } else if ((staDescId == 1 && locArea == 1) || staDescId == 10) { // 满板入成品库或者空板入成品库 |
| | | // 按层列排顺序获取一个CanningLineInLocParam param库位 |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_sts", 'O').in("row1", 1, 4, 5, 6, 7, 8).orderBy("lev1").orderBy("bay1").orderBy("row1")); |
| | | |
| | | // 浅库位没有了则获取一个浅库位 |
| | | // 入成品库摆放规则 判断可用堆垛机自动-无报警 按层列排顺序从下往上,从前往后排 先深库位在浅库位 最上面一层只能放208L桶(剩余库位达到一个阈值208L就先从最上面开始放,下面留给其他货物-后续优化) |
| | | |
| | | List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<BasCrnp>().eq("crn_sts", 3).eq("crn_err", 0).in("crn_no",1,2,3)); |
| | | if (basCrnps.size() == 0) { |
| | | log.error("入库请求库位失败,没有联机堆垛机或堆垛机异常"); |
| | | throw new CoolException("入库请求库位失败,没有联机堆垛机或堆垛机异常"); |
| | | } |
| | | |
| | | List<Integer> crnList = basCrnps.stream().map(BasCrnp::getCrnNo).collect(Collectors.toList()); |
| | | |
| | | // 入库桶型 |
| | | String model = findLocNoAttributeVo.getModel(); |
| | | Wrapper<LocMast> wrapper = new EntityWrapper<LocMast>().eq("loc_sts", 'O') |
| | | .in("crn_no", crnList).orderBy("lev1").orderBy("bay1").orderBy("row1"); |
| | | // 入库桶型是不是208L |
| | | if (model == null || !model.equals("208L")) { |
| | | wrapper.ne("lev1", 11); |
| | | } |
| | | locMast = locMastService.selectOne(wrapper.in("row1", 1, 4, 5, 6, 7, 8)); |
| | | // 深库位没有了则获取一个浅库位 |
| | | if (locMast == null) { |
| | | locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_sts", 'O').in("row1", 2, 3).orderBy("lev1").orderBy("bay1").orderBy("row1")); |
| | | locMast = locMastService.selectOne(wrapper.in("row1", 2, 3)); |
| | | if (locMast == null) { |
| | | log.error("-----库位不足----"); |
| | | throw new CoolException("库位不足"); |
| | | } else { |
| | | int count = locMastService.selectCount(new EntityWrapper<LocMast>().eq("loc_sts", 'O')); |
| | | int count = locMastService.selectCount(wrapper.in("row1", 2, 3)); |
| | | if (count <= 10) { |
| | | log.error("-----库位不足,预留10个库位用来库位转移----"); |
| | | throw new CoolException("库位不足,预留10个库位用来库位转移"); |
| | |
| | | } |
| | | |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public StartupDto getLocNo(SearchLocParam param, Integer wantBucketFlag) { |
| | | public StartupDto getLocNo(SearchLocParam param, Integer staNo) { |
| | | |
| | | // 返回dto |
| | | StartupDto startupDto = new StartupDto(); |
| | | |
| | | startupDto.setWorkNo(getWorkNo(0)); // 工作号 |
| | | startupDto.setSourceStaNo(param.getSourceStaNo()); // 源站点 |
| | | startupDto.setStaNo(fillingLineMappingSite[wantBucketFlag]); // 目标站点 |
| | | startupDto.setCrnNo(wantBucketFlag); // 记录罐装线号,wcs清除要桶信号 |
| | | startupDto.setStaNo(staNo); // 目标站点 |
| | | return startupDto; |
| | | } |
| | | |