|
@@ -62,8 +62,19 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
//新增
|
|
|
+
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- request.code =$"Notice-{request.code}";
|
|
|
+ if (request.scope.Equals("school") && (!string.IsNullOrEmpty(request.school)|| !string.IsNullOrEmpty(school)))
|
|
|
+ {
|
|
|
+ request.school = string.IsNullOrWhiteSpace(request.school) ? school : request.school;
|
|
|
+ request.code = $"Notice-{request.school}";
|
|
|
+ }
|
|
|
+ else if (request.scope.Equals("private") && (!string.IsNullOrEmpty(request.creatorId)|| !string.IsNullOrEmpty(userid)))
|
|
|
+ {
|
|
|
+ request.creatorId = string.IsNullOrWhiteSpace(request.creatorId) ? userid : request.creatorId;
|
|
|
+ request.code = $"Notice";
|
|
|
+ }
|
|
|
+ // request.code =$"Notice-{request.code}";
|
|
|
request.pk = "Notice";
|
|
|
request.ttl = -1;
|
|
|
long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
@@ -87,20 +98,20 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
request.id = Guid.NewGuid().ToString();
|
|
|
|
|
|
- request = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
+ request = await client.GetContainer(Constant.TEAMModelOS,Constant.Common).CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
|
|
|
+ var response = await client.GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
|
|
|
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
|
|
|
|
- request = await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
|
|
|
+ request = await client.GetContainer(Constant.TEAMModelOS, Constant.Common).ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- request = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
+ request = await client.GetContainer(Constant.TEAMModelOS, Constant.Common).CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
}
|
|
|
}
|
|
|
return Ok(new { vote = request });
|
|
@@ -110,19 +121,12 @@ namespace TEAMModelOS.Controllers
|
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},school/Notice/upsert()\n{e.Message}\n{e.StackTrace}\n{e .StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
return BadRequest(e.StackTrace);
|
|
|
}
|
|
|
- }/// <summary>
|
|
|
- /// 查询投票活动,用于列表,编辑,查看
|
|
|
- /// </summary>
|
|
|
- /// <data>
|
|
|
- ///Vote-学校/教师编码 活动分区 !"code":"hbcn"/1606285227
|
|
|
- ///时间筛选范围开始时间 默认30天之前 ?"stime":1608274766154
|
|
|
- ///时间筛选范围结束时间 默认当前时间 ?"etime":1608274766666
|
|
|
- ///每页大小 ?"count":10/null/Undefined
|
|
|
- ///分页Token ?"continuationToken":Undefined/null/"[{\"token\":\"+RID:~omxMAP3ipcSEEwAAAAAAAA==#RT:2#TRC:20#ISV:2#IEO:65551#QCF:1#FPC:AYQTAAAAAAAAiRMAAAAAAAA=\",\"range\":{\"min\":\"\",\"max\":\"FF\"}}]"
|
|
|
- /// 当前状态 ?"progress":Undefined/null/"" 表示两种状态都要查询/ "going"/"finish" 表示查询进行中/ 或者已完成 学生端只能查询正在进行或已经结束 going 已发布|finish 已结束
|
|
|
- /// </data>
|
|
|
- /// <param name="request"></param>
|
|
|
- /// <returns></returns>
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="requert"></param>
|
|
|
+ /// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("find")]
|
|
|
[Authorize(Roles = "IES")]
|
|
@@ -168,6 +172,17 @@ namespace TEAMModelOS.Controllers
|
|
|
publishsql = $" and c.publish={publish} ";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ var creatorIdSql = "";
|
|
|
+ if (requert.TryGetProperty("creatorId", out JsonElement creatorId))
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!publish.ValueKind.Equals(JsonValueKind.Undefined) && !publish.ValueKind.Equals(JsonValueKind.Null) && publish.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ {
|
|
|
+ publishsql = $" and c.creatorId='{creatorId}' ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
var typesql = "";
|
|
|
if (requert.TryGetProperty("type", out JsonElement type))
|
|
|
{
|
|
@@ -197,8 +212,8 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
List<Notice> notices = new List<Notice>();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- var query = $"select distinct value(c) from c {joinSqlClasses} where 1=1 {etimestampsql} {stimestampsql} {publishsql } {typesql} {andSqlClasses} ";
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Notice>(queryText: query,
|
|
|
+ var query = $"select distinct value(c) from c {joinSqlClasses} where 1=1 {etimestampsql} {stimestampsql} {publishsql } {typesql} {andSqlClasses} {creatorIdSql} ";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIterator<Notice>(queryText: query,
|
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Notice-{code}") }))
|
|
|
{
|
|
|
notices.Add(item);
|
|
@@ -211,6 +226,105 @@ namespace TEAMModelOS.Controllers
|
|
|
return BadRequest(ex.StackTrace);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="requert"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("find-by-student")]
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+ [AuthToken(Roles = "teacher,admin,student")]
|
|
|
+ public async Task<IActionResult> FindByStudent(JsonElement requert)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ object scope = null;
|
|
|
+ HttpContext?.Items.TryGetValue("Scope", out scope);
|
|
|
+ var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
+ //必须有学校或者教师编码
|
|
|
+ // if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+
|
|
|
+ string stimestampsql = "";
|
|
|
+ string etimestampsql = "";
|
|
|
+ var stimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ if (requert.TryGetProperty("stime", out JsonElement stime))
|
|
|
+ {
|
|
|
+ if (long.TryParse($"{stime}", out long data))
|
|
|
+ {
|
|
|
+ stimestamp = data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ stimestampsql = $" and c.startTime <= {stimestamp} ";
|
|
|
+ //默认当前时间
|
|
|
+ var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ if (requert.TryGetProperty("etime", out JsonElement etime))
|
|
|
+ {
|
|
|
+ if (long.TryParse($"{etime}", out long data))
|
|
|
+ {
|
|
|
+ etimestamp = data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ etimestampsql = $" and c.endTime >= {etimestamp} ";
|
|
|
+ var publishsql = $" and c.publish=1 ";
|
|
|
+ string joinSqlClasses = "";
|
|
|
+ string andSqlClasses = "";
|
|
|
+ if (requert.TryGetProperty("classes", out JsonElement _classes))
|
|
|
+ {
|
|
|
+
|
|
|
+ if (_classes.ValueKind is JsonValueKind.Array)
|
|
|
+ {
|
|
|
+ List<string> subjects = _classes.ToObject<List<string>>();
|
|
|
+ if (subjects.IsNotEmpty())
|
|
|
+ {
|
|
|
+ joinSqlClasses = " join A2 in c.classes ";
|
|
|
+ List<string> sqlList = new List<string>();
|
|
|
+ subjects.ForEach(x => { sqlList.Add($" '{x}' "); });
|
|
|
+ string sql = string.Join(" , ", sqlList);
|
|
|
+ andSqlClasses = $" and A2 in ({sql}) ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ List<Notice> notices = new List<Notice>();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ var query = $"select distinct value(c) from c {joinSqlClasses} where 1=1 {etimestampsql} {stimestampsql} {publishsql} {andSqlClasses} ";
|
|
|
+
|
|
|
+ if ($"{scope}".Equals(Constant.ScopeTmdUser))
|
|
|
+ {
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIterator<Notice>(queryText: query,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Notice") }))
|
|
|
+ {
|
|
|
+ notices.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIterator<Notice>(queryText: query,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Notice") }))
|
|
|
+ {
|
|
|
+ notices.Add(item);
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(school)) {
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Common).GetItemQueryIterator<Notice>(queryText: query,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Notice-{school}") }))
|
|
|
+ {
|
|
|
+ notices.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { notices });
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},school/Notice/find()\n", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest(ex.StackTrace);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 删除
|
|
|
/// </summary>
|
|
@@ -227,7 +341,7 @@ namespace TEAMModelOS.Controllers
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemStreamAsync(id.GetString(), new PartitionKey($"Notice-{code}"));
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, Constant.Common).DeleteItemStreamAsync(id.GetString(), new PartitionKey($"Notice-{code}"));
|
|
|
return Ok(new { status = 200 });
|
|
|
}
|
|
|
catch (Exception e)
|