From 3590ec552055adb6a20fa2b6424b4326b586eecd Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <1247017146@qq.com>
Date: 星期一, 02 六月 2025 17:45:04 +0800
Subject: [PATCH] 1
---
项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs | 647 ++++++++++++++++++++++++++++++----------------------------
1 files changed, 333 insertions(+), 314 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 8caa053..0b968d9 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"
@@ -22,6 +22,13 @@
using WIDESEA_Core.BaseRepository;
using AutoMapper;
using Mapster;
+using AngleSharp.Dom;
+using Masuit.Tools.Security;
+using WIDESEA_IStorageTaskServices;
+using System.Threading.Tasks;
+using Microsoft.Extensions.DependencyInjection;
+using WIDESEA_IBusinessesRepository;
+using WIDESEA_Repository;
namespace WIDESEA_StorageSocketServices
{
@@ -42,13 +49,28 @@
private readonly IDt_Task_HtyRepository _task_HtyRepository;
private readonly IMapper _mapper;
private readonly ILocationInfoRepository _locationRepository;
+ private readonly IDt_TaskService _taskService;
+ private readonly IDt_HostLogRepository _hostLogRepository;
+ private bool _IsOnline=false;
- public SocketClientService(IDt_TaskRepository TaskRepository, IDt_StationManagerRepository stationManagerRepository, ILogger<SocketClientService> logger)
+ public SocketClientService(IDt_TaskService TaskService, IDt_TaskRepository TaskRepository, IDt_StationManagerRepository stationManagerRepository, ILogger<SocketClientService> logger, ILocationInfoRepository locationInfoRepository,IDt_HostLogRepository hostLogRepository)
{
BaseDal = TaskRepository;
_stationManagerRepository = stationManagerRepository;
_logger = logger;
+ _taskService = TaskService;
+ _locationRepository = locationInfoRepository;
+ _hostLogRepository = hostLogRepository;
+ #region
+ //if (App.RootServices != null)
+ //{
+ // IDt_TaskRepository? BaseDal = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(IDt_TaskRepository)) as IDt_TaskRepository;
+ // IDt_TaskService? _taskService = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(IDt_TaskService)) as IDt_TaskService;
+ // ILocationInfoRepository? _locationRepository = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(ILocationInfoRepository)) as ILocationInfoRepository;
+ // IDt_StationManagerRepository? _stationManagerRepository = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(IDt_StationManagerRepository)) as IDt_StationManagerRepository;
+ //}
+ #endregion
}
public void ConnectServer(string IP, int Port)
@@ -58,10 +80,10 @@
// 妫�鏌ユ槸鍚﹀凡杩炴帴锛岄伩鍏嶉噸澶嶅垱寤�
if (socket != null && socket.Connected)
{
- //Console.WriteLine("Socket宸茶繛鎺ワ紝鏃犻渶閲嶅鍒涘缓");
ConsoleHelper.WriteErrorLine($"Socket宸插浜庤繛鎺ョ姸鎬�");
return;
}
+
//鍒涘缓璐熻矗閫氫俊鐨剆ocket
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress ip = IPAddress.Parse(IP);
@@ -72,7 +94,7 @@
_logger.LogInformation("Socket杩炴帴鎴愬姛");
ConsoleHelper.WriteSuccessLine("Socket杩炴帴鎴愬姛");
-
+ _IsOnline = true;
RequestCommunication();
DeviceStateReport("I");
@@ -80,14 +102,18 @@
Thread th = new Thread(Receive);
th.IsBackground = true;
th.Start();
- ConsoleHelper.WriteErrorLine($"Socket鍚姩");
return;
}
catch (Exception ex)
{
+ _IsOnline = false;
ConsoleHelper.WriteErrorLine($"Socket杩炴帴澶辫触{ex.Message}");
HandleDisconnection();
}
+ }
+ public bool Socketonline()
+ {
+ return _IsOnline;
}
void Receive()
{
@@ -146,6 +172,7 @@
}
catch
{
+ _IsOnline = false;
HandleDisconnection();
}
@@ -160,10 +187,10 @@
ReceiveCommandResponse(x);
break;
case "906":
- AGVJobStartOrEndResponse(x.Substring(21, 1), x.Substring(22, 1));
+ AGVJobStartOrEndResponse(x.Substring(20, 1), x.Substring(21, 1));
break;
case "902":
- DataReportResponse(x.Substring(21, 1));
+ DataReportResponse(x.Substring(20, 1));
break;
case "935":
DeviceStationStatusInvite(x.Substring(15, 5));
@@ -175,7 +202,7 @@
RecreateGetLocation(x);
break;
case "108":
- RecreateGetLocation(x.Substring(21, 1));
+ EmptyOutBoundResponse(x.Substring(20, 1));
break;
case "909":
DeviceStatusReportRequest();
@@ -209,22 +236,6 @@
attempts--;
} while (!socket.Connected && attempts > 0);
}
-
- //private void CheckTimeout(object state)
- //{
- // TimeSpan elapsed = DateTime.Now - _lastActivityTime;
- // if (elapsed.TotalSeconds > 180) // 3鍒嗛挓瓒呮椂
- // {
- // Console.WriteLine("瓒呮椂鏈敹鍒版暟鎹紝瑙﹀彂909鍛戒护骞跺皾璇曢噸鏂拌繛鎺�...");
-
- // // 瑙﹀彂909鍛戒护
- // _workTaskService.DeviceStatusReportRequest();
-
- // // 灏濊瘯閲嶆柊杩炴帴
- // HandleDisconnection();
- // }
- //}
-
public void clientSend(byte[] buffer)
{
var Y = Encoding.UTF8.GetString(buffer);
@@ -264,6 +275,14 @@
/// 浼樺厛绾� 棰勭暀
/// </summary>
public const string priority = "1";
+
+ /// <summary>
+ /// 閲嶅叆搴�
+ /// </summary>
+ public const string Restocking = "2100";
+
+
+ public const string EmptyOutBoundconst = "2101";
/// <summary>
/// 鎵樼洏涓暟 棰勭暀
@@ -336,7 +355,7 @@
{
try
{
- string str = SendandReply + "101" + BaseDal.GetSeqNo().Result.ToString("D5") + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + "1" + GetFieldsAsString(inStation);
+ string str = SendandReply + "101" + BaseDal.GetSeqNo().Result.ToString("D5") + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + OutStationSpare2 + "1" + GetFieldsAsString(inStation);
clientSend(MakeStringToByteMsg(str));
}
catch (Exception ex)
@@ -478,6 +497,13 @@
try
{
string str = SendandReply + "901" + BaseDal.GetSeqNo().Result.ToString("D5") + "0" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode;
+ Dt_HostLog hostLog = new Dt_HostLog()
+ {
+ CommandID = 901,
+ Count=0,
+ Messgae=str,
+ };
+ _hostLogRepository.AddData(hostLog);
clientSend(MakeStringToByteMsg(str));
}
catch (Exception ex)
@@ -524,6 +550,13 @@
try
{
string str = SendandReply + "105" + BaseDal.GetSeqNo().Result.ToString("D5") + "R" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode;
+ Dt_HostLog hostLog = new Dt_HostLog()
+ {
+ CommandID = 105,
+ Count = 0,
+ Messgae = str,
+ };
+ _hostLogRepository.AddData(hostLog);
clientSend(MakeStringToByteMsg(str));
}
catch (Exception ex)
@@ -584,6 +617,13 @@
try
{
string str = SendandReply + "107" + BaseDal.GetSeqNo().Result.ToString("D5") + "1" + JobOrderID + priority + FormLocation + ToLocation + "O" + TrayCnt + PallteCode;
+ Dt_HostLog hostLog = new Dt_HostLog()
+ {
+ CommandID = 107,
+ Count = 0,
+ Messgae = str,
+ };
+ _hostLogRepository.AddData(hostLog);
clientSend(MakeStringToByteMsg(str));
}
catch (Exception ex)
@@ -614,25 +654,35 @@
public void ReceiveCommandResponse(string message)
{
var parseMessage = GetParse(message);
+ var lcationEnd = parseMessage.body.ToLocation;
switch (parseMessage.body.ret)
{
//OK
case "0":
- var location = _locationRepository.QueryFirst(x => x.LocationCode == parseMessage.body.ToLocation);
+ //var location = _locationRepository.QueryFirst(x => x.LocationCode == lcationEnd);
+ var location = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.ToLocation).First();
if (location == null)
{
return;
}
if (location.LocationStatus == (int)LocationEnum.Free)
{
- InsertWMSTask(parseMessage);
+ var task = InsertWMSTask(parseMessage);
Thread.Sleep(500);
+ InsertAGVTask(task);
+ location.LocationStatus = 1;
+ //SqlSugarHelper.DbWMS.Insertable(task).ExecuteCommand();
+ SqlSugarHelper.DbWMS.Updateable(location).ExecuteCommand();
+ BaseDal.AddData(task);
//915
JobReady("0");
return;
}
else
{
+ ErrorReport(Restocking, "A", "00");
+ Thread.Sleep(500);
+ RecreateGetLocation(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.JobType, parseMessage.body.TrayIdList.Substring(0, 10));
//todo璐т綅鏈夎揣閲嶅鍏ュ簱
return;
}
@@ -654,6 +704,8 @@
default:
break;
}
+
+ LogFactory.GetLog("Host102鍥炲WMS101").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(parseMessage)}{Environment.NewLine}", "");
}
/// <summary>
@@ -681,6 +733,8 @@
default:
break;
}
+
+ LogFactory.GetLog("Host906鍥炲WMS905").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(status)}{Environment.NewLine}{JsonConvert.SerializeObject(message)}{Environment.NewLine}", "");
}
/// <summary>
@@ -688,50 +742,45 @@
/// </summary>
public void DataReportResponse(string message)
{
- Dt_Task task = BaseDal.QueryFirst(x => x.TaskState == (int)TaskOutStatusEnum.AGV_OutFinish || x.TaskState == (int)TaskRelocationStatusEnum.AGV_RelocationFinish || x.TaskState == (int)TaskInStatusEnum.AGV_InFinish);
- if (task != null)
- {
- switch (task.TaskType)
- {
- case (int)TaskInboundTypeEnum.Inbound:
- //鍏ュ簱
- task.TaskState = (int)TaskInStatusEnum.AGV_InFinish;
- if (message == "0")
- {
- JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode);
- }
- CompleteInboundTask(task);
- break;
- case (int)TaskOutboundTypeEnum.Outbound:
- //鍑哄簱
- if (message == "0")
- {
- JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode);
- }
- task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish;
- CompleteOutboundTask(task);
- break;
- case (int)TaskRelocationTypeEnum.Relocation:
- if (message == "0")
- {
- JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode);
- }
- task.TaskState = (int)TaskRelocationStatusEnum.AGV_RelocationFinish;
- CompleteRelocationboundTask(task);
- break;
- case (int)TaskStationTypeEnum.StationToStation:
- if (message == "0")
- {
- JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode);
- }
- task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish;
- TaskMoveHty(task);
- break;
- default:
- break;
- }
-
- }
+ LogFactory.GetLog("Host902鍥炲WMS901").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(message)}{Environment.NewLine}", "");
+ #region
+ //Dt_Task task = BaseDal.QueryFirst(x => (x.TaskState == (int)TaskOutStatusEnum.AGV_OutFinish || x.TaskState == (int)TaskRelocationStatusEnum.AGV_RelocationFinish || x.TaskState == (int)TaskInStatusEnum.AGV_InFinish) && x.Roadway != "PDA");
+ //if (task != null)
+ //{
+ // switch (task.TaskType)
+ // {
+ // case 200:
+ // //鍏ュ簱
+ // if (message == "0")
+ // {
+ // JobStartOrEnd("E", task.Remark, task.TargetAddress, "O", task.PalletCode);
+ // }
+ // break;
+ // case 100:
+ // //鍑哄簱
+ // if (message == "0")
+ // {
+ // JobStartOrEnd("E", task.SourceAddress, task.Remark, "O", task.PalletCode);
+ // }
+ // break;
+ // case 300:
+ // if (message == "0")
+ // {
+ // JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode);
+ // }
+ // _taskService.CompleteRelocationboundTask(task);
+ // break;
+ // case 400:
+ // if (message == "0")
+ // {
+ // JobStartOrEnd("E", task.Remark, task.HostName, "O", task.PalletCode);
+ // }
+ // break;
+ // default:
+ // break;
+ // }
+ //}
+ #endregion
}
/// <summary>
/// HOST涓嬪彂鍑哄簱浠诲姟 宸ュ簭103
@@ -746,17 +795,20 @@
{
//OK
case "0":
- var location = _locationRepository.QueryFirst(x => x.LocationCode == parseMessage.body.ToLocation);
+ var location = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.FromLocation).First();
if (location == null)
{
return;
}
if (location.LocationStatus == (int)LocationEnum.InStock)
{
- var task = InsertWMSTask(parseMessage);
- BaseDal.AddData(task);
+ Dt_Task task = InsertWMSTask(parseMessage);
+ //BaseDal.AddData(task);
+ location.LocationStatus = 1;
+ SqlSugarHelper.DbWMS.Insertable(task).ExecuteCommand();
+ SqlSugarHelper.DbWMS.Updateable(location).ExecuteCommand();
InsertAGVTask(task);
- Thread.Sleep(500);
+ //Thread.Sleep(500);
//915
JobReady("0");
Thread.Sleep(500);
@@ -765,7 +817,9 @@
}
else
{
- //todo璐т綅鏃犺揣绌哄嚭搴�
+ ErrorReport(EmptyOutBoundconst, "A", "00");
+ Thread.Sleep(500);
+ EmptyOutBound(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.TrayIdList.Substring(0, 10));
return;
}
@@ -773,8 +827,10 @@
default:
break;
}
+ LogFactory.GetLog("Host103").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(parseMessage)}{Environment.NewLine}", "");
+
}
- catch (Exception)
+ catch (Exception ex)
{
DeviceReceiveJobResponse("1");
}
@@ -790,49 +846,59 @@
try
{
//鍥炲936
- List<OutStationStatus> outStationStatus = new List<OutStationStatus>();
- List<InStationStatus> inStationStatus = new List<InStationStatus>();
+
StationStatus stationIn = GetStationStatus("B002");
-
- inStationStatus.Add(new InStationStatus()
- {
- StationName = "02",
- StationEnable = stationIn.WorkstationO == "1" ? "0" : "1",
- IsDistributionTask = "0",
- PallteCode = "0000000000",
- });
- inStationStatus.Add(new InStationStatus()
- {
- StationName = "01",
- StationEnable = stationIn.WorkstationT == "1" ? "0" : "1",
- IsDistributionTask = "0",
- PallteCode = "0000000000",
- });
-
StationStatus stationOut = GetStationStatus("B001");
- var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B001::1" || x.TargetAddress == "B001::1");
- var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B001::2" || x.TargetAddress == "B001::2");
- outStationStatus.Add(new OutStationStatus()
- {
- StationName = "04",
- StationEnable = stationOut.WorkstationO == "1" ? "0" : "1",
- IsDistributionTask = taskOutStationO == null ? "0" : "1",
- Spare1 = "00"
- });
- outStationStatus.Add(new OutStationStatus()
- {
- StationName = "03",
- StationEnable = stationOut.WorkstationT == "1" ? "0" : "1",
- IsDistributionTask = taskOutStationT == null ? "0" : "1",
- Spare1 = "00"
- });
+ List<OutStationStatus> outStationStatus = GetOutStationStatus(stationOut);
+ List<InStationStatus> inStationStatus = GetInStationStatus(stationIn);
+
+ #region
+ //inStationStatus.Add(new InStationStatus()
+ //{
+ // StationName = "02",
+ // StationEnable = stationIn.WorkstationO == "1" ? "0" : "1",
+ // IsDistributionTask = "0",
+ // PallteCode = "0000000000",
+ //});
+ //inStationStatus.Add(new InStationStatus()
+ //{
+ // StationName = "01",
+ // StationEnable = stationIn.WorkstationT == "1" ? "0" : "1",
+ // IsDistributionTask = "0",
+ // PallteCode = "0000000000",
+ //});
+ //var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B001::1" || x.TargetAddress == "B001::1");
+ //var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B001::2" || x.TargetAddress == "B001::2");
+ //outStationStatus.Add(new OutStationStatus()
+ //{
+ // StationName = "04",
+ // StationEnable = stationOut.WorkstationO == "1" ? "0" : "1",
+ // IsDistributionTask = taskOutStationO == null ? "0" : "1",
+ // Spare1 = "00"
+ //});
+ //outStationStatus.Add(new OutStationStatus()
+ //{
+ // StationName = "03",
+ // StationEnable = stationOut.WorkstationT == "1" ? "0" : "1",
+ // IsDistributionTask = taskOutStationT == null ? "0" : "1",
+ // Spare1 = "00"
+ //});
+ #endregion
AGVStatusRespone status = GetAGVStatus();
HOSTAGVStatus AgvStatus = new HOSTAGVStatus()
{
RuntimeStatus = CapitalizeFirstLetter(status.RuntimeStatus),
AutoStatus = status.AutoStatus == "MaintenanceMode" ? "1" : "0",
- Ready = status.AutoStatus == "MaintenanceMode" ? "0" : "1",
+ //Ready = status.AutoStatus == "MaintenanceMode" ? "0" : "1",
};
+ if (status.RuntimeStatus == "Idle" && status.AutoStatus == "ControlMode")
+ {
+ AgvStatus.Ready = "1";
+ }
+ else
+ {
+ AgvStatus.Ready = "0";
+ }
DeviceStationStatusReport(AgvStatus, outStationStatus, inStationStatus, sSeqNo);
}
catch (Exception)
@@ -840,6 +906,7 @@
DeviceReceiveJobResponse("1");
}
+ LogFactory.GetLog("Host935").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(sSeqNo)}{Environment.NewLine}", "");
}
/// <summary>
@@ -851,12 +918,55 @@
try
{
var parseMessage = GetParse(message);
+ var lcationEnd = parseMessage.body.ToLocation;
switch (parseMessage.body.ret)
{
//OK
case "0":
- UpdateTaskLocation(parseMessage);
- break;
+ var location = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.ToLocation).First();
+ if (location == null)
+ {
+ ErrorReport("2102", "A", "00");
+ Thread.Sleep(500);
+ RecreateGetLocation(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.JobType, parseMessage.body.TrayIdList.Substring(0, 10));
+ return;
+ }
+ if (location.LocationStatus == (int)LocationEnum.Free)
+ {
+ var task = SqlSugarHelper.DbWMS.Queryable<Dt_Task>().Where(x => x.PalletCode == parseMessage.body.TrayIdList.Substring(0, 10)).First();
+ if (task == null)
+ {
+ location.LocationStatus = (int)LocationEnum.Lock;
+ var tasknew = InsertWMSTask(parseMessage);
+ InsertAGVTask(tasknew);
+ BaseDal.AddData(tasknew);
+ SqlSugarHelper.DbWMS.Updateable(location);
+ Thread.Sleep(500);
+ //915
+ JobReady("0");
+ }
+ else
+ {
+ var Agvtask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(x => x.d_involed5 == task.TaskNum.ToString()).First();
+ location.LocationStatus = (int)LocationEnum.Lock;
+ task.TargetAddress = lcationEnd;
+ Agvtask.d_involed2 = lcationEnd;
+ SqlSugarHelper.DbWMS.Updateable(task);
+ SqlSugarHelper.DbWMS.Updateable(location);
+ SqlSugarHelper.DbAGV.Updateable(Agvtask);
+ Thread.Sleep(500);
+ //915
+ JobReady("0");
+ }
+ return;
+ }
+ else
+ {
+ ErrorReport(Restocking, "A", "00");
+ Thread.Sleep(500);
+ RecreateGetLocation(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.JobType, parseMessage.body.TrayIdList.Substring(0, 10));
+ return;
+ }
//NG
case "1":
break;
@@ -868,12 +978,13 @@
default:
break;
}
+
+ LogFactory.GetLog("Host106閲嶆柊鍒嗛厤搴撲綅").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(parseMessage)}{Environment.NewLine}", "");
}
catch (Exception)
{
DeviceReceiveJobResponse("1");
}
-
}
/// <summary>
@@ -885,10 +996,10 @@
if (message != null && message == "0")
{
DeviceStateReport("I");
- Thread.Sleep(500);
+ Thread.Sleep(2000);
JobReady("1");
-
}
+ LogFactory.GetLog("Host108绌哄嚭搴撳搷搴�").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(message)}{Environment.NewLine}", "");
}
/// <summary>
@@ -902,11 +1013,21 @@
{
RuntimeStatus = CapitalizeFirstLetter(status.RuntimeStatus),
AutoStatus = status.AutoStatus == "MaintenanceMode" ? "1" : "0",
- Ready = status.AutoStatus == "MaintenanceMode" ? "0" : "1",
+
};
+ if (status.RuntimeStatus == "Idle" && status.AutoStatus == "ControlMode")
+ {
+ AgvStatus.Ready = "1";
+ }
+ else
+ {
+ AgvStatus.Ready = "0";
+ }
string axis = "000000";
DeviceStatusReportResponse(AgvStatus, axis, axis);
+
+ LogFactory.GetLog("Host蹇冭烦").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(AgvStatus)}{Environment.NewLine}{JsonConvert.SerializeObject(status)}{Environment.NewLine}", "");
}
#endregion
@@ -1013,6 +1134,49 @@
}
}
+ public List<OutStationStatus> GetOutStationStatus(StationStatus stationOut)
+ {
+ List<OutStationStatus> outStationStatus = new List<OutStationStatus>();
+ var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B001::1" || x.TargetAddress == "B001::1");
+ var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B001::2" || x.TargetAddress == "B001::2");
+ outStationStatus.Add(new OutStationStatus()
+ {
+ StationName = "04",
+ StationEnable = stationOut.WorkstationO == "1" ? "0" : "1",
+ IsDistributionTask = taskOutStationO == null ? "0" : "1",
+ Spare1 = "00"
+ });
+ outStationStatus.Add(new OutStationStatus()
+ {
+ StationName = "03",
+ StationEnable = stationOut.WorkstationT == "1" ? "0" : "1",
+ IsDistributionTask = taskOutStationT == null ? "0" : "1",
+ Spare1 = "00"
+ });
+ return outStationStatus;
+ }
+
+ public List<InStationStatus> GetInStationStatus(StationStatus stationIn)
+ {
+ List<InStationStatus> inStationStatus = new List<InStationStatus>();
+ var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B002::1" || x.TargetAddress == "B002::1");
+ var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B002::2" || x.TargetAddress == "B002::2");
+ inStationStatus.Add(new InStationStatus()
+ {
+ StationName = "02",
+ StationEnable = stationIn.WorkstationO == "1" ? "0" : "1",
+ IsDistributionTask = taskOutStationO == null ? "0" : "1",
+ PallteCode = "0000000000",
+ });
+ inStationStatus.Add(new InStationStatus()
+ {
+ StationName = "01",
+ StationEnable = stationIn.WorkstationT == "1" ? "0" : "1",
+ IsDistributionTask = taskOutStationT == null ? "0" : "1",
+ PallteCode = "0000000000",
+ });
+ return inStationStatus;
+ }
public ParseMessage SubString(string Y)
{
@@ -1053,8 +1217,6 @@
}
else
{
-
-
Console.WriteLine("鏍¢獙澶辫触锛�");
return null;
}
@@ -1073,60 +1235,74 @@
#endregion
#region 绉佹湁鏂规硶
- private void UpdateTaskLocation(ParseMessage parseMessage)
- {
- var task = BaseDal.QueryFirst(x => x.SeqNo == Convert.ToInt32(parseMessage.nSeqNo) && x.PalletCode.Contains(parseMessage.body.TrayIdList));
- if (task != null)
- {
- task.TargetAddress = parseMessage.body.ToLocation;
- task_call agvtask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(it => it.d_involed5 == task.TaskNum).First();
- BaseDal.Update(task);
- SqlSugarHelper.DbAGV.Updateable(agvtask).ExecuteCommand();
- }
-
- }
private Dt_Task InsertWMSTask(ParseMessage parseMessage)
{
- //var task = BaseDal.QueryFirst(x => x.PalletCode.Contains(parseMessage.body.TrayIdList));
int taskType = 0;
int taskState = 0;
+ Dt_Task task = new Dt_Task();
if (parseMessage.body.JobType == "I")
{
+ Dt_StationManager Instation = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.FromLocation.Substring(4, 2));
+ task.SourceAddress = Instation.stationName;
+ task.TargetAddress = parseMessage.body.ToLocation;
+ task.CurrentAddress = Instation.stationName;
+ task.NextAddress = parseMessage.body.ToLocation;
taskType = (int)TaskInboundTypeEnum.Inbound;
taskState = (int)TaskInStatusEnum.InNew;
+ task.Remark = parseMessage.body.FromLocation;
+
}
else if (parseMessage.body.JobType == "O")
{
+ task.SourceAddress = parseMessage.body.FromLocation;
+ Dt_StationManager Instation = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.ToLocation.Substring(4, 2));
+ task.TargetAddress = Instation.stationName;
+ task.CurrentAddress = parseMessage.body.FromLocation;
+ task.NextAddress = Instation.stationName;
taskType = (int)TaskOutboundTypeEnum.Outbound;
taskState = (int)TaskOutStatusEnum.OutNew;
+ task.Remark = parseMessage.body.ToLocation;
}
else if (parseMessage.body.JobType == "S")
{
+ Dt_StationManager stationone = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.FromLocation.Substring(4, 2));
+ Dt_StationManager stationtwo = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.ToLocation.Substring(4, 2));
taskType = (int)TaskStationTypeEnum.StationToStation;
taskState = (int)TaskOutStatusEnum.OutNew;
+ task.SourceAddress = stationone.stationName;
+ task.TargetAddress = stationtwo.stationName;
+ task.CurrentAddress = stationone.stationName;
+ task.NextAddress = stationtwo.stationName;
+ task.Remark = parseMessage.body.FromLocation;
+ task.HostName = parseMessage.body.ToLocation;
+ task.HostName = parseMessage.body.ToLocation;
}
else if (parseMessage.body.JobType == "R")
{
taskType = (int)TaskRelocationTypeEnum.Relocation;
taskState = (int)TaskRelocationStatusEnum.RelocationNew;
+
+ task.SourceAddress = parseMessage.body.FromLocation;
+ task.TargetAddress = parseMessage.body.ToLocation;
+ task.CurrentAddress = parseMessage.body.FromLocation;
+ task.NextAddress = parseMessage.body.ToLocation;
}
else
{
throw new Exception("鏈煡搴撲綅");
}
- return new Dt_Task()
- {
- TaskNum = BaseDal.GetTaskNo().Result,
- SourceAddress = parseMessage.body.FromLocation,
- TargetAddress = parseMessage.body.ToLocation,
- PalletCode = parseMessage.body.TrayIdList.Substring(0, 10),
- TaskType = taskType,
- TaskState = taskState,
- Dispatchertime = DateTime.Now,
- SeqNo = Convert.ToInt32(parseMessage.nSeqNo),
- CommandID = Convert.ToInt32(parseMessage.bCmdID)
- };
+
+
+ task.TaskNum = BaseDal.GetTaskNo().Result;
+ task.PalletCode = parseMessage.body.TrayIdList.Substring(0, 10);
+ task.TaskType = taskType;
+ task.TaskState = taskState;
+ task.Dispatchertime = DateTime.Now;
+ task.Grade = 1;
+ task.SeqNo = Convert.ToInt32(parseMessage.nSeqNo);
+ task.CommandID = Convert.ToInt32(parseMessage.bCmdID);
+ return task;
}
/// <summary>
@@ -1140,11 +1316,13 @@
string TargetAddress = string.Empty;
if (task.TaskType == (int)TaskInboundTypeEnum.Inbound)
{
+ SourceAddress = task.SourceAddress;
TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress);
}
else if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
{
SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress);
+ TargetAddress = task.TargetAddress;
}
else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation)
{
@@ -1158,11 +1336,11 @@
}
task_call task_Call = new task_call()
{
- d_task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? 1 : 2,
- d_floor = 1,
+ d_task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? "1" : "2",
+ d_floor = "1",
d_involed1 = SourceAddress,
d_involed2 = TargetAddress,
- d_involed5 = task.TaskNum,
+ d_involed5 = task.TaskNum.ToString(),
};
return SqlSugarHelper.DbAGV.Insertable(task_Call).ExecuteCommand();
@@ -1178,14 +1356,14 @@
nSeqNo = x.Substring(15, 5),
body = new ReceiveBody
{
- ret = x.Substring(21, 1),
- JobOrderID = x.Substring(22, 16),
- priority = x.Substring(39, 1),
- FromLocation = x.Substring(40, 6),
- ToLocation = x.Substring(47, 6),
- JobType = x.Substring(54, 1),
- TrayCnt = x.Substring(55, 1),
- TrayIdList = x.Substring(56)
+ ret = x.Substring(20, 1),
+ JobOrderID = x.Substring(21, 16),
+ priority = x.Substring(37, 1),
+ FromLocation = x.Substring(38, 6),
+ ToLocation = x.Substring(44, 6),
+ JobType = x.Substring(50, 1),
+ TrayCnt = x.Substring(51, 1),
+ TrayIdList = x.Substring(52)
},
};
}
@@ -1209,7 +1387,6 @@
{
return "";
}
-
char firstChar = s[0];
return char.ToUpper(firstChar).ToString();
}
@@ -1236,165 +1413,7 @@
return result.ToString();
}
- #region 澶栭儴鎺ュ彛鏂规硶
- public WebResponseContent CompleteInboundTask(Dt_Task task)
- {
- WebResponseContent content = new WebResponseContent();
- try
- {
- _unitOfWorkManage.BeginTran();
- var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
- locationInf.LocationStatus = (int)LocationEnum.InStock;
- var stock = new DtStockInfo()
- {
- PalletCode = task.PalletCode,
- LocationCode = task.TargetAddress,
- CreateDate = DateTime.Now,
- Creater = "system",
- LocationId = locationInf.Id,
- };
- _stockInfoRepository.AddData(stock);
- _locationRepository.UpdateData(locationInf);
- TaskMoveHty(task);
- _unitOfWorkManage.CommitTran();
- return content.OK();
- }
- catch (Exception ex)
- {
- _unitOfWorkManage.RollbackTran();
- return content.Error(ex.Message);
- }
- }
-
- public WebResponseContent CompleteOutboundTask(Dt_Task task)
- {
- WebResponseContent content = new WebResponseContent();
- try
- {
- _unitOfWorkManage.BeginTran();
- var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
- locationInf.LocationStatus = (int)LocationEnum.Free;
- var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
-
- DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>();
- stockInfo_Hty.ModifyDate = DateTime.Now;
-
- AddStockInfoHty(stockInfo_Hty);
-
- _stockInfoRepository.DeleteData(stock);
- _locationRepository.UpdateData(locationInf);
-
- TaskMoveHty(task);
-
- _unitOfWorkManage.CommitTran();
- return content.OK();
- }
- catch (Exception ex)
- {
- _unitOfWorkManage.RollbackTran();
- return content.Error(ex.Message);
- }
- }
-
- public WebResponseContent CompleteRelocationboundTask(Dt_Task task)
- {
- WebResponseContent content = new WebResponseContent();
- try
- {
- _unitOfWorkManage.BeginTran();
- var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
- var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
- locationInf.LocationStatus = (int)LocationEnum.InStock;
- location.LocationStatus = (int)LocationEnum.Free;
-
- var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
-
- stock.LocationCode = locationInf.LocationCode;
- stock.LocationId = locationInf.Id;
-
-
- _stockInfoRepository.UpdateData(stock);
- _locationRepository.UpdateData(locationInf);
- _locationRepository.UpdateData(location);
- TaskMoveHty(task);
- _unitOfWorkManage.CommitTran();
- return content.OK();
- }
- catch (Exception ex)
- {
- _unitOfWorkManage.RollbackTran();
- return content.Error(ex.Message);
- }
- }
- public WebResponseContent TaskMoveHty(Dt_Task task)
- {
- WebResponseContent content = new WebResponseContent();
- try
- {
- _unitOfWorkManage.BeginTran();
- var taskHtyNG = CreateHistoricalTask(task);
- var isTaskHtyAdd = _task_HtyRepository.AddData(taskHtyNG) > 0;
- var isTaskDelete = Delete(task.TaskId);
- var AgvTask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(x => x.d_involed5 == task.TaskNum).First();
- if (AgvTask != null)
- {
- SqlSugarHelper.DbAGV.Deleteable(AgvTask).ExecuteCommand();
- }
- _unitOfWorkManage.CommitTran();
- return content.OK();
- }
- catch (Exception ex)
- {
- _unitOfWorkManage.RollbackTran();
- return content.Error(ex.Message);
- }
- }
-
- #endregion 澶栭儴鎺ュ彛鏂规硶
-
- #region private 鍐呴儴鏂规硶
-
- /// <summary>
- /// 鍒涘缓鍘嗗彶浠诲姟璁板綍
- /// </summary>
- /// <param name="task"></param>
- /// <returns></returns>
- public Dt_Task_Hty CreateHistoricalTask(Dt_Task task, bool isHand = false)
- {
- task.CurrentAddress = task.NextAddress;
-
- // 鍒涘缓鍘嗗彶浠诲姟
- var taskHty = _mapper.Map<Dt_Task_Hty>(task);
- taskHty.FinishTime = DateTime.Now;
- taskHty.TaskId = 0;
- taskHty.OperateType = isHand ? (int)OperateTypeEnum.浜哄伐鍒犻櫎 : App.User.UserName != null ? (int)OperateTypeEnum.浜哄伐瀹屾垚 : (int)OperateTypeEnum.鑷姩瀹屾垚;
- taskHty.SourceId = task.TaskId;
- if (isHand)
- {
- taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System";
- }
- return taskHty;
- }
- /// <summary>
- /// 鍒犻櫎涓�涓换鍔�
- /// </summary>
- /// <param name="id">浠诲姟ID</param>
- /// <returns>鏄惁鍒犻櫎鎴愬姛</returns>
- public bool Delete(int id)
- {
- return BaseDal.Delete(id);
- }
- private void AddStockInfoHty(DtStockInfo_Hty dtStock)
- {
- var isStockAdd = SqlSugarHelper.DbWMS.InsertNav(dtStock).IncludesAllFirstLayer().ExecuteCommand();
- if (!isStockAdd)
- {
- throw new Exception("搴撳瓨鍘嗗彶淇℃伅娣诲姞澶辫触");
- }
- }
-
- #endregion private 鍐呴儴鏂规硶
#endregion
}
}
\ No newline at end of file
--
Gitblit v1.9.3