|
@@ -482,193 +482,6 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
return Ok(new {records = res});
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 问卷记录 当活动没结算且没有BlobUrl时则调用此接口
|
|
|
- /// </summary>
|
|
|
- /// <redis>
|
|
|
- /// {"C":2,"A":2,"other":2}
|
|
|
- /// </redis>
|
|
|
- /// <param name="request">
|
|
|
- /// !"id":"aaaa"
|
|
|
- /// !"code":"Survey-hbcn"/"code":"Survey-1606285227"
|
|
|
- /// </param>
|
|
|
- /// <returns>
|
|
|
- /// </returns>
|
|
|
- [ProducesDefaultResponseType]
|
|
|
- [HttpPost("settlement")]
|
|
|
- //[AuthToken(Roles = "teacher,student")]
|
|
|
- public async Task<IActionResult> Settlement(JsonElement request)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- //活动id
|
|
|
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
- //活动分区
|
|
|
- if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
- Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.GetString(), new PartitionKey($"{code}"));
|
|
|
- List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", $"{id}" }, { "PartitionKey", survey.progress } });
|
|
|
- ActivityData data = null;
|
|
|
- if (survey != null)
|
|
|
- {
|
|
|
- var adid = survey.id;
|
|
|
- var adcode = $"Activity-{survey.school}";
|
|
|
- try {
|
|
|
- if (survey.scope == "school")
|
|
|
- {
|
|
|
- data = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
|
|
|
- }
|
|
|
- else if (survey.scope == "private")
|
|
|
- {
|
|
|
- data = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<ActivityData>(adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
|
|
|
- }
|
|
|
- } catch {
|
|
|
- data = null;
|
|
|
- }
|
|
|
- if (survey.ttl >= 1)
|
|
|
- {
|
|
|
- _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{survey.id}");
|
|
|
- _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{survey.id}");
|
|
|
- if (data != null)
|
|
|
- {
|
|
|
- data.ttl = 1;
|
|
|
- if (survey.scope == "school")
|
|
|
- {
|
|
|
- data = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<ActivityData>(data, adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
|
|
|
- }
|
|
|
- else if (survey.scope == "private")
|
|
|
- {
|
|
|
- data = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, adid, new Azure.Cosmos.PartitionKey($"{adcode}"));
|
|
|
- }
|
|
|
- }
|
|
|
- await _dingDing.SendBotMsg($"问卷调查【{survey.name}-{survey.id}】被删除", GroupNames.醍摩豆服務運維群組);
|
|
|
- return Ok();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- switch (survey.progress)
|
|
|
- {
|
|
|
-
|
|
|
- case "finish":
|
|
|
- var records = await _azureRedis.GetRedisClient(8).HashGetAllAsync($"Survey:Record:{survey.id}");
|
|
|
- List<dynamic> recs = new List<dynamic>();
|
|
|
- foreach (var rcd in records)
|
|
|
- {
|
|
|
- var value = rcd.Value.ToString().ToObject<JsonElement>();
|
|
|
- recs.Add(new { index = rcd.Name.ToString(), ans = value });
|
|
|
- }
|
|
|
- var cods = new { records = recs };
|
|
|
- //问卷整体情况
|
|
|
- await _azureStorage.UploadFileByContainer(survey.blobcntr, cods.ToJsonString(), "survey", $"{survey.id}/record.json");
|
|
|
- //结算每道题的答题情况
|
|
|
-
|
|
|
- var ContainerClient = _azureStorage.GetBlobContainerClient(survey.blobcntr);
|
|
|
- var route = ContainerClient.Uri.ToString();
|
|
|
-
|
|
|
- //获取
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- List<string> items = await ContainerClient.List($"survey/{survey.id}/urecord");
|
|
|
- List<SurveyRecord> surveyRecords = new List<SurveyRecord>();
|
|
|
- (string uri, string sas) blobAuth = _azureStorage.GetBlobContainerSAS(survey.blobcntr, BlobContainerSasPermissions.Read);
|
|
|
- string sas = blobAuth.sas;
|
|
|
- var rcode = await _clientFactory.CreateClient().GetAsync(new Uri($"{route}/survey/{survey.id}/record.json?{sas}"));
|
|
|
- var jsonc = await JsonDocument.ParseAsync(await rcode.Content.ReadAsStreamAsync());
|
|
|
- var Recordc = jsonc.RootElement.ToObject<JsonElement>();
|
|
|
- HttpClient httpClient = _clientFactory.CreateClient();
|
|
|
- await _dingDing.SendBotMsg($"问卷调查问题结算数据11111--->>{Recordc.ToJsonString()}", GroupNames.成都开发測試群組);
|
|
|
- foreach (string item in items)
|
|
|
- {
|
|
|
- var url = $"{route}/{item}?{sas}";
|
|
|
- var response = await httpClient.GetAsync(new Uri(url));
|
|
|
- var json = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());
|
|
|
- var Record = json.RootElement.ToObject<SurveyRecord>();
|
|
|
- surveyRecords.Add(Record);
|
|
|
- }
|
|
|
- await _dingDing.SendBotMsg($"问卷调查问题结算数据{surveyRecords.ToJsonString()}", GroupNames.成都开发測試群組);
|
|
|
- for (int index = 0; index < survey.answers.Count; index++)
|
|
|
- {
|
|
|
- string url = $"{survey.id}/qrecord/{index}.json";
|
|
|
- QuestionRecord question = new QuestionRecord() { index = index };
|
|
|
- foreach (SurveyRecord record in surveyRecords)
|
|
|
- {
|
|
|
- if (record.ans.Count == survey.answers.Count)
|
|
|
- {
|
|
|
- foreach (var an in record.ans[index])
|
|
|
- {
|
|
|
- //
|
|
|
- if (question.opt.ContainsKey(an))
|
|
|
- {
|
|
|
- if (question.opt[an] != null)
|
|
|
- {
|
|
|
- question.opt[an].Add(record.userid);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- question.opt[an] = new HashSet<string>() { record.userid };
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (survey.answers[index].Contains(an))
|
|
|
- {
|
|
|
- //如果是客观题code
|
|
|
- question.opt.Add(an, new HashSet<string> { record.userid });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //如果不是客观code
|
|
|
- question.other[record.userid] = an;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- await _azureStorage.UploadFileByContainer(survey.blobcntr, question.ToJsonString(), "survey", url);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- await _dingDing.SendBotMsg($"问卷调查问题结算异常{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
- }
|
|
|
- if (string.IsNullOrEmpty(survey.recordUrl))
|
|
|
- {
|
|
|
- survey.recordUrl = $"/survey/{survey.id}/record.json";
|
|
|
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync<Survey>(survey, survey.id, new Azure.Cosmos.PartitionKey(survey.code));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //异动,且已经有结算记录则不必再继续。
|
|
|
- //break;
|
|
|
- }
|
|
|
- // await Task.WhenAll(tasks);
|
|
|
- //更新结束状态
|
|
|
- data.progress = "finish";
|
|
|
- if (survey.scope == "school")
|
|
|
- {
|
|
|
- await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
|
|
|
- }
|
|
|
- else if (survey.scope == "private")
|
|
|
- {
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<ActivityData>(data, data.id, new Azure.Cosmos.PartitionKey(data.code));
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- return Ok();
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- await _dingDing.SendBotMsg($"OS,{_option.Location},common/survey/find-id()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
- return BadRequest(ex.StackTrace);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
public class QuestionRecord
|
|
|
{
|