wangxinhui
昨天 6d3ea08855337c0cfcc60df2903d3431611c7097
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
using Autofac.Core;
using Microsoft.AspNetCore.Components.Routing;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Text.Unicode;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.Helper;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.ConveyorLine.Enum;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.DBNames;
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class ConveyorLineJob1 : 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 static string BarCode1 = "";
        private static string BarCode2 = "";
        public ConveyorLineJob1(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;
        }
        /*
        1号位出库口允许放箱        0
        1号位放箱完成信号          21
        6号位拣选位料箱到达        1
        6号位拣选位料箱条码        2
        6号位拣选位料箱流动        22
        8号位入库口允许取箱        11
        8号位入库口料箱条码        12
        8号位机器人取箱完成        23
        */
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                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);
                    
                    foreach (var station in stationMangers)
                    {
                        if (station.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt())
                        {
 
                            //拣选申请
                            short pickArrived = device.Communicator.Read<short>("1");
                            if (pickArrived == 256)
                            {
                                byte[] bytesPick = device.Communicator.Read("2", 5);
                                string pickBarCode = Encoding.UTF8.GetString(bytesPick).Replace("\0", "").Replace("\\0", "");
                                //上报WMS料箱到达
                                if (pickBarCode.IsNotEmptyOrNull())
                                {
                                    if (device.DeviceCode == "CL1" && BarCode1!= pickBarCode)
                                    {
                                        WebResponseContent content = _taskService.WMSPickUp(station.PickStationCode, pickBarCode);
                                        if (content.Status)
                                        {
                                            WriteInfo(device.DeviceCode, $"{station.PickStationCode}拣选申请上报成功{pickBarCode}");
                                        }
                                        else
                                        {
                                            WriteError(device.DeviceCode, $"{station.PickStationCode}拣选申请上报WMS错误{pickBarCode},信息{content.Message}");
                                        }
                                        BarCode1 = pickBarCode;
                                    }
                                    if (device.DeviceCode == "CL2" && BarCode1 != pickBarCode)
                                    {
                                        WebResponseContent content = _taskService.WMSPickUp(station.PickStationCode, pickBarCode);
                                        if (content.Status)
                                        {
                                            WriteInfo(device.DeviceCode, $"{station.PickStationCode}拣选申请上报成功{pickBarCode}");
                                        }
                                        else
                                        {
                                            WriteError(device.DeviceCode, $"{station.PickStationCode}拣选申请上报WMS错误{pickBarCode},信息{content.Message}");
                                        }
                                        BarCode2 = pickBarCode;
                                    }
                                }
                                else
                                {
                                    WriteError(device.DeviceCode, $"{station.PickStationCode}拣选申请为{pickArrived}条码为空值");
                                }
                            }
                        }
                        else
                        {
                            //入库申请
                            short InTake = device.Communicator.Read<short>("11");
                            byte[] bytesIn = device.Communicator.Read("12", 5);
                            string InBarCode = Encoding.UTF8.GetString(bytesIn).Replace("\0", "").Replace("\\0", "");
                            if (InTake==256 && InBarCode.IsNotEmptyOrNull())
                            {
                                //申请入库任务
                                Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == InBarCode && x.TaskType == TaskTypeEnum.Inbound.ObjToInt() && x.TaskState != TaskStatusEnum.CL_Executing.ObjToInt() && x.DeviceCode==device.DeviceCode);
                                if (task != null) continue;
 
                                WebResponseContent content = _taskService.RequestInTask(station.StationCode, InBarCode);
                                if (content.Status)
                                {
                                    WriteInfo(device.DeviceCode, $"站台{station.StationCode}料箱{InBarCode}申请入库成功");
                                }
                                else
                                {
                                    WriteError(device.DeviceCode, $"站台{station.StationCode}料箱{InBarCode}申请入库任务错误,信息{content.Message}");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteError(nameof(ConveyorLineJob1), ex.Message);
            }
            return Task.CompletedTask;
        }
    }
}