feat: 修改message单独一个module,修改默认json字段 (#90)
This commit is contained in:
parent
84a3b6e6fa
commit
a357b49824
31
server/src/modules/message/messagePushing.module.ts
Normal file
31
server/src/modules/message/messagePushing.module.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { MessagePushingTaskService } from './services/messagePushingTask.service';
|
||||||
|
import { MessagePushingLogService } from './services/messagePushingLog.service';
|
||||||
|
|
||||||
|
import { MessagePushingTaskController } from './controllers/messagePushingTask.controller';
|
||||||
|
|
||||||
|
import { MessagePushingTask } from 'src/models/messagePushingTask.entity';
|
||||||
|
import { MessagePushingLog } from 'src/models/messagePushingLog.entity';
|
||||||
|
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
|
||||||
|
import { AuthModule } from '../auth/auth.module';
|
||||||
|
|
||||||
|
import { LoggerProvider } from 'src/logger/logger.provider';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([MessagePushingTask, MessagePushingLog]),
|
||||||
|
ConfigModule,
|
||||||
|
AuthModule,
|
||||||
|
],
|
||||||
|
controllers: [MessagePushingTaskController],
|
||||||
|
providers: [
|
||||||
|
MessagePushingTaskService,
|
||||||
|
MessagePushingLogService,
|
||||||
|
LoggerProvider,
|
||||||
|
],
|
||||||
|
exports: [MessagePushingTaskService],
|
||||||
|
})
|
||||||
|
export class MessagePushingModule {}
|
@ -7,12 +7,16 @@ import { CreateMessagePushingTaskDto } from '../dto/createMessagePushingTask.dto
|
|||||||
import { UpdateMessagePushingTaskDto } from '../dto/updateMessagePushingTask.dto';
|
import { UpdateMessagePushingTaskDto } from '../dto/updateMessagePushingTask.dto';
|
||||||
import { ObjectId } from 'mongodb';
|
import { ObjectId } from 'mongodb';
|
||||||
import { RECORD_STATUS } from 'src/enums';
|
import { RECORD_STATUS } from 'src/enums';
|
||||||
|
import { MESSAGE_PUSHING_TYPE } from 'src/enums/messagePushing';
|
||||||
|
import { MessagePushingLogService } from './messagePushingLog.service';
|
||||||
|
import fetch from 'node-fetch';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MessagePushingTaskService {
|
export class MessagePushingTaskService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(MessagePushingTask)
|
@InjectRepository(MessagePushingTask)
|
||||||
private readonly messagePushingTaskRepository: MongoRepository<MessagePushingTask>,
|
private readonly messagePushingTaskRepository: MongoRepository<MessagePushingTask>,
|
||||||
|
private readonly messagePushingLogService: MessagePushingLogService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(
|
async create(
|
||||||
@ -146,4 +150,53 @@ export class MessagePushingTaskService {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async runResponseDataPush({ surveyId, sendData }) {
|
||||||
|
try {
|
||||||
|
// 数据推送
|
||||||
|
const messagePushingTasks = await this.findAll({
|
||||||
|
surveyId,
|
||||||
|
hook: MESSAGE_PUSHING_HOOK.RESPONSE_INSERTED,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
Array.isArray(messagePushingTasks) &&
|
||||||
|
messagePushingTasks.length > 0
|
||||||
|
) {
|
||||||
|
for (const task of messagePushingTasks) {
|
||||||
|
switch (task.type) {
|
||||||
|
case MESSAGE_PUSHING_TYPE.HTTP: {
|
||||||
|
try {
|
||||||
|
const res = await fetch(task.pushAddress, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json, */*',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(sendData),
|
||||||
|
});
|
||||||
|
const response = await res.json();
|
||||||
|
await this.messagePushingLogService.createPushingLog({
|
||||||
|
taskId: task._id.toString(),
|
||||||
|
request: sendData,
|
||||||
|
response: response,
|
||||||
|
status: res.status,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
await this.messagePushingLogService.createPushingLog({
|
||||||
|
taskId: task._id.toString(),
|
||||||
|
request: sendData,
|
||||||
|
response: error.data || error.message,
|
||||||
|
status: error.status || 500,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {}
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,21 +12,18 @@ import { SurveyController } from './controllers/survey.controller';
|
|||||||
import { SurveyHistoryController } from './controllers/surveyHistory.controller';
|
import { SurveyHistoryController } from './controllers/surveyHistory.controller';
|
||||||
import { SurveyMetaController } from './controllers/surveyMeta.controller';
|
import { SurveyMetaController } from './controllers/surveyMeta.controller';
|
||||||
import { SurveyUIController } from './controllers/surveyUI.controller';
|
import { SurveyUIController } from './controllers/surveyUI.controller';
|
||||||
import { MessagePushingTaskController } from './controllers/messagePushingTask.controller';
|
|
||||||
|
|
||||||
import { SurveyConf } from 'src/models/surveyConf.entity';
|
import { SurveyConf } from 'src/models/surveyConf.entity';
|
||||||
import { SurveyHistory } from 'src/models/surveyHistory.entity';
|
import { SurveyHistory } from 'src/models/surveyHistory.entity';
|
||||||
import { SurveyMeta } from 'src/models/surveyMeta.entity';
|
import { SurveyMeta } from 'src/models/surveyMeta.entity';
|
||||||
import { SurveyResponse } from 'src/models/surveyResponse.entity';
|
import { SurveyResponse } from 'src/models/surveyResponse.entity';
|
||||||
import { Word } from 'src/models/word.entity';
|
import { Word } from 'src/models/word.entity';
|
||||||
import { MessagePushingTask } from 'src/models/messagePushingTask.entity';
|
|
||||||
|
|
||||||
import { DataStatisticService } from './services/dataStatistic.service';
|
import { DataStatisticService } from './services/dataStatistic.service';
|
||||||
import { SurveyConfService } from './services/surveyConf.service';
|
import { SurveyConfService } from './services/surveyConf.service';
|
||||||
import { SurveyHistoryService } from './services/surveyHistory.service';
|
import { SurveyHistoryService } from './services/surveyHistory.service';
|
||||||
import { SurveyMetaService } from './services/surveyMeta.service';
|
import { SurveyMetaService } from './services/surveyMeta.service';
|
||||||
import { ContentSecurityService } from './services/contentSecurity.service';
|
import { ContentSecurityService } from './services/contentSecurity.service';
|
||||||
import { MessagePushingTaskService } from './services/messagePushingTask.service';
|
|
||||||
|
|
||||||
import { PluginManagerProvider } from 'src/securityPlugin/pluginManager.provider';
|
import { PluginManagerProvider } from 'src/securityPlugin/pluginManager.provider';
|
||||||
|
|
||||||
@ -38,7 +35,6 @@ import { PluginManagerProvider } from 'src/securityPlugin/pluginManager.provider
|
|||||||
SurveyHistory,
|
SurveyHistory,
|
||||||
SurveyResponse,
|
SurveyResponse,
|
||||||
Word,
|
Word,
|
||||||
MessagePushingTask,
|
|
||||||
]),
|
]),
|
||||||
ConfigModule,
|
ConfigModule,
|
||||||
SurveyResponseModule,
|
SurveyResponseModule,
|
||||||
@ -50,7 +46,6 @@ import { PluginManagerProvider } from 'src/securityPlugin/pluginManager.provider
|
|||||||
SurveyHistoryController,
|
SurveyHistoryController,
|
||||||
SurveyMetaController,
|
SurveyMetaController,
|
||||||
SurveyUIController,
|
SurveyUIController,
|
||||||
MessagePushingTaskController,
|
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
DataStatisticService,
|
DataStatisticService,
|
||||||
@ -59,7 +54,6 @@ import { PluginManagerProvider } from 'src/securityPlugin/pluginManager.provider
|
|||||||
SurveyMetaService,
|
SurveyMetaService,
|
||||||
PluginManagerProvider,
|
PluginManagerProvider,
|
||||||
ContentSecurityService,
|
ContentSecurityService,
|
||||||
MessagePushingTaskService,
|
|
||||||
LoggerProvider,
|
LoggerProvider,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
@ -1,15 +1,4 @@
|
|||||||
{
|
{
|
||||||
"bannerConf": {
|
|
||||||
"titleConfig": {
|
|
||||||
"mainTitle": "<h3 style=\"text-align: center\">欢迎填写问卷</h3><p>为了给您提供更好的服务,希望您能抽出几分钟时间,将您的感受和建议告诉我们,<span style=\"color: rgb(204, 0, 0)\">期待您的参与!</span></p>",
|
|
||||||
"subTitle": ""
|
|
||||||
},
|
|
||||||
"bannerConfig": {
|
|
||||||
"bgImage": "/imgs/skin/17e06b7604a007e1d3e1453b9ddadc3c.webp",
|
|
||||||
"videoLink": "",
|
|
||||||
"postImg": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dataConf": {
|
"dataConf": {
|
||||||
"dataList": [
|
"dataList": [
|
||||||
{
|
{
|
||||||
@ -28,8 +17,6 @@
|
|||||||
"maxNum": "",
|
"maxNum": "",
|
||||||
"star": 5,
|
"star": 5,
|
||||||
"placeholderDesc": "",
|
"placeholderDesc": "",
|
||||||
"addressType": 3,
|
|
||||||
"isAuto": false,
|
|
||||||
"urlKey": "",
|
"urlKey": "",
|
||||||
"textRange": {
|
"textRange": {
|
||||||
"min": {
|
"min": {
|
||||||
@ -82,8 +69,6 @@
|
|||||||
"cOptions": [],
|
"cOptions": [],
|
||||||
"star": 5,
|
"star": 5,
|
||||||
"exclude": false,
|
"exclude": false,
|
||||||
"addressType": 3,
|
|
||||||
"isAuto": false,
|
|
||||||
"textRange": {
|
"textRange": {
|
||||||
"min": {
|
"min": {
|
||||||
"placeholder": "0",
|
"placeholder": "0",
|
||||||
@ -96,25 +81,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"submitConf": {
|
|
||||||
"submitTitle": "提交",
|
|
||||||
"confirmAgain": {
|
|
||||||
"is_again": true,
|
|
||||||
"again_text": "确认要提交吗?"
|
|
||||||
},
|
|
||||||
"msgContent": {
|
|
||||||
"msg_200": "提交成功",
|
|
||||||
"msg_9001": "您来晚了,感谢支持问卷~",
|
|
||||||
"msg_9002": "请勿多次提交!",
|
|
||||||
"msg_9003": "您来晚了,已经满额!",
|
|
||||||
"msg_9004": "提交失败!"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"baseConf": {
|
|
||||||
"begTime": "2018-05-22 17:17:48",
|
|
||||||
"endTime": "2028-05-22 17:17:48",
|
|
||||||
"tLimit": "0",
|
|
||||||
"language": "chinese"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,4 @@
|
|||||||
{
|
{
|
||||||
"bannerConf": {
|
|
||||||
"titleConfig": {
|
|
||||||
"mainTitle": "<h3 style=\"text-align: center\">欢迎填写问卷</h3><p>为了给您提供更好的服务,希望您能抽出几分钟时间,将您的感受和建议告诉我们,<span style=\"color: rgb(204, 0, 0)\">期待您的参与!</span></p>",
|
|
||||||
"subTitle": ""
|
|
||||||
},
|
|
||||||
"bannerConfig": {
|
|
||||||
"bgImage": "/imgs/skin/17e06b7604a007e1d3e1453b9ddadc3c.webp",
|
|
||||||
"videoLink": "",
|
|
||||||
"postImg": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dataConf": {
|
"dataConf": {
|
||||||
"dataList": [
|
"dataList": [
|
||||||
{
|
{
|
||||||
@ -28,17 +17,7 @@
|
|||||||
"maxNum": "",
|
"maxNum": "",
|
||||||
"star": 5,
|
"star": 5,
|
||||||
"exclude": false,
|
"exclude": false,
|
||||||
"relTypes": {
|
|
||||||
"textarea": "多行文本框",
|
|
||||||
"text": "单行输入框"
|
|
||||||
},
|
|
||||||
"placeholderDesc": "",
|
"placeholderDesc": "",
|
||||||
"mhLimit": 0,
|
|
||||||
"addressType": 3,
|
|
||||||
"isAuto": false,
|
|
||||||
"jumpTo": "",
|
|
||||||
"startDate": "",
|
|
||||||
"endDate": "",
|
|
||||||
"textRange": {
|
"textRange": {
|
||||||
"min": {
|
"min": {
|
||||||
"placeholder": "0",
|
"placeholder": "0",
|
||||||
@ -105,8 +84,6 @@
|
|||||||
],
|
],
|
||||||
"star": 5,
|
"star": 5,
|
||||||
"exclude": false,
|
"exclude": false,
|
||||||
"addressType": 3,
|
|
||||||
"isAuto": false,
|
|
||||||
"urlKey": "",
|
"urlKey": "",
|
||||||
"defaultProps": {
|
"defaultProps": {
|
||||||
"children": "children",
|
"children": "children",
|
||||||
@ -127,26 +104,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"submitConf": {
|
|
||||||
"submitTitle": "提交",
|
|
||||||
"confirmAgain": {
|
|
||||||
"is_again": true,
|
|
||||||
"again_text": "确认要提交吗?"
|
|
||||||
},
|
|
||||||
"msgContent": {
|
|
||||||
"msg_200": "提交成功",
|
|
||||||
"msg_9001": "您来晚了,感谢支持问卷~",
|
|
||||||
"msg_9002": "请勿多次提交!",
|
|
||||||
"msg_9003": "您来晚了,已经满额!",
|
|
||||||
"msg_9004": "提交失败!"
|
|
||||||
},
|
|
||||||
"link": ""
|
|
||||||
},
|
|
||||||
"baseConf": {
|
|
||||||
"begTime": "2018-05-22 17:17:48",
|
|
||||||
"endTime": "2028-05-22 17:17:48",
|
|
||||||
"tLimit": "0",
|
|
||||||
"language": "chinese"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,4 @@
|
|||||||
{
|
{
|
||||||
"bannerConf": {
|
|
||||||
"titleConfig": {
|
|
||||||
"mainTitle": "<h3 style=\"text-align: center\">欢迎填写问卷</h3><p>为了给您提供更好的服务,希望您能抽出几分钟时间,将您的感受和建议告诉我们,<span style=\"color: rgb(204, 0, 0)\">期待您的参与!</span></p>",
|
|
||||||
"subTitle": ""
|
|
||||||
},
|
|
||||||
"bannerConfig": {
|
|
||||||
"bgImage": "/imgs/skin/17e06b7604a007e1d3e1453b9ddadc3c.webp",
|
|
||||||
"videoLink": "",
|
|
||||||
"postImg": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dataConf": {
|
"dataConf": {
|
||||||
"dataList": [
|
"dataList": [
|
||||||
{
|
{
|
||||||
@ -29,13 +18,7 @@
|
|||||||
"maxNum": "",
|
"maxNum": "",
|
||||||
"star": 5,
|
"star": 5,
|
||||||
"exclude": false,
|
"exclude": false,
|
||||||
"relTypes": {
|
|
||||||
"textarea": "多行文本框",
|
|
||||||
"text": "单行输入框"
|
|
||||||
},
|
|
||||||
"placeholderDesc": "",
|
"placeholderDesc": "",
|
||||||
"addressType": 3,
|
|
||||||
"isAuto": false,
|
|
||||||
"urlKey": "",
|
"urlKey": "",
|
||||||
"textRange": {
|
"textRange": {
|
||||||
"min": {
|
"min": {
|
||||||
@ -84,7 +67,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"star": 5,
|
"star": 5,
|
||||||
"addressType": 3,
|
|
||||||
"textRange": {
|
"textRange": {
|
||||||
"min": {
|
"min": {
|
||||||
"placeholder": "0",
|
"placeholder": "0",
|
||||||
@ -97,25 +79,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"submitConf": {
|
|
||||||
"submitTitle": "提交",
|
|
||||||
"confirmAgain": {
|
|
||||||
"is_again": true,
|
|
||||||
"again_text": "确认要提交吗?"
|
|
||||||
},
|
|
||||||
"msgContent": {
|
|
||||||
"msg_200": "提交成功",
|
|
||||||
"msg_9001": "您来晚了,感谢支持问卷~",
|
|
||||||
"msg_9002": "请勿多次提交!",
|
|
||||||
"msg_9003": "您来晚了,已经满额!",
|
|
||||||
"msg_9004": "提交失败!"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"baseConf": {
|
|
||||||
"begTime": "2018-05-25 10:22:23",
|
|
||||||
"endTime": "2028-05-25 10:22:23",
|
|
||||||
"tLimit": "0",
|
|
||||||
"language": "chinese"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,12 @@
|
|||||||
"logoImageWidth": "60%"
|
"logoImageWidth": "60%"
|
||||||
},
|
},
|
||||||
"baseConf": {
|
"baseConf": {
|
||||||
"begTime": "2018-05-30 10:38:31",
|
"begTime": "2024-01-01 00:00:00",
|
||||||
"endTime": "2028-05-30 10:38:31",
|
"endTime": "2034-01-01 00:00:00",
|
||||||
"tLimit": "0",
|
"tLimit": 0,
|
||||||
"language": "chinese",
|
"language": "chinese",
|
||||||
"showVoteProcess": "allow"
|
"answerBegTime": "00:00:00",
|
||||||
|
"answerEndTime": "23:59:59"
|
||||||
},
|
},
|
||||||
"skinConf": {
|
"skinConf": {
|
||||||
"skinColor": "#4a4c5b",
|
"skinColor": "#4a4c5b",
|
||||||
|
@ -4,24 +4,18 @@ import { SurveyNotFoundException } from 'src/exceptions/surveyNotFoundException'
|
|||||||
import { checkSign } from 'src/utils/checkSign';
|
import { checkSign } from 'src/utils/checkSign';
|
||||||
import { ENCRYPT_TYPE } from 'src/enums/encrypt';
|
import { ENCRYPT_TYPE } from 'src/enums/encrypt';
|
||||||
import { EXCEPTION_CODE } from 'src/enums/exceptionCode';
|
import { EXCEPTION_CODE } from 'src/enums/exceptionCode';
|
||||||
import {
|
|
||||||
MESSAGE_PUSHING_HOOK,
|
|
||||||
MESSAGE_PUSHING_TYPE,
|
|
||||||
} from 'src/enums/messagePushing';
|
|
||||||
import { getPushingData } from 'src/utils/messagePushing';
|
import { getPushingData } from 'src/utils/messagePushing';
|
||||||
|
|
||||||
import { ResponseSchemaService } from '../services/responseScheme.service';
|
import { ResponseSchemaService } from '../services/responseScheme.service';
|
||||||
import { CounterService } from '../services/counter.service';
|
import { CounterService } from '../services/counter.service';
|
||||||
import { SurveyResponseService } from '../services/surveyResponse.service';
|
import { SurveyResponseService } from '../services/surveyResponse.service';
|
||||||
import { ClientEncryptService } from '../services/clientEncrypt.service';
|
import { ClientEncryptService } from '../services/clientEncrypt.service';
|
||||||
import { MessagePushingTaskService } from '../../survey/services/messagePushingTask.service';
|
import { MessagePushingTaskService } from '../../message/services/messagePushingTask.service';
|
||||||
import { MessagePushingLogService } from '../services/messagePushingLog.service';
|
|
||||||
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import * as Joi from 'joi';
|
import * as Joi from 'joi';
|
||||||
import * as forge from 'node-forge';
|
import * as forge from 'node-forge';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import fetch from 'node-fetch';
|
|
||||||
|
|
||||||
@ApiTags('surveyResponse')
|
@ApiTags('surveyResponse')
|
||||||
@Controller('/api/surveyResponse')
|
@Controller('/api/surveyResponse')
|
||||||
@ -32,7 +26,6 @@ export class SurveyResponseController {
|
|||||||
private readonly surveyResponseService: SurveyResponseService,
|
private readonly surveyResponseService: SurveyResponseService,
|
||||||
private readonly clientEncryptService: ClientEncryptService,
|
private readonly clientEncryptService: ClientEncryptService,
|
||||||
private readonly messagePushingTaskService: MessagePushingTaskService,
|
private readonly messagePushingTaskService: MessagePushingTaskService,
|
||||||
private readonly messagePushingLogService: MessagePushingLogService,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Post('/createResponse')
|
@Post('/createResponse')
|
||||||
@ -198,17 +191,18 @@ export class SurveyResponseController {
|
|||||||
optionTextAndId,
|
optionTextAndId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const surveyId = responseSchema.pageId;
|
||||||
const sendData = getPushingData({
|
const sendData = getPushingData({
|
||||||
surveyResponse,
|
surveyResponse,
|
||||||
questionList: responseSchema?.code?.dataConf?.dataList || [],
|
questionList: responseSchema?.code?.dataConf?.dataList || [],
|
||||||
surveyId: responseSchema.pageId,
|
surveyId,
|
||||||
surveyPath: responseSchema.surveyPath,
|
surveyPath: responseSchema.surveyPath,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 数据异步推送
|
// 异步执行推送任务
|
||||||
this.sendSurveyResponseMessage({
|
this.messagePushingTaskService.runResponseDataPush({
|
||||||
|
surveyId,
|
||||||
sendData,
|
sendData,
|
||||||
surveyId: responseSchema.pageId,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 入库成功后,要把密钥删掉,防止被重复使用
|
// 入库成功后,要把密钥删掉,防止被重复使用
|
||||||
@ -219,53 +213,4 @@ export class SurveyResponseController {
|
|||||||
msg: '提交成功',
|
msg: '提交成功',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendSurveyResponseMessage({ sendData, surveyId }) {
|
|
||||||
try {
|
|
||||||
// 数据推送
|
|
||||||
const messagePushingTasks = await this.messagePushingTaskService.findAll({
|
|
||||||
surveyId,
|
|
||||||
hook: MESSAGE_PUSHING_HOOK.RESPONSE_INSERTED,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (
|
|
||||||
Array.isArray(messagePushingTasks) &&
|
|
||||||
messagePushingTasks.length > 0
|
|
||||||
) {
|
|
||||||
for (const task of messagePushingTasks) {
|
|
||||||
switch (task.type) {
|
|
||||||
case MESSAGE_PUSHING_TYPE.HTTP: {
|
|
||||||
try {
|
|
||||||
const res = await fetch(task.pushAddress, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
Accept: 'application/json, */*',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(sendData),
|
|
||||||
});
|
|
||||||
const response = await res.json();
|
|
||||||
await this.messagePushingLogService.createPushingLog({
|
|
||||||
taskId: task._id.toString(),
|
|
||||||
request: sendData,
|
|
||||||
response: response,
|
|
||||||
status: res.status,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
await this.messagePushingLogService.createPushingLog({
|
|
||||||
taskId: task._id.toString(),
|
|
||||||
request: sendData,
|
|
||||||
response: error.data || error.message,
|
|
||||||
status: error.status || 500,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { MessagePushingModule } from '../message/messagePushing.module';
|
||||||
|
|
||||||
import { ResponseSchemaService } from './services/responseScheme.service';
|
import { ResponseSchemaService } from './services/responseScheme.service';
|
||||||
import { SurveyResponseService } from './services/surveyResponse.service';
|
import { SurveyResponseService } from './services/surveyResponse.service';
|
||||||
import { CounterService } from './services/counter.service';
|
import { CounterService } from './services/counter.service';
|
||||||
import { ClientEncryptService } from './services/clientEncrypt.service';
|
import { ClientEncryptService } from './services/clientEncrypt.service';
|
||||||
import { MessagePushingTaskService } from '../survey/services/messagePushingTask.service';
|
// import { MessagePushingTaskService } from '../messagePushing/services/messagePushingTask.service';
|
||||||
import { MessagePushingLogService } from './services/messagePushingLog.service';
|
|
||||||
|
|
||||||
import { ResponseSchema } from 'src/models/responseSchema.entity';
|
import { ResponseSchema } from 'src/models/responseSchema.entity';
|
||||||
import { Counter } from 'src/models/counter.entity';
|
import { Counter } from 'src/models/counter.entity';
|
||||||
import { SurveyResponse } from 'src/models/surveyResponse.entity';
|
import { SurveyResponse } from 'src/models/surveyResponse.entity';
|
||||||
import { ClientEncrypt } from 'src/models/clientEncrypt.entity';
|
import { ClientEncrypt } from 'src/models/clientEncrypt.entity';
|
||||||
import { MessagePushingTask } from 'src/models/messagePushingTask.entity';
|
|
||||||
import { MessagePushingLog } from 'src/models/messagePushingLog.entity';
|
|
||||||
|
|
||||||
import { ClientEncryptController } from './controllers/clientEncrpt.controller';
|
import { ClientEncryptController } from './controllers/clientEncrpt.controller';
|
||||||
import { CounterController } from './controllers/counter.controller';
|
import { CounterController } from './controllers/counter.controller';
|
||||||
@ -30,10 +29,9 @@ import { ConfigModule } from '@nestjs/config';
|
|||||||
Counter,
|
Counter,
|
||||||
SurveyResponse,
|
SurveyResponse,
|
||||||
ClientEncrypt,
|
ClientEncrypt,
|
||||||
MessagePushingTask,
|
|
||||||
MessagePushingLog,
|
|
||||||
]),
|
]),
|
||||||
ConfigModule,
|
ConfigModule,
|
||||||
|
MessagePushingModule,
|
||||||
],
|
],
|
||||||
controllers: [
|
controllers: [
|
||||||
ClientEncryptController,
|
ClientEncryptController,
|
||||||
@ -47,8 +45,6 @@ import { ConfigModule } from '@nestjs/config';
|
|||||||
SurveyResponseService,
|
SurveyResponseService,
|
||||||
CounterService,
|
CounterService,
|
||||||
ClientEncryptService,
|
ClientEncryptService,
|
||||||
MessagePushingTaskService,
|
|
||||||
MessagePushingLogService,
|
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
ResponseSchemaService,
|
ResponseSchemaService,
|
||||||
|
@ -81,7 +81,7 @@ const rating = computed({
|
|||||||
|
|
||||||
const confirmNps = (num) => {
|
const confirmNps = (num) => {
|
||||||
if (props.readonly) return;
|
if (props.readonly) return;
|
||||||
rating.value = num + '';
|
rating.value = num;
|
||||||
};
|
};
|
||||||
|
|
||||||
const minMsg = computed(() => {
|
const minMsg = computed(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user