|
@@ -1,4 +1,4 @@
|
|
-import { Provide } from '@midwayjs/decorator';
|
|
|
|
|
|
+import { Provide, Inject } from '@midwayjs/decorator';
|
|
import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
import { ReturnModelType } from '@typegoose/typegoose';
|
|
import { ReturnModelType } from '@typegoose/typegoose';
|
|
import {
|
|
import {
|
|
@@ -7,14 +7,20 @@ import {
|
|
ServiceError,
|
|
ServiceError,
|
|
} from 'free-midway-component';
|
|
} from 'free-midway-component';
|
|
import { Admin } from '../../entity/user/admin.entity';
|
|
import { Admin } from '../../entity/user/admin.entity';
|
|
-import { LoginDTO } from '../../interface/user/admin.interface';
|
|
|
|
|
|
+import { LoginDTO, QDTO_admin } from '../../interface/user/admin.interface';
|
|
import isEqual = require('lodash/isEqual');
|
|
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 Admin>;
|
|
type modelType = ReturnModelType<typeof Admin>;
|
|
@Provide()
|
|
@Provide()
|
|
export class AdminService extends BaseService<modelType> {
|
|
export class AdminService extends BaseService<modelType> {
|
|
@InjectEntityModel(Admin)
|
|
@InjectEntityModel(Admin)
|
|
model: modelType;
|
|
model: modelType;
|
|
|
|
|
|
|
|
+ @Inject()
|
|
|
|
+ util: UtilService;
|
|
|
|
+
|
|
async findUserToLogin(data: LoginDTO): Promise<object> {
|
|
async findUserToLogin(data: LoginDTO): Promise<object> {
|
|
const { account, password } = data;
|
|
const { account, password } = data;
|
|
const user = await this.model.findOne({ account }, '+password').lean();
|
|
const user = await this.model.findOne({ account }, '+password').lean();
|
|
@@ -27,4 +33,55 @@ export class AdminService extends BaseService<modelType> {
|
|
throw new ServiceError('密码错误', FrameworkErrorEnum.SERVICE_FAULT);
|
|
throw new ServiceError('密码错误', FrameworkErrorEnum.SERVICE_FAULT);
|
|
return user;
|
|
return user;
|
|
}
|
|
}
|
|
|
|
+ async dealQueryCondition(condition: QDTO_admin): Promise<QDTO_admin> {
|
|
|
|
+ const { type, code } = this.ctx.user;
|
|
|
|
+ condition = this.util.dealQuery(condition);
|
|
|
|
+ // 查询业务管理
|
|
|
|
+ const busFind = async query =>
|
|
|
|
+ await this.model.find({ ...query, type: '3' }, { code: 1 });
|
|
|
|
+ // 查询机构管理
|
|
|
|
+ const orgFind = async query =>
|
|
|
|
+ await this.model.find({ ...query, type: '2' }, { code: 1 });
|
|
|
|
+ // 查询管理员
|
|
|
|
+ const aFind = async query =>
|
|
|
|
+ await this.model.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;
|
|
|
|
+ }
|
|
}
|
|
}
|