| | |
| | | using WIDESEA_Core.Core; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.GradingMachine; |
| | | using WIDESEA_DTO.MES; |
| | | using WIDESEA_DTO.Stock; |
| | | using WIDESEA_DTO.Task; |
| | | using WIDESEA_IBasicService; |
| | |
| | | private readonly HttpClientHelper _httpClientHelper; |
| | | private readonly IConfiguration _configuration; |
| | | private readonly RoundRobinService _roundRobinService; |
| | | private readonly IMesService _mesService; |
| | | private readonly ITask_HtyService _task_HtyService; |
| | | private readonly IStockInfo_HtyService _stockInfo_HtyService; |
| | | |
| | | public IRepository<Dt_Task> Repository => BaseDal; |
| | | |
| | |
| | | ILocationInfoService locationInfoService, |
| | | HttpClientHelper httpClientHelper, |
| | | IConfiguration configuration, |
| | | RoundRobinService roundRobinService) : base(BaseDal) |
| | | RoundRobinService roundRobinService, |
| | | IMesService mesService, |
| | | ITask_HtyService task_HtyService, |
| | | IStockInfo_HtyService stockInfo_HtyService) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _stockInfoService = stockInfoService; |
| | |
| | | _httpClientHelper = httpClientHelper; |
| | | _configuration = configuration; |
| | | _roundRobinService = roundRobinService; |
| | | _mesService = mesService; |
| | | _task_HtyService = task_HtyService; |
| | | _stockInfo_HtyService = stockInfo_HtyService; |
| | | } |
| | | |
| | | #region WCS逻辑处理 |
| | |
| | | |
| | | return await ExecuteWithinTransactionAsync(async () => |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | stockInfo.LocationCode = location.LocationCode; |
| | | stockInfo.LocationId = location.Id; |
| | | stockInfo.OutboundDate = task.Roadway switch |
| | |
| | | var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo); |
| | | if (!updateLocationResult || !updateStockResult) |
| | | return WebResponseContent.Instance.Error("任务完成失败"); |
| | | return await CompleteTaskAsync(task); |
| | | // 调用MES托盘进站 |
| | | var inboundRequest = new InboundInContainerRequest |
| | | { |
| | | EquipmentCode = "STK-GROUP-001", |
| | | ResourceCode = "STK-GROUP-001", |
| | | LocalTime = DateTime.Now, |
| | | ContainerCode = taskDto.PalletCode |
| | | }; |
| | | var inboundResult = _mesService.InboundInContainer(inboundRequest); |
| | | if (inboundResult == null || inboundResult.Data == null || !inboundResult.Data.IsSuccess) |
| | | { |
| | | return content.Error($"任务完成失败:MES进站失败: {inboundResult?.Data?.Msg ?? inboundResult?.ErrorMessage ?? "未知错误"}"); |
| | | } |
| | | return await CompleteTaskAsync(task, "Inbound"); |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode); |
| | | if (stockInfo == null) return WebResponseContent.Instance.Error("未找到对应库存信息"); |
| | | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | return await ExecuteWithinTransactionAsync(async () => |
| | | { |
| | | stockInfo.LocationId = 0; |
| | |
| | | var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo); |
| | | if (!updateLocationResult || !updateStockResult) |
| | | return WebResponseContent.Instance.Error("任务完成失败"); |
| | | return await CompleteTaskAsync(task); |
| | | |
| | | // 调用MES托盘出站 |
| | | var outboundRequest = new OutboundInContainerRequest |
| | | { |
| | | EquipmentCode = "STK-GROUP-001", |
| | | ResourceCode = "STK-GROUP-001", |
| | | LocalTime = DateTime.Now, |
| | | ContainerCode = taskDto.PalletCode, |
| | | ParamList = new List<ParamItem>() |
| | | }; |
| | | var outboundResult = _mesService.OutboundInContainer(outboundRequest); |
| | | if (outboundResult == null || outboundResult.Data == null || !outboundResult.Data.IsSuccess) |
| | | { |
| | | return content.Error($"任务完成失败:MES出站失败: {outboundResult?.Data?.Msg ?? outboundResult?.ErrorMessage ?? "未知错误"}"); |
| | | } |
| | | |
| | | return await CompleteTaskAsync(task, "Outbound"); |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | if (!updateSourceResult || !updateTargetResult || !updateStockResult) |
| | | return WebResponseContent.Instance.Error("移库任务完成失败"); |
| | | |
| | | return await CompleteTaskAsync(task); |
| | | return await CompleteTaskAsync(task, "Relocation"); |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error($"查询任务失败: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 空托盘入库完成 |
| | | /// </summary> |
| | | public async Task<WebResponseContent> InboundFinishTaskTrayAsync(CreateTaskDto taskDto) |
| | | { |
| | | try |
| | | { |
| | | var task = await BaseDal.QueryFirstAsync(s => s.PalletCode == taskDto.PalletCode); |
| | | if (task == null) return WebResponseContent.Instance.Error("未找到对应的任务"); |
| | | |
| | | var location = await _locationInfoService.GetLocationInfo(task.Roadway, task.TargetAddress); |
| | | if (location == null) return WebResponseContent.Instance.Error("未找到对应的货位"); |
| | | |
| | | var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode); |
| | | if (stockInfo == null) return WebResponseContent.Instance.Error("未找到对应库存信息"); |
| | | |
| | | return await ExecuteWithinTransactionAsync(async () => |
| | | { |
| | | stockInfo.LocationCode = location.LocationCode; |
| | | stockInfo.LocationId = location.Id; |
| | | stockInfo.StockStatus = StockStatusEmun.空托盘库存.GetHashCode(); |
| | | |
| | | location.LocationStatus = LocationStatusEnum.InStock.GetHashCode(); |
| | | |
| | | var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location); |
| | | var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo); |
| | | if (!updateLocationResult || !updateStockResult) |
| | | return WebResponseContent.Instance.Error("任务完成失败"); |
| | | |
| | | var deleteResult = await BaseDal.DeleteDataAsync(task); |
| | | if (!deleteResult) return WebResponseContent.Instance.Error("任务完成失败"); |
| | | |
| | | return WebResponseContent.Instance.OK("任务完成"); |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error($"完成任务失败: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error($"查询任务失败: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 空托盘出库完成 |
| | | /// </summary> |
| | | public async Task<WebResponseContent> OutboundFinishTaskTrayAsync(CreateTaskDto taskDto) |
| | | { |
| | | try |
| | | { |
| | | var task = await BaseDal.QueryFirstAsync(s => s.PalletCode == taskDto.PalletCode); |
| | | if (task == null) return WebResponseContent.Instance.Error("未找到对应的任务"); |
| | | |
| | | var location = await _locationInfoService.GetLocationInfo(task.Roadway, task.SourceAddress); |
| | | if (location == null) return WebResponseContent.Instance.Error("未找到对应的货位"); |
| | | |
| | | var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode); |
| | | if (stockInfo == null) return WebResponseContent.Instance.Error("未找到对应库存信息"); |
| | | |
| | | return await ExecuteWithinTransactionAsync(async () => |
| | | { |
| | | stockInfo.LocationId = 0; |
| | | stockInfo.LocationCode = null; |
| | | stockInfo.StockStatus = StockStatusEmun.出库完成.GetHashCode(); |
| | | |
| | | location.LocationStatus = LocationStatusEnum.Free.GetHashCode(); |
| | | |
| | | var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location); |
| | | var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo); |
| | | if (!updateLocationResult || !updateStockResult) |
| | | return WebResponseContent.Instance.Error("任务完成失败"); |
| | | |
| | | var deleteResult = await BaseDal.DeleteDataAsync(task); |
| | | if (!deleteResult) return WebResponseContent.Instance.Error("任务完成失败"); |
| | | |
| | | return WebResponseContent.Instance.OK("任务完成"); |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error($"完成任务失败: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | |
| | | /// <summary> |
| | | /// 完成任务后统一处理(删除任务数据) |
| | | /// </summary> |
| | | private async Task<WebResponseContent> CompleteTaskAsync(Dt_Task task) |
| | | private async Task<WebResponseContent> CompleteTaskAsync(Dt_Task task, string operateType) |
| | | { |
| | | var deleteTaskResult = await BaseDal.DeleteDataAsync(task); |
| | | if (!deleteTaskResult) return WebResponseContent.Instance.Error("任务完成失败"); |
| | | |
| | | // 保留历史对象构建逻辑,后续可接入历史表落库 |
| | | var historyTask = _mapper.Map<Dt_Task_Hty>(task); |
| | | historyTask.InsertTime = DateTime.Now; |
| | | historyTask.OperateType = operateType; |
| | | var saveResult = _task_HtyService.AddData(historyTask); |
| | | if (!saveResult.Status) return WebResponseContent.Instance.Error("任务历史保存失败"); |
| | | |
| | | return WebResponseContent.Instance.OK("任务完成"); |
| | | } |