change - 包材出库逻辑实现

master
WenJY 2 months ago
parent 660ca866ab
commit 5bef324e36

@ -23,9 +23,181 @@
#endregion << 版 本 注 释 >>
using System.Linq.Expressions;
using Sln.Wcs.Business.Domain.Dto.CreateTask;
using Sln.Wcs.Business.Domain.Dto.FilterLocation;
using Sln.Wcs.Business.Domain.Dto.SaveTask;
using Sln.Wcs.Business.Domain.Dto.ValidateMaterial;
using Sln.Wcs.Business.Domain.Enum;
using Sln.Wcs.Business.Domain.Model.CreateTask;
using Sln.Wcs.Business.Domain.Model.FilterLocation;
using Sln.Wcs.Business.Domain.Model.SaveTask;
using Sln.Wcs.Model.Domain;
using Sln.Wcs.Repository.service;
namespace Sln.Wcs.Business.OutStore;
public class MaterialOutStore
/// <summary>
/// 包材出库
/// </summary>
public class MaterialOutStore:BaseBusiness
{
private readonly IBasePathInfoService _basePathInfoService;
private readonly ILiveTaskQueueService _liveTaskQueueService;
private readonly IBaseStoreInfoService _baseStoreInfoService;
public MaterialOutStore(IBasePathInfoService basePathInfoService, ILiveTaskQueueService liveTaskQueueService, IBaseStoreInfoService baseStoreInfoService)
{
_basePathInfoService = basePathInfoService;
_liveTaskQueueService = liveTaskQueueService;
_baseStoreInfoService = baseStoreInfoService;
}
public override ValidateMaterialResultDto ValidateMaterial(ValidateMaterialDto validateMaterialDto)
{
throw new NotImplementedException();
}
/// <summary>
/// 创建任务
/// </summary>
/// <param name="createTaskDto"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override CreateTaskResultDto CreateTask(CreateTaskDto createTaskDto)
{
CreateTaskResultDto resultDto = new CreateTaskResultDto();
try
{
#region CreateTaskDto 参数校验
if (string.IsNullOrEmpty(createTaskDto.materialCode))
{
throw new InvalidOperationException($"物料编号不允许为 NULL");
}
if (string.IsNullOrEmpty(createTaskDto.palletBarcode))
{
throw new InvalidOperationException($"托盘条码不允许为 NULL");
}
if (string.IsNullOrEmpty(createTaskDto.startPoint) || string.IsNullOrEmpty(createTaskDto.endPoint))
{
throw new InvalidOperationException($"起始位置、终点位置不允许为 NULL");
}
#endregion
createTaskDto.taskType = TaskTypeEnum.OutStore;
createTaskDto.taskCategory = TaskCategoryEnum.Material;
//获取包材出库路径
Expression<Func<BasePathInfo, bool>> exp = x=>x.startPoint == createTaskDto.startPoint && x.endPoint == createTaskDto.endPoint && x.pathType == (int)createTaskDto.taskType && x.pathCategory == (int)createTaskDto.taskCategory;
BasePathInfo pathInfo = _basePathInfoService.GetBasePathInfo(exp).FirstOrDefault() ?? throw new InvalidOperationException($"包材出库输送路径为 NULL");
#region 路径转为任务
string taskCode = "2026050700001"; //需根据现场实际定义生成规则
List<LiveTaskDetail> taskDetails = pathInfo.pathDetails.Select( item => base.LiveTaskDetailWrapper(taskCode,createTaskDto,item)).ToList();
var taskQueue = base.LiveTaskQueueWrapper(taskCode, createTaskDto, pathInfo);
taskQueue.taskSteps = taskDetails.Count;
taskQueue.taskDetails = taskDetails;
#endregion
resultDto.code = BusinessStatusEnum.;
resultDto.msg = $"包材出库任务创建成功:{taskCode};关联路径:{pathInfo.pathName}";
resultDto.data = new CreateTaskResultModel()
{
taskCode = taskCode,
taskQueue = taskQueue,
taskDetails = taskDetails,
};
}
catch (Exception e)
{
resultDto.code = BusinessStatusEnum.;
resultDto.msg = e.Message;
}
return resultDto;
}
/// <summary>
/// 筛选库位
/// </summary>
/// <param name="filterLocationDto"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override FilterLocationResultDto FilterLocation(FilterLocationDto filterLocationDto)
{
FilterLocationResultDto resultDto = new FilterLocationResultDto();
try
{
#region 参数校验
if (string.IsNullOrEmpty(filterLocationDto.materialCode))
{
throw new InvalidOperationException($"物料编号不允许为 NULL");
}
#endregion
Expression<Func<BaseStoreInfo,bool>> storeWhere = x => x.storeType == (int)StoreTypeEnum.Material;
Expression<Func<BaseLocationInfo,bool>> locationWhere = x=>x.materialCode==filterLocationDto.materialCode && x.locationStatus == 1 && x.isFlag == 1;
List<BaseStoreInfo> storeInfos = _baseStoreInfoService.GetBasePathInfo(storeWhere,locationWhere);
//先对仓库进行排序
BaseStoreInfo? storeInfo = storeInfos.Where(s => s.locationInfos.Count > 0).OrderBy(x=>x.storeCode).FirstOrDefault() ?? throw new ArgumentNullException($"未获取到可用仓库");
BaseLocationInfo? locationInfo = storeInfo.locationInfos.OrderBy(x => x.locationRows).ThenBy(x=>x.locationColumns).ThenBy(x=>x.locationLayers).FirstOrDefault() ?? throw new ArgumentNullException($"目标仓库:{storeInfo.storeName}中未获取到可用库位");
resultDto.code = BusinessStatusEnum.;
resultDto.msg = "执行完成";
resultDto.data = new FilterLocationResultModel()
{
storeInfo = storeInfo,
locationInfos = storeInfo.locationInfos,
locationInfo = locationInfo,
};
}
catch (Exception e)
{
resultDto.code = BusinessStatusEnum.;
resultDto.msg = e.Message;
}
return resultDto;
}
/// <summary>
/// 保存任务
/// </summary>
/// <param name="saveTaskDto"></param>
/// <returns></returns>
public override SaveTaskResultDto SaveTask(SaveTaskDto saveTaskDto)
{
SaveTaskResultDto resultDto = new SaveTaskResultDto();
try
{
var inRes = _liveTaskQueueService.InsertTaskQueue(saveTaskDto.taskQueue);
resultDto.code = BusinessStatusEnum.;
resultDto.msg = "执行完成";
resultDto.data = new SaveTaskResultModel()
{
isRes = inRes
};
}
catch (Exception e)
{
resultDto.code = BusinessStatusEnum.;
resultDto.msg = e.Message;
}
return resultDto;
}
}

@ -43,11 +43,6 @@ namespace Sln.Wcs.Repository.service.Impl
{
try
{
// var result = _rep.Context.Queryable<BaseStoreInfo>()
// .Includes(x => x.locationInfos.Where(p => p.isFlag == 1).ToList())
// .Where(storeWhere)
// .ToList();
var res = _rep.Context.Queryable<BaseStoreInfo>()
.Includes(x => x.locationInfos) // 先加载所有
.Where(storeWhere)
@ -70,7 +65,7 @@ namespace Sln.Wcs.Repository.service.Impl
}
catch (Exception ex)
{
throw new InvalidOperationException($"通过导航查询方式获取设备信息及下属参数执行异常:{ex.Message}");
throw new InvalidOperationException($"通过导航查询方式获取仓库信息及下属参数执行异常:{ex.Message}");
}
}
}

Loading…
Cancel
Save