reloaded před 5 roky
rodič
revize
5bc2bb1246
2 změnil soubory, kde provedl 11 přidání a 3 odebrání
  1. 2 2
      app/controller/student.js
  2. 9 1
      app/service/student.js

+ 2 - 2
app/controller/student.js

@@ -22,8 +22,8 @@ class StudentController extends Controller {
   // GET
   // 查询
   async findbedroom() {
-    const res = await this.service.findbedroom(this.ctx.query);
-    this.ctx.ok({ ...res });
+    const data = await this.service.findbedroom(this.ctx.query);
+    this.ctx.ok({ data });
   }
 
 }

+ 9 - 1
app/service/student.js

@@ -25,14 +25,17 @@ class StudentService extends CrudService {
   async findbedroom(data) {
     const { batchid, classid } = data;
     const result = [];
+    // 如果传的是批次id
     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) {
@@ -42,16 +45,21 @@ class StudentService extends CrudService {
         studentList = [];
       }
     }
+    // 如果传的是班级id
     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);
           }