瀏覽代碼

調整代碼

JAELYS 4 年之前
父節點
當前提交
b540826639

+ 2 - 12
TEAMModelOS.SDK/Models/Cosmos/Common/Knowledge.cs

@@ -17,23 +17,13 @@ namespace TEAMModelOS.SDK.Models
     {
         public Knowledge()
         {
+            pk = "Knowledge";
             points = new List<string>();
         }
-        /// <summary>
-        /// 学校编码 如果是教师个人知识点为醍摩豆id 否则为学校编码 
-        /// </summary>
-        [PartitionKey]
-        [Required(ErrorMessage = "{0} 必须填写")]
-        public string code { get; set; }
-        // [PartitionKey(name = "Knowledge")]
-        public string pk { get; set; }
-        public int? ttl { get; set; }
         
-        public string id { get; set; }
         /// <summary>
         /// 标记为知识块,0=知识块 ,1 知识点
-        /// </summary>
-        
+        /// </summary>        
         [Required(ErrorMessage = "{0} 必须填写")]
         public int type { get; set; } = 0;
         /// <summary>

+ 19 - 32
TEAMModelOS.SDK/Models/Cosmos/Common/Volume.cs

@@ -1,4 +1,4 @@
- using System;
+using System;
 using System.Collections.Generic;
 using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
@@ -10,83 +10,70 @@ using TEAMModelOS.SDK.DI;
 
 namespace TEAMModelOS.SDK.Models
 {
-    [CosmosDB(Database = "TEAMModelOS", Name = "Common", Monitor =true)]
-    
-    public class Volume :CosmosEntity
+    [CosmosDB(Database = "TEAMModelOS", Name = "Common", Monitor = true)]
+
+    public class Volume : CosmosEntity
     {
-        [PartitionKey]
-        [Required(ErrorMessage = "{0} 必须填写")]
-        public string code { get; set; }
-        // [PartitionKey(name = "SyllabusVolume")]
-        public string pk { get; set; }
-        public int? ttl { get; set; } 
-        /// <summary>
-        /// id生成规则
-        /// </summary>
-        
-        public string id { get; set; }
         /// <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 volumeName { get; set; }
-        
+
 
         /// <summary>
         /// 册别code
         /// </summary>
         public string volumeCode { get; set; }
-        
+
 
         /// <summary>
         /// 创建者醍摩豆id
         /// </summary>
-        [JsonPropertyName("TEAMModelId")]
-        [JsonProperty("TEAMModelId")]
         public string TEAMModelId { get; set; }
-        
+
         /// <summary>
         /// 共编使用者 的醍摩豆id
         /// </summary>

+ 1 - 8
TEAMModelOS.SDK/Models/Cosmos/School/CourseManagement.cs

@@ -18,14 +18,7 @@ namespace TEAMModelOS.SDK.Models
             courses = new List<CourseSimple>();
             teacher = new Teachers();
         }
-        /// <summary>
-        /// 班级id
-        /// </summary>
-        public string id { get; set; }
-        public int? ttl { get; set; }
-        public string pk { get; set; }
-        [PartitionKey]
-        public string code { get; set; }
+        
         public string name { get; set; }
         public List<CourseSimple> courses { get; set; }
         public Teachers teacher { get; set; }

+ 2 - 6
TEAMModelOS.SDK/Models/Cosmos/School/ExamAnswer.cs

@@ -21,11 +21,7 @@ namespace TEAMModelOS.SDK.Models
         {
             answer = new List<List<string>>();
         }
-        [JsonProperty(PropertyName = "id")]
-        public string id { get; set; } 
-        public List<List<string>> answer { get; set; }
-        [PartitionKey]
-        [Required(ErrorMessage = "{0} 必须填写")]
-        public string code { get; set; }
+       
+        public List<List<string>> answer { get; set; }       
     }
 }

+ 1 - 3
TEAMModelOS.SDK/Models/Cosmos/School/ExamInfo.cs

@@ -21,9 +21,7 @@ namespace TEAMModelOS.SDK.Models
             subjects = new List<ExamSubject>();
             papers = new List<PaperSimple>();
             targetClassIds = new List<string>();
-        }
-        [JsonProperty(PropertyName = "id")]
-        public string id { get; set; }
+        }      
 
         public string name { get; set; }
         public string school { get; set; }

+ 0 - 253
TEAMModelOS/Controllers/School/ClassStudentController.cs

@@ -1,253 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
-using TEAMModelOS.SDK.Context.Exception;
-using TEAMModelOS.SDK;
-using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
-using TEAMModelOS.SDK.Helper.Common.ValidateHelper;
-using TEAMModelOS.SDK.DI;
-using TEAMModelOS.Models;
-using System.Text.Json;
-using TEAMModelOS.SDK.Models;
-using Azure.Cosmos;
-using TEAMModelOS.SDK.Extension;
-
-namespace TEAMModelOS.Controllers
-{
-    [ProducesResponseType(StatusCodes.Status200OK)]
-    [ProducesResponseType(StatusCodes.Status400BadRequest)]
-    //[Authorize(Roles = "IES5")]
-    [Route("student/class")]
-    [ApiController]
-    public class ClassStudentController : ControllerBase
-    {
-
-        private AzureCosmosFactory _azureCosmos;
-
-        public ClassStudentController(AzureCosmosFactory azureCosmos)
-        {
-            _azureCosmos = azureCosmos;
-        }
-
-        /// <summary>
-        ///  获取实时的学生-班级关联信息
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "Teacher")]
-        [HttpPost("find")]
-        public async Task<IActionResult> find(JsonElement request) {
-            //ResponseBuilder builder = ResponseBuilder.custom();
-            // 班级编码
-            /*            if (request.TryGetProperty("classroomCode", out JsonElement classroomCode)
-                             && request.TryGetProperty("schoolCode", out JsonElement schoolCode)
-                            )
-                        {*/
-            if (!request.TryGetProperty("classroomCode", out JsonElement classroomCode)) return BadRequest();
-            if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
-                //List<ClassStudent> classroomStudents = await _azureCosmos.FindByDict<ClassStudent>(new Dictionary<string, object> { { "id", classroomCode } });
-                var client = _azureCosmos.GetCosmosClient();
-                List<object> classrooms = new List<object>();
-                string info = "";
-                for (int i = 0; i < classroomCode.GetArrayLength(); i++)
-                {
-                    //ids.Add(id[i].ToJsonString());
-                    info += classroomCode[i].ToJsonString() + ",";
-                }
-            var query = $"select c.name, c.students from c where c.id in ({info[0..^1]}) ";
-                await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Classroom-{school_code}") }))
-                {
-                    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())
-                        {
-                            classrooms.Add(obj.ToObject<object>());
-                        }
-                    }
-                }
-            //List<StudentSimple> students = new List<StudentSimple>();
-           /* classrooms.ForEach(c =>
-            {
-
-                c.students.ForEach(s =>
-                {
-                    StudentSimple student = new StudentSimple
-                    {
-                        id = s.id,
-                        name = s.name,
-                        no = s.no
-                    };
-                    students.Add(student);
-                });
-                //students = c.students;
-            });*/
-        
-
-            return Ok(new { classrooms });
-            /*List<Student> students = await _azureCosmos.FindByDict<Student>(
-                new Dictionary<string, object>() { { "classroomCode", classroomCode }, { "code", schoolCode } },
-                new List<string> { "id", "name", "code", "seatNo", "studentId", "classroomCode" });
-            List<dynamic> stus = new List<dynamic>();
-            List<ClassStudent> newClassStudents = new List<ClassStudent>();
-            ///新增的学生
-            if (students.IsNotEmpty())
-            {
-                students.ForEach(x =>
-                {
-                    if (!classroomStudents.Select(m => m.code).Contains(x.studentId))
-                    {
-                        newClassStudents.Add(new ClassStudent() { id = x.classroomCode, code = x.studentId });
-                    }
-                    var stu = new { x.id, x.name, x.code, x.seatNo, x.studentId, x.classroomCode };
-                    stus.Add(stu);
-                });
-            }
-            ///反射已存在的id信息
-            if (classroomStudents.IsNotEmpty())
-            {
-                ///处理冗余的id查询
-                List<string> ids = new List<string>();
-                if (students.IsNotEmpty()) {
-                    classroomStudents.ForEach(x =>
-                    {
-                        if (!students.Select(m => m.studentId).Contains(x.code))
-                        {
-                            ids.Add(x.code);
-                        }
-                    });
-                }
-
-                var sts = await _azureCosmos.FindByDict<Student>(new Dictionary<string, object>() { { "studentId", ids.ToArray() } });
-                if (sts.IsNotEmpty())
-                {
-                    sts.ForEach(x =>
-                    {
-                        var stu = new { x.id, x.name, x.code, x.seatNo, x.studentId, x.classroomCode };
-                        stus.Add(stu);
-                    });
-                }
-
-            }
-            //保存新增学生
-            if (newClassStudents.IsNotEmpty())
-            {
-                classroomStudents.AddRange(await _azureCosmos.SaveOrUpdateAll(newClassStudents));
-            }
-            return builder.Data(classroomStudents).Extend(new Dictionary<string, object> { { "students", stus }, { "count", stus.Count } }).build();
-        }
-        else
-        {
-            return builder.Error(ResponseCode.PARAMS_ERROR, "参数异常classroomCode,code!").build();
-        }*/
-
-        }
-
-        /// <summary>
-        /// 保存或修改教室学生关联
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "Teacher")]
-        [HttpPost("upsert")]
-        public async Task<BaseResponse> Upsert(List<ClassStudent> request)
-        {
-            ResponseBuilder builder = ResponseBuilder.custom();
-            List<ClassStudent> students = await _azureCosmos.SaveOrUpdateAll(request);
-            builder.Data(students);
-            return builder.build();
-        }
-
-
-        ///// <summary>
-        ///// 学生加入教室 
-        ///// </summary>
-        ///// <param name="request"></param>
-        ///// <returns></returns>
-        //[HttpPost("addStudent")]
-        //public async Task<BaseResponse> addStudent(JosnRPCRequest<List<ClassStudent>> request)
-        //{
-        //    JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
-
-        //    List<ClassStudent> students = await _cosmos.SaveOrUpdateAll(request.@params);
-        //    builder.Data(students);
-        //    return builder.build();
-        //}
-        /// <summary>
-        /// 学生退出教室,只能退出非原生班级的教室
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "Teacher")]
-        [HttpPost("exit")]
-        public async Task<BaseResponse> Exit(List<ClassStudent> request)
-        {
-            ResponseBuilder builder = ResponseBuilder.custom();
-            if (ValidateHelper.IsValid(request) && request.Count>0)
-            {
-                List<ClassStudent> rm = new List<ClassStudent>();
-                List<OldStudent> students = await _azureCosmos.FindByDict<OldStudent>(new Dictionary<string, object> { { "studentId", request.GroupBy(x => x.code).ToList().Select(x => x.Key).ToArray() } });
-                students.ForEach(x => {
-                    if (!string.IsNullOrEmpty(x.classroomCode)) {
-                        request.ForEach(m =>
-                        {
-                            if (x.classroomCode.Equals(m.id) && x.studentId.Equals(m.code)) {
-                                rm.Add(m);
-                            }
-                        });
-                    }
-                });
-                rm.ForEach(x=> { request.Remove(x); });
-                List<IdPk> idPks = await _azureCosmos.DeleteAll<ClassStudent>(request.Select(x=> new IdPk { id=x.id,pk=x.code}).ToList());
-                builder.Data(idPks);
-            }
-            return builder.build();
-        }
-
-        /// <summary>
-        /// 查询教室学生关联 根据id
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "Teacher")]
-        [HttpPost("find-by-id")]
-        public async Task<BaseResponse> FindById(IdPk request)
-        {
-            ResponseBuilder builder = ResponseBuilder.custom();
-            if (ValidateHelper.IsValid(request))
-            {
-                ClassStudent classStudent = await _azureCosmos.FindByIdPk<ClassStudent>(request.id,request.pk);
-                List<OldStudent> students = await _azureCosmos.FindByDict<OldStudent>(new Dictionary<string, object> { { "studentId",request.pk } }, new List<string> { "id", "name", "code", "seatNo", "studentId", "classroomCode" });
-                builder.Data(classStudent).Extend(new Dictionary<string, object> { { "student",students.IsNotEmpty()&& classStudent !=null? new { students[0].id, students[0].name, students[0].code, students[0].seatNo, students[0].studentId, students[0].classroomCode }:null } });
-            }
-            return builder.build();
-        }
-        /// <summary>
-        /// 查询学生在哪些教室
-        /// </summary>
-        /// <param name="studentId"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "Teacher")]
-        [HttpPost("find-by-stu")]
-        public async Task<BaseResponse> FindByStu(JsonElement request)
-        {
-            ResponseBuilder builder = ResponseBuilder.custom();
-            if (request.TryGetProperty("code", out JsonElement studentId))
-            {
-                List<ClassStudent> sc = await _azureCosmos.FindByDict<ClassStudent>(new Dictionary<string, object> { { "code",studentId.ToString()} });
-                List<Class> classrooms = await _azureCosmos.FindByDict<Class>(new Dictionary<string, object> { { "classroomCode", sc.GroupBy(x => x.id).Select(x => x.Key).ToArray() } });
-                builder.Data(classrooms).Extend(new Dictionary<string, object> { { "count", classrooms.Count } });
-            }
-            return builder.build();
-        }
-
-    }
-}

+ 2 - 1
TEAMModelOS/Controllers/Syllabus/VolumeController.cs

@@ -163,7 +163,8 @@ namespace TEAMModelOS.Controllers
                     request.id = key;
                     request.volumeCode = key;
                     string code = request.code;
-                    request.code = typeof(Volume).Name + "-" + request.code;
+                    //TODO 優化
+                    request.code = typeof(Volume).Name + "-" + request.code; 
                     volume = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").CreateItemAsync(request, new PartitionKey($"Volume-{code}"));
                 }
                 else if (request.type == 1)