xiaojiao
昨天 9376389dbf19d202f766a4fe47cf80dfe4db4f42
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
171
172
173
174
175
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using SixLabors.ImageSharp;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common.StationEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.PDA;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_Tasks.TaskAcquisition;
 
namespace WIDESEAWCS_Tasks
{
    /// <summary>
    /// 任务获取 后底板1 的任务
    /// </summary>
    /// 
    [DisallowConcurrentExecution]
    public class TaskAcquisition_Back1_Job : JobBase, IJob
    {
        private readonly ITaskRepository _taskRepository;
        private readonly ITaskService _taskService;
        private readonly ISys_ConfigService _sys_ConfigService;
        private readonly IDt_StationManagerRepository _stationManagerRepository;
        private readonly IDt_MaterialInfoRepository _IDt_MaterialInfoRepository;
        public TaskAcquisition_Back1_Job(ITaskRepository taskRepository, ITaskService taskService, ISys_ConfigService configService, IDt_StationManagerRepository stationManagerRepository, IDt_MaterialInfoRepository IDt_MaterialInfoRepository)
        {
            _taskRepository = taskRepository;
            _taskService = taskService;
            _sys_ConfigService = configService;
            _stationManagerRepository = stationManagerRepository;
            _IDt_MaterialInfoRepository = IDt_MaterialInfoRepository;
        }
        public Task Execute(IJobExecutionContext context)
        {
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null)
            {
                OtherDevice device = (OtherDevice)value;
                if (!device.IsConnected)
                {
                    return Task.CompletedTask;
                }
                //string ip = "127.0.0.1";
                //int port = 502;
                //string Region = "后底板1";
                //ModbusTcp modbusTcp = new ModbusTcp(ip, port, Region);
                //modbusTcp.Connect();
                // Dictionary<int, int> Signal = new Dictionary<int, int>() { [10] = 2, [30] = 3, [50] = 4, [70] = 5 };
                // Dictionary<int, int> FeedingPoint = new Dictionary<int, int>() { [10] = 2001, [30] = 2002, [50] = 2003, [70] = 2004 }; // 叫料的点位 终点位置
 
                Baseconversion baseconversion = new Baseconversion();
                try
                {
                    List<Dt_StationManager> dt_StationManagers = _stationManagerRepository.QueryData(x =>
                            x.StationStatus == ((int)StationEnum.Enable).ToString()
                            && x.StationArea == ((int)StationEnum.Rearbaseplate1).ToString()
                            && x.Remark == "上线点").ToList();
 
                    foreach (var item in dt_StationManagers)
                    {
                        byte[] SignalNumber = device.Communicator.Read(item.StationChildCode, 1); // 信号 1:叫料 2:拉出空框
 
                        if (SignalNumber[1] == 1)
                        {
                            byte[] PartNumber = device.Communicator.Read(item.StationDeviceCode, 20); // 读取零件号
 
                            string Ku1_Value = baseconversion.TenthTurn16(PartNumber);
                            if (Ku1_Value.IsNotEmptyOrNull())
                            {
                                // 等功能测试完,这里要做日志记录
 
                                Console.WriteLine(Ku1_Value);
                                // 找对应的零件号是否已经绑定(组盘) // 这里要改要加区域 加是否已生成任务 还要根据时间排序 先绑定的先发过去
                                Dt_MaterialInfo? dt_MaterialInfo = _IDt_MaterialInfoRepository.QueryData(x => x.MaterialName == Ku1_Value
                                                                   && x.Region == ((int)StationEnum.Rearbaseplate1).ToString()
                                                                   && (x.IsNotEmptyOrNull())).OrderBy(x => x.CreateDate).FirstOrDefault();
 
                                if (dt_MaterialInfo != null)
                                {
                                    Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.PalletCode == dt_MaterialInfo.ContainerCode);
                                    if (dt_Task != null) continue; //证明有当前任务
 
                                    dt_Task = new Dt_Task();
                                    dt_Task.PalletCode = dt_MaterialInfo.ContainerCode;
                                    dt_Task.SourceAddress = dt_MaterialInfo.Position; // 当前位置
                                    dt_Task.TargetAddress = item.StationLocation; // 终点位置
                                    dt_Task.Grade = 2;
                                    dt_Task.TaskState = (int)TaskAGVCarryStatusEnum.AGV_CarryNew;
                                    dt_Task.TaskType = (int)TaskAGVCarryTypeEnum.Carry;
                                    dt_Task.Roadway = (int.Parse(item.StationChildCode) - 1).ToString(); // 库1 叫料那就是1巷道
                                    dt_Task.CurrentAddress = dt_MaterialInfo.Position; // 当前位置
                                    dt_Task.NextAddress = item.StationLocation; // 终点位置
 
                                    dt_MaterialInfo.EndPosition = item.StationLocation; // 终点位置
 
                                    item.StationStatus = ((int)StationEnum.Thereisatask).ToString();
                                    item.StationRemark = dt_MaterialInfo.ContainerCode;
                                    _stationManagerRepository.UpdateData(item);
 
                                    _taskRepository.AddData(dt_Task);
                                    _IDt_MaterialInfoRepository.UpdateData(dt_MaterialInfo);
                                }
 
                                // 如果没绑定则不生成任务 如果查找到对应的零件号绑定了 则生成一条任务数据
                            }
                        }
 
                        if (SignalNumber[1] == 2) // 表示拉出空框
                        {
                            Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.SourceAddress == item.StationLocation && x.TaskType == (int)TaskAGVCarryTypeEnum.CarryEmpty);
                            if (dt_Task != null) continue;
 
                            Dt_StationManager RecyclingpointStation = _stationManagerRepository.QueryFirst(x =>
                            x.StationStatus == ((int)StationEnum.Enable).ToString()
                            && x.StationArea == ((int)StationEnum.Rearbaseplate1).ToString()
                            && x.Remark == "回收点");
 
                            if (RecyclingpointStation == null)
                            {
                                // 记录错误日志
                                continue;
                            }
                            dt_Task = new Dt_Task();
                            dt_Task.PalletCode = item.StationRemark;
                            dt_Task.SourceAddress = item.StationLocation;
                            dt_Task.TargetAddress = RecyclingpointStation.StationLocation;
                            dt_Task.Grade = 2;
                            dt_Task.TaskState = (int)TaskAGVCarryStatusEnum.AGV_CarryNew;
                            dt_Task.TaskType = (int)TaskAGVCarryTypeEnum.CarryEmpty;
                            dt_Task.Roadway = (int.Parse(item.StationChildCode) - 1).ToString(); // 库1 叫料那就是1巷道
                            dt_Task.CurrentAddress = item.StationLocation; // 当前位置
                            dt_Task.NextAddress = RecyclingpointStation.StationLocation;// 终点位置
 
                            RecyclingpointStation.StationStatus = ((int)StationEnum.Thereisatask).ToString();
 
                            _stationManagerRepository.UpdateData(RecyclingpointStation);
                            _taskRepository.AddData(dt_Task);
                        }
                    }
                }
                catch (Exception)
                {
 
                    throw;
                }
            }
 
            // 16进制转成10进制
            // 2. 16进制 → 转回十进制(你要的功能)
            //ulong decimalResult = Convert.ToUInt64("123", 16);
            //Console.WriteLine("16进制转回十进制:" + decimalResult);
 
            //// 写入
            //bool flag2 = modbusTcp.Write("30", decimalResult.ToString());
 
            //modbusTcp.Disconnect();
            //Console.WriteLine("进入了TaskAcquisition_Back1_Job");
            return Task.CompletedTask;
        }
    }
}