|
@@ -6,10 +6,112 @@ using TEAMModelOS.SDK.DI;
|
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
using HTEXLib.COMM.Helpers;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Diagnostics.CodeAnalysis;
|
|
|
+
|
|
|
namespace TEAMModelOS.SDK.Models.Service
|
|
|
{
|
|
|
- public class GroupChangeService
|
|
|
+ public class GroupListService
|
|
|
{
|
|
|
+ public static async Task<(List<GroupList> groups, List<GroupList> changes)> GetGroupListMemberInfo(CosmosClient client, DingDing _dingDing,string type, List<GroupList> groups) {
|
|
|
+
|
|
|
+ var members = groups.SelectMany(x => x.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> 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(x => new { key = x.Key, list = x.ToList() });
|
|
|
+ List<Student> studentsData = new List<Student>();
|
|
|
+ if (stu != null)
|
|
|
+ {
|
|
|
+ foreach (var item in stu)
|
|
|
+ {
|
|
|
+ var ids = item.list.Select(x => x.id).ToList();
|
|
|
+ if (ids.IsNotEmpty())
|
|
|
+ {
|
|
|
+ StringBuilder stuSql = new StringBuilder($"SELECT distinct c.name,c.id,c.code,c.picture,c.no FROM c ");
|
|
|
+ string insql = string.Join(",", ids.Select(x => $"'{x}'"));
|
|
|
+ stuSql.Append($"c.id in ({insql})");
|
|
|
+ await foreach (var student in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: stuSql.ToString(),
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-{item.key}") }))
|
|
|
+ {
|
|
|
+ studentsData.Add(student);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<TmdUser> tmds = new List<TmdUser>();
|
|
|
+ if (tmids.IsNotEmpty())
|
|
|
+ {
|
|
|
+ string memberTbname = "";
|
|
|
+ //可能会出现在两种表中
|
|
|
+ if ($"{type}".Equals("teach") || $"{type}".Equals("research") || $"{type}".Equals("group")
|
|
|
+ || $"{type}".Equals("friend") || $"{type}".Equals("manage") || $"{type}".Equals("subject"))
|
|
|
+ {
|
|
|
+ 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})");
|
|
|
+ memberTbname = "Teacher";
|
|
|
+ await foreach (var tmd in client.GetContainer(Constant.TEAMModelOS, memberTbname).GetItemQueryIterator<TmdUser>(queryText: tmdidSql.ToString(),
|
|
|
+ requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
|
|
|
+ {
|
|
|
+ tmds.Add(tmd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($"{type}".Equals("teach") || $"{type}".Equals("friend") || $"{type}".Equals("group"))
|
|
|
+ {
|
|
|
+ //取差集,减少二次搜寻
|
|
|
+ var tmdidexp = tmids.Select(x => x.id).Except(tmds.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") }))
|
|
|
+ {
|
|
|
+ tmds.Add(tmd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //去重
|
|
|
+ tmds = tmds.Where((x, i) => tmds.FindIndex(n => n.id.Equals(x.id)) == i).ToList();
|
|
|
+ }
|
|
|
+ HashSet<GroupList> changes = new HashSet<GroupList>();
|
|
|
+ var unexist_tmdid = tmids.Select(x => x.id).Except(tmds.Select(y => y.id)).ToList();
|
|
|
+ groups.ForEach(x => {
|
|
|
+ int item = x.members.RemoveAll(y => unexist_tmdid.Contains(y.id) && y.type == 1);
|
|
|
+ if (item > 0)
|
|
|
+ {
|
|
|
+ changes.Add(x);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ var unexist_student = students.Select(x => (x.id, x.code)).Except(studentsData.Select(y => (y.id, y.code)), new CompareStudent()).ToList();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return (groups, changes.ToList());
|
|
|
+ }
|
|
|
+ class CompareStudent : IEqualityComparer<(string id, string code)>
|
|
|
+ {
|
|
|
+ public bool Equals( (string id, string code) x,(string id, string code) y)
|
|
|
+ {
|
|
|
+ return x.id.Equals(y.id) && x.code.Equals(y.code);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int GetHashCode((string id, string code) obj)
|
|
|
+ {
|
|
|
+ if (obj.id != null && obj.code != null) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
public static async Task FixActivity(CosmosClient client, DingDing _dingDing, GroupChange groupChange, string type)
|
|
|
{
|
|
|
try
|