Browse Source

update 课例

CrazyIter_Bin 3 years ago
parent
commit
d671999a76

+ 12 - 1
TEAMModelOS.SDK/Models/Cosmos/Common/LessonRecord.cs

@@ -177,7 +177,18 @@ namespace TEAMModelOS.SDK.Models
         /// 过期时间,-1永不过期, 1577808000000 2020-01-01
         /// </summary>
         public long expire { get; set; } = -1;
-
+        /// <summary>
+        /// 先使用这种模式,["all","student"], 暂不 开放 school【开放给部分学校查看】,teacher【开放给部分教师查看】   ["all","school","teacher","student"]
+        /// </summary>
+        public List<string> show { get; set; } = new List<string>();
+        /// <summary>
+        /// school【开放给部分学校查看】学校编码
+        /// </summary>
+        public List<string> showSchs { get; set; } = new List<string>();
+        /// <summary>
+        /// teacher【开放给部分教师查看】醍摩豆id 
+        /// </summary>
+        public List<string> showTchs { get; set; } = new List<string>();
     }
     public class LessonTC
     {

+ 82 - 3
TEAMModelOS/Controllers/Both/LessonRecordController.cs

@@ -64,6 +64,7 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         [HttpPost("update-lesson-baseinfo")]
+        [AuthToken(Roles = "admin,teacher")]
         public async Task<IActionResult> UpdateLessonBaseInfo(JsonElement request)
         {
             var client = _azureCosmos.GetCosmosClient();
@@ -163,6 +164,7 @@ namespace TEAMModelOS.Controllers
         // [AuthToken(Roles = "teacher,admin")]
         [HttpPost("delete-lesson-record")]
         [Authorize(Roles = "IES")]
+        [AuthToken(Roles = "admin,teacher")]
         public async Task<IActionResult> DeleteLessonRecord(JsonElement request)
         {
             string lessonId;
@@ -228,9 +230,16 @@ namespace TEAMModelOS.Controllers
         //[AuthToken(Roles = "teacher,admin")]
         [HttpPost("get-lesson-record-count")]
         [Authorize(Roles = "IES")]
+        [AuthToken(Roles = "admin,teacher,student")]
         public async Task<IActionResult> GetLessonRecordCont(JsonElement request)
         {
-           
+            object _roles = null;
+            HttpContext?.Items.TryGetValue("Roles", out _roles);
+            List<string> roles = new List<string>();
+            if (_roles != null)
+            {
+                roles = _roles.ToJsonString().ToObject<List<string>>();
+            }
             if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
             StringBuilder sql = new StringBuilder();
             sql.Append("select value(count(1)) from c   ");
@@ -269,7 +278,13 @@ namespace TEAMModelOS.Controllers
                 return BadRequest();
             }
             int count=0;
-            cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", " where (c.status<>404 or IS_DEFINED(c.status) = false ) and  ");
+
+            string sqlShow = "";
+            if (roles.Count == 1 && roles.Contains("student"))
+            {
+                sqlShow = " and array_contains(c.show,'student') ";
+            }
+            cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) {sqlShow}  and  ");
             await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<int>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
             {
                 count = item;
@@ -283,10 +298,69 @@ namespace TEAMModelOS.Controllers
         /// <returns></returns>
         [ProducesDefaultResponseType]
         // [AuthToken(Roles = "teacher,admin")]
+        [HttpPost("get-lesson-record-id")]
+        [Authorize(Roles = "IES")]
+        [AuthToken(Roles = "admin,teacher,student")]
+        public async Task<IActionResult> GetLessonRecordId(JsonElement request) {
+            if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
+            if (!request.TryGetProperty("id", out JsonElement _id)) return BadRequest();
+            string tbname = "";
+            string code = "";
+            if (_scope.GetString().Equals("school"))
+            {
+                if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
+                if (!string.IsNullOrEmpty($"{_school}"))
+                {
+                    code = $"LessonRecord-{_school}";
+                    tbname = "School";
+                }
+                else
+                {
+                    return BadRequest();
+                }
+            }
+            else if ($"{_scope}".Equals("private"))
+            {
+                if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
+                if (!string.IsNullOrEmpty($"{_tmdid}"))
+                {
+                    code = $"LessonRecord-{_tmdid}";
+                    tbname = "Teacher";
+                }
+                else
+                {
+                    return BadRequest();
+                }
+            }
+            else
+            {
+                return BadRequest();
+            }
+            try {
+                LessonRecord lessonRecord = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<LessonRecord>($"{_id}", new PartitionKey(code));
+                return Ok(new { lessonRecord });
+            } catch (CosmosException ex) when (ex.Status == 404) {
+                return Ok(new { status =404});
+            }
+        }
+        /// <summary>
+        /// 获取开课记录
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        // [AuthToken(Roles = "teacher,admin")]
         [HttpPost("get-lesson-record")]
         [Authorize(Roles = "IES")]
+        [AuthToken(Roles ="admin,teacher,student")]
         public async Task<IActionResult> GetLessonRecord(JsonElement request)
         {
+            object _roles = null;
+            HttpContext?.Items.TryGetValue("Roles", out   _roles);
+            List<string> roles = new List<string>();
+            if (_roles != null) {
+                roles = _roles.ToJsonString().ToObject<List<string>>();
+            }
             if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
             StringBuilder sql = new StringBuilder();
             sql.Append("select value(c) from c ");
@@ -354,7 +428,11 @@ namespace TEAMModelOS.Controllers
             List<LessonRecord> lessonRecords = new List<LessonRecord>();
             try
             {
-                cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", " where (c.status<>404 or IS_DEFINED(c.status) = false ) and  ");
+                string sqlShow = "";
+                if (roles.Count == 1 && roles.Contains("student") ) {
+                    sqlShow = " and array_contains(c.show,'student') ";
+                }
+                cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) {sqlShow} and  ");
                 await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
                    .GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, continuationToken: continuationToken,
                    requestOptions: new QueryRequestOptions() { MaxItemCount = pageCount, PartitionKey = new PartitionKey(code) }))
@@ -434,6 +512,7 @@ namespace TEAMModelOS.Controllers
        // [AuthToken(Roles = "teacher,admin")]
         [HttpPost("get-other-lesson-record")]
         [Authorize(Roles = "IES")]
+        [AuthToken(Roles = "admin,teacher,student")]
         public async Task<IActionResult> GetOtherLessonRecord(JsonElement request)
         {
             if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();

+ 55 - 1
TEAMModelOS/Controllers/XTest/FixDataController.cs

@@ -2164,8 +2164,62 @@ namespace TEAMModelOS.Controllers
                 .GetItemQueryIterator<string>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") })) {
                 ids.Add(item);
             }
-            return Ok();
+            List<Student> studentsData = new List<Student>();
+            foreach (var id in ids) {
+                List<Student> students = new List<Student>();
+                string sqlstu = "select value(c) from c ";
+                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student)
+                .GetItemQueryIterator<Student>(sqlstu, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{id}") }))
+                {
+                    students.Add(item);
+                }
+                var groups= students.Where(x => !string.IsNullOrWhiteSpace(x.classId)).GroupBy(y => y.classId).Select(z => new { key = z.Key,list = z.ToList() });
+                foreach (var group in groups) {
+                    foreach (var stu in group.list) {
+                        var lst = DoIrs(group.list, stu);
+                        await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReplaceItemAsync(stu, stu.id, new PartitionKey($"Base-{id}"));
+                    }
+                }
+                studentsData.AddRange(students);
+            }
+            return Ok(studentsData);
+        }
+        private List<Student> DoIrs(List<Student> students, Student student) {
+            string irs = string.Empty;
+            List<string> irsOrder = students.Select(x => x.irs)?.Where(y => !string.IsNullOrEmpty(y) && Regex.IsMatch(y, @"^\d*$")).OrderBy(x => int.Parse(x)).ToList();
+            if (!irsOrder.Contains("0"))
+            {
+                irsOrder.Insert(0, "0");
+            }
+            if (irsOrder != null)
+            {
+                if (!irsOrder.Contains("0"))
+                {
+                    irsOrder.Insert(0, "0");
+                }
+            }
+            else { irsOrder = new List<string>() { "0" }; }
+            for (int i = 0; i < irsOrder.Count; i++)
+            {
+                irs = $"{int.Parse(irsOrder[i]) + 1}";
+                int index = i + 1;
+                if (index <= irsOrder.Count - 1)
+                {
+                    if (!irs.Equals(irsOrder[index]))
+                    {
+                        break;
+                    }
+                }
+            }
+          
+            student.irs = irs;
+            student.no = irs;
+            var stu= students.Find(x => x.id.Equals(student.id));
+            stu.irs = irs; stu.no = irs;
+            return students;
         }
+
+
         public record CorrectStu
         {
             public string id { get; set; }