فهرست منبع

增加根据批次id或班级id查询寝室名单

reloaded 5 سال پیش
والد
کامیت
2ffa64182c
1فایلهای تغییر یافته به همراه35 افزوده شده و 13 حذف شده
  1. 35 13
      app/service/student.js

+ 35 - 13
app/service/student.js

@@ -22,21 +22,43 @@ class StudentService extends CrudService {
     return result;
   }
 
-  async findbedroom({ batchid }) {
-    const students = await this.model.find({ batchid });
-    const bedroomList = new Set();
-    for (const student of students) {
-      bedroomList.add(student.bedroom);
-    }
+  async findbedroom(data) {
+    const { batchid, classid } = data;
     const result = [];
-    let studentList = [];
-    for (const bedroom of bedroomList) {
-      const newstudents = await this.model.find({ bedroom });
-      for (const newstudent of newstudents) {
-        studentList.push(newstudent.name);
+    if (batchid) {
+      const students = await this.model.find({ batchid });
+      const bedroomList = new Set();
+      for (const student of students) {
+        bedroomList.add(student.bedroom);
+      }
+
+      let studentList = [];
+      for (const bedroom of bedroomList) {
+        const newstudents = await this.model.find({ bedroom });
+        for (const newstudent of newstudents) {
+          studentList.push(newstudent.name);
+        }
+        result.push({ bedroom, studentList });
+        studentList = [];
+      }
+    }
+    if (classid) {
+      const students = await this.model.find({ classid });
+      const bedroomList = new Set();
+      for (const student of students) {
+        bedroomList.add(student.bedroom);
+      }
+      let studentList = [];
+      for (const bedroom of bedroomList) {
+        const newstudents = await this.model.find({ bedroom });
+        for (const newstudent of newstudents) {
+          if (newstudent.classid === classid) {
+            studentList.push(newstudent.name);
+          }
+        }
+        result.push({ bedroom, studentList });
+        studentList = [];
       }
-      result.push({ bedroom, studentList });
-      studentList = [];
     }
     return result;
   }