快乐的昕的电脑
2025-11-01 47f9b65b2571000595bfafbadef28ce9d04484c8
service/Warehouse/MesInvItemInCDetailsManager.cs
@@ -26,25 +26,25 @@
        var freeze = 0;
        decimal cSyQty = 0;
        //if (string.IsNullOrEmpty(sectionCode))
        //    throw new Exception("请扫库位条码!");
        if (string.IsNullOrEmpty(sectionCode))
            throw new Exception("请扫库位条码!");
        var itemBarcodeDetails = Db.Queryable<MesInvItemBarcodes>()
            .Where(it => it.ItemBarcode == itemBarcode)
            .First();
        //if (itemBarcodeDetails == null)
        //    throw new Exception("条码不存在,请核对!");
        if (itemBarcodeDetails == null)
            throw new Exception("条码不存在,请核对!");
        if (string.IsNullOrEmpty(itemBarcodeDetails.Memo) || itemBarcodeDetails.Memo != "采购入库")
            throw new Exception("此条码不属于到货条码,无法用采购入库!");
        var inventory = Db.Queryable<MesInvItemArn>()
            .Where(it => it.BillNo == itemBarcodeDetails.BillNo)
            .Where(it => it.BillNo == itemBarcodeDetails.BillNo && it.Fstatus == true )
            .First();
        if (inventory == null)
            throw new Exception("此条码找不到对应收货单!");
            throw new Exception("此条码找不到对应收货单或未审核!");
        // var inventoryDetails = Db.Queryable<MesInvItemArnDetail>()
        //     .Where(it => it.ParentGuid == inventory.Guid
@@ -61,13 +61,21 @@
            .Where(it => it.EbelnK3id == inventoryDetails.LineK3id)
            .First();
        if (cgddDetails == null)
            throw new Exception("此条码找不到对应采购订单明细!");
        if (inventoryDetails == null)
            throw new Exception("此条码找不到对应收货单明细!");
        //if (string.IsNullOrEmpty(inventoryDetails.CheckRes) || inventoryDetails.CheckRes != "Y:合格")
        //{
        //    throw new Exception("该条码对应的收料单检验不合格或未检验!");
        //}
        //获取到货检验明细
        var sqlParams = new List<SugarParameter> { new("@dhmxGuid", itemBarcodeDetails.AboutGuid) };
        var sql1 = @"SELECT *FROM v_dhmx WHERE dhmxGuid = @dhmxGuid ";
        var dhjymx = Db.Ado.SqlQuery<vDhmx>(sql1, sqlParams).First();
        //判定检验能否入库
        if (dhjymx.CanStore!= 1)
        {
            throw new Exception($"该条码对应的收料单检验结果:【{dhjymx.InspectionResult}】,判定结果:【{dhjymx.JudgmentResult}】,处理意见:【{dhjymx.HandlingSuggestion}】,无法入库");
        }
        var depotCode = Db.Queryable<MesDepotSections>()
            .Where(it => it.DepotSectionCode == sectionCode)
@@ -82,10 +90,10 @@
        MesDepots mesDepost = null;
        var checkGuid = UtilityHelper.CheckGuid(depotCode);
        if (checkGuid && depotCode2 != null)
        if (checkGuid && depotCode != null)
        {
            mesDepost = Db.Queryable<MesDepots>()
                .Where(s => s.DepotId.ToString() == depotCode2).First();
                .Where(s => s.DepotId.ToString() == depotCode).First();
            // if (depotCode != mesDepost.Guid)
            //     throw new Exception("扫描库位与采购入库库位不一致!");
@@ -95,6 +103,33 @@
            throw new Exception("库位编码 " + sectionCode + " 不存在,请确认!");
        }
        // ========== 新增:验证当前库位与物料默认库位是否一致 ==========
        // 获取物料信息
        var mesItems = Db.Queryable<MesItems>()
            .Where(s => s.Id == itemBarcodeDetails.ItemId)
            .First();
        if (mesItems == null)
            throw new Exception("找不到对应的物料信息!");
        // 检查物料是否有默认库位设置
        if (!string.IsNullOrEmpty(mesItems.DepotCode))
        {
            // 获取物料默认库位对应的仓库信息
            var defaultDepot = Db.Queryable<MesDepots>()
                .Where(d => d.DepotCode == mesItems.DepotCode)
                .First();
            if (mesItems.DepotCode != null && mesItems.DepotCode != "0")
            {
                // 比较当前扫描的库位所属仓库编码与物料默认仓库编码是否一致
                if (mesDepost.DepotId?.ToString() != mesItems.DepotCode)
                {
                    throw new Exception($"当前库位所属仓库[{mesDepost.DepotId}]与物料默认仓库[{mesItems.DepotCode}]不一致,请扫描正确的库位!");
                }
            }
        }
        //num = Db.Queryable<MesInvItemInCDetails>()
        //    .Where(it => it.ItemBarcode == itemBarcode)
@@ -240,9 +275,7 @@
                    CreateDate = DateTime.Now,
                    LastupdateBy = user,
                    LastupdateDate = DateTime.Now,
                    UrgentFlag = itemBarcodeDetails.UrgentFlag.Value
                        ? "1"
                        : "0",
                    UrgentFlag = itemBarcodeDetails.UrgentFlag.GetValueOrDefault() ? "1" : "0",
                    CbillNo = itemBarcodeDetails.BillNo,
                    Fstatus = 0,
                    Status = 0,
@@ -293,7 +326,7 @@
                            .Where(it =>
                                it.ItemInId == cId &&
                                    it.ItemId == detail.ItemId &&
                                    it.DepotId == depotCode2 &&
                                    it.DepotId == mesDepost.DepotId.ToString() &&
                                    it.EbelnK3id == detail.EbelnK3id &&
                                    it.LineK3id == detail.LineK3id)
                            .Count();
@@ -322,7 +355,7 @@
                                Remark = itemBarcodeDetails.Memo,
                                EbelnK3id = detail.EbelnK3id,
                                LineK3id = detail.LineK3id,
                                DepotId = depotCode2,
                                DepotId = mesDepost.DepotId.ToString(),
                                itemDabid = itemBarcodeDetails.AboutGuid.ToString()
                            }).IgnoreColumns(true).ExecuteCommand();
                        else
@@ -332,7 +365,7 @@
                                .Where(it =>
                                    it.ItemInId == cId &&
                                    it.ItemId == detail.ItemId &&
                                    it.DepotId == depotCode2 &&
                                    it.DepotId == mesDepost.DepotId.ToString() &&
                                    it.EbelnK3id == detail.EbelnK3id &&
                                    it.LineK3id == detail.LineK3id)
                                .IgnoreColumns(true)
@@ -390,7 +423,7 @@
                            .Where(it =>
                                it.ItemInId == cId &&
                                    it.ItemId == detail.ItemId &&
                                    it.DepotId == depotCode2 &&
                                    it.DepotId == mesDepost.DepotId.ToString() &&
                                    it.EbelnK3id == detail.EbelnK3id &&
                                    it.LineK3id == detail.LineK3id)
                            .Count();
@@ -418,7 +451,7 @@
                                EbelnK3id = detail.EbelnK3id,
                                LineK3id = detail.LineK3id,
                                ItemId = detail.ItemId,
                                DepotId = depotCode2
                                DepotId = mesDepost.DepotId.ToString()
                            }).IgnoreColumns(true).ExecuteCommand();
                        else
                            db.Updateable<MesInvItemInCItems>()
@@ -427,7 +460,7 @@
                                .Where(it =>
                                    it.ItemInId == cId &&
                                    it.ItemId == detail.ItemId &&
                                    it.DepotId == depotCode2 &&
                                    it.DepotId == mesDepost.DepotId.ToString() &&
                                    it.EbelnK3id == detail.EbelnK3id &&
                                    it.LineK3id == detail.LineK3id)
                                .IgnoreColumns(true)
@@ -516,7 +549,7 @@
                    .Where(it =>
                    it.ItemInId == cId &&
                                    it.ItemId == detailone.ItemId &&
                                    it.DepotId == depotCode2 &&
                                    it.DepotId == mesDepost.DepotId.ToString() &&
                                    it.itemDabid == itemBarcodeDetails.AboutGuid.ToString())
                    .Count();
@@ -544,7 +577,7 @@
                        EbelnK3id = itemBarcodeDetails.EbelnK3id,
                        LineK3id = itemBarcodeDetails.LineK3id,
                        ItemId = itemBarcodeDetails.ItemId,
                        DepotId = depotCode2,
                        DepotId = mesDepost.DepotId.ToString(),
                        itemDabid = itemBarcodeDetails.AboutGuid.ToString()
                    }).IgnoreColumns(true).ExecuteCommand();
                else
@@ -557,7 +590,7 @@
                        .Where(it =>
                                    it.ItemInId == cId &&
                                    it.ItemId == detailone.ItemId &&
                                    it.DepotId == depotCode2 &&
                                    it.DepotId == mesDepost.DepotId.ToString() &&
                                    it.itemDabid == itemBarcodeDetails.AboutGuid.ToString())
                        //.IgnoreColumns(true) // 保留 IgnoreColumns
                        .ExecuteCommand();
@@ -601,7 +634,7 @@
                    CheckRes = inventoryDetails.CheckRes,
                    CheckStates = inventoryDetails.CheckStates,
                    ReceiveOrgId = inventory.ReceiveOrgId,
                    DepotId = Convert.ToInt64(depotCode2)
                    DepotId = Convert.ToInt64(mesDepost.DepotId.ToString())
                }).IgnoreColumns(true).ExecuteCommand();
                // 插入 mes_inv_business2 表
@@ -662,7 +695,7 @@
                LineK3id = itemBarcodeDetails.LineK3id,
                ItemId = itemBarcodeDetails.ItemId,
                BillNo = itemBarcodeDetails.BillNo,
                DepotId = Convert.ToInt32(depotCode2),
                DepotId = Convert.ToInt32(mesDepost.DepotId),
                OwnerId = cgddDetails.DemandOrg,
                OwnerType = owner_type,
                StockOrgId = mesDepost.FSubsidiary,
@@ -784,7 +817,8 @@
                        FQty = a.Quantity, // 申请数量
                        FMaterialId = b.ItemId,
                        Id = a.Guid.ToString(),
                        kw = a.DepotSectionCode
                        kw = a.DepotSectionCode,
                        barcode = a.ItemBarcode
                    })
                    .ToList();
@@ -855,6 +889,11 @@
            if (mesInvItemInCDetails == null)
                throw new Exception("物料入库条码明细不存在"); // 抛出异常以供前台处理
            // 创建 插入日志
            var logService = new LogService();
            var LogMsg = "【PDA】采购入库。条码【" + entity.barcode + "】 入库单号【" + cBillNo + "】";
            logService.CreateLog(db, entity.userName, inventory.Guid.ToString(), "MES_INV_ITEM_ARN", LogMsg, inventory.BillNo);
            return 1;
        });