lrf402788946 4 년 전
부모
커밋
c149a9327e
4개의 변경된 파일74개의 추가작업 그리고 4개의 파일을 삭제
  1. 17 0
      app/service/bedroom.js
  2. 29 0
      app/service/school.js
  3. 14 2
      app/service/student.js
  4. 14 2
      app/service/teacher.js

+ 17 - 0
app/service/bedroom.js

@@ -19,6 +19,23 @@ class BedroomService extends CrudService {
     this.nmodel = this.ctx.model.Notice;
   }
 
+  async query({ code, ...data }, { skip, limit }) {
+    const query = { ...data };
+    if (code) {
+      query.code = { $regex: code };
+    }
+    const res = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit));
+    return res;
+  }
+  async count({ code, ...data }) {
+    const query = { ...data };
+    if (code) {
+      query.code = { $regex: code };
+    }
+    const res = await this.model.count(query);
+    return res;
+  }
+
   // 根据班级id查找班级下所有寝室列表并查询出寝室下学生信息
   async roomstu({ id }) {
     // 通过班级id查询学生表信息

+ 29 - 0
app/service/school.js

@@ -39,6 +39,35 @@ class SchoolService extends CrudService {
     return res;
   }
 
+  async query({ name, ...data }, { skip, limit }) {
+    const query = { ...data };
+    if (name) {
+      query.name = { $regex: name };
+    }
+    let res = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit));
+    if (res && res.length > 0) {
+      res = JSON.parse(JSON.stringify(res));
+      const ids = res.map(i => i._id);
+      const users = await this.umodel.find({ uid: { $in: ids } }, '+passwd');
+      for (const tea of res) {
+        const r = users.find(f => f.uid === tea._id);
+        if (r) {
+          const passwd = _.get(r.passwd, 'secret');
+          if (passwd) tea.passwd = passwd;
+        }
+      }
+    }
+    return res;
+  }
+
+  async count({ name, ...data }) {
+    const query = { ...data };
+    if (name) {
+      query.name = { $regex: name };
+    }
+    return await this.model.count(query);
+  }
+
   async stuimport(data) {
     const { filepath, termid, schid, type, batchid } = data;
     assert(filepath, 'filepath不能为空');

+ 14 - 2
app/service/student.js

@@ -64,9 +64,13 @@ class StudentService extends CrudService {
   }
 
   // 查询
-  async query({ ...info }, { skip, limit }) {
+  async query({ name, ...info }, { skip, limit }) {
+    const query = { ...info };
+    if (name) {
+      query.name = { $regex: name };
+    }
     let data = await this.model
-      .find({ ...info })
+      .find(query)
       .populate([
         {
           path: 'classid',
@@ -112,6 +116,14 @@ class StudentService extends CrudService {
     return data;
   }
 
+  async count({ name, ...info }) {
+    const query = { ...info };
+    if (name) {
+      query.name = { $regex: name };
+    }
+    return await this.model.count(query);
+  }
+
   // 查询
   async seek({ termid, type, batchid, skip, limit }) {
     const total = await this.model.count({

+ 14 - 2
app/service/teacher.js

@@ -16,9 +16,13 @@ class TeacherService extends CrudService {
     this.umodel = this.ctx.model.User;
   }
 
-  async query(info, { skip, limit }) {
+  async query({ name, ...info }, { skip, limit }) {
+    const query = { ...info };
+    if (name) {
+      query.name = { $regex: name };
+    }
     let res = await this.model
-      .find(info)
+      .find(query)
       .skip(Number(skip))
       .limit(Number(limit));
     res = JSON.parse(JSON.stringify(res));
@@ -32,6 +36,14 @@ class TeacherService extends CrudService {
     }
     return res;
   }
+  async count({ name, ...info }) {
+    const query = { ...info };
+    if (name) {
+      query.name = { $regex: name };
+    }
+    const res = await this.model.count(query);
+    return res;
+  }
 
   // 根据状态删除教师信息
   async deleteByStatus({ status }) {