浏览代码

update 行政班删除

CrazyIter_Bin 3 年之前
父节点
当前提交
a46878d24e
共有 2 个文件被更改,包括 21 次插入17 次删除
  1. 14 7
      TEAMModelOS.SDK/Models/Service/ActivityService.cs
  2. 7 10
      TEAMModelOS/Controllers/School/ClassController.cs

+ 14 - 7
TEAMModelOS.SDK/Models/Service/ActivityService.cs

@@ -520,16 +520,23 @@ namespace TEAMModelOS.SDK
             if (groupChange.status.Equals("delete")) {
                 foreach (var item in courses)
                 {
-                    var count = item.schedule.RemoveAll(x => x.classId.Equals(groupChange.listid) || x.stulist.Equals(groupChange.listid));
-                    if (count > 0) {
-                        if (item.scope.Equals("school"))
-                        {
-                            await  client.GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
+                    item.schedule.ForEach(x => {
+                        if ( !string.IsNullOrWhiteSpace(x.classId) && x.classId.Equals(groupChange.listid)) {
+                            x.classId = "";
                         }
-                        else {
-                            await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
+                        if (!string.IsNullOrWhiteSpace(x.stulist) && x.stulist.Equals(groupChange.listid))
+                        {
+                            x.stulist = "";
                         }
+                    });
+                    if (item.scope.Equals("school"))
+                    {
+                        await  client.GetContainer(Constant.TEAMModelOS, Constant.School).ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
+                    }
+                    else {
+                        await client.GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync(item, item.id, new PartitionKey(item.code));
                     }
+                    
                 }
             }
         }

+ 7 - 10
TEAMModelOS/Controllers/School/ClassController.cs

@@ -218,12 +218,8 @@ namespace TEAMModelOS.Controllers
            
             try
             {
-                
                 string school_code = code.ToString();
-                
                 var client = _azureCosmos.GetCosmosClient();
-                Class classroom = await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemAsync<Class>(id.ToString(), new PartitionKey($"Class-{school_code}"));
-                
                 List<Student> students = new List<Student>();
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryIterator<Student>(queryText: $"select *  from c where c.classId='{id}' ", requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"Base-{code}") }))
                 {
@@ -235,7 +231,6 @@ namespace TEAMModelOS.Controllers
                 {
                     tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Student").ReplaceItemAsync(stu, stu.id, new PartitionKey(($"Base-{code}"))));
                 }
-
                 GroupChange change = new GroupChange();
                 if (students.IsNotEmpty()) {
                     change.stuleave.AddRange(students.Select(x=> new Member {
@@ -249,10 +244,10 @@ namespace TEAMModelOS.Controllers
                         code = $"{code}"
                     }));
                 }
-                change.listid = classroom.id;
+                change.listid = $"{id}";
                 change.scope = "school";
                 change.originCode = $"{code}";
-                change.school = classroom.school;
+                change.school = $"{school_code}";
                 change.type = "class";
                 change.status = "delete";
                 var messageChange = new ServiceBusMessage(change.ToJsonString());
@@ -260,6 +255,8 @@ namespace TEAMModelOS.Controllers
                 var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
                 await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
                 //查询含有该班级的课程ID
+
+                /*
                 List<string> cids = new List<string>();
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryStreamIterator(
                     queryText: $"select distinct c.id from c join A0 in c.schedule where A0.classId = '{id}'",
@@ -288,7 +285,6 @@ namespace TEAMModelOS.Controllers
                     }
                 }
                
-                //courses.ForEach(c => c.schedule.Where(s => !string.IsNullOrEmpty(s.classId)&& s.classId.Equals(id))
                 foreach (Course course in courses)
                 {
                     for (int i =0;i< course.schedule.Count;i++) {
@@ -301,9 +297,10 @@ namespace TEAMModelOS.Controllers
                     }
                     taskCourses.Add(client.GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync(course, course.id, new PartitionKey((course.code))));
                 }
-
-                await Task.WhenAll(tasks);
                 await Task.WhenAll(taskCourses);
+                */
+                await Task.WhenAll(tasks);
+                Class classroom=   await client.GetContainer(Constant.TEAMModelOS, "School").DeleteItemAsync<Class>(id.ToString(), new PartitionKey($"Class-{school_code}"));
                 return Ok(new { classroom });
             }
             catch (Exception ex)