reloaded преди 4 години
родител
ревизия
4ed51de71d
променени са 3 файла, в които са добавени 45 реда и са изтрити 7 реда
  1. 5 0
      app/controller/student.js
  2. 1 0
      app/router.js
  3. 39 7
      app/service/student.js

+ 5 - 0
app/controller/student.js

@@ -46,6 +46,11 @@ class StudentController extends Controller {
     const data = await this.service.findscore(this.ctx.query);
     this.ctx.ok({ ...data });
   }
+
+  async findbystuids() {
+    const data = await this.service.findbystuids(this.ctx.request.body);
+    this.ctx.ok({ data });
+  }
 }
 
 module.exports = CrudController(StudentController, meta);

+ 1 - 0
app/router.js

@@ -47,6 +47,7 @@ module.exports = app => {
   router.post('student', '/api/train/student/update/:id', controller.student.update);
   router.post('student', '/api/train/student/upjob', controller.student.upjob);
   router.post('student', '/api/train/student/deleteclass', controller.student.deleteclass); // 删除学生班级
+  router.post('student', '/api/train/student/findbystuids', controller.student.findbystuids);
 
   // 班主任表设置路由
   router.resources('headteacher', '/api/train/headteacher', controller.headteacher); // index、create、show、destroy

+ 39 - 7
app/service/student.js

@@ -21,10 +21,15 @@ class StudentService extends CrudService {
   // 查询
   async query({ skip, limit, ...info }) {
     const total = await this.model.count(info);
-    const res = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
+    const res = await this.model
+      .find(info)
+      .skip(Number(skip))
+      .limit(Number(limit));
     const data = [];
     for (const elm of res) {
-      const plan = await this.tmodel.findOne({ 'termnum._id': ObjectId(elm.termid) });
+      const plan = await this.tmodel.findOne({
+        'termnum._id': ObjectId(elm.termid),
+      });
       const newdata = { ...JSON.parse(JSON.stringify(elm)) };
       if (plan) {
         const term = await plan.termnum.id(elm.termid);
@@ -48,8 +53,14 @@ class StudentService extends CrudService {
 
   // 查询
   async seek({ termid, skip, limit }) {
-    const total = await this.model.count({ termid, $or: [{ classid: null }, { classid: '' }] });
-    const data = await this.model.find({ termid, $or: [{ classid: null }, { classid: '' }] }).skip(Number(skip)).limit(Number(limit));
+    const total = await this.model.count({
+      termid,
+      $or: [{ classid: null }, { classid: '' }],
+    });
+    const data = await this.model
+      .find({ termid, $or: [{ classid: null }, { classid: '' }] })
+      .skip(Number(skip))
+      .limit(Number(limit));
     const result = { total, data };
     return result;
   }
@@ -114,7 +125,14 @@ class StudentService extends CrudService {
       const detail = '你已被班主任设置为' + job + ',请及时登录查看';
       const remark = '感谢您的使用';
       if (openid) {
-        this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark);
+        this.ctx.service.weixin.sendTemplateMsg(
+          this.ctx.app.config.REVIEW_TEMPLATE_ID,
+          openid,
+          '您有一个新的通知',
+          detail,
+          date,
+          remark
+        );
       }
     }
     return await student.save();
@@ -135,12 +153,17 @@ class StudentService extends CrudService {
   async findscore({ skip, limit, ...info }) {
     const { classid } = info;
     const total = await this.model.count(info);
-    const students = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
+    const students = await this.model
+      .find(info)
+      .skip(Number(skip))
+      .limit(Number(limit));
     const data = [];
     const groups = await this.gmodel.find({ classid });
     for (const student of students) {
       const _student = JSON.parse(JSON.stringify(student));
-      const group = groups.find(item => item.students.find(stuinfo => stuinfo.stuid === _student.id));
+      const group = groups.find(item =>
+        item.students.find(stuinfo => stuinfo.stuid === _student.id)
+      );
       console.log(group);
       if (group) {
         _student.groupscore = group.score;
@@ -152,6 +175,15 @@ class StudentService extends CrudService {
 
     return { total, data };
   }
+
+  async findbystuids({ data }) {
+    const res = [];
+    for (const stuid of data) {
+      const stu = await this.model.findById(stuid);
+      if (stu)res.push(stu);
+    }
+    return res;
+  }
 }
 
 module.exports = StudentService;