| | |
| | | private readonly IStockRepository _stockRepository; |
| | | private IPalletTypeInfoRepository _palletTypeInfoRepository; |
| | | private readonly IReturnOrderRepository _returnOrderRepository; |
| | | private readonly ICPInboundOrderDetailRepository _cPInboundOrderDetailRepository; |
| | | |
| | | |
| | | public IInboundOrderRepository Repository => BaseDal; |
| | | |
| | | public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IBasicService basicService, IBasicRepository basicRepository, IInboundRepository inboundRepository, IUnitOfWorkManage unitOfWorkManage, ITaskRepository taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IInboundOrder_HtyService inboundOrderHtyService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IWarehouseService warehouseService, IStockRepository stockRepository, IPalletTypeInfoRepository palletTypeInfoRepository, IReturnOrderRepository returnOrderRepository) : base(BaseDal) |
| | | public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IBasicService basicService, IBasicRepository basicRepository, IInboundRepository inboundRepository, IUnitOfWorkManage unitOfWorkManage, ITaskRepository taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IInboundOrder_HtyService inboundOrderHtyService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IWarehouseService warehouseService, IStockRepository stockRepository, IPalletTypeInfoRepository palletTypeInfoRepository, IReturnOrderRepository returnOrderRepository, ICPInboundOrderDetailRepository cPInboundOrderDetailRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | |
| | | _stockRepository = stockRepository; |
| | | _palletTypeInfoRepository = palletTypeInfoRepository; |
| | | _returnOrderRepository = returnOrderRepository; |
| | | _cPInboundOrderDetailRepository = cPInboundOrderDetailRepository; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | var orderNo = saveModel.MainData["orderNo"].ToString(); |
| | | var palletCode = saveModel.MainData["palletCode"].ToString(); |
| | | var warehouseId = saveModel.MainData["warehouseId"].ObjToInt(); |
| | | var Initiallife = saveModel.MainData["initiallife"].ObjToInt(); |
| | | // 首先验证输入数据 |
| | | var serialNumbers = new List<string>(); |
| | | var quantities = new List<decimal>(); |
| | | var lotNos = new List<string>(); |
| | | var materielCodes = new List<string>(); |
| | | |
| | | foreach (var item in saveModel.DelKeys) |
| | | { |
| | | // 直接使用动态类型访问属性,避免多余的序列化/反序列化 |
| | | var delKeyDict = item as IDictionary<string, object>; |
| | | if (delKeyDict == null) |
| | | { |
| | |
| | | return WebResponseContent.Instance.Error("serialNumber的值为空"); |
| | | } |
| | | serialNumbers.Add(serialNumber); |
| | | |
| | | // 处理数量 |
| | | if (!delKeyDict.TryGetValue("quantity", out object quantityObj) || quantityObj == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("缺少物料数量字段或值为空"); |
| | | } |
| | | |
| | | if (!decimal.TryParse(quantityObj.ToString(), out decimal quantity)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"物料数量'{quantityObj}'无法转换为数字"); |
| | | } |
| | | |
| | | if (quantity <= 0) |
| | | { |
| | | return WebResponseContent.Instance.Error("物料数量必须大于0"); |
| | | } |
| | | quantities.Add(quantity); |
| | | } |
| | | |
| | | // 验证数量与序列号数量一致 |
| | | if (serialNumbers.Count != quantities.Count) |
| | | { |
| | | return WebResponseContent.Instance.Error("序列号数量与物料数量不匹配"); |
| | | } |
| | | |
| | | // 获取仓库信息 |
| | | Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId); |
| | | if (warehouse == null) |
| | |
| | | return WebResponseContent.Instance.Error($"未找到入库单信息"); |
| | | } |
| | | |
| | | // 批量查询所有相关箱号/托盘号的CP入库单明细 |
| | | // 根据您的业务逻辑,这里应该是查询 BoxCode 或者 PalletCode 在 serialNumbers 中的记录 |
| | | // 我假设您需要查询 BoxCode 在 serialNumbers 列表中的所有记录 |
| | | // 批量查询所有相关箱号的CP入库单明细 |
| | | List<Dt_CPInboundOrderDetail> CPinboundOrderDetails = BaseDal.Db.Queryable<Dt_CPInboundOrderDetail>() |
| | | .LeftJoin<Dt_InboundOrderDetail>((cp, d) => cp.OrderDetailId == d.Id) |
| | | .LeftJoin<Dt_InboundOrder>((cp, d, o) => d.OrderId == o.Id) |
| | | .Where((cp, d, o) => |
| | | o.OrderNo == orderNo && |
| | | o.WarehouseId == warehouse.WarehouseId && |
| | | serialNumbers.Contains(cp.BoxCode) // 修改这里:批量查询 |
| | | serialNumbers.Contains(cp.BoxCode) |
| | | ) |
| | | .Select((cp, d, o) => cp) |
| | | .ToList(); |
| | | |
| | | |
| | | // 方式2:如果您需要分别处理箱号和托盘号,可以分开查询 |
| | | var boxDetails = CPinboundOrderDetails.Where(x => serialNumbers.Contains(x.BoxCode)).ToList(); |
| | | float totalQty = CPinboundOrderDetails.Sum(x => x.QtyOfpcs); |
| | | |
| | | // 验证查询到的数据数量是否匹配 |
| | | if (CPinboundOrderDetails.Count < serialNumbers.Count) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到所有对应的箱号/托盘号信息,找到{CPinboundOrderDetails.Count}条,期望{serialNumbers.Count}条"); |
| | | return WebResponseContent.Instance.Error($"未找到所有对应的箱号信息,找到{CPinboundOrderDetails.Count}条,期望{serialNumbers.Count}条"); |
| | | } |
| | | |
| | | // 按照箱号分组,用于后续处理 |
| | | var cpDetailsByBoxCode = CPinboundOrderDetails |
| | | .GroupBy(x => x.BoxCode) |
| | | .ToDictionary(g => g.Key, g => g.ToList()); |
| | | |
| | | |
| | | |
| | | // 获取所有相关的入库单明细ID |
| | | var orderDetailIds = CPinboundOrderDetails.Select(x => x.OrderDetailId).Distinct().ToList(); |
| | | |
| | | // 查询对应的入库单明细 |
| | | List<Dt_InboundOrderDetail> inboundOrderDetails = BaseDal.Db.Queryable<Dt_InboundOrderDetail>() |
| | | .Where(x => orderDetailIds.Contains(x.Id)) |
| | | .ToList(); |
| | | |
| | | // 按订单明细ID分组,检查每个明细的所有箱号是否都扫描了 |
| | | var detailsByOrderDetailId = CPinboundOrderDetails |
| | | .GroupBy(x => x.OrderDetailId) |
| | | .ToDictionary(g => g.Key, g => g.ToList()); |
| | | |
| | | // 获取相关的订单明细 |
| | | List<Dt_InboundOrderDetail> orderDetails = new List<Dt_InboundOrderDetail>(); |
| | | List<Dt_InboundOrderDetail> detailsToUpdate = new List<Dt_InboundOrderDetail>(); |
| | | |
| | | // 检查每个订单明细是否完成了所有箱号的扫描 |
| | | foreach (var kvp in detailsByOrderDetailId) |
| | | { |
| | | int orderDetailId = kvp.Key; |
| | | var cpDetails = kvp.Value; |
| | | |
| | | // 获取订单明细 |
| | | var orderDetail = inboundOrder.Details.FirstOrDefault(x => x.Id == orderDetailId); |
| | | if (orderDetail == null) |
| | | { |
| | | orderDetail = BaseDal.Db.Queryable<Dt_InboundOrderDetail>() |
| | | .First(x => x.Id == orderDetailId); |
| | | } |
| | | |
| | | if (orderDetail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"未找到订单明细ID:{orderDetailId}"); |
| | | } |
| | | |
| | | orderDetails.Add(orderDetail); |
| | | |
| | | // 标记该明细为已完成组盘 |
| | | orderDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt(); |
| | | var recqty = orderDetail.ReceiptQuantity; |
| | | orderDetail.ReceiptQuantity = ((decimal)totalQty) + recqty; // 收货数量等于订单数量 |
| | | |
| | | detailsToUpdate.Add(orderDetail); |
| | | } |
| | | |
| | | // 检查托盘是否已存在 |
| | |
| | | // 创建新托盘 |
| | | stockInfo = new Dt_StockInfo() |
| | | { |
| | | //BatchNo = models.FirstOrDefault()?.LotNo ?? "", |
| | | BatchNo = "", // 使用入库单批次号 |
| | | PalletCode = palletCode, |
| | | PalletType = GetPalletType(warehouse, palletCode), |
| | | IsFull = true, |
| | |
| | | } |
| | | } |
| | | |
| | | // 验证和更新每个物料的组盘数量 |
| | | List<Dt_InboundOrderDetail> detailsToUpdate = new List<Dt_InboundOrderDetail>(); |
| | | // 创建库存明细 - 按订单明细创建 |
| | | foreach (var orderDetail in orderDetails) |
| | | { |
| | | // 获取该明细对应的所有箱号 |
| | | var detailBoxCodes = detailsByOrderDetailId[orderDetail.Id] |
| | | .Select(x => x.BoxCode) |
| | | .ToList(); |
| | | |
| | | List<Dt_CPInboundOrderDetail> cPInboundOrderDetail = BaseDal.Db.Queryable<Dt_CPInboundOrderDetail>().Where(x => detailBoxCodes.Contains(x.BoxCode)).ToList(); |
| | | List<Dt_StockInfoDetailCP> stockInfoDetailCP = new List<Dt_StockInfoDetailCP>(); |
| | | foreach (var item in cPInboundOrderDetail) |
| | | { |
| | | Dt_StockInfoDetailCP stockInfoDetailCP1 = new Dt_StockInfoDetailCP() |
| | | { |
| | | BoxId = item.BoxId, |
| | | BoxCode = item.BoxCode, |
| | | DateCode = item.DateCode, |
| | | JobId = item.JobId, |
| | | PartNum = item.PartNum, |
| | | QtyOfpcs = item.QtyOfpcs, |
| | | QtyOfxout = item.QtyOfxout, |
| | | CPStockDetailStatus = (int)StockStatusEmun.组盘暂存, |
| | | Creater = "上游WMS", |
| | | }; |
| | | stockInfoDetailCP.Add(stockInfoDetailCP1); |
| | | |
| | | item.CPOrderDetailStatus = InOrderStatusEnum.入库中.ObjToInt(); |
| | | } |
| | | |
| | | // 创建库存明细 |
| | | Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail() |
| | | { |
| | | MaterielCode = orderDetail.MaterielCode, |
| | | MaterielName = orderDetail.MaterielName, |
| | | OrderNo = inboundOrder.OrderNo, |
| | | BatchNo = orderDetail.BatchNo, |
| | | SupplierBatch = orderDetail.SupplierBatch, |
| | | LinId = orderDetail.LinId, |
| | | StockQuantity = ((decimal)totalQty), |
| | | Status = (int)StockStatusEmun.组盘暂存, |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | | Id = orderDetail.LinId.ObjToInt(), |
| | | //DeliveryNote = orderDetail.DeliveryNote, |
| | | MaterieSpec = orderDetail.MaterieSpec, |
| | | StockDetails = stockInfoDetailCP |
| | | }; |
| | | |
| | | if (stockInfo.Id > 0) |
| | | { |
| | | stockInfoDetail.StockId = stockInfo.Id; |
| | | } |
| | | stockInfo.Details.Add(stockInfoDetail); |
| | | } |
| | | |
| | | // 检查入库单是否所有明细都已完成组盘 |
| | | bool allDetailsCompleted = inboundOrder.Details.All(x => |
| | | detailsToUpdate.Any(d => d.Id == x.Id) || |
| | | x.OrderDetailStatus == OrderDetailStatusEnum.GroupAndInbound.ObjToInt()); |
| | | |
| | | |
| | | |
| | | // 更新订单状态 |
| | | inboundOrder.OrderStatus = InOrderStatusEnum.入库中.ObjToInt(); |
| | | |
| | | |
| | | // 事务处理 |
| | | _unitOfWorkManage.BeginTran(); |
| | |
| | | if (stockInfo.Id == 0) |
| | | { |
| | | _stockRepository.StockInfoRepository.Db.InsertNav(stockInfo) |
| | | .Include(x => x.Details) |
| | | .Include(x => x.Details).ThenInclude(x => x.StockDetails) |
| | | .ExecuteCommand(); |
| | | } |
| | | else |
| | |
| | | .Include(x => x.Details, new UpdateNavOptions() |
| | | { |
| | | OneToManyInsertOrUpdate = true |
| | | }) |
| | | }).ThenInclude(x => x.StockDetails) |
| | | .ExecuteCommand(); |
| | | } |
| | | |
| | | // 更新订单明细 |
| | | if (detailsToUpdate.Count > 0) |
| | | { |
| | | _inboundRepository.InboundOrderDetailRepository.UpdateData(detailsToUpdate); |
| | | } |
| | | |
| | | // 更新订单 |
| | | _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder); |
| | | |
| | | _cPInboundOrderDetailRepository.UpdateData(CPinboundOrderDetails); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | |
| | | content = WebResponseContent.Instance.OK("组盘成功"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | throw; |
| | | throw new Exception($"组盘事务处理失败:{ex.Message}", ex); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | { |
| | | return content.Error($"未找到仓库信息"); |
| | | } |
| | | if (warehouse.WarehouseCode.Contains("CP")) |
| | | if (warehouse.WarehouseCode.Contains("TestJCLK")) |
| | | { |
| | | if (item.SupplierBatch == null) |
| | | { |
| | |
| | | OverInQuantity = 0, |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | LinId = item.LinId, |
| | | LPNNo = item.LPN_No, |
| | | LPNNo = item.LPNNo, |
| | | MaterielName = item.MaterielName, |
| | | MaterieSpec = item.MaterieSpec, |
| | | Creater = "上游WMS", |
| | |
| | | } |
| | | else |
| | | { |
| | | List<Dt_CPInboundOrderDetail> cPInboundOrderDetail = new List<Dt_CPInboundOrderDetail>(); |
| | | foreach (var list in item.BoxList) |
| | | { |
| | | Dt_CPInboundOrderDetail cPInboundOrderDetail = new Dt_CPInboundOrderDetail() |
| | | Dt_CPInboundOrderDetail cPInboundOrderDetail1 = new Dt_CPInboundOrderDetail() |
| | | { |
| | | BoxId = list.BoxId, |
| | | BoxId = (float)list.BoxId, |
| | | BoxCode = list.BoxCode, |
| | | DateCode = list.DateCode, |
| | | JobId = list.JobId, |
| | | JobId = (float)list.JobId, |
| | | PartNum = list.PartNum, |
| | | QtyOfpcs = list.QtyOfpcs, |
| | | QtyOfxout = list.QtyOfxout, |
| | | QtyOfpcs = (float)list.QtyOfpcs, |
| | | QtyOfxout = (float)list.QtyOfxout, |
| | | CPOrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | Creater = "上游WMS", |
| | | }; |
| | | cPInboundOrderDetail.Add(cPInboundOrderDetail1); |
| | | } |
| | | |
| | | Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail() |
| | | { |
| | |
| | | OverInQuantity = 0, |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | LinId = item.LinId, |
| | | LPNNo = item.LPN_No, |
| | | LPNNo = item.LPNNo, |
| | | MaterielName = item.MaterielName, |
| | | MaterieSpec = item.MaterieSpec, |
| | | Creater = "上游WMS", |
| | | SupplierBatch = item.SupplierBatch, |
| | | CPDetails = new List<Dt_CPInboundOrderDetail> { cPInboundOrderDetail } |
| | | CPDetails = cPInboundOrderDetail |
| | | }; |
| | | |
| | | Dt_InboundOrder inboundOrder = new Dt_InboundOrder() |
| | |
| | | // default: |
| | | // break; |
| | | //}; |
| | | |
| | | |
| | | Db.InsertNav(inboundOrder).Include(x => x.Details).ThenInclude(x => x.CPDetails).ExecuteCommand(); |
| | | } |
| | | } |
| | | } |
| | | else |
| | |
| | | OverInQuantity = 0, |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | LinId = item.LinId, |
| | | LPNNo = item.LPN_No, |
| | | LPNNo = item.LPNNo, |
| | | MaterielName = item.MaterielName, |
| | | MaterieSpec = item.MaterieSpec, |
| | | Creater = "上游WMS", |
| | |
| | | OverInQuantity = 0, |
| | | OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(), |
| | | LinId = item.LinId, |
| | | LPNNo = item.LPN_No, |
| | | LPNNo = item.LPNNo, |
| | | MaterielName = item.MaterielName, |
| | | MaterieSpec = item.MaterieSpec, |
| | | Creater = "上游WMS", |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | //反拣回库单 |
| | | public WebResponseContent ReceiveReturnOrder(List<HouseReturnOrder> houseReturnOrder) |
| | | { |
| | | try |