From 011ca316e6ec2ed93e31c45a9ebd9d3c66664871 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期五, 17 四月 2026 11:47:03 +0800
Subject: [PATCH] 代码更新
---
项目代码/WCS/WCSServices/WIDESEAWCS_Tasks/成品仓/ConveyorLineJob_CPH.cs | 223 +++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 166 insertions(+), 57 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPH.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPH.cs"
index bdf7663..3373570 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPH.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSServices/WIDESEAWCS_Tasks/\346\210\220\345\223\201\344\273\223/ConveyorLineJob_CPH.cs"
@@ -1,18 +1,22 @@
-锘縰sing Microsoft.AspNetCore.Components.Routing;
+锘縰sing Autofac.Core;
+using Microsoft.AspNetCore.Components.Routing;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
+using Org.BouncyCastle.Asn1.Ocsp;
using Org.BouncyCastle.Tls;
using Quartz;
-using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.Linq;
using System.Text;
+using System.Threading.Channels;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
@@ -23,6 +27,7 @@
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
+using WIDESEAWCS_TaskInfoRepository;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using ICacheService = WIDESEAWCS_Core.Caches.ICacheService;
@@ -40,9 +45,11 @@
private readonly IRouterService _routerService;
private readonly IRouterExtension _routerExtension;
private readonly List<Dt_WarehouseDevice> warehouseDevices;
+ private readonly IPackaxisTaskRepository _packaxisTaskRepository;
+ private readonly IPackaxisTaskService _packaxisTaskService;
private static object lockObj = 0;//
- public ConveyorLineJob_CPH(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension)
+ public ConveyorLineJob_CPH(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension, IPackaxisTaskRepository packaxisTaskRepository, IPackaxisTaskService packaxisTaskService)
{
_cacheService = cacheService;
_taskService = taskService;
@@ -52,7 +59,6 @@
_routerRepository = routerRepository;
_routerService = routerService;
_routerExtension = routerExtension;
-
string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice));
if (!string.IsNullOrEmpty(warehouseDevicesStr))
{
@@ -62,6 +68,8 @@
{
warehouseDevices = new List<Dt_WarehouseDevice>();
}
+ _packaxisTaskRepository = packaxisTaskRepository;
+ _packaxisTaskService = packaxisTaskService;
}
public Task Execute(IJobExecutionContext context)
@@ -71,83 +79,184 @@
if (lockObj.ToString()=="0")
{
lockObj = 1;
- Task task = Task.Run(() =>
+ bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
+ if (flag && value != null)
{
try
{
- while (true)
+ //鑾峰彇褰撳墠璁惧
+ OtherDevice device = (OtherDevice)value;
+ List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
+ Task.Run(() =>
{
- bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
- if (flag && value != null)
+ bool shouldRestart = true;
+
+ while (shouldRestart)
{
- //鑾峰彇褰撳墠璁惧
- OtherDevice device = (OtherDevice)value;
- List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).Distinct().ToList();
- List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode);
- foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
+ try
{
- DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
- DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
- if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && deviceProRead != null && deviceProWrite != null)
+ shouldRestart = false;
+ Dt_StationManger? RequestIn = stationMangers.FirstOrDefault(x => x.StationDeviceCode == device.DeviceCode && x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt());
+ WriteInfo($"绾跨▼ {Thread.CurrentThread.ManagedThreadId}鍒嗗灈鍙�","寮�濮嬫墽琛�");
+ while (true)
{
- R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
- //鐮佸灈鐜嚎璇锋眰浠诲姟
- if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.R_BoxCode) && conveyorLineInfoRead.R_Request == 1)
+ //WriteInfo($"鍒嗗灈鍙h繍琛屾椂闂�" , $"寮�濮嬫椂闂�:" + DateTime.Now.ToString("HH:mm:ss.fff"));
+ if (RequestIn != null)
{
- //WebResponseContent content = _taskService.RequestWMSTaskSimple(conveyorLineInfoRead.R_BoxCode, item.StationCode);
- ////鍚慦MS璇锋眰浠诲姟
- //if (true)
- //{
-
- //}
- //鍐欏叆鎵ц鏁版嵁
- device.SetValue(W_CLineCPHDB.W_TaskNo, 1002, item.StationCode);
- device.SetValue(W_CLineCPHDB.W_Channel, 5, item.StationCode);
- device.SetValue(W_CLineCPHDB.W_Long, 400, item.StationCode);
- device.SetValue(W_CLineCPHDB.W_Wide, 370, item.StationCode);
- device.SetValue(W_CLineCPHDB.W_High, 300, item.StationCode);
- device.SetValue(W_CLineCPHDB.W_TMID, conveyorLineInfoRead.R_BoxCode, item.StationCode);
- device.SetValue(W_CLineCPHDB.W_Request, 1, item.StationCode);
-
- }
- }
- else if (item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt() && deviceProRead != null)
- {
- R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
- //鑾峰彇鐮佸灈鍙d换鍔℃洿鏂颁换鍔$姸鎬�
- if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo > 0)
- {
- Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.R_TaskNo && x.NextAddress == item.StationCode && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt());
- if (task != null)
+ DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == RequestIn.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+ DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == RequestIn.StationCode && x.DeviceProParamType == nameof(W_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+ if (deviceProRead != null && deviceProWrite != null)
{
- task.CurrentAddress = item.StationCode;
- task.NextAddress = task.TargetAddress;
- task.DeviceCode = item.StackerCraneCode;
- _taskService.UpdateTask(task, TaskStatusEnum.MD_Executing);
+ R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress);
+ //鐮佸灈鐜嚎璇锋眰浠诲姟
+ if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.R_BoxCode) && conveyorLineInfoRead.R_Request == 1)
+ {
+ //WriteInfo($"鍒嗗灈鍙h繍琛屾椂闂�", $"{conveyorLineInfoRead.R_BoxCode}璇锋眰" + DateTime.Now.ToString("HH:mm:ss.fff"));
+ //鍒ゆ柇鏄惁浠诲姟宸茬粡瀛樺湪
+ Dt_PackaxisTask packaxisTask = _packaxisTaskRepository.Db.Queryable<Dt_PackaxisTask>().Where(x => x.BarCode == conveyorLineInfoRead.R_BoxCode.Trim() && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt()).First();
+ if (packaxisTask != null)
+ {
+ //鍐欏叆鎵ц鏁版嵁
+ device.SetValue(W_CLineCPHDB.W_TaskNo, packaxisTask.PackTaskNum, RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_Channel, packaxisTask.NextAddress, RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_Long, packaxisTask.PackLength, RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_Wide, packaxisTask.PackWidth, RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_High, packaxisTask.PackHeight, RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_TMID, conveyorLineInfoRead.R_BoxCode.Trim(), RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_Request, 1, RequestIn.StationCode);
+ //WriteInfo($"鍒嗗灈鍙h繍琛屾椂闂�", $"{conveyorLineInfoRead.R_BoxCode}璇锋眰瀹屾垚" + DateTime.Now.ToString("HH:mm:ss.fff"));
+ }
+ else
+ {
+ #region
+ WebResponseContent webResponse = _packaxisTaskService.ReqPackTask(conveyorLineInfoRead.R_BoxCode.Trim(), RequestIn.StationDeviceCode);
+ if (webResponse.Status)
+ {
+ Dt_PackaxisTask _PackaxisTask = webResponse.Data as Dt_PackaxisTask;
+ //鍐欏叆鎵ц鏁版嵁
+ device.SetValue(W_CLineCPHDB.W_TaskNo, _PackaxisTask.PackTaskNum, RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_Channel, _PackaxisTask.NextAddress.ObjToInt(), RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_Long, _PackaxisTask.PackLength, RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_Wide, _PackaxisTask.PackWidth, RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_High, _PackaxisTask.PackHeight, RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_TMID, conveyorLineInfoRead.R_BoxCode.Trim(), RequestIn.StationCode);
+ device.SetValue(W_CLineCPHDB.W_Request, 1, RequestIn.StationCode);
+ //WriteInfo($"鍒嗗灈鍙h繍琛屾椂闂�", $"{conveyorLineInfoRead.R_BoxCode}璇锋眰瀹屾垚" + DateTime.Now.ToString("HH:mm:ss.fff"));
+ WebResponseContent content = _taskService.MESBoxCodeNotice(conveyorLineInfoRead.R_BoxCode.Trim());
+ if (content.Status)
+ {
+ WriteInfo(RequestIn.StationName, content.Message);
+ }
+ else
+ {
+ WriteError(RequestIn.StationName, content.Message);
+ }
+ }
+ else
+ {
+ WriteError(RequestIn.StationName, webResponse.Message);
+ }
+ #endregion
+ }
+ Thread.Sleep(200);
+ }
+ }
+ else
+ {
+ WriteError(RequestIn.StationName, $"鏈壘鍒拌澶囧瓙缂栧彿{RequestIn.StationCode}鐨勫崗璁俊鎭�");
}
}
- }
- else
- {
- WriteError(item.StationName, $"鏈壘鍒拌澶囧瓙缂栧彿{item.StationCode}鐨勫崗璁俊鎭�");
+ //WriteInfo($"鍒嗗灈鍙h繍琛屾椂闂�", $"缁撴潫鏃堕棿:" + DateTime.Now.ToString("HH:mm:ss.fff"));
}
}
+ catch (Exception ex)
+ {
+ WriteInfo($"绾跨▼ {Thread.CurrentThread.ManagedThreadId}鍒嗗灈鍙�", $"寮傚父:{ex.Message}");
+ Thread.Sleep(3000);
+ shouldRestart = true;
+ }
}
- Thread.Sleep(100);
-
- }
+ });
+ Task.Run(() =>
+ {
+ bool shouldRestart = true;
+
+ while (shouldRestart)
+ {
+ try
+ {
+ shouldRestart = false;
+ //鑾峰彇鎵�鏈夌爜鍨涘彛
+ List<Dt_StationManger> stationMangersMD = stationMangers.Where(x => x.StationDeviceCode == device.DeviceCode && x.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt()).ToList();
+ WriteInfo($"绾跨▼ {Thread.CurrentThread.ManagedThreadId}鐮佸灈鍙�", "寮�濮嬫墽琛�");
+ while (true)
+ {
+ if (stationMangersMD.Count > 0)
+ {
+ foreach (var item in stationMangersMD)
+ {
+ DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+ if (deviceProRead != null)
+ {
+ R_CLineCPHChannelInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHChannelInfo>(deviceProRead.DeviceProAddress);
+ //鑾峰彇鐮佸灈鍙d换鍔℃洿鏂颁换鍔$姸鎬�
+ if (conveyorLineInfoRead != null && conveyorLineInfoRead.R_State == 5 && conveyorLineInfoRead.R_TaskNo > 0)
+ {
+ Dt_PackaxisTask packaxisTask = _packaxisTaskRepository.QueryFirst(x => x.PackTaskNum == conveyorLineInfoRead.R_TaskNo && x.NextAddress == item.StationCode && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode == item.StationDeviceCode);
+ if (packaxisTask != null)
+ {
+ Dt_PackaxisTask packaxisTaskOld = _packaxisTaskRepository.QueryFirst(x => x.TaskState == TaskStatusEnum.MD_Executing.ObjToInt() && x.DeviceCode == item.StackerCraneCode);
+ if (packaxisTaskOld != null)
+ {
+ WriteError(item.StationName, $"鐮佸灈{item.StackerCraneCode}姝f墽琛屼换鍔packaxisTaskOld.PackTaskNum},鏃犳硶缁х画涓嬪彂");
+ }
+ else
+ {
+ packaxisTask.CurrentAddress = item.StationCode;
+ packaxisTask.NextAddress = packaxisTask.TargetAddress;
+ packaxisTask.DeviceCode = item.StackerCraneCode;
+ packaxisTask.TaskState = TaskStatusEnum.MD_Executing.ObjToInt();
+ _packaxisTaskRepository.UpdateData(packaxisTask);
+ device.SetValue(W_CLineCPHDB.W_Request, 1, item.StationCode);
+ }
+ }
+ else
+ {
+ WriteError(item.StationName, $"鏈壘鍒颁换鍔conveyorLineInfoRead.R_TaskNo}淇℃伅");
+ }
+ Thread.Sleep(2000);
+ }
+ }
+ }
+ }
+ else
+ {
+ WriteError(nameof(ConveyorLineJob_CPH), $"閿欒淇℃伅锛氭湭鎵惧埌鐮佸灈鍙d俊鎭�");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ WriteInfo($"绾跨▼ {Thread.CurrentThread.ManagedThreadId}鐮佸灈鍙�", $"寮傚父:{ex.Message}");
+ Thread.Sleep(3000);
+ shouldRestart = true;
+ }
+ }
+ });
+
}
catch (Exception ex)
{
-
lockObj = 0;
WriteError(nameof(ConveyorLineJob_CPH), $"閿欒淇℃伅锛歿ex.Message}");
}
- });
+ }
+
}
}
+
return Task.CompletedTask;
}
}
--
Gitblit v1.9.3