From ce1292c9cf37195b6abd2699dfc5d6cb3e143c9b Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期日, 12 四月 2026 23:38:19 +0800
Subject: [PATCH] feat(MES): 添加MES接口相关实体和DTO JS扩展文件至JSX格式并更新配置
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_AutoOutbound.cs | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 175 insertions(+), 0 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_AutoOutbound.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_AutoOutbound.cs
new file mode 100644
index 0000000..bf5137d
--- /dev/null
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/WCS/TaskService_AutoOutbound.cs
@@ -0,0 +1,175 @@
+using Microsoft.Extensions.Configuration;
+using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.StockEnum;
+using WIDESEA_Common.TaskEnum;
+using WIDESEA_Core;
+using WIDESEA_Core.Helper;
+using WIDESEA_DTO.Task;
+using WIDESEA_Model.Models;
+
+namespace WIDESEA_TaskInfoService
+{
+ public partial class TaskService
+ {
+ #region 鑷姩鍑哄簱浠诲姟
+
+ /// <summary>
+ /// 鑷姩鍒涘缓鍑哄簱浠诲姟 - 鏌ヨ鍒版湡搴撳瓨骞跺垱寤轰换鍔�
+ /// </summary>
+ public async Task<WebResponseContent> CreateAutoOutboundTasksAsync()
+ {
+ try
+ {
+ // 1. 鏌ヨ鍒版湡搴撳瓨
+ var expiredStocks = await _stockInfoService.Repository
+ .QueryDataNavAsync(s => s.OutboundDate <= DateTime.Now
+ && s.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode());
+
+ if (expiredStocks == null || !expiredStocks.Any())
+ {
+ return WebResponseContent.Instance.OK("鏃犲埌鏈熷簱瀛橀渶瑕佸鐞�");
+ }
+
+ // 杩囨护鏈変綅缃笖浣嶇疆鏈夊簱瀛樼殑璁板綍
+ expiredStocks = expiredStocks
+ .Where(s => s.LocationDetails != null
+ && s.LocationDetails.LocationStatus == LocationStatusEnum.InStock.GetHashCode())
+ .ToList();
+
+ if (!expiredStocks.Any())
+ {
+ return WebResponseContent.Instance.OK("鏃犵鍚堟潯浠剁殑鍒版湡搴撳瓨");
+ }
+
+ // 2. 妫�鏌ュ凡瀛樺湪鐨勪换鍔�
+ var palletCodes = expiredStocks.Select(s => s.PalletCode).ToList();
+ var existingTasks = await Repository.QueryDataAsync(t =>
+ palletCodes.Contains(t.PalletCode)
+ && (t.TaskStatus == TaskStatusEnum.New.GetHashCode()
+ || t.TaskStatus == TaskStatusEnum.SC_Executing.GetHashCode()
+ || t.TaskStatus == TaskInStatusEnum.InNew.GetHashCode()));
+
+ var processedPallets = existingTasks.Select(t => t.PalletCode).ToHashSet();
+
+ // 3. 绛涢�夐渶瑕佸鐞嗙殑搴撳瓨
+ var stocksToProcess = expiredStocks
+ .Where(s => !processedPallets.Contains(s.PalletCode))
+ .ToList();
+
+ if (!stocksToProcess.Any())
+ {
+ return WebResponseContent.Instance.OK("鎵�鏈夊埌鏈熷簱瀛樺凡瀛樺湪浠诲姟");
+ }
+
+ // 4. 鑾峰彇閰嶇疆鐨勭洰鏍囧湴鍧�鏄犲皠
+ var targetAddressMap = _configuration.GetSection("AutoOutboundTask:TargetAddresses")
+ .Get<Dictionary<string, List<string>>>()
+ ?? new Dictionary<string, List<string>>();
+
+ // 5. 鎵归噺鍒涘缓浠诲姟
+ var taskList = new List<Dt_Task>();
+ foreach (var stock in stocksToProcess)
+ {
+ // 鏍规嵁宸烽亾纭畾鐩爣鍦板潃锛堜紭鍏堟牴鎹� Remark 纭畾锛孯emark 涓虹┖鍒欐牴鎹贩閬撻厤缃級
+ var targetAddress = DetermineTargetAddressByRemark(
+ stock.Remark ?? "",
+ stock.LocationDetails?.RoadwayNo ?? "",
+ targetAddressMap);
+
+ var task = new Dt_Task
+ {
+ WarehouseId = stock.WarehouseId,
+ PalletCode = stock.PalletCode,
+ PalletType = stock.PalletType,
+ SourceAddress = stock.LocationCode,
+ CurrentAddress = stock.LocationCode,
+ NextAddress = targetAddress,
+ TargetAddress = targetAddress,
+ Roadway = stock.LocationDetails?.RoadwayNo ?? "",
+ TaskType = TaskTypeEnum.Outbound.GetHashCode(),
+ TaskStatus = TaskStatusEnum.New.GetHashCode(),
+ Grade = 1,
+ TaskNum = await BaseDal.GetTaskNo(),
+ Creater = "system_auto"
+ };
+ taskList.Add(task);
+ }
+
+ var transactionResult = await _unitOfWorkManage.BeginTranAsync(async () =>
+ {
+ var addResult = await BaseDal.AddDataAsync(taskList) > 0;
+ if (!addResult)
+ {
+ return WebResponseContent.Instance.Error($"鎵归噺鍒涘缓浠诲姟澶辫触锛屽叡 {taskList.Count} 涓换鍔�");
+ }
+
+ // 浠诲姟鍒涘缓鎴愬姛鍚庯紝鍚屾閿佸畾搴撳瓨鍜岃揣浣嶇姸鎬侊紝閬垮厤閲嶅鍒嗛厤
+ var stocksToUpdate = stocksToProcess
+ .Select(s =>
+ {
+ s.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.GetHashCode();
+ return s;
+ })
+ .ToList();
+
+ var updateStockResult = await _stockInfoService.Repository.UpdateDataAsync(stocksToUpdate);
+ if (!updateStockResult)
+ {
+ return WebResponseContent.Instance.Error($"浠诲姟鍒涘缓鎴愬姛锛屼絾搴撳瓨鐘舵�佹洿鏂板け璐ワ紝鍏� {stocksToUpdate.Count} 鏉�");
+ }
+
+ var locationsToUpdate = stocksToProcess
+ .Where(s => s.LocationDetails != null)
+ .GroupBy(s => s.LocationDetails.Id)
+ .Select(g =>
+ {
+ var location = g.First().LocationDetails;
+ location.LocationStatus = LocationStatusEnum.InStockLock.GetHashCode();
+ return location;
+ })
+ .ToList();
+
+ if (locationsToUpdate.Any())
+ {
+ var updateLocationResult = await _locationInfoService.Repository.UpdateDataAsync(locationsToUpdate);
+ if (!updateLocationResult)
+ {
+ return WebResponseContent.Instance.Error($"浠诲姟鍒涘缓鎴愬姛锛屼絾璐т綅鐘舵�佹洿鏂板け璐ワ紝鍏� {locationsToUpdate.Count} 鏉�");
+ }
+ }
+
+ return WebResponseContent.Instance.OK();
+ });
+ if (!transactionResult.Status)
+ {
+ return transactionResult;
+ }
+
+ // 6. 閫氱煡 WCS锛堝紓姝ワ紝涓嶅奖鍝嶄富娴佺▼锛�
+ _ = Task.Run(() =>
+ {
+ try
+ {
+ var wmstaskDtos = _mapper.Map<List<WMSTaskDTO>>(taskList);
+ _httpClientHelper.Post<WebResponseContent>(
+ "http://localhost:9292/api/Task/ReceiveTask",
+ wmstaskDtos.ToJson());
+ }
+ catch (Exception ex)
+ {
+ // WCS 閫氱煡澶辫触涓嶅奖鍝嶄换鍔″垱寤猴紝璁板綍鏃ュ織鍗冲彲
+ Console.WriteLine($"WCS 鎵归噺閫氱煡澶辫触锛屼换鍔℃暟閲�: {taskList.Count}, 閿欒: {ex.Message}");
+ }
+ });
+
+ return WebResponseContent.Instance.OK($"鎴愬姛鍒涘缓 {taskList.Count} 涓嚭搴撲换鍔�", taskList.Count);
+ }
+ catch (Exception ex)
+ {
+ return WebResponseContent.Instance.Error($"鑷姩鍒涘缓鍑哄簱浠诲姟澶辫触: {ex.Message}");
+ }
+ }
+
+ #endregion 鑷姩鍑哄簱浠诲姟
+ }
+}
--
Gitblit v1.9.3