Browse Source

Merge branch 'develop' of http://52.130.252.100:10000/TEAMMODEL/TEAMModelOS into develop

XW 1 year ago
parent
commit
10057ba9e7

+ 31 - 23
TEAMModelOS.SDK/Models/Service/StudentService.cs

@@ -42,14 +42,14 @@ namespace TEAMModelOS.SDK
             public string scope { get; set; }
             public string school { get; set; }
             public string creatorId { get; set; }
-        
-            public List<string> subjects { get; set; }
-         
-            public List<string> classes { get; set; }
-            public List<string> stuLists { get; set; }
-            public List<string> tchLists { get; set; }
+
+            public List<ExamSubject> subjects { get; set; } = new List<ExamSubject>();
+
+            public List<string> classes { get; set; } = new List<string>();
+            public List<string> stuLists { get; set; } = new List<string>();
+            public List<string> tchLists { get; set; }= new List<string>();
             public long createTime { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-            public Dictionary<string, JsonElement> ext { get; set; } = new Dictionary<string, JsonElement>();
+            //public Dictionary<string, JsonElement> ext { get; set; } = new Dictionary<string, JsonElement>();
             /// 评分状态,0,未评分, 1已评分
             public int sStatus { get; set; } = 0;
             //评测 纸本1或者书面问答0
@@ -76,9 +76,9 @@ namespace TEAMModelOS.SDK
         /// <param name="types">Exam ,Vote,Homework,Survey</param>
         /// <param name="_azureCosmos"></param>
         /// <param name="azureRedis"></param>
-        public static async void FindActivity(JsonElement request,string userId ,string userType, List<string>groupListIds,List<string> subjects, string school,List<string> types, AzureCosmosFactory _azureCosmos, AzureRedisFactory azureRedis)
+        public static async Task<List<StudentActivity>> FindActivity(JsonElement request,string userId ,string userScope, List<string>groupListIds,List<string> subjects, string school,List<string> types, AzureCosmosFactory _azureCosmos)
         {
-            string filed = "c.id ,c.code,c.owner,c.pk,c.qamode,c.name,c.school,c.startTime,c.endTime,c.classes,c.stuLists,c.tchLists,c.createTime,c.creatorId,c.ext,c.isSub,c.mustSubmit,c.sStatus,c.scope,c.source,c.subjects";
+            string filed = "c.id ,c.code,c.owner,c.pk,c.qamode,c.name,c.school,c.startTime,c.endTime,c.classes,c.stuLists,c.tchLists,c.createTime,c.creatorId,c.isSub,c.mustSubmit,c.sStatus,c.scope,c.source,c.subjects";
             if (string.IsNullOrWhiteSpace(school))
             {
                 if (request.TryGetProperty("school", out JsonElement schooljson))
@@ -104,17 +104,17 @@ namespace TEAMModelOS.SDK
                     etime= data;
                 }
             }
-            string code = null;
             string  groupListSQL =string .Empty ;
-
-
             if (groupListIds.IsNotEmpty())
             {
                 List<string >  arrayStr= new List<string>();
                 groupListIds.ForEach(z => {
                     arrayStr.Add($"array_contains(c.classes,'{z}') ");
                     arrayStr.Add($"array_contains(c.stuLists,'{z}') ");
-                    arrayStr.Add($"array_contains(c.tchLists,'{z}') ");
+                    if (userScope.Equals(Constant.ScopeTeacher))
+                    {
+                        arrayStr.Add($"array_contains(c.tchLists,'{z}') ");
+                    }
                 });
                 groupListSQL= $"and ({string.Join(" or ", arrayStr)})";
             }
@@ -131,9 +131,9 @@ namespace TEAMModelOS.SDK
                     subjectJoin = "join s in c.subjects";
                     subjectSQL = $" and  c.id in ({string.Join(",",subjects.Select(z=>$"'{z}'"))}) ";
                 }
-                StringBuilder SQL = new StringBuilder( $"select { filed} from c {subjectJoin} where c.pk='Exam' {subjectSQL} {groupListSQL} and c.createTime>={stime} and c.createTime <= {etime} and c.startTime <= {DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}");
+                StringBuilder SQL = new StringBuilder( $"select { filed} from c {subjectJoin} where c.pk='Exam' {subjectSQL} {groupListSQL} and c.startTime>={stime} and c.startTime <= {etime} ");
                 //获取学校发布的活动
-                if (userType.Equals(Constant.ScopeStudent)  && ! string.IsNullOrWhiteSpace(school)) {
+                if (userScope.Equals(Constant.ScopeStudent)  && ! string.IsNullOrWhiteSpace(school)) {
                    var resultSchool =   await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<StudentActivity>($"{SQL.ToString()}  and c.owner='school' ", $"Exam-{school}");
                     activities.AddRange(resultSchool.list);
                 }
@@ -147,9 +147,9 @@ namespace TEAMModelOS.SDK
             if (types.IsEmpty()|| types.Contains("Vote"))
             {
                
-                StringBuilder SQL = new StringBuilder($"select {filed} from c  where c.pk='Vote' {groupListSQL} and c.createTime>={stime} and c.createTime <= {etime} and c.startTime <= {DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}");
+                StringBuilder SQL = new StringBuilder($"select {filed} from c  where c.pk='Vote' {groupListSQL} and c.startTime>={stime} and c.startTime <= {etime} ");
                 //获取学校发布的活动
-                if (userType.Equals(Constant.ScopeStudent)  && !string.IsNullOrWhiteSpace(school))
+                if (userScope.Equals(Constant.ScopeStudent)  && !string.IsNullOrWhiteSpace(school))
                 {
                     var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<StudentActivity>($"{SQL.ToString()}  and c.owner='school' ", $"Vote-{school}");
                     activities.AddRange(resultSchool.list);
@@ -163,9 +163,9 @@ namespace TEAMModelOS.SDK
             if (types.IsEmpty()|| types.Contains("Survey"))
             {
 
-                StringBuilder SQL = new StringBuilder($"select {filed} from c  where c.pk='Survey' {groupListSQL} and c.createTime>={stime} and c.createTime <= {etime} and c.startTime <= {DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}");
+                StringBuilder SQL = new StringBuilder($"select {filed} from c  where c.pk='Survey' {groupListSQL} and c.startTime>={stime} and c.startTime <= {etime} ");
                 //获取学校发布的活动
-                if (userType.Equals(Constant.ScopeStudent)  && !string.IsNullOrWhiteSpace(school))
+                if (userScope.Equals(Constant.ScopeStudent)  && !string.IsNullOrWhiteSpace(school))
                 {
                     var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<StudentActivity>($"{SQL.ToString()}  and c.owner='school' ", $"Survey-{school}");
                     activities.AddRange(resultSchool.list);
@@ -179,9 +179,9 @@ namespace TEAMModelOS.SDK
             if (types.IsEmpty()|| types.Contains("Homework"))
             {
 
-                StringBuilder SQL = new StringBuilder($"select {filed} from c  where c.pk='Homework' {groupListSQL} and c.createTime>={stime} and c.createTime <= {etime} and c.startTime <= {DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}");
+                StringBuilder SQL = new StringBuilder($"select {filed} from c  where c.pk='Homework' {groupListSQL} and c.startTime>={stime} and c.startTime <= {etime} ");
                 //获取学校发布的活动
-                if (userType.Equals(Constant.ScopeStudent)  && !string.IsNullOrWhiteSpace(school))
+                if (userScope.Equals(Constant.ScopeStudent)  && !string.IsNullOrWhiteSpace(school))
                 {
                     var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<StudentActivity>($"{SQL.ToString()}  and c.owner='school' ", $"Homework-{school}");
                     activities.AddRange(resultSchool.list);
@@ -194,16 +194,24 @@ namespace TEAMModelOS.SDK
             }
             if (types.IsEmpty()|| types.Contains("Art"))
             {
+                string subjectSQL = "";
+                string subjectJoin = "";
+                if (subjects.IsNotEmpty())
+                {
+                    subjectJoin = "join s in c.subjects";
+                    subjectSQL = $" and  c.id in ({string.Join(",", subjects.Select(z => $"'{z}'"))}) ";
+                }
 
-                StringBuilder SQL = new StringBuilder($"select {filed} from c  where c.pk='Art' {groupListSQL} and c.createTime>={stime} and c.createTime <= {etime} and c.startTime <= {DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}");
+                StringBuilder SQL = new StringBuilder($"select {filed} from c  {subjectJoin} where c.pk='Art' {subjectSQL} {groupListSQL} and c.startTime>={stime} and c.startTime <= {etime} ");
                 //获取学校发布的活动
-                if (userType.Equals(Constant.ScopeStudent)  && !string.IsNullOrWhiteSpace(school))
+                if (userScope.Equals(Constant.ScopeStudent)  && !string.IsNullOrWhiteSpace(school))
                 {
                     var resultSchool = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<StudentActivity>($"{SQL.ToString()}  and c.school='school' ", $"Art-{school}");
                     activities.AddRange(resultSchool.list);
                 }
             }
             //作答 记录recordUrl  taskStatus
+            return activities;
         }
 
        

+ 3 - 2
TEAMModelOS/Controllers/Both/GroupListController.cs

@@ -205,12 +205,13 @@ namespace TEAMModelOS.Controllers
             }
             if (!json.TryGetProperty("stuListNo", out JsonElement _stuListNo)) return BadRequest();
             var (userid, _name, _picture, school) = HttpContext.GetAuthTokenInfo();
-            object scope = null;
+          
             int type = 0;
             string no = null;
             var client = _azureCosmos.GetCosmosClient();
-            HttpContext?.Items.TryGetValue("Scope", out scope);
             int year = DateTimeOffset.UtcNow.Year;
+            object scope = null;
+            HttpContext?.Items.TryGetValue("Scope", out scope);
             if ($"{scope}".Equals(Constant.ScopeStudent))
             {
                 type = 2;

+ 19 - 4
TEAMModelOS/Controllers/Student/StudentCommonController.cs

@@ -18,6 +18,7 @@ using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
 using TEAMModelOS.SDK.Services;
+using static TEAMModelOS.SDK.StudentService;
 
 namespace TEAMModelOS.Controllers
 {
@@ -68,10 +69,24 @@ namespace TEAMModelOS.Controllers
         public async Task<IActionResult> StudentActivity(JsonElement request)
         {
             var (id, name, pic, school) = HttpContext.GetAuthTokenInfo();
-
-            //(List<StuActivity> datas, string continuationToken) = await ActivityStudentService.FindActivity(request, id, school, _azureCosmos, _azureRedis);
-            //return Ok(new { datas, continuationToken });
-            return Ok();
+            object _scope = null;
+            List<string> groupListIds = new List<string>();
+            List<string> subjects = new List<string>();
+            if (request.TryGetProperty("groupListIds", out JsonElement _groupListIds)) {
+                groupListIds= _groupListIds.ToObject<List<string>>();
+            }
+            if (request.TryGetProperty("subjects", out JsonElement _subjects))
+            {
+                subjects= _subjects.ToObject<List<string>>();
+            }
+            List<string> types = new List<string>();
+            if (request.TryGetProperty("types", out JsonElement _types))
+            {
+                types= _types.ToObject<List<string>>();
+            }
+            HttpContext?.Items.TryGetValue("Scope", out  _scope);
+            List<StudentActivity> activities =  await  StudentService.FindActivity(request, id, $"{_scope}", groupListIds, subjects, school, types, _azureCosmos);
+            return Ok(new { code =200, activities ,serverTime=DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()});
         }
 
         /// <summary>