¶Ô±ÈÐÂÎļþ |
| | |
| | | #region MyRegion |
| | | #region << ç æ¬ 注 é >> |
| | | |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_Tasks.ConveyorLineJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using AutoMapper; |
| | | using HslCommunication; |
| | | using Microsoft.AspNetCore.Server.HttpSys; |
| | | using Newtonsoft.Json; |
| | | using Quartz; |
| | | using SqlSugar; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Reflection; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_BasicInfoRepository; |
| | | using WIDESEAWCS_BasicInfoService; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_IProcessRepository; |
| | | using WIDESEAWCS_ISystemRepository; |
| | | using WIDESEAWCS_ISystemServices; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_Tasks.ConveyorLineJob; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | | [DisallowConcurrentExecution] |
| | | public partial class CommonConveyorLine_GWJob : JobBase, IJob |
| | | { |
| | | public readonly ITaskService _taskService; |
| | | private readonly ITaskRepository _taskRepository; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly IRouterService _routerService; |
| | | private readonly IPlatFormRepository _platFormRepository; |
| | | private readonly ISys_ConfigService _sys_ConfigService; |
| | | private readonly IMapper _mapper; |
| | | private readonly IDt_StationManagerRepository _stationManagerRepository; |
| | | |
| | | public CommonConveyorLine_GWJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository, IPlatFormRepository platFormRepository, ISys_ConfigService sys_ConfigService, IDt_StationManagerRepository stationManagerRepository) |
| | | { |
| | | _taskService = taskService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _routerService = routerService; |
| | | _mapper = mapper; |
| | | _taskRepository = taskRepository; |
| | | _platFormRepository = platFormRepository; |
| | | _sys_ConfigService = sys_ConfigService; |
| | | _stationManagerRepository = stationManagerRepository; |
| | | } |
| | | |
| | | public Task Execute(IJobExecutionContext context) |
| | | { |
| | | try |
| | | { |
| | | CommonConveyorLine_GW conveyorLine = (CommonConveyorLine_GW)context.JobDetail.JobDataMap.Get("JobParams"); |
| | | if (conveyorLine != null) |
| | | { |
| | | #region ç«å°æ¹å¼ |
| | | //List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode); |
| | | |
| | | //foreach (var station in stationManagers) |
| | | //{ |
| | | // ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(station.stationChildCode); |
| | | |
| | | // DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand_After.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString()); |
| | | // if (deviceProtocolDetails != null) |
| | | // { |
| | | // MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType); |
| | | // if (method != null) |
| | | // { |
| | | // method.Invoke(this, new object[] { conveyorLine, command, station }); |
| | | // } |
| | | // } |
| | | //} |
| | | #endregion |
| | | |
| | | #region è·¯ç±æ¹å¼ |
| | | List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode); |
| | | foreach (string childDeviceCode in childDeviceCodes) |
| | | { |
| | | ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode); |
| | | |
| | | if (command.ConveyorLineBarcode.Trim().Contains("\0")) command.ConveyorLineBarcode = ""; |
| | | |
| | | DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand_After.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString()); |
| | | if (deviceProtocolDetails != null) |
| | | { |
| | | MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType); |
| | | if (method != null) |
| | | { |
| | | method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode }); |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.Out.WriteLine(nameof(CommonConveyorLine_AfterJob) + ":" + ex.ToString()); |
| | | } |
| | | finally |
| | | { |
| | | //WriteDebug("CommonConveyorLineJob", "test"); |
| | | //Console.Out.WriteLine(DateTime.Now); |
| | | } |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// è¾é线请æ±å
¥åº |
| | | /// </summary> |
| | | /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> |
| | | /// <param name="command">读åç请æ±ä¿¡æ¯</param> |
| | | /// <param name="childDeviceCode">å设å¤ç¼å·</param> |
| | | /// <param name="ProtocalDetailValue">线ä½å½åbool读ååç§»å°å</param> |
| | | public void RequestInbound(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) |
| | | { |
| | | try |
| | | { |
| | | var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode); |
| | | //HandleTaskOut(conveyorLine, command, childDeviceCode, task); |
| | | // && command.ConveyorLineBarcode != "NoRead" && !command.ConveyorLineBarcode.IsNotEmptyOrNull() |
| | | if (task == null) |
| | | { |
| | | HandleNewTask(conveyorLine, command, childDeviceCode); |
| | | |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.Out.WriteLine(ex.ToString()); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è¾é线å
¥åºå®æ |
| | | /// </summary> |
| | | /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> |
| | | /// <param name="command">读åç请æ±ä¿¡æ¯</param> |
| | | /// <param name="childDeviceCode">å设å¤ç¼å·</param> |
| | | /// <param name="ProtocalDetailValue">线ä½å½åbool读ååç§»å°å</param> |
| | | public void ConveyorLineInFinish(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) |
| | | { |
| | | var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); |
| | | if (task != null && task.TaskState != (int)TaskInStatusEnum.Line_InFinish) |
| | | { |
| | | //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); |
| | | |
| | | WebResponseContent content = _taskService.UpdateTaskStatusToNext(task); |
| | | |
| | | if(content.Status) |
| | | { |
| | | conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, childDeviceCode); |
| | | } |
| | | |
| | | Console.Out.WriteLine(content.Serialize()); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è¾é线请æ±åºä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> |
| | | /// <param name="command">读åç请æ±ä¿¡æ¯</param> |
| | | /// <param name="childDeviceCode">å设å¤ç¼å·</param> |
| | | /// <param name="ProtocalDetailValue">线ä½å½åbool读ååç§»å°å</param> |
| | | public void RequestOutbound(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, int ProtocalDetailValue) |
| | | { |
| | | var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode); |
| | | if (task != null) |
| | | { |
| | | ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task); |
| | | taskCommand.InteractiveSignal = command.InteractiveSignal; |
| | | conveyorLine.SendCommand(taskCommand, childDeviceCode); |
| | | |
| | | //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); |
| | | _taskService.UpdateTaskStatusToNext(task); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// è¾é线åºåºå®æ |
| | | /// </summary> |
| | | /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> |
| | | /// <param name="command">读åç请æ±ä¿¡æ¯</param> |
| | | /// <param name="childDeviceCode">å设å¤ç¼å·</param> |
| | | public void ConveyorLineOutFinish(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) |
| | | { |
| | | var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); |
| | | if (task != null) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); |
| | | taskCommand.InteractiveSignal = command.InteractiveSignal; |
| | | if (task.PalletCode != command.ConveyorLineBarcode) |
| | | { |
| | | var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == task.TargetAddress).Capacity; |
| | | taskCommand.ConveyorLineTargetAddress = (short)NGAddress; |
| | | } |
| | | else |
| | | { |
| | | taskCommand.ConveyorLineTargetAddress = 1000; |
| | | } |
| | | |
| | | conveyorLine.SendCommand(taskCommand, childDeviceCode); |
| | | //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); |
| | | content = _taskService.UpdateTaskStatusToNext(task); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è¾é线交äºå®æ |
| | | /// </summary> |
| | | /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> |
| | | /// <param name="childDeviceCode">å设å¤ç¼å·</param> |
| | | /// <param name="ProtocalDetailValue">线ä½å½åbool读ååç§»å°å</param> |
| | | /// <param name="value">å¼</param> |
| | | //public void ConveyorLineSendFinish(CommonConveyorLine conveyorLine, string childDeviceCode, int ProtocalDeValue, bool value) |
| | | //{ |
| | | // DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == childDeviceCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | // string[] x = devicePro.DeviceProAddress.Split('.'); |
| | | // x[x.Length - 1] = (ProtocalDetailValue + 1).ToString(); |
| | | // string DeviceProAddress = string.Join(".", x); |
| | | // conveyorLine.Communicator.Write(DeviceProAddress, value); |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// çæµç©ºæçå®çåºåº |
| | | /// </summary> |
| | | /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> |
| | | /// <param name="command">读åç请æ±ä¿¡æ¯</param> |
| | | /// <param name="childDeviceCode">å设å¤ç¼å·</param> |
| | | /// <param name="index">线ä½å½åbool读ååç§»å°å</param> |
| | | public async void EmptyTrayReturn(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, int index, Platform platform) |
| | | { |
| | | try |
| | | { |
| | | TaskOutboundTypeEnum taskOutboundTypeEnum; |
| | | if (platform.PlatformType.Contains("OutTray")) |
| | | taskOutboundTypeEnum = TaskOutboundTypeEnum.OutTray; |
| | | else |
| | | taskOutboundTypeEnum = TaskOutboundTypeEnum.Outbound; |
| | | await CheckAndCreateTask(taskOutboundTypeEnum, childDeviceCode, index, platform.Stacker); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ£æ¥ä»»å¡å¹¶å建æ°ä»»å¡ |
| | | /// </summary> |
| | | private async Task CheckAndCreateTask(TaskOutboundTypeEnum taskType, string childDeviceCode, int index, string roadWay, List<string> roadways = null) |
| | | { |
| | | var tasks = _taskRepository.QueryData(x => x.TaskType == (int)taskType && x.TargetAddress == childDeviceCode); |
| | | if (tasks.Count < index) |
| | | { |
| | | #region è°ç¨WMSè·ååºåºä»»å¡ |
| | | |
| | | WMSTaskDTO taskDTO = new WMSTaskDTO(); |
| | | |
| | | // è·åWMSipå°å |
| | | var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); |
| | | var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; |
| | | var requestTrayOutTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTrayOutTask)?.ConfigValue; |
| | | if (wmsBase == null || requestTrayOutTask == null) |
| | | { |
| | | throw new InvalidOperationException("WMS IP æªé
ç½®"); |
| | | } |
| | | var wmsIpAddress = wmsBase + requestTrayOutTask; |
| | | |
| | | |
| | | var result = await HttpHelper.PostAsync(wmsIpAddress, new { position = childDeviceCode, tag = (int)taskType, areaCdoe = roadWay, roadways = roadways }.ToJsonString()); |
| | | //var result = await HttpHelper.PostAsync("http://localhost:5000/api/Task/RequestTrayOutTaskAsync", dynamic.ToJsonString()); |
| | | |
| | | WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result); |
| | | |
| | | // æ£æ¥ç¶æå¹¶è¿å |
| | | if (!content.Status) |
| | | return; |
| | | |
| | | taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); |
| | | |
| | | #endregion |
| | | |
| | | CreateAndSendTask(taskDTO); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åå»ºä»»å¡ |
| | | /// </summary> |
| | | public WebResponseContent CreateAndSendTask(WMSTaskDTO taskDTO) |
| | | { |
| | | var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | if (content.Status) |
| | | { |
| | | Console.WriteLine($"{taskDTO.TaskType}å¼å«æå"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | } |
| | | } |
| | | #endregion |