|
@@ -58,6 +58,7 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
//新增
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
request.code =$"Notice-{request.code}";
|
|
@@ -65,7 +66,7 @@ namespace TEAMModelOS.Controllers
|
|
|
request.ttl = -1;
|
|
|
long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
request.createTime = now;
|
|
|
-
|
|
|
+ request.creatorId = userid;
|
|
|
//如果设置的时间是小于当前时间则立即发布
|
|
|
if (request.startTime <= 0)
|
|
|
{
|
|
@@ -78,20 +79,20 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
request.id = Guid.NewGuid().ToString();
|
|
|
|
|
|
- request = await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
+ request = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
|
|
|
+ var response = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(request.id, new PartitionKey($"{request.code}"));
|
|
|
|
|
|
if (response.Status == 200)
|
|
|
{
|
|
|
|
|
|
- request = await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
|
|
|
+ request = await client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- request = await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
+ request = await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
}
|
|
|
}
|
|
|
return Ok(new { vote = request });
|
|
@@ -124,46 +125,52 @@ namespace TEAMModelOS.Controllers
|
|
|
var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
//必须有学校或者教师编码
|
|
|
if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
- //开始时间,默认最近三十天
|
|
|
- var stimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- if (requert.TryGetProperty("stime", out JsonElement stime))
|
|
|
- {
|
|
|
- if (long.TryParse($"{stime}", out long data))
|
|
|
+ requert.TryGetProperty("admin", out JsonElement admin);
|
|
|
+ string stimestampsql = "";
|
|
|
+ string etimestampsql = "";
|
|
|
+ if (!$"{admin}" .Equals("1")) {
|
|
|
+ var stimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
+ if (requert.TryGetProperty("stime", out JsonElement stime))
|
|
|
{
|
|
|
- stimestamp = data;
|
|
|
- };
|
|
|
- };
|
|
|
- //默认当前时间
|
|
|
- var etimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
- if (requert.TryGetProperty("etime", out JsonElement etime))
|
|
|
- {
|
|
|
- if (long.TryParse($"{etime}", out long data))
|
|
|
+ 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))
|
|
|
{
|
|
|
- etimestamp = data;
|
|
|
- };
|
|
|
-
|
|
|
- };
|
|
|
- var progresssql = "";
|
|
|
- if (!requert.TryGetProperty("publish", out JsonElement publish))
|
|
|
+ if (long.TryParse($"{etime}", out long data))
|
|
|
+ {
|
|
|
+ etimestamp = data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ etimestampsql = $" and c.endTime >= {etimestamp} ";
|
|
|
+
|
|
|
+ }
|
|
|
+ var publishsql = "";
|
|
|
+ if (requert.TryGetProperty("publish", out JsonElement publish))
|
|
|
{
|
|
|
|
|
|
- if (!publish.ValueKind.Equals(JsonValueKind.Undefined) && !publish.ValueKind.Equals(JsonValueKind.Null) && publish.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ if (!publish.ValueKind.Equals(JsonValueKind.Undefined) && !publish.ValueKind.Equals(JsonValueKind.Null) && publish.ValueKind.Equals(JsonValueKind.Number))
|
|
|
{
|
|
|
- progresssql = $" and c.publish={publish} ";
|
|
|
+ publishsql = $" and c.publish={publish} ";
|
|
|
}
|
|
|
}
|
|
|
var typesql = "";
|
|
|
- if (!requert.TryGetProperty("type", out JsonElement type))
|
|
|
+ if (requert.TryGetProperty("type", out JsonElement type))
|
|
|
{
|
|
|
|
|
|
- if (!publish.ValueKind.Equals(JsonValueKind.Undefined) && !publish.ValueKind.Equals(JsonValueKind.Null) && publish.ValueKind.Equals(JsonValueKind.String))
|
|
|
+ if (!type.ValueKind.Equals(JsonValueKind.Undefined) && !type.ValueKind.Equals(JsonValueKind.Null) && type.ValueKind.Equals(JsonValueKind.String))
|
|
|
{
|
|
|
typesql = $" and c.type='{type}' ";
|
|
|
}
|
|
|
}
|
|
|
List<Notice> notices = new List<Notice>();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- var query = $"select value(c) from c where c.endTime >= {stimestamp} and c.startTime <= {etimestamp} {progresssql } and c.ttl=-1 ";
|
|
|
+ var query = $"select value(c) from c where c.ttl=-1 {etimestampsql} {stimestampsql} {publishsql } {typesql} ";
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Notice>(queryText: query,
|
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Notice-{code}") }))
|
|
|
{
|
|
@@ -177,5 +184,28 @@ namespace TEAMModelOS.Controllers
|
|
|
return BadRequest(ex.StackTrace);
|
|
|
}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 删除
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("delete")]
|
|
|
+ [AuthToken(Roles = "admin,teacher")]
|
|
|
+ public async Task<IActionResult> Delete(JsonElement request) {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
+ 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}"));
|
|
|
+ return Ok(new { status = 200 });
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ return BadRequest(e.StackTrace);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|