dengjunjie
2024-12-29 7f078e66be9959d94fc78344f195b7b4656812be
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_DTO.Agv;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_Tasks
{
    public partial class AGVJob
    {
        /// <summary>
        /// 下发AGV任务
        /// </summary>
        public void SendAGVTask()
        {
            try
            {
                var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => x.TaskState == TaskStatusEnum.AGV_Execute.ObjToInt()).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
                foreach (var agvTask in newTasks)
                {
                    AgvTaskDTO taskDTO = new AgvTaskDTO()
                    {
                        ReqCode = Guid.NewGuid().ToString().Replace("-", ""),
                        TaskTyp = AgvTaskType(agvTask.TaskType, agvTask.DeviceCode),
                        PositionCodePath = new List<CodePath>()
                        {
                            new CodePath()
                            {
                                type="00",
                                positionCode=agvTask.CurrentAddress
                            },
                            new CodePath()
                            {
                                type="00",
                                positionCode=agvTask.NextAddress
                            }
                        },
                        TaskCode = agvTask.AgvTaskNum,
                        PodTyp = agvTask.PalletType < 3 ? "XX" : "DD",
                    };
                    WebResponseContent content = _taskService.AgvSendTask(taskDTO);
                    if (content.Status)
                    {
                        agvTask.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
                        //agvTask.Remark = content.Data.ObjToString();
                    }
                    else
                    {
                        agvTask.TaskState = TaskStatusEnum.Exception.ObjToInt();
                        //agvTask.Remark = content.Data.ObjToString();
                        agvTask.ExceptionMessage = content.Message;
                    }
                }
                _taskService.UpdateData(newTasks);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(nameof(AGVJob) + ":" + ex.Message);
            }
        }
        /// <summary>
        /// 下发AGV继续执行任务
        /// </summary>
        public void SendAGVWaitToTask()
        {
            try
            {
                var WaitToTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => x.TaskState == TaskStatusEnum.AGV_WaitToExecute.ObjToInt()).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
                foreach (var WaitToTask in WaitToTasks)
                {
                    AgvSecureReplyDTO replyDTO = new AgvSecureReplyDTO()
                    {
                        ReqCode = Guid.NewGuid().ToString().Replace("-", ""), //WaitToTask.TaskNum.ToString(),
                        taskCode = WaitToTask.AgvTaskNum,
                    };
                    WebResponseContent content = _taskService.AgvSecureReply(replyDTO);
                    if (content.Status)
                    {
                        WaitToTask.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
                    }
                    else
                    {
                        WaitToTask.TaskState = TaskStatusEnum.Exception.ObjToInt();
                        WaitToTask.ExceptionMessage = content.Message;
                    }
                }
                _taskService.UpdateData(WaitToTasks);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(nameof(AGVJob) + ":" + ex.Message);
            }
        }
 
        public string AgvTaskType(int TaskType, string DeviceCode)
        {
            switch (DeviceCode)
            {
                case "AGV_CSJ":
                    {
                        return TaskType == TaskTypeEnum.ProductionReturn.ObjToInt() ? "23" : "24";
                    }
                case "AGV_ZH":
                    {
                        if (TaskType == TaskTypeEnum.InboundXB.ObjToInt())
                            return "20";
                        else if (TaskType == TaskTypeEnum.InboundJT.ObjToInt())
                            return "21";
                        else return "22";
                    }
                default:
                    throw new NotImplementedException();
            }
        }
    }
}