From ce3b28cdcdb2b6a912413cd9e744d0ecadcb78a0 Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期二, 13 一月 2026 17:47:30 +0800
Subject: [PATCH] 优化成品出入库流程代码
---
WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs | 287 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 264 insertions(+), 23 deletions(-)
diff --git a/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs b/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
index b2902c0..73d7358 100644
--- a/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
+++ b/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -15,7 +15,10 @@
*----------------------------------------------------------------*/
#endregion << 鐗� 鏈� 娉� 閲� >>
+using Autofac.Core;
using AutoMapper;
+using Microsoft.AspNetCore.Routing;
+using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using System;
@@ -24,12 +27,20 @@
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
+using WIDESEAWCS_Common;
+using WIDESEAWCS_Common.Helper;
+using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_IBasicInfoRepository;
+using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
+using WIDESEAWCS_QuartzJob.Models;
+using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob;
@@ -41,44 +52,274 @@
private readonly ITaskService _taskService;
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
private readonly IRouterService _routerService;
+ private readonly IRouterRepository _routerRepository;
+ private readonly ITaskRepository _taskRepository;
private readonly IMapper _mapper;
+ private readonly IStationMangerRepository _stationMangerRepository;
+ private readonly ICacheService _cacheService;
+ private readonly List<Dt_WarehouseDevice> warehouseDevices;
- public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper)
+ public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, ITaskRepository taskRepository, ICacheService cacheService, IMapper mapper)
{
_taskService = taskService;
_taskExecuteDetailService = taskExecuteDetailService;
_routerService = routerService;
+ _stationMangerRepository = stationMangerRepository;
+ _taskRepository = taskRepository;
+ _routerRepository = routerRepository;
+ _cacheService = cacheService;
_mapper = mapper;
- }
+ string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice));
+ if (!string.IsNullOrEmpty(warehouseDevicesStr))
+ {
+ warehouseDevices = JsonConvert.DeserializeObject<List<Dt_WarehouseDevice>>(warehouseDevicesStr) ?? new List<Dt_WarehouseDevice>();
+ }
+ else
+ {
+ warehouseDevices = new List<Dt_WarehouseDevice>();
+ }
+
+ }
public Task Execute(IJobExecutionContext context)
{
- //Console.Out.WriteLine(DateTime.Now);
try
{
CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
if (conveyorLine != null)
{
- List<string> childDeviceCodes = new List<string>();
-
- foreach (string childDeviceCode in childDeviceCodes)
+ List<string> deviceStations = conveyorLine.DeviceProDTOs.Select(x => x.DeviceChildCode).ToList();
+ List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == conveyorLine.DeviceCode);
+ foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode)))
{
- R_ConveyorLineInfo command = conveyorLine.ReadCustomer<R_ConveyorLineInfo>(childDeviceCode);
- if (command != null)
+ try
{
-
- }
- }
- }
+ DeviceProDTO? deviceProRead = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ConveyorLineDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+ DeviceProDTO? deviceProWrite = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_ConveyorLineDBName)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+
+ if (deviceProRead != null && deviceProWrite != null)
+ {
+ R_ConveyorLineInfo conveyorLineInfoRead = conveyorLine.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
+
+ W_ConveyorLineInfo conveyorLineInfoWrite = conveyorLine.Communicator.ReadCustomer<W_ConveyorLineInfo>(deviceProWrite.DeviceProAddress);
+ if (conveyorLineInfoRead == null || conveyorLineInfoWrite == null)
+ {
+ continue;
+ }
+
+ R_ConveyorLineStatus conveyorLineStatus = conveyorLineInfoRead.Status.ByteToBoolObject<R_ConveyorLineStatus>();
+
+ ConveyorLineSignal conveyorLineSignalRead = conveyorLineInfoRead.Signal.ByteToBoolObject<ConveyorLineSignal>();
+
+
+ bool ACK = conveyorLine.GetValue<W_ConveyorLineDBName, bool>(W_ConveyorLineDBName.W_ConveyorLine_ACK, item.StationCode);
+
+ bool STB = conveyorLine.GetValue<W_ConveyorLineDBName, bool>(W_ConveyorLineDBName.W_ConveyorLine_STB, item.StationCode);
+
+ //bool Return = conveyorLine.GetValue<W_ConveyorLineDB, bool>(W_ConveyorLineDB.Return, item.StationCode);
+ if (item.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt())
+ {
+
+ if (conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !ACK)
+ {
+ if (conveyorLineInfoRead.TaskNo == 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.Barcode))//閲囪喘鍏ュ簱
+ {
+ WebResponseContent webResponse = _taskService.ApplyLocation(conveyorLineInfoRead.Barcode);
+ if (webResponse.Status)
+ {
+ List<Dt_WarehouseDevice> warehouseDevicesList = warehouseDevices.Where(x => x.WarehouseId == webResponse.Data.ObjToInt()).ToList();
+
+ foreach (var list in warehouseDevicesList)
+ {
+ Dt_Router routers = _routerRepository.QueryFirst(x => x.StartPosi == item.StationCode && x.ChildPosiDeviceCode == list.DeviceCode);
+ #region 鍏堟壘鍏佽鍏ュ簱鐨勮緭閫佺嚎鍏ュ彛
+ deviceProRead = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == routers.NextPosi && x.DeviceProParamType == nameof(R_ConveyorLineDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+ Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.NextAddress == routers.NextPosi);
+ if (dt_Task != null) { continue; }
+ if (deviceProRead != null)
+ {
+ R_ConveyorLineInfo conveyorLineInfoRead1 = conveyorLine.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
+ R_ConveyorLineStatus conveyorLineStatus1 = conveyorLineInfoRead1.Status.ByteToBoolObject<R_ConveyorLineStatus>();
+ if (conveyorLineInfoRead1.Status == 6 && conveyorLineStatus1.Free && conveyorLineStatus1.Online && !conveyorLineStatus1.Goods)
+ {
+
+ #region 璇锋眰WMS鐢熸垚浠诲姟鍚庣粰杈撻�佺嚎鍚姩淇″彿
+ WebResponseContent content = _taskService.CPRequestWMSTaskSimple(conveyorLineInfoRead.Barcode, routers.NextPosi, conveyorLineInfoRead.Spare2, item.StationCode);
+ if (content.Status)
+ {
+ Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == conveyorLineInfoRead.Barcode && x.CurrentAddress == item.StationCode && x.DeviceCode == conveyorLine.DeviceCode && x.TaskState == TaskStatusEnum.New.ObjToInt());
+ if (task != null)
+ {
+ conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, true, item.StationCode);
+ _taskService.UpdateTask(task, TaskStatusEnum.RGV_NEW, sourceAddress: item.StationCode, RGVCode: item.AGVStationCode);
+ WebResponseContent responseContent = _taskService.LedShowTask(item.StationCode, task.PalletCode, task.TaskType);
+ }
+
+ }
+ #endregion
+ }
+ }
+ #endregion
+ }
+ }
+ }
+ }
+ }
+ if (item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt())
+ {
+ if (conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !ACK)
+ {
+ if (conveyorLineInfoRead.TaskNo == 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.Barcode))//閲囪喘鍏ュ簱
+ {
+ WebResponseContent webResponse = _taskService.ApplyLocation(conveyorLineInfoRead.Barcode);
+ if (webResponse.Status)
+ {
+ List<Dt_WarehouseDevice> warehouseDevicesList = warehouseDevices.Where(x => x.WarehouseId == webResponse.Data.ObjToInt()).ToList();
+
+ foreach (var list in warehouseDevicesList)
+ {
+ Dt_Router routers = _routerRepository.QueryFirst(x => x.StartPosi == item.StationCode && x.ChildPosiDeviceCode == list.DeviceCode);
+ #region 鍏堟壘鍏佽鍏ュ簱鐨勮緭閫佺嚎鍏ュ彛
+ deviceProRead = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == routers.NextPosi && x.DeviceProParamType == nameof(R_ConveyorLineDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+ Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.NextAddress == routers.NextPosi);
+ if (dt_Task != null) { continue; }
+ if (deviceProRead != null)
+ {
+ R_ConveyorLineInfo conveyorLineInfoRead1 = conveyorLine.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
+ R_ConveyorLineStatus conveyorLineStatus1 = conveyorLineInfoRead1.Status.ByteToBoolObject<R_ConveyorLineStatus>();
+ if (conveyorLineInfoRead1.Status == 6 && conveyorLineStatus1.Free && conveyorLineStatus1.Online && !conveyorLineStatus1.Goods)
+ {
+
+ #region 璇锋眰WMS鐢熸垚浠诲姟鍚庣粰杈撻�佺嚎鍚姩淇″彿
+ WebResponseContent content = _taskService.CPRequestWMSTaskSimple(conveyorLineInfoRead.Barcode, routers.NextPosi, conveyorLineInfoRead.Spare2, item.StationCode);
+ if (content.Status)
+ {
+ Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == conveyorLineInfoRead.Barcode && x.CurrentAddress == item.StationCode && x.DeviceCode == conveyorLine.DeviceCode && x.TaskState == TaskStatusEnum.New.ObjToInt());
+ if (task != null)
+ {
+ conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, true, item.StationCode);
+ _taskService.UpdateTask(task, TaskStatusEnum.RGV_NEW, sourceAddress: item.StationCode, RGVCode: item.AGVStationCode);
+
+ }
+
+ }
+ #endregion
+ }
+ }
+ }
+ }
+ #endregion
+ }
+ }
+ }
+ //鍑哄簱绔欏彴
+ if (item.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt())
+ {
+
+ }
+ if (item.StationType == StationTypeEnum.SC_In.ObjToInt())
+ {
+ if (conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !ACK)
+ {
+ Dt_Task task = _taskRepository.QueryFirst(x => x.NextAddress == item.StationCode && x.DeviceCode == item.StationDeviceCode && x.TaskState == TaskStatusEnum.RGV_Finish.ObjToInt());
+ if (task != null)
+ {
+ _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, deviceCode: task.Roadway, currentAddress: task.NextAddress);
+ conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, true, item.StationCode);
+ }
+ }
+ }
+ if (item.StationType == StationTypeEnum.SC_Out.ObjToInt())
+ {
+ if (!conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !STB && !ACK)
+ {
+ Dt_Task _Task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt());
+ if (_Task != null)
+ {
+ Dt_Router routers = _routerRepository.QueryFirst(x => x.StartPosi == _Task.CurrentAddress);
+ if (routers != null)
+ {
+ conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_TaskNo, _Task.TaskNum, item.StationCode);
+ conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_EndPos, routers.NextPosi, item.StationCode);
+ conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_STB, true, item.StationCode);
+ _taskService.UpdateTask(_Task, TaskStatusEnum.Line_Executing, nextAddress: routers.NextPosi);
+ WriteDebug($"鍫嗗灈鏈哄嚭搴撳彛{item.StationCode}", $"鍫嗗灈鏈哄嚭搴撳彛浠诲姟鏇存柊,浠诲姟鍙穥_Task.TaskId}锛岀洰鏍囧嚭鍙d綅缃畕_Task.TargetAddress}锛屾墭鐩樺彿锛歿_Task.PalletCode}");
+ }
+ }
+
+ }
+ //鍫嗗灈鏈哄嚭搴撳彛澶栭潰涓�娈靛嚭搴撶珯鍙�
+ if (conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !STB && !ACK)
+ {
+ Dt_Task task = _taskRepository.QueryFirst(x => x.NextAddress == item.StationCode && x.DeviceCode == conveyorLine.DeviceCode && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt());
+ if (task != null)
+ {
+ List<Dt_Router> routers = _routerRepository.QueryData(x => x.StartPosi == item.StationCode).ToList();
+ foreach (var items in routers)
+ {
+ deviceProRead = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == items.NextPosi && x.DeviceProParamType == nameof(R_ConveyorLineDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
+ if (deviceProRead != null)
+ {
+ R_ConveyorLineInfo conveyorLineInfoRead3 = conveyorLine.Communicator.ReadCustomer<R_ConveyorLineInfo>(deviceProRead.DeviceProAddress);
+
+ R_ConveyorLineStatus conveyorLineStatus3 = conveyorLineInfoRead3.Status.ByteToBoolObject<R_ConveyorLineStatus>();
+
+ ConveyorLineSignal conveyorLineSignalRead3 = conveyorLineInfoRead3.Signal.ByteToBoolObject<ConveyorLineSignal>();
+
+ if (!conveyorLineSignalRead3.STB && !conveyorLineSignalRead3.ACK && conveyorLineStatus3.Online && conveyorLineStatus3.Free && !conveyorLineStatus3.Goods && !conveyorLineStatus3.Alarm && !STB && !ACK)//鍒ゆ柇鍑哄簱鍙f槸鍚︾┖闂�
+ {
+ Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TargetAddress == items.NextPosi);
+ if (dt_Task == null)
+ {
+ conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, true, item.StationCode);
+ _taskService.UpdateTask(task, TaskStatusEnum.RGV_Execute, currentAddress: item.StationCode, targetAddress: items.NextPosi, nextAddress: items.NextPosi, RGVCode: item.AGVStationCode);
+ Thread.Sleep(500);
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ }
+ if (!conveyorLineSignalRead.STB && conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && STB && !ACK)
+ {
+ conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_STB, false, item.StationCode);
+ }
+ if (!conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !STB && ACK)
+ {
+ conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, false, item.StationCode);
+ }
+ if (!conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && !conveyorLineStatus.Alarm && !STB && ACK)
+ {
+ conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, false, item.StationCode);
+ }
+ //if (!conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && !conveyorLineStatus.Alarm && !STB && !ACK && Return)
+ //{
+ // conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_Return, false, item.StationCode);
+ //}
+ if (conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && ACK)
+ {
+ conveyorLine.SetValue(W_ConveyorLineDBName.W_ConveyorLine_ACK, false, item.StationCode);
+ }
+
+
+ }
+ }
+ catch (Exception ex)
+ {
+ WriteError(nameof(CommonConveyorLine), ex.Message, ex);
+ }
+
+ }
+
+ }
}
catch (Exception ex)
{
- Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
- }
- finally
- {
- //Console.Out.WriteLine(DateTime.Now);
+ WriteError(nameof(CommonConveyorLine), ex.Message, ex);
}
return Task.CompletedTask;
}
@@ -91,7 +332,7 @@
/// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
{
-
+
}
/// <summary>
@@ -102,7 +343,7 @@
/// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
{
-
+
}
/// <summary>
@@ -113,7 +354,7 @@
/// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
{
-
+
}
/// <summary>
@@ -124,7 +365,7 @@
/// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
{
-
+
}
/// <summary>
@@ -135,7 +376,7 @@
/// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
public void RequestOutNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
{
-
+
}
/// <summary>
@@ -146,7 +387,7 @@
/// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
{
-
+
}
}
}
--
Gitblit v1.9.3