|
@@ -8,88 +8,391 @@ using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
+using System.Text.Json;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using Azure.Messaging.ServiceBus;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
namespace TEAMModelOS.SDK.Models.Service
|
|
|
{
|
|
|
-public class GroupListService
|
|
|
-{
|
|
|
- public static async Task< List<GroupList> > GetStutmdidListids(CosmosClient client, DingDing _dingDing, List<string> classes, string school) {
|
|
|
- Dictionary<string, List<GroupList>> groups = new Dictionary<string, List<GroupList>>();
|
|
|
- List<Student> students = new List<Student>();
|
|
|
- string sql = string.Join(",", classes.Select(x => $"'{x}'"));
|
|
|
- if (!string.IsNullOrEmpty(school)) {
|
|
|
- List<GroupList> schoolList = new List<GroupList>();
|
|
|
-
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: $"select value(c) from c where c.id in ({sql})",
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
|
|
|
+ public class GroupListService
|
|
|
+ {
|
|
|
+ public static async Task<(int status, GroupList stuList)> CodeJoinList(CosmosClient client, string _stuListNo, string userid, string name, string no, int type, string picture, string school)
|
|
|
+ {
|
|
|
+ var queryNo = $"SELECT value(c) FROM c where c.no ='{_stuListNo}'";
|
|
|
+ (int status, GroupList stuList) data = (-1, null);
|
|
|
+ if (!string.IsNullOrEmpty(school))
|
|
|
+ {
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: queryNo,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
|
|
|
{
|
|
|
- schoolList.Add(item);
|
|
|
+ data = JoinList(item, userid, name, no, type, picture, school);
|
|
|
+ break;
|
|
|
}
|
|
|
- if (schoolList.IsNotEmpty()) {
|
|
|
- groups.Add("School", schoolList);
|
|
|
+ }
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<GroupList>(queryText: queryNo,
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList") }))
|
|
|
+ {
|
|
|
+ data = JoinList(item, userid, name, no, type, picture, school);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+ public static (int status, GroupList stuList) JoinList(GroupList stuList, string userid, string name, string no, int type, string picture, string school)
|
|
|
+ {
|
|
|
+ int status = -1;
|
|
|
+ if (string.IsNullOrEmpty($"{userid}"))
|
|
|
+ {
|
|
|
+ //加入学生或醍摩豆ID为空
|
|
|
+ status = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (type == 1)
|
|
|
+ {
|
|
|
+ var student = stuList.members.Find(x => x.type == 1 && x.id.Equals(userid));
|
|
|
+ if (student != null)
|
|
|
+ {
|
|
|
+ //重复加入
|
|
|
+ status = 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ status = 0;
|
|
|
+ stuList.members.Add(new Member { id = userid, name = name, no = no, picture = picture, type = type });
|
|
|
+ }
|
|
|
}
|
|
|
- //取差集,减少二次搜寻
|
|
|
- classes = classes.Except(schoolList.Select(y => y.id)).ToList();
|
|
|
- if (classes.IsNotEmpty()) {
|
|
|
- sql = string.Join(",", classes.Select(x => $"'{x}'"));
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
|
|
|
+ else if (type == 2)
|
|
|
+ {
|
|
|
+ var student = stuList.members.Find(x => x.type == 2 && x.id.Equals(userid) && x.code.Equals(school));
|
|
|
+ if (student != null)
|
|
|
{
|
|
|
- students.Add(item);
|
|
|
+ //重复加入
|
|
|
+ status = 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ status = 0;
|
|
|
+ stuList.members.Add(new Member { id = userid, code = school, name = name, no = no, picture = picture, type = type });
|
|
|
}
|
|
|
- //取差集,减少二次搜寻
|
|
|
- classes = classes.Except(students.Select(y => y.classId)).ToList();
|
|
|
}
|
|
|
}
|
|
|
- if (classes.IsNotEmpty()) {
|
|
|
- List<GroupList> privateList = new List<GroupList>();
|
|
|
- sql = string.Join(",", classes.Select(x => $"'{x}'"));
|
|
|
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<GroupList>(queryText: $"select value(c) from c where c.id in ({sql})",
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList") }))
|
|
|
+ return (status, stuList);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static async Task<GroupList> UpsertList(GroupList list, AzureCosmosFactory _azureCosmos, AzureStorageFactory _azureStorage, IConfiguration _configuration, AzureServiceBusFactory _serviceBus)
|
|
|
+ {
|
|
|
+ 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";
|
|
|
+ list.tcount = list.members.Where(x => x.type == 1).Count();
|
|
|
+ list.scount = list.members.Where(x => x.type == 2).Count();
|
|
|
+ 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()))
|
|
|
{
|
|
|
- privateList.Add(item);
|
|
|
+ //加入的
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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 (privateList.IsNotEmpty())
|
|
|
+ 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)
|
|
|
{
|
|
|
- groups.Add("Teacher", privateList);
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
- foreach (var item in groups) {
|
|
|
- var list= item.Value.GroupBy(x => x.type).Select(y => new { key = y.Key, list = y.ToList() });
|
|
|
- foreach (var group in list) {
|
|
|
- await GetGroupListMemberInfo(client, group.key, group.list, item.Key);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ public static async Task<GroupList> CheckListNo(GroupList list, AzureCosmosFactory _azureCosmos, DingDing _dingDing, Option _option)
|
|
|
+ {
|
|
|
+ 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 List<string>();
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+
|
|
|
}
|
|
|
- List<GroupList> groupLists = groups.SelectMany(x => x.Value).ToList();
|
|
|
- if (students.IsNotEmpty()) {
|
|
|
- List<string> sqlList = students.Select(x=>x.classId).ToList();
|
|
|
- classes.ForEach(x => { sqlList.Add($" '{x}' "); });
|
|
|
- sql = string.Join(" , ", sqlList);
|
|
|
- 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 ({sql})",
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Class-{school}") }))
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ public static async Task<List<GroupList>> GetStutmdidListids(CosmosClient client, DingDing _dingDing, List<string> classes, string school)
|
|
|
+ {
|
|
|
+ List<GroupList> groupLists = null;
|
|
|
+ if (classes.Count == 1 && classes.First().Equals("default") && !string.IsNullOrEmpty(school))
|
|
|
+ {
|
|
|
+ //默认的教研组
|
|
|
+ List<Member> members = new List<Member>();
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<TmdInfo>(queryText: $"SELECT value(c) FROM c ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school}") }))
|
|
|
{
|
|
|
- ///行政班(学生搜寻classId动态返回)class
|
|
|
- GroupList group = new GroupList {
|
|
|
+ Member member = new Member
|
|
|
+ {
|
|
|
id = item.id,
|
|
|
- code = $"GroupList-{school}",
|
|
|
name = item.name,
|
|
|
- periodId = item.periodId,
|
|
|
- scope = "school",
|
|
|
- school = school,
|
|
|
- type = "class",
|
|
|
- members = students.Where(x => x.classId.Equals(item.id)).Select(y => new Member {id=y.id,code=school,name=y.name,type= 2,picture=y.picture,no=y.no }).ToList()
|
|
|
+ picture = item.picture,
|
|
|
+ type = 1,
|
|
|
};
|
|
|
- groupLists.Add(group);
|
|
|
+ members.Add(member);
|
|
|
}
|
|
|
+ GroupList groupList = new GroupList
|
|
|
+ {
|
|
|
+ id = "default",
|
|
|
+ name = "default",
|
|
|
+ code = $"GroupList-{school}",
|
|
|
+ school = school,
|
|
|
+ scope = "school",
|
|
|
+ type = "research",
|
|
|
+ members = members
|
|
|
+ };
|
|
|
+ groupLists = new List<GroupList> { groupList };
|
|
|
}
|
|
|
- return groupLists;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Dictionary<string, List<GroupList>> groups = new Dictionary<string, List<GroupList>>();
|
|
|
+ List<Student> students = new List<Student>();
|
|
|
+ string sql = string.Join(",", classes.Select(x => $"'{x}'"));
|
|
|
+ if (!string.IsNullOrEmpty(school))
|
|
|
+ {
|
|
|
+ List<GroupList> schoolList = new List<GroupList>();
|
|
|
+
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<GroupList>(queryText: $"select value(c) from c where c.id in ({sql})",
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList-{school}") }))
|
|
|
+ {
|
|
|
+ schoolList.Add(item);
|
|
|
+ }
|
|
|
+ if (schoolList.IsNotEmpty())
|
|
|
+ {
|
|
|
+ groups.Add("School", schoolList);
|
|
|
+ }
|
|
|
+ //取差集,减少二次搜寻
|
|
|
+ classes = classes.Except(schoolList.Select(y => y.id)).ToList();
|
|
|
+ if (classes.IsNotEmpty())
|
|
|
+ {
|
|
|
+ sql = string.Join(",", classes.Select(x => $"'{x}'"));
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select value(c) from c where c.classId in ({sql})",
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{school}") }))
|
|
|
+ {
|
|
|
+ students.Add(item);
|
|
|
+ }
|
|
|
+ //取差集,减少二次搜寻
|
|
|
+ classes = classes.Except(students.Select(y => y.classId)).ToList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (classes.IsNotEmpty())
|
|
|
+ {
|
|
|
+ List<GroupList> privateList = new List<GroupList>();
|
|
|
+ sql = string.Join(",", classes.Select(x => $"'{x}'"));
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<GroupList>(queryText: $"select value(c) from c where c.id in ({sql})",
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"GroupList") }))
|
|
|
+ {
|
|
|
+ privateList.Add(item);
|
|
|
+ }
|
|
|
+ if (privateList.IsNotEmpty())
|
|
|
+ {
|
|
|
+ groups.Add("Teacher", privateList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach (var item in groups)
|
|
|
+ {
|
|
|
+ var list = item.Value.GroupBy(x => x.type).Select(y => new { key = y.Key, list = y.ToList() });
|
|
|
+ foreach (var group in list)
|
|
|
+ {
|
|
|
+ await GetGroupListMemberInfo(client, group.key, group.list, item.Key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ groupLists = groups.SelectMany(x => x.Value).ToList();
|
|
|
+ if (students.IsNotEmpty())
|
|
|
+ {
|
|
|
+ List<string> sqlList = students.Select(x => x.classId).ToList();
|
|
|
+ string insql = string.Join(",", sqlList.Select(x => $"'{x}'"));
|
|
|
+ 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-{school}") }))
|
|
|
+ {
|
|
|
+ ///行政班(学生搜寻classId动态返回)class
|
|
|
+ List<Member> members = students.Where(x => x.classId.Equals(item.id)).Select(y => new Member { id = y.id, code = school, name = y.name, type = 2, picture = y.picture, no = y.no }).ToList();
|
|
|
+ GroupList group = new GroupList
|
|
|
+ {
|
|
|
+ id = item.id,
|
|
|
+ code = $"GroupList-{school}",
|
|
|
+ name = item.name,
|
|
|
+ periodId = item.periodId,
|
|
|
+ scope = "school",
|
|
|
+ school = school,
|
|
|
+ type = "class",
|
|
|
+ year = item.year,
|
|
|
+ members = members,
|
|
|
+ scount = members.Count
|
|
|
+ };
|
|
|
+ groupLists.Add(group);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return groupLists;
|
|
|
}
|
|
|
|
|
|
- public static async Task<(List<GroupList> groups, List<Member> members)> GetGroupListMemberInfo(CosmosClient client, string type, List<GroupList> groups,string groupTbname) {
|
|
|
+ public static async Task<(List<GroupList> groups, List<Member> members)> GetGroupListMemberInfo(CosmosClient client, string type, List<GroupList> groups, string groupTbname)
|
|
|
+ {
|
|
|
|
|
|
- var members = groups. SelectMany(y=>y.members).ToList();
|
|
|
+ var members = groups.SelectMany(y => y.members).ToList();
|
|
|
//去重
|
|
|
- List<Member> tmids = members.FindAll(x => x.type == 1).Where((x, i) => members.FindAll(x => x.type == 1).FindIndex(n => n.id.Equals(x.id)) == i).ToList();
|
|
|
+ List<Member> tmids = members.FindAll(x => x.type == 1).Where((x, i) => members.FindAll(x => x.type == 1).FindIndex(n => n.id.Equals(x.id)) == i).ToList();
|
|
|
List<Member> students = members.FindAll(x => x.type == 2).Where((x, i) => members.FindAll(x => x.type == 2).FindIndex(n => n.id.Equals(x.id) && n.code.Equals(x.code)) == i).ToList();
|
|
|
var stu = students.GroupBy(x => x.code).Select(y => new { key = y.Key, list = y.ToList() });
|
|
|
List<Student> studentsData = new List<Student>();
|
|
@@ -121,7 +424,7 @@ public class GroupListService
|
|
|
{
|
|
|
StringBuilder tmdidSql = new StringBuilder($"SELECT distinct c.name,c.id,c.picture FROM c ");
|
|
|
string insql = string.Join(",", tmids.Select(x => $"'{x.id}'"));
|
|
|
- tmdidSql.Append($"c.id in ({insql})");
|
|
|
+ tmdidSql.Append($" where c.id in ({insql})");
|
|
|
memberTbname = "Teacher";
|
|
|
await foreach (var tmd in client.GetContainer(Constant.TEAMModelOS, memberTbname).GetItemQueryIterator<TmdUser>(queryText: tmdidSql.ToString(),
|
|
|
requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
@@ -133,15 +436,18 @@ public class GroupListService
|
|
|
{
|
|
|
//取差集,减少二次搜寻
|
|
|
var tmdidexp = tmids.Select(x => x.id).Except(tmdsData.Select(y => y.id)).ToList();
|
|
|
- StringBuilder tmdidSql = new StringBuilder($"SELECT distinct c.name,c.id,c.picture FROM c ");
|
|
|
- string insql = string.Join(",", tmdidexp.Select(x => $"'{x}'"));
|
|
|
- tmdidSql.Append($"c.id in ({insql})");
|
|
|
-
|
|
|
- memberTbname = "Student";
|
|
|
- await foreach (var tmd in client.GetContainer(Constant.TEAMModelOS, memberTbname).GetItemQueryIterator<TmdUser>(queryText: tmdidSql.ToString(),
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
+ if (tmdidexp.IsNotEmpty())
|
|
|
{
|
|
|
- tmdsData.Add(tmd);
|
|
|
+ StringBuilder tmdidSql = new StringBuilder($"SELECT distinct c.name,c.id,c.picture FROM c ");
|
|
|
+ string insql = string.Join(",", tmdidexp.Select(x => $"'{x}'"));
|
|
|
+ tmdidSql.Append($" where c.id in ({insql})");
|
|
|
+
|
|
|
+ memberTbname = "Student";
|
|
|
+ await foreach (var tmd in client.GetContainer(Constant.TEAMModelOS, memberTbname).GetItemQueryIterator<TmdUser>(queryText: tmdidSql.ToString(),
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
+ {
|
|
|
+ tmdsData.Add(tmd);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//去重
|
|
@@ -149,7 +455,8 @@ public class GroupListService
|
|
|
}
|
|
|
HashSet<GroupList> changes = new HashSet<GroupList>();
|
|
|
var unexist_tmdid = tmids.Select(x => x.id).Except(tmdsData.Select(y => y.id)).ToList();
|
|
|
- groups.ForEach(x => {
|
|
|
+ groups.ForEach(x =>
|
|
|
+ {
|
|
|
int item = x.members.RemoveAll(y => unexist_tmdid.Contains(y.id) && y.type == 1);
|
|
|
if (item > 0)
|
|
|
{
|
|
@@ -157,24 +464,31 @@ public class GroupListService
|
|
|
}
|
|
|
});
|
|
|
var unexist_student = students.Select(x => (x.id, x.code)).Except(studentsData.Select(y => (y.id, y.code)), new CompareIdCode()).ToList();
|
|
|
- groups.ForEach(x => {
|
|
|
+ groups.ForEach(x =>
|
|
|
+ {
|
|
|
int item = x.members.RemoveAll(y => y.type == 2 && unexist_student.Exists(x => x.id.Equals(y.id) && x.code.Equals(y.code)));
|
|
|
if (item > 0)
|
|
|
{
|
|
|
changes.Add(x);
|
|
|
}
|
|
|
});
|
|
|
- if (changes.Count > 0 && !string.IsNullOrEmpty(groupTbname)) {
|
|
|
- foreach (var change in changes) {
|
|
|
+ if (changes.Count > 0 && !string.IsNullOrEmpty(groupTbname))
|
|
|
+ {
|
|
|
+ foreach (var change in changes)
|
|
|
+ {
|
|
|
+ change.tcount = change.members.Where(x => x.type == 1).Count();
|
|
|
+ change.scount = change.members.Where(x => x.type == 2).Count();
|
|
|
await client.GetContainer(Constant.TEAMModelOS, groupTbname).ReplaceItemAsync(change, change.id, new PartitionKey(change.code));
|
|
|
}
|
|
|
}
|
|
|
- tmids.ForEach(x => {
|
|
|
+ tmids.ForEach(x =>
|
|
|
+ {
|
|
|
var user = tmdsData.Find(y => y.id.Equals(x.id));
|
|
|
x.name = user?.name;
|
|
|
x.picture = user?.picture;
|
|
|
});
|
|
|
- students.ForEach(x => {
|
|
|
+ students.ForEach(x =>
|
|
|
+ {
|
|
|
var student = studentsData.Find(y => y.id.Equals(x.id) && y.code.Equals(x.code));
|
|
|
x.name = student?.name;
|
|
|
x.picture = student?.picture;
|
|
@@ -184,7 +498,7 @@ public class GroupListService
|
|
|
mbs.AddRange(students);
|
|
|
return (groups, mbs);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static async Task FixActivity(CosmosClient client, DingDing _dingDing, GroupChange groupChange, string type)
|
|
|
{
|
|
|
try
|
|
@@ -196,7 +510,7 @@ public class GroupListService
|
|
|
if (groupChange.scope.Equals("school", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(groupChange.school))
|
|
|
{
|
|
|
await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<MQActivity>(queryText: query,
|
|
|
- requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{groupChange.school}") }))
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"{type}-{groupChange.school}") }))
|
|
|
{
|
|
|
datas.Add(item);
|
|
|
}
|
|
@@ -232,7 +546,7 @@ public class GroupListService
|
|
|
foreach (MQActivity activity in datas)
|
|
|
{
|
|
|
//已经完结的不再允许加入,还未开始的。
|
|
|
- if (activity.progress.Equals("finish") || activity.progress.Equals("pending"))
|
|
|
+ if (string.IsNullOrEmpty(activity.progress)|| activity.progress.Equals("finish") || activity.progress.Equals("pending"))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
@@ -320,10 +634,10 @@ public class GroupListService
|
|
|
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{member.code.Replace("Base-", "")}-{member.id}"));
|
|
|
}
|
|
|
- catch (CosmosException )
|
|
|
+ catch (CosmosException)
|
|
|
{
|
|
|
continue;
|
|
|
- // 继续执行 删除失败
|
|
|
+ // 继续执行 删除失败
|
|
|
}
|
|
|
}
|
|
|
foreach (Member member in groupChange.tmdleave)
|
|
@@ -333,7 +647,7 @@ public class GroupListService
|
|
|
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{member.id}"));
|
|
|
}
|
|
|
- catch (CosmosException )
|
|
|
+ catch (CosmosException)
|
|
|
{
|
|
|
continue;
|
|
|
// 继续执行 删除失败
|
|
@@ -345,7 +659,7 @@ public class GroupListService
|
|
|
{
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemAsync<StuActivity>(activity.id, new PartitionKey($"Activity-{member.id}"));
|
|
|
}
|
|
|
- catch (CosmosException )
|
|
|
+ catch (CosmosException)
|
|
|
{
|
|
|
continue;
|
|
|
// 继续执行 删除失败
|