啊鑫
8 天以前 0aa54059b26e6641196e9953490dd18616e916e3
service/Warehouse/MesItemQtManager.cs
@@ -1,13 +1,11 @@
using Masuit.Tools;
using System.Data;
using System.Data.SqlClient;
using Masuit.Tools;
using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
using NewPdaSqlServer.entity.Base;
using NewPdaSqlServer.util;
using SqlSugar;
using System.Data;
using System.Data.SqlClient;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace NewPdaSqlServer.service.Warehouse;
@@ -19,7 +17,7 @@
    /// </summary>
    /// <returns>退料单号列表</returns>
    public dynamic GetPendingQtList(dynamic RequestInfo)
     {
    {
        var orgId = RequestInfo.OrgId;
        if (orgId == null)
@@ -28,17 +26,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_qtck_list @pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters);
                "EXEC prc_pda_qtck_list @pi_orgId,@inP1,@inP2,@inP3,@inP4",
                parameters);
            return blDetails;
        }
        catch (Exception ex)
@@ -60,25 +59,26 @@
            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_qtck_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_qtck_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,
                allList = blDetails,
                items,
                ysitems,
                allList = blDetails
            };
        }
        catch (Exception ex)
@@ -89,7 +89,7 @@
    }
    /// <summary>
    /// 扫码出库
    ///     扫码出库
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
@@ -124,8 +124,6 @@
            throw new Exception($"mes中不存在此条码,请核对!{p_item_barcode}");
        // 获取库存信息
        var stock = Db.Queryable<MesInvItemStocks>()
            .Where(it => it.ItemBarcode == p_item_barcode && it.Quantity > 0)
@@ -153,7 +151,9 @@
        // 获取其他出库单信息
        var mesItemQt = Db.Queryable<MesItemQt>()
            .Where(it => it.Qtck == p_bill_no && it.Qt015 == true && it.Qt026 == true && it.Qt029 == true && it.Qt032 == true)
            .Where(it =>
                it.Qtck == p_bill_no && it.Qt015 == true && it.Qt026 == true &&
                it.Qt029 == true && it.Qt032 == true)
            .First();
        if (mesItemQt == null)
@@ -169,17 +169,14 @@
        if (qtDetail == null) throw new Exception("扫码物料非本次出库申请物料,请核对!");
        if (mesItemQt.Qt014 == true)
        if (mesItemQt.Qt014)
            throw new Exception($"其他出库申请单 {p_bill_no} 已完结,请确认!");
        // 检查仓库是否一致
        if (qtDetail.DepotId  != stock.DepotId)
        if (qtDetail.DepotId != stock.DepotId)
            throw new Exception(
                $"扫码出货仓库id{qtDetail.DepotId}与其他出库申请仓库{stock.DepotId}不一致,请核对!");
        // 检查剩余数量
        var remainingQty = (qtDetail.Qd007 ?? 0) - (qtDetail.Qd008 ?? 0);
@@ -190,8 +187,8 @@
        if (stock.Quantity > remainingQty)
        {
            var pendingList = Db
                .Queryable<MesItemQt, MesItemQtDatall, MesItems>(
                    (a, b, c) => new JoinQueryInfos(
                .Queryable<MesItemQt, MesItemQtDatall, MesItems>((a, b, c) =>
                    new JoinQueryInfos(
                        JoinType.Left, a.Guid == b.QtGuid,
                        JoinType.Left, b.ItemId == c.Id.ToString()))
                .Where((a, b, c) => a.Qtck == p_bill_no &&
@@ -210,7 +207,7 @@
            var message =
                $"请确认发料数量!!已带出满足其他出库单的发料数量 {remainingQty} 确认后请点击条码拆分";
            throw new Exception($"条码数量超出发料数量,请拆分后再扫描!");
            throw new Exception("条码数量超出发料数量,请拆分后再扫描!");
            query.itemNo = stock.ItemNo;
            query.Num = stock.Quantity;
@@ -298,7 +295,8 @@
            // 检查是否已存在出库物料记录
            var existingOutItem = Db.Queryable<MesInvItemOutItems>()
                .Where(it =>
                    it.ItemOutId == outId && it.ItemId == barcode.ItemId && it.ItemDabid == qtDetail.Guid)
                    it.ItemOutId == outId && it.ItemId == barcode.ItemId &&
                    it.ItemDabid == qtDetail.Guid)
                .First();
            if (existingOutItem == null)
@@ -340,7 +338,9 @@
                commit += db.Updateable<MesInvItemOutItems>()
                    .SetColumns(it =>
                        it.TlQty == (it.TlQty ?? 0) + stock.Quantity)
                    .Where(it => it.ItemOutId == outId && it.ItemId == barcode.ItemId && it.ItemDabid == qtDetail.Guid)
                    .Where(it =>
                        it.ItemOutId == outId && it.ItemId == barcode.ItemId &&
                        it.ItemDabid == qtDetail.Guid)
                    .ExecuteCommand();
            }
@@ -431,8 +431,8 @@
                    .ExecuteCommand();
            mesItemQtDatalls = Db
                .Queryable<MesItemQt, MesItemQtDatall, MesItems>(
                    (a, b, c) => new JoinQueryInfos(
                .Queryable<MesItemQt, MesItemQtDatall, MesItems>((a, b, c) =>
                    new JoinQueryInfos(
                        JoinType.Left, a.Guid == b.QtGuid,
                        JoinType.Left, b.ItemId == c.Id.ToString()))
                .Where((a, b, c) => a.Qtck == p_bill_no &&
@@ -465,8 +465,10 @@
            // 创建 插入日志
            var logService = new LogService();
            var LogMsg = "【PDA】其他出库。条码【" + query.barcode + "】数量【"+ stock.Quantity.ToString() + "】 出库单号【" + outNo + "】";
            logService.CreateLog(db, query.userName, mesItemQt.Guid.ToString(), "MES_ITEM_QT", LogMsg, mesItemQt.Qtck);
            var LogMsg = "【PDA】其他出库。条码【" + query.barcode + "】数量【" +
                         stock.Quantity + "】 出库单号【" + outNo + "】";
            logService.CreateLog(db, query.userName, mesItemQt.Guid.ToString(),
                "MES_ITEM_QT", LogMsg, mesItemQt.Qtck);
            if (commit < 5) throw new Exception("更新失败");
@@ -477,7 +479,7 @@
    }
    /// <summary>
    /// 拆分条码并出库
    ///     拆分条码并出库
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
@@ -862,8 +864,8 @@
            // 获取剩余待处理明细
            mesItemQtDatalls = db
                .Queryable<MesItemQt, MesItemQtDatall, MesItems>(
                    (a, b, c) => new JoinQueryInfos(
                .Queryable<MesItemQt, MesItemQtDatall, MesItems>((a, b, c) =>
                    new JoinQueryInfos(
                        JoinType.Left, a.Guid == b.QtGuid,
                        JoinType.Left, b.ItemId == c.Id.ToString()))
                .Where((a, b, c) => a.Qtck == p_bill_no &&
@@ -888,7 +890,7 @@
    /// <summary>
    /// 其他出库(新)存储过程
    ///     其他出库(新)存储过程
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
@@ -900,7 +902,8 @@
        using (var conn = new SqlConnection(DbHelperSQL.strConn))
        {
            if (query.userName.IsNullOrEmpty()) throw new Exception("用户名不允许为空");
            if (query.billNo.IsNullOrEmpty()) throw new Exception("申请单号不允许为空"); if (query.barcode.IsNullOrEmpty()) throw new Exception("条码不允许为空");
            if (query.billNo.IsNullOrEmpty()) throw new Exception("申请单号不允许为空");
            if (query.barcode.IsNullOrEmpty()) throw new Exception("条码不允许为空");
            using (var cmd = new SqlCommand("[prc_pda_QTCK]", conn))
            {
@@ -968,7 +971,7 @@
        var _strMsg = "";
        var _intSum = "";
        var _cfBar = "";//拆分后条码
        var _cfBar = ""; //拆分后条码
        using (var conn = new SqlConnection(DbHelperSQL.strConn))
        {
            using (var cmd = new SqlCommand("[prc_pda_QTCK_CF]", conn))
@@ -1004,8 +1007,8 @@
                    var dto = new ProductionPickDto
                    {
                        daa001 = query.billNo,
                        barcode = query.barcode,//原条码
                        cfBarcode = _cfBar//拆分后条码
                        barcode = query.barcode, //原条码
                        cfBarcode = _cfBar //拆分后条码
                    };
                    return dto;