zs 2 năm trước cách đây
mục cha
commit
00978283c6

+ 4 - 0
src/controller/user/admin.controller.ts

@@ -39,6 +39,7 @@ import get = require('lodash/get');
 import lowerCase = require('lodash/lowerCase');
 import { RegisterCanNotIncludes } from '../../util/util';
 import { UserUtilService } from '../../service/util/user.util';
+import { UtilService } from '../../service/util/util';
 @ApiTags(['管理员表'])
 @Controller('/admin')
 export class AdminController extends BaseController {
@@ -54,6 +55,8 @@ export class AdminController extends BaseController {
 
   @Inject()
   userUtil: UserUtilService;
+  @Inject()
+  util: UtilService;
 
   @Post('/login')
   @Validate()
@@ -110,6 +113,7 @@ export class AdminController extends BaseController {
     @Query('skip') skip: number,
     @Query('limit') limit: number
   ) {
+    filter = this.util.turnDateRangeQuery(this.util.turnFilter(filter));
     const list = await this.service.query(filter, { skip, limit });
     const data = [];
     for (const i of list) {

+ 36 - 1
src/controller/user/expert.controller.ts

@@ -36,6 +36,7 @@ import {
 import { Validate } from '@midwayjs/validate';
 import { UserUtilService } from '../../service/util/user.util';
 import { JwtService } from '@midwayjs/jwt';
+import { UtilService } from '../../service/util/util';
 import get = require('lodash/get');
 @ApiTags(['专家用户'])
 @Controller('/expert')
@@ -53,6 +54,9 @@ export class ExpertController extends BaseController {
   @Config('jwt.expiresIn')
   jwtExpiresIn;
 
+  @Inject()
+  util: UtilService;
+
   @Post('/login')
   @Validate()
   async login(@Body() body: LoginDTO) {
@@ -100,7 +104,38 @@ export class ExpertController extends BaseController {
     @Query('skip') skip: number,
     @Query('limit') limit: number
   ) {
-    const list = await this.service.query(filter, { skip, limit });
+    filter = this.util.dealQuery(filter);
+    const { code, status, company, name, phone } = filter;
+    let query: any = {};
+    if (code) query.code = code;
+    if (status) query.status = status;
+    if (name) query.name = name;
+    if (phone) query.phone = phone;
+    if (company) {
+      if (company === '中科系') {
+        query.company = {
+          $in: [
+            '中科院长春分院',
+            '中国科学院东北地理与农业生态研究所',
+            '中国科学院长春应用化学研究所',
+            '中科院长春光学精密机械与物理研究所',
+          ],
+        };
+      } else if (company === '其他') {
+        query.company = {
+          $nin: [
+            '中科院长春分院',
+            '中国科学院东北地理与农业生态研究所',
+            '中国科学院长春应用化学研究所',
+            '中科院长春光学精密机械与物理研究所',
+            '吉林大学',
+            '长春工业大学',
+          ],
+        };
+      } else query.company = company;
+    }
+    query = await this.service.dealQueryCondition(query);
+    const list = await this.service.query(query, { skip, limit });
     const data = [];
     for (const i of list) {
       const newData = new QVO_expert(i);

+ 2 - 1
src/controller/user/personal.controller.ts

@@ -100,7 +100,8 @@ export class PersonalController extends BaseController {
     @Query('skip') skip: number,
     @Query('limit') limit: number
   ) {
-    const list = await this.service.query(filter, { skip, limit });
+    const query: any = 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_personal(i);

+ 3 - 0
src/interface/user/expert.interface.ts

@@ -82,6 +82,7 @@ export class QDTO_expert extends SearchBase {
       'email',
       'card',
       'status',
+      'company',
     ];
     const mapping = [];
     super({ like_prop, props, mapping });
@@ -102,6 +103,8 @@ export class QDTO_expert extends SearchBase {
   'card': string = undefined;
   @ApiProperty({ description: '状态' })
   'status': string = undefined;
+  @ApiProperty({ description: '单位名称' })
+  'company': string = undefined;
 }
 
 export class QVO_expert extends FVO_expert {

+ 1 - 1
src/service/user/admin.service.ts

@@ -20,7 +20,7 @@ export class AdminService extends BaseService<modelType> {
     const user = await this.model.findOne({ account }, '+password').lean();
     if (!user)
       throw new ServiceError(
-        '未找到用户信息',
+        '未找到管理员信息',
         FrameworkErrorEnum.NOT_FOUND_DATA
       );
     if (!isEqual(user.password.secret, password))

+ 3 - 3
src/service/user/company.service.ts

@@ -21,12 +21,12 @@ export class CompanyService extends BaseService<modelType> {
     const user = await this.model.findOne({ account }, '+password').lean();
     if (!user)
       throw new ServiceError(
-        '未找到用户信息',
+        '未找到企业用户信息',
         FrameworkErrorEnum.NOT_FOUND_DATA
       );
-    if (get(user, 'exam_status') !== '1')
+    if (get(user, 'status') !== '1')
       throw new ServiceError(
-        '当前用户没有通过审核,拒绝登录',
+        '当前企业用户没有通过审核,拒绝登录',
         FrameworkErrorEnum.SERVICE_FAULT
       );
     if (!isEqual(user.password.secret, password))

+ 64 - 4
src/service/user/expert.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,30 +7,90 @@ import {
   ServiceError,
 } 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 isEqual = require('lodash/isEqual');
 import get = require('lodash/get');
+import head = require('lodash/head');
+import { UtilService } from '../../service/util/util';
 type modelType = ReturnModelType<typeof Expert>;
 @Provide()
 export class ExpertService extends BaseService<modelType> {
   @InjectEntityModel(Expert)
   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();
     if (!user)
       throw new ServiceError(
-        '未找到用户信息',
+        '未找到专家用户信息',
         FrameworkErrorEnum.NOT_FOUND_DATA
       );
-    if (get(user, 'exam_status') !== '1')
+    if (get(user, 'status') !== '1')
       throw new ServiceError(
-        '当前用户没有通过审核,拒绝登录',
+        '当前专家用户没有通过审核,拒绝登录',
         FrameworkErrorEnum.SERVICE_FAULT
       );
     if (!isEqual(user.password.secret, password))
       throw new ServiceError('密码错误', FrameworkErrorEnum.SERVICE_FAULT);
     return user;
   }
+  async dealQueryCondition({ code, ...condition }) {
+    const role = this.ctx.user.type;
+    condition = this.util.dealQuery(condition);
+    // 查询业务管理
+    const busFind = async query =>
+      await this.adminModel.find({ ...query, role: '3' }, { code: 1 });
+    // 查询机构管理
+    const orgFind = async query =>
+      await this.adminModel.find({ ...query, role: '2' }, { code: 1 });
+    // 查询管理员
+    const aFind = async query =>
+      await this.adminModel.find({ ...query, role: '1' }, { code: 1 });
+    if (role === '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 = [
+        ...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 ServiceError(
+          '未找到该机构',
+          FrameworkErrorEnum.NOT_FOUND_DATA
+        );
+      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;
+    }
+    // 没有code,超级管理员,说明不限制
+    return condition;
+  }
 }

+ 64 - 4
src/service/user/personal.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,30 +7,90 @@ import {
   ServiceError,
 } from 'free-midway-component';
 import { Personal } from '../../entity/user/personal.entity';
+import { Admin } from '../../entity/user/admin.entity';
 import { LoginDTO } from '../../interface/user/personal.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 Personal>;
 @Provide()
 export class PersonalService extends BaseService<modelType> {
   @InjectEntityModel(Personal)
   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();
     if (!user)
       throw new ServiceError(
-        '未找到用户信息',
+        '未找到个人用户信息',
         FrameworkErrorEnum.NOT_FOUND_DATA
       );
-    if (get(user, 'exam_status') !== '1')
+    if (get(user, 'status') !== '1')
       throw new ServiceError(
-        '当前用户没有通过审核,拒绝登录',
+        '当前个人用户没有通过审核,拒绝登录',
         FrameworkErrorEnum.SERVICE_FAULT
       );
     if (!isEqual(user.password.secret, password))
       throw new ServiceError('密码错误', FrameworkErrorEnum.SERVICE_FAULT);
     return user;
   }
+  async dealQueryCondition({ code, ...condition }) {
+    const role = this.ctx.user.type;
+    condition = this.util.dealQuery(condition);
+    // 查询业务管理
+    const busFind = async query =>
+      await this.adminModel.find({ ...query, role: '3' }, { code: 1 });
+    // 查询机构管理
+    const orgFind = async query =>
+      await this.adminModel.find({ ...query, role: '2' }, { code: 1 });
+    // 查询管理员
+    const aFind = async query =>
+      await this.adminModel.find({ ...query, role: '1' }, { code: 1 });
+    if (role === '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 = [
+        ...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 ServiceError(
+          '未找到该机构',
+          FrameworkErrorEnum.NOT_FOUND_DATA
+        );
+      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;
+    }
+    // 没有code,超级管理员,说明不限制
+    return condition;
+  }
 }

+ 2 - 2
src/service/util/user.util.ts

@@ -84,7 +84,7 @@ export class UserUtilService {
    * @param data 参数
    */
   async checkUpdateCardAndPid(id, data: CheckUpdateCardAndPid) {
-    const { phone, code } = data;
+    const { phone, code, name } = data;
     if (phone && code) {
       const personalan = await this.personalModel.count({
         _id: { $ne: id },
@@ -94,7 +94,7 @@ export class UserUtilService {
       });
       if (personalan > 0)
         throw new ServiceError(
-          `姓名:${data.name} ; 手机号: ${data.phone} ;已有机构所属的个人用户使用该手机号`,
+          `姓名:${name} ; 手机号: ${phone} ;已有机构所属的个人用户使用该手机号`,
           FrameworkErrorEnum.BAD_BODY
         );
     }

+ 151 - 0
src/service/util/util.ts

@@ -0,0 +1,151 @@
+import { Provide } from '@midwayjs/decorator';
+import { Inject } from '@midwayjs/core';
+import { Context } from '@midwayjs/koa';
+const Excel = require('exceljs');
+import * as fs from 'node:fs';
+import * as Path from 'node:path';
+import get = require('lodash/get');
+@Provide()
+export class UtilService {
+  @Inject()
+  ctx: Context;
+
+  async utilMethod(query, body) {
+    // console.log(this.mq);
+    this.ctx.service.patent.patentinfo.export({
+      query: { apply_personal: '长春' },
+    });
+    // return res;
+  }
+
+  async expertExport() {
+    const { data } = await this.ctx.service.users.expert.query();
+    const root_path = 'E:\\exportFile\\';
+    const file_type = '';
+    if (!fs.existsSync(`${root_path}${file_type}`)) {
+      // 如果不存在文件夹,就创建
+      fs.mkdirSync(`${root_path}${file_type}`);
+    }
+    const workbook = new Excel.Workbook();
+    const sheet = workbook.addWorksheet('sheet');
+    const meta = this.getHeader();
+    const head = meta.map(i => i.label);
+    // sheet.addRows(head);
+    const rows = [];
+    rows.push(head);
+    for (let i = 0; i < data.length; i++) {
+      const e = data[i];
+      const row = [];
+      let imgid;
+      for (const obj of meta) {
+        const { key } = obj;
+        if (key !== 'img_path') {
+          row.push(e[key] || '');
+        } else if (e.img_path) {
+          try {
+            const suffix = Path.extname(e.img_path).substring(1);
+            // 先请求图片buffer,然后addImage存起来
+            const res = await this.ctx.curl(
+              `http://broadcast.waityou24.cn${e.img_path}`
+            );
+            if (res.status === 200) {
+              const buffer = res.data;
+              imgid = workbook.addImage({
+                buffer,
+                extension: suffix,
+              });
+            }
+          } catch (error) {
+            console.log(`${e.name}图片下载失败`);
+          }
+        }
+      }
+      rows.push(row);
+      if (imgid || imgid === 0) {
+        sheet.addImage(imgid, {
+          tl: { col: 15.2, row: i + 1 + 0.2 },
+          br: { col: 16, row: i + 1 + 1 },
+          editAs: 'oneCell',
+        });
+      }
+    }
+    sheet.addRows(rows);
+    const filepath = `${root_path}专家导出.xlsx`;
+    await workbook.xlsx.writeFile(filepath);
+  }
+
+  getHeader() {
+    return [
+      { key: 'name', label: '用户姓名' },
+      { key: 'phone', label: '联系电话' },
+      { key: 'education', label: '最高学历' },
+      { key: 'school', label: '毕业学校' },
+      { key: 'birthDate', label: '出生日期' },
+      { key: 'email', label: '电子邮箱' },
+      { key: 'qqwx', label: 'QQ/微信' },
+      { key: 'company', label: '工作单位' },
+      { key: 'zwzc', label: '职务职称' },
+      { key: 'expertise', label: '擅长领域' },
+      { key: 'workexperience', label: '工作经历' },
+      { key: 'scientific', label: '科研综述' },
+      { key: 'undertakingproject', label: '承担项目' },
+      { key: 'scienceaward', label: '科技奖励' },
+      { key: 'social', label: '社会任职' },
+      { key: 'img_path', label: '用户头像' },
+    ];
+  }
+
+  dealQuery(query) {
+    return this.turnFilter(this.turnDateRangeQuery(query));
+  }
+
+  /**
+   * 将查询条件中模糊查询的标识转换成对应object
+   * @param {Object} filter 查询条件
+   */
+  turnFilter(filter) {
+    const str = /^%\S*%$/;
+    const keys = Object.keys(filter);
+    for (const key of keys) {
+      const res = key.match(str);
+      if (res) {
+        const newKey = key.slice(1, key.length - 1);
+        filter[newKey] = new RegExp(filter[key]);
+        delete filter[key];
+      }
+    }
+    return filter;
+  }
+  /**
+   * 将时间转换成对应查询Object
+   * @param {Object} filter 查询条件
+   */
+  turnDateRangeQuery(filter) {
+    const keys = Object.keys(filter);
+    for (const k of keys) {
+      if (k.includes('@')) {
+        const karr = k.split('@');
+        if (karr.length === 2) {
+          const type = karr[1];
+          if (type === 'start') {
+            if (filter[k] && filter[k] !== '') {
+              filter[karr[0]] = {
+                ...get(filter, karr[0], {}),
+                $gte: filter[k],
+              };
+            }
+          } else {
+            if (filter[k] && filter[k] !== '') {
+              filter[karr[0]] = {
+                ...get(filter, karr[0], {}),
+                $lte: filter[k],
+              };
+            }
+          }
+          delete filter[k];
+        }
+      }
+    }
+    return filter;
+  }
+}