zs hace 2 años
padre
commit
35a6ce2e3d

+ 3 - 2
src/controller/user/company.controller.ts

@@ -96,13 +96,14 @@ export class CompanyController extends BaseController {
     @Query('skip') skip: number,
     @Query('limit') limit: number
   ) {
-    const list = await this.service.query(filter, { skip, limit });
+    const query = await this.service.dealQueryCondition(filter);
+    const list = await this.service.query(query, { skip, limit });
     const data = [];
     for (const i of list) {
       const newData = new QVO_company(i);
       data.push(newData);
     }
-    const total = await this.service.count(filter);
+    const total = await this.service.count(query);
     return { data, total };
   }
 

+ 3 - 3
src/controller/user/expert.controller.ts

@@ -136,14 +136,14 @@ export class ExpertController extends BaseController {
     //     };
     //   } else query.company = company;
     // }
-    // query = await this.service.dealQueryCondition(query);
-    const list = await this.service.query(filter, { skip, limit });
+    const query = await this.service.dealQueryCondition(filter);
+    const list = await this.service.query(query, { skip, limit });
     const data = [];
     for (const i of list) {
       const newData = new QVO_expert(i);
       data.push(newData);
     }
-    const total = await this.service.count(filter);
+    const total = await this.service.count(query);
     return { data, total };
   }
 

+ 62 - 2
src/service/user/company.service.ts

@@ -1,4 +1,4 @@
-import { Provide } from '@midwayjs/decorator';
+import { Provide, Inject } from '@midwayjs/decorator';
 import { InjectEntityModel } from '@midwayjs/typegoose';
 import { ReturnModelType } from '@typegoose/typegoose';
 import {
@@ -7,15 +7,24 @@ import {
   ServiceError,
 } from 'free-midway-component';
 import { Company } from '../../entity/user/company.entity';
-import { LoginDTO } from '../../interface/user/company.interface';
+import { Admin } from '../../entity/user/admin.entity';
+import { LoginDTO, QDTO_company } from '../../interface/user/company.interface';
 import isEqual = require('lodash/isEqual');
 import get = require('lodash/get');
+import head = require('lodash/head');
+import { UtilService } from '../../service/util/util';
 type modelType = ReturnModelType<typeof Company>;
 @Provide()
 export class CompanyService extends BaseService<modelType> {
   @InjectEntityModel(Company)
   model: modelType;
 
+  @InjectEntityModel(Admin)
+  adminModel: ReturnModelType<typeof Admin>;
+
+  @Inject()
+  util: UtilService;
+
   async findUserToLogin(data: LoginDTO): Promise<object> {
     const { account, password } = data;
     const user = await this.model.findOne({ account }, '+password').lean();
@@ -33,4 +42,55 @@ export class CompanyService extends BaseService<modelType> {
       throw new ServiceError('密码错误', FrameworkErrorEnum.SERVICE_FAULT);
     return user;
   }
+  async dealQueryCondition(condition: QDTO_company): Promise<QDTO_company> {
+    const { type, code } = this.ctx.user;
+    condition = this.util.dealQuery(condition);
+    // 查询业务管理
+    const busFind = async query =>
+      await this.adminModel.find({ ...query, type: '3' }, { code: 1 });
+    // 查询机构管理
+    const orgFind = async query =>
+      await this.adminModel.find({ ...query, type: '2' }, { code: 1 });
+    // 查询管理员
+    const aFind = async query =>
+      await this.adminModel.find({ ...query, type: '1' }, { code: 1 });
+    if (type === '1' && code) {
+      // 管理员查询
+      // =>获取该code下的机构管理员列表 => 用机构管理员id 获取业务管理员列表 => 将code都整理出来作为查询条件
+      const a = await aFind({ code });
+      if (a.length <= 0)
+        throw new ServiceError(
+          '未找到该管理员',
+          FrameworkErrorEnum.NOT_FOUND_DATA
+        );
+      const aid = get(head(a), '_id');
+      const orgList = await orgFind({ pid: aid });
+      const busList = await busFind({ pid: orgList.map(i => i._id) });
+      const codes: any = [
+        ...orgList.map(i => i.code),
+        ...busList.map(i => i.code),
+        code,
+      ];
+      condition.code = codes;
+    } else if (type === '2' && code) {
+      // 机构查询
+      // =>获取该code下的业务管理员列表 => 将code都整理出来作为查询条件
+      const o = await orgFind({ code });
+      if (o.length <= 0)
+        throw new ServiceError(
+          '未找到该机构',
+          FrameworkErrorEnum.NOT_FOUND_DATA
+        );
+      const oid = get(head(o), '_id');
+      const busList = await busFind({ pid: oid });
+      const codes: any = [...busList.map(i => i.code), code];
+      condition.code = codes;
+    } else if (type === '3' && code) {
+      // 业务查询
+      // code直接查询用户返回即可
+      condition.code = code;
+    }
+    // 没有code,超级管理员,说明不限制
+    return condition;
+  }
 }

+ 11 - 11
src/service/user/expert.service.ts

@@ -8,7 +8,7 @@ import {
 } from 'free-midway-component';
 import { Expert } from '../../entity/user/expert.entity';
 import { Admin } from '../../entity/user/admin.entity';
-import { LoginDTO } from '../../interface/user/expert.interface';
+import { LoginDTO, QDTO_expert } from '../../interface/user/expert.interface';
 import isEqual = require('lodash/isEqual');
 import get = require('lodash/get');
 import head = require('lodash/head');
@@ -42,19 +42,19 @@ export class ExpertService extends BaseService<modelType> {
       throw new ServiceError('密码错误', FrameworkErrorEnum.SERVICE_FAULT);
     return user;
   }
-  async dealQueryCondition({ code, ...condition }) {
-    const role = this.ctx.user.type;
+  async dealQueryCondition(condition: QDTO_expert): Promise<QDTO_expert> {
+    const { type, code } = this.ctx.user;
     condition = this.util.dealQuery(condition);
     // 查询业务管理
     const busFind = async query =>
-      await this.adminModel.find({ ...query, role: '3' }, { code: 1 });
+      await this.adminModel.find({ ...query, type: '3' }, { code: 1 });
     // 查询机构管理
     const orgFind = async query =>
-      await this.adminModel.find({ ...query, role: '2' }, { code: 1 });
+      await this.adminModel.find({ ...query, type: '2' }, { code: 1 });
     // 查询管理员
     const aFind = async query =>
-      await this.adminModel.find({ ...query, role: '1' }, { code: 1 });
-    if (role === '1' && code) {
+      await this.adminModel.find({ ...query, type: '1' }, { code: 1 });
+    if (type === '1' && code) {
       // 管理员查询
       // =>获取该code下的机构管理员列表 => 用机构管理员id 获取业务管理员列表 => 将code都整理出来作为查询条件
       const a = await aFind({ code });
@@ -66,13 +66,13 @@ export class ExpertService extends BaseService<modelType> {
       const aid = get(head(a), '_id');
       const orgList = await orgFind({ pid: aid });
       const busList = await busFind({ pid: orgList.map(i => i._id) });
-      const codes = [
+      const codes: any = [
         ...orgList.map(i => i.code),
         ...busList.map(i => i.code),
         code,
       ];
       condition.code = codes;
-    } else if (role === '2' && code) {
+    } else if (type === '2' && code) {
       // 机构查询
       // =>获取该code下的业务管理员列表 => 将code都整理出来作为查询条件
       const o = await orgFind({ code });
@@ -83,9 +83,9 @@ export class ExpertService extends BaseService<modelType> {
         );
       const oid = get(head(o), '_id');
       const busList = await busFind({ pid: oid });
-      const codes = [...busList.map(i => i.code), code];
+      const codes: any = [...busList.map(i => i.code), code];
       condition.code = codes;
-    } else if (code) {
+    } else if (type === '3' && code) {
       // 业务查询
       // code直接查询用户返回即可
       condition.code = code;

+ 7 - 8
src/service/user/personal.service.ts

@@ -47,19 +47,18 @@ export class PersonalService extends BaseService<modelType> {
     return user;
   }
   async dealQueryCondition(condition: QDTO_personal): Promise<QDTO_personal> {
-    const role = this.ctx.user.type;
-    const code = condition.code;
+    const { type, code } = this.ctx.user;
     condition = this.util.dealQuery(condition);
     // 查询业务管理
     const busFind = async query =>
-      await this.adminModel.find({ ...query, role: '3' }, { code: 1 });
+      await this.adminModel.find({ ...query, type: '3' }, { code: 1 });
     // 查询机构管理
     const orgFind = async query =>
-      await this.adminModel.find({ ...query, role: '2' }, { code: 1 });
+      await this.adminModel.find({ ...query, type: '2' }, { code: 1 });
     // 查询管理员
     const aFind = async query =>
-      await this.adminModel.find({ ...query, role: '1' }, { code: 1 });
-    if (role === '1' && code) {
+      await this.adminModel.find({ ...query, type: '1' }, { code: 1 });
+    if (type === '1' && code) {
       // 管理员查询
       // =>获取该code下的机构管理员列表 => 用机构管理员id 获取业务管理员列表 => 将code都整理出来作为查询条件
       const a = await aFind({ code });
@@ -77,7 +76,7 @@ export class PersonalService extends BaseService<modelType> {
         code,
       ];
       condition.code = codes;
-    } else if (role === '2' && code) {
+    } else if (type === '2' && code) {
       // 机构查询
       // =>获取该code下的业务管理员列表 => 将code都整理出来作为查询条件
       const o = await orgFind({ code });
@@ -90,7 +89,7 @@ export class PersonalService extends BaseService<modelType> {
       const busList = await busFind({ pid: oid });
       const codes: any = [...busList.map(i => i.code), code];
       condition.code = codes;
-    } else if (code) {
+    } else if (type === '3' && code) {
       // 业务查询
       // code直接查询用户返回即可
       condition.code = code;