|
@@ -44,59 +44,75 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
}
|
|
|
|
|
|
//取得ErrorItems錯題
|
|
|
- Dictionary<string, Dictionary<string, List<ErrorItemsStuRow>>> ErrorItemsDic = new Dictionary<string, Dictionary<string, List<ErrorItemsStuRow>>>();
|
|
|
- string qry = "SELECT SUM(ARRAY_LENGTH(c.its)) AS number, c.stuId, c.school, c.subjectId, c.code FROM c WHERE " +
|
|
|
- "CONTAINS(c.code, 'ErrorItems') " +
|
|
|
- "GROUP BY c.stuId, c.school, c.subjectId, c.code";
|
|
|
- await foreach (var item in _azureCosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: qry, requestOptions: null))
|
|
|
+ Dictionary<string, Dictionary<string, List<ErrorItemsStuRowWithItems>>> ErrorItemsDic = new Dictionary<string, Dictionary<string, List<ErrorItemsStuRowWithItems>>>();
|
|
|
+ string qry = "SELECT ARRAY(SELECT VALUE t.id FROM t IN c.its ) AS itemIds, c.stuId, c.school AS schoolId, c.subjectId, c.code FROM c WHERE " +
|
|
|
+ "CONTAINS(c.code, 'ErrorItems') ";
|
|
|
+ await foreach (var item in _azureCosmosClient.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<ErrorItemsDoc>(queryText: qry, requestOptions: null))
|
|
|
{
|
|
|
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ string schoolId = (!string.IsNullOrWhiteSpace(item.schoolId)) ? item.schoolId : "noschoolid";
|
|
|
+ string stuId = item.stuId;
|
|
|
+ string subjectId = item.subjectId;
|
|
|
+ bool goFlg = ((schStuDic.ContainsKey(schoolId) && schStuDic[schoolId].Contains(item.stuId)) || schoolId.Equals("noschoolid")) ? true : false;
|
|
|
+ if (goFlg)
|
|
|
{
|
|
|
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ if (ErrorItemsDic.ContainsKey(schoolId))
|
|
|
{
|
|
|
- string code = Convert.ToString(obj.GetProperty("code"));
|
|
|
- string stuId = Convert.ToString(obj.GetProperty("stuId"));
|
|
|
- string schoolId = Convert.ToString(obj.GetProperty("school"));
|
|
|
- schoolId = (!string.IsNullOrWhiteSpace(schoolId)) ? schoolId : "noschoolid";
|
|
|
- string subjectId = Convert.ToString(obj.GetProperty("subjectId"));
|
|
|
- int number = obj.GetProperty("number").GetInt32();
|
|
|
- bool goFlg = ((schStuDic.ContainsKey(schoolId) && schStuDic[schoolId].Contains(stuId)) || schoolId.Equals("noschoolid")) ? true : false;
|
|
|
- if (goFlg)
|
|
|
+ if (ErrorItemsDic[schoolId].ContainsKey(stuId))
|
|
|
{
|
|
|
- if (ErrorItemsDic.ContainsKey(schoolId))
|
|
|
+ List<ErrorItemsStuRowWithItems> ErrorItemsStuRowList = ErrorItemsDic[schoolId][stuId];
|
|
|
+ ErrorItemsStuRowWithItems ErrorItemsStuRow = ErrorItemsStuRowList.Where(s => s.subjectId.Equals(subjectId)).FirstOrDefault();
|
|
|
+ if (ErrorItemsStuRow == null)
|
|
|
{
|
|
|
- if (ErrorItemsDic[schoolId].ContainsKey(stuId))
|
|
|
- {
|
|
|
- List<ErrorItemsStuRow> ErrorItemsStuRowList = ErrorItemsDic[schoolId][stuId];
|
|
|
- ErrorItemsStuRow ErrorItemsStuRow = ErrorItemsStuRowList.Where(s => s.subjectId.Equals(subjectId)).FirstOrDefault();
|
|
|
- if (ErrorItemsStuRow == null)
|
|
|
- {
|
|
|
- ErrorItemsDic[schoolId][stuId].Add(new ErrorItemsStuRow() { subjectId = subjectId, number = number });
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- List<ErrorItemsStuRow> ErrorItemsStuRowList = new List<ErrorItemsStuRow>();
|
|
|
- ErrorItemsStuRow ErrorItemsStuRow = new ErrorItemsStuRow() { subjectId = subjectId, number = number };
|
|
|
- ErrorItemsStuRowList.Add(ErrorItemsStuRow);
|
|
|
- ErrorItemsDic[schoolId].Add(stuId, ErrorItemsStuRowList);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- List<ErrorItemsStuRow> ErrorItemsStuRowList = new List<ErrorItemsStuRow>();
|
|
|
- ErrorItemsStuRow ErrorItemsStuRow = new ErrorItemsStuRow() { subjectId = subjectId, number = number };
|
|
|
- ErrorItemsStuRowList.Add(ErrorItemsStuRow);
|
|
|
- Dictionary<string, List<ErrorItemsStuRow>> ErrorItemsSchRow = new Dictionary<string, List<ErrorItemsStuRow>> { { stuId, ErrorItemsStuRowList } };
|
|
|
- ErrorItemsDic.Add(schoolId, ErrorItemsSchRow);
|
|
|
+ ErrorItemsDic[schoolId][stuId].Add(new ErrorItemsStuRowWithItems() { subjectId = subjectId });
|
|
|
+ ErrorItemsStuRow = ErrorItemsDic[schoolId][stuId].Where(s => s.subjectId.Equals(subjectId)).FirstOrDefault();
|
|
|
}
|
|
|
+ ErrorItemsStuRow.itemIds = ErrorItemsStuRow.itemIds.Union(item.itemIds).ToList();
|
|
|
+ ErrorItemsStuRow.number = ErrorItemsStuRow.itemIds.Count;
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ List<ErrorItemsStuRowWithItems> ErrorItemsStuRowList = new List<ErrorItemsStuRowWithItems>();
|
|
|
+ ErrorItemsStuRowWithItems ErrorItemsStuRow = new ErrorItemsStuRowWithItems() { subjectId = subjectId };
|
|
|
+ ErrorItemsStuRow.itemIds = item.itemIds;
|
|
|
+ ErrorItemsStuRow.number = ErrorItemsStuRow.itemIds.Count;
|
|
|
+ ErrorItemsStuRowList.Add(ErrorItemsStuRow);
|
|
|
+ ErrorItemsDic[schoolId].Add(stuId, ErrorItemsStuRowList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ List<ErrorItemsStuRowWithItems> ErrorItemsStuRowList = new List<ErrorItemsStuRowWithItems>();
|
|
|
+ ErrorItemsStuRowWithItems ErrorItemsStuRow = new ErrorItemsStuRowWithItems() { subjectId = subjectId };
|
|
|
+ ErrorItemsStuRow.itemIds = item.itemIds;
|
|
|
+ ErrorItemsStuRow.number = ErrorItemsStuRow.itemIds.Count;
|
|
|
+ ErrorItemsStuRowList.Add(ErrorItemsStuRow);
|
|
|
+ Dictionary<string, List<ErrorItemsStuRowWithItems>> ErrorItemsSchRow = new Dictionary<string, List<ErrorItemsStuRowWithItems>> { { stuId, ErrorItemsStuRowList } };
|
|
|
+ ErrorItemsDic.Add(schoolId, ErrorItemsSchRow);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //Dic整形:去除itemIds欄位
|
|
|
+ Dictionary<string, Dictionary<string, List<ErrorItemsStuRow>>> ErrorItemsDicResult = new Dictionary<string, Dictionary<string, List<ErrorItemsStuRow>>>();
|
|
|
+ foreach (KeyValuePair<string, Dictionary<string, List<ErrorItemsStuRowWithItems>>> schItem in ErrorItemsDic)
|
|
|
+ {
|
|
|
+ string schoolId = schItem.Key;
|
|
|
+ ErrorItemsDicResult.Add(schoolId, new Dictionary<string, List<ErrorItemsStuRow>>());
|
|
|
+ Dictionary<string, List<ErrorItemsStuRowWithItems>> schDic = schItem.Value;
|
|
|
+ foreach(KeyValuePair<string, List<ErrorItemsStuRowWithItems>> stuItem in schDic)
|
|
|
+ {
|
|
|
+ string stuId = stuItem.Key;
|
|
|
+ ErrorItemsDicResult[schoolId].Add(stuId, new List<ErrorItemsStuRow>());
|
|
|
+ List<ErrorItemsStuRowWithItems> stuList = stuItem.Value;
|
|
|
+ foreach(ErrorItemsStuRowWithItems stuRow in stuList)
|
|
|
+ {
|
|
|
+ ErrorItemsStuRow stuRowNew = new ErrorItemsStuRow() { subjectId = stuRow.subjectId , number = stuRow.number };
|
|
|
+ ErrorItemsDicResult[schoolId][stuId].Add(stuRowNew);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
//寫入Redis
|
|
|
- foreach(var SchItem in ErrorItemsDic)
|
|
|
+ foreach (var SchItem in ErrorItemsDicResult)
|
|
|
{
|
|
|
string schoolId = SchItem.Key;
|
|
|
string hkey = $"ErrorItems:{schoolId}";
|
|
@@ -117,9 +133,24 @@ namespace TEAMModelOS.SDK.Models.Service
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //ErrorItems 各學生資料項目
|
|
|
public class ErrorItemsStuRow
|
|
|
{
|
|
|
public string subjectId { get; set; }
|
|
|
public int number { get; set; }
|
|
|
}
|
|
|
+ //ErrorItems 各學生資料項目
|
|
|
+ public class ErrorItemsStuRowWithItems : ErrorItemsStuRow
|
|
|
+ {
|
|
|
+ public List<string> itemIds { get; set; } = new List<string>();
|
|
|
+ }
|
|
|
+ //ErrorItems承接DB用
|
|
|
+ public class ErrorItemsDoc
|
|
|
+ {
|
|
|
+ public string code { get; set; }
|
|
|
+ public string stuId { get; set; }
|
|
|
+ public string schoolId { get; set; }
|
|
|
+ public string subjectId { get; set; }
|
|
|
+ public List<string> itemIds { get; set; } = new();
|
|
|
+ }
|
|
|
}
|