From a3014a01e07619105d597d0c51cf195217b0806f Mon Sep 17 00:00:00 2001 From: wankeda <Administrator@DESKTOP-HAU3ST3> Date: 星期二, 29 七月 2025 10:47:01 +0800 Subject: [PATCH] 1 --- WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs | 312 +++++++++++++++++++++++++++++++++++---------------- 1 files changed, 212 insertions(+), 100 deletions(-) diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs index 77ca387..f96becc 100644 --- a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs +++ b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs @@ -71,6 +71,7 @@ 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; @@ -86,9 +87,10 @@ private readonly IOutboundOrderDetail_HtyService _outboundOrderDetail_HtyService; private readonly IPalletTypeInfoRepository _palletTypeInfoRepository; private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository; + private readonly IStockInfoDetailRepository _stockInfoDetailRepository; 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) : base(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) : base(BaseDal) { _mapper = mapper; _stockRepository = stockRepository; @@ -107,6 +109,9 @@ _outboundOrder_HtyService = outboundOrder_HtyService; _outboundOrderDetail_HtyService = outboundOrderDetail_HtyService; _outboundOrderDetailRepository = outboundOrderDetailRepository; + _basicRepository = basicRepository; + _stockInfoDetailRepository = stockInfoDetailRepository; + _palletTypeInfoRepository = palletTypeInfoRepository; } public string ReceiveWMSTaskin = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskin"]; @@ -171,32 +176,67 @@ /// </summary> /// <param name="taskNum">浠诲姟鍙�</param> /// <returns>杩斿洖澶勭悊缁撴灉</returns> - public WebResponseContent TaskCompleted(int taskNum) + public async Task<WebResponseContent> TaskCompleted(int taskNum) { try { - Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); + Dt_Task task = await Repository.QueryFirstAsync(x => x.TaskNum == taskNum); if (task == null) { - return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�"); + return await Task.FromResult(WebResponseContent.Instance.Error($"鏈壘鍒颁换鍔′俊鎭�")); } - MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCompleted"); - if (methodInfo != null) + if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) { - WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { task }); - if (responseContent != null) - { - return responseContent; - } + return await Task.FromResult(InboundTaskCompleted(taskNum)); } - return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔$被鍨嬪搴斾笟鍔″鐞嗛�昏緫"); + 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)); + } + } + + + + /// <summary> + /// 淇敼浠诲姟鐘舵�� + /// </summary> + /// <param name="task"></param> + /// <returns></returns> + 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(); @@ -235,7 +275,7 @@ Dt_StockInfoDetail stockInfoDetail = stockInfo.Details.FirstOrDefault(x => x.StockId == stockInfo.Id); List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.Repository.LocationCodesGetStockInfos(new List<string> { stockInfo.LocationCode }).Where(x => x.StockStatus == (int)StockStatusEmun.宸插叆搴�.ObjToInt()).ToList(); - if (task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt()) + if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt()) { stockInfo.SerialNumber = stockInfos.Count + 1; stockInfo.InDate = DateTime.Now; @@ -293,7 +333,7 @@ _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail); //_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); Db.Ado.CommitTran(); - SendInboundInfoToWMS(task, inboundOrder, stockInfoDetail); + SendInboundInfoToWMS(task, inboundOrder, stockInfo); #endregion } catch (Exception ex) @@ -444,12 +484,12 @@ // 鏇存柊鍏ュ簱鍗� UpdateInboundOrder(inboundOrder, inboundOrderDetail); - // 濡傛灉鏄渶鍚庝竴鏉℃槑缁嗭紝澶勭悊WMS鍥炰紶 - if (inboundOrder.Details.Count == 1) - { - var stockInfoDetail = stockInfo.Details.FirstOrDefault(); - SendInboundInfoToWMS(task, inboundOrder, stockInfoDetail); - } + // 鍗曟嵁鏁伴噺鍏ㄩ儴涓婃灦瀹屾垚锛屽鐞哤MS鍥炰紶 + //if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()) + //{ + // var stockInfoDetail = stockInfo.Details.FirstOrDefault(); + // SendInboundInfoToWMS(task, inboundOrder, stockInfo); + //} _unitOfWorkManage.CommitTran(); return WebResponseContent.Instance.OK(); @@ -464,36 +504,76 @@ private WebResponseContent ProcessAllocateInbound(Dt_Task task, Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo, int lastStatus, Dt_InboundOrder inboundOrder, Dt_InboundOrderDetail inboundOrderDetail) { - // 濡傛灉鏄渶鍚庝竴鏉℃槑缁� - if (inboundOrder.Details.Count == 1) + //// 濡傛灉鏄渶鍚庝竴鏉℃槑缁� + //if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()) + //{ + // try + // { + // _unitOfWorkManage.BeginTran(); + + // // 澶勭悊璋冩嫧鍏ュ簱鍗� + // ProcessAllocateInboundOrder(inboundOrder, inboundOrderDetail); + + // // 鑾峰彇鐩稿叧搴撳瓨淇℃伅 + // var relatedStockInfo = _stockService.StockInfoService.Repository + // .QueryData(x => x.BatchNo == inboundOrderDetail.BatchNo); + + // // 鍙戦�佽皟鎷ㄤ俊鎭埌WMS + // SendAllocateInfoToWMS(task, inboundOrder, relatedStockInfo); + + // _unitOfWorkManage.CommitTran(); + // } + // catch + // { + // _unitOfWorkManage.RollbackTran(); + // throw; + // } + //} + + //// 娣诲姞鍘嗗彶璁板綍 + //AddInboundOrderDetailHistory(inboundOrderDetail); + + //return WebResponseContent.Instance.OK(); + // 鏇存柊鍏ュ簱鍗曟槑缁嗙姸鎬� + UpdateInboundOrderDetails(stockInfo, inboundOrder, ref inboundOrderDetail); + + // 鏇存柊搴撳瓨鏄庣粏鐘舵�� + stockInfo.Details.ForEach(x => x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()); + + try { - try - { - _unitOfWorkManage.BeginTran(); + _unitOfWorkManage.BeginTran(); - // 澶勭悊璋冩嫧鍏ュ簱鍗� - //ProcessAllocateInboundOrder(inboundOrder, inboundOrderDetail); + // 鏇存柊浠诲姟鐘舵�� + UpdateTaskStatus(task); - // 鑾峰彇鐩稿叧搴撳瓨淇℃伅 - var relatedStockInfo = _stockService.StockInfoService.Repository - .QueryData(x => x.BatchNo == inboundOrderDetail.BatchNo); + // 鏇存柊璐т綅鐘舵�� + UpdateLocationStatus(locationInfo, lastStatus); - // 鍙戦�佽皟鎷ㄤ俊鎭埌WMS - SendAllocateInfoToWMS(task, inboundOrder, relatedStockInfo); + // 鏇存柊搴撳瓨淇℃伅 + UpdateStockInfo(stockInfo); - _unitOfWorkManage.CommitTran(); - } - catch - { - _unitOfWorkManage.RollbackTran(); - throw; - } + // 娣诲姞璁板綍 + AddRecords(task, stockInfo, locationInfo, lastStatus); + + // 鏇存柊鍏ュ簱鍗� + UpdateInboundOrder(inboundOrder, inboundOrderDetail); + + // 鍗曟嵁鏁伴噺鍏ㄩ儴涓婃灦瀹屾垚锛屽鐞哤MS鍥炰紶 + //if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()) + //{ + // var stockInfoDetail = stockInfo.Details.FirstOrDefault(); + // SendInboundInfoToWMS(task, inboundOrder, stockInfo); + //} + + _unitOfWorkManage.CommitTran(); + return WebResponseContent.Instance.OK(); } - - // 娣诲姞鍘嗗彶璁板綍 - AddInboundOrderDetailHistory(inboundOrderDetail); - - return WebResponseContent.Instance.OK(); + catch + { + _unitOfWorkManage.RollbackTran(); + throw; + } } #region Helper Methods @@ -560,53 +640,62 @@ } } - private void SendInboundInfoToWMS(Dt_Task task, Dt_InboundOrder inboundOrder, Dt_StockInfoDetail stockInfoDetail) + private void SendInboundInfoToWMS(Dt_Task task, Dt_InboundOrder inboundOrder, Dt_StockInfo stockInfo) { - if (stockInfoDetail == null) return; + + List<Dt_StockInfo> StockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == task.WarehouseId).Includes(x => x.Details).Where(x => x.Details.Any(v => v.OrderNo == inboundOrder.OrderNo)).ToList(); + //var dt_StockInfo = _stockRepository.StockInfoRepository.QueryData(x => x.Id == stockInfo.Id).ToList(); + //List<Dt_StockInfo> StockInfos = new List<Dt_StockInfo>(); + //foreach (var item in dt_StockInfo) + //{ + // Dt_StockInfo StockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.Id == item.Id).Includes(x => x.Details).First(); + // StockInfos.Add(StockInfo); + //} + + if (StockInfos.Count == 0) throw new Exception("鏈壘鍒板簱瀛樹俊鎭�"); var houseInboundPassBack = new HouseInboundPassBack { ApiType = "AsnController", Method = "AsrsGroudingAsn", Parameters = new List<HouseInboundPassBack.data> + { + new HouseInboundPassBack.data { - new HouseInboundPassBack.data + Value = new List<data.data1> { - Value = new List<data.data1> + new data.data1 { - new data.data1 + AsnNo = inboundOrder.OrderNo, + //InWarehouse = task.Roadway, + TransactionCode = inboundOrder.TransactionCode, + InoutType = inboundOrder.OrderType, + OrderType = inboundOrder.InoutType, + // 閬嶅巻鎵�鏈夊簱瀛樻槑缁嗭紝娣诲姞鍒� DetailList + DetailList = StockInfos.Select(d => new data.data1.Inbound { - AsnNo = task.OrderNo, - InWarehouse = task.Roadway, - TransactionCode = inboundOrder.TransactionCode, - InoutType = inboundOrder.OrderType, - OrderType = inboundOrder.InoutType, - DetailList = new List<data.data1.Inbound> - { - new data.data1.Inbound - { - LinId = stockInfoDetail.LinId, - MaterielCode = stockInfoDetail.MaterielCode, - OrderQuantity = stockInfoDetail.StockQuantity, - BatchNo = stockInfoDetail.BatchNo, - FinishQty = stockInfoDetail.StockQuantity, - LocationName = task.TargetAddress - } - } - } + LinId = d.Details.FirstOrDefault()?.LinId?? "", + MaterielCode = d.Details.FirstOrDefault()?.MaterielCode?? "", + OrderQuantity = d.Details.FirstOrDefault().StockQuantity, + BatchNo = d.BatchNo, + LPNNo = d.PalletCode, + FinishQty = d.Details.FirstOrDefault().StockQuantity, + LocationName = d.LocationCode + }).ToList() } } } + } }; var authResult = AuthenticateWithWMS(); if (authResult.IsSuccess) { houseInboundPassBack.Context = new Dictionary<string, string> - { - { "Ticket", authResult.Ticket }, - { "InvOrgId", authResult.InvOrgId } - }; + { + { "Ticket", authResult.Ticket }, + { "InvOrgId", authResult.InvOrgId } + }; HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, houseInboundPassBack, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS"); } @@ -728,15 +817,15 @@ ApiType = "AuthenticationController", Parameters = new List<Parameter> { - new Parameter { Value = "LKAdmin" }, - new Parameter { Value = "LKAdmin" } + new Parameter { Value = "LK-Admin" }, + new Parameter { Value = "LK-Admin" } }, Method = "Login", }; var response = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskAUT, authentication, "鐧诲綍WMS璐﹀彿"); - if (response.Status && response.Context != null) + if (response.Context != null) { return (true, response.Context["Ticket"].ToString(), response.Context["InvOrgId"].ToString()); } @@ -806,10 +895,10 @@ foreach (var lockInfo in outStockLockInfos) { - var detail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == lockInfo.OrderDetailId); + var detail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == lockInfo.BatchNo); if (detail != null) { - detail.OverOutQuantity = detail.LockQuantity; + detail.OverOutQuantity = lockInfo.OriginalQuantity; if (detail.LockQuantity == detail.OrderQuantity) { detail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt(); @@ -845,11 +934,11 @@ // 鏍规嵁璁㈠崟绫诲瀷澶勭悊涓嶅悓閫昏緫 var outDetail = _outboundService.OutboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() - .Where(x => x.LPNNo == stockInfo.PalletCode).First(); + .Where(x => x.BatchNo == outboundOrderDetails.FirstOrDefault().BatchNo).First(); var outboundOrder = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrder>() .Where(x => x.Id == outDetail.OrderId).Includes(x => x.Details).First(); - if (outboundOrder.OrderType == 1) // 鏅�氬嚭搴� + if (outboundOrder.OrderType == 1) // 鏅�氬嚭搴� && outDetail.OrderDetailStatus = OutboundStatusEnum.鍑哄簱瀹屾垚 { ProcessNormalOutbound(task, stockInfo, outboundOrder, outDetail); } @@ -907,9 +996,23 @@ var stockInfoDetail = _stockRepository.StockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>() .Where(x => x.StockId == stockInfo.Id).First(); - if (outboundOrder.Details.Count == 1) + if (outboundOrder.OrderStatus == OutboundStatusEnum.鍑哄簱瀹屾垚.ObjToInt()) { - MoveOutboundOrderToHistory(outboundOrder); + var history = new Dt_OutboundOrder_Hty + { + OrderStatus = outboundOrder.OrderStatus, + CreateType = outboundOrder.CreateType, + UpperOrderNo = outboundOrder.UpperOrderNo, + OrderNo = outboundOrder.OrderNo, + OutWareHouse = outboundOrder.OutWareHouse, + TransactionCode = outboundOrder.TransactionCode, + InoutType = outboundOrder.InoutType, + OrderType = outboundOrder.OrderType, + Creater = "WMS", + CreateDate = DateTime.Now, + }; + _outboundOrder_HtyService.AddData(history); + _outboundService.OutboundOrderService.DeleteData(outboundOrder); } MoveOutboundDetailToHistory(outDetail); @@ -928,7 +1031,21 @@ if (outboundOrder.Details.Count == 1) { - MoveOutboundOrderToHistory(outboundOrder); + var history = new Dt_OutboundOrder_Hty + { + OrderStatus = outboundOrder.OrderStatus, + CreateType = outboundOrder.CreateType, + UpperOrderNo = outboundOrder.UpperOrderNo, + OrderNo = outboundOrder.OrderNo, + OutWareHouse = outboundOrder.OutWareHouse, + TransactionCode = outboundOrder.TransactionCode, + InoutType = outboundOrder.InoutType, + OrderType = outboundOrder.OrderType, + Creater = "WMS", + CreateDate = DateTime.Now, + }; + _outboundOrder_HtyService.AddData(history); + _outboundService.OutboundOrderService.DeleteData(outboundOrder); } MoveOutboundDetailToHistory(outDetail); @@ -940,24 +1057,6 @@ DeleteStockInfo(stockInfo); } - private void MoveOutboundOrderToHistory(Dt_OutboundOrder outboundOrder) - { - var history = new Dt_OutboundOrder_Hty - { - OrderStatus = outboundOrder.OrderStatus, - CreateType = outboundOrder.CreateType, - UpperOrderNo = outboundOrder.UpperOrderNo, - OrderNo = outboundOrder.OrderNo, - OutWareHouse = outboundOrder.OutWareHouse, - TransactionCode = outboundOrder.TransactionCode, - InoutType = outboundOrder.InoutType, - OrderType = outboundOrder.OrderType, - Creater = "WMS", - CreateDate = DateTime.Now, - }; - _outboundOrder_HtyService.AddData(history); - _outboundService.OutboundOrderService.DeleteData(outboundOrder); - } private void MoveOutboundDetailToHistory(Dt_OutboundOrderDetail outDetail) { @@ -979,6 +1078,19 @@ private void SendNormalOutboundToWMS(Dt_Task task, Dt_OutboundOrder outboundOrder, Dt_StockInfoDetail stockInfoDetail, Dt_OutboundOrderDetail outDetail) { + + + List<Dt_StockInfo> StockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == task.WarehouseId).Includes(x => x.Details).Where(x => x.Details.Any(v => v.OrderNo == outboundOrder.OrderNo)).ToList(); + //var dt_StockInfo = _stockRepository.StockInfoRepository.QueryData(x => x.Id == stockInfo.Id).ToList(); + //List<Dt_StockInfo> StockInfos = new List<Dt_StockInfo>(); + //foreach (var item in dt_StockInfo) + //{ + // Dt_StockInfo StockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.Id == item.Id).Includes(x => x.Details).First(); + // StockInfos.Add(StockInfo); + //} + + if (StockInfos.Count == 0) throw new Exception("鏈壘鍒板簱瀛樹俊鎭�"); + var passBack = new HouseoutboundPassBack { ApiType = "ShippingOrderController", -- Gitblit v1.9.3