From 18d1f45193e34e00fc1b6f65b8596ddb29c5267d Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期二, 24 十二月 2024 15:32:43 +0800 Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/HuaiAn --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs | 232 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 208 insertions(+), 24 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 7198373..bc617ce 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" @@ -16,29 +16,24 @@ #endregion << 鐗� 鏈� 娉� 閲� >> using AutoMapper; -using MailKit.Search; using Newtonsoft.Json; -using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using SqlSugar; -using System; -using System.Collections.Generic; -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.Reflection.Emit; using System.Threading.Tasks; +using WIDESEA_Common.CommonEnum; +using WIDESEA_Common.LocationEnum; +using WIDESEA_Common.OrderEnum; +using WIDESEA_Common.StockEnum; +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.Log; using WIDESEA_DTO.Inbound; using WIDESEA_DTO.Stock; +using WIDESEA_DTO.Task; +using WIDESEA_External.ERPService; using WIDESEA_IBasicRepository; using WIDESEA_IBasicService; using WIDESEA_IInboundService; @@ -58,30 +53,219 @@ { private readonly IMapper _mapper; private readonly IUnitOfWorkManage _unitOfWorkManage; - + private readonly IStockRepository _stockRepository; private readonly IBasicService _basicService; - private readonly IOutboundService _outboundService; - private readonly IInboundService _inboundService; private readonly IRecordService _recordService; + private readonly IOutboundService _outboundService; private readonly IStockService _stockService; - private readonly ITask_HtyService _taskHtyService; - private readonly ILocationInfoService _locationInfoService; + private readonly IBasicRepository _basicRepository; + private readonly IApiInfoRepository _apiInfoRepository; + private readonly IInvokeERPService _invokeERPService; 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) + private Dictionary<string, OrderByType> _taskOrderBy = new() + { + {nameof(Dt_Task.Grade),OrderByType.Desc }, + {nameof(Dt_Task.CreateDate),OrderByType.Asc}, + }; + + public List<int> TaskTypes => typeof(TaskTypeEnum).GetEnumIndexList(); + + public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList(); + + public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockRepository stockRepository, IBasicService basicService, IRecordService recordService, IOutboundService outboundService, IStockService stockService, IBasicRepository basicRepository, IApiInfoRepository apiInfoRepository, IInvokeERPService invokeERPService) : base(BaseDal) { _mapper = mapper; _unitOfWorkManage = unitOfWorkManage; + _stockRepository = stockRepository; _basicService = basicService; - _outboundService = outboundService; - _inboundService = inboundService; _recordService = recordService; + _outboundService = outboundService; _stockService = stockService; - _taskHtyService = taskHtyService; - _locationInfoService = locationInfoService; + _basicRepository = basicRepository; + _apiInfoRepository = apiInfoRepository; + _invokeERPService = invokeERPService; } - + /// <summary> + /// 浠诲姟淇℃伅鎺ㄩ�佽嚦WCS + /// </summary> + /// <returns></returns> + public WebResponseContent PushTasksToWCS(List<Dt_Task> tasks, string agvDescription = "") + { + try + { + List<WMSTaskDTO> taskDTOs = _mapper.Map<List<WMSTaskDTO>>(tasks); + taskDTOs.ForEach(x => + { + x.AGVArea = agvDescription; + }); + string response = HttpHelper.Post("http://127.0.0.1:9291/api/Task/ReceiveTask", taskDTOs.Serialize()); + + return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("杩斿洖閿欒"); + } + catch (Exception ex) + { + return WebResponseContent.Instance.Error(ex.Message); + } + } + + /// <summary> + /// 鍏ュ簱浠诲姟瀹屾垚 + /// </summary> + /// <param name="taskNum">浠诲姟鍙�</param> + /// <returns></returns> + public WebResponseContent InboundTaskCompleted(int taskNum) + { + try + { + Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); + if (task == null) + { + return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅"); + } + + if (task.TaskType != TaskTypeEnum.Inbound.ObjToInt()) + { + return WebResponseContent.Instance.Error($"浠诲姟绫诲瀷閿欒"); + } + + Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == task.PalletCode).Includes(x => x.Details).First(); + if (stockInfo == null) + { + return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅"); + } + + if (!string.IsNullOrEmpty(stockInfo.LocationCode)) + { + return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅"); + } + + if (stockInfo.Details == null || stockInfo.Details.Count == 0) + { + return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅"); + } + + Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); + if (locationInfo == null) + { + return WebResponseContent.Instance.Error($"鏈壘鍒扮洰鏍囪揣浣嶄俊鎭�"); + } + + if (locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt()) + { + return WebResponseContent.Instance.Error($"璐т綅鐘舵�佷笉姝g‘"); + } + + LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus; + locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); + + //娴嬭瘯鏋跺叆搴撳簱瀛樼姸鎬� + if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt()) + { + stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚鏈缓鍑哄簱鍗�.ObjToInt(); + stockInfo.Details.ForEach(x => + { + x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt(); + }); + } + else + { + stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt(); + } + stockInfo.LocationCode = locationInfo.LocationCode; + + _unitOfWorkManage.BeginTran(); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚); + + _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, (PalletTypeEnum)stockInfo.PalletType, LocationStatusEnum.InStock, stockInfo.WarehouseId); + + _stockRepository.StockInfoRepository.UpdateData(stockInfo); + _stockRepository.StockInfoDetailRepository.UpdateData(stockInfo.Details); + _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationChangeType.InboundCompleted); + _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, stockInfo.Details.Sum(x => x.StockQuantity), stockInfo.Details.Sum(x => x.StockQuantity), StockChangeTypeEnum.Inbound, taskNum); + _unitOfWorkManage.CommitTran(); + return WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); + } + } + + /// <summary> + /// 鍑哄簱浠诲姟瀹屾垚 + /// </summary> + /// <param name="taskNum">浠诲姟鍙�</param> + /// <returns></returns> + public WebResponseContent OutboundTaskCompleted(int taskNum) + { + try + { + Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); + if (task == null) + { + return WebResponseContent.Instance.Error($"鏈壘鍒颁换鍔′俊鎭�"); + } + + Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); + + Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); + if (stockInfo == null) + { + return WebResponseContent.Instance.Error($"鏈壘鍒板簱瀛樹俊鎭�"); + } + if (locationInfo == null) + { + return WebResponseContent.Instance.Error($"鏈壘鍒拌揣浣嶄俊鎭�"); + } + + List<Dt_OutStockLockInfo> outStockLockInfos = _outboundService.OutboundStockLockInfoService.Repository.QueryData(x => x.TaskNum == taskNum); + if (outStockLockInfos == null || outStockLockInfos.Count == 0) + { + return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撹鎯呬俊鎭�"); + } + + List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>(); + for (int i = 0; i < outStockLockInfos.Count; i++) + { + Dt_OutboundOrderDetail outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == outStockLockInfos[i].OrderDetailId); + if (outboundOrderDetail != null) + { + outboundOrderDetail.OverOutQuantity = outboundOrderDetail.LockQuantity; + if (outboundOrderDetail.LockQuantity == outboundOrderDetail.OrderQuantity) + { + outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt(); + } + outboundOrderDetails.Add(outboundOrderDetail); + } + } + + _unitOfWorkManage.BeginTran(); + _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails); + + stockInfo.LocationCode = locationInfo.LocationCode; + stockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt(); + _stockService.StockInfoService.Repository.UpdateData(stockInfo); + + int beforeStatus = locationInfo.LocationStatus; + locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); + _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, (PalletTypeEnum)stockInfo.PalletType, LocationStatusEnum.Free, stockInfo.WarehouseId); + BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚); + + _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, (LocationStatusEnum)beforeStatus, LocationChangeType.OutboundCompleted, stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); + _unitOfWorkManage.CommitTran(); + + return WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); + } + } + } } -- Gitblit v1.9.3