소스 검색

重写学生查询方法

liuyu 4 년 전
부모
커밋
12488c5328
1개의 변경된 파일23개의 추가작업 그리고 0개의 파일을 삭제
  1. 23 0
      app/service/student.js

+ 23 - 0
app/service/student.js

@@ -12,6 +12,29 @@ class StudentService extends CrudService {
     super(ctx, 'student');
     this.model = this.ctx.model.Student;
     this.umodel = this.ctx.model.User;
+    this.tmodel = this.ctx.model.Trainplan;
+  }
+
+  // 查询
+  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 data = [];
+    for (const elm of res) {
+      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);
+        newdata.termname = term.term;
+        if (elm.batchid) {
+          const _batch = await term.batchnum.id(elm.batchid);
+          newdata.batchname = _batch.batch;
+        }
+      }
+      data.push(newdata);
+    }
+    const result = { total, data };
+    return result;
   }
 
   // 查询