南骏 池
2025-02-18 518ec4f634a949aae7602a38b1fefa40f69d2311
1.生产退料入库优化
已修改3个文件
185 ■■■■ 文件已修改
Controllers/Warehouse/MesItemTblController.cs 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
entity/MesItemTblDetail.cs 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/Warehouse/MesItemTblManager.cs 167 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Controllers/Warehouse/MesItemTblController.cs
@@ -201,6 +201,17 @@
        {
            dynamic resultInfos = new ExpandoObject();
            resultInfos.tbBillList = m.GetMesItemTblDetailByBillNo(query);
            if(resultInfos.tbBillList.Count < 1)
            {
                return new ResponseResult
                {
                    status = 1,
                    message = "该申请单号不存在或未审核!!!",
                    data = ""
                };
            }
            return new ResponseResult
            {
                status = 0,
entity/MesItemTblDetail.cs
@@ -95,6 +95,13 @@
    [SugarColumn(ColumnName = "tld012")]
    public int? Tld012 { get; set; }
    /// <summary>
    ///     是否补料完成
    ///     默认值: ((0))
    /// </summary>
    [SugarColumn(ColumnName = "tld013")]
    public string? Tld013 { get; set; }
    [SugarColumn(IsIgnore = true)] public string? BillNo { get; set; }
    [SugarColumn(IsIgnore = true)] public string? ItemNo { get; set; }
service/Warehouse/MesItemTblManager.cs
@@ -4,6 +4,7 @@
using NewPdaSqlServer.entity;
using NewPdaSqlServer.util;
using SqlSugar;
using System.Security.Cryptography;
namespace NewPdaSqlServer.service.Warehouse;
@@ -43,7 +44,7 @@
                    a.Id == b.Tlmid,
                    JoinType.Left,
                    b.Tld009 == c.Id)
            ).Where((a, b, c) => a.BillNo == query.billNo)
            ).Where((a, b, c) => a.BillNo == query.billNo && (a.Tbl013 ?? 0) == 1)
            .Select<MesItemTblDetail>((a, b, c) => new MesItemTblDetail
            {
                BillNo = a.BillNo,
@@ -162,18 +163,56 @@
            .Where(a => a.BillNo == c_mes_inv_item_barcodes.BillNo
                        && (a.Tbl013 ?? 0) == 1).First();
        // 获取退料单信息
        var tbWOMDAA = Db.Queryable<Womdaa>()
            .Where(a => a.Guid.ToString() == C_MES_ITEM_TBL.Tbl002).First();
        if (C_MES_ITEM_TBL == null) throw new Exception("申请单已撤回,无法扫码!");
        if (C_MES_ITEM_TBL.Tbl020 == 1) throw new Exception("扫码完成,申请单已完结!");
        // 获取退料单明细
        var C_MES_ITEM_TBL_DETAIL = Db.Queryable<MesItemTblDetail>()
            .Where(a => a.Tlmid == C_MES_ITEM_TBL.Id
                        && a.Tld010 == c_mes_inv_item_barcodes.WorkLine)
            .Where(a => a.Tlid == c_mes_inv_item_barcodes.AboutGuid)
            .First();
        if (C_MES_ITEM_TBL_DETAIL == null)
            throw new Exception("条码不属于该申请单明细,无法扫码!");
        var CABerpid = Db.Queryable<Womdab>().Where(womdab => womdab.Guid.ToString() == C_MES_ITEM_TBL_DETAIL.Tld013).Select(womdab => womdab.Erpid).First();
        var ownerId = Db.Queryable<Womcab>().Where(womcab => womcab.Erpid == CABerpid.Value).Select(womcab => womcab.OwnerId).First();
        if (ownerId == null) throw new Exception("用料清单货主信息不存在,无法扫码,请联系管理员!");
        var owner_type = "";
        if (Db.Queryable<SysOrganization>().Any(x => x.Fid == ownerId))
        {
            owner_type = "BD_OwnerOrg";
        }
        else
        {
            // 第二层判断:检查 MES_CUSTOMER
            if (Db.Queryable<MesCustomer>().Any(x => x.Id == Convert.ToInt32(ownerId)))
            {
                owner_type = "BD_Customer";
            }
            else
            {
                // 第三层判断:检查 MES_SUPPLIER
                if (Db.Queryable<MesSupplier>().Any(x => x.Id == Convert.ToInt32(ownerId)))
                {
                    owner_type = "BD_Supplier";
                }
                else
                {
                    throw new Exception("入库失败,用料清单货主信息存在问题,请联系管理员解决!");
                }
            }
        }
        var c_quantity = c_mes_inv_item_barcodes.Quantity;
@@ -188,7 +227,7 @@
                .Where(d =>
                    d.Status == 0 && d.TransctionNo ==
                                  p_transction_no.ToString()
                                  && d.CbillNo == c_mes_inv_item_barcodes.BillNo
                                  && d.TaskNo == c_mes_inv_item_barcodes.BillNo
                                  && d.DepotsId == c_depot_code
                                  && d.InsDate.Value.ToString("yyyyMMdd") ==
                                  DateTime.Now.ToString("yyyyMMdd")).First();
@@ -198,7 +237,7 @@
            // 如果入库单不存在则创建新的入库单
            if (mesInvItemIns == null)
            {
                c_bill_no = BillNo.GetBillNo("IN(入库单)");
                c_bill_no = BillNo.GetBillNo("SCTL(生产退料)");
                c_id = Guid.NewGuid();
@@ -207,19 +246,26 @@
                    Guid = c_id,
                    BillNo = c_bill_no,
                    BillTypeId = p_bill_type_id,
                    InsDate = DateTime.Now,
                    DepotsId = c_depot_code,
                    UserNoBack = c_user,
                    Reason = C_MES_ITEM_TBL.Tbl005,
                    Remark = C_MES_ITEM_TBL.Tbl006,
                    InsDate = DateTime.Now,
                    // DepotsCode = c_depot_code,
                    DepotsId = c_depot_code,
                    //InsDate = DateTime.Now,
                    DepotsCode = c_mes_depots.DepotCode,
                    TaskNo = c_mes_inv_item_barcodes.BillNo,
                    //DepotsId = c_depot_code,
                    TransctionNo = p_transction_no.ToString(),
                    CreateBy = c_user,
                    CreateDate = DateTime.Now,
                    LastupdateBy = c_user,
                    LastupdateDate = DateTime.Now,
                    CbillNo = C_MES_ITEM_TBL.BillNo,
                    RbillNo = C_MES_ITEM_TBL.Tbl002
                    CbillNo = tbWOMDAA.Daa001,
                    InType = "生产退料",
                    ReceiveOrgId = c_mes_depots.FSubsidiary,
                    Fstatus = 0,
                    Status = 0,
                    WorkNo = tbWOMDAA.Daa021
                }).IgnoreColumns(true).ExecuteCommand();
            }
            else
@@ -232,24 +278,72 @@
            var hbdy = c_mes_inv_item_barcodes.Hbdy ?? 0;
            if (hbdy == 1) throw new Exception("不支持合并打印的条码:" + p_item_barcode);
            // 插入入库单明细
            // 检查是否存在于 MES_INV_ITEM_IN_C_ITEMS 表
            var existingCount = db.Queryable<MesInvItemInCItems>()
            .Where(it =>
                it.ItemInId == c_id &&
                                it.ItemId == C_MES_ITEM_TBL_DETAIL.Tld009 &&
                                it.DepotId == c_depot_code.ToString())
                .Count();
            if (existingCount == 0)
                // 不存在时插入新记录
                db.Insertable(new MesInvItemInCItems
                {
                    ItemInId = c_id,
                    Quantity = c_mes_inv_item_barcodes.Quantity,
                    CreateBy = c_user,
                    CreateDate = DateTime.Now,
                    ItemNo = c_mes_inv_item_barcodes.ItemNo,
                    //DepotCode = mesDepost.DepotCode,
                    ItemSname = c_mes_inv_item_barcodes.ItemSname,
                    Unit = c_mes_inv_item_barcodes.Unit,
                    Ebeln = c_mes_inv_item_barcodes.WorkNo,
                    BillNo = c_bill_no,
                    WorkNo = c_mes_inv_item_barcodes.WorkNo,
                    EbelnLineNo = c_mes_inv_item_barcodes.WorkLine,
                    CbillNo = c_mes_inv_item_barcodes.BillNo,
                    WorkLine = c_mes_inv_item_barcodes.WorkLine,
                    SuppId = c_mes_inv_item_barcodes.SuppId,
                    SuppNo = c_mes_inv_item_barcodes.SuppNo,
                    Remark = c_mes_inv_item_barcodes.Memo,
                    EbelnK3id = c_mes_inv_item_barcodes.EbelnK3id,
                    LineK3id = c_mes_inv_item_barcodes.LineK3id,
                    ItemId = c_mes_inv_item_barcodes.ItemId,
                    DepotCode = c_mes_depots.DepotCode,
                    DepotId = c_depot_code.ToString()
                }).IgnoreColumns(true).ExecuteCommand();
            else
                // 存在时更新数量
                db.Updateable<MesInvItemInCItems>()
                    .SetColumns(it => new MesInvItemInCItems
                    {
                        Quantity = SqlFunc.IsNull(it.Quantity, 0) + c_mes_inv_item_barcodes.Quantity // 确保 Quantity 不为 null
                    })
                .Where(it =>
                       it.ItemInId == c_id &&
                                it.ItemId == C_MES_ITEM_TBL_DETAIL.Tld009 &&
                                it.DepotId == c_depot_code.ToString())
                    //.IgnoreColumns(true) // 保留 IgnoreColumns
                    .ExecuteCommand();
            // 插入 mes_inv_item_in_c_details 表
            totalResult += db.Insertable(new MesInvItemInCDetails
            {
                Guid = Guid.NewGuid(),
                ItemInId = c_id,
                BillNo = c_bill_no,
                ItemBarcode = p_item_barcode,
                Quantity = c_quantity,
                Quantity = c_mes_inv_item_barcodes.Quantity,
                BarcodeFlag = true,
                EpFlag = true,
                WorkType = 1,
                ItemId = c_mes_inv_item_barcodes.ItemId,
                ItemNo = c_mes_inv_item_barcodes.ItemNo,
                LotNo = c_mes_inv_item_barcodes.LotNo,
                //LotNo = cgddDetails.BatchNumber,--批号,退料不设置批号
                SuppId = c_mes_inv_item_barcodes.SuppId,
                SuppNo = c_mes_inv_item_barcodes.SuppNo,
                DepotId = c_mes_depots.DepotId,
                DepotCode = c_mes_depots.DepotCode,
                //DepotCode = mesDepost.DepotCode,
                DepotSectionCode = p_section_code,
                ItemSname = c_mes_inv_item_barcodes.ItemSname,
                Unit = c_mes_inv_item_barcodes.Unit,
@@ -266,7 +360,16 @@
                UrgentFlag = c_mes_inv_item_barcodes.UrgentFlag,
                BoardStyle = c_mes_inv_item_barcodes.BoardStyle,
                TaskNo = c_mes_inv_item_barcodes.TaskNo,
                RbillNo = C_MES_ITEM_TBL.Tbl002
                EbelnK3id = c_mes_inv_item_barcodes.EbelnK3id,
                LineK3id = c_mes_inv_item_barcodes.LineK3id,
                ItemId = c_mes_inv_item_barcodes.ItemId,
                Ischeck = true,
                //CheckDate = C_MES_ITEM_TBL_DETAIL.CheckDate,
                //CheckRes = C_MES_ITEM_TBL_DETAIL.CheckRes,
                //CheckStates = C_MES_ITEM_TBL_DETAIL.CheckStates,--检验信息
                ReceiveOrgId = c_mes_depots.FSubsidiary,
                DepotCode = c_mes_depots.DepotCode,
                DepotId = Convert.ToInt64(c_depot_code)
            }).IgnoreColumns(true).ExecuteCommand();
            // 插入业务记录
@@ -308,9 +411,9 @@
                ItemNo = c_mes_inv_item_barcodes.ItemNo,
                LotNo = c_mes_inv_item_barcodes.LotNo,
                Quantity = c_mes_inv_item_barcodes.Quantity,
                EpFlag = c_mes_inv_item_barcodes.EpFlag.Value
                    ? (byte)1
                    : (byte)0,
                //EpFlag = c_mes_inv_item_barcodes.EpFlag.Value
                //    ? (byte)1
                //    : (byte)0,
                DepotId = c_mes_depots.DepotId,
                DepotsCode = c_mes_depots.DepotCode,
                DepotSectionsCode = p_section_code,
@@ -320,7 +423,13 @@
                WorkNo = c_mes_inv_item_barcodes.WorkNo,
                WorkLine = c_mes_inv_item_barcodes.WorkLine,
                SuppNo = c_mes_inv_item_barcodes.SuppNo,
                ItemId = c_mes_inv_item_barcodes.ItemId
                ItemId = c_mes_inv_item_barcodes.ItemId,
                BillNo = c_mes_inv_item_barcodes.BillNo,
                //DepotId = Convert.ToInt32(c_depot_code),
                OwnerId = ownerId,
                OwnerType = owner_type,
                StockOrgId = c_mes_depots.FSubsidiary,
                IndepUserCode = c_user
            }).IgnoreColumns(true).ExecuteCommand();
            // 根据退料类型(良品退料、来料不良退料、作业不良退料)更新相关数据
@@ -376,10 +485,8 @@
                        Tld006 = (it.Tld006 ?? 0) +
                                 (int)c_mes_inv_item_barcodes.Quantity // 增加已退数量
                    })
                    .Where(it => it.Tlmid == C_MES_ITEM_TBL.Id
                                 && it.Tld009 == c_mes_inv_item_barcodes.ItemId
                                 && it.Tld010 ==
                                 c_mes_inv_item_barcodes.WorkLine)
                    .Where(it => it.Tlmid == C_MES_ITEM_TBL.Id &&
                                 it.Tlid == c_mes_inv_item_barcodes.AboutGuid)
                    .ExecuteCommand();
            }
            // 作业不良退料 - 更新工单表和退料单明细表
@@ -410,10 +517,8 @@
                        Tld006 = (it.Tld006 ?? 0) +
                                 (int)c_mes_inv_item_barcodes.Quantity // 增加已退数量
                    })
                    .Where(it => it.Tlmid == C_MES_ITEM_TBL.Id
                                 && it.Tld009 == c_mes_inv_item_barcodes.ItemId
                                 && it.Tld010 ==
                                 c_mes_inv_item_barcodes.WorkLine)
                    .Where(it => it.Tlmid == C_MES_ITEM_TBL.Id &&
                                 it.Tlid == c_mes_inv_item_barcodes.AboutGuid)
                    .ExecuteCommand();
            }
@@ -423,7 +528,7 @@
                c_mes_inv_item_barcodes.Quantity)
                totalResult += Db.Updateable<MesItemTblDetail>()
                    .SetColumns(it => new MesItemTblDetail
                        { Tld008 = 1 }) // 设置完成标志
                    { Tld008 = 1 }) // 设置完成标志
                    .Where(it => it.Tlid == C_MES_ITEM_TBL_DETAIL.Tlid)
                    .ExecuteCommand();