|
@@ -37,6 +37,8 @@ using Azure.Storage.Sas;
|
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
|
using System.Runtime.Intrinsics.X86;
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
+using TEAMModelOS.SDK.Models.Dtos;
|
|
|
+using System.Net.Http;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -987,6 +989,174 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
return Ok(new { inviteTeachers });
|
|
|
}
|
|
|
+ //导入评审专家
|
|
|
+ case bool when $"{grant_type}".Equals("invited-teachers", StringComparison.OrdinalIgnoreCase):
|
|
|
+ {
|
|
|
+ if (!request.TryGetProperty("activityId", out JsonElement _activityId)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("experts", out JsonElement _experts) || !_experts.ValueKind.Equals(JsonValueKind.Array)) { return BadRequest(); }
|
|
|
+ List<Expert> experts = _experts.ToObject<List<Expert>>();
|
|
|
+ var tmdids = experts.Where(x => !string.IsNullOrWhiteSpace(x.tmdid)).Select(z => z.tmdid);
|
|
|
+ var phones = experts.Where(x => !string.IsNullOrWhiteSpace(x.mobile)).Select(z => z.mobile);
|
|
|
+ var emails = experts.Where(x => !string.IsNullOrWhiteSpace(x.email)).Select(z => z.email);
|
|
|
+ List<string> keys = new List<string>();
|
|
|
+ if (tmdids.Any())
|
|
|
+ {
|
|
|
+ keys.AddRange(tmdids);
|
|
|
+ }
|
|
|
+ if (phones.Any())
|
|
|
+ {
|
|
|
+ keys.AddRange(phones);
|
|
|
+ }
|
|
|
+ if (emails.Any())
|
|
|
+ {
|
|
|
+ keys.AddRange(emails);
|
|
|
+ }
|
|
|
+ ActivityExpert activityExpert = null;
|
|
|
+ experts.ForEach(x => { x.status = 0; x.iname = x.name; x.name = null; });
|
|
|
+ List<CoreUser> coreUsers = new List<CoreUser>();
|
|
|
+ if (keys.Any())
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var content = new StringContent(keys.ToJsonString(), Encoding.UTF8, "application/json");
|
|
|
+ string json = await _coreAPIHttpService.GetUserInfos(content);
|
|
|
+ if (!string.IsNullOrWhiteSpace(json))
|
|
|
+ {
|
|
|
+ coreUsers = json.ToObject<List<CoreUser>>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"{_option.Location},导入名单时,查验key信息错误{ex.Message}\n{ex.StackTrace}\n\n{keys.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (coreUsers.IsNotEmpty())
|
|
|
+ {
|
|
|
+ foreach (var t in experts)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrWhiteSpace(t.tmdid))
|
|
|
+ {
|
|
|
+ CoreUser coreUser = coreUsers.Find(x => x.id.Equals(t.tmdid));
|
|
|
+ if (coreUser != null)
|
|
|
+ {
|
|
|
+ t.id = coreUser.id;
|
|
|
+ t.name = coreUser.name;
|
|
|
+ t.picture = coreUser.picture;
|
|
|
+ t.tmdid = coreUser.id;
|
|
|
+ if (!string.IsNullOrWhiteSpace(coreUser.mobile))
|
|
|
+ {
|
|
|
+ t.mobile = coreUser.mobile;
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(coreUser.mail))
|
|
|
+ {
|
|
|
+ t.email = coreUser.mail;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (string.IsNullOrWhiteSpace(t.id))
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrWhiteSpace(t.mobile))
|
|
|
+ {
|
|
|
+ CoreUser coreUser = coreUsers.Find(x => !string.IsNullOrWhiteSpace(x.mobile) && x.mobile.Equals(t.mobile));
|
|
|
+ if (coreUser != null)
|
|
|
+ {
|
|
|
+ t.id = coreUser.id;
|
|
|
+ t.name = coreUser.name;
|
|
|
+ t.picture = coreUser.picture;
|
|
|
+ t.tmdid = coreUser.id;
|
|
|
+ if (!string.IsNullOrWhiteSpace(coreUser.mobile))
|
|
|
+ {
|
|
|
+ t.mobile = coreUser.mobile;
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(coreUser.mail))
|
|
|
+ {
|
|
|
+ t.email = coreUser.mail;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (string.IsNullOrWhiteSpace(t.id))
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrWhiteSpace(t.email))
|
|
|
+ {
|
|
|
+ CoreUser coreUser = coreUsers.Find(x => !string.IsNullOrWhiteSpace(x.mail) && x.mail.Equals(t.email));
|
|
|
+ if (coreUser != null)
|
|
|
+ {
|
|
|
+ t.id = coreUser.id;
|
|
|
+ t.name = coreUser.name;
|
|
|
+ t.picture = coreUser.picture;
|
|
|
+ t.tmdid = coreUser.id;
|
|
|
+ if (!string.IsNullOrWhiteSpace(coreUser.mobile))
|
|
|
+ {
|
|
|
+ t.mobile = coreUser.mobile;
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(coreUser.mail))
|
|
|
+ {
|
|
|
+ t.email = coreUser.mail;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemStreamAsync($"{_activityId}", new PartitionKey("ActivityExpert"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ activityExpert = JsonDocument.Parse(response.Content).RootElement.Deserialize<ActivityExpert>();
|
|
|
+ experts.ForEach(x =>
|
|
|
+ {
|
|
|
+ Expert tch = null;
|
|
|
+ if (string.IsNullOrWhiteSpace(x.id))
|
|
|
+ {
|
|
|
+ tch = activityExpert.experts.Find(t => !string.IsNullOrWhiteSpace(t.iname) && t.iname.Equals(x.iname));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tch = activityExpert.experts.Find(t => !string.IsNullOrWhiteSpace(x.id) && !string.IsNullOrWhiteSpace(t.id) && t.id.Equals(x.id));
|
|
|
+ }
|
|
|
+ if (tch != null)
|
|
|
+ {
|
|
|
+ tch.status = x.status;
|
|
|
+ tch.name = x.name;
|
|
|
+ tch.iname = x.iname;
|
|
|
+ tch.picture = x.picture;
|
|
|
+ tch.mobile = x.mobile;
|
|
|
+ tch.tmdid = x.tmdid;
|
|
|
+ tch.email = x.email;
|
|
|
+ tch.id = x.id;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ activityExpert.experts.Add(new Expert
|
|
|
+ {
|
|
|
+ status = x.status,
|
|
|
+ name = x.name,
|
|
|
+ iname = x.iname,
|
|
|
+ picture = x.picture,
|
|
|
+ mobile = x.mobile,
|
|
|
+ tmdid = x.tmdid,
|
|
|
+ email = x.email,
|
|
|
+ id = x.id,
|
|
|
+ title = x.title,
|
|
|
+ subjects = x.subjects,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).UpsertItemAsync(activityExpert, new PartitionKey("ActivityExpert"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ activityExpert = new ActivityExpert { id = $"{_activityId}", code = "ActivityExpert", pk = "ActivityExpert", experts = experts };
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).UpsertItemAsync(activityExpert, new PartitionKey("ActivityExpert"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ activityExpert = new ActivityExpert { id = $"{_activityId}", code = "ActivityExpert", pk = "ActivityExpert", experts = experts };
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).UpsertItemAsync(activityExpert, new PartitionKey("ActivityExpert"));
|
|
|
+ }
|
|
|
+ return Ok(new { activityExpert});
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
} catch (Exception ex)
|
|
|
{
|
|
@@ -1032,19 +1202,26 @@ namespace TEAMModelOS.Controllers
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- if (tmdid == null && !string.IsNullOrWhiteSpace($"{_token}")) {
|
|
|
+ if (tmdid == null && !string.IsNullOrWhiteSpace($"{_token}"))
|
|
|
+ {
|
|
|
var jwt = new JwtSecurityToken(_token.GetString());
|
|
|
- tmdid = jwt.Payload.Sub;
|
|
|
-
|
|
|
- if (HttpContext.Request.Headers.TryGetValue("lang", out var _lang))
|
|
|
+ if (JwtAuthExtension.ValidateAuthTokenRefresh(_token.GetString(), _option.JwtSecretKey))
|
|
|
{
|
|
|
- head_lang = $"{_lang}";
|
|
|
+ tmdid = jwt.Payload.Sub;
|
|
|
+
|
|
|
+ if (HttpContext.Request.Headers.TryGetValue("lang", out var _lang))
|
|
|
+ {
|
|
|
+ head_lang = $"{_lang}";
|
|
|
+ }
|
|
|
+ jwt.Payload.TryGetValue("name", out name);
|
|
|
+ jwt.Payload.TryGetValue("picture", out picture);
|
|
|
+ jwt.Payload.TryGetValue("lang", out object _jwtlang);
|
|
|
+ head_lang = !string.IsNullOrWhiteSpace($"{_jwtlang}") ? $"{_jwtlang}" : head_lang;
|
|
|
}
|
|
|
- jwt.Payload.TryGetValue("name", out name);
|
|
|
- jwt.Payload.TryGetValue("picture", out picture);
|
|
|
- jwt.Payload.TryGetValue("lang", out object _jwtlang);
|
|
|
- head_lang = !string.IsNullOrWhiteSpace($"{_jwtlang}") ? $"{_jwtlang}" : head_lang;
|
|
|
+ else { return Ok(new { code = 2, msg = "Token验证失败" }); }
|
|
|
+
|
|
|
}
|
|
|
+ else { return Ok(new { code = 3, msg = "凭证验证失败" }); }
|
|
|
teacherInfo = await TeacherService.TeacherInfoLite(_azureCosmos, $"{name}", $"{picture}", tmdid, _azureStorage, _option, _azureRedis, ip, _httpTrigger, head_lang);
|
|
|
string sql = $"select value c from c where c.route='{_route}'";
|
|
|
var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetList<ActivityWebsite>(sql, "ActivityWebsite");
|
|
@@ -1066,7 +1243,7 @@ namespace TEAMModelOS.Controllers
|
|
|
CoreUser coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", teacherInfo.teacher.id } }, _option.Location, _configuration);
|
|
|
string sqlExpert = $"select value c from c join e in c.experts where e.id='{teacherInfo.teacher.id}'";
|
|
|
if (!string.IsNullOrWhiteSpace(coreUser.mobile)) {
|
|
|
- sqlExpert=$" or e.mobile='{coreUser.mobile}' ";
|
|
|
+ sqlExpert=$" {sqlExpert } or e.mobile='{coreUser.mobile}' ";
|
|
|
|
|
|
}
|
|
|
var resultActivityExpert = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetList<ActivityExpert>(sqlExpert, "ActivityExpert",pageSize:1);
|
|
@@ -1090,7 +1267,7 @@ namespace TEAMModelOS.Controllers
|
|
|
// 產出所需要的 JWT securityToken 物件,並取得序列化後的 Token 結果(字串格式)
|
|
|
var tokenHandler = new JwtSecurityTokenHandler();
|
|
|
var serializeToken = tokenHandler.WriteToken(secToken);
|
|
|
- return Ok(new { website, code =200,token =serializeToken, schools= teacherInfo.teacher.schools.Where(z=>z.status.Equals("join"))});
|
|
|
+ return Ok(new { code =200,token =serializeToken, schools= teacherInfo.teacher.schools.Where(z=>z.status.Equals("join"))});
|
|
|
}
|
|
|
|
|
|
|