feat: 修改message单独一个module,修改默认json字段 (#90)

This commit is contained in:
luch 2024-04-03 19:04:24 +08:00 committed by GitHub
parent b7a716778a
commit 08aaefc3e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 100 additions and 235 deletions

View 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 {}

View File

@ -7,12 +7,16 @@ import { CreateMessagePushingTaskDto } from '../dto/createMessagePushingTask.dto
import { UpdateMessagePushingTaskDto } from '../dto/updateMessagePushingTask.dto';
import { ObjectId } from 'mongodb';
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()
export class MessagePushingTaskService {
constructor(
@InjectRepository(MessagePushingTask)
private readonly messagePushingTaskRepository: MongoRepository<MessagePushingTask>,
private readonly messagePushingLogService: MessagePushingLogService,
) {}
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) {}
}
}

View File

@ -12,21 +12,18 @@ import { SurveyController } from './controllers/survey.controller';
import { SurveyHistoryController } from './controllers/surveyHistory.controller';
import { SurveyMetaController } from './controllers/surveyMeta.controller';
import { SurveyUIController } from './controllers/surveyUI.controller';
import { MessagePushingTaskController } from './controllers/messagePushingTask.controller';
import { SurveyConf } from 'src/models/surveyConf.entity';
import { SurveyHistory } from 'src/models/surveyHistory.entity';
import { SurveyMeta } from 'src/models/surveyMeta.entity';
import { SurveyResponse } from 'src/models/surveyResponse.entity';
import { Word } from 'src/models/word.entity';
import { MessagePushingTask } from 'src/models/messagePushingTask.entity';
import { DataStatisticService } from './services/dataStatistic.service';
import { SurveyConfService } from './services/surveyConf.service';
import { SurveyHistoryService } from './services/surveyHistory.service';
import { SurveyMetaService } from './services/surveyMeta.service';
import { ContentSecurityService } from './services/contentSecurity.service';
import { MessagePushingTaskService } from './services/messagePushingTask.service';
import { PluginManagerProvider } from 'src/securityPlugin/pluginManager.provider';
@ -38,7 +35,6 @@ import { PluginManagerProvider } from 'src/securityPlugin/pluginManager.provider
SurveyHistory,
SurveyResponse,
Word,
MessagePushingTask,
]),
ConfigModule,
SurveyResponseModule,
@ -50,7 +46,6 @@ import { PluginManagerProvider } from 'src/securityPlugin/pluginManager.provider
SurveyHistoryController,
SurveyMetaController,
SurveyUIController,
MessagePushingTaskController,
],
providers: [
DataStatisticService,
@ -59,7 +54,6 @@ import { PluginManagerProvider } from 'src/securityPlugin/pluginManager.provider
SurveyMetaService,
PluginManagerProvider,
ContentSecurityService,
MessagePushingTaskService,
LoggerProvider,
],
})

View File

@ -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": {
"dataList": [
{
@ -32,8 +21,6 @@
"rightText": "极满意"
},
"placeholderDesc": "",
"addressType": 3,
"isAuto": false,
"urlKey": "",
"textRange": {
"min": {
@ -90,8 +77,6 @@
},
"star": 5,
"exclude": false,
"addressType": 3,
"isAuto": false,
"textRange": {
"min": {
"placeholder": "0",
@ -104,25 +89,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"
}
}

View File

@ -1,36 +1,4 @@
{
"submitConf": {
"submitTitle": "提交",
"confirmAgain": {
"is_again": true,
"again_text": "确认要提交吗?"
},
"msgContent": {
"msg_200": "提交成功",
"msg_9001": "您来晚了,感谢支持问卷~",
"msg_9002": "请勿多次提交!",
"msg_9003": "您来晚了,已经满额!",
"msg_9004": "提交失败!"
}
},
"bannerConf": {
"titleConfig": {
"mainTitle": "<h3 style=\"text-align: center\">满意度调研</h3> <p>&nbsp;</p> <p>为了给您提供更好的服务,希望您能抽出几分钟时间,将您的感受和建议告诉我们,<span style=\"color: rgb(204, 0, 0)\">期待您的参与</span></p>",
"subTitle": ""
},
"bannerConfig": {
"bgImage": "/imgs/skin/17e06b7604a007e1d3e1453b9ddadc3c.webp",
"videoLink": "",
"postImg": ""
}
},
"baseConf": {
"showVoteProcess": "allow",
"begTime": "2018-05-22 17:17:48",
"endTime": "2028-05-22 17:17:48",
"tLimit": "0",
"language": "chinese"
},
"dataConf": {
"dataList": [
{
@ -52,12 +20,9 @@
"importKey": "single",
"importData": "",
"npsMin": 0,
"addressType": 3,
"isAuto": false,
"urlKey": "",
"hasRely": true,
"relyList": [],
"jumpTo": "",
"optionOrigin": "",
"answerTip": "",
"type": "text",
@ -97,8 +62,6 @@
"cOptions": [],
"npsMin": 0,
"star": 5,
"addressType": 3,
"isAuto": false,
"urlKey": "",
"defaultProps": {
"children": "children",
@ -107,7 +70,6 @@
},
"hasRely": true,
"relyList": [],
"jumpTo": "",
"optionOrigin": "",
"answerTip": "",
"type": "radio-star",

View File

@ -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": {
"dataList": [
{
@ -32,17 +21,7 @@
"rightText": "极满意"
},
"exclude": false,
"relTypes": {
"textarea": "多行文本框",
"text": "单行输入框"
},
"placeholderDesc": "",
"mhLimit": 0,
"addressType": 3,
"isAuto": false,
"jumpTo": "",
"startDate": "",
"endDate": "",
"textRange": {
"min": {
"placeholder": "0",
@ -113,8 +92,6 @@
},
"star": 5,
"exclude": false,
"addressType": 3,
"isAuto": false,
"urlKey": "",
"defaultProps": {
"children": "children",
@ -135,26 +112,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"
}
}

View File

@ -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": {
"dataList": [
{
@ -33,13 +22,7 @@
"rightText": "极满意"
},
"exclude": false,
"relTypes": {
"textarea": "多行文本框",
"text": "单行输入框"
},
"placeholderDesc": "",
"addressType": 3,
"isAuto": false,
"urlKey": "",
"textRange": {
"min": {
@ -92,7 +75,6 @@
"rightText": "极满意"
},
"star": 5,
"addressType": 3,
"textRange": {
"min": {
"placeholder": "0",
@ -105,25 +87,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"
}
}

View File

@ -29,11 +29,12 @@
"logoImageWidth": "60%"
},
"baseConf": {
"begTime": "2018-05-30 10:38:31",
"endTime": "2028-05-30 10:38:31",
"tLimit": "0",
"begTime": "2024-01-01 00:00:00",
"endTime": "2034-01-01 00:00:00",
"tLimit": 0,
"language": "chinese",
"showVoteProcess": "allow"
"answerBegTime": "00:00:00",
"answerEndTime": "23:59:59"
},
"skinConf": {
"skinColor": "#4a4c5b",

View File

@ -4,24 +4,18 @@ import { SurveyNotFoundException } from 'src/exceptions/surveyNotFoundException'
import { checkSign } from 'src/utils/checkSign';
import { ENCRYPT_TYPE } from 'src/enums/encrypt';
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 { ResponseSchemaService } from '../services/responseScheme.service';
import { CounterService } from '../services/counter.service';
import { SurveyResponseService } from '../services/surveyResponse.service';
import { ClientEncryptService } from '../services/clientEncrypt.service';
import { MessagePushingTaskService } from '../../survey/services/messagePushingTask.service';
import { MessagePushingLogService } from '../services/messagePushingLog.service';
import { MessagePushingTaskService } from '../../message/services/messagePushingTask.service';
import moment from 'moment';
import * as Joi from 'joi';
import * as forge from 'node-forge';
import { ApiTags } from '@nestjs/swagger';
import fetch from 'node-fetch';
@ApiTags('surveyResponse')
@Controller('/api/surveyResponse')
@ -32,7 +26,6 @@ export class SurveyResponseController {
private readonly surveyResponseService: SurveyResponseService,
private readonly clientEncryptService: ClientEncryptService,
private readonly messagePushingTaskService: MessagePushingTaskService,
private readonly messagePushingLogService: MessagePushingLogService,
) {}
@Post('/createResponse')
@ -198,17 +191,18 @@ export class SurveyResponseController {
optionTextAndId,
});
const surveyId = responseSchema.pageId;
const sendData = getPushingData({
surveyResponse,
questionList: responseSchema?.code?.dataConf?.dataList || [],
surveyId: responseSchema.pageId,
surveyId,
surveyPath: responseSchema.surveyPath,
});
// 数据异步推送
this.sendSurveyResponseMessage({
// 异步执行推送任务
this.messagePushingTaskService.runResponseDataPush({
surveyId,
sendData,
surveyId: responseSchema.pageId,
});
// 入库成功后,要把密钥删掉,防止被重复使用
@ -219,53 +213,4 @@ export class SurveyResponseController {
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) {}
}
}

View File

@ -1,18 +1,17 @@
import { Module } from '@nestjs/common';
import { MessagePushingModule } from '../message/messagePushing.module';
import { ResponseSchemaService } from './services/responseScheme.service';
import { SurveyResponseService } from './services/surveyResponse.service';
import { CounterService } from './services/counter.service';
import { ClientEncryptService } from './services/clientEncrypt.service';
import { MessagePushingTaskService } from '../survey/services/messagePushingTask.service';
import { MessagePushingLogService } from './services/messagePushingLog.service';
// import { MessagePushingTaskService } from '../messagePushing/services/messagePushingTask.service';
import { ResponseSchema } from 'src/models/responseSchema.entity';
import { Counter } from 'src/models/counter.entity';
import { SurveyResponse } from 'src/models/surveyResponse.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 { CounterController } from './controllers/counter.controller';
@ -30,10 +29,9 @@ import { ConfigModule } from '@nestjs/config';
Counter,
SurveyResponse,
ClientEncrypt,
MessagePushingTask,
MessagePushingLog,
]),
ConfigModule,
MessagePushingModule,
],
controllers: [
ClientEncryptController,
@ -47,8 +45,6 @@ import { ConfigModule } from '@nestjs/config';
SurveyResponseService,
CounterService,
ClientEncryptService,
MessagePushingTaskService,
MessagePushingLogService,
],
exports: [
ResponseSchemaService,

View File

@ -78,7 +78,7 @@ const rating = computed({
const confirmNps = (num) => {
if (props.readonly) return;
rating.value = num + '';
rating.value = num;
};
const minMsg = computed(() => {