lrf 7 月之前
父節點
當前提交
b53ba27eac

+ 23 - 20
src/controller/users/contactApply.controller.ts

@@ -26,7 +26,16 @@ export class ContactApplyController {
   @ApiQuery({ name: 'examine' })
   async examine(@Body('id') id: number, @Body('status') status: string) {
     if (!id || !status) throw new ServiceError(ErrorCode.BODY_ERROR);
-    const result = await this.service.update({ id }, { status });
+    const originData = await this.service.fetch({ id });
+    if (!originData) throw new ServiceError(ErrorCode.DATA_NOT_FOUND); // 抛出异常,未找到要审核的数据
+    const user = get(this.ctx, 'user');
+    const exam_admin = get(user, 'id');
+    if (!exam_admin) throw new ServiceError(ErrorCode.ADMIN_NOT_LOGIN); // 抛出异常,无管理员
+    // 需要查询当前管理员所在部门是否有审核的能力,再查询可见的数据
+    const source = await this.service.checkUserSourceRange();
+    const hasPermission = source.find(f => f === get(originData, 'source'));
+    if (!hasPermission) throw new ServiceError(ErrorCode.ADMIN_NOT_LOGIN); // 抛出异常,当前管理人员无审核该数据的权限
+    const result = await this.service.update({ id }, { status, exam_admin });
     if (status === '1') {
       try {
         // 审核成功的发送通知, 生成message,然后发送消息
@@ -69,22 +78,26 @@ export class ContactApplyController {
     // 检查当前 来源数据是否是当前用户的.是当前用户的也不需要继续了,自己找自己么?
     const otherData = await this.service.searchCompleteData(source, source_id);
     const sourceData = get(otherData, 'sourceData');
-    // TODO: 判断是否是 孵化基地 数据,如果是孵化基地,则不需要计算匹配度,就是单纯要信息
-    // 需求,供给,项目,成果都是用name去查询匹配度
-    const keyword = get(sourceData, 'name');
-    // 没有keyword,无法计算匹配度,不用继续往下了.
-    if (!keyword) return; //TODO:抛出异常: 无关键词,无法进行匹配计算
-    // 查询匹配度
-    const result = await this.esService.getCS(keyword, source);
-    if (!result) return; // TODO: 抛出异常,无匹配度到4星,无法进行预约
     const source_user = get(sourceData, 'user');
     const user_id = get(this.ctx, 'user.id');
-    if (user_id === source_user) return; // TODO:抛出异常: 来源数据是当前用户的数据
+    if (user_id === source_user) throw new ServiceError(ErrorCode.CONTACTAPPLY_IS_THIS_USER_DATA); // 抛出异常: 来源数据是当前用户的数据
     /**组织数据,填充联系方式申请表:将被申请方的id填充 */
     const userData = get(otherData, 'userData');
     if (!userData) throw new ServiceError(ErrorCode.CONTACTAPPLY_TARGET_USER_NOT_FOUND);
     const target_user = get(userData, 'id');
     data['target_user'] = target_user;
+    // 检查是否有未审核的申请
+    await this.service.checkHasApply(data);
+    // 判断是否是 孵化基地 数据,如果是孵化基地,则不需要计算匹配度,就是单纯要信息
+    if (source !== 'incubator') {
+      // 需求,供给,项目,成果都是用name去查询匹配度
+      const keyword = get(sourceData, 'name');
+      // 没有keyword,无法计算匹配度,不用继续往下了.
+      if (!keyword) throw new ServiceError(ErrorCode.CONTACTAPPLY_NO_KEYWORD); //抛出异常: 无关键词,无法进行匹配计算
+      // 查询匹配度
+      const result = await this.esService.getCS(keyword, source);
+      if (!result) throw new ServiceError(ErrorCode.CONTACTAPPLY_MATCHING_NOT_ENOUGH); // 抛出异常,无匹配度到4星,无法进行预约
+    }
     /**创建申请数据 */
     const dbData = await this.service.create(data);
     /**找到应该接收该消息的管理员:通过消息类型分配的部门,发送给部门下的所有管理员
@@ -104,14 +117,4 @@ export class ContactApplyController {
     }
     return dbData;
   }
-
-  @Post('/status/:id', { routerName: `审核${namePrefix}申请` })
-  @ApiTags('审核申请')
-  @Validate()
-  async update(@Param('id') id: number, @Body('status') status: string) {
-    if (!id) throw new ServiceError(ErrorCode.ID_NOT_FOUND);
-    const result = await this.service.update({ id }, { status });
-    this.service.sendMqMsg(id);
-    return result;
-  }
 }

+ 3 - 0
src/entity/platform/design.entity.ts

@@ -23,4 +23,7 @@ export class Design extends BaseModel {
   friendship: Array<any>;
   @Column({ type: 'jsonb', nullable: true, comment: '网站底部信息', default: {} })
   footInfo: object;
+  @Column({ type: 'jsonb', nullable: true, comment: '联系申请部门审核设置', default: {} })
+  contactApplyConfig: object;
+
 }

+ 8 - 0
src/error/service.error.ts

@@ -5,6 +5,7 @@ export enum ErrorCode {
   ES_INDEX_NOT_FOUND = 'ES_INDEX_NOT_FOUND',
   ES_DATA_NOT_FOUND = 'ES_DATA_NOT_FOUND',
   NOT_LOGIN = 'NOT_LOGIN',
+  ADMIN_NOT_LOGIN = 'ADMIN_NOT_LOGIN',
   ACCOUNT_HAS_EXPIRED = 'ACCOUNT_HAS_EXPIRED',
   ACCOUNT_LOGGED_IN_ELESWHERE = 'ACCOUNT_LOGGED_IN_ELESWHERE',
   USER_NOT_FOUND = 'USER_NOT_FOUND',
@@ -31,7 +32,14 @@ export enum ErrorCode {
   // contactApply
   CONTACTAPPLY_TARGET_USER_NOT_FOUND = 'TARGET_USER_NOT_FOUND',
   CONTACTAPPLY_HAS_APPLY_NOT_STATUS = 'CONTACTAPPLY_HAS_APPLY_NOT_STATUS',
+  CONTACTAPPLY_NO_PERMISSION = 'CONTACTAPPLY_NO_PERMISSION',
+  CONTACTAPPLY_NO_KEYWORD = 'CONTACTAPPLY_NO_KEYWORD',
+  CONTACTAPPLY_MATCHING_NOT_ENOUGH = 'CONTACTAPPLY_MATCHING_NOT_ENOUGH',
+  CONTACTAPPLY_IS_THIS_USER_DATA='CONTACTAPPLY_IS_THIS_USER_DATA',
+  CONTACTAPPLY_DEPT_NO_ADMIN='CONTACTAPPLY_DEPT_NO_ADMIN',
   SERVICE_APPLY = 'SERVICE_APPLY',
+
+  DATA_NOT_FOUND = 'DATA_NOT_FOUND',
 }
 export class ServiceError extends Error {
   constructor(errcode: string) {

+ 9 - 1
src/service/initData/initSystemData.service.ts

@@ -740,13 +740,21 @@ export class InitSystemDataService {
         ],
       },
       {
-        name: '申请审核',
+        name: '审核管理',
         path: '/exam/index',
         type: '1',
         is_default: '0',
         is_use: '0',
         route_name: 'exam',
         children: [
+          {
+            name: '审核设置',
+            component: 'setting',
+            type: '2',
+            is_default: '0',
+            is_use: '0',
+            route_name: 'exam_setting',
+          },
           {
             name: '联系申请',
             component: 'contact',

+ 21 - 78
src/service/users/contactApply.service.ts

@@ -11,12 +11,16 @@ import { User } from '../../entity/system/user.entity';
 import { ErrorCode, ServiceError } from '../../error/service.error';
 import { MessageUserType } from '../../public/var';
 import { Admin } from '../../entity/system/admin.entity';
+import { Design } from '../../entity/platform/design.entity';
 
 @Provide()
 export class ContactApplyService extends BaseServiceV2 {
   getQueryColumnsOpera(): object {
     return {};
   }
+  @InjectEntityModel(Design)
+  design: Repository<Design>;
+
   @InjectEntityModel(ContactApply)
   model: Repository<ContactApply>;
 
@@ -39,8 +43,8 @@ export class ContactApplyService extends BaseServiceV2 {
    */
   async successMessage(id) {
     const apply = await this.model.createQueryBuilder().where(`id =:id`, { id }).getOne();
-    // TODO: 抛异常,未找到数据
-    if (!apply) return;
+    // 抛异常,未找到数据
+    if (!apply) throw new ServiceError(ErrorCode.DATA_NOT_FOUND);
     const source = get(apply, 'source');
     const source_id = get(apply, 'source_id');
     const mqTarget = get(apply, 'apply_user');
@@ -127,15 +131,15 @@ export class ContactApplyService extends BaseServiceV2 {
     if (is_super === '0') return [];
     // 接下来取出部门
     const dept = get(user, 'dept');
-    // TODO: 抛出异常: 本管理员无部门,无法查询预约申请
-    if (!dept) return;
-    // TODO: 需要从系统设置中查询配置
-    const config = { messageConfig: { demand: 20, supply: 20, project: 20, achievement: 21, incubator: 21 } };
-    const msgConfig = get(config, 'messageConfig', {});
+    // 抛出异常: 本管理员无部门,无法查询预约申请
+    if (!dept) throw new ServiceError(ErrorCode.CONTACTAPPLY_DEPT_NO_ADMIN);
+    const config = await this.design.createQueryBuilder().getOne();
+    if (!config) throw new ServiceError(ErrorCode.DATA_NOT_FOUND);
+    const setting = get(config, 'contactApplyConfig', {});
     // 整理出本部门管理的数据来源
-    const sources = [];
-    for (const key in msgConfig) {
-      const val = msgConfig[key];
+    const sources: Array<string> = [];
+    for (const key in setting) {
+      const val = setting[key];
       if (val === dept) sources.push(key);
     }
     return sources;
@@ -146,9 +150,10 @@ export class ContactApplyService extends BaseServiceV2 {
    * @param source 数据来源
    */
   async getSourceDept(source: string) {
-    // TODO: 需要从系统设置中查询配置
-    const config = { messageConfig: { demand: 20, supply: 20, project: 20, achievement: 21, incubator: 21 } };
-    const dept_id = get(config, `messageConfig.${source}`);
+    const config = await this.design.createQueryBuilder().getOne();
+    if (!config) throw new ServiceError(ErrorCode.DATA_NOT_FOUND);
+    const setting = get(config, 'contactApplyConfig', {});
+    const dept_id = get(setting, `${source}`);
     if (!dept_id) return;
     const adminList = await this.admin.createQueryBuilder().where(`dept =:dept`, { dept: dept_id }).getMany();
     const ids = adminList.map(i => i.id);
@@ -180,65 +185,6 @@ export class ContactApplyService extends BaseServiceV2 {
     return messageData;
   }
 
-  /**
-   * 发送mq消息
-   * 如果status是0,那就给被申请人发送;如果是1,那就给申请人发送联系方式,如果是-1:那就给申请人发送拒绝申请
-   * 需求是先从需求中找联系方式,没有再从用户中招,其余的都直接从用户中找
-   * @param id 数据id
-   */
-  async sendMqMsg(id) {
-    const data = await this.model.createQueryBuilder().where(`"id" = :id`, { id }).getOne();
-    if (!data) return;
-    const status = get(data, 'status');
-    const source = get(data, 'source');
-    const source_id = get(data, 'source_id');
-    const otherData = await this.searchCompleteData(source, source_id);
-    const targetUserData = await this.getUserData(get(data, 'target_user'));
-    const applyUserData = await this.getUserData(get(data, 'apply_user'));
-    let sourceStr = this.getSourceZh(source);
-    let sourceProp = 'name';
-    let sourcePropValue;
-    let mqTarget;
-    let msgStr;
-    let mqUserType = MessageUserType.USER;
-    let mqUserNickName;
-    const sourceData = get(otherData, 'sourceData');
-    if (sourceProp) sourcePropValue = get(sourceData, sourceProp);
-    switch (status) {
-      case '0':
-        // 给被申请人发送和mq消息
-        mqTarget = get(data, 'target_user');
-        mqUserNickName = get(targetUserData, 'nick_name');
-        const apply_userName = get(applyUserData, 'nick_name');
-        msgStr = `用户${apply_userName} 通过 ${sourceStr}数据 ${sourcePropValue ? `- ${sourcePropValue}` : ''} 申请获取您的联系方式!`;
-        break;
-      case '1':
-        // 给申请人发送消息和mq消息
-        mqTarget = get(data, 'apply_user');
-        mqUserNickName = get(applyUserData, 'nick_name');
-        const contacts = this.getContactObject(otherData, source);
-        msgStr = `您通过 ${sourceStr}数据 ${sourcePropValue ? `- ${sourcePropValue}` : ''} 获取对方联系方式的申请已通过.`;
-        // 拼接联系方式
-        const person = get(contacts, 'person');
-        if (person) msgStr = `${msgStr} 联系人: ${person};`;
-        const phone = get(contacts, 'phone');
-        if (phone) msgStr = `${msgStr} 联系电话: ${phone};`;
-        const email = get(contacts, 'email');
-        if (email) msgStr = `${msgStr} 邮箱: ${email}`;
-        break;
-      case '-1':
-        mqTarget = get(data, 'apply_user');
-        mqUserNickName = get(applyUserData, 'nick_name');
-        msgStr = `您通过 ${sourceStr}数据 ${sourcePropValue ? `- ${sourcePropValue}` : ''} 获取对方联系方式的申请已被拒绝.`;
-        break;
-      default:
-        break;
-    }
-    // 创建消息,发送
-    const to = [{ user: mqTarget, user_type: mqUserType, user_nick_name: mqUserNickName, is_read: '0' }];
-    const msgObj = { content: msgStr, to, type: '0' };
-    return msgObj;
-  }
   /**
    * 获取用户数据
    * @param id 用户id
@@ -249,7 +195,8 @@ export class ContactApplyService extends BaseServiceV2 {
     return user;
   }
   /**
-   * 根据 apply_user ,target_user检查是否有过申请且已通过审核的数据
+   * 根据 apply_user ,target_user检查是否有未通过审核的数据
+   * 允许重复多次申请,但是每次必须都得审核完后再申请
    * 如果有:直接返回信息;
    * 如果没有,返回继续执行
    * @param data
@@ -258,11 +205,7 @@ export class ContactApplyService extends BaseServiceV2 {
     const apply_user = get(data, 'apply_user');
     const target_user = get(data, 'target_user');
     const builder = this.model.createQueryBuilder().where(`"apply_user" = :apply_user`, { apply_user }).andWhere(`"target_user" = :target_user`, { target_user });
-    const apply = await builder.andWhere(`"status" = :status`, { status: '1' }).getOne();
-    if (apply) {
-      const msgObj = await this.sendMqMsg(get(apply, 'id'));
-      return { status: '1', content: msgObj.content };
-    }
+    // const apply = await builder.andWhere(`"status" = :status`, { status: '1' }).getOne();
     // 查询是不是有其他状态的申请: 未审核,已拒绝,如果有,就根据状态返回提示语
     const othersApply = await builder.getOne();
     // 没有找到其他的申请,直接返回