zhao
2021-07-09 0821715ebc11d3934d0594a1cc2c39686d808906
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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
using HH.Redis.ReisModel;
using HH.WMS.BLL;
using HH.WMS.BLL.Algorithm;
using HH.WMS.BLL.Basic;
using HH.WMS.BLL.ERP;
using HH.WMS.BLL.External;
using HH.WMS.BLL.InStock;
using HH.WMS.BLL.Interface;
using HH.WMS.BLL.Pda;
using HH.WMS.BLL.SysMgr;
using HH.WMS.Common;
using HH.WMS.Common.Algorithm;
using HH.WMS.Common.External;
using HH.WMS.Common.Response;
using HH.WMS.DAL;
using HH.WMS.DAL.Algorithm;
using HH.WMS.DAL.Basic;
using HH.WMS.Entitys;
using HH.WMS.Entitys.Autobom;
using HH.WMS.Entitys.Basic;
using HH.WMS.Entitys.Common;
using HH.WMS.Entitys.Dto;
using HH.WMS.Entitys.Entitys;
using HH.WMS.Entitys.Enums;
using HH.WMS.Entitys.ERP;
using HH.WMS.Entitys.External;
using HH.WMS.Entitys.Tzlj;
using HH.WMS.TaskService.Jobs;
using HH.WMS.WebApi.App_Start;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.Http;
 
namespace HH.WMS.WebApi.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    public class WmsApiController : ApiController
    {
        #region 入作业区 + InWorkArea
        /// <summary>
        /// 入作业区
        /// </summary>
        /// <returns></returns>
        /// <history>[HanHe(zh)] CREATED 2018/5/3</history>
        //[HttpPost]
        //public string InWorkArea(List<InWorkAreaEntity> inWorkAreaEntitys)
        //{
        //    var result =  WmsApiBLLRoute.InWorkArea(inWorkAreaEntitys);
        //    return result;
        //}
 
        [HttpPost]
        public string ReturnWorkArea(List<InWorkAreaEntity> inWorkAreaEntitys)
        {
            foreach (var i in inWorkAreaEntitys)
            {
                i.taskType = "退库";
            }
            return WmsApiBLLRoute.InWorkArea(inWorkAreaEntitys);
        }
 
        #endregion
 
        #region 出作业区 + OutWorkArea
        /// <summary>
        /// 出作业区
        /// </summary>
        /// <returns></returns>
        /// <history>[HanHe(zh)] CREATED 2018/5/3</history>
        [HttpPost]
        public string OutWorkArea(List<OutWorkAreaEntity> outWorkAreaEntitys)
        {
            return WmsApiBLLRoute.OutWorkArea(outWorkAreaEntitys); ;
        }
        #endregion
 
        #region 完工回报 + ExecuteState
        /// <summary>
        /// AGV执行情况 完成时调用
        /// </summary>
        /// <param name="json">传入的Json数组</param>
        /// <returns></returns>
        /// <history>[HanHe(lt)] CREATED 2018/4/8</history>
        [HttpPost]
        public string ExecuteState(ExecuteStateDto data)
        {
            var result = WmsApiBLLRoute.ExecuteState(data);
            try
            {
                var projectCode = System.Configuration.ConfigurationManager.AppSettings["projectCode"].ToString();
                if (result.IndexOf("true") > 0 && data.stateNo == 2 && projectCode == ProjectCodes.JuXingHaiNing)
                {
                    var logPara = LogType.LogPara("调用巨星WMS接口反馈状态");
                    Log.Detail(logPara, "result:" + result + ",data.stateNo" + data.stateNo.ToString() + ",projectCode:" + projectCode);
                    Log.Detail(logPara, "调用巨星WebService反馈状态");
                    string jxWebUrl = string.Empty;
                    string clientKey1 = string.Empty;
                    string clientKey2 = string.Empty;
                    try
                    {
                        jxWebUrl = System.Configuration.ConfigurationManager.AppSettings["jxWebUrl"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Log.Detail(logPara, "异常:获取webconfig中jxWebUrl配置异常!");
                        return result;
                    }
                    try
                    {
                        clientKey1 = System.Configuration.ConfigurationManager.AppSettings["clientKey1"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Log.Detail(logPara, "异常:获取webconfig中clientKey1配置异常!");
                        return result;
                    }
                    try
                    {
                        clientKey2 = System.Configuration.ConfigurationManager.AppSettings["clientKey2"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Log.Detail(logPara, "异常:获取webconfig中clientKey2配置异常!");
                        return result;
                    }
                    //更新是否传递给巨星任务完成
                    TN_WM_TASKEntity transportTask = DALCreator.Create<DapperDAL<TN_WM_TASKEntity>>().GetSingleEntity(new { CN_S_TASK_NO = data.taskNo });
 
                    WebServiceAgent jxAgent = new WebServiceAgent(jxWebUrl);
                    object[] para = { clientKey1, clientKey2, transportTask.CN_S_REMARK, transportTask.CN_S_TRAY_CODE, transportTask.CN_S_END_BIT, "80", "Y", "hh" };
 
                    object returnObject = jxAgent.Invoke("SetAGVJobStatus", para);
                    // HH.WMS.JX.JXWMSServices.WebServiceSoapClient jxServices = new JX.JXWMSServices.WebServiceSoapClient();
                    // jxServices.SetAGVJobStatus("GreatStar", "HNWSRFID", transportTask.CN_S_TRAY_CODE, transportTask.CN_S_END_BIT, "", "");
                    Log.Detail(logPara, "returnFromJuxing,SetAGVJobStatus,Y:" + returnObject.ToString());
                    //调用巨星接口回报托盘所入货位及库区
                    if (string.IsNullOrEmpty(returnObject.ToString()))
                    {
                        DALCreator.Create<DapperDAL<TN_WM_TASKEntity>>().Update(new
                        {
                            CN_S_EXT1 = "Y"
                        }, new
                        {
                            CN_S_TASK_NO = data.taskNo
                        }, null);
                        Log.Detail(logPara, "调用巨星WMS反馈状态返回结果:" + "调用成功");
                    }
                    else
                    {
                        DALCreator.Create<DapperDAL<TN_WM_TASKEntity>>().Update(new
                        {
                            CN_S_EXT1 = "NeedSync"
                        }, new
                        {
                            CN_S_TASK_NO = data.taskNo
                        }, null);
                        Log.Detail(logPara, "调用巨星WMS反馈状态返回结果:" + returnObject.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Detail(LogType.LogPara("调用巨星WMS接口反馈状态"), "调用巨星WMS反馈状态返回结果:" + ex.Message + ex.StackTrace);
            }
            return result;
        }
 
        #endregion
 
        #region 更新托盘中物料的长度或重量
        ///// <summary>
        ///// 更新托盘中物料的长度或重量
        ///// </summary>
        ///// <returns></returns>
        //[HttpPost]
        //public string UpdateTrayItemInfo(dynamic param)
        //{
        //    Log.Info("更新托盘中物料的长度或重量", "UpdateTrayItemInfo接口请求参数:" + JsonConvert.SerializeObject(param));
        //    CommInfResult res = new CommInfResult() { success = false };
        //    try
        //    {
        //        //任务号
        //        string taskNo = Util.ToReplaceSymbolStr(param.taskNo);
        //        //托盘号
        //        string trayCode = Util.ToReplaceSymbolStr(param.trayCode);
        //        //更新对象 1:物料长度 2:重量
        //        string updateObj = Util.ToString(param.updateObj);
        //        //物料长度
        //        string itemQty = Util.ToString(param.itemQty);
        //        //物料重量
        //        string weight = Util.ToString(param.weight);
        //        if (string.IsNullOrEmpty(taskNo) && string.IsNullOrEmpty(trayCode))
        //        {
        //            res.errMsg = "任务号和托盘不可同时为空!";
        //        }
        //        if (updateObj != "1" && updateObj != "2")
        //        {
        //            res.errMsg += " 更新对象参数不正确!";
        //        }
        //        else
        //        {
        //            if (updateObj.Equals("1"))
        //            {
        //                if (!Util.IsNumber(itemQty))
        //                    res.errMsg += " 物料长度值不正确!";
        //            }
        //            else
        //            {
        //                if (!Util.IsNumber(weight))
        //                    res.errMsg += " 托盘重量值不正确!";
        //            }
        //        }
        //        //参数校验失败,直接return
 
 
        //        if (string.IsNullOrEmpty(res.errMsg))
        //        {
        //            //托盘为空,根据任务号先把托盘取出来
        //            if (string.IsNullOrEmpty(trayCode))
        //            {
        //                var currentTaskDt = BLLCreator.Create<DapperBLL<TN_WM_TASKEntity>>().GetSingleEntity(new { CN_S_TASK_NO = taskNo });//BLLCreator.Create<TN_WM_TRANSPORT_TASKBLL>().GetTaskEntity(taskNo);
        //                if (currentTaskDt == null)
        //                {
        //                    res.errMsg = "未找到任务号:" + taskNo;
        //                    Log.Info("更新托盘中物料的长度或重量", "UpdateTrayItemInfo接口返回参数:" + JsonConvert.SerializeObject(res));
        //                    return JsonConvert.SerializeObject(res);
        //                }
        //                else
        //                {
        //                    trayCode = Util.ToString(currentTaskDt.CN_S_TRAY_CODE);
        //                }
        //            }
        //            //校验是否该托盘有物料关联数据
 
        //            var trayItemRelList = BLLCreator.Create<DapperBLL<TN_WM_B_TRAY_ITEM_MSTEntity>>().GetList(new { CN_S_TRAY_CODE = trayCode }); //BLLCreator.Create<TN_WM_B_TRAY_ITEM_RELBLL>().GetItemRelModel(" WHERE CN_S_TRAY_CODE='" + trayCode + "' ");
        //            if (!trayItemRelList.Any())
        //            {
        //                res.errMsg = "未找到托盘:" + trayCode + "的物料关联数据";
        //                Log.Info("更新托盘中物料的长度或重量", "UpdateTrayItemInfo接口返回参数:" + JsonConvert.SerializeObject(res));
        //                return JsonConvert.SerializeObject(res);
        //            }
        //            SqlExecuteResult sqlResult = new SqlExecuteResult();
        //            if (updateObj.Equals("1"))
        //            {
        //                //更新物料长度
        //                sqlResult = BLLCreator.Create<TN_WM_B_TRAY_ITEM_RELBLL>().UpdateItemQtyByTrayCode(trayCode, itemQty);
        //            }
        //            else
        //            {
        //                //更新托盘重量
        //                sqlResult = BLLCreator.Create<TN_WM_B_TRAY_ITEM_RELBLL>().UpdateTrayWeight(trayCode, weight);
        //            }
        //            if (sqlResult.Success)
        //            {
        //                //成功
        //                res.success = true;
        //            }
        //            else
        //            {
        //                res.errMsg = sqlResult.Exception.Message + sqlResult.Exception.StackTrace;
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        res.errMsg = "UpdateTrayItemInfo方法异常" + ex.Message + ex.StackTrace;
        //    }
        //    string result = JsonConvert.SerializeObject(res);
        //    Log.Info("更新托盘中物料的长度或重量", "UpdateTrayItemInfo接口返回参数:" + result);
        //    return result;
        //}
        #endregion
 
        #region 同步货位状态,货位状态不一致设为异常
        /// <summary>
        /// 同步货位状态,货位状态不一致设为异常
        /// </summary>
        /// <param name="synchroLocationEntity"></param>
        /// <returns></returns>
        /// <history>[HanHe(zh)] CREATED 2018/5/3</history>
        [HttpPost]
        public string SynchroLocation(List<SynchroLocationEntity> synchroLocationEntitys)
        {
            Log.Info("同步货位状态", "SynchroLocation接口请求参数:" + JsonConvert.SerializeObject(synchroLocationEntitys));
            ExternalResponse response = BLLCreator.Create<WmsApiBaseBLL>().SynchroLocation(synchroLocationEntitys);
            Log.Info("同步货位状态", "SynchroLocation接口返回参数:" + JsonConvert.SerializeObject(response));
            return JsonConvert.SerializeObject(response);
        }
        #endregion
 
        #region 改道
        /// <summary>
        /// 改道
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public string UpdateWay(dynamic param)
        {
            var logPara = new TOOLS.LOG.LogPara("改道");
            logPara.Push("接口请求参数:" + JsonConvert.SerializeObject(param));
 
            var result = new UpdateWayResult() { success = false, errCode = "200", location = "" };
            try
            {
                //任务号
                string taskNo = param.taskNo;
                //改道类型(起点/终点)
                string updateType = param.updateType;
                //改道类型对应的原因
                string reasonCode = param.reasonCode;
                if (string.IsNullOrEmpty(taskNo))
                {
                    result.errMsg = "任务号不可为空";
                    result.errCode = "102";
                }
                if (string.IsNullOrEmpty(updateType) || !(updateType.Equals("起点") || updateType.Equals("终点")))
                {
                    result.errMsg += " 改道类型不正确";
                    result.errCode = "102";
                }
                var currentTask = BLLCreator.Create<DapperBLL<TN_WM_TASKEntity>>().GetSingleEntity(new { CN_S_TASK_NO = taskNo });//BLLCreator.Create<TN_WM_TRANSPORT_TASKBLL>().GetTransportTask(taskNo);
                if (currentTask == null)
                {
                    result.errMsg += "未找到任务号:" + taskNo;
                    result.errCode = "102";
                }
                string changeLocation = param.changeLocation;
                if (string.IsNullOrEmpty(changeLocation))
                {
                    result.errCode = "102";
                    result.errMsg = "改道货位不能为空!";
                }
                else
                {
                    //Log.Info("改道", "UpdateWay接口changeLocation不为空,不需重新计算货位,改道货位为:" + changeLocation);
                    string type = updateType.Equals("起点") ? "start" : "end";
 
                    AutoBomLocationEntity locationModel = DALCreator.Create<TN_WMS_LOCATIONDAL>().GetModel(changeLocation);
                    var locationArea = DALCreator.Create<TN_AB_STOCK_LOCATIONDAL>().GetAreaModelByLocation(changeLocation);
                    var sqlResult = BLLCreator.Create<TN_WM_TASKBLL>().UpdateWay(currentTask, locationModel, locationArea, type);
                    if (!sqlResult.Success)
                        result.errMsg = sqlResult.Msg;
                    else
                    {
                        result.success = true;
                        result.errCode = "100";
                        result.location = changeLocation;
                    }
                }
 
                if (result.success)
                {
                    logPara.PushAndAdd("改道成功!");
                }
                else
                {
                    logPara.PushAndAdd("改道失败,原因:" + result.errMsg);
                }
            }
            catch (Exception ex)
            {
                result.errCode = "200";
                result.errMsg = "UpdateWay方法异常" + ex.Message + ex.StackTrace;
                logPara.PushAndAdd(ex);
            }
            return JsonConvert.SerializeObject(result);
        }
        #endregion
 
        #region 中策
        /// <summary>
        /// 改道
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public string ChangeWay(dynamic param)
        {
            var logPara = new TOOLS.LOG.LogPara("改道");
            logPara.Push("接口请求参数:" + JsonConvert.SerializeObject(param));
 
            var result = new ChangeWayResult() { success = false, errCode = "200", location = "" };
            try
            {
                //任务号
                string taskNo = param.taskNo;
                //改道类型(起点/终点)
                string updateType = param.updateType;
                //改道类型对应的原因
                string reasonCode = param.reasonCode;
                if (string.IsNullOrEmpty(taskNo))
                {
                    result.errMsg = "任务号不可为空";
                    result.errCode = "102";
                }
                if (string.IsNullOrEmpty(updateType) || !(updateType.Equals("起点") || updateType.Equals("终点")))
                {
                    result.errMsg += " 改道类型不正确";
                    result.errCode = "102";
                }
                if (taskNo.Split('_').Length <= 1)
                {
                    result.errMsg += " 主任务无法变更起点";
                    result.errCode = "102";
                }
                string preTaskNo = taskNo.Split('_')[0] + "_1";
                string navTaskNo = taskNo.Split('_')[1];
                if (navTaskNo != "2")
                {
                    result.errMsg += " 当前任务无前置任务,不支持变更起点";
                    result.errCode = "102";
                }
                var preTask = BLLCreator.Create<DapperBLL<TN_WM_TASKEntity>>().GetSingleEntity(new { CN_S_TASK_NO = preTaskNo });
                if (preTask == null)
                {
                    result.errMsg += "未找到此任务的主任务,任务号:" + taskNo;
                    result.errCode = "102";
                }
                var currentTask = BLLCreator.Create<DapperBLL<TN_WM_TASKEntity>>().GetSingleEntity(new { CN_S_TASK_NO = taskNo });
                if (currentTask == null)
                {
                    result.errMsg += "未找到此任务,任务号:" + taskNo;
                    result.errCode = "102";
                }
                // 主任务的立库接驳位
                string connectBit = preTask.CN_S_END_BIT;
                AutoBomLocationEntity locationModel = DALCreator.Create<TN_WMS_LOCATIONDAL>().GetModel(connectBit);
                var locationArea = DALCreator.Create<TN_AB_STOCK_LOCATIONDAL>().GetAreaModelByLocation(connectBit);
                if (locationModel == null)
                {
                    result.errMsg += "未找到接驳位货位:" + connectBit;
                    result.errCode = "102";
                }
                if (locationModel.CN_S_LOCATION_STATE != Constants.Location_State_Normal)
                {
                    result.errMsg += "接驳位货位:" + connectBit + "存在未执行完的任务";
                    result.errCode = "102";
                }
 
                if (result.errCode == "200")
                {
                    var sqlResult = BLLCreator.Create<TN_WM_TASKBLL>().ChangeWay(currentTask, locationModel, locationArea,"start");
 
                    if (!sqlResult.Success)
                        result.errMsg = sqlResult.Msg;
                    else
                    {
                        result.success = true;
                        result.errCode = "100";
                        result.location = connectBit;
                    }
                }
 
                if (result.success)
                {
                    logPara.PushAndAdd("改道成功!");
                }
                else
                {
                    logPara.PushAndAdd("改道失败,原因:" + result.errMsg);
                }
            }
            catch (Exception ex)
            {
                result.errCode = "200";
                result.errMsg = "ChangeWay方法异常" + ex.Message + ex.StackTrace;
                logPara.PushAndAdd(ex);
            }
            return JsonConvert.SerializeObject(result);
        }
 
        #endregion
 
        #region 宇寿 叫料
        /// <summary>
        /// 叫料
        /// </summary>
        /// <returns></returns>
        /// <history>[HanHe(zh)] CREATED 2018/5/3</history>
        [HttpPost]
        public OperateResult CallMaterial(JObject jsonData)
        {
            try
            {
                Log.Info("===>宇寿MES叫料传进来的参数:", jsonData.ToString());
                TN_WM_B_CALL_MATERIALEntity entity = JsonConvert.DeserializeObject<TN_WM_B_CALL_MATERIALEntity>(jsonData.ToString());
 
 
                if (!string.IsNullOrEmpty(entity.itemCode))
                {
                    //检查物料编码是否正确 
                    var item = BLLCreator.Create<TN_WMS_ITEMBLL>().GetItem(entity.itemCode);
                    if (item == null)
                    {
                        return OperateResult.Error("当前物料编码在AutoBom中未找到!");
                    }
                }
                #region
                StringBuilder strAreaCodes = new StringBuilder();
                string stockCode = string.Empty;
                List<AutoBomStockAreaEntity> areaModel = BLLCreator.Create<TN_AB_B_STOCK_AREABLL>().GetAreaByManyClass("中间库,混装区");
                Log.Info("===>宇寿MES叫料areaModel:", JsonConvert.SerializeObject(areaModel));
                string workFloor = string.Empty;
                if (entity.workBit.IndexOf("F1") >= 0)
                {
                    workFloor = "F1";
                }
                else if (entity.workBit.IndexOf("F2") >= 0)
                {
                    workFloor = "F2";
                }
                else if (entity.workBit.IndexOf("F3") >= 0)
                {
                    workFloor = "F3";
                }
                List<areaPriorClass> lstArea = new List<areaPriorClass>();
                foreach (AutoBomStockAreaEntity areaEntity in areaModel)
                {
                    if (areaEntity.CN_S_AREA_CODE.IndexOf(workFloor) >= 0 && areaEntity.CN_S_AREA_CODE.IndexOf("ZJK") >= 0)
                    {
                        areaPriorClass areaClass = new areaPriorClass();
                        areaClass.areaCode = areaEntity.CN_S_AREA_CODE;
                        areaClass.Prior = 1;
                        lstArea.Add(areaClass);
                        stockCode = areaEntity.CN_S_STOCK_CODE;
                    }
 
                }
                foreach (AutoBomStockAreaEntity abEntity in areaModel)
                {
 
                    if (abEntity.CN_S_AREA_CODE.IndexOf(workFloor) >= 0 && abEntity.CN_S_AREA_CODE.IndexOf("HZ") >= 0)
                    {
                        areaPriorClass areaClass = new areaPriorClass();
                        areaClass.areaCode = abEntity.CN_S_AREA_CODE;
                        areaClass.Prior = 2;
                        lstArea.Add(areaClass);
                        stockCode = abEntity.CN_S_STOCK_CODE;
                    }
 
                }
                if (lstArea.Count == 0)
                {
                    return OperateResult.Error("该叫料任务工作站点找不到对应的叫料库区!");
                }
                #endregion
 
                //调用出库算法,获取待出去托盘
                OutAssignEnitty oAe = new OutAssignEnitty()
                {
                    projectCode = "ys001",
                    lstAreaPrior = lstArea,
                    stockCode = stockCode,
                    itemCode = entity.itemCode,
                    traySpec = "",
                    itemQty = entity.qty,
                    lockLocation = true//是否需要锁定货位
                };
                OutAssignResultEntity oaEresult = BLLCreator.Create<Out_AlgorBLL>().OutAssign(oAe);
                if (!oaEresult.Success)
                {
                    Log.Error("调用出库算法,获取待出库托盘:", oaEresult.Msg);
                    return OperateResult.Error(oaEresult.Msg);//货位获取失败!
                }
                //转运货位-移动起点外层的货位
                var logPara = LogType.LogPara("叫料");
                var moveResult = BLLCreator.Create<YuShouApiBLL>().MoveLocation(oaEresult.locationCode, logPara);
                Log.Detail(logPara, "转运货位结果:" + moveResult.Success + ",信息:" + moveResult.Msg);
                if (!moveResult.Success)
                {
                    BLLCreator.Create<YuShouApiBLL>().RollBackLocation(moveResult, oaEresult.locationCode, logPara);
                    return OperateResult.Error(moveResult.Msg);
                }
 
                TrayOnShelfEntity trayOnEntity = new TrayOnShelfEntity();
                trayOnEntity.CN_S_DEVICE_NO = entity.workBit;   //目的货位码
                trayOnEntity.CN_S_LOCATION_CODE = oaEresult.locationCode; //建议货位码
                trayOnEntity.CN_S_END_AREA_CODE = oaEresult.areaCode;//目标库区
                trayOnEntity.CN_S_TRAY_CODE = oaEresult.trayCode; //起始托盘码
                trayOnEntity.CN_S_TASK_TYPE = "叫料"; //任务类型
                RedisUserEntity userEntity = new RedisUserEntity();
                userEntity.CN_S_LOGIN = "mes";
                userEntity.CN_S_NAME = "mes";
                OperateResult opResult = BLLCreator.Create<TN_WM_B_TRAY_LOCATIONBLL>().SimZTDownShelfCallMaterialYS(trayOnEntity, userEntity);
                if (!opResult.Success)
                {
                    BLLCreator.Create<YuShouApiBLL>().RollBackLocation(moveResult, oaEresult.locationCode, logPara);
                }
                else
                {
                    //增加库区量表
                    TN_WM_LOCATION_EXTEntity startlocation = BLLCreator.Create<TN_WM_LOCATION_EXTBLL>().GetExtModel(" where CN_S_LOCATION_CODE='" + oaEresult.locationCode + "'");
                    BLLCreator.Create<YuShouApiBLL>().AddAllocQty(oaEresult.trayCode, startlocation.CN_S_STOCK_CODE, startlocation.CN_S_AREA_CODE, logPara);
                }
                Log.Detail(logPara, "调用叫料结果:" + JsonConvert.SerializeObject(opResult));
                entity.CN_GUID = Guid.NewGuid().ToString();
                entity.CN_S_STATE = "未执行";
                entity.CN_T_CREATE = DateTime.Now;
                if (opResult.Success)
                {
                    opResult = BLLCreator.Create<WmsApiForWxysBLL>().CallMaterial(entity);
                }
 
                Log.Info("===>宇寿MES叫料返回结果:", JsonConvert.SerializeObject(opResult));
 
                return opResult;
            }
            catch (Exception ex)
            {
                Log.Info("CallMaterial异常:====>", ex.Message + ex.StackTrace);
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        #endregion
 
        #region 宇寿 送料
        /// <summary>
        /// 叫料
        /// </summary>
        /// <returns></returns>
        /// <history>[HanHe(zh)] CREATED 2018/5/3</history>
        [HttpPost]
        public OperateResult SendMaterial(JObject jsonData)
        {
 
            try
            {
                Log.Info("===>宇寿MES送料传进来的参数:", jsonData.ToString());
 
                TN_WM_B_SEND_MATERIALEntity entity = JsonConvert.DeserializeObject<TN_WM_B_SEND_MATERIALEntity>(jsonData.ToString());
                string deviceNo = entity.workBit;//起点
                string locationCode = "CK001-B-02-01";
                string endAreaCode = "";
                string trayCode = entity.trayNo;
 
                string stockCode = string.Empty;
                List<AutoBomStockAreaEntity> areaModel = BLLCreator.Create<TN_AB_B_STOCK_AREABLL>().GetAreaByManyClass("中间库,混装区");
                string workFloor = string.Empty;
                if (entity.workBit.IndexOf("F1") >= 0)
                {
                    workFloor = "F1";
                }
                else if (entity.workBit.IndexOf("F2") >= 0)
                {
                    workFloor = "F2";
                }
                else if (entity.workBit.IndexOf("F3") >= 0)
                {
                    workFloor = "F3";
                }
                List<areaPriorClass> lstArea = new List<areaPriorClass>();
                foreach (AutoBomStockAreaEntity areaEntity in areaModel)
                {
                    if (areaEntity.CN_S_AREA_CODE.IndexOf(workFloor) >= 0 && areaEntity.CN_S_AREA_CODE.IndexOf("ZJK") >= 0)
                    {
                        endAreaCode = areaEntity.CN_S_AREA_CODE;
                        stockCode = areaEntity.CN_S_STOCK_CODE;
                    }
 
                }
                foreach (AutoBomStockAreaEntity abEntity in areaModel)
                {
 
                    if (abEntity.CN_S_AREA_CODE.IndexOf(workFloor) >= 0 && abEntity.CN_S_AREA_CODE.IndexOf("HZ") >= 0)
                    {
                        endAreaCode = abEntity.CN_S_AREA_CODE;
                        stockCode = abEntity.CN_S_STOCK_CODE;
                    }
 
                }
                if (string.IsNullOrEmpty(endAreaCode))
                {
                    return OperateResult.Error("该送料任务工作站点找不到对应的入库库区!");
                }
                if (string.IsNullOrEmpty(locationCode))
                {
                    //调用算法计算终点货位
                    //调用入库算法,获取空货位
                    List<areaPriorClass> lstTmpArea = new List<areaPriorClass>();
                    lstTmpArea.Add(new areaPriorClass { areaCode = endAreaCode, Prior = 1 });
 
                    InAssignEntity iAe = new InAssignEntity()
                    {
                        lstAreaPrior = lstTmpArea,
                        logicAreaCode = "",
                        objectCode = trayCode,
                        projectCode = "ys001",
                        lockLocation = false//是否需要锁定货位
                    };
                    iAe.lstDevice = null;
                    InAssignResultEntity irEresult = BLLCreator.Create<In_AlgorBLL>().InAssign(iAe);
                    if (!irEresult.Success)
                    {
                        return OperateResult.Error(irEresult.Msg);//货位获取失败!
                    }
                    else
                    {
                        locationCode = irEresult.locationCode.ToString();
                    }
                }
                TrayOnShelfEntity trayOnEntity = new TrayOnShelfEntity();
                trayOnEntity.CN_S_DEVICE_NO = entity.workBit;   //目的货位码
                trayOnEntity.CN_S_LOCATION_CODE = locationCode; //建议货位码
                trayOnEntity.CN_S_END_AREA_CODE = endAreaCode;//目标库区
                trayOnEntity.CN_S_TRAY_CODE = trayCode; //起始托盘码
                trayOnEntity.CN_S_TASK_TYPE = "上架"; //任务类型
                RedisUserEntity userEntity = new RedisUserEntity();
                userEntity.CN_S_LOGIN = "mes";
                userEntity.CN_S_NAME = "mes";
                OperateResult result = BLLCreator.Create<TN_WM_B_TRAY_LOCATIONBLL>().SimZTShelfAutoYS(trayOnEntity, userEntity);
 
                entity.CN_GUID = Guid.NewGuid().ToString();
                entity.CN_S_STATE = "未执行";
                entity.CN_T_CREATE = DateTime.Now;
                if (result.Success)
                {
                    result = BLLCreator.Create<WmsApiForWxysBLL>().SendMaterial(entity);
                }
                return result;
                Log.Info("===>宇寿MES送料返回结果:", JsonConvert.SerializeObject(result));
                return result;
            }
            catch (Exception ex)
            {
                Log.Info("SendMaterial异常:====>", ex.Message + ex.StackTrace);
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        #endregion
 
        #region 宇寿 获取库存信息
        /// <summary>
        /// 叫料
        /// </summary>
        /// <returns></returns>
        /// <history>[HanHe(zh)] CREATED 2018/5/3</history>
        [HttpGet]
        public OperateResult GetStockQtyInfo(string itemName, string itemCode, string stockCode, string areaCode)
        {
 
            try
            {
                List<TN_WM_B_AREA_QTY_YSEntity> lstResult = BLLCreator.Create<WmsApiForWxysBLL>().GetStockQtyInfo(itemName, itemCode, stockCode, areaCode);
                return OperateResult.Succeed("", lstResult);
 
            }
            catch (Exception ex)
            {
                Log.Info("GetStockQtyInfo异常:====>", ex.Message + ex.StackTrace);
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        #endregion
 
        #region 宇寿 获取库存明细信息
        /// <summary>
        /// 叫料
        /// </summary>
        /// <returns></returns>
        /// <history>[HanHe(zh)] CREATED 2018/5/3</history>
        [HttpGet]
        public OperateResult GetStockQtyDetailList(string itemName, string itemCode, string stockCode, string areaCode)
        {
 
            try
            {
                List<TN_WM_B_STOCK_DETAIL_YSEntity> lstResult = BLLCreator.Create<WmsApiForWxysBLL>().GetStockQtyDetailList(itemName, itemCode, stockCode, areaCode);
                return OperateResult.Succeed("", lstResult);
            }
            catch (Exception ex)
            {
                Log.Info("GetStockQtyDetailList异常:====>", ex.Message + ex.StackTrace);
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        #endregion
 
        #region 宇寿 叫料送料延时反馈
        /// <summary>
        /// 叫料
        /// </summary>
        /// <returns></returns>
        /// <history>[HanHe(zh)] CREATED 2018/5/3</history>
        [HttpPost]
        public OperateResult WMSFeedbackResult(JObject jsonData)
        {
            try
            {
                Log.Info("===>宇寿MES叫料送料延时反馈传进来的参数:", jsonData.ToString());
                string result = WebApiManager.HttpMes_Post("YesoMedMes/WMSFeedbackResult", JsonConvert.SerializeObject(jsonData));
                MesResponse s = JsonConvert.DeserializeObject<MesResponse>(result);
                Log.Info("===>宇寿MES叫料送料延时反馈返回结果:", result);
                if (s.Success)
                {
                    return OperateResult.Succeed();
                }
                else
                {
                    return OperateResult.Error(s.Msg.ToString());
                }
 
 
            }
            catch (Exception ex)
            {
                Log.Info("SendMaterial异常:====>", ex.Message + ex.StackTrace);
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        #endregion
 
        #region 宇寿 整托叫料
        /// <summary>
        /// 叫料
        /// </summary>
        /// <returns></returns>
        /// <history>[HanHe(zh)] CREATED 2018/5/3</history>
        [HttpPost]
        public OperateResult CallMaterialTray(JObject jsonData)
        {
 
            try
            {
                Log.Info("===>宇寿MES叫料CallMaterialTray传进来的参数:", jsonData.ToString());
                TN_WM_B_CALL_MATERIALEntity entity = JsonConvert.DeserializeObject<TN_WM_B_CALL_MATERIALEntity>(jsonData.ToString());
                if (!string.IsNullOrEmpty(entity.itemCode))
                {
                    //检查物料编码是否正确 
                    var item = BLLCreator.Create<TN_WMS_ITEMBLL>().GetItem(entity.itemCode);
                    if (item == null)
                    {
                        return OperateResult.Error("当前物料编码在AutoBom中未找到!");
                    }
                }
                #region
                StringBuilder strAreaCodes = new StringBuilder();
                string stockCode = string.Empty;
                List<AutoBomStockAreaEntity> areaModel = BLLCreator.Create<TN_AB_B_STOCK_AREABLL>().GetAreaByManyClass("中间库,混装区");
                string workFloor = string.Empty;
                if (entity.workBit.IndexOf("F1") > 0)
                {
                    workFloor = "F1";
                }
                else if (entity.workBit.IndexOf("F2") > 0)
                {
                    workFloor = "F2";
                }
                else if (entity.workBit.IndexOf("F3") > 0)
                {
                    workFloor = "F3";
                }
                List<areaPriorClass> lstArea = new List<areaPriorClass>();
                foreach (AutoBomStockAreaEntity areaEntity in areaModel)
                {
                    if (areaEntity.CN_S_AREA_CODE.IndexOf(workFloor) > 0 && areaEntity.CN_S_AREA_CODE.IndexOf("ZJK") > 0)
                    {
                        areaPriorClass areaClass = new areaPriorClass();
                        areaClass.areaCode = areaEntity.CN_S_AREA_CODE;
                        areaClass.Prior = 1;
                        lstArea.Add(areaClass);
                        stockCode = areaEntity.CN_S_STOCK_CODE;
                    }
 
                }
                foreach (AutoBomStockAreaEntity abEntity in areaModel)
                {
 
                    if (abEntity.CN_S_AREA_CODE.IndexOf(workFloor) > 0 && abEntity.CN_S_AREA_CODE.IndexOf("HZ") > 0)
                    {
                        areaPriorClass areaClass = new areaPriorClass();
                        areaClass.areaCode = abEntity.CN_S_AREA_CODE;
                        areaClass.Prior = 2;
                        lstArea.Add(areaClass);
                        stockCode = abEntity.CN_S_STOCK_CODE;
                    }
 
                }
                if (lstArea.Count == 0)
                {
                    return OperateResult.Error("该叫料任务工作站点找不到对应的叫料库区!");
                }
                #endregion
 
                //调用出库算法,获取待出去托盘
                OutAssignEnitty oAe = new OutAssignEnitty()
                {
                    projectCode = "ys001",
                    lstAreaPrior = lstArea,
                    stockCode = stockCode,
                    itemCode = entity.itemCode,
                    traySpec = "",
                    itemQty = entity.qty,
                    lockLocation = true//是否需要锁定货位
                };
                OutAssignResultEntity oaEresult = BLLCreator.Create<Out_AlgorBLL>().OutAssign(oAe);
                if (!oaEresult.Success)
                {
                    Log.Error("调用出库算法,获取待出库托盘:", oaEresult.Msg);
                    return OperateResult.Error(oaEresult.Msg);//货位获取失败!
                }
                //转运货位-移动起点外层的货位
                var logPara = LogType.LogPara("叫料");
                var moveResult = BLLCreator.Create<YuShouApiBLL>().MoveLocation(oaEresult.locationCode, logPara);
                Log.Detail(logPara, "转运货位结果:" + moveResult.Success + ",信息:" + moveResult.Msg);
                if (!moveResult.Success)
                {
                    BLLCreator.Create<YuShouApiBLL>().RollBackLocation(moveResult, oaEresult.locationCode, logPara);
                    return OperateResult.Error(moveResult.Msg);
                }
 
                TrayOnShelfEntity trayOnEntity = new TrayOnShelfEntity();
                trayOnEntity.CN_S_DEVICE_NO = entity.workBit;   //目的货位码
                trayOnEntity.CN_S_LOCATION_CODE = oaEresult.locationCode; //建议货位码
                trayOnEntity.CN_S_END_AREA_CODE = oaEresult.areaCode;//目标库区
                trayOnEntity.CN_S_TRAY_CODE = oaEresult.trayCode; //起始托盘码
                trayOnEntity.CN_S_TASK_TYPE = "叫料"; //任务类型
                RedisUserEntity userEntity = new RedisUserEntity();
                userEntity.CN_S_LOGIN = "mes";
                userEntity.CN_S_NAME = "mes";
                var result = BLLCreator.Create<TN_WM_B_TRAY_LOCATIONBLL>().SimZTDownShelfCallMaterialYS(trayOnEntity, userEntity);
                if (!result.Success)
                {
                    BLLCreator.Create<YuShouApiBLL>().RollBackLocation(moveResult, oaEresult.locationCode, logPara);
                }
                else
                {
                    //增加库区量表
                    TN_WM_LOCATION_EXTEntity startlocation = BLLCreator.Create<TN_WM_LOCATION_EXTBLL>().GetExtModel(" where CN_S_LOCATION_CODE='" + oaEresult.locationCode + "'");
                    BLLCreator.Create<YuShouApiBLL>().AddAllocQty(oaEresult.trayCode, startlocation.CN_S_STOCK_CODE, startlocation.CN_S_AREA_CODE, logPara);
                }
                Log.Detail(logPara, "调用叫料结果:" + JsonConvert.SerializeObject(result));
                return result;
 
            }
            catch (Exception ex)
            {
                Log.Info("CallMaterialTray异常:====>", ex.Message + ex.StackTrace);
                return OperateResult.Error(ex.Message.ToString());
            }
        }
        #endregion
 
        #region 南通桑德 称重
 
        /// <summary>
        /// 大榜单 进厂 车牌号、车辆总重
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IHttpActionResult InCarPound(CarPoundPara data)
        {
            var logPara = LogType.LogPara("AMS上传大榜单-进厂");
            var response = BLLCreator.Create<WmsApiForNtsdBLL>().InCarPound(data.carNo, data.areaCode, data.weight, data.itemType, data.supplierCode, logPara);
            Log.Detail(logPara, response.Describe());
            return Json(response);
        }
 
        /// <summary>
        /// 大榜单 出厂
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public IHttpActionResult OutCarPound(CarPoundPara data)
        {
            var logPara = LogType.LogPara("AMS上传大榜单-出厂");
            var response = BLLCreator.Create<WmsApiForNtsdBLL>().OutCarPound(data.carNo, data.weight, logPara);
            Log.Detail(logPara, response.Describe());
            return Json(response);
        }
 
        [HttpGet]
        public IHttpActionResult GetErrorInfo()
        {
            return Json(CommResponse.Error("123"));
        }
 
        #endregion
 
        #region 南通桑德 根据货位找产线开工的物料
 
        /// <summary>
        /// 产线开工的物料
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public string GetItemByLocationForNt(dynamic obj)
        {
            var locationCode = obj.Value<string>("locationCode");
            var produceLineMapStr = JsonHelper.GetValue("produceLineMapping");
            List<ProduceLineMapDto> produceLineMaps = JsonConvert.DeserializeObject<List<ProduceLineMapDto>>(produceLineMapStr);
 
            foreach (var produceLineMap in produceLineMaps)
            {
                if (produceLineMap.locationCode.Equals(locationCode))
                {
                    var produceLine = produceLineMap.produceLine;
                    if (!string.IsNullOrEmpty(produceLine))
                    {
                        List<TN_SYS_MATERIAL_STOCKOUTEntity> materialStockOuts = BLLCreator.Create<MiddleLibraryBLL>().GetMaterialStockOut(produceLine);
                        if (materialStockOuts.Count > 0)
                        {
                            var materialStockOut = materialStockOuts[0];
                            var data = new
                            {
                                itemName = materialStockOut.CN_S_ITEM_NAME,
                                itemCode = materialStockOut.CN_S_ITEM_CODE,
                                produceLine = materialStockOut.CN_S_LINE
                            };
                            return JsonConvert.SerializeObject(DataResponse.Data(true, ErrorEnum.Normal, "", data));
                        }
                    }
                }
            }
 
            //var endBits = new Dictionary<string, string> { { "HCX01", "1" }, { "HCX02", "2" }, { "HCX03", "3" }, { "HCX04", "4" } };
            //if (endBits.ContainsKey(locationCode))
            //{ 
            //}
            return JsonConvert.SerializeObject(DataResponse.Data(false, ErrorEnum.SystemError, "", null));
        }
 
        #endregion
 
        #region 解绑货位
 
        [HttpGet]
        public IHttpActionResult UnbindLocation(string locationCode)
        {
            return Json(WmsApiBLLRoute.UnbindLocation(locationCode));
        }
 
        #endregion
 
        #region 获取货位状态 - 板焊
 
        /// <summary>
        /// 获取货位状态
        /// </summary>
        /// <param name="locationCode"></param>
        /// <returns></returns>
        [HttpPost]
        public string GetLocationUseState(dynamic obj)
        {
            var logPara = LogType.LogPara("获取货位状态-板焊");
            var result = "";
            try
            {
                var locationCode = obj.Value<string>("locationCode");
                if (string.IsNullOrEmpty(locationCode))
                {
                    return JsonConvert.SerializeObject(new { success = false, errMsg = "货位编码不能为空!", errCode = "-1", state = "" });
                }
                var locationExt = BLLCreator.Create<DapperBLL<TN_WM_LOCATION_EXTEntity>>().GetSingleEntity(new { CN_S_LOCATION_CODE = locationCode });
                if (locationExt == null)
                {
                    return JsonConvert.SerializeObject(new { success = false, errMsg = "未找到当前货位!", errCode = "-1", state = "" });
                }
                result = JsonConvert.SerializeObject(new { success = true, errMsg = "成功!", errCode = "0", state = locationExt.CN_S_LOCATION_STATE == "正常" ? locationExt.CN_S_USE_STATE : locationExt.CN_S_LOCATION_STATE });
                Log.Detail(logPara, result);
                return result;
            }
            catch (Exception ex)
            {
                return JsonConvert.SerializeObject(new { success = false, errMsg = ex.Message, errCode = "-1", state = "" });
            }
        }
 
        #endregion
 
        #region 同步服务测试
 
        [HttpGet]
        public IHttpActionResult TestSyncJob()
        {
            NtErpPoundJob job = new NtErpPoundJob();
            job.Run(new LogPara("同步服务测试"));
            return Json("成功");
        }
 
        [HttpGet]
        public IHttpActionResult TestEnum()
        {
            var temp = EnumExtensions.GetEnumByName<CheckStateEnum>("EEEE");
            return Json(EnumExtensions.GetDescription(temp));
        }
 
        #endregion
 
        #region 泰州隆基测试
 
        [HttpPost]
        public OperateResult SendAmsTask(JObject jsonData)
        {
            try
            {
                TN_WM_TRANSPORT_TASKEntity entity = JsonConvert.DeserializeObject<TN_WM_TRANSPORT_TASKEntity>(jsonData.ToString());
                AutoBomLocationEntity locationEntity = DALCreator.Create<TN_WMS_LOCATIONDAL>().GetModel(entity.CN_S_START_BIT);
                entity.CN_S_STOCK_CODE = locationEntity.CN_S_STOCK_CODE;
                entity.CN_N_PRIORITY = 1;
                //  entity.CN_S_END_BIT = GetEndBit(entity.CN_S_START_BIT);
                string postData = "{\"appCode\":\"" + Constants.appCode + "\",\"ruleName\":\"" + Constants.Rule_TransTaskNo + "\",\"orgId\":\"\",\"orgFlag\":\"0\"}";
                string taskNo = WebApiManager.HttpAutoBom_Post("api/BillRule/GenBillNo", postData);
                if (string.IsNullOrEmpty(taskNo))
                {
                    return OperateResult.Error("任务号生成失败,请检查autobom中是否配置了转运任务号生成规则!");
                }
                entity.CN_S_TASK_NO = taskNo;
                OperateResult re = new OtherSysApi().SendAmsCreateTaskLJ(entity);
                if (!re.Success)
                {
                    throw new Exception("SendAmsCreateTask异常:" + re.Msg);
                }
                else
                {
                    return OperateResult.Succeed();
                }
            }
            catch (Exception ex)
            {
                Log.Error("SendAmsTask异常:====>", ex.Message + ex.StackTrace);
                return OperateResult.Error(ex.Message);
            }
 
        }
        public string GetEndBit(string startBit)
        {
            string str = string.Empty;
            if (startBit.IndexOf("A") > 0)
            {
                str = "A-RGSL01";
            }
            else if (startBit.IndexOf("B") > 0)
            {
                str = "B-RGSL01";
            }
            else if (startBit.IndexOf("C") > 0)
            {
                str = "C-RGSL01";
            }
            else if (startBit.IndexOf("D") > 0)
            {
                str = "D-RGSL01";
            }
            return str;
        }
        [HttpGet]
        public OperateResult GetMesInfo(string trayCode)
        {
            try
            {
                var result = WebApiManager.HttpMes_Auth_Get("/api/values/?lotsn=" + trayCode, "");
                var mesStackTrayDto = JsonConvert.DeserializeObject<MesStackTrayDto>(result);
                if (mesStackTrayDto.RetVal.Equals("true"))
                {
                    //var mesStackTrayEntity = new MesStackTrayEntity().Map(mesStackTrayDto);
                    // var result2 = BLLCreator.Create<DapperBLL<MesStackTrayEntity>>().Add(mesStackTrayEntity, null);
                    return OperateResult.Succeed(null, mesStackTrayDto);
                }
                else
                {
                    return OperateResult.Error(mesStackTrayDto.ErrMsg);
                }
            }
            catch (Exception ex)
            {
                Log.Error("GetMesInfo异常:====>", ex.Message + ex.StackTrace);
                return OperateResult.Error(ex.Message);
            }
 
        }
 
        #endregion
 
        #region 海潮中策
 
        /// <summary>
        /// 任务下发接口
        /// </summary>
        /// <param name="jsonData"></param>
        /// <returns></returns>
        [HttpPost]
        public object InWorkArea(dynamic jsonData)
        {
            var logPara = LogType.LogPara("任务下发");
 
            ZCReceiveTaskEntity sendTaskEntity = JsonConvert.DeserializeObject<ZCReceiveTaskEntity>(jsonData.ToString());
 
            if (string.IsNullOrEmpty(sendTaskEntity.BUSI_TYPE))
            {
                Log.Detail(logPara, "ZCSendTask任务下发失败,缺少参数BUSI_TYPE。" + jsonData.ToString());
                return new
                {
                    success = false,
                    code = -1,
                    lastTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    message = "缺少参数BUSI_TYPE"
                };
            }
            if (string.IsNullOrEmpty(sendTaskEntity.Location_From) && string.IsNullOrEmpty(sendTaskEntity.Location_To))
            {
                Log.Detail(logPara, "ZCSendTask任务下发失败,起点和终点同时为空。" + jsonData.ToString());
                return new
                {
                    success = false,
                    code = -1,
                    lastTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    message = "缺少起点Location_From或终点Location_To"
                };
            }
            if (string.IsNullOrEmpty(sendTaskEntity.task_no))
            {
                Log.Detail(logPara, "ZCSendTask任务下发失败,缺少参数task_no。" + jsonData.ToString());
                return new
                {
                    success = false,
                    code = -1,
                    lastTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    message = "缺少参数task_no"
                };
            }
 
            Log.Detail(logPara, "ZCSendTask任务下发传递参数:" + jsonData.ToString());
 
            //调用ReceiveTask方法保存至中间库
            var result = BLLCreator.Create<WmsApiBaseBLL>().ReceiveTask(sendTaskEntity);
            return new
            {
                success = result.Success,
                code = result.Success ? 0 : -1,
                lastTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                message = result.Msg
            };
        }
 
        #endregion
    }
}