啊鑫
8 天以前 0aa54059b26e6641196e9953490dd18616e916e3
service/Warehouse/MesItemQtrkManager.cs
@@ -1,10 +1,10 @@
using NewPdaSqlServer.DB;
using System.Text.RegularExpressions;
using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
using NewPdaSqlServer.entity.Base;
using NewPdaSqlServer.util;
using SqlSugar;
using System.Text.RegularExpressions;
namespace NewPdaSqlServer.service.Warehouse;
@@ -20,17 +20,18 @@
        // 获取未完成的退料单号列表
        var parameters = new[]
        {
        new SugarParameter("@pi_orgId", orgId),
        new SugarParameter("@inP1", null),
        new SugarParameter("@inP2", null),
        new SugarParameter("@inP3", null),
        new SugarParameter("@inP4", null)
            new SugarParameter("@pi_orgId", orgId),
            new SugarParameter("@inP1", null),
            new SugarParameter("@inP2", null),
            new SugarParameter("@inP3", null),
            new SugarParameter("@inP4", null)
        };
        try
        {
            // 返回单号字符串列表
            var blDetails = Db.Ado.SqlQuery<string>(
                "EXEC prc_pda_qtrk_list @pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters);
                "EXEC prc_pda_qtrk_list @pi_orgId,@inP1,@inP2,@inP3,@inP4",
                parameters);
            return blDetails;
        }
        catch (Exception ex)
@@ -47,24 +48,24 @@
            throw new Exception("组织不存在!");
        var parameters = new[]
{
        new SugarParameter("@billNo",query.billNo),
        new SugarParameter("@pi_orgId", orgId),
        new SugarParameter("@inP1", null),
        new SugarParameter("@inP2", null),
        new SugarParameter("@inP3", null),
        new SugarParameter("@inP4", null)
        {
            new SugarParameter("@billNo", query.billNo),
            new SugarParameter("@pi_orgId", orgId),
            new SugarParameter("@inP1", null),
            new SugarParameter("@inP2", null),
            new SugarParameter("@inP3", null),
            new SugarParameter("@inP4", null)
        };
        try
        {
            List<dynamic>? blDetails = Db.Ado.SqlQuery<dynamic>(
                "EXEC prc_pda_qtrk_detailList @billNo,@pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters);
            var items = blDetails.Where(x => x.DSQty > 0).ToList();    // 待扫物料
            var ysitems = blDetails.Where(x => x.SQty > 0).ToList();   // 已扫物料
            var blDetails = Db.Ado.SqlQuery<dynamic>(
                "EXEC prc_pda_qtrk_detailList @billNo,@pi_orgId,@inP1,@inP2,@inP3,@inP4",
                parameters);
            var items = blDetails.Where(x => x.DSQty > 0).ToList(); // 待扫物料
            var ysitems = blDetails.Where(x => x.SQty > 0).ToList(); // 已扫物料
            return new
            {
                items = items,
                ysitems = ysitems
                items, ysitems
            };
        }
        catch (Exception ex)
@@ -76,13 +77,14 @@
    public dynamic ScanInDepotsQT(WarehouseQuery query)
    {
      var sectionCode = query.sectionCode;
        var sectionCode = query.sectionCode;
        var billNo = query.billNo;
        // 1. 验证库位条码是否为空
        if (string.IsNullOrEmpty(sectionCode)) throw new Exception("请扫库位条码!");
        var sqlParams = new List<SugarParameter> { new("@sectionCode", sectionCode) };
        var sqlParams = new List<SugarParameter>
            { new("@sectionCode", sectionCode) };
        var sql2 = @"        SELECT TOP 1  b.depot_code,
                      b.depot_id,
@@ -95,7 +97,7 @@
        var depotInfo = Db.Ado.SqlQuery<dynamic>(sql2, sqlParams).First();
        if (depotInfo is  null)
        if (depotInfo is null)
            throw new Exception($"库位编码 {sectionCode} 不存在,请确认!");
        // 5. 返回成功信息
@@ -118,9 +120,8 @@
            throw new Exception("请扫库位条码!");
        // 2. 查询库位对应的仓库编码和仓库ID
        var depotInfo = Db.Queryable<MesDepotSections, MesDepots>(
                (a, b) =>
                    new JoinQueryInfos(JoinType.Inner, a.DepotGuid == b.Guid))
        var depotInfo = Db.Queryable<MesDepotSections, MesDepots>((a, b) =>
                new JoinQueryInfos(JoinType.Inner, a.DepotGuid == b.Guid))
            .Where((a, b) => a.DepotSectionCode == p_section_code)
            .Select((a, b) => new { b.DepotCode, b.DepotId })
            .First();
@@ -131,7 +132,8 @@
        var c_depot_code = depotInfo.DepotCode;
        var c_depot_id = depotInfo.DepotId;
        var sqlParams = new List<SugarParameter> { new("@barcode", p_item_barcode), new("@billNo", p_bill_no) };
        var sqlParams = new List<SugarParameter>
            { new("@barcode", p_item_barcode), new("@billNo", p_bill_no) };
//        var sql1 = @"   SELECT TOP 1 A.rkCkId
//FROM MES_QA_ITEMS_DETECT_01 A
@@ -143,13 +145,8 @@
//        var appDepotInfo = Db.Ado.SqlQuery<dynamic>(sql1, sqlParams).First();
        var mesDepost = Db.Queryable<MesDepots>()
                .Where(s => s.DepotId == c_depot_id).First();
            .Where(s => s.DepotId == c_depot_id).First();
        // 3. 验证条码是否已入库
@@ -181,13 +178,15 @@
        if (qtrk == null) throw new Exception("其他入库申请单不存在!");
        if(p_bill_no != barcode.BillNo)
        if (p_bill_no != barcode.BillNo)
            throw new Exception($"该条码对应的申请单【{barcode.BillNo}】与当前申请单号不匹配!");
        if (qtrk.Qt008 != c_depot_id.ToString())
            throw new Exception($"该 {p_section_code} 对应的仓库 与 检验判定的入库仓库不一致,请确认!");
            throw new Exception(
                $"该 {p_section_code} 对应的仓库 与 检验判定的入库仓库不一致,请确认!");
        var sql = @"SELECT c.item_no ItemNo,c.item_name ItemName,c.item_model ItemModel,
        var sql =
            @"SELECT c.item_no ItemNo,c.item_name ItemName,c.item_model ItemModel,
                    ISNULL(A.qd007,0) FQty,ISNULL(A.qd008,0) SQty,ISNULL(A.qd007,0) - ISNULL(A.qd008,0) DSQty
                    FROM MES_ITEM_QTRR_DETAIL A
                    LEFT JOIN MES_ITEM_QTRK B ON A.qtrkGuid = B.guid
@@ -195,7 +194,8 @@
                    WHERE B.qtck = @billNo AND QT015 = 1 AND QT028 = 1 AND QT032 = 1 AND QT014 = 0 ";
        //AND QT014 = 0
        var sqlParams1 = new List<SugarParameter> {
        var sqlParams1 = new List<SugarParameter>
        {
            new("@billNo", p_bill_no)
        };
@@ -224,20 +224,15 @@
        var details = new List<MesItemQtrrDetail>();
        string pattern = @"\(([^)]+)\)";
        Match match = Regex.Match(qtrk.Qt023, pattern);
        var pattern = @"\(([^)]+)\)";
        var match = Regex.Match(qtrk.Qt023, pattern);
        var owner_type = "";
        // 8.获取货主类型
        if (match.Success)
        {
            owner_type = match.Groups[1].Value;
        }
        else
        {
            throw new Exception("其他入库申请单货主类型有误,请核对!");
        }
        // 10. 执行入库事务
@@ -247,14 +242,15 @@
            // 查询是否存在未入库的入库单
            var existingInv = db.Queryable<MesInvItemIns>()
                .Where(x => x.Status == 0
                            && x.InsDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")
                            && x.InsDate.Value.ToString("yyyy-MM-dd") ==
                            DateTime.Now.ToString("yyyy-MM-dd")
                            && x.TransctionNo == transactionNo.ToString()
                            && x.TaskNo == p_bill_no
                            //&& x.CbillNo == p_bill_no
                            && x.BillTypeId == billTypeId
                            && x.DepotsId == Convert.ToInt64(c_depot_id))
                            // && x.DepotsCode == c_depot_code)
                            //&& x.SuppNo == barcode.SuppNo)
                // && x.DepotsCode == c_depot_code)
                //&& x.SuppNo == barcode.SuppNo)
                .First();
            var newId = Guid.Empty;
@@ -286,10 +282,9 @@
                    Status = 0,
                    Reason = qtrk.Qt010,
                    TaskNo = p_bill_no,
                    DepotsId = Convert.ToInt64(c_depot_id) ,
                    DepotsId = Convert.ToInt64(c_depot_id),
                    InType = "其他入库",
                    ReceiveOrgId = qtrk.Qt022
                }).IgnoreColumns(true).ExecuteCommand();
            }
            else
@@ -303,7 +298,7 @@
                .Where(x => x.ItemInId == newId
                            && x.ItemId == barcode.ItemId
                            && x.DepotId == c_depot_id.ToString()
                             )
                )
                //&& x.DepotCode =
                .First();
@@ -334,16 +329,16 @@
                    LineK3id = barcode.LineK3id,
                    ItemId = barcode.ItemId,
                    DepotId = c_depot_id.ToString(),
                    itemDabid = barcode.AboutGuid.ToString(),
                    itemDabid = barcode.AboutGuid.ToString()
                }).IgnoreColumns(true).ExecuteCommand();
            else
                // 存在则更新数量
                res += db.Updateable<MesInvItemInCItems>()
                    .SetColumns(
                        x => x.Quantity == x.Quantity + barcode.Quantity)
                    .SetColumns(x =>
                        x.Quantity == x.Quantity + barcode.Quantity)
                    .Where(x => x.ItemInId == newId
                            && x.ItemId == barcode.ItemId
                            && x.DepotId == c_depot_id.ToString())
                                && x.ItemId == barcode.ItemId
                                && x.DepotId == c_depot_id.ToString())
                    .ExecuteCommand();
@@ -469,7 +464,7 @@
            res += db.Updateable<MesItemQtrrDetail>()
                .SetColumns(x => x.Qd008 == (x.Qd008 ?? 0) + barcode.Quantity)
                .Where(x => x.QtrkGuid == qtrk.Guid &&
                x.ItemId == barcode.ItemId.ToString())
                            x.ItemId == barcode.ItemId.ToString())
                .ExecuteCommand();
            // 检查是否完全入库并更新状态
@@ -483,10 +478,11 @@
                    .Where(x => x.Guid == detail1.Guid)
                    .ExecuteCommand();
            details = Db.Queryable<MesItemQtrk, MesItemQtrrDetail, MesItems>(
                    (a, b, c) => new JoinQueryInfos(
                        JoinType.Left, a.Guid == b.QtrkGuid,
                        JoinType.Left, c.Id.ToString() == b.ItemId))
            details = Db
                .Queryable<MesItemQtrk, MesItemQtrrDetail,
                    MesItems>((a, b, c) => new JoinQueryInfos(
                    JoinType.Left, a.Guid == b.QtrkGuid,
                    JoinType.Left, c.Id.ToString() == b.ItemId))
                .Where((a, b, c) =>
                    a.Qtck == p_bill_no &&
                    (b.Qd007 ?? 0) - (b.Qd008 ?? 0) > 0)
@@ -509,8 +505,10 @@
            // 创建 插入日志
            var logService = new LogService();
            var LogMsg = "【PDA】其他入库。条码【" + query.barcode + "】数量【" + barcode.Quantity.ToString() + "】 入库单号【" + billNo + "】";
            logService.CreateLog(db, query.userName, qtrk.Guid.ToString(), "MES_ITEM_QTRK", LogMsg, qtrk.Qtck);
            var LogMsg = "【PDA】其他入库。条码【" + query.barcode + "】数量【" +
                         barcode.Quantity + "】 入库单号【" + billNo + "】";
            logService.CreateLog(db, query.userName, qtrk.Guid.ToString(),
                "MES_ITEM_QTRK", LogMsg, qtrk.Qtck);
            if (res < 5) throw new Exception("插入或更新失败");