|
@@ -20,9 +20,10 @@ namespace TEAMModelOS.API.Controllers.Core
|
|
|
// [Authorize]
|
|
|
public class CommonController : BaseController
|
|
|
{
|
|
|
- public readonly IWebHostEnvironment webHostEnvironment;
|
|
|
+ public readonly IWebHostEnvironment webHostEnvironment;
|
|
|
|
|
|
- public CommonController(IWebHostEnvironment _webHostEnvironment) {
|
|
|
+ public CommonController(IWebHostEnvironment _webHostEnvironment)
|
|
|
+ {
|
|
|
webHostEnvironment = _webHostEnvironment;
|
|
|
|
|
|
}
|
|
@@ -32,18 +33,22 @@ namespace TEAMModelOS.API.Controllers.Core
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("SubjectDefault")]
|
|
|
- public async Task<BaseJosnRPCResponse> SubjectDefault(JosnRPCRequest<bool> request)
|
|
|
+ public async Task<BaseJosnRPCResponse> SubjectDefault(JosnRPCRequest<bool> request)
|
|
|
{
|
|
|
JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
|
|
|
string contentRootPath = webHostEnvironment.ContentRootPath;
|
|
|
- JsonDocument document= await GetJson(contentRootPath, "Subject/SubjectDefault");
|
|
|
- if (request.@params) {
|
|
|
+ JsonDocument document = await GetJson(contentRootPath, "/JsonFile/Subject/SubjectDefault.json");
|
|
|
+ if (!request.@params)
|
|
|
+ {
|
|
|
List<JsonElement> jsonElements = new List<JsonElement>();
|
|
|
foreach (JsonElement element in document.RootElement.EnumerateArray())
|
|
|
{
|
|
|
- string date = element.GetProperty("lang").GetString();
|
|
|
- if (!string.IsNullOrEmpty(date)&&date.Equals(request.lang)) {
|
|
|
- jsonElements.Add(element);
|
|
|
+ if (element.TryGetProperty("lang", out JsonElement json))
|
|
|
+ {
|
|
|
+ if (json.GetString().Equals(request.lang))
|
|
|
+ {
|
|
|
+ jsonElements.Add(element);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return builder.Data(jsonElements).build();
|
|
@@ -52,18 +57,15 @@ namespace TEAMModelOS.API.Controllers.Core
|
|
|
{
|
|
|
return builder.Data(document.RootElement).build();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
public static async Task<JsonDocument> GetJson(string contentRootPath, string name)
|
|
|
{
|
|
|
- //string webRootPath = _hostingEnvironment.WebRootPath;
|
|
|
-
|
|
|
try
|
|
|
{
|
|
|
- string path = contentRootPath + "/JsonFile/" + name + ".json";
|
|
|
- //获取正在占用的文件
|
|
|
- var fs = await System.IO. File.ReadAllTextAsync(path,Encoding.UTF8);
|
|
|
- return JsonDocument.Parse(fs);
|
|
|
+ string path = contentRootPath + name;
|
|
|
+ var fs = await System.IO.File.ReadAllTextAsync(path, Encoding.UTF8);
|
|
|
+ return JsonDocument.Parse(fs);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|