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
using HH.WMS.BLL;
using HH.WMS.BLL.External;
using HH.WMS.Common;
using HH.WMS.Common.External;
using HH.WMS.Common.Response;
using HH.WMS.Entitys.Dto;
using HH.WMS.Entitys.External;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
 
namespace HH.WMS.WebApi.App_Start
{
    public class WmsApiBLLRoute
    {
        #region 入库
 
        public static string InWorkArea(List<InWorkAreaEntity> inWorkAreaEntitys)
        {
            var result = string.Empty;
            var projectCode = getProjectCode();
            string jxWebUrl = string.Empty;
 
            foreach (var inWorkArea in inWorkAreaEntitys)
            {
                inWorkArea.projectCode = projectCode;
            }
            switch (projectCode)
            {
                case ProjectCodes.JuXingHaiNing:        //巨星海宁        
                    //调用巨星接口获取入库库区
                    var logPara = LogType.LogPara("巨星-入作业区");
                    DataSet ds = new DataSet();
                    string clientKey1 = string.Empty;
                    string clientKey2 = string.Empty;
                    //调用巨星接口获取托盘入库库区
                    try
                    {
                        jxWebUrl = System.Configuration.ConfigurationManager.AppSettings["jxWebUrl"].ToString();
                    }
                    catch (Exception ep)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中jxWebUrl配置异常!" + ep.Message };
                        Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return JsonConvert.SerializeObject(eResponse);
                    }
                    try
                    {
                        clientKey1 = System.Configuration.ConfigurationManager.AppSettings["clientKey1"].ToString();
                    }
                    catch (Exception ep)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中clientKey1配置异常!" + ep.Message };
                        Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return JsonConvert.SerializeObject(eResponse);
                    }
                    try
                    {
                        clientKey2 = System.Configuration.ConfigurationManager.AppSettings["clientKey2"].ToString();
                    }
                    catch (Exception ep)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中clientKey2配置异常!" + ep.Message };
                        Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return JsonConvert.SerializeObject(eResponse);
                    }
                    if (inWorkAreaEntitys[0].needCallJobDetail.Equals("Y"))
                    {
                        #region 需要调巨星接口获取转运任务号
                        try
                        {
 
                            WebServiceAgent jxAgent = new WebServiceAgent(jxWebUrl);
                            object[] para = { clientKey1, clientKey2, "AGV", inWorkAreaEntitys[0].trayCode, "", "I", "N", null, null };
                            Log.Detail(logPara, "调用巨星接口获取托盘入库库区输入参数:" + JsonConvert.SerializeObject(para));
                            object returnObject = jxAgent.Invoke("GetJobDetail", para);
                            ds = (DataSet)returnObject;
                            Log.Detail(logPara, "调用巨星接口获取托盘入库库区:" + JsonConvert.SerializeObject(ds));
                            if (ds.Tables[0].Rows.Count == 0)
                            {
                                ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = string.Format("托盘号{0}调用巨星WMS的GetJobDetail未获取到数据!", inWorkAreaEntitys[0].trayCode) };
                                Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                                return JsonConvert.SerializeObject(eResponse);
                            }
 
 
                        }
                        catch (Exception ex)
                        {
                            ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = string.Format("调用巨星WMS的GetJobDetail接口异常:{0}!", ex.Message) };
                            Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                            return JsonConvert.SerializeObject(eResponse);
                        }
                        if (string.IsNullOrEmpty(inWorkAreaEntitys[0].endBit))
                        {
                            inWorkAreaEntitys[0].endArea = ds.Tables[0].Rows[0]["ToAreaCode"].ToString();
                            inWorkAreaEntitys[0].remark = ds.Tables[0].Rows[0]["TrnSeqNo"].ToString();
                        }
                        else
                        {
                            inWorkAreaEntitys[0].remark = ds.Tables[0].Rows[0]["TrnSeqNo"].ToString();
                        }
                        #endregion 
                    }
                    else
                    {
                        inWorkAreaEntitys[0].remark = inWorkAreaEntitys[0].trnSeqNo;
                    }
 
                    string needCreateAMSTask = string.Empty;
                    try
                    {
                        needCreateAMSTask = System.Configuration.ConfigurationManager.AppSettings["needCreateAMSTask"].ToString();
                    }
                    catch (Exception ep)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中needCreateAMSTask配置异常!" + ep.Message };
                        Log.Detail(logPara, "InWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return JsonConvert.SerializeObject(eResponse);
                    }
                    inWorkAreaEntitys[0].needCreateAMSTask = needCreateAMSTask;
                    ExternalResponse resultJX = BLLCreator.Create<WmsApiForJxhnBLL>().InWorkAreaJX(inWorkAreaEntitys);
                    try
                    {
                        if (resultJX.success)
                        {
                            //更新是否传递给巨星任务完成     
                            WebServiceAgent jxAgent = new WebServiceAgent(jxWebUrl);
                            //object[] para1 = { clientKey1, clientKey2, inWorkAreaEntitys[0].remark, inWorkAreaEntitys[0].trayCode, resultJX.okList[0].endBit, "80", "8", "hh" };
                            object[] para1 = { clientKey1, clientKey2, inWorkAreaEntitys[0].remark, inWorkAreaEntitys[0].trayCode, "", "80", "8", "hh" };
                            Log.Detail(logPara, "入库调用巨星接口SetAGVJobStatus输入参数:" + JsonConvert.SerializeObject(para1));
                            object returnObject1 = jxAgent.Invoke("SetAGVJobStatus", para1);
                            Log.Detail(logPara, "returnFromJuxing,SetAGVJobStatus,8:" + returnObject1.ToString());
                            Log.Detail(logPara, "调用巨星WebService接口反馈托盘搬运货位异动");
                            object[] para = { clientKey1, clientKey2, inWorkAreaEntitys[0].remark, resultJX.okList[0].trayCode, resultJX.okList[0].startBit, "", "I", "hh" };
                            object returnObject = jxAgent.Invoke("SetLocation", para);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Detail(LogType.LogPara("调用巨星WMS接口反馈状态"), "调用巨星WMS接口SetAGVJobStatus反馈状态异常:" + ex.Message + ex.StackTrace);
                    }
                    result = JsonConvert.SerializeObject(resultJX);
                    break;
                case ProjectCodes.NanTongSangDe:       //南通桑德
                    result = BLLCreator.Create<WmsApiForNtsdBLL>().InWorkArea(inWorkAreaEntitys);
                    break;
                case ProjectCodes.QuZhouHuaKai:        //衢州华凯
                    result = BLLCreator.Create<WmsApiForQzhkBLL>().InWorkArea(inWorkAreaEntitys);
                    break;
                case ProjectCodes.HangChaBanHan:        //杭叉板焊
                    var locationMapStr = JsonHelper.GetValue("locationMapping");
                    var locationMaps = JsonConvert.DeserializeObject<List<LocationMapDto>>(locationMapStr);
                    var rowMapStr = JsonHelper.GetValue("rowMapping");
                    var rowMaps = JsonConvert.DeserializeObject<List<RowMapDto>>(rowMapStr);
                    foreach (var inWorkAreaEntity in inWorkAreaEntitys)
                    {
                        foreach (var location in rowMaps)
                        {
                            if (!string.IsNullOrEmpty(inWorkAreaEntity.startBit))
                            {
                                if (inWorkAreaEntity.startBit.Equals(location.endBit))
                                {
                                    //判断当前叫料工位到空托区的起点是否为2个特殊工位(AGV配料区工位)
                                    var locationExt = BLLCreator.Create<DapperBLL<HH.WMS.Entitys.Basic.TN_WM_LOCATION_EXTEntity>>().GetSingleEntity(new { CN_S_LOCATION_CODE = location.endBit });
                                    //判断当前起点货位是否已绑定空托盘
                                    if (locationExt.CN_S_USE_STATE.Equals("空"))
                                    {
                                        var response = new ExternalResponse();
                                        response.success = false;
                                        response.errMsg = "货位:" + inWorkAreaEntity.startBit + "当前已无空托盘!";
                                        return JsonConvert.SerializeObject(response);
                                    }
                                }
                            }
                        }
 
 
                        foreach (var locationMap in locationMaps)
                        {
                            if (!string.IsNullOrEmpty(inWorkAreaEntity.startBit))
                            {
                                //判断当前叫料工位到空托区的起点是否为8个普通工位(人工配料区工位)
                                if (inWorkAreaEntity.startBit.Equals(locationMap.endBit))
                                {
                                    //判断当前工位对应的起点是否为满,必须要先绑定托盘。
                                    var locationExt = BLLCreator.Create<DapperBLL<HH.WMS.Entitys.Basic.TN_WM_LOCATION_EXTEntity>>().GetSingleEntity(new { CN_S_LOCATION_CODE = locationMap.startBit });
                                    if (!locationExt.CN_S_USE_STATE.Equals("满"))
                                    {
                                        var response = new ExternalResponse();
                                        response.success = false;
                                        response.errMsg = "货位:" + inWorkAreaEntity.startBit + ",为空,请先同步货位!";
                                        return JsonConvert.SerializeObject(response);
                                    }
 
                                }
 
                            }
                        }
                    }
                    result = BLLCreator.Create<WmsApiForHcbhBLL>().InWorkArea(inWorkAreaEntitys);
                    break;
                case ProjectCodes.TaiZhouLongJi:        //泰州隆基
                    result = BLLCreator.Create<WmsApiForTzljBLL>().InWorkArea(inWorkAreaEntitys);
                    break;
                case ProjectCodes.HuanSheng://环晟
                    result = BLLCreator.Create<WmsApiForHsBLL>().InWorkArea(inWorkAreaEntitys);
                    break;
                case ProjectCodes.LYL:
                    result = BLLCreator.Create<WmsApiForLylBLL>().InWorkArea(inWorkAreaEntitys);
                    break;
                default:
                    result = BLLCreator.Create<WmsApiBaseBLL>().InWorkArea(inWorkAreaEntitys);
                    break;
            }
            return result;
        }
 
        #endregion
 
        #region 出库
 
        public static string OutWorkArea(List<OutWorkAreaEntity> outWorkAreaEntitys)
        {
            var result = string.Empty;
            string jxWebUrl = string.Empty;
 
            var projectCode = getProjectCode();
            foreach (var OutWorkAreaEntity in outWorkAreaEntitys)
            {
                OutWorkAreaEntity.projectCode = projectCode;
            }
            switch (projectCode)
            {
                case ProjectCodes.JuXingHaiNing:        //巨星海宁
                    //调用巨星接口获取入库库区
                    var logPara = LogType.LogPara("巨星-出作业区");
                    string clientKey1 = "";
                    string clientKey2 = "";
                    try
                    {
                        jxWebUrl = System.Configuration.ConfigurationManager.AppSettings["jxWebUrl"].ToString();
                    }
                    catch (Exception ep)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中jxWebUrl配置异常!" + ep.Message };
                        Log.Detail(logPara, "OutWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return JsonConvert.SerializeObject(eResponse);
                    }
                    try
                    {
                        clientKey1 = System.Configuration.ConfigurationManager.AppSettings["clientKey1"].ToString();
                    }
                    catch (Exception ep)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中clientKey1配置异常!" + ep.Message };
                        Log.Detail(logPara, "OutWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return JsonConvert.SerializeObject(eResponse);
                    }
                    try
                    {
                        clientKey2 = System.Configuration.ConfigurationManager.AppSettings["clientKey2"].ToString();
                    }
                    catch (Exception ep)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中clientKey2配置异常!" + ep.Message };
                        Log.Detail(logPara, "OutWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return JsonConvert.SerializeObject(eResponse);
                    }
                    string needCreateAMSTask = string.Empty;
                    try
                    {
                        needCreateAMSTask = System.Configuration.ConfigurationManager.AppSettings["needCreateAMSTask"].ToString();
                    }
                    catch (Exception ep)
                    {
                        ExternalResponse eResponse = new ExternalResponse { success = false, errMsg = "异常:获取webconfig中needCreateAMSTask配置异常!" + ep.Message };
                        Log.Detail(logPara, "OutWorkArea接口返回结果:" + JsonConvert.SerializeObject(eResponse));
                        return JsonConvert.SerializeObject(eResponse);
                    }
                    outWorkAreaEntitys[0].needCreateAMSTask = needCreateAMSTask;
                    ExternalResponse resultJX = BLLCreator.Create<WmsApiForJxhnBLL>().OutWorkAreaJX(outWorkAreaEntitys);
                    result = JsonConvert.SerializeObject(resultJX);
                    try
                    {
                        if (resultJX.success)
                        {
                            WebServiceAgent jxAgent = new WebServiceAgent(jxWebUrl);
                            object[] para = { clientKey1, clientKey2, outWorkAreaEntitys[0].remark, outWorkAreaEntitys[0].trayCode, "", "80", "8", "hh" };
                            Log.Detail(logPara, "出库调用巨星接口SetAGVJobStatus输入参数:" + JsonConvert.SerializeObject(para));
                            object returnObject1 = jxAgent.Invoke("SetAGVJobStatus", para);
                            Log.Detail(logPara, "returnFromJuxing,SetAGVJobStatus,8:" + returnObject1.ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Detail(LogType.LogPara("调用巨星WMS接口反馈状态"), "出库调用巨星WMS接口SetAGVJobStatus:" + ex.Message + ex.StackTrace);
                    }
                    break;
                case ProjectCodes.NanTongSangDe:        //南通桑德
                    result = BLLCreator.Create<WmsApiForNtsdBLL>().OutWorkArea(outWorkAreaEntitys);
                    break;
                case ProjectCodes.HangChaBanHan:        //杭叉板焊
                    var locationMapStr = JsonHelper.GetValue("locationMapping");
                    var locationMaps = JsonConvert.DeserializeObject<List<LocationMapDto>>(locationMapStr);
                    foreach (var outWorkAreaEntity in outWorkAreaEntitys)
                    {
                        foreach (var locationMap in locationMaps)
                        {
                            if (!string.IsNullOrEmpty(outWorkAreaEntity.startBit))
                            {
                                if (outWorkAreaEntity.startBit.Equals(locationMap.startBit))
                                {
                                    outWorkAreaEntity.endBit = locationMap.endBit;
                                }
                            }
                            //AMS从工位叫料后,根据匹配关系找到起点,8个工位与起点是一一对应的。
                            if (!string.IsNullOrEmpty(outWorkAreaEntity.endBit))
                            {
                                if (outWorkAreaEntity.endBit.Equals(locationMap.endBit))
                                {
                                    outWorkAreaEntity.startBit = locationMap.startBit;
                                }
                            }
                        }
                    }
                    result = BLLCreator.Create<WmsApiForHcbhBLL>().OutWorkArea(outWorkAreaEntitys);
                    break;
                case ProjectCodes.TaiZhouLongJi:        //泰州隆基
                    result = BLLCreator.Create<WmsApiForTzljBLL>().OutWorkArea(outWorkAreaEntitys);
                    break;
                default:
                    result = BLLCreator.Create<WmsApiBaseBLL>().OutWorkArea(outWorkAreaEntitys);
                    break;
            }
            return result;
        }
 
        #endregion
 
        #region 完工回报
 
        public static string ExecuteState(ExecuteStateDto executeState)
        {
            var result = string.Empty;
            switch (getProjectCode())
            {
                case ProjectCodes.WuXiYuShou:        //无锡宇寿
                    result = BLLCreator.Create<WmsApiForWxysBLL>().ExecuteState(executeState);
                    break;
                case ProjectCodes.JuXingHaiNing:        //巨星海宁
                    result = BLLCreator.Create<WmsApiForJxhnBLL>().ExecuteState(executeState);
                    break;
                case ProjectCodes.NanTongSangDe:        //南通桑德
                    result = BLLCreator.Create<WmsApiForNtsdBLL>().ExecuteState(executeState);
                    break;
                case ProjectCodes.TaiZhouLongJi:        //泰州隆基
                    result = BLLCreator.Create<WmsApiForTzljBLL>().ExecuteState(executeState);
                    break;
                case ProjectCodes.QuZhouHuaKai:         //衢州华凯
                    result = BLLCreator.Create<WmsApiForQzhkBLL>().ExecuteState(executeState);
                    break;
                case ProjectCodes.MaAnShanYueMei:       //马鞍山粤美
                    result = BLLCreator.Create<WmsApiForMasymBLL>().ExecuteState(executeState);
                    break;
                case ProjectCodes.HuanSheng:            //huansheng
                    result = BLLCreator.Create<WmsApiForHsBLL>().ExecuteState(executeState);
                    break;
                default:
                    result = BLLCreator.Create<WmsApiBaseBLL>().ExecuteState(executeState);
                    break;
            }
            return result;
        }
 
        public static string ExecuteState(List<ExecuteStateDto> executeStates)
        {
            var result = string.Empty;
            switch (getProjectCode())
            {
                case ProjectCodes.WuXiYuShou:           //无锡宇寿
                    result = BLLCreator.Create<WmsApiForWxysBLL>().ExecuteState(executeStates);
                    break;
                case ProjectCodes.JuXingHaiNing:        //巨星海宁
                    result = BLLCreator.Create<WmsApiForJxhnBLL>().ExecuteState(executeStates);
                    break;
                case ProjectCodes.NanTongSangDe:        //南通桑德
                    result = BLLCreator.Create<WmsApiForNtsdBLL>().ExecuteState(executeStates);
                    break;
                case ProjectCodes.TaiZhouLongJi:        //泰州隆基
                    result = BLLCreator.Create<WmsApiForTzljBLL>().ExecuteState(executeStates);
                    break;
                case ProjectCodes.QuZhouHuaKai:       //衢州华凯
                    result = BLLCreator.Create<WmsApiForQzhkBLL>().ExecuteState(executeStates);
                    break;
                case ProjectCodes.MaAnShanYueMei:       //马鞍山粤美
                    result = BLLCreator.Create<WmsApiForMasymBLL>().ExecuteState(executeStates);
                    break;
                default:
                    result = BLLCreator.Create<WmsApiBaseBLL>().ExecuteState(executeStates);
                    break;
            }
            return result;
        }
 
        #endregion
 
        #region 绑定与解绑
 
        public static string BindingAndUnBinding(BindingAndUnBindingDto bindEntity)
        {
            var result = string.Empty;
            switch (getProjectCode())
            {
                case ProjectCodes.JuXingHaiNing:         //巨星海宁
                    result = BLLCreator.Create<WmsApiForJxhnBLL>().BindingAndUnBinding(bindEntity);
                    break;
                default:
                    break;
            }
            return result;
        }
 
        #endregion
 
        #region 解绑货位
 
        public static BasisResponse UnbindLocation(string locationCode)
        {
            var result = BasisResponse.Normal();
            var projectCode = getProjectCode();
            switch (projectCode)
            {
                case ProjectCodes.HangChaBanHan:
                    result = BLLCreator.Create<WmsApiForHcbhBLL>().UnbindLocation(locationCode);
                    break;
            }
            return result;
        }
 
        #endregion
 
        #region 获取当前项目编号
 
        /// <summary>
        /// 获取当前项目编号
        /// </summary>
        /// <returns></returns>
        public static string getProjectCode()
        {
            try
            {
                return System.Configuration.ConfigurationManager.AppSettings["projectCode"].ToString();
            }
            catch (Exception)
            {
                return "";
            }
        }
 
        #endregion
 
    }
}