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/StockInfoDetailController.cs | 355 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 354 insertions(+), 1 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoDetailController.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoDetailController.cs
index 5ff0f67..1c4242a 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoDetailController.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoDetailController.cs
@@ -1,8 +1,14 @@
锘縰sing Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
+using WIDESEA_Core;
using WIDESEA_Core.BaseController;
+using WIDESEA_DTO.MES;
using WIDESEA_IStockService;
+using WIDESEA_IBasicService;
+using WIDESEA_IMesService;
+using WIDESEA_ISystemService;
using WIDESEA_Model.Models;
+using System.Diagnostics;
namespace WIDESEA_WMSServer.Controllers.Stock
{
@@ -13,8 +19,355 @@
[ApiController]
public class StockInfoDetailController : ApiBaseController<IStockInfoDetailService, Dt_StockInfoDetail>
{
- public StockInfoDetailController(IStockInfoDetailService service) : base(service)
+ private readonly IMesLogService _mesLogService;
+ private readonly IMesService _mesService;
+ private readonly ISys_DictionaryService _sysDictionaryService;
+
+ public StockInfoDetailController(
+ IStockInfoDetailService service,
+ IMesLogService mesLogService,
+ IMesService mesService,
+ ISys_DictionaryService sysDictionaryService) : base(service)
{
+ _mesLogService = mesLogService;
+ _mesService = mesService;
+ _sysDictionaryService = sysDictionaryService;
+ }
+
+ /// <summary>
+ /// 鎵樼洏鐢佃姱缁戝畾 - 璋冪敤MES鎺ュ彛
+ /// </summary>
+ /// <param name="dto">缁戝畾璇锋眰鍙傛暟</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ [HttpPost("bindContainer")]
+ public async Task<WebResponseContent> BindContainer([FromBody] BindContainerRequestDto dto)
+ {
+ var response = new WebResponseContent();
+ var stopwatch = Stopwatch.StartNew();
+
+ try
+ {
+ // 1. 鍙傛暟楠岃瘉
+ if (string.IsNullOrWhiteSpace(dto.PalletCode))
+ {
+ return response.Error("鎵樼洏缂栧彿涓嶈兘涓虹┖");
+ }
+
+ if (dto.SfcList == null || !dto.SfcList.Any())
+ {
+ return response.Error("鐢佃姱鐮佸垪琛ㄤ笉鑳戒负绌�");
+ }
+
+ // 2. 楠岃瘉鐢佃姱鐘舵�侊紙闈�'宸查攣瀹�'鐘舵�佸厑璁哥粦瀹氾級
+ var stockDetails = await Service.Repository.QueryDataAsync(x => dto.SfcList.Contains(x.SerialNumber));
+ if (stockDetails != null && stockDetails.Any(d => d.Status == 99))
+ {
+ return response.Error("褰撳墠搴撳瓨鏄庣粏鍖呭惈宸查攣瀹氱姸鎬侊紝涓嶅厑璁告墽琛岀粦瀹氭搷浣�");
+ }
+
+ // 3. 鑾峰彇绯荤粺閰嶇疆
+ 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");
+
+ // 3. 鏋勯�燤ES璇锋眰 - 灏嗙數鑺垪琛ㄨ浆鎹负ContainerSfcItem鏍煎紡
+ var mesRequest = new BindContainerRequest
+ {
+ EquipmentCode = equipmentCode,
+ ResourceCode = resourceCode,
+ LocalTime = DateTime.Now,
+ ContainerCode = dto.PalletCode,
+ ContainerSfcList = dto.SfcList.Select(sfc => new ContainerSfcItem
+ {
+ Sfc = sfc,
+ Location = dto.Location ?? ""
+ }).ToList(),
+ OperationType = dto.OperationType
+ };
+
+ string requestJson = System.Text.Json.JsonSerializer.Serialize(mesRequest);
+
+ // 4. 璋冪敤MES鎺ュ彛锛堝悓姝ユ柟娉曪級
+ var mesResult = _mesService.BindContainer(mesRequest);
+ stopwatch.Stop();
+
+ // 5. 璁板綍鏃ュ織
+ await _mesLogService.LogAsync(new MesApiLogDto
+ {
+ ApiType = "BindContainer",
+ RequestJson = requestJson,
+ ResponseJson = System.Text.Json.JsonSerializer.Serialize(mesResult),
+ IsSuccess = mesResult.IsSuccess,
+ ErrorMessage = mesResult.ErrorMessage,
+ ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
+ Creator = App.User.UserName
+ });
+
+ // 6. 杩斿洖缁撴灉
+ 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 = "BindContainer",
+ IsSuccess = false,
+ ErrorMessage = ex.Message,
+ ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
+ Creator = App.User.UserName
+ });
+
+ return response.Error($"鎵樼洏鐢佃姱缁戝畾澶辫触: {ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 鎵樼洏鐢佃姱瑙g粦 - 璋冪敤MES鎺ュ彛
+ /// </summary>
+ /// <param name="dto">瑙g粦璇锋眰鍙傛暟</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ [HttpPost("unbindContainer")]
+ public async Task<WebResponseContent> UnbindContainer([FromBody] UnbindContainerRequestDto dto)
+ {
+ var response = new WebResponseContent();
+ var stopwatch = Stopwatch.StartNew();
+
+ try
+ {
+ // 1. 鍙傛暟楠岃瘉
+ if (string.IsNullOrWhiteSpace(dto.PalletCode))
+ {
+ return response.Error("鎵樼洏缂栧彿涓嶈兘涓虹┖");
+ }
+
+ if (dto.SfcList == null || !dto.SfcList.Any())
+ {
+ return response.Error("鐢佃姱鐮佸垪琛ㄤ笉鑳戒负绌�");
+ }
+
+ // 2. 楠岃瘉鐢佃姱鐘舵�侊紙闈�'宸查攣瀹�'鐘舵�佸厑璁歌В缁戯級
+ var stockDetails = await Service.Repository.QueryDataAsync(x => dto.SfcList.Contains(x.SerialNumber));
+ if (stockDetails != null && stockDetails.Any(d => d.Status == 99))
+ {
+ return response.Error("褰撳墠搴撳瓨鏄庣粏鍖呭惈宸查攣瀹氱姸鎬侊紝涓嶅厑璁告墽琛岃В缁戞搷浣�");
+ }
+
+ // 3. 鑾峰彇绯荤粺閰嶇疆
+ 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");
+
+ // 3. 鏋勯�燤ES璇锋眰
+ var mesRequest = new UnBindContainerRequest
+ {
+ EquipmentCode = equipmentCode,
+ ResourceCode = resourceCode,
+ LocalTime = DateTime.Now,
+ ContainCode = dto.PalletCode,
+ SfcList = dto.SfcList
+ };
+
+ string requestJson = System.Text.Json.JsonSerializer.Serialize(mesRequest);
+
+ // 4. 璋冪敤MES鎺ュ彛锛堝悓姝ユ柟娉曪級
+ var mesResult = _mesService.UnBindContainer(mesRequest);
+ stopwatch.Stop();
+
+ // 5. 璁板綍鏃ュ織
+ await _mesLogService.LogAsync(new MesApiLogDto
+ {
+ ApiType = "UnbindContainer",
+ RequestJson = requestJson,
+ ResponseJson = System.Text.Json.JsonSerializer.Serialize(mesResult),
+ IsSuccess = mesResult.IsSuccess,
+ ErrorMessage = mesResult.ErrorMessage,
+ ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
+ Creator = App.User.UserName
+ });
+
+ // 6. 杩斿洖缁撴灉
+ if (mesResult.IsSuccess)
+ {
+ return response.OK("鎵樼洏鐢佃姱瑙g粦鎴愬姛");
+ }
+ else
+ {
+ return response.Error($"MES鎺ュ彛璋冪敤澶辫触: {mesResult.ErrorMessage}");
+ }
+ }
+ catch (System.Exception ex)
+ {
+ stopwatch.Stop();
+
+ // 璁板綍閿欒鏃ュ織
+ await _mesLogService.LogAsync(new MesApiLogDto
+ {
+ ApiType = "UnbindContainer",
+ IsSuccess = false,
+ ErrorMessage = ex.Message,
+ ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
+ Creator = App.User.UserName
+ });
+
+ return response.Error($"鎵樼洏鐢佃姱瑙g粦澶辫触: {ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 鎵樼洏NG鐢佃姱涓婃姤 - 璋冪敤MES鎺ュ彛
+ /// </summary>
+ /// <param name="dto">NG涓婃姤璇锋眰鍙傛暟</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ [HttpPost("containerNgReport")]
+ public async Task<WebResponseContent> ContainerNgReport([FromBody] ContainerNgReportRequestDto dto)
+ {
+ var response = new WebResponseContent();
+ var stopwatch = Stopwatch.StartNew();
+
+ try
+ {
+ // 1. 鍙傛暟楠岃瘉
+ if (string.IsNullOrWhiteSpace(dto.PalletCode))
+ {
+ return response.Error("鎵樼洏缂栧彿涓嶈兘涓虹┖");
+ }
+
+ if (dto.NgSfcList == null || !dto.NgSfcList.Any())
+ {
+ return response.Error("NG鐢佃姱鍒楄〃涓嶈兘涓虹┖");
+ }
+
+ // 2. 楠岃瘉鐢佃姱鐘舵�侊紙闈�'宸查攣瀹�'鐘舵�佸厑璁窷G涓婃姤锛�
+ var sfcList = dto.NgSfcList.Select(x => x.Sfc).ToList();
+ var stockDetails = await Service.Repository.QueryDataAsync(x => sfcList.Contains(x.SerialNumber));
+ if (stockDetails != null && stockDetails.Any(d => d.Status == 99))
+ {
+ return response.Error("褰撳墠搴撳瓨鏄庣粏鍖呭惈宸查攣瀹氱姸鎬侊紝涓嶅厑璁告墽琛孨G涓婃姤鎿嶄綔");
+ }
+
+ // 3. 鑾峰彇绯荤粺閰嶇疆
+ 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");
+
+ // 3. 鏋勯�燤ES璇锋眰 - 灏咲TO鏍煎紡杞崲涓篗ES璇锋眰鏍煎紡
+ var mesRequest = new ContainerNgReportRequest
+ {
+ EquipmentCode = equipmentCode,
+ ResourceCode = resourceCode,
+ LocalTime = DateTime.Now,
+ ContainerCode = dto.PalletCode,
+ NgSfcList = dto.NgSfcList.Select(ng => new NgSfcItem
+ {
+ Sfc = ng.Sfc,
+ NgCode = ng.NgCode,
+ NgEquipmentCode = ng.NgEquipmentCode,
+ NgResourceCode = ng.NgResourceCode
+ }).ToList()
+ };
+
+ string requestJson = System.Text.Json.JsonSerializer.Serialize(mesRequest);
+
+ // 4. 璋冪敤MES鎺ュ彛锛堝悓姝ユ柟娉曪級
+ var mesResult = _mesService.ContainerNgReport(mesRequest);
+ stopwatch.Stop();
+
+ // 5. 璁板綍鏃ュ織
+ await _mesLogService.LogAsync(new MesApiLogDto
+ {
+ ApiType = "ContainerNgReport",
+ RequestJson = requestJson,
+ ResponseJson = System.Text.Json.JsonSerializer.Serialize(mesResult),
+ IsSuccess = mesResult.IsSuccess,
+ ErrorMessage = mesResult.ErrorMessage,
+ ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
+ Creator = App.User.UserName
+ });
+
+ // 6. 杩斿洖缁撴灉
+ if (mesResult.IsSuccess)
+ {
+ return response.OK("NG鐢佃姱涓婃姤鎴愬姛");
+ }
+ else
+ {
+ return response.Error($"MES鎺ュ彛璋冪敤澶辫触: {mesResult.ErrorMessage}");
+ }
+ }
+ catch (System.Exception ex)
+ {
+ stopwatch.Stop();
+
+ // 璁板綍閿欒鏃ュ織
+ await _mesLogService.LogAsync(new MesApiLogDto
+ {
+ ApiType = "ContainerNgReport",
+ IsSuccess = false,
+ ErrorMessage = ex.Message,
+ ElapsedMs = (int)stopwatch.ElapsedMilliseconds,
+ Creator = App.User.UserName
+ });
+
+ return response.Error($"NG鐢佃姱涓婃姤澶辫触: {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