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
using Autofac.Core;
using AutoMapper;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Service;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public partial class ConveyorLineJob2 : JobBase, IJob
    {
        public readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IStationMangerRepository _stationMangerRepository;
        private readonly ILocationInfoRepository _locationInfoRepository;
        private readonly IMapper _mapper;
 
        public ConveyorLineJob2(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IStationMangerRepository stationMangerRepository, ILocationInfoRepository locationInfoRepository, IMapper mapper)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _stationMangerRepository = stationMangerRepository;
            _locationInfoRepository = locationInfoRepository;
            _mapper = mapper;
        }
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                if (conveyorLine != null)
                {
                    List<Dt_StationManger> stationManagers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == conveyorLine.DeviceCode);
 
                    foreach (var station in stationManagers)
                    {
                        if (station.StationType==StationTypeEnum.StationType_OnlyOutbound.ObjToInt()) 
                        {
                            //拣选申请
                            bool PickRequest = conveyorLine.GetValue<ConveyorLineDBName, bool>(ConveyorLineDBName.R_PickRequest, station.StationCode);
                            if (PickRequest)
                            {
                                string PickBarCode = conveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.R_PickBarCode, station.StationCode).Trim();
                                //上报WMS料箱到达
                                if (PickBarCode.IsNotEmptyOrNull())
                                {
                                    WebResponseContent content = _taskService.WMSPickUp(station.PickStationCode, PickBarCode);
                                    //WebResponseContent content = WebResponseContent.Instance.OK();
                                    if (content.Status)
                                    {
                                        //写入拣选确认
                                        conveyorLine.SetValue(ConveyorLineDBName.W_PickToHode, (short)300, station.StationCode);
                                        WriteInfo(conveyorLine.DeviceCode, $"{station.PickStationCode}拣选申请上报成功{PickBarCode}");
                                    }
                                    else
                                    {
                                        WriteError(conveyorLine.DeviceCode, $"{station.PickStationCode}拣选申请上报WMS错误{PickBarCode},信息{content.Message}");
                                    }
                                }
                                else
                                {
                                    WriteError(conveyorLine.DeviceCode, $"{station.PickStationCode}拣选申请为{PickRequest}条码为空值");
                                }
                            }
                            //按钮申请
                            bool DownRequest = conveyorLine.GetValue<ConveyorLineDBName, bool>(ConveyorLineDBName.R_DownRequest, station.StationCode);
                            if (DownRequest)
                            {
                                string PickBarCode = conveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.R_PickBarCode, station.StationCode).Trim();
                                //上报WMS料箱到达
                                if (PickBarCode.IsNotEmptyOrNull())
                                {
                                    ContainerFlowDTO containerFlowDTO = new ContainerFlowDTO()
                                    {
                                        SlotCode = station.PickStationCode,
                                        ContainerCode = PickBarCode,
                                        Direction="100"
                                    };
                                    WebResponseContent responseContent = _taskService.ContainerFlow(containerFlowDTO, station.StationDeviceCode, station.PickStationCode);
                                    if (responseContent.Status)
                                    {
                                        conveyorLine.SetValue(ConveyorLineDBName.W_PickToHode, (short)containerFlowDTO.Direction.ObjToInt(), station.StationCode);
                                    }
                                    else
                                    {
                                        WriteError(conveyorLine.DeviceCode, $"{station.PickStationCode}按钮申请错误{PickBarCode},信息{responseContent.Message}");
                                    };
                                }
                                else
                                {
                                    WriteError(conveyorLine.DeviceCode, $"{station.PickStationCode}按钮申请为{DownRequest}条码为空值");
                                }
                                
                            }
 
                        }
                        else
                        {
                            //入库申请
                            bool InRequest = conveyorLine.GetValue<ConveyorLineDBName, bool>(ConveyorLineDBName.R_InRequest, station.StationCode);
                            bool InResponse = conveyorLine.GetValue<ConveyorLineDBName, bool>(ConveyorLineDBName.W_InResponse, station.StationCode);
                            int InWeight = conveyorLine.GetValue<ConveyorLineDBName, int>(ConveyorLineDBName.R_InWeight, station.StationCode);
                            if (InRequest && !InResponse && InWeight>0)
                            {
                                string InBarCode = conveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.R_InBarCode, station.StationCode).Trim();
                                //料箱到达
                                if (InBarCode.IsNotEmptyOrNull())
                                {
                                    //申请入库任务
                                    WebResponseContent content =_taskService.RequestInTask(station.StationCode,InBarCode);
                                    if (content.Status)
                                    {
                                        //写入入库确认
                                        conveyorLine.SetValue(ConveyorLineDBName.W_InResponse, true, station.StationCode);
                                        WriteInfo(conveyorLine.DeviceCode, $"站台{station.StationCode}料箱{InBarCode}申请入库成功");
                                    }
                                    else
                                    {
                                        WriteError(conveyorLine.DeviceCode, $"站台{station.StationCode}料箱{InBarCode}申请入库任务错误,信息{content.Message}");
                                    }
                                }
                                else
                                {
                                    WriteError(conveyorLine.DeviceCode, $"站台{station.StationCode}入库申请为{InRequest}条码为空值");
                                }
                            }
                        }
                        
                    }
 
                    conveyorLine.SetValue(ConveyorLineDBName.WriteHeart, true, conveyorLine.DeviceCode);
                }
            }
            catch (Exception ex)
            {
                WriteError(nameof(ConveyorLineJob2), ex.Message);
            }
            return Task.CompletedTask;
        }
    }
}