wangxinhui
2025-10-17 ce40df5daffae0d17b4e9fa7cb6d677afaa4d66f
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
using Newtonsoft.Json;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_Tasks.DBNames;
using WIDESEAWCS_Core.Helper;
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
using WIDESEAWCS_Tasks.ConveyorLineJob;
 
namespace WIDESEAWCS_Tasks
{
    /// <summary>
    /// 纸箱桁架
    /// </summary>
    [DisallowConcurrentExecution]
    public class TrussCartonJob : JobBase, IJob
    {
        private readonly ICacheService _cacheService;
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly ITaskRepository _taskRepository;
        private readonly IStationMangerRepository _stationMangerRepository;
        private readonly IRouterRepository _routerRepository;
        private readonly IRouterService _routerService;
        private readonly IRouterExtension _routerExtension;
        private readonly List<Dt_WarehouseDevice> warehouseDevices;
 
        public TrussCartonJob(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension)
        {
            _cacheService = cacheService;
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _taskRepository = taskRepository;
            _stationMangerRepository = stationMangerRepository;
            _routerRepository = routerRepository;
            _routerService = routerService;
            _routerExtension = routerExtension;
 
            string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice));
            if (!string.IsNullOrEmpty(warehouseDevicesStr))
            {
                warehouseDevices = JsonConvert.DeserializeObject<List<Dt_WarehouseDevice>>(warehouseDevicesStr) ?? new List<Dt_WarehouseDevice>();
            }
            else
            {
                warehouseDevices = new List<Dt_WarehouseDevice>();
            }
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null)
            {
                OtherDevice device = (OtherDevice)value;
                List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
                //获取协议
                DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == device.DeviceCode && x.DeviceProParamType == nameof(R_TrussCartonDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == device.DeviceCode && x.DeviceProParamType == nameof(W_TrussCartonDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                //判断协议是否满足
                if (deviceProRead!=null && deviceProWrite!=null)
                {
                    foreach (var item in stationMangers)
                    {
                        //码垛状态
                        bool Call = device.GetValue<R_TrussCartonDB, bool>(GetCartonCall(item.StackerCraneStationCode), item.StackerCraneCode);
                        
                        if (Call && item.IsOccupied == 0)
                        {
                            //请求WMS叫料任务
 
                        }
                        else if (Call && item.IsOccupied==1)
                        {
                            //请求WMS空托叠盘任务
 
                        }
                        
                    }
                }
                else
                {
                    WriteError(device.DeviceCode, $"未找到设备编号{device.DeviceCode}的协议信息");
                }
            }
            return Task.CompletedTask;
        }
 
        /// <summary>
        /// 获取桁架呼叫信号
        /// </summary>
        public R_TrussCartonDB GetCartonCall(string StationCode)
        {
            switch (StationCode)
            {
                case "1":
                    return R_TrussCartonDB.R_CartonCall1;
                case "2":
                    return R_TrussCartonDB.R_CartonCall2;
                case "3":
                    return R_TrussCartonDB.R_CartonCall3;
                case "4":
                    return R_TrussCartonDB.R_CartonCall4;
                case "5":
                    return R_TrussCartonDB.R_CartonCall5;
                case "6":
                    return R_TrussCartonDB.R_CartonCall6;
                default:
                    throw new Exception("未定义工位");
            }
        }
    }
}