From cebd0800e9b5e1a1055a48d5e52f3f8a85e8d82c Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期一, 13 一月 2025 20:59:26 +0800 Subject: [PATCH] 1 --- 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/板材仓/ConveyorLineJob_BC.cs | 234 ++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 130 insertions(+), 104 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\235\277\346\235\220\344\273\223/ConveyorLineJob_BC.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\235\277\346\235\220\344\273\223/ConveyorLineJob_BC.cs" index 8ac14fc..9c98f0c 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\235\277\346\235\220\344\273\223/ConveyorLineJob_BC.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/\346\235\277\346\235\220\344\273\223/ConveyorLineJob_BC.cs" @@ -1,4 +1,6 @@ -锘縰sing Quartz; +锘縰sing Newtonsoft.Json; +using Quartz; +using SqlSugar; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +11,7 @@ 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; @@ -19,14 +22,16 @@ using WIDESEAWCS_QuartzJob.Models; using WIDESEAWCS_QuartzJob.Repository; using WIDESEAWCS_QuartzJob.Service; +using WIDESEAWCS_TaskInfoService; using WIDESEAWCS_Tasks.ConveyorLineJob; +using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; namespace WIDESEAWCS_Tasks { [DisallowConcurrentExecution] public class ConveyorLineJob_BC : JobBase, IJob { - + private readonly ICacheService _cacheService; private readonly ITaskService _taskService; private readonly ITaskExecuteDetailService _taskExecuteDetailService; private readonly ITaskRepository _taskRepository; @@ -34,9 +39,11 @@ private readonly IRouterRepository _routerRepository; private readonly IRouterService _routerService; private readonly IRouterExtension _routerExtension; + private readonly List<Dt_WarehouseDevice> warehouseDevices; - public ConveyorLineJob_BC(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension) + public ConveyorLineJob_BC(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension) { + _cacheService = cacheService; _taskService = taskService; _taskExecuteDetailService = taskExecuteDetailService; _taskRepository = taskRepository; @@ -44,6 +51,16 @@ _routerRepository = routerRepository; _routerService = routerService; _routerExtension = routerExtension; + + 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) @@ -52,6 +69,12 @@ if (flag && value != null) { OtherDevice device = (OtherDevice)value; + Dt_WarehouseDevice? warehouseDevice = warehouseDevices.FirstOrDefault(x => x.DeviceCode == device.DeviceCode); + if (warehouseDevice == null) + { + WriteError(device.DeviceName, $"璇烽厤缃粨搴撹澶囦俊鎭�"); + return Task.CompletedTask; + } List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).ToList(); List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode); foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode))) @@ -78,18 +101,40 @@ if (item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt()) { + { + #region 鐢熸垚浠诲姟鍚庣粰杈撻�佺嚎鍚姩淇″彿 + Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) /*&& x.DeviceCode == item.StationDeviceCode*/ && (x.TaskState == TaskStatusEnum.New.ObjToInt()) && x.WarehouseId == warehouseDevice.WarehouseId); + if (task != null && conveyorLineInfoWrite.Spare2 == 0) + { + List<string> stations = _routerExtension.GetEndPoint(item.StationCode, TaskTypeEnum.Inbound.ObjToInt()).Select(x => x.NextPosi).ToList(); + WebResponseContent responseContent = _taskService.RequestWMSAssignRoadway(stations, task.TaskNum, conveyorLineInfoRead.Spare2); + if (responseContent.Status) + { + device.SetValue(W_ConveyorLineDB.Spare2, 1, item.StationCode); + _taskService.UpdateTask(task, TaskStatusEnum.Line_Execute, deviceCode: item.StationDeviceCode, roadwayNo: responseContent.Data.ToString() ?? ""); + } + } + #endregion + } + if (conveyorLineSignalRead.STB && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !conveyorLineSignalWrite.ACK) { if (conveyorLineInfoRead.TaskNum == 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.Barcode))//閲囪喘鍏ュ簱 { - Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.DeviceCode == item.StationDeviceCode && (x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() || x.TaskState == TaskStatusEnum.New.ObjToInt())); + #region 浠诲姟鍙蜂负0锛屼笖鏈夋墭鐩樺彿锛屽垯鏄噰璐叆搴� + Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.DeviceCode == item.StationDeviceCode && (x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt()) && x.PalletCode == conveyorLineInfoRead.Barcode && x.WarehouseId == warehouseDevice.WarehouseId); if (task != null) { + device.SetValue(W_ConveyorLineDB.Spare2, 0, item.StationCode); + string currentAddress = task.CurrentAddress; string nextAddress = task.NextAddress; + string targetAddress = task.TargetAddress; + string deviceCode = task.DeviceCode; TaskStatusEnum taskState = TaskStatusEnum.Line_Executing; List<Dt_Router> routers = _routerService.QueryNextRoutes(item.StationCode, task.Roadway, task.TaskType); - if (routers == null || routers.Count == 0) + Dt_Router? router = routers.FirstOrDefault(); + if (routers == null || routers.Count == 0 || router == null) { WriteError(item.StationName, $"鏈壘鍒板搴旇矾鐢变俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}"); continue; @@ -99,13 +144,24 @@ WriteError(item.StationName, $"璺敱淇℃伅閰嶇疆閿欒,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}"); continue; } - Dt_Router router = routers.FirstOrDefault(); + if (router.IsEnd) { - currentAddress = item.StackerCraneStationCode; - nextAddress = task.TargetAddress; - taskState = TaskStatusEnum.SC_Execute; - device.SetValue(W_ConveyorLineDB.EndPos, task.CurrentAddress, item.StationCode); + string? targetLoca = _taskService.RequestAssignLocationByHeight(task.TaskNum, task.Roadway, conveyorLineInfoRead.Spare2); + if (!string.IsNullOrEmpty(targetLoca)) + { + currentAddress = item.StackerCraneStationCode; + targetAddress = targetLoca; + nextAddress = targetLoca; + taskState = TaskStatusEnum.SC_Execute; + deviceCode = item.StackerCraneCode; + device.SetValue(W_ConveyorLineDB.EndPos, task.CurrentAddress, item.StationCode); + } + else + { + WriteError(item.StationName, $"璇锋眰鍒嗛厤璐т綅澶辫触,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}"); + continue; + } } else { @@ -115,95 +171,65 @@ device.SetValue(W_ConveyorLineDB.StartPos, task.CurrentAddress, item.StationCode); device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode); device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode); - _taskService.UpdateTask(task, taskState, currentAddress: currentAddress, nextAddress: nextAddress); + _taskService.UpdateTask(task, taskState, currentAddress: currentAddress, nextAddress: nextAddress, targetAddress: targetAddress, deviceCode: deviceCode); } - else - { - List<Dt_Router> routers = _routerExtension.GetEndPoint(item.StationCode, TaskTypeEnum.Inbound.ObjToInt()); - - List<string> stations = routers.Select(x => x.NextPosi).ToList(); - - WebResponseContent responseContent = _taskService.RequestWMSAssignRoadway(stations); - if (responseContent.Status) - { - WebResponseContent content = _taskService.RequestWMSTask(conveyorLineInfoRead.Barcode, item.StationCode, responseContent.Data.ToString()); - if (content.Status) - { - task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.DeviceCode == item.StationDeviceCode && (x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() || x.TaskState == TaskStatusEnum.New.ObjToInt())); - if (task != null) - { - Dt_Router router = _routerRepository.QueryFirst(x => x.InOutType == task.TaskType && x.StartPosi == item.StationCode); - if (router == null) - { - WriteError(item.StationName, $"鏈壘鍒板搴旇矾鐢变俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}"); - continue; - } - string currentAddress = task.CurrentAddress; - string nextAddress = task.NextAddress; - TaskStatusEnum taskState = TaskStatusEnum.Line_Executing; - - device.SetValue(W_ConveyorLineDB.TaskNum, task.TaskNum, item.StationCode); - device.SetValue(W_ConveyorLineDB.StartPos, task.CurrentAddress, item.StationCode); - if (router.NextPosi != task.NextAddress) - { - currentAddress = item.StackerCraneStationCode; - nextAddress = task.TargetAddress; - taskState = TaskStatusEnum.SC_Execute; - device.SetValue(W_ConveyorLineDB.EndPos, task.CurrentAddress, item.StationCode); - } - else - { - device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress, item.StationCode); - } - - device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode); - device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode); - _taskService.UpdateTask(task, taskState, currentAddress: currentAddress, nextAddress: nextAddress); - //continue; - - //_taskService.UpdateTask(task, TaskStatusEnum.Line_Executing); - - //device.SetValue(W_ConveyorLineDB.TaskNum, task.TaskNum, item.StationCode); - //device.SetValue(W_ConveyorLineDB.StartPos, task.CurrentAddress, item.StationCode); - //device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress, item.StationCode); - //device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode); - //device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode); - } - } - } - } - + #endregion } else//鐢熶骇閫�搴� { - Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNum && x.NextAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType)); // 甯︿换鍔″彿鏌ヨ浠诲姟 + #region 鐢熶骇閫�搴�,甯︿换鍔″彿鏌ヨ浠诲姟 + Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNum && x.NextAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.WarehouseId == warehouseDevice.WarehouseId); // 甯︿换鍔″彿鏌ヨ浠诲姟 if (task != null) { - Dt_Router router = _routerRepository.QueryFirst(x => x.InOutType == task.TaskType && x.StartPosi == item.StationCode); - if (router == null) + List<string> stations = _routerExtension.GetEndPoint(item.StationCode, TaskTypeEnum.Inbound.ObjToInt()).Select(x => x.NextPosi).ToList(); + WebResponseContent responseContent = _taskService.RequestWMSAssignRoadway(stations, task.TaskNum, conveyorLineInfoRead.Spare2); + if (responseContent.Status) { - WriteError(item.StationName, $"鏈壘鍒板搴旇矾鐢变俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}"); - continue; + string currentAddress = task.CurrentAddress; + string nextAddress = task.NextAddress; + string targetAddress = task.TargetAddress; + TaskStatusEnum taskState = TaskStatusEnum.Line_Executing; + List<Dt_Router> routers = _routerService.QueryNextRoutes(item.StationCode, task.Roadway, task.TaskType); + Dt_Router? router = routers.FirstOrDefault(); + if (routers == null || routers.Count == 0 || router == null) + { + WriteError(item.StationName, $"鏈壘鍒板搴旇矾鐢变俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}"); + continue; + } + if (routers.Count > 1) + { + WriteError(item.StationName, $"璺敱淇℃伅閰嶇疆閿欒,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}"); + continue; + } + + if (router.IsEnd) + { + string? targetLoca = _taskService.RequestAssignLocationByHeight(task.TaskNum, task.Roadway, conveyorLineInfoRead.Spare2); + if (!string.IsNullOrEmpty(targetLoca)) + { + currentAddress = item.StackerCraneStationCode; + nextAddress = targetAddress; + taskState = TaskStatusEnum.SC_Execute; + targetAddress = targetLoca; + device.SetValue(W_ConveyorLineDB.EndPos, task.CurrentAddress, item.StationCode); + } + else + { + WriteError(item.StationName, $"璇锋眰鍒嗛厤璐т綅澶辫触,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}"); + continue; + } + } + else + { + device.SetValue(W_ConveyorLineDB.EndPos, task.NextAddress, item.StationCode); + } + device.SetValue(W_ConveyorLineDB.TaskNum, task.TaskNum, item.StationCode); + device.SetValue(W_ConveyorLineDB.StartPos, task.CurrentAddress, item.StationCode); + device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode); + device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode); + _taskService.UpdateTask(task, taskState, currentAddress: currentAddress, nextAddress: nextAddress, targetAddress: targetAddress); } - - Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.StationCode == item.StationCode); - if (stationManger == null) - { - WriteError(item.StationName, $"鏈壘鍒板搴旂珯鍙颁俊鎭�,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}"); - continue; - } - - string? locationCode = _taskService.RequestAssignLocation(task.TaskNum, router.NextPosi); - if (string.IsNullOrEmpty(locationCode)) - { - WriteError(item.StationName, $"璇锋眰鍒嗛厤璐т綅杩斿洖淇℃伅閿欒,璁惧缂栧彿:{item.StationCode},浠诲姟鍙�:{task.TaskNum}"); - continue; - } - - _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, deviceCode: stationManger.StackerCraneCode, targetAddress: locationCode, currentAddress: stationManger.StackerCraneStationCode, nextAddress: locationCode); - - device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Inbound.ObjToInt(), item.StationCode); - device.SetValue(W_ConveyorLineDB.ACK, true, item.StationCode); + #endregion } } } @@ -213,7 +239,7 @@ } else if (!conveyorLineSignalRead.STB && !conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && !conveyorLineSignalWrite.STB && !conveyorLineSignalWrite.ACK && conveyorLineInfoRead.TaskNum == 0)//鍑哄簱 { - Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.DeviceCode == item.StationDeviceCode && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt()); + Dt_Task task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskOutboundTypes.Contains(x.TaskType) && x.DeviceCode == item.StationDeviceCode && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() && x.WarehouseId == warehouseDevice.WarehouseId); if (task != null) { _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing); @@ -224,18 +250,18 @@ device.SetValue(W_ConveyorLineDB.Spare1, ConveyorWorkTypeEnum.Outbound.ObjToInt(), item.StationCode); device.SetValue(W_ConveyorLineDB.STB, true, item.StationCode); } - else - { - task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && string.IsNullOrEmpty(x.DeviceCode) && x.TaskState == TaskStatusEnum.New.ObjToInt()); - if (task != null) - { - Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.CurrentAddress); - if (stationManger != null) - { - _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, deviceCode: stationManger.StackerCraneCode, currentAddress: stationManger.StackerCraneStationCode, nextAddress: task.TargetAddress); - } - } - } + //else + //{ + // task = _taskRepository.QueryFirst(x => x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && string.IsNullOrEmpty(x.DeviceCode) && x.TaskState == TaskStatusEnum.New.ObjToInt() && x.WarehouseId == warehouseDevice.WarehouseId); + // if (task != null) + // { + // Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.CurrentAddress); + // if (stationManger != null) + // { + // _taskService.UpdateTask(task, TaskStatusEnum.SC_Execute, deviceCode: stationManger.StackerCraneCode, currentAddress: stationManger.StackerCraneStationCode, nextAddress: task.TargetAddress); + // } + // } + //} } else if (!conveyorLineSignalRead.STB && conveyorLineSignalRead.ACK && conveyorLineStatus.Online && conveyorLineStatus.Goods && !conveyorLineStatus.Alarm && conveyorLineSignalWrite.STB && !conveyorLineSignalWrite.ACK) { -- Gitblit v1.9.3