#region << 版 本 注 释 >> /*---------------------------------------------------------------- * 命名空间:WIDESEA_TaskInfoService * 创建者:胡童庆 * 创建时间:2024/8/2 16:13:36 * 版本:V1.0.0 * 描述: * * ---------------------------------------------------------------- * 修改人: * 修改时间: * 版本:V1.0.1 * 修改说明: * *----------------------------------------------------------------*/ #endregion << 版 本 注 释 >> using AutoMapper; using MailKit.Search; using Microsoft.AspNetCore.SignalR; using Newtonsoft.Json; using OfficeOpenXml.FormulaParsing.Excel.Functions.Database; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using Org.BouncyCastle.Asn1.Tsp; using Spire.Pdf; using SqlSugar; using System; using System; using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis; using System.Drawing.Printing; using System.IO; using System.Linq; using System.Net.Http; using System.Reflection; using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; using System.Threading.Tasks; using WIDESEA_BasicRepository; using WIDESEA_Common; using WIDESEA_Common.Log; using WIDESEA_Common.OrderEnum; using WIDESEA_Common.TaskEnum; using WIDESEA_Core; using WIDESEA_Core.BaseRepository; using WIDESEA_Core.BaseServices; using WIDESEA_Core.Enums; using WIDESEA_Core.Helper; using WIDESEA_Core.TaskEnum; using WIDESEA_DTO.Basic; using WIDESEA_DTO.ERP; using WIDESEA_DTO.Inbound; using WIDESEA_DTO.Stock; using WIDESEA_DTO.Task; using WIDESEA_IBasicRepository; using WIDESEA_IBasicService; using WIDESEA_IInboundRepository; using WIDESEA_IInboundService; using WIDESEA_InboundRepository; using WIDESEA_IOutboundRepository; using WIDESEA_IOutboundService; using WIDESEA_IRecordService; using WIDESEA_IStockRepository; using WIDESEA_IStockService; using WIDESEA_ITaskInfoRepository; using WIDESEA_ITaskInfoService; using WIDESEA_Model.Models; using WIDESEA_Model.Models.Inbound; using WIDESEA_OutboundRepository; using WIDESEA_StockRepository; using WIDESEA_TaskInfoRepository; using static WIDESEA_Common.Authentication; using static WIDESEA_Common.HouseBackboundPassBack; using static WIDESEA_Common.HouseInboundPassBack; using static WIDESEA_Common.HouseInboundPassBack.data.data1; using static WIDESEA_Common.HouseoutboundPassBack; using static WIDESEA_Common.InventoryAllocate; using static WIDESEA_Common.NewHouseInboundPassBack; using static WIDESEA_Common.NewHouseInboundPassBack.Parame.Syncretism; using static WIDESEA_ITaskInfoService.ITaskService; using Parameter = WIDESEA_Common.Parameter; using WIDESEA_DTO.ERP; using WIDESEA_OutboundRepository; using System.ComponentModel.DataAnnotations; using System; using System.IO; using System.Net.Http; using System.Threading.Tasks; using Spire.Pdf; using WIDESEA_InboundRepository; using System.Drawing.Printing; using System; using WIDESEA_Common.Log; using static WIDESEA_Common.HouseInboundPassBack.data.data1; using System.Diagnostics; namespace WIDESEA_TaskInfoService { public partial class TaskService : ServiceBase, ITaskService { private readonly IMapper _mapper; private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly IStockRepository _stockRepository; private readonly IBasicService _basicService; private readonly IBasicRepository _basicRepository; private readonly IOutboundService _outboundService; private readonly IInboundService _inboundService; private readonly IInboundOrderDetailService _inboundOrderDetailService; private readonly IRecordService _recordService; private readonly IStockService _stockService; private readonly ITask_HtyService _taskHtyService; private readonly ILocationInfoService _locationInfoService; private readonly ITaskService _taskService; private readonly IMaterielInfoService _materielInfoService; private readonly IInboundOrder_HtyService _inboundOrder_HtyService; private readonly IInboundOrderDetail_HtyService _inboundOrderDetail_HtyService; private readonly IOutboundOrder_HtyService _outboundOrder_HtyService; private readonly IOutboundOrderDetail_HtyService _outboundOrderDetail_HtyService; private readonly IPalletTypeInfoRepository _palletTypeInfoRepository; private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository; private readonly IStockInfoDetailRepository _stockInfoDetailRepository; private readonly IStockInfoDetailCPRepository _stockInfoDetailCPRepository; private readonly IReturnOrderRepository _returnOrderRepository; private readonly IProductionRepository _productionRepository; private readonly IInboundRepository _inboundRepository; private readonly ITakeStockOrderCPRepository _takeStockOrderCPRepository; private readonly ITakeStockOrderDetailCPRepository _takeStockOrderDetailCPRepository; public ITaskRepository Repository => BaseDal; public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IMaterielInfoService materielInfoService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IOutboundOrder_HtyService outboundOrder_HtyService, IOutboundOrderDetail_HtyService outboundOrderDetail_HtyService, IInboundOrder_HtyService inboundOrder_HtyService, IStockRepository stockRepository, IInboundOrderDetailService inboundOrderDetailService, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IBasicRepository basicRepository, IStockInfoDetailRepository stockInfoDetailRepository, IPalletTypeInfoRepository palletTypeInfoRepository, IReturnOrderRepository returnOrderRepository, IProductionRepository productionRepository, IInboundRepository inboundRepository, ITakeStockOrderCPRepository takeStockOrderCPRepository, ITakeStockOrderDetailCPRepository takeStockOrderDetailCPRepository, IStockInfoDetailCPRepository stockInfoDetailCPRepository) : base(BaseDal) { _mapper = mapper; _stockRepository = stockRepository; _unitOfWorkManage = unitOfWorkManage; _basicService = basicService; _outboundService = outboundService; _inboundService = inboundService; _recordService = recordService; _stockService = stockService; _taskHtyService = taskHtyService; _locationInfoService = locationInfoService; _inboundOrderDetailService = inboundOrderDetailService; _materielInfoService = materielInfoService; _inboundOrder_HtyService = inboundOrder_HtyService; _inboundOrderDetail_HtyService = inboundOrderDetail_HtyService; _outboundOrder_HtyService = outboundOrder_HtyService; _outboundOrderDetail_HtyService = outboundOrderDetail_HtyService; _outboundOrderDetailRepository = outboundOrderDetailRepository; _basicRepository = basicRepository; _stockInfoDetailRepository = stockInfoDetailRepository; _palletTypeInfoRepository = palletTypeInfoRepository; _returnOrderRepository = returnOrderRepository; _productionRepository = productionRepository; _inboundRepository = inboundRepository; _takeStockOrderCPRepository = takeStockOrderCPRepository; _takeStockOrderDetailCPRepository = takeStockOrderDetailCPRepository; _stockInfoDetailCPRepository = stockInfoDetailCPRepository; } public string ReceiveWMSTaskin = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskin"]; public string ReceiveWMSTaskreturn = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskreturn"]; public string ReceiveWMSTaskout = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskout"]; public string ReceiveWMSTaskAUT = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskAUT"]; public string ReceiveWMSTaskAllocatein = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskAllocatein"]; public string ReceiveERPTaskout = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveERPTaskout"]; public string InMaterialWarehousingCallback = WIDESEA_Core.Helper.AppSettings.Configuration["InMaterialWarehousingCallback"]; /// /// 任务信息推送至WCS /// /// public WebResponseContent PushTasksToWCS(List tasks, string agvDescription = "") { try { List taskDTOs = _mapper.Map>(tasks); taskDTOs.ForEach(x => { x.AGVArea = agvDescription; }); string url = AppSettings.app("WCS"); if (string.IsNullOrEmpty(url)) { return WebResponseContent.Instance.Error($"未找到WCSApi地址,请检查配置文件"); } string response = HttpHelper.Post($"{url}/api/Task/ReceiveTask", taskDTOs.Serialize()); return JsonConvert.DeserializeObject(response) ?? WebResponseContent.Instance.Error("返回错误"); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } public WebResponseContent PushTasksWCS(List tasks, string agvDescription = "") { try { List taskDTOs = _mapper.Map>(tasks); taskDTOs.ForEach(x => { x.AGVArea = agvDescription; }); string url = AppSettings.app("WCS"); if (string.IsNullOrEmpty(url)) { return WebResponseContent.Instance.Error($"未找到WCSApi地址,请检查配置文件"); } string response = HttpHelper.Post($"{url}/api/Task/ReceiveCPTask", taskDTOs.Serialize()); return JsonConvert.DeserializeObject(response) ?? WebResponseContent.Instance.Error("返回错误"); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } public WebResponseContent FeedBackWCSTaskCompleted(int taskNum) { try { Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); if (task == null) { return WebResponseContent.Instance.Error("未找到该任务信息"); } string url = AppSettings.app("WCS"); if (string.IsNullOrEmpty(url)) { return WebResponseContent.Instance.Error($"未找到WCSApi地址,请检查配置文件"); } string response = HttpHelper.Post($"{url}/api/Task/RecWMSTaskCompleted?taskNum=" + taskNum); return JsonConvert.DeserializeObject(response) ?? WebResponseContent.Instance.Error("返回错误"); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } /// /// 放货完成 /// /// /// public WebResponseContent PutFinish(string code) { try { string url = AppSettings.app("WCS"); if (string.IsNullOrEmpty(url)) { return WebResponseContent.Instance.Error($"未找到WCSAApi地址,请检查配置文件"); } string response = HttpHelper.Post($"{url}/api/CTU_AGV/PutFinish?code=" + code); return JsonConvert.DeserializeObject(response) ?? WebResponseContent.Instance.Error("返回错误"); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } /// /// 任务完成 /// /// 任务号 /// 返回处理结果 public async Task TaskCompleted(int taskNum) { try { Dt_Task task = await Repository.QueryFirstAsync(x => x.TaskNum == taskNum); if (task == null) { return await Task.FromResult(WebResponseContent.Instance.Error($"未找到任务信息")); } if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) { return await Task.FromResult(InboundTaskCompleted(taskNum)); } else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) { return await Task.FromResult(OutboundTaskCompleted(taskNum)); } //else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) //{ // return await Task.FromResult(RelocationTaskCompleted(task)); //} else { return await Task.FromResult(WebResponseContent.Instance.Error($"未找到该类型任务,任务类型:{task.TaskType}")); } } catch (Exception ex) { return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message)); } } /// /// 修改任务状态 /// /// /// public WebResponseContent UpdateTaskInfo(WCSTaskDTO task) { try { Dt_Task wmsTask = BaseDal.QueryFirst(x => x.TaskNum == task.TaskNum); if (wmsTask != null) { wmsTask.TaskStatus = task.TaskState; wmsTask.CurrentAddress = task.CurrentAddress; wmsTask.NextAddress = task.NextAddress; wmsTask.Dispatchertime = task.Dispatchertime; BaseDal.UpdateData(wmsTask); } return WebResponseContent.Instance.OK(); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } public WebResponseContent UpdateTaskStatus(int taskNum, int tasktype) { WebResponseContent content = new WebResponseContent(); try { Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.TaskType == tasktype); if (task == null) return WebResponseContent.Instance.Error("未找到任务信息"); if (TaskEnumHelper.GetTaskTypeGroup(task.TaskType) == TaskTypeGroup.InboundGroup) { task.TaskStatus = TaskInStatusEnum.InFinish.ObjToInt(); content = UpdateTaskStatusInFinish(task); } } catch (Exception) { throw; } return content; } public WebResponseContent UpdateTaskStatusInFinish(Dt_Task task) { WebResponseContent content = new WebResponseContent(); try { Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);//组盘库存 Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);//货位 var result = CheckCompleted(stockInfo, locationInfo); if (!result.Item1) { throw new Exception(result.Item2); } if (stockInfo.StockStatus != StockStatusEmun.入库中.ObjToInt()) throw new Exception($"托盘[{task.PalletCode}],该组盘状态不可入库"); Dt_StockInfoDetail stockInfoDetail = stockInfo.Details.FirstOrDefault(x => x.StockId == stockInfo.Id); List stockInfos = _stockService.StockInfoService.Repository.LocationCodesGetStockInfos(new List { stockInfo.LocationCode }).Where(x => x.StockStatus == (int)StockStatusEmun.已入库.ObjToInt()).ToList(); if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt()) { stockInfo.SerialNumber = stockInfos.Count + 1; stockInfo.InDate = DateTime.Now; stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt(); stockInfoDetail.Status = StockStatusEmun.已入库.ObjToInt(); locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); task.CurrentAddress = task.NextAddress; task.NextAddress = string.Empty; Db.Ado.BeginTran(); BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成); _basicService.LocationInfoService.Repository.UpdateData(locationInfo); _stockService.StockInfoService.Repository.UpdateData(stockInfo); _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail); Db.Ado.CommitTran(); return content; } #region 入库单 Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo); if (inboundOrder != null || inboundOrder.Details.Count < 1) throw new Exception($"未找到托盘[{task.PalletCode}]的入库单明细信息"); Dt_InboundOrderDetail inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfoDetail.BatchNo && x.MaterielCode == stockInfoDetail.MaterielCode); inboundOrderDetail.OrderDetailStatus = inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity ? OrderDetailStatusEnum.Over.ObjToInt() : OrderDetailStatusEnum.GroupAndInbound.ObjToInt(); if (inboundOrder.Details.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()) == null) { inboundOrder.OrderStatus = InboundStatusEnum.入库完成.ObjToInt(); } else if (inboundOrder.OrderStatus == InboundStatusEnum.未开始.ObjToInt()) { inboundOrder.OrderStatus = InboundStatusEnum.入库中.ObjToInt(); } stockInfo.SerialNumber = stockInfos.Count + 1; stockInfo.InDate = DateTime.Now; stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt(); stockInfoDetail.Status = StockStatusEmun.已入库.ObjToInt(); locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); task.CurrentAddress = task.NextAddress; task.NextAddress = string.Empty; Db.Ado.BeginTran(); #region 任务和入库单 BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成); if (inboundOrder.OrderStatus != InboundStatusEnum.入库完成.ObjToInt()) { _inboundService.InbounOrderService.Repository.UpdateData(inboundOrder); _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail); } else { List orderDetails = inboundOrder.Details; inboundOrder.Details = null; _inboundService.InbounOrderService.Repository.DeleteAndMoveIntoHty(inboundOrder, OperateType.自动完成); _inboundService.InboundOrderDetailService.Repository.DeleteAndMoveIntoHty(orderDetails, OperateType.自动完成); } #endregion _basicService.LocationInfoService.Repository.UpdateData(locationInfo); _stockService.StockInfoService.Repository.UpdateData(stockInfo); _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail); //_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); Db.Ado.CommitTran(); #endregion } catch (Exception ex) { Db.Ado.RollbackTran(); content.Error(ex.Message); } return content; } /// /// 验证数据 /// /// /// /// private (bool, string) CheckCompleted(Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo, bool isCheckStockDetail = true) { if (stockInfo == null) { return (false, "未找到组盘信息"); } if (locationInfo == null) { return (false, "未找到货位信息"); } if (isCheckStockDetail && (stockInfo.Details == null || stockInfo.Details.Count == 0)) { return (false, "未找到组盘明细信息"); } return (true, "成功"); } #region 入库任务完成 public WebResponseContent InboundTaskCompleted(int taskNum) { return null; } #endregion #region//出库任务完成 public WebResponseContent OutboundTaskCompleted(int taskNum) { return null; } #endregion } }