|  |  | 
 |  |  |         private readonly IRecordService _recordService; | 
 |  |  |         private readonly IInvokeERPService _invokeERPService; | 
 |  |  |         private readonly IWarehouseService _warehouseService; | 
 |  |  |         private readonly IPalletTypeInfoRepository _palletTypeInfoRepository; | 
 |  |  |  | 
 |  |  |         public IInboundOrderRepository Repository => BaseDal; | 
 |  |  |  | 
 |  |  |         public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IInboundRepository inboundRepository, IBasicRepository basicRepository, IStockRepository stockRepository, IRecordService recordService, IInvokeERPService invokeERPService, IWarehouseService warehouseService) : base(BaseDal) | 
 |  |  |         public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IInboundRepository inboundRepository, IBasicRepository basicRepository, IStockRepository stockRepository, IRecordService recordService, IInvokeERPService invokeERPService, IWarehouseService warehouseService, IPalletTypeInfoRepository palletTypeInfoRepository) : base(BaseDal) | 
 |  |  |         { | 
 |  |  |             _mapper = mapper; | 
 |  |  |             _unitOfWorkManage = unitOfWorkManage; | 
 |  |  | 
 |  |  |             _recordService = recordService; | 
 |  |  |             _invokeERPService = invokeERPService; | 
 |  |  |             _warehouseService = warehouseService; | 
 |  |  |             _palletTypeInfoRepository = palletTypeInfoRepository; | 
 |  |  |         } | 
 |  |  |         /// <summary> | 
 |  |  |         /// å
¶ä»å
¥åºåå建 | 
 |  |  | 
 |  |  |                         PalletCode = palletCode, | 
 |  |  |                         StockStatus = StockStatusEmun.ç»çæå.ObjToInt(), | 
 |  |  |                         WarehouseId = inboundOrder.WarehouseId, | 
 |  |  |                         PalletType = PalletTypeEnum.SmallPallet.ObjToInt(), | 
 |  |  |                         PalletType = GetPalletType(warehouse, palletCode, materielInfo), | 
 |  |  |                         Details = new List<Dt_StockInfoDetail>() | 
 |  |  |                     }; | 
 |  |  |                 } | 
 |  |  | 
 |  |  |                         return WebResponseContent.Instance.Error($"æçå·éå¤"); | 
 |  |  |                     } | 
 |  |  |                     beforeQuantity = stockInfo.Details.Sum(x => x.StockQuantity); | 
 |  |  |                 }; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 if (warehouse.WarehouseCode == WarehouseEnum.HA64.ToString()) | 
 |  |  |                 { | 
 |  |  |                     stockInfo.Remark = Initiallife.ToString(); | 
 |  |  |                     string batchNo = models.FirstOrDefault()?.LotNo ?? ""; | 
 |  |  |                     Dt_StockInfoDetail existDetail = _stockRepository.StockInfoDetailRepository.QueryFirst(x => x.BatchNo == batchNo); | 
 |  |  |                     if (existDetail != null) | 
 |  |  |                     { | 
 |  |  |                         return WebResponseContent.Instance.Error($"{batchNo}æµè¯æ¶å·²åå¨"); | 
 |  |  |                     } | 
 |  |  |                     if (models.Count >= 2) | 
 |  |  |                     { | 
 |  |  |                         return WebResponseContent.Instance.Error($"ç»çæç»ä¸å¯ä¸"); | 
 |  |  |                     } | 
 |  |  |                     if (palletCode.Substring(0, 1) == "6") | 
 |  |  |                     { | 
 |  |  |                         stockInfo.PalletType = PalletTypeEnum.MediumPallet.ObjToInt(); | 
 |  |  |                     } | 
 |  |  |                     else | 
 |  |  |                     { | 
 |  |  |                         stockInfo.PalletType = PalletTypeEnum.LargestPallet.ObjToInt(); | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>(); | 
 |  |  |                 List<int> detailKeys = new List<int>(); | 
 |  |  | 
 |  |  |                 _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder); | 
 |  |  |                 _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfoDetails, beforeQuantity, totalQuantity, StockChangeTypeEnum.MaterielGroup); | 
 |  |  |                 _unitOfWorkManage.CommitTran(); | 
 |  |  |                 //if (warehouse.WarehouseCode==WarehouseEnum.HA153.ToString()) | 
 |  |  |                 //{ | 
 |  |  |                 //    //忥æµè¯æ¶ä¿¡æ¯ | 
 |  |  |                 //    foreach (var model in models) | 
 |  |  |                 //    { | 
 |  |  |                 //        _taskService.TestSynStock(new TestToolSynInfo() { ToolCode = model.LotNo, Life = Initiallife }); | 
 |  |  |                 //    } | 
 |  |  |                 //} | 
 |  |  |                 content.OK(); | 
 |  |  |             } | 
 |  |  |             catch (Exception ex) | 
 |  |  | 
 |  |  |                 float beforeQuantity = 0; | 
 |  |  |  | 
 |  |  |                 Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First(); | 
 |  |  |  | 
 |  |  |                 if (stockInfo == null) | 
 |  |  |                 { | 
 |  |  |                     stockInfo = new Dt_StockInfo() | 
 |  |  | 
 |  |  |                         PalletCode = palletCode, | 
 |  |  |                         StockStatus = StockStatusEmun.æå¨ç»çæå.ObjToInt(), | 
 |  |  |                         WarehouseId = warehouse.WarehouseId, | 
 |  |  |                         PalletType = PalletTypeEnum.SmallPallet.ObjToInt(), | 
 |  |  |                         PalletType = GetPalletType(warehouse, palletCode, materielInfo), | 
 |  |  |                         Details = new List<Dt_StockInfoDetail>() | 
 |  |  |                     }; | 
 |  |  |                 } | 
 |  |  | 
 |  |  |  | 
 |  |  |                 if (warehouse.WarehouseCode == WarehouseEnum.HA64.ToString()) | 
 |  |  |                 { | 
 |  |  |                     string batchNo = models.FirstOrDefault()?.LotNo ?? ""; | 
 |  |  |                     Dt_StockInfoDetail existDetail = _stockRepository.StockInfoDetailRepository.QueryFirst(x => x.BatchNo == batchNo); | 
 |  |  |                     if (existDetail != null) | 
 |  |  |                     { | 
 |  |  |                         return WebResponseContent.Instance.Error($"{batchNo}æµè¯æ¶å·²åå¨"); | 
 |  |  |                     } | 
 |  |  |                     if (models.Count >= 2) | 
 |  |  |                     { | 
 |  |  |                         return WebResponseContent.Instance.Error($"ç»çæç»ä¸å¯ä¸"); | 
 |  |  |                     } | 
 |  |  |                     stockInfo.Remark = Initiallife.ToString(); | 
 |  |  |                     if (palletCode.Substring(0, 1) == "6") | 
 |  |  |                     { | 
 |  |  | 
 |  |  |                         SerialNumber = model.SerialNumber, | 
 |  |  |                         StockQuantity = model.Quantity, | 
 |  |  |                         OutboundQuantity = 0, | 
 |  |  |                         Unit= materielInfo.MaterielUnit, | 
 |  |  |                         Unit = materielInfo.MaterielUnit, | 
 |  |  |                         Status = StockStatusEmun.ç»çæå.ObjToInt(), | 
 |  |  |                         ProductionDate = model.ProductionDate, | 
 |  |  |                         EffectiveDate = model.EffectiveDate, | 
 |  |  | 
 |  |  |                 } | 
 |  |  |                 _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfoDetails, beforeQuantity, totalQuantity, StockChangeTypeEnum.MaterielGroup); | 
 |  |  |                 _unitOfWorkManage.CommitTran(); | 
 |  |  |                 //忥æµè¯æ¶ä¿¡æ¯ | 
 |  |  |                 //foreach (var model in models) | 
 |  |  |                 //{ | 
 |  |  |                 //    _taskService.TestSynStock(new TestToolSynInfo() { ToolCode = model.LotNo, Life = Initiallife }); | 
 |  |  |                 //} | 
 |  |  |                 content.OK(); | 
 |  |  |             } | 
 |  |  |             catch (Exception ex) | 
 |  |  | 
 |  |  |             } | 
 |  |  |             return content; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /// <summary> | 
 |  |  |         /// å
¥åºå®æä¸æ¥ERP | 
 |  |  |         /// </summary> | 
 |  |  | 
 |  |  |                 { | 
 |  |  |                     return WebResponseContent.Instance.Error($"å
¥åºåæ®å·²å®æ"); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == stockInfo.WarehouseId); | 
 |  |  |                 if (warehouse == null) | 
 |  |  |                 { | 
 |  |  | 
 |  |  |             } | 
 |  |  |             catch (Exception ex) | 
 |  |  |             { | 
 |  |  |                 _unitOfWorkManage.RollbackTran(); | 
 |  |  |                 content.Error(ex.Message); | 
 |  |  |             } | 
 |  |  |             return content; | 
 |  |  | 
 |  |  |                 return WebResponseContent.Instance.Error(ex.Message); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         public int GetPalletType(Dt_Warehouse warehouse, string palletCode, Dt_MaterielInfo materielInfo) | 
 |  |  |         { | 
 |  |  |             if (warehouse.WarehouseCode == WarehouseEnum.HA64.ToString()) | 
 |  |  |             { | 
 |  |  |                 if (palletCode.Substring(0, 1) == "6") | 
 |  |  |                 { | 
 |  |  |                     return PalletTypeEnum.MediumPallet.ObjToInt(); | 
 |  |  |                 } | 
 |  |  |                 else | 
 |  |  |                 { | 
 |  |  |                     return PalletTypeEnum.LargestPallet.ObjToInt(); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             else if (warehouse.WarehouseCode == WarehouseEnum.HA152.ObjToString()) | 
 |  |  |             { | 
 |  |  |                 Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2)); | 
 |  |  |                 if (palletTypeInfo == null) | 
 |  |  |                 { | 
 |  |  |                     throw new Exception($"æçå·é误"); | 
 |  |  |                 } | 
 |  |  |                 return palletTypeInfo.PalletType; | 
 |  |  |             } | 
 |  |  |             return -1; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | } |