南骏 池
2025-03-29 99b5d3d7c950a8332f81d3ca07be9f2d5957f58c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
namespace NewPdaSqlServer.service.@base
{
    using NewPdaSqlServer.Dto.service;
    using NewPdaSqlServer.entity;
    using SqlSugar;
    using System;
    using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
    using System.Data;
    using NewPdaSqlServer.DB;
    using System.Data;
    using System.Data.SqlClient;
    using Microsoft.EntityFrameworkCore.Metadata.Internal;
 
 
    public class WmsBaseMangeer : Repository<dynamic>
    {
 
        /// <summary>
        /// 通用入库校验
        /// </summary>
        /// <param name="db">SqlSugar 数据库上下文</param>
        /// <param name="edtUserNo">操作人工号</param>
        /// <param name="barcode">物料条码</param>
        /// <param name="sectionCode">库位编码</param>
        /// <param name="stockId">仓库ID</param>
        /// <param name="stockOrgId">库存组织ID</param>
        /// <param name="billNo">申请单号</param>
        /// <param name="transactionNo">事务类型</param>
        /// <returns>包含校验结果的数据传输对象</returns>
        public dynamic pdaInvJY(SqlSugarScope db, string edtUserNo,
            string barcode, string sectionCode, string stockId, string stockOrgId,
            string billNo, string transactionNo)
        {
            var outputMsg = "";
            var outputStatus = -1;
 
            using (var conn = new SqlConnection(DbHelperSQL.strConn))
            using (var cmd = new SqlCommand("prc_pda_inv_JY", conn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                // 输入参数配置
                SqlParameter[] parameters =
                {
                    new("@pi_user", SqlDbType.NVarChar, 100) { Value = edtUserNo },
                    new("@pi_barcode", SqlDbType.NVarChar, 100) { Value = barcode },
                    new("@pi_sectionCode", SqlDbType.NVarChar, 100) { Value = sectionCode },
                    new("@pi_stockId", SqlDbType.NVarChar, 100) { Value = stockId },
                    new("@pi_stockOrgId", SqlDbType.NVarChar, 100) { Value = stockOrgId },
                    new("@pi_billno", SqlDbType.NVarChar, 100) { Value = billNo },
                    new("@pi_transaction_no", SqlDbType.NVarChar, 10) { Value = transactionNo },
                    new("@pi_val1", SqlDbType.NVarChar, 100) { Value = DBNull.Value }, // 预留扩展字段
                    new("@pi_val2", SqlDbType.NVarChar, 100) { Value = DBNull.Value }, // 预留扩展字段
                    new("@po_outMsg", SqlDbType.NVarChar, 2000) { Direction = ParameterDirection.Output },
                    new("@po_outStatus", SqlDbType.Int) { Direction = ParameterDirection.Output }
                };
 
                try
                {
                    conn.Open();
                    cmd.Parameters.AddRange(parameters);
                    cmd.ExecuteNonQuery();
 
                    // 获取输出参数
                    outputMsg = parameters[9].Value?.ToString() ?? "";
                    outputStatus = Convert.ToInt32(parameters[10].Value);
 
                    if (outputStatus <= 0)
                        throw new Exception(outputMsg);
 
                    return new ProductionPickDto
                    {
                        barcode = barcode,
                        strMsg = outputMsg,
                        result = outputStatus.ToString(),
                        // 其他需要映射的字段...
                    };
                }
                catch (Exception ex)
                {
                    throw new Exception($"入库校验失败: {ex.Message}");
                }
            }
        }
 
        /// <summary>
        /// 获取条码信息
        /// </summary>
        /// <param name="unity"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public MesInvItemBarcodes GetBarInfo(WarehouseQuery unity)
        {
            var barInfo = Db.Queryable<MesInvItemBarcodes>()
                .Where(s => s.ItemBarcode == unity.barcode)
                .First();
            if (barInfo is null) throw new Exception("该条码库存不存在!");
 
            return barInfo; // 返回第一行数据,如果没有则返回 null
        }
 
        /// <summary>
        /// 获取物料信息
        /// </summary>
        /// <param name="strItemId"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public MesItems GetItemNo(decimal strItemId)
        {
            var itemInfo = Db.Queryable<MesItems>()
                .Where(s => s.Id == strItemId && s.Fforbidstatus == "A")
                .First();
            if (itemInfo is null) throw new Exception("该条码对应物料信息不存在或已禁用!");
 
            return itemInfo;
        }
    }
}