From 46f0794372bb79dedfbb1d7f0a34081cf06204ce Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期五, 22 八月 2025 14:58:25 +0800
Subject: [PATCH] 增加堆垛机召回功能
---
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs | 211 +++++++++++++++++++++++++++++++++++-----------------
1 files changed, 143 insertions(+), 68 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs"
index 478a196..772c2af 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs"
@@ -2,18 +2,24 @@
using Mapster;
using Newtonsoft.Json;
using SqlSugar;
+using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
+using WIDESEA_Common.Log;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO.StackerHandTask;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_Model.BasicInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.DeviceBase;
+using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_Tasks.ConveyorLineJob;
+using WIDESEAWCS_Tasks.StackerCraneJob;
namespace WIDESEAWCS_Tasks
{
@@ -50,94 +56,163 @@
private async Task RequestTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, Dt_StationManager stationManager)
{
- var hasTask = await _taskRepository.QueryFirstAsync(x => x.SourceAddress == childDeviceCode && x.TaskState < (int)TaskInStatusEnum.RGV_InExecutingFinish && x.TaskState >= (int)TaskInStatusEnum.InNew);
- if (hasTask != null)
+ try
{
- var log = $"銆恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵hasTask.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵hasTask.PalletCode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣緭閫佺嚎瀛樺湪浠诲姟";
+ var hasTask = await _taskRepository.QueryFirstAsync(x => x.SourceAddress == childDeviceCode && x.TaskState < (int)TaskInStatusEnum.RGV_InExecutingFinish && x.TaskState >= (int)TaskInStatusEnum.InNew);
+ if (hasTask != null)
+ {
+ var log = $"銆恵conveyorLine._deviceName}銆戜换鍔″彿锛氥�恵hasTask.TaskNum}銆�,鎵樼洏鏉$爜锛氥�恵hasTask.PalletCode}銆戝凡鍒拌揪銆恵childDeviceCode}銆戣緭閫佺嚎瀛樺湪浠诲姟";
+ ConsoleHelper.WriteWarningLine(log);
+
+ await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
+ WriteInfo(conveyorLine.DeviceName, log);
+ return;
+ }
+ var RGVName = string.Empty;
+ if (stationManager.stationFloor == "1F")
+ {
+ RGVName = stationManager.RGVName;
+ }
+ else
+ {
+ RGVName = "RGV03";
+ }
+ int targetStation = 0;
+ if (childDeviceCode == "1004" || childDeviceCode == "1039" || childDeviceCode == "1040" || childDeviceCode == "1013" || childDeviceCode == "1014")
+ {
+ targetStation = 14;
+ }
+ else if (childDeviceCode == "1015" || childDeviceCode == "1016" || childDeviceCode == "1027" || childDeviceCode == "1028" || childDeviceCode == "1029" || childDeviceCode == "1030")
+ {
+ targetStation = 1;
+ }
+ else
+ {
+ targetStation = 0;
+ }
+ Dt_Task task = new Dt_Task()
+ {
+ TaskNum = _taskRepository.GetTaskNo().Result,
+ TaskType = (int)TaskInboundTypeEnum.Inbound,
+ TaskState = (int)TaskInStatusEnum.InNew,
+ SourceAddress = childDeviceCode,
+ Dispatchertime = DateTime.Now,
+ Grade = 1,
+ Creater = "System",
+ Floor = stationManager.stationFloor,
+ RGVName = RGVName,
+ SourceStation = stationManager.remark,
+ TargetStation = targetStation,
+ };
+
+ _taskRepository.AddData(task);
+ }
+ catch (Exception ex)
+ {
+ var log = $"銆恵conveyorLine._deviceName}銆戣緭閫佺嚎銆恵childDeviceCode}銆戙�恵ex.Message}銆�";
ConsoleHelper.WriteWarningLine(log);
await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
WriteInfo(conveyorLine.DeviceName, log);
- return;
}
- var RGVName = string.Empty;
- if (stationManager.stationFloor == "1F")
+
+ }
+ private void RequestWMSTask(CommonConveyorLine conveyorLine, Dt_StationManager stationManager)
+ {
+ if (stationManager.stationChildCode == "3002")
{
- var deviceCode = _deviceInfoRepository.Db.Queryable<Dt_DeviceInfo>().Where(x => x.DeviceStatus == "1" && x.DeviceRemark == "1F").Where(x => x.DeviceCode.Contains("RGV")).ToList().Select(x => x.DeviceCode).ToList();
- if (deviceCode != null && deviceCode.Count() > 0)
+
+ var newTask = _taskRepository.QueryFirst(x => x.TargetAddress == "3004");
+ if (newTask != null)
{
- if (deviceCode.Contains("RGV01") && deviceCode.Contains("RGV02"))
+ return;
+ }
+
+ DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode && x.DeviceProParamName == "ConveyorLineBarcode").FirstOrDefault();
+ var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 10);
+
+ string Barcode = Encoding.UTF8.GetString(x);
+
+ if (Barcode == null || Barcode==""|| Barcode.Trim().Contains("\0"))
+ {
+ conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode);
+ }
+ var task = _taskRepository.QueryFirst(x => x.PalletCode == Barcode && x.TaskState == (int)TaskInStatusEnum.HoistNew);
+
+ if (task != null)
+ {
+ ConveyorLineTaskCommandWrite taskCommand = new ConveyorLineTaskCommandWrite()
{
- var RGVOne = _taskRepository.QueryData(x => x.RGVName == "RGV01").ToList();
- var RGVTwo = _taskRepository.QueryData(x => x.RGVName == "RGV02").ToList();
- if (RGVOne.Count > RGVTwo.Count)
- {
- RGVName = "RGV01";
- }
- else
- {
- RGVName = "RGV02";
- }
- }
- else
+ TaskNum = Convert.ToInt16(task.TaskNum),
+ TargetAddress = Convert.ToInt16(task.NextAddress),
+ WriteInteractiveSignal = task.TaskType == (int)TaskOutboundTypeEnum.Outbound ? (byte)Convert.ToSByte(2) : (byte)Convert.ToSByte(1)
+ };
+ var result = SendCommand(taskCommand, conveyorLine, stationManager.stationChildCode);
+ if (result)
{
- RGVName = deviceCode[0];
+ task.TaskState = (int)TaskInStatusEnum.HoistInExecuting;
+ _taskRepository.UpdateData(task);
}
}
else
{
- RGVName = "RGV01";
+ var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
+ var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
+ var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTask)?.ConfigValue;
+
+ WMSTaskDTO taskDTO = new WMSTaskDTO()
+ {
+ TPbarcode = Barcode,
+ WhCode = "1001",
+ BeginPoint = stationManager.stationChildCode
+ };
+ if (wmsBase == null || requestTask == null)
+ {
+ throw new InvalidOperationException("WMS IP 鏈厤缃�");
+ }
+ var wmsIpAddress = wmsBase + requestTask;
+ var result = WIDESEA_Comm.Http.HttpHelper.PostAsync(wmsIpAddress, taskDTO.ToJsonString()).Result;
+ WriteLog.GetLog("WMS鎺ュ彛杩斿洖淇℃伅").Write(JsonConvert.SerializeObject(result), "WMS鎺ュ彛杩斿洖淇℃伅");
}
}
else
{
- RGVName = "RGV03";
- }
- Dt_Task task = new Dt_Task()
- {
- TaskNum = _taskRepository.GetTaskNo().Result,
- TaskType = (int)TaskInboundTypeEnum.Inbound,
- TaskState = (int)TaskInStatusEnum.InNew,
- SourceAddress = childDeviceCode,
- Dispatchertime = DateTime.Now,
- Grade = 1, // 璁剧疆榛樿浼樺厛绾т负1
- Creater = "System",
- Floor = stationManager.stationFloor,
- RGVName = stationManager.RGVName != null ? stationManager.RGVName : RGVName,
- };
- _taskRepository.AddData(task);
- }
- private void RequestWMSTask(CommonConveyorLine conveyorLine, Dt_StationManager stationManager)
- {
- var Barcode = conveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.ConveyorLineBarcode, stationManager.stationNextChildCode);
+ DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationNextChildCode && x.DeviceProParamName == "ConveyorLineBarcode").FirstOrDefault();
+ var x = conveyorLine.Communicator.Read(devicePro.DeviceProAddress, 10);
- if (Barcode == "")
- {
- conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal,Convert.ToSByte(3), stationManager.stationChildCode);
- }
- var task = _taskRepository.QueryFirst(x => x.PalletCode == Barcode);
- if (task != null)
- {
+ string Barcode = Encoding.UTF8.GetString(x);
- }
- else
- {
- //var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
- //var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
- //var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTask)?.ConfigValue;
- //var keys = new Dictionary<string, object>()
- //{
- // {"TPbarcode", Barcode},
- // {"WhCode", "1001"},
- // {"BeginPoint", stationManager.stationChildCode}
- //};
- //if (wmsBase == null || requestTask == null)
- //{
- // throw new InvalidOperationException("WMS IP 鏈厤缃�");
- //}
- //var wmsIpAddress = wmsBase + requestTask;
- //var result = WIDESEA_Comm.Http.HttpHelper.PostAsync(wmsIpAddress, keys.ToString()).Result;
- }
+ if (Barcode == null || Barcode == "" || Barcode.Trim().Contains("\0"))
+ {
+ conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode);
+ }
+ var task = _taskRepository.QueryFirst(x => x.PalletCode == Barcode);
+ if (task != null)
+ {
+ var log = $"銆恵conveyorLine._deviceName}銆戠珯鍙般�恵stationManager.stationChildCode}銆戣姹傚彇璐с�佸凡瀛樺湪浠诲姟浠诲姟鍙穥task.TaskNum}";
+ LogAndWarn(conveyorLine.DeviceName, log);
+ }
+ else
+ {
+ var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
+ var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
+ var requestTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTask)?.ConfigValue;
+
+ WMSTaskDTO taskDTO = new WMSTaskDTO()
+ {
+ TPbarcode = Barcode,
+ WhCode = "1001",
+ BeginPoint = stationManager.stationChildCode
+ };
+ if (wmsBase == null || requestTask == null)
+ {
+ throw new InvalidOperationException("WMS IP 鏈厤缃�");
+ }
+ var wmsIpAddress = wmsBase + requestTask;
+ var result = WIDESEA_Comm.Http.HttpHelper.PostAsync(wmsIpAddress, taskDTO.ToJsonString()).Result;
+ WriteLog.GetLog("WMS鎺ュ彛杩斿洖淇℃伅").Write(JsonConvert.SerializeObject(result), "WMS鎺ュ彛杩斿洖淇℃伅");
+ }
+ }
}
}
}
--
Gitblit v1.9.3