CrazyIter_Bin 1 year ago
parent
commit
49c394600f

+ 109 - 0
TEAMModelOS.SDK/Models/Service/OpenApiService.cs

@@ -2302,7 +2302,116 @@ namespace TEAMModelOS.SDK
                 return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务器错误" };
                 return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务器错误" };
             }
             }
         }
         }
+
+        public static async Task<ResponseData<dynamic>> UpsertSchoolItem(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureRedisFactory azureRedis, JsonElement jsonElement, string school)
+        {
+            return new ResponseData<dynamic>() { };
+        }
     }
     }
+
+    /*
+
+       {
+           "id": "", //题目id,id值为空则新增,不为空尝试更新,更新失败则新增
+           "level": 1, //1-5题目难度
+           "knowledge": [
+               "知识点1",
+               "知识点2"
+           ], //知识点
+           "answer": [
+               "答案1",
+               "答案2"
+           ], //答案,  "单选题","多选题","有序多选题","判断题"等的答案为[A,B,C,D,E]等数组,如果是填空题答案为字符串数组,问答题答案为字符串。
+           "explain": "解析",
+           "type": "single", //题目类型,"single": "单选题",  "multiple": "多选题", "sortmultiple": "有序多选题", "judge": "判断题",  "complete": "填空题",  "subjective": "问答题",  "compose": "综合题"
+           "pid": "综合题父级题目id",
+           "field": 1, //布鲁姆认知层次 1:记忆|2:理解|3:应用|4:分析|:5评价|6:创造
+           "subject": "语文", //学科,语文/数学/英语/物理/化学/地理/历史/生物/政治, 如果有其他学科,按学科名称传递即可。
+           "grade": [
+               "1",
+               "2",
+               "3",
+               "4"
+           ], //年级,1-6年级/1-5年级(小学),7-9年级/6-9年级(初中),10-12年级(高中)
+           "question": "题干信息",
+           "option":[{"code":"A","value":"选项A的内容"},{ "code":"B","value":"选项B的内容"}],//单选,多选,有序多选题,判断题的选项。其中判断题可为[{"code":"A","value":"正确/对"},{"code":"B","value":"错误/错"}]
+           "children":[
+               {}//子题目,包含题型"单选题",    "多选题",  "有序多选题", "判断题",    "填空题",    "问答题"
+           ]
+       }
+        **/
+    /// <summary>
+    /// 
+    /// 
+    /// </summary>
+    public class OItem
+    {
+        /// <summary>
+        /// //题目id,id值为空则新增,不为空尝试更新,更新失败则新增
+        /// </summary>
+        public string id { get; set; }
+
+        /// <summary>
+        /// 1-5题目难度
+        /// </summary>
+        public int level { get; set; }
+
+        /// <summary>
+        /// 知识点
+        /// </summary>
+        public List<string> knowledge { get; set; } = new List<string>();
+
+        /// <summary>
+        /// 答案,  "单选题","多选题","有序多选题","判断题"等的答案为[A,B,C,D,E]等数组,如果是填空题答案为字符串数组,问答题答案为字符串。
+        /// </summary>
+        public List<string> answer { get; set; } = new List<string>();
+
+        /// <summary>
+        /// 解析
+        /// </summary>
+        public string explain { get; set; }
+
+        /// <summary>
+        /// 题目类型,"single": "单选题",  "multiple": "多选题", "sortmultiple": "有序多选题", "judge": "判断题",  "complete": "填空题",  "subjective": "问答题",  "compose": "综合题"
+        /// </summary>
+        public string type { get; set; }
+
+        /// <summary>
+        /// 综合题父级题目id,当前题目是某一综合题的子题时才填写,否则为null,
+        /// </summary>
+        public string pid { get; set; }
+
+        /// <summary>
+        /// 布鲁姆认知层次 1:记忆|2:理解|3:应用|4:分析|:5评价|6:创造
+        /// </summary>
+        public int field { get; set; } = 1;
+
+        /// <summary>
+        /// 学科,语文/数学/英语/物理/化学/地理/历史/生物/政治, 如果有其他学科,按学科名称传递即可。
+        /// </summary>
+        public string subject { get; set; }
+
+        /// <summary>
+        /// 年级,1-6年级/1-5年级(小学),7-9年级/6-9年级(初中),10-12年级(高中)
+        /// </summary>
+        public List<int> grade { get; set; } = new List<int>();
+
+        /// <summary>
+        /// 题干信息
+        /// </summary>
+        public string question { get; set; }
+
+        /// <summary>
+        /// 单选,多选,有序多选题,判断题的选项。其中判断题可为[{"code":"A","value":"正确/对"},{"code":"B","value":"错误/错"}]
+        /// </summary>
+        public List<CodeValue> option { get; set; } = new List<CodeValue>();
+
+        /// <summary>
+        /// 子题目,包含题型"单选题",    "多选题",  "有序多选题", "判断题",    "填空题",    "问答题"
+        /// </summary>
+        public List<OItem> children { get; set; } = new List<OItem>();
+    }
+
     public class OCourseBase
     public class OCourseBase
     {
     {
         public string tmdname { get; set; }
         public string tmdname { get; set; }

+ 244 - 99
TEAMModelOS/Controllers/Both/ItemController.cs

@@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Http;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Extension;
 using Azure.Cosmos;
 using Azure.Cosmos;
 using System.Text;
 using System.Text;
-using TEAMModelOS.SDK.DI;
 using Microsoft.Extensions.Options;
 using Microsoft.Extensions.Options;
 using Azure.Messaging.ServiceBus;
 using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Configuration;
@@ -27,7 +26,7 @@ namespace TEAMModelOS.Controllers
 {
 {
     [ProducesResponseType(StatusCodes.Status200OK)]
     [ProducesResponseType(StatusCodes.Status200OK)]
     [ProducesResponseType(StatusCodes.Status400BadRequest)]
     [ProducesResponseType(StatusCodes.Status400BadRequest)]
-    
+
     [Route("item")]
     [Route("item")]
     [ApiController]
     [ApiController]
     public class ItemController : ControllerBase
     public class ItemController : ControllerBase
@@ -41,7 +40,7 @@ namespace TEAMModelOS.Controllers
         private readonly AzureRedisFactory _azureRedis;
         private readonly AzureRedisFactory _azureRedis;
         public IConfiguration _configuration { get; set; }
         public IConfiguration _configuration { get; set; }
         public ItemController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
         public ItemController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
-             AzureRedisFactory azureRedis,AzureServiceBusFactory serviceBus, IConfiguration configuration)
+             AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration)
         {
         {
             _azureCosmos = azureCosmos;
             _azureCosmos = azureCosmos;
             _snowflakeId = snowflakeId;
             _snowflakeId = snowflakeId;
@@ -64,7 +63,8 @@ namespace TEAMModelOS.Controllers
 #if !DEBUG
 #if !DEBUG
         [Authorize(Roles = "IES")]
         [Authorize(Roles = "IES")]
 #endif
 #endif
-        public async Task<IActionResult> CondCount(JsonElement request) {
+        public async Task<IActionResult> CondCount(JsonElement request)
+        {
             try
             try
             {
             {
                 var client = _azureCosmos.GetCosmosClient();
                 var client = _azureCosmos.GetCosmosClient();
@@ -80,7 +80,8 @@ namespace TEAMModelOS.Controllers
 
 
                         itemCond = value.ToString().ToObject<ItemCond>();
                         itemCond = value.ToString().ToObject<ItemCond>();
                     }
                     }
-                    else {
+                    else
+                    {
                         List<ItemInfo> items = new List<ItemInfo>();
                         List<ItemInfo> items = new List<ItemInfo>();
                         var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where   c.periodId='{periodId}' and c.pid= null  ";
                         var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where   c.periodId='{periodId}' and c.pid= null  ";
                         await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{schoolCode}") }))
                         await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{schoolCode}") }))
@@ -111,10 +112,11 @@ namespace TEAMModelOS.Controllers
                 else if (!string.IsNullOrEmpty($"{schoolCode}"))
                 else if (!string.IsNullOrEmpty($"{schoolCode}"))
                 {
                 {
                     List<ItemCond> itemConds = new List<ItemCond>();
                     List<ItemCond> itemConds = new List<ItemCond>();
-                    School school =await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{schoolCode}", new PartitionKey("Base"));
+                    School school = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{schoolCode}", new PartitionKey("Base"));
                     List<string> nocachePeriods = new List<string>();
                     List<string> nocachePeriods = new List<string>();
-                    foreach (var period in school.period) {
-                        var value = await _azureRedis.GetRedisClient(8).HashGetAsync($"ItemCond:{schoolCode}", $"{period.id}"); 
+                    foreach (var period in school.period)
+                    {
+                        var value = await _azureRedis.GetRedisClient(8).HashGetAsync($"ItemCond:{schoolCode}", $"{period.id}");
                         ItemCond itemCond = null;
                         ItemCond itemCond = null;
                         if (value != default && !value.IsNullOrEmpty)
                         if (value != default && !value.IsNullOrEmpty)
                         {
                         {
@@ -122,14 +124,15 @@ namespace TEAMModelOS.Controllers
                             itemCond = value.ToString().ToObject<ItemCond>();
                             itemCond = value.ToString().ToObject<ItemCond>();
                             itemConds.Add(itemCond);
                             itemConds.Add(itemCond);
                         }
                         }
-                        else {
+                        else
+                        {
                             nocachePeriods.Add(period.id);
                             nocachePeriods.Add(period.id);
                         }
                         }
                     }
                     }
                     string nocachePeriodsql = "";
                     string nocachePeriodsql = "";
                     if (nocachePeriods.IsNotEmpty())
                     if (nocachePeriods.IsNotEmpty())
-                    { 
-                        string  sql =   string.Join(',', nocachePeriods.Select(x => $"'{x}'"));
+                    {
+                        string sql = string.Join(',', nocachePeriods.Select(x => $"'{x}'"));
                         nocachePeriodsql = $" and  c.periodId in ({sql})";
                         nocachePeriodsql = $" and  c.periodId in ({sql})";
                         List<ItemInfo> items = new List<ItemInfo>();
                         List<ItemInfo> items = new List<ItemInfo>();
                         var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field,c.scope FROM c where    c.pid= null  {nocachePeriodsql}";
                         var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field,c.scope FROM c where    c.pid= null  {nocachePeriodsql}";
@@ -175,7 +178,8 @@ namespace TEAMModelOS.Controllers
 
 
                         itemCond = value.ToString().ToObject<ItemCond>();
                         itemCond = value.ToString().ToObject<ItemCond>();
                     }
                     }
-                    else {
+                    else
+                    {
                         List<ItemInfo> items = new List<ItemInfo>();
                         List<ItemInfo> items = new List<ItemInfo>();
                         var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where c.pid= null  ";
                         var queryslt = $"SELECT c.gradeIds,c.subjectId,c.periodId,c.type,c.level,c.field ,c.scope FROM c where c.pid= null  ";
                         await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{tmdid}") }))
                         await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{tmdid}") }))
@@ -185,7 +189,8 @@ namespace TEAMModelOS.Controllers
                         itemCond = new ItemCond() { id = $"{tmdid}", code = $"ItemCond", pk = "ItemCond", ttl = -1, count = items.Count };
                         itemCond = new ItemCond() { id = $"{tmdid}", code = $"ItemCond", pk = "ItemCond", ttl = -1, count = items.Count };
                         items.ForEach(z =>
                         items.ForEach(z =>
                         {
                         {
-                            if (!string.IsNullOrEmpty(z.type)) {
+                            if (!string.IsNullOrEmpty(z.type))
+                            {
                                 ItemService.CountItemCond(z, null, itemCond);
                                 ItemService.CountItemCond(z, null, itemCond);
                             }
                             }
                         });
                         });
@@ -225,102 +230,225 @@ namespace TEAMModelOS.Controllers
             {
             {
                 Dictionary<string, ItemCondDto> dict = new Dictionary<string, ItemCondDto>();
                 Dictionary<string, ItemCondDto> dict = new Dictionary<string, ItemCondDto>();
                 itemInfos = items.ToObject<List<ItemInfo>>();
                 itemInfos = items.ToObject<List<ItemInfo>>();
-                foreach (var itemInfo in itemInfos) {
-                    itemInfo.ttl = -1;
-                    itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
-                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
-                    if (option.ToString().Equals("insert"))
+                if (itemInfos.IsNotEmpty())
+                {
+                    IEnumerable<string> ids = itemInfos.Where(x => !string.IsNullOrWhiteSpace(x.id)).Select(x => x.id);
+                    List<ItemInfo> dbIDs = new List<ItemInfo>();
+                    if (ids!=null  && ids.Count()>0)
                     {
                     {
-                        itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                        if (!itemInfo.code.Contains("Item"))
+                        string scope = itemInfos[0].scope.Equals("school") ? Constant.School : Constant.Teacher;
+                        string code = !itemInfos[0].code.Contains("Item") ? $"Item-" + itemInfos[0].code : itemInfos[0].code;
+                        string sql = $"select value c from c where c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))} )";
+                        var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, scope).GetList<ItemInfo>(sql, code);
+                        if (result.list.IsNotEmpty())
                         {
                         {
-                            itemInfo.code = "Item-" + itemInfo.code;
+                            dbIDs= result.list;
                         }
                         }
-                        var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
-                        if (response.Status == 200)
+                    }
+                    {
+                        //处理数据库没有的数据
+                        var notinDB = itemInfos.ExceptBy(dbIDs.Select(x=>x.id),x=>x.id);
+                        if (notinDB!=null && notinDB.Count()>0) 
                         {
                         {
-                            return Ok();
+                            foreach (var itemInfo in notinDB) 
+                            {
+                                try {
+                                    itemInfo.ttl = -1;
+                                    itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
+                                    await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
+                                    itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                                    if (!itemInfo.code.Contains("Item"))
+                                    {
+                                        itemInfo.code = "Item-" + itemInfo.code;
+                                    }
+                                    if (itemInfo.scope.Equals("private"))
+                                    {
+                                        if (string.IsNullOrEmpty(itemInfo.pid))
+                                        {
+                                            if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}"))
+                                            {
+                                                dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed= $"{itemInfo.code.Replace("Item-", "")}", scope= "private" });
+                                            }
+                                        }
+                                        await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
+                                    }
+                                    else
+                                    {
+                                        if (string.IsNullOrEmpty(itemInfo.pid))
+                                        {
+                                            if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}"))
+                                            {
+                                                dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed=$"{itemInfo.periodId}", scope = "school" });
+                                            }
+                                        }
+                                        await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
+
+                                    }
+                                } catch (Exception ex) 
+                                {
+                                    await  _dingDing.SendBotMsg($"{_option.Location},题目批量保存报错:,{ex.Message}\n{ex.StackTrace}\n{itemInfo.ToJsonString()}", GroupNames.成都开发測試群組);
+                                }
+                            }
                         }
                         }
-                        else
-                        {
+                    }
+                    {
+                        //处理更新的
+                        var dbs = dbIDs.Select(x => x.id);
+                        var inDB = itemInfos.Where(x => dbs.Contains(x.id));
+                        foreach (var itemInfo in inDB) {
+                            itemInfo.ttl = -1;
+                            itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
+                            await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
+
+                            itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                             if (itemInfo.scope.Equals("private"))
                             if (itemInfo.scope.Equals("private"))
                             {
                             {
+                                if (!itemInfo.code.Contains("Item"))
+                                {
+                                    itemInfo.code = "Item-" + itemInfo.code;
+                                }
                                 if (string.IsNullOrEmpty(itemInfo.pid))
                                 if (string.IsNullOrEmpty(itemInfo.pid))
                                 {
                                 {
                                     if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}"))
                                     if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}"))
                                     {
                                     {
-                                        dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}",filed= $"{itemInfo.code.Replace("Item-", "")}", scope= "private" });
+                                        dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.code.Replace("Item-", "")}", scope = "private" });
+                                    }
+                                    //ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
+                                    ItemInfo olditemInfo = dbIDs.Find(x => x.id.Equals(itemInfo.id)  && x.code.Equals(itemInfo.code));
+                                    if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}"))
+                                    {
+                                        dict.Add($"{olditemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.code.Replace("Item-", "")}", scope = "private" });
                                     }
                                     }
                                 }
                                 }
-                                await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
+                                await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
+
                             }
                             }
                             else
                             else
                             {
                             {
+                                if (!itemInfo.code.Contains("Item"))
+                                {
+                                    itemInfo.code = "Item-" + itemInfo.code;
+                                }
                                 if (string.IsNullOrEmpty(itemInfo.pid))
                                 if (string.IsNullOrEmpty(itemInfo.pid))
                                 {
                                 {
                                     if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}"))
                                     if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}"))
                                     {
                                     {
-                                        dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}",filed=$"{itemInfo.periodId}", scope = "school" });
+                                        dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.periodId}", scope = "school" });
+                                    }
+                                   // ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
+                                    ItemInfo olditemInfo = dbIDs.Find(x=>x.id.Equals(itemInfo.id)  && x.code.Equals(itemInfo.code));
+                                    if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}"))
+                                    {
+                                        dict.Add($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.periodId}", scope = "school" });
                                     }
                                     }
                                 }
                                 }
-                                await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
-
+                                await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
                             }
                             }
                         }
                         }
                     }
                     }
-                    else
+                    /*
+                     foreach (var itemInfo in itemInfos)
                     {
                     {
-                        itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                        if (itemInfo.scope.Equals("private"))
+                        itemInfo.ttl = -1;
+                        itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
+                        await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
+                        if (option.ToString().Equals("insert"))
                         {
                         {
+                            itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                             if (!itemInfo.code.Contains("Item"))
                             if (!itemInfo.code.Contains("Item"))
                             {
                             {
                                 itemInfo.code = "Item-" + itemInfo.code;
                                 itemInfo.code = "Item-" + itemInfo.code;
                             }
                             }
-                            if (string.IsNullOrEmpty(itemInfo.pid))
+                            var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
+                            if (response.Status == 200)
                             {
                             {
-                                if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}"))
+                                return Ok();
+                            }
+                            else
+                            {
+                                if (itemInfo.scope.Equals("private"))
                                 {
                                 {
-                                    dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.code.Replace("Item-", "")}", scope = "private" });
+                                    if (string.IsNullOrEmpty(itemInfo.pid))
+                                    {
+                                        if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}"))
+                                        {
+                                            dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed= $"{itemInfo.code.Replace("Item-", "")}", scope= "private" });
+                                        }
+                                    }
+                                    await client.GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
                                 }
                                 }
-                                ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
-                                if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}"))
+                                else
                                 {
                                 {
-                                    dict.Add($"{olditemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.code.Replace("Item-", "")}", scope = "private" });
+                                    if (string.IsNullOrEmpty(itemInfo.pid))
+                                    {
+                                        if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}"))
+                                        {
+                                            dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed=$"{itemInfo.periodId}", scope = "school" });
+                                        }
+                                    }
+                                    await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
+
                                 }
                                 }
                             }
                             }
-                            await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
-
                         }
                         }
                         else
                         else
                         {
                         {
-                            if (!itemInfo.code.Contains("Item"))
+                            itemInfo.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                            if (itemInfo.scope.Equals("private"))
                             {
                             {
-                                itemInfo.code = "Item-" + itemInfo.code;
+                                if (!itemInfo.code.Contains("Item"))
+                                {
+                                    itemInfo.code = "Item-" + itemInfo.code;
+                                }
+                                if (string.IsNullOrEmpty(itemInfo.pid))
+                                {
+                                    if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}"))
+                                    {
+                                        dict.Add($"{itemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.code.Replace("Item-", "")}", scope = "private" });
+                                    }
+                                    ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
+                                    if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}"))
+                                    {
+                                        dict.Add($"{olditemInfo.code.Replace("Item-", "")}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.code.Replace("Item-", "")}", scope = "private" });
+                                    }
+                                }
+                                await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
+
                             }
                             }
-                            if (string.IsNullOrEmpty(itemInfo.pid))
+                            else
                             {
                             {
-                                if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}"))
+                                if (!itemInfo.code.Contains("Item"))
                                 {
                                 {
-                                    dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.periodId}", scope = "school" });
+                                    itemInfo.code = "Item-" + itemInfo.code;
                                 }
                                 }
-                                ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
-                                if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}"))
+                                if (string.IsNullOrEmpty(itemInfo.pid))
                                 {
                                 {
-                                    dict.Add($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.periodId}", scope = "school" });
+                                    if (!dict.ContainsKey($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}"))
+                                    {
+                                        dict.Add($"{itemInfo.code.Replace("Item-", "")}-{itemInfo.periodId}", new ItemCondDto { key = $"{itemInfo.code.Replace("Item-", "")}", filed = $"{itemInfo.periodId}", scope = "school" });
+                                    }
+                                    ItemInfo olditemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
+                                    if (!dict.ContainsKey($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}"))
+                                    {
+                                        dict.Add($"{olditemInfo.code.Replace("Item-", "")}-{olditemInfo.periodId}", new ItemCondDto { key = $"{olditemInfo.code.Replace("Item-", "")}", filed = $"{olditemInfo.periodId}", scope = "school" });
+                                    }
+
                                 }
                                 }
+                                await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
 
 
                             }
                             }
-                            await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(itemInfo, itemInfo.id, new PartitionKey($"{itemInfo.code}"));
-
                         }
                         }
                     }
                     }
+                     */
+                    var itemCondDtos = dict.Select(x => x.Value).ToList();
+                    var str = itemCondDtos.ToJsonString();
+                    var messageBlobItemCond = new ServiceBusMessage(str);
+                    await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
+                    return Ok(new { itemInfos });
+                }
+                else {
+                    return BadRequest();
                 }
                 }
-                var itemCondDtos=  dict.Select(x => x.Value).ToList();
-                var str = itemCondDtos.ToJsonString();
-                var messageBlobItemCond = new ServiceBusMessage(str);
-                await _serviceBus.GetServiceBusClient().SendMessageAsync(ItemCondQueue, messageBlobItemCond);
-                return Ok(new { itemInfos });
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
@@ -329,7 +457,7 @@ namespace TEAMModelOS.Controllers
             }
             }
         }
         }
 
 
-        
+
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]
         [HttpPost("upsert")]
         [HttpPost("upsert")]
         [AuthToken(Roles = "teacher,admin,student")]
         [AuthToken(Roles = "teacher,admin,student")]
@@ -350,7 +478,7 @@ namespace TEAMModelOS.Controllers
                 ItemInfo itemInfo;
                 ItemInfo itemInfo;
                 itemInfo = item.ToObject<ItemInfo>();
                 itemInfo = item.ToObject<ItemInfo>();
                 itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
                 itemInfo.size = await _azureStorage.GetBlobContainerClient(itemInfo.code).GetBlobsSize($"item/{itemInfo.id}");
-               
+
                 await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
                 await BlobService.RefreshBlobRoot(new BlobRefreshMessage { progress = "update", root = $"item", name = $"{itemInfo.code}".Replace("Item-", "") }, _serviceBus, _configuration, _azureRedis);
                 if (option.ToString().Equals("insert"))
                 if (option.ToString().Equals("insert"))
                 {
                 {
@@ -362,7 +490,7 @@ namespace TEAMModelOS.Controllers
                     var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
                     var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(itemInfo.id, new PartitionKey($"{itemInfo.code}"));
                     if (response.Status == 200)
                     if (response.Status == 200)
                     {
                     {
-                        return Ok(new { code=409,msg="题目已经存在"});
+                        return Ok(new { code = 409, msg = "题目已经存在" });
                     }
                     }
                     else
                     else
                     {
                     {
@@ -387,7 +515,7 @@ namespace TEAMModelOS.Controllers
                                 }
                                 }
                             }
                             }
                             itemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
                             itemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(itemInfo, new PartitionKey($"{itemInfo.code}"));
-                          
+
                         }
                         }
                     }
                     }
                 }
                 }
@@ -449,7 +577,7 @@ namespace TEAMModelOS.Controllers
                 return BadRequest();
                 return BadRequest();
             }
             }
         }
         }
-        
+
         /// <summary>
         /// <summary>
         //获取题目摘要信息
         //获取题目摘要信息
         /// </summary>
         /// </summary>
@@ -561,16 +689,19 @@ namespace TEAMModelOS.Controllers
             {
             {
                 Dictionary<string, ItemCondDto> dict = new Dictionary<string, ItemCondDto>();
                 Dictionary<string, ItemCondDto> dict = new Dictionary<string, ItemCondDto>();
                 var ItemCondQueue = _configuration.GetValue<string>("Azure:ServiceBus:ItemCondQueue");
                 var ItemCondQueue = _configuration.GetValue<string>("Azure:ServiceBus:ItemCondQueue");
-                List<string> ids= new List<string>();
+                List<string> ids = new List<string>();
                 request.TryGetProperty("id", out JsonElement _id);
                 request.TryGetProperty("id", out JsonElement _id);
-                if (_id.ValueKind.Equals(JsonValueKind.String) && !string.IsNullOrWhiteSpace(_id.GetString())) {
+                if (_id.ValueKind.Equals(JsonValueKind.String) && !string.IsNullOrWhiteSpace(_id.GetString()))
+                {
                     ids.Add(_id.GetString());
                     ids.Add(_id.GetString());
                 }
                 }
                 request.TryGetProperty("ids", out JsonElement _ids);
                 request.TryGetProperty("ids", out JsonElement _ids);
-                if (_ids.ValueKind.Equals(JsonValueKind.Array)) {
+                if (_ids.ValueKind.Equals(JsonValueKind.Array))
+                {
                     var __ids = _ids.ToObject<List<string>>();
                     var __ids = _ids.ToObject<List<string>>();
-                    var ds= __ids.Where(z => !string.IsNullOrWhiteSpace(z));
-                    if (ds.Any()) {
+                    var ds = __ids.Where(z => !string.IsNullOrWhiteSpace(z));
+                    if (ds.Any())
+                    {
                         ids.AddRange(ds);
                         ids.AddRange(ds);
                     }
                     }
                 }
                 }
@@ -612,7 +743,7 @@ namespace TEAMModelOS.Controllers
                         codes.Add(new { id, code = response.Status });
                         codes.Add(new { id, code = response.Status });
                     }
                     }
                 }
                 }
-                return Ok(new { code =200, codes });
+                return Ok(new { code = 200, codes });
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
@@ -637,7 +768,8 @@ namespace TEAMModelOS.Controllers
 #if !DEBUG
 #if !DEBUG
         [Authorize(Roles = "IES")]
         [Authorize(Roles = "IES")]
 #endif
 #endif
-        public async Task<IActionResult> Research(JsonElement request) {
+        public async Task<IActionResult> Research(JsonElement request)
+        {
             var client = _azureCosmos.GetCosmosClient();
             var client = _azureCosmos.GetCosmosClient();
             StringBuilder sql = new StringBuilder();
             StringBuilder sql = new StringBuilder();
             sql.Append("select distinct c.id,c.code,c.repairResource, c.periodId,c.question,c.useCount,c.level,c.field,c.knowledge,c.type,c.option,c.createTime," +
             sql.Append("select distinct c.id,c.code,c.repairResource, c.periodId,c.question,c.useCount,c.level,c.field,c.knowledge,c.type,c.option,c.createTime," +
@@ -647,23 +779,27 @@ namespace TEAMModelOS.Controllers
             if (!request.TryGetProperty("researchKey", out JsonElement researchKey)) return BadRequest();
             if (!request.TryGetProperty("researchKey", out JsonElement researchKey)) return BadRequest();
             request.TryGetProperty("orOpt", out JsonElement _orOpt);
             request.TryGetProperty("orOpt", out JsonElement _orOpt);
             string _researchKey = Regex.Replace($"{researchKey}", "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
             string _researchKey = Regex.Replace($"{researchKey}", "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
-            var keys = Regex.Split(_researchKey, "\\s+", RegexOptions.IgnoreCase).Where(y=>!string.IsNullOrWhiteSpace(y));
-            if (keys.Count() ==0) {
+            var keys = Regex.Split(_researchKey, "\\s+", RegexOptions.IgnoreCase).Where(y => !string.IsNullOrWhiteSpace(y));
+            if (keys.Count() ==0)
+            {
                 return BadRequest();
                 return BadRequest();
             }
             }
             else if (keys.Count() == 1)
             else if (keys.Count() == 1)
             {
             {
                 sql.Append($" and   contains(c.question,'{keys.First()}')");
                 sql.Append($" and   contains(c.question,'{keys.First()}')");
             }
             }
-            else {
+            else
+            {
                 string join = " and ";
                 string join = " and ";
-                if (_orOpt.ValueKind.Equals(JsonValueKind.True)) {
+                if (_orOpt.ValueKind.Equals(JsonValueKind.True))
+                {
                     join = " or ";
                     join = " or ";
                 }
                 }
                 sql.Append($" and ( {string.Join(join, keys.Select(x => $" contains(c.question,'{x}') "))})");
                 sql.Append($" and ( {string.Join(join, keys.Select(x => $" contains(c.question,'{x}') "))})");
             }
             }
             request.TryGetProperty("type", out JsonElement type);
             request.TryGetProperty("type", out JsonElement type);
-            if (!string.IsNullOrWhiteSpace($"{type}")) {
+            if (!string.IsNullOrWhiteSpace($"{type}"))
+            {
                 sql.Append($" and  c.type='{type}' ");
                 sql.Append($" and  c.type='{type}' ");
             }
             }
             request.TryGetProperty("level", out JsonElement level);
             request.TryGetProperty("level", out JsonElement level);
@@ -691,11 +827,11 @@ namespace TEAMModelOS.Controllers
                     pageCount = pcount;
                     pageCount = pcount;
                 }
                 }
             }
             }
-           
+
             List<object> items = new List<object>();
             List<object> items = new List<object>();
             if (scope.ToString().Equals("private"))
             if (scope.ToString().Equals("private"))
             {
             {
-                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: sql.ToString(),   requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
                 {
                 {
                     using var json = await JsonDocument.ParseAsync(item.ContentStream);
                     using var json = await JsonDocument.ParseAsync(item.ContentStream);
 
 
@@ -728,7 +864,7 @@ namespace TEAMModelOS.Controllers
                 }
                 }
             }
             }
             //需要处理 图片中的 base64
             //需要处理 图片中的 base64
-            return Ok(new { items , continuationToken });
+            return Ok(new { items, continuationToken });
         }
         }
         /// <summary>
         /// <summary>
         /// 根据条件随机挑选一个题目
         /// 根据条件随机挑选一个题目
@@ -755,16 +891,16 @@ namespace TEAMModelOS.Controllers
                 Dictionary<string, object> dict = new Dictionary<string, object>();
                 Dictionary<string, object> dict = new Dictionary<string, object>();
                 if (request.TryGetProperty("periodId", out JsonElement periodId))
                 if (request.TryGetProperty("periodId", out JsonElement periodId))
                 {
                 {
-                    sql=$"{sql} and c.periodId='{periodId}'" ;
+                    sql=$"{sql} and c.periodId='{periodId}'";
                 }
                 }
                 if (request.TryGetProperty("subjectId", out JsonElement subjectId))
                 if (request.TryGetProperty("subjectId", out JsonElement subjectId))
                 {
                 {
-                    sql = $"{sql}  and c.subjectId='{subjectId}'"; 
+                    sql = $"{sql}  and c.subjectId='{subjectId}'";
                 }
                 }
                 if (request.TryGetProperty("level", out JsonElement level))
                 if (request.TryGetProperty("level", out JsonElement level))
                 {
                 {
                     sql = $"{sql}  and c.level={level}";
                     sql = $"{sql}  and c.level={level}";
-                    
+
                 }
                 }
                 if (request.TryGetProperty("type", out JsonElement type))
                 if (request.TryGetProperty("type", out JsonElement type))
                 {
                 {
@@ -777,7 +913,8 @@ namespace TEAMModelOS.Controllers
                 if (request.TryGetProperty("gradeIds", out JsonElement _gradeIds) && _gradeIds.ValueKind.Equals(JsonValueKind.Array))
                 if (request.TryGetProperty("gradeIds", out JsonElement _gradeIds) && _gradeIds.ValueKind.Equals(JsonValueKind.Array))
                 {
                 {
                     List<string> gradeIds = _gradeIds.ToObject<List<string>>();
                     List<string> gradeIds = _gradeIds.ToObject<List<string>>();
-                    if (gradeIds.IsNotEmpty()) {
+                    if (gradeIds.IsNotEmpty())
+                    {
                         sql = $"{sql}  and g in ({string.Join(",", gradeIds.Select(x => $"'{x}'"))})";
                         sql = $"{sql}  and g in ({string.Join(",", gradeIds.Select(x => $"'{x}'"))})";
                         sql= sql.Replace("joingradeIds", " join g in c.gradeIds");
                         sql= sql.Replace("joingradeIds", " join g in c.gradeIds");
                     }
                     }
@@ -791,8 +928,8 @@ namespace TEAMModelOS.Controllers
                         sql= sql.Replace("joinknowledge", " join k in c.knowledge");
                         sql= sql.Replace("joinknowledge", " join k in c.knowledge");
                     }
                     }
                 }
                 }
-                   
-                 
+
+
                 if (request.TryGetProperty("pid", out JsonElement pd))
                 if (request.TryGetProperty("pid", out JsonElement pd))
                 {
                 {
                     if (pd.ValueKind != JsonValueKind.Null)
                     if (pd.ValueKind != JsonValueKind.Null)
@@ -813,7 +950,7 @@ namespace TEAMModelOS.Controllers
                         sql = $"{sql}  and c.id not in ({string.Join(",", notinIds.Select(x => $"'{x}'"))})";
                         sql = $"{sql}  and c.id not in ({string.Join(",", notinIds.Select(x => $"'{x}'"))})";
                     }
                     }
                 }
                 }
-                string sqlstr = sql.ToString().Replace("joingradeIds", " ").Replace("joinknowledge"," " );
+                string sqlstr = sql.ToString().Replace("joingradeIds", " ").Replace("joinknowledge", " ");
                 if (sqlstr.EndsWith("1=1") || !sqlstr.Contains("and"))
                 if (sqlstr.EndsWith("1=1") || !sqlstr.Contains("and"))
                 {
                 {
                     return Ok(new { itemInfo = itemInfo });
                     return Ok(new { itemInfo = itemInfo });
@@ -825,14 +962,19 @@ namespace TEAMModelOS.Controllers
                     {
                     {
                         items.Add(item);
                         items.Add(item);
                     }
                     }
-                    if (notinIds.IsNotEmpty()) {
+                    if (notinIds.IsNotEmpty())
+                    {
                         items =  items.Except(notinIds).ToList();
                         items =  items.Except(notinIds).ToList();
                     }
                     }
-                    string id= items.OrderBy(x => Guid.NewGuid().ToString()).Take(1).FirstOrDefault();
-                    if (!string.IsNullOrWhiteSpace(id)) {
-                        try { 
+                    string id = items.OrderBy(x => Guid.NewGuid().ToString()).Take(1).FirstOrDefault();
+                    if (!string.IsNullOrWhiteSpace(id))
+                    {
+                        try
+                        {
                             itemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(id, new PartitionKey($"Item-{code}"));
                             itemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(id, new PartitionKey($"Item-{code}"));
-                        } catch (Exception ex) {
+                        }
+                        catch (Exception ex)
+                        {
                             itemInfo = null;
                             itemInfo = null;
                         }
                         }
                     }
                     }
@@ -861,7 +1003,7 @@ namespace TEAMModelOS.Controllers
                         }
                         }
                     }
                     }
                 }
                 }
-                return Ok(new { itemInfo= itemInfo });
+                return Ok(new { itemInfo = itemInfo });
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
@@ -882,27 +1024,29 @@ namespace TEAMModelOS.Controllers
 #if !DEBUG
 #if !DEBUG
         [Authorize(Roles = "IES")]
         [Authorize(Roles = "IES")]
 #endif
 #endif
-        public async Task<IActionResult> FindIds(JsonElement request) {
+        public async Task<IActionResult> FindIds(JsonElement request)
+        {
             var client = _azureCosmos.GetCosmosClient();
             var client = _azureCosmos.GetCosmosClient();
             if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
             if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
             if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
             if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
             if (!request.TryGetProperty("ids", out JsonElement _ids)) return BadRequest();
             if (!request.TryGetProperty("ids", out JsonElement _ids)) return BadRequest();
             string tbname = $"{scope}".Equals("school") ? Constant.School : Constant.Teacher;
             string tbname = $"{scope}".Equals("school") ? Constant.School : Constant.Teacher;
-            List<ItemInfo> items= new List<ItemInfo>();
+            List<ItemInfo> items = new List<ItemInfo>();
             List<string> ids = _ids.ToObject<List<string>>();
             List<string> ids = _ids.ToObject<List<string>>();
             if (ids.IsNotEmpty())
             if (ids.IsNotEmpty())
             {
             {
                 string sql = $"select value c from c where c.id in ({string.Join(",", ids.Select(z => $"'{z}'"))})";
                 string sql = $"select value c from c where c.id in ({string.Join(",", ids.Select(z => $"'{z}'"))})";
-                await  foreach (var item in client.GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<ItemInfo>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Item-{code}") })) 
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<ItemInfo>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Item-{code}") }))
                 {
                 {
                     items.Add(item);
                     items.Add(item);
                 }
                 }
                 return Ok(new { items });
                 return Ok(new { items });
             }
             }
-            else {
+            else
+            {
                 return Ok(new { items });
                 return Ok(new { items });
             }
             }
-            
+
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -924,7 +1068,7 @@ namespace TEAMModelOS.Controllers
                 if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 /*            if (!request.TryGetProperty("@CURRPAGE", out JsonElement page)) return BadRequest();
                 /*            if (!request.TryGetProperty("@CURRPAGE", out JsonElement page)) return BadRequest();
                             if (!request.TryGetProperty("@PAGESIZE", out JsonElement size)) return BadRequest();*/
                             if (!request.TryGetProperty("@PAGESIZE", out JsonElement size)) return BadRequest();*/
-               
+
                 if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
                 Dictionary<string, object> dict = new Dictionary<string, object>();
                 Dictionary<string, object> dict = new Dictionary<string, object>();
                 /*var emobj = request.EnumerateObject();
                 /*var emobj = request.EnumerateObject();
@@ -939,7 +1083,8 @@ namespace TEAMModelOS.Controllers
                 }*/
                 }*/
                 /*            dict.Add("@CURRPAGE", page.GetInt32());
                 /*            dict.Add("@CURRPAGE", page.GetInt32());
                             dict.Add("@PAGESIZE", size.GetInt32());*/
                             dict.Add("@PAGESIZE", size.GetInt32());*/
-                if (request.TryGetProperty("@DESC", out JsonElement desc)) {
+                if (request.TryGetProperty("@DESC", out JsonElement desc))
+                {
                     dict.Add("@DESC", desc.ToString());
                     dict.Add("@DESC", desc.ToString());
                 }
                 }
                 if (request.TryGetProperty("@ASC", out JsonElement asc))
                 if (request.TryGetProperty("@ASC", out JsonElement asc))
@@ -1268,7 +1413,7 @@ namespace TEAMModelOS.Controllers
                     {
                     {
                         if (!string.IsNullOrWhiteSpace(item.pid))
                         if (!string.IsNullOrWhiteSpace(item.pid))
                         {
                         {
-                            if (item.scope .Equals("school"))
+                            if (item.scope.Equals("school"))
                             {
                             {
                                 var iteme = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(item.id, new PartitionKey(item.code));
                                 var iteme = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(item.id, new PartitionKey(item.code));
                                 if (iteme != null)
                                 if (iteme != null)
@@ -1277,7 +1422,7 @@ namespace TEAMModelOS.Controllers
                                 }
                                 }
 
 
                             }
                             }
-                            else if (item.scope .Equals("private"))
+                            else if (item.scope.Equals("private"))
                             {
                             {
                                 var iteme = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(item.id, new PartitionKey(item.code));
                                 var iteme = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(item.id, new PartitionKey(item.code));
                                 if (iteme != null)
                                 if (iteme != null)

+ 50 - 0
TEAMModelOS/Controllers/OpenApi/Business/BizResourceController.cs

@@ -0,0 +1,50 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Options;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.Filter;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+namespace TEAMModelOS.Controllers
+{
+    [Route("business")]
+    [ApiController]
+    public class BizResourceController : ControllerBase
+    {
+        private AzureCosmosFactory _azureCosmos;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+        private readonly AzureServiceBusFactory _serviceBus;
+        private readonly AzureStorageFactory _azureStorage;
+        private readonly AzureRedisFactory _azureRedis;
+        public IConfiguration _configuration { get; set; }
+        public BizResourceController(AzureRedisFactory azureRedis, AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureServiceBusFactory serviceBus, AzureStorageFactory azureStorage, IConfiguration configuration)
+        {
+            _azureCosmos = azureCosmos;
+            _dingDing = dingDing;
+            _option = option?.Value;
+            _serviceBus = serviceBus;
+            _configuration = configuration;
+            _azureStorage = azureStorage;
+            _azureRedis = azureRedis;
+        }
+
+        /// <summary>
+        /// 更新或保存题目资源
+        /// </summary>
+        /// <param name="portrait"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("upsert-school-item")]
+        [ApiToken(Auth = "2400", Name = "题目资源新增或更新", TName = "题目资源新增或更新", EName = "Upsert The Question", RWN = "W", Limit = false)]
+        public async Task<IActionResult> UpsertSchoolItem(JsonElement jsonElement)
+        {
+            var (id, school) = HttpContext.GetApiTokenInfo();
+            var responseData = await OpenApiService.UpsertSchoolItem(_azureCosmos, _dingDing, _azureRedis, jsonElement, school);
+            return Ok(new { responseData });
+        }
+    }
+}

+ 5 - 5
TEAMModelOS/Controllers/Third/Moofen/MoofenController.cs

@@ -53,6 +53,7 @@ namespace TEAMModelOS.Controllers.Third.Moofen
         public async Task<IActionResult> Question(JsonElement json) 
         public async Task<IActionResult> Question(JsonElement json) 
         {
         {
             var tokenData= HttpContext.GetAuthTokenInfo();
             var tokenData= HttpContext.GetAuthTokenInfo();
+            string content = string.Empty;
             try {
             try {
                 School school = null;
                 School school = null;
                 Dictionary<string, string> dict = new Dictionary<string, string>();
                 Dictionary<string, string> dict = new Dictionary<string, string>();
@@ -127,7 +128,7 @@ namespace TEAMModelOS.Controllers.Third.Moofen
                 List<MoofenItemInfo> items = new List<MoofenItemInfo>();
                 List<MoofenItemInfo> items = new List<MoofenItemInfo>();
                 if (response.StatusCode.Equals(HttpStatusCode.OK))
                 if (response.StatusCode.Equals(HttpStatusCode.OK))
                 {
                 {
-                    string content = await response.Content.ReadAsStringAsync();
+                      content = await response.Content.ReadAsStringAsync();
 
 
                     var data = content.ToObject<JsonElement>();
                     var data = content.ToObject<JsonElement>();
                     int count = 0;
                     int count = 0;
@@ -207,13 +208,12 @@ namespace TEAMModelOS.Controllers.Third.Moofen
                 }
                 }
                 else
                 else
                 {
                 {
-                    string content = await response.Content.ReadAsStringAsync();
-                    var data = content.ToObject<JsonElement>();
-                    return Ok(new { code = response.StatusCode });
+                    content = await response.Content.ReadAsStringAsync();
+                    return Ok(new { code = response.StatusCode, data = content }) ;
                 }
                 }
             } catch (Exception ex) {
             } catch (Exception ex) {
                 await _dingDing.SendBotMsg($"多分题目异常{ex.Message}\n{ex.StackTrace}",GroupNames.成都开发測試群組);
                 await _dingDing.SendBotMsg($"多分题目异常{ex.Message}\n{ex.StackTrace}",GroupNames.成都开发測試群組);
-                return Ok(new { code = 500,msg=$"{ex.Message}" });
+                return Ok(new { code = 500,msg=$"{ex.Message}",data= content });
             }
             }
         }
         }
         private List<MoofenItemInfo> MoofenQS(List<MoofenQuestion> questions, string subject,string pquestion,string schoolId, string pid = null)
         private List<MoofenItemInfo> MoofenQS(List<MoofenQuestion> questions, string subject,string pquestion,string schoolId, string pid = null)