huangxiaoqiang
5 天以前 bfd2cde0cc9b9871eeab1503c837beabb9ade9e5
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
using Microsoft.IdentityModel.Tokens;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_DTO.Agv;
using WIDESEAWCS_Common.APIEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.Agv;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
 
namespace WIDESEAWCS_Tasks
{
    public partial class AGV_CPJob
    {
        public void SendAGVTask()
        {
            try
            {
                var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()|| x.TaskState == TaskStatusEnum.New.ObjToInt()) && x.DeviceCode=="AGV").ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
 
                if (newTasks.Count>0)
                {
                    foreach (var task in newTasks)
                    {
                        try
                        {
                            Guid guid = Guid.NewGuid(); 
                            AgvTaskSendDTO agvTaskSend = new AgvTaskSendDTO()
                            {
                                SysToken=guid.ToString().Replace("-",""),
                                ReceiveTaskID=task.TaskNum.ToString(),
                                MapCode="01",
                                Variables=new List<PointDetail>()
                            };
                            Dt_StationManger stationMangerStart = _stationMangerRepository.QueryFirst(x=>x.StationCode==task.CurrentAddress);
                            Dt_StationManger stationMangerEnd = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress);
                            //添加任务路径及高度
                            if (stationMangerStart !=null && stationMangerEnd != null)
                            {
                                PointDetail pointDetail1 = new PointDetail()
                                {
                                    Code= "GoodPoint",
                                    Value=stationMangerStart.AGVStationCode
                                };
                                //判断是否有前置点
                                if (!string.IsNullOrEmpty(stationMangerStart.AGVFrontCode))
                                {
                                    PointDetail pointDetail2 = new PointDetail()
                                    {
                                        Code = "CostPoint",
                                        Value = stationMangerStart.AGVFrontCode
                                    };
                                    agvTaskSend.Variables.Add(pointDetail2);
                                }
                                PointDetail pointDetail3 = new PointDetail()
                                {
                                    Code = "PointB",
                                    Value = stationMangerEnd.AGVStationCode
                                };
                                //判断是否有前置点
                                if (!string.IsNullOrEmpty(stationMangerEnd.AGVFrontCode))
                                {
                                    PointDetail pointDetail4 = new PointDetail()
                                    {
                                        Code = "PointA",
                                        Value = stationMangerEnd.AGVFrontCode
                                    };
                                    agvTaskSend.Variables.Add(pointDetail4);
                                }
                                PointDetail pointDetail5 = new PointDetail()
                                {
                                    Code = "QUQTH",
                                    Value = stationMangerStart.AGVStationHeight.ToString()
                                };
                                PointDetail pointDetail6 = new PointDetail()
                                {
                                    Code = "FHMH",
                                    Value = stationMangerEnd.AGVStationHeight.ToString()
                                };
                                agvTaskSend.Variables.Add(pointDetail1);
                                agvTaskSend.Variables.Add(pointDetail3);
                                agvTaskSend.Variables.Add(pointDetail5);
                                agvTaskSend.Variables.Add(pointDetail6);
                            }
                            else
                            {
                                throw new Exception("未找到AGV站点");
                            }
                            //取放任务模版
                            if (stationMangerStart.StationCode.Contains("PNT") && !stationMangerEnd.StationCode.Contains("PNT"))//请求放
                            {
                                agvTaskSend.TaskCode = "DUIGAO1";
                                if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//潜伏顶升车
                                {
                                    agvTaskSend.TaskCode = "DUOLUN1";
                                }
                            }
                            else if (!stationMangerStart.StationCode.Contains("PNT") && stationMangerEnd.StationCode.Contains("PNT"))//请求取
                            {
                                agvTaskSend.TaskCode = "DUIGAO2";
                                if (stationMangerStart.StationType==998 || stationMangerEnd.StationType == 998)//潜伏顶升车
                                {
                                    agvTaskSend.TaskCode = "DUOLUN2";
                                }
                            }
                            else if (!stationMangerStart.StationCode.Contains("PNT") && !stationMangerEnd.StationCode.Contains("PNT"))//请求取放
                            {
                                agvTaskSend.TaskCode = "DUIGAO3";
                                if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//潜伏顶升车
                                {
                                    agvTaskSend.TaskCode = "DUOLUN3";
                                }
                            }
                            else if (stationMangerStart.StationCode.Contains("PNT") && stationMangerEnd.StationCode.Contains("PNT"))//无请求
                            {
                                agvTaskSend.TaskCode = "DUIGAO4";
                                if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//潜伏顶升车
                                {
                                    agvTaskSend.TaskCode = "DUOLUN4";
                                }
                            }
                            if (stationMangerStart.StationType == 998 || stationMangerEnd.StationType == 998)//潜伏顶升车
                            {
                                agvTaskSend.Variables.FirstOrDefault(x => x.Code == "FHMH").Value = "0";
                                agvTaskSend.Variables.FirstOrDefault(x => x.Code == "GoodPoint").Value = "";
                                //下发任务AGV任务集群
                                agvTaskSend.AgvGroupCode = "QianF";
                                PointDetail pointDetail2 = new PointDetail()
                                {
                                    Code = "CostPoint",
                                    Value = stationMangerStart.AGVStationCode
                                };
                                agvTaskSend.Variables.Add(pointDetail2);
                            }
                            //延时
                            Thread.Sleep(500);
                            //发送AGV任务
                            WebResponseContent content = _taskService.AgvSendTask(agvTaskSend, APIEnum.AgvSendTask);
                            if (!content.Status)
                                throw new Exception(content.Message);
                            task.Dispatchertime = DateTime.Now;
                            _taskService.UpdateTask(task, TaskStatusEnum.AGV_Executing);
                            Thread.Sleep(200);
                        }
                        catch (Exception ex)
                        {
                            task.TaskState = TaskStatusEnum.Exception.ObjToInt();
                            task.ExceptionMessage = ex.Message;
                        }
                    }
                    //更新任务
                    if (newTasks.Count > 0)
                    {
                        _taskService.UpdateData(newTasks);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteError(nameof(AGV_CPJob), ex.Message, ex);
            }
        }
    }
}