|
@@ -2,6 +2,7 @@ using Azure.Cosmos;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
@@ -16,6 +17,7 @@ using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
+using TEAMModelOS.SDK.Models.Service;
|
|
|
using TEAMModelOS.Services.Common;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
@@ -31,13 +33,16 @@ namespace TEAMModelOS.Controllers
|
|
|
private readonly SnowflakeId _snowflakeId;
|
|
|
private readonly DingDing _dingDing;
|
|
|
private readonly Option _option;
|
|
|
-
|
|
|
- public ShareController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option)
|
|
|
+ private readonly IConfiguration _configuration;
|
|
|
+ private readonly NotificationService _notificationService;
|
|
|
+ public ShareController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_snowflakeId = snowflakeId;
|
|
|
_dingDing = dingDing;
|
|
|
- _option = option?.Value;
|
|
|
+ _option = option?.Value;
|
|
|
+ _configuration = configuration;
|
|
|
+ _notificationService = notificationService;
|
|
|
}
|
|
|
/*
|
|
|
{
|
|
@@ -97,9 +102,47 @@ namespace TEAMModelOS.Controllers
|
|
|
(Syllabus syllabus, List<Share> shares) = DoAuth(request, syllabusD);
|
|
|
shares.ForEach(async x=> {
|
|
|
await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<Share>(x, new PartitionKey($"{x.code}"));
|
|
|
+ //发送共编或分享通知
|
|
|
+ if (x.coedit == true) {
|
|
|
+ Notification notification = new Notification
|
|
|
+ {
|
|
|
+ hubName = "hita",
|
|
|
+ type = "msg",
|
|
|
+ from = $"ies5:{request.school}",
|
|
|
+ to = new List<string>() { x.code.Replace("Share-","") },
|
|
|
+ label = $"coedit_syllabus",
|
|
|
+ body = new { biz = "coedit", tmdid = x.issuer, schoolcode = $"{request.school}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
+ };
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ var location = _option.Location;
|
|
|
+ var code = await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);
|
|
|
+ }
|
|
|
+ if (x.share == true)
|
|
|
+ {
|
|
|
+ Notification notification = new Notification
|
|
|
+ {
|
|
|
+ hubName = "hita",
|
|
|
+ type = "msg",
|
|
|
+ from = $"ies5:{request.school}",
|
|
|
+ to = new List<string>() { x.code.Replace("Share-", "") },
|
|
|
+ label = $"share_syllabus",
|
|
|
+ body = new { biz = "share", tmdid = x.issuer, schoolcode = $"{request.school}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
+ };
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ var location = _option.Location;
|
|
|
+ var code = await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);
|
|
|
+ }
|
|
|
+
|
|
|
});
|
|
|
-
|
|
|
await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<Syllabus>(syllabus, new PartitionKey($"Syllabus-{request.volumeId}"));
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
else if (request.scope.Equals("private"))
|
|
@@ -161,7 +204,9 @@ namespace TEAMModelOS.Controllers
|
|
|
school = request.school,
|
|
|
scope = request.scope,
|
|
|
coedit = request.coedit,
|
|
|
- share = request.share
|
|
|
+ share = request.share,
|
|
|
+ cagree = 0,
|
|
|
+ sagree = 0
|
|
|
};
|
|
|
shares.Add(share);
|
|
|
});
|
|
@@ -221,6 +266,101 @@ namespace TEAMModelOS.Controllers
|
|
|
return (syllabus, shares);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// {"code":"教师编码","id":"章节id","agree":1共编同意,2共编拒绝,3分享同意,4分享拒绝}
|
|
|
+ /// 教师拉取自己收到的分享及共编
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("agree")]
|
|
|
+ // [AuthToken(Roles = "Teacher")]
|
|
|
+ public async Task<IActionResult> Agree(JsonElement request) {
|
|
|
+ try {
|
|
|
+ if (!request.TryGetProperty("agree", out JsonElement agree)) { return BadRequest(); }
|
|
|
+ if (!request.TryGetProperty("code", out JsonElement code)) { return BadRequest(); }
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id)) { return BadRequest(); }
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ Share share= await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Share>($"{id}", new PartitionKey($"Share-{code}"));
|
|
|
+ if (agree.ValueKind.Equals(JsonValueKind.Number))
|
|
|
+ {
|
|
|
+ int agreeNum = agree.GetInt32();
|
|
|
+ if (agreeNum == 1)
|
|
|
+ {
|
|
|
+ share.cagree = 1;
|
|
|
+ }
|
|
|
+ else if (agreeNum == 2)
|
|
|
+ {
|
|
|
+ share.cagree = 2;
|
|
|
+ }
|
|
|
+ else if (agreeNum == 3)
|
|
|
+ {
|
|
|
+ share.sagree = 1;
|
|
|
+ }
|
|
|
+ else if (agreeNum == 4)
|
|
|
+ {
|
|
|
+ share.sagree = 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { status = 500 });
|
|
|
+ }
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share, $"{id}", new PartitionKey($"Share-{code}"));
|
|
|
+ Syllabus syllabus = null;
|
|
|
+ if (share.scope == "school")
|
|
|
+ {
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
+ }
|
|
|
+ else if (share.scope == "private")
|
|
|
+ {
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
+ }
|
|
|
+ if (syllabus.auth.IsNotEmpty())
|
|
|
+ {
|
|
|
+ syllabus.auth.ForEach(x =>
|
|
|
+ {
|
|
|
+ if (x.tmdid == $"{code}")
|
|
|
+ {
|
|
|
+ if (agreeNum == 1)
|
|
|
+ {
|
|
|
+ x.cagree = 1;
|
|
|
+ }
|
|
|
+ else if (agreeNum == 2)
|
|
|
+ {
|
|
|
+ x.cagree = 2;
|
|
|
+ }
|
|
|
+ else if (agreeNum == 3)
|
|
|
+ {
|
|
|
+ x.sagree = 1;
|
|
|
+ }
|
|
|
+ else if (agreeNum == 4)
|
|
|
+ {
|
|
|
+ x.sagree = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (share.scope == "school")
|
|
|
+ {
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
+ }
|
|
|
+ else if (share.scope == "private")
|
|
|
+ {
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
+ }
|
|
|
+ return Ok(new { status = 200 });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { status = 500 });
|
|
|
+ }
|
|
|
+ } catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/agree()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return Ok(new { status = 500 });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
@@ -299,7 +439,7 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("view-share")]
|
|
|
- // [AuthToken(Roles = "Teacher")]
|
|
|
+ [AuthToken(Roles = "teacher")]
|
|
|
public async Task<IActionResult> View(ShareView request)
|
|
|
{
|
|
|
try
|