wip: 代码生成临时提交
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
package com.youlai.system.config.property;
|
package com.youlai.system.config.property;
|
||||||
|
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码生成配置属性
|
* 代码生成配置属性
|
||||||
*
|
*
|
||||||
@@ -14,4 +17,20 @@ import org.springframework.stereotype.Component;
|
|||||||
@ConfigurationProperties(prefix = "generator")
|
@ConfigurationProperties(prefix = "generator")
|
||||||
@Data
|
@Data
|
||||||
public class GeneratorProperties {
|
public class GeneratorProperties {
|
||||||
|
|
||||||
|
private Map<String, TemplateConfig> templateConfigs = MapUtil.newHashMap(true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板配置
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class TemplateConfig{
|
||||||
|
|
||||||
|
private String templatePath;
|
||||||
|
|
||||||
|
private String packageName;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.youlai.system.model.query.TablePageQuery;
|
|||||||
import com.youlai.system.model.vo.TableColumnVO;
|
import com.youlai.system.model.vo.TableColumnVO;
|
||||||
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
||||||
import com.youlai.system.model.vo.TablePageVO;
|
import com.youlai.system.model.vo.TablePageVO;
|
||||||
import com.youlai.system.service.DatabaseService;
|
import com.youlai.system.service.GeneratorService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
@@ -25,14 +25,14 @@ import java.util.List;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class GeneratorController {
|
public class GeneratorController {
|
||||||
|
|
||||||
private final DatabaseService databaseService;
|
private final GeneratorService generatorService;
|
||||||
|
|
||||||
@Operation(summary = "获取数据表分页列表")
|
@Operation(summary = "获取数据表分页列表")
|
||||||
@GetMapping("/table/page")
|
@GetMapping("/table/page")
|
||||||
public PageResult<TablePageVO> getTablePage(
|
public PageResult<TablePageVO> getTablePage(
|
||||||
TablePageQuery queryParams
|
TablePageQuery queryParams
|
||||||
) {
|
) {
|
||||||
Page<TablePageVO> result = databaseService.getTablePage(queryParams);
|
Page<TablePageVO> result = generatorService.getTablePage(queryParams);
|
||||||
return PageResult.success(result);
|
return PageResult.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public class GeneratorController {
|
|||||||
public Result<List<TableColumnVO>> getTableColumns(
|
public Result<List<TableColumnVO>> getTableColumns(
|
||||||
@Parameter(description = "表名", example = "sys_user") @PathVariable String tableName
|
@Parameter(description = "表名", example = "sys_user") @PathVariable String tableName
|
||||||
) {
|
) {
|
||||||
List<TableColumnVO> list = databaseService.getTableColumns(tableName);
|
List<TableColumnVO> list = generatorService.getTableColumns(tableName);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ public class GeneratorController {
|
|||||||
@Operation(summary = "获取预览生成代码")
|
@Operation(summary = "获取预览生成代码")
|
||||||
@GetMapping("/table/{tableName}/preview")
|
@GetMapping("/table/{tableName}/preview")
|
||||||
public Result<List<TableGeneratePreviewVO>> getTablePreviewData(@PathVariable String tableName) {
|
public Result<List<TableGeneratePreviewVO>> getTablePreviewData(@PathVariable String tableName) {
|
||||||
List<TableGeneratePreviewVO> list = databaseService.getTablePreviewData(tableName);
|
List<TableGeneratePreviewVO> list = generatorService.getTablePreviewData(tableName);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
* @author haoxr
|
* @author haoxr
|
||||||
* @since 2.11.0
|
* @since 2.11.0
|
||||||
*/
|
*/
|
||||||
public interface DatabaseService {
|
public interface GeneratorService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,7 +11,7 @@ import com.youlai.system.model.query.TablePageQuery;
|
|||||||
import com.youlai.system.model.vo.TableColumnVO;
|
import com.youlai.system.model.vo.TableColumnVO;
|
||||||
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
||||||
import com.youlai.system.model.vo.TablePageVO;
|
import com.youlai.system.model.vo.TablePageVO;
|
||||||
import com.youlai.system.service.DatabaseService;
|
import com.youlai.system.service.GeneratorService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import cn.hutool.extra.template.TemplateConfig.ResourceMode;
|
import cn.hutool.extra.template.TemplateConfig.ResourceMode;
|
||||||
@@ -27,7 +27,7 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DatabaseServiceImpl implements DatabaseService {
|
public class GeneratorServiceImpl implements GeneratorService {
|
||||||
|
|
||||||
private final DatabaseMapper databaseMapper;
|
private final DatabaseMapper databaseMapper;
|
||||||
|
|
||||||
@@ -81,14 +81,28 @@ public class DatabaseServiceImpl implements DatabaseService {
|
|||||||
|
|
||||||
Template template = templateEngine.getTemplate("generator" + File.separator + "controller.java.vm");
|
Template template = templateEngine.getTemplate("generator" + File.separator + "controller.java.vm");
|
||||||
String content = template.render(bindingMap);
|
String content = template.render(bindingMap);
|
||||||
|
TableGeneratePreviewVO controller = new TableGeneratePreviewVO();
|
||||||
|
controller.setPath("youlai-boot/controller");
|
||||||
|
controller.setContent(content);
|
||||||
|
controller.setFileName("UserController.java");
|
||||||
|
|
||||||
|
list.add(controller);
|
||||||
|
|
||||||
TableGeneratePreviewVO vo = new TableGeneratePreviewVO();
|
TableGeneratePreviewVO vo = new TableGeneratePreviewVO();
|
||||||
vo.setPath("controller");
|
vo.setPath("youlai-boot/model/vo");
|
||||||
vo.setContent(content);
|
vo.setContent(content);
|
||||||
vo.setFileName("UserController.java");
|
vo.setFileName("UserVO.java");
|
||||||
|
|
||||||
list.add(vo);
|
list.add(vo);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String generatePath(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,175 +1,9 @@
|
|||||||
server:
|
### 代码生成器配置
|
||||||
port: 8989
|
generator:
|
||||||
|
## 模板配置
|
||||||
spring:
|
templateConfigs:
|
||||||
jackson:
|
Controller:
|
||||||
## 默认序列化时间格式
|
## 模板路径
|
||||||
date-format: yyyy-MM-dd HH:mm:ss
|
templatePath: templates/generator/controller.java.vm
|
||||||
## 默认序列化时区
|
## 包名
|
||||||
time-zone: GMT+8
|
packageName: controller
|
||||||
datasource:
|
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
url: jdbc:mysql://www.youlai.tech:3306/youlai_boot?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&allowMultiQueries=true
|
|
||||||
username: root
|
|
||||||
password: YoulaiWuhui@2023
|
|
||||||
data:
|
|
||||||
redis:
|
|
||||||
database: 0
|
|
||||||
host: www.youlai.tech
|
|
||||||
port: 6379
|
|
||||||
# 如果Redis 服务未设置密码,需要将password删掉或注释,而不是设置为空字符串
|
|
||||||
password: 123456
|
|
||||||
|
|
||||||
timeout: 10s
|
|
||||||
lettuce:
|
|
||||||
pool:
|
|
||||||
# 连接池最大连接数 默认8 ,负数表示没有限制
|
|
||||||
max-active: 8
|
|
||||||
# 连接池最大阻塞等待时间(使用负值表示没有限制) 默认-1
|
|
||||||
max-wait: -1
|
|
||||||
# 连接池中的最大空闲连接 默认8
|
|
||||||
max-idle: 8
|
|
||||||
# 连接池中的最小空闲连接 默认0
|
|
||||||
min-idle: 0
|
|
||||||
cache:
|
|
||||||
enabled: false
|
|
||||||
# 缓存类型 redis、none(不使用缓存)
|
|
||||||
type: redis
|
|
||||||
# 缓存时间(单位:ms)
|
|
||||||
redis:
|
|
||||||
time-to-live: 3600000
|
|
||||||
# 缓存null值,防止缓存穿透
|
|
||||||
cache-null-values: true
|
|
||||||
mybatis-plus:
|
|
||||||
global-config:
|
|
||||||
db-config:
|
|
||||||
# 主键ID类型
|
|
||||||
id-type: none
|
|
||||||
# 逻辑删除字段名称
|
|
||||||
logic-delete-field: deleted
|
|
||||||
# 逻辑删除-删除值
|
|
||||||
logic-delete-value: 1
|
|
||||||
# 逻辑删除-未删除值
|
|
||||||
logic-not-delete-value: 0
|
|
||||||
configuration:
|
|
||||||
# 驼峰下划线转换
|
|
||||||
map-underscore-to-camel-case: true
|
|
||||||
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
|
|
||||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
|
||||||
|
|
||||||
|
|
||||||
# 安全配置
|
|
||||||
security:
|
|
||||||
jwt:
|
|
||||||
# JWT 秘钥
|
|
||||||
key: SecretKey012345678901234567890123456789012345678901234567890123456789
|
|
||||||
# JWT 有效期(单位:秒)
|
|
||||||
ttl: 7200
|
|
||||||
ignore-urls:
|
|
||||||
- /v3/api-docs/**
|
|
||||||
- /doc.html
|
|
||||||
- /swagger-resources/**
|
|
||||||
- /webjars/**
|
|
||||||
- /doc.html
|
|
||||||
- /swagger-ui/**
|
|
||||||
- /swagger-ui.html
|
|
||||||
- /api/v1/auth/captcha
|
|
||||||
- /ws/**
|
|
||||||
- /ws-app/**
|
|
||||||
|
|
||||||
oss:
|
|
||||||
# OSS 类型 (目前支持aliyun、minio)
|
|
||||||
type: minio
|
|
||||||
# MinIO 对象存储服务
|
|
||||||
minio:
|
|
||||||
# 服务Endpoint
|
|
||||||
endpoint: http://localhost:9000
|
|
||||||
# 访问凭据
|
|
||||||
access-key: minioadmin
|
|
||||||
# 凭据密钥
|
|
||||||
secret-key: minioadmin
|
|
||||||
# 存储桶名称
|
|
||||||
bucket-name: default
|
|
||||||
# (可选)自定义域名,如果配置了域名,生成的文件URL是域名格式,未配置则URL则是IP格式 (eg: https://oss.youlai.tech)
|
|
||||||
custom-domain:
|
|
||||||
# 阿里云OSS对象存储服务
|
|
||||||
aliyun:
|
|
||||||
# 服务Endpoint
|
|
||||||
endpoint: oss-cn-hangzhou.aliyuncs.com
|
|
||||||
# 访问凭据
|
|
||||||
access-key-id: your-access-key-id
|
|
||||||
# 凭据密钥
|
|
||||||
access-key-secret: your-access-key-secret
|
|
||||||
# 存储桶名称
|
|
||||||
bucket-name: default
|
|
||||||
|
|
||||||
# springdoc配置: https://springdoc.org/properties.html
|
|
||||||
springdoc:
|
|
||||||
swagger-ui:
|
|
||||||
path: /swagger-ui.html
|
|
||||||
operationsSorter: alpha
|
|
||||||
tags-sorter: alpha
|
|
||||||
api-docs:
|
|
||||||
path: /v3/api-docs
|
|
||||||
group-configs:
|
|
||||||
- group: 'default'
|
|
||||||
paths-to-match: '/**'
|
|
||||||
packages-to-scan: com.youlai.system.controller
|
|
||||||
default-flat-param-object: true
|
|
||||||
|
|
||||||
# knife4j 接口文档配置
|
|
||||||
knife4j:
|
|
||||||
# 是否开启 Knife4j 增强功能
|
|
||||||
enable: true # 设置为 true 表示开启增强功能
|
|
||||||
# 生产环境配置
|
|
||||||
production: false # 设置为 true 表示在生产环境中不显示文档,为 false 表示显示文档(通常在开发环境中使用)
|
|
||||||
setting:
|
|
||||||
language: zh_cn
|
|
||||||
|
|
||||||
# xxl-job 定时任务配置
|
|
||||||
xxl:
|
|
||||||
job:
|
|
||||||
# 定时任务开关
|
|
||||||
enabled: false
|
|
||||||
admin:
|
|
||||||
# 多个地址使用,分割
|
|
||||||
addresses: http://127.0.0.1:8080/xxl-job-admin
|
|
||||||
accessToken: default_token
|
|
||||||
executor:
|
|
||||||
appname: xxl-job-executor-${spring.application.name}
|
|
||||||
address:
|
|
||||||
ip:
|
|
||||||
port: 9999
|
|
||||||
logpath: /data/applogs/xxl-job/jobhandler
|
|
||||||
logretentiondays: 30
|
|
||||||
|
|
||||||
# 验证码配置
|
|
||||||
captcha:
|
|
||||||
# 验证码类型 circle-圆圈干扰验证码|gif-Gif验证码|line-干扰线验证码|shear-扭曲干扰验证码
|
|
||||||
type: circle
|
|
||||||
# 验证码宽度
|
|
||||||
width: 120
|
|
||||||
# 验证码高度
|
|
||||||
height: 40
|
|
||||||
# 验证码干扰元素个数
|
|
||||||
interfere-count: 2
|
|
||||||
# 文本透明度(0.0-1.0)
|
|
||||||
text-alpha: 0.8
|
|
||||||
# 验证码字符配置
|
|
||||||
code:
|
|
||||||
# 验证码字符类型 math-算术|random-随机字符
|
|
||||||
type: math
|
|
||||||
# 验证码字符长度,type=算术时,表示运算位数(1:个位数运算 2:十位数运算);type=随机字符时,表示字符个数
|
|
||||||
length: 1
|
|
||||||
# 验证码字体
|
|
||||||
font:
|
|
||||||
# 字体名称 Dialog|DialogInput|Monospaced|Serif|SansSerif
|
|
||||||
name: SansSerif
|
|
||||||
# 字体样式 0-普通|1-粗体|2-斜体
|
|
||||||
weight: 1
|
|
||||||
# 字体大小
|
|
||||||
size: 24
|
|
||||||
# 验证码有效期(秒)
|
|
||||||
expire-seconds: 120
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user