package com.zy.asrs.wms.utils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.asrs.framework.common.Cools; import com.zy.asrs.framework.exception.CoolException; import com.zy.asrs.wms.asrs.entity.*; import com.zy.asrs.wms.asrs.entity.enums.LocStsType; import com.zy.asrs.wms.asrs.entity.enums.LocTypeHeightType; import com.zy.asrs.wms.asrs.entity.param.FieldParam; import com.zy.asrs.wms.asrs.mapper.ViewLocDetlMapper; import com.zy.asrs.wms.asrs.mapper.ViewTaskDetlMapper; import com.zy.asrs.wms.asrs.service.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; import java.util.Map; @Component public class LocUtils { @Autowired private TaskService taskService; @Autowired private LocService locService; @Autowired private SuggestLocRuleService suggestLocRuleService; @Autowired private LanewayRuleService lanewayRuleService; @Autowired private LocTypeService locTypeService; @Autowired private LocTypeBindService locTypeBindService; @Autowired private ViewLocDetlMapper viewLocDetlMapper; @Autowired private ViewTaskDetlMapper viewTaskDetlMapper; @Autowired private MatService matService; //从库存或任务中匹配相邻库位(满托盘) public Loc getNeighborLoc(Long taskType, Long matId, String batch, List uniqueFields, Integer locTypeHeight) { //满托盘 Mat mat = matService.getById(matId); if (mat == null) { return null; } //从任务中进行匹配 List locs = new ArrayList<>(); List> list = viewTaskDetlMapper.getList(mat.getMatnr(), batch, uniqueFields); for (Map map : list) { Task task = taskService.getById(map.get("taskId").toString()); if (task == null) { continue; } String targetLoc = task.getTargetLoc(); Loc one = locService.getOne(new LambdaQueryWrapper().eq(Loc::getLocNo, targetLoc)); if (one == null) { continue; } locs.add(one); } Loc loc = filterLoc(taskType, locs); if (loc != null) { return loc; } //从库存中进行匹配 List locs2 = new ArrayList<>(); List> list2 = viewLocDetlMapper.getList(mat.getMatnr(), batch, uniqueFields, null); for (Map map : list2) { Loc one = locService.getById(map.get("locId").toString()); if (one == null) { continue; } locs2.add(one); } Loc loc2 = filterLoc(taskType, locs2); if (loc2 != null) { return loc2; } return null; } //获取推荐库位(满托盘) public List getSuggestLoc(Long taskType, Long matId, String batch, Integer locTypeHeight, List laneRowList, Integer currentLev) { //满托盘 List locs = new ArrayList<>(); LocTypeHeightType locTypeHeightType = LocTypeHeightType.get(locTypeHeight); if (locTypeHeightType == null) { throw new CoolException("库位高度类型异常"); } //获取库位高度 LocType locType = locTypeService.getOne(new LambdaQueryWrapper().eq(LocType::getFlag, locTypeHeightType.flag)); //符合库位高度的库位集合 List locIdList = locTypeBindService.getLocIdListByType(locType); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(SuggestLocRule::getLocType, 1); wrapper.eq(SuggestLocRule::getMatId, matId); if (!Cools.isEmpty(batch)) { wrapper.eq(SuggestLocRule::getBatch, batch); } List suggestLocRules = suggestLocRuleService.list(wrapper); for (SuggestLocRule suggestLocRule : suggestLocRules) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.ge(Loc::getRow1, suggestLocRule.getStartRow()); queryWrapper.le(Loc::getRow1, suggestLocRule.getTargetRow()); queryWrapper.ge(Loc::getBay1, suggestLocRule.getStartBay()); queryWrapper.le(Loc::getBay1, suggestLocRule.getTargetBay()); queryWrapper.ge(Loc::getLev1, suggestLocRule.getStartLev()); queryWrapper.le(Loc::getLev1, suggestLocRule.getTargetLev()); queryWrapper.eq(Loc::getLocStsId, LocStsType.O.val()); queryWrapper.in(Loc::getId, locIdList); if (laneRowList != null && !laneRowList.isEmpty()) { queryWrapper.in(Loc::getRow1, laneRowList); } if (currentLev != null) { queryWrapper.eq(Loc::getLev1, currentLev); } List list = locService.list(queryWrapper); if (!list.isEmpty()) { locs.addAll(list); } } return locs; } //获取全局库位(完整巷道) public List getGlobalLoc(Long taskType, Integer locTypeHeight, List laneRowList, Integer currentLev) { List locs = new ArrayList<>(); LocTypeHeightType locTypeHeightType = LocTypeHeightType.get(locTypeHeight); if (locTypeHeightType == null) { throw new CoolException("库位高度类型异常"); } //获取库位高度 LocType locType = locTypeService.getOne(new LambdaQueryWrapper().eq(LocType::getFlag, locTypeHeightType.flag)); //符合库位高度的库位集合 List locIdList = locTypeBindService.getLocIdListByType(locType); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Loc::getLocStsId, LocStsType.O.val()); queryWrapper.in(Loc::getId, locIdList); if (laneRowList != null && !laneRowList.isEmpty()) { queryWrapper.in(Loc::getRow1, laneRowList); } if (currentLev != null) { queryWrapper.eq(Loc::getLev1, currentLev); } List list = locService.list(queryWrapper); if (!list.isEmpty()) { locs.addAll(list); } return locs; } //从库位集合中获取符合深浅的库位 public Loc filterLoc(Long taskType, List locs) { if (locs == null || locs.isEmpty()) { return null; } Loc defaultLoc = null; for (Loc loc : locs) { //获取库位所在巷道 LanewayRule lanewayRule = lanewayRuleService.getLaneByLoc(loc); if(lanewayRule == null) { throw new CoolException("库位未配置巷道"); } //获取库位方向 List direction = null; if (lanewayRule.getLaneX$().contains(loc.getRow1())) { direction = lanewayRule.getLaneX$(); }else { direction = lanewayRule.getLaneY$(); } for (Integer row : direction) { Loc one = locService.getOne(new LambdaQueryWrapper() .eq(Loc::getRow1, row) .eq(Loc::getBay1, loc.getBay1()) .eq(Loc::getLev1, loc.getLev1())); if (one == null) { continue; } if(one.getLocStsId() != LocStsType.O.val()) { continue; } //当前库位是空库位 defaultLoc = one; break; } if (defaultLoc != null) { break; } } return defaultLoc; } //从库位集合中获取完整空巷道 public Loc filterAllLoc(List locs) { if (locs == null || locs.isEmpty()) { return null; } Loc defaultLoc = null; for (Loc loc : locs) { //获取库位所在巷道 LanewayRule lanewayRule = lanewayRuleService.getLaneByLoc(loc); if(lanewayRule == null) { throw new CoolException("库位未配置巷道"); } //获取库位方向 List direction = null; if (lanewayRule.getLaneX$().contains(loc.getRow1())) { direction = lanewayRule.getLaneX$(); }else { direction = lanewayRule.getLaneY$(); } boolean flag = false; List allLocs = new ArrayList<>(); for (Integer row : direction) { Loc one = locService.getOne(new LambdaQueryWrapper() .eq(Loc::getRow1, row) .eq(Loc::getBay1, loc.getBay1()) .eq(Loc::getLev1, loc.getLev1())); if (one == null) { continue; } if(one.getLocStsId() != LocStsType.O.val()) { flag = true; break; } allLocs.add(one); } if (flag) { continue; } if (!allLocs.isEmpty()) { defaultLoc = allLocs.get(0); break;//找到一个完整空巷道 } } return defaultLoc; } //从库存或任务中匹配相邻库位(空托盘) public Loc getNeighborEmptyLoc(Long taskType, Integer locTypeHeight) { //从任务中进行匹配 List locs = new ArrayList<>(); List list = taskService.list(new LambdaQueryWrapper().eq(Task::getTaskType, 10)); for (Task task : list) { String targetLoc = task.getTargetLoc(); Loc one = locService.getOne(new LambdaQueryWrapper().eq(Loc::getLocNo, targetLoc)); if(one == null) { continue; } locs.add(one); } Loc loc = filterLoc(taskType, locs); if (loc != null) { return loc; } //从库存中进行匹配 List locs2 = locService.list(new LambdaQueryWrapper().eq(Loc::getLocStsId, LocStsType.D.val())); Loc loc2 = filterLoc(taskType, locs2); if (loc2 != null) { return loc2; } return null; } //获取推荐库位(空托盘) public List getSuggestEmptyLoc(Long taskType, Integer locTypeHeight, List laneRowList, Integer currentLev) { List locs = new ArrayList<>(); //空托盘 List suggestLocRules = suggestLocRuleService.list(new LambdaQueryWrapper().eq(SuggestLocRule::getLocType, 0)); for (SuggestLocRule suggestLocRule : suggestLocRules) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.ge(Loc::getRow1, suggestLocRule.getStartRow()); queryWrapper.le(Loc::getRow1, suggestLocRule.getTargetRow()); queryWrapper.ge(Loc::getBay1, suggestLocRule.getStartBay()); queryWrapper.le(Loc::getBay1, suggestLocRule.getTargetBay()); queryWrapper.ge(Loc::getLev1, suggestLocRule.getStartLev()); queryWrapper.le(Loc::getLev1, suggestLocRule.getTargetLev()); queryWrapper.eq(Loc::getLocStsId, LocStsType.O.val()); if (laneRowList != null && !laneRowList.isEmpty()) { queryWrapper.in(Loc::getRow1, laneRowList); } if (currentLev != null) { queryWrapper.eq(Loc::getLev1, currentLev); } List list = locService.list(queryWrapper); if (!list.isEmpty()) { locs.addAll(list); } } return locs; } //获取全局库位(完整巷道) public List getGlobalEmptyLoc(Long taskType, Integer locTypeHeight, List laneRowList, Integer currentLev) { List locs = new ArrayList<>(); LocTypeHeightType locTypeHeightType = LocTypeHeightType.get(locTypeHeight); if (locTypeHeightType == null) { throw new CoolException("库位高度类型异常"); } //获取库位高度 LocType locType = locTypeService.getOne(new LambdaQueryWrapper().eq(LocType::getFlag, locTypeHeightType.flag)); //符合库位高度的库位集合 List locIdList = locTypeBindService.getLocIdListByType(locType); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Loc::getLocStsId, LocStsType.O.val()); queryWrapper.in(Loc::getId, locIdList); if (laneRowList != null && !laneRowList.isEmpty()) { queryWrapper.in(Loc::getRow1, laneRowList); } if (currentLev != null) { queryWrapper.eq(Loc::getLev1, currentLev); } List list = locService.list(queryWrapper); if (!list.isEmpty()) { locs.addAll(list); } return locs; } }