From a9edf162ac5dd98719c2f93ab0800c98673fd220 Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期三, 01 四月 2026 16:14:49 +0800
Subject: [PATCH] fix: 修复AGV任务下发,修改找空闲为深度优先等
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_AGV.cs | 142 ++++++++++++++++++++++++++++++++++-------------
1 files changed, 103 insertions(+), 39 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_AGV.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_AGV.cs
index 3e77721..6425d1b 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_AGV.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_AGV.cs
@@ -14,13 +14,12 @@
{
public partial class TaskService
{
- #region 鏋佸嵎搴撲换鍔℃ā鍧�
public string AGV_OutTaskComplete = WIDESEA_Core.Helper.AppSettings.Configuration["AGV_OutTaskComplete"];
public string WCS_ReceiveTask = WIDESEA_Core.Helper.AppSettings.Configuration["WCS_ReceiveTask"];
/// <summary>
- /// 鍑哄叆搴撶敵璇枫��
+ /// 鏋佸嵎搴撳嚭鍏ュ簱鐢宠
/// </summary>
public async Task<AGVResponse> ApplyInOutAsync(ApplyInOutDto applyInOutDto)
{
@@ -32,7 +31,7 @@
if (validationMessage != null)
return response.Error(validationMessage);
- var existingTask = await BaseDal.QueryFirstAsync(x => x.PalletCode == applyInOutDto.TrayNumber);
+ var existingTask = await BaseDal.QueryFirstAsync(x => x.PalletCode == applyInOutDto.TrayNumber || x.OrderNo == applyInOutDto.TaskId);
if (existingTask != null)
return response.Error($"WMS宸叉湁褰撳墠浠诲姟锛屼笉鍙噸澶嶄笅鍙戯紝浠诲姟鍙凤細{applyInOutDto.TaskId}");
@@ -61,7 +60,7 @@
}
/// <summary>
- /// 鎵嬪姩鍑哄簱瀹屾垚鍙嶉缁橝GV銆�
+ /// 鎵嬪姩鍑哄簱瀹屾垚鍙嶉缁橝GV
/// </summary>
public async Task<WebResponseContent> OutTaskComplete(OutTaskCompleteDto outTaskCompleteDto)
{
@@ -83,7 +82,7 @@
return response.Error(httpResponse?.Msg ?? "AGV鎺ュ彛璋冪敤寮傚父");
if (!httpResponse.Code)
- return response.Error(string.IsNullOrWhiteSpace(httpResponse.Msg) ? "AGV鎺ュ彛璋冪敤澶辫触" : httpResponse.Msg);
+ return response.Error(string.IsNullOrWhiteSpace(httpResponse.Msg) ? "AGV鎺ュ彛璋冪敤澶辫触" : httpResponse.Msg);
var syncResult = await CompleteLocalOutboundAfterAgvAckAsync(task);
return syncResult.Status ? response.OK(httpResponse.Msg) : syncResult;
@@ -96,7 +95,7 @@
}
/// <summary>
- /// 杈撻�佺嚎鐢宠杩涘叆銆�
+ /// 杈撻�佺嚎鐢宠杩涘叆
/// </summary>
public async Task<AGVResponse> ApplyEnterAsync(ApplyEnterDto applyEnterDto)
{
@@ -124,7 +123,7 @@
}
/// <summary>
- /// 鍙栨斁璐у畬鎴愩��
+ /// 鍙栨斁璐у畬鎴�
/// </summary>
public async Task<AGVResponse> TaskCompleteAsync(TaskCompleteDto taskCompleteDto)
{
@@ -152,7 +151,7 @@
}
/// <summary>
- /// 浠诲姟鍙栨秷銆�
+ /// 浠诲姟鍙栨秷
/// </summary>
public async Task<AGVResponse> TaskCancelAsync(TaskCancelDto taskCancelDto)
{
@@ -183,6 +182,7 @@
}
}
+ #region 鍙傛暟楠岃瘉
private static string? ValidateApplyInOutRequest(ApplyInOutDto dto)
{
if (dto == null) return "璇锋眰鍙傛暟涓嶈兘涓虹┖";
@@ -231,7 +231,10 @@
if (string.IsNullOrWhiteSpace(dto.TaskId)) return "浠诲姟鍙蜂笉鑳戒负绌�";
return null;
}
+ #endregion 鍙傛暟楠岃瘉
+ #region 鍏蜂綋瀹炵幇
+ // 鍑哄叆搴撳叡鐢ㄥ垱寤轰换鍔�
private Dt_Task BuildAgvTask(ApplyInOutDto dto)
{
var task = new Dt_Task
@@ -265,6 +268,7 @@
return task;
}
+ // 鏋勫缓杩斿洖AGV鍑哄叆搴撹姹備綋
private AGVDataDto BuildAgvDataDto(Dt_Task task, ApplyInOutDto dto)
{
return new AGVDataDto
@@ -287,6 +291,7 @@
};
}
+ // 鍏ュ簱鍒涘缓
private async Task<AGVResponse?> CreateAgvInboundTaskAsync(Dt_Task task, ApplyInOutDto dto)
{
AGVResponse response = new AGVResponse();
@@ -302,6 +307,7 @@
return addResult ? null : response.Error("鍏ュ簱浠诲姟鍒涘缓澶辫触");
}
+ // 鍑哄簱鍒涘缓
private async Task<AGVResponse?> CreateAgvOutboundTaskAsync(Dt_Task task, ApplyInOutDto dto)
{
AGVResponse response = new AGVResponse();
@@ -309,13 +315,13 @@
if (stockInfo == null)
return response.Error($"鏈壘鍒版墭鐩榹dto.TrayNumber}鐨勫簱瀛樹俊鎭�");
- if (stockInfo.WarehouseId != dto.YinYang)
- return response.Error($"鎵樼洏{dto.TrayNumber}涓嶅睘浜庡綋鍓峽(dto.YinYang == 1 ? "闃存瀬" : "闃虫瀬")}");
+ //if (stockInfo.WarehouseId != dto.YinYang)
+ // return response.Error($"鎵樼洏{dto.TrayNumber}涓嶅睘浜庡綋鍓峽(dto.YinYang == 1 ? "闃存瀬" : "闃虫瀬")}");
if (stockInfo.StockStatus != (int)StockStatusEmun.鍏ュ簱瀹屾垚)
return response.Error($"鎵樼洏{dto.TrayNumber}姝e湪绉诲姩涓紝璇风◢鍚庯紒");
- var locationInfo = await _locationInfoService.GetLocationInfoAsync(stockInfo.LocationCode);
+ var locationInfo = await _locationInfoService.GetLocationInfo(stockInfo.LocationCode);
if (locationInfo == null)
return response.Error($"鏈壘鍒版墭鐩榹stockInfo.LocationCode}鐨勮揣浣嶄俊鎭�");
@@ -327,6 +333,14 @@
task.SourceAddress = stockInfo.LocationCode;
task.CurrentAddress = stockInfo.LocationCode;
task.TargetAddress = dto.YinYang == 1 ? "D10020" : "D10090";
+
+ var wmsTaskDto = _mapper.Map<WMSTaskDTO>(task);
+ var taskList = new List<WMSTaskDTO> { wmsTaskDto };
+ var requestBody = JsonSerializer.Serialize(taskList);
+
+ var httpResponse = _httpClientHelper.Post<WebResponseContent>(WCS_ReceiveTask, requestBody);
+ if (httpResponse == null || httpResponse.Data == null || !httpResponse.Data.Status)
+ return response.Error(httpResponse?.Data?.Message ?? "涓嬪彂WCS澶辫触");
stockInfo.StockStatus = (int)StockStatusEmun.鍑哄簱閿佸畾;
locationInfo.LocationStatus = (int)LocationStatusEnum.InStockLock;
@@ -340,34 +354,22 @@
_unitOfWorkManage.RollbackTran();
return response.Error("鍑哄簱浠诲姟鍒涘缓澶辫触");
}
-
_unitOfWorkManage.CommitTran();
+
+
return null;
}
private async Task<WebResponseContent> CompleteLocalOutboundAfterAgvAckAsync(Dt_Task task)
{
- var stockInfo = await _stockInfoService.GetStockInfoAsync(task.PalletCode);
- if (stockInfo == null)
- return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩榹task.PalletCode}鐨勫簱瀛樹俊鎭�");
-
- var locationInfo = await _locationInfoService.GetLocationInfoAsync(stockInfo.LocationCode);
- if (locationInfo == null)
- return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩榹stockInfo.LocationCode}鐨勮揣浣嶄俊鎭�");
-
- if (stockInfo.StockStatus != (int)StockStatusEmun.鍑哄簱閿佸畾 || locationInfo.LocationStatus != (int)LocationStatusEnum.InStockLock)
- return WebResponseContent.Instance.Error($"褰撳墠搴撳瓨{stockInfo.StockStatus}鎴栬�呰揣浣峽locationInfo.LocationStatus}鐘舵�佷俊鎭敊璇�");
-
- locationInfo.LocationStatus = (int)LocationStatusEnum.Free;
+ task.TaskStatus = (int)TaskOutStatusEnum.Line_OutFinish;
_unitOfWorkManage.BeginTran();
- var deleteTaskResult = BaseDal.DeleteData(task);
- var updateLocationResult = _locationInfoService.UpdateData(locationInfo);
- var deleteStockResult = _stockInfoService.DeleteData(stockInfo);
- if (!deleteTaskResult || !updateLocationResult.Status || !deleteStockResult.Status)
+ var updateResult = BaseDal.UpdateData(task);
+ if (!updateResult)
{
_unitOfWorkManage.RollbackTran();
- return WebResponseContent.Instance.Error("AGV瀹屾垚鍥炰紶鍚庯紝鏈湴浠诲姟/搴撳瓨/璐т綅鏇存柊澶辫触");
+ return WebResponseContent.Instance.Error("AGV瀹屾垚鍥炰紶鍚庯紝浠诲姟鏇存柊澶辫触");
}
_unitOfWorkManage.CommitTran();
@@ -376,11 +378,62 @@
private bool CanApplyEnter(Dt_Task task, ApplyEnterDto dto)
{
- return dto.InOut == 1
- ? task.TaskType == (int)TaskInboundTypeEnum.Inbound && task.TaskStatus == (int)TaskInStatusEnum.InNew
- : task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TaskStatus == (int)TaskStatusEnum.Line_Finish;
+ if (dto.InOut == 1)
+ {
+ var hasExecutingOutTask = BaseDal.QueryFirst(x => x.TaskType == (int)TaskOutboundTypeEnum.Outbound
+ && x.TargetAddress == task.SourceAddress
+ && (x.TaskStatus == (int)TaskOutStatusEnum.SC_OutExecuting
+ || x.TaskStatus == (int)TaskOutStatusEnum.Line_OutExecuting));
+
+ // 濡傛灉娌℃湁姝e湪鎵ц鐨勫嚭搴撲换鍔★紝鍒欏厑璁稿叆搴�
+ return hasExecutingOutTask == null;
+ }
+ else
+ {
+ return task.TaskType == (int)TaskOutboundTypeEnum.Outbound
+ && task.TaskStatus == (int)TaskStatusEnum.Line_Finish;
+ }
}
+ // WCS鍏ュ簱瀹屾垚
+ private async Task<WebResponseContent> CompleteAgvInboundTaskAsync(CreateTaskDto taskDto)
+ {
+ WebResponseContent response = new WebResponseContent();
+ var task = await BaseDal.QueryFirstAsync(x => x.PalletType == taskDto.PalletType);
+ if (task == null)
+ return response.Error($"娌℃湁褰撳墠鎵樼洏{taskDto.PalletType}鍏ュ簱浠诲姟");
+
+ var stockInfo = await _stockInfoService.GetStockInfoAsync(task.PalletCode);
+ if (stockInfo == null)
+ return response.Error($"鏈壘鍒版墭鐩榹task.PalletCode}鐨勫簱瀛樹俊鎭�");
+
+ var locationInfo = await _locationInfoService.GetLocationInfoAsync(task.TargetAddress);
+ if (locationInfo == null)
+ return response.Error($"鏈壘鍒拌揣浣峽task.TargetAddress}鐨勪俊鎭�");
+
+ if (locationInfo.LocationStatus == (int)LocationStatusEnum.InStock)
+ return response.Error($"褰撳墠璐т綅{locationInfo.LocationStatus}鐘舵�佷笉鏄┖闂茬姸鎬侊紝鏃犳硶鍏ュ簱");
+
+ // 鏇存柊璐т綅鐘舵�佷负鍗犵敤
+ locationInfo.LocationStatus = (int)LocationStatusEnum.InStock;
+ task.TaskStatus = (int)TaskInStatusEnum.InFinish;
+ stockInfo.StockStatus = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
+ _unitOfWorkManage.BeginTran();
+ var addStockResult = _stockInfoService.UpdateData(stockInfo);
+ var updateLocationResult = _locationInfoService.UpdateData(locationInfo);
+ BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
+
+ if (!addStockResult.Status || !updateLocationResult.Status)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return response.Error("鍏ュ簱瀹屾垚鍚庯紝娣诲姞搴撳瓨鎴栬揣浣嶆洿鏂板け璐�");
+ }
+
+ _unitOfWorkManage.CommitTran();
+ return response.OK();
+ }
+
+ // AGV鍑哄簱瀹屾垚
private async Task<AGVResponse> CompleteAgvOutboundTaskAsync(Dt_Task task)
{
AGVResponse response = new AGVResponse();
@@ -400,9 +453,9 @@
_unitOfWorkManage.BeginTran();
var deleteStockResult = _stockInfoService.DeleteData(stockInfo);
- var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(locationInfo);
+ var updateLocationResult = _locationInfoService.UpdateData(locationInfo);
BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.鑷姩瀹屾垚 : OperateTypeEnum.浜哄伐瀹屾垚);
- if (!deleteStockResult.Status || !updateLocationResult)
+ if (!deleteStockResult.Status || !updateLocationResult.Status)
{
_unitOfWorkManage.RollbackTran();
return response.Error("鍑哄簱瀹屾垚鍚庯紝鏈湴搴撳瓨鎴栬揣浣嶆洿鏂板け璐�");
@@ -412,6 +465,7 @@
return response.OK();
}
+ // AGV宸叉斁璐э紝鍑嗗杈撻�佺嚎鍏ュ簱
private async Task<AGVResponse> CompleteAgvInboundTaskAsync(Dt_Task task)
{
AGVResponse response = new AGVResponse();
@@ -421,12 +475,15 @@
task.TargetAddress = availableLocation.LocationCode;
- var wcsTaskDto = _mapper.Map<WCSTaskDTO>(task);
- var httpResponse = _httpClientHelper.Post<WebResponseContent>(WCS_ReceiveTask, JsonSerializer.Serialize(wcsTaskDto));
+ var wmsTaskDto = _mapper.Map<WMSTaskDTO>(task);
+ var taskList = new List<WMSTaskDTO> { wmsTaskDto };
+ var requestBody = JsonSerializer.Serialize(taskList);
+
+ var httpResponse = _httpClientHelper.Post<WebResponseContent>(WCS_ReceiveTask, requestBody);
if (httpResponse == null || httpResponse.Data == null || !httpResponse.Data.Status)
return response.Error(httpResponse?.Data?.Message ?? "涓嬪彂WCS澶辫触");
- task.TaskStatus = (int)TaskStatusEnum.Line_Executing;
+ task.TaskStatus = (int)TaskInStatusEnum.Line_InExecuting;
task.Dispatchertime = DateTime.Now;
var locationInfo = await _locationInfoService.GetLocationInfoAsync(task.TargetAddress);
@@ -435,6 +492,10 @@
if (locationInfo.LocationStatus != (int)LocationStatusEnum.Free)
return response.Error($"褰撳墠璐т綅{locationInfo.LocationStatus}鐘舵�佷俊鎭敊璇�");
+
+ var existingStock = await _stockInfoService.GetStockInfoAsync(task.PalletCode);
+ if (existingStock != null)
+ return response.Error($"鎵樼洏{task.PalletCode}鐨勫簱瀛樹俊鎭凡瀛樺湪锛岃鍕块噸澶嶅叆搴�");
Dt_StockInfo stockInfo = new Dt_StockInfo
{
@@ -462,6 +523,7 @@
return response.OK();
}
+ // AGV鍏ュ簱鍙栨秷
private AGVResponse CancelAgvInboundTask(Dt_Task task)
{
AGVResponse response = new AGVResponse();
@@ -473,6 +535,8 @@
return response.OK();
}
+
+ // AGV鍑哄簱鍙栨秷
private async Task<AGVResponse> CancelAgvOutboundTaskAsync(Dt_Task task)
{
AGVResponse response = new AGVResponse();
@@ -505,6 +569,6 @@
return response.OK();
}
- #endregion 鏋佸嵎搴撲换鍔℃ā鍧�
+ #endregion 鍏蜂綋瀹炵幇
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3