|
@@ -15,6 +15,9 @@ using Microsoft.Extensions.Options;
|
|
|
using TEAMModelBI.Tool.Extension;
|
|
|
using TEAMModelOS.SDK.DI;
|
|
|
using TEAMModelBI.Filter;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using System.Linq;
|
|
|
+using TEAMModelBI.Models;
|
|
|
|
|
|
namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
{
|
|
@@ -38,7 +41,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- ///
|
|
|
+ /// 获取应用配置文件
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("get-config")]
|
|
@@ -61,7 +64,7 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 配置文件修改
|
|
|
+ /// 应用配置文件修改
|
|
|
/// </summary>
|
|
|
/// <param name="jsonElement"></param>
|
|
|
/// <returns></returns>
|
|
@@ -247,9 +250,153 @@ namespace TEAMModelBI.Controllers.DingDingStruc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 获取当前应用的
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "admin")]
|
|
|
+ [HttpPost("get-allconfig")]
|
|
|
+ public async Task<IActionResult> GetAllConfig()
|
|
|
+ {
|
|
|
+ var builder = $"{_hostingEnvironment.ContentRootPath}/JsonFile/SystemConfig.json";
|
|
|
+ StreamReader streamReader = new(new FileStream(builder, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
|
|
|
+ StringBuilder stringBuilder = new();
|
|
|
+ string text;
|
|
|
+ while ((text = streamReader.ReadLine()) != null)
|
|
|
+ {
|
|
|
+ stringBuilder.Append(text.ToString());
|
|
|
+ }
|
|
|
+ string input = stringBuilder.ToString();
|
|
|
+ List<SysConfig> allConfigs = input.ToObject<List<SysConfig>>();
|
|
|
+
|
|
|
+ return Ok(new { state = 200, allConfigs });
|
|
|
+ }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 修改或者添加配置文件,到多个配置文件中
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sysConfig"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "admin")]
|
|
|
+ [HttpPost("set-singleconfig")]
|
|
|
+ public async Task<IActionResult> SetSingleConfig(SysConfig sysConfig)
|
|
|
+ {
|
|
|
+ var builder = $"{_hostingEnvironment.ContentRootPath}/JsonFile/SystemConfig.json";
|
|
|
+ StreamReader streamReader = new(new FileStream(builder, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
|
|
|
+ StringBuilder stringBuilder = new();
|
|
|
+ string text;
|
|
|
+ while ((text = streamReader.ReadLine()) != null)
|
|
|
+ {
|
|
|
+ stringBuilder.Append(text.ToString());
|
|
|
+ }
|
|
|
+ string input = stringBuilder.ToString();
|
|
|
|
|
|
+ List<SysConfig> allConfigs = new();
|
|
|
+ if (!string.IsNullOrEmpty(input))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ allConfigs = input.ToObject<List<SysConfig>>();
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ allConfigs.Add(sysConfig);
|
|
|
+ }
|
|
|
+ var tempSysConfig = allConfigs.Where(x => x.site.Equals(sysConfig.site)).FirstOrDefault();
|
|
|
+ if (tempSysConfig != null)
|
|
|
+ {
|
|
|
|
|
|
+ tempSysConfig.site = sysConfig.site;
|
|
|
+ tempSysConfig.proDeptId = sysConfig.proDeptId;
|
|
|
+ tempSysConfig.clientKey = sysConfig.clientKey;
|
|
|
+ tempSysConfig.dDAuth = sysConfig.dDAuth;
|
|
|
+ tempSysConfig.azureClient = sysConfig.azureClient;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ allConfigs.Add(sysConfig);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ allConfigs.Add(sysConfig);
|
|
|
+ }
|
|
|
+
|
|
|
+ string ListJson = JsonConvert.SerializeObject(allConfigs, Formatting.Indented);
|
|
|
+ System.IO.File.WriteAllText(builder, ListJson);
|
|
|
+
|
|
|
+ return Ok(new { state = 200, allConfigs });
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 切换站点
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="jsonElement"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "admin")]
|
|
|
+ [HttpPost("cut-site")]
|
|
|
+ public async Task<IActionResult> CutSite(JsonElement jsonElement)
|
|
|
+ {
|
|
|
+ if (!jsonElement.TryGetProperty("site", out JsonElement site)) return BadRequest();
|
|
|
+ var builder = $"{_hostingEnvironment.ContentRootPath}/JsonFile/SystemConfig.json";
|
|
|
+ var formalDeploy = $"{_hostingEnvironment.ContentRootPath}/appsettings.json";
|
|
|
+ var extendDeploy = $"{_hostingEnvironment.ContentRootPath}/appsettings.Development.json";
|
|
|
+
|
|
|
+ StreamReader streamReader = new(new FileStream(builder, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
|
|
|
+ StringBuilder stringBuilder = new();
|
|
|
+ string text;
|
|
|
+ while ((text = streamReader.ReadLine()) != null)
|
|
|
+ {
|
|
|
+ stringBuilder.Append(text.ToString());
|
|
|
+ }
|
|
|
+ string input = stringBuilder.ToString();
|
|
|
+
|
|
|
+ List<SysConfig> allConfigs = input.ToObject<List<SysConfig>>();
|
|
|
+
|
|
|
+ var tempSysConfig = allConfigs.Where(x => x.site.Equals($"{site}")).FirstOrDefault();
|
|
|
+
|
|
|
+ // 有排版 注释全无
|
|
|
+ StreamReader reader = System.IO.File.OpenText(formalDeploy);
|
|
|
+ JsonTextReader jsonTextReader = new(reader);
|
|
|
+ JObject jsonObject = (JObject)JToken.ReadFrom(jsonTextReader);
|
|
|
+
|
|
|
+ StreamReader readerDeve = System.IO.File.OpenText(extendDeploy);
|
|
|
+ JsonTextReader jsonTextReaderDeve = new(readerDeve);
|
|
|
+ JObject jsonObjectDeve = (JObject)JToken.ReadFrom(jsonTextReaderDeve);
|
|
|
+
|
|
|
+ if (tempSysConfig != null)
|
|
|
+ {
|
|
|
+ jsonObject["Option"]["Location"] = tempSysConfig.site;
|
|
|
+ jsonObject["CustomParam"]["proDeptId"] = tempSysConfig.proDeptId;
|
|
|
+
|
|
|
+ jsonObject["CoreService"]["clientID"] = tempSysConfig.clientKey.clientID;
|
|
|
+ jsonObject["CoreService"]["clientSecret"] = tempSysConfig.clientKey.clientSecret;
|
|
|
+
|
|
|
+ jsonObject["DingDingAuth"]["Agentld"] = tempSysConfig.dDAuth.agebtId;
|
|
|
+ jsonObject["DingDingAuth"]["appKey"] = tempSysConfig.dDAuth.appKey;
|
|
|
+ jsonObject["DingDingAuth"]["appSecret"] = tempSysConfig.dDAuth.appSecret;
|
|
|
+
|
|
|
+ jsonObject["Azure"]["Storage"]["ConnectionString"] = tempSysConfig.azureClient.storage;
|
|
|
+ jsonObject["Azure"]["Cosmos"]["ConnectionString"] = tempSysConfig.azureClient.cosmos;
|
|
|
+ jsonObject["Azure"]["Redis"]["ConnectionString"] = tempSysConfig.azureClient.redis;
|
|
|
+ jsonObject["Azure"]["ServiceBus"]["ConnectionString"] = tempSysConfig.azureClient.servicBus;
|
|
|
+ }
|
|
|
+ else return Ok(new { state = 404,msg = "未找到你需要的参数" });
|
|
|
+
|
|
|
+ reader.Close();
|
|
|
+ string output = JsonConvert.SerializeObject(jsonObject, Formatting.Indented); //是否json文件有缩进
|
|
|
+ System.IO.File.WriteAllText(formalDeploy, output);
|
|
|
+
|
|
|
+ readerDeve.Close();
|
|
|
+ string outputDeve = JsonConvert.SerializeObject(jsonObjectDeve, Formatting.Indented); //是否json文件有缩进
|
|
|
+ System.IO.File.WriteAllText(extendDeploy, outputDeve);
|
|
|
+
|
|
|
+ return Ok(new { state = 200, SysConfig = tempSysConfig });
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|