Browse Source

更新课纲

CrazyIter_Bin 4 năm trước cách đây
mục cha
commit
ecbab1cf07

+ 61 - 4
TEAMModelFunction/ActivityHttpTrigger.cs

@@ -353,7 +353,9 @@ namespace TEAMModelFunction
                                 school = info.school,
                                 creatorId = info.creatorId,
                                 subjects = new List<string>() { "" },
-                                blob = info.blob
+                                blob = info.blob,
+                                owner=info.owner
+                                
                             });
                         });
                     }
@@ -374,7 +376,8 @@ namespace TEAMModelFunction
                                 school = info.school,
                                 creatorId = info.creatorId,
                                 subjects = new List<string>() { "" },
-                                blob=info.blob
+                                blob=info.blob,
+                                owner = info.owner
                             });
                         });
                     }
@@ -397,8 +400,62 @@ namespace TEAMModelFunction
             string id = "";
             string code = "";
             var client = _azureCosmos.GetCosmosClient();
-            List<MQActivity> datas = new List<MQActivity>();
-            var item = client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<MQActivity>(id , new Azure.Cosmos.PartitionKey($"{code}"));
+            // var query = $"SELECT distinct c.owner, c.id,c.code, c.classes,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime   FROM c  join A1 in c.classes  where  c.pk='{type}' and A1 in('{stuListChange.listid}') "; 
+            MQActivity activity = null;
+            try {
+                activity= await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<MQActivity>(id, new Azure.Cosmos.PartitionKey($"{code}"));
+            } catch (Exception ex) { 
+                
+            }
+            if (activity != null) {
+               (List<string> tmdids, List<Students> students) =await  TriggerStuActivity.GetStuList(client,_dingDing, activity.classes, activity.school);
+                if (tmdids.IsNotEmpty()) {
+                    foreach (string tmdid in tmdids)
+                    {
+                        var stucourse = new StuActivity
+                        {
+                            id = activity.id,
+                            scode = activity.code,
+                            name = activity.name,
+                            code = $"Activity-{tmdid}",
+                            scope = activity.scope,
+                            school = activity.school,
+                            creatorId = activity.creatorId,
+                            pk = "Activity",
+                            type = activity.pk,
+                            subjects = activity.pk.ToLower().Equals("exam") ? activity.subjects : new List<string>() { "" },
+                            startTime = activity.startTime,
+                            endTime = activity.endTime,
+                            blob = activity.blob,
+                            owner = activity.owner
+                        };
+                        await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
+                    }
+                }
+                if (students.IsNotEmpty()) {
+                    foreach (Students student in students)
+                    {
+                        var stucourse = new StuActivity
+                        {
+                            id = activity.id,
+                            scode = activity.code,
+                            name = activity.name,
+                            code = $"Activity-{activity.school}-{student.id}",
+                            scope = activity.scope,
+                            school = activity.school,
+                            creatorId = activity.creatorId,
+                            pk = "Activity",
+                            type = activity.pk,
+                            subjects = activity.pk.Equals("exam") ? activity.subjects : new List<string>() { "" },
+                            startTime = activity.startTime,
+                            endTime = activity.endTime,
+                            blob = activity.blob,
+                            owner = activity.owner
+                        };
+                        await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
+                    }
+                }
+            }
             return null;
         }
 

+ 7 - 3
TEAMModelFunction/StuListService.cs

@@ -40,14 +40,15 @@ namespace TEAMModelFunction
                         scode = activity.code,
                         name = activity.name,
                         code = $"Activity-{activity.school}-{students.id}",
-                        scope = activity.scope,
+                        scope = activity.scope, 
                         school = activity.school,
                         creatorId = activity.creatorId,
                         pk = "Activity",
                         type = type,
-                        subjects = type.Equals("Exam") ? activity.subjects : new List<string>() { "" },
+                        subjects = type.Equals("exam") ? activity.subjects : new List<string>() { "" },
                         startTime = activity.startTime,
                         endTime = activity.endTime,
+                        blob=activity.blob,
                         owner= activity.owner
                     };
                     await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));
@@ -65,7 +66,10 @@ namespace TEAMModelFunction
                         creatorId = activity.creatorId,
                         pk = "Activity",
                         type = type,
-                        subjects = type.ToLower().Equals("Exam") ? activity.subjects : new List<string>() { "" },
+                        subjects = type.ToLower().Equals("exam") ? activity.subjects : new List<string>() { "" },
+                        startTime = activity.startTime,
+                        endTime = activity.endTime,
+                        blob = activity.blob,
                         owner = activity.owner
                     };
                     await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(stucourse, new PartitionKey(stucourse.code));

+ 0 - 108
TEAMModelOS.SDK/Models/Cosmos/Common/Inner/SyllabusNode.cs

@@ -1,108 +0,0 @@
-
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using TEAMModelOS.SDK.Context.Attributes.Azure;
-using TEAMModelOS.SDK.DI;
-
-namespace TEAMModelOS.SDK.Models
-{
-
-    public class SyllabusNode
-    {
-
-        public SyllabusNode() {
-            //resources = new List<string>();
-            //knowledges = new List<string>();
-        }
-      
-        [Required(ErrorMessage = "{0} 必须填写")]
-
-        public string id { get; set; }
-        /// <summary>
-        /// 节点名称
-        /// </summary>
-        [Required(ErrorMessage = "{0} 必须填写")]
-
-        public string title { get; set; }
-        /// <summary>
-        /// 是否展开
-        /// </summary>
-        public bool expand { get; set; }
-        /// <summary>
-        /// 是否编辑
-        /// </summary>
-        public bool editable { get; set; } = true;
-        /// <summary>
-        /// 版本
-        /// </summary>
-        public string version { get; set; }
-        /// <summary>
-        /// 排序
-        /// </summary>
-        [Required(ErrorMessage = "{0} 必须填写")]
-
-        public int order { get; set; }
-        /// <summary>
-        /// 类型  0分支节点 1资源节点
-        /// </summary>
-        [Required(ErrorMessage = "{0} 必须填写")]
-
-        public int type { get; set; }
-
-        /// <summary>
-        /// 节点Key
-        /// </summary>
-        [Required(ErrorMessage = "{0} 必须填写")]
-
-        public string nodeKey { get; set; }
-
-        /// <summary>
-        /// 父级
-        /// </summary>
-        [Required(ErrorMessage = "{0} 必须填写")]
-
-        public string pid { get; set; }
-
-        /// <summary>
-        /// 册别编码
-        /// </summary>
-        [Required(ErrorMessage = "{0} 必须填写")]
-
-        public string code { get; set; }
-        /// <summary>
-        /// 数据状态
-        /// </summary>
-        [Required(ErrorMessage = "{0} 必须填写")]
-
-        public int status { get; set; } = 1;
-
-        // public List<CodeValue> resources { get; set; }
-        /// <summary>
-        /// 关联知识点
-        /// </summary>
-        ///public List<string> points { get; set; } = new List<string>();
-
-        public List<SyllabusContent> items { get; set; }
-
-
-        //public bool resource { get; set; }
-        //[ProtoMember(15)]
-        //public bool knowledge { get; set; }
-        //public bool item { get; set; }
-
-    }
-
-    /// <summary>
-    /// 课纲内容结构
-    /// </summary>
-    public class SyllabusContent{
-        public string id { get; set; }
-        public string name { get; set; }
-        public string code { get; set; }
-        public string link { get; set; }
-        /// <summary>
-        /// 试题 ,试卷,内容资源,外部链接(只有link,和name),
-        /// </summary>
-        public string type { get; set; }
-    }
-}

+ 9 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/Inner/SyllabusTree.cs

@@ -1,12 +1,20 @@
 using System.Collections.Generic;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 
 namespace TEAMModelOS.SDK.Models
 {
-    public class SyllabusTree :SyllabusNode
+    public class SyllabusTree : Tnode
     {
         public SyllabusTree() {
             children = new List<SyllabusTree>();
         }
         public List<SyllabusTree> children { get; set; }
     }
+    public class SyllabusTreeNode: CosmosEntity{
+        public SyllabusTreeNode() {
+            trees = new List<SyllabusTree>();
+        }
+        public List<SyllabusTree> trees { get; set; }
+    }
+
 }

+ 3 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/Syllabus.cs

@@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
 using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 
 namespace TEAMModelOS.SDK.Models
 {
@@ -20,6 +21,7 @@ namespace TEAMModelOS.SDK.Models
       //  [PartitionKey]
       //  public string volumeCode { get; set; }
 
-        public List<SyllabusNode> children { get; set; }
+        public List<Tnode> children { get; set; }
+
     }
 }

+ 90 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/Volume.cs

@@ -0,0 +1,90 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Models.Cosmos.Common
+{
+    public class Volume: CosmosEntity
+    { 
+        /// <summary>
+        /// 0默认教学课纲的册别 1个人或单独的专题课纲册别 2,系统课纲
+        /// </summary>
+       // public int type { get; set; }
+        /// <summary>
+        /// 学段
+        /// </summary>
+
+        public string periodId { get; set; }
+
+
+        /// <summary>
+        /// 学科
+        /// </summary>
+
+        public string subjectId { get; set; }
+
+
+        /// <summary>
+        /// 年级
+        /// </summary>
+
+        public string gradeId { get; set; }
+
+
+        /// <summary>
+        /// 学期code
+        /// </summary>
+
+        public string semesterId { get; set; }
+
+
+        /// <summary>
+        /// 状态
+        /// </summary>
+
+        public int status { get; set; } = 1;
+
+
+        /// <summary>
+        /// 册别name
+        /// </summary>
+        [Required(ErrorMessage = "{0} 必须填写")]
+        public string name { get; set; }
+
+
+        /// <summary>
+        /// 册别code
+        /// </summary>
+      //  public string volumeCode { get; set; }
+
+        /// <summary>
+        /// 创建者醍摩豆id
+        /// </summary>
+       
+        public string creatorId { get; set; }
+
+        /// <summary>
+        /// 共编使用者 的醍摩豆id
+        /// </summary>
+        public List<string> editors { get; set; }
+
+        //public int resourceCount { get; set; }
+        //public int itemCount { get; set; }
+        /// <summary>
+        /// 发布层级 类型 school  teacher
+        /// </summary>
+        public string owner { get; set; }
+        /// <summary>
+        /// 学校编码或教师tmdid
+        /// </summary>
+        [Required(ErrorMessage = "school 必须设置")]
+        public string school { get; set; }
+        public bool repeat { get; set; }
+        /// <summary>
+        /// school|private
+        /// </summary>
+        [Required(ErrorMessage = "scope 必须设置")]
+        public string scope { get; set; }
+    }
+}

+ 1 - 0
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -65,6 +65,7 @@ namespace TEAMModelOS.Controllers
                 var client = _azureCosmos.GetCosmosClient();
                 ExamInfo exam;
                 string code = request.code;
+                request.ttl = -1;
                 request.code = "Exam-" + request.code;
                 long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                 request.createTime = now;

+ 2 - 1
TEAMModelOS/Controllers/Common/SurveyController.cs

@@ -75,6 +75,7 @@ namespace TEAMModelOS.Controllers
                 request.code = request.pk + "-" + request.code;
                 long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                 request.createTime = now;
+                request.ttl = -1;
                 //如果设置的时间是小于当前时间则立即发布
                 if (request.startTime <= 0)
                 {
@@ -309,7 +310,7 @@ namespace TEAMModelOS.Controllers
                     survey = await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(survey, new PartitionKey($"{survey.code}"));
                     _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Record:{survey.id}");
                     _azureRedis.GetRedisClient(8).KeyDelete($"Survey:Submit:{survey.id}");
-                    await _dingDing.SendBotMsg($"问卷调查【{survey.name}-{survey.id}】被删除", GroupNames.成都开发測試群組);
+                    await _dingDing.SendBotMsg($"{_option.Location}-问卷调查【{survey.name}-{survey.id}】被删除", GroupNames.成都开发測試群組);
                     return Ok(new { flag });
                 }
                 else

+ 3 - 2
TEAMModelOS/Controllers/Common/VoteController.cs

@@ -71,6 +71,7 @@ namespace TEAMModelOS.Controllers.Learn
                 //新增Vote
                 var client = _azureCosmos.GetCosmosClient();
                 request.code = request.pk + "-" + request.code;
+                request.ttl = -1;
                 long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                 request.createTime = now;
                 //如果设置的时间是小于当前时间则立即发布
@@ -305,10 +306,10 @@ namespace TEAMModelOS.Controllers.Learn
                     vote.ttl = 1;
                     vote.status = 404;
                     vote = await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(vote,  new PartitionKey($"{vote.code}"));
-                    await _dingDing.SendBotMsg($"投票活动【{vote.name}-{vote.id}-ttl={vote.ttl}】正在操作", GroupNames.成都开发測試群組);
+                    await _dingDing.SendBotMsg($"{_option.Location}-投票活动【{vote.name}-{vote.id}-ttl={vote.ttl}】正在操作", GroupNames.成都开发測試群組);
                     _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Record:{vote.id}");
                     _azureRedis.GetRedisClient(8).KeyDelete($"Vote:Count:{vote.id}");
-                    await _dingDing.SendBotMsg($"投票活动【{vote.name}-{vote.id}】被删除", GroupNames.成都开发測試群組);
+                    await _dingDing.SendBotMsg($"{_option.Location}-投票活动【{vote.name}-{vote.id}】被删除", GroupNames.成都开发測試群組);
                     return Ok(new { flag });
                 }
                 else {

+ 86 - 3
TEAMModelOS/Controllers/Syllabus/SyllabusController.cs

@@ -13,6 +13,7 @@ using System.Text.Json;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using Microsoft.AspNetCore.Http;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 
 namespace TEAMModelOS.Controllers
 {
@@ -44,7 +45,6 @@ namespace TEAMModelOS.Controllers
         [HttpPost("upsert-tree")]
         public async Task<IActionResult> SaveOrUpdateAsTree(List<SyllabusTree> request)
         {
-            ////ResponseBuilder builder = ResponseBuilder.custom();
             //List<SyllabusTree> treess = await SaveOrUpdateToTree(request);
             ////return builder.Data(treess).build();
             return Ok();
@@ -59,7 +59,7 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [HttpPost("upsert-nodes")]
-        public async Task<IActionResult> SaveOrUpdateAsNodes(List<SyllabusNode> request)
+        public async Task<IActionResult> SaveOrUpdateAsNodes(List<Tnode> request)
         {
             return Ok();
             //List<Syllabus> syllabuses = await SaveOrUpdateToNodes(request);
@@ -131,5 +131,88 @@ namespace TEAMModelOS.Controllers
             ////return builder.Data(treess).build();
             //return Ok(treess);
         }
+
+        private async Task<List<SyllabusTree>> SaveOrUpdateToTree(List<SyllabusTree> request)
+        {
+            List<Tnode> nodes = new List<Tnode>();
+            Syllabus syllabus = new Syllabus();
+
+            TreeToList(request, nodes);
+            // List<SyllabusNode> nods = nodes.ToJson().FromJson<List<SyllabusNode>>() ;
+            syllabus.children = nodes;
+            syllabus.id = request[0].code;
+            syllabus.code = request[0].code;
+            await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").UpsertItemAsync<Syllabus>(syllabus,new Azure.Cosmos.PartitionKey(syllabus.code));
+            List<SyllabusTree> treess = ListToTree(nodes);
+            return treess;
+        }
+
+        private async Task<List<Tnode>> FindByPid(Tnode data, List<Tnode> nodes, List<Tnode> nodedata)
+        {
+            foreach (Tnode syllabus in nodedata)
+            {
+                if (syllabus.pid == data.id)
+                {
+                    nodes.Add(syllabus);
+                    await FindByPid(syllabus, nodes, nodedata);
+                }
+            }
+            return nodes;
+        }
+          
+
+        private List<Tnode> TreeToList(List<SyllabusTree> trees, List<Tnode> nodes)
+        {
+            int index = 0;
+            foreach (SyllabusTree tr in trees)
+            {
+                tr.order = index;
+                index++;
+            }
+            trees = trees.OrderBy(x => x.order).ToList();
+            nodes.AddRange(trees.ToJsonString().ToObject<List<Tnode>>());
+
+            foreach (SyllabusTree tree in trees)
+            {
+                if (null != tree.children && tree.children.Count > 0)
+                {
+                    TreeToList(tree.children, nodes);
+                }
+            }
+            return nodes;
+        }
+        private List<SyllabusTree> ListToTree(List<Tnode> noes)
+        {
+            List<SyllabusTree> list = noes.ToJsonString().ToObject<List<SyllabusTree>>();
+            //var lookup = list.ToDictionary(n => n.RowKey, n => n);
+
+            var res = from r in list group r by r.id into g select g;
+            Dictionary<string, SyllabusTree> blockDict = new Dictionary<string, SyllabusTree>();
+            foreach (var s in res)
+            {
+                blockDict.TryAdd(s.First().id, s.First());
+            }
+            return GetChild(list, blockDict);
+        }
+
+        private List<SyllabusTree> GetChild(List<SyllabusTree> list, Dictionary<string, SyllabusTree> dict)
+        {
+            //  list = list.OrderBy(m => m.Order).ToList();
+            List<SyllabusTree> trees = new List<SyllabusTree>();
+            trees = trees.OrderBy(x => x.order).ToList();
+            foreach (SyllabusTree node in list)
+            {
+                bool flag = dict.TryGetValue(node.pid, out SyllabusTree syllabus);
+                if (flag && syllabus != null)
+                {
+                    syllabus.children.Add(node);
+                }
+                else
+                {
+                    trees.Add(node);
+                }
+            }
+            return trees;
+        }
     }
-}
+}

+ 134 - 0
TEAMModelOS/Controllers/Syllabus/VolumeController.cs

@@ -0,0 +1,134 @@
+using Azure;
+using Azure.Cosmos;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Options;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.Json;
+using System.Threading.Tasks;
+using TEAMModelOS.Models;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
+
+namespace TEAMModelOS.Controllers
+{
+    [ProducesResponseType(StatusCodes.Status200OK)]
+    [ProducesResponseType(StatusCodes.Status400BadRequest)]
+    //[Authorize(Roles = "IES5")]
+    [Route("common/volume")]
+    [ApiController]
+    public class VolumeController : ControllerBase
+    {
+        private readonly AzureCosmosFactory _azureCosmos;
+        private readonly SnowflakeId _snowflakeId;
+        private readonly DingDing _dingDing;
+        private readonly Option _option;
+
+        public VolumeController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option)
+        {
+            _azureCosmos = azureCosmos;
+            _snowflakeId = snowflakeId;
+            _dingDing = dingDing;
+            _option = option?.Value; ;
+        }
+
+        /// <summary>
+        /// 新增册别
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "Teacher")]
+        [HttpPost("upsert")]
+        public async Task<IActionResult> Upsert(Volume request) {
+
+            var client = _azureCosmos.GetCosmosClient();
+            if (request.editors != null && request.editors.Count > 5)
+            {
+                return BadRequest("共编人数大于5人!");
+                // throw new BizException("共编人数大于5人!");
+            }
+            request.pk = "Volume";
+            request.ttl = -1;
+            request.code = "Volume-" + request.code;
+            // 检查册别条件相同的是否存在
+            
+            string code = "Volume-";
+            if (request.scope.Equals("private"))
+            {
+                code = $"Volume-{request.creatorId}";
+            }
+            else if (request.scope.Equals("school"))
+            {
+                code = $"Volume-{request.school}";
+            }
+           
+            request.code = code;
+            ///表示更新
+            if (!string.IsNullOrEmpty(request.id))
+            {
+                try {
+                    await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Volume>(request,request.id, new Azure.Cosmos.PartitionKey(request.code));
+                }
+                catch (Exception  ex) {
+                    return BadRequest(new { error = ResponseCode.FAILED });
+                }
+
+            }
+            //表示新增,则需要检查是否重复
+            else {
+                try
+                {
+                    StringBuilder sql = new StringBuilder("select value(c) from c where c.status = 1 ");
+                    //私人课纲 只检查是否重名
+                    if (request.scope.Equals("private"))
+                    {
+                        sql.Append($" and c.name = '{request.name}' ");
+                        AsyncPageable<Volume> volumes = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher")
+                        .GetItemQueryIterator<Volume>(queryText: sql.ToString(), requestOptions: new Azure.Cosmos.QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey() });
+                        if (volumes != null)
+                        {
+                            return BadRequest(new { error = ResponseCode.DATA_EXIST });
+                        }
+                    }
+                    //学校课纲检查 学段 科目 年级 学期
+                    else if (request.scope.Equals("school")
+                        && !string.IsNullOrEmpty(request.periodId)
+                        && !string.IsNullOrEmpty(request.subjectId)
+                        && !string.IsNullOrEmpty(request.gradeId)
+                        && !string.IsNullOrEmpty(request.semesterId))
+                    {
+                        sql.Append($" and c.periodId = '{request.periodId}' and  c.subjectId = '{request.subjectId}'" +
+                            $" and c.gradeId = '{request.gradeId}' and c.semesterId = '{request.semesterId}' and c.name = '{request.name}' ");
+                        AsyncPageable<Volume> volumes = _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
+                        .GetItemQueryIterator<Volume>(queryText: sql.ToString(), requestOptions: new Azure.Cosmos.QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey() });
+                        if (volumes != null)
+                        {
+                            return BadRequest(new { error = ResponseCode.DATA_EXIST });
+                        }
+                    }
+                    else {
+                        return BadRequest(new { error = ResponseCode.PARAMS_ERROR });
+                    }
+                    
+                    request.id = System.Guid.NewGuid().ToString();
+                    if (request.scope.Equals("private"))
+                    {
+                        await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(request, new PartitionKey(request.code));
+                    }
+                    else {
+                        await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync(request, new PartitionKey(request.code));
+                    }
+                }
+                catch (Exception ex)
+                {
+                    await _dingDing.SendBotMsg($"OS,{_option.Location},VolumeController:Upsert\n{ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
+                }
+            }
+            return Ok(request);
+        }
+    }
+}

+ 0 - 326
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -112,331 +112,5 @@ namespace TEAMModelOS.Controllers.XTest
                 return BadRequest(e.StackTrace);
             }
         }
-
-
-
-        [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "teacher")]
-        [HttpPost("fix-stu-course")]
-        public async Task<IActionResult> fixStuCourse(JsonElement request) {
-
-            string originCode = request.GetProperty("originCode").GetString();
-            List<Course> courses = new List<Course>();
-            var client = _azureCosmos.GetCosmosClient();
-            var query = $"select  *  from c ";
-            await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryIterator<Course>(queryText: query,
-                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{originCode}") }))
-            {
-                courses.Add(item);
-            }
-            await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Course>(queryText: query,
-                    requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Course-{originCode}") }))
-            {
-                courses.Add(item);
-            }
-            //2.获取课程的id 并尝试添加或移除对应的学生课程记录StuCourse。
-            foreach (var course in courses)
-            {
-                if (course.schedule.IsNotEmpty())
-                {
-                    foreach (var sc in course.schedule)
-                    {
-                        if (!string.IsNullOrEmpty(sc.stulist))
-                        {
-                            (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, new List<string>() { sc.stulist }, course.school);
-                            foreach (var addStu in studentss)
-                            {
-                                var stuCourse = new StuCourse
-                                {
-                                    id = course.id,
-                                    scode = course.code,
-                                    name = course.name,
-                                    code = $"StuCourse-{course.school}-{addStu.id}",
-                                    scope = course.scope,
-                                    school = course.school,
-                                    creatorId = course.creatorId,
-                                    pk = "StuCourse"
-                                };
-                                await client.GetContainer("TEAMModelOS", "Student").UpsertItemAsync(stuCourse, new PartitionKey(stuCourse.code));
-                            }
-                            foreach (var addTmd in tmdids)
-                            {
-                                var tmdCourse = new StuCourse
-                                {
-                                    id = course.id,
-                                    scode = course.code,
-                                    name = course.name,
-                                    code = $"StuCourse-{addTmd}",
-                                    scope = course.scope,
-                                    //school = courseChange.school,
-                                    creatorId = course.creatorId,
-                                    pk = "StuCourse"
-                                };
-                                await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync(tmdCourse, new PartitionKey(tmdCourse.code));
-                            }
-                        }
-                    }
-                }
-            }
-            return new OkObjectResult(new { });
-        }
-
-
-
-        [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "teacher")]
-        [HttpPost("fix-exam-activity")]
-        public async Task<IActionResult> ExamActivity(JsonElement request)
-        {
-            
-           var datas = request.ToObject<List<string>>();
-            var client = _azureCosmos.GetCosmosClient();
-
-            var query = $"select  *  from c ";
-            foreach (string data in datas)
-            {
-                List<ExamInfo> exams = new List<ExamInfo>();
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(
-                    queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{data}") }))
-                {
-                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                    {
-                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
-                        {
-                            exams.Add(obj.ToObject<ExamInfo>());
-                        }
-                    }
-                }
-                foreach (var info in exams)
-                {
-                    if (!info.classes.IsNotEmpty())
-                    {
-                        continue;
-                    }
-                    List<string> sub = new List<string>();
-                    foreach (ExamSubject subject in info.subjects)
-                    {
-                        sub.Add(subject.id);
-                    }
-                    (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
-                    List<StuActivity> stuActivities = new List<StuActivity>();
-                    List<StuActivity> tmdActivities = new List<StuActivity>();
-                    if (tmdids.IsNotEmpty())
-                    {
-                        tmdids.ForEach(x => {
-                            tmdActivities.Add(new StuActivity
-                            {
-                                pk = "Activity",
-                                id = info.id,
-                                code = $"Activity-{x}",
-                                type = "exam",
-                                name = info.name,
-                                startTime = info.startTime,
-                                endTime = info.endTime,
-                                scode = info.code,
-                                scope = info.scope,
-                                school = info.school,
-                                creatorId = info.creatorId,
-                                subjects = sub,
-                                blob = null,
-                                owner = info.owner
-
-                            });
-                        });
-                    }
-                    if (studentss.IsNotEmpty())
-                    {
-                        studentss.ForEach(x => {
-                            stuActivities.Add(new StuActivity
-                            {
-                                pk = "Activity",
-                                id = info.id,
-                                code = $"Activity-{info.school}-{x.id}",
-                                type = "exam",
-                                name = info.name,
-                                startTime = info.startTime,
-                                endTime = info.endTime,
-                                scode = info.code,
-                                scope = info.scope,
-                                school = info.school,
-                                creatorId = info.creatorId,
-                                subjects = sub,
-                                blob = null,
-                                owner = info.owner
-                            });
-                        });
-                    }
-                    await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
-                }
-            }
-            return new OkObjectResult(new { });
-        }
-
-
-        [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "teacher")]
-        [HttpPost("fix-vote-activity")]
-        public async Task<IActionResult> VoteActivity(JsonElement request)
-        {
-
-            var datas = request.ToObject<List<string>>();
-            var client = _azureCosmos.GetCosmosClient();
-
-            var query = $"select  *  from c ";
-            foreach (string data in datas)
-            {
-                List<Vote> votes = new List<Vote>();
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(
-                    queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Vote-{data}") }))
-                {
-                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                    {
-                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
-                        {
-                            votes.Add(obj.ToObject<Vote>());
-                        }
-                    }
-                }
-                foreach (var info in votes)
-                {
-                    if (!info.classes.IsNotEmpty())
-                    {
-                        continue;
-                    }
-
-                    (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
-                    List<StuActivity> stuActivities = new List<StuActivity>();
-                    List<StuActivity> tmdActivities = new List<StuActivity>();
-                    if (tmdids.IsNotEmpty())
-                    {
-                        tmdids.ForEach(x => {
-                            tmdActivities.Add(new StuActivity
-                            {
-                                pk = "Activity",
-                                id = info.id,
-                                code = $"Activity-{x}",
-                                type = "vote",
-                                name = info.name,
-                                startTime = info.startTime,
-                                endTime = info.endTime,
-                                scode = info.code,
-                                scope = info.scope,
-                                school = info.school,
-                                creatorId = info.creatorId,
-                                subjects = new List<string>() { "" },
-                                blob = null,
-                                owner = info.owner
-
-                            });
-                        });
-                    }
-                    if (studentss.IsNotEmpty())
-                    {
-                        studentss.ForEach(x => {
-                            stuActivities.Add(new StuActivity
-                            {
-                                pk = "Activity",
-                                id = info.id,
-                                code = $"Activity-{info.school}-{x.id}",
-                                type = "vote",
-                                name = info.name,
-                                startTime = info.startTime,
-                                endTime = info.endTime,
-                                scode = info.code,
-                                scope = info.scope,
-                                school = info.school,
-                                creatorId = info.creatorId,
-                                subjects = new List<string>() { "" },
-                                blob = null,
-                                owner = info.owner
-                            });
-                        });
-                    }
-                    await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
-                }
-            }
-            return new OkObjectResult(new { });
-        }
-        [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "teacher")]
-        [HttpPost("fix-survey-activity")]
-        public async Task<IActionResult> SurveyActivity(JsonElement request)
-        {
-            var datas = request.ToObject<List<string>>();
-            var client = _azureCosmos.GetCosmosClient();
-            var query = $"select  *  from c ";
-            foreach (string data in datas)
-            {
-                List<Survey> surveys = new List<Survey>();
-                await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(
-                    queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Survey-{data}") }))
-                {
-                    using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                    {
-                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
-                        {
-                            surveys.Add(obj.ToObject<Survey>());
-                        }
-                    }
-                }
-                foreach (var info in surveys)
-                {
-                    if (!info.classes.IsNotEmpty())
-                    {
-                        continue;
-                    }
-                    (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
-                    List<StuActivity> stuActivities = new List<StuActivity>();
-                    List<StuActivity> tmdActivities = new List<StuActivity>();
-                    if (tmdids.IsNotEmpty())
-                    {
-                        tmdids.ForEach(x => {
-                            tmdActivities.Add(new StuActivity
-                            {
-                                pk = "Activity",
-                                id = info.id,
-                                code = $"Activity-{x}",
-                                type = "survey",
-                                name = info.name,
-                                startTime = info.startTime,
-                                endTime = info.endTime,
-                                scode = info.code,
-                                scope = info.scope,
-                                school = info.school,
-                                creatorId = info.creatorId,
-                                subjects = new List<string>() { "" },
-                                blob = info.blob
-                            });
-                        });
-                    }
-                    if (studentss.IsNotEmpty())
-                    {
-                        studentss.ForEach(x => {
-                            stuActivities.Add(new StuActivity
-                            {
-                                pk = "Activity",
-                                id = info.id,
-                                code = $"Activity-{info.school}-{x.id}",
-                                type = "survey",
-                                name = info.name,
-                                startTime = info.startTime,
-                                endTime = info.endTime,
-                                scode = info.code,
-                                scope = info.scope,
-                                school = info.school,
-                                creatorId = info.creatorId,
-                                subjects = new List<string>() { "" },
-                                blob = info.blob
-                            });
-                        });
-                    }
-                    await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
-                }
-            }
-            return new OkObjectResult(new { });
-        }
     }
 }