jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
using HH.WMS.Entitys.Func;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Dynamic;
using HH.WMS.Common.Algorithm;
using HH.WMS.Entitys.Common;
using System.Data.Common;
using HH.WMS.Common.Algorithm.Out;
using HH.WMS.Common;
 
namespace HH.WMS.DAL.Algorithm
{
    public class Out_AlgorDAL : DapperBaseDAL
    {
        /// <summary>
        /// 根据物料等获取作业区中匹配的可出库货位,作业区目前都是整托出货
        /// </summary>
        /// <param name="itemCodes">物料编码集合 以逗号分隔</param>
        /// <param name="code">仓库/库区编号</param>
        /// <param name="type">1:根据库区  2:根据仓库</param>
        /// <returns></returns>
        public List<outAssignLocation> GetAssignFlatItemQty(string itemCodes, string areaCodes)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT TB.*,TB2.CN_S_USE_STATE  FROM ");
            strSql.AppendLine(" (SELECT  A.CN_S_TRAY_CODE as trayCode,D.CN_T_PRODUCTION as productDate,D.CN_S_LOT_NO as lotNo, ");
            strSql.AppendLine(" B.CN_S_LOCATION_CODE as locationCode,B.CN_S_STOCK_AREA as stockAreaCode,B.CN_T_CREATE as opTime FROM TN_WM_B_TRAY_ITEM_MST A ");
            strSql.AppendLine(" INNER JOIN dbo.tn_wm_b_tray_location B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE ");
            strSql.AppendLine(" INNER JOIN dbo.TN_WM_B_TRAY_ITEM_DTL D ON D.CN_PARENT_GUID = A.CN_GUID ");
            if (!string.IsNullOrEmpty(areaCodes))
            {
                strSql.AppendLine(" AND B.CN_S_STOCK_AREA IN ('" + areaCodes + "') ");
            }
            //追加查询条件
            strSql.AppendLine(" AND A.CN_S_ITEM_CODE = '" + itemCodes + "' ");
            strSql.AppendLine(" ) TB INNER JOIN tn_wm_b_location_ext TB2 on TB.locationCode=TB2.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" WHERE  TB2.CN_S_LOCATION_STATE='正常' AND TB2.CN_S_USE_STATE!='空' ");
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("outAssign-GetAssignFlatItemQty", "sql语句为:" + strSql.ToString());
            List<outAssignLocation> lstQty = ExecuteQuery<outAssignLocation>(strSql.ToString());
            return lstQty;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemCodes"></param>
        /// <param name="areaCodes"></param>
        /// <returns></returns>
        public List<outAssignLocation> GetAssignFlatItemQtyJX(string areaCodes)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT A.CN_S_TRAY_CODE as trayCode,'' as productDate,'' as lotNo, A.CN_S_LOCATION_CODE as locationCode,A.CN_S_STOCK_AREA as stockAreaCode, ");
            strSql.AppendLine(" A.CN_T_CREATE as opTime,TB2.CN_S_USE_STATE   FROM tn_wm_b_tray_location A ");
            strSql.AppendLine(" INNER JOIN tn_wm_b_location_ext TB2 on A.locationCode=TB2.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" WHERE  TB2.CN_S_LOCATION_STATE='正常' AND TB2.CN_S_USE_STATE!='空' ");
            if (!string.IsNullOrEmpty(areaCodes))
            {
                strSql.AppendLine(" AND A.CN_S_STOCK_AREA = '" + areaCodes + "' ");
            }
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("outAssign-GetAssignFlatItemQty", "sql语句为:" + strSql.ToString());
            List<outAssignLocation> lstQty = ExecuteQuery<outAssignLocation>(strSql.ToString());
            return lstQty;
        }
        /// <summary>
        /// 根据物料等获取作业区中匹配的可出库货位,作业区目前都是整托出货
        /// </summary>
        /// <param name="itemCodes">物料编码集合 以逗号分隔</param>
        /// <param name="code">仓库/库区编号</param>
        /// <param name="type">1:根据库区  2:根据仓库</param>
        /// <returns></returns>
        public List<outAssignLocation> GetAssignFlatItemQtyNT(string itemCodes, string areaCodes)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT TB.trayCode,TB.productDate,TB.locationCode,TB.stockAreaCode,TB.opTime,TB2.CN_S_USE_STATE,SUM(TB.CN_F_QUANTITY) AS totalQty  FROM ");
            strSql.AppendLine(" (SELECT  A.CN_S_TRAY_CODE as trayCode,D.CN_T_PRODUCTION as productDate,");
            strSql.AppendLine(" B.CN_S_LOCATION_CODE as locationCode,B.CN_S_STOCK_AREA as stockAreaCode,B.CN_T_CREATE as opTime,A.CN_F_QUANTITY FROM TN_WM_B_TRAY_ITEM_MST A ");
            strSql.AppendLine(" INNER JOIN dbo.tn_wm_b_tray_location B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE ");
            strSql.AppendLine(" INNER JOIN dbo.TN_WM_B_TRAY_ITEM_DTL D ON D.CN_PARENT_GUID = A.CN_GUID ");
            if (!string.IsNullOrEmpty(areaCodes))
            {
                strSql.AppendLine(" AND B.CN_S_STOCK_AREA IN ('" + areaCodes + "') ");
            }
            //追加查询条件
            strSql.AppendLine(" AND A.CN_S_ITEM_CODE = '" + itemCodes + "' ");
            strSql.AppendLine(" ) TB INNER JOIN tn_wm_b_location_ext TB2 on TB.locationCode=TB2.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" WHERE  TB2.CN_S_LOCATION_STATE='正常' AND TB2.CN_S_USE_STATE!='空' ");
            strSql.AppendLine(" GROUP BY  TB.trayCode,TB.productDate,TB.locationCode,TB.stockAreaCode,TB.opTime,TB2.CN_S_USE_STATE ");
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("outAssign-GetAssignFlatItemQty", "sql语句为:" + strSql.ToString());
            List<outAssignLocation> lstQty = ExecuteQuery<outAssignLocation>(strSql.ToString());
            return lstQty;
        }
        /// <summary>
        /// 根据物料等获取作业区中匹配的可出库货位,作业区目前都是整托出货
        /// </summary>
        /// <param name="itemCodes">物料编码集合 以逗号分隔</param>
        /// <param name="code">仓库/库区编号</param>
        /// <param name="type">1:根据库区  2:根据仓库</param>
        /// <returns></returns>
        public List<outAssignLocation> GetAssignFlatItemQtyYS(string itemCodes, string lotNo, string areaCodes)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT TB.trayCode,TB.locationCode,TB.stockAreaCode,TB2.CN_S_USE_STATE as useState ,isnull(SUM(CN_F_PACKING_QTY),0) as totalWeight FROM ");
            strSql.AppendLine(" (SELECT  A.CN_S_TRAY_CODE as trayCode, ");
            strSql.AppendLine(" B.CN_S_LOCATION_CODE as locationCode,B.CN_S_STOCK_AREA as stockAreaCode,CN_S_SERIAL_NO,CN_F_PACKING_QTY FROM TN_WM_B_TRAY_ITEM_MST A ");
            strSql.AppendLine(" INNER JOIN dbo.tn_wm_b_tray_location B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE ");
            strSql.AppendLine(" INNER JOIN dbo.TN_WM_B_TRAY_ITEM_DTL D ON D.CN_PARENT_GUID = A.CN_GUID ");
            if (!string.IsNullOrEmpty(areaCodes))
            {
                strSql.AppendLine(" AND B.CN_S_STOCK_AREA IN ('" + areaCodes + "') ");
            }
            if (!string.IsNullOrEmpty(lotNo))
            {
                strSql.AppendLine(" AND D.CN_S_LOT_NO ='" + lotNo + "' ");
            }
            //追加查询条件
            strSql.AppendLine(" AND A.CN_S_ITEM_CODE = '" + itemCodes + "' ");
            strSql.AppendLine(" ) TB INNER JOIN tn_wm_b_location_ext TB2 on TB.locationCode=TB2.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" WHERE  TB2.CN_S_LOCATION_STATE='正常' AND TB2.CN_S_USE_STATE!='空' ");
            strSql.AppendLine(" GROUP BY  TB.trayCode,TB.locationCode,TB.stockAreaCode,TB2.CN_S_USE_STATE ");
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("outAssign-GetAssignFlatItemQtyYS", "sql语句为:" + strSql.ToString());
            List<outAssignLocation> lstQty = ExecuteQuery<outAssignLocation>(strSql.ToString());
            return lstQty;
        }
 
        /// <summary>
        /// 根据库区、托盘类型获取空托盘的匹配货位
        /// </summary>
        /// <param name="itemCode"></param>
        /// <param name="traySpec"></param>
        /// <param name="areaCodes"></param>
        /// <returns></returns>
        public List<outAssignLocation> GetAssignFlatEmptySpecTray(string traySpec, string areaCodes)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT A.CN_S_TRAY_CODE as trayCode,A.CN_S_LOCATION_CODE as locationCode,A.CN_S_STOCK_AREA as stockAreaCode  FROM dbo.tn_wm_b_tray_location A ");
            strSql.AppendLine(" INNER JOIN tn_wm_b_location_ext TB2 on A.CN_S_LOCATION_CODE=TB2.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" INNER JOIN tn_wm_tray_info B on A.CN_S_TRAY_CODE=B.CN_S_TRAY_CODE ");
            strSql.AppendLine(" LEFT JOIN TN_WM_B_TRAY_ITEM_MST C on A.CN_S_TRAY_CODE=C.CN_S_TRAY_CODE ");
            strSql.AppendLine(" WHERE C.CN_S_TRAY_CODE IS NULL AND TB2.CN_S_LOCATION_STATE='正常' AND TB2.CN_S_USE_STATE!='空' ");
            if (!string.IsNullOrEmpty(areaCodes))
            {
                strSql.AppendLine(" AND A.CN_S_STOCK_AREA = '" + areaCodes + "' ");
            }
            //追加查询条件
            //物料编码
            if (!string.IsNullOrEmpty(traySpec))
            {
                strSql.AppendLine(" AND B.CN_S_SPEC = '" + traySpec + "' ");
            }
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("outAssign-GetAssignFlatEmptySpecTray", "sql语句为:" + strSql.ToString());
            List<outAssignLocation> lstQty = ExecuteQuery<outAssignLocation>(strSql.ToString());
          
            return lstQty;
        }
 
        /// <summary>
        /// 根据库区、托盘类型获取空托盘的匹配货位
        /// </summary>
        /// <param name="itemCode"></param>
        /// <param name="traySpec"></param>
        /// <param name="areaCodes"></param>
        /// <returns></returns>
        public List<outAssignLocation> GetAssignFlatEmptySpecTrayBH(string traySpec, string areaCodes)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT A.CN_S_TRAY_CODE  as trayCode,B.CN_S_LOCATION_CODE as locationCode,B.CN_S_AREA_CODE as stockAreaCode FROM dbo.tn_wm_b_tray_location A  INNER JOIN  tn_wm_b_location_ext B ");
            strSql.AppendLine(" ON a.CN_S_LOCATION_CODE = B.CN_S_LOCATION_CODE WHERE B.CN_S_LOCATION_STATE='正常' AND B.CN_S_USE_STATE!='空' ");
            if (!string.IsNullOrEmpty(areaCodes))
            {
                strSql.AppendLine(" AND B.CN_S_AREA_CODE = '" + areaCodes + "' ");
            }
 
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("outAssign-GetAssignFlatEmptySpecTrayBH", "sql语句为:" + strSql.ToString());
            List<outAssignLocation> lstQty = ExecuteQuery<outAssignLocation>(strSql.ToString());
 
            return lstQty;
        }
 
        /// <summary>
        /// 根据库区、托盘类型获取空托盘的匹配货位
        /// </summary>
        /// <param name="itemCode"></param>
        /// <param name="traySpec"></param>
        /// <param name="areaCodes"></param>
        /// <returns></returns>
        public List<outAssignLocation> GetAssignFlatEmptySpecTrayLJ(string traySpec, string areaCodes)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT A.CN_S_TRAY_CODE  as trayCode,B.CN_S_LOCATION_CODE as locationCode,B.CN_S_AREA_CODE as stockAreaCode FROM dbo.tn_wm_b_tray_location A  INNER JOIN  tn_wm_b_location_ext B ");
            strSql.AppendLine(" ON a.CN_S_LOCATION_CODE = B.CN_S_LOCATION_CODE WHERE B.CN_S_LOCATION_STATE='正常' AND B.CN_S_USE_STATE!='空' ");
            if (!string.IsNullOrEmpty(areaCodes))
            {
                strSql.AppendLine(" AND B.CN_S_AREA_CODE = '" + areaCodes + "' ");
            }
 
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("outAssign-GetAssignFlatEmptySpecTrayLJ", "sql语句为:" + strSql.ToString());
            List<outAssignLocation> lstQty = ExecuteQuery<outAssignLocation>(strSql.ToString());
 
            return lstQty;
        }
        /// <summary>
        /// 根据库区、托盘类型获取空托盘的匹配货位
        /// </summary>
        /// <param name="itemCode"></param>
        /// <param name="traySpec"></param>
        /// <param name="areaCodes"></param>
        /// <returns></returns>
        public List<outAssignLocation> GetAssignFlatEmptySpecTrayYM(string traySpec, string areaCodes)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT A.CN_S_TRAY_CODE  as trayCode,B.CN_S_LOCATION_CODE as locationCode,B.CN_S_AREA_CODE as stockAreaCode FROM dbo.tn_wm_b_tray_location A  INNER JOIN  tn_wm_b_location_ext B ");
            strSql.AppendLine(" ON a.CN_S_LOCATION_CODE = B.CN_S_LOCATION_CODE WHERE B.CN_S_LOCATION_STATE='正常' AND B.CN_S_USE_STATE!='空' ");
            if (!string.IsNullOrEmpty(areaCodes))
            {
                strSql.AppendLine(" AND B.CN_S_AREA_CODE = '" + areaCodes + "' ");
            }
 
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            Log.AlgorInfo("outAssign-GetAssignFlatEmptySpecTrayYM", "sql语句为:" + strSql.ToString());
            List<outAssignLocation> lstQty = ExecuteQuery<outAssignLocation>(strSql.ToString());
 
            return lstQty;
        }
 
        #region 根据库区或者仓库获取对应物料的数量
        /// <summary>
        /// 根据库区或者仓库获取对应物料的数量
        /// </summary>
        /// <param name="itemCodes">物料编码集合 以逗号分隔</param>
        /// <param name="code">仓库/库区编号</param>
        /// <param name="type">1:根据库区  2:根据仓库</param>
        /// <returns></returns>
        public List<itemQty> GetItemQtyByAreaCode(string strWhere, string code, int type, string orderBy)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT TB.*,TB2.CN_S_USE_STATE FROM ");
            strSql.AppendLine(" (SELECT CN_F_PACKING_QTY AS itemQty,CN_S_ITEM_CODE,a.CN_S_TRAY_CODE,CN_S_TRAY_GRID, ");
            strSql.AppendLine(" B.CN_T_OPERATE,A.CN_S_LOT_NO,A.CN_T_EXPIRATION,B.CN_S_LOCATION_CODE,B.CN_S_STOCK_AREA,B.CN_N_INDEX FROM tn_wm_b_tray_item_rel A ");
            strSql.AppendLine(" INNER JOIN tn_wm_b_tray_location B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE ");
            if (type == 1)
            {
                strSql.AppendLine(" WHERE B.CN_S_STOCK_AREA='" + code + "' ");
            }
            else
            {
                strSql.AppendLine(" WHERE B.CN_S_STOCK_CODE='" + code + "' ");
            }
            //追加查询条件
            strSql.AppendLine(strWhere);
            strSql.AppendLine(" ) TB INNER JOIN tn_wm_b_location_ext TB2 on TB.CN_S_LOCATION_CODE=TB2.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" WHERE  TB2.CN_S_LOCATION_STATE='正常' AND TB2.CN_S_USE_STATE!='空' ");
            strSql.AppendLine(orderBy);
 
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            List<itemQty> lstQty = ExecuteQuery<itemQty>(strSql.ToString());
            return lstQty;
        }
 
        #endregion
 
 
        #region 获取对应出库所需物料的数量-锁货位物料量不锁货位
        /// <summary>
        /// 获取对应出库所需物料的数量-锁货位物料量不锁货位-吉鑫祥
        /// </summary>
        /// <param name="itemCodes">物料编码集合 以逗号分隔</param>
        /// <param name="code">仓库/库区编号</param>
        /// <param name="type">1:根据库区  2:根据仓库</param>
        /// <returns></returns>
        public List<itemQty> GetItemQtyLockRel(string strWhere, string code, string orderBy)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT  (A.CN_F_QUANTITY-A.CN_F_ALLOC_QTY) AS Qty,A.CN_S_ITEM_CODE as itemCode,A.CN_S_TRAY_CODE as trayCode,A.CN_S_TRAY_GRID as trayGrid, ");
            strSql.AppendLine(" C.CN_T_EXPIRATION as ExpireDate ,C.CN_S_LOT_NO as lotNo,C.CN_S_PRODUCTION_BATCH as prodBatchCode,B.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" as locationCode,B.CN_S_STOCK_AREA as stockAreaCode FROM tn_wm_b_tray_item_mst A ");
            strSql.AppendLine(" INNER JOIN tn_wm_b_tray_location B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE INNER JOIN (select top 1 *   tn_wm_b_tray_item_dtl D where d.CN_PARENT_GUID = A.CN_GUID ORDER BY CN_S_PRODUCTION_BATCH ASC,CN_S_LOT_NO ASC)  C");
            strSql.AppendLine(" ON A.CN_GUID = C.CN_PARENT_GUID WHERE B.CN_S_STOCK_AREA='" + code + "' ");
            //追加查询条件
            strSql.AppendLine(strWhere);
            strSql.AppendLine(orderBy);
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            List<itemQty> lstQty = ExecuteQuery<itemQty>(strSql.ToString());
            return lstQty;
        }
        /// <summary>
        /// 获取对应出库所需物料的数量-锁货位物料量不锁货位-吉鑫祥-不管控批次
        /// </summary>
        /// <param name="itemCodes">物料编码集合 以逗号分隔</param>
        /// <param name="code">仓库/库区编号</param>
        /// <param name="type">1:根据库区  2:根据仓库</param>
        /// <returns></returns>
        public List<itemQty> GetItemQtyJxx(string strWhere, string code)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT C.CN_F_QUANTITY AS Qty,A.CN_F_ALLOC_QTY,A.CN_S_ITEM_CODE as itemCode,A.CN_S_OWNER,A.CN_S_ITEM_STATE,A.CN_S_TRAY_CODE as trayCode,A.CN_S_TRAY_GRID as trayGrid, ");
            strSql.AppendLine(" C.CN_T_EXPIRATION as ExpireDate ,C.CN_S_LOT_NO as lotNo,C.CN_S_PRODUCTION_BATCH as prodBatchCode,B.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" as locationCode,B.CN_S_STOCK_AREA as stockAreaCode FROM tn_wm_b_tray_item_mst A ");
            strSql.AppendLine(" INNER JOIN tn_wm_b_tray_location B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE INNER JOIN   tn_wm_b_tray_item_dtl  C");
            strSql.AppendLine(" ON A.CN_GUID = C.CN_PARENT_GUID WHERE B.CN_S_STOCK_AREA='" + code + "' ");         
            //追加查询条件
            strSql.AppendLine(strWhere);
            strSql.AppendLine(" ORDER BY   C.CN_S_LOT_NO ASC");
            HH.WMS.Common.Log.AlgorInfo("GetItemQtyJxxt", "strSql语句:" + strSql.ToString());
            //strSql.AppendLine(orderBy);
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            List<itemQty> lstQty = ExecuteQuery<itemQty>(strSql.ToString());
            return lstQty;
        }
        /// <summary>
        /// 获取对应出库所需物料的数量-锁货位物料量不锁货位-吉鑫祥-不管控批次
        /// </summary>
        /// <param name="itemCodes">物料编码集合 以逗号分隔</param>
        /// <param name="code">仓库/库区编号</param>
        /// <param name="type">1:根据库区  2:根据仓库</param>
        /// <returns></returns>
        public List<itemQty> GetOutItemQty(string itemCode,string itemState,string prodBatchCode,string batchCode,string ownerName, string areaCode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT cast(newid() as varchar(50)) as ID, C.CN_F_QUANTITY AS Qty,case C.CN_F_PACKING_QTY when 0 then 1 else CN_F_PACKING_QTY end as PAKQty,C.CN_S_PACKING_UNIT as packUnit, A.CN_F_ALLOC_QTY,A.CN_S_ITEM_CODE as itemCode,A.CN_S_OWNER,A.CN_S_ITEM_STATE,A.CN_S_TRAY_CODE as trayCode,A.CN_S_TRAY_GRID as trayGrid, ");
            strSql.AppendLine(" C.CN_T_EXPIRATION as ExpireDate ,C.CN_T_PRODUCTION AS productDate,C.CN_S_LOT_NO as lotNo,C.CN_S_PRODUCTION_BATCH as prodBatchCode,B.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" as locationCode,B.CN_S_STOCK_AREA as stockAreaCode, A.CN_S_TIMESTAMP,TB2.CN_S_ROW,TB2.CN_S_COL  FROM tn_wm_b_tray_item_mst A ");
            strSql.AppendLine(" INNER JOIN tn_wm_b_tray_location B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE INNER JOIN   tn_wm_b_tray_item_dtl  C");
            strSql.AppendLine(" ON A.CN_GUID = C.CN_PARENT_GUID  ");
            strSql.AppendLine(" INNER JOIN  tn_wm_b_location_ext  TB2 on B.CN_S_LOCATION_CODE=TB2.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" WHERE  TB2.CN_S_LOCATION_STATE='正常' AND TB2.CN_S_USE_STATE!='空' ");
            strSql.AppendLine(" AND B.CN_S_STOCK_AREA='" + areaCode + "' ");
            //物料编码
            if (!string.IsNullOrEmpty(itemCode))
            {
                strSql.AppendLine(" AND A.CN_S_ITEM_CODE  ='" + itemCode + "' ");
            }
            //物料状态
            if (!string.IsNullOrEmpty(itemState))
            {
                strSql.AppendLine(" AND A.CN_S_ITEM_STATE = '" + itemState + "' ");
            }
            //批次号
            if (!string.IsNullOrEmpty(batchCode))
            {
                strSql.AppendLine(" AND C.CN_S_LOT_NO = '" + batchCode + "' ");
            }
            //生产批次号
            if (!string.IsNullOrEmpty(prodBatchCode))
            {
                strSql.AppendLine(" AND C.CN_S_PRODUCTION_BATCH = '" + prodBatchCode + "' ");
            }
            //货主
            if (!string.IsNullOrEmpty(ownerName))
            {
                strSql.AppendLine(" AND A.CN_S_OWNER = '" + ownerName + "' ");
            }
            //strSql.AppendLine(orderBy);
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            HH.WMS.Common.Log.AlgorInfo("GetOutItemQty", "获取库区中匹配物料的strSql语句:" + strSql.ToString());
            List<itemQty> lstQty = ExecuteQuery<itemQty>(strSql.ToString());
            return lstQty;
        }
        /// <summary>
        /// 获取对应出库所需物料的数量-锁货位物料量不锁货位-吉鑫祥-不管控批次
        /// </summary>
        /// <param name="itemCodes">物料编码集合 以逗号分隔</param>
        /// <param name="code">仓库/库区编号</param>
        /// <param name="type">1:根据库区  2:根据仓库</param>
        /// <returns></returns>
        public List<itemQty> GetOutItemAllocQty(string itemCode, string itemState,  string ownerName, string areaCode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT A.CN_F_ALLOC_QTY,A.CN_S_ITEM_CODE as itemCode,A.CN_S_OWNER,A.CN_S_ITEM_STATE,B.CN_S_TRAY_CODE as trayCode,A.CN_S_TRAY_GRID as trayGrid ");
            strSql.AppendLine(" FROM tn_wm_b_tray_item_mst A INNER JOIN tn_wm_b_tray_location B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE WHERE B.CN_S_STOCK_AREA='" + areaCode + "'");
            //追加查询条件
 
            //物料编码
            if (!string.IsNullOrEmpty(itemCode))
            {
                strSql.AppendLine(" AND A.CN_S_ITEM_CODE  ='" + itemCode + "' ");
            }
            //物料状态
            if (!string.IsNullOrEmpty(itemState))
            {
                strSql.AppendLine(" AND A.CN_S_ITEM_STATE = '" + itemState + "' ");
            }
            //货主
            if (!string.IsNullOrEmpty(ownerName))
            {
                strSql.AppendLine(" AND A.CN_S_OWNER = '" + ownerName + "' ");
            }
            //strSql.AppendLine(orderBy);
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            HH.WMS.Common.Log.AlgorInfo("GetOutItemAllocQty", "获取库区中匹配物料的strSql语句:" + strSql.ToString());
            List<itemQty> lstQty = ExecuteQuery<itemQty>(strSql.ToString());
            return lstQty;
        }
        public List<itemQty> GetItemQtyLockRelSszy(string strWhere, string code)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT C.CN_F_QUANTITY AS Qty,A.CN_F_ALLOC_QTY,A.CN_S_ITEM_CODE as itemCode,A.CN_S_OWNER,A.CN_S_ITEM_STATE,A.CN_S_TRAY_CODE as trayCode,A.CN_S_TRAY_GRID as trayGrid, ");
            strSql.AppendLine(" C.CN_T_EXPIRATION as ExpireDate ,C.CN_S_LOT_NO as lotNo,C.CN_S_PRODUCTION_BATCH as prodBatchCode,B.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" as locationCode,B.CN_S_STOCK_AREA as stockAreaCode FROM tn_wm_b_tray_item_mst A ");
            strSql.AppendLine(" INNER JOIN tn_wm_b_tray_location B ON A.CN_S_TRAY_CODE = B.CN_S_TRAY_CODE INNER JOIN   FROM tn_wm_b_tray_item_dtl  C");
            strSql.AppendLine(" ON A.CN_GUID = C.CN_PARENT_GUID WHERE B.CN_S_STOCK_AREA='" + code + "' ");
            strSql.AppendLine(" ORDER BY  C.prodBatchCode ASC, C.CN_S_LOT_NO ASC");
            //追加查询条件
            strSql.AppendLine(strWhere);
            //strSql.AppendLine(orderBy);
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            List<itemQty> lstQty = ExecuteQuery<itemQty>(strSql.ToString());
            return lstQty;
        }
 
        #endregion
 
 
        #region 补料  取空托盘
        /// <summary>
        /// 补料  取空托盘
        /// </summary>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public List<FeedEmptyTrayEntity> GetEmptyTrayList(string areaCode, string traySpec, string locationCodes)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" select A.CN_S_LOCATION_CODE,A.CN_S_TRAY_CODE,C.CN_S_SPEC,C.CN_F_LOADBEARING ");
            strSql.AppendLine(" from tn_wm_b_tray_location A ");
            strSql.AppendLine(" LEFT JOIN  ");
            strSql.AppendLine(" ( ");
            strSql.AppendLine(" SELECT CN_S_TRAY_CODE FROM TN_WM_B_TRAY_ITEM_MST ");
            strSql.AppendLine(" GROUP BY CN_S_TRAY_CODE ");
            strSql.AppendLine(" ) B ");
            strSql.AppendLine(" ON A.CN_S_TRAY_CODE=B.CN_S_TRAY_CODE ");
            strSql.AppendLine(" INNER JOIN tn_wm_tray_info C ON A.CN_S_TRAY_CODE=C.CN_S_TRAY_CODE ");
            strSql.AppendLine(" INNER JOIN tn_wm_b_location_ext D ON A.CN_S_LOCATION_CODE=D.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" where B.CN_S_TRAY_CODE IS NULL AND D.CN_S_LOCATION_STATE = '正常'  AND A.CN_S_STOCK_AREA='" + areaCode + "' ");
            if (!string.IsNullOrEmpty(locationCodes))
            {
                strSql.AppendLine("  AND A.CN_S_LOCATION_CODE IN (" + locationCodes + ")");
            }
            if (!string.IsNullOrEmpty(traySpec))
            {
                strSql.AppendLine("  AND C.CN_S_SPEC = '" + traySpec + "'");
            }
            DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            HH.WMS.Common.Log.AlgorInfo("Feed按重量补料-GetEmptyTrayList", strSql.ToString());
            List<FeedEmptyTrayEntity> list = ExecuteQuery<FeedEmptyTrayEntity>(strSql.ToString());
            return list;
        }
        public List<FridTrayWeight> GetTrayWeightBySpec(string areaCode, string traySpec, string locationCodes)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT B.CN_S_TRAY_CODE as trayCode,CN_F_LOADBEARING as loadWeight,C.CN_F_WEIGHT as fridWeight,CN_F_GROSSWEIGHT as crossWeight,B.CN_S_LOCATION_CODE as locationCode,C.CN_S_SPEC as traySpec ");
            strSql.AppendLine(" FROM  tn_wm_b_tray_location B  ");
            strSql.AppendLine(" INNER JOIN tn_wm_tray_info  C ON B.CN_S_TRAY_CODE=C.CN_S_TRAY_CODE ");
            strSql.AppendLine(" INNER JOIN tn_wm_b_location_ext TB2 ON B.CN_S_LOCATION_CODE=TB2.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" where C.CN_S_USE_STATE='不满'    AND TB2.CN_S_LOCATION_STATE='正常'  ");
            if (!string.IsNullOrEmpty(areaCode))
            {
                strSql.AppendLine(" and B.CN_S_STOCK_AREA='" + areaCode + "' ");
            }
            if (!string.IsNullOrEmpty(traySpec))
            {
                strSql.AppendLine(" and C.CN_S_SPEC = '" + traySpec + "' ");
            }
            if (!string.IsNullOrEmpty(locationCodes))
            {
                strSql.AppendLine(" and B.CN_S_LOCATION_CODE in( " + locationCodes + ") ");
            }
            HH.WMS.Common.Log.AlgorInfo("Feed按重量补料-GetTrayWeightBySpec", strSql.ToString());
           // DbCommand cmd = DataAccess.GetSqlStringCommand(strSql.ToString());
            List<FridTrayWeight> lstFrid = ExecuteQuery<FridTrayWeight>(strSql.ToString());
            return lstFrid;
        }
        public List<ItemInWeight> GetItemWeightByTray(string trayCode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT A.CN_S_ITEM_CODE,B.CN_S_LOT_NO,SUM(CN_F_PACKING_QTY) AS  ITEMQTY");
            strSql.AppendLine(" FROM TN_WM_B_TRAY_ITEM_MST A INNER JOIN TN_WM_B_TRAY_ITEM_DTL  B ON  A.CN_GUID = B.CN_PARENT_GUID   ");
            strSql.AppendLine(" where CN_S_TRAY_CODE ='" + trayCode + "'");
            strSql.AppendLine(" GROUP BY  CN_S_ITEM_CODE,CN_S_LOT_NO");
            List<ItemInWeight> lstItem = ExecuteQuery<ItemInWeight>(strSql.ToString());
            return lstItem;
        }
        public List<ItemInTray> GetItemByTray(string trayCode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT A.CN_S_ITEM_CODE,B.CN_S_LOT_NO");
            strSql.AppendLine(" FROM TN_WM_B_TRAY_ITEM_MST A INNER JOIN TN_WM_B_TRAY_ITEM_DTL  B ON  A.CN_GUID = B.CN_PARENT_GUID   ");
            strSql.AppendLine(" where CN_S_TRAY_CODE ='" + trayCode + "'");
            strSql.AppendLine(" GROUP BY  CN_S_ITEM_CODE,CN_S_LOT_NO");
            List<ItemInTray> lstItem = ExecuteQuery<ItemInTray>(strSql.ToString());
            return lstItem;
        }
 
        public List<FridTray> GetNotFullTrayBySpec(string areaCode, string itemCode, string traySpec)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.AppendLine(" SELECT B.CN_S_TRAY_CODE as trayCode,B.CN_S_LOCATION_CODE as locationCode,C.CN_N_GOODUPLINE ");
            strSql.AppendLine(" FROM  tn_wm_b_tray_location B  ");
            strSql.AppendLine(" INNER JOIN tn_wm_tray_info  C ON B.CN_S_TRAY_CODE=C.CN_S_TRAY_CODE ");
            strSql.AppendLine(" INNER JOIN SELECT TN_WM_B_TRAY_ITEM_MST  D ON B.CN_S_TRAY_CODE=D.CN_S_TRAY_CODE ");
            strSql.AppendLine(" INNER JOIN tn_wm_b_location_ext TB2 ON B.CN_S_LOCATION_CODE=TB2.CN_S_LOCATION_CODE ");
            strSql.AppendLine(" where C.CN_S_USE_STATE  in ('空','不满')    AND TB2.CN_S_LOCATION_STATE='正常'  ");
            if (!string.IsNullOrEmpty(areaCode))
            {
                strSql.AppendLine(" and B.CN_S_STOCK_AREA='" + areaCode + "' ");
            }
            if (!string.IsNullOrEmpty(traySpec))
            {
                strSql.AppendLine(" and C.CN_S_SPEC = '" + traySpec + "' ");
            }
            if (!string.IsNullOrEmpty(itemCode))
            {
                strSql.AppendLine(" and D.CN_S_ITEM_CODE = '" + itemCode + "' ");
            }
            HH.WMS.Common.Log.AlgorInfo("Feed未满托盘补料-GetNotFullTrayBySpec", strSql.ToString());
            List<FridTray> lstFrid = ExecuteQuery<FridTray>(strSql.ToString());
            return lstFrid;
        }
        #endregion
 
 
 
 
 
 
 
 
 
    }
}