WebApiController.cs
50.3 KB
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
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using RCS.Dal;
using RCS.Model.Comm;
using RCS.Model.Entity;
using RCS.Model.ManualModel;
using RCS.Model.WebApi.Request;
using RCS.WinClient.Common;
using RCS.WinClient.Service;
using SqlSugar;
namespace RCS.WinClient.WebApi.Service
{
[ApiController]
[Route("api/[controller]/[action]")]
public class WebApiController : ControllerBase
{
/// <summary>
/// 增删改RFID值
/// </summary>
/// <param name="point">点实体类</param>
/// <returns></returns>
[HttpPost]
public BllResult ChangePoint([FromBody] Base_Point point)
{
try
{
string json = JsonConvert.SerializeObject(point);
App.ExFile.MessageWebApi("WebApiMsg", "接口(ChangePoint)," + json + "\r");
string strBarcode = point.Barcode;
string areaType = point.AreaType;
string type = point.Type;
var currentStation = App.StationList.FirstOrDefault(t => t.Barcode == point.Barcode);
point.PreBarcode = currentStation == null ? "" : currentStation.PreBarcode;
point.BarcodeValue = point.Barcode;
switch (type)
{
case "insert":
if (!App.PointList.Exists(a => a.Barcode == strBarcode && a.AreaType == areaType))
{
var insertSql = UpdateManage.SqlPoint(point, type);
if (!insertSql.IsSuccess) return BllResult.Error(1, "插入RFID失败!");
}
break;
case "delete":
var delPointSql = UpdateManage.SqlPoint(point, type);
if (!delPointSql.IsSuccess) return BllResult.Error(1, "删除RFID失败!");
App.PointList.RemoveAll(a => a.AreaType == point.AreaType);
//App.Config_PointList.RemoveAll(a => a.areaType == point.AreaType);
break;
case "save":
var pointResult = Init.DownPoint();
if (!pointResult.IsSuccess) return BllResult.Error(pointResult.Data);
//bool sqlConfigPoint = UpdateManage.SqlConfigPointMsg(App.PointList.FindAll(a => a.AreaType == areaType));
//if (!sqlConfigPoint) return BllResult.Error(1, "旋转点绑定失败!");
//获取所旋转点,将旋转点周围点放到一个集合中,插入数据库中
//Init.DownConfigPoint(ref ErrMsg);
//if(ErrMsg != "") return BllResult.Error(1, ErrMsg);
break;
case "simInsert":
if (App.DemoPointList.Exists(a => a.Barcode == strBarcode && a.AreaType == areaType))
return BllResult.Error(1, "当前" + areaType + "区域已存在相同RFID!");
var simInsertSql = UpdateManage.SqlDemoPoint(point, type);
if (!simInsertSql.IsSuccess) return BllResult.Error(1, "插入RFID失败!");
break;
case "simDelete":
var simDeleteSql = UpdateManage.SqlDemoPoint(point, type);
if (!simDeleteSql.IsSuccess) return BllResult.Error(1, "删除RFID失败!");
App.DemoPointList.RemoveAll(a => a.AreaType == point.AreaType);
break;
case "simSave":
var demoPointResult = Init.DownDemoPoint();
if (!demoPointResult.IsSuccess) return BllResult.Error(demoPointResult.Data);
break;
default:
return BllResult.Error(1, "类型错误");
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
return BllResult.Success(0, "建立成功");
}
/// <summary>
/// 增删改AGV信息
/// </summary>
/// <param name="agv"></param>
/// <returns></returns>
[HttpPost]
public BllResult ChangeAGV([FromBody] Base_Agv agv)
{
try
{
string json = JsonConvert.SerializeObject(agv);
App.ExFile.MessageWebApi("WebApiMsg", "接口(ChangeAGV)," + json + "\r");
string strAgvNo = agv.AgvNo;
string agvGroup = agv.Group;
agv.AgvState = 0;
agv.Voltage = 0;
agv.IsOnline = false;
agv.StopReason = string.Empty;
string type = agv.Type;
if (strAgvNo == "" || agvGroup == "") return BllResult.Error(1, "AGV输入有误或群组为空!");
Base_Agv getAgv = App.AgvList.FirstOrDefault(a => a.AgvNo == strAgvNo);
switch (type)
{
case "insert":
if (getAgv != null) return BllResult.Error(1, "已经存在当前AGV!");
var insertSql = UpdateManage.SqlAgvMsg(agv, type);
if (!insertSql.IsSuccess) return BllResult.Error(1, "插入AGV失败!");
//插入数据库的车,插到缓存表中
App.AgvList.Add(agv);
break;
case "update":
if (getAgv == null) return null;//BllResult.Error(1, "不存在更改的AGV!");
if (!agv.IsEnable && getAgv.AgvTask != null)
{
if (getAgv.AgvTask.TaskType == "回家" || getAgv.AgvTask.TaskType == "充电" ||
getAgv.AgvTask.TaskType == "取消充电")
{
getAgv.AgvTask.TaskState = EnumMsg.TaskState.手动删除;
TaskManage.TaskDelete(getAgv.AgvTask.TaskNo);
}
else
{
return BllResult.Error(1, "当前AGV存在任务,请删除任务后,再下线!");
}
}
//getAgv.IsEnable = agv.IsEnable;
//getAgv.ChooseStation = agv.ChooseStation;
//getAgv.Group = agv.Group;
////getAgv.agvAreaType = agv.agvAreaType;
//getAgv.CurrMap = agv.CurrMap;
//if (!getAgv.IsEnable)
//{
// getAgv.Barcode = "0";
// getAgv.IsOnline = false;
// getAgv.AgvState = 0;
// List<Base_Point> agvLockedList = App.PointList.Where(a => a.LockedAgv == getAgv).ToList();
// foreach (Base_Point point in agvLockedList)
// {
// point.LockedAgv = null;
// }
//}
//UpdateManage.UpdateAgvMsg(getAgv);
break;
case "delete":
if (getAgv == null) return BllResult.Error(1, "不存在当前AGV!");
var delSql = UpdateManage.SqlAgvMsg(agv, type);
if (!delSql.IsSuccess) return BllResult.Error(1, "数据库删除失败!");
App.AgvList.Remove(getAgv);
break;
default:
return BllResult.Error(1, "类型错误");
}
}
catch (Exception ex)
{
App.ExFile.MessageWebApi("WebApiError", "接口(ChangeAGV)," + ex.ToString() + "\r");
return BllResult.Error(1, ex.ToString());
}
return BllResult.Success(0, "建立成功");
}
/// <summary>
/// 站台处理,因为2个站台对应1个点位,所以特别处理
/// </summary>
/// <param name="station"></param>
/// <returns></returns>
[HttpPost]
public BllResult ChangeStation([FromBody] Base_Station station)
{
try
{
string json = JsonConvert.SerializeObject(station);
App.ExFile.MessageWebApi("WebApiMsg", "接口(ChangeStation)," + json + "\r");
station.ID = 0;
station.Tim = 0;
if (station.PreBarcode == null)
{
station.PreBarcode = "";
}
else
{
var temp = station.PreBarcode.Split('#');
if (temp.Length > 1)
{
station.PreBarcode = temp[0];
station.Tim = int.Parse(temp[1]);
}
}
//现在是2个站台对应1个料点,站台的命名规则是“站台名称-层数”,所以-前面相同的就是同1个站台
var stationName = station.Name.Contains('-') ? station.Name.Split('-')[0] : station.Name;
if (station.Type == "insert" || station.Type == "webpointupdate" || station.Type == "webpointupdate")
{
var list = App.StationList.Where(t => t.Name == station.Name || (t.Name.StartsWith(stationName) && t.Name.Contains('-'))).ToList();
if (list.Count == 0)
{
var insertSql = UpdateManage.SqlStationMsg(station, "insert");
if (!insertSql.IsSuccess)
{
return BllResult.Error(1, "插入站台失败!");
}
App.StationList.Add(station);
}
else
{
var names = list.Select(t => t.Name).ToArray();
var isResult1 = UpdateManage.UpdateStationBarcode(names, station);
if (!isResult1.IsSuccess) return BllResult.Error(1, "更新站台失败!");
}
}
}
catch (Exception ex)
{
App.ExFile.MessageWebApi("WebApiError", "接口(ChangeStation)," + ex.ToString() + "\r");
return BllResult.Error(1, ex.StackTrace);
}
return BllResult.Success(0, "建立成功");
}
#region 旧的站台处理,因为当前2个站台对应1个点位,旧的1个站台1个点位不适合当前项目,先注释
///// <summary>
///// 增删改站台信息
///// </summary>
///// <param name="station"></param>
///// <returns></returns>
//[HttpPost]
//public BllResult ChangeStation([FromBody] Base_Station station)
//{
// try
// {
// string json = JsonConvert.SerializeObject(station);
// App.ExFile.MessageWebApi("WebApiMsg", "接口(ChangeStation)," + json + "\r");
// int stationType = (int)station.StationType;
// string stationArea = station.Area;
// bool isEnable = station.IsEnable;
// bool isLocked = station.IsLocked;
// long id = station.ID;
// string strStationNo = station.Name;
// if (station.PreBarcode != null)
// {
// station.Tim = int.Parse(station.PreBarcode.Split('#')[1]);
// station.PreBarcode = station.PreBarcode.Split('#')[0];
// }
// else
// {
// station.Tim = 0;
// station.PreBarcode = "";
// }
// string type = station.Type;
// switch (type)
// {
// case "insert":
// Base_Station insertcs = App.StationList.Find(a => a.ID == id);
// if (insertcs != null) break;
// var insertSql = UpdateManage.SqlStationMsg(station, type);
// if (!insertSql.Success) return BllResult.Error(1, "插入站台失败!");
// App.StationList.Add(station);
// break;
// case "webpointupdate":
// Base_Station cs = App.StationList.Find(a => a.ID == id);
// if (cs == null)
// {
// var webpointInsert = UpdateManage.SqlStationMsg(station, "insert");
// if (!webpointInsert.Success) return BllResult.Error(1, "插入站台失败!");
// }
// else
// {
// var isResult = UpdateManage.SqlStationMsg(station, type);
// if (!isResult.Success) return BllResult.Error(1, "更新站台失败!");
// }
// break;
// case "update":
// Base_Station upStation = App.StationList.Find(a => a.Name == strStationNo);
// if (upStation == null) return BllResult.Error(1, "未获取到站台!");
// var isResult1 = UpdateManage.UpdateStation(station);
// if (!isResult1.Success) return BllResult.Error(1, "更新站台失败!");
// break;
// case "delete":
// var delSql = UpdateManage.SqlStationMsg(station, type);
// App.StationList.RemoveAll(a => a.Name == strStationNo);
// break;
// default:
// return BllResult.Error(1, "类型错误");
// }
// }
// catch (Exception ex)
// {
// App.ExFile.MessageWebApi("WebApiError", "接口(ChangeStation)," + ex.ToString() + "\r");
// return BllResult.Error(1, ex.StackTrace);
// }
// return BllResult.Sucess(0, "建立成功");
//}
#endregion
/// <summary>
/// 关机
/// </summary>
/// <param name="offAgv"></param>
/// <returns></returns>
[HttpPost]
public BllResult CloseAgv([FromBody] ReqSingleAgv offAgv)
{
try
{
string json = JsonConvert.SerializeObject(offAgv);
App.ExFile.MessageWebApi("WebApiMsg", "接口(OffAgv)," + json + "\r");
App.offAgv = 1;
App.offTime = DateTime.Now;
App.OffAgvNos.Clear();
if (offAgv.OffType == 2)
{
Base_Agv getAgv = App.AgvList.FirstOrDefault(a => a.AgvNo == offAgv.AgvNo);
if (getAgv != null)
{
App.OffAgvNos.Add(offAgv.AgvNo);
}
}
else if (offAgv.OffType == 1)
{
foreach (Base_Agv agv in App.AgvList.FindAll(a => a.IsEnable && a.IsOnline))
{
App.OffAgvNos.Add(agv.AgvNo);
if (agv.AgvState == EnumMsg.AGVState.充电中 && agv.AgvTask == null)
{
var buildresult = TaskManage.TaskBuild("取消充电", "", "", 1, agv.AgvNo, agv.Barcode, agv.Barcode, "", "", "");
if (!buildresult.IsSuccess)
{
return BllResult.Error(1, buildresult.Message);
}
}
}
}
}
catch (Exception ex)
{
return BllResult.Error(1, ex.ToString());
}
return BllResult.Success(0, "建立成功");
}
/// <summary>
/// 连接需要单步控制的AGV
/// </summary>
/// <param name="linkAgv"></param>
/// <returns></returns>
[HttpPost]
public BllResult LinkAgv([FromBody] ReqSingleAgv linkAgv)
{
try
{
string json = JsonConvert.SerializeObject(linkAgv);
App.ExFile.MessageWebApi("WebApiMsg", "接口(LinkAgv)," + json + "\r");
string agvNo = linkAgv.AgvNo;
bool link = linkAgv.IsLink;
Base_Agv agv = App.AgvList.FirstOrDefault(a => a.AgvNo == agvNo);
//if (agv == null || !agv.isOnline || !agv.isEnable) return BllResult.Error(1, "AGV编号输入错误!");
if (link)
{
if (App.SingleControlList.Exists(a => a.AgvNo == agvNo)) return BllResult.Error(1, "当前AGV已被操作!");
//连接agv
SingleControl singleAgv = new SingleControl();
singleAgv.AgvNo = agvNo;
singleAgv.Action = 200;
App.SingleControlList.Add(singleAgv);
}
else
{
//断开AGV
SingleControl singleAgv = App.SingleControlList.Find(a => a.AgvNo == agvNo);
if (singleAgv == null) return BllResult.Success(0, "建立成功");
singleAgv.Action = 209;
}
}
catch (Exception ex)
{
return BllResult.Error(1, ex.ToString());
}
return BllResult.Success(0, "建立成功");
}
/// <summary>
/// 单步控制AGV
/// </summary>
/// <param name="linkAgv"></param>
/// <returns></returns>
[HttpPost]
public BllResult ControlAgv([FromBody] ReqSingleAgv linkAgv)
{
try
{
string json = JsonConvert.SerializeObject(linkAgv);
App.ExFile.MessageWebApi("WebApiMsg", "接口(ControlAgv)," + json + "\r");
SingleControl singleAgv = App.SingleControlList.Find(a => a.AgvNo == linkAgv.AgvNo);
if (singleAgv == null) return BllResult.Error(1, "请断开连接,并重新连接AGV!");
singleAgv.Action = linkAgv.Action;
Console.WriteLine(singleAgv.Action);
}
catch (Exception ex)
{
return BllResult.Error(1, ex.ToString());
}
return BllResult.Success(0, "建立成功");
}
/// <summary>
/// 满电,安全,危险电量更改
/// </summary>
/// <param name="keyValue"></param>
/// <returns></returns>
[HttpPost]
public BllResult KeyValue([FromBody] Config_KeyValue keyValue)
{
try
{
string json = JsonConvert.SerializeObject(keyValue);
App.ExFile.MessageWebApi("WebApiMsg", "接口(KeyValue)," + json + "\r");
//switch (keyValue.KeyVariable)
//{
// case "Cfull":
// App.FullCharge = float.Parse(keyValue.Value);
// break;
// case "Savety":
// App.SafeCharge = float.Parse(keyValue.Value);
// break;
// case "Danger":
// App.DangerCharge = float.Parse(keyValue.Value);
// break;
// case "MinCharges":
// App.MinCharges = float.Parse(keyValue.Value);
// break;
// default:
// return BllResult.Error(1, "类型错误");
//}
BaseDal<Config_KeyValue> _keyValueDb = new BaseDal<Config_KeyValue>();
var updateresult = _keyValueDb.Update(it => it.KeyVariable == keyValue.KeyVariable, it => new Config_KeyValue()
{
Value = keyValue.Value,
});
if (!updateresult.IsSuccess) return BllResult.Error(1, "更新电量失败!");
}
catch (Exception ex)
{
App.ExFile.MessageWebApi("WebApiError", "接口(KeyValue)," + ex.StackTrace + "\r");
return BllResult.Error(1, ex.StackTrace);
}
return BllResult.Success(0, "建立成功");
}
/// <summary>
/// 对未执行的任务状态更改,暂停/删除
/// </summary>
/// <param name="keyValue"></param>
/// <returns></returns>
[HttpPost]
public BllResult TaskChange([FromBody] Base_Task fTask)
{
try
{
string json = JsonConvert.SerializeObject(fTask);
App.ExFile.MessageWebApi("WebApiMsg", "接口(TaskChange)," + json + "\r");
//string strTaskNo = fTask.TaskNo;
//string strTaskState = fTask.TaskState;
//Base_Task getFTask = App.TaskList.FirstOrDefault(a => a.TaskNo == strTaskNo);
//if (getFTask == null) return BllResult.Error(1, "当前任务已被删除,无法操作");
switch (fTask.TaskState)
{
case EnumMsg.TaskState.手动完成:
case EnumMsg.TaskState.手动删除:
//getFTask.TaskState = fTask.TaskState;
var strResult = TaskManage.TaskDelete(fTask.TaskNo);
if (!strResult.IsSuccess)
return BllResult.Error(1, strResult.Message);
break;
default:
return BllResult.Error(1, "类型错误");
}
}
catch (Exception ex)
{
App.ExFile.MessageWebApi("WebApiError", "接口(TaskChange)," + ex.ToString() + "\r");
return BllResult.Error(1, ex.ToString());
}
return BllResult.Success(0, "建立成功");
}
/// <summary>
/// 任务分解
/// </summary>
/// <param name="config_TaskSplit"></param>
/// <returns></returns>
[HttpPost]
public BllResult TaskSplit([FromBody] ReqTaskSplit config_TaskSplit)
{
try
{
string json = JsonConvert.SerializeObject(config_TaskSplit);
App.ExFile.MessageWebApi("WebApiMsg", "接口(TaskSplit)," + json + "\r");
BaseDal<Config_TaskSplit> _taskSplitDb = new BaseDal<Config_TaskSplit>();
//2取3放9停
string taskID = config_TaskSplit.TaskID;
int intSerialNo = config_TaskSplit.SeriaNo;
int agvTaskType = (int)config_TaskSplit.AgvTaskType;
Base_Point fromPoint = App.PointList.FirstOrDefault(a => a.Barcode == config_TaskSplit.FromPoint);
Base_Point toPoint = App.PointList.FirstOrDefault(a => a.Barcode == config_TaskSplit.ToPoint);
int waitTime = config_TaskSplit.WaitTime;
string type = config_TaskSplit.Type;
//任务ID重复,删除已经存在的任务ID,添加新的ID
if (App.Config_TaskSplitList.Exists(a => a.TaskType == taskID && intSerialNo == 1) || type == "delete")
{
var deleteresult = _taskSplitDb.Delete(it => it.TaskType == taskID);
if (!deleteresult.IsSuccess)
{
return BllResult.Error(1, "删除任务分解失败!");
}
//插入数据库的车,插到缓存表中
App.Config_TaskSplitList.RemoveAll(a => a.TaskType == config_TaskSplit.TaskID);
}
if (type == "insert")
{
//当前任务ID最大编号
int oldSerialNo = 0;
if (intSerialNo > 1)
{
oldSerialNo = App.Config_TaskSplitList.Where(a => a.TaskType == taskID).Max(b => b.SerialNo);
}
List<Config_TaskSplit> listSplits = new List<Config_TaskSplit>();
int index = 0;
if (fromPoint != null && fromPoint.AreaType != toPoint.AreaType)
{
index = 3;
}
else
{
index = 2;
if (fromPoint != null && fromPoint.AreaType == toPoint.AreaType && fromPoint.AreaType == "P5_C区_1F" && intSerialNo != 3)
{
index = 4;
}
}
for (int i = 1; i <= index; i++)
{
Config_TaskSplit taskSplit = new Config_TaskSplit();
taskSplit.TaskType = taskID;
taskSplit.SerialNo = oldSerialNo + i;
taskSplit.TaskRequestType = 0;
if (i % index == 1)
{
taskSplit.AgvTaskType = EnumMsg.ActionType.普通行走;
if (fromPoint == null)
{
taskSplit.FromPoint = EnumMsg.ConfigToFromPoint.小车当前点;
taskSplit.ToPoint = Extends.ToEnum<EnumMsg.ConfigToFromPoint>(toPoint.Barcode);
}
else
{
taskSplit.FromPoint = Extends.ToEnum<EnumMsg.ConfigToFromPoint>(fromPoint.Barcode);
if (index == 2)
{
taskSplit.ToPoint = Extends.ToEnum<EnumMsg.ConfigToFromPoint>(toPoint.Barcode);
}
else if (index == 3)
{
//跨區域獲取終點最近电梯点
taskSplit.ToPoint =
Extends.ToEnum<EnumMsg.ConfigToFromPoint>(ComnMethod.GetMinLiftPoint(toPoint).Barcode);
}
else
{
//同區域跨兩個電梯獲取起點最近電梯點
taskSplit.ToPoint =
Extends.ToEnum<EnumMsg.ConfigToFromPoint>(ComnMethod.GetMinLiftPoint(fromPoint).Barcode);
}
}
}
else if (i % index == 2 || i % index == 3)
{
taskSplit.AgvTaskType = EnumMsg.ActionType.普通行走;
if (index == 4)
{
if (i % index == 2)
{
taskSplit.FromPoint =
Extends.ToEnum<EnumMsg.ConfigToFromPoint>(ComnMethod.GetMinLiftPoint(fromPoint).Barcode);
taskSplit.ToPoint =
Extends.ToEnum<EnumMsg.ConfigToFromPoint>(ComnMethod.GetMinLiftPoint(toPoint).Barcode);
}
else
{
taskSplit.FromPoint =
Extends.ToEnum<EnumMsg.ConfigToFromPoint>(ComnMethod.GetMinLiftPoint(toPoint).Barcode);
taskSplit.ToPoint = Extends.ToEnum<EnumMsg.ConfigToFromPoint>(toPoint.Barcode);
}
}
else if (index == 3)
{
taskSplit.FromPoint =
Extends.ToEnum<EnumMsg.ConfigToFromPoint>(ComnMethod.GetMinLiftPoint(toPoint).Barcode);
taskSplit.ToPoint = Extends.ToEnum<EnumMsg.ConfigToFromPoint>(toPoint.Barcode);
}
}
else
{
taskSplit.AgvTaskType = (EnumMsg.ActionType)agvTaskType;
taskSplit.FromPoint = Extends.ToEnum<EnumMsg.ConfigToFromPoint>(toPoint.Barcode);
taskSplit.ToPoint = Extends.ToEnum<EnumMsg.ConfigToFromPoint>(toPoint.Barcode);
taskSplit.WaitTime = waitTime;
}
if (i % index == 2 || i % index == 1 || i % index == 3)
{
Config_TaskSplit beforeSplit = App.Config_TaskSplitList.Find(a => a.SerialNo == taskSplit.SerialNo - 1
&& a.TaskType == taskID);
if (intSerialNo > 1 && ((beforeSplit != null && beforeSplit.AgvTaskType == EnumMsg.ActionType.上升到顶)
|| ((listSplits.Count == 1 || listSplits.Count == 2) && listSplits.Exists(a => a.IsCarry))))
{
taskSplit.IsCarry = true;
}
else
{
taskSplit.IsCarry = false;
}
}
listSplits.Add(taskSplit);
}
foreach (Config_TaskSplit split in listSplits)
{
#region 更改taskRequestType
//if (Split.intSerialNo == 1) Split.taskRequestType = EnumMsg.TaskRequestType.取货请求;
//if (Split.intSerialNo == 2) Split.taskRequestType = EnumMsg.TaskRequestType.取货完成请求;
#endregion 更改taskRequestType
var insertresult = _taskSplitDb.Insert(split);
if (!insertresult.IsSuccess)
{
return BllResult.Error(1, "插入任务分解失败!");
}
//插入数据库的车,插到缓存表中
App.Config_TaskSplitList.Add(split);
}
}
else if (type != "delete")
{
return BllResult.Error(1, "类型错误");
}
}
catch (Exception ex)
{
App.ExFile.MessageWebApi("WebApiError", "接口(TaskSplit)," + ex.ToString() + "\r");
return BllResult.Error(1, ex.ToString());
}
return BllResult.Success(0, "建立成功");
}
/// <summary>
/// 任务群组绑定
/// </summary>
/// <param name="taskAgv"></param>
/// <returns></returns>
[HttpPost]
public BllResult TaskAgvGroup([FromBody] Config_TaskAgvGroup taskAgv)
{
try
{
string json = JsonConvert.SerializeObject(taskAgv);
App.ExFile.MessageWebApi("WebApiMsg", "接口(TaskAgvGroup)," + json + "\r");
switch (taskAgv.Type)
{
case "insert":
var insertresult = UpdateManage.SqlTaskAgvGroup(taskAgv, taskAgv.Type);
if (!insertresult.IsSuccess) return BllResult.Error(1, "插入任务AGV群组绑定失败");
App.TaskAgvGroupList.Add(taskAgv);
break;
case "delete":
var isTrue = App.TaskAgvGroupList.Exists(a => a.AgvGroup == taskAgv.AgvGroup && a.TaskType == taskAgv.AgvGroup);
if (!isTrue) { return BllResult.Success(0, "建立成功"); }
var deleteresult = UpdateManage.SqlTaskAgvGroup(taskAgv, taskAgv.Type);
if (!deleteresult.IsSuccess) return BllResult.Error(1, "删除任务AGV群组绑定失败");
App.TaskAgvGroupList.Remove(taskAgv);
break;
default:
return BllResult.Error(1, "类型错误");
}
}
catch (Exception ex)
{
return BllResult.Error(1, ex.ToString());
}
return BllResult.Success(0, "建立成功");
}
/// <summary>
/// 任务路径预览
/// </summary>
/// <param name="webTaskSplitList"></param>
/// <returns></returns>
[HttpPost]
public BllResult TaskPreview([FromBody] List<ReqTaskSplit> webTaskSplitList)
{
try
{
string json = JsonConvert.SerializeObject(webTaskSplitList);
App.ExFile.MessageWebApi("WebApiMsg", "接口(TaskPreview)," + json + "\r");
//返回任务路径
List<ReqTaskPath> pathList = new List<ReqTaskPath>();
int index = 1;
for (int i = 0; i < webTaskSplitList.Count; i++)
{
PathAStar pathAStar = new PathAStar();
List<Base_Point> listApoint = App.PointList.FindAll(a => a.PointType != EnumMsg.PointType.充电点);
Base_Point startPoint = App.PointList.Find(a => a.Barcode == webTaskSplitList[i].FromPoint);
if (webTaskSplitList[i].FromArea != null)
{
startPoint = App.PointList.Find(a => a.Barcode == startPoint.Barcode && a.AreaType == webTaskSplitList[i].FromArea);
}
Base_Point endPoint = App.PointList.Find(a => a.Barcode == webTaskSplitList[i].ToPoint);
if (webTaskSplitList[i].ToArea != null)
{
endPoint = App.PointList.Find(a => a.Barcode == endPoint.Barcode && a.AreaType == webTaskSplitList[i].ToArea);
}
//不再同一区域
if (startPoint.AreaType != endPoint.AreaType)
{
//找到同一区域电梯点
endPoint = App.PointList.Find(a => a.AreaType == startPoint.AreaType && a.Barcode == ComnMethod.GetMinLiftPoint(endPoint).Barcode);
//获取当前不同区域终点
Base_Point toPoint = App.PointList.Find(a => a.Barcode == webTaskSplitList[i].ToPoint);
var taskSplit = new ReqTaskSplit
{
FromPoint = App.PointList.Find(a =>
a.AreaType == toPoint.AreaType && a.PointType == EnumMsg.PointType.电梯点).Barcode,
ToPoint = toPoint.Barcode,
FromArea = toPoint.AreaType,
};
webTaskSplitList.Insert(i + 1, taskSplit);
}
listApoint.Add(endPoint);
GetPath.ClearParentPoint();
Base_Point Parent = pathAStar.GetPathPoint(listApoint, startPoint, endPoint, webTaskSplitList[i].AgvTaskType, EnumMsg.Direction.无方向, false);
if (Parent == null || (Parent != null && Parent != endPoint))
{
//找不到路径判断是否有电梯
if (startPoint.AreaType == endPoint.AreaType && startPoint.PointType != EnumMsg.PointType.电梯点 && endPoint.PointType != EnumMsg.PointType.电梯点)
{
Base_Point startLiftPoint = ComnMethod.GetMinLiftPoint(startPoint);
Base_Point endLiftPoint = ComnMethod.GetMinLiftPoint(endPoint);
if (startLiftPoint != null && endLiftPoint != null && startLiftPoint != endLiftPoint)
{
for (int j = 1; j < 4; j++)
{
//获取当前区域电梯电点
var taskSplit = new ReqTaskSplit();
//获取当前不同区域终点
switch (j)
{
case 1:
taskSplit.FromPoint = startPoint.Barcode;
taskSplit.ToPoint = startLiftPoint.Barcode;
taskSplit.ToArea = startPoint.AreaType;
break;
case 2:
taskSplit.FromPoint = startLiftPoint.Barcode;
taskSplit.ToPoint = endLiftPoint.Barcode;
taskSplit.FromArea = App.PointList.Find(a => a.AreaType != startLiftPoint.AreaType && a.Barcode == taskSplit.FromPoint).AreaType;
taskSplit.ToArea = App.PointList.Find(a => a.AreaType != startLiftPoint.AreaType && a.Barcode == taskSplit.ToPoint).AreaType;
break;
case 3:
taskSplit.FromPoint = endLiftPoint.Barcode;
taskSplit.ToPoint = endPoint.Barcode;
taskSplit.FromArea = endLiftPoint.AreaType;
break;
default:
break;
}
webTaskSplitList.Insert(i + j, taskSplit);
}
continue;
}
}
return BllResult.Error(1, "未找到路径;请查看坐标(" + (Parent.IntX - 1) * 30 + "," + (Parent.IntY - 1) * 30 + ")附近是否配置错误");
}
List<Base_PathPoint> listPathPoint = GetPath.GetPathPointList(Parent, null);
//获取路径方点的方向
GetPath.GetPathDirection(listPathPoint);
for (int j = 0; j < listPathPoint.Count; j++)
{
var taskPath = new ReqTaskPath();
taskPath.AreaType = listPathPoint[j].Point.AreaType;
taskPath.SerialNo = index;
taskPath.Barcode = listPathPoint[j].Point.Barcode;
taskPath.IntX = listPathPoint[j].Point.IntX;
taskPath.IntY = 1000 - listPathPoint[j].Point.IntY;
taskPath.PathDriection = (int)listPathPoint[j].PathDirection;
if (taskPath.PathDriection == 4) { taskPath.PathDriection = 2; }
else if (taskPath.PathDriection == 2) { taskPath.PathDriection = 4; }
if (taskPath.PathDriection == 0 && i + 1 < webTaskSplitList.Count) continue;
pathList.Add(taskPath);
index++;
}
}
//转换为JSON形式,返回WEB界面
string jsontoweb = JsonConvert.SerializeObject(pathList);
return BllResult.Success(0, jsontoweb);
}
catch (Exception ex)
{
return BllResult.Error(1, ex.StackTrace);
}
}
/// <summary>
/// Demo任务路径预览
/// </summary>
/// <param name="webTaskSplitList"></param>
/// <returns></returns>
[HttpPost]
public BllResult DemoTaskPreview([FromBody] List<ReqTaskSplit> webTaskSplitList)
{
try
{
string json = JsonConvert.SerializeObject(webTaskSplitList);
App.ExFile.MessageWebApi("WebApiMsg", "接口(DemoTaskPreview)," + json + "\r");
//返回任务路径
var pathList = new List<ReqTaskPath>();
int index = 1;
for (int i = 0; i < webTaskSplitList.Count; i++)
{
PathAStar pathAStar = new PathAStar();
List<Base_Point> listApoint = App.DemoPointList.FindAll(a => a.PointType != EnumMsg.PointType.充电点
&& a.AreaType == webTaskSplitList[i].TaskMap);
Base_Point startPoint = App.DemoPointList.Find(a => a.Barcode == webTaskSplitList[i].FromPoint && a.AreaType == webTaskSplitList[i].TaskMap);
Base_Point endPoint = App.DemoPointList.Find(a => a.Barcode == webTaskSplitList[i].ToPoint && a.AreaType == webTaskSplitList[i].TaskMap);
if (startPoint == null && endPoint == null) continue;
if (startPoint == null)
{
startPoint = ComnMethod.GetMinLiftDemoPoint(endPoint);
}
else if (endPoint == null)
{
endPoint = ComnMethod.GetMinLiftDemoPoint(startPoint);
}
listApoint.Add(endPoint);
GetPath.ClearDemoParentPoint();
Base_Point Parent = pathAStar.GetPathPoint(listApoint, startPoint, endPoint, webTaskSplitList[i].AgvTaskType, EnumMsg.Direction.无方向, false);
if (Parent == null || (Parent != null && Parent.Barcode != endPoint.Barcode))
{
if (startPoint.AreaType == endPoint.AreaType && startPoint.PointType != EnumMsg.PointType.电梯点
&& endPoint.PointType != EnumMsg.PointType.电梯点)
{
Base_Point startLiftPoint = ComnMethod.GetMinLiftDemoPoint(startPoint);
Base_Point endLiftPoint = ComnMethod.GetMinLiftDemoPoint(endPoint);
for (int j = 1; j < 3; j++)
{
//获取当前区域电梯电点
var taskSplit = new ReqTaskSplit();
//获取当前不同区域终点
switch (j)
{
case 1:
taskSplit.FromPoint = startPoint.Barcode;
taskSplit.ToPoint = startLiftPoint.Barcode;
taskSplit.ToArea = startPoint.AreaType;
break;
case 2:
taskSplit.FromPoint = endLiftPoint.Barcode;
taskSplit.ToPoint = endPoint.Barcode;
taskSplit.FromArea = endLiftPoint.AreaType;
break;
default:
break;
}
webTaskSplitList.Insert(i + j, taskSplit);
}
continue;
}
return BllResult.Error(1, "未找到路径;请查看坐标(" + (Parent.IntX - 1) * 30 + "," + (Parent.IntY - 1) * 30 + ")附近是否配置错误");
}
List<Base_PathPoint> listPathPoint = GetPath.GetPathPointList(Parent, null);
//获取路径方点的方向
GetPath.GetPathDirection(listPathPoint);
for (int j = 0; j < listPathPoint.Count; j++)
{
var taskPath = new ReqTaskPath();
taskPath.AreaType = listPathPoint[j].Point.AreaType;
taskPath.SerialNo = index;
taskPath.Barcode = listPathPoint[j].Point.Barcode;
taskPath.IntX = listPathPoint[j].Point.IntX;
taskPath.IntY = listPathPoint[j].Point.IntY;
taskPath.PathDriection = (int)listPathPoint[j].PathDirection;
if (taskPath.PathDriection == 0 && i + 1 < webTaskSplitList.Count) continue;
pathList.Add(taskPath);
index++;
}
}
//转换为JSON形式,返回WEB界面
string jsontoweb = JsonConvert.SerializeObject(pathList);
return BllResult.Success(0, jsontoweb);
}
catch (Exception ex)
{
return BllResult.Error(1, ex.ToString());
}
}
/// <summary>
/// 任务完成
/// </summary>
/// <param name="stationNo"></param>
/// <returns></returns>
[HttpPost]
public BllResult TaskFinish([FromBody] ReqTaskFinish stationNo)
{
try
{
string json = JsonConvert.SerializeObject(stationNo);
App.ExFile.MessageWebApi("WebApiMsg", "接口(TaskFinish)," + json + "\r");
string station = stationNo.StName;
int state = stationNo.StState;
//判断站台是否有车,有车给任务类型
Base_Station st = App.StationList.FirstOrDefault(a => a.Name == station);
if (st == null) return BllResult.Error(1, "没有当前站台");
Base_Point point = App.PointList.FirstOrDefault(a => a.Barcode == st.Barcode);
Base_Agv agv = App.AgvList.FirstOrDefault(a => a.Barcode == point.Barcode);
if (agv == null || agv.AgvTask == null || agv.AgvTask.SubTaskList.Count == 0) return BllResult.Error(1, "当前站台没有AGV");
var agvSonTask = agv.AgvTask.SubTaskList[0];
if (agvSonTask.RequestType == EnumMsg.RequestType.取货完成确认)
agvSonTask.RequestType = EnumMsg.RequestType.信号发送完成;
}
catch (Exception ex)
{
App.ExFile.MessageWebApi("WebApiError", "接口(ChangePoint)," + ex.StackTrace + "\r");
return BllResult.Error(1, ex.StackTrace);
}
return BllResult.Success(0, "建立成功");
}
/// <summary>
/// web网页任务下发
/// </summary>
/// <param name="fTask"></param>
/// <returns></returns>
[HttpPost]
public BllResult TaskAssign([FromBody] ReqTaskAssign fTask)
{
try
{
string json = JsonConvert.SerializeObject(fTask);
App.ExFile.MessageWebApi("WebApiMsg", "接口(TaskAssign)," + json + "\r");
string strTaskID = fTask.TaskID;
string strTaskGroup = fTask.TaskGroup;
string strPalletNo = fTask.PalletNo;
int intTaskLevel = fTask.TaskLevel;
var taskSplit = App.Config_TaskSplitList.Where(a => a.TaskType == strTaskID).OrderBy(a => a.SerialNo)
.ToList();
if (taskSplit.Count == 0) return BllResult.Error(1, "当前任务ID没有进行任务编辑!");
Base_Point startPoint = App.PointList.Find(a => a.Barcode == taskSplit[0].ToPoint.ToString());
Base_Point endPoint =
App.PointList.Find(a => a.Barcode == taskSplit[taskSplit.Count - 1].ToPoint.ToString());
if (App.TaskList.FirstOrDefault(a => a.EndPoint == endPoint) != null && endPoint.LockedAgv != null)
{
return BllResult.Error(1, "存在当前站台的任务,请稍后下发");
}
string taskNo = "";
var getTaskNo = ComnMethod.GetTaskNo();
if (!getTaskNo.IsSuccess)
{
return BllResult.Error(1, $"当前任务号获取失败");
}
taskNo = getTaskNo.Data;
var result = TaskManage.TaskBuild(strTaskID, strTaskGroup, strPalletNo, intTaskLevel, "",
startPoint.Barcode, endPoint.Barcode, taskNo, "", "");
if (!result.IsSuccess) return BllResult.Error(1, $"创建{strPalletNo}任务失败{result.Message}");
return BllResult.Success(0, taskNo);
}
catch (Exception ex)
{
App.ExFile.MessageWebApi("WebApiError", "接口(TaskAssign)," + ex.ToString() + "\r");
return BllResult.Error(1, ex.ToString());
}
}
/// <summary>
/// 单步任务下发
/// </summary>
/// <param name="singleAgv"></param>
/// <returns></returns>
[HttpPost]
public BllResult SingleTask([FromBody] ReqSingleAgv singleAgv)
{
try
{
string json = JsonConvert.SerializeObject(singleAgv);
App.ExFile.MessageWebApi("WebApiMsg", "接口(SingleTask)," + json + "\r");
var strTaskID = Enum.Parse(typeof(EnumMsg.TaskType), singleAgv.TaskType.ToString());
var agv = App.AgvList.Find(a => a.AgvNo == singleAgv.AgvNo);
if (agv.AgvTask != null) return BllResult.Error(1, "AGV有任务未完成!");
var result = TaskManage.TaskBuild(strTaskID.ToString(), "", "", 1, singleAgv.AgvNo, agv.Barcode, singleAgv.ToLocationNo, "", "", "");
if (!result.IsSuccess) return BllResult.Error(100, $"任务创建失败!{result.Message}");
}
catch (Exception ex)
{
App.ExFile.MessageWebApi("WebApiError", "接口(SingleTask)," + ex.StackTrace + "\r");
return BllResult.Error(1, ex.StackTrace);
}
return BllResult.Success(0, "建立成功");
}
}
}