Browse Source

题目随机筛选一个,

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

+ 43 - 1
TEAMModelAPI/Controllers/School/CourseController.cs

@@ -68,6 +68,8 @@ namespace TEAMModelAPI.Controllers
             var period = data.period.Find(x => x.id.Equals($"{_periodId}"));
             var period = data.period.Find(x => x.id.Equals($"{_periodId}"));
             if (period != null)
             if (period != null)
             {
             {
+                //1 2 3 4 5 6 7
+                List<string> weekDays = new List<string> { "MON","TUE","WED","THU","FRI","SAT","SUN" };
                 return Ok(new { period.subjects, period.timetable, period.grades, period.majors });
                 return Ok(new { period.subjects, period.timetable, period.grades, period.majors });
             }
             }
             else
             else
@@ -169,9 +171,49 @@ namespace TEAMModelAPI.Controllers
         {
         {
             var (id, school) = HttpContext.GetApiTokenInfo();
             var (id, school) = HttpContext.GetApiTokenInfo();
             if (!json.TryGetProperty("courseId", out JsonElement _courseId)) { return Ok(new { error = 1, msg = "课程参数错误" }); }
             if (!json.TryGetProperty("courseId", out JsonElement _courseId)) { return Ok(new { error = 1, msg = "课程参数错误" }); }
+            if (!json.TryGetProperty("schedules", out JsonElement _schedules) || !_schedules.ValueKind.Equals(JsonValueKind.Array)) { return Ok(new { error = 1, msg = "排课参数错误" }); }
             School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
             School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
             Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{_courseId}", new PartitionKey($"Course-{school}"));
             Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{_courseId}", new PartitionKey($"Course-{school}"));
-            return Ok();
+            List<Schedule> schedules=   _schedules.ToObject<List<Schedule>>();
+            if (schedules.IsNotEmpty() && schedules.Valid().isVaild)
+            {
+                //检查排课时段相同的情况
+                Dictionary<string, List<Schedule>> dict = new Dictionary<string, List<Schedule>>();
+                schedules.ForEach(item => {
+                    item.time.ForEach(x => {
+                    string key = $"{item.teacherId}-{x.id}-{x.week}";
+                        if (dict.ContainsKey(key))
+                        {
+                            dict[key].Add(item);
+                        }
+                        else {
+                            dict[key] = new List<Schedule> { item };
+                        }
+                    });
+                });
+
+                //教学班
+                var stulist_schedules = schedules.Where(x => !string.IsNullOrWhiteSpace(x.stulist));
+                //行政班
+                var classId_schedules = schedules.Where(x => !string.IsNullOrWhiteSpace(x.classId));
+                //处理教室和教学班名单,教师,同时存在且相同,重复的课堂
+                var stulist_schedules_hasRoom = stulist_schedules.Where(x => !string.IsNullOrWhiteSpace(x.room));
+                //处理教学班名单,教师,同时存在且相同,重复的课堂
+                var stulist_schedules_noRoom = stulist_schedules.Where(x => !string.IsNullOrWhiteSpace(x.room));
+
+                //处理教室和行政班名单,教师,同时存在且相同,重复的课堂
+                var classId_schedules_hasRoom = stulist_schedules_hasRoom.Where(x => !string.IsNullOrWhiteSpace(x.room));
+                //处理行政班名单,教师,同时存在且相同,重复的课堂
+                var classId_schedules_noRoom = stulist_schedules_hasRoom.Where(x => !string.IsNullOrWhiteSpace(x.room));
+
+             
+                return Ok();
+            }
+            else { 
+                return Ok(new { error = 1, msg = "排课参数错误" }); 
+            
+            }
+           
         }
         }
 
 
         [ProducesDefaultResponseType]
         [ProducesDefaultResponseType]

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/School/Course.cs

@@ -73,6 +73,7 @@ namespace TEAMModelOS.SDK.Models
         /// 班级名单id
         /// 班级名单id
         /// </summary>
         /// </summary>
         public string classId { get; set; }
         public string classId { get; set; }
+        [Required(ErrorMessage = "教师id {0} 必须填写")]
         public string teacherId { get; set; }
         public string teacherId { get; set; }
         /// <summary>
         /// <summary>
         /// 自定义名单
         /// 自定义名单

+ 137 - 40
TEAMModelOS/Controllers/Both/ItemController.cs

@@ -698,6 +698,143 @@ namespace TEAMModelOS.Controllers
             //需要处理 图片中的 base64
             //需要处理 图片中的 base64
             return Ok(new { items , continuationToken });
             return Ok(new { items , continuationToken });
         }
         }
+        /// <summary>
+        /// 根据条件随机挑选一个题目
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "teacher")]
+        [HttpPost("find-random-one")]
+        [Authorize(Roles = "IES")]
+        public async Task<IActionResult> FindRandomOne(JsonElement request)
+        {
+            try
+            {
+                ItemInfo itemInfo = null;
+                var client = _azureCosmos.GetCosmosClient();
+                string sql = $"select value(c.id)    from c  joingradeIds joinknowledge where 1=1";
+                if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
+                Dictionary<string, object> dict = new Dictionary<string, object>();
+                if (request.TryGetProperty("periodId", out JsonElement periodId))
+                {
+                    sql=$"{sql} and c.periodId='{periodId}'" ;
+                }
+                if (request.TryGetProperty("subjectId", out JsonElement subjectId))
+                {
+                    sql = $"{sql}  and c.subjectId='{subjectId}'"; 
+                }
+                if (request.TryGetProperty("level", out JsonElement level))
+                {
+                    sql = $"{sql}  and c.level={level}";
+                    
+                }
+                if (request.TryGetProperty("type", out JsonElement type))
+                {
+                    sql = $"{sql}  and c.type='{type}'";
+                }
+                if (request.TryGetProperty("field", out JsonElement field))
+                {
+                    sql = $"{sql}  and c.field={field}";
+                }
+                if (request.TryGetProperty("gradeIds", out JsonElement _gradeIds) && _gradeIds.ValueKind.Equals(JsonValueKind.Array))
+                {
+                    List<string> gradeIds = _gradeIds.ToObject<List<string>>();
+                    if (gradeIds.IsNotEmpty()) {
+                        sql = $"{sql}  and g in ({string.Join(",", gradeIds.Select(x => $"'{x}'"))})";
+                        sql= sql.Replace("joingradeIds", " join g in c.gradeIds");
+                    }
+                }
+                if (request.TryGetProperty("knowledge", out JsonElement _knowledge) && _knowledge.ValueKind.Equals(JsonValueKind.Array))
+                {
+                    List<string> knowledge = _knowledge.ToObject<List<string>>();
+                    if (knowledge.IsNotEmpty())
+                    {
+                        sql = $"{sql}  and k in ({string.Join(",", knowledge.Select(x => $"'{x}'"))})";
+                        sql= sql.Replace("joinknowledge", " join k in c.knowledge");
+                    }
+                }
+                   
+                 
+                if (request.TryGetProperty("pid", out JsonElement pd))
+                {
+                    if (pd.ValueKind != JsonValueKind.Null)
+                    {
+                        sql = $"{sql}  and c.pid='{pd}'";
+                    }
+                    else
+                    {
+                        sql = $"{sql}  and c.pid= null ";
+                    }
+                }
+                List<string> notinIds = null;
+                if (request.TryGetProperty("notinIds", out JsonElement _notinIds) && _notinIds.ValueKind.Equals(JsonValueKind.Array))
+                {
+                    notinIds = _notinIds.ToObject<List<string>>();
+                    if (notinIds.IsNotEmpty())
+                    {
+                        sql = $"{sql}  and c.id not in ({string.Join(",", notinIds.Select(x => $"'{x}'"))})";
+                    }
+                }
+                string sqlstr = sql.ToString().Replace("joingradeIds", " ").Replace("joinknowledge"," " );
+                if (sqlstr.EndsWith("1=1") || !sqlstr.Contains("and"))
+                {
+                    return Ok(new { itemInfo = itemInfo });
+                }
+                if (scope.ToString().Equals("private"))
+                {
+                    List<string> items = new List<string>();
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<string>(queryText: sqlstr, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
+                    {
+                        items.Add(item);
+                    }
+                    if (notinIds.IsNotEmpty()) {
+                        items =  items.Except(notinIds).ToList();
+                    }
+                    string id= items.OrderBy(x => Guid.NewGuid().ToString()).Take(1).FirstOrDefault();
+                    if (!string.IsNullOrWhiteSpace(id)) {
+                        try { 
+                            itemInfo = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<ItemInfo>(id, new PartitionKey($"Item-{code}"));
+                        } catch (Exception ex) {
+                            itemInfo = null;
+                        }
+                    }
+                }
+                if (scope.ToString().Equals("school"))
+                {
+                    List<string> items = new List<string>();
+                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<string>(queryText: sqlstr, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{code}") }))
+                    {
+                        items.Add(item);
+                    }
+                    if (notinIds.IsNotEmpty())
+                    {
+                        items = items.Except(notinIds).ToList();
+                    }
+                    string id = items.OrderBy(x => Guid.NewGuid().ToString()).Take(1).FirstOrDefault();
+                    if (!string.IsNullOrWhiteSpace(id))
+                    {
+                        try
+                        {
+                            itemInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<ItemInfo>(id, new PartitionKey($"Item-{code}"));
+                        }
+                        catch (Exception ex)
+                        {
+                            itemInfo = null;
+                        }
+                    }
+                }
+                return Ok(new { itemInfo= itemInfo });
+            }
+            catch (Exception e)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},item/Find()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
+                return BadRequest();
+            }
+        }
+
+
         /// <summary>
         /// <summary>
         /// 手动挑题
         /// 手动挑题
         /// </summary>
         /// </summary>
@@ -824,48 +961,8 @@ namespace TEAMModelOS.Controllers
                 await _dingDing.SendBotMsg($"OS,{_option.Location},item/Find()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 await _dingDing.SendBotMsg($"OS,{_option.Location},item/Find()\n{e.Message}\n{e.StackTrace}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
                 return BadRequest();
             }
             }
-
         }
         }
 
 
-        /// <summary>
-        /// 手动挑题
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        //[AuthToken(Roles = "teacher")]
-        [HttpPost("Find-cache-shell")]
-        [Authorize(Roles = "IES")]
-        public async Task<IActionResult> FindCacheShell(JsonElement request)
-        {
-            var client = _azureCosmos.GetCosmosClient();
-            if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
-            if (!request.TryGetProperty("ids", out JsonElement id)) return BadRequest();
-            //List<string> ids = new List<string>();
-            string info = "";
-            for (int i = 0; i < id.GetArrayLength(); i++)
-            {
-                //ids.Add(id[i].ToJsonString());
-                info += id[i].ToJsonString() + ",";
-            }
-            List<object> items = new List<object>();
-            var query = $"select c.id, c.question,c.useCount,c.level,c.field,c.knowledge,c.type,c.option,c.createTime from c where c.id in ({info[0..^1]})";
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-{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())
-                    {
-                        items.Add(obj.ToObject<object>());
-                    }
-                }
-            }
-
-            return Ok(new { items });
-
-        }
 
 
         /// <summary>
         /// <summary>
         /// 自动组题
         /// 自动组题