package com.wms.utils.storage; import com.wms.constants.enums.LocationStatus; import com.wms.entity.table.Location; import com.wms.entity.table.Stock; import com.wms.entity.table.Task; import com.wms.mapper.LocationMapper; import com.wms.mapper.StockMapper; import com.wms.mapper.TaskMapper; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; /** * 库位工具类 */ @Component @RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class LocationUtils { /** * 库存 Mapper */ private final StockMapper stockMapper; /** * 库位 Mapper */ private final LocationMapper locationMapper; /** * 任务mapper */ private final TaskMapper taskMapper; /** * 获取一个区域的可用的库位 * @param areaId 区域ID * @return 可用的库位排序 */ public List getNewLocation(Integer areaId) { Location query = new Location(); query.setAreaId(areaId); query.setLocationStatus(LocationStatus.EMPTY.getCode()); return locationMapper.selNextLocation(query); } /** * 在一堆空闲的库位中寻找一个可用的入库库位 * @param canUseLocations 可用的库位 * @return 可用的库位,若没有可用的库位则返回 null */ public Location checkCanUse(List canUseLocations) { if(canUseLocations == null || canUseLocations.isEmpty()) { return null; } for (Location location : canUseLocations) { if(location.getDepth() == 1) { return location; // 1 深度的不需要检验 } /* 校验此位置是否有遮挡 */ /* 如果这位置有库存(可能出现记错导致有库存),或者这位置其他深度(不论深度大小)有任务则不采用此位置 */ /* 1 判断库存 */ Stock checkStock = new Stock(); checkStock.setLocationId(location.getLocationId()); List checkResult = stockMapper.selStocks(checkStock); if(!checkResult.isEmpty()) { continue; // 库存不为空,跳过 } /* 2 判断同位置不同深度是否有任务 */ // 找出此位置不同深度的库位 Location queryDifferentDepthLocation = new Location(); queryDifferentDepthLocation.setAreaId(location.getAreaId()); queryDifferentDepthLocation.setEquipmentId(location.getEquipmentId()); queryDifferentDepthLocation.setQueue(location.getQueue()); queryDifferentDepthLocation.setLine(location.getLine()); queryDifferentDepthLocation.setLayer(location.getLayer()); List differentDepthLocations = locationMapper.selLocations(queryDifferentDepthLocation); if(differentDepthLocations == null) { continue; // 数据库查询失败 } boolean canUse = false; // 指示当前库位是否可用,若可用会置成 true if(!differentDepthLocations.isEmpty()) { // 存在干涉库位,检验其是否有未完成的任务 for (Location differentDepthLocation : differentDepthLocations) { // 找出此位置不同深度的库位 Location queryLocationTask = new Location(); queryLocationTask.setLocationId(differentDepthLocation.getLocationId()); List locationTasks = taskMapper.haveNotCompleteTask(differentDepthLocation.getLocationId()); if(locationTasks == null) { continue; // 数据库查询失败 } if(!locationTasks.isEmpty()) { break; // 有任务这个库位不行 } } canUse = true; } if(canUse) { return location; } } return null; } }