| using System; | 
| using System.Collections.Generic; | 
| using System.Linq; | 
| using System.Text; | 
| using System.Threading.Tasks; | 
| using WIDESEA_Common.OrderEnum; | 
| using WIDESEA_Core; | 
| using WIDESEA_Core.BaseRepository; | 
| using WIDESEA_Core.BaseServices; | 
| using WIDESEA_Core.CodeConfigEnum; | 
| using WIDESEA_Core.Helper; | 
| using WIDESEA_DTO.Basic; | 
| using WIDESEA_DTO.MES; | 
| using WIDESEA_IBasicRepository; | 
| using WIDESEA_IInboundRepository; | 
| using WIDESEA_IInboundService; | 
| using WIDESEA_IOutboundService; | 
| using WIDESEA_IStockRepository; | 
| using WIDESEA_Model.Models; | 
|   | 
| namespace WIDESEA_InboundService | 
| { | 
|     public class MesProInOrderService : ServiceBase<Dt_MesProInOrder, IMesProInOrderRepository>, IMesProInOrderService | 
|     { | 
|         public IMesProInOrderRepository Repository => BaseDal; | 
|         private readonly IUnitOfWorkManage _unitOfWorkManage; | 
|         private readonly IInboundRepository _inboundRepository; | 
|         private readonly IStockRepository _stockRepository; | 
|         public MesProInOrderService(IMesProInOrderRepository BaseDal, IUnitOfWorkManage unitOfWorkManag, IInboundRepository inboundRepository, IStockRepository stockRepository) : base(BaseDal) | 
|         { | 
|             _unitOfWorkManage = unitOfWorkManag; | 
|             _inboundRepository = inboundRepository; | 
|             _stockRepository = stockRepository; | 
|         } | 
|         /// <summary> | 
|         /// 成品入库扫码 | 
|         /// </summary> | 
|         /// <param name="Id"></param> | 
|         /// <param name="saveModel"></param> | 
|         /// <returns></returns> | 
|         public WebResponseContent ProInboundScan(int Id,string serNum) | 
|         { | 
|             WebResponseContent content = new WebResponseContent(); | 
|             try | 
|             { | 
|                 //获取对应MES成品入库单据 | 
|                 Dt_MesProInOrder mesProInOrder = BaseDal.Db.Queryable<Dt_MesProInOrder>().Where(x => x.Id == Id).Includes(x => x.Details).First(); | 
|                 if (mesProInOrder==null) | 
|                 { | 
|                     return content.Error("当前MES入库单据不存在"); | 
|                 } | 
|                 if (mesProInOrder.MesProStatus>= InOrderStatusEnum.入库完成.ObjToInt()) | 
|                 { | 
|                     return content.Error("当前单据已入库或关闭状态"); | 
|                 } | 
|                 ProSerNumAnalysisModel model = CodeAnalysisHelper.CodeAnalysis<ProSerNumAnalysisModel>(AnalysisCodeEnum.ProSerNumAnalysis, serNum); | 
|                 Dt_MesProInOrderDetail? proInOrderDetail = mesProInOrder.Details.FirstOrDefault(x => x.BagNo == model.BagNO); | 
|                 //判断扫描和单据中是否匹配 | 
|                 if (proInOrderDetail == null) | 
|                 { | 
|                     return content.Error($"框码{mesProInOrder.BatchNo}中无内包{model.BagNO}信息"); | 
|                 } | 
|                 if ((proInOrderDetail.OverInQuantity + model.OKPCSQTY.ObjToInt())> proInOrderDetail.OKPCSQTY) | 
|                 { | 
|                     return content.Error($"内包数量溢出{(proInOrderDetail.OverInQuantity + model.OKPCSQTY.ObjToInt()) - proInOrderDetail.OKPCSQTY}"); | 
|                 } | 
|                 float SumPCSQty = mesProInOrder.Details.Sum(x => x.OKPCSQTY); | 
|                 float OverPCSQty = mesProInOrder.Details.Sum(x=>x.OverInQuantity); | 
|                 if ((OverPCSQty+model.OKPCSQTY.ObjToInt())>SumPCSQty) | 
|                 { | 
|                     return content.Error($"当前入库订单数量溢出{(OverPCSQty + model.OKPCSQTY.ObjToInt())- SumPCSQty}"); | 
|                 } | 
|   | 
|                 proInOrderDetail.OverInQuantity += model.OKPCSQTY.ObjToInt(); | 
|                 _inboundRepository.MesProInOrderDetailRepository.UpdateData(proInOrderDetail); | 
|                 return content.OK($"内包{proInOrderDetail.BagNo}已扫数量:{proInOrderDetail.OverInQuantity},剩余:{proInOrderDetail.OKPCSQTY-proInOrderDetail.OverInQuantity}"); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 content.Error(ex.Message); | 
|             } | 
|             return content; | 
|         } | 
|     } | 
| } |