zhanghonglin
6 天以前 8f9b9411ca279670bd85fcfa7763987295ed9abf
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autofac.Core;
using HslCommunication.WebSocket;
using Microsoft.AspNetCore.Components;
using Quartz;
using SqlSugar;
using WIDESEA_Model.Models.Basic;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_DTO.MES;
using WIDESEAWCS_DTO.Stock;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models.System;
using WIDESEAWCS_Model.Models.TaskInfo;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_Tasks.Command;
using WIDESEAWCS_Tasks.DBname;
using WIDESEAWCS_Tasks.DBName;
using static Dm.net.buffer.ByteArrayBuffer;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class ConveyorLineJob : JobBase, IJob
    {
 
        private readonly IRepository<Dt_StationManger> _stationMangerRepository;
        private readonly IRepository<Dt_Task> _TaskRepository;
        private readonly IRepository<Dt_FillingOrder> _FillingOrderRepository;
        private readonly ITaskService _ITaskService;
        private static Stock Stock = new Stock();
        private static bool k = true;
        private static int i = 0;
 
        //判断是否把出库信号发给WMS
        private static bool m = true;
        private static bool n = true;
 
        //存储信号
        private readonly Commands comm = new Commands();
 
        public ConveyorLineJob(WebSocketServer webSocketServer, IRepository<Dt_StationManger> stationMangerRepository, IRepository<Dt_Task> TaskRepository, IRepository<Dt_FillingOrder> FillingOrderRepository, ITaskService ITaskService)
        {
            _stationMangerRepository = stationMangerRepository;
            _TaskRepository = TaskRepository;
            _ITaskService = ITaskService;
            _FillingOrderRepository = FillingOrderRepository;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            //堆垛机设备状态
            int sc = comm.GETR_TaskStatus();
            //连接设备
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null)
            {
                OtherDevice device = (OtherDevice)value;
                List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).Distinct().ToList();
                List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
                try
                {
                    //具体设备
                    foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
                    {
                        i++;
                        //读取信号
                        DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                        //DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode ).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                        if (deviceProRead != null)
                        {
                            ConveyorLineCommand conveyorLineInfoRead = device.Communicator.ReadCustomer<ConveyorLineCommand>(deviceProRead.DeviceProAddress);
                            //空桶入库任务
                            if (item.StationName == "空桶入")
                            {
                                comm.R_StatusA((short)conveyorLineInfoRead.R_State);
                                comm.R_PickA((short)conveyorLineInfoRead.R_Pick);
                                if (conveyorLineInfoRead.R_Pick == 1 && conveyorLineInfoRead.R_State == 1 && sc == 2)
                                {
                                    //判断任务是否重复
                                    Dt_Task task = _TaskRepository.QueryFirst(x => x.TaskType == (int)TaskTypeEnum.InEmpty);
                                    if (task == null)
                                    {
                                        LogLock.OutLogAOP("输送线任务日志", new string[] { device.DeviceCode, $"{"空桶入库任务生成" + "申请取(放)料:" + conveyorLineInfoRead.R_Pick + "设备状态:" + conveyorLineInfoRead.R_State}" });
                                        //WMS生成任务
                                        string address = AppSettings.Get("WMSApiAddress");
                                        if (!string.IsNullOrEmpty(address))
                                        {
                                            HttpHelper.Post($"{address}/api/Task/addInTask/?location={item.location}", "");
                                        }
                                    }
                                }
                            }
                            //满桶入库任务
                            if (item.StationName == "满桶入")
                            {
                                comm.R_StatusC((short)conveyorLineInfoRead.R_State);
                                comm.R_PickC((short)conveyorLineInfoRead.R_Pick);
                                if (conveyorLineInfoRead.R_Pick == 1 && conveyorLineInfoRead.R_State == 1 && sc == 2)
                                {
                                    //清空物料编号
                                    if (k)
                                    {
                                        Stock.MaterialCode1 = "";
                                        Stock.MaterialCode2 = "";
                                        Stock.MaterialCode3 = "";
                                        Stock.MaterialCode4 = "";
                                        k = false;
                                    }
                                    //存储物料编号
                                    Stock.MaterialCode1 = conveyorLineInfoRead.R_NumberA;
                                    Stock.MaterialCode2 = conveyorLineInfoRead.R_NumberB;
                                    Stock.MaterialCode3 = conveyorLineInfoRead.R_NumberC;
                                    Stock.MaterialCode4 = conveyorLineInfoRead.R_NumberD;
 
                                    //判断任务是否重复
                                    Dt_Task task = _TaskRepository.QueryFirst(x => x.TaskType == (int)TaskTypeEnum.Infull || x.TaskType == (int)TaskTypeEnum.OutDirect);
                                    if (task == null)
                                    {
                                        LogLock.OutLogAOP("输送线任务日志", new string[] { device.DeviceCode, $"{"满桶入库任务生成" + "申请取(放)料:" + conveyorLineInfoRead.R_Pick + "设备状态:" + conveyorLineInfoRead.R_State + "//" + conveyorLineInfoRead.R_NumberA + "/" + conveyorLineInfoRead.R_NumberB + "/" + conveyorLineInfoRead.R_NumberC + "/" + conveyorLineInfoRead.R_NumberD}" });
                                        Stock.location = item.location;
                                        //WMS生成任务
                                        string address = AppSettings.Get("WMSApiAddress");
                                        if (!string.IsNullOrEmpty(address))
                                        {
                                            HttpHelper.Post($"{address}/api/Task/addOutTask/", Stock.Serialize());
 
                                            //发送收到编号信号
                                            device.SetValue(ConveyorLineName.W_ReceivedD, 1, item.StationCode);
                                            k = true;
                                        }
 
                                    }
                                }
                            }
                            //空桶出
                            if (item.StationName == "空桶出")
                            {
                                comm.R_StatusB((short)conveyorLineInfoRead.R_State);
                                comm.R_PickB((short)conveyorLineInfoRead.R_Pick);
                                //if (conveyorLineInfoRead.R_Pick == 1 && conveyorLineInfoRead.R_State == 1 && sc == 2)
                                //{
 
                                //    //判断任务是否重复
                                //    Dt_Task task = _TaskRepository.QueryFirst(x => x.TaskType == (int)TaskTypeEnum.OutEmpty);
                                //    if (task == null)
                                //    {
                                //        LogLock.OutLogAOP("输送线任务日志", new string[] { device.DeviceCode, $"{"空桶出库任务生成" + "申请取(放)料:" + conveyorLineInfoRead.R_Pick + "设备状态:" + conveyorLineInfoRead.R_State}" });
                                //        //WMS生成任务
                                //        string address = AppSettings.Get("WMSApiAddress");
                                //        if (!string.IsNullOrEmpty(address))
                                //        {
                                //            HttpHelper.Post($"{address}/api/Task/addOutEmptyTask/?location={item.location}", "");
                                //        }
                                //    }
 
                                //}
                            }
                            //满桶出
                            if (item.StationName == "满桶出")
                            {
                                comm.R_StatusD((short)conveyorLineInfoRead.R_State);
                                comm.R_PickD((short)conveyorLineInfoRead.R_Pick);
                            }
                        }
                    }
                    i = 0;
                }
                catch (Exception ex)
                {
                    //写入日志
                    WriteInfo(device.DeviceCode, $"{ex.Message}");
                }
            }
            return Task.CompletedTask;
        }
    }
}