|  |  |  | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using Newtonsoft.Json.Serialization; | 
|---|
|  |  |  | using Newtonsoft.Json; | 
|---|
|  |  |  | using SqlSugar; | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | using System.Collections.Generic; | 
|---|
|  |  |  | using System.Linq; | 
|---|
|  |  |  | using System.Text; | 
|---|
|  |  |  | using System.Threading.Tasks; | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | private readonly IOutStockLockInfoService _outStockLockInfoService; | 
|---|
|  |  |  | 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) : 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; | 
|---|
|  |  |  | _outStockLockInfoService = outStockLockInfoService; | 
|---|
|  |  |  | _basicService = basicService; | 
|---|
|  |  |  | _recordService = recordService; | 
|---|
|  |  |  | _outProStockInfoService = outProStockInfoService; | 
|---|
|  |  |  | _stockRepository = stockRepository; | 
|---|
|  |  |  | _outProStockInfoRepository = outProStockInfoRepository; | 
|---|
|  |  |  | _unitOfWorkManage = unitOfWorkManage; | 
|---|
|  |  |  | _apiInfoRepository = apiInfoRepository; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// æåºä»»å¡åé
åºå | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | public (List<Dt_ProStockInfo>?,Dt_MesRworkOutboundOrder?,List<Dt_OutProStockInfo>?,List<Dt_LocationInfo>) AssignMesStocks(Dt_MesRworkOutboundOrder mesRworkOutboundOrder) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | List<Dt_ProStockInfo> proStockInfos = new List<Dt_ProStockInfo>(); | 
|---|
|  |  |  | Dt_MesRworkOutboundOrder assignOutOrder= new Dt_MesRworkOutboundOrder(); | 
|---|
|  |  |  | List<Dt_OutProStockInfo> outProStockInfos=new List<Dt_OutProStockInfo>(); | 
|---|
|  |  |  | List<Dt_LocationInfo> locationInfos=new List<Dt_LocationInfo>(); | 
|---|
|  |  |  | float needQty = mesRworkOutboundOrder.RequiredQuantity; | 
|---|
|  |  |  | //æ¥æ¾å¯ç¨åºå | 
|---|
|  |  |  | List<Dt_ProStockInfo> stockInfoss = _stockService.ProStockInfoService.GetUseableStocks(mesRworkOutboundOrder); | 
|---|
|  |  |  | if (!stockInfoss.Any()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new Exception("æªæ¾å°å¯åé
åºå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //è·ååºåºåºå | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | //åé
åºåºçPCSæ°é | 
|---|
|  |  |  | float assignQuantity = needQty; | 
|---|
|  |  |  | //订åæç»çåºåºPCSæ°é | 
|---|
|  |  |  | float orderQuantity = mesRworkOutboundOrder.RequiredQuantity; | 
|---|
|  |  |  | for (int j = 0; j < assignOutStocks.Count; j++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //åºåºè®¢åæç»å·²åé
æ°é | 
|---|
|  |  |  | float detailAssignQuantity = outProStockInfos.Where(x => x.OrderDetailId == mesRworkOutboundOrder.Id).Sum(x => x.AssignQuantity); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //æå©æ°é | 
|---|
|  |  |  | float orderDetailNeedQuantity = mesRworkOutboundOrder.RequiredQuantity - detailAssignQuantity; | 
|---|
|  |  |  | //çæåºåºè¯¦æ | 
|---|
|  |  |  | if (orderDetailNeedQuantity > assignOutStocks[j].proStockInfoDetails.Sum(x => x.OutboundQuantity)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<string> locationArr = proStockInfos.Select(x => x.LocationCode).ToList(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | stockInfos.ForEach(x => { | 
|---|
|  |  |  | x.StockStatus = StockStatusEmun.åºåºéå®.ObjToInt(); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | _stockService.ProStockInfoService.Repository.UpdateData(stockInfos); | 
|---|
|  |  |  | List<Dt_ProStockInfoDetail> stockInfoDetails = new List<Dt_ProStockInfoDetail>(); | 
|---|
|  |  |  | foreach (var item in stockInfos) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | stockInfoDetails.AddRange(item.proStockInfoDetails); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | _stockService.ProStockInfoDetailService.Repository.UpdateData(stockInfoDetails); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Dt_OutProStockInfo> addOutStockLockInfos = outStockLockInfos.Where(x => x.Id == 0).ToList(); | 
|---|
|  |  |  | if (addOutStockLockInfos != null && addOutStockLockInfos.Any()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (tasks != null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | addOutStockLockInfos.ForEach(x => | 
|---|
|  |  |  | { | 
|---|
|  |  |  | x.TaskNum = tasks.FirstOrDefault(v => v.PalletCode == x.PalletCode)?.TaskNum; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _outProStockInfoService.Repository.AddData(addOutStockLockInfos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Dt_OutProStockInfo> updateOutStockLockInfos = outStockLockInfos.Where(x => x.Id > 0).ToList(); | 
|---|
|  |  |  | if (updateOutStockLockInfos != null && updateOutStockLockInfos.Any()) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _outProStockInfoService.Repository.UpdateData(updateOutStockLockInfos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, locationStatus, LocationChangeType.OutboundAssignLocation, "", tasks?.Select(x => x.TaskNum).ToList()); | 
|---|
|  |  |  | _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, locationStatus); | 
|---|
|  |  |  | return WebResponseContent.Instance.OK(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //è·åå½åçMesæåºå | 
|---|
|  |  |  | Dt_MesRworkOutboundOrder rworkOutboundOrder = BaseDal.QueryFirst(x => x.Id == OrderId); | 
|---|
|  |  |  | if (rworkOutboundOrder == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | return content.Error("æªæ¾å°å½åMesæåºå"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|