English | 简体中文
This system is a report rendering module extracted from the actual production platform, as a stand-alone report generation system.
This system is BS architecture, this project is a backend service:
- Github: https://github.com/52jing/wang-template-backend
- Gitee: https://gitee.com/i52jing/wang-template-backend
Frontend service at:
- Github: https://github.com/52jing/wang-template-admin
- Gitee: https://gitee.com/i52jing/wang-template-admin
- Lightweight
This system only focuses on report generation, which can interface with any data source and generate corresponding reports through customized templates.
- Extensible
The system adopts a modular architecture and an interface-oriented design, which makes it easy to quickly extend other data sources and rendering methods.
- Easy Integration
Easily integrated into other systems as a module for report generation functions.
- More Intelligent
Integration of AIGC services provides smarter report generation capabilities.
Tech | Version |
---|---|
Java | 8+ |
Spring | 5.3.31 |
Spring Boot | 2.7.18 |
- Relational database SQL: supports querying data from relational databases, and data querying is realized through JDBC interface. Among them, MySQL, Postgresql and H2 have been verified and tested.
- Word Report: Use poi-tl to support Word templates to generate Word reports.
- Text Report: Use FreeMarker to support arbitrary text reports, generating text reports, such as TXT, Markdown, HTML and so on.
WangTemplateBackend
|-- app -- Report rendering module
|-- design -- Database design files
|-- framework -- Framework module
|-- report -- Unit tests aggregation report
|-- system -- System management module
|-- task -- Task management module
Use docker compose to quickly deploy:
- Github: https://github.com/52jing/wang-template-compose
- Gitee: https://gitee.com/i52jing/wang-template-compose
Build Image
docker build -t wang-template-backend:1.0 .
Mount config file and start container
docker run -d --name wang-template-backend -p 8000:8000 -v <path-to-config>/application-prod.yml:/opt/config/application-prod.yml wang-template-backend:1.0
Package by Maven
mvn clean package -DskipTests
Jar file is under app/target/app.jar, add config file and start jar.
Build Image
docker build -t wang-template-admin:1.0 .
Start Container
docker run -d --name wang-template-admin -p 8001:80 wang-template-admin:1.0
Build by Vite
yarn build
Files are under dist/spa directory.
Note: Since the frontend defaults to the same domain and port for backend services, you need to use a front load-balancing proxy, or configure the backend request base path when build the frontend (see Environment Variables).
The template file is shown below
The report generated is shown below
Add configuration file application-prod.yml
or application-prod.properties
, can refer to app/src/main/resources/example-application-dev.yml
.
Configure under spring.datasource.druid
or mybatis-flex.datasource.master
.
Example:
spring:
flyway:
# Enable flyway to migrate
enabled: true
# Note to change to the corresponding database directory
# If there is no corresponding database, you can use PDManer to generate a database with design files.
locations:
- classpath:db/migration/mysql
mybatis-flex:
# configure datasource
datasource:
# master datasource
master:
url: jdbc:mysql://localhost:3306/wb-template-dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: 123456
# The following Druid parameters can be configured according to actual requirements
# Initial connection pool size
initial-size: 5
# max active connection pool size
max-active: 20
# min connection pool size
min-idle: 5
Supported databases for service (the following databases have been tested):
- MySQL 8
- MySQL 5 (Since Flyway doesn't support it, it needs to be executed manually for migration in
db.migration/mysql
and disable flyway) - Postgresql
- H2
It depends on x-file-storage, support local files, MinIO and cloud service storage, please refer to the official documentation.
Example
dromara:
x-file-storage: # Storage configuration
default-platform: local-plus-1 # default platform
thumbnail-suffix: ".min.jpg" # thumbnail
# storage platform configuration
local-plus:
- platform: local-plus-1 # name
enable-storage: true # enabled
enable-access: true # enable access
domain: http://127.0.0.1:8080/file/ # domain
base-path: local-plus/ # base path
path-patterns: /file/** # access path
storage-path: ./data # storage directory
analysis:
# enable indicator analysis
indicatorAnalysis: true
# use kimi cloud service, please use Kimi API access key, refer to https://platform.moonshot.cn/docs/intro#%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97
moonShot:
accessToken:
All templates are injected with a rendered context object, which has the following format:
{
"templateName": "", // template name
"datasourceName": "", // datasource name
"params": {}, // render parameters
"envs": { // environments
"year": 2024, // year
"month": 6, // month
"day": 12, // day
"dayOfWeek": 3, // day of week
"hour": 0, // hour
"minute": 0, // minute
"second": 0 // second
},
"data": {} // data obtained from a data source, which may be an array or an object
}
To use it in the template like this: ${envs.year}
。
Word template depends on poi-tl , the syntax can be found in the official documentation. The variables use ${name}
style。
Text template depends on FreeMarker , the syntax tan be found in the official documentation.
- Support for more data sources
- Adding timed tasks and generating schedules
- Integrate more AI capabilities