helongyang
2026-03-31 8fcd7a67e4391a5f1fbdb590c2a3f913aeb2a0a0
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs
@@ -78,6 +78,42 @@
            _warehouseService = warehouseService;
            _palletTypeInfoRepository = palletTypeInfoRepository;
        }
        public override PageGridData<Dt_InboundOrder> GetPageData(PageDataOptions options)
        {
            PageGridData<Dt_InboundOrder> pageGridData = base.GetPageData(options);
            ISugarQueryable<Dt_InboundOrder> sugarQueryable1 = BaseDal.Db.Queryable<Dt_InboundOrder>().Includes(x => x.Details);
            if (!string.IsNullOrEmpty(options.Wheres))
            {
                List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
                int totalCount = 0;
                if (searchParametersList.Count > 0)
                {
                    {
                        SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrderDetail.MaterielCode).FirstLetterToLower());
                        if (searchParameters != null)
                        {
                            sugarQueryable1 = sugarQueryable1.Where(x => x.Details.Any(v => v.MaterielCode.Contains(searchParameters.Value)));
                            List<Dt_InboundOrder> dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
                            return new PageGridData<Dt_InboundOrder>(totalCount, dataList);
                        }
                    }
                    {
                        SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrderDetail.BatchNo).FirstLetterToLower());
                        if (searchParameters != null)
                        {
                            sugarQueryable1 = sugarQueryable1.Where(x => x.Details.Any(v => v.BatchNo.Contains(searchParameters.Value)));
                            List<Dt_InboundOrder> dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
                            return new PageGridData<Dt_InboundOrder>(totalCount, dataList);
                        }
                    }
                }
            }
            return pageGridData;
        }
        public override object GetDetailPage(PageDataOptions pageData)
        {
            Type t = typeof(Dt_InboundOrder);
@@ -591,7 +627,7 @@
                #region å…¥åº“完成上报ERP
                if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.入库完成.ObjToInt() && inboundOrder.OrderType != InOrderTypeEnum.Allocat.ObjToInt())
                {
                    if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt())
                    if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt() || inboundOrder.OrderType == InOrderTypeEnum.BomReturn.ObjToInt())
                    {
                        FeedbackReturnOrder(inboundOrder, returnOrder);
                    }
@@ -1817,6 +1853,15 @@
            {
                return 4;
            }
            else if (warehouse.WarehouseCode == WarehouseEnum.HA581.ObjToString())
            {
                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
                if (palletTypeInfo == null)
                {
                    throw new Exception($"托盘号错误");
                }
                return palletTypeInfo.PalletType;
            }
            return -1;
        }
        /// <summary>
@@ -1864,5 +1909,143 @@
            }
            return WebResponseContent.Instance.OK();
        }
        public WebResponseContent PPPKMaterielGroup(string palletCode, int Initiallife, int warehouseId, List<string> serNums)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId);
                if (warehouse == null)
                {
                    return WebResponseContent.Instance.Error($"未找到该仓库信息");
                }
                List<MatSerNumAnalysisModel> models = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.PPPKSerNumAnalysis, serNums);
                if (models.Select(x => x.MaterielCode).Distinct().Count() > 1)
                {
                    return WebResponseContent.Instance.Error($"物料不可混放");
                }
                //验证判断时间格式
                WebResponseContent IsValidContent = IsValidMCDates(models);
                if (!IsValidContent.Status)
                {
                    return content.Error(IsValidContent.Message);
                }
                string materielCode = models.FirstOrDefault()?.MaterielCode ?? "";
                int materielWidth = 0;
                if (materielCode.Contains("-"))
                {
                    var model = models.FirstOrDefault();
                    if (model != null && !string.IsNullOrEmpty(model.MaterielCode))
                    {
                        var codeParts = model.MaterielCode.Split("-");
                        if (codeParts.Length >= 2)
                        {
                            if (int.TryParse(codeParts[1], out int widthValue))
                            {
                                materielWidth = widthValue;
                            }
                            else
                            {
                                materielWidth = 0;
                            }
                            materielCode = codeParts[0];
                        }
                    }
                }
                Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode);
                if (materielInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到该物料的信息");
                }
                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 = GetPalletType(warehouse, palletCode),
                        Details = new List<Dt_StockInfoDetail>()
                    };
                }
                else
                {
                    if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt())
                    {
                        return WebResponseContent.Instance.Error($"托盘号重复");
                    }
                    beforeQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
                }
                if(materielWidth != 0&& materielWidth < 650 && stockInfo.PalletType > 1)
                {
                    return WebResponseContent.Instance.Error("低于650裁切宽的物料请用小托盘条码重新组盘!");
                }
                else if(materielWidth != 0 && materielWidth >= 650 && stockInfo.PalletType < 2)
                {
                    return WebResponseContent.Instance.Error("650裁切宽以上的物料请用大托盘条码重新组盘!");
                }
                List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>();
                List<int> detailKeys = new List<int>();
                foreach (var model in models)
                {
                    Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
                    {
                        BatchNo = model.LotNo,
                        MaterielCode = model.MaterielCode,
                        MaterielName = materielInfo.MaterielName,
                        MaterielSpec = materielInfo.MaterielSpec,
                        OrderNo = "",
                        SerialNumber = model.SerialNumber,
                        StockQuantity = model.MaterielCode.Contains("-")? model.MaterielLength.ObjToInt():model.Quantity,
                        OutboundQuantity = 0,
                        Unit = materielInfo.MaterielUnit,
                        Status = StockStatusEmun.组盘暂存.ObjToInt(),
                        ProductionDate = model.ProductionDate,
                        EffectiveDate = model.EffectiveDate,
                        InboundOrderRowNo = 0,
                    };
                    if (stockInfo.Id > 0)
                    {
                        stockInfoDetail.StockId = stockInfo.Id;
                    }
                    stockInfo.Details.Add(stockInfoDetail);
                    stockInfoDetails.Add(stockInfoDetail);
                }
                float totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
                _unitOfWorkManage.BeginTran();
                if (stockInfo.Id == 0)
                {
                    _stockRepository.StockInfoRepository.Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand();
                }
                else
                {
                    _stockRepository.StockInfoRepository.Db.UpdateNav(stockInfo).Include(x => x.Details, new UpdateNavOptions() { OneToManyInsertOrUpdate = true }).ExecuteCommand();
                }
                _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfoDetails, beforeQuantity, totalQuantity, StockChangeTypeEnum.MaterielGroup);
                _unitOfWorkManage.CommitTran();
                content.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
    }
}