huangxiaoqiang
11 小时以前 e483ac11616ffc9260d8f491fcc0d66f480b5443
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
using HslCommunication;
using Mapster;
using Microsoft.AspNetCore.Components.Routing;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using Quartz;
using WIDESEAWCS_BasicInfoService;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.OtherDeviceJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonMiddleOtherDevicesJob : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly ITaskRepository _taskRepository;
        private readonly IRouterService _routerService;
        private readonly IDt_StationManagerService _stationManagerService;
        private readonly ICacheService _cacheService;
        private readonly INoticeService _noticeService;
        private readonly IDt_StationManagerRepository _stationManagerRepository;
        private readonly ITask_HtyRepository _task_htyRepository;
        private readonly ISys_ConfigService _sys_ConfigService;
        private static List<string>? userTokenIds;
        private static List<int>? userIds;
 
        public CommonMiddleOtherDevicesJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, IDt_StationManagerService stationManagerService, ITask_HtyRepository task_htyRepository, ISys_ConfigService sys_ConfigService)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _taskRepository = taskRepository;
            _routerService = routerService;
            _cacheService = cacheService;
            _noticeService = noticeService;
            _stationManagerService = stationManagerService;
            _stationManagerRepository = stationManagerRepository;
            _task_htyRepository = task_htyRepository;
            _sys_ConfigService = sys_ConfigService;
        }
 
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                MiddleOtherDevice middleOtherDevice = (MiddleOtherDevice)context.JobDetail.JobDataMap.Get("JobParams");
                List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(middleOtherDevice.DeviceCode);
                
                foreach (var item in stationManagers.Where(x => x.stationType == 2))
                {
                    //读取下料请求
                    var DownRequest = middleOtherDevice.GetValue<DownOtherDeviceDBName, short>(DownOtherDeviceDBName.DownRequest, item.stationChildCode);
                    if (DownRequest == 1)
                    {
                        await RequestDownMaterialAsync(middleOtherDevice, item);
                    }
                }
 
            }
            catch (Exception ex)
            {
                WriteError("CommonOtherDevicesJob", "test", ex);
            }
            return;
        }
 
        /// <summary>
        /// 请求下料
        /// </summary>
        /// <param name="middleOtherDevice"></param>
        /// <param name="stationManager"></param>
        public async Task RequestDownMaterialAsync(MiddleOtherDevice middleOtherDevice, Dt_StationManager stationManager)
        {
            WebResponseContent content = new WebResponseContent();
            if (stationManager.stationProcessCodeType == 2)
            {
 
                List<string> str = stationManager.stationNextProcessCode.IsNullOrEmpty() ? new List<string>() : stationManager.stationNextProcessCode.Split(',').ToList();
                if (str.Count > 0)
                {
                    foreach (var item in str)
                    {
                        var nextStation = _stationManagerRepository.QueryFirst(x => x.stationProcessCode == item);
                        var UpRequest = middleOtherDevice.GetValue<UpOtherDeviceDBName, short>(UpOtherDeviceDBName.UpRequest, nextStation.stationChildCode);
                        if (UpRequest == 1)
                        {
                            var UpPosition = middleOtherDevice.GetValue<UpOtherDeviceDBName, short>(UpOtherDeviceDBName.UpPosition, nextStation.stationChildCode);
                            var wmsIpAddrss = _taskService.GetIpAddress(SysConfigKeyConst.RequsetInToGWOrCW);
                            var result = await HttpHelper.PostAsync(wmsIpAddrss, JsonConvert.SerializeObject(new { Position = stationManager.stationChildCode , TargetAddress = UpPosition , TargetStationManager  = item}));
                            content = JsonConvert.DeserializeObject<WebResponseContent>(result);
                            if (!content.Status)
                            {
                                ConsoleHelper.WriteErrorLine($"请求上料失败,站台:{stationManager.stationChildCode},错误信息:{content.Message}");
                                return;
                            }
                            var task = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString());
                            if (task == null)
                            {
                                ConsoleHelper.WriteErrorLine($"请求上料失败,站台:{stationManager.stationChildCode},错误信息:返回数据解析失败");
                                return;
                            }
                            _taskService.ReceiveWMSTask(task);
                            return;
                        }
                    }
                }
            }
        }
    }
}