|
@@ -23,6 +23,7 @@ using Microsoft.International.Converters.PinYinConverter;
|
|
|
using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
|
|
|
using Microsoft.OData.Edm;
|
|
|
using Newtonsoft.Json;
|
|
|
+using NUnit.Framework;
|
|
|
using NUnit.Framework.Internal;
|
|
|
using OpenXmlPowerTools;
|
|
|
using StackExchange.Redis;
|
|
@@ -1056,7 +1057,7 @@ namespace TEAMModelOS.Controllers
|
|
|
scoreCalcFunc_standard_interaction.name = "標準化評分";
|
|
|
scoreCalcFunc_standard_interaction.scorecalcActId = scoreCalcLsRecord.id;
|
|
|
scoreCalcFunc_standard_interaction.type = "lessonrecord";
|
|
|
- scoreCalcFunc_standard_interaction.method = "point";
|
|
|
+ scoreCalcFunc_standard_interaction.method = "interaction";
|
|
|
scoreCalcFunc_standard_interaction.template = "standard";
|
|
|
scoreCalcFunc_standard_interaction.keyvals.Add(new ScoreCalcFuncTemplateKeyval() { key = "原始分數", val = "X" });
|
|
|
scoreCalcFunc_standard_interaction.keyvals.Add(new ScoreCalcFuncTemplateKeyval() { key = "平均分數", val = "Y" });
|
|
@@ -1071,7 +1072,7 @@ namespace TEAMModelOS.Controllers
|
|
|
scoreCalcFunc_percent_interaction.name = "百分比評分";
|
|
|
scoreCalcFunc_percent_interaction.scorecalcActId = scoreCalcLsRecord.id;
|
|
|
scoreCalcFunc_percent_interaction.type = "lessonrecord";
|
|
|
- scoreCalcFunc_percent_interaction.method = "point";
|
|
|
+ scoreCalcFunc_percent_interaction.method = "interaction";
|
|
|
scoreCalcFunc_percent_interaction.template = "percent";
|
|
|
scoreCalcFunc_percent_interaction.keyvals.Add(new ScoreCalcFuncTemplateKeyval() { key = "原始分數", val = "X" });
|
|
|
scoreCalcFunc_percent_interaction.keyvals.Add(new ScoreCalcFuncTemplateKeyval() { key = "最高分數", val = "Y" });
|
|
@@ -1114,10 +1115,10 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
List<Object> scoreCalc = new List<object>();
|
|
|
try
|
|
|
- {
|
|
|
+ {
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
if (!request.TryGetProperty("teammodelId", out JsonElement teammodelId)) return BadRequest();
|
|
|
- var clientTeacher = _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher);
|
|
|
+ var clientTeacher = _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher);
|
|
|
UpdateSscoreCalcRq updateSscoreCalcRq = JsonConvert.DeserializeObject<UpdateSscoreCalcRq>(request.ToString());
|
|
|
|
|
|
// 取主表資料
|
|
@@ -1152,8 +1153,8 @@ namespace TEAMModelOS.Controllers
|
|
|
ScoreCalcActivity scoreCalcActivity = await clientTeacher.ReadItemAsync<ScoreCalcActivity>(updateSscoreCalcRq.ScoreCalcAct[i].id, new PartitionKey($"ScoreCalcAct-{teammodelId}"));
|
|
|
scoreCalcActivity.rate = updateSscoreCalcRq.ScoreCalcAct[i].rate;
|
|
|
scoreCalcActivity.editScores = updateSscoreCalcRq.ScoreCalcAct[i].editScores;
|
|
|
-
|
|
|
- scoreCalcActivity = await clientTeacher.ReplaceItemAsync(scoreCalcActivity, $"{scoreCalcActivity.id}", new PartitionKey(scoreCalcActivity.code));
|
|
|
+
|
|
|
+ scoreCalcActivity = await clientTeacher.ReplaceItemAsync(scoreCalcActivity, $"{scoreCalcActivity.id}", new PartitionKey(scoreCalcActivity.code));
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
@@ -1176,7 +1177,167 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// (五)刪除成績統計
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("delete-scorecalc")]
|
|
|
+ public async Task<IActionResult> DeleteSscoreCalc(JsonElement request)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("teammodelId", out JsonElement teammodelId)) return BadRequest();
|
|
|
+ var clientTeacher = _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher);
|
|
|
+ List<string> idslist = new List<string>();
|
|
|
+ List<string> scorecalcIdslist = new List<string>();
|
|
|
+ List<string> formulaIdslist = new List<string>();
|
|
|
+
|
|
|
+ idslist.Add(id.ToString());
|
|
|
+
|
|
|
+ // 取項目表的 Id
|
|
|
+ string sql = $"SELECT c.id FROM c where c.scorecalcId = '{id}' ";
|
|
|
+ await foreach (var item in clientTeacher.GetItemQueryIterator<ItemId>(queryText: sql))
|
|
|
+ {
|
|
|
+ scorecalcIdslist.Add(item.id);
|
|
|
+ }
|
|
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 0; i < scorecalcIdslist.Count; i++)
|
|
|
+ {
|
|
|
+ sb.Append($"'{scorecalcIdslist[i]}',");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 取公式表的 id
|
|
|
+ string sql_Formula = $"SELECT c.id FROM c where c.scorecalcActId in ({sb.ToString().Remove(sb.Length - 1, 1)}) ";
|
|
|
+ await foreach (var item in clientTeacher.GetItemQueryIterator<ItemId>(queryText: sql_Formula))
|
|
|
+ {
|
|
|
+ formulaIdslist.Add(item.id);
|
|
|
+ }
|
|
|
+
|
|
|
+ //刪除主表 用傳進來的主表id 刪除資料
|
|
|
+ await clientTeacher.DeleteItemsStreamAsync(idslist, $"ScoreCalc-{teammodelId}");
|
|
|
+ //刪除項目表
|
|
|
+ await clientTeacher.DeleteItemsStreamAsync(scorecalcIdslist, $"ScoreCalcAct-{teammodelId}");
|
|
|
+ //刪除公式表
|
|
|
+ await clientTeacher.DeleteItemsStreamAsync(formulaIdslist, $"ScoreCalcActFormula-{teammodelId}");
|
|
|
+
|
|
|
+
|
|
|
+ var result = new
|
|
|
+ {
|
|
|
+ RtCode = "0",
|
|
|
+ RtMsg = "OK"
|
|
|
+ };
|
|
|
+
|
|
|
+ return Ok(result);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ //await _dingDing.SendBotMsg($"OS,{_option.Location},open-api/upsert()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// (六)更新公式設定(一次可以處理多個公式)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("update-formula")]
|
|
|
+ public async Task<IActionResult> UpdateFormula(JsonElement request)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!request.TryGetProperty("scoreCalcActId", out JsonElement scoreCalcActId)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("teammodelId", out JsonElement teammodelId)) return BadRequest();
|
|
|
+ var clientTeacher = _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher);
|
|
|
+ UpdateFormulaRq updateFormulaRq = JsonConvert.DeserializeObject<UpdateFormulaRq>(request.ToString());
|
|
|
+
|
|
|
+ List<ScoreCalcFunc> scoreCalcFuncs = new List<ScoreCalcFunc>();
|
|
|
+
|
|
|
+ // 取公式表的 資料
|
|
|
+ string sql = $"SELECT * FROM c where c.scorecalcActId = '{scoreCalcActId}' ";
|
|
|
+ await foreach (var item in clientTeacher.GetItemQueryIterator<ScoreCalcFunc>(queryText: sql))
|
|
|
+ {
|
|
|
+ scoreCalcFuncs.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 比對資料 決定哪些公式及項目表要更新
|
|
|
+ for (int i = 0; i < updateFormulaRq.scoreCalcFunc.Count; i++)
|
|
|
+ {
|
|
|
+ #region 更新項目表公式id
|
|
|
+ if (updateFormulaRq.scoreCalcFunc[i].use)
|
|
|
+ {
|
|
|
+ // 更新項目使用的公式id
|
|
|
+ // 取課堂紀錄資料
|
|
|
+ // ToDo...以後可能需要其他活動也可以用公式
|
|
|
+ ScoreCalcLsRecord scoreCalcLsRecord = await clientTeacher.ReadItemAsync<ScoreCalcLsRecord>(updateFormulaRq.scoreCalcActId, new PartitionKey($"ScoreCalcAct-{teammodelId}"));
|
|
|
+ switch (updateFormulaRq.method)
|
|
|
+ {
|
|
|
+ case "attend":
|
|
|
+ scoreCalcLsRecord.stuAttendFunctionId = updateFormulaRq.scoreCalcFunc[i].id;
|
|
|
+ break;
|
|
|
+ case "point":
|
|
|
+ scoreCalcLsRecord.stuPointFunctionId = updateFormulaRq.scoreCalcFunc[i].id;
|
|
|
+ break;
|
|
|
+ case "interaction":
|
|
|
+ scoreCalcLsRecord.stuItactFunctionId = updateFormulaRq.scoreCalcFunc[i].id;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ scoreCalcLsRecord = await clientTeacher.ReplaceItemAsync(scoreCalcLsRecord, $"{scoreCalcLsRecord.id}", new PartitionKey(scoreCalcLsRecord.code));
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 更新 or 新增公式
|
|
|
+ for (int j = 0; j < scoreCalcFuncs.Count; j++)
|
|
|
+ {
|
|
|
+ if (updateFormulaRq.scoreCalcFunc[i].id == scoreCalcFuncs[j].id)
|
|
|
+ {// 如果公式Id有代入 則更新公式
|
|
|
+ // 取公式資料
|
|
|
+ scoreCalcFuncs[j].name = updateFormulaRq.scoreCalcFunc[i].name;
|
|
|
+ scoreCalcFuncs[j].keyvals = updateFormulaRq.scoreCalcFunc[i].keyvals;
|
|
|
+ scoreCalcFuncs[j].content = updateFormulaRq.scoreCalcFunc[i].content;
|
|
|
+ scoreCalcFuncs[j] = await clientTeacher.ReplaceItemAsync(scoreCalcFuncs[j], $"{scoreCalcFuncs[j].id}", new PartitionKey(scoreCalcFuncs[j].code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (updateFormulaRq.scoreCalcFunc[i].id == "")
|
|
|
+ {// 如果公式Id沒有代入 則新增公式
|
|
|
+ ScoreCalcFunc scoreCalcFunc = new ScoreCalcFunc();
|
|
|
+ scoreCalcFunc.code = $"ScoreCalcActFormula-{teammodelId}";
|
|
|
+ scoreCalcFunc.id = Guid.NewGuid().ToString();
|
|
|
+ scoreCalcFunc.name = updateFormulaRq.scoreCalcFunc[i].name;
|
|
|
+ scoreCalcFunc.scorecalcActId = updateFormulaRq.scoreCalcActId;
|
|
|
+ // ToDo...以後可能需要其他活動也可以用公式
|
|
|
+ scoreCalcFunc.type = "lessonrecord";
|
|
|
+ scoreCalcFunc.method = updateFormulaRq.method;
|
|
|
+ scoreCalcFunc.template = updateFormulaRq.scoreCalcFunc[i].template;
|
|
|
+ scoreCalcFunc.keyvals = updateFormulaRq.scoreCalcFunc[i].keyvals;
|
|
|
+ scoreCalcFunc.content = updateFormulaRq.scoreCalcFunc[i].content;
|
|
|
+ scoreCalcFunc = await clientTeacher.CreateItemAsync(scoreCalcFunc, new PartitionKey($"{scoreCalcFunc.code}"));
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var result = new
|
|
|
+ {
|
|
|
+ RtCode = "0",
|
|
|
+ RtMsg = "OK"
|
|
|
+ };
|
|
|
+
|
|
|
+ return Ok(result);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ //await _dingDing.SendBotMsg($"OS,{_option.Location},open-api/upsert()\n{e.Message}\n{e.StackTrace}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|