|
@@ -36,6 +36,7 @@ namespace TEAMModelOS.Controllers
|
|
|
private readonly Option _option;
|
|
|
private readonly AzureServiceBusFactory _serviceBus;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
+ private const string SummarySql = " c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type,c.year,c.tcount,c.scount ";
|
|
|
public IConfiguration _configuration { get; set; }
|
|
|
public GroupListController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, AzureServiceBusFactory serviceBus, AzureStorageFactory azureStorage, IConfiguration configuration)
|
|
|
{
|
|
@@ -46,24 +47,371 @@ namespace TEAMModelOS.Controllers
|
|
|
_configuration = configuration;
|
|
|
_azureStorage = azureStorage;
|
|
|
}
|
|
|
+ //学生获取自己已经加入的名单和课程。
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("get-my-course-grouplist")]
|
|
|
+ public async Task<IActionResult> GetMyCourseAndGroupList(JsonElement json)
|
|
|
+ {
|
|
|
+ var (userid, _name, _picture, school) = HttpContext.GetAuthTokenInfo();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ object scope = null; ;
|
|
|
+ HttpContext?.Items.TryGetValue("Scope", out scope);
|
|
|
+
|
|
|
+ if ($"{scope}".Equals(Constant.ScopeStudent))
|
|
|
+ {
|
|
|
+ Student student = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<Student>(userid, new PartitionKey($"Base-{school}"));
|
|
|
+ }
|
|
|
+ if ($"{scope}".Equals(Constant.ScopeTmdUser))
|
|
|
+ {
|
|
|
+ }
|
|
|
+ if ($"{scope}".Equals(Constant.ScopeTeacher))
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 扫码加入名单
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="json"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("scan-code-join-list")]
|
|
|
+ public async Task<IActionResult> ScanCodeJoinList(JsonElement json)
|
|
|
+ {
|
|
|
+ if (!json.TryGetProperty("stuListNo", out JsonElement _stuListNo)) return BadRequest();
|
|
|
+ json.TryGetProperty("school", out JsonElement school);
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ json.TryGetProperty("id_token", out JsonElement id_token);
|
|
|
+ var jwt = new JwtSecurityToken(id_token.GetString());
|
|
|
+ var id = jwt.Payload.Sub;
|
|
|
+ jwt.Payload.TryGetValue("name", out object name);
|
|
|
+ jwt.Payload.TryGetValue("picture", out object picture);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ TmdUser tmduser = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<TmdUser>(id, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ if (ex.Status == 404)
|
|
|
+ {
|
|
|
+ //如果沒有,則初始化Teacher基本資料到Cosmos
|
|
|
+ TmdUser tmduser = new TmdUser
|
|
|
+ {
|
|
|
+ id = id,
|
|
|
+ pk = "Base",
|
|
|
+ code = "Base",
|
|
|
+ name = name?.ToString(),
|
|
|
+ picture = picture?.ToString(),
|
|
|
+ //创建账号并第一次登录IES5则默认赠送1G
|
|
|
+ defaultSchool = null,
|
|
|
+ schools = new List<TmdUser.School>(),
|
|
|
+ };
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Student").CreateItemAsync<TmdUser>(tmduser, new PartitionKey("Base"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ (int status, GroupList stuList) data = await GroupListService.CodeJoinList(client, $"{_stuListNo}", id, $"{name}", null, type: 1, $"{picture}", $"{school}");
|
|
|
+ //没有TmdUser时
|
|
|
+ if (data.status == 0)
|
|
|
+ {
|
|
|
+ await GroupListService.UpsertList(data.stuList, _azureCosmos, _azureStorage, _configuration, _serviceBus);
|
|
|
+ return Ok(new { data.stuList, data.status });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { data.status });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 根据邀请码加入名单
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="json"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "admin,teacher,student")]
|
|
|
+ [HttpPost("input-code-join-list")]
|
|
|
+ public async Task<IActionResult> InputCodeJoinList(JsonElement json)
|
|
|
+ {
|
|
|
+ if (!json.TryGetProperty("stuListNo", out JsonElement _stuListNo)) return BadRequest();
|
|
|
+ var (userid, _name, _picture, school) = HttpContext.GetAuthTokenInfo();
|
|
|
+ object scope = null;
|
|
|
+ int type = 0;
|
|
|
+ string no = null;
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ HttpContext?.Items.TryGetValue("Scope", out scope);
|
|
|
+ if ($"{scope}".Equals(Constant.ScopeStudent))
|
|
|
+ {
|
|
|
+ type = 2;
|
|
|
+ Student student = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<Student>(userid, new PartitionKey($"Base-{school}"));
|
|
|
+ no = student.no;
|
|
|
+ }
|
|
|
+ if ($"{scope}".Equals(Constant.ScopeTmdUser))
|
|
|
+ {
|
|
|
+ type = 1;
|
|
|
+ }
|
|
|
+ if ($"{scope}".Equals(Constant.ScopeTeacher))
|
|
|
+ {
|
|
|
+ type = 1;
|
|
|
+ }
|
|
|
+ (int status, GroupList stuList) data = await GroupListService.CodeJoinList(client, $"{_stuListNo}", userid, _name, no, type, _picture, school);
|
|
|
+ if (data.status == 0)
|
|
|
+ {
|
|
|
+ await GroupListService.UpsertList(data.stuList, _azureCosmos, _azureStorage, _configuration, _serviceBus);
|
|
|
+ return Ok(new { data.stuList, data.status });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { data.status });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private class GroupListDto
|
|
|
+ {
|
|
|
+ public string id { get; set; }
|
|
|
+ public string code { get; set; }
|
|
|
+ public string name { get; set; }
|
|
|
+ //标记该名单唯一code
|
|
|
+ public string no { get; set; }
|
|
|
+ public string periodId { get; set; }
|
|
|
+ //课程id,需要标记则标记
|
|
|
+ //public string courseId { get; set; }
|
|
|
+ public string scope { get; set; }
|
|
|
+ public string school { get; set; }
|
|
|
+ public string creatorId { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ ///教学班teach ,行政班(学生搜寻classId动态返回)class ,教研组research,学科组(学科搜寻动态返回)subject,好友friend,管理manage,群组group等
|
|
|
+ /// </summary>
|
|
|
+ public string type { get; set; } = "teach";
|
|
|
+ public int year { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 醍摩豆id成员数量
|
|
|
+ /// </summary>
|
|
|
+ public int tcount { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 校内账号成员数量
|
|
|
+ /// </summary>
|
|
|
+ public int scount { get; set; }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取发布活动的名单
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="json"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "teacher,admin")]
|
|
|
+ [HttpPost("get-activity-grouplist")]
|
|
|
+ public async Task<IActionResult> GetActivityGrouplist(JsonElement json)
|
|
|
+ {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ json.TryGetProperty("tmdid", out JsonElement tmdid);
|
|
|
+ json.TryGetProperty("schoolId", out JsonElement schoolId);
|
|
|
+ if (!json.TryGetProperty("opt", out JsonElement opt)) { return BadRequest(); }
|
|
|
+ json.TryGetProperty("periodId", out JsonElement periodId);
|
|
|
+ List<GroupListDto> groupLists = new List<GroupListDto>();
|
|
|
+ switch (true)
|
|
|
+ {
|
|
|
+ //我管理的
|
|
|
+ case bool when $"{opt}".Equals("manage", StringComparison.OrdinalIgnoreCase):
|
|
|
+ //包含,学校的行政班,教学班
|
|
|
+ StringBuilder sql = new StringBuilder($"SELECT c.id,c.name,c.periodId ,c.year FROM c ");
|
|
|
+ if (!string.IsNullOrEmpty($"{periodId}"))
|
|
|
+ {
|
|
|
+ sql.Append($" where and c.periodId='{periodId}' ");
|
|
|
+ }
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: sql.ToString(),
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{schoolId}") }))
|
|
|
+ {
|
|
|
+ ///行政班(学生搜寻classId动态返回)class
|
|
|
+ GroupListDto group = new GroupListDto
|
|
|
+ {
|
|
|
+ id = item.id,
|
|
|
+ code = $"GroupList-{schoolId}",
|
|
|
+ name = item.name,
|
|
|
+ periodId = item.periodId,
|
|
|
+ scope = "school",
|
|
|
+ school = $"{schoolId}",
|
|
|
+ type = "class",
|
|
|
+ year = item.year
|
|
|
+ };
|
|
|
+ groupLists.Add(group);
|
|
|
+ }
|
|
|
+ string sqls = $"SELECT distinct {SummarySql} FROM c ";
|
|
|
+ //教学班
|
|
|
+ sql = new StringBuilder($"{sqls} where c.type='teach'");
|
|
|
+ if (!string.IsNullOrEmpty($"{periodId}"))
|
|
|
+ {
|
|
|
+ sql.Append($" and c.periodId='{periodId}'");
|
|
|
+ }
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
|
|
|
+ GetItemQueryIterator<GroupListDto>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{schoolId}") }))
|
|
|
+ {
|
|
|
+ groupLists.Add(item);
|
|
|
+ }
|
|
|
+ //教研组
|
|
|
+ sql = new StringBuilder($"{sqls} where c.type='research'");
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
|
|
|
+ GetItemQueryIterator<GroupListDto>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"GroupList-{schoolId}") }))
|
|
|
+ {
|
|
|
+ groupLists.Add(item);
|
|
|
+ }
|
|
|
+ return Ok(new { groupLists });
|
|
|
+ case bool when $"{opt}".Equals("teach", StringComparison.OrdinalIgnoreCase):
|
|
|
+ //我执教的
|
|
|
+ //从学校的课程和个人课程搜寻与我相关的课程对应的名单。
|
|
|
+ List<TeachCourse> teachCourses = new List<TeachCourse>();
|
|
|
+ if (!string.IsNullOrEmpty($"{schoolId}"))
|
|
|
+ {
|
|
|
+ var schoolQuery = new StringBuilder($"select distinct c.name,c.id, c.scope,c.subject,c.period,A0 schedule from c join A0 in c.schedule where A0.teacherId = '{tmdid}'");
|
|
|
+ if (!string.IsNullOrEmpty($"{periodId}"))
|
|
|
+ {
|
|
|
+ schoolQuery.Append($" and c.period.id='{periodId}' ");
|
|
|
+ }
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").
|
|
|
+ GetItemQueryIterator<TeachCourse>(queryText: schoolQuery.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{schoolId}") }))
|
|
|
+ {
|
|
|
+ teachCourses.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var query = new StringBuilder($"select distinct c.name,c.id, c.scope,c.subject,c.period,A0 schedule from c join A0 in c.schedule where A0.teacherId = '{tmdid}'");
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").
|
|
|
+ GetItemQueryIterator<TeachCourse>(queryText: query.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{tmdid}") }))
|
|
|
+ {
|
|
|
+ teachCourses.Add(item);
|
|
|
+ }
|
|
|
+ var classIds = teachCourses.Select(x => x.schedule).Where(y => !string.IsNullOrEmpty(y.classId)).Select(x => x.classId).Distinct().ToList();
|
|
|
+ var schedule = teachCourses.Where(y => !string.IsNullOrEmpty(y.schedule.stulist)).Distinct().ToList();
|
|
|
+ //var schedule = teachCourses.Select(x => new { schedule = x.schedule.Where(mm=>!string.IsNullOrEmpty(mm.stulist)), scope = x.scope }).ToList();
|
|
|
+ if (classIds.IsNotEmpty())
|
|
|
+ {
|
|
|
+ string insql = string.Join(",", classIds.Select(x => $"'{x}'"));
|
|
|
+ query = new StringBuilder($"SELECT c.id,c.name,c.periodId ,c.year FROM c where c.id in ({insql}) ");
|
|
|
+ ///行政班(学生搜寻classId动态返回)class
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ClassInfo>(queryText: $"select c.id,c.name ,c.periodId ,c.year from c where c.id in ({insql})",
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{schoolId}") }))
|
|
|
+ {
|
|
|
+ GroupListDto group = new GroupListDto
|
|
|
+ {
|
|
|
+ id = item.id,
|
|
|
+ code = $"GroupList-{schoolId}",
|
|
|
+ name = item.name,
|
|
|
+ periodId = item.periodId,
|
|
|
+ scope = "school",
|
|
|
+ school = $"{schoolId}",
|
|
|
+ type = "class",
|
|
|
+ year = item.year
|
|
|
+ };
|
|
|
+ groupLists.Add(group);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (schedule.IsNotEmpty())
|
|
|
+ {
|
|
|
+ var privateList = schedule.Where(x => x.scope.Equals("private")).Select(x => x.schedule.stulist).Distinct();
|
|
|
+ if (privateList.Count() > 0)
|
|
|
+ {
|
|
|
+ string insql = string.Join(",", privateList.Select(x => $"'{x}'"));
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<GroupListDto>(queryText: $"select distinct {SummarySql} from c where c.id in ({insql})",
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"StuList") }))
|
|
|
+ {
|
|
|
+ groupLists.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var schoolList = schedule.Where(x => x.scope.Equals("school")).Select(x => x.schedule.stulist).Distinct();
|
|
|
+ if (schoolList.Count() > 0)
|
|
|
+ {
|
|
|
+ List<GroupListDto> groups = new List<GroupListDto>();
|
|
|
+ string insql = string.Join(",", schoolList.Select(x => $"'{x}'"));
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupListDto>(queryText: $"select distinct {SummarySql} from c where c.id in ({insql})",
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{schoolId}") }))
|
|
|
+ {
|
|
|
+ groupLists.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<CourseGroupList> courseGroups = new List<CourseGroupList>();
|
|
|
+ teachCourses.GroupBy(y => (y.id, y.name, y.scope, y.period.name, y.period.id, y.subject.name, y.subject.id)).ToList().ForEach(x => {
|
|
|
+ List<GroupListDto> classIds = groupLists.Where(n => x.Where(m => !string.IsNullOrEmpty(m.schedule.classId)).Select(b=>b.schedule.classId).Contains(n.id)).ToList();
|
|
|
+ List<GroupListDto> stulists = groupLists.Where(n => x.Where(m => !string.IsNullOrEmpty(m.schedule.stulist)).Select(b => b.schedule.stulist).Contains(n.id)).ToList();
|
|
|
+ if (classIds == null)
|
|
|
+ {
|
|
|
+ classIds = new List<GroupListDto>();
|
|
|
+ }
|
|
|
+ if (stulists != null)
|
|
|
+ {
|
|
|
+ classIds.AddRange(stulists);
|
|
|
+ }
|
|
|
+ CourseGroupList groupList = new CourseGroupList()
|
|
|
+ {
|
|
|
+ scope = x.Key.Item3,
|
|
|
+ subject = x.Key.Item6,
|
|
|
+ period = x.Key.Item4,
|
|
|
+ id = x.Key.Item1,
|
|
|
+ name = x.Key.Item2,
|
|
|
+ groups = classIds
|
|
|
+ };
|
|
|
+ courseGroups.Add(groupList);
|
|
|
+ });
|
|
|
+ return Ok(new { groupLists = courseGroups });
|
|
|
+ case bool when $"{opt}".Equals("private", StringComparison.OrdinalIgnoreCase):
|
|
|
+ //我个人的
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return Ok(new { error = 1, msg = "参数异常" });
|
|
|
+ }
|
|
|
+ private class CourseGroupList
|
|
|
+ {
|
|
|
+ public string scope { get; set; }
|
|
|
+ public string subject { get; set; }
|
|
|
+ public string period { get; set; }
|
|
|
+ public string name { get; set; }
|
|
|
+ public string id { get; set; }
|
|
|
+ public List<GroupListDto> groups { get; set; } = new List<GroupListDto>();
|
|
|
+ }
|
|
|
+ private class TeachCourse
|
|
|
+ {
|
|
|
+ public string scope { get; set; }
|
|
|
|
|
|
+ public IdName subject { get; set; }
|
|
|
+ public IdName period { get; set; }
|
|
|
+ public string name { get; set; }
|
|
|
+ public string id { get; set; }
|
|
|
+ public TeachSchedule schedule { get; set; }
|
|
|
+ }
|
|
|
+ private class TeachSchedule
|
|
|
+ {
|
|
|
+ public string classId { get; set; }
|
|
|
+ public string stulist { get; set; }
|
|
|
+ public string teacherId { get; set; }
|
|
|
+ }
|
|
|
+ private class IdName
|
|
|
+ {
|
|
|
+ public string id { get; set; }
|
|
|
+ public string name { get; set; }
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
- ///
|
|
|
+ /// 根据任意名单id获取成员信息。
|
|
|
/// </summary>
|
|
|
/// <param name="json"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[AuthToken(Roles = "teacher,admin")]
|
|
|
- [HttpPost("get-stutmdid-listids")]
|
|
|
- public async Task<IActionResult> GetStutmdidListids(JsonElement json) {
|
|
|
+ [HttpPost("get-members-listids")]
|
|
|
+ public async Task<IActionResult> GetStutmdidListids(JsonElement json)
|
|
|
+ {
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
if (!json.TryGetProperty("ids", out JsonElement ids)) return BadRequest();
|
|
|
- json.TryGetProperty("school_code", out JsonElement schoolId);
|
|
|
+ json.TryGetProperty("schoolId", out JsonElement schoolId);
|
|
|
List<string> listids = ids.ToObject<List<string>>();
|
|
|
- List<GroupList> groups= await GroupListService. GetStutmdidListids(client, _dingDing, listids, $"{schoolId}");
|
|
|
+ List<GroupList> groups = await GroupListService.GetStutmdidListids(client, _dingDing, listids, $"{schoolId}");
|
|
|
return Ok(new { groups });
|
|
|
}
|
|
|
- //处理通用名单
|
|
|
+ /// <summary>
|
|
|
+ /// 获取名单和成员信息。
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="json"></param>
|
|
|
+ /// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[AuthToken(Roles = "teacher,admin")]
|
|
|
[HttpPost("get-grouplists-members")]
|
|
@@ -72,21 +420,13 @@ namespace TEAMModelOS.Controllers
|
|
|
try
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- if (!json.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
|
|
|
- if (!json.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
|
|
|
+ json.TryGetProperty("tmdid", out JsonElement _tmdid);
|
|
|
+ json.TryGetProperty("schoolId", out JsonElement _schoolId);
|
|
|
if (!json.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
if (!json.TryGetProperty("type", out JsonElement type)) return BadRequest();
|
|
|
json.TryGetProperty("periodId", out JsonElement periodId);
|
|
|
json.TryGetProperty("no", out JsonElement no);
|
|
|
StringBuilder sql = new StringBuilder($"SELECT distinct value(c) FROM c where c.type='{type}'");
|
|
|
- if (!string.IsNullOrEmpty($"{periodId}"))
|
|
|
- {
|
|
|
- sql.Append($" and c.periodId='{periodId}'");
|
|
|
- }
|
|
|
- if (!string.IsNullOrEmpty($"{no}"))
|
|
|
- {
|
|
|
- sql.Append($" and c.no='{no}'");
|
|
|
- }
|
|
|
List<GroupList> groups = new List<GroupList>();
|
|
|
string tbname = "Teacher";
|
|
|
string code = $"GroupList";
|
|
@@ -94,21 +434,42 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
tbname = "School";
|
|
|
code = $"GroupList-{_schoolId}";
|
|
|
+ if (!string.IsNullOrEmpty($"{periodId}"))
|
|
|
+ {
|
|
|
+ sql.Append($" and c.periodId='{periodId}'");
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty($"{no}"))
|
|
|
+ {
|
|
|
+ sql.Append($" and c.no='{no}'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sql.Append($" and c.creatorId='{_tmdid}'");
|
|
|
}
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<GroupList>(queryText: sql.ToString(),
|
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
|
|
|
{
|
|
|
groups.Add(item);
|
|
|
}
|
|
|
- (List<GroupList> groupsData, List<Member> members) = await GroupListService.GetGroupListMemberInfo(client, $"{type}", groups, tbname);
|
|
|
+ (List<GroupList> groupsData, List<Member> members) = await GroupListService.GetGroupListMemberInfo(client, $"{type}", groups, tbname);
|
|
|
return Ok(new { groups = groupsData, members });
|
|
|
}
|
|
|
- catch (CosmosException)
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},grouplist/upsert-grouplist()\n{ex.Message}{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},grouplist/upsert-grouplist()\n{ex.Message}{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
return Ok();
|
|
|
}
|
|
|
- //处理通用名单
|
|
|
+ /// <summary>
|
|
|
+ /// 获取名单列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="json"></param>
|
|
|
+ /// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[AuthToken(Roles = "teacher,admin")]
|
|
|
[HttpPost("get-grouplists")]
|
|
@@ -117,36 +478,48 @@ namespace TEAMModelOS.Controllers
|
|
|
try
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- if (!json.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
|
|
|
- if (!json.TryGetProperty("schoolId", out JsonElement _schoolId)) return BadRequest();
|
|
|
+ json.TryGetProperty("tmdid", out JsonElement _tmdid);
|
|
|
+ json.TryGetProperty("schoolId", out JsonElement _schoolId);
|
|
|
if (!json.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
if (!json.TryGetProperty("type", out JsonElement type)) return BadRequest();
|
|
|
json.TryGetProperty("periodId", out JsonElement periodId);
|
|
|
json.TryGetProperty("no", out JsonElement no);
|
|
|
- StringBuilder sql = new StringBuilder($"SELECT distinct c.id,c.code,c.name,c.no,c.periodId,c.scope,c.school,c.creatorId,c.type FROM c where c.type='{type}'");
|
|
|
- if (!string.IsNullOrEmpty($"{periodId}")) {
|
|
|
- sql.Append($" and c.periodId='{periodId}'");
|
|
|
- }
|
|
|
- if (!string.IsNullOrEmpty($"{no}"))
|
|
|
- {
|
|
|
- sql.Append($" and c.no='{no}'");
|
|
|
- }
|
|
|
- List<dynamic> groups = new List<dynamic>();
|
|
|
+ StringBuilder sql = new StringBuilder($"SELECT distinct {SummarySql} FROM c where c.type='{type}'");
|
|
|
+
|
|
|
+ List<GroupListDto> groups = new List<GroupListDto>();
|
|
|
string tbname = "Teacher";
|
|
|
- string code =$"GroupList";
|
|
|
- if ($"{scope}".Equals("school", StringComparison.OrdinalIgnoreCase)) {
|
|
|
+ string code = $"GroupList";
|
|
|
+ if ($"{scope}".Equals("school", StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
tbname = "School";
|
|
|
code = $"GroupList-{_schoolId}";
|
|
|
+ if (!string.IsNullOrEmpty($"{periodId}"))
|
|
|
+ {
|
|
|
+ sql.Append($" and c.periodId='{periodId}'");
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty($"{no}"))
|
|
|
+ {
|
|
|
+ sql.Append($" and c.no='{no}'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sql.Append($" and c.creatorId='{_tmdid}'");
|
|
|
}
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<dynamic>(queryText: sql.ToString(),
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<GroupListDto>(queryText: sql.ToString(),
|
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
|
|
|
{
|
|
|
groups.Add(item);
|
|
|
}
|
|
|
return Ok(new { groups });
|
|
|
}
|
|
|
- catch (CosmosException)
|
|
|
+ catch (CosmosException ex)
|
|
|
{
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},grouplist/upsert-grouplist()\n{ex.Message}{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},grouplist/upsert-grouplist()\n{ex.Message}{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
return Ok();
|
|
|
}
|
|
@@ -154,28 +527,38 @@ namespace TEAMModelOS.Controllers
|
|
|
[ProducesDefaultResponseType]
|
|
|
[AuthToken(Roles = "teacher,admin")]
|
|
|
[HttpPost("get-grouplist-idcode")]
|
|
|
- public async Task<IActionResult> GetGrouplistIdcode(JsonElement json) {
|
|
|
+ public async Task<IActionResult> GetGrouplistIdcode(JsonElement json)
|
|
|
+ {
|
|
|
GroupList groupList = null;
|
|
|
- try {
|
|
|
+ try
|
|
|
+ {
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- if (!json.TryGetProperty("code", out JsonElement _code)) return BadRequest();
|
|
|
+ json.TryGetProperty("code", out JsonElement _code);
|
|
|
if (!json.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
if (!json.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
- string tbname = $"{scope}".Equals("private") ? "Teacher" : "School";
|
|
|
+ string tbname = $"{scope}".Equals("private") ? "Teacher" : "School";
|
|
|
string code = "";
|
|
|
- if ( $"{scope}".Equals("private"))
|
|
|
+ if ($"{scope}".Equals("private"))
|
|
|
{
|
|
|
//私人名单
|
|
|
- code = "GroupList";
|
|
|
+ code = "GroupList";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//学校自定义名单
|
|
|
- code = !code.StartsWith("GroupList-") ? $"GroupList-{code}" : code;
|
|
|
+ code = !code.StartsWith("GroupList-") ? $"GroupList-{code}" : code;
|
|
|
}
|
|
|
- groupList= await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<GroupList>($"{id}", new PartitionKey($"{code}"));
|
|
|
- } catch (CosmosException) {
|
|
|
- groupList = null;
|
|
|
+ groupList = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<GroupList>($"{id}", new PartitionKey($"{code}"));
|
|
|
+ (List<GroupList> groupsData, List<Member> members) = await GroupListService.GetGroupListMemberInfo(client, $"{groupList.type}", new List<GroupList> { groupList }, tbname);
|
|
|
+ groupList = groupsData.FirstOrDefault();
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},grouplist/upsert-grouplist()\n{ex.Message}{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},grouplist/upsert-grouplist()\n{ex.Message}{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
|
|
|
}
|
|
|
return Ok(new { groupList });
|
|
|
}
|
|
@@ -188,243 +571,95 @@ namespace TEAMModelOS.Controllers
|
|
|
[ProducesDefaultResponseType]
|
|
|
[AuthToken(Roles = "teacher,admin")]
|
|
|
[HttpPost("upsert-grouplist")]
|
|
|
- public async Task<IActionResult> UpsertGroupList(JsonElement json)
|
|
|
+ public async Task<IActionResult> UpsertGroupList(GroupList list)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
|
- if (!json.TryGetProperty("type", out JsonElement _type))
|
|
|
+ if (string.IsNullOrEmpty(list.type))
|
|
|
{
|
|
|
return BadRequest();
|
|
|
}
|
|
|
- if (!json.TryGetProperty("list", out JsonElement _list))
|
|
|
+ list.year = list.year > 0 ? list.year : DateTimeOffset.UtcNow.Year;
|
|
|
+ list.ttl = -1;
|
|
|
+ list.creatorId = userid;
|
|
|
+ list.school = string.IsNullOrEmpty(list.school) ? school : list.school;
|
|
|
+ list.pk = "GroupList";
|
|
|
+ if (list.scope.Equals("private"))
|
|
|
{
|
|
|
- return BadRequest();
|
|
|
+ //私人名单
|
|
|
+ list.code = "GroupList";
|
|
|
+ list.school = null;
|
|
|
}
|
|
|
- GroupList list = _list.ToObject<GroupList>();
|
|
|
- if (list != null) {
|
|
|
- list.ttl = -1;
|
|
|
- list.creatorId = userid;
|
|
|
- list.school =string.IsNullOrEmpty(list.school)?school: list.school;
|
|
|
- list.pk = "GroupList";
|
|
|
- if (list.scope.Equals("private"))
|
|
|
- {
|
|
|
- //私人名单
|
|
|
- list.code = "GroupList";
|
|
|
- }
|
|
|
- else {
|
|
|
- //学校自定义名单
|
|
|
- list.code = !list.code.StartsWith("GroupList-") ? $"GroupList-{list.code}" : list.code;
|
|
|
- }
|
|
|
- switch (true)
|
|
|
- {
|
|
|
- //普通学生名单(包含学校教学班名单,个人课程名单),其中学生成员账号类型可以是学校学生账号和醍摩豆ID,分区键为GroupList-hbcn 分区键为GroupList
|
|
|
- case bool when $"{_type}".Equals("teach", StringComparison.OrdinalIgnoreCase):
|
|
|
- list.type = "teach";
|
|
|
- list = await CheckListNo(list);
|
|
|
- list = await UpsertList(list);
|
|
|
- break;
|
|
|
- //教研组名单,只有加入学校的老师名单 成员账号类型是醍摩豆ID,保存在学校表,分区键为GroupList-hbcn
|
|
|
- case bool when $"{_type}".Equals("research", StringComparison.OrdinalIgnoreCase):
|
|
|
- list.type = "research";
|
|
|
- list.scope = "school";
|
|
|
- list = await UpsertList(list);
|
|
|
- break;
|
|
|
- //个人好友名单,成员账号类型可以是学校学生账号和醍摩豆ID,分区键为GroupList
|
|
|
- case bool when $"{_type}".Equals("friend", StringComparison.OrdinalIgnoreCase):
|
|
|
- list.type = "friend";
|
|
|
- list = await UpsertList(list);
|
|
|
- break;
|
|
|
- //社交群组类型(包含学校交流群组,个人交流群组),成员账号类型可以是学校学生账号和醍摩豆ID,,分区键为GroupList-hbcn 分区键为GroupList
|
|
|
- case bool when $"{_type}".Equals("group", StringComparison.OrdinalIgnoreCase):
|
|
|
- list.type = "group";
|
|
|
- list = await CheckListNo(list);
|
|
|
- list = await UpsertList(list);
|
|
|
- break;
|
|
|
- }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //学校自定义名单
|
|
|
+ list.code = !list.code.StartsWith("GroupList-") ? $"GroupList-{list.code}" : list.code;
|
|
|
+ }
|
|
|
+ switch (true)
|
|
|
+ {
|
|
|
+ //普通学生名单(包含学校教学班名单,个人课程名单),其中学生成员账号类型可以是学校学生账号和醍摩豆ID,分区键为GroupList-hbcn
|
|
|
+ case bool when $"{list.type}".Equals("teach", StringComparison.OrdinalIgnoreCase):
|
|
|
+ list.type = "teach";
|
|
|
+ list = await GroupListService.CheckListNo(list, _azureCosmos, _dingDing, _option);
|
|
|
+ list = await GroupListService.UpsertList(list, _azureCosmos, _azureStorage, _configuration, _serviceBus);
|
|
|
+ break;
|
|
|
+ //教研组名单,只有加入学校的老师名单 成员账号类型是醍摩豆ID,保存在学校表,分区键为GroupList-hbcn
|
|
|
+ case bool when $"{list.type}".Equals("research", StringComparison.OrdinalIgnoreCase):
|
|
|
+ list.type = "research";
|
|
|
+ list.scope = "school";
|
|
|
+ list = await GroupListService.UpsertList(list, _azureCosmos, _azureStorage, _configuration, _serviceBus);
|
|
|
+ break;
|
|
|
+ //个人好友名单,成员账号类型可以是学校学生账号和醍摩豆ID,分区键为GroupList
|
|
|
+ case bool when $"{list.type}".Equals("friend", StringComparison.OrdinalIgnoreCase):
|
|
|
+ list.type = "friend";
|
|
|
+ list = await GroupListService.UpsertList(list, _azureCosmos, _azureStorage, _configuration, _serviceBus);
|
|
|
+ break;
|
|
|
+ //社交群组类型(包含学校交流群组,个人交流群组),成员账号类型可以是学校学生账号和醍摩豆ID,,分区键为GroupList-hbcn
|
|
|
+ case bool when $"{list.type}".Equals("group", StringComparison.OrdinalIgnoreCase):
|
|
|
+ list.type = "group";
|
|
|
+ list = await GroupListService.CheckListNo(list, _azureCosmos, _dingDing, _option);
|
|
|
+ list = await GroupListService.UpsertList(list, _azureCosmos, _azureStorage, _configuration, _serviceBus);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return Ok(new { error = 400, msg = "参数错误!" });
|
|
|
}
|
|
|
return Ok(new { list });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- await _dingDing.SendBotMsg($"OS,{_option.Location},course/upsert-list()\n{ex.Message}{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},grouplist/upsert-grouplist()\n{ex.Message}{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
|
|
|
return BadRequest();
|
|
|
}
|
|
|
}
|
|
|
- private async Task<GroupList> UpsertList(GroupList list) {
|
|
|
- bool isnew = false;
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- if (string.IsNullOrEmpty(list.id)) {
|
|
|
- list.id = Guid.NewGuid().ToString();
|
|
|
- isnew = true;
|
|
|
- }
|
|
|
- string tbname = list.scope.Equals("private") ? "Teacher" : "School";
|
|
|
- await client.GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(list, new PartitionKey(list.code));
|
|
|
- //学生名单,教研组会触发活动中间表刷新
|
|
|
- if (list.type.Equals("teach") || list.type.Equals("research")) {
|
|
|
- GroupChange change = new GroupChange()
|
|
|
- {
|
|
|
- type = list.type,
|
|
|
- listid = list.id,
|
|
|
- scope = list.scope,
|
|
|
- originCode = list.school,
|
|
|
- school = list.school,
|
|
|
- creatorId = list.creatorId
|
|
|
- };
|
|
|
- GroupList oldList = null;
|
|
|
- if (!isnew)
|
|
|
- {
|
|
|
- try {
|
|
|
- oldList = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<GroupList>(list.id, new PartitionKey(list.code));
|
|
|
- } catch (CosmosException) {
|
|
|
- oldList = null;
|
|
|
- }
|
|
|
- }
|
|
|
- if (list.members.IsNotEmpty()&&(oldList == null || !oldList.members.IsNotEmpty()))
|
|
|
+
|
|
|
+ //删除名单
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [AuthToken(Roles = "Teacher,Admin")]
|
|
|
+ [HttpPost("delete-grouplist")]
|
|
|
+ public async Task<IActionResult> deleteList(JsonElement requert)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ if (scope.ToString().Equals("school", StringComparison.OrdinalIgnoreCase))
|
|
|
{
|
|
|
- //加入的
|
|
|
- var tmdids = list.members.FindAll(x => x.type == 1);
|
|
|
- if (tmdids.IsNotEmpty()) {
|
|
|
- if (list.type.Equals("research"))
|
|
|
- {
|
|
|
- change.tchjoin.AddRange(tmdids);
|
|
|
- }
|
|
|
- else {
|
|
|
- change.tmdjoin.AddRange(tmdids);
|
|
|
- }
|
|
|
- }
|
|
|
- var stuids = list.members.FindAll(x => x.type == 2);
|
|
|
- if (stuids.IsNotEmpty()) {
|
|
|
- change.stujoin.AddRange(stuids);
|
|
|
- }
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"GroupList-{code}"));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (list.members.IsNotEmpty())
|
|
|
- {
|
|
|
- var tmdids = list.members.FindAll(x => x.type == 1);
|
|
|
- var oldtmdids = oldList.members.FindAll(x => x.type == 1);
|
|
|
-
|
|
|
- //取各自的差集
|
|
|
- //新=》旧差集,表示新增
|
|
|
- var jointmdid = tmdids.Select(x => x.id).Except(oldtmdids.Select(y => y.id)).ToList();
|
|
|
- //旧=》新差集,表示离开
|
|
|
- var leavetmdid = oldtmdids .Select(x => x.id).Except(tmdids.Select(y => y.id)).ToList();
|
|
|
-
|
|
|
- if (list.type.Equals("research"))
|
|
|
- {
|
|
|
- change.tchjoin.AddRange(tmdids.Where(x=> jointmdid.Exists(y=>y.Equals(x.id))));
|
|
|
- change.tchleave.AddRange(oldtmdids.Where(x => leavetmdid.Exists(y => y.Equals(x.id))));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- change.tmdjoin.AddRange(tmdids.Where(x => jointmdid.Exists(y => y.Equals(x.id))));
|
|
|
- change.tmdleave.AddRange(oldtmdids.Where(x => leavetmdid.Exists(y => y.Equals(x.id))));
|
|
|
- }
|
|
|
- var stuids = list.members.FindAll(x => x.type == 2);
|
|
|
- var oldstuids = oldList.members.FindAll(x => x.type == 2);
|
|
|
-
|
|
|
- var joinstudent = stuids.Select(x => (x.id, x.code)).Except(oldstuids.Select(y => (y.id, y.code)), new CompareIdCode()).ToList();
|
|
|
- var leavestudent = oldstuids.Select(x => (x.id, x.code)).Except(stuids.Select(y => (y.id, y.code)), new CompareIdCode()).ToList();
|
|
|
-
|
|
|
- change.stujoin.AddRange(stuids.Where(x => joinstudent.Exists(y => y.id.Equals(x.id)&&y.code.Equals(x.code))));
|
|
|
- change.stuleave.AddRange(oldstuids.Where(x => leavestudent.Exists(y => y.id.Equals(x.id) && y.code.Equals(x.code))));
|
|
|
- }
|
|
|
- else {
|
|
|
- //离开的
|
|
|
- var tmdids = oldList.members.FindAll(x => x.type == 1);
|
|
|
- if (tmdids.IsNotEmpty())
|
|
|
- {
|
|
|
- if (list.type.Equals("research"))
|
|
|
- {
|
|
|
- change.tchleave.AddRange(tmdids);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- change.tmdleave.AddRange(tmdids);
|
|
|
- }
|
|
|
- }
|
|
|
- var stuids = oldList.members.FindAll(x => x.type == 2);
|
|
|
- if (stuids.IsNotEmpty())
|
|
|
- {
|
|
|
- change.stuleave.AddRange(stuids);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (change.tmdjoin.Count != 0 || change.tmdleave.Count != 0 || change.stujoin.Count != 0 || change.stuleave.Count != 0
|
|
|
- || change.tchjoin.Count != 0 || change.tchleave.Count != 0)
|
|
|
- {
|
|
|
- var messageChange = new ServiceBusMessage(change.ToJsonString());
|
|
|
- messageChange.ApplicationProperties.Add("name", "GroupChange");
|
|
|
- var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
- await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
|
|
|
+ await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"GroupList"));
|
|
|
}
|
|
|
+ return Ok(new { id });
|
|
|
}
|
|
|
- return list;
|
|
|
- }
|
|
|
- private async Task<GroupList> CheckListNo(GroupList list ) {
|
|
|
- try {
|
|
|
- var client = _azureCosmos.GetCosmosClient();
|
|
|
- if (string.IsNullOrEmpty(list.no)) {
|
|
|
- list.no = $"{Utils.CreatSaltString(6, "0123456789")}";
|
|
|
- for (int i = 0; i < 10; i++)
|
|
|
- {
|
|
|
- List<string> noStus = new();
|
|
|
- var queryNo = $"SELECT c.no FROM c where c.no ='{list.no}'";
|
|
|
- if (list.scope.Equals("school")) {
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(queryText: queryNo,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{list.code}") }))
|
|
|
- {
|
|
|
- using var jsonNo = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (jsonNo.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- var accounts = jsonNo.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
- while (accounts.MoveNext())
|
|
|
- {
|
|
|
- JsonElement account = accounts.Current;
|
|
|
- noStus.Add(account.GetProperty("no").GetString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: queryNo,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey("GroupList") }))
|
|
|
- {
|
|
|
- using var jsonNo = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
- if (jsonNo.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
- {
|
|
|
- var accounts = jsonNo.RootElement.GetProperty("Documents").EnumerateArray();
|
|
|
- while (accounts.MoveNext())
|
|
|
- {
|
|
|
- JsonElement account = accounts.Current;
|
|
|
- noStus.Add(account.GetProperty("no").GetString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (noStus.Count == 0)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (i == 9)
|
|
|
- {
|
|
|
- string msg = $"OS,{_option.Location},school/course/upsert-list()\n 编号生成异常,重复生成次数超过10次";
|
|
|
- await _dingDing.SendBotMsg(msg, GroupNames.醍摩豆服務運維群組);
|
|
|
- throw new Exception(msg);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- list.no = $"{Utils.CreatSaltString(6, "0123456789")}";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception ex) {
|
|
|
-
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},grouplist/delete-grouplist()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
|
|
|
+ return BadRequest();
|
|
|
}
|
|
|
- return list;
|
|
|
}
|
|
|
}
|
|
|
}
|