CrazyIter_Bin 1 year ago
parent
commit
b12fbc6beb

+ 22 - 331
TEAMModelOS.FunctionV4/HttpTrigger/IESHttpTrigger.cs

@@ -1,7 +1,9 @@
 using Azure.Cosmos;
 using Azure.Storage.Blobs.Models;
 using Azure.Storage.Sas;
+using DocumentFormat.OpenXml.Bibliography;
 using DocumentFormat.OpenXml.Drawing.Wordprocessing;
+using DocumentFormat.OpenXml.Office2010.Excel;
 using DocumentFormat.OpenXml.Office2013.Excel;
 using DocumentFormat.OpenXml.Spreadsheet;
 using HTEXLib;
@@ -33,9 +35,11 @@ using System.Threading.Tasks;
 using System.Web;
 using TEAMModelOS.Models;
 using TEAMModelOS.SDK;
+using TEAMModelOS.SDK.Context.Constant;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Dtos;
 using TEAMModelOS.SDK.Models.Service;
 using TEAMModelOS.SDK.Models.Table;
 using static TEAMModelOS.SDK.Models.Teacher;
@@ -75,341 +79,28 @@ namespace TEAMModelOS.FunctionV4
         /// <param name="req"></param>
         /// <param name="log"></param>
         /// <returns></returns>
-        [Function("delete-unlinked-resource")]
+        [Function("push-intelligence")]
 
-        public async Task<HttpResponseData> DeleteUnlinkedResource([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req) {
+        public async Task<HttpResponseData> PushIntelligence([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req) 
+        {
             var response = req.CreateResponse(HttpStatusCode.OK);
+             
+            return response;
+        }
+        /// <summary>
+         /// </summary>
+         /// <param name="req"></param>
+         /// <param name="log"></param>
+         /// <returns></returns>
+        [Function("upsert-student-portrait")]
+
+        public async Task<HttpResponseData> PushArt([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestData req)
+        {
             string data = await new StreamReader(req.Body).ReadToEndAsync();
             var json = JsonDocument.Parse(data).RootElement;
-            if (!json.TryGetProperty("containerName", out JsonElement containerName) || !json.TryGetProperty("scope", out JsonElement scope)) {
-                return response;
-            }
-            List<UnLink> unLinks = new List<UnLink>();
-            //文件名(关联路径)导向的文件夹  内容(audio doc image video other  thum 缩略图) 学生头像(avatar)
-            string[] prefixFile = new string[] { "audio","doc", "image" , "video" , "other"  , "thum", "avatar" };
-            foreach (string prefix in prefixFile) {
-                string tbname = scope.ToString().Equals("school") ? Constant.School : Constant.Teacher;
-                switch (true)
-                {
-                    //Bloblog
-
-                    case bool when prefix.Equals("doc", StringComparison.OrdinalIgnoreCase)
-                        || prefix.Equals("image", StringComparison.OrdinalIgnoreCase)
-                        || prefix.Equals("video", StringComparison.OrdinalIgnoreCase)
-                        || prefix.Equals("audio", StringComparison.OrdinalIgnoreCase)
-                        || prefix.Equals("other", StringComparison.OrdinalIgnoreCase):
-                        {
-                            //   audio/最愛情歌80-89-這些日子以來 (張清芳+范怡文).mp3
-                            List<KeyValuePair<string, long?>> blobs = new List<KeyValuePair<string, long?>>();
-                            await foreach (BlobItem blobItem in _azureStorage.GetBlobContainerClient(containerName.ToString()).GetBlobsAsync(BlobTraits.None, BlobStates.None, prefix: prefix))
-                            {
-                                blobs.Add(new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength));
-                            }
-                            if (blobs.IsNotEmpty()) {
-                                string code = $"Bloblog-{containerName}";
-                                string sql = $"select value c from c where c.url in ({string.Join(",", blobs.Select(z => $"'{z.Key}'"))})";
-                                var result =await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetList<Bloblog>(sql, code);
-                                if (result.list.IsNotEmpty()) {
-                                    var urls=  result.list.Select(x => x.url).ToHashSet();
-                                    var unlink  =  blobs.ExceptBy(urls, x => x.Key).ToList();
-                                    long?  size = unlink.Select(z => z.Value).Sum();
-                                    unLinks.Add(new UnLink { prefix = prefix, blobs = unlink , size= size });
-                                }
-                            }
-                            break;
-                        }
-                    case bool when prefix.Equals("avatar", StringComparison.OrdinalIgnoreCase) && scope.ToString().Equals("school"):
-                        {
-                            List<KeyValuePair<string, long?>> blobs = new List<KeyValuePair<string, long?>>();
-                            await foreach (BlobItem blobItem in _azureStorage.GetBlobContainerClient(containerName.ToString()).GetBlobsAsync(BlobTraits.None, BlobStates.None, prefix: prefix))
-                            {
-                                blobs.Add(new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength));
-                            }
-                            if (blobs.IsNotEmpty()) {
-                                string code = $"Base-{containerName}";
-                                List<KeyValuePair<string, long?>> unlink = new List<KeyValuePair<string, long?>>();
-                                foreach (var blob in blobs) {
-                                    string sql = $"select value c from c  where contains(c.picture,'{blob.Key}')";
-                                    var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetList<Bloblog>(sql, code,pageSize:1);
-                                    //找不到对应的数据存储
-                                    if (!result.list.IsNotEmpty())
-                                    {
-                                        unlink.Add(blob);
-                                    }
-                                }
-                                long? size = unlink.Select(z => z.Value).Sum();
-                                unLinks.Add(new UnLink { prefix = prefix, blobs = unlink, size = size });
-                            }
-                            break; 
-                        }
-                    default:break;
-                       
-                }
-            }
-            //文件夹(关联id)导向的文件夹 exam  homework art records  survey  vote  item
-            string[] prefixDirId = new string[] { "exam"  , "homework" , "art" , "records"  , "survey"  , "vote"  ,"item" };
-            foreach (string prefix in prefixDirId) {
-                string tbname = string.Empty;
-                HashSet<string> ids = new HashSet<string>();
-                Dictionary<string, List<KeyValuePair<string, long?>>> recordUrls = new Dictionary<string, List<KeyValuePair<string, long?>>>();
-                await foreach (BlobItem blobItem in _azureStorage.GetBlobContainerClient(containerName.ToString()).GetBlobsAsync(BlobTraits.None, BlobStates.None, prefix: prefix))
-                {
-                    var path = blobItem.Name.Split("/");
-                    if (path.Length >3)
-                    {
-                        string id = path[1];
-                        ids.Add(id);
-                        if (recordUrls.ContainsKey(id))
-                        {
-                            recordUrls[id].Add(new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength));
-                        }
-                        else
-                        {
-                            recordUrls[id] = new List<KeyValuePair<string, long?>> { new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength) };
-                        }
-                    }
-                    if (path.Length == 3) {
-                        unLinks.Add(new UnLink { prefix = prefix, blobs = new List<KeyValuePair<string, long?>> { new KeyValuePair<string, long?>(blobItem.Name,blobItem.Properties.ContentLength)}, size = blobItem.Properties.ContentLength });
-                    }
-                }
-                string code=string.Empty;
-                if (ids.Any() && ids.Count>0) {
-                    string sql = $"select value c.id  from c where   c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})";
-                    switch (true)
-                    {
-                        case bool when prefix.Equals("exam", StringComparison.OrdinalIgnoreCase):
-                            {
-                                tbname = Constant.Common;
-                                code = $"Exam-{containerName}";
-                                break;
-                            }
-                        case bool when prefix.Equals("homework", StringComparison.OrdinalIgnoreCase) :
-                            {
-                                tbname = Constant.Common;
-                                code = $"Homework-{containerName}";
-                                break;
-                            }
-                        case bool when prefix.Equals("art", StringComparison.OrdinalIgnoreCase) :
-                            {
-                                tbname = Constant.Common;
-                                code = $"Art-{containerName}";
-                                break;
-                            }
-                        case bool when prefix.Equals("survey", StringComparison.OrdinalIgnoreCase):
-                            {
-                                tbname = Constant.Common;
-                                code = $"Survey-{containerName}";
-                                break;
-                            }
-                        case bool when prefix.Equals("vote", StringComparison.OrdinalIgnoreCase) :
-                            {
-                                tbname = Constant.Common;
-                                code = $"Vote-{containerName}";
-                                break;
-                            }
-                        case bool when prefix.Equals("item", StringComparison.OrdinalIgnoreCase):
-                            {
-                                tbname = scope.ToString().Equals("school") ? Constant.School : Constant.Teacher;
-                                code = $"Item-{containerName}";
-                                break;
-                            }
-                        case bool when prefix.Equals("records", StringComparison.OrdinalIgnoreCase):
-                            {
-                                tbname = scope.ToString().Equals("school") ? Constant.School : Constant.Teacher;
-                                code = scope.ToString().Equals("school") ? $"LessonRecord-{containerName}" : "LessonRecord";
-                                break;
-                            }
-                    }
-                    IEnumerable<string> unlink = null;
-                    var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetList<string>(sql, code);
-                    if (result != null && result.list.Any())
-                    {
-                        unlink = ids.Except(result.list);
-                    }
-                    else
-                    {
-                        unlink = ids;
-                    }
-                    var unlinkData = recordUrls.Where(x => unlink.Contains(x.Key));
-                    var unlinkPaths = unlinkData.SelectMany(z => z.Value).ToList();
-                    unLinks.Add(new UnLink { prefix = prefix, blobs = unlinkPaths, size = unlinkPaths.Select(z=>z.Value).Sum() });
-                }
-            }
-            //名字导向 试卷(paper) 
-            {
-                string prefix = "paper";
-                //List<KeyValuePair<string, long?>> blobs = new List<KeyValuePair<string, long?>>();
-                HashSet<string> paperNames  = new HashSet<string>();
-                Dictionary<string, List<KeyValuePair<string, long?>>> recordUrls = new Dictionary<string, List<KeyValuePair<string, long?>>>();
-                await foreach (BlobItem blobItem in _azureStorage.GetBlobContainerClient(containerName.ToString()).GetBlobsAsync(BlobTraits.None, BlobStates.None, prefix: prefix))
-                {
-                    var path = blobItem.Name.Split("/");
-                    if (path.Length > 3)
-                    {
-                        string paperName = path[1];
-                        paperNames.Add(paperName);
-                        if (recordUrls.ContainsKey(paperName))
-                        {
-                            recordUrls[paperName].Add(new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength));
-                        }
-                        else
-                        {
-                            recordUrls[paperName] = new List<KeyValuePair<string, long?>> { new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength) };
-                        }
-                    }
-                    if (path.Length == 3)
-                    {
-                        unLinks.Add(new UnLink { prefix = prefix, blobs = new List<KeyValuePair<string, long?>> { new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength) }, size = blobItem.Properties.ContentLength });
-                    }
-                }
-                string tbname = scope.ToString().Equals("school") ? Constant.School : Constant.Teacher;
-                string code = $"Paper-{containerName}";
-                if (paperNames.Any() && paperNames.Count > 0)
-                {
-                    IEnumerable<string> unlink = null;
-                    string sql = $"select value c from c where   c.name in ({string.Join(",", paperNames.Select(x => $"'{x}'"))})";
-                    var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetList<string>(sql, code);
-                    if (result != null && result.list.Any())
-                    {
-                        unlink = paperNames.Except(result.list);
-                    }
-                    else
-                    {
-                        unlink = paperNames;
-                    }
-                    var unlinkData = recordUrls.Where(x => unlink.Contains(x.Key));
-                    var unlinkPaths = unlinkData.SelectMany(z => z.Value).ToList();
-                    unLinks.Add(new UnLink { prefix = prefix, blobs = unlinkPaths, size = unlinkPaths.Select(z => z.Value).Sum() });
-                }
-            }
-            //htex hte (res)
-            {
-                string prefix = "res";
-               
-                //List<KeyValuePair<string, long?>> blobs = new List<KeyValuePair<string, long?>>();
-                HashSet<string> htexNames = new HashSet<string>();
-                List<KeyValuePair<string, long?>> hteBlobs = new List<KeyValuePair<string, long?>>();
-                Dictionary<string, List<KeyValuePair<string, long?>>> recordUrls = new Dictionary<string, List<KeyValuePair<string, long?>>>();
-                await foreach (BlobItem blobItem in _azureStorage.GetBlobContainerClient(containerName.ToString()).GetBlobsAsync(BlobTraits.None, BlobStates.None, prefix: prefix))
-                {
-                    var path = blobItem.Name.Split("/");
-                    if (path.Length > 3)
-                    {
-                        string htexName = path[1];
-                        htexNames.Add(htexName);
-                        if (recordUrls.ContainsKey(htexName))
-                        {
-                            recordUrls[htexName].Add(new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength));
-                        }
-                        else
-                        {
-                            recordUrls[htexName] = new List<KeyValuePair<string, long?>> { new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength) };
-                        }
-                    }
-                    if (path.Length == 3)
-                    {
-                        string blobName = "";
-                        if (blobItem.Name.EndsWith(".htex", StringComparison.OrdinalIgnoreCase) ) {
-                            blobName= blobItem.Name.Substring(0, blobItem.Name.Length - 5);
-                        }
-                        if (blobItem.Name.EndsWith(".hte", StringComparison.OrdinalIgnoreCase)) {
-                            blobName = blobItem.Name.Substring(0, blobItem.Name.Length - 4);
-                        }
-                        if (!string.IsNullOrWhiteSpace(blobName))
-                        {
-                            hteBlobs.Add(new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength));
-                        }
-
-                        //unLinks.Add(new UnLink { prefix = prefix, blobs = new List<KeyValuePair<string, long?>> { new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength) }, size = blobItem.Properties.ContentLength });
-                    }
-                }
-                string tbname = scope.ToString().Equals("school") ? Constant.School : Constant.Teacher;
-                string code = $"Bloblog-{containerName}";
-                if (htexNames.Any() && htexNames.Count > 0)
-                {
-                    List<string> unlink = new List<string>() ;
-                    foreach (var htexName in htexNames)
-                    {
-
-                        string sql = $"select value c from c    where contains(c.url,'{htexName}')  ";
-                        var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetList<Bloblog>(sql, code,pageSize:1);
-                        //找不到对应的数据存储
-                        if (!result.list.IsNotEmpty())
-                        {
-                            unlink.Add(htexName);
-                        }
-                    }
-                    var unlinkData = recordUrls.Where(x => unlink.Contains(x.Key));
-                    var unlinkPaths = unlinkData.SelectMany(z => z.Value).ToList();
-                    unLinks.Add(new UnLink { prefix = prefix, blobs = unlinkPaths, size = unlinkPaths.Select(z => z.Value).Sum() });
-                }
-
-                if (hteBlobs.IsNotEmpty()) {
-                    List<KeyValuePair<string, long?>> unlink = new List<KeyValuePair<string, long?>>();
-                    foreach (var hteName in hteBlobs)
-                    {
-                        string sql = $"select value c from c    where contains(c.url,'{hteName}')  ";
-                        var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetList<Bloblog>(sql, code, pageSize: 1);
-                        //找不到对应的数据存储
-                        if (!result.list.IsNotEmpty())
-                        {
-                            unlink.Add(hteName);
-                        }
-                    }
-                    long? size = unlink.Select(z => z.Value).Sum();
-                    unLinks.Add(new UnLink { prefix = prefix, blobs = unlink, size = size });
-                }
-            }
-            // 课纲(syllabus)  节点id  fc4b7ac5-24e7-4eba-b0f2-7eccd007b4cd
-            {
-                string prefix = "syllabus";
-                //List<KeyValuePair<string, long?>> blobs = new List<KeyValuePair<string, long?>>();
-                HashSet<string> rnodeIds = new HashSet<string>();
-                Dictionary<string, List<KeyValuePair<string, long?>>> recordUrls = new Dictionary<string, List<KeyValuePair<string, long?>>>();
-                await foreach (BlobItem blobItem in _azureStorage.GetBlobContainerClient(containerName.ToString()).GetBlobsAsync(BlobTraits.None, BlobStates.None, prefix: prefix))
-                {
-                    var path = blobItem.Name.Split("/");
-                    if (path.Length > 3)
-                    {
-                        string rnodeId = path[1];
-                        rnodeIds.Add(rnodeId);
-                        if (recordUrls.ContainsKey(rnodeId))
-                        {
-                            recordUrls[rnodeId].Add(new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength));
-                        }
-                        else
-                        {
-                            recordUrls[rnodeId] = new List<KeyValuePair<string, long?>> { new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength) };
-                        }
-                    }
-                    if (path.Length == 3)
-                    {
-                        unLinks.Add(new UnLink { prefix = prefix, blobs = new List<KeyValuePair<string, long?>> { new KeyValuePair<string, long?>(blobItem.Name, blobItem.Properties.ContentLength) }, size = blobItem.Properties.ContentLength });
-                    }
-                }
-
-                if (rnodeIds.Any() && rnodeIds.Count > 0) {
-                    string code = $"Syllabus-{containerName}";
-                    string tbname = scope.ToString().Equals("school") ? Constant.School : Constant.Teacher; ;
-                    string sql = $"select distinct value b.id from  c  join b in c.children where c.pk='Syllabus' and b.id in ({string.Join(",", rnodeIds.Select(x=>$"'{x}'"))})";
-                    IEnumerable<string> unlink = null;
-                    var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetList<string>(sql, code);
-                    if (result != null && result.list.Any())
-                    {
-                        unlink = rnodeIds.Except(result.list);
-                    }
-                    else
-                    {
-                        unlink = rnodeIds;
-                    }
-                    var unlinkData = recordUrls.Where(x => unlink.Contains(x.Key));
-                    var unlinkPaths = unlinkData.SelectMany(z => z.Value).ToList();
-                    unLinks.Add(new UnLink { prefix = prefix, blobs = unlinkPaths, size = unlinkPaths.Select(z => z.Value).Sum() });
-                }
-            }
-
-            //待确认  德育风采 (elegant)  public    研修培训(train) 研修平台  yxpt
-            //直接删除的 test  jyzx
+            var response = req.CreateResponse(HttpStatusCode.OK);
+            var responseData = await OpenApiService.UpsertStudentPortrait(_azureCosmos, _dingDing, json);
+            await response.WriteAsJsonAsync(new { responseData });
             return response;
         }
         /// <summary>

TEAMModelOS/Models/ShanDa/Field.cs → TEAMModelOS.SDK/Models/Dtos/ShanDa/Field.cs


+ 120 - 44
TEAMModelOS/Controllers/OpenApi/OpenApiService.cs

@@ -30,13 +30,9 @@ using TEAMModelOS.SDK.Models.Service;
 using TEAMModelOS.SDK.Models.Cosmos.BI.BINormal;
 using TEAMModelOS.SDK.Models.Cosmos.Student;
 using Microsoft.OData.Edm;
-using TEAMModelOS.Controllers.Core;
-using DocumentFormat.OpenXml.VariantTypes;
-using static TEAMModelOS.Controllers.CourseController;
 using System.IdentityModel.Tokens.Jwt;
 using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
 using Microsoft.OData.UriParser;
-using FastJSON;
 using Azure.Core;
 using System.Security.Policy;
 using System.Net.Http.Json;
@@ -49,7 +45,7 @@ using TEAMModelOS.Models.ShanDa;
 using System.Runtime.ConstrainedExecution;
 using DocumentFormat.OpenXml.Wordprocessing;
 
-namespace TEAMModelOS.Controllers
+namespace TEAMModelOS.SDK
 {
     public class OpenApiService
     {
@@ -632,22 +628,26 @@ namespace TEAMModelOS.Controllers
                     members = x.members,
                     id = x.id
                 }).ToList();
-                if (bizId.Equals("cc7e900c-4881-4fe9-9c64-abb1a1f95518") || bizId.Equals("8254bc86-aae9-4fef-9655-4fbda1bd39da")) {
-                    if (listids.Count == 1 && listids.First().Equals("TeacherAll") && !string.IsNullOrEmpty(school)) {
-                        var keys = members.Select(x=>x.id).ToHashSet();
+                if (bizId.Equals("cc7e900c-4881-4fe9-9c64-abb1a1f95518") || bizId.Equals("8254bc86-aae9-4fef-9655-4fbda1bd39da"))
+                {
+                    if (listids.Count == 1 && listids.First().Equals("TeacherAll") && !string.IsNullOrEmpty(school))
+                    {
+                        var keys = members.Select(x => x.id).ToHashSet();
                         var content = new StringContent(keys.ToJsonString(), Encoding.UTF8, "application/json");
                         string ujson = await _coreAPIHttpService.GetUserInfos(content);
                         if (!string.IsNullOrWhiteSpace(ujson))
                         {
                             var coreUsers = ujson.ToObject<List<CoreUser>>();
-                            if (coreUsers.IsNotEmpty()) {
+                            if (coreUsers.IsNotEmpty())
+                            {
                                 coreUsers.ForEach(z => {
                                     var mb = members.Find(x => x.id.Equals(z.id));
-                                    if (mb != null) {
+                                    if (mb != null)
+                                    {
                                         mb.no = z.mobile;
                                     }
                                 });
-                               
+
                             }
                         }
                     }
@@ -793,7 +793,7 @@ namespace TEAMModelOS.Controllers
                 string input = stringBuilder.ToString();
                 Field fields = input.ToObject<Field>();
                 List<OCourseBase> courses = new();
-                List<(string name, double T, double P, int attendCount,int mCount,int groups,long time, 
+                List<(string name, double T, double P, int attendCount, int mCount, int groups, long time,
                     List<(string name, int count)> counts, List<(string name, double score)> ps,
                     List<(string name, long time)> appTimes, List<(string name, string url, int duration, long time)> vd)> scores = new();
                 //List<(string name, List<(string name, int count)> counts)> eveCounts = new();
@@ -838,11 +838,13 @@ namespace TEAMModelOS.Controllers
                         int P4Count = 0;
                         int P5Count = 0;
                         List<(string name, long time)> eveTimes = new();
-                        List<(string name, string url,int duration, long time)> videos = new();
-                        foreach (var v in eve.videos) {
-                            videos.Add((v.videoName,v.video,v.duration, v.startTime));
+                        List<(string name, string url, int duration, long time)> videos = new();
+                        foreach (var v in eve.videos)
+                        {
+                            videos.Add((v.videoName, v.video, v.duration, v.startTime));
                         }
-                        foreach (var apps in eve.eves) {
+                        foreach (var apps in eve.eves)
+                        {
                             var name = fields.fields.Where(x => x.field.Equals(apps.@event)).FirstOrDefault()?.desc;
                             eveTimes.Add((name, apps.createTime));
                         }
@@ -972,7 +974,7 @@ namespace TEAMModelOS.Controllers
                         double scoreT = scoreA + scoreB + scoreC;
                         scoreT = scoreT > 0 ? Math.Round(scoreT, 2) : 0;
                         P = P > 0 ? Math.Round(P, 2) : 0;
-                        scores.Add((eve.courseName, scoreT, P,eve.attendCount,eve.mCount,eve.groups.Count,eve.time,eves, PScore, eveTimes, videos));
+                        scores.Add((eve.courseName, scoreT, P, eve.attendCount, eve.mCount, eve.groups.Count, eve.time, eves, PScore, eveTimes, videos));
                         //eveCounts.Add((eve.courseName, eves));
                     }
                     //var eve = courses.Select(c => c.eves).ToList();
@@ -992,16 +994,16 @@ namespace TEAMModelOS.Controllers
                     c.groups,
                     c.time,
                     count = c.counts.Select(x => new { x.name, x.count }),
-                    pScore = c.ps.Select(x => new {x.name,x.score }),
-                    appTime = c.appTimes.Select(x => new {x.name,x.time }),
-                    videos = c.vd.Select(x =>new { x.name,x.url,x.duration,x.time})
+                    pScore = c.ps.Select(x => new { x.name, x.score }),
+                    appTime = c.appTimes.Select(x => new { x.name, x.time }),
+                    videos = c.vd.Select(x => new { x.name, x.url, x.duration, x.time })
                 });
                 /*var courseCount = eveCounts.Select(c => new
                 {
                     c.name,
                     count = c.counts.Select(x => new { x.name, x.count })
                 });*/
-                return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = new { courseScore} };
+                return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = new { courseScore } };
                 /*if (period != null)
                 {
                     return new ResponseData<dynamic>() { code = RespondCode.Ok, msg = "成功", data = new { period.subjects, period.timetable, period.grades, period.majors, weekDays } };
@@ -1679,7 +1681,7 @@ namespace TEAMModelOS.Controllers
         /// <param name="_dingDing"></param>
         /// <param name="json"></param>
         /// <returns></returns>
-        public static async Task<ResponseData<dynamic>> UpsertStudentPortrait(AzureCosmosFactory _azureCosmos, DingDing _dingDing, string bizId, string school, JsonElement json)
+        public static async Task<ResponseData<dynamic>> UpsertStudentPortrait(AzureCosmosFactory _azureCosmos, DingDing _dingDing,   JsonElement json,string school=null)
         {
             try
             {
@@ -1689,6 +1691,11 @@ namespace TEAMModelOS.Controllers
                 {
                     return responseData = new() { code = RespondCode.ParamsError, msg = "schoolCode为空" };
                 }
+#if !DEBUG
+                if (!string.IsNullOrWhiteSpace(school) && !school.Equals($"{schoolCode}", StringComparison.OrdinalIgnoreCase)) {
+                    return responseData = new() { code = RespondCode.ParamsError, msg = "授权学校与参数schoolCode不匹配" };
+                }
+#endif
                 if (!json.TryGetProperty("periodId", out JsonElement periodId))
                 {
                     return responseData = new() { code = RespondCode.ParamsError, msg = "periodId为空" };
@@ -1702,17 +1709,21 @@ namespace TEAMModelOS.Controllers
                     return responseData = new() { code = RespondCode.ParamsError, msg = "students为空或格式错误" };
                 }
                 if (!$"{subjectId}".Equals("subject_sport") && !$"{subjectId}".Equals("subject_virtue") && !$"{subjectId}".Equals("subject_labour")
-                    //&& !$"{subjectId}".Equals("subject_music") && !$"{subjectId}".Equals("subject_painting") 
+                    && !$"{subjectId}".Equals("subject_intelligence")  
                     && !$"{subjectId}".Equals("subject_art"))
                 {
                     return responseData = new() { code = RespondCode.ParamsError, msg = "当前subjectId未开放画像业务" };
                 }
-                School schoolBase = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>(school, new PartitionKey("Base"));
+                School schoolBase = await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<School>($"{schoolCode}", new PartitionKey("Base"));
                 List<PortraitStudent> students = _students.ToObject<List<PortraitStudent>>();
                 List<(Student studentBase, PortraitStudent portrait)> studentsBases = new List<(Student, PortraitStudent)>();
+                //学生信息不匹配的
                 List<PortraitStudent> unmatchStuInfo = new List<PortraitStudent>();
+                //学期不匹配的
                 List<PortraitStudent> unmatchSemester = new List<PortraitStudent>();
                 List<PortraitStudent> upsertDatas = new List<PortraitStudent>();
+                //细项类型不匹配的
+                List<PortraitStudent> unmatchItemScoreType = new List<PortraitStudent>();
                 string stusql = $"select c.id,c.classId,c.name,c.year  from c where c.id in ({string.Join(",", students.Select(f => $"'{f.studentId}'"))})";
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, Constant.Student)
                     .GetItemQueryIterator<Student>(queryText: stusql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{schoolCode}") }))
@@ -1763,9 +1774,9 @@ namespace TEAMModelOS.Controllers
                         periodChange = true;
                     }
                     //是否需要创建科目 
-                    if (!$"{subjectId}".Equals("subject_art"))
+                    if (!$"{subjectId}".Equals("subject_art", StringComparison.OrdinalIgnoreCase) || !$"{subjectId}".Equals("subject_intelligence", StringComparison.OrdinalIgnoreCase))
                     {
-                        var bind = period.subjects.Find(x => !string.IsNullOrWhiteSpace(x.bindId) && x.bindId.Equals($"{subjectId}"));
+                        var bind = period.subjects.Find(x => !string.IsNullOrWhiteSpace(x.bindId) && x.bindId.Equals($"{subjectId}", StringComparison.OrdinalIgnoreCase));
                         if (bind == null)
                         {
                             string subjectName = "";
@@ -1802,9 +1813,44 @@ namespace TEAMModelOS.Controllers
                             }
                         }
                     }
+                    //是否要创建艺术类的 音乐,美术科目
+                    if ($"{subjectId}".Equals("subject_art", StringComparison.OrdinalIgnoreCase))
+                    {
+                        var bind_music = period.subjects.Find(x => !string.IsNullOrWhiteSpace(x.bindId) && x.bindId.Equals("subject_music", StringComparison.OrdinalIgnoreCase));
+                        if (bind_music != null)
+                        {
+                            string subjectName = "音乐";
+                            var subName = period.subjects.Find(z => z.name.Contains(subjectName));
+                            if (subName != null)
+                            {
+                                subName.bindId = "subject_music";
+                            }
+                            else
+                            {
+                                period.subjects.Add(new Subject { id = Guid.NewGuid().ToString(), name = subjectName, bindId = "subject_music", type = 1 });
+                            }
+                            periodChange = true;
+                        }
+                        var bind_painting = period.subjects.Find(x => !string.IsNullOrWhiteSpace(x.bindId) && x.bindId.Equals("subject_painting", StringComparison.OrdinalIgnoreCase));
+                        if (bind_painting != null)
+                        {
+                            string subjectName = "美术";
+                            var subName = period.subjects.Find(z => z.name.Contains(subjectName));
+                            if (subName != null)
+                            {
+                                subName.bindId = "subject_painting";
+                            }
+                            else
+                            {
+                                period.subjects.Add(new Subject { id = Guid.NewGuid().ToString(), name = subjectName, bindId = "subject_painting", type = 1 });
+                            }
+                            periodChange = true;
+
+                        }
+                    }
                     if (periodChange)
                     {
-                        await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync<School>(schoolBase, school, new PartitionKey("Base"));
+                        await client.GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync<School>(schoolBase, $"{schoolCode}", new PartitionKey("Base"));
                     }
                     List<Semester> sortedSemesters = SchoolService.SortSemester(period.semesters);
                     foreach (var studentInfo in studentsBases)
@@ -1930,7 +1976,7 @@ namespace TEAMModelOS.Controllers
                                 });
                                 if (newOverallEducations.Any())
                                 {
-                                    newOverallEducations = FillSemesterData($"{subjectId}", newOverallEducations, newDatas);
+                                    (newOverallEducations, unmatchItemScoreType) = FillSemesterData($"{subjectId}", newOverallEducations, unmatchItemScoreType, newDatas,period);
                                     foreach (var edu in newOverallEducations)
                                     {
                                         await client.GetContainer(Constant.TEAMModelOS, Constant.Student).CreateItemAsync(edu, new PartitionKey(edu.code));
@@ -1938,7 +1984,7 @@ namespace TEAMModelOS.Controllers
                                 }
                                 if (overallEducations.Any())
                                 {
-                                    overallEducations = FillSemesterData($"{subjectId}", overallEducations, updateDatas);
+                                    (overallEducations, unmatchItemScoreType) = FillSemesterData($"{subjectId}", overallEducations, unmatchItemScoreType, updateDatas, period);
                                     foreach (var edu in overallEducations)
                                     {
                                         await client.GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(edu, edu.id, new PartitionKey(edu.code));
@@ -1948,7 +1994,7 @@ namespace TEAMModelOS.Controllers
                         }
                     }
                 }
-                return responseData = new() { data = new { unmatchStuInfo, unmatchSemester, upsertDatas }, code = RespondCode.Ok, msg = "成功" };
+                return responseData = new() { data = new { unmatchStuInfo, unmatchSemester, unmatchItemScoreType, upsertDatas }, code = RespondCode.Ok, msg = "成功" };
             }
             catch (CosmosException cex) when (cex.Status == 404)
             {
@@ -1956,14 +2002,13 @@ namespace TEAMModelOS.Controllers
             }
             catch (Exception ex)
             {
-                await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/UpsertStudentPortrait()  参数:bizId:{bizId},school:{school},参数json:{json.ToJsonString()} \n  {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"OpenApi,{Environment.GetEnvironmentVariable("Option:Location")} OpenApiService/UpsertStudentPortrait() ,参数json:{json.ToJsonString()} \n  {ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
                 return new ResponseData<dynamic>() { code = RespondCode.Error, msg = "服务端异常" };
             }
         }
-        public static List<OverallEducation> FillSemesterData(string subjectId, List<OverallEducation> overallEducations, List<SemesterData> semestersDatas)
+        public static (List<OverallEducation> overallEducations, List<PortraitStudent> unmatchItemScoreType) FillSemesterData(string subjectId, List<OverallEducation> overallEducations,List<PortraitStudent> unmatchItemScoreType, List<SemesterData> semestersDatas,Period period)
         {
-
-            semestersDatas.ForEach(z =>
+            foreach (var z in semestersDatas)  
             {
                 var oedu = overallEducations.Find(x => x.id.Equals($"{z.year}-{z.semesterId}"));
                 if (oedu != null)
@@ -1980,15 +2025,46 @@ namespace TEAMModelOS.Controllers
                         case bool when $"{subjectId}".Equals("subject_labour"):
                             educationScores = oedu.labour;
                             break;
-                        //case bool when $"{subjectId}".Equals("subject_music"):
-                        //    educationScores = oedu.art;
-                        //    break;
-                        //case bool when $"{subjectId}".Equals("subject_painting"):
-                        //    educationScores = oedu.art;
-                        //    break;
+                        case bool when $"{subjectId}".Equals("subject_intelligence"):
+                            {
+                                educationScores = oedu.intelligence;
+                                //对评测需要验证 细项的具体信息
+                                bool isunmatch = false;
+                                foreach (var v in z.itemScore)
+                                {
+                                    var subject = period.subjects.Find(b => b.id.Equals(v.type));
+                                    if (subject == null)
+                                    {
+                                        isunmatch = true;
+                                    }
+                                }
+                                if (isunmatch)
+                                {
+                                    unmatchItemScoreType.Add(new PortraitStudent { classId = oedu.classId, name = oedu.name, studentId = oedu.studentId, semesterData = new List<SemesterData> { z } });
+                                    continue;
+                                }
+                                break;
+                            }
                         case bool when $"{subjectId}".Equals("subject_art"):
-                            educationScores = oedu.art;
-                            break;
+                            {
+                                educationScores = oedu.art;
+                                //对艺术评测需要验证 细项的具体信息
+                                bool isunmatch = false;
+                                foreach (var v in z.itemScore)
+                                {
+                                    var subject = period.subjects.Find(b => b.bindId.Equals(v.type));
+                                    if (subject == null)
+                                    {
+                                        isunmatch = true;
+                                    }
+                                }
+                                if (isunmatch)
+                                {
+                                    unmatchItemScoreType.Add(new PortraitStudent { classId = oedu.classId, name = oedu.name, studentId = oedu.studentId, semesterData = new List<SemesterData> { z } });
+                                    continue;
+                                }
+                                break;
+                            }
                         default:
                             educationScores = new List<EducationScore>();
                             break;
@@ -2012,8 +2088,8 @@ namespace TEAMModelOS.Controllers
                     edu.passRate = z.passRate;
                     edu.itemScore = z.itemScore;
                 }
-            });
-            return overallEducations;
+            }
+            return (overallEducations, unmatchItemScoreType);
         }
         public static void GenApiTableRecord(AzureStorageFactory azureStorage)
         {

+ 1 - 1
TEAMModelOS/Controllers/OpenApi/Business/BizOverallEducationController.cs

@@ -61,7 +61,7 @@ namespace TEAMModelOS.Controllers
         public async Task<IActionResult> UpsertStudentPortrait(JsonElement jsonElement)
         {
             var (id, school) = HttpContext.GetApiTokenInfo();
-            var responseData = await OpenApiService.UpsertStudentPortrait(_azureCosmos, _dingDing, id, school, jsonElement);
+            var responseData = await OpenApiService.UpsertStudentPortrait(_azureCosmos, _dingDing,   jsonElement,school);
             return Ok(new { responseData });
         }
 

+ 1 - 0
TEAMModelOS/Controllers/OpenApi/Business/BizRoomController.cs

@@ -6,6 +6,7 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.Filter;
 using TEAMModelOS.Models;
+using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 

+ 1 - 0
TEAMModelOS/Controllers/OpenApi/OpenSchool/ScRoomController.cs

@@ -9,6 +9,7 @@ using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.Filter;
 using TEAMModelOS.Models;
+using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;