From 63d187526792e6e29bfec07d0e3f0dce07df31b3 Mon Sep 17 00:00:00 2001 From: helongyang <647556386@qq.com> Date: 星期六, 19 七月 2025 17:32:41 +0800 Subject: [PATCH] 成品报废单新增优化 --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesRworkOutboundOrderService.cs | 316 +++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 272 insertions(+), 44 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesRworkOutboundOrderService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesRworkOutboundOrderService.cs" index 876025c..c0b232b 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesRworkOutboundOrderService.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/MesRworkOutboundOrderService.cs" @@ -1,4 +1,7 @@ -锘縰sing System; +锘縰sing Newtonsoft.Json.Serialization; +using Newtonsoft.Json; +using SqlSugar; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,16 +9,25 @@ using WIDESEA_Common.LocationEnum; using WIDESEA_Common.StockEnum; using WIDESEA_Core; +using WIDESEA_Core.BaseRepository; using WIDESEA_Core.BaseServices; +using WIDESEA_Core.Enums; using WIDESEA_Core.Helper; +using WIDESEA_DTO; +using WIDESEA_DTO.MES; using WIDESEA_IBasicRepository; using WIDESEA_IBasicService; using WIDESEA_IOutboundRepository; using WIDESEA_IOutboundService; using WIDESEA_IRecordService; +using WIDESEA_IStockRepository; using WIDESEA_IStockService; using WIDESEA_Model.Models; using WIDESEA_OutboundRepository; +using WIDESEA_Common.APIEnum; +using WIDESEA_Common.OrderEnum; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; +using System.Reflection.Metadata; namespace WIDESEA_OutboundService { @@ -27,10 +39,14 @@ private readonly IBasicService _basicService; private readonly IRecordService _recordService; private readonly IOutProStockInfoService _outProStockInfoService; + private readonly IStockRepository _stockRepository; + private readonly IOutProStockInfoRepository _outProStockInfoRepository; + private readonly IUnitOfWorkManage _unitOfWorkManage; + private readonly IApiInfoRepository _apiInfoRepository; public IMesRworkOutboundOrderRepository Repository => BaseDal; - public MesRworkOutboundOrderService(IMesRworkOutboundOrderRepository BaseDal, IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, IRecordService recordService, IOutProStockInfoService outProStockInfoService) : base(BaseDal) + public MesRworkOutboundOrderService(IMesRworkOutboundOrderRepository BaseDal, IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, IRecordService recordService, IOutProStockInfoService outProStockInfoService, IStockRepository stockRepository, IOutProStockInfoRepository outProStockInfoRepository,IUnitOfWorkManage unitOfWorkManage, IApiInfoRepository apiInfoRepository) : base(BaseDal) { _basicRepository = basicRepository; _stockService = stockService; @@ -38,6 +54,10 @@ _basicService = basicService; _recordService = recordService; _outProStockInfoService = outProStockInfoService; + _stockRepository = stockRepository; + _outProStockInfoRepository = outProStockInfoRepository; + _unitOfWorkManage = unitOfWorkManage; + _apiInfoRepository = apiInfoRepository; } /// <summary> /// 鎻愬簱浠诲姟鍒嗛厤搴撳瓨 @@ -48,62 +68,52 @@ Dt_MesRworkOutboundOrder assignOutOrder= new Dt_MesRworkOutboundOrder(); List<Dt_OutProStockInfo> outProStockInfos=new List<Dt_OutProStockInfo>(); List<Dt_LocationInfo> locationInfos=new List<Dt_LocationInfo>(); - float originalNeedQuantity = mesRworkOutboundOrder.RequiredQuantity; - - float needQuantity = originalNeedQuantity; - + float needQty = mesRworkOutboundOrder.RequiredQuantity; //鏌ユ壘鍙敤搴撳瓨 List<Dt_ProStockInfo> stockInfoss = _stockService.ProStockInfoService.GetUseableStocks(mesRworkOutboundOrder); if (!stockInfoss.Any()) { throw new Exception("鏈壘鍒板彲鍒嗛厤搴撳瓨"); } - List<Dt_ProStockInfo> autoAssignStocks = _stockService.ProStockInfoService.GetOutboundStocks(stockInfoss,mesRworkOutboundOrder, needQuantity,out float residueQuantity); - mesRworkOutboundOrder.LockQuantity += needQuantity - residueQuantity; - autoAssignStocks.OrderBy(x => x.proStockInfoDetails.FirstOrDefault()?.StockPcsQty).ToList(); - proStockInfos.AddRange(autoAssignStocks); - float assignQuantity = needQuantity - residueQuantity; - + //鑾峰彇鍑哄簱搴撳瓨 + List<Dt_ProStockInfo> assignOutStocks = _stockService.ProStockInfoService.GetOutboundStocks(stockInfoss, mesRworkOutboundOrder, needQty, out float residueQuantity); + mesRworkOutboundOrder.LockQuantity += needQty - residueQuantity; + if (mesRworkOutboundOrder.RequiredQuantity > mesRworkOutboundOrder.LockQuantity) + { + throw new Exception($"浜у搧缂栫爜{mesRworkOutboundOrder.ProductCode},鐗堟湰{mesRworkOutboundOrder.ProductVersion}鍙垎閰嶆暟閲忎笉瓒�,鍙敤鏁伴噺{mesRworkOutboundOrder.LockQuantity}"); + } + proStockInfos.AddRange(assignOutStocks); + //鍒嗛厤鍑哄簱鐨凱CS鏁伴噺 + float assignQuantity = needQty; + //璁㈠崟鏄庣粏鐨勫嚭搴揚CS鏁伴噺 float orderQuantity = mesRworkOutboundOrder.RequiredQuantity; - for (int j = 0; j < autoAssignStocks.Count; j++) + for (int j = 0; j < assignOutStocks.Count; j++) { //鍑哄簱璁㈠崟鏄庣粏宸插垎閰嶆暟閲� - float detailAssignQuantity = outProStockInfos - .Where(x => x.SaleOrder == mesRworkOutboundOrder.SaleOrder - && x.PCode == mesRworkOutboundOrder.ProductCode - && x.PVer == mesRworkOutboundOrder.ProductVersion) - .Sum(x => x.AssignQuantity); + float detailAssignQuantity = outProStockInfos.Where(x => x.OrderDetailId == mesRworkOutboundOrder.Id).Sum(x => x.AssignQuantity); - //鍑哄簱璇︽儏宸插垎閰嶆暟閲� - float palletAssignQuantity = outProStockInfos - .Where(x => x.SaleOrder == mesRworkOutboundOrder.SaleOrder - && x.PCode == mesRworkOutboundOrder.ProductCode - && x.PVer == mesRworkOutboundOrder.ProductVersion - && x.PalletCode == autoAssignStocks[j].PalletCode) - .Sum(x => x.AssignQuantity); - - float palletOutboundQuantity = autoAssignStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity); - if (palletAssignQuantity < palletOutboundQuantity)//濡傛灉鍑哄簱璇︽儏宸插垎閰嶆暟閲忓皬浜庢墭鐩樺凡鍒嗛厤鏁伴噺锛屽垯鍙互缁х画娣诲姞璇ユ墭鐩樺嚭搴撲俊鎭� + //鎵�鍓╂暟閲� + float orderDetailNeedQuantity = mesRworkOutboundOrder.RequiredQuantity - detailAssignQuantity; + //鐢熸垚鍑哄簱璇︽儏 + if (orderDetailNeedQuantity > assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity)) { - float orderDetailNeedQuantity = mesRworkOutboundOrder.RequiredQuantity - detailAssignQuantity; - if (orderDetailNeedQuantity > autoAssignStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity) - { - mesRworkOutboundOrder.LockQuantity += autoAssignStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity; - Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(mesRworkOutboundOrder, autoAssignStocks[j], autoAssignStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity) - palletAssignQuantity); - outProStockInfos.Add(outStockLockInfo); - } - else - { - Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(mesRworkOutboundOrder, autoAssignStocks[j], mesRworkOutboundOrder.RequiredQuantity-mesRworkOutboundOrder.LockQuantity); - outProStockInfos.Add(outStockLockInfo); - mesRworkOutboundOrder.LockQuantity = mesRworkOutboundOrder.RequiredQuantity; - break; - } + mesRworkOutboundOrder.LockQuantity += assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity); + Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(mesRworkOutboundOrder, assignOutStocks[j], assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity)); + outProStockInfos.Add(outStockLockInfo); + } + else + { + Dt_OutProStockInfo outStockLockInfo = _outProStockInfoService.GetOutStockLockInfo(mesRworkOutboundOrder, assignOutStocks[j], mesRworkOutboundOrder.RequiredQuantity - detailAssignQuantity); + outProStockInfos.Add(outStockLockInfo); + mesRworkOutboundOrder.LockQuantity = mesRworkOutboundOrder.RequiredQuantity; + break; } } - locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(proStockInfos.Select(x => x.LocationCode).ToList())); + List<string> locationArr = proStockInfos.Select(x => x.LocationCode).ToList(); - return (proStockInfos, assignOutOrder, outProStockInfos, locationInfos); + locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(locationArr)); + + return (proStockInfos, mesRworkOutboundOrder, outProStockInfos, locationInfos); } public WebResponseContent LockOutboundStockDataUpdate(List<Dt_ProStockInfo> stockInfos, List<Dt_OutProStockInfo> outStockLockInfos, List<Dt_LocationInfo> locationInfos, LocationStatusEnum locationStatus = LocationStatusEnum.Lock, List<Dt_Task>? tasks = null) { @@ -148,5 +158,223 @@ return WebResponseContent.Instance.Error(ex.Message); } } + /// <summary> + /// 鎴愬搧MES鎻愬簱鍑哄簱瀹屽悗涓�鍖呬竴鍖呮嫞閫� + /// </summary> + /// <returns></returns> + public WebResponseContent MesRworkOutPick(int OrderId,string InrPKCode,int Count=0) + { + WebResponseContent content = new WebResponseContent(); + try + { + //鑾峰彇褰撳墠鐨凪es鎻愬簱鍗� + Dt_MesRworkOutboundOrder rworkOutboundOrder = BaseDal.QueryFirst(x => x.Id == OrderId); + if (rworkOutboundOrder == null) + { + return content.Error("鏈壘鍒板綋鍓峂es鎻愬簱鍗�"); + } + if (rworkOutboundOrder.OrderStatus>=OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()) + { + return content.Error("褰撳墠Mes鎻愬簱鍗曞凡瀹屾垚鎴栧叧闂�"); + } + //鏍规嵁鎵弿鍐呭寘鍙疯幏鍙栧簱瀛� + Dt_ProStockInfoDetail? proStockInfoDetail = _stockRepository.ProStockInfoDetailRepository.QueryFirst(x => x.BagNo == InrPKCode && x.ProOutDetailStatus == StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt()); + if (proStockInfoDetail == null) + { + return content.Error($"鏈壘鍒板唴鍖厈InrPKCode}淇℃伅"); + } + //鑾峰彇搴撳瓨淇℃伅 + Dt_ProStockInfo? proStockInfo = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x => x.Id == proStockInfoDetail.ProStockId).Includes(x => x.proStockInfoDetails).First(); + if (proStockInfo == null) + { + return content.Error($"鏈壘鍒板唴鍖厈InrPKCode}搴撳瓨淇℃伅"); + } + //鏌ヨ璇ユ墭鐩樻槸鍚﹀瓨鍦ㄨ鍗曟嵁鐨勫嚭搴撹鎯� + Dt_OutProStockInfo outProStockInfo = _outProStockInfoRepository.QueryFirst(x => x.OrderNo == rworkOutboundOrder.TaskNo && x.PalletCode == proStockInfo.PalletCode); + if (outProStockInfo == null) + { + return content.Error($"鍐呭寘{InrPKCode}闈炲崟鎹畕rworkOutboundOrder.TaskNo}鍐呭"); + } + //鍒ゆ柇鏄惁鏁村寘鏁伴噺 + if (Count > 0) + { + if (Count> proStockInfoDetail.StockPcsQty) + { + return content.Error($"鍐呭寘鏁伴噺{(int)proStockInfoDetail.StockPcsQty}<鍑哄簱鏁伴噺{Count}"); + } + int setinterval = (int)proStockInfoDetail.StockPcsQty / (int)proStockInfoDetail.SETQty; + if (Count % setinterval!=0) + { + return content.Error($"鑾峰彇SET鏁伴噺澶辫触,1SET:{setinterval}PCS"); + } + proStockInfoDetail.OutSETQty = Count / setinterval; + proStockInfoDetail.OutboundQuantity = Count; + } + else + { + proStockInfoDetail.OutSETQty = proStockInfoDetail.SETQty; + proStockInfoDetail.OutboundQuantity = proStockInfoDetail.StockPcsQty; + } + rworkOutboundOrder.OverOutQuantity += proStockInfoDetail.OutboundQuantity; + if (rworkOutboundOrder.OverOutQuantity> rworkOutboundOrder.RequiredQuantity) + { + return content.Error($"鍗曟嵁{rworkOutboundOrder.TaskNo}婧㈠嚭{rworkOutboundOrder.OverOutQuantity - rworkOutboundOrder.RequiredQuantity}"); + } + if (rworkOutboundOrder.OverOutQuantity== rworkOutboundOrder.RequiredQuantity) + { + rworkOutboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt(); + } + + int SetCount = (int)proStockInfoDetail.OutSETQty; + int EligiblePcsCount = (int)proStockInfoDetail.OutboundQuantity; + _unitOfWorkManage.BeginTran(); + if (proStockInfoDetail.SETQty == proStockInfoDetail.OutSETQty && proStockInfoDetail.StockPcsQty== proStockInfoDetail.OutboundQuantity) + { + proStockInfo.proStockInfoDetails.Remove(proStockInfoDetail); + if (proStockInfo.proStockInfoDetails.Count==0) + { + _stockRepository.ProStockInfoRepository.DeleteAndMoveIntoHty(proStockInfo, OperateTypeEnum.鑷姩鍒犻櫎); + } + _stockRepository.ProStockInfoDetailRepository.DeleteAndMoveIntoHty(proStockInfoDetail, OperateTypeEnum.鑷姩鍒犻櫎); + } + else + { + proStockInfoDetail.SETQty -= proStockInfoDetail.OutSETQty; + proStockInfoDetail.StockPcsQty -= proStockInfoDetail.OutboundQuantity; + proStockInfoDetail.OutSETQty = 0; + proStockInfoDetail.OutboundQuantity = 0; + _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfoDetail); + } + BaseDal.UpdateData(rworkOutboundOrder); + //MES鎴愬搧搴撳瓨鏉垮嚭搴撳悓姝� + WebResponseContent responseContent = ProductOutBoundSync(MesProOutBound(rworkOutboundOrder, new List<Dt_ProStockInfoDetail> { proStockInfoDetail }, SetCount, EligiblePcsCount)); + if (responseContent.Status) + { + throw new Exception("鍚屾MES搴撳瓨鏉垮嚭搴撳け璐�,閿欒:" + responseContent.Message); + } + _unitOfWorkManage.CommitTran(); + if (rworkOutboundOrder.OrderStatus==OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()) + { + content.OK($"鍗曞彿{rworkOutboundOrder.TaskNo}宸插畬鎴�"); + } + else + { + content.OK($"鍗曞彿{rworkOutboundOrder.TaskNo},鍓╀綑:{rworkOutboundOrder.RequiredQuantity-rworkOutboundOrder.OverOutQuantity}PCS"); + } + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + content.Error(ex.Message); + } + return content; + } + /// <summary> + /// 搴撳瓨鏉挎暟鎹浆鎹� + /// </summary> + /// <returns></returns> + public MesProductOutBound MesProOutBound(Dt_MesRworkOutboundOrder mesRworkOutboundOrder, List<Dt_ProStockInfoDetail> proStockInfoDetails,int SetCount,int EligiblePcsCount) + { + //鑾峰彇浠撳簱淇℃伅 + Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == mesRworkOutboundOrder.WarehouseId); + List<MesInventoryInfo> inventoryInfos = new List<MesInventoryInfo>(); + foreach (var item in proStockInfoDetails) + { + MesInventoryInfo mesInventoryInfo = new MesInventoryInfo() + { + Warhouseno = warehouse.WarehouseCode, + InternalPackageNumber = item.BagNo, + SetCount = SetCount, + EligiblePcsCount = EligiblePcsCount + }; + inventoryInfos.Add(mesInventoryInfo); + } + MesProductOutBound mesProductOutBound = new MesProductOutBound() + { + TaskNo = mesRworkOutboundOrder.TaskNo, + ProductCode = mesRworkOutboundOrder.ProductCode, + ProductVersion = mesRworkOutboundOrder.ProductVersion, + DateCode = mesRworkOutboundOrder.DateCode, + SaleOrder = mesRworkOutboundOrder.SaleOrder, + InventoryInfo = inventoryInfos + }; + return mesProductOutBound; + } + //搴撳瓨鏉挎暟鎹浆鎹� + public MesProductOutBound MesProOutBound(Dt_MesRworkOutboundOrder mesRworkOutboundOrder, List<Dt_ProStockInfoDetail> proStockInfoDetails) + { + //鑾峰彇浠撳簱淇℃伅 + Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == mesRworkOutboundOrder.WarehouseId); + List<MesInventoryInfo> inventoryInfos = new List<MesInventoryInfo>(); + foreach (var item in proStockInfoDetails.Where(x=>x.OutboundQuantity>0)) + { + int setinterval = (int)item.StockPcsQty / (int)item.SETQty; + if (setinterval == 0) + { + throw new Exception($"{item.BagNo}鑾峰彇SET鏁伴噺杞崲澶辫触"); + } + item.OutSETQty = (int)item.OutboundQuantity / setinterval; + if (item.OutSETQty == 0) + { + throw new Exception($"{item.BagNo}鑾峰彇SET鏁伴噺杞崲澶辫触"); + } + MesInventoryInfo mesInventoryInfo = new MesInventoryInfo() + { + Warhouseno = warehouse.WarehouseCode, + InternalPackageNumber = item.BagNo, + SetCount = (int)item.OutSETQty, + EligiblePcsCount = (int)item.OutboundQuantity + }; + inventoryInfos.Add(mesInventoryInfo); + } + MesProductOutBound mesProductOutBound = new MesProductOutBound() + { + TaskNo = mesRworkOutboundOrder.TaskNo, + ProductCode = mesRworkOutboundOrder.ProductCode, + ProductVersion = mesRworkOutboundOrder.ProductVersion, + DateCode = mesRworkOutboundOrder.DateCode, + SaleOrder = mesRworkOutboundOrder.SaleOrder, + InventoryInfo = inventoryInfos + }; + return mesProductOutBound; + } + /// <summary> + /// 鎴愬搧搴撳瓨鏉垮悓姝ユ帴鍙� + /// </summary> + public WebResponseContent ProductOutBoundSync(MesProductOutBound model) + { + WebResponseContent content = new WebResponseContent(); + try + { + Dt_ApiInfo apiInfo = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMS_MES_ProductOutBound.ToString()); + MESRoot<MesProductOutBound> root = new MESRoot<MesProductOutBound>() + { + From = "WMS", + DateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), + Content = model + }; + JsonSerializerSettings settings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }; + string request = JsonConvert.SerializeObject(root, settings); + string response = HttpMesHelper.Post(apiInfo.ApiAddress, request); + MesResponseContent mesResponseContent = response.DeserializeObject<MesResponseContent>(); + //璋冪敤鎺ュ彛 + if (mesResponseContent.BSucc == true) + { + content.OK(mesResponseContent.StrMsg); + } + else + { + content.Error(mesResponseContent.StrMsg); + } + } + catch (Exception ex) + { + content.Error(ex.Message); + } + return content; + } } } -- Gitblit v1.9.3