Преглед изворни кода

增加按批次查询所有学生的寝室及各寝室学生名单

reloaded пре 5 година
родитељ
комит
6d3ef2ac5b
3 измењених фајлова са 27 додато и 0 уклоњено
  1. 7 0
      app/controller/student.js
  2. 1 0
      app/router.js
  3. 19 0
      app/service/student.js

+ 7 - 0
app/controller/student.js

@@ -19,6 +19,13 @@ class StudentController extends Controller {
     this.ctx.ok({ ...res });
   }
 
+  // GET
+  // 查询
+  async findbedroom() {
+    const res = await this.service.findbedroom(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
+
 }
 
 module.exports = CrudController(StudentController, meta);

+ 1 - 0
app/router.js

@@ -33,6 +33,7 @@ module.exports = app => {
   router.get('questionnaire', '/api/train/questionnaire/show/:id', controller.questionnaire.show);
 
   // 学生表设置路由
+  router.get('sutdent', '/api/train/student/findbedroom', controller.student.findbedroom);
   router.get('sutdent', '/api/train/student/seek', controller.student.seek);
   router.resources('student', '/api/train/student', controller.student); // index、create、show、destroy
   router.post('student', '/api/train/student/update/:id', controller.student.update);

+ 19 - 0
app/service/student.js

@@ -22,6 +22,25 @@ 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);
+    }
+    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);
+      }
+      result.push({ bedroom, studentList });
+      studentList = [];
+    }
+    return result;
+  }
+
 }
 
 module.exports = StudentService;