diff --git a/server/src/modules/survey/__test/createMessagePushingTask.dto.spec.ts b/server/src/modules/message/__test/createMessagePushingTask.dto.spec.ts similarity index 100% rename from server/src/modules/survey/__test/createMessagePushingTask.dto.spec.ts rename to server/src/modules/message/__test/createMessagePushingTask.dto.spec.ts diff --git a/server/src/modules/surveyResponse/__test/messagePushingLog.service.spec.ts b/server/src/modules/message/__test/messagePushingLog.service.spec.ts similarity index 100% rename from server/src/modules/surveyResponse/__test/messagePushingLog.service.spec.ts rename to server/src/modules/message/__test/messagePushingLog.service.spec.ts diff --git a/server/src/modules/survey/__test/messagePushingTask.controller.spec.ts b/server/src/modules/message/__test/messagePushingTask.controller.spec.ts similarity index 100% rename from server/src/modules/survey/__test/messagePushingTask.controller.spec.ts rename to server/src/modules/message/__test/messagePushingTask.controller.spec.ts diff --git a/server/src/modules/survey/__test/messagePushingTask.dto.spec.ts b/server/src/modules/message/__test/messagePushingTask.dto.spec.ts similarity index 100% rename from server/src/modules/survey/__test/messagePushingTask.dto.spec.ts rename to server/src/modules/message/__test/messagePushingTask.dto.spec.ts diff --git a/server/src/modules/survey/__test/messagePushingTask.service.spec.ts b/server/src/modules/message/__test/messagePushingTask.service.spec.ts similarity index 100% rename from server/src/modules/survey/__test/messagePushingTask.service.spec.ts rename to server/src/modules/message/__test/messagePushingTask.service.spec.ts diff --git a/server/src/modules/survey/__test/queryMessagePushingTaskList.dto.spec.ts b/server/src/modules/message/__test/queryMessagePushingTaskList.dto.spec.ts similarity index 100% rename from server/src/modules/survey/__test/queryMessagePushingTaskList.dto.spec.ts rename to server/src/modules/message/__test/queryMessagePushingTaskList.dto.spec.ts diff --git a/server/src/modules/survey/__test/updateMessagePushingTask.dto.spec.ts b/server/src/modules/message/__test/updateMessagePushingTask.dto.spec.ts similarity index 100% rename from server/src/modules/survey/__test/updateMessagePushingTask.dto.spec.ts rename to server/src/modules/message/__test/updateMessagePushingTask.dto.spec.ts diff --git a/server/src/modules/survey/controllers/messagePushingTask.controller.ts b/server/src/modules/message/controllers/messagePushingTask.controller.ts similarity index 100% rename from server/src/modules/survey/controllers/messagePushingTask.controller.ts rename to server/src/modules/message/controllers/messagePushingTask.controller.ts diff --git a/server/src/modules/survey/dto/createMessagePushingTask.dto.ts b/server/src/modules/message/dto/createMessagePushingTask.dto.ts similarity index 100% rename from server/src/modules/survey/dto/createMessagePushingTask.dto.ts rename to server/src/modules/message/dto/createMessagePushingTask.dto.ts diff --git a/server/src/modules/survey/dto/messagePushingTask.dto.ts b/server/src/modules/message/dto/messagePushingTask.dto.ts similarity index 100% rename from server/src/modules/survey/dto/messagePushingTask.dto.ts rename to server/src/modules/message/dto/messagePushingTask.dto.ts diff --git a/server/src/modules/survey/dto/queryMessagePushingTaskList.dto.ts b/server/src/modules/message/dto/queryMessagePushingTaskList.dto.ts similarity index 100% rename from server/src/modules/survey/dto/queryMessagePushingTaskList.dto.ts rename to server/src/modules/message/dto/queryMessagePushingTaskList.dto.ts diff --git a/server/src/modules/survey/dto/updateMessagePushingTask.dto.ts b/server/src/modules/message/dto/updateMessagePushingTask.dto.ts similarity index 100% rename from server/src/modules/survey/dto/updateMessagePushingTask.dto.ts rename to server/src/modules/message/dto/updateMessagePushingTask.dto.ts diff --git a/server/src/modules/message/messagePushing.module.ts b/server/src/modules/message/messagePushing.module.ts new file mode 100644 index 00000000..36bd6922 --- /dev/null +++ b/server/src/modules/message/messagePushing.module.ts @@ -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 {} diff --git a/server/src/modules/surveyResponse/services/messagePushingLog.service.ts b/server/src/modules/message/services/messagePushingLog.service.ts similarity index 100% rename from server/src/modules/surveyResponse/services/messagePushingLog.service.ts rename to server/src/modules/message/services/messagePushingLog.service.ts diff --git a/server/src/modules/survey/services/messagePushingTask.service.ts b/server/src/modules/message/services/messagePushingTask.service.ts similarity index 66% rename from server/src/modules/survey/services/messagePushingTask.service.ts rename to server/src/modules/message/services/messagePushingTask.service.ts index b5332857..2bf1e8e6 100644 --- a/server/src/modules/survey/services/messagePushingTask.service.ts +++ b/server/src/modules/message/services/messagePushingTask.service.ts @@ -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, + 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) {} + } } diff --git a/server/src/modules/survey/survey.module.ts b/server/src/modules/survey/survey.module.ts index 8b1b5860..8236d35d 100644 --- a/server/src/modules/survey/survey.module.ts +++ b/server/src/modules/survey/survey.module.ts @@ -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, ], }) diff --git a/server/src/modules/survey/template/surveyTemplate/survey/normal.json b/server/src/modules/survey/template/surveyTemplate/survey/normal.json index 6cc73a62..3808e775 100644 --- a/server/src/modules/survey/template/surveyTemplate/survey/normal.json +++ b/server/src/modules/survey/template/surveyTemplate/survey/normal.json @@ -1,15 +1,4 @@ { - "bannerConf": { - "titleConfig": { - "mainTitle": "

欢迎填写问卷

为了给您提供更好的服务,希望您能抽出几分钟时间,将您的感受和建议告诉我们,期待您的参与!

", - "subTitle": "" - }, - "bannerConfig": { - "bgImage": "/imgs/skin/17e06b7604a007e1d3e1453b9ddadc3c.webp", - "videoLink": "", - "postImg": "" - } - }, "dataConf": { "dataList": [ { @@ -28,8 +17,6 @@ "maxNum": "", "star": 5, "placeholderDesc": "", - "addressType": 3, - "isAuto": false, "urlKey": "", "textRange": { "min": { @@ -82,8 +69,6 @@ "cOptions": [], "star": 5, "exclude": false, - "addressType": 3, - "isAuto": false, "textRange": { "min": { "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" } } diff --git a/server/src/modules/survey/template/surveyTemplate/survey/register.json b/server/src/modules/survey/template/surveyTemplate/survey/register.json index 80faf029..5f2fd5be 100644 --- a/server/src/modules/survey/template/surveyTemplate/survey/register.json +++ b/server/src/modules/survey/template/surveyTemplate/survey/register.json @@ -1,15 +1,4 @@ { - "bannerConf": { - "titleConfig": { - "mainTitle": "

欢迎填写问卷

为了给您提供更好的服务,希望您能抽出几分钟时间,将您的感受和建议告诉我们,期待您的参与!

", - "subTitle": "" - }, - "bannerConfig": { - "bgImage": "/imgs/skin/17e06b7604a007e1d3e1453b9ddadc3c.webp", - "videoLink": "", - "postImg": "" - } - }, "dataConf": { "dataList": [ { @@ -28,17 +17,7 @@ "maxNum": "", "star": 5, "exclude": false, - "relTypes": { - "textarea": "多行文本框", - "text": "单行输入框" - }, "placeholderDesc": "", - "mhLimit": 0, - "addressType": 3, - "isAuto": false, - "jumpTo": "", - "startDate": "", - "endDate": "", "textRange": { "min": { "placeholder": "0", @@ -105,8 +84,6 @@ ], "star": 5, "exclude": false, - "addressType": 3, - "isAuto": false, "urlKey": "", "defaultProps": { "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" } } diff --git a/server/src/modules/survey/template/surveyTemplate/survey/vote.json b/server/src/modules/survey/template/surveyTemplate/survey/vote.json index 40233584..9ae7d7fe 100644 --- a/server/src/modules/survey/template/surveyTemplate/survey/vote.json +++ b/server/src/modules/survey/template/surveyTemplate/survey/vote.json @@ -1,15 +1,4 @@ { - "bannerConf": { - "titleConfig": { - "mainTitle": "

欢迎填写问卷

为了给您提供更好的服务,希望您能抽出几分钟时间,将您的感受和建议告诉我们,期待您的参与!

", - "subTitle": "" - }, - "bannerConfig": { - "bgImage": "/imgs/skin/17e06b7604a007e1d3e1453b9ddadc3c.webp", - "videoLink": "", - "postImg": "" - } - }, "dataConf": { "dataList": [ { @@ -29,13 +18,7 @@ "maxNum": "", "star": 5, "exclude": false, - "relTypes": { - "textarea": "多行文本框", - "text": "单行输入框" - }, "placeholderDesc": "", - "addressType": 3, - "isAuto": false, "urlKey": "", "textRange": { "min": { @@ -84,7 +67,6 @@ } ], "star": 5, - "addressType": 3, "textRange": { "min": { "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" } } diff --git a/server/src/modules/survey/template/surveyTemplate/templateBase.json b/server/src/modules/survey/template/surveyTemplate/templateBase.json index cc17b7f3..de6debc5 100644 --- a/server/src/modules/survey/template/surveyTemplate/templateBase.json +++ b/server/src/modules/survey/template/surveyTemplate/templateBase.json @@ -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", diff --git a/server/src/modules/surveyResponse/controllers/surveyResponse.controller.ts b/server/src/modules/surveyResponse/controllers/surveyResponse.controller.ts index 06aaee6e..8c77584e 100644 --- a/server/src/modules/surveyResponse/controllers/surveyResponse.controller.ts +++ b/server/src/modules/surveyResponse/controllers/surveyResponse.controller.ts @@ -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) {} - } } diff --git a/server/src/modules/surveyResponse/surveyResponse.module.ts b/server/src/modules/surveyResponse/surveyResponse.module.ts index 50fc790b..50c8f941 100644 --- a/server/src/modules/surveyResponse/surveyResponse.module.ts +++ b/server/src/modules/surveyResponse/surveyResponse.module.ts @@ -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, diff --git a/web/src/materials/questions/widgets/NpsModule/index.vue b/web/src/materials/questions/widgets/NpsModule/index.vue index 913fdbe0..9d819533 100644 --- a/web/src/materials/questions/widgets/NpsModule/index.vue +++ b/web/src/materials/questions/widgets/NpsModule/index.vue @@ -81,7 +81,7 @@ const rating = computed({ const confirmNps = (num) => { if (props.readonly) return; - rating.value = num + ''; + rating.value = num; }; const minMsg = computed(() => {