Ver código fonte

处理未参与评审的专家数据

CrazyIter_Bin 1 ano atrás
pai
commit
ff66d34cda

+ 163 - 0
TEAMModelOS.SDK/Models/Service/Common/ActivityService.cs

@@ -13,10 +13,12 @@ using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.Linq;
 using System.Linq;
+using System.Net.Http;
 using System.Net.NetworkInformation;
 using System.Net.NetworkInformation;
 using System.Text;
 using System.Text;
 using System.Text.Json;
 using System.Text.Json;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
+using TEAMModelOS.Models;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models;
@@ -29,6 +31,167 @@ namespace TEAMModelOS.SDK
     public static class ActivityService
     public static class ActivityService
     {
     {
 
 
+
+       public static  async Task<List<ExpertDto>> ListExperts(AzureCosmosFactory _azureCosmos ,CoreAPIHttpService _coreAPIHttpService,DingDing _dingDing, Option _option, string _activityId) {
+            List<ExpertDto> expertTasks = new List<ExpertDto>();
+            ActivityExpert activityExpert = null;
+
+            Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemStreamAsync($"{_activityId}", new PartitionKey("ActivityExpert"));
+            if (response.Status == 200)
+            {
+                bool change = false;
+                activityExpert = JsonDocument.Parse(response.Content).RootElement.Deserialize<ActivityExpert>();
+                var experts = activityExpert.experts.FindAll(z => string.IsNullOrWhiteSpace(z.id));
+                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);
+                }
+                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)
+                            {
+                                change=true;
+                                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)
+                                {
+                                    change=true;
+                                    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)
+                                {
+                                    change=true;
+                                    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 (change)
+                {
+                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(activityExpert, new PartitionKey("ActivityExpert"));
+                }
+
+                Contest contest = null;
+                Azure.Response contestResponse = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(_activityId, new PartitionKey("Contest"));
+                if (contestResponse.Status==200)
+                {
+                    contest = JsonDocument.Parse(contestResponse.Content).RootElement.ToObject<Contest>();
+                }
+                List<ExpertDto> expertDtos = activityExpert.experts.Select(z => z.ToJsonString().ToObject<ExpertDto>()).ToList();
+                long now = DateTimeOffset.Now.ToUnixTimeMilliseconds();
+                //进入评审环节
+                if (contest.review!= null  && now > contest.review.stime)
+                {
+
+                    if (expertDtos!=null  && expertDtos.Count()>0)
+                    {
+                        var hasIds = expertDtos.Where(x => !string.IsNullOrWhiteSpace(x.id));
+                        if (hasIds!=null  && hasIds.Count()>0)
+                        {
+                            string taskSql = $"select value c from c where c.id in ({string.Join(",", hasIds.Select(z => $"'{z.id}'"))})";
+                            var taskResults = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<ActivityExpertTask>(taskSql, $"ActivityExpertTask-{_activityId}");
+
+                            foreach (var item in taskResults.list)
+                            {
+                                var dto = expertDtos.Find(z => !string.IsNullOrWhiteSpace(z.id)  &&  z.id.Equals(item.id));
+                                if (dto!=null)
+                                {
+                                    dto.taskCount =item.contestTasks.Count();
+                                    dto.teacherCount=item.contestTasks.SelectMany(z => z.members).Count();
+                                    dto.completeCount=item.contestTasks.Where(z => z.status==1).Count();
+                                    dto.uploads=  item.contestTasks.Select(z => new ContestUploadData { name = z.name, id=z.uploadId, code=string.Join(",", z.uploadTypes), count=z.count, status= z.status, score=z.score, detailScore=z.detailScore }).ToList();
+                                }
+                            }
+                        }
+                    }
+                }
+                expertTasks.AddRange(expertDtos);
+            }
+       
+            return expertTasks;
+        }
+
         public static async Task<List<ActivityScoreLevel>> ActivityScores (AzureCosmosFactory _azureCosmos,JsonElement _activityId,string teacherId= null) {
         public static async Task<List<ActivityScoreLevel>> ActivityScores (AzureCosmosFactory _azureCosmos,JsonElement _activityId,string teacherId= null) {
             List<ActivityScoreLevel> scoreLevels = new List<ActivityScoreLevel>();
             List<ActivityScoreLevel> scoreLevels = new List<ActivityScoreLevel>();
             Azure.Response responseContest = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(_activityId.GetString(), new PartitionKey("Contest"));
             Azure.Response responseContest = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(_activityId.GetString(), new PartitionKey("Contest"));

+ 29 - 163
TEAMModelOS/Controllers/Common/ActivityController.cs

@@ -1411,27 +1411,44 @@ namespace TEAMModelOS.Controllers
                                         // List<ActivityExpertTask> expertTasks = new List<ActivityExpertTask>();
                                         // List<ActivityExpertTask> expertTasks = new List<ActivityExpertTask>();
                                         string taskSQL = $"select distinct value c from c  join s in c.contestTasks  where c.pk='ActivityExpertTask' and s.uploadId in ({string.Join(",", uploadContestIds.Select(z => $"'{z}'"))})";
                                         string taskSQL = $"select distinct value c from c  join s in c.contestTasks  where c.pk='ActivityExpertTask' and s.uploadId in ({string.Join(",", uploadContestIds.Select(z => $"'{z}'"))})";
                                         List<ExpertContestTaskDto> worksDB = new List<ExpertContestTaskDto>();
                                         List<ExpertContestTaskDto> worksDB = new List<ExpertContestTaskDto>();
+                                       
                                         var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<ActivityExpertTask>(taskSQL, $"ActivityExpertTask-{_activityId}");
                                         var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<ActivityExpertTask>(taskSQL, $"ActivityExpertTask-{_activityId}");
                                         if (result.list.IsNotEmpty())
                                         if (result.list.IsNotEmpty())
                                         {
                                         {
+                                            List<ActivityExpertTask> change = new List<ActivityExpertTask>();
+                                            var experts = await ActivityService.ListExperts(_azureCosmos, _coreAPIHttpService, _dingDing, _option, $"{_activityId}");
                                             foreach (var item in result.list)
                                             foreach (var item in result.list)
                                             {
                                             {
-                                                foreach (var task in item.contestTasks)
+                                                var expert= experts.Find(x => !string.IsNullOrWhiteSpace(x.id) &&  x.id.Equals(item.id));
+                                                if (expert!=null) 
                                                 {
                                                 {
-                                                    var teachers = inviteEnrollTeachers.FindAll(z => !string.IsNullOrWhiteSpace(z.uploadContestId) && z.uploadContestId.Equals(task.uploadId));
-                                                    if (teachers!=null)
+                                                    foreach (var task in item.contestTasks)
                                                     {
                                                     {
-                                                        teachers.ForEach(z => { z.reviewContestAssignCount+=1; z.reviewContestExperts.Add(new ExpertUploadScore 
+                                                        var teachers = inviteEnrollTeachers.FindAll(z => !string.IsNullOrWhiteSpace(z.uploadContestId) && z.uploadContestId.Equals(task.uploadId));
+                                                        if (teachers!=null)
                                                         {
                                                         {
-                                                            score=task.score,
-                                                            detailScore=task.detailScore,
-                                                            id= item.id,
-                                                            name=item.name,
-                                                            nickname=item.tmdname,
-                                                            picture=item.picture
-                                                        }); });
+                                                            teachers.ForEach(z => {
+                                                                z.reviewContestAssignCount+=1;
+                                                                z.reviewContestExperts.Add(new ExpertUploadScore
+                                                                {
+                                                                    score=task.score,
+                                                                    detailScore=task.detailScore,
+                                                                    id= item.id,
+                                                                    name=item.name,
+                                                                    nickname=item.tmdname,
+                                                                    picture=item.picture
+                                                                });
+                                                            });
+                                                        }
                                                     }
                                                     }
                                                 }
                                                 }
+                                                else
+                                                {
+                                                    change.Add(item);
+                                                }
+                                            }
+                                            if (change.IsNotEmpty()) {
+                                              await  _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).DeleteItemsAsync<ActivityExpertTask>(change.Select(x=>x.id).ToList(),$"ActivityExpertTask-{_activityId}");
                                             }
                                             }
                                         }
                                         }
                                     }
                                     }
@@ -1693,158 +1710,7 @@ namespace TEAMModelOS.Controllers
                     case bool when $"{grant_type}".Equals("list-experts", StringComparison.OrdinalIgnoreCase):
                     case bool when $"{grant_type}".Equals("list-experts", StringComparison.OrdinalIgnoreCase):
                         {
                         {
                             if (!request.TryGetProperty("activityId", out JsonElement _activityId)) return BadRequest();
                             if (!request.TryGetProperty("activityId", out JsonElement _activityId)) return BadRequest();
-                            ActivityExpert activityExpert = null;
-                            List<ExpertDto> expertTasks = new List<ExpertDto>();
-                            Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemStreamAsync($"{_activityId}", new PartitionKey("ActivityExpert"));
-                            if (response.Status == 200)
-                            {
-                                bool change = false;
-                                activityExpert = JsonDocument.Parse(response.Content).RootElement.Deserialize<ActivityExpert>();
-                                var experts = activityExpert.experts.FindAll(z => string.IsNullOrWhiteSpace(z.id));
-                                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);
-                                }
-                                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)
-                                            {
-                                                change=true;
-                                                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)
-                                                {
-                                                    change=true;
-                                                    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)
-                                                {
-                                                    change=true;
-                                                    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 (change)
-                                {
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(activityExpert, new PartitionKey("ActivityExpert"));
-                                }
-
-                                Contest contest = null;
-                                Azure.Response contestResponse = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(_activityId.GetString(), new PartitionKey("Contest"));
-                                if (contestResponse.Status==200)
-                                {
-                                    contest = JsonDocument.Parse(contestResponse.Content).RootElement.ToObject<Contest>();
-                                }
-                                List<ExpertDto> expertDtos = activityExpert.experts.Select(z => z.ToJsonString().ToObject<ExpertDto>()).ToList();
-                                long now = DateTimeOffset.Now.ToUnixTimeMilliseconds();
-                                //进入评审环节
-                                if (contest.review!= null  && now > contest.review.stime) {
-                                  
-                                    if (expertDtos!=null  && expertDtos.Count()>0)
-                                    {
-                                        var hasIds = expertDtos.Where(x => !string.IsNullOrWhiteSpace(x.id));
-                                        if (hasIds!=null  && hasIds.Count()>0)
-                                        {
-                                            string taskSql = $"select value c from c where c.id in ({string.Join(",", hasIds.Select(z => $"'{z.id}'"))})";
-                                            var taskResults = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<ActivityExpertTask>(taskSql, $"ActivityExpertTask-{_activityId}");
-
-                                            foreach (var item in taskResults.list) {
-                                                var dto = expertDtos.Find(z => !string.IsNullOrWhiteSpace(z.id)  &&  z.id.Equals(item.id));
-                                                if (dto!=null  )
-                                                {
-                                                    dto.taskCount =item.contestTasks.Count();
-                                                    dto.teacherCount=item.contestTasks.SelectMany(z => z.members).Count();
-                                                    dto.completeCount=item.contestTasks.Where(z => z.status==1).Count();
-                                                    dto.uploads=  item.contestTasks.Select(z => new ContestUploadData { name = z.name, id=z.uploadId, code=string.Join(",", z.uploadTypes), count=z.count,status= z.status,score=z.score, detailScore=z.detailScore }).ToList();
-                                                }
-                                            }
-                                        }
-                                    }
-                                }
-                                expertTasks.AddRange(expertDtos);
-                            }
+                            var expertTasks = await  ActivityService.ListExperts(_azureCosmos, _coreAPIHttpService, _dingDing, _option, $"{_activityId}");
                             return Ok(new { expertTasks, code = 200 });
                             return Ok(new { expertTasks, code = 200 });
                         }
                         }
                     case bool when $"{grant_type}".Equals("update-reviewStatus", StringComparison.OrdinalIgnoreCase): 
                     case bool when $"{grant_type}".Equals("update-reviewStatus", StringComparison.OrdinalIgnoreCase):