wangxinhui
4 小时以前 c2cdf0b95d4c9214646c860609b8c838d6ffa779
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
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" && x.TaskType!=999).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(stationMangerStart.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站点");
                            }
                            //发送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(500);
                        }
                        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);
            }
        }
    }
}