helongyang
2026-03-31 8fcd7a67e4391a5f1fbdb590c2a3f913aeb2a0a0
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
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_Model.Models;
using WIDESEAWCS_Tasks.StackerCraneJob;
 
namespace WIDESEAWCS_Tasks
{
    public partial class AGV_PPJob
    {
        public void SendAGVTask()
        {
            try
            {
                var newTasks = _taskService.Db.Queryable<Dt_Task>().Where(x => (x.TaskState == TaskStatusEnum.New.ObjToInt()||x.TaskState==TaskStatusEnum.AGV_Execute.ObjToInt()) && nameof(AGV_PPJob).Contains(x.DeviceCode) && !string.IsNullOrEmpty(x.DeviceCode)).ToList().OrderBy(x => x.Grade).ThenBy(x => x.CreateDate).ToList();
                foreach (var agvTask in newTasks)
                {
                    try
                    {
                        string taskTyp;
                        if (agvTask.TaskType == TaskTypeEnum.MesPPMove.ObjToInt())
                        {
                            taskTyp = "110";
                        }
                        else if (agvTask.PalletType < 2)
                        {
                            taskTyp = "008";
                        }
                        else
                        {
                            taskTyp = "004";
                        }
 
                        AgvTaskDTO taskDTO = new AgvTaskDTO()
                        {
                            ReqCode = Guid.NewGuid().ToString().Replace("-", ""),
                            TaskTyp = taskTyp,
                            PositionCodePath = new List<CodePath>()
                            {
                                new CodePath()
                                {
                                    type = "00",
                                    positionCode = agvTask.CurrentAddress
                                },
                                new CodePath()
                                {
                                    type = (agvTask.TaskType == TaskTypeEnum.PPPKInbound.ObjToInt()||agvTask.TaskType == TaskTypeEnum.MesPPCutOutbound.ObjToInt()) ? "00" : "04",
                                    positionCode = agvTask.NextAddress
                                }
                            },
                            TaskCode = agvTask.AgvTaskNum,
                        };
                        WebResponseContent content = _taskService.AgvSendTask(taskDTO);
                        if (content.Status)
                        {
                            agvTask.TaskState = TaskStatusEnum.AGV_Executing.ObjToInt();
                            //agvTask.Remark = content.Data.ObjToString();
                            _taskService.UpdateTask(agvTask, TaskStatusEnum.AGV_Executing);
                        }
                        else
                        {
                            agvTask.TaskState = TaskStatusEnum.Exception.ObjToInt();
                            //agvTask.Remark = content.Data.ObjToString();
                            agvTask.ExceptionMessage = content.Message;
                        }
                    }
                    catch (Exception ex)
                    {
                        agvTask.TaskState = TaskStatusEnum.Exception.ObjToInt();
                        //agvTask.Remark = content.Data.ObjToString();
                        agvTask.ExceptionMessage = ex.Message;
                        WriteError(nameof(AGV_PPJob), ex.Message, ex);
                    }
                }
                _taskService.UpdateData(newTasks);
            }
            catch (Exception ex)
            {
                WriteError(nameof(AGV_PPJob), ex.Message, ex);
            }
        }
    }
}