From 07b2fc307e6d7f8ddb4f652198f3d4856f884141 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <1247017146@qq.com>
Date: 星期三, 21 五月 2025 14:25:34 +0800
Subject: [PATCH] 1
---
项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs | 138 +++++++++++++++++++++++++++++++++-------------
1 files changed, 99 insertions(+), 39 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs"
index 898832d..43d6f4f 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs"
@@ -1,38 +1,28 @@
锘縰sing LogLibrary.Log;
using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
-using MimeKit;
using Newtonsoft.Json;
-using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
-using Org.BouncyCastle.Tls;
-using System;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Text;
using WIDESEA_Common;
using WIDESEA_Core;
-using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
-using WIDESEA_Core.Middlewares;
using WIDESEA_DTO.AGV;
using WIDESEA_DTO;
-using WIDESEA_IServices;
using WIDESEA_IStorageBasicRepository;
using WIDESEA_IStorageSocketServices;
using WIDESEA_IStorageTaskRepository;
-using WIDESEA_IStorageTaskServices;
using WIDESEA_Model.Models.AGV;
using WIDESEA_Model.Models;
using WIDESEAWCS_BasicInfoRepository;
-//using static MailKit.Telemetry;
using WIDESEAWCS_Model.Models;
-using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
using WIDESEA_Core.BaseRepository;
using AutoMapper;
using Mapster;
+using System.Threading.Tasks;
namespace WIDESEA_StorageSocketServices
{
@@ -58,8 +48,8 @@
public SocketClientService(/*IDt_TaskService taskService*/IDt_TaskRepository TaskRepository, IDt_StationManagerRepository stationManagerRepository, ILogger<SocketClientService> logger)
{
//_taskService = taskService;
- BaseDal= TaskRepository;
- _stationManagerRepository= stationManagerRepository;
+ BaseDal = TaskRepository;
+ _stationManagerRepository = stationManagerRepository;
_logger = logger;
}
@@ -153,7 +143,7 @@
}
else
{
- LogFactory.GetLog("Socket鎺ユ敹鏁版嵁").Error(true, "鏃犳晥鎶ユ枃鏍煎紡");
+ LogFactory.GetLog("Socket鎺ユ敹鏁版嵁").Error(true, "鏃犳晥鎶ユ枃鏍煎紡");
}
}
catch
@@ -172,7 +162,7 @@
ReceiveCommandResponse(x);
break;
case "906":
- AGVJobStartOrEndResponse(x.Substring(21, 1),x.Substring(22,1));
+ AGVJobStartOrEndResponse(x.Substring(21, 1), x.Substring(22, 1));
break;
case "902":
DataReportResponse(x.Substring(21, 1));
@@ -249,7 +239,7 @@
int sum = 0;
try
{
- for (int i = 0; i < x.Length-2; i++)
+ for (int i = 0; i < x.Length - 2; i++)
{
sum += x[i];
}
@@ -626,12 +616,24 @@
{
//OK
case "0":
- //UpdateTaskLocation(parseMessage);
- InsertWMSTask(parseMessage);
- Thread.Sleep(500);
- //915
- JobReady("0");
- break;
+ var location = _locationRepository.QueryFirst(x => x.LocationCode == parseMessage.body.ToLocation);
+ if (location == null)
+ {
+ return;
+ }
+ if (location.LocationStatus == (int)LocationEnum.Free)
+ {
+ InsertWMSTask(parseMessage);
+ Thread.Sleep(500);
+ //915
+ JobReady("0");
+ return;
+ }
+ else
+ {
+ //todo璐т綅鏈夎揣閲嶅鍏ュ簱
+ return;
+ }
//NG
case "1":
break;
@@ -696,7 +698,7 @@
{
JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode);
}
- CompleteInboundTask(task);
+ CompleteInboundTask(task);
break;
case (int)TaskOutboundTypeEnum.Outbound:
//鍑哄簱
@@ -742,15 +744,29 @@
{
//OK
case "0":
- var task = InsertWMSTask(parseMessage);
- BaseDal.AddData(task);
- InsertAGVTask(task);
- Thread.Sleep(500);
- //915
- JobReady("0");
- Thread.Sleep(500);
- //104
- DeviceReceiveJobResponse("0");
+ var location = _locationRepository.QueryFirst(x => x.LocationCode == parseMessage.body.ToLocation);
+ if (location == null)
+ {
+ return;
+ }
+ if (location.LocationStatus == (int)LocationEnum.InStock)
+ {
+ var task = InsertWMSTask(parseMessage);
+ BaseDal.AddData(task);
+ InsertAGVTask(task);
+ Thread.Sleep(500);
+ //915
+ JobReady("0");
+ Thread.Sleep(500);
+ //104
+ DeviceReceiveJobResponse("0");
+ }
+ else
+ {
+ //todo璐т綅鏃犺揣绌哄嚭搴�
+ return;
+ }
+
break;
default:
break;
@@ -792,7 +808,7 @@
var taskStation = BaseDal.QueryFirst(x => x.SourceAddress == item.stationName || x.TargetAddress == item.stationName);
outStationStatus.Add(new OutStationStatus()
{
- StationName = item.stationName,
+ StationName = item.HostName,
StationEnable = station.StationEnable == "1" ? "0" : "1",
IsDistributionTask = taskStation == null ? "0" : "1",
Spare1 = "00"
@@ -875,11 +891,13 @@
/// </summary>
public void DeviceStatusReportRequest()
{
+ AGVStatusRespone status = GetAGVStatus();
+
HOSTAGVStatus AgvStatus = new HOSTAGVStatus()
{
- RuntimeStatus = "R",
- AutoStatus = "1",
- Ready = "1"
+ RuntimeStatus = CapitalizeFirstLetter(status.RuntimeStatus),
+ AutoStatus = status.AutoStatus == "MaintenanceMode" ? "1" : "0",
+ Ready = status.AutoStatus == "MaintenanceMode" ? "0" : "1",
};
string axis = "000000";
DeviceStatusReportResponse(AgvStatus, axis, axis);
@@ -1113,12 +1131,32 @@
/// <returns></returns>
private int InsertAGVTask(Dt_Task task)
{
+ string SourceAddress = string.Empty;
+ string TargetAddress = string.Empty;
+ if (task.TaskType == (int)TaskInboundTypeEnum.Inbound)
+ {
+ TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress);
+ }
+ else if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
+ {
+ SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress);
+ }
+ else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation)
+ {
+ TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress);
+ SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress);
+ }
+ else if (task.TaskType == (int)TaskStationTypeEnum.StationToStation)
+ {
+ TargetAddress = task.TargetAddress;
+ SourceAddress = task.SourceAddress;
+ }
task_call task_Call = new task_call()
{
d_task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? 1 : 2,
d_floor = 1,
- d_involed1 = task.SourceAddress,
- d_involed2 = task.TargetAddress,
+ d_involed1 = SourceAddress,
+ d_involed2 = TargetAddress,
d_involed5 = task.TaskNum,
};
@@ -1156,7 +1194,7 @@
public StationStatus GetStationStatus(string stationName)
{
- string urlnew = url + "/ilns/strl/getStat";
+ string urlnew = url + "/ilns/strl/getState";
var result = HttpsClient.PostAsync(urlnew, JsonConvert.DeserializeObject<Dictionary<string, object>>(new { strlName = stationName }.ToJson())).Result;
return JsonConvert.DeserializeObject<StationStatus>(result.ToString());
}
@@ -1170,7 +1208,29 @@
char firstChar = s[0];
return char.ToUpper(firstChar).ToString();
}
+ public string InsertHyphenEveryTwoChars(string input)
+ {
+ if (string.IsNullOrEmpty(input))
+ {
+ return input;
+ }
+ StringBuilder result = new StringBuilder();
+
+ for (int i = 0; i < input.Length; i += 2)
+ {
+ // 娣诲姞涓や釜瀛楃
+ result.Append(input.Substring(i, 2));
+
+ // 濡傛灉涓嶆槸鏈�鍚庝袱涓瓧绗︼紝娣诲姞涓�涓繛瀛楃
+ if (i + 2 < input.Length)
+ {
+ result.Append('-');
+ }
+ }
+
+ return result.ToString();
+ }
#region 澶栭儴鎺ュ彛鏂规硶
public WebResponseContent CompleteInboundTask(Dt_Task task)
--
Gitblit v1.9.3