From 4f39dcc195f28fa275fc2d065fbf1bf6a46c21b7 Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期二, 17 六月 2025 00:41:18 +0800 Subject: [PATCH] 优化出入库逻辑 --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs | 835 +++++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 577 insertions(+), 258 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" index 469485b..d584a14 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" @@ -17,6 +17,7 @@ using AutoMapper; using MailKit.Search; +using Newtonsoft.Json; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using SqlSugar; using System; @@ -24,7 +25,10 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Linq.Expressions; +using System.Net.Http.Headers; using System.Reflection; +using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; using WIDESEA_Core; @@ -32,13 +36,17 @@ using WIDESEA_Core.BaseServices; using WIDESEA_Core.Enums; using WIDESEA_Core.Helper; +using WIDESEA_Core.Log; using WIDESEA_DTO.Inbound; using WIDESEA_DTO.Stock; using WIDESEA_IBasicRepository; using WIDESEA_IBasicService; +using WIDESEA_IInboundService; +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; @@ -46,209 +54,249 @@ namespace WIDESEA_TaskInfoService { - public class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService + public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService { private readonly IMapper _mapper; private readonly IUnitOfWorkManage _unitOfWorkManage; - private readonly ILocationInfoService _locationInfoService; - private readonly ILocationInfoRepository _locationInfoRepository; - private readonly IStockInfoRepository _stockInfoRepository; - private readonly ILocationStatusChangeRecordSetvice _locationStatusChangeRecordSetvice; - private readonly IOutboundOrderDetailService _outboundOrderDetailService; - private readonly IRoadwayInfoRepository _roadwayInfoRepository; - public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, ILocationInfoService locationInfoService, ILocationInfoRepository locationInfoRepository, IStockInfoRepository stockInfoRepository, ILocationStatusChangeRecordSetvice locationStatusChangeRecordSetvice, IOutboundOrderDetailService outboundOrderDetailService, IRoadwayInfoRepository roadwayInfoRepository) : base(BaseDal) + private readonly IBasicService _basicService; + private readonly IOutboundService _outboundService; + private readonly IInboundService _inboundService; + private readonly IRecordService _recordService; + private readonly IStockService _stockService; + private readonly ITask_HtyService _taskHtyService; + private readonly ILocationInfoService _locationInfoService; + + public ITaskRepository Repository => BaseDal; + + public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService) : base(BaseDal) { _mapper = mapper; - _locationInfoService = locationInfoService; - _locationInfoRepository = locationInfoRepository; - _stockInfoRepository = stockInfoRepository; - _locationStatusChangeRecordSetvice = locationStatusChangeRecordSetvice; - _outboundOrderDetailService = outboundOrderDetailService; - _roadwayInfoRepository = roadwayInfoRepository; _unitOfWorkManage = unitOfWorkManage; + _basicService = basicService; + _outboundService = outboundService; + _inboundService = inboundService; + _recordService = recordService; + _stockService = stockService; + _taskHtyService = taskHtyService; + _locationInfoService = locationInfoService; } /// <summary> - /// PDA鐢宠鍏ュ簱--鍫嗗灈鏈虹珛搴撳叆搴� + /// 浠诲姟瀹屾垚 /// </summary> - /// <param name="stationCode">璧峰鍦板潃</param> - /// <param name="taskType">浠诲姟绫诲瀷--鍏ョ┖锛屽叆鏂�</param> - /// <param name="palletCode">鎵樼洏缂栧彿</param> + /// <param name="taskNum">浠诲姟鍙�</param> /// <returns>杩斿洖澶勭悊缁撴灉</returns> - public WebResponseContent GenerateInboundTask(string stationCode, int taskType, string palletCode) + public WebResponseContent TaskCompleted(int taskNum) { - string? name = Enum.GetName(typeof(TaskTypeEnum), taskType); - MethodInfo? methodInfo = GetType().GetMethod(name + "Request"); - if (methodInfo != null) + WebResponseContent content = new WebResponseContent(); + try { - WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { stationCode, palletCode }); - if (responseContent != null) + Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); + if (task == null) { - return responseContent; + return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�"); } - } - else - { - return WebResponseContent.Instance.Error("鏈壘鍒拌浠诲姟绫诲瀷涓氬姟"); - } - return WebResponseContent.Instance.Error("閿欒"); - } - - /// <summary> - /// 绌烘墭鐩樺叆搴� - /// </summary> - /// <param name="stationCode">璧峰鍦板潃</param> - /// <param name="palletCode">鎵樼洏缂栧彿</param> - /// <returns>杩斿洖澶勭悊缁撴灉</returns> - public WebResponseContent PalletInboundRequest(string stationCode, string palletCode) - { - WebResponseContent content = new WebResponseContent(); - try - { - (bool, string) result = CheckRequestInbound(stationCode, palletCode, false); - if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2); - content = AssignLocUpdateData(stationCode, TaskTypeEnum.PalletInbound.ObjToInt(), palletCode, false); - } - catch (Exception ex) - { - content = WebResponseContent.Instance.Error(ex.Message); - } - return content; - } - - /// <summary> - /// 鐗╂枡鍏ュ簱 - /// </summary> - /// <param name="stationCode">璧峰鍦板潃</param> - /// <param name="palletCode">鎵樼洏缂栧彿</param> - /// <returns>杩斿洖澶勭悊缁撴灉</returns> - public WebResponseContent InboundRequest(string stationCode, string palletCode) - { - WebResponseContent content = new WebResponseContent(); - try - { - Dt_StockInfo stockInfo = _stockInfoRepository.GetStockInfo(palletCode); - (bool, string) result = CheckRequestInbound(stationCode, palletCode, true, stockInfo); - if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2); - content = AssignLocUpdateData(stationCode, TaskTypeEnum.Inbound.ObjToInt(), palletCode, true, stockInfo); - } - catch (Exception ex) - { - content = WebResponseContent.Instance.Error(ex.Message); - } - return content; - } - - /// <summary> - /// 鍏ュ簱鍒嗛厤璐т綅鍙婂鐞嗘暟鎹� - /// </summary> - /// <param name="stationCode">璧峰鍦板潃</param> - /// <param name="taskType">浠诲姟绫诲瀷</param> - /// <param name="palletCode">鎵樼洏缂栧彿</param> - /// <param name="isUpdateStock">鏄惁鏇存柊缁勭洏淇℃伅--鍖哄垎鐗╂枡鍏ュ簱鍜岀┖鎵樺叆搴�</param> - /// <param name="stockInfo">缁勭洏淇℃伅--鍙┖</param> - /// <param name="orderNo">璁㈠崟鍙�--鍙┖</param> - /// <returns>杩斿洖澶勭悊缁撴灉</returns> - private WebResponseContent AssignLocUpdateData(string stationCode, int taskType, string palletCode, bool isUpdateStock = true, Dt_StockInfo? stockInfo = null, string orderNo = "") - { - WebResponseContent content = new WebResponseContent(); - try - { - Dt_LocationInfo? locationInfo = _locationInfoService.AssignLocation(stationCode, taskType); - if (locationInfo != null) + _unitOfWorkManage.BeginTran(); + #region MyRegion + switch ((TaskTypeEnum)task.TaskType) { - Dt_Task task = new() - { - CurrentAddress = stationCode, - Grade = 0, - PalletCode = palletCode, - NextAddress = locationInfo.LocationCode, - Roadway = locationInfo.RoadwayNo, - SourceAddress = stationCode, - TargetAddress = locationInfo.LocationCode, - TaskStatus = InTaskStatusEnum.InNew.ObjToInt(), - TaskType = taskType, - }; - BaseDal.AddData(task); - int beforeStatus = locationInfo.LocationStatus; + case TaskTypeEnum.Inbound: + content = InboundTaskCompleted(task); + break; + case TaskTypeEnum.Outbound: + content = OutboundTaskCompleted(task); + break; + case TaskTypeEnum.PalletInbound: + content = PalletInboundTaskCompleted(task); + break; + case TaskTypeEnum.PalletOutbound: + content = PalletOutboundTaskCompleted(task); + break; + case TaskTypeEnum.Relocation: + content = RelocationTaskCompleted(task); + break; + case TaskTypeEnum.AGVCarry: - locationInfo.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt(); - if (isUpdateStock) + break; + default: + return content = WebResponseContent.Instance.Error("鏈壘鍒颁换鍔$被鍨嬪搴斾笟鍔″鐞嗛�昏緫"); + } + if (content.Status) + { + if (App.User.UserId > 0) { - locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); - if (stockInfo != null && stockInfo.Details != null && stockInfo.Details.Count > 0) + content = HttpHelper.Post<WebResponseContent>(url + "StackCraneTaskCompleted?taskNum=" + task.TaskNum, "", "浠诲姟瀹屾垚"); + if (!content.Status) throw new Exception(content.Message); + } + _unitOfWorkManage.CommitTran(); + } + return content; + #endregion + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + return content = WebResponseContent.Instance.Error(ex.Message); + } + finally + { + WriteLog.GetLog("浠诲姟瀹屾垚").Write($"鎿嶄綔浜猴細{(App.User.UserId > 0 ? App.User.UserName : "System")}{Environment.NewLine}浠诲姟鍙凤細{taskNum}{Environment.NewLine}{JsonConvert.SerializeObject(content)}", "浠诲姟瀹屾垚"); + } + } + /// <summary> + /// 浠诲姟鍙栨秷 + /// </summary> + /// <param name="taskNum"></param> + /// <returns></returns> + public WebResponseContent TaskCancel(int taskNum) + { + WebResponseContent content = new WebResponseContent(); + try + { + Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); + if (task == null) + { + return content = WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�"); + } + _unitOfWorkManage.BeginTran(); + MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCancel"); + if (methodInfo != null) + { + WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { task }); + if (responseContent != null) + { + if (responseContent != null) { - orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? ""; - - stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt(); - _stockInfoRepository.UpdateData(stockInfo); - } - else - { - return content = WebResponseContent.Instance.Error("鏈壘鍒板簱瀛樹俊鎭�"); + if (App.User.UserId > 0) + { + var response = HttpHelper.Post<WebResponseContent>(url + "TaskCancel?taskNum=" + task.TaskNum, "", "浠诲姟鍙栨秷"); + if (!response.Status) + { + _unitOfWorkManage.RollbackTran(); + return content = WebResponseContent.Instance.Error(response.Message); + } + _unitOfWorkManage.CommitTran(); + return content = responseContent; + } + _unitOfWorkManage.CommitTran(); + return content = responseContent; } } - _locationInfoRepository.UpdateData(locationInfo); - _locationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), orderNo, task.TaskNum); - - return content = WebResponseContent.Instance.OK(); } - return content = WebResponseContent.Instance.Error("鏈壘鍒板彲鍒嗛厤璐т綅"); + return content = WebResponseContent.Instance.Error("鏈壘鍒颁换鍔$被鍨嬪搴斾笟鍔″鐞嗛�昏緫"); } catch (Exception ex) { - content = WebResponseContent.Instance.Error(ex.Message); + _unitOfWorkManage.RollbackTran(); + return content = WebResponseContent.Instance.Error(ex.Message); } - return content; + finally + { + WriteLog.GetLog("浠诲姟鍙栨秷").Write($"鎿嶄綔浜猴細{(App.User.UserId > 0 ? App.User.UserName : "System")}{Environment.NewLine}浠诲姟鍙凤細{taskNum}{Environment.NewLine}{JsonConvert.SerializeObject(content)}", "浠诲姟鍙栨秷"); + } } - /// <summary> - /// 楠岃瘉鏁版嵁 - /// </summary> - /// <param name="stationCode">璧峰鍦板潃</param> - /// <param name="palletCode">鎵樼洏缂栧彿</param> - /// <param name="isCheckStock">鏄惁妫�鏌ョ粍鐩樹俊鎭�--鍖哄垎鐗╂枡鍏ュ簱鍜岀┖鎵樺叆搴�</param> - /// <param name="stockInfo">缁勭洏淇℃伅--鍙┖</param> - /// <returns>杩斿洖澶勭悊缁撴灉</returns> - private (bool, string) CheckRequestInbound(string stationCode, string palletCode, bool isCheckStock = true, Dt_StockInfo? stockInfo = null) + public WebResponseContent UpdateTaskStatus(int taskNum) { - if (BaseDal.QueryFirst(x => x.PalletCode == palletCode) != null) + WebResponseContent content = new WebResponseContent(); + try { - return (false, "璇ユ墭鐩樺彿宸叉湁浠诲姟"); + Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); + if (task == null) + { + return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�"); + } + if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletOutbound.ObjToInt()) + { + task.TaskStatus = OutTaskStatusEnum.SC_OutExecuting.ObjToInt(); + } + else if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt()) + { + task.TaskStatus = InTaskStatusEnum.SC_InExecuting.ObjToInt(); + } + else if (task.TaskType == TaskTypeEnum.Relocation.ObjToInt()) + { + task.TaskStatus = RelocationTaskStatusEnum.RelocationExecuting.ObjToInt(); + } + else + { + throw new Exception($"浠诲姟绫诲瀷閿欒,鏈壘鍒拌浠诲姟绫诲瀷,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟绫诲瀷:銆恵task.TaskType}銆�"); + } + _unitOfWorkManage.BeginTran(); + task.Dispatchertime = DateTime.Now; + task.ModifyDate = DateTime.Now; + task.Modifier = App.User.UserId > 0 ? App.User.UserName : "System"; + BaseDal.UpdateData(task); + _unitOfWorkManage.CommitTran(); + return content = WebResponseContent.Instance.OK(); } - if (BaseDal.QueryFirst(x => (x.SourceAddress == stationCode || x.CurrentAddress == stationCode) && x.TaskStatus == InTaskStatusEnum.InNew.ObjToInt()) != null) + catch (Exception ex) { - return (false, "褰撳墠鍏ュ簱绔欏彴宸叉湁涓�鏉℃柊寤轰换鍔�"); + _unitOfWorkManage.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); } - if (isCheckStock) + } + public WebResponseContent InboundTaskCompleted(Dt_Task task) + { + try { - if (stockInfo == null) + decimal beforeQuantity = 0; + + Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); + Dt_StockInfoDetail stockInfoDetail = stockInfo.Details.FirstOrDefault(); + + Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); + + CheckCompleted(stockInfo, locationInfo); + + Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo); + if (inboundOrder != null) { - return (false, "鏈壘鍒扮粍鐩樹俊鎭�"); + Dt_InboundOrderDetail? inboundOrderDetail = inboundOrder.Details.Where(x => x.BatchNo == stockInfoDetail.BatchNo).FirstOrDefault(); + if (inboundOrderDetail != null) + { + inboundOrderDetail.OverInQuantity++; + inboundOrderDetail.OrderDetailStatus = inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity ? OrderDetailStatusEnum.Over.ObjToInt() : OrderDetailStatusEnum.GroupAndInbound.ObjToInt(); + + if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()) + { + if (inboundOrder.Details.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt() && x.BatchNo != inboundOrderDetail.BatchNo) == null) + { + inboundOrder.OrderStatus = InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt(); + _inboundService.InbounOrderService.Repository.DeleteAndMoveIntoHty(inboundOrder, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + _inboundService.InboundOrderDetailService.Repository.DeleteAndMoveIntoHty(inboundOrder.Details, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + } + } + _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail); + } + _inboundService.InbounOrderService.Repository.UpdateData(inboundOrder); } - if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt()) - { - return (false, "璇ョ粍鐩樼姸鎬佷笉鍙叆搴�"); - } - if (!string.IsNullOrEmpty(stockInfo.LocationCode)) - { - return (false, "璇ユ墭鐩樺凡缁戝畾璐т綅"); - } - if (stockInfo.Details == null || stockInfo.Details.Count == 0) - { - return (false, "娌℃湁搴撳瓨鏄庣粏淇℃伅"); - } + + stockInfo.LocationCode = locationInfo.LocationCode; + stockInfo.StockStatus = StockStatusEmun.宸插叆搴�.ObjToInt(); + _stockService.StockInfoService.Repository.UpdateData(stockInfo); + + beforeQuantity = stockInfo.Details.Where(x => x.Id != 0).Sum(x => x.StockQuantity); + + int beforeStatus = locationInfo.LocationStatus; + locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); + _basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Inbound.ObjToInt(), false); + + _basicService.LocationInfoService.Repository.UpdateData(locationInfo); + task.TaskStatus = InTaskStatusEnum.InFinish.ObjToInt(); + + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + + _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); + _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, StockChangeType.Inbound, task.TaskNum); + return WebResponseContent.Instance.OK(); } - else + catch (Exception ex) { - if (_stockInfoRepository.QueryFirst(x => x.PalletCode == palletCode) != null) - { - return (false, "璇ユ墭鐩樺凡瀛樺湪搴撳唴"); - } + return WebResponseContent.Instance.Error(ex.Message); } - return (true, "鎴愬姛"); } /// <summary> @@ -258,51 +306,42 @@ /// <returns>杩斿洖澶勭悊缁撴灉</returns> public WebResponseContent PalletInboundTaskCompleted(Dt_Task task) { - Dt_StockInfo stockInfo = new Dt_StockInfo() + try { - PalletCode = task.PalletCode, - LocationCode = task.TargetAddress, - StockStatus = StockStatusEmun.宸插叆搴�.ObjToInt() - }; - Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); + _unitOfWorkManage.BeginTran(); - CheckInboundCompleted(stockInfo, locationInfo); + Dt_StockInfo stockInfo = new Dt_StockInfo() + { + PalletCode = task.PalletCode, + LocationCode = task.TargetAddress, + StockStatus = StockStatusEmun.宸插叆搴�.ObjToInt(), + Creater = App.User.UserId > 0 ? App.User.UserName : "System", + CreateDate = DateTime.Now, + }; + Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); - _stockInfoRepository.AddData(stockInfo); + CheckCompleted(stockInfo, locationInfo); - int beforeStatus = locationInfo.LocationStatus; - locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); - _locationInfoRepository.UpdateData(locationInfo); + _stockService.StockInfoService.Repository.AddData(stockInfo); + int beforeStatus = locationInfo.LocationStatus; + locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); + _basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Inbound.ObjToInt(), false); + _basicService.LocationInfoService.Repository.UpdateData(locationInfo); - BaseDal.DeleteData(task); + task.TaskStatus = InTaskStatusEnum.InFinish.ObjToInt(); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); - _locationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum); + _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum); - return WebResponseContent.Instance.OK(); - } - - public WebResponseContent InboundTaskCompleted(Dt_Task task) - { - Dt_StockInfo stockInfo = _stockInfoRepository.GetStockInfo(task.PalletCode); - - Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); - - CheckInboundCompleted(stockInfo, locationInfo); - - stockInfo.LocationCode = locationInfo.LocationCode; - stockInfo.StockStatus = StockStatusEmun.宸插叆搴�.ObjToInt(); - _stockInfoRepository.UpdateData(stockInfo); - - int beforeStatus = locationInfo.LocationStatus; - locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); - _locationInfoRepository.UpdateData(locationInfo); - - BaseDal.DeleteData(task); - - _locationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); - - return WebResponseContent.Instance.OK(); + _unitOfWorkManage.CommitTran(); + return WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); + } } /// <summary> @@ -311,7 +350,7 @@ /// <param name="stockInfo"></param> /// <param name="locationInfo"></param> /// <returns></returns> - private (bool, string) CheckInboundCompleted(Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo, bool isCheckStockDetail = true) + private (bool, string) CheckCompleted(Dt_StockInfo stockInfo, Dt_LocationInfo locationInfo, bool isCheckStockDetail = true) { if (stockInfo == null) { @@ -331,74 +370,80 @@ return (true, "鎴愬姛"); } - /// <summary> - /// 浠诲姟瀹屾垚 - /// </summary> - /// <param name="taskNum">浠诲姟鍙�</param> - /// <returns>杩斿洖澶勭悊缁撴灉</returns> - public WebResponseContent TaskCompleted(int taskNum) - { - Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); - if (task == null) - { - return WebResponseContent.Instance.Error("鏈壘鍒颁换鍔′俊鎭�"); - } - MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCompleted"); - if (methodInfo != null) - { - WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { task }); - if (responseContent != null) - { - return responseContent; - } - } - return WebResponseContent.Instance.Error(); - } - - public WebResponseContent GenerateOutboundTask(int orderDetailId, List<StockSelectViewDTO> stockSelectViews) + public WebResponseContent OutboundTaskCompleted(Dt_Task task) { try { - List<Dt_Task> tasks = new List<Dt_Task>(); - (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundOrderDetailService.AssignStockOutbound(orderDetailId, stockSelectViews); - for (int i = 0; i < result.Item1.Count; i++) - { - Dt_StockInfo stockInfo = result.Item1[i]; + decimal beforeQuantity = 0; + Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); - if (stockInfo != null) + Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); + + CheckCompleted(stockInfo, locationInfo); + + stockInfo.LocationCode = locationInfo.LocationCode; + stockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt(); + _stockService.StockInfoService.Repository.UpdateData(stockInfo); + int beforeStatus = locationInfo.LocationStatus; + if (locationInfo.Depth == 2) + { + if (DepthTask(locationInfo) == false) { - Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode); - Dt_RoadwayInfo roadwayInfo = _roadwayInfoRepository.QueryFirst(x => x.RoadwayNo == locationInfo.RoadwayNo); - if (roadwayInfo != null) - { - Dt_Task task = new() - { - CurrentAddress = stockInfo.LocationCode, - Grade = 0, - PalletCode = stockInfo.PalletCode, - NextAddress = roadwayInfo.OutSCStationCode, - Roadway = locationInfo.RoadwayNo, - SourceAddress = stockInfo.LocationCode, - TargetAddress = roadwayInfo.OutStationCode, - TaskStatus = InTaskStatusEnum.InNew.ObjToInt(), - TaskType = TaskTypeEnum.Outbound.ObjToInt(), - }; - tasks.Add(task); - } + _basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), false); + } } - result.Item2.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt(); - result.Item3.ForEach(x => - { - x.Status = OutStockStatus.鍑哄簱涓�.ObjToInt(); - }); - List<Dt_LocationInfo> locationInfos = _locationInfoRepository.GetLocationInfos(result.Item3.Select(x => x.LocationCode).ToList()); + locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); + _basicService.LocationInfoService.Repository.UpdateData(locationInfo); + task.TaskStatus = OutTaskStatusEnum.OutFinish.ObjToInt(); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + + beforeQuantity = stockInfo.Details.Where(x => x.Id != 0).Sum(x => x.StockQuantity); + + _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); + _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) - beforeQuantity, StockChangeType.Outbound, task.TaskNum); + + return OnOutboundTaskCompleted?.Invoke(task) ?? WebResponseContent.Instance.OK(); + + } + catch (Exception ex) + { + return WebResponseContent.Instance.Error(ex.Message); + } + } + + public WebResponseContent PalletOutboundTaskCompleted(Dt_Task task) + { + try + { _unitOfWorkManage.BeginTran(); + Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); - BaseDal.AddData(tasks); - _outboundOrderDetailService.LockOutboundStockDataUpdate(result.Item1, result.Item2, result.Item3, locationInfos); - _locationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.Lock.ObjToInt(), StockChangeType.Outbound.ObjToInt(), "", tasks.Select(x => x.TaskNum).ToList()); + Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); + + CheckCompleted(stockInfo, locationInfo); + + int beforeStatus = locationInfo.LocationStatus; + + if (locationInfo.Depth == 2) + { + if (DepthTask(locationInfo) == false) + { + _basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), false); + } + } + locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); + _basicService.LocationInfoService.Repository.UpdateData(locationInfo); + + task.TaskStatus = OutTaskStatusEnum.OutFinish.ObjToInt(); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + + _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); + _unitOfWorkManage.CommitTran(); return WebResponseContent.Instance.OK(); } @@ -408,5 +453,279 @@ return WebResponseContent.Instance.Error(ex.Message); } } + + public WebResponseContent RelocationTaskCompleted(Dt_Task task) + { + try + { + _unitOfWorkManage.BeginTran(); + Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); + + Dt_LocationInfo locationEnd = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); + Dt_LocationInfo locationStart = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); + + CheckCompleted(stockInfo, locationEnd); + + stockInfo.LocationCode = locationEnd.LocationCode; + stockInfo.StockStatus = StockStatusEmun.宸插叆搴�.ObjToInt(); + _stockService.StockInfoService.Repository.UpdateData(stockInfo); + + if (locationStart.Depth == 1) + { + if (DepthTask(locationStart) == false) + { + locationStart.LocationStatus = LocationStatusEnum.Free.ObjToInt(); + _basicService.LocationInfoService.RelocationFree(locationEnd, task.TaskNum); + _basicService.LocationInfoService.Repository.UpdateData(locationStart); + } + else + { + locationStart.LocationStatus = LocationStatusEnum.Free.ObjToInt(); + _basicService.LocationInfoService.Repository.UpdateData(locationStart); + } + } + + _basicService.LocationInfoService.RelocationFree(locationEnd, task.TaskNum); + + task.TaskStatus = RelocationTaskStatusEnum.RelocationFinish.ObjToInt(); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + + _unitOfWorkManage.CommitTran(); + return WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); + } + } + + public WebResponseContent InboundTaskCancel(Dt_Task task) + { + try + { + _unitOfWorkManage.BeginTran(); + decimal beforeQuantity = 0; + + Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); + + Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); + + CheckCompleted(stockInfo, locationInfo); + + stockInfo.StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(); + _stockService.StockInfoService.Repository.UpdateData(stockInfo); + + beforeQuantity = stockInfo.Details.Where(x => x.Id != 0).Sum(x => x.StockQuantity); + + int beforeStatus = locationInfo.LocationStatus; + locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); + if (locationInfo.Depth == 2) + { + _basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), false); + } + + _basicService.LocationInfoService.Repository.UpdateData(locationInfo); + task.TaskStatus = InTaskStatusEnum.InCancel.ObjToInt(); + + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + + _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); + + _unitOfWorkManage.CommitTran(); + return WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); + } + + } + + public WebResponseContent PalletInboundTaskCancel(Dt_Task task) + { + try + { + _unitOfWorkManage.BeginTran(); + Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); + + int beforeStatus = locationInfo.LocationStatus; + + locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); + if (locationInfo.Depth == 2) + { + _basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), false); + } + _basicService.LocationInfoService.Repository.UpdateData(locationInfo); + + task.TaskStatus = InTaskStatusEnum.InCancel.ObjToInt(); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + + _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum); + + _unitOfWorkManage.CommitTran(); + return WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); + } + } + + + public WebResponseContent OutboundTaskCancel(Dt_Task task) + { + try + { + _unitOfWorkManage.BeginTran(); + decimal beforeQuantity = 0; + Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); + Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id); + + Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); + + CheckCompleted(stockInfo, locationInfo); + + stockInfo.LocationCode = locationInfo.LocationCode; + stockInfo.StockStatus = StockStatusEmun.宸插叆搴�.ObjToInt(); + stockInfoDetail.OutboundQuantity = beforeQuantity; + + _stockService.StockInfoService.Repository.UpdateData(stockInfo); + _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail); + int beforeStatus = locationInfo.LocationStatus; + + if (locationInfo.Depth == 2) + { + if (DepthTask(locationInfo) == false) + { + _basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), true); + } + } + locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); + _basicService.LocationInfoService.Repository.UpdateData(locationInfo); + + + task.TaskStatus = OutTaskStatusEnum.OutCancel.ObjToInt(); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + + beforeQuantity = stockInfo.Details.Where(x => x.Id != 0).Sum(x => x.StockQuantity); + + _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); + _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) - beforeQuantity, StockChangeType.Outbound, task.TaskNum); + + _unitOfWorkManage.CommitTran(); + return WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); + } + } + + public WebResponseContent PalletOutboundTaskCancel(Dt_Task task) + { + try + { + _unitOfWorkManage.BeginTran(); + Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); + + Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); + + CheckCompleted(stockInfo, locationInfo); + + int beforeStatus = locationInfo.LocationStatus; + + if (locationInfo.Depth == 2) + { + if (DepthTask(locationInfo) == false) + { + _basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), true); + } + } + locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); + _basicService.LocationInfoService.Repository.UpdateData(locationInfo); + + stockInfo.StockStatus = StockStatusEmun.宸插叆搴�.ObjToInt(); + _stockService.StockInfoService.Repository.UpdateData(stockInfo); + + task.TaskStatus = OutTaskStatusEnum.OutCancel.ObjToInt(); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + + _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); + + _unitOfWorkManage.CommitTran(); + return WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); + } + } + + public WebResponseContent RelocationTaskCancel(Dt_Task task) + { + try + { + _unitOfWorkManage.BeginTran(); + Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); + + Dt_LocationInfo locationEnd = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); + Dt_LocationInfo locationStart = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); + + stockInfo.StockStatus = StockStatusEmun.宸插叆搴�.ObjToInt(); + _stockService.StockInfoService.Repository.UpdateData(stockInfo); + + locationEnd.LocationStatus = LocationStatusEnum.Free.ObjToInt(); + _basicService.LocationInfoService.RelocationFree(locationStart, task.TaskNum); + _basicService.LocationInfoService.Repository.UpdateData(locationEnd); + + task.TaskStatus = RelocationTaskStatusEnum.RelocationCancel.ObjToInt(); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚); + + _unitOfWorkManage.CommitTran(); + return WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); + } + } + public bool DepthTask(Dt_LocationInfo location) + { + if (location != null) + { + Dt_LocationInfo locations = _locationInfoService.Repository.QueryFirst(x => x.RoadwayNo == location.RoadwayNo && x.Column == location.Column && x.Layer == location.Layer && x.Depth != location.Depth && x.Row != location.Row && (SqlFunc.Abs(x.Row - location.Row) == 1)); + if (locations != null) + { + Dt_Task tasks = BaseDal.QueryFirst(x => x.SourceAddress == locations.LocationCode); + return tasks != null ? true : false; + } + } + return false; + } + public WebResponseContent GetTaskInfo() + { + WebResponseContent content = new WebResponseContent(); + try + { + Expression<Func<Dt_Task, bool>> expression = x => true; + if (!App.User.IsSuperAdmin) + { + expression = x => x.Creater == App.User.UserName; + } + var task = BaseDal.Db.Queryable<Dt_Task>().OrderByDescending(x => x.CreateDate).Take(10).Select(x => new Dt_Task { TaskNum = x.TaskNum, PalletCode = x.PalletCode, TaskType = x.TaskType, SourceAddress = x.SourceAddress, TargetAddress = x.TargetAddress }).ToList(); + content = WebResponseContent.Instance.OK(data: task); + } + catch (Exception ex) + { + content = WebResponseContent.Instance.Error(ex.Message); + } + return content; + } } } -- Gitblit v1.9.3