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 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.R_PickRequest, station.StationCode); if (PickRequest) { string PickBarCode = conveyorLine.GetValue(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.R_DownRequest, station.StationCode); if (DownRequest) { string PickBarCode = conveyorLine.GetValue(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.R_InRequest, station.StationCode); bool InResponse = conveyorLine.GetValue(ConveyorLineDBName.W_InResponse, station.StationCode); int InWeight = conveyorLine.GetValue(ConveyorLineDBName.R_InWeight, station.StationCode); if (InRequest && !InResponse && InWeight>0) { string InBarCode = conveyorLine.GetValue(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; } } }