1
z8018
2025-06-10 e46aa927d231af83724683c7286d9db503e24cf7
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using WIDESEAWCS_Common;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_Tasks.ConveyorLineJob;
 
namespace WIDESEAWCS_Tasks
{
    /// <summary>
    /// 站点释放任务,用于自动释放指定设备的容器并更新灯光状态。
    /// </summary>
    /// <remarks>
    /// 1. 从任务上下文中获取设备参数 <br/>
    /// 2. 筛选出需要处理的设备子编码 <br/>
    /// 3. 检查每个设备的站台释放信号 <br/>
    /// 4. 若信号为真,则自动释放容器并更新对应设备的灯光状态为"已完成" <br/>
    /// 5. 处理过程中捕获并记录异常
    /// </remarks>
    [DisallowConcurrentExecution]
    public class StationReleaseJob : JobBase, IJob
    {
        private readonly IContainerService _containerService;
        public StationReleaseJob(IContainerService containerService)
        {
            _containerService = containerService;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null && value is OtherDevice otherDevice)
            {
                try
                {
                    List<string> deviceChildCodes = otherDevice.DeviceProDTOs.Where(x => x.DeviceProParamType == nameof(ConveyorLineStationDBName.StationRelease)).GroupBy(x => x.DeviceChildCode).Select(x => x.Key).ToList();
                    foreach (string deviceChildCode in deviceChildCodes)
                    {
                        bool signal = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.StationRelease, deviceChildCode);
                        if (signal)
                        {
                            WriteDebug($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", $"按钮释放工位【{deviceChildCode}】");
 
                            _containerService.AutoReleaseContainer(deviceChildCode);
 
                            if (LightStatusStorage.LightStatusDic.ContainsKey(deviceChildCode))
                            {
                                LightStatusStorage.LightStatusDic[deviceChildCode] = LightStatusEnum.LightCompleted;
                                Thread.Sleep(5 * 1000);
                                LightStatusStorage.LightStatusDic[deviceChildCode] = LightStatusEnum.None;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", ex.Message, ex);
                }
            }
            else
            {
                WriteError(nameof(StationReleaseJob), "参数错误,未传递设备参数或设备类型错误");
            }
            return Task.CompletedTask;
        }
    }
}