|
@@ -698,6 +698,143 @@ namespace TEAMModelOS.Controllers
|
|
//需要处理 图片中的 base64
|
|
//需要处理 图片中的 base64
|
|
return Ok(new { items , continuationToken });
|
|
return Ok(new { items , continuationToken });
|
|
}
|
|
}
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 根据条件随机挑选一个题目
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="request"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ //[AuthToken(Roles = "teacher")]
|
|
|
|
+ [HttpPost("find-random-one")]
|
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
|
+ public async Task<IActionResult> FindRandomOne(JsonElement request)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ItemInfo itemInfo = null;
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+ string sql = $"select value(c.id) from c joingradeIds joinknowledge where 1=1";
|
|
|
|
+ if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
|
+ if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
|
+ Dictionary<string, object> dict = new Dictionary<string, object>();
|
|
|
|
+ if (request.TryGetProperty("periodId", out JsonElement periodId))
|
|
|
|
+ {
|
|
|
|
+ sql=$"{sql} and c.periodId='{periodId}'" ;
|
|
|
|
+ }
|
|
|
|
+ if (request.TryGetProperty("subjectId", out JsonElement subjectId))
|
|
|
|
+ {
|
|
|
|
+ sql = $"{sql} and c.subjectId='{subjectId}'";
|
|
|
|
+ }
|
|
|
|
+ if (request.TryGetProperty("level", out JsonElement level))
|
|
|
|
+ {
|
|
|
|
+ sql = $"{sql} and c.level={level}";
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if (request.TryGetProperty("type", out JsonElement type))
|
|
|
|
+ {
|
|
|
|
+ sql = $"{sql} and c.type='{type}'";
|
|
|
|
+ }
|
|
|
|
+ if (request.TryGetProperty("field", out JsonElement field))
|
|
|
|
+ {
|
|
|
|
+ sql = $"{sql} and c.field={field}";
|
|
|
|
+ }
|
|
|
|
+ if (request.TryGetProperty("gradeIds", out JsonElement _gradeIds) && _gradeIds.ValueKind.Equals(JsonValueKind.Array))
|
|
|
|
+ {
|
|
|
|
+ List<string> gradeIds = _gradeIds.ToObject<List<string>>();
|
|
|
|
+ if (gradeIds.IsNotEmpty()) {
|
|
|
|
+ sql = $"{sql} and g in ({string.Join(",", gradeIds.Select(x => $"'{x}'"))})";
|
|
|
|
+ sql= sql.Replace("joingradeIds", " join g in c.gradeIds");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (request.TryGetProperty("knowledge", out JsonElement _knowledge) && _knowledge.ValueKind.Equals(JsonValueKind.Array))
|
|
|
|
+ {
|
|
|
|
+ List<string> knowledge = _knowledge.ToObject<List<string>>();
|
|
|
|
+ if (knowledge.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ sql = $"{sql} and k in ({string.Join(",", knowledge.Select(x => $"'{x}'"))})";
|
|
|
|
+ sql= sql.Replace("joinknowledge", " join k in c.knowledge");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (request.TryGetProperty("pid", out JsonElement pd))
|
|
|
|
+ {
|
|
|
|
+ if (pd.ValueKind != JsonValueKind.Null)
|
|
|
|
+ {
|
|
|
|
+ sql = $"{sql} and c.pid='{pd}'";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ sql = $"{sql} and c.pid= null ";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<string> notinIds = null;
|
|
|
|
+ if (request.TryGetProperty("notinIds", out JsonElement _notinIds) && _notinIds.ValueKind.Equals(JsonValueKind.Array))
|
|
|
|
+ {
|
|
|
|
+ notinIds = _notinIds.ToObject<List<string>>();
|
|
|
|
+ if (notinIds.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ sql = $"{sql} and c.id not in ({string.Join(",", notinIds.Select(x => $"'{x}'"))})";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ string sqlstr = sql.ToString().Replace("joingradeIds", " ").Replace("joinknowledge"," " );
|
|
|
|
+ if (sqlstr.EndsWith("1=1") || !sqlstr.Contains("and"))
|
|
|
|
+ {
|
|
|
|
+ return Ok(new { itemInfo = itemInfo });
|
|
|
|
+ }
|
|
|
|
+ if (scope.ToString().Equals("private"))
|
|
|
|
+ {
|
|
|
|
+ List<string> items = new List<string>();
|
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<string>(queryText: sqlstr, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
|
|
|
|
+ {
|
|
|
|
+ items.Add(item);
|
|
|
|
+ }
|
|
|
|
+ if (notinIds.IsNotEmpty()) {
|
|
|
|
+ items = items.Except(notinIds).ToList();
|
|
|
|
+ }
|
|
|
|
+ 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}"));
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ itemInfo = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (scope.ToString().Equals("school"))
|
|
|
|
+ {
|
|
|
|
+ List<string> items = new List<string>();
|
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<string>(queryText: sqlstr, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
|
|
|
|
+ {
|
|
|
|
+ items.Add(item);
|
|
|
|
+ }
|
|
|
|
+ if (notinIds.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ items = items.Except(notinIds).ToList();
|
|
|
|
+ }
|
|
|
|
+ string id = items.OrderBy(x => Guid.NewGuid().ToString()).Take(1).FirstOrDefault();
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(id))
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ itemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(id, new PartitionKey($"Item-{code}"));
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ itemInfo = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return Ok(new { itemInfo= itemInfo });
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},item/Find()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 手动挑题
|
|
/// 手动挑题
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -824,48 +961,8 @@ namespace TEAMModelOS.Controllers
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/Find()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},item/Find()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// 手动挑题
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="request"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- [ProducesDefaultResponseType]
|
|
|
|
- //[AuthToken(Roles = "teacher")]
|
|
|
|
- [HttpPost("Find-cache-shell")]
|
|
|
|
- [Authorize(Roles = "IES")]
|
|
|
|
- public async Task<IActionResult> FindCacheShell(JsonElement request)
|
|
|
|
- {
|
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
|
- if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
|
|
- if (!request.TryGetProperty("ids", out JsonElement id)) return BadRequest();
|
|
|
|
- //List<string> ids = new List<string>();
|
|
|
|
- string info = "";
|
|
|
|
- for (int i = 0; i < id.GetArrayLength(); i++)
|
|
|
|
- {
|
|
|
|
- //ids.Add(id[i].ToJsonString());
|
|
|
|
- info += id[i].ToJsonString() + ",";
|
|
|
|
- }
|
|
|
|
- List<object> items = new List<object>();
|
|
|
|
- var query = $"select c.id, c.question,c.useCount,c.level,c.field,c.knowledge,c.type,c.option,c.createTime from c where c.id in ({info[0..^1]})";
|
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{school_code}") }))
|
|
|
|
- {
|
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
|
-
|
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
|
- {
|
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
|
- {
|
|
|
|
- items.Add(obj.ToObject<object>());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return Ok(new { items });
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 自动组题
|
|
/// 自动组题
|