Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine_NewCW.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,342 @@ #region << ç æ¬ 注 é >> /*---------------------------------------------------------------- * å½å空é´ï¼WIDESEAWCS_QuartzJob * å建è ï¼è¡ç«¥åº * å建æ¶é´ï¼2024/8/2 16:13:36 * çæ¬ï¼V1.0.0 * æè¿°ï¼ä¸è¬è¾é线å®ç°ç±» * * ---------------------------------------------------------------- * ä¿®æ¹äººï¼ * ä¿®æ¹æ¶é´ï¼ * çæ¬ï¼V1.0.1 * ä¿®æ¹è¯´æï¼ * *----------------------------------------------------------------*/ #endregion << ç æ¬ 注 é >> using HslCommunication; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEAWCS_Communicator; using WIDESEAWCS_QuartzJob.ConveyorLine.Enum; using WIDESEAWCS_QuartzJob.DeviceBase; using WIDESEAWCS_QuartzJob.DTO; using WIDESEAWCS_QuartzJob.StackerCrane.Enum; namespace WIDESEAWCS_QuartzJob { [Description("常温æ°å è¾é线")] public class CommonConveyorLine_NewCW : IConveyorLine { #region Private Member /// <summary> /// å åæºé讯对象 /// </summary> private readonly BaseCommunicator _communicator; /// <summary> /// å åæºåè®®ä¿¡æ¯ /// </summary> private readonly List<DeviceProDTO> _deviceProDTOs; /// <summary> /// å åæºåè®®æç»ä¿¡æ¯ /// </summary> private readonly List<DeviceProtocolDetailDTO> _deviceProtocolDetailDTOs; /// <summary> /// 设å¤ç¼å· /// </summary> public readonly string _deviceCode; /// <summary> /// 设å¤åç§° /// </summary> public readonly string _deviceName; private bool _heartStatr = true; private bool _isConnected = true; #endregion #region Public Member /// <summary> /// è¾é线é讯对象 /// </summary> public BaseCommunicator Communicator => _communicator; /// <summary> /// è¾é线åè®®ä¿¡æ¯ /// </summary> public List<DeviceProDTO> DeviceProDTOs => _deviceProDTOs; /// <summary> /// è¾é线åè®®æç»ä¿¡æ¯ /// </summary> public List<DeviceProtocolDetailDTO> DeviceProtocolDetailDTOs => _deviceProtocolDetailDTOs; /// <summary> /// 设å¤ç¼å· /// </summary> public string DeviceCode => _deviceCode; /// <summary> /// 设å¤åç§° /// </summary> public string DeviceName => _deviceName; /// <summary> /// æ¯å¦ææ é /// </summary> public bool IsFault => false; /// <summary> /// é讯æ¯å¦å·²è¿æ¥ /// </summary> public bool IsConnected => Communicator.IsConnected && _isConnected; /// <summary> /// 设å¤ç¶æ /// </summary> public DeviceStatus Status => DeviceStatus.Offline; #endregion #region Constructor Function /// <summary> /// æé 彿° /// </summary> /// <param name="communicator">å åæºé讯对象</param> /// <param name="deviceProDTOs">å åæºå议信æ¯</param> /// <param name="deviceProtocolDetailDTOs">å åæºåè®®æç»ä¿¡æ¯</param> /// <param name="deviceCode">设å¤ç¼å·</param> /// <param name="deviceName">设å¤åç§°</param> public CommonConveyorLine_NewCW(BaseCommunicator communicator, List<DeviceProDTO> deviceProDTOs, List<DeviceProtocolDetailDTO> deviceProtocolDetailDTOs, string deviceCode, string deviceName) { _communicator = communicator; _deviceProDTOs = deviceProDTOs; _deviceProtocolDetailDTOs = deviceProtocolDetailDTOs; _deviceCode = deviceCode; _deviceName = deviceName; CheckConnect(); } #endregion #region Private Method private void CheckConnect() { Task.Run(() => { while (_heartStatr) { try { DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(); if (devicePro == null) _isConnected = false; else Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); _isConnected = true; } catch (Exception ex) { _isConnected = false; } Thread.Sleep(500); } }); } #endregion #region Public Method /// <summary> /// 读åPLCåè®®å°åçæ°æ® /// </summary> /// <typeparam name="TEnum">å议信æ¯çæä¸¾å¯¹è±¡ä¿¡æ¯ã</typeparam> /// <typeparam name="TRsult">è¯»åæ°æ®çç±»å对象信æ¯ã</typeparam> /// <param name="value">æä¸¾å¼</param> /// <param name="deviceChildCode">设å¤åç¼å·</param> /// <returns>读åå°çæ°æ®</returns> public TRsult GetValue<TEnum, TRsult>(TEnum value, string deviceChildCode) where TEnum : Enum { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString() && x.DeviceChildCode == deviceChildCode); return devicePro == null ? throw new Exception() : (TRsult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); } /// <summary> /// ä¸è®¾å¤çå¿è·³ /// </summary> public void Heartbeat() { throw new NotImplementedException(); } /// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="command"></param> /// <param name="deviceChildCode"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public bool SendCommand<T>(T command, string deviceChildCode) where T : IDataTransfer, new() { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); if (devicePro == null) { return false; } if (Communicator.WriteCustomer(devicePro.DeviceProAddress, command)) { return true; } return false; } /// <summary> /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ /// </summary> /// <typeparam name="T">æ³å</typeparam> /// <param name="deviceChildCode">å设å¤ç¼å·</param> /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> /// <exception cref="Exception"></exception> public T ReadCustomer<T>(string deviceChildCode) where T : IDataTransfer, new() { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == "DeviceCommand" && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); if (devicePro == null) { throw new Exception($"ã{_deviceCode}ã--æªæ¾å°ã{deviceChildCode}ãå议信æ¯"); } else { return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); } } /// <summary> /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ /// </summary> /// <typeparam name="T">æ³å</typeparam> /// <param name="deviceChildCode">å设å¤ç¼å·</param> /// <param name="deviceProParamType">åæ°ç±»å</param> /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> /// <exception cref="Exception"></exception> public T ReadCustomer<T>(string deviceChildCode, string deviceProParamType) where T : IDataTransfer, new() { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == deviceProParamType && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); if (devicePro == null) { throw new Exception($"æªæ¾å°ã{deviceChildCode}ãå议信æ¯"); } else { return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); } } /// <summary> /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·åå ¥å¯¹åºçæ°æ®ã /// </summary> /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> /// <typeparam name="TValue">è¦åå ¥çæ°æ®ç±»åã</typeparam> /// <param name="enum">åæ°åç§°ã</param> /// <param name="value">è¦åå ¥çæ°æ®ã</param> /// <param name="deviceChildCode">设å¤åç¼å·å</param> /// <returns>è¿ååå ¥æåæå¤±è´¥</returns> public bool SetValue<TEnum, TValue>(TEnum @enum, TValue value, string deviceChildCode) where TEnum : Enum where TValue : notnull { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); return devicePro == null ? throw new Exception() : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value); } /// <summary> /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·è¯»å对åºçæ°æ®ã /// </summary> /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> /// <param name="enum">åæ°åç§°ã</param> /// <param name="deviceChildCode">设å¤åç¼å·å</param> /// <returns>è¿ååå ¥æåæå¤±è´¥</returns> public object ReadValue<TEnum>(TEnum @enum, string deviceChildCode) where TEnum : Enum { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); return devicePro == null ? throw new Exception() : Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); } //public bool IsOccupied(string deviceChildCode) //{ // if (Communicator.IsConnected) // { // } //} /// <summary> /// /// </summary> /// <param name="deviceChildCode"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public bool IsOccupied(string deviceChildCode) { if (Communicator.IsConnected) { List<DeviceProDTO> devicePros = _deviceProDTOs.Where(x => x.DeviceChildCode == deviceChildCode && x.DeviceProParamName == "InteractiveSignal").ToList(); if (devicePros.Count == 0) { //todo åè®®ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ throw new Exception(); } for (int i = 0; i < devicePros.Count; i++) { object readStatus = Communicator.ReadAsObj(devicePros[i].DeviceProAddress, devicePros[i].DeviceDataType); //todo åè®®æç»ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamName) ?? throw new Exception(); deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == "InteractiveSignal" && x.ProtocalDetailValue.Equals(readStatus.ToString())); if (deviceProtocolDetail != null) { return true; } return false; } } //todo é讯æªè¿æ¥æ¶æåºå¼å¸¸ return false; } public void Dispose() { _heartStatr = false; _communicator.Dispose(); GC.SuppressFinalize(this); } #endregion } } Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/CommonConveyorLine_GWJob.cs
@@ -231,10 +231,10 @@ { if (childDeviceCode == "1039") { var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList(); if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2")) var GWTask = _taskRepository.QueryData(x => (x.Roadway.Contains("GWSC2")|| x.Roadway.Contains("GWSC3")) && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList(); if ((GWTask.Where(x => x.Roadway.Contains("GWSC2")).ToList().Count >= 2 && task.Roadway.Contains("GWSC2")) || (GWTask.Where(x => x.Roadway.Contains("GWSC3")).ToList().Count >= 2 && task.Roadway.Contains("GWSC3"))) { ConsoleHelper.WriteErrorLine($"æ¶é´ï¼ã{DateTime.Now}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã髿¸©äºå·²åå¨ã{GWTask.Count}ã个任å¡å¤§äº2个任å¡ä¸å¯ä¸å"); ConsoleHelper.WriteErrorLine($"æ¶é´ï¼ã{DateTime.Now}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã髿¸©{(task.Roadway.Contains("GWSC3")?"ä¸":"äº")}å·²åå¨ã{GWTask.Count}ã个任å¡å¤§äº2个任å¡ä¸å¯ä¸å"); return; } } Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_NewCW/CommonConveyorLine_NewCWJob.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,620 @@ #region MyRegion #region << ç æ¬ 注 é >> /*---------------------------------------------------------------- * å½å空é´ï¼WIDESEAWCS_Tasks.ConveyorLineJob * å建è ï¼è¡ç«¥åº * å建æ¶é´ï¼2024/8/2 16:13:36 * çæ¬ï¼V1.0.0 * æè¿°ï¼ * * ---------------------------------------------------------------- * ä¿®æ¹äººï¼ * ä¿®æ¹æ¶é´ï¼ * çæ¬ï¼V1.0.1 * ä¿®æ¹è¯´æï¼ * *----------------------------------------------------------------*/ #endregion << ç æ¬ 注 é >> using AutoMapper; using HslCommunication; using Masuit.Tools; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using Quartz; using SqlSugar; using System.ComponentModel.Design; using System.Reflection; using WIDESEAWCS_BasicInfoRepository; using WIDESEAWCS_Common; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Core; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_Core.HttpContextUser; using WIDESEAWCS_DTO.MOM; using WIDESEAWCS_DTO.TaskInfo; using WIDESEAWCS_IProcessRepository; using WIDESEAWCS_ISystemServices; using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_QuartzJob.DTO; using WIDESEAWCS_QuartzJob.Repository; using WIDESEAWCS_QuartzJob.Service; using WIDESEAWCS_SignalR; using WIDESEAWCS_Tasks.ConveyorLineJob; using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; using Platform = WIDESEAWCS_Model.Models.Platform; namespace WIDESEAWCS_Tasks { [DisallowConcurrentExecution] public partial class CommonConveyorLine_NewCWJob : 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; private readonly ICacheService _cacheService; private readonly INoticeService _noticeService; private readonly IDt_needBarcodeRepository _needBarcodeRepository; private readonly IDeviceInfoRepository _deviceInfoRepository; private static List<string>? userTokenIds; private static List<int>? userIds; private static List<string> childCodeList = new List<string>(); public CommonConveyorLine_NewCWJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository, IPlatFormRepository platFormRepository, ISys_ConfigService sys_ConfigService, IDt_StationManagerRepository stationManagerRepository, ICacheService cacheService, INoticeService noticeService, IDt_needBarcodeRepository needBarcodeRepository, IDeviceInfoRepository deviceInfoRepository) { _taskService = taskService; _taskExecuteDetailService = taskExecuteDetailService; _routerService = routerService; _mapper = mapper; _taskRepository = taskRepository; _platFormRepository = platFormRepository; _sys_ConfigService = sys_ConfigService; _stationManagerRepository = stationManagerRepository; _cacheService = cacheService; _noticeService = noticeService; _needBarcodeRepository = needBarcodeRepository; _deviceInfoRepository = deviceInfoRepository; } public Task Execute(IJobExecutionContext context) { try { CommonConveyorLine_NewCW conveyorLine = (CommonConveyorLine_NewCW)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 == null) continue; //if (command.InteractiveSignal == 0 && command.HasPallet != 1) continue; 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 }); } } if (childDeviceCode == "1670" || childDeviceCode == "1666" || childDeviceCode == "1548" || childDeviceCode == "1448") { Platform platform = _platFormRepository.QueryFirst(x => x.DeviceCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active"); if (platform != null) { if (command.HasPallet != 1) { MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod); if (method != null) { //var strings = platform.Location.Split(',').ToList(); int count = 1; method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform }); } } } } #region è°ç¨äºä»¶æ»çº¿éç¥å端 var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken"); if (tokenInfos == null || !tokenInfos.Any()) { //throw new Exception(conveyorLine.DeviceName + "ç¼å䏿ªæ¾å°Tokenç¼å"); continue; } var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList(); var userIds = tokenInfos?.Select(x => x.UserId).ToList(); object obj = new { childDeviceCode, commandAfter = command, }; _noticeService.LineData(userIds?.FirstOrDefault(), userTokenIds, new { conveyorLine.DeviceName, data = obj }); #endregion è°ç¨äºä»¶æ»çº¿éç¥å端 } #endregion è·¯ç±æ¹å¼ } } catch (Exception ex) { Console.Out.WriteLine(nameof(CommonConveyorLine_NewCW) + ":" + DateTime.Now + ":" + ex.ToString(),ex.StackTrace); } finally { } 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_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { try { var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode); var log = $"æ¶é´ï¼ã{DateTime.Now}ãã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ãä»»å¡å·ï¼ã{command.ConveyorLineTaskNum}ã设å¤ç¼ç ï¼ã{childDeviceCode}ã"; ConsoleHelper.WriteSuccessLine(log); //_noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); if (task == null) { HandleNewTask(conveyorLine, command, childDeviceCode); } else { if (childDeviceCode == "1039") { var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList(); if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2")) { ConsoleHelper.WriteErrorLine($"æ¶é´ï¼ã{DateTime.Now}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã髿¸©äºå·²åå¨ã{GWTask.Count}ã个任å¡å¤§äº2个任å¡ä¸å¯ä¸å"); return; } } ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateTaskStatusToNext(task); } } } catch (Exception ex) { Console.Out.WriteLine(ex.ToString()); } } /// <summary> /// è¾é线请æ±å ¥åºä¸ä¸å°å /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> public void RequestInNextAddress(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode); if (task != null) { if (command.ConveyorLineBarcode != task.PalletCode) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); return; } Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress); if (newTask != null) { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(newTask); //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateData(newTask); } } } //else //{ // //å½åå°åè¯·æ± å¯»æ¾å½åå°åçæçå· ä»»å¡å·çä»»å¡ï¼å¦åå¨ä»»å¡å鿰忬¡åå ¥æ°ç®æ å°å // Dt_Task currentTask = _taskService.QueryExecutingCurrentConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode); // if (currentTask != null) // { // conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(currentTask.TargetAddress), childDeviceCode); // } //} } /// <summary> /// è¾éçº¿å ¥åºå®æ /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> /// <param name="ProtocalDetailValue">线ä½å½åbool读ååç§»å°å</param> public void ConveyorLineInFinish(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { var task = _taskService.QueryExecutingTaskByBarcode(command.ConveyorLineBarcode, childDeviceCode); if (task != null && task.TaskState != (int)TaskInStatusEnum.Line_InFinish) { WebResponseContent content = _taskService.UpdateTaskStatusToNext(task); if (content.Status) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(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_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode); if (task != null) { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateTaskStatusToNext(task); if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray) { _taskService.UpdateTaskStatusToNext(task); } } } } /// <summary> /// è¾é线请æ±åºåºä¸ä¸å°å /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> public void RequestOutNextAddress(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode); if (task != null) { var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.MOMIP_BASE)?.ConfigValue; var ipAddress = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.TrayCellsStatus)?.ConfigValue; if (wmsBase == null || ipAddress == null) { throw new InvalidOperationException("MOM IP æªé ç½®"); } Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); TrayCellsStatusDto trayCells = new TrayCellsStatusDto() { Software = "WMS", TrayBarcode = command.ConveyorLineBarcode, EquipmentCode = stationManager.stationEquipMOM, SessionId = Guid.NewGuid().ToString(), EmployeeNo = "MITest", SceneType = "1", RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") }; var MOMIpAddress = wmsBase + ipAddress; var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.Serialize()).Result; WriteInfo("å ¥ç«æ ¡éª", $"ã{childDeviceCode}ãå ¥ç«æ ¡éªè¯·æ±åæ°ã{trayCells.Serialize()}ã"); WriteInfo("å ¥ç«æ ¡éª", ""); WriteInfo("å ¥ç«æ ¡éª", $"ã{childDeviceCode}ãå ¥ç«æ ¡éªè¿ååæ°ã{result}ã"); ResultTrayCellsStatus result1 = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result); if (result1.Success || task.Remark != "NG") { Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress); if (newTask != null) { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(newTask); //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateData(newTask); } } } else { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode); //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateTaskStatusToNext(task); } } } } /// <summary> /// è¾é线åºåºå®æ /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> public void ConveyorLineOutFinish(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { var log = $"æ¶é´ï¼ã{DateTime.Now}ãã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ãä»»å¡å·ï¼ã{command.ConveyorLineTaskNum}ã设å¤ç¼ç ï¼ã{childDeviceCode}ã"; ConsoleHelper.WriteSuccessLine(log); //_noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode); if (task != null) { WebResponseContent content = new WebResponseContent(); ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); taskCommand.InteractiveSignal = command.InteractiveSignal; Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); if (task.PalletCode != command.ConveyorLineBarcode) { taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode); } else { taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationLocation); } if (stationManager.stationPLC == "1018" && stationManager.stationArea == "Cache") //æ´æ°å¨éæ°æ® { dt_needBarcode needBarcode = _needBarcodeRepository.QueryFirst(x => x.productLine == stationManager.productLine && x.toArea == stationManager.stationChildCode); if (needBarcode != null) { needBarcode.inLineNum--; _needBarcodeRepository.UpdateData(needBarcode); } } //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); content = _taskService.UpdateTaskStatusToNext(task); } } else { var taskNext = _taskService.QueryExecutingConveyorLineTask(childDeviceCode, command.ConveyorLineBarcode); if (taskNext != null) { WebResponseContent content = new WebResponseContent(); ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(taskNext); taskCommand.InteractiveSignal = command.InteractiveSignal; Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); if (taskNext.PalletCode != command.ConveyorLineBarcode) { taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode); } else { taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationLocation); } if (stationManager.stationPLC == "1018" && stationManager.stationArea == "Cache") //æ´æ°å¨éæ°æ® { dt_needBarcode needBarcode = _needBarcodeRepository.QueryFirst(x => x.productLine == stationManager.productLine && x.toArea == stationManager.stationChildCode); if (needBarcode != null) { needBarcode.inLineNum--; _needBarcodeRepository.UpdateData(needBarcode); } } //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); taskNext.ExceptionMessage = log; content = _taskService.UpdateTaskStatusToNext(taskNext); } } } } /// <summary> /// çæµç©ºæçå®çåºåº /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> /// <param name="index">线ä½å½åbool读ååç§»å°å</param> public async void EmptyTrayReturn(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, int index, WIDESEAWCS_Model.Models.Platform platform) { try { TaskOutboundTypeEnum taskOutboundTypeEnum; if (platform.PlatformType.Contains("OutTray")) taskOutboundTypeEnum = TaskOutboundTypeEnum.OutTray; else taskOutboundTypeEnum = TaskOutboundTypeEnum.Outbound; await CheckAndCreateTask(taskOutboundTypeEnum, childDeviceCode, index, platform); } catch (Exception) { } } /// <summary> /// æ£æ¥ä»»å¡å¹¶å建æ°ä»»å¡ /// </summary> private async Task CheckAndCreateTask(TaskOutboundTypeEnum taskType, string childDeviceCode, int index, Platform platform) { var tasks = _taskRepository.QueryData(x => x.TaskType == (int)taskType && x.TargetAddress == childDeviceCode); if (tasks.Count < platform.Capacity) { #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; List<string> strings = platform.Location.Split(',').ToList(); WriteInfo("è°åº¦æ§è¡æ¶é´è®°å½", "ãè°åWMSåºåºæ¥å£å¼å§æ¶é´ï¼ã" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); var result = await HttpHelper.PostAsync(wmsIpAddress, new { Position = childDeviceCode, Tag = (int)taskType, AreaCdoe = platform.Stacker, AreaCdoes = strings, platform.ProductionLine }.Serialize()); WriteInfo("è°åº¦æ§è¡æ¶é´è®°å½", "ãè°åWMSåºåºæ¥å£ç»ææ¶é´ï¼ã" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result); // æ£æ¥ç¶æå¹¶è¿å if (!content.Status) return; taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); #endregion è°ç¨WMSè·ååºåºä»»å¡ 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; } public bool SendCommand(ConveyorLineTaskCommand_After taskCommand, CommonConveyorLine_NewCW conveyorLine, string childDeviceCode) { conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(taskCommand.ConveyorLineTargetAddress), childDeviceCode); Thread.Sleep(100); conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, taskCommand.ConveyorLineBarcode, childDeviceCode); Thread.Sleep(100); conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, taskCommand.ConveyorLineTaskNum, childDeviceCode); for (int i = 0; i < 6; i++) { ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode); if (command != null) { if (command.ConveyorLineBarcode == taskCommand.ConveyorLineBarcode && command.ConveyorLineTaskNum == taskCommand.ConveyorLineTaskNum && command.ConveyorLineTargetAddress == taskCommand.ConveyorLineTargetAddress) { WriteInfo(conveyorLine.DeviceName, $"æ¶é´ï¼ã{DateTime.Now}ãåå ¥ä»»å¡æååå ¥æ¬¡æ°{i}åå ¥ä»»å¡ã{JsonConvert.SerializeObject(taskCommand)}ã"); return true; } if (command.ConveyorLineTargetAddress != taskCommand.ConveyorLineTargetAddress) { conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(taskCommand.ConveyorLineTargetAddress), childDeviceCode); Thread.Sleep(100); } if (command.ConveyorLineBarcode != taskCommand.ConveyorLineBarcode) { conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, taskCommand.ConveyorLineBarcode, childDeviceCode); Thread.Sleep(100); } if (command.ConveyorLineTaskNum != taskCommand.ConveyorLineTaskNum) { conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, taskCommand.ConveyorLineTaskNum, childDeviceCode); Thread.Sleep(100); } } } WriteInfo(conveyorLine.DeviceName, $"æ¶é´ï¼ã{DateTime.Now}ãåå ¥ä»»å¡å¤±è´¥ä»»å¡å·ã{taskCommand.ConveyorLineTaskNum}ãæçå·ã{taskCommand.ConveyorLineBarcode}ãç®æ å°åã{taskCommand.ConveyorLineTargetAddress}ãå½åèç¹ã{childDeviceCode}ã"); return false; } } } #endregion Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_NewCW/NewCWTask/RequestInbound.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,407 @@ using Mapster; using Masuit.Tools; using Newtonsoft.Json; using System.Threading.Tasks; using WIDESEAWCS_Common; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Core; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_DTO.TaskInfo; using WIDESEAWCS_DTO.WMS; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_Tasks.ConveyorLineJob; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace WIDESEAWCS_Tasks { public partial class CommonConveyorLine_NewCWJob { /// <summary> /// å¤çåºåºä»»å¡ /// </summary> private void HandleTaskOut(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, int ProtocalDetailValue, Dt_Task taskOut) { if (taskOut == null) return; var taskCommand = MapTaskCommand(taskOut, command); bool isOutTray = taskOut.TaskType == (int)TaskOutboundTypeEnum.OutTray; bool isOutboundAndOutFinish = taskOut.TaskType == (int)TaskOutboundTypeEnum.Outbound && taskOut.TaskState == (int)TaskOutStatusEnum.SC_OutFinish; bool isOutboundAndLineOutExecuting = taskOut.TaskType == (int)TaskOutboundTypeEnum.Outbound && taskOut.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting; if (isOutTray || isOutboundAndOutFinish || !isOutboundAndLineOutExecuting) { conveyorLine.SendCommand(taskCommand, childDeviceCode); //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); _taskService.UpdateTaskStatusToNext(taskOut); } else if (taskOut.TaskType == (int)TaskOutboundTypeEnum.OutTray && taskOut.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting) { CompleteWmsTask(taskOut, command, conveyorLine, childDeviceCode, ProtocalDetailValue); } } /// <summary> /// å¤çæ°ä»»å¡ /// </summary> private void HandleNewTask(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); if (stationManager == null) { // Handle the case where stationManager is not found, if necessary Console.WriteLine($"æªæ¾å°{childDeviceCode}ç«å°"); return; } // æ ¹æ®ç«ç±»åæ§è¡ç¸åºçæ¹æ³ switch (stationManager.stationType) { case 8: case 9: case 11: case 12: var task = _taskService.QueryExecutingTaskByBarcode(command.ConveyorLineBarcode, childDeviceCode); if (task != null) { ExecuteStationAction(stationManager, conveyorLine, command, childDeviceCode); } break; case 1: case 6: case 10: ExecuteStationAction(stationManager, conveyorLine, command, childDeviceCode); break; //case 16: // ExecuteStationAction(stationManager, conveyorLine, command, childDeviceCode); // break; } #region //Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); //if (stationManager.stationType == 8) //{ // var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); // if (task != null) // { // RequestInNextAddress(conveyorLine, command, childDeviceCode); // } //} //else if (stationManager.stationType == 9) //{ // var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); // if (task != null) // { // ConveyorLineInFinish(conveyorLine, command, childDeviceCode); // } //} //else if (stationManager.stationType == 1) //{ // if (stationManager.stationArea.Contains("GW")) // { // var taskGW = _taskRepository.QueryFirst(x => x.TargetAddress == childDeviceCode && x.TaskState == (int)TaskOutStatusEnum.OutFinish); // if (taskGW != null) // { // command.ConveyorLineBarcode = taskGW.PalletCode; // } // } // RequestWmsTask(conveyorLine, command, childDeviceCode); //} //else if (stationManager.stationType == 10) //{ // var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode); // if (task != null) // { // RequestOutbound(conveyorLine, command, childDeviceCode); // } //} //else if (stationManager.stationType == 11) //{ // var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); // if (task != null) // { // RequestOutNextAddress(conveyorLine, command, childDeviceCode); // } //} //else if (stationManager.stationType == 12) //{ // var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); // if (task != null) // { // ConveyorLineOutFinish(conveyorLine, command, childDeviceCode); // } //} #endregion } private void ExecuteStationAction(Dt_StationManager stationManager, CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { switch (stationManager.stationType) { case 8: RequestInNextAddress(conveyorLine, command, childDeviceCode); break; case 9: ConveyorLineInFinish(conveyorLine, command, childDeviceCode); break; case 10: RequestOutbound(conveyorLine, command, childDeviceCode); break; case 11: RequestOutNextAddress(conveyorLine, command, childDeviceCode); break; case 12: ConveyorLineOutFinish(conveyorLine, command, childDeviceCode); break; case 6: CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode); break; case 16: AbNormalStationBZTask(conveyorLine, command, childDeviceCode); break; case 1: RequestWmsTask(conveyorLine, command, childDeviceCode, stationManager); break; } } /// <summary> /// æ å°ä»»å¡å½ä»¤ /// </summary> private ConveyorLineTaskCommand_After MapTaskCommand(Dt_Task task, ConveyorLineTaskCommand_After command) { var comm = _mapper.Map<ConveyorLineTaskCommand_After>(task); comm.InteractiveSignal = command.InteractiveSignal; return comm; } /// <summary> /// 宿WMSä»»å¡ /// </summary> private void CompleteWmsTask(Dt_Task taskOut, ConveyorLineTaskCommand_After command, CommonConveyorLine_NewCW conveyorLine, string childDeviceCode, int ProtocalDetailValue) { if (command.ConveyorLineBarcode == "NoRead") { var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == taskOut.TargetAddress).Capacity; taskOut.TargetAddress = NGAddress.ToString(); } var keys = new Dictionary<string, object>() { {"taskNum", taskOut.TaskNum} }; var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; var completeTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.CompleteTask)?.ConfigValue; if (wmsBase == null || completeTask == null) { throw new InvalidOperationException("WMS IP æªé ç½®"); } var wmsIpAddress = wmsBase + completeTask; var result = HttpHelper.GetAsync(wmsIpAddress, keys).Result; WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result); if (content.Status) { //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); _taskService.UpdateTaskStatusToNext(taskOut); } } /// <summary> /// å建并åé空æçä»»å¡ /// </summary> public void CreateAndSendEmptyTrayTask(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { if (command.ConveyorLineBarcode != "NoRead") { var taskDTO = CreateEmptyTrayTaskDto(command.ConveyorLineBarcode, childDeviceCode); if (_taskRepository.QueryFirst(x => x.PalletCode == command.ConveyorLineBarcode) != null) { List<string> strings = new List<string>() { "1743", "1739", "1837", "1841" }; var taskExecuting = _taskRepository.QueryFirst(x => x.PalletCode == command.ConveyorLineBarcode && x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting && strings.Contains(x.TargetAddress)); if (taskExecuting != null) { taskExecuting.ExceptionMessage = "æªæ¥æ¶å°çº¿ä½å®æä¿¡å·ç³»ç»å é¨èªå¨å®æ"; _taskService.Delete(taskExecuting); } ConsoleHelper.WriteErrorLine($"å½åæçåå¨ä»»å¡ï¼ã{command.ConveyorLineBarcode}ã"); WriteInfo(conveyorLine.DeviceName, $"å½åæçåå¨ä»»å¡{command.ConveyorLineBarcode}"); } var content = CreateAndSendTask(taskDTO); if (content.Status) { var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode, command.ConveyorLineBarcode); if (task != null) { var taskCommand = MapTaskCommand(task, command); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { _taskService.UpdateTaskStatusToNext(task); } } } } } /// <summary> /// å建空æçä»»å¡DTO /// </summary> private WMSTaskDTO CreateEmptyTrayTaskDto(string barcode, string childDeviceCode) { var request = new RequestTaskDto() { Position = childDeviceCode, PalletCode = barcode, }; var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; var requestTrayInTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTrayInTask)?.ConfigValue; if (wmsBase == null || requestTrayInTask == null) { throw new InvalidOperationException("WMS IP æªé ç½®"); } var wmsIpAddrss = wmsBase + requestTrayInTask; var result = HttpHelper.PostAsync(wmsIpAddrss, request.ToJsonString()).Result; if (result == null) return new WMSTaskDTO(); WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result); if (!content.Status) return new WMSTaskDTO(); return JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); } /// <summary> /// 请æ±WMSä»»å¡ /// </summary> private async void RequestWmsTask(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, Dt_StationManager stationManager) { try { if (command.ConveyorLineBarcode.IsNullOrEmpty()) return; var content = await _taskService.RequestWMSTask(command.ConveyorLineBarcode, childDeviceCode); if (content.Status) { var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode); if (task != null) { if (childDeviceCode == "1039") { var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList(); if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2")) { ConsoleHelper.WriteErrorLine($"æçå·ï¼ã{command.ConveyorLineBarcode}ã髿¸©äºå·²åå¨ã{GWTask.Count}ã个任å¡å¤§äº2个任å¡ä¸å¯ä¸å"); return; } } ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateTaskStatusToNext(task); } } } else { if (content.Message != "请æ±è¿äºé¢ç¹ï¼è¯·ç¨ååè¯" && content.Message != "æ æ³è·åç®æ å°å") { WriteInfo(conveyorLine.DeviceName, content.Message); conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, stationManager.stationNGChildCode, childDeviceCode); conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); ConsoleHelper.WriteErrorLine($"ã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã请æ±ç¹ä½ï¼ã{childDeviceCode}ãå¼å¸¸ä¿¡æ¯ã{content.Message}ã"); WriteInfo(conveyorLine.DeviceName, $"ã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã请æ±ç¹ä½ï¼ã{childDeviceCode}ãå¼å¸¸ä¿¡æ¯ã{content.Message}ã"); } ConsoleHelper.WriteErrorLine($"ã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã请æ±ç¹ä½ï¼ã{childDeviceCode}ãå¼å¸¸ä¿¡æ¯ã{content.Message}ã"); } } catch (Exception ex) { WriteInfo(conveyorLine.DeviceName, $"ã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã请æ±ç¹ä½ï¼ã{childDeviceCode}ãå¼å¸¸ä¿¡æ¯ã{ex.Message}ãå¼å¸¸è¡ã{ex.StackTrace}ã"); } } /// <summary> /// 髿¸©åºåºåä»»å¡å®æ 妿任塿 è¯NGåå°ä»»å¡æ¹ä¸ºå¼å¸¸æåºä»»å¡ /// </summary> /// <param name="conveyorLine"></param> /// <param name="command"></param> /// <param name="childDeviceCode"></param> /// <param name="task"></param> /// <exception cref="Exception"></exception> private void CreateAbNormalOutbound(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, Dt_Task task) { Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode); if (stationManager == null || string.IsNullOrWhiteSpace(stationManager.stationNGChildCode) || string.IsNullOrWhiteSpace(stationManager.stationNGLocation)) { throw new Exception("æªé ç½®ç«å°ç对åºNGå£ä¿¡æ¯"); } task.SourceAddress = task.TargetAddress; task.TargetAddress = stationManager.stationNGLocation; task.TaskState = (int)TaskOutStatusEnum.OutNew; task.TaskType = (int)TaskOutboundTypeEnum.InToOut; task.Grade = 10; //æ¤å¤ åºåºè³å¼å¸¸æåºå£çä»»å¡åºé¤ç«è¦å¤æä¼å æ§è¡ _taskRepository.UpdateData(task); //Dt_Task task= _taskRepository.QueryFirst(x=>) //_taskRepository.QueryFirst() } /// <summary> /// å è£ å¼å¸¸æåºå£é»è¾ /// </summary> /// <param name="conveyorLine"></param> /// <param name="command"></param> /// <param name="childDeviceCode"></param> private void AbNormalStationBZTask(CommonConveyorLine_NewCW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode); if (command.ConveyorLineBarcode.IsNullOrEmpty()) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); return; } if (conveyorLine.ReadValue(ConveyorLineDBName_After.InteractiveSignal, childDeviceCode).ObjToInt() == 0) //æçæ£åä¿¡å· { } ; conveyorLine.ReadValue(ConveyorLineDBName_After.InteractiveSignal, childDeviceCode); //æçææ çµè¯ä¿¡å· } } } Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob_NewCW/CommonStackerCrane_NewCWJob.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,604 @@ using Mapster; using Newtonsoft.Json; using Quartz; using System.Diagnostics.CodeAnalysis; using System.Text; using WIDESEAWCS_BasicInfoRepository; using WIDESEAWCS_Common; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Core.Caches; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_Core.HttpContextUser; using WIDESEAWCS_IProcessRepository; using WIDESEAWCS_ISystemServices; using WIDESEAWCS_ITaskInfo_HtyRepository; using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_QuartzJob.DeviceBase; using WIDESEAWCS_QuartzJob.Models; using WIDESEAWCS_QuartzJob.Service; using WIDESEAWCS_QuartzJob.StackerCrane.Enum; using WIDESEAWCS_SignalR; using WIDESEAWCS_Tasks.ConveyorLineJob; using WIDESEAWCS_Tasks.StackerCraneJob; namespace WIDESEAWCS_Tasks { [DisallowConcurrentExecution] public class CommonStackerCrane_NewCWJob : JobBase, IJob { private readonly ITaskService _taskService; private readonly ITaskExecuteDetailService _taskExecuteDetailService; private readonly ITaskRepository _taskRepository; private readonly IRouterService _routerService; private readonly IProcessRepository _processRepository; private readonly ICacheService _cacheService; private readonly INoticeService _noticeService; private readonly IDt_StationManagerRepository _stationManagerRepository; private readonly ITask_HtyRepository _htyRepository; private readonly ISys_ConfigService _sys_ConfigService; private static List<string>? userTokenIds; private static List<int>? userIds; public CommonStackerCrane_NewCWJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IProcessRepository processRepository, ICacheService cacheService, INoticeService noticeService, IDt_StationManagerRepository stationManagerRepository, ITask_HtyRepository htyRepository, ISys_ConfigService sys_ConfigService) { _taskService = taskService; _taskExecuteDetailService = taskExecuteDetailService; _taskRepository = taskRepository; _routerService = routerService; _processRepository = processRepository; _cacheService = cacheService; _noticeService = noticeService; _stationManagerRepository = stationManagerRepository; _htyRepository = htyRepository; _sys_ConfigService = sys_ConfigService; } public Task Execute(IJobExecutionContext context) { try { CommonStackerCrane_NewCW commonStackerCrane = (CommonStackerCrane_NewCW)context.JobDetail.JobDataMap.Get("JobParams"); if (commonStackerCrane != null) { if (!commonStackerCrane.IsEventSubscribed) { commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订é ä»»å¡å®æäºä»¶ } if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal) { commonStackerCrane.CheckStackerCraneTaskCompleted();//鲿¢ä»»å¡å®æäºä»¶çæµè¶ æ¶ï¼åæå¨è§¦å䏿¬¡ if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby) { Dt_Task? task = GetTask(commonStackerCrane); if (task != null) { StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task); if (stackerCraneTaskCommand != null) { var taskNum = commonStackerCrane.GetValue<StackerCraneDBName, int>(StackerCraneDBName.TaskNum); //var taskBarCode = commonStackerCrane.GetValue<StackerCraneDBName, string>(StackerCraneDBName.Barcode); ConsoleHelper.WriteColorLine($"ã{commonStackerCrane.DeviceName}ãå åæºä»»å¡å·ï¼ã{taskNum}ãä»»å¡ä»»å¡å·ï¼ã{task.TaskNum}ã", ConsoleColor.DarkBlue); if (taskNum == 0) { ConsoleHelper.WriteColorLine($"ã{commonStackerCrane.DeviceName}ãä»»å¡å·ä¸ºã{0}ã,ä»»å¡å·ä¸ä¸è´å¯ä»¥ä¸åä»»å¡", ConsoleColor.DarkBlue); Thread.Sleep(1000); bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand); if (sendFlag) { StringBuilder builder = new StringBuilder(); builder.AppendLine(); builder.AppendLine($"ã{commonStackerCrane.DeviceName}ãå åæºç¶æï¼ã{commonStackerCrane.StackerCraneStatusDes}ã,æ¶é´ï¼ã{DateTime.Now}ã"); builder.AppendLine($"ã{commonStackerCrane.DeviceName}ãæèªå¨ç¶æï¼ã{commonStackerCrane.StackerCraneAutoStatusDes}ã,æ¶é´ï¼ã{DateTime.Now}ã"); builder.AppendLine($"ã{commonStackerCrane.DeviceName}ãä½ä¸ç¶æï¼ã{commonStackerCrane.StackerCraneWorkStatusDes}ã,æ¶é´ï¼ã{DateTime.Now}ã"); builder.AppendLine($"ã{commonStackerCrane.DeviceName}ãä¸å任塿å,ã{JsonConvert.SerializeObject(stackerCraneTaskCommand, Formatting.Indented)}ã"); builder.AppendLine($"æ¶é´ï¼ã{DateTime.Now}ã"); builder.AppendLine(); ConsoleHelper.WriteColorLine(builder, ConsoleColor.Blue); commonStackerCrane.LastTaskType = task.TaskType; _taskService.UpdateTaskStatusToNext(task.TaskNum); } } else { ConsoleHelper.WriteColorLine($"ã{commonStackerCrane.DeviceName}ãä»»å¡å·ä¸ä¸ºã{0}ã,ä¸å¯ä»¥ä¸åä»»å¡", ConsoleColor.DarkBlue); } } } } } #region è°ç¨äºä»¶æ»çº¿éç¥å端 var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken"); if (tokenInfos != null && tokenInfos.Any()) { var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList(); var userIds = tokenInfos?.Select(x => x.UserId).ToList(); object obj = new { commonStackerCrane.StackerCraneStatusDes, commonStackerCrane.StackerCraneAutoStatusDes, commonStackerCrane.StackerCraneWorkStatusDes, commonStackerCrane.DeviceCode, commonStackerCrane.DeviceName, commonStackerCrane.CurrentTaskNum, commonStackerCrane.LastTaskNum, }; _noticeService.StackerData(userIds?.FirstOrDefault(), userTokenIds, new { commonStackerCrane.DeviceName, data = obj }); } #endregion è°ç¨äºä»¶æ»çº¿éç¥å端 } } catch (Exception ex) { WriteError("CommonConveyorLineJob", "test", ex); ConsoleHelper.WriteErrorLine($"{ex.Message}"); //Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString()); } //WriteDebug("CommonConveyorLineJob", "test"); return Task.CompletedTask; } /// <summary> /// ä»»å¡å®æäºä»¶è®¢é çæ¹æ³ /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e) { CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane; if (commonStackerCrane != null) { if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5) { ConsoleHelper.WriteColorLine($"ã{commonStackerCrane.DeviceName}ãå åæºä½ä¸ç¶æï¼ã{(int)commonStackerCrane.StackerCraneWorkStatusValue}ãæ¶é´ã{DateTime.Now}ã", ConsoleColor.Magenta); string str = $"ã{commonStackerCrane.DeviceName}ãä»»å¡å®æ,ä»»å¡å·ï¼ã{e.TaskNum}ãæ¶é´ã{DateTime.Now}ã"; WriteInfo(commonStackerCrane.DeviceName, str); ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue); var task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum); if (task == null) commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5); if (commonStackerCrane.DeviceCode.Contains("CW") && task.TaskType==(int)TaskOutboundTypeEnum.InToOut) { var stationinfo = _stationManagerRepository.QueryFirst(x => x.stationPLC == "1017" && x.stationType == 10 && x.Roadway == commonStackerCrane.DeviceCode); IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationinfo.stationPLC); if (device != null) { CommonConveyorLine_NewCW conveyorLine = (CommonConveyorLine_NewCW)device; conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(1815), stationinfo.stationChildCode); Thread.Sleep(100); conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, 1000, stationinfo.stationChildCode); } WriteInfo(commonStackerCrane.DeviceName, $"ãæå¨åºåºè®°å½ãä»»å¡å·ã{e.TaskNum}ãæçå·ã{task.PalletCode}ã"); } if (commonStackerCrane.DeviceCode.Contains("GW") && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) { var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.TargetAddress); IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == station.stationPLC); if (device != null) { CommonConveyorLine_GW conveyorLine = (CommonConveyorLine_GW)device; var isResult = conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, task.PalletCode, task.TargetAddress); if (!isResult) { var result = conveyorLine.GetValue<ConveyorLineDBName_After, string>(ConveyorLineDBName_After.ConveyorLineBarcode, task.TargetAddress); if (result != task.PalletCode) { conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, task.PalletCode, task.TargetAddress); } } } else return; } var content = _taskService.StackCraneTaskCompleted(e.TaskNum); if (commonStackerCrane.DeviceCode.Contains("CH") && task.TaskType == (int)TaskOutboundTypeEnum.Outbound) { task = _taskRepository.QueryFirst(x => x.TaskNum == e.TaskNum); Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress); _taskService.UpdateData(newTask); } if ((task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && (task.TargetAddress == "002-021-001" || task.TargetAddress == "001-021-001"))|| task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm) { var TASKHTY = task.Adapt<Dt_Task_Hty>(); _taskRepository.DeleteData(task); _htyRepository.AddData(TASKHTY); } var isWorkType = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5); str = $"{commonStackerCrane.DeviceName}ãWMS|WCSä»»å¡å®æï¼ã{content.Status}ã,å åæºå®æä¿¡å·åå ¥ï¼ã{isWorkType}ã,ä»»å¡å·ï¼ã{e.TaskNum}ãæ¶é´ã{DateTime.Now}ã"; WriteInfo(commonStackerCrane.DeviceName, str); ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue); } } } /// <summary> /// è·åä»»å¡ /// </summary> /// <param name="commonStackerCrane">å åæºå¯¹è±¡</param> /// <returns></returns> private Dt_Task? GetTask(CommonStackerCrane_NewCW commonStackerCrane) { Dt_Task task; task = _taskService.QueryOutFireAlarmTask(commonStackerCrane.DeviceCode); if (task != null) { return task; } if (commonStackerCrane.LastTaskType == null) { task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode); } else { var lastTaskTypeGroup = commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup(); if (lastTaskTypeGroup == TaskTypeGroup.OutbondGroup) { task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode); if (task == null) { task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode); } } else { task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode); } } if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) { // æ£æ¥å½ååºåºä»»å¡ç«å°æ¯å¦å 许æ¾è´§ var occupiedStation = OutTaskStationIsOccupied(task); if (occupiedStation == null) { // 妿å½ååºåºä»»å¡ç«å°ä¸å 许æ¾è´§ï¼æé¤å½åä»»å¡ï¼æ¥æ¾å ¶ä»åºåºä»»å¡ var log = $"ä»»å¡å·ï¼ã{task.TaskNum}ãåºåºå°åï¼ã{task.NextAddress}ãä¸å 许æ¾è´§"; ConsoleHelper.WriteErrorLine(log); _noticeService.Logs(userTokenIds, new { commonStackerCrane.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(commonStackerCrane.DeviceName, log); task = FindAnotherOutboundTask(commonStackerCrane.DeviceCode, task.TaskId); if (task == null) { task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode); } } else { return task; } } else if (task == null) { task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode); } return task; } /// <summary> /// åºåºä»»å¡å¤æåºåºç«å°æ¯å¦è¢«å ç¨ /// </summary> /// <param name="task">ä»»å¡å®ä½</param> /// <returns>妿æªè¢«å ç¨ï¼è¿åä¼ å ¥çä»»å¡ä¿¡æ¯ï¼å¦åï¼è¿ånull</returns> private Dt_Task? OutTaskStationIsOccupied([NotNull] Dt_Task task) { Dt_Router? router = _routerService.QueryNextRoutes(task.Roadway, task.NextAddress).FirstOrDefault(); if (task.Roadway.Contains("GW") || task.Roadway.Contains("CW")) { if (router != null) { IDevice? device = null; if (task.Roadway.Contains("CW")) { device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == router.ChildPosiDeviceCode); if (device != null) { CommonConveyorLine_NewCW conveyorLine = (CommonConveyorLine_NewCW)device; if (conveyorLine.IsOccupied(task.NextAddress))//åºåºç«å°æªè¢«å ç¨ { return task; } } else { _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"æªæ¾å°åºåºç«å°ã{task.NextAddress}ã对åºçéè®¯å¯¹è±¡ï¼æ æ³å¤æåºåºç«å°æ¯å¦è¢«å ç¨"); } } } else { IDevice? device = null; if (task.Roadway.Contains("GW")) { device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1015"); if (device != null) { CommonConveyorLine_GW conveyorLine = (CommonConveyorLine_GW)device; if (conveyorLine.IsOccupied(task.TargetAddress))//åºåºç«å°æªè¢«å ç¨ { return task; } } else { _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"æªæ¾å°åºåºç«å°ã{task.TargetAddress}ã对åºçéè®¯å¯¹è±¡ï¼æ æ³å¤æåºåºç«å°æ¯å¦è¢«å ç¨"); } } //_taskService.UpdateTaskExceptionMessage(task.TaskNum, $"æªæ¾å°ç«å°ã{task.TargetAddress}ãä¿¡æ¯ï¼æ æ³æ ¡éªç«å°"); } } else { if ((task.NextAddress == ("002-021-001") || task.NextAddress == ("001-021-001")) && task.Roadway.Contains("JZ")) { return task; } else { //Dt_Router? router = _routerService.QueryNextRoutes(task.Roadway, task.NextAddress).FirstOrDefault(); if (router != null) { IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == router.ChildPosiDeviceCode); if (device != null) { CommonConveyorLine conveyorLine = (CommonConveyorLine)device; if (conveyorLine.IsOccupiedx(router.ChildPosi))//åºåºç«å°æªè¢«å ç¨ { return task; } } else { _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"æªæ¾å°åºåºç«å°ã{router.ChildPosiDeviceCode}ã对åºçéè®¯å¯¹è±¡ï¼æ æ³å¤æåºåºç«å°æ¯å¦è¢«å ç¨"); } } else { _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"æªæ¾å°ç«å°ã{task.NextAddress}ãä¿¡æ¯ï¼æ æ³æ ¡éªç«å°"); } } } return null; } /// <summary> /// æ¥æ¾å ¶ä»åºåºä»»å¡çè¾ å©æ¹æ³ï¼æé¤æå®ä»»å¡IDçä»»å¡ï¼ /// </summary> /// <param name="deviceCode">设å¤ä»£ç </param> /// <param name="excludedTaskId">è¦æé¤çä»»å¡ID</param> /// <returns></returns> private Dt_Task? FindAnotherOutboundTask(string deviceCode, int excludedTaskId) { // å è·åææç¬¦åæ¡ä»¶ï¼æé¤æå®ä»»å¡IDï¼çåºåºä»»å¡å表 var allOutboundTasks = _taskService.QueryAllOutboundTasks(deviceCode); var availableTasks = allOutboundTasks?.Where(t => excludedTaskId != t.TaskId && t.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup).ToList(); if (availableTasks == null || availableTasks.Count == 0) { return null; } // éåå¯ç¨ä»»å¡åè¡¨ï¼æ£æ¥ä»»å¡ç«å°æ¯å¦å 许æ¾è´§ï¼æ¾å°ç¬¬ä¸ä¸ªå 许æ¾è´§çä»»å¡å°±è¿å foreach (var candidateTask in availableTasks) { var occupiedStation = OutTaskStationIsOccupied(candidateTask); if (occupiedStation != null) { return candidateTask; } var log = $"ä»»å¡å·ï¼ã{candidateTask.TaskNum}ãåºåºå°åï¼ã{candidateTask.NextAddress}ãä¸å 许æ¾è´§"; ConsoleHelper.WriteErrorLine(log); _noticeService.Logs(userTokenIds, new { deviceCode, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(deviceCode, log); } return null; } /// <summary> /// ä»»å¡å®ä½è½¬æ¢æå½ä»¤Model /// </summary> /// <param name="task">ä»»å¡å®ä½</param> /// <returns></returns> /// <exception cref="Exception"></exception> public StackerCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task) { StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand(); stackerCraneTaskCommand.Barcode = task.PalletCode; stackerCraneTaskCommand.TaskNum = task.TaskNum; stackerCraneTaskCommand.WorkType = 1; stackerCraneTaskCommand.TrayType = 0; stackerCraneTaskCommand.StartCommand = 1; stackerCraneTaskCommand.FireCommand = Convert.ToInt16(task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm ? 2 : 0); if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//夿æ¯å¦æ¯å ¥åºä»»å¡ { var value = _sys_ConfigService.GetByConfigKey(CateGoryConst.CONFIG_SYS_InStation, SysConfigKeyConst.JZNGInBoundStation).ConfigValue; var valueList = value.Split(',').ToList(); if ((valueList.Contains(task.SourceAddress)) && task.Roadway.Contains("JZ")) { string[] souredCodes = task.CurrentAddress.Split("-"); if (souredCodes.Length == 3) { stackerCraneTaskCommand.StartRow = Convert.ToInt16(souredCodes[0]); stackerCraneTaskCommand.StartColumn = Convert.ToInt16(souredCodes[1]); stackerCraneTaskCommand.StartLayer = Convert.ToInt16(souredCodes[2]); } else { //æ°æ®é ç½®é误 _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"å ¥åºä»»å¡èµ·ç¹é误ï¼èµ·ç¹ï¼ã{task.CurrentAddress}ã"); return null; } string[] targetCodes = task.NextAddress.Split("-"); if (targetCodes.Length == 3) { stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]) % 2 != 0 ? (short)1 : (short)2; stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); } else { //æ°æ®é ç½®é误 _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"å ¥åºä»»å¡ç»ç¹é误ï¼èµ·ç¹ï¼ã{task.NextAddress}ã"); return null; } } else { List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.Roadway); if (routers.Count > 0) { stackerCraneTaskCommand.StartRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow); stackerCraneTaskCommand.StartColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn); stackerCraneTaskCommand.StartLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer); string[] targetCodes = task.NextAddress.Split("-"); if (targetCodes.Length == 3) { stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]) % 2 != 0 ? (short)1 : (short)2; stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); } else { //æ°æ®é ç½®é误 _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"å ¥åºä»»å¡ç»ç¹é误ï¼èµ·ç¹ï¼ã{task.NextAddress}ã"); return null; } } else { _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"æªæ¾å°ç«å°ã{task.NextAddress}ãä¿¡æ¯ï¼æ æ³è·å对åºçå åæºåè´§ç«å°ä¿¡æ¯"); return null; } } } else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) { if (task.Roadway.Contains("GW")|| task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm) { string[] endCodes = task.NextAddress.Split("-"); stackerCraneTaskCommand.EndRow = Convert.ToInt16(endCodes[0]); stackerCraneTaskCommand.EndColumn = Convert.ToInt16(endCodes[1]); stackerCraneTaskCommand.EndLayer = Convert.ToInt16(endCodes[2]); string[] sourceCodes = task.SourceAddress.Split("-"); stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2; stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]); stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]); } else { if ( task.TaskType == (int)TaskOutboundTypeEnum.InToOut) { string[] endCodes = task.TargetAddress.Split("-"); stackerCraneTaskCommand.EndRow = Convert.ToInt16(endCodes[0]); stackerCraneTaskCommand.EndColumn = Convert.ToInt16(endCodes[1]); stackerCraneTaskCommand.EndLayer = Convert.ToInt16(endCodes[2]); string[] sourceCodes = task.SourceAddress.Split("-"); stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2; stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]); stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]); } else if (((task.TargetAddress == "002-021-001" || task.TargetAddress == "001-021-001") && task.Roadway.Contains("JZ")) || task.TaskType == (int)TaskOutboundTypeEnum.OutFireAlarm) { string[] endCodes = task.NextAddress.Split("-"); stackerCraneTaskCommand.EndRow = Convert.ToInt16(endCodes[0]); stackerCraneTaskCommand.EndColumn = Convert.ToInt16(endCodes[1]); stackerCraneTaskCommand.EndLayer = Convert.ToInt16(endCodes[2]); string[] sourceCodes = task.SourceAddress.Split("-"); stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2; stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]); stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]); } else { List<Dt_Router> routers = _routerService.QueryNextRoutes(task.Roadway, task.TargetAddress); if (routers.Count > 0) { stackerCraneTaskCommand.EndRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow); stackerCraneTaskCommand.EndColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn); stackerCraneTaskCommand.EndLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer); string[] sourceCodes = task.CurrentAddress.Split("-"); if (sourceCodes.Length == 3) { stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2; stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]); stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]); } else { //æ°æ®é ç½®é误 _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"åºåºä»»å¡èµ·ç¹é误ï¼èµ·ç¹ï¼ã{task.CurrentAddress}ã"); return null; } } else { _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"æªæ¾å°ç«å°ã{task.NextAddress}ãä¿¡æ¯ï¼æ æ³è·å对åºçå åæºæ¾è´§ç«å°ä¿¡æ¯"); return null; } } } } else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) { string[] targetCodes = task.NextAddress.Split("-"); if (targetCodes.Length == 3) { stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]) % 2 != 0 ? (short)1 : (short)2; stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]); stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]); } else { //æ°æ®é ç½®é误 _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"ç§»åºä»»å¡ç»ç¹é误ï¼èµ·ç¹ï¼ã{task.NextAddress}ã"); return null; } string[] sourceCodes = task.CurrentAddress.Split("-"); if (sourceCodes.Length == 3) { stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]) % 2 != 0 ? (short)1 : (short)2; stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]); stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]); } else { //æ°æ®é ç½®é误 _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"ç§»åºä»»å¡èµ·ç¹é误ï¼èµ·ç¹ï¼ã{task.CurrentAddress}ã"); return null; } } return stackerCraneTaskCommand; } } } Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Core/Const/ConfigConst.cs
@@ -113,6 +113,11 @@ public const string AgingOutput = "AgingOutput"; /// <summary> /// æ¢å /// </summary> public const string EqptRun = "EqptRun"; /// <summary> /// å·¥èºè·¯çº¿ç³è¯· /// </summary> public const string ProcessApply = "ProcessApply"; Code Management/WMS/WIDESEA_WMSServer/WIDESEA_DTO/MOM/ResponeAgingInputDto.cs
@@ -91,4 +91,30 @@ /// </summary> public string ParameterCode { get; set; } } public class EqptRunDTO: BasicResult { public string WipOrderNo { get; set; } public string ProductDesc { get; set; } public string FirstArticleNum { get; set; } public string DebugNum { get; set; } public string ParamVersion { get; set; } public string ParamRefreshFlag { get; set; } public string ProductType { get; set; } public bool ProductModel { get; set; } public string ParameterInfo { get; set; } public string IsProcessed { get; set; } public string PreProductNo { get; set; } } } Code Management/WMS/WIDESEA_WMSServer/WIDESEA_IStoragIntegrationServices/MOM/AgingInOrOutInput/IAgingInOrOutInputService.cs
@@ -18,4 +18,11 @@ /// <param name="input">åºåºæ°æ®</param> /// <returns></returns> Task<WebResponseContent> GetOCVOutputAsync(AgingOutputDto input); /// <summary> /// ä¿®æ¹è®¾å¤åå· /// </summary> /// <param name="input"></param> /// <returns></returns> Task<WebResponseContent> Change(EqptRunDto input); } Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/AgingInOrOutInput/AgingInOrOutInputService.cs
@@ -122,4 +122,41 @@ } return content; } public async Task<WebResponseContent> Change(EqptRunDto input) { WebResponseContent content = new WebResponseContent(); try { input.SessionId = Guid.NewGuid().ToString(); input.EmployeeNo = "MITest"; input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input); // Specify the namespace explicitly var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); var MOMBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.EqptRun)?.ConfigValue; if (MOMBase == null || ipAddress == null) { throw new InvalidOperationException("WMS IP æªé ç½®"); } var MOMIpAddress = MOMBase + ipAddress; var result = HttpsClient.PostAsync(MOMIpAddress, inputJson).Result; //var respone = JsonConvert.DeserializeObject<EqptRunDTO>(result.ToString()); content.OK(data: result); LogFactory.GetLog("æ¢å").Info(true, $"\r\r--------------------------------------"); LogFactory.GetLog("æ¢å").Info(true, input.EquipmentCode); LogFactory.GetLog("æ¢å").Info(true, result); } catch (Exception err) { LogFactory.GetLog("æ¢å").Error(true, $"\r\r--------------------------------------"); LogFactory.GetLog("æ¢å").Error(true, err.StackTrace); content.Error(err.Message); } return content; } } Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Dt_TaskService.cs
@@ -769,6 +769,7 @@ // return await HandleErrorCells(input, area, serialNosError); //} #endregion var boxing = CreateBoxingInfo(result, input.PalletCode); if (boxing == null) return content.Error("ç»ç失败"); @@ -932,7 +933,9 @@ } else { _boxingInfoRepository.DeleteData(boxing); _boxingInfoRepository.Db.DeleteNav<DtBoxingInfo>(x => x.Id == boxing.Id) .Include(x => x.BoxingInfoDetails) .ExecuteCommandAsync(); return new DtBoxingInfo { PalletCode = palletCode, Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/Dt_TaskService.cs
@@ -4,6 +4,7 @@ using SqlSugar; using WIDESEA_Common.CustomModels; using WIDESEA_Core.Const; using WIDESEA_DTO; using WIDESEA_DTO.MOM; using WIDESEA_DTO.WMS; using WIDESEA_Model.Models; @@ -1078,24 +1079,39 @@ WebResponseContent content = new WebResponseContent(); try { LogFactory.GetLog($"å è£ è¯·æ±åºåºä»»å¡").Info(true, $"ã请æ±åæ°ãï¼ã{JsonConvert.SerializeObject(json)}ã{Environment.NewLine}{Environment.NewLine}"); Dt_StationManager station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == json.Position && x.stationType == 12 && x.stationArea == "Call"); if (station == null) { throw new Exception($"æªæ¾å°å è£ ç«å°ä¿¡æ¯ï¼è¯·æ£æ¥ä¼ å ¥åæ°{json.Position}"); } EqptRunDto basic = new EqptRunDto() { EquipmentModel = "0", Password ="", EmployeeNo = "82412152", SessionId = Guid.NewGuid().ToString(), RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), Software = "å è£ ä¸æ", EquipmentCode = station.stationEquipMOM, }; var result = _agingInOrOutInputService.Change(basic).Result; var respone = JsonConvert.DeserializeObject<EqptRunDTO>(result.Data.ToString()); if(!result.Status || !respone.Success) { throw new Exception($"{station.productLine}è·åMOMæ¢åæ°æ®å¼å¸¸,å¼å¸¸ä¿¡æ¯{respone.MOMMessage}"); } var deviceCode = SqlSugarHelper.DbWCS.Queryable<Dt_DeviceInfo>() .Where(x => x.DeviceStatus == "1") .Where(x => x.DeviceCode.Contains("CWSC")) // è¿æ»¤æ¡ä»¶ .ToList().Select(x => x.DeviceCode).ToList(); //var outBoundMateriel = AppSettings.app<OutBoundMateriel>("OutBoundMateriel"); var outBoundMateriel = _dt_ChangeoversRepository.QueryData(x => x.Status == "1").ToList(); List<string>? materielCodes = outBoundMateriel.Count != 0 ? outBoundMateriel.Where(x => x.ProductionLine == station.productLine && x.ProcessCode == "CWSC3") .Select(x => x.MaterielCode) .ToList() : null; //var outBoundMateriel = _dt_ChangeoversRepository.QueryData(x => x.Status == "1").ToList(); //List<string>? materielCodes = outBoundMateriel.Count != 0 // ? outBoundMateriel.Where(x => x.ProductionLine == station.productLine && x.ProcessCode == "CWSC3") // .Select(x => x.MaterielCode) // .ToList() // : null; #region #region Redisç¼åæ¥è¯¢ä»£ç //// ä»ç¼åä¸è·ååºåä¿¡æ¯ //IDictionary<string, DtStockInfo>? stockInfos = _simpleCacheService.HashGetAll<DtStockInfo>(WIDESEA_Cache.CacheConst.Cache_DtStockInfo); //List<DtStockInfo> stockInfoList = stockInfos.Values.ToList(); @@ -1115,7 +1131,7 @@ // .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails != null && x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode))) // .FirstOrDefault(); // ä¿®æ¹åçæ¥è¯¢ä»£ç #endregion //var stockInfo = await _stockInfoRepository.Db.Queryable<DtStockInfo>() // .Includes(x => x.LocationInfo) // .Includes(x => x.StockInfoDetails) @@ -1128,6 +1144,7 @@ // .WhereIF(!materielCodes.IsNullOrEmpty(), x => x.StockInfoDetails.Any(y => materielCodes.Contains(y.MaterielCode))) // .OrderBy(x => x.OutboundTime) // .FirstAsync(); #endregion DtStockInfo stockInfo = null; var stockInfoList = await _stockInfoRepository.Db.Queryable<DtStockInfo>() @@ -1143,7 +1160,7 @@ foreach (var stock in stockInfoList) { var hasMatchingDetail = await _stockInfoRepository.Db.Queryable<DtStockInfoDetail>() .Where(d => d.StockId == stock.Id && materielCodes.Contains(d.MaterielCode)) .Where(d => d.StockId == stock.Id && respone.PreProductNo.Contains(d.MaterielCode)) .AnyAsync(); if (hasMatchingDetail) @@ -1152,7 +1169,7 @@ break; } } if (stockInfo == null) throw new Exception($"åºå {station.productLine}æ æ»¡è¶³æ¡ä»¶çåºåå¯åºåº"); if (stockInfo == null) throw new Exception($"CWSC3åºå ã{station.productLine}ã,ãç©æç¼ç {respone.PreProductNo}ãæ æ»¡è¶³æ¡ä»¶çåºåå¯åºåº"); DtLocationInfo locationInfo = _locationRepository.QueryFirst(x => x.AreaId == 5 && x.LocationCode == stockInfo.LocationCode); @@ -1189,7 +1206,6 @@ _locationStatusChangeRecordRepository.AddLocationStatusChangeRecord(stockInfo.LocationInfo, lastStatus, (int)StatusChangeTypeEnum.AutomaticDelivery, task.TaskNum); LogFactory.GetLog($"å è£ è¯·æ±åºåºä»»å¡").Info(true, $"ãè¿ååæ°ãï¼ã{JsonConvert.SerializeObject(taskDTO)}ã{Environment.NewLine}{Environment.NewLine}"); return content.OK(data: taskDTO); } catch (Exception ex) Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StorageTaskServices/Task/Partial/RequestInTaskAsync.cs
@@ -45,26 +45,16 @@ try { // 夿éä¸éè¦å»å è£ ï¼ä¸éè¦å°±å»å¸¸æ¸©ä¸ var stationManagers = _stationManagerRepository.QueryData(x => x.stationPLC == "1018" && x.stationArea == "Cache" && x.productLine == input.ProductionLine); //var stationManagers = _stationManagerRepository.QueryData(x => x.stationPLC == "1018" && x.stationArea == "Cache" && x.productLine == input.ProductionLine); var STATION = _stationManagerRepository.QueryFirst(x => x.stationChildCode == input.Position); //var STATION = _stationManagerRepository.QueryFirst(x => x.stationChildCode == input.Position); //var station = stationManagers.Select(x => x.stationChildCode).ToList(); //// è·åWCSipå°åç¸å ³é ç½® // è·åWCSipå°åç¸å ³é ç½® var wcsIpAddrss = GetWCSIpAddress(); //if (wcsIpAddrss == null) //{ // throw new InvalidOperationException("WCS IP æªé ç½®"); //} //var abc = HttpHelper.PostAsync(wcsIpAddrss, station.ToJsonString()).Result; //content = JsonConvert.DeserializeObject<WebResponseContent>(abc); //var num = content.Data.ObjToInt(); //妿å½ååºå å卿¯å½åæ¶é´ç对åºäº§çº¿çæ åå ¥åºè³å¸¸æ¸©3 DtStockInfo stockInfo = _stockInfoRepository.QueryFirst(x => x.AreaCode == "CWSC3" && x.IsFull == true && x.ProductionLine == STATION.productLine && x.OutboundTime < DateTime.Now); if (stockInfo != null) //DtStockInfo stockInfo = _stockInfoRepository.QueryFirst(x => x.AreaCode == "CWSC3" && x.IsFull == true && x.ProductionLine == STATION.productLine && x.OutboundTime < DateTime.Now); //if (stockInfo != null) { var config = _configService.GetByConfigKey("SYS_InStacker", "CW3InStacker"); var strings = config.ConfigValue.Split(',').ToList(); @@ -79,32 +69,34 @@ // TODO 夿å¨éæ°é var needBarcode = await SqlSugarHelper.DbWCS.Queryable<dt_needBarcode>().FirstAsync(x => x.productLine == STATION.productLine && x.fromArea == "CW"); var needCount = BaseDal.QueryData(x => x.TargetAddress == needBarcode.toArea).Count(); //var count = BaseDal.QueryData(x => x.TargetAddress == stationManagers[0].Roadway).Count; if (needCount < needBarcode.cacheNum) { // éè³å è£ List<string> strings = stationManagers.Where(x => x.stationType == 0 && x.productLine == input.ProductionLine).Select(x => x.Roadway).ToList(); var x = await SqlSugarHelper.DbWCS.Updateable<dt_needBarcode>() .SetColumns(x => x.inLineNum == x.inLineNum + 1) .Where(x => x.id == needBarcode.id).ExecuteCommandHasChangeAsync(); ConsoleHelper.WriteSuccessLine($"å¨éæ°éæ·»å {(x ? "æå" : "失败")}æ°é+1,å½åå·¥åº{boxing.ProcessCode},产线{input.ProductionLine}"); LogFactory.GetLog("OCVB").InfoFormat(true, $"å¨éæ°éæ·»å {(x ? "æå" : "失败")}æ°é+1,å½åå·¥åº{boxing.ProcessCode},产线{input.ProductionLine}", "æ åæ°"); return await CreateNewTask(input, input.ProductionLine, boxing.ProcessCode, strings, 3); } else { var config = _configService.GetByConfigKey("SYS_InStacker", "CW3InStacker"); var strings = config.ConfigValue.Split(',').ToList(); // å ¥åºéè³å¸¸æ¸©3 var resultContent = await CreateNewTask(input, input.ProductionLine, boxing.ProcessCode, strings); if (resultContent.Status) { await _boxingInfoRepository.AddDataNavAsync(boxing); } return resultContent; } #region OCV常温3ç´æ¥å»å è£ è·¯å¾ä¸éæ¤é»è¾ä¸éè¦ //var needBarcode = await SqlSugarHelper.DbWCS.Queryable<dt_needBarcode>().FirstAsync(x => x.productLine == STATION.productLine && x.fromArea == "CW"); //var needCount = BaseDal.QueryData(x => x.TargetAddress == needBarcode.toArea).Count(); //if (needCount < needBarcode.cacheNum) //{ // // éè³å è£ // List<string> strings = stationManagers.Where(x => x.stationType == 0 && x.productLine == input.ProductionLine).Select(x => x.Roadway).ToList(); // var x = await SqlSugarHelper.DbWCS.Updateable<dt_needBarcode>() // .SetColumns(x => x.inLineNum == x.inLineNum + 1) // .Where(x => x.id == needBarcode.id).ExecuteCommandHasChangeAsync(); // ConsoleHelper.WriteSuccessLine($"å¨éæ°éæ·»å {(x ? "æå" : "失败")}æ°é+1,å½åå·¥åº{boxing.ProcessCode},产线{input.ProductionLine}"); // LogFactory.GetLog("OCVB").InfoFormat(true, $"å¨éæ°éæ·»å {(x ? "æå" : "失败")}æ°é+1,å½åå·¥åº{boxing.ProcessCode},产线{input.ProductionLine}", "æ åæ°"); // return await CreateNewTask(input, input.ProductionLine, boxing.ProcessCode, strings, 3); //} //else //{ // var config = _configService.GetByConfigKey("SYS_InStacker", "CW3InStacker"); // var strings = config.ConfigValue.Split(',').ToList(); // // å ¥åºéè³å¸¸æ¸©3 // var resultContent = await CreateNewTask(input, input.ProductionLine, boxing.ProcessCode, strings); // if (resultContent.Status) // { // await _boxingInfoRepository.AddDataNavAsync(boxing); // } // return resultContent; //} #endregion } catch (Exception ex) {