zhao
2021-06-04 c7ec496f9e41c2227103b3ef776e4a3f91bce6b2
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
using HH.Redis.ReisModel;
using HH.WMS.BLL;
using HH.WMS.BLL.Basic;
using HH.WMS.BLL.InStock;
using HH.WMS.Common;
using HH.WMS.Entitys;
using HH.WMS.Entitys.Basic;
using HH.WMS.Entitys.Entitys;
using HH.WMS.WebApi.Areas.Common.Controllers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
 
namespace HH.WMS.WebApi.Areas.InStock.Controllers
{
    public class TrayLocationController : BaseController
    {
        #region 根据货位找托盘及其物料
        /// <summary>
        /// 根据货位获取货位上托盘物料信息
        /// </summary>
        /// <param name="tokenId">token验证值</param>
        /// <param name="locationCode">货位编码</param>
        /// <returns></returns>
        /// <History>[HANHE(XDL)] CREATED BY 2018-11-13</History>
        [HttpGet]
        public string GetTrayByLocationCode(string locationCode)
        {
            try
            {
                return ValidateToken(t =>
                {
                    //判断货位编码是否存在
                    AutoBomLocationEntity locationModel = BLLCreator.Create<TN_AB_STOCK_LOCATIONBLL>().GetLocationModel(locationCode);
                    if (locationModel == null)
                    {
                        return JsonConvert.SerializeObject(OperateResult.Error("货位编码不存在!"));
                    }
                    DataTable dt = BLLCreator.Create<TN_WM_B_TRAY_LOCATIONBLL>().GetTrayByLocationCode(locationCode);
 
                    return JsonConvert.SerializeObject(OperateResult.Succeed("", dt));
                });
            }
            catch (Exception ex)
            {
                return JsonConvert.SerializeObject(OperateResult.Error(ex.Message.ToString()));
            }
        }
        #endregion
 
        #region 根据托盘找所在货位
        /// <summary>
        /// 根据托盘找所在货位
        /// </summary>
        /// <param name="tokenId">token验证值</param>
        /// <param name="CN_S_LOCATION_CODE">货位编码</param>
        /// <returns></returns>
        /// <History>[HANHE(XDL)] CREATED BY 2018-11-15</History>
        [HttpGet]
        public OperateResult GetLocationByTrayCode(string trayCode, string locationCode)
        {
            try
            {
                return ValidateToken(t =>
                {
                    if (!string.IsNullOrEmpty(trayCode))
                    {
                        TN_WM_B_TRAY_INFOEntity trayInfo = BLLCreator.Create<DapperBLL<TN_WM_B_TRAY_INFOEntity>>().GetSingleEntity(new { CN_S_TRAY_CODE = trayCode }, "");
                        if (trayInfo == null)
                        {
                            return OperateResult.Error("托盘码不存在!");
                        }
                    }
 
                    if (string.IsNullOrEmpty(trayCode) && string.IsNullOrEmpty(locationCode))
                    {
                        return OperateResult.Error("参数缺失!");
                    }
                    string isAuto = Constants.Y;
                    if (!string.IsNullOrEmpty(locationCode))
                    {
                        AutoBomLocationEntity locationModel = BLLCreator.Create<TN_AB_STOCK_LOCATIONBLL>().GetLocationModel(locationCode);
                        if (locationModel != null)
                        {
                            AutoBomStockAreaEntity areaEntity = BLLCreator.Create<TN_AB_B_STOCK_AREABLL>().GetStockAreaEntity(locationModel.CN_S_AREA_CODE);
                            isAuto = areaEntity.CN_C_IS_AUTO;
                        }
                    }
 
                    DataTable dt = BLLCreator.Create<TN_WM_B_TRAY_LOCATIONBLL>().GetLocationByTrayCode(trayCode, locationCode);
 
                    if (dt.Rows.Count > 0)
                    {
                        dt.Columns.Add("CN_C_IS_AUTO");
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            dt.Rows[i]["CN_C_IS_AUTO"] = isAuto;
                        }
                    }
 
                    return OperateResult.Succeed("", dt);
                });
            }
            catch (Exception ex)
            {
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        /// <summary>
        /// 根据容器找所在货位信息
        /// </summary>
        /// <param name="trayCode"></param>
        /// <returns></returns>
        [HttpGet]
        public OperateResult GetLocationByTray(string trayCode)
        {
            try
            {
                return ValidateToken(t =>
                {
                    TN_WM_B_TRAY_LOCATIONEntity trayLocationEntity = BLLCreator.Create<DapperBLL<TN_WM_B_TRAY_LOCATIONEntity>>().GetSingleEntity(new { CN_S_TRAY_CODE = trayCode }, "");
                    return OperateResult.Succeed("", trayLocationEntity);
                });
            }
            catch (Exception ex)
            {
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        #endregion
 
        #region (PDA接口)物料上架
        /// <summary>
        /// 物料执行上架
        /// </summary>
        /// <param name="tokenId">token验证值</param>
        /// <param name="jsonData">数据Json</param>
        /// <returns></returns>
        /// <History>[HANHE(XDL)] CREATED BY 2018-11-13</History>
        [HttpPost]
        public OperateResult SaveLocationPalletRelation(JObject json)
        {
            try
            {
                Log.Info("物料上架开始", "");
                ItemOnShelfEntity entity = JsonConvert.DeserializeObject<ItemOnShelfEntity>(json.ToString());
                return ValidateToken(entity.TokenId, t =>
                    {
                        if (t == null)
                        {
                            return OperateResult.Error("登陆人员信息获取失败!");
                        }
 
                        return BLLCreator.Create<TN_WM_B_TRAY_LOCATIONBLL>().SaveLocationPalletRelation(entity, t);
                    });
            }
            catch (Exception ex)
            {
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        #endregion
 
        #region (PDA接口)整托上架
        /// <summary>
        /// 整托执行上架
        /// </summary>
        /// <param name="json">数据Json</param>
        /// <returns></returns>
        /// <History>[HANHE(XDL)] CREATED BY 2018-12-12</History>
        [HttpPost]
        public OperateResult ZTSaveLocationPalletRelation(JObject json)
        {
            try
            {
                Log.Info("整托上架开始", "");
                TrayOnShelfEntity entity = JsonConvert.DeserializeObject<TrayOnShelfEntity>(json.ToString());
                return ValidateToken(entity.TokenId, t =>
                {
                    if (t == null)
                    {
                        return OperateResult.Error("登陆人员信息获取失败!");
                    }
 
                    return BLLCreator.Create<TN_WM_B_TRAY_LOCATIONBLL>().ZTSaveLocationPalletRelation(entity, t);
                });
            }
            catch (Exception ex)
            {
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        #endregion
 
        #region (PDA接口)维修工还料上架
        /// <summary>
        /// 物料执行上架
        /// </summary>
        /// <param name="tokenId">token验证值</param>
        /// <param name="jsonData">数据Json</param>
        /// <returns></returns>
        /// <History>[HANHE(XDL)] CREATED BY 2018-11-13</History>
        [HttpPost]
        public OperateResult HLSaveLocationPalletRelation(JObject jsonData)
        {
            try
            {
                Log.Info("还料上架开始", "");
 
                string ItemBackNo = jsonData["ItemBackNo"].ToString();
                string locationCode = jsonData["locationCode"].ToString();
                string trayCode = jsonData["trayCode"].ToString();
                string tokenId = jsonData["tokenId"].ToString();
 
                Log.Info("还料传参", "ItemBackNo:" + ItemBackNo + ",locationCode:" + locationCode + ",trayCode:" + trayCode + ",tokenId:" + tokenId);
 
                TN_WM_ITEMBACK_MSTEntity itemBackEntity = BLLCreator.Create<TN_WM_ITEMBACK_MSTBLL>().GetItemBackMstAndDtl(ItemBackNo);
 
                ItemOnShelfEntity entity = new ItemOnShelfEntity();
 
                entity.TokenId = tokenId;
                entity.CN_S_DEVICE_NO = "";
                entity.CN_S_LOCATION_CODE = locationCode;
                entity.CN_S_TRAY_CODE = trayCode;
 
                List<ItemRow> itemRowList = new List<ItemRow>();
                foreach (var item in itemBackEntity.DTLEntity)
                {
                    ItemRow itemRow = new ItemRow();
                    itemRow.CN_F_PACKING_QTY = item.CN_F_PACKING_QTY.ToString();
                    itemRow.CN_F_PURCHASE_PRICE = item.CN_F_PURCHASE_PRICE;
                    itemRow.CN_F_RETAIL_PRICE = item.CN_F_RETAIL_PRICE;
                    itemRow.CN_F_QUANTITY = item.CN_F_QUANTITY;
                    itemRow.CN_S_FROM_NO = "";
                    itemRow.CN_S_ITEM_CODE = item.CN_S_ITEM_CODE;
                    itemRow.CN_S_ITEM_NAME = item.CN_S_ITEM_NAME;
                    itemRow.CN_S_ITEM_STATE = item.CN_S_ITEM_STATE;
                    itemRow.CN_S_LOT_NO = item.CN_S_LOT_NO;
                    itemRow.CN_S_OWNER = itemBackEntity.CN_S_OWNER;
                    itemRow.CN_S_PACKING_UNIT = item.CN_S_PACKING_UNIT;
                    itemRow.CN_S_PRODUCTION_BATCH = item.CN_S_PRODUCTION_BATCH;
                    itemRow.CN_S_SERIAL_NO = item.CN_S_SERIAL_NO;
                    itemRow.CN_S_TRAY_CODE = trayCode;
                    itemRow.CN_S_TRAY_GRID = "1";
                    itemRow.CN_S_UNIQUE_CODE = item.CN_S_UNIQUE_CODE;
                    itemRow.CN_S_VENDOR_NAME = item.CN_S_VENDOR_NAME;
                    itemRow.CN_S_VENDOR_NO = item.CN_S_VENDOR_NO;
                    itemRow.CN_T_EXPIRATION = item.CN_T_EXPIRATION;
                    itemRow.CN_T_PRODUCTION = item.CN_T_PRODUCTION;
 
                    itemRowList.Add(itemRow);
                }
                entity.row = itemRowList;
 
                return ValidateToken(entity.TokenId, t =>
                {
                    if (t == null)
                    {
                        return OperateResult.Error("登陆人员信息获取失败!");
                    }
 
                    return BLLCreator.Create<TN_WM_B_TRAY_LOCATIONBLL>().HLSaveLocationPalletRelation(ItemBackNo, entity, t);
                });
            }
            catch (Exception ex)
            {
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        #endregion
 
        #region (PDA接口)物料上架获取建议货位
        /// <summary>
        /// 物料上架获取建议货位
        /// </summary>
        /// <param name="itemCode">物料编码</param>
        /// <param name="areaCode">库区编码</param>
        /// <param name="quantity">上架数量</param>
        /// <param name="lotCode">批次编码</param>
        /// <returns></returns>
        /// <History>[HANHE(XDL)] CREATED BY 2019-03-20</History>
        [HttpGet]
        public string ItemGetLocationCode(string itemCode, string areaCode, int quantity, string lotCode)
        {
            try
            {
                return ValidateToken(t =>
                {
                    OperateResult result = BLLCreator.Create<TN_WM_B_TRAY_LOCATIONBLL>().ItemGetLocationCode(itemCode, areaCode, quantity, lotCode);
 
                    return JsonConvert.SerializeObject(result);
                });
            }
            catch (Exception ex)
            {
                return JsonConvert.SerializeObject(OperateResult.Error(ex.Message.ToString()));
            }
        }
        #endregion
 
        #region (PDA接口)根据货位编码获取货位上托盘信息
        /// <summary>
        /// (PDA接口)根据货位编码获取货位上托盘信息
        /// </summary>
        /// <param name="locationCode">货位编码</param>
        /// <returns></returns>
        /// <history>[HanHe(xdl)] CREATED 2019/03/20</history>
        [HttpGet]
        public string GetDetailByLocationCode(string locationCode)
        {
            try
            {
                return ValidateToken(t =>
                {
                    List<TN_WM_B_TRAY_LOCATIONEntity> result = BLLCreator.Create<TN_WM_B_TRAY_LOCATIONBLL>().GetDetailByLocationCode(locationCode);
 
                    return JsonConvert.SerializeObject(OperateResult.Succeed("", result));
                });
            }
            catch (Exception ex)
            {
                return JsonConvert.SerializeObject(OperateResult.Error(ex.Message.ToString()));
            }
        }
        #endregion
 
        #region (PDA接口)呼叫不满托盘出库
        /// <summary>
        /// 根据托盘规格-呼叫不满托盘出库
        /// </summary>
        /// <param name="jsonData">数据Json</param>
        /// <returns></returns>
        /// <History>[HANHE(XDL)] CREATED BY 2019-04-10</History>
        [HttpPost]
        public OperateResult CallNoFullPallet(JObject jsonData)
        {
            try
            {
                Log.Info("呼叫不满托盘开始", "");
 
                string itemCode = jsonData["itemCode"].ToString();
                string trayQuantity = jsonData["trayQuantity"].ToString();
                string endLocationCode = jsonData["endLocationCode"].ToString();
                string startAreaCode = jsonData["startAreaCode"].ToString();
                string tokenId = jsonData["tokenId"].ToString();
 
                Log.Info("呼叫不满托盘传参", "itemCode:" + itemCode + ",trayQuantity:" + trayQuantity +",endLocationCode:" + endLocationCode + ",startAreaCode:" + startAreaCode + ",tokenId:" + tokenId);
 
                if (string.IsNullOrEmpty(itemCode) || string.IsNullOrEmpty(trayQuantity) || string.IsNullOrEmpty(endLocationCode) || string.IsNullOrEmpty(startAreaCode) || string.IsNullOrEmpty(tokenId))
                {
                    return OperateResult.Error("参数不全!");
                }
 
                return ValidateToken(tokenId, t =>
                {
                    if (t == null)
                    {
                        return OperateResult.Error("登陆人员信息获取失败!");
                    }
 
                    return BLLCreator.Create<TN_WM_B_TRAY_LOCATIONBLL>().CallNoFullPallet(itemCode, trayQuantity, endLocationCode, startAreaCode, t);
                });
            }
            catch (Exception ex)
            {
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        #endregion
    }
}