diff --git a/Config/appsettings.json b/Config/appsettings.json index 9ff7b79..8d94542 100644 --- a/Config/appsettings.json +++ b/Config/appsettings.json @@ -88,6 +88,7 @@ "X-KDApi-AppSec": "df3e8fd75c794f11af72faa6f6df0d48", "X-KDApi-LCID": "2052", "X-KDApi-ServerUrl": "http://192.168.0.233/k3cloud/", + "PRD_PickMtrl_Port": 1500, "CustomRequestRemoteSql": "", "VoucherGroup": "记", "MesSchema": "TEST", diff --git a/Context/LocalStatic/LocalStaticRequest.cs b/Context/LocalStatic/LocalStaticRequest.cs index 6bbd463..9ae47f6 100644 --- a/Context/LocalStatic/LocalStaticRequest.cs +++ b/Context/LocalStatic/LocalStaticRequest.cs @@ -14,13 +14,13 @@ namespace RB_MES_API.Context /// public static class LocalStaticRequest { - public static K3CloudApi cloudApi { get; set; }=new K3CloudApi(); + public static K3CloudApi cloudApi { get; set; } = new K3CloudApi(); public static bool Islogin { get; set; } = false; - public static string LoginMsg { get; set; }=string.Empty; + public static string LoginMsg { get; set; } = string.Empty; public static bool NeedRefresh { get; set; } = true; - public static List HashCode { get; set; }= new List(); + public static List HashCode { get; set; } = new List(); public static List sysprofile = new List(); - public static string GetSystemProfile(int categoryid,string key) + public static string GetSystemProfile(int categoryid, string key) { if (sysprofile.Any(s => s.FCategoryID == categoryid && s.FKey == key)) { diff --git a/Controllers/EnpowerApiController.cs b/Controllers/EnpowerApiController.cs index 3beadcb..9609298 100644 --- a/Controllers/EnpowerApiController.cs +++ b/Controllers/EnpowerApiController.cs @@ -1,4 +1,5 @@ using Kingdee.CDP.WebApi.SDK; +using Kingdee.CDP.WebApi.SDK.DataEntity; using Microsoft.AspNetCore.Mvc; using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; @@ -1060,7 +1061,20 @@ namespace RB_MES_API.Controllers Stopwatch stopwatch = new Stopwatch(); // 开始计时 stopwatch.Start(); - string result = LocalStaticRequest.cloudApi.BatchSave(formid, jsonstr); + + string result = ""; + + string setPort = ApiSettingsHelper.GetConfig($"{formid}_Port"); + if (!setPort.IsNullOrEmpty()) + { + string serverUrl = ApiSettingsHelper.GetConfig("X-KDApi-ServerUrl"); + serverUrl = ReplaceOrAddPortAdvanced(serverUrl, setPort); + result = new K3CloudApi(serverUrl).BatchSave(formid, jsonstr); + } + else + { + result = LocalStaticRequest.cloudApi.BatchSave(formid, jsonstr); + } // 停止计时 stopwatch.Stop(); // 获取执行时间 @@ -1092,6 +1106,34 @@ namespace RB_MES_API.Controllers } return data; } + + /// + /// 替换或添加URL中的端口号(支持指定协议) + /// + /// + /// + /// + /// + public static string ReplaceOrAddPortAdvanced(string input, string newPort, string protocol = "http") + { + // 构建协议特定的模式 + string protocolPattern = string.IsNullOrEmpty(protocol) ? @"(https?|ftp)://" : $"{protocol}://"; + + // 匹配已有端口号 + string patternWithPort = $@"({protocolPattern}[^/]+?):\d+"; + // 匹配没有端口号 + string patternWithoutPort = $@"({protocolPattern}[^/:/]+)(?=/|$)"; + + // 先尝试替换已有端口号 + string result = Regex.Replace(input, patternWithPort, $"$1:{newPort}"); + + // 如果没有端口号被替换,尝试添加端口号 + if (result == input) + result = Regex.Replace(input, patternWithoutPort, $"$1:{newPort}"); + + return result; + } + /// /// 批量提交已保存的单据 ///