刘磊
2024-11-23 222d2040c2a5e958b5fbd0b7047a8e802ec14288
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#region MyRegion
#region << 版 本 注 释 >>
 
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 *
 *----------------------------------------------------------------*/
 
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using HslCommunication;
using Microsoft.AspNetCore.Server.HttpSys;
using Newtonsoft.Json;
using Quartz;
using SqlSugar;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Threading.Tasks;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonConveyorLine_AfterJob : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskRepository _taskRepository;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IMapper _mapper;
        private readonly IDt_StationManagerService _stationManagerService;
 
        public CommonConveyorLine_AfterJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository, IDt_StationManagerService stationManagerService)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _mapper = mapper;
            _taskRepository = taskRepository;
            _stationManagerService = stationManagerService;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                CommonConveyorLine_After conveyorLine = (CommonConveyorLine_After)context.JobDetail.JobDataMap.Get("JobParams");
                if (conveyorLine != null)
                {
                    List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode);
                    foreach (var station in stationManagers)
                    {
                        ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(station.stationChildCode);
 
                        DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand_After.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString());
                        if (deviceProtocolDetails != null)
                        {
                            MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType);
                            if (method != null)
                            {
                                method.Invoke(this, new object[] { conveyorLine, command, station });
                            }
                        }
                    }
 
                    #region 路由方式
                    //List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
                    //foreach (string childDeviceCode in childDeviceCodes)
                    //{
                    //    ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode);
 
                    //    if (command.ConveyorLineBarcode.Trim().Contains("\0")) command.ConveyorLineBarcode = "";
 
                    //    DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand_After.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString());
                    //    if (deviceProtocolDetails != null)
                    //    {
                    //        MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType);
                    //        if (method != null)
                    //        {
                    //            method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode });
                    //        }
                    //    }
                    //} 
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(nameof(CommonConveyorLine_AfterJob) + ":" + ex.ToString());
            }
            finally
            {
                //WriteDebug("CommonConveyorLineJob", "test");
                //Console.Out.WriteLine(DateTime.Now);
            }
            return Task.CompletedTask;
        }
 
        /// <summary>
        /// 输送线请求入库
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestInbound(CommonConveyorLine_After conveyorLine, ConveyorLineTaskCommand_After command, Dt_StationManager stationInfo)
        {
            var taskNew = _taskService.QueryTaskByPalletCode(command.ConveyorLineBarcode, stationInfo.Roadway);
            if (taskNew == null)
            {
                if (_taskService.RequestTask(command.ConveyorLineBarcode, stationInfo).Result.Status)
                {
                    Dt_Task task = _taskService.QueryTaskByPalletCode(command.ConveyorLineBarcode, stationInfo.Roadway);
                    if (task != null)
                    {
                        //ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
                        //taskCommand.InteractiveSignal = command.InteractiveSignal;
                        //taskCommand.ResponState = 1;
                        //taskCommand.ConveyorLineTaskNum = task.TaskNum;
                        //taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(task.NextAddress);
                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, stationInfo.stationChildCode);
                        //conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, 1, task.NextAddress);
                        //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                    }
                }
            }
        }
 
        /// <summary>
        /// 输送线请求入库
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        //public void RequestInbound(CommonConveyorLine_After conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
        //{
        //    var stationInfo = _stationManagerService.GetStationInfoByChildCode(childDeviceCode);
        //    if (stationInfo != null)
        //    {
        //        //_taskService.r
        //    }
        //    var taskNew = _taskService.QueryCraneConveyorLineTask(command.ConveyorLineTaskNum.ObjToInt(), childDeviceCode);
        //    if (taskNew == null)
        //    {
        //        string barcode = command.ConveyorLineBarcode.TrimEnd();
        //        if (_taskService.RequestWMSTask(command.ConveyorLineBarcode, childDeviceCode).Result.Status)
        //        {
        //            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
        //            if (task != null)
        //            {
        //                ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
        //                //taskCommand.InteractiveSignal = command.InteractiveSignal;
        //                taskCommand.ResponState = 1;
        //                taskCommand.ConveyorLineTaskNum = task.TaskNum;
        //                taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(task.NextAddress);
        //                conveyorLine.SendCommand(taskCommand, childDeviceCode);
 
        //                //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
 
        //                _taskService.UpdateTaskStatusToNext(task);
        //            }
        //        }
        //    }
        //}
 
    }
}
#endregion