From aefdecd0aa3226b7d00d1dc764241b82658b3be8 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 06 三月 2026 10:41:02 +0800
Subject: [PATCH] 添加机器人客户端;更新 WCS 缓存及任务
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs | 344 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 330 insertions(+), 14 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
index 4400580..5606824 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -1,10 +1,13 @@
锘縰sing AutoMapper;
using SqlSugar;
+using System.Text.Json;
using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
+using WIDESEA_DTO;
using WIDESEA_DTO.Task;
using WIDESEA_IBasicService;
using WIDESEA_IStockService;
@@ -18,6 +21,7 @@
private readonly IMapper _mapper;
private readonly IStockInfoService _stockInfoService;
private readonly ILocationInfoService _locationInfoService;
+ private readonly HttpClientHelper _httpClientHelper;
public IRepository<Dt_Task> Repository => BaseDal;
@@ -34,12 +38,16 @@
IRepository<Dt_Task> BaseDal,
IMapper mapper,
IStockInfoService stockInfoService,
- ILocationInfoService locationInfoService) : base(BaseDal)
+ ILocationInfoService locationInfoService,
+ HttpClientHelper httpClientHelper) : base(BaseDal)
{
_mapper = mapper;
_stockInfoService = stockInfoService;
_locationInfoService = locationInfoService;
+ _httpClientHelper = httpClientHelper;
}
+
+ #region WCS閫昏緫澶勭悊
/// <summary>
/// 鍒涘缓浠诲姟锛堢粍鐩樺叆搴撲换鍔°�佺┖鎵樼洏鍥炲簱浠诲姟锛�
@@ -48,27 +56,39 @@
{
try
{
+ WebResponseContent content = await GetTasksByPalletCodeAsync(taskDto.PalletCode);
+ if (content.Status)
+ {
+ return content;
+ }
+
if (string.IsNullOrWhiteSpace(taskDto.PalletCode) ||
- string.IsNullOrWhiteSpace(taskDto.SourceAddress) ||
- string.IsNullOrWhiteSpace(taskDto.TargetAddress) ||
string.IsNullOrWhiteSpace(taskDto.Roadway))
{
- return WebResponseContent.Instance.Error("Invalid task details.");
+ return WebResponseContent.Instance.Error("鏃犳晥鐨勪换鍔¤鎯�");
}
if (taskDto.TaskType != TaskTypeEnum.Inbound && taskDto.TaskType != TaskTypeEnum.InEmpty)
{
- return WebResponseContent.Instance.Error("Invalid task details.");
+ return WebResponseContent.Instance.Error("鏃犳晥鐨勪换鍔¤鎯�");
}
+
+ // 浣跨敤 switch 琛ㄨ揪寮忔槧灏勪换鍔$被鍨�
+ int taskInboundType = taskDto.TaskType switch
+ {
+ TaskTypeEnum.Inbound => TaskInboundTypeEnum.Inbound.GetHashCode(),
+ TaskTypeEnum.InEmpty => TaskInboundTypeEnum.InEmpty.GetHashCode(),
+ _ => 0 // 鐞嗚涓婁笉浼氳蛋鍒拌繖閲岋紝鍥犱负宸茬粡楠岃瘉杩囦簡
+ };
var task = new Dt_Task
{
- TaskNum = 0,
+ TaskNum = await BaseDal.GetTaskNo(),
PalletCode = taskDto.PalletCode,
PalletType = taskDto.PalletType,
Roadway = taskDto.Roadway,
- TaskType = taskDto.TaskType.GetHashCode(),
- TaskStatus = TaskStatusEnum.New.GetHashCode(),
+ TaskType = taskInboundType,
+ TaskStatus = TaskInStatusEnum.InNew.GetHashCode(),
SourceAddress = taskDto.SourceAddress,
TargetAddress = taskDto.TargetAddress,
CurrentAddress = taskDto.SourceAddress,
@@ -89,7 +109,6 @@
return WebResponseContent.Instance.Error($"浠诲姟鍒涘缓澶辫触: {ex.Message}");
}
}
-
/// <summary>
/// 鏍规嵁鎸囧畾鐨勪换鍔¤鎯呭紓姝ュ垱寤烘柊鐨勫嚭搴撲换鍔�
@@ -121,14 +140,13 @@
var result = await BaseDal.AddDataAsync(taskList) > 0;
var wmstaskDto = result ? _mapper.Map<WMSTaskDTO>(taskList) : null;
- return WebResponseContent.Instance.OK(result ? "浠诲姟鍒涘缓鎴愬姛" : "浠诲姟鍒涘缓澶辫触", wmstaskDto);
+ return WebResponseContent.Instance.OK(result ? "浠诲姟鍒涘缓鎴愬姛" : "浠诲姟鍒涘缓澶辫触", wmstaskDto ?? new object());
}
catch (Exception ex)
{
return WebResponseContent.Instance.Error($"浠诲姟鍒涘缓澶辫触: {ex.Message}");
}
}
-
/// <summary>
/// 鑾峰彇鍙叆搴撹揣浣�
@@ -144,9 +162,9 @@
if (locationInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑璐т綅");
locationInfo.LocationStatus = LocationStatusEnum.FreeLock.GetHashCode();
- task.CurrentAddress = taskDto.SourceAddress;
+ task.CurrentAddress = task.SourceAddress;
task.NextAddress = locationInfo.LocationCode;
- task.TargetAddress = taskDto.TargetAddress;
+ task.TargetAddress = locationInfo.LocationCode;
task.TaskStatus = TaskStatusEnum.Line_Finish.GetHashCode();
var updateResult = await BaseDal.UpdateDataAsync(task);
@@ -243,5 +261,303 @@
return WebResponseContent.Instance.Error($"瀹屾垚浠诲姟澶辫触: {ex.Message}");
}
}
+
+ /// <summary>
+ /// 鍒涘缓绌烘墭鐩樺叆搴撲换鍔�
+ /// </summary>
+ /// <param name="taskDto"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> CreateTaskInboundTrayAsync(CreateTaskDto taskDto)
+ {
+ try
+ {
+ WebResponseContent content = await GetTasksByPalletCodeAsync(taskDto.PalletCode);
+ if (content.Status)
+ {
+ return content;
+ }
+
+ //var tasks = await BaseDal.QueryAsync(s => s.PalletCode == palletCode);
+ //if (tasks == null || !tasks.Any())
+ // return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑浠诲姟");
+ //var taskDtos = _mapper.Map<List<WMSTaskDTO>>(tasks);
+ return WebResponseContent.Instance.OK("鏌ヨ鎴愬姛"/*, taskDtos*/);
+ }
+ catch (Exception ex)
+ {
+ return WebResponseContent.Instance.Error($"鏌ヨ浠诲姟澶辫触: {ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 鍒涘缓绌烘墭鐩樺嚭搴撲换鍔�
+ /// </summary>
+ /// <param name="taskDto"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> GetOutBoundTrayTaskAsync(CreateTaskDto taskDto)
+ {
+ try
+ {
+
+ var stockInfo = await _stockInfoService.Repository.QueryFirstAsync(x => x.LocationDetails.WarehouseId == taskDto.WarehouseId && x.LocationDetails.LocationStatus == LocationStatusEnum.InStock.GetHashCode() && x.StockStatus == StockStatusEmun.绌烘墭鐩樺簱瀛�.GetHashCode());
+ if (stockInfo == null)
+ return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑搴撳瓨淇℃伅");
+
+ var task = new Dt_Task()
+ {
+ WarehouseId = stockInfo.LocationDetails.WarehouseId,
+ PalletCode = stockInfo.PalletCode,
+ PalletType = stockInfo.PalletType,
+ SourceAddress = stockInfo.LocationCode,
+ CurrentAddress = stockInfo.LocationCode,
+ NextAddress = taskDto.TargetAddress,
+ TargetAddress = taskDto.TargetAddress,
+ Roadway = stockInfo.LocationDetails.RoadwayNo,
+ TaskType = TaskTypeEnum.OutEmpty.GetHashCode(),
+ TaskStatus = TaskStatusEnum.New.GetHashCode(),
+ Grade = 1,
+ TaskNum = await BaseDal.GetTaskNo(),
+ Creater = "system",
+ };
+ var taskDtos = _mapper.Map<List<WMSTaskDTO>>(task);
+ return WebResponseContent.Instance.OK("鏌ヨ鎴愬姛", taskDtos);
+ }
+ catch (Exception ex)
+ {
+ return WebResponseContent.Instance.Error($"鏌ヨ浠诲姟澶辫触: {ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 淇敼浠诲姟鐘舵�侊紙鏍规嵁浠诲姟ID淇敼涓烘寚瀹氱姸鎬侊級
+ /// </summary>
+ /// <param name="taskId"></param>
+ /// <param name="newStatus"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> UpdateTaskByStatusAsync(int taskId, int newStatus)
+ {
+ try
+ {
+ var tasks = await BaseDal.QueryFirstAsync(s => s.TaskId == taskId);
+ if (tasks == null)
+ return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑浠诲姟");
+
+ tasks.TaskStatus = newStatus;
+ await BaseDal.UpdateDataAsync(tasks);
+
+ return WebResponseContent.Instance.OK("淇敼鎴愬姛", tasks);
+ }
+ catch (Exception ex)
+ {
+ return WebResponseContent.Instance.Error($"淇敼澶辫触: {ex.Message}");
+ }
+ }
+
+
+ /// <summary>
+ /// 鏌ユ壘鎵樼洏鏄惁鏈変换鍔�
+ /// </summary>
+ /// <param name="palletCode"></param>
+ /// <returns></returns>
+ private async Task<WebResponseContent> GetTasksByPalletCodeAsync(string palletCode)
+ {
+ try
+ {
+ var tasks = await BaseDal.QueryFirstAsync(s => s.PalletCode == palletCode);
+ if (tasks == null)
+ return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑浠诲姟");
+ var taskDtos = _mapper.Map<List<WMSTaskDTO>>(tasks);
+ return WebResponseContent.Instance.OK("鏌ヨ鎴愬姛", taskDtos);
+ }
+ catch (Exception ex)
+ {
+ return WebResponseContent.Instance.Error($"鏌ヨ浠诲姟澶辫触: {ex.Message}");
+ }
+ }
+
+ #endregion WCS閫昏緫澶勭悊
+
+ #region 鍒嗗鏌滄帴鍙�
+
+ /// <summary>
+ /// 鍫嗗灈鏈哄彇鏀捐揣瀹屾垚鍚庣墿娴侀�氱煡鍖栨垚鍒嗗鏌滃畬鎴愪俊鍙�
+ /// </summary>
+ public async Task<WebResponseContent> InOrOutCompletedAsync(InputDto input)
+ {
+ WebResponseContent content = new WebResponseContent();
+ if (string.IsNullOrWhiteSpace(input.PalletCode) || string.IsNullOrWhiteSpace(input.LocationCode))
+ {
+ return content.Error($"鎵樼洏鍙锋垨鑰呰揣浣嶇紪鍙蜂笉鑳戒负绌�");
+ }
+
+ try
+ {
+ var stockInfo = await _stockInfoService.GetStockInfoAsync(input.PalletCode, input.LocationCode);
+ if (stockInfo == null)
+ {
+ var location = await _locationInfoService.GetLocationInfoAsync(input.LocationCode);
+
+ OutPutDto outPutDto = new OutPutDto()
+ {
+ LocationCode = input.LocationCode,
+ PalletCode = input.PalletCode,
+ IsNormalProcedure = 1,
+ LocationStatus = location.LocationStatus
+ };
+ content.OK(data: outPutDto);
+ }
+ else
+ {
+ OutPutDto outPutDto = new OutPutDto()
+ {
+ LocationCode = input.LocationCode,
+ PalletCode = input.PalletCode,
+ IsNormalProcedure = 1,
+ LocationStatus = stockInfo.LocationDetails.LocationStatus
+ };
+ content.OK(data: outPutDto);
+ }
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+
+ return content;
+ }
+
+ /// <summary>
+ /// 鍖栨垚鍒嗗鏌滃畾鏃跺悜鐗╂祦鏇存柊鍒嗗鏌滅姸鎬佷俊鎭�
+ /// </summary>
+ /// <param name="input"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> SendLocationStatusAsync(InputDto input)
+ {
+ WebResponseContent content = new WebResponseContent();
+ if (string.IsNullOrWhiteSpace(input.LocationCode))
+ {
+ return content.Error($"璐т綅缂栧彿涓嶈兘涓虹┖");
+ }
+
+ try
+ {
+ var result = await _locationInfoService.Db.Updateable<Dt_LocationInfo>()
+ .SetColumns(s => new Dt_LocationInfo
+ {
+ LocationStatus = input.LocationStatus
+ }).Where(s => s.LocationCode == input.LocationCode).ExecuteCommandAsync() > 0;
+
+ if (result)
+ {
+ content.OK("鏇存柊鎴愬姛");
+ }
+ else
+ {
+ content.Error("鏇存柊澶辫触");
+ }
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+
+ /// <summary>
+ /// 鍒嗗鏌滃伐浣滃畬鎴愬悗璋冪敤姝ゆ帴鍙i�氱煡鐗╂祦鍑哄簱
+ /// </summary>
+ /// <param name="input"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> RequestOutboundAsync(InputDto input)
+ {
+ WebResponseContent content = new WebResponseContent();
+ if (string.IsNullOrWhiteSpace(input.LocationCode) || string.IsNullOrWhiteSpace(input.PalletCode))
+ {
+ return content.Error($"鎵樼洏鍙锋垨鑰呰揣浣嶇紪鍙蜂笉鑳戒负绌�");
+ }
+ try
+ {
+ var stock = await _stockInfoService.GetStockInfoAsync(input.PalletCode, input.LocationCode);
+ if (stock == null)
+ {
+ content.Error("鏈壘鍒板搴旂殑鎵樼洏");
+ }
+ else
+ {
+ var taskList = new Dt_Task
+ {
+ WarehouseId = stock.WarehouseId,
+ PalletCode = stock.PalletCode,
+ PalletType = stock.PalletType,
+ SourceAddress = stock.LocationCode,
+ CurrentAddress = stock.LocationCode,
+ NextAddress = "10080",
+ TargetAddress = "10081",
+ Roadway = stock.LocationDetails.RoadwayNo,
+ TaskType = TaskTypeEnum.Outbound.GetHashCode(),
+ TaskStatus = TaskStatusEnum.New.GetHashCode(),
+ Grade = 1,
+ TaskNum = await BaseDal.GetTaskNo(),
+ Creater = "system",
+ };
+
+ var result = await BaseDal.AddDataAsync(taskList) > 0;
+ var wmstaskDto = result ? _mapper.Map<WMSTaskDTO>(taskList) : null;
+
+ var httpResponse = _httpClientHelper.Post<WebResponseContent>("http://logistics-service/api/logistics/notifyoutbound", JsonSerializer.Serialize(wmstaskDto)).Data;
+ if (result && httpResponse != null)
+ {
+ content.OK("鍑哄簱璇锋眰鎴愬姛");
+ }
+ else
+ {
+ content.Error("鍑哄簱璇锋眰澶辫触");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
+
+ /// <summary>
+ /// 鍏ュ簱瀹屾垚鍒嗗璋冪敤鑾峰彇鎵樼洏涓婃瘡涓�氶亾鐢佃姱
+ /// </summary>
+ /// <param name="input"></param>
+ /// <returns></returns>
+ public async Task<WebResponseContent> GetPalletCodeCellAsync(InputDto input)
+ {
+ WebResponseContent content = new WebResponseContent();
+ if (string.IsNullOrWhiteSpace(input.PalletCode) || string.IsNullOrWhiteSpace(input.LocationCode))
+ {
+ return content.Error($"鎵樼洏鍙锋垨鑰呰揣浣嶇紪鍙蜂笉鑳戒负绌�");
+ }
+ try
+ {
+ var stockInfo = await _stockInfoService.GetStockInfoAsync(input.PalletCode, input.LocationCode);
+ if (stockInfo == null)
+ {
+ return content.Error("鏈壘鍒板搴旂殑鎵樼洏");
+ }
+ var outPutDtos = stockInfo.Details.Select(x => new OutPutDto()
+ {
+ LocationCode = input.LocationCode,
+ PalletCode = input.PalletCode,
+ IsNormalProcedure = 1,
+ LocationStatus = stockInfo.LocationDetails.LocationStatus,
+ CellCode = x.SerialNumber,
+ Channel = x.InboundOrderRowNo.ToString()
+ }).ToList();
+ return content.OK(data: outPutDtos);
+ }
+ catch (Exception ex)
+ {
+ return content.Error(ex.Message);
+ }
+ }
+
+ #endregion 鍒嗗鏌滄帴鍙�
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3