AcsWebApiController.cs
15.4 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
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using RCS.Model.Comm;
using RCS.Model.Entity;
using RCS.Model.PLC;
using RCS.Model.WebApi.Request;
using RCS.Model.WebApi.Respose;
using RCS.WinClient.Common;
using RCS.WinClient.Service;
namespace RCS.WinClient.WebApi.Service
{
[ApiController]
[Route("api/[controller]/[action]")]
public class AcsWebApiController : ControllerBase
{
/// <summary>
/// 上层系统下发
/// </summary>
/// <param name="fTask"></param>
/// <returns></returns>
[HttpPost]
public BllResult TaskAssign([FromBody] ReqTaskAssign fTask)
{
try
{
if (fTask != null)
{
string json = JsonConvert.SerializeObject(fTask);
App.ExFile.MessageWebApi("TaskAssign", "接口(TaskAssign)," + json + "\r");
if (string.IsNullOrEmpty(fTask.TaskNo))
{
return BllResult.Error("任务号字段不允许为空!");
}
Base_Station? startStation;
Base_Station? endStation;
startStation = App.StationList.Find(t => t.Code == fTask.fromPort);
endStation = App.StationList.Find(t => t.Code == fTask.toPort);
var fromPoint = App.PointList.FirstOrDefault(x => x.Barcode == startStation?.Barcode);
var toPoint = App.PointList.FirstOrDefault(x => x.Barcode == endStation?.Barcode);
if (startStation == null)
{
return BllResult.Error("任务起点站台编码不存在!");
}
if (endStation == null)
{
var endBarcode = App.LoctionList.Find(x => x.LoctionCode == fTask.toPort)?.LoctionBarcode;
if (string.IsNullOrEmpty(endBarcode))
return BllResult.Error("任务终点站台编码不存在!");
toPoint = App.PointList.Find(x => x.Barcode == endBarcode);
if (toPoint == null)
{
return BllResult.Error("任务终点站台编码不存在!");
}
if (!ComnMethod.IsGroundPoint(toPoint))
{
return BllResult.Error("终点站台对应点位不是地面库!");
}
}
if (fromPoint == null || toPoint == null)
{
return BllResult.Error($"货架【{fTask.fromPort}】和【{fTask.toPort}】,配置的点位【{startStation.Barcode}】【{endStation?.Barcode}】在点位列表中不存在!");
}
var taskType = TaskManage.GetTaskType(fromPoint, toPoint);
if (taskType.IsNullOrEmpty())
{
return BllResult.Error("任务类型获取异常");
}
var taskGroup = EnumMsg.TaskGroup.WMS任务.ToString();
var result = TaskManage.TaskBuild(taskType, taskGroup, fTask.containerCode, fTask.priority, "", fromPoint.Barcode, toPoint.Barcode, fTask.TaskNo, startStation.Name, endStation?.Name ?? toPoint.Barcode);//startStation?.Name, endStation?.Name);
if (!result.IsSuccess)
return BllResult.Error($"创建{fTask.TaskNo}任务失败!,原因:{result.Message}");
}
else
{
return BllResult.Error("未获取到TaskAssign函数的参数,请检查Json数据");
}
}
catch (Exception ex)
{
var msg = $"接口【TaskAssign】发生异常,原因:{ex.Message},堆栈:{ex.StackTrace}";
App.ExFile.MessageWebApi("AcsWebApiError", msg);
return BllResult.Error(msg);
}
return BllResult.Success("建立成功");
}
/// <summary>
/// 任务删除
/// </summary>
/// <param name="taskCancel"></param>
/// <returns></returns>
[HttpPost]
public BllResult TaskCancel([FromBody] ReqTaskCancel taskCancel)
{
try
{
if (taskCancel != null)
{
string json = JsonConvert.SerializeObject(taskCancel);
App.ExFile.MessageWebApi("TaskCancel", $"接口(TaskCancel),{json} \r");
var strResult = TaskManage.TaskDelete(taskCancel.TaskNo, -1);
return strResult;
}
else
{
return BllResult.Error($"未获取到TaskCancel函数的数据,请检查Json数据");
}
}
catch (Exception ex)
{
var msg = $"接口【TaskCancel】发生异常,原因:{ex.StackTrace},堆栈:{ex.StackTrace}";
App.ExFile.MessageWebApi("AcsWebApiError", msg);
return BllResult.Error(msg);
}
}
/// <summary>
/// 任务确认完成
/// </summary>
/// <param name="taskFinish"></param>
/// <returns></returns>
[HttpPost]
public BllResult TaskFinish([FromBody] ReqTaskFinish taskFinish)
{
try
{
if (taskFinish != null)
{
string json = JsonConvert.SerializeObject(taskFinish);
App.ExFile.MessageWebApi("TaskFinish", $"接口(TaskFinish),{json} \r");
var result = App.TaskList.FirstOrDefault(a => a.TaskPallet == taskFinish.PalletNo);
if (result == null)
{
return BllResult.Error("没有当前托盘号任务!");
}
}
else
{
return BllResult.Error($"未获取到TaskFinish函数的数据,请检查Json数据");
}
}
catch (Exception ex)
{
var msg = $"接口【TaskFinish】发生异常,原因:{ex.StackTrace},堆栈:{ex.StackTrace}";
App.ExFile.MessageWebApi("AcsWebApiError", msg);
return BllResult.Error(msg);
}
return BllResult.Success($"确认成功");
}
/// <summary>
/// AGV信息查询
/// </summary>
/// <returns></returns>
[HttpGet]
public BllResult<IEnumerable<object>> AgvInfoList()
{
try
{
var agvInfoList = App.AgvList.Select(_agv => new
{
AgvNumber = _agv.AgvNo,
TaskNo = _agv.AgvTask?.TaskNo,
Landmark = _agv.Barcode,
StartLandmark = _agv.AgvTask?.SubTaskList == null ? null : _agv.AgvTask?.SubTaskList.FirstOrDefault()?.StartBarcode,
EndLandmark = _agv.AgvTask?.SubTaskList == null ? null : _agv.AgvTask?.SubTaskList.FirstOrDefault()?.StartBarcode,
Status = _agv.AgvState.ToString(),
Speed = _agv.Speed,
Battery = _agv.Voltage
});
return BllResult<IEnumerable<object>>.Success(agvInfoList);
}
catch (Exception ex)
{
var msg = $"接口【AgvInfoList】发生异常,原因:{ex.StackTrace},堆栈:{ex.StackTrace}";
App.ExFile.MessageWebApi("AgvInfoList", msg);
return BllResult<IEnumerable<object>>.Error(msg);
}
}
/// <summary>
/// 继续任务
/// </summary>
/// <param name="taskFinish"></param>
/// <returns></returns>
[HttpPost]
public BllResult ContinueTask([FromBody] ReqContinueTask continueTask)
{
try
{
if (continueTask != null)
{
string json = JsonConvert.SerializeObject(continueTask);
App.ExFile.MessageWebApi("AcsWebApiMsg", $"接口(ContinueTask),{json} \r");
//获取任务号所属任务
var task = App.TaskList.FirstOrDefault(a => a.TaskNo == continueTask.TaskNo);
if (task == null) { return BllResult.Error($"未获取到任务"); }
var agv = App.AgvList.FirstOrDefault(a => a.AgvNo == task.TaskAgvNo);
var sonTask = task.SubTaskList[0];
if (continueTask.TaskStatus != (int)sonTask.RequestType)
{
return BllResult.Error($"中控返回任务状态和AGV当前状态不匹配");
}
//if (task.SubTaskList.Count() == 1 && sonTask.TaskRequestType == EnumMsg.TaskRequestType.等待MES回复已经出来终点光栅)
//{
// sonTask.TaskRequestType = EnumMsg.TaskRequestType.任务完成信号;
// sonTask.SubTaskState = EnumMsg.SubTaskState.动作完成;
//}
//else
//{
// sonTask.TaskRequestType = EnumMsg.TaskRequestType.信号发送完成;
//}
}
else
{
return BllResult.Error($"未获取到ContinueTask函数的数据,请检查Json数据");
}
}
catch (Exception ex)
{
var msg = $"接口【ContinueTask】发生异常,原因:{ex.StackTrace},堆栈:{ex.StackTrace}";
App.ExFile.MessageWebApi("AcsWebApiError", msg);
return BllResult.Error(msg);
}
return BllResult.Success($"确认成功");
}
[HttpPost]
public BllResult PlaceholderTask()
{
try
{
List<ResPlaceholderTask> Rpt = new List<ResPlaceholderTask>();
var equipmentProps = App.EquipmentList.Where(t => t.Type == EnumPLC.EquipmentType.HuaHengStation.ToString())
//.SelectMany(t => t.EquipmentProps)
//.Where(t => t.Code == EnumPLC.PLCHuaHengProps.Placeholder.ToString())
.ToList();
//1-true有货,0-false无货
foreach (var equipmentProp in equipmentProps)
{
ResPlaceholderTask content = new ResPlaceholderTask();
//content.StationCode = equipmentProp.Equipment.Code;
//content.Placeholder = equipmentProp.Value;
Rpt.Add(content);
}
return BllResult.Success(Rpt, "发送成功");
}
catch (Exception ex)
{
var msg = $"接口【PlaceholderTask】发生异常,原因:{ex.StackTrace},堆栈:{ex.StackTrace}";
App.ExFile.MessageWebApi("AcsWebApiError", msg);
return BllResult.Error(msg);
}
}
#region 兼容Java版Rcs接口
/// <summary>
/// 上层系统下发
/// </summary>
/// <param name="fTask"></param>
/// <returns></returns>
[HttpPost]
public BllResult CreateAGVTask([FromBody] ReqTaskAssign fTask)
{
try
{
if (fTask != null)
{
string json = JsonConvert.SerializeObject(fTask);
App.ExFile.MessageWebApi("TaskAssign", "接口(TaskAssign)," + json + "\r");
if (string.IsNullOrEmpty(fTask.TaskNo))
{
return BllResult.Error("任务号字段不允许为空!");
}
Base_Station? startStation;
Base_Station? endStation;
startStation = App.StationList.Find(t => t.Code == fTask.fromPort);
endStation = App.StationList.Find(t => t.Code == fTask.toPort);
var fromPoint = App.PointList.FirstOrDefault(x => x.Barcode == startStation?.Barcode);
var toPoint = App.PointList.FirstOrDefault(x => x.Barcode == endStation?.Barcode);
if (startStation == null)
{
return BllResult.Error("任务起点站台编码不存在!");
}
if (endStation == null)
{
return BllResult.Error("任务终点站台编码不存在!");
}
if (fromPoint == null || toPoint == null)
{
return BllResult.Error($"货架【{fTask.fromPort}】和【{fTask.toPort}】,配置的点位【{startStation.Barcode}】【{endStation.Barcode}】在点位列表中不存在!");
}
var taskType = TaskManage.GetTaskType(fromPoint, toPoint);
var taskGroup = EnumMsg.TaskGroup.WMS任务.ToString();
var result = TaskManage.TaskBuild(taskType, taskGroup, fTask.containerCode, fTask.priority, "", fromPoint.Barcode, toPoint.Barcode, fTask.TaskNo, startStation.Name, endStation?.Name ?? toPoint.Barcode);//startStation?.Name, endStation?.Name);
if (!result.IsSuccess)
return BllResult.Error($"创建{fTask.TaskNo}任务失败!,原因:{result.Message}");
}
else
{
return BllResult.Error("未获取到TaskAssign函数的参数,请检查Json数据");
}
}
catch (Exception ex)
{
var msg = $"接口【TaskAssign】发生异常,原因:{ex.Message},堆栈:{ex.StackTrace}";
App.ExFile.MessageWebApi("AcsWebApiError", msg);
return BllResult.Error(msg);
}
return BllResult.Success("建立成功");
}
/// <summary>
/// 任务删除
/// </summary>
/// <param name="taskCancel"></param>
/// <returns></returns>
[HttpPost]
public BllResult CancelAGVTask([FromBody] ReqTaskCancel taskCancel)
{
try
{
if (taskCancel != null)
{
string json = JsonConvert.SerializeObject(taskCancel);
App.ExFile.MessageWebApi("TaskCancel", $"接口(TaskCancel),{json} \r");
var strResult = TaskManage.TaskDelete(taskCancel.TaskNo);
return strResult;
}
else
{
return BllResult.Error($"未获取到TaskCancel函数的数据,请检查Json数据");
}
}
catch (Exception ex)
{
var msg = $"接口【TaskCancel】发生异常,原因:{ex.StackTrace},堆栈:{ex.StackTrace}";
App.ExFile.MessageWebApi("AcsWebApiError", msg);
return BllResult.Error(msg);
}
}
#endregion
}
}