Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【北大开源实践】增加数据导出功能 #294

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<img src="https://img.shields.io/badge/help-%E5%AE%98%E7%BD%91-blue" alt="docs">
</a>
<a href="https://github.com/didi/xiaoju-survey/blob/main/README_EN.md">
<img src="https://img.shields.io/badge/help-%E8%8B%B1%E6%96%87README-50c62a" alt="docs">
<img src="https://img.shields.io/badge/help-README_EN-50c62a" alt="docs">
</a>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
<img src="https://img.shields.io/badge/PRs-welcome-%23ffa600" alt="pr">
</a>
<a href="https://xiaojusurvey.didi.cn">
<img src="https://img.shields.io/badge/help-%E5%AE%98%E7%BD%91-blue" alt="docs">
<img src="https://img.shields.io/badge/help-website-blue" alt="docs">
</a>
<a href="https://github.com/didi/xiaoju-survey/blob/main/README.md">
<img src="https://img.shields.io/badge/help-README-50c62a" alt="docs">
<img src="https://img.shields.io/badge/help-README_ZH-50c62a" alt="docs">
</a>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ http {
try_files $uri $uri/ /management.html;
}

location /management/preview/ {
try_files $uri $uri/ /render.html;
}


location /render/ {
try_files $uri $uri/ /render.html;
}
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"node-cron": "^3.0.3"
}
}
4 changes: 4 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,9 @@
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
}
},
"engines": {
"node": ">=18.0.0",
"npm": ">=8.6.0"
}
}
2 changes: 2 additions & 0 deletions server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { PluginManagerProvider } from './securityPlugin/pluginManager.provider';
import { LogRequestMiddleware } from './middlewares/logRequest.middleware';
import { XiaojuSurveyPluginManager } from './securityPlugin/pluginManager';
import { Logger } from './logger';
import { SurveyDownload } from './models/surveyDownload.entity';

@Module({
imports: [
Expand Down Expand Up @@ -81,6 +82,7 @@ import { Logger } from './logger';
Workspace,
WorkspaceMember,
Collaborator,
SurveyDownload,
],
};
},
Expand Down
21 changes: 21 additions & 0 deletions server/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const mongo = {
url: process.env.XIAOJU_SURVEY_MONGO_URL || 'mongodb://localhost:27017',
dbName: process.env.XIAOJU_SURVER_MONGO_DBNAME || 'xiaojuSurvey',
};

const session = {
expireTime:
parseInt(process.env.XIAOJU_SURVEY_JWT_EXPIRES_IN) || 8 * 3600 * 1000,
};

const encrypt = {
type: process.env.XIAOJU_SURVEY_ENCRYPT_TYPE || 'aes',
aesCodelength: parseInt(process.env.XIAOJU_SURVEY_ENCRYPT_TYPE_LEN) || 10, //aes密钥长度
};

const jwt = {
secret: process.env.XIAOJU_SURVEY_JWT_SECRET || 'xiaojuSurveyJwtSecret',
expiresIn: process.env.XIAOJU_SURVEY_JWT_EXPIRES_IN || '8h',
};

export { mongo, session, encrypt, jwt };
1 change: 1 addition & 0 deletions server/src/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum RECORD_STATUS {
PUBLISHED = 'published', // 发布
REMOVED = 'removed', // 删除
FORCE_REMOVED = 'forceRemoved', // 从回收站删除
COMOPUTETING = 'computing', // 计算中
}

// 历史类型
Expand Down
46 changes: 46 additions & 0 deletions server/src/models/surveyDownload.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Entity, Column, BeforeInsert, AfterLoad } from 'typeorm';
import pluginManager from '../securityPlugin/pluginManager';
import { BaseEntity } from './base.entity';

@Entity({ name: 'surveyDownload' })
export class SurveyDownload extends BaseEntity {
@Column()
pageId: string;

@Column()
surveyPath: string;

@Column()
title: string;

@Column()
filePath: string;

@Column()
onwer: string;

@Column()
filename: string;

@Column()
fileSize: string;

@Column()
fileType: string;

// @Column()
// ownerId: string;

@Column()
downloadTime: string;

@BeforeInsert()
async onDataInsert() {
return await pluginManager.triggerHook('beforeResponseDataCreate', this);
}

@AfterLoad()
async onDataLoaded() {
return await pluginManager.triggerHook('afterResponseDataReaded', this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { SURVEY_PERMISSION } from 'src/enums/surveyPermission';
import { Logger } from 'src/logger';
import { HttpException } from 'src/exceptions/httpException';
import { EXCEPTION_CODE } from 'src/enums/exceptionCode';
import { SurveyDownloadService } from '../services/surveyDownload.service';

@ApiTags('survey')
@ApiBearerAuth()
Expand All @@ -30,6 +31,8 @@ export class DataStatisticController {
private readonly dataStatisticService: DataStatisticService,
private readonly pluginManager: XiaojuSurveyPluginManager,
private readonly logger: Logger,
//
private readonly surveyDownloadService: SurveyDownloadService,
) {}

@Get('/dataTable')
Expand Down
32 changes: 32 additions & 0 deletions server/src/modules/survey/controllers/survey.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,38 @@ export class SurveyController {
};
}

@Get('/getPreviewSchema')
@HttpCode(200)
async getPreviewSchema(
@Query()
queryInfo: {
surveyPath: string;
},
@Request()
req,
) {
const { value, error } = Joi.object({
surveyId: Joi.string().required(),
}).validate({ surveyId: queryInfo.surveyPath });

if (error) {
this.logger.error(error.message, { req });
throw new HttpException('参数有误', EXCEPTION_CODE.PARAMETER_ERROR);
}
const surveyId = value.surveyId;
const surveyConf =
await this.surveyConfService.getSurveyConfBySurveyId(surveyId);
const surveyMeta = await this.surveyMetaService.getSurveyById({ surveyId });
return {
code: 200,
data: {
...surveyConf,
title: surveyMeta?.title,
surveyPath: surveyMeta?.surveyPath,
},
};
}

@Post('/publishSurvey')
@HttpCode(200)
@UseGuards(SurveyGuard)
Expand Down
Loading
Loading