南骏 池
2025-02-15 e33ee3adc98f5411395682cbfc9b1d367cdae7ee
1.生产报工优化
2.采购入库优化
已修改5个文件
197 ■■■■ 文件已修改
NewPdaSqlServer.sln 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
entity/MesWorkProd.cs 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
entity/MesWorkProdCDetails.cs 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/Warehouse/MesInvItemInCDetailsManager.cs 148 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/Wom/MesWorkProdManager.cs 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
NewPdaSqlServer.sln
@@ -3,7 +3,7 @@
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewPdaSqlServer", "NewPdaSqlServer.csproj", "{927F4816-FDC4-45F2-B329-3E2DB246946C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewPdaSqlServer", "NewPdaSqlServer.csproj", "{927F4816-FDC4-45F2-B329-3E2DB246946C}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
entity/MesWorkProd.cs
@@ -115,4 +115,15 @@
    /// </summary>
    [SugarColumn(ColumnName = "box_qty")]
    public decimal? BoxQty { get; set; }
    /// <summary>
    ///     报工人员
    /// </summary>
    [SugarColumn(ColumnName = "report_by")]
    public string? ReportBy { get; set; }
    /// <summary>
    ///     报工时间
    /// </summary>
    [SugarColumn(ColumnName = "report_date")]
    public DateTime? ReportDate { get; set; }
}
entity/MesWorkProdCDetails.cs
@@ -102,5 +102,11 @@
    ///     报工员工
    /// </summary>
    [SugarColumn(ColumnName = "bg_yg")]
    public decimal? BgYg { get; set; }
    public string? BgYg { get; set; }
    /// <summary>
    ///     报工员工
    /// </summary>
    [SugarColumn(ColumnName = "mes_work_prod_id")]
    public Guid? MesWorkProdId { get; set; }
}
service/Warehouse/MesInvItemInCDetailsManager.cs
@@ -1,4 +1,5 @@
using NewPdaSqlServer.DB;
using Masuit.Tools.Models;
using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
using NewPdaSqlServer.util;
@@ -51,6 +52,10 @@
        var inventoryDetails = Db.Queryable<MesInvItemArnDetail>()
            .Where(it => it.Guid == itemBarcodeDetails.AboutGuid)
            .First();
        var cgddDetails = Db.Queryable<MesRohInData>()
            .Where(it => it.EbelnK3id == inventoryDetails.LineK3id)
            .First();
        if (inventoryDetails == null)
@@ -121,6 +126,41 @@
                throw new Exception("入库失败,到货单据有问题!");
        }
        var owner_type = "";
        if (Db.Queryable<SysOrganization>().Any(x => x.Fid == cgddDetails.DemandOrg))
        {
            owner_type = "BD_OwnerOrg";
        }
        else
        {
            // 第二层判断:检查 MES_CUSTOMER
            if (Db.Queryable<MesCustomer>().Any(x => x.Id == Convert.ToInt32(cgddDetails.DemandOrg)))
            {
                owner_type = "BD_Customer";
            }
            else
            {
                // 第三层判断:检查 MES_SUPPLIER
                if (Db.Queryable<MesSupplier>().Any(x => x.Id == Convert.ToInt32(cgddDetails.DemandOrg)))
                {
                    owner_type = "BD_Supplier";
                }
                else
                {
                    // 第四层判断:再次检查 SYS_ORGANIZATION
                    if (Db.Queryable<SysOrganization>().Any(x => x.Fid == cgddDetails.ReceivingOrg))
                    {
                        owner_type = "BD_OwnerOrg";
                    }
                    else
                    {
                        throw new Exception("入库失败,到货单据对应的需求组织有问题!");
                    }
                }
            }
        }
        var result = new PurchaseInventory();
        UseTransaction(db =>
@@ -129,7 +169,7 @@
                .Where(it => it.InsDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")
                             && it.Status == 0
                             && it.TransctionNo == transactionNo
                             && it.BillNo == itemBarcodeDetails.BillNo
                             && it.CbillNo == itemBarcodeDetails.BillNo
                             && it.DepotsCode == mesDepost.DepotCode)
                .Select(it => new
                {
@@ -150,7 +190,7 @@
            else
            {
                cId = Guid.NewGuid();
                cBillNo = BillNo.GetBillNo("IN(入库单)");
                cBillNo = BillNo.GetBillNo("CGRK(采购入库)");
                var suppNo = db.Queryable<MesSupplier>()
                    .Where(s => s.Id.ToString() == inventory.SuppId).First();
@@ -176,7 +216,9 @@
                    CbillNo = itemBarcodeDetails.BillNo,
                    Fstatus = 0,
                    Status = 0,
                    ReceiveOrgId = inventory.ReceiveOrgId
                    ReceiveOrgId = inventory.ReceiveOrgId,
                    InType = "采购入库",
                    //WorkNo = itemBarcodeDetails.WorkNo
                }).IgnoreColumns(true).ExecuteCommand();
            }
@@ -217,11 +259,12 @@
                        // Check if already inserted
                        var count = db.Queryable<MesInvItemInCItems>()
                            .Where(t =>
                                t.ItemInId == cId &&
                                t.ItemId == detail.ItemId &&
                                t.WorkNo == detail.WorkNo &&
                                t.WorkLine == detail.WorkLine)
                            .Where(it =>
                                it.ItemInId == cId &&
                                    it.ItemId == detail.ItemId &&
                                    it.DepotId == depotCode2 &&
                                    it.EbelnK3id == detail.EbelnK3id &&
                                    it.LineK3id == detail.LineK3id)
                            .Count();
                        cSyQty -= remainingQty.Value;
@@ -247,7 +290,8 @@
                                SuppNo = itemBarcodeDetails.SuppNo,
                                Remark = itemBarcodeDetails.Memo,
                                EbelnK3id = detail.EbelnK3id,
                                LineK3id = detail.LineK3id
                                LineK3id = detail.LineK3id,
                                DepotId = depotCode2
                            }).IgnoreColumns(true).ExecuteCommand();
                        else
                            db.Updateable<MesInvItemInCItems>()
@@ -256,8 +300,9 @@
                                .Where(it =>
                                    it.ItemInId == cId &&
                                    it.ItemId == detail.ItemId &&
                                    it.WorkNo == detail.WorkNo &&
                                    it.WorkLine == detail.WorkLine)
                                    it.DepotId == depotCode2 &&
                                    it.EbelnK3id == detail.EbelnK3id &&
                                    it.LineK3id == detail.LineK3id)
                                .IgnoreColumns(true)
                                .ExecuteCommand();
@@ -293,7 +338,8 @@
                            EbelnK3id = detail.EbelnK3id,
                            LineK3id = detail.LineK3id,
                            ItemId = detail.ItemId,
                            ReceiveOrgId = inventory.ReceiveOrgId
                            ReceiveOrgId = inventory.ReceiveOrgId,
                            LotNo = cgddDetails.BatchNumber
                        }).IgnoreColumns(true).ExecuteCommand();
                    }
                    else
@@ -309,11 +355,12 @@
                            .ExecuteCommand();
                        var count = db.Queryable<MesInvItemInCItems>()
                            .Where(t =>
                                t.ItemInId == cId &&
                                t.ItemId == detail.ItemId &&
                                t.WorkNo == detail.WorkNo &&
                                t.WorkLine == detail.WorkLine)
                            .Where(it =>
                                it.ItemInId == cId &&
                                    it.ItemId == detail.ItemId &&
                                    it.DepotId == depotCode2 &&
                                    it.EbelnK3id == detail.EbelnK3id &&
                                    it.LineK3id == detail.LineK3id)
                            .Count();
                        if (count == 0)
@@ -338,7 +385,8 @@
                                Remark = itemBarcodeDetails.Memo,
                                EbelnK3id = detail.EbelnK3id,
                                LineK3id = detail.LineK3id,
                                ItemId = detail.ItemId
                                ItemId = detail.ItemId,
                                DepotId = depotCode2
                            }).IgnoreColumns(true).ExecuteCommand();
                        else
                            db.Updateable<MesInvItemInCItems>()
@@ -347,8 +395,9 @@
                                .Where(it =>
                                    it.ItemInId == cId &&
                                    it.ItemId == detail.ItemId &&
                                    it.WorkNo == detail.WorkNo &&
                                    it.WorkLine == detail.WorkLine)
                                    it.DepotId == depotCode2 &&
                                    it.EbelnK3id == detail.EbelnK3id &&
                                    it.LineK3id == detail.LineK3id)
                                .IgnoreColumns(true)
                                .ExecuteCommand();
@@ -384,7 +433,8 @@
                            EbelnK3id = detail.EbelnK3id,
                            LineK3id = detail.LineK3id,
                            ItemId = detail.ItemId,
                            ReceiveOrgId = inventory.ReceiveOrgId
                            ReceiveOrgId = inventory.ReceiveOrgId,
                            LotNo = cgddDetails.BatchNumber
                        }).IgnoreColumns(true).ExecuteCommand();
                        cSyQty = 0; // Remaining quantity fulfilled
@@ -399,7 +449,7 @@
                    BusinessType = 1,
                    ItemBarcode = itemBarcode,
                    ItemNo = itemBarcodeDetails.ItemNo,
                    LotNo = itemBarcodeDetails.LotNo,
                    LotNo = cgddDetails.BatchNumber,
                    EpFlag = true,
                    Quantity = itemBarcodeDetails.Quantity,
                    ToInvDepotsCode = mesDepost.DepotCode,
@@ -424,12 +474,19 @@
            }
            else
            {
                var detailone = db.Queryable<MesInvItemArnDetail>()
                    .Where(d =>
                        d.Guid == itemBarcodeDetails.AboutGuid)
                    .First();
                // 检查是否存在于 MES_INV_ITEM_IN_C_ITEMS 表
                var existingCount = db.Queryable<MesInvItemInCItems>()
                    .Where(t => t.ItemInId == cId &&
                                t.ItemId == itemBarcodeDetails.ItemId &&
                                t.WorkNo == itemBarcodeDetails.WorkNo &&
                                t.WorkLine == itemBarcodeDetails.WorkLine)
                    .Where(it =>
                    it.ItemInId == cId &&
                                    it.ItemId == detailone.ItemId &&
                                    it.DepotId == depotCode2 &&
                                    it.EbelnK3id == detailone.EbelnK3id &&
                                    it.LineK3id == detailone.LineK3id)
                    .Count();
                if (existingCount == 0)
@@ -455,19 +512,23 @@
                        Remark = itemBarcodeDetails.Memo,
                        EbelnK3id = itemBarcodeDetails.EbelnK3id,
                        LineK3id = itemBarcodeDetails.LineK3id,
                        ItemId = itemBarcodeDetails.ItemId
                        ItemId = itemBarcodeDetails.ItemId,
                        DepotId = depotCode2
                    }).IgnoreColumns(true).ExecuteCommand();
                else
                    // 存在时更新数量
                    db.Updateable<MesInvItemInCItems>()
                        .SetColumns(it =>
                            it.Quantity ==
                            it.Quantity + itemBarcodeDetails.Quantity)
                        .Where(it => it.ItemInId == cId &&
                                     it.ItemId == itemBarcodeDetails.ItemId &&
                                     it.WorkNo == itemBarcodeDetails.WorkNo &&
                                     it.WorkLine == itemBarcodeDetails.WorkLine)
                        .IgnoreColumns(true)
                        .SetColumns(it => new MesInvItemInCItems
                        {
                            Quantity = SqlFunc.IsNull(it.Quantity, 0) + itemBarcodeDetails.Quantity // 确保 Quantity 不为 null
                        })
                        .Where(it =>
                                it.ItemInId == cId &&
                                it.ItemId == detailone.ItemId &&
                                it.DepotId == depotCode2 &&
                                it.EbelnK3id == detailone.EbelnK3id &&
                                it.LineK3id == detailone.LineK3id)
                        //.IgnoreColumns(true) // 保留 IgnoreColumns
                        .ExecuteCommand();
                // 插入 mes_inv_item_in_c_details 表
@@ -481,7 +542,7 @@
                    EpFlag = true,
                    WorkType = 1,
                    ItemNo = itemBarcodeDetails.ItemNo,
                    LotNo = itemBarcodeDetails.LotNo,
                    LotNo = cgddDetails.BatchNumber,
                    SuppId = itemBarcodeDetails.SuppId,
                    SuppNo = itemBarcodeDetails.SuppNo,
                    DepotCode = mesDepost.DepotCode,
@@ -508,7 +569,8 @@
                    CheckDate = inventoryDetails.CheckDate,
                    CheckRes = inventoryDetails.CheckRes,
                    CheckStates = inventoryDetails.CheckStates,
                    ReceiveOrgId = inventory.ReceiveOrgId
                    ReceiveOrgId = inventory.ReceiveOrgId,
                    DepotId = Convert.ToInt64(depotCode2)
                }).IgnoreColumns(true).ExecuteCommand();
                // 插入 mes_inv_business2 表
@@ -546,11 +608,13 @@
                // 插入 mes_inv_item_stocks 表
            }
            db.Insertable(new MesInvItemStocks
            {
                TaskNo = itemBarcodeDetails.TaskNo,
                ItemBarcode = itemBarcode,
                ItemNo = itemBarcodeDetails.ItemNo,
                ItemNo = cgddDetails.BatchNumber,
                LotNo = itemBarcodeDetails.LotNo,
                Quantity = itemBarcodeDetails.Quantity,
                DepotsCode = mesDepost.DepotCode,
@@ -567,7 +631,11 @@
                LineK3id = itemBarcodeDetails.LineK3id,
                ItemId = itemBarcodeDetails.ItemId,
                BillNo = itemBarcodeDetails.BillNo,
                DepotId = Convert.ToInt32(depotCode2)
                DepotId = Convert.ToInt32(depotCode2),
                OwnerId = cgddDetails.DemandOrg,
                OwnerType = owner_type,
                StockOrgId = mesDepost.FSubsidiary,
                IndepUserCode = user
            }).IgnoreColumns(true).ExecuteCommand();
            itemBarcodeDetails.Hbdy ??= 0;
service/Wom/MesWorkProdManager.cs
@@ -84,7 +84,7 @@
        var exists = Db.Queryable<MesWorkProd, MesWorkProdCDetails>(
                (a, b) =>
                    new JoinQueryInfos(JoinType.Inner,
                        a.BillNo == b.BillNo))
                        a.Id == b.MesWorkProdId))
            .Where((a, b) => b.ItemBarcode == request.ItemBarcode
                             && a.BillTypeId == billTypeId
                             && a.TransactionNo == transactionNo)
@@ -133,8 +133,8 @@
                db.Updateable<MesInvItemBarcodes>()
                    .SetColumns(x => new MesInvItemBarcodes
                    {
                        WorkFlg = true,
                        Quantity = reportQty
                        WorkFlg = true
                        //Quantity = reportQty
                    })
                    .Where(x => x.Guid == barcode.Guid)
                    .ExecuteCommand();
@@ -147,13 +147,15 @@
                                DateTime.Now.Date.ToString("yyyy-MM-dd")
                                && x.BillTypeId == billTypeId
                                && x.TransactionNo == transactionNo
                                && x.Status == 0)
                                && x.ReportBy == request.StaffNo)
                    .First();
                var id = Guid.Empty;
                var billNo = "";
                if (workProd == null)
                {
                    var id = Guid.NewGuid();
                    var billNo = BillNo.GetBillNo("BG(报工编号)");
                    id = Guid.NewGuid();
                    billNo = BillNo.GetBillNo("BG(报工编号)");
                    workProd = new MesWorkProd
                    {
@@ -168,11 +170,18 @@
                        LastupdateDate = DateTime.Now,
                        BillTypeId = billTypeId,
                        TransactionNo = transactionNo,
                        TaskNo = barcode.BillNo
                        TaskNo = barcode.BillNo,
                        ReportBy = request.StaffNo,
                        ReportDate = DateTime.Now
                    };
                    db.Insertable(workProd).IgnoreColumns(true)
                        .ExecuteCommand();
                }
                else
                {
                    id = workProd.Id;
                    billNo = workProd.BillNo;
                }
                // 12. 插入报工明细
@@ -180,7 +189,8 @@
                db.Insertable(new MesWorkProdCDetails
                {
                    Id = detailId,
                    BillNo = workProd.BillNo,
                    MesWorkProdId = id,
                    BillNo = billNo,
                    ItemBarcode = request.ItemBarcode,
                    Quantity = (int)reportQty,
                    Company = barcode.Company,
@@ -194,7 +204,7 @@
                    SilkPqty = barcode.SilkPqty,
                    SilkId = barcode.SilkId,
                    Silk = barcode.Silk,
                    BgYg = staff.Id
                    BgYg = request.StaffNo
                }).IgnoreColumns(true).ExecuteCommand();
                // 13. 更新工单已报工数量