lrf 3 gadi atpakaļ
vecāks
revīzija
161d6cd128
1 mainītis faili ar 26 papildinājumiem un 0 dzēšanām
  1. 26 0
      app/service/users/personal.js

+ 26 - 0
app/service/users/personal.js

@@ -15,6 +15,32 @@ class PersonalService extends CrudService {
     super(ctx, 'personal');
     this.redis = this.app.redis;
     this.model = this.ctx.model.Personal;
+    this.orgModel = this.ctx.model.Organization;
+    this.util = this.ctx.service.util.util;
+  }
+  async query(condition, { skip = 0, limit = 0 }) {
+    condition = await this.dealQueryCondition(condition);
+    const res = await this.model.find(condition).skip(parseInt(skip)).limit(parseInt(limit));
+    return res;
+  }
+  async count({ role, code, ...condition }) {
+    condition = await this.dealQueryCondition(condition);
+    const res = await this.model.count(condition);
+    return res;
+  }
+
+  async dealQueryCondition({ role, code, ...condition } = {}) {
+    condition = this.util.dealQuery(condition);
+    if (role === 1) {
+      //code查询机构,取出机构的code,用code到model(个人用户)里查询用户,合为一个数组,返回
+      const orgRes = await this.orgModel.find({ code }, { code: 1 });
+      const codes = orgRes.map((i) => i.code);
+      condition.code = codes;
+    } else {
+      //code直接查询用户返回即可
+      condition.code = code;
+    }
+    return condition;
   }
   /**
    * 创建用户