1
z8018
2025-04-16 1f361850d35ba47225951efbc49d592eea685cf8
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
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using HslCommunication;
using Quartz;
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.BasicInfo;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonConveyorLineStationJob : JobBase, IJob
    {
        private readonly IMapper _mapper;
 
        private readonly ITaskRepository _taskRepository;
 
        public CommonConveyorLineStationJob(IMapper mapper, ITaskRepository taskRepository)
        {
            _mapper = mapper;
            _taskRepository = taskRepository;
        }
 
 
        public Task Execute(IJobExecutionContext context)
        {
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null && value is OtherDevice)
            {
                OtherDevice otherDevice = (OtherDevice)value;
                try
                {
                    List<string> deviceChildCodes = otherDevice.DeviceProDTOs.GroupBy(x => x.DeviceChildCode).Select(x => x.Key).ToList();
                    for (int i = 0; i < deviceChildCodes.Count; i++)
                    {
                        bool request = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationRequest, deviceChildCodes[i]);   //申请
                        bool response = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.PLCStationResponse, deviceChildCodes[i]);    //应答
 
                        bool wcsResponse = otherDevice.GetValue<ConveyorLineStationDBName, bool>(ConveyorLineStationDBName.WCSStationResponse, deviceChildCodes[i]);    //应答
 
                        if (request && !response && !wcsResponse)
                        {
                            int taskNum = otherDevice.GetValue<ConveyorLineStationDBName, int>(ConveyorLineStationDBName.PLCStationTaskNum, deviceChildCodes[i]);
                            if (taskNum > 0)
                            {
                                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
                                if (task != null)
                                {
                                    task.TaskState = TaskStatusEnum.Gantry_New.ObjToInt();
                                    _taskRepository.UpdateData(task);
                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, 0, deviceChildCodes[i]);
                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true, deviceChildCodes[i]);
                                }
                                else
                                {
                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationTarget, 8, deviceChildCodes[i]);
                                    otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, true, deviceChildCodes[i]);
                                }
                            }
                        }
                        else
                        {
                            if (wcsResponse && !request)
                                otherDevice.SetValue(ConveyorLineStationDBName.WCSStationResponse, false, deviceChildCodes[i]);  //清除响应
                        }
                    }
 
 
                }
                catch (Exception ex)
                {
                    WriteError($"{otherDevice.DeviceCode}-{otherDevice.DeviceName}", ex.Message, ex);
                }
            }
            else
            {
                WriteError(nameof(CommonConveyorLineStationJob), "参数错误,未传递设备参数或设备类型错误");
            }
            return Task.CompletedTask;
        }
 
        public int[] GetIndexArray<T>(T[] values, T value)
        {
            List<int> result = new List<int>();
            for (int i = 0; i < values.Length; i++)
            {
                if (value.Equals(values[i]))
                {
                    result.Add(i);
                }
            }
            return result.ToArray();
        }
    }
}