|
@@ -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();
|
|
|
// 没有找到其他的申请,直接返回
|