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_WMSServer/Controllers/Stock/StockInfoController.cs | 264 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 263 insertions(+), 1 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoController.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoController.cs
index 1a7ac90..1d4292c 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoController.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoController.cs
@@ -4,8 +4,14 @@
using WIDESEA_Core;
using WIDESEA_Core.BaseController;
using WIDESEA_DTO.Stock;
+using WIDESEA_DTO.MES;
using WIDESEA_IStockService;
+using WIDESEA_IBasicService;
+using WIDESEA_IMesService;
+using WIDESEA_ISystemService;
using WIDESEA_Model.Models;
+using WIDESEA_Common.StockEnum;
+using System.Diagnostics;
namespace WIDESEA_WMSServer.Controllers.Stock
{
@@ -16,8 +22,19 @@
[ApiController]
public class StockInfoController : ApiBaseController<IStockInfoService, Dt_StockInfo>
{
- public StockInfoController(IStockInfoService service) : base(service)
+ private readonly IMesLogService _mesLogService;
+ private readonly IMesService _mesService;
+ private readonly ISys_DictionaryService _sysDictionaryService;
+
+ public StockInfoController(
+ IStockInfoService service,
+ IMesLogService mesLogService,
+ IMesService mesService,
+ ISys_DictionaryService sysDictionaryService) : base(service)
{
+ _mesLogService = mesLogService;
+ _mesService = mesService;
+ _sysDictionaryService = sysDictionaryService;
}
/// <summary>
@@ -31,5 +48,250 @@
var result = await Service.Get3DLayoutAsync(warehouseId);
return WebResponseContent.Instance.OK(data: result);
}
+
+ /// <summary>
+ /// 鎵樼洏杩涚珯 - 璋冪敤MES鎺ュ彛
+ /// </summary>
+ /// <param name="dto">杩涚珯璇锋眰鍙傛暟</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ [HttpPost("inboundInContainer")]
+ public async Task<WebResponseContent> InboundInContainer([FromBody] InboundInContainerRequestDto dto)
+ {
+ var response = new WebResponseContent();
+ var stopwatch = Stopwatch.StartNew();
+
+ try
+ {
+ // 1. 鍙傛暟楠岃瘉
+ if (string.IsNullOrWhiteSpace(dto.PalletCode))
+ {
+ return response.Error("鎵樼洏缂栧彿涓嶈兘涓虹┖");
+ }
+
+ // 2. 鏌ヨ搴撳瓨淇℃伅 - 浣跨敤鍗曟潯璁板綍鏌ヨ鏂规硶鎻愰珮鏁堢巼
+ var stockInfo = await Service.Repository.QueryDataNavFirstAsync(x => x.Id == dto.StockId);
+
+ if (stockInfo == null)
+ {
+ return response.Error("搴撳瓨淇℃伅涓嶅瓨鍦�");
+ }
+
+ // 3. 楠岃瘉搴撳瓨鐘舵�侊紙浠�"鍏ュ簱瀹屾垚"鐘舵�佸厑璁歌繘绔欙級
+ if (stockInfo.StockStatus != StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode())
+ {
+ return response.Error($"褰撳墠搴撳瓨鐘舵�佷笉鍏佽杩涚珯鎿嶄綔锛屽綋鍓嶇姸鎬侊細{stockInfo.StockStatus}");
+ }
+
+ // 4. 鑾峰彇绯荤粺閰嶇疆 - 鐩存帴浠庢暟鎹簱鏌ヨ
+ var configs = _sysDictionaryService.GetVueDictionary(new[] { "MES_EquipmentCode", "MES_ResourceCode" });
+
+ string equipmentCode = GetConfigValue(configs, "MES_EquipmentCode", "WCS_001");
+ string resourceCode = GetConfigValue(configs, "MES_ResourceCode", "RESOURCE_001");
+
+ // 5. 鏋勯�燤ES璇锋眰
+ var mesRequest = new InboundInContainerRequest
+ {
+ EquipmentCode = equipmentCode,
+ ResourceCode = resourceCode,
+ LocalTime = DateTime.Now,
+ ContainerCode = dto.PalletCode
+ };
+
+ string requestJson = System.Text.Json.JsonSerializer.Serialize(mesRequest);
+
+ // 6. 璋冪敤MES鎺ュ彛锛堝悓姝ユ柟娉曪級
+ var mesResult = _mesService.InboundInContainer(mesRequest);
+ stopwatch.Stop();
+
+ // 7. 璁板綍鏃ュ織
+ await _mesLogService.LogAsync(new MesApiLogDto
+ {
+ ApiType = "InboundInContainer",
+ RequestJson = requestJson,
+ ResponseJson = System.Text.Json.JsonSerializer.Serialize(mesResult),
+ IsSuccess = mesResult.IsSuccess,
+ ErrorMessage = mesResult.ErrorMessage,
+ ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
+ Creator = App.User.UserName
+ });
+
+ // 8. 杩斿洖缁撴灉
+ if (mesResult.IsSuccess)
+ {
+ return response.OK("鎵樼洏杩涚珯鎴愬姛");
+ }
+ else
+ {
+ return response.Error($"MES鎺ュ彛璋冪敤澶辫触: {mesResult.ErrorMessage}");
+ }
+ }
+ catch (System.Exception ex)
+ {
+ stopwatch.Stop();
+
+ // 璁板綍閿欒鏃ュ織
+ await _mesLogService.LogAsync(new MesApiLogDto
+ {
+ ApiType = "InboundInContainer",
+ IsSuccess = false,
+ ErrorMessage = ex.Message,
+ ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
+ Creator = App.User.UserName
+ });
+
+ return response.Error($"鎵樼洏杩涚珯澶辫触: {ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 鎵樼洏鍑虹珯 - 璋冪敤MES鎺ュ彛
+ /// </summary>
+ /// <param name="dto">鍑虹珯璇锋眰鍙傛暟</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ [HttpPost("outboundInContainer")]
+ public async Task<WebResponseContent> OutboundInContainer([FromBody] OutboundInContainerRequestDto dto)
+ {
+ var response = new WebResponseContent();
+ var stopwatch = Stopwatch.StartNew();
+
+ try
+ {
+ // 1. 鍙傛暟楠岃瘉
+ if (string.IsNullOrWhiteSpace(dto.PalletCode))
+ {
+ return response.Error("鎵樼洏缂栧彿涓嶈兘涓虹┖");
+ }
+
+ // 2. 鏌ヨ搴撳瓨淇℃伅 - 浣跨敤鍗曟潯璁板綍鏌ヨ鏂规硶鎻愰珮鏁堢巼
+ var stockInfo = await Service.Repository.QueryDataNavFirstAsync(x => x.Id == dto.StockId);
+
+ if (stockInfo == null)
+ {
+ return response.Error("搴撳瓨淇℃伅涓嶅瓨鍦�");
+ }
+
+ // 3. 楠岃瘉搴撳瓨鐘舵�侊紙"鍑哄簱閿佸畾"鎴�"鍑哄簱瀹屾垚"鐘舵�佸厑璁稿嚭绔欙級
+ var allowedStatuses = new[]
+ {
+ StockStatusEmun.鍑哄簱閿佸畾.GetHashCode(),
+ StockStatusEmun.鍑哄簱瀹屾垚.GetHashCode()
+ };
+
+ if (!allowedStatuses.Contains(stockInfo.StockStatus))
+ {
+ return response.Error($"褰撳墠搴撳瓨鐘舵�佷笉鍏佽鍑虹珯鎿嶄綔锛屽綋鍓嶇姸鎬侊細{stockInfo.StockStatus}");
+ }
+
+ // 4. 鑾峰彇绯荤粺閰嶇疆
+ var configs = _sysDictionaryService.GetVueDictionary(new[] { "MES_EquipmentCode", "MES_ResourceCode" });
+
+ string equipmentCode = GetConfigValue(configs, "MES_EquipmentCode", "WCS_001");
+ string resourceCode = GetConfigValue(configs, "MES_ResourceCode", "RESOURCE_001");
+
+ // 5. 鏋勯�燤ES璇锋眰
+ var mesRequest = new OutboundInContainerRequest
+ {
+ EquipmentCode = equipmentCode,
+ ResourceCode = resourceCode,
+ LocalTime = DateTime.Now,
+ ContainerCode = dto.PalletCode,
+ ParamList = dto.ParamList?.Select(p => new ParamItem
+ {
+ ParamCode = p.ParamCode,
+ ParamValue = p.ParamValue,
+ CollectionTime = DateTime.TryParse(p.CollectionTime, out var ct) ? ct : DateTime.Now
+ }).ToList()
+ };
+
+ string requestJson = System.Text.Json.JsonSerializer.Serialize(mesRequest);
+
+ // 6. 璋冪敤MES鎺ュ彛锛堝悓姝ユ柟娉曪級
+ var mesResult = _mesService.OutboundInContainer(mesRequest);
+ stopwatch.Stop();
+
+ // 7. 璁板綍鏃ュ織
+ await _mesLogService.LogAsync(new MesApiLogDto
+ {
+ ApiType = "OutboundInContainer",
+ RequestJson = requestJson,
+ ResponseJson = System.Text.Json.JsonSerializer.Serialize(mesResult),
+ IsSuccess = mesResult.IsSuccess,
+ ErrorMessage = mesResult.ErrorMessage,
+ ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
+ Creator = App.User.UserName
+ });
+
+ // 8. 杩斿洖缁撴灉
+ if (mesResult.IsSuccess)
+ {
+ return response.OK("鎵樼洏鍑虹珯鎴愬姛");
+ }
+ else
+ {
+ return response.Error($"MES鎺ュ彛璋冪敤澶辫触: {mesResult.ErrorMessage}");
+ }
+ }
+ catch (System.Exception ex)
+ {
+ stopwatch.Stop();
+
+ // 璁板綍閿欒鏃ュ織
+ await _mesLogService.LogAsync(new MesApiLogDto
+ {
+ ApiType = "OutboundInContainer",
+ IsSuccess = false,
+ ErrorMessage = ex.Message,
+ ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
+ Creator = App.User.UserName
+ });
+
+ return response.Error($"鎵樼洏鍑虹珯澶辫触: {ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 浠庨厤缃瓧鍏镐腑鑾峰彇閰嶇疆鍊�
+ /// </summary>
+ /// <param name="configs">閰嶇疆瀛楀吀鍒楄〃</param>
+ /// <param name="key">閰嶇疆閿�</param>
+ /// <param name="defaultValue">榛樿鍊�</param>
+ /// <returns>閰嶇疆鍊�</returns>
+ private string GetConfigValue(System.Collections.Generic.List<WIDESEA_DTO.System.VueDictionaryDTO> configs, string key, string defaultValue = "")
+ {
+ if (configs != null)
+ {
+ var config = configs.FirstOrDefault(c => c.DicNo == key);
+ if (config != null && config.Data != null)
+ {
+ // Data鏄痙ynamic绫诲瀷锛屽皾璇曡幏鍙栫涓�涓厓绱犵殑value灞炴��
+ try
+ {
+ // 浣跨敤dynamic鏉ヨ闂尶鍚嶇被鍨嬬殑灞炴��
+ dynamic data = config.Data;
+ if (data != null)
+ {
+ // data鍙兘鏄疘Enumerable鎴栬�呭崟涓璞�
+ var enumerable = data as System.Collections.IEnumerable;
+ if (enumerable != null)
+ {
+ foreach (var item in enumerable)
+ {
+ // 鑾峰彇绗竴涓厓绱�
+ dynamic firstItem = item;
+ var value = firstItem.value;
+ return value?.ToString() ?? defaultValue;
+ }
+ }
+ }
+ }
+ catch
+ {
+ // 濡傛灉鏃犳硶鑾峰彇锛岃繑鍥為粯璁ゅ��
+ return defaultValue;
+ }
+ }
+ }
+ return defaultValue;
+ }
}
}
--
Gitblit v1.9.3