|
@@ -39,6 +39,7 @@ using System.Runtime.Intrinsics.X86;
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
using TEAMModelOS.SDK.Models.Dtos;
|
|
|
using System.Net.Http;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -366,10 +367,7 @@ namespace TEAMModelOS.Controllers
|
|
|
[ProducesDefaultResponseType]
|
|
|
[AuthToken(Roles = "teacher,admin,area")]
|
|
|
[HttpPost("manage")]
|
|
|
-#if !DEBUG
|
|
|
[Authorize(Roles = "IES")]
|
|
|
-#endif
|
|
|
-
|
|
|
public async Task<IActionResult> Manage(JsonElement request)
|
|
|
{
|
|
|
try
|
|
@@ -650,73 +648,7 @@ namespace TEAMModelOS.Controllers
|
|
|
//教师活动列表
|
|
|
case bool when $"{grant_type}".Equals("list-teacher", StringComparison.OrdinalIgnoreCase):
|
|
|
{
|
|
|
- List<Activity> activities = new List<Activity>();
|
|
|
- HashSet<string> inviteActivityIds = new HashSet<string>();
|
|
|
- string yearSql = $" and c.year={DateTimeOffset.Now.Year}";
|
|
|
- if (request.TryGetProperty("year", out JsonElement _year))
|
|
|
- {
|
|
|
- yearSql = $" and c.year={_year}";
|
|
|
- }
|
|
|
- //先获取邀请制的
|
|
|
- string sqlInvite = $"select value c from c join t in c.inviteTeachers where t.id='{tmdid}'";
|
|
|
- var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ActivityTeacher>(sqlInvite, "ActivityTeacher");
|
|
|
- inviteActivityIds= result.list.Select(z => z.id).ToHashSet();
|
|
|
- if (inviteActivityIds.Count>0) {
|
|
|
- string sqlActivity = $"select value c from c where c.id in ({string.Join(",", inviteActivityIds.Select(z => $"'{z}'"))}) {yearSql} ";
|
|
|
- var resultActivity = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<Activity>(sqlInvite, "ActivityTeacher");
|
|
|
- if (resultActivity.list.IsNotEmpty()) {
|
|
|
- activities.AddRange(resultActivity.list);
|
|
|
- }
|
|
|
- }
|
|
|
- Teacher teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>(tmdid, new PartitionKey("Base"));
|
|
|
- string schoolOwnerIn = string.Empty;
|
|
|
- string schoolIdIn = string.Empty;
|
|
|
- if (teacher.schools.IsNotEmpty()) {
|
|
|
- schoolIdIn = $"and i.id in ({string.Join(",", teacher.schools.Select(z => $"'{z.schoolId}'"))})";
|
|
|
- schoolOwnerIn= $"and c.owner in ({string.Join(",", teacher.schools.Select(z => $"'{z.schoolId}'"))})";
|
|
|
- }
|
|
|
- //获取开放的
|
|
|
- {
|
|
|
- //完全开放 所有的学校
|
|
|
- string sqlOpen = $"select value c from c where c.scope='public' and (c.publish=1 or c.publish=2 ) and( ARRAY_LENGTH(c.invitedSchools)=0 or IS_DEFINED(c.invitedSchools) = false ) {yearSql} ";
|
|
|
- var resultOpen = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<Activity>(sqlOpen, "Activity");
|
|
|
- activities.AddRange(resultOpen.list);
|
|
|
-
|
|
|
- if (!string.IsNullOrWhiteSpace(schoolIdIn))
|
|
|
- { //部分学校
|
|
|
- string sqlSchool = $"select value c from c join i in c.confirmedSchools where c.scope='public' and c.joinMode='enroll' and (c.publish=1 or c.publish=2 ) and i.status=1 {yearSql} {schoolIdIn} ";
|
|
|
- var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<Activity>(sqlSchool, "Activity");
|
|
|
- activities.AddRange(resultSchool.list);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- string areaOwnerIn = string.Empty;
|
|
|
- var hasAreaSchools = teacher.schools.FindAll(z => !string.IsNullOrWhiteSpace(z.areaId));
|
|
|
- if (hasAreaSchools.IsNotEmpty())
|
|
|
- {
|
|
|
- areaOwnerIn = $"and c.owner in ({string.Join(",", hasAreaSchools.Select(z => $"'{z.areaId}'"))})";
|
|
|
- schoolIdIn = $"and i.id in ({string.Join(",", hasAreaSchools.Select(z => $"'{z.schoolId}'"))})";
|
|
|
- }
|
|
|
- //获取所有区级的
|
|
|
- if (!string.IsNullOrWhiteSpace(areaOwnerIn) && !string.IsNullOrEmpty(schoolIdIn)) {
|
|
|
-
|
|
|
- string sqlOpen = $"select value c from c join i in c.confirmedSchools where c.scope='area' and c.joinMode='enroll' and (c.publish=1 or c.publish=2 ) and i.status=1 {yearSql} {areaOwnerIn} {schoolIdIn} ";
|
|
|
- var resultOpen = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<Activity>(sqlOpen, "Activity");
|
|
|
- activities.AddRange(resultOpen.list);
|
|
|
- }
|
|
|
-
|
|
|
- //获取所有学校的
|
|
|
- if (!string.IsNullOrWhiteSpace(schoolOwnerIn))
|
|
|
- {
|
|
|
- string sqlSchool = $"select value c from c where c.scope='school' and c.joinMode='enroll' and (c.publish=1 or c.publish=2 ) {yearSql} {schoolOwnerIn} ";
|
|
|
- var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<Activity>(sqlSchool, "Activity");
|
|
|
- activities.AddRange(resultSchool.list);
|
|
|
- }
|
|
|
-
|
|
|
- activities.ForEach(z => {
|
|
|
- var (blob_uri, blob_sas) = _azureStorage.GetBlobContainerSAS(z.owner, BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
|
|
|
- z.sas=blob_sas;
|
|
|
- });
|
|
|
+ List<TeacherActivityDto> activities = await TeacherActivityList(request, tmdid);
|
|
|
return Ok(new { activities = activities.OrderByDescending(z => z.stime) });
|
|
|
}
|
|
|
//读取优课评选模块及评审规则
|
|
@@ -1357,6 +1289,83 @@ namespace TEAMModelOS.Controllers
|
|
|
return Ok();
|
|
|
}
|
|
|
|
|
|
+ private async Task<List<TeacherActivityDto>> TeacherActivityList(JsonElement request, string tmdid)
|
|
|
+ {
|
|
|
+ List<TeacherActivityDto> activities = new List<TeacherActivityDto>();
|
|
|
+ HashSet<string> inviteActivityIds = new HashSet<string>();
|
|
|
+ string yearSql = $" and c.year={DateTimeOffset.Now.Year}";
|
|
|
+ if (request.TryGetProperty("year", out JsonElement _year))
|
|
|
+ {
|
|
|
+ yearSql = $" and c.year={_year}";
|
|
|
+ }
|
|
|
+ //先获取邀请制的
|
|
|
+ string sqlInvite = $"select value c from c join t in c.inviteTeachers where t.id='{tmdid}'";
|
|
|
+ var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ActivityTeacher>(sqlInvite, "ActivityTeacher");
|
|
|
+ inviteActivityIds= result.list.Select(z => z.id).ToHashSet();
|
|
|
+ if (inviteActivityIds.Count>0)
|
|
|
+ {
|
|
|
+ string sqlActivity = $"select value c from c where c.id in ({string.Join(",", inviteActivityIds.Select(z => $"'{z}'"))}) {yearSql} ";
|
|
|
+ var resultActivity = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<TeacherActivityDto>(sqlInvite, "Activity");
|
|
|
+ if (resultActivity.list.IsNotEmpty())
|
|
|
+ {
|
|
|
+ activities.AddRange(resultActivity.list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Teacher teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Teacher>(tmdid, new PartitionKey("Base"));
|
|
|
+ string schoolOwnerIn = string.Empty;
|
|
|
+ string schoolIdIn = string.Empty;
|
|
|
+ if (teacher.schools.IsNotEmpty())
|
|
|
+ {
|
|
|
+ schoolIdIn = $"and i.id in ({string.Join(",", teacher.schools.Select(z => $"'{z.schoolId}'"))})";
|
|
|
+ schoolOwnerIn= $"and c.owner in ({string.Join(",", teacher.schools.Select(z => $"'{z.schoolId}'"))})";
|
|
|
+ }
|
|
|
+ //获取开放的
|
|
|
+ {
|
|
|
+ //完全开放 所有的学校
|
|
|
+ string sqlOpen = $"select value c from c where c.scope='public' and (c.publish=1 or c.publish=2 ) and( ARRAY_LENGTH(c.invitedSchools)=0 or IS_DEFINED(c.invitedSchools) = false ) {yearSql} ";
|
|
|
+ var resultOpen = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<TeacherActivityDto>(sqlOpen, "Activity");
|
|
|
+ activities.AddRange(resultOpen.list);
|
|
|
+
|
|
|
+ if (!string.IsNullOrWhiteSpace(schoolIdIn))
|
|
|
+ { //部分学校
|
|
|
+ string sqlSchool = $"select value c from c join i in c.confirmedSchools where c.scope='public' and c.joinMode='enroll' and (c.publish=1 or c.publish=2 ) and i.status=1 {yearSql} {schoolIdIn} ";
|
|
|
+ var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<TeacherActivityDto>(sqlSchool, "Activity");
|
|
|
+ activities.AddRange(resultSchool.list);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ string areaOwnerIn = string.Empty;
|
|
|
+ var hasAreaSchools = teacher.schools.FindAll(z => !string.IsNullOrWhiteSpace(z.areaId));
|
|
|
+ if (hasAreaSchools.IsNotEmpty())
|
|
|
+ {
|
|
|
+ areaOwnerIn = $"and c.owner in ({string.Join(",", hasAreaSchools.Select(z => $"'{z.areaId}'"))})";
|
|
|
+ schoolIdIn = $"and i.id in ({string.Join(",", hasAreaSchools.Select(z => $"'{z.schoolId}'"))})";
|
|
|
+ }
|
|
|
+ //获取所有区级的
|
|
|
+ if (!string.IsNullOrWhiteSpace(areaOwnerIn) && !string.IsNullOrEmpty(schoolIdIn))
|
|
|
+ {
|
|
|
+
|
|
|
+ string sqlOpen = $"select value c from c join i in c.confirmedSchools where c.scope='area' and c.joinMode='enroll' and (c.publish=1 or c.publish=2 ) and i.status=1 {yearSql} {areaOwnerIn} {schoolIdIn} ";
|
|
|
+ var resultOpen = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<TeacherActivityDto>(sqlOpen, "Activity");
|
|
|
+ activities.AddRange(resultOpen.list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取所有学校的
|
|
|
+ if (!string.IsNullOrWhiteSpace(schoolOwnerIn))
|
|
|
+ {
|
|
|
+ string sqlSchool = $"select value c from c where c.scope='school' and c.joinMode='enroll' and (c.publish=1 or c.publish=2 ) {yearSql} {schoolOwnerIn} ";
|
|
|
+ var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<TeacherActivityDto>(sqlSchool, "Activity");
|
|
|
+ activities.AddRange(resultSchool.list);
|
|
|
+ }
|
|
|
+
|
|
|
+ activities.ForEach(z =>
|
|
|
+ {
|
|
|
+ var (blob_uri, blob_sas) = _azureStorage.GetBlobContainerSAS(z.owner, BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
|
|
|
+ z.sas=blob_sas;
|
|
|
+ });
|
|
|
+ return activities;
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// portal站的
|
|
|
/// </summary>
|
|
@@ -1462,7 +1471,19 @@ namespace TEAMModelOS.Controllers
|
|
|
// 產出所需要的 JWT securityToken 物件,並取得序列化後的 Token 結果(字串格式)
|
|
|
var tokenHandler = new JwtSecurityTokenHandler();
|
|
|
var serializeToken = tokenHandler.WriteToken(secToken);
|
|
|
- return Ok(new { code =200,token =serializeToken, schools= teacherInfo.teacher.schools.Where(z=>z.status.Equals("join"))});
|
|
|
+ var core_clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var core_clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ string location= _option.Location;
|
|
|
+ if (location.Contains("China"))
|
|
|
+ {
|
|
|
+ location = "China";
|
|
|
+ }
|
|
|
+ else if (location.Contains("Global"))
|
|
|
+ {
|
|
|
+ location = "Global";
|
|
|
+ }
|
|
|
+ var access_token = await CoreTokenExtensions.CreateAccessToken(core_clientID, core_clientSecret, location);
|
|
|
+ return Ok(new { auth_token = new { access_token= access_token .AccessToken, token_type= access_token.TokenType, expires_in= access_token.ExpiresOn}, code =200,token =serializeToken, schools= teacherInfo.teacher.schools.Where(z=>z.status.Equals("join"))});
|
|
|
}
|
|
|
/// <summary>
|
|
|
///
|
|
@@ -1501,8 +1522,37 @@ namespace TEAMModelOS.Controllers
|
|
|
else {
|
|
|
return Ok(new { code = 2, msg = "未匹配分站" }) ;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 教师在赛课模块的操作
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("teacher-contest")]
|
|
|
+ [AuthToken(Roles = "teacher")]
|
|
|
+#if !DEBUG
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+#endif
|
|
|
+ public async Task<IActionResult> Teacher(JsonElement request) {
|
|
|
+ (string tmdid, _, _, _) = HttpContext.GetAuthTokenInfo();
|
|
|
+ if (!request.TryGetProperty("grant_type", out JsonElement grant_type)) return BadRequest();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ switch (true)
|
|
|
+ {
|
|
|
+ //教师活动列表
|
|
|
+ case bool when $"{grant_type}".Equals("create", StringComparison.OrdinalIgnoreCase):
|
|
|
+ {
|
|
|
+ List<TeacherActivityDto> activities= await TeacherActivityList(request, tmdid);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// portal站的
|
|
|
/// </summary>
|