wangxinhui
22 小时以前 c6e8b600398de38b6684f5fa1eaaaade8562859b
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
using Autofac.Core;
using Microsoft.AspNetCore.Components.Routing;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using Quartz;
using System.Reflection;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_IPackInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.StackPlateJob;
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class StackPlate : JobBase, IJob
    {
        private readonly ICacheService _cacheService;
        private readonly ITaskService _taskService;
        private readonly ITaskRepository _taskRepository;
        private readonly IStationMangerRepository _stationMangerRepository;
        private readonly IDt_PackaxisRepository _packaxisRepository;
 
        public StackPlate(ICacheService cacheService, ITaskService taskService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IDt_PackaxisRepository packaxisRepository)
        {
            _cacheService = cacheService;
            _taskService = taskService;
            _taskRepository = taskRepository;
            _stationMangerRepository = stationMangerRepository;
            _packaxisRepository = packaxisRepository;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            CommonConveyorLine device = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
            //获取当前设备对应的站台
            StackPlateTaskCommandCommand command = device.ReadCustomer<StackPlateTaskCommandCommand>(device.DeviceCode);
 
            if (command != null && command.State == 2)
            {
                DeviceProtocolDetailDTO? deviceProtocolDetails = device.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(StackPlateTaskCommandCommand.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString());
                if (deviceProtocolDetails != null)
                {
                    MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType);
                    if (method != null)
                    {
                        method.Invoke(this, new object[] { device, command });
                    }
                }
            }
 
            return Task.CompletedTask;
        }
 
        /// <summary>
        /// 有料运行,申请入库
        /// </summary>
        /// <param name="device"></param>
        /// <param name="command"></param>
        public void InStockAllow(CommonConveyorLine device, StackPlateTaskCommandCommand command)
        {
            var station = _stationMangerRepository.QueryFirst(x => x.StationDeviceCode == device.DeviceCode);
            if (station != null && station.Remark != null)//获取站台里面的托盘号
            {
                var task = _taskRepository.QueryFirst(x => x.DeviceCode == device.DeviceCode && (x.TaskState == (int)TaskStatusEnum.AGV_Execute || x.TaskState == (int)TaskStatusEnum.AGV_Executing) && x.SourceAddress == station.AGVStationCode);
                if (task == null)
                {
                    WebResponseContent content = _taskService.CPEmptyInbound(station.Remark, station.AGVStationCode);
                }
            }
        }
 
        /// <summary>
        /// 空位运行,允许叠盘
        /// </summary>
        /// <param name="device"></param>
        /// <param name="command"></param>
        public void EmptySeatAllow(CommonConveyorLine device, StackPlateTaskCommandCommand command)
        {
            var station = _stationMangerRepository.QueryFirst(x => x.StationDeviceCode == device.DeviceCode);
            var tasks = _taskRepository.QueryData(x => x.Roadway == device.DeviceCode && (x.TaskState == (int)TaskStatusEnum.AGV_Execute || x.TaskState == (int)TaskStatusEnum.AGV_Executing) && x.TargetAddress == device.DeviceCode);
            if (tasks.Count + Convert.ToInt32(command.Num) < 9)
            {
                var task = _taskRepository.QueryFirst(x => x.Roadway == device.DeviceCode && x.TaskState == (int)TaskStatusEnum.StackPlate_Execute);
                if (task != null && station != null)
                {
                    task.TaskState = (int)TaskStatusEnum.AGV_Execute;
                    _taskRepository.UpdateData(task);
                    station.Remark = task.PalletCode;
                    _stationMangerRepository.UpdateData(station);
                }
            }
        }
    }
}