| | |
| | | |
| | | /// <summary> |
| | | /// 根据巷道获取空闲货位信息 |
| | | /// 排序策略:深度优先(二深位优先),其次按层、列、行升序 |
| | | /// </summary> |
| | | /// <param name="roadwayNo">巷道编号</param> |
| | | /// <returns>空闲货位信息,如果未找到则返回null</returns> |
| | | /// <returns>空闲货位信息,如果空闲货位不足则返回null</returns> |
| | | public async Task<Dt_LocationInfo?> GetLocationInfo(string roadwayNo) |
| | | { |
| | | var locations = await BaseDal.QueryDataAsync(x => |
| | | x.EnableStatus == EnableStatusEnum.Normal.GetHashCode() && |
| | | x.RoadwayNo == roadwayNo && |
| | | x.LocationStatus == LocationStatusEnum.Free.GetHashCode() && |
| | | (roadwayNo.Contains("HC") |
| | | ? x.LocationType == (int)LocationTypeEnum.Capacity |
| | | : x.LocationType == (int)LocationTypeEnum.ShelfCapacity)); |
| | | // HC 巷道使用 Capacity 类型,其他巷道使用 ShelfCapacity 类型 |
| | | var locationType = roadwayNo.Contains("HC") |
| | | ? (int)LocationTypeEnum.Capacity |
| | | : (int)LocationTypeEnum.ShelfCapacity; |
| | | |
| | | return locations? |
| | | .OrderByDescending(x => x.Depth) // 1. 深度优先(从大到小) |
| | | .ThenBy(x => x.Layer) // 2. 层数 |
| | | .ThenBy(x => x.Column) // 3. 列 |
| | | .ThenBy(x => x.Row) // 4. 行 |
| | | .FirstOrDefault(); |
| | | var enableStatus = EnableStatusEnum.Normal.GetHashCode(); |
| | | var freeStatus = LocationStatusEnum.Free.GetHashCode(); |
| | | |
| | | // 数据库端 COUNT 检查空闲货位数量(仅返回一个数字,无数据传输开销) |
| | | var freeCount = await BaseDal.Db.Queryable<Dt_LocationInfo>() |
| | | .Where(x => x.EnableStatus == enableStatus |
| | | && x.RoadwayNo == roadwayNo |
| | | && x.LocationStatus == freeStatus |
| | | && x.LocationType == locationType) |
| | | .CountAsync(); |
| | | |
| | | // 空闲货位不足最低保留数量时返回null,避免将巷道分配耗尽 |
| | | const int minFreeLocationThreshold = 5; |
| | | if (freeCount < minFreeLocationThreshold) return null; |
| | | |
| | | // 数据库端排序取第一条(只传输单行数据) |
| | | return await BaseDal.Db.Queryable<Dt_LocationInfo>() |
| | | .Where(x => x.EnableStatus == enableStatus |
| | | && x.RoadwayNo == roadwayNo |
| | | && x.LocationStatus == freeStatus |
| | | && x.LocationType == locationType) |
| | | .OrderByDescending(x => x.Depth) |
| | | .OrderBy(x => x.Layer) |
| | | .OrderBy(x => x.Column) |
| | | .OrderBy(x => x.Row) |
| | | .FirstAsync(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | // 判断该位置是否有库存 |
| | | var stockInfo = await _stockInfoRepository.QueryDataNavFirstAsync(x => |
| | | x.LocationCode == newLocationID && |
| | | x.StockStatus == StockStatusEmun.入库完成.GetHashCode() && |
| | | (x.StockStatus == StockStatusEmun.入库完成.GetHashCode() || x.StockStatus == StockStatusEmun.空托盘库存.GetHashCode()) && |
| | | x.LocationDetails.LocationStatus == LocationStatusEnum.InStock.GetHashCode()); |
| | | if (stockInfo == null) |
| | | { |