diff --git a/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs b/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs index 535b2aea3..bf2d433ed 100644 --- a/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs +++ b/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs @@ -807,9 +807,10 @@ namespace IRaCIS.Core.Application.Service.Allocation //var defalutSortArray = new string[] { nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.IsUrgent) + " desc", nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.SubjectId), nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.VisitTaskNum) }; - var defalutSortArray = new string[] { nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.TaskState), + var defalutSortArray = new string[] { nameof(ReReadingTaskView.RequestReReadingResultEnum) , nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.IsUrgent) + " desc", + nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.TaskState), nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.SubjectId),nameof(ReReadingTaskView.OriginalReReadingTask) + "." + nameof(ReReadingTaskView.OriginalReReadingTask.VisitTaskNum) }; diff --git a/IRaCIS.Core.Application/Service/Common/SystemMonitor.cs b/IRaCIS.Core.Application/Service/Common/SystemMonitor.cs index cbe58cf9a..004aff76f 100644 --- a/IRaCIS.Core.Application/Service/Common/SystemMonitor.cs +++ b/IRaCIS.Core.Application/Service/Common/SystemMonitor.cs @@ -14,8 +14,8 @@ using SharpCompress.Common; using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Encodings.Web; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Newtonsoft.Json; namespace IRaCIS.Core.Application.Service.Common { @@ -109,43 +109,11 @@ namespace IRaCIS.Core.Application.Service.Common //jObject.WriteTo(jsonTextWriter); #endregion - // Read JSON file into a JObject - //var json = File.ReadAllText("appsettings.json"); - //var jObject = JObject.Parse(json); - //// Update or add the property - //jObject[key] = newValue; - //// Get the property to update - //var property = jObject.Property(key); - //// Get the comment before the property - //var comment = property.Previous?.Type == JTokenType.Comment ? property.Previous : null; - //// Write the updated JSON back to the file, preserving the comments - //using (var reader = new JsonTextReader(new StringReader(json))) - //using (var writer = new JsonTextWriter(new StreamWriter("appsettings.json"))) - //{ - // writer.Formatting = Formatting.Indented; - // while (reader.Read()) - // { - // if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == newValue) - // { - // // Write the updated property value - // writer.WritePropertyName(key); - // writer.WriteValue(newValue); - // // Write the comment after the property - // if (property.Next?.Type == JTokenType.Comment) - // { - // writer.WriteComment(property.Next.ToString()); - // } - // continue; - // } - // // Write all other tokens - // writer.WriteToken(reader.TokenType, reader.Value); - // } - //} //var json = File.ReadAllText("appsettings.json"); - //var jObject = JObject.Parse(json, new JsonLoadSettings { CommentHandling = CommentHandling.Load }); + //var jObject = JToken.Parse(json, new JsonLoadSettings { CommentHandling = CommentHandling.Load,DuplicatePropertyNameHandling=DuplicatePropertyNameHandling.Ignore }); //// Update or add the property //jObject[key] = newValue; @@ -155,7 +123,8 @@ namespace IRaCIS.Core.Application.Service.Common //{ // PreserveReferencesHandling = PreserveReferencesHandling.Objects, // Formatting = Formatting.Indented, - // StringEscapeHandling = StringEscapeHandling.Default + // StringEscapeHandling = StringEscapeHandling.Default, + //}; //var updatedJson = JsonConvert.SerializeObject(jObject, settings); //File.WriteAllText("appsettings.json", updatedJson); @@ -207,54 +176,51 @@ namespace IRaCIS.Core.Application.Service.Common // Console.WriteLine(newJson); - //var json = File.ReadAllText("appsettings.json"); - //var jObject = JObject.Parse(json); - //var property = jObject.Property(key); - //// 如果属性不存在,则添加属性 - //if (property == null) - //{ - // jObject.Add(new JProperty(key, newValue)); - //} - //// 否则,修改属性 - //else - //{ - // property.Value = newValue; - //} - //using (var reader = new JsonTextReader(new StringReader(json))) - //using (var writer = new JsonTextWriter(new StreamWriter("appsettings.json"))) - //{ - // writer.Formatting = Formatting.Indented; - // while (reader.Read()) - // { - // if (reader.TokenType == JsonToken.Comment) - // { - // writer.WriteComment((string)reader.Value); - // } - // else - // { - // // 将更改后的JSON写回文件中 - // writer.WriteToken(reader.TokenType, jObject); - // break; - // } - // } - //} - // 读取 JSON 文件,并保留注释 - string json = File.ReadAllText("appsettings.json"); - JsonSerializerSettings settings = new JsonSerializerSettings + + + // 读取 Json 文件 + string jsonFilePath = "appsettings.json"; + + var json = File.ReadAllText("appsettings.json"); + + JObject jsonObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling=CommentHandling.Load}); + // 获取 UpdateConfig 属性所在的节点 + JToken updateConfigNode = jsonObject.SelectToken("UpdateConfig"); + + JProperty updateConfigProperty = (JProperty)updateConfigNode.Parent; + JObject updateConfigParent = (JObject)updateConfigProperty.Value; + + + + // 向 updateConfigParent 添加或者属性 + updateConfigParent[key] = newValue; + + + // 将更改保存回 Json 文件 + //File.WriteAllText(jsonFilePath, jsonObject.ToString()); + + using (var reader = new JsonTextReader(new StringReader(json))) + using (var writer = new JsonTextWriter(new StreamWriter("appsettings.json"))) { - PreserveReferencesHandling = PreserveReferencesHandling.All, - Formatting = Formatting.Indented, - - }; - dynamic data = JsonConvert.DeserializeObject(json, settings); + while (reader.Read()) + { + if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == key) + { + // Write the updated property value + writer.WritePropertyName(key); + writer.WriteValue(newValue); + + continue; + } + + // Write all other tokens + writer.WriteToken(reader.TokenType, reader.Value); + } + } + - // 修改 JSON 对象 - data.foo = "bar"; - // 将修改后的对象序列化为字符串,并写回原始 JSON 文件 - string output = JsonConvert.SerializeObject(data, settings); - File.WriteAllText("appsettings.json", output); } }