From c54e0666bdd34fbe133fe521bf9d46dd6c0fe53e Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期四, 12 六月 2025 10:33:28 +0800
Subject: [PATCH] 代码提交
---
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs | 297 ++++++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 200 insertions(+), 97 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs"
index 77f391b..dad3669 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs"
@@ -15,183 +15,285 @@
*----------------------------------------------------------------*/
#endregion << 鐗� 鏈� 娉� 閲� >>
+using Autofac.Core;
using AutoMapper;
+using HslCommunication;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
+using System.Reflection;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_Core.Caches;
+using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_Core.HttpContextUser;
using WIDESEAWCS_DTO.Enum;
+using WIDESEAWCS_DTO.TaskInfo;
+using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ISystemServices;
+using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
-using WIDESEAWCS_Model.Models.System;
+using WIDESEAWCS_Model.Models.BasicInfo;
using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.DeviceBase;
+using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Service;
+using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.ConveyorLineJob;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
namespace WIDESEAWCS_Tasks
{
[DisallowConcurrentExecution]
- public class CommonConveyorLineJob : IJob
+ public class CommonConveyorLineJob :JobBase, IJob
{
private readonly ITaskService _taskService;
+ private readonly ITaskRepository _taskRepository;
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
private readonly IRouterService _routerService;
- private readonly IAgvStationService _agvStationService;
+ private readonly IDt_StationManagerService _stationManagerService;
private readonly IMapper _mapper;
+ private readonly ICacheService _cacheService;
+ private readonly INoticeService _noticeService;
+ private static List<string>? userTokenIds;
+ private static List<int>? userIds;
- public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IAgvStationService agvStation, IMapper mapper)
+ public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IDt_StationManagerService stationManagerService, IMapper mapper, ICacheService cacheService, INoticeService noticeService, ITaskRepository taskRepository)
{
_taskService = taskService;
_taskExecuteDetailService = taskExecuteDetailService;
_routerService = routerService;
- _agvStationService = agvStation;
+ _stationManagerService = stationManagerService;
_mapper = mapper;
+ _cacheService = cacheService;
+ _noticeService = noticeService;
+ _taskRepository = taskRepository;
}
- public Task Execute(IJobExecutionContext context)
+ public async Task Execute(IJobExecutionContext context)
{
try
{
- wcsWriteLog("LineJob", "杩愯鐘舵��", $"寮�濮嬫椂闂达細{DateTime.Now}");
CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
if (conveyorLine != null)
{
- //鐢熸垚鍙栬揣浠诲姟锛屾斁鑷充笂鏂欎綅
- RequestInbound(conveyorLine);
- //鏍规嵁agv涓嬫枡浠诲姟锛屾妸鏂欐斁鑷充笂鏂欏彛鎴栫紦瀛樹綅
- RequestOutbound(conveyorLine); //涓婃枡鍙i渶瑕佹壘浠诲姟锛屾壘缂撳瓨鍖�
+ // 鑾峰彇鎵�鏈夌珯鐐圭鐞嗗櫒
+ List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode);
+
+ // 骞惰澶勭悊姣忎釜瀛愯澶�
+ var tasks = stationManagers.Select(station => ProcessDeviceAsync(conveyorLine, station)).ToList();
+
+ await Task.WhenAll(tasks);
}
}
catch (Exception ex)
{
- //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
- wcsWriteLog("LineJob閿欒淇℃伅", "寮傚父淇℃伅", ex.ToString());
+ Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
}
- wcsWriteLog("LineJob", "杩愯鐘舵��", $"缁撴潫鏃堕棿锛歿DateTime.Now}");
+ return;
+ }
+ private Task ProcessDeviceAsync(CommonConveyorLine conveyorLine, Dt_StationManager station)
+ {
+ try
+ {
+ ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationName);
+ if (command != null)
+ {
+ #region 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
+
+ // 鑾峰彇缂撳瓨涓殑鐢ㄦ埛淇℃伅
+ var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
+ if (tokenInfos != null && tokenInfos.Any())
+ {
+ userTokenIds = tokenInfos.Select(x => x.Token_ID).ToList();
+ userIds = tokenInfos.Select(x => x.UserId).ToList();
+ }
+
+ #endregion 璋冪敤浜嬩欢鎬荤嚎閫氱煡鍓嶇
+
+ // 灏嗕氦浜掍俊鍙疯浆鎹负甯冨皵鏁扮粍
+ var writeInteractiveSignal = command.InteractiveSignal;
+ var structs = BitConverter.GetBytes(writeInteractiveSignal).Reverse().ToArray().ToBoolArray();
+ // 鑾峰彇璁惧鍗忚璇︽儏
+ List<DeviceProtocolDetailDTO>? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.Where(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal)).ToList();
+
+ if (deviceProtocolDetails != null)
+ {
+ foreach (var item in deviceProtocolDetails)
+ {
+ int itemValue = Convert.ToInt32(item.ProtocalDetailValue);
+ if (structs[itemValue] == true)
+ {
+ // 鑾峰彇澶勭悊鏂规硶
+
+ MethodInfo? method = GetType().GetMethod(item.ProtocolDetailType);
+ if (method != null)
+ {
+ method.Invoke(this, new object[] { conveyorLine, station.stationName });
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ WriteInfo(conveyorLine.DeviceName, ex.Message);
+ }
return Task.CompletedTask;
}
-
/// <summary>
- /// 杈撻�佺嚎璇锋眰鍏ュ簱
+ /// 鐢熸垚鍙栬揣浠诲姟锛屾斁鑷充笂鏂欎綅
/// </summary>
/// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
/// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>Request outbound
/// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
- public void RequestInbound(CommonConveyorLine conveyorLine)
+ public async Task RequestInbound(CommonConveyorLine conveyorLine, string childDeviceCode)
{
- List<string> _Task = _taskService.QueryConveyorLineTaskSourceAddress();
- List<AGVStation> childDeviceCodes = _agvStationService.QuerypLatform(conveyorLine.DeviceCode, _Task); //瀵瑰簲姣忎釜ip鎵惧叏閮ㄧ殑涓嬫枡绔欑偣涓庡灚鏉垮洖鏀剁偣绔欏彴鐐�
- foreach (var childDeviceCode in childDeviceCodes)
+ try
{
- ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(childDeviceCode.Station_name);
- if (command != null)
+ // 杈撳嚭淇℃伅锛岃〃绀虹珯鍙拌姹傚彇璐�
+ var log = $"銆恵conveyorLine._deviceName}銆戠珯鍙般�恵childDeviceCode}銆戣姹傚彇璐�";
+ ConsoleHelper.WriteWarningLine(log);
+ // 鎺ㄩ�侀�氱煡鍒板墠绔疭ignIR
+ await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "Red" });
+ WriteInfo(conveyorLine.DeviceName, log);
+
+ // 鑾峰彇鎵�鏈変换鍔℃簮鍦板潃
+ List<string> task = _taskService.QueryConveyorLineTaskSourceAddress();
+
+ // 鏍规嵁璁惧缂栧彿鍜屼换鍔℃簮鍦板潃鏌ヨ鎵�鏈夋湭鎵ц鐨勪换鍔�
+ List<Dt_StationManager> childDeviceCodes = _stationManagerService.QuerypLatform(conveyorLine.DeviceCode, task); //瀵瑰簲姣忎釜ip鎵惧叏閮ㄧ殑涓嬫枡绔欑偣涓庡灚鏉垮洖鏀剁偣绔欏彴鐐�
+
+
+ foreach (var item in childDeviceCodes)
{
- if (command.R_Releasespermitted == 1)
+ ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item.stationName);
+ if (command != null)
{
- if (childDeviceCode.Station_material==(int)AgvStationEnum.PadRecycle)
+ var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray();
+ if (structs[1])
{
- RequestHcdbst(conveyorLine, childDeviceCode.Station_Area, childDeviceCode.Station_name, childDeviceCode.Station_remark);
+ if (item.stationMaterial == (int)AgvStationEnum.PadRecycle)
+ {
+ RequestHcdbst(conveyorLine, item.stationArea, item.stationName, item.stationRemark);
+ return;
+ }
+ else
+ {
+ Dt_Task taskDTO = new Dt_Task()
+ {
+ TaskNum = _taskRepository.GetTaskNo().Result,
+ Grade = 1,
+ Roadway = item.stationArea.ToString(),
+ SourceAddress = childDeviceCode,
+ TargetAddress = item.stationName,
+ TaskState = (int)AGVTaskStatusEnum.AGVNew,
+ TaskType = item.stationMaterial,
+ };
+ _taskService.ReceiveWMSTask(new List<Dt_Task> { taskDTO });
+ return;
+ }
}
else
{
- Dt_Task taskDTO = new Dt_Task()
- {
- TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")) + childDeviceCode.Station_code,
- Grade = 1,
- Roadway = childDeviceCode.Station_Area.ToString(),
- SourceAddress = childDeviceCode.Station_name,
- CurrentAddress = childDeviceCode.Station_name,
- TaskState = (int)TaskInStatusEnum.InNew,
- TaskType = (int)childDeviceCode.Station_material,
- };
- _taskService.ReceiveWMSTask(taskDTO);
+ WriteInfo(conveyorLine.DeviceName, $"绔欏彴{item.stationName}鐘舵�佷笉鍙敤{structs[2]}");
}
}
else
{
- wcsWriteLog(childDeviceCode.Station_name, "璇诲彇淇℃伅", $"鏈壘鍒拌璇诲彇妯″潡");
+ WriteInfo(conveyorLine.DeviceName, $"閫氳杩炴帴閿欒锛寋item.stationName}鏈壘鍒拌鍙栨ā鍧楀湴鍧�");
}
}
- else
- {
- wcsWriteLog(childDeviceCode.Station_name, "璇诲彇淇℃伅", $"閫氳杩炴帴閿欒锛屾湭鎵惧埌璇诲彇妯″潡鍦板潃");
- }
+
+ }
+ catch (Exception ex)
+ {
+ WriteInfo(conveyorLine.DeviceName, ex.Message);
}
}
/// <summary>
- /// 杈撻�佺嚎璇锋眰鍑虹珯
+ /// 鏍规嵁agv涓嬫枡浠诲姟锛屾妸鏂欐斁鑷充笂鏂欏彛鎴栫紦瀛樹綅
/// </summary>
/// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
- /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
/// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
- public void RequestOutbound(CommonConveyorLine conveyorLine)
+ public void RequestOutbound(CommonConveyorLine conveyorLine, string childDeviceCode)
{
- List<AGVStation> AGVStationListdata = _agvStationService.QuerypLatformarer(conveyorLine.DeviceCode);
- foreach (var AGVStationitem in AGVStationListdata)
+ try
{
- ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(AGVStationitem.Station_name);
- if (command != null)
+ List<Dt_StationManager> station = _stationManagerService.QuerypLatformarer(conveyorLine.DeviceCode);
+ foreach (var item in station)
{
- if (command.R_Pickuppermitted == 1)
+ ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item.stationName);
+ if (command != null)
{
- if (AGVStationitem.Station_material == (int)AgvStationEnum.BoardLoad)
+ var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray();
+ if (structs[2])
{
- Dt_Task agvstack= _taskService.QueryConveyorLineTaskRoadway(AGVStationitem.Station_Area);
- if(agvstack != null)
+ if (item.stationMaterial == (int)AgvStationEnum.BoardLoad)
{
- _taskService.UpdateTargetAddress(agvstack.TaskId, AGVStationitem.Station_name);
- }
- else
- {
- //鍘绘壘缂撳瓨鍖哄簱瀛�
- RequestHcst(conveyorLine, AGVStationitem.Station_Area, AGVStationitem.Station_name, AGVStationitem.Station_remark);
+ //Dt_Task agvstack= _taskService.QueryConveyorLineTaskRoadway(AGVStationitem.stationArea);
+ //if(agvstack != null)
+ //{
+ // _taskService.UpdateTargetAddress(agvstack.TaskId, AGVStationitem.stationName);
+ //}
+ //else
+ //{
+ // //鍘绘壘缂撳瓨鍖哄簱瀛�
+ // RequestHcst(conveyorLine, AGVStationitem.stationArea, AGVStationitem.stationName, AGVStationitem.stationRemark);
+ //}
}
}
- }
- else
- {
- wcsWriteLog(AGVStationitem.Station_name, "璇诲彇淇℃伅", $"閫氳杩炴帴閿欒锛屾湭鎵惧埌璇诲彇妯″潡鍦板潃");
+ else
+ {
+ WriteInfo(conveyorLine.DeviceName, $"绔欏彴{item.stationName}鐘舵�佷笉鍙敤{structs[2]}");
+ }
}
}
+ }
+ catch (Exception ex)
+ {
+ WriteInfo(conveyorLine.DeviceName, ex.Message);
}
}
public void RequestHcst(CommonConveyorLine conveyorLine,int Station_Area,string Station_names,string Station_remark)
{
- List<AGVStation> AGVStationListdata = _agvStationService.QuerypLatformmaterial(Station_Area); //鏌ュ嚭缂撳瓨浣�
+ List<Dt_StationManager> AGVStationListdata = _stationManagerService.QuerypLatformmaterial(Station_Area); //鏌ュ嚭缂撳瓨浣�
if (Station_remark != null) //鎵惧瀵瑰簲鐨勬斁璐х珯鍙�
{
- AGVStationListdata = _agvStationService.QuerypStation_Area2(Station_remark);
+ AGVStationListdata = _stationManagerService.QuerypStation_Area2(Station_remark);
}
- foreach (var AGVStationitem in AGVStationListdata)
+ foreach (var item in AGVStationListdata)
{
- ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(AGVStationitem.Station_name);
+ ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item.stationName);
if (command != null)
{
- if (command.R_Releasespermitted == 1)
+ var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray();
+ if (structs[1])
{
- if (_taskService.QueryConveyorLinetaeersuadd(AGVStationitem.Station_name))
+ if (_taskService.QueryConveyorLinetaeersuadd(item.stationName))
{
Dt_Task taskDTO = new Dt_Task()
{
- TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")) + AGVStationitem.Station_code,
+ TaskNum = _taskRepository.GetTaskNo().Result,
Grade = 1,
- Roadway = AGVStationitem.Station_Area.ToString(),
- SourceAddress = AGVStationitem.Station_name,
- CurrentAddress = AGVStationitem.Station_name,
+ Roadway = item.stationArea.ToString(),
+ SourceAddress = item.stationName,
+ CurrentAddress = item.stationName,
TaskState = (int)TaskInStatusEnum.InNew,
- TaskType = (int)AGVStationitem.Station_material,
+ TaskType = (int)item.stationMaterial,
TargetAddress = Station_names,
NextAddress = Station_names,
};
- _taskService.ReceiveWMSTask(taskDTO);
+ _taskService.ReceiveWMSTask(new List<Dt_Task> { taskDTO });
}
}
else
{
- wcsWriteLog(AGVStationitem.Station_name, "璇诲彇淇℃伅", $"閫氳杩炴帴閿欒锛屾湭鎵惧埌璇诲彇妯″潡鍦板潃");
+ WriteInfo(conveyorLine.DeviceName, $"閫氳杩炴帴閿欒锛寋item.stationName}鏈壘鍒拌鍙栨ā鍧楀湴鍧�");
}
}
}
@@ -199,56 +301,57 @@
public void RequestHcdbst(CommonConveyorLine conveyorLine, int Station_Area, string Station_names,string Station_remark)
{
- List<AGVStation> AGVStationListdata = _agvStationService.QuerypStation_Area(Station_Area); //鏌ュ嚭缂撳瓨浣�
+ List<Dt_StationManager> AGVStationListdata = _stationManagerService.QuerypStation_Area(Station_Area); //鏌ュ嚭缂撳瓨浣�
if(Station_remark !=null) //鎵惧瀵瑰簲鐨勬斁璐х珯鍙�
{
- AGVStationListdata= _agvStationService.QuerypStation_Area2(Station_remark);
+ AGVStationListdata= _stationManagerService.QuerypStation_Area2(Station_remark);
}
- foreach (var AGVStationitem in AGVStationListdata)
+ foreach (var item in AGVStationListdata)
{
- ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(AGVStationitem.Station_name);
+ ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item.stationName);
if (command != null)
{
- if (command.R_Releasespermitted == 1)
+ var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray();
+ if (structs[1])
{
- if (_taskService.QueryConveyorLinetaeersuadd(AGVStationitem.Station_name))
+ if (_taskService.QueryConveyorLinetaeersuadd(item.stationName))
{
Dt_Task taskDTO = new Dt_Task()
{
- TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")) + AGVStationitem.Station_code,
+ TaskNum = _taskRepository.GetTaskNo().Result,
Grade = 1,
- Roadway = AGVStationitem.Station_Area.ToString(),
+ Roadway = item.stationArea.ToString(),
SourceAddress = Station_names,
CurrentAddress = Station_names,
TaskState = (int)TaskInStatusEnum.InNew,
- TaskType = (int)AGVStationitem.Station_material,
- TargetAddress = AGVStationitem.Station_name,
- NextAddress = AGVStationitem.Station_name,
+ TaskType = (int)item.stationMaterial,
+ TargetAddress = item.stationName,
+ NextAddress = item.stationName,
};
- _taskService.ReceiveWMSTask(taskDTO);
+ _taskService.ReceiveWMSTask(new List<Dt_Task> { taskDTO });
}
}
else
{
- wcsWriteLog(AGVStationitem.Station_name, "璇诲彇淇℃伅", $"璇诲彇鏀捐揣淇″彿涓猴細{command.R_Releasespermitted}");
+ WriteInfo(conveyorLine.DeviceName, $"璇诲彇鏀捐揣淇″彿涓猴細{structs[2]}");
}
}
}
}
-
-
/// <summary>
- /// 璇诲彇淇℃伅璁板綍
+ /// 杈撻�佺嚎浜や簰瀹屾垚
/// </summary>
- /// <param name="SCLLinStack"></param>
- /// <param name="Logtype"></param>
- /// <param name="Magessadd"></param>
- public void wcsWriteLog(string SCLLinStack,string Logtype,string Magessadd)
+ /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
+ /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
+ /// <param name="ProtocalDetailValue">绾夸綋褰撳墠bool璇诲彇鍋忕Щ鍦板潃</param>
+ /// <param name="value">鍊�</param>
+ public void ConveyorLineSendFinish(CommonConveyorLine conveyorLine, string childDeviceCode)
{
- WriteLog.Write_Log("绔欏彴璇诲彇淇℃伅璁板綍", SCLLinStack+"绔欏彴", Logtype, new{淇℃伅 = Magessadd });
- }
+ DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == childDeviceCode && x.DeviceProParamName == "WriteInteractiveSignal").OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+ conveyorLine.Communicator.Write(devicePro.DeviceProAddress, true);
+ }
}
}
--
Gitblit v1.9.3