From 02a4fdd78cef9c7d2a26bfb9aa187179cf0baac3 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期三, 25 二月 2026 17:44:26 +0800
Subject: [PATCH] 1
---
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_CW/CommonConveyorLine_CWJob.cs | 212 +++++++++++++++++++++++++++--------------------------
1 files changed, 108 insertions(+), 104 deletions(-)
diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_CW/CommonConveyorLine_CWJob.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_CW/CommonConveyorLine_CWJob.cs
index dca1ac8..0e755ba 100644
--- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_CW/CommonConveyorLine_CWJob.cs
+++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_CW/CommonConveyorLine_CWJob.cs
@@ -28,12 +28,16 @@
using SqlSugar;
using System.ComponentModel.Design;
using System.Reflection;
+using System.Reflection.Metadata;
+using System.Threading;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Core.HttpContextUser;
+using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_DTO.MOM;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IProcessRepository;
@@ -47,6 +51,7 @@
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.ConveyorLineJob;
+using static Quartz.Logging.OperationName;
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
using Platform = WIDESEAWCS_Model.Models.Platform;
@@ -69,7 +74,7 @@
private readonly IDeviceInfoRepository _deviceInfoRepository;
private static List<string>? userTokenIds;
private static List<int>? userIds;
- private static List<string> childCodeList = new List<string>();
+ private static DateTime? lastUpdateTime;
public CommonConveyorLine_CWJob(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)
{
@@ -94,99 +99,109 @@
CommonConveyorLine_CW conveyorLine = (CommonConveyorLine_CW)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);
- if (conveyorLine.DeviceCode == "1024")
+ var chunks = childDeviceCodes.Chunk(10);
+
+ //if (conveyorLine.DeviceCode == "1024")
+ //{
+ // childDeviceCodes.Add("4000");
+ //}
+
+ //var options = new ParallelOptions
+ //{
+ // MaxDegreeOfParallelism = 10
+ // //MaxDegreeOfParallelism = Environment.ProcessorCount
+ //};
+
+ //{
+ // SiemensS7 siemensS7 = new SiemensS7(conveyorLine.Communicator.IpAddress, conveyorLine.Communicator.Port, conveyorLine.DeviceName);
+ // siemensS7.Connect();
+ // tasks.Add(Task.Run(() =>
+ // {
+
+ // }));
+ //}
+ //Parallel.For(0, childDeviceCodes.Count, options, i =>
+ //Parallel.ForEach(childDeviceCodes, options, childDeviceCode =>
+ var tasks = new List<Task>();
+
+ foreach (var item in chunks)
{
- childDeviceCodes.Add("4000");
- }
-
- 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)
+ tasks.Add(Task.Run(() =>
{
- MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType);
- if (method != null)
+ foreach (string childDeviceCode in item)
{
- method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode });
- }
- }
+ ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(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)
+ if (command != null)
{
- MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod);
- if (method != null)
+ 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)
{
- int count = 1;
- method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform });
+ 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")
+ {
+ if (lastUpdateTime > DateTime.Now.AddMinutes(1))
+ {
+ lastUpdateTime = DateTime.Now;
+ 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)
+ {
+ 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())
+ {
+
+ 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 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
}
+
+
}
- }
-
-
- #region 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
-
- var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
- if (tokenInfos == null || !tokenInfos.Any())
- {
- 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 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
-
+ }));
}
+ //Task.WaitAll(tasks.ToArray());
#endregion 璺敱鏂瑰紡
}
}
catch (Exception ex)
{
- Console.Out.WriteLine(nameof(CommonConveyorLine_CWJob) + ":" + DateTime.Now + ":" + ex.ToString(),ex.StackTrace);
+ Console.Out.WriteLine(nameof(CommonConveyorLine_CWJob) + ":" + DateTime.Now + ":" + ex.ToString(), ex.StackTrace);
}
finally
{
@@ -209,7 +224,6 @@
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 (childDeviceCode == "4000")
@@ -225,15 +239,15 @@
}
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;
- }
- }
+ //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);
@@ -282,15 +296,6 @@
}
}
}
- //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>
@@ -412,12 +417,9 @@
// 鎷兼帴瀹屾暣鐨凪OM鎺ュ彛鍦板潃锛堝熀纭�IP + 鎺ュ彛璺緞锛�
var MOMIpAddress = wmsBase + ipAddress;
- // 5. 璋冪敤MOM鎺ュ彛锛圥OST寮傛璇锋眰锛屽悓姝ョ瓑寰呯粨鏋滐級
+ WriteInfo("鍏ョ珯鏍¢獙", $"銆恵childDeviceCode}銆戝叆绔欐牎楠岃姹傚弬鏁般�恵trayCells.Serialize()}銆�");
var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.Serialize()).Result;
- // 璁板綍鎺ュ彛璋冪敤鏃ュ織锛堣姹傚弬鏁般�佽繑鍥炲弬鏁帮級锛屼究浜庨棶棰樻帓鏌�
- WriteInfo("鍏ョ珯鏍¢獙", $"銆恵childDeviceCode}銆戝叆绔欐牎楠岃姹傚弬鏁般�恵trayCells.Serialize()}銆�");
- WriteInfo("鍏ョ珯鏍¢獙", "");
WriteInfo("鍏ョ珯鏍¢獙", $"銆恵childDeviceCode}銆戝叆绔欐牎楠岃繑鍥炲弬鏁般�恵result}銆�");
// 6. 瑙f瀽MOM鎺ュ彛杩斿洖缁撴灉涓哄疄浣撳璞�
@@ -519,7 +521,11 @@
content = _taskService.UpdateTaskStatusToNext(task);
}
var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationArea == "Call" && x.stationType == 12);
- CommonConveyorLine_BZ? commonConveyorBZ=Storage.Devices.FirstOrDefault(x=>x.DeviceCode==station.stationPLC) as CommonConveyorLine_BZ;
+ if (station == null)
+ {
+ return;
+ }
+ CommonConveyorLine_BZ? commonConveyorBZ = Storage.Devices.FirstOrDefault(x => x.DeviceCode == station.stationPLC) as CommonConveyorLine_BZ;
if (commonConveyorBZ != null)
{
ConveyorLineTaskCommand_After readSignal = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(station.stationLocation);
@@ -633,14 +639,11 @@
}
var wmsIpAddress = wmsBase + requestTrayOutTask;
-
+
List<string> strings = platform.Location.Split(',').ToList();
- WriteInfo("璋冨害鎵ц鏃堕棿璁板綍", "銆愯皟鍙朩MS鍑哄簱鎺ュ彛寮�濮嬫椂闂达細銆�" + 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("璋冨害鎵ц鏃堕棿璁板綍", "銆愯皟鍙朩MS鍑哄簱鎺ュ彛缁撴潫鏃堕棿锛氥��" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
+ WriteInfo("OCV璇锋眰杩斿洖鍙傛暟", $"鏃堕棿锛氥�恵DateTime.Now}銆戣姹傜偣浣嶃�恵childDeviceCode}銆戣繑鍥炲弬鏁般�恵JsonConvert.SerializeObject(result)}銆�");
WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
@@ -662,6 +665,7 @@
public WebResponseContent CreateAndSendTask(WMSTaskDTO taskDTO)
{
var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
+
if (content.Status)
{
Console.WriteLine($"{taskDTO.TaskType}鍛煎彨鎴愬姛");
--
Gitblit v1.9.3