南骏 池
2025-02-15 df1e1fca9bc95c58463a1f709e95261077a7f249
service/Warehouse/MesItemQtrkManager.cs
@@ -3,6 +3,7 @@
using NewPdaSqlServer.entity;
using NewPdaSqlServer.util;
using SqlSugar;
using System.Text.RegularExpressions;
namespace NewPdaSqlServer.service.Warehouse;
@@ -56,34 +57,34 @@
    public string ScanInDepotsQT(WarehouseQuery query)
    {
        var sectionCode = query.sectionCode;
      var sectionCode = query.sectionCode;
        var billNo = query.billNo;
        // 1. 验证库位条码是否为空
        if (string.IsNullOrEmpty(sectionCode)) throw new Exception("请扫库位条码!");
        // 2. 查询库位对应的仓库编码
        var depotCode = Db.Queryable<MesDepotSections, MesDepots>(
        var depotId = Db.Queryable<MesDepotSections, MesDepots>(
                (a, b) => new JoinQueryInfos(
                    JoinType.Inner, a.DepotGuid == b.Guid))
            .Where((a, b) => a.DepotSectionCode == sectionCode)
            .Select((a, b) => b.DepotCode)
            .Select((a, b) => b.DepotId)
            .First();
        if (depotCode == null)
        if (depotId == null)
            throw new Exception($"库位编码 {sectionCode} 不存在,请确认!");
        // 3. 查询申请单对应的仓库
        var qtrk = Db.Queryable<MesItemQtrk>()
            .Where(x => x.Qtck == billNo)
            .Select(x => x.Qt011)
            .Select(x => x.Qt008)
            .First();
        if (qtrk == null) throw new Exception($"库位编码 {sectionCode} 不存在,请确认!");
        // 4. 验证库位是否属于申请仓库
        if (depotCode != qtrk)
            throw new Exception($"扫码库位 {sectionCode} 不属于申请此仓库!");
        if (depotId != Convert.ToInt32(qtrk))
            throw new Exception($"扫码库位 {sectionCode} 不属于申请仓库!");
        // 5. 返回成功信息
        return $"仓库:{qtrk} 库位:{sectionCode}";
@@ -118,6 +119,13 @@
        var c_depot_code = depotInfo.DepotCode;
        var c_depot_id = depotInfo.DepotId;
        var mesDepost = Db.Queryable<MesDepots>()
                .Where(s => s.DepotId == c_depot_id).First();
        // 3. 验证条码是否已入库
        var existsInStock = Db.Queryable<MesInvItemInCDetails>()
            .Any(x => x.ItemBarcode == p_item_barcode);
@@ -147,6 +155,10 @@
        if (qtrk == null) throw new Exception("其他入库申请单不存在!");
        //  验证库位是否属于申请仓库
        if (c_depot_id != Convert.ToInt32(qtrk.Qt008))
            throw new Exception($"扫码库位 {p_section_code} 不属于申请仓库!");
        // 6. 查询申请单明细
        var detail = Db.Queryable<MesItemQtrrDetail>()
            .Where(x =>
@@ -163,7 +175,23 @@
        var details = new List<MesItemQtrrDetail>();
        // 8. 执行入库事务
        string pattern = @"\(([^)]+)\)";
        Match match = Regex.Match(qtrk.Qt023, pattern);
        var owner_type = "";
        // 8.获取货主类型
        if (match.Success)
        {
            owner_type = match.Groups[1].Value;
        }
        else
        {
            throw new Exception("其他入库申请单货主类型有误,请核对!");
        }
        // 10. 执行入库事务
        UseTransaction(db =>
        {
            var res = 0;
@@ -186,7 +214,7 @@
            if (existingInv == null)
            {
                newId = Guid.NewGuid();
                billNo = BillNo.GetBillNo("QTRK(其他入库单)");
                billNo = BillNo.GetBillNo("QTRK(其他入库)");
                barcode.UrgentFlag ??= false;
@@ -204,13 +232,14 @@
                    LastupdateBy = c_user,
                    LastupdateDate = DateTime.Now,
                    UrgentFlag = barcode.UrgentFlag.Value ? "1" : "0",
                    CbillNo = p_bill_no,
                    //CbillNo = p_bill_no,
                    Fstatus = 0,
                    Status = 0,
                    Reason = qtrk.Qt010,
                    TaskNo = p_bill_no,
                    DepotsId = Convert.ToInt64(c_depot_id) ,
                    InType = "其他入库"
                    InType = "其他入库",
                    ReceiveOrgId = qtrk.Qt022
                }).IgnoreColumns(true).ExecuteCommand();
            }
@@ -263,9 +292,8 @@
                    .SetColumns(
                        x => x.Quantity == x.Quantity + barcode.Quantity)
                    .Where(x => x.ItemInId == newId
                                && x.ItemId == barcode.ItemId
                                && x.WorkNo == barcode.WorkNo
                                && x.WorkLine == barcode.WorkLine)
                            && x.ItemId == barcode.ItemId
                            && x.DepotId == c_depot_id.ToString())
                    .ExecuteCommand();
@@ -370,7 +398,11 @@
                EbelnK3id = barcode.EbelnK3id,
                LineK3id = barcode.LineK3id,
                ItemId = barcode.ItemId,
                BillNo = barcode.BillNo
                BillNo = barcode.BillNo,
                OwnerId = qtrk.Qt024,
                OwnerType = owner_type,
                StockOrgId = qtrk.Qt022,
                IndepUserCode = c_user
                // SalesOrder = barcode.SalesOrder,
                // IsZy = barcode.IsZy,
                // Visable = 0,