1
z8018
2025-04-08 e69f814f50fd59739dbedd88518dc8cb8d2ed3ee
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using WIDESEAWCS_Common;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
 
namespace WIDESEAWCS_Tasks
{
    /// <summary>
    /// 龙门架
    /// </summary>
    [DisallowConcurrentExecution]
    public class GantryJob : JobBase, IJob
    {
        private readonly ITaskRepository _taskRepository;
        private readonly ITaskService _taskService;
        private readonly IContainerItemRepository _containerItemRepository;
        public GantryJob(ITaskRepository taskRepository, ITaskService taskService, IContainerItemRepository containerItemRepository)
        {
            _taskRepository = taskRepository;
            _taskService = taskService;
            _containerItemRepository = containerItemRepository;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
                if (flag && value != null && value is OtherDevice)
                {
                    OtherDevice otherDevice = (OtherDevice)value;
 
                    byte gantryStatus = otherDevice.GetValue<GantryDBName, byte>(GantryDBName.GantryStatus);
                    byte gantryAutoStatus = otherDevice.GetValue<GantryDBName, byte>(GantryDBName.GantryAutoStatus);
                    byte gantryWorkStatus = otherDevice.GetValue<GantryDBName, byte>(GantryDBName.GantryWorkStatus);
 
                    if(gantryStatus == 1 && gantryAutoStatus == 3 && gantryWorkStatus == 0)
                    {
                        // 逻辑处理
                        // 1. 读取任务
                        // 2. 任务执行
                        // 3. 任务完成
                        Dt_Task? task = _taskService.QueryAGantryUnExecuteTask(otherDevice.DeviceCode);
                        if(task != null)
                        {
                            string[] takePositions = task.CurrentAddress.Split("*");
                            if(takePositions.Length != 5)
                            {
                                //WriteError
                                return Task.CompletedTask;
                            }
 
                            string[] putPositions = task.NextAddress.Split("*");
                            if (putPositions.Length != 5)
                            {
                                //WriteError
                                return Task.CompletedTask;
                            }
 
                            Dt_ContainerItem containerItem = _containerItemRepository.QueryFirst(x => x.ItemCode == task.PalletCode);
                            if (containerItem == null)
                            {
                                //WriteError
                                return Task.CompletedTask;
                            }
 
                            otherDevice.SetValue(GantryDBName.TwoHand, true);
 
                            otherDevice.SetValue(GantryDBName.TaskNum, task.TaskNum);
                            //otherDevice.SetValue(GantryDBName.TakePosition, Convert.ToInt32(takePositions[0]));
                            otherDevice.SetValue(GantryDBName.TakePositionX, Convert.ToInt32(takePositions[1]));
                            otherDevice.SetValue(GantryDBName.TakePositionY, Convert.ToInt32(takePositions[2]));
                            otherDevice.SetValue(GantryDBName.TakePositionZ, Convert.ToInt32(takePositions[3]));
                            otherDevice.SetValue(GantryDBName.TakePositionR, Convert.ToInt32(takePositions[4]));
                            //otherDevice.SetValue(GantryDBName.PutPosition, Convert.ToInt32(putPositions[0]));
                            otherDevice.SetValue(GantryDBName.PutPositionX, Convert.ToInt32(putPositions[1]));
                            otherDevice.SetValue(GantryDBName.PutPositionY, Convert.ToInt32(putPositions[2]));
                            otherDevice.SetValue(GantryDBName.PutPositionZ, Convert.ToInt32(putPositions[3]));
                            otherDevice.SetValue(GantryDBName.PutPositionR, Convert.ToInt32(putPositions[4]));
                            otherDevice.SetValue(GantryDBName.Length, containerItem.ItemLength);
                            otherDevice.SetValue(GantryDBName.Width, containerItem.ItemWidth);
                            otherDevice.SetValue(GantryDBName.Height, containerItem.ItemHeight);
                            otherDevice.SetValue(GantryDBName.WorkType, 1);
                            otherDevice.SetValue(GantryDBName.StartCommand, 1);
 
                            task.TaskState = TaskStatusEnum.Gantry_Executing.ObjToInt();
                            _taskRepository.UpdateData(task);
                        }
                    }
                    else if(gantryWorkStatus == 5)
                    {
                        
                    }
                }
            }
            catch (Exception ex)
            {
 
            }
            return Task.CompletedTask;
        }
 
        public Dt_Task GetTask()
        {
            return new Dt_Task();
        }
    }
}