dengjunjie
2025-06-17 4f39dcc195f28fa275fc2d065fbf1bf6a46c21b7
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Service/InboundOrderService.cs
@@ -36,6 +36,81 @@
            return BaseDal.Db.Queryable<Dt_InboundOrder>().Includes(x => x.Details).First(x => x.OrderNo == inboundOrderNo); ;
        }
        public WebResponseContent MaterielGroup(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var palletCode = saveModel.MainData["palletCode"].ToString();
                if (string.IsNullOrEmpty(palletCode)) throw new Exception("托盘号不可为空");
                var orderNo = saveModel.MainData["orderNo"].ToString();
                if (string.IsNullOrEmpty(orderNo)) throw new Exception("单号不可为空");
                var batchNo = saveModel.MainData["batchNo"].ToString();
                if (string.IsNullOrEmpty(batchNo)) throw new Exception("批号不可为空");
                //var StationCode = saveModel.MainData["address"].ToString();
                //if (string.IsNullOrEmpty(StationCode)) throw new Exception("地址不可为空");
                //Dt_RoadwayInfo roadwayInfo = _basicService.RoadwayInfoService.Repository.QueryFirst(x => x.InStationCode == StationCode) ?? throw new Exception("未找到该入库站台,请检查基础配置信息!");
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(palletCode);
                if (stockInfo != null) throw new Exception($"托盘【{palletCode}】已存在库存信息");
                stockInfo = new Dt_StockInfo();
                stockInfo.Details = new List<Dt_StockInfoDetail>();
                Dt_InboundOrder? inboundOrder = GetInboundOrder(orderNo);
                if (inboundOrder == null) throw new Exception($"未找到单号为【{orderNo}】的入库单");
                Dt_InboundOrderDetail? inboundOrderDetail = inboundOrder.Details.Where(x => x.BatchNo == batchNo).FirstOrDefault();
                if (inboundOrderDetail == null) throw new Exception($"单号【{orderNo}】的入库单未找到批号【{batchNo}】");
                if (inboundOrderDetail.OrderQuantity - inboundOrderDetail.ReceiptQuantity < 1) throw new Exception($"单号【{orderNo}】的批号【{batchNo}】可组盘数量不足");
                #region å¤„理入库单
                inboundOrder.OrderStatus = InboundStatusEnum.入库中.ObjToInt();
                inboundOrderDetail.ReceiptQuantity++;
                inboundOrderDetail.OrderDetailStatus = inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity ? OrderDetailStatusEnum.Over.ObjToInt() : OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
                #endregion
                #region æ·»åŠ åº“å­˜
                if (stockInfo.Id == 0)
                {
                    stockInfo.PalletCode = palletCode;
                    stockInfo.StockStatus = StockStatusEmun.组盘暂存.ObjToInt();
                    stockInfo.Creater = "System";
                    stockInfo.Remark = "人工组盘入库";
                }
                Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
                {
                    Status = StockStatusEmun.组盘暂存.ObjToInt(),
                    OrderNo = inboundOrder.OrderNo,
                    StockId = stockInfo.Id != 0 ? stockInfo.Id : 0,
                    MaterielName = inboundOrderDetail.MaterielName,
                    MaterielCode = inboundOrderDetail.MaterielCode,
                    BatchNo = inboundOrderDetail.BatchNo,
                    StockQuantity = 1,
                    SerialNumber = "",
                    Creater = "System"
                };
                stockInfo.Details.Add(stockInfoDetail);
                #endregion
                Db.Ado.BeginTran();
                BaseDal.UpdateData(inboundOrder);
                _inboundOrderDetailService.UpdateData(inboundOrderDetail);
                _stockService.StockInfoService.AddMaterielGroup(stockInfo);
                Db.Ado.CommitTran();
                content.OK();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
        public WebResponseContent QueryOrderDetailInfo(int pageNo, string orderNo)
        {
            WebResponseContent content = new WebResponseContent();
            Dt_InboundOrder inboundOrder = GetInboundOrder(orderNo);
            List<Dt_InboundOrderDetail> inboundOrderDetails = inboundOrder.Details;
            content.OK(data: inboundOrderDetails);
            return content;
        }
        /// <summary>
        /// ç»„盘
        /// </summary>
@@ -58,6 +133,7 @@
                Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(materielGroupDTO.PalletCode);
                //if (stockInfo != null) throw new Exception($"托盘号【{materielGroupDTO.PalletCode}】已存在");
                (bool, string, object?) result = CheckMaterielGroupParam(materielGroupDTO, matSerialNumberDTOs, materielInfos, materielCodes, inboundOrder, stockInfo);
                if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
@@ -71,7 +147,8 @@
                List<Dt_StockInfoDetail> stockInfoDetails = _mapper.Map<List<Dt_StockInfoDetail>>(matSerialNumberDTOs);
                stockInfoDetails.ForEach(x =>
                {
                    x.Status = 0;
                    //x.Status = 0;
                    x.Status = StockStatusEmun.组盘暂存.ObjToInt();
                    x.OrderNo = inboundOrder.OrderNo;
                    x.MaterielName = materielInfos.FirstOrDefault(v => v.MaterielCode == x.MaterielCode)?.MaterielName ?? "";
                    x.StockId = stockInfo.Id != 0 ? stockInfo.Id : 0;
@@ -87,12 +164,23 @@
                for (int i = 0; i < materielCodes.Count; i++)
                {
                    decimal stockQuantity = stockInfoDetails.Where(x => x.MaterielCode == materielCodes[i]).Sum(x => x.StockQuantity);
                    inboundOrderDetails.AddRange(_inboundOrderDetailService.UpdateReceiptQuantity(inboundOrder.Details.Where(x => x.MaterielCode == materielCodes[i]).ToList(), stockQuantity));
                    List<Dt_InboundOrderDetail> orderDetails = inboundOrder.Details.Where(x => x.MaterielCode == materielCodes[i]).ToList();
                    if (orderDetails.Count > 0)
                    {
                        var OrderQuantity = orderDetails.Sum(x => x.OrderQuantity);
                        if (OrderQuantity < stockQuantity) throw new Exception("组盘数量超出单据数量");
                        inboundOrderDetails.AddRange(_inboundOrderDetailService.UpdateReceiptQuantity(orderDetails, stockQuantity));
                    }
                }
                List<int> updateDetailIds = inboundOrderDetails.Select(x => x.Id).ToList();
                if (inboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()) == null && inboundOrder.Details.FirstOrDefault(x => !updateDetailIds.Contains(x.Id) && x.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()) == null)
                {
                    inboundOrder.OrderStatus = InboundStatusEnum.入库完成.ObjToInt();
                    BaseDal.DeleteAndMoveIntoHty(inboundOrder, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                    for (int i = 0; i < inboundOrderDetails.Count; i++)
                    {
                        _inboundOrderDetailService.Repository.DeleteAndMoveIntoHty(inboundOrderDetails[i], App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                    }
                }
                else if (inboundOrder.OrderStatus == InboundStatusEnum.未开始.ObjToInt())
                {
@@ -103,7 +191,7 @@
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
                content.Error(ex.Message);
            }
            finally
            {
@@ -214,6 +302,12 @@
            return (true, "成功", materielGroupDTO);
        }
        /// <summary>
        /// PDA分页查询数据
        /// </summary>
        /// <param name="pageNo">页码</param>
        /// <param name="orderNo">订单号</param>
        /// <returns></returns>
        public WebResponseContent QueryOrderInfo(int pageNo, string orderNo)
        {
            if (string.IsNullOrEmpty(orderNo))