11
啊鑫
2025-01-08 a204df28fd20b4908bba80deb482f9c91ecc0877
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System.Data;
using System.Data.SqlClient;
using Masuit.Tools;
using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
using SqlSugar;
 
namespace NewPdaSqlServer.service.Wom;
 
public class WwGdManager : Repository<WwGd>
{
    public ProductionPickDto ScanCode(WarehouseQuery query)
    {
        var _strMsg = "";
        var _intSum = "";
        using (var conn = new SqlConnection(DbHelperSQL.strConn))
        {
            if (query.userName.IsNullOrEmpty()) throw new Exception("用户名不允许为空");
            if (query.daa001.IsNullOrEmpty()) throw new Exception("领料单号不允许为空");
            if (query.barcode.IsNullOrEmpty()) throw new Exception("条码不允许为空");
 
            using (var cmd = new SqlCommand("[prc_pda_WWLL]", conn))
            {
                try
                {
                    conn.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlParameter[] parameters =
                    {
                        new("@outMsg", SqlDbType.NVarChar, 300),
                        new("@outSum", SqlDbType.NVarChar, 300),
                        new("@barcode_num", SqlDbType.NVarChar, 300),
                        new("@split_num", SqlDbType.NVarChar, 300),
                        new("@c_User", query.userName),
                        new("@p_biLL_no", query.daa001),
                        new("@p_item_barcode", query.barcode)
                    };
                    parameters[0].Direction = ParameterDirection.Output;
                    parameters[1].Direction = ParameterDirection.Output;
                    parameters[2].Direction = ParameterDirection.Output;
                    parameters[3].Direction = ParameterDirection.Output;
                    foreach (var parameter in parameters)
                        cmd.Parameters.Add(parameter);
                    cmd.ExecuteNonQuery();
                    _strMsg = parameters[0].Value.ToString();
                    _intSum = parameters[1].Value.ToString();
 
                    var barcodeNum = parameters[2].Value.ToString();
                    var splitNum = parameters[3].Value.ToString();
 
                    var result = Convert.ToInt32(_intSum);
                    if (result <= 0) throw new Exception(_strMsg);
 
                    var dto = new ProductionPickDto
                    {
                        daa001 = query.daa001,
                        barcodeNum = barcodeNum,
                        splitNum = splitNum,
                        barcode = query.barcode
                    };
 
                    return dto;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
    }
 
    //prC_pda_SCLL_CF
    public ProductionPickDto ScanCodeCF(WarehouseQuery query)
    {
        if (query.userName.IsNullOrEmpty()) throw new Exception("用户名不允许为空");
        if (query.daa001.IsNullOrEmpty()) throw new Exception("领料单号不允许为空");
        if (query.barcode.IsNullOrEmpty()) throw new Exception("条码不允许为空");
 
        if (query.Num is null or 0) throw new Exception("条码拆分数不允许为空或者为0");
 
        var _strMsg = "";
        var _intSum = "";
        using (var conn = new SqlConnection(DbHelperSQL.strConn))
        {
            using (var cmd = new SqlCommand("[prc_pda_WWLL_CF]", conn))
            {
                try
                {
                    conn.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlParameter[] parameters =
                    {
                        new("@outMsg", SqlDbType.NVarChar, 300),
                        new("@outSum", SqlDbType.NVarChar, 300),
                        new("@c_User", query.userName),
                        new("@p_biLL_no", query.daa001),
                        new("@p_item_barcode", query.barcode),
                        new("@num", query.Num)
                    };
                    parameters[0].Direction = ParameterDirection.Output;
                    parameters[1].Direction = ParameterDirection.Output;
                    foreach (var parameter in parameters)
                        cmd.Parameters.Add(parameter);
                    cmd.ExecuteNonQuery();
                    _strMsg = parameters[0].Value.ToString();
                    _intSum = parameters[1].Value.ToString();
 
 
                    var result = Convert.ToInt32(_intSum);
                    if (result <= 0) throw new Exception(_strMsg);
 
                    var dto = new ProductionPickDto
                    {
                        daa001 = query.daa001,
                        barcode = query.barcode
                    };
 
                    return dto;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
    }
 
    public ProductionPickDto GetItemsByDaa001(WarehouseQuery query)
    {
        return getDaa001(query);
    }
 
    private ProductionPickDto getDaa001(WarehouseQuery query)
    {
        if (string.IsNullOrEmpty(query.daa001)) throw new Exception("工单号为空");
 
        var womdaa = Db.Queryable<WwGd, MesItems>((a, i) =>
                new JoinQueryInfos(JoinType.Left,
                    a.Daa003 == i.ItemId))
            .Where((a, i) => a.Daa001 == query.daa001)
            .Select((a, i) => new
            {
                a.Daa001, a.Eid
            }).First();
 
        if (womdaa?.Daa001 == null) throw new Exception("工单号不存在");
 
        var womdabs = Db.Queryable<WwGd, WwGdDetail, MesItems, Womcab>(
                (a, b, c, d) =>
                    new JoinQueryInfos(
                        JoinType.Left,
                        a.Id == b.Pid,
                        JoinType.Inner,
                        c.Id ==
                        b.Dab003,
                        JoinType.Inner, b.Erpid == d.Erpid
                    ))
            .Where((a, b, c, d) =>
                a.Daa001 == query.daa001 && d.IssueType == "1")
            .Select((a, b, c, d) => new WwGdDetail
            {
                Pid = b.Pid,
                Dab003 = b.Dab003,
                Dab006 = b.Dab006,
                Dab007 = b.Dab007,
                wNum = b.Dab006 - b.Dab007, // 计算字段 W_NUM
                ItemName = c.ItemName, // 动态字段 ITEM_NAME
                ItemNo = c.ItemNo // 动态字段 ITEM_NO
            })
            .ToList();
 
        var list = womdabs.Where(s => s.wNum > 0).ToList();
 
        var mesInvItemOutCDetailsList = Db
            .Queryable<MesInvItemOutCDetails, MesItems, MesDepots>
            ((a, b, c) =>
                new JoinQueryInfos(
                    JoinType.Inner, a.ItemId == b.Id,
                    JoinType.Inner, c.DepotId == a.DepotId
                ))
            .Where((a, b, c) => a.WorkNo == query.daa001)
            .Select((a, b, c) => new MesInvItemOutCDetails
            {
                ItemName = b.ItemName,
                ItemNo = b.ItemNo,
                ItemId = a.ItemId,
                DepotId = a.DepotId,
                WorkNo = a.WorkNo,
                DepotName = c.DepotName,
                Quantity = a.Quantity
            })
            .ToList();
 
        var womcaa = Db.Queryable<ProductionOrder>()
            .Where(s => s.ErpId == womdaa.Eid.ToString())
            .First();
 
        var dto = new ProductionPickDto
        {
            daa001 = womdaa.Daa001,
            PlanNo = womcaa.ErpProductionOrderNo,
            totals1 = womdabs,
            daisao1 = list,
            yisao = mesInvItemOutCDetailsList
        };
 
        return dto;
    }
}