|
@@ -17,8 +17,6 @@ using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
|
|
using TEAMModelOS.SDK.Extension;
|
|
using TEAMModelOS.SDK.Extension;
|
|
using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
|
|
using TEAMModelOS.SDK.Helper.Common.StringHelper;
|
|
using TEAMModelOS.SDK.Helper.Common.StringHelper;
|
|
-using TEAMModelOS.Models;
|
|
|
|
-using Microsoft.Extensions.Options;
|
|
|
|
|
|
|
|
namespace TEAMModelOS.Controllers.Learn
|
|
namespace TEAMModelOS.Controllers.Learn
|
|
{
|
|
{
|
|
@@ -32,19 +30,15 @@ namespace TEAMModelOS.Controllers.Learn
|
|
[ApiController]
|
|
[ApiController]
|
|
public class VoteController : ControllerBase
|
|
public class VoteController : ControllerBase
|
|
{
|
|
{
|
|
- private readonly AzureCosmosFactory _azureCosmos;
|
|
|
|
private readonly SnowflakeId _snowflakeId;
|
|
private readonly SnowflakeId _snowflakeId;
|
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
private readonly AzureServiceBusFactory _serviceBus;
|
|
private readonly AzureServiceBusFactory _serviceBus;
|
|
- private readonly DingDing _dingDing;
|
|
|
|
- private readonly Option _option;
|
|
|
|
|
|
|
|
- public VoteController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option)
|
|
|
|
|
|
+ public VoteController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId)
|
|
{
|
|
{
|
|
|
|
+ _snowflakeId = snowflakeId;
|
|
_azureCosmos = azureCosmos;
|
|
_azureCosmos = azureCosmos;
|
|
_serviceBus = serviceBus;
|
|
_serviceBus = serviceBus;
|
|
- _snowflakeId = snowflakeId;
|
|
|
|
- _dingDing = dingDing;
|
|
|
|
- _option = option?.Value;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -54,123 +48,153 @@ namespace TEAMModelOS.Controllers.Learn
|
|
/// <param name="request"></param>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
- [HttpPost("save")]
|
|
|
|
- public async Task<IActionResult> Save(Vote request)
|
|
|
|
|
|
+ [HttpPost("upsert")]
|
|
|
|
+ public async Task<IActionResult> Upsert(VoteDto request)
|
|
{
|
|
{
|
|
- try {
|
|
|
|
- //新增Vote
|
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
|
- request.code = request.pk + "-" + request.code;
|
|
|
|
- request.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
|
|
|
+ /*ResponseBuilder builder = ResponseBuilder.custom();
|
|
|
|
+ //新增
|
|
|
|
+ if (string.IsNullOrEmpty(request.vote.id))
|
|
|
|
+ {
|
|
|
|
+ request.vote.id = _snowflakeId.NextId()+"";
|
|
|
|
+ request.vote.status = 100;
|
|
|
|
+ request.vote.code = typeof(Vote).Name + "-" + request.vote.code;
|
|
|
|
+ }
|
|
|
|
+ if (request.vote.publishModel.Equals("0"))
|
|
|
|
+ {
|
|
|
|
+ request.vote.startTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
|
+ request.vote.status = 200;
|
|
|
|
+
|
|
|
|
+ } else if (request.vote.publishModel.Equals("1")) {
|
|
|
|
+
|
|
|
|
+ string msgId = _snowflakeId.NextId() + "";
|
|
|
|
+ long SequenceNumber = await _serviceBus.GetServiceBusClient().SendLeamMessage<Vote>(Constants.TopicName, request.vote.id, request.vote.code, request.vote.startTime, 200, msgId);
|
|
|
|
+ request.vote.sequenceNumber = SequenceNumber;
|
|
|
|
+ }*/
|
|
|
|
|
|
- if (string.IsNullOrEmpty(request.id))
|
|
|
|
|
|
+
|
|
|
|
+ //新增ote
|
|
|
|
+ //string code = request.vote.code;
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+ Vote vote = new Vote();
|
|
|
|
+ request.vote.school = request.vote.code;
|
|
|
|
+ request.vote.code = request.vote.pk + "-" + request.vote.code;
|
|
|
|
+ request.vote.createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
|
+ /*if (request.vote.publishModel.Equals("0"))
|
|
|
|
+ {
|
|
|
|
+ //request.vote.startTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
|
+ request.vote.progress = "going";
|
|
|
|
+ }
|
|
|
|
+ else if (request.vote.publishModel.Equals("1"))
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ string msgId = _snowflakeId.NextId() + "";
|
|
|
|
+ long SequenceNumber = await _serviceBus.GetServiceBusClient().SendLeamMessage<Survey>(Constants.TopicName, request.vote.id, request.vote.code, request.vote.startTime, "going", msgId);
|
|
|
|
+ request.vote.sequenceNumber = SequenceNumber;
|
|
|
|
+
|
|
|
|
+ }*/
|
|
|
|
+ if (string.IsNullOrEmpty(request.vote.id))
|
|
|
|
+ {
|
|
|
|
+ request.vote.id = Guid.NewGuid().ToString();
|
|
|
|
+ //request.survey.status = 100;
|
|
|
|
+ request.vote.progress = "pending";
|
|
|
|
+ /* long SequenceNumber = await _serviceBus.GetServiceBusClient().SendLeamMessage<Vote>(Constants.TopicName, request.vote.id, request.vote.code, request.vote.startTime);
|
|
|
|
+ request.vote.sequenceNumber = SequenceNumber;*/
|
|
|
|
+ vote = await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(request.vote, new PartitionKey($"{request.vote.code}"));
|
|
|
|
+ /*if (request.vote.scope.Equals("school"))
|
|
{
|
|
{
|
|
- request.id = Guid.NewGuid().ToString();
|
|
|
|
- request.progress = "pending";
|
|
|
|
- request = await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
|
|
|
+ vote = await client.GetContainer("TEAMModelOS", "School").CreateItemAsync(request.vote, new PartitionKey($"Vote-{code}"));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- Vote info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(request.id, new PartitionKey($"{request.code}"));
|
|
|
|
- if (info.progress.Equals("going"))
|
|
|
|
- {
|
|
|
|
- return Ok(new { v = "活动正在进行中" });
|
|
|
|
- }
|
|
|
|
- request.progress = info.progress;
|
|
|
|
- request = await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(request, info.id, new PartitionKey($"{info.code}"));
|
|
|
|
- }
|
|
|
|
- return Ok(new { request });
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- await _dingDing.SendBotMsg($"OS,{_option.Location},common/vote/save()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
|
- return BadRequest(e.StackTrace);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- /// <summary>
|
|
|
|
- /// 查询投票活动,用于列表,编辑,查看
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="request"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- [ProducesDefaultResponseType]
|
|
|
|
- [HttpPost("find")]
|
|
|
|
- public async Task<IActionResult> Find(JsonElement requert) {
|
|
|
|
- try {
|
|
|
|
- if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
|
- List<object> votes = new List<object>();
|
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
|
- var query = $"select c.id,c.name,c.code,c.startTime,c.progress, from c ";
|
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Vote-{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())
|
|
|
|
- {
|
|
|
|
- votes.Add(obj);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return Ok(votes);
|
|
|
|
- } catch (Exception ex) {
|
|
|
|
- await _dingDing.SendBotMsg($"OS,{_option.Location},common/vote/find()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
|
- return BadRequest(ex.StackTrace);
|
|
|
|
|
|
+ vote = await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(request.vote, new PartitionKey($"Vote-{code}"));
|
|
|
|
+ }*/
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- /// 查询投票活动,用于列表,编辑,查看
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="request"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- [ProducesDefaultResponseType]
|
|
|
|
- [HttpPost("find-id")]
|
|
|
|
- public async Task<IActionResult> FindById(JsonElement requert) {
|
|
|
|
- try {
|
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
|
- if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
|
- if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
|
- Vote vote = null;
|
|
|
|
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Vote>(queryText: $"select value(c) from c where c.id = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Vote info = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(request.vote.id, new PartitionKey($"{request.vote.code}"));
|
|
|
|
+ if (info.progress.Equals("going"))
|
|
{
|
|
{
|
|
- vote = item;
|
|
|
|
- break;
|
|
|
|
|
|
+ return Ok(new { v = "活动正在进行中" });
|
|
}
|
|
}
|
|
- if (vote != null)
|
|
|
|
|
|
+ //request.vote.code = info.code;
|
|
|
|
+ request.vote.progress = info.progress;
|
|
|
|
+ /* await _serviceBus.GetServiceBusClient().cancelMessage(Constants.TopicName,info.sequenceNumber);
|
|
|
|
+ long SequenceNumber = await _serviceBus.GetServiceBusClient().SendLeamMessage<Vote>(Constants.TopicName, request.vote.id, request.vote.code, request.vote.startTime);
|
|
|
|
+ request.vote.sequenceNumber = SequenceNumber;*/
|
|
|
|
+ vote = await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(request.vote, info.id, new PartitionKey($"{info.code}"));
|
|
|
|
+ /*if (request.vote.scope.Equals("school"))
|
|
{
|
|
{
|
|
- return Ok(vote);
|
|
|
|
|
|
+ vote = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync(request.vote, request.vote.id, new PartitionKey($"{request.vote.code}"));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- return BadRequest("id,code不存在!");
|
|
|
|
- }
|
|
|
|
- } catch (Exception ex) {
|
|
|
|
- await _dingDing.SendBotMsg($"OS,{_option.Location},common/vote/find-id()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
|
- return BadRequest(ex.StackTrace);
|
|
|
|
|
|
+ vote = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(request.vote, request.vote.id, new PartitionKey($"{request.vote.code}"));
|
|
|
|
+ }*/
|
|
}
|
|
}
|
|
-
|
|
|
|
- }
|
|
|
|
- /// <summary>
|
|
|
|
- /// 查询投票活动,用于学生可以投票的列表
|
|
|
|
- /// </summary>
|
|
|
|
- /// <json>
|
|
|
|
- ///
|
|
|
|
- /// </json>
|
|
|
|
- /// <param name="request"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- [ProducesDefaultResponseType]
|
|
|
|
- [HttpPost("find-stu")]
|
|
|
|
- public async Task<IActionResult> FindStu(JsonElement requert) {
|
|
|
|
- var(id,name,_,school) = HttpContext.GetAuthTokenInfo();
|
|
|
|
|
|
+ //Vote homeWork = await _azureCosmos.SaveOrUpdate<Vote>(request.vote);
|
|
|
|
+
|
|
|
|
+ //设定结束时间
|
|
|
|
+ //_timerWorkService.TimerWork<Vote>(request.vote.endTime, 300, new Dictionary<string, object> { { "id", request.vote.id } });
|
|
|
|
+ //设定结束时间
|
|
|
|
+ //await _serviceBus.GetServiceBusClient().SendLeamMessage<Vote>(Constants.TopicName, request.vote.id, request.vote.code, request.vote.endTime);
|
|
|
|
+ //清除作业
|
|
|
|
+ /* if (!request.reset)
|
|
|
|
+ {
|
|
|
|
+ //根据作业发布对象查找到每一个具体学生生成关联关系表 HomeWorkStudent
|
|
|
|
+
|
|
|
|
+ List<VoteRecord> voteRecords = await _azureCosmos.FindByDict<VoteRecord>(new Dictionary<string, object> { { "id", request.vote.id } });
|
|
|
|
+
|
|
|
|
+ if (voteRecords.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ await _azureCosmos.DeleteAll(voteRecords);
|
|
|
|
+ }*/
|
|
|
|
+ //List<Target> targets = request.@params.vote.target;
|
|
|
|
+ //List<VoteRecord> votekStudents = new List<VoteRecord>();
|
|
|
|
+ //foreach (Target target in targets)
|
|
|
|
+ //{
|
|
|
|
+ // //查询之前是否有 关联关系表 HomeWorkStudent 有则删除
|
|
|
|
|
|
- return Ok();
|
|
|
|
|
|
+ // List<ClassStudent> classroom = await _cosmos.FindByDict<ClassStudent>(new Dictionary<string, object> { { "id", target.classroomCode } });
|
|
|
|
+ // if (classroom.IsNotEmpty() && classroom[0].code!=null)
|
|
|
|
+ // {
|
|
|
|
+ // foreach (ClassStudent student in classroom)
|
|
|
|
+ // {
|
|
|
|
+ // VoteRecord voteStudent = new VoteRecord();
|
|
|
|
+ // voteStudent.id = request.@params.vote.id;
|
|
|
|
+ // voteStudent.code = student.code;
|
|
|
|
+ // voteStudent.classroom.code = target.classroomCode;
|
|
|
|
+ // voteStudent.classroom.name = target.classroomName;
|
|
|
|
+ // votekStudents.Add(voteStudent);
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ //if (votekStudents.IsNotEmpty())
|
|
|
|
+ //{
|
|
|
|
+ // foreach (VoteRecord voteRecord in votekStudents)
|
|
|
|
+ // {
|
|
|
|
+ // List<Student> student = await _cosmos.FindByDict<Student>(new Dictionary<string, object> { { "studentId", voteRecord.code } });
|
|
|
|
+ // if (student.IsNotEmpty())
|
|
|
|
+ // {
|
|
|
|
+ // voteRecord.name = student[0].name;
|
|
|
|
+ // voteRecord.code = student[0].studentId;
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // await _cosmos.SaveOrUpdateAll(votekStudents);
|
|
|
|
+ //}
|
|
|
|
+ /* }*/
|
|
|
|
+ //return builder.Data(homeWork).build();
|
|
|
|
+ return Ok(new { vote });
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 查询投票活动,用于教师投票的列表
|
|
|
|
|
|
+ /// 查询投票活动
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
+
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
- [HttpPost("find-tch")]
|
|
|
|
- public async Task<IActionResult> FindTch(JsonElement requert)
|
|
|
|
|
|
+ [HttpPost("find")]
|
|
|
|
+ public async Task<IActionResult> Find(JsonElement requert)
|
|
{
|
|
{
|
|
|
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
@@ -404,9 +428,11 @@ namespace TEAMModelOS.Controllers.Learn
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public class Options {
|
|
|
|
|
|
+ public class Options
|
|
|
|
+ {
|
|
|
|
|
|
- public Options() {
|
|
|
|
|
|
+ public Options()
|
|
|
|
+ {
|
|
students = new List<VoteRecord>();
|
|
students = new List<VoteRecord>();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -419,7 +445,7 @@ namespace TEAMModelOS.Controllers.Learn
|
|
/// 选项value
|
|
/// 选项value
|
|
/// </summary>
|
|
/// </summary>
|
|
public string optionValue { get; set; }
|
|
public string optionValue { get; set; }
|
|
-
|
|
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 选项人
|
|
/// 选项人
|
|
/// </summary>
|
|
/// </summary>
|