|
@@ -27,7 +27,7 @@ namespace TEAMModelOS.Controllers
|
|
//[Authorize(Roles = "IES5")]
|
|
//[Authorize(Roles = "IES5")]
|
|
[Route("teacher/share")]
|
|
[Route("teacher/share")]
|
|
[ApiController]
|
|
[ApiController]
|
|
- public class ShareController: ControllerBase
|
|
|
|
|
|
+ public class ShareController : ControllerBase
|
|
{
|
|
{
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
private readonly SnowflakeId _snowflakeId;
|
|
private readonly SnowflakeId _snowflakeId;
|
|
@@ -40,7 +40,7 @@ namespace TEAMModelOS.Controllers
|
|
_azureCosmos = azureCosmos;
|
|
_azureCosmos = azureCosmos;
|
|
_snowflakeId = snowflakeId;
|
|
_snowflakeId = snowflakeId;
|
|
_dingDing = dingDing;
|
|
_dingDing = dingDing;
|
|
- _option = option?.Value;
|
|
|
|
|
|
+ _option = option?.Value;
|
|
_configuration = configuration;
|
|
_configuration = configuration;
|
|
_notificationService = notificationService;
|
|
_notificationService = notificationService;
|
|
}
|
|
}
|
|
@@ -67,7 +67,7 @@ namespace TEAMModelOS.Controllers
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
[HttpPost("to")]
|
|
[HttpPost("to")]
|
|
- // [AuthToken(Roles = "Teacher")]
|
|
|
|
|
|
+ // [AuthToken(Roles = "Teacher")]
|
|
public async Task<IActionResult> To(ShareData request) {
|
|
public async Task<IActionResult> To(ShareData request) {
|
|
// var (id, _, _, _) = HttpContext.GetAuthTokenInfo();
|
|
// var (id, _, _, _) = HttpContext.GetAuthTokenInfo();
|
|
|
|
|
|
@@ -82,11 +82,11 @@ namespace TEAMModelOS.Controllers
|
|
if (syllabusD.auth.IsNotEmpty())
|
|
if (syllabusD.auth.IsNotEmpty())
|
|
{
|
|
{
|
|
List<SyllabusAuth> syllabusAuths = new List<SyllabusAuth>();
|
|
List<SyllabusAuth> syllabusAuths = new List<SyllabusAuth>();
|
|
- syllabusD.auth.ForEach(x=> {
|
|
|
|
- if (request.tmdInfo.Select(tmd=>tmd.tmdid).Contains(x.tmdid)) {
|
|
|
|
|
|
+ syllabusD.auth.ForEach(x => {
|
|
|
|
+ if (request.tmdInfo.Select(tmd => tmd.tmdid).Contains(x.tmdid)) {
|
|
syllabusAuths.Add(x);
|
|
syllabusAuths.Add(x);
|
|
- }
|
|
|
|
- }) ;
|
|
|
|
|
|
+ }
|
|
|
|
+ });
|
|
syllabusAuths.ForEach(x => {
|
|
syllabusAuths.ForEach(x => {
|
|
syllabusD.auth.Remove(x);
|
|
syllabusD.auth.Remove(x);
|
|
});
|
|
});
|
|
@@ -94,13 +94,13 @@ namespace TEAMModelOS.Controllers
|
|
request.tmdInfo.ForEach(async x => {
|
|
request.tmdInfo.ForEach(async x => {
|
|
await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>(request.syllabusId, new PartitionKey($"Share-{x.tmdid}"));
|
|
await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>(request.syllabusId, new PartitionKey($"Share-{x.tmdid}"));
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (request.opt.Equals("add") || request.opt.Equals("edit"))
|
|
else if (request.opt.Equals("add") || request.opt.Equals("edit"))
|
|
{
|
|
{
|
|
(Syllabus syllabus, List<Share> shares) = DoAuth(request, syllabusD);
|
|
(Syllabus syllabus, List<Share> shares) = DoAuth(request, syllabusD);
|
|
- shares.ForEach(async x=> {
|
|
|
|
|
|
+ shares.ForEach(async x => {
|
|
await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<Share>(x, new PartitionKey($"{x.code}"));
|
|
await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<Share>(x, new PartitionKey($"{x.code}"));
|
|
//发送共编或分享通知
|
|
//发送共编或分享通知
|
|
Notification notification = new Notification
|
|
Notification notification = new Notification
|
|
@@ -108,9 +108,9 @@ namespace TEAMModelOS.Controllers
|
|
hubName = "hita",
|
|
hubName = "hita",
|
|
type = "msg",
|
|
type = "msg",
|
|
from = $"ies5:{request.school}",
|
|
from = $"ies5:{request.school}",
|
|
- to = new List<string>() { x.code.Replace("Share-","") },
|
|
|
|
|
|
+ to = new List<string>() { x.code.Replace("Share-", "") },
|
|
label = $"{x.type}_syllabus",
|
|
label = $"{x.type}_syllabus",
|
|
- body = new { biz = x.type, tmdid = x.issuer, schoolcode = $"{request.school}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
|
|
|
+ body = new { biz = x.type, tmdid = x.issuer, schoolcode = $"{request.school}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
};
|
|
};
|
|
var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
@@ -121,7 +121,7 @@ namespace TEAMModelOS.Controllers
|
|
});
|
|
});
|
|
await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<Syllabus>(syllabus, new PartitionKey($"Syllabus-{request.volumeId}"));
|
|
await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<Syllabus>(syllabus, new PartitionKey($"Syllabus-{request.volumeId}"));
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (request.scope.Equals("private"))
|
|
else if (request.scope.Equals("private"))
|
|
@@ -133,7 +133,7 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
List<SyllabusAuth> syllabusAuths = new List<SyllabusAuth>();
|
|
List<SyllabusAuth> syllabusAuths = new List<SyllabusAuth>();
|
|
syllabusD.auth.ForEach(x => {
|
|
syllabusD.auth.ForEach(x => {
|
|
- if (request.tmdInfo.Select(tmd=>x.tmdid).Contains(x.tmdid))
|
|
|
|
|
|
+ if (request.tmdInfo.Select(tmd => x.tmdid).Contains(x.tmdid))
|
|
{
|
|
{
|
|
syllabusAuths.Add(x);
|
|
syllabusAuths.Add(x);
|
|
}
|
|
}
|
|
@@ -156,9 +156,9 @@ namespace TEAMModelOS.Controllers
|
|
await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<Syllabus>(syllabusD, new PartitionKey($"Syllabus-{request.volumeId}"));
|
|
await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<Syllabus>(syllabusD, new PartitionKey($"Syllabus-{request.volumeId}"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return Ok(new { code=200});
|
|
|
|
|
|
+ return Ok(new { code = 200 });
|
|
}
|
|
}
|
|
- catch (Exception ex ) {
|
|
|
|
|
|
+ catch (Exception ex) {
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/to\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/to\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
}
|
|
}
|
|
return Ok(new { code = 500 });
|
|
return Ok(new { code = 500 });
|
|
@@ -182,12 +182,12 @@ namespace TEAMModelOS.Controllers
|
|
createTime = now,
|
|
createTime = now,
|
|
school = request.school,
|
|
school = request.school,
|
|
scope = request.scope,
|
|
scope = request.scope,
|
|
- type =request.type,
|
|
|
|
|
|
+ type = request.type,
|
|
agree = request.agree
|
|
agree = request.agree
|
|
};
|
|
};
|
|
shares.Add(share);
|
|
shares.Add(share);
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
if (syllabus.auth.IsNotEmpty())
|
|
if (syllabus.auth.IsNotEmpty())
|
|
{
|
|
{
|
|
request.tmdInfo.ForEach(xmd => {
|
|
request.tmdInfo.ForEach(xmd => {
|
|
@@ -196,7 +196,7 @@ namespace TEAMModelOS.Controllers
|
|
int indx = 0;
|
|
int indx = 0;
|
|
for (int index = 0; index < syllabus.auth.Count; index++)
|
|
for (int index = 0; index < syllabus.auth.Count; index++)
|
|
{
|
|
{
|
|
- if (syllabus.auth[index].tmdid == xmd.tmdid && request.type== syllabus.auth[index].type)
|
|
|
|
|
|
+ if (syllabus.auth[index].tmdid == xmd.tmdid && request.type == syllabus.auth[index].type)
|
|
{
|
|
{
|
|
flag = true;
|
|
flag = true;
|
|
indx = index;
|
|
indx = index;
|
|
@@ -273,7 +273,7 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
syllabus.auth.ForEach(x =>
|
|
syllabus.auth.ForEach(x =>
|
|
{
|
|
{
|
|
- if (x.tmdid == $"{code}" && x.type==$"{type}")
|
|
|
|
|
|
+ if (x.tmdid == $"{code}" && x.type == $"{type}")
|
|
{
|
|
{
|
|
if ($"{opt}".Equals("ignore"))
|
|
if ($"{opt}".Equals("ignore"))
|
|
{
|
|
{
|
|
@@ -282,34 +282,51 @@ namespace TEAMModelOS.Controllers
|
|
else if ($"{opt}".Equals("ignore")) {
|
|
else if ($"{opt}".Equals("ignore")) {
|
|
x.agree = 1;
|
|
x.agree = 1;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- 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}"));
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
if ($"{opt}".Equals("ignore"))
|
|
if ($"{opt}".Equals("ignore"))
|
|
{
|
|
{
|
|
share.agree = 1;
|
|
share.agree = 1;
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share,$"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share, $"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
}
|
|
}
|
|
else if ($"{opt}".Equals("ignore"))
|
|
else if ($"{opt}".Equals("ignore"))
|
|
{
|
|
{
|
|
await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
}
|
|
}
|
|
|
|
+ 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 });
|
|
return Ok(new { status = 200 });
|
|
} catch (Exception ex) {
|
|
} catch (Exception ex) {
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/agree-share()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/agree-share()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
return Ok(new { status = 500 });
|
|
return Ok(new { status = 500 });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [HttpPost("del-share")]
|
|
|
|
+ public async Task<IActionResult> DelShare(JsonElement request) {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+ if (!request.TryGetProperty("type", out JsonElement type)) { return BadRequest(); }
|
|
|
|
+ if (!request.TryGetProperty("code", out JsonElement code)) { return BadRequest(); }
|
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id)) { return BadRequest(); }
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
|
|
+ return Ok(new { status = 200 });
|
|
|
|
+ } catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/del-share()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
|
+ return Ok(new { status = 500 });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
/// <summary>
|
|
/// <summary>
|
|
/// {"code":"教师编码","type":"coedit/share","id":"册别id"}
|
|
/// {"code":"教师编码","type":"coedit/share","id":"册别id"}
|
|
/// 教师拉取自己收到的分享及共编
|
|
/// 教师拉取自己收到的分享及共编
|
|
@@ -339,12 +356,12 @@ namespace TEAMModelOS.Controllers
|
|
shares.Add(item);
|
|
shares.Add(item);
|
|
}
|
|
}
|
|
var sharesGp = shares.GroupBy(x => new {id= x.volumeId ,code=x.scope=="school"?x.school:x.issuer}).Select(y=>new { id=y.Key.id,code=y.Key.code,list=y.ToList()});
|
|
var sharesGp = shares.GroupBy(x => new {id= x.volumeId ,code=x.scope=="school"?x.school:x.issuer}).Select(y=>new { id=y.Key.id,code=y.Key.code,list=y.ToList()});
|
|
- return Ok(new { shares = sharesGp });
|
|
|
|
|
|
+ return Ok(new { shares = sharesGp ,status=200});
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/find()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
await _dingDing.SendBotMsg($"OS,{_option.Location},teacher/share/find()\n{ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
- return BadRequest();
|
|
|
|
|
|
+ return Ok(new { status = 404 });
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|