Kaynağa Gözat

学生分数查询

reloaded 4 yıl önce
ebeveyn
işleme
f295412a54
3 değiştirilmiş dosya ile 23 ekleme ve 1 silme
  1. 4 1
      app/controller/student.js
  2. 1 0
      app/router.js
  3. 18 0
      app/service/student.js

+ 4 - 1
app/controller/student.js

@@ -7,7 +7,6 @@ const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 学生管理
 class StudentController extends Controller {
-
   constructor(ctx) {
     super(ctx);
     this.service = this.ctx.service.student;
@@ -43,6 +42,10 @@ class StudentController extends Controller {
     this.ctx.ok({ data });
   }
 
+  async findscore() {
+    const data = await this.service.findscore(this.ctx.query);
+    this.ctx.ok({ ...data });
+  }
 }
 
 module.exports = CrudController(StudentController, meta);

+ 1 - 0
app/router.js

@@ -39,6 +39,7 @@ module.exports = app => {
   router.get('questionnaire', '/api/train/questionnaire/show/:id', controller.questionnaire.show);
 
   // 学生表设置路由
+  router.get('sutdent', '/api/train/student/findscore', controller.student.findscore);
   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

+ 18 - 0
app/service/student.js

@@ -14,6 +14,7 @@ class StudentService extends CrudService {
     this.umodel = this.ctx.model.User;
     this.tmodel = this.ctx.model.Trainplan;
     this.clamodel = this.ctx.model.Class;
+    this.upmodel = this.ctx.model.Uploadtask;
   }
 
   // 查询
@@ -129,6 +130,23 @@ class StudentService extends CrudService {
     }
   }
 
+  // 根据班级id查出班级各个学生的分数
+  async findscore({ skip, limit, ...info }) {
+    const total = await this.model.count(info);
+    const students = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
+    const data = [];
+    for (const student of students) {
+      const _student = _.cloneDeep(student);
+      const group = await this.ctx.service.group.findbystuid({ stuid: _student.id });
+      if (group && group.score) {
+        _student.groupscore = group.score;
+      }
+      const tasks = await this.upmodel.find({ studentid: _student.id });
+      _student.tasks = tasks;
+      data.push(_student);
+    }
+    return { total, data };
+  }
 }
 
 module.exports = StudentService;