This commit is contained in:
liangjunyu
2025-09-19 10:04:01 +08:00
parent 0ec9c70e60
commit 63b5b02b23
3 changed files with 48 additions and 5 deletions

View File

@@ -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",

View File

@@ -14,13 +14,13 @@ namespace RB_MES_API.Context
/// </summary>
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<int> HashCode { get; set; }= new List<int>();
public static List<int> HashCode { get; set; } = new List<int>();
public static List<SystemProfile> sysprofile = new List<SystemProfile>();
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))
{

View File

@@ -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;
}
/// <summary>
/// 替换或添加URL中的端口号支持指定协议
/// </summary>
/// <param name="input"></param>
/// <param name="newPort"></param>
/// <param name="protocol"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 批量提交已保存的单据
/// </summary>