|
@@ -542,6 +542,51 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 删除名单同时从关联的课程移除名单 ,只针对个人名单 个人课程、
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ //[AuthToken(Roles = "teacher")]
|
|
|
+ [HttpPost("del-stulist-rmv-rel-course")]
|
|
|
+#if !DEBUG
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+#endif
|
|
|
+ public async Task<IActionResult> DelStulistRmvRelCourse(JsonElement requert) {
|
|
|
+ //教师编码
|
|
|
+ if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+ //课程id
|
|
|
+ if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ //名单id
|
|
|
+ if (!requert.TryGetProperty("stulist", out JsonElement stulist)) return BadRequest();
|
|
|
+ try {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ List<Course> courses = new List<Course>();
|
|
|
+ Course cs = await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<Course>($"{id}", new PartitionKey($"Course-{code}"));
|
|
|
+ courses.Add(cs);
|
|
|
+ string sql = $"SELECT distinct value(c) FROM c join s in c.schedule where c.pk='Course' and s.stulist='{stulist}' and c.id<>'{cs.id}' ";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Course>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{code}") }))
|
|
|
+ {
|
|
|
+ courses.Add(item);
|
|
|
+ }
|
|
|
+ List<Task<ItemResponse<Course>>> responses = new List<Task<ItemResponse<Course>>>();
|
|
|
+ courses.ForEach(course => {
|
|
|
+ course.schedule.RemoveAll(x => string.IsNullOrWhiteSpace(x.classId) && !string.IsNullOrWhiteSpace(x.stulist) && x.stulist.Equals($"{stulist}"));
|
|
|
+ responses.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync(course, course.id, new PartitionKey(course.code)));
|
|
|
+ });
|
|
|
+ await Task.WhenAll(responses);
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await GroupListService.DeleteGrouplistEvent($"{stulist}", "GroupList", Constant.Teacher, client, _configuration, _serviceBus);
|
|
|
+ }
|
|
|
+ catch (Exception ex) { }
|
|
|
+
|
|
|
+ } catch (Exception ex) {
|
|
|
+ }
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询课程详情
|
|
@@ -551,7 +596,9 @@ namespace TEAMModelOS.Controllers
|
|
|
[ProducesDefaultResponseType]
|
|
|
//[AuthToken(Roles = "teacher")]
|
|
|
[HttpPost("find-summary")]
|
|
|
+#if !DEBUG
|
|
|
[Authorize(Roles = "IES")]
|
|
|
+#endif
|
|
|
public async Task<IActionResult> FindSummary(JsonElement requert)
|
|
|
{
|
|
|
|
|
@@ -579,10 +626,17 @@ namespace TEAMModelOS.Controllers
|
|
|
courseList.Add(item);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ List<IdCode> privateCourseStulist = new List<IdCode>();
|
|
|
+ //检查个人课程的个人名单关联情况,以便于删除管理名单。
|
|
|
if (!$"{scope}".Equals("school")) {
|
|
|
- var stulist =courseList.SelectMany(x => x.schedule).Select(z => z.stulist).Where(y => !string.IsNullOrWhiteSpace(y));
|
|
|
-
|
|
|
+ var stulists =courseList.SelectMany(x => x.schedule).Select(z => z.stulist).Where(y => !string.IsNullOrWhiteSpace(y));
|
|
|
+ if (stulists.Any()) {
|
|
|
+ string sql = $"SELECT distinct c.id,s.stulist as code FROM c join s in c.schedule where c.pk='Course' and s.stulist in ({string.Join(",", stulists.Select(x=>$"'{x}'"))}) ";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<IdCode>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{code}") }))
|
|
|
+ {
|
|
|
+ privateCourseStulist.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
foreach (Course course in courseList)
|
|
|
{
|
|
@@ -612,6 +666,19 @@ namespace TEAMModelOS.Controllers
|
|
|
scheduleExtobj.teacherName = teacher.name;
|
|
|
}
|
|
|
}
|
|
|
+ if (!$"{scope}".Equals("school")) {
|
|
|
+ if (!string.IsNullOrWhiteSpace(schedule.stulist))
|
|
|
+ {
|
|
|
+ var list = privateCourseStulist.FindAll(x => x.code.Equals(schedule.stulist));
|
|
|
+ if (list.Any())
|
|
|
+ {
|
|
|
+ scheduleExtobj.stulistRel = list.Count;
|
|
|
+ }
|
|
|
+ else { scheduleExtobj.stulistRel = 1; }
|
|
|
+ }
|
|
|
+ else { scheduleExtobj.stulistRel = 1; }
|
|
|
+ }//stulistRel 只针对个人课程,学校课程 -1 .
|
|
|
+ else { scheduleExtobj.stulistRel =-1 ; }
|
|
|
scheduleExtobj.stulist = schedule.stulist;
|
|
|
scheduleExtobj.time = schedule.time;
|
|
|
scheduleExtobj.room = schedule.room;
|
|
@@ -652,14 +719,14 @@ namespace TEAMModelOS.Controllers
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
if (!request.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
- //string school_code = code.ToString().Substring(typeof(Course).Name.Length + 1);
|
|
|
+
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
if (scope.ToString().Equals("school"))
|
|
|
{
|
|
|
Course course = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<Course>(id.ToString(), new PartitionKey($"Course-{code}"));
|
|
|
CourseChange courseChange = new CourseChange { id = course.id, code = course.code, name = course.name, scope = course.scope, school = course.school, creatorId = course.creatorId };
|
|
|
- courseChange.delClass = course.schedule.Select(x => x.classId).ToList();
|
|
|
- courseChange.delList = course.schedule.Select(x => x.stulist).ToList();
|
|
|
+ courseChange.delClass = course.schedule.Where(z => !string.IsNullOrWhiteSpace(z.classId)).Select(x => x.classId).ToList();
|
|
|
+ courseChange.delList = course.schedule.Where(z => !string.IsNullOrWhiteSpace(z.stulist)).Select(x => x.stulist).ToList();
|
|
|
var messageBlob = new ServiceBusMessage(courseChange.ToJsonString()); ;
|
|
|
messageBlob.ApplicationProperties.Add("name", "Course");
|
|
|
var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
@@ -670,13 +737,52 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
Course course = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Course>(id.ToString(), new PartitionKey($"Course-{code}"));
|
|
|
CourseChange courseChange = new CourseChange { id = course.id, code = course.code, name = course.name, scope = course.scope, school = course.school, creatorId = course.creatorId };
|
|
|
- courseChange.delClass = course.schedule.Select(x => x.classId).ToList();
|
|
|
- courseChange.delList = course.schedule.Select(x => x.stulist).ToList();
|
|
|
+ courseChange.delClass = course.schedule.Where(z=>!string.IsNullOrWhiteSpace(z.classId)).Select(x => x.classId).ToList();
|
|
|
+ courseChange.delList = course.schedule.Where(z => !string.IsNullOrWhiteSpace(z.stulist)).Select(x => x.stulist).ToList();
|
|
|
var messageBlob = new ServiceBusMessage(courseChange.ToJsonString()); ;
|
|
|
messageBlob.ApplicationProperties.Add("name", "Course");
|
|
|
var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
|
|
|
await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
|
|
|
await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemStreamAsync(id.ToString(), new PartitionKey($"Course-{code}"));
|
|
|
+
|
|
|
+ request.TryGetProperty("deleteStulist", out JsonElement deleteStulist);
|
|
|
+
|
|
|
+ List<Course> courses = new List<Course>();
|
|
|
+ //先检查名单有没有多个关联
|
|
|
+ string sql = $"SELECT distinct value(c) FROM c join s in c.schedule where c.pk='Course' and s.stulist in ({string.Join(",", courseChange.delList.Select(x => $"'{x}'"))}) ";
|
|
|
+ await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Course>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{code}") }))
|
|
|
+ {
|
|
|
+ courses.Add(item);
|
|
|
+ }
|
|
|
+ if (deleteStulist.ValueKind.Equals(JsonValueKind.Number) && $"{deleteStulist}".Equals("1") && courseChange.delList.Any())
|
|
|
+ {
|
|
|
+ List<Task<ItemResponse<Course>>> responses = new List<Task<ItemResponse<Course>>>();
|
|
|
+ courses.ForEach(course =>
|
|
|
+ {
|
|
|
+ course.schedule.RemoveAll(x => string.IsNullOrWhiteSpace(x.classId) && !string.IsNullOrWhiteSpace(x.stulist) && courseChange.delList.Contains(x.stulist));
|
|
|
+ responses.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync(course, course.id, new PartitionKey(course.code)));
|
|
|
+ });
|
|
|
+ await Task.WhenAll(responses);
|
|
|
+ //deleteStulist==1 强制删除关联的名单,则需要处理当前课程的所有delList
|
|
|
+ foreach (var listid in courseChange.delList) {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await GroupListService.DeleteGrouplistEvent(listid, "GroupList", Constant.Teacher, client, _configuration, _serviceBus);
|
|
|
+ }
|
|
|
+ catch (Exception ex) { continue; }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //deleteStulist !=1 没有强制移除关联课程的名单时, 删除课程时,自动删除只有当前课程唯一对应的名单。
|
|
|
+ var exlists = courseChange.delList.Except(courses.SelectMany(x => x.schedule).Select(y => y.stulist));
|
|
|
+ if (exlists.Any()) {
|
|
|
+ foreach (var listid in exlists) {
|
|
|
+ try {
|
|
|
+ await GroupListService.DeleteGrouplistEvent(listid, "GroupList", Constant.Teacher, client, _configuration, _serviceBus);
|
|
|
+ } catch (Exception ex) { continue; }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return Ok(new { id });
|
|
|
}
|
|
@@ -692,10 +798,11 @@ namespace TEAMModelOS.Controllers
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
- [ProducesDefaultResponseType]
|
|
|
+ //[ProducesDefaultResponseType]
|
|
|
//[AuthToken(Roles = "teacher")]
|
|
|
- [HttpPost("delete-all")]
|
|
|
- [Authorize(Roles = "IES")]
|
|
|
+ //[HttpPost("delete-all")]//不要了
|
|
|
+
|
|
|
+ // [Authorize(Roles = "IES")]
|
|
|
public async Task<IActionResult> DeleteAll(BatchOption request)
|
|
|
{
|
|
|
try
|