|
@@ -35,16 +35,41 @@ class PersonalService extends CrudService {
|
|
|
|
|
|
async dealQueryCondition({ role, code, ...condition } = {}) {
|
|
|
condition = this.util.dealQuery(condition);
|
|
|
- if (role === '1') {
|
|
|
- // code查询机构,取出机构的code,用code到model(个人用户)里查询用户,合为一个数组,返回
|
|
|
- const orgRes = await this.adminModel.find({ code }, { _id: 1 });
|
|
|
- const ids = orgRes.map(i => i._id);
|
|
|
- const res2 = await this.adminModel.find({ pid: ids, role: '2' }, { code });
|
|
|
- const codes = res2.map(i => i.code);
|
|
|
+ // 查询业务管理
|
|
|
+ const busFind = async query => await this.adminModel.find({ ...query, role: '3' }, { code });
|
|
|
+ // 查询机构管理
|
|
|
+ const orgFind = async query => await this.adminModel.find({ ...query, role: '2' }, { code });
|
|
|
+ // 查询管理员
|
|
|
+ const aFind = async query => await this.adminModel.find({ ...query, role: '1' }, { code });
|
|
|
+ if (role === '1' && code) {
|
|
|
+ // 管理员查询
|
|
|
+ // =>获取该code下的机构管理员列表 => 用机构管理员id 获取业务管理员列表 => 将code都整理出来作为查询条件
|
|
|
+ const a = await aFind({ code });
|
|
|
+ if (a.length <= 0) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该管理员');
|
|
|
+ const aid = _.get(_.head(a), '_id');
|
|
|
+ const orgList = await orgFind({ pid: aid });
|
|
|
+ const busList = await busFind({ pid: orgList.map(i => i._id) });
|
|
|
+ const codes = [ ...orgList.map(i => i.code), ...busList.map(i => i.code), code ];
|
|
|
+ condition.code = codes;
|
|
|
+ } else if (role === '2' && code) {
|
|
|
+ // 机构查询
|
|
|
+ // =>获取该code下的业务管理员列表 => 将code都整理出来作为查询条件
|
|
|
+ const o = await orgFind({ code });
|
|
|
+ if (o.length <= 0) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该机构');
|
|
|
+ const oid = _.get(_.head(o), '_id');
|
|
|
+ const busList = await busFind({ pid: oid });
|
|
|
+ const codes = [ ...busList.map(i => i.code), code ];
|
|
|
condition.code = codes;
|
|
|
} else if (code) {
|
|
|
+ // 业务查询
|
|
|
// code直接查询用户返回即可
|
|
|
condition.code = code;
|
|
|
+ } else {
|
|
|
+ // 超级管理员查询
|
|
|
+ // 将所有管理员的code都查出来做条件
|
|
|
+ const allAdmin = await this.adminModel.find({}, { code });
|
|
|
+ const codes = allAdmin.map(i => i.code);
|
|
|
+ condition.code = codes;
|
|
|
}
|
|
|
return condition;
|
|
|
}
|