Commit 8e6fa3db558ecfed7c6b1a740df3c18b43db4eea
1 parent
8a13470f
项目结构调整 x 19 : 解决多数据源后,数据库文档导出问题
Showing
10 changed files
with
64 additions
and
71 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/doc/InfDbDocController.java
| ... | ... | @@ -9,6 +9,8 @@ import cn.smallbun.screw.core.engine.EngineFileType; |
| 9 | 9 | import cn.smallbun.screw.core.engine.EngineTemplateType; |
| 10 | 10 | import cn.smallbun.screw.core.execute.DocumentationExecute; |
| 11 | 11 | import cn.smallbun.screw.core.process.ProcessConfig; |
| 12 | +import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty; | |
| 13 | +import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties; | |
| 12 | 14 | import com.zaxxer.hikari.HikariConfig; |
| 13 | 15 | import com.zaxxer.hikari.HikariDataSource; |
| 14 | 16 | import io.swagger.annotations.Api; |
| ... | ... | @@ -32,7 +34,7 @@ import java.util.Collections; |
| 32 | 34 | public class InfDbDocController { |
| 33 | 35 | |
| 34 | 36 | @Resource |
| 35 | - private DataSourceProperties dataSourceProperties; | |
| 37 | + private DynamicDataSourceProperties dynamicDataSourceProperties; | |
| 36 | 38 | |
| 37 | 39 | private static final String FILE_OUTPUT_DIR = System.getProperty("java.io.tmpdir") + File.separator |
| 38 | 40 | + "db-doc"; |
| ... | ... | @@ -114,11 +116,14 @@ public class InfDbDocController { |
| 114 | 116 | */ |
| 115 | 117 | // TODO 芋艿:screw 暂时不支持 druid,尴尬 |
| 116 | 118 | private HikariDataSource buildDataSource() { |
| 119 | + // 获得 DataSource 数据源,目前只支持首个 | |
| 120 | + String primary = dynamicDataSourceProperties.getPrimary(); | |
| 121 | + DataSourceProperty dataSourceProperty = dynamicDataSourceProperties.getDatasource().get(primary); | |
| 117 | 122 | // 创建 HikariConfig 配置类 |
| 118 | 123 | HikariConfig hikariConfig = new HikariConfig(); |
| 119 | - hikariConfig.setJdbcUrl(dataSourceProperties.getUrl()); | |
| 120 | - hikariConfig.setUsername(dataSourceProperties.getUsername()); | |
| 121 | - hikariConfig.setPassword(dataSourceProperties.getPassword()); | |
| 124 | + hikariConfig.setJdbcUrl(dataSourceProperty.getUrl()); | |
| 125 | + hikariConfig.setUsername(dataSourceProperty.getUsername()); | |
| 126 | + hikariConfig.setPassword(dataSourceProperty.getPassword()); | |
| 122 | 127 | hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息 |
| 123 | 128 | // 创建数据源 |
| 124 | 129 | return new HikariDataSource(hikariConfig); | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/convert/test/ToolTestDemoConvert.java
| 1 | 1 | package cn.iocoder.yudao.adminserver.modules.tool.convert.test; |
| 2 | 2 | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 3 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoExcelVO; | |
| 6 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoRespVO; | |
| 7 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoUpdateReqVO; | |
| 8 | -import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; | |
| 6 | + | |
| 9 | 7 | import org.mapstruct.Mapper; |
| 10 | 8 | import org.mapstruct.factory.Mappers; |
| 11 | - | |
| 12 | -import java.util.List; | |
| 9 | +import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*; | |
| 10 | +import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; | |
| 13 | 11 | |
| 14 | 12 | /** |
| 15 | -* 字典类型 Convert | |
| 16 | -* | |
| 17 | -* @author 芋艿 | |
| 18 | -*/ | |
| 13 | + * 字典类型 Convert | |
| 14 | + * | |
| 15 | + * @author 芋艿 | |
| 16 | + */ | |
| 19 | 17 | @Mapper |
| 20 | 18 | public interface ToolTestDemoConvert { |
| 21 | 19 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/dal/dataobject/test/ToolTestDemoDO.java
| 1 | 1 | package cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 5 | -import com.baomidou.mybatisplus.annotation.TableId; | |
| 6 | -import com.baomidou.mybatisplus.annotation.TableName; | |
| 7 | 3 | import lombok.*; |
| 4 | +import java.util.*; | |
| 5 | +import com.baomidou.mybatisplus.annotation.*; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 8 | 7 | |
| 9 | 8 | /** |
| 10 | -* 字典类型 DO | |
| 11 | -* | |
| 12 | -* @author 芋艿 | |
| 13 | -*/ | |
| 9 | + * 字典类型 DO | |
| 10 | + * | |
| 11 | + * @author 芋艿 | |
| 12 | + */ | |
| 14 | 13 | @TableName("tool_test_demo") |
| 15 | 14 | @Data |
| 16 | 15 | @EqualsAndHashCode(callSuper = true) |
| ... | ... | @@ -31,20 +30,14 @@ public class ToolTestDemoDO extends BaseDO { |
| 31 | 30 | private String name; |
| 32 | 31 | /** |
| 33 | 32 | * 状态 |
| 34 | - * | |
| 35 | - * 枚举 {@link CommonStatusEnum} | |
| 36 | 33 | */ |
| 37 | 34 | private Integer status; |
| 38 | 35 | /** |
| 39 | 36 | * 类型 |
| 40 | - * | |
| 41 | - * 枚举 {@link cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum} | |
| 42 | 37 | */ |
| 43 | 38 | private Integer type; |
| 44 | 39 | /** |
| 45 | 40 | * 分类 |
| 46 | - * | |
| 47 | - * 枚举 {@link cn.iocoder.yudao.framework.redis.core.RedisKeyDefine.TimeoutTypeEnum} | |
| 48 | 41 | */ |
| 49 | 42 | private Integer category; |
| 50 | 43 | /** | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/dal/mysql/test/ToolTestDemoMapper.java
| 1 | 1 | package cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.test; |
| 2 | 2 | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 3 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoExportReqVO; | |
| 7 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoPageReqVO; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | 8 | import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; |
| 9 | 9 | import org.apache.ibatis.annotations.Mapper; |
| 10 | - | |
| 11 | -import java.util.List; | |
| 10 | +import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*; | |
| 12 | 11 | |
| 13 | 12 | /** |
| 14 | 13 | * 字典类型 Mapper |
| ... | ... | @@ -26,7 +25,7 @@ public interface ToolTestDemoMapper extends BaseMapperX<ToolTestDemoDO> { |
| 26 | 25 | .eqIfPresent("category", reqVO.getCategory()) |
| 27 | 26 | .eqIfPresent("remark", reqVO.getRemark()) |
| 28 | 27 | .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) |
| 29 | - ); | |
| 28 | + .orderByDesc("id")); | |
| 30 | 29 | } |
| 31 | 30 | |
| 32 | 31 | default List<ToolTestDemoDO> selectList(ToolTestDemoExportReqVO reqVO) { |
| ... | ... | @@ -37,7 +36,7 @@ public interface ToolTestDemoMapper extends BaseMapperX<ToolTestDemoDO> { |
| 37 | 36 | .eqIfPresent("category", reqVO.getCategory()) |
| 38 | 37 | .eqIfPresent("remark", reqVO.getRemark()) |
| 39 | 38 | .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) |
| 40 | - ); | |
| 39 | + .orderByDesc("id")); | |
| 41 | 40 | } |
| 42 | 41 | |
| 43 | 42 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/enums/ToolDictTypeConstants.java
0 → 100644
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/codegen/impl/ToolCodegenEngine.java
| ... | ... | @@ -125,8 +125,6 @@ public class ToolCodegenEngine { |
| 125 | 125 | // VO 类,独有字段 |
| 126 | 126 | globalBindingMap.put("PageParamClassName", PageParam.class.getName()); |
| 127 | 127 | globalBindingMap.put("DictFormatClassName", DictFormat.class.getName()); |
| 128 | - // TODO 芋艿:代码生成器,解决下枚举类 | |
| 129 | -// globalBindingMap.put("SysDictTypeEnumClassName", SysDictTypeEnum.class.getName()); | |
| 130 | 128 | // DO 类,独有字段 |
| 131 | 129 | globalBindingMap.put("baseDOFields", ToolCodegenBuilder.BASE_DO_FIELDS); |
| 132 | 130 | globalBindingMap.put("BaseDOClassName", BaseDO.class.getName()); | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/test/ToolTestDemoService.java
| 1 | 1 | package cn.iocoder.yudao.adminserver.modules.tool.service.test; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoExportReqVO; | |
| 6 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoPageReqVO; | |
| 7 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoUpdateReqVO; | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*; | |
| 8 | 6 | import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; |
| 9 | - | |
| 10 | -import javax.validation.Valid; | |
| 11 | -import java.util.Collection; | |
| 12 | -import java.util.List; | |
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 13 | 8 | |
| 14 | 9 | /** |
| 15 | 10 | * 字典类型 Service 接口 |
| ... | ... | @@ -68,7 +63,7 @@ public interface ToolTestDemoService { |
| 68 | 63 | * 获得字典类型列表, 用于 Excel 导出 |
| 69 | 64 | * |
| 70 | 65 | * @param exportReqVO 查询条件 |
| 71 | - * @return 字典类型分页 | |
| 66 | + * @return 字典类型列表 | |
| 72 | 67 | */ |
| 73 | 68 | List<ToolTestDemoDO> getTestDemoList(ToolTestDemoExportReqVO exportReqVO); |
| 74 | 69 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/test/impl/ToolTestDemoServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.adminserver.modules.tool.service.test.impl; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | + | |
| 7 | +import java.util.*; | |
| 8 | +import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*; | |
| 9 | +import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; | |
| 4 | 10 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoCreateReqVO; | |
| 6 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoExportReqVO; | |
| 7 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoPageReqVO; | |
| 8 | -import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoUpdateReqVO; | |
| 11 | + | |
| 9 | 12 | import cn.iocoder.yudao.adminserver.modules.tool.convert.test.ToolTestDemoConvert; |
| 10 | -import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; | |
| 11 | 13 | import cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.test.ToolTestDemoMapper; |
| 12 | 14 | import cn.iocoder.yudao.adminserver.modules.tool.service.test.ToolTestDemoService; |
| 13 | -import org.springframework.stereotype.Service; | |
| 14 | -import org.springframework.validation.annotation.Validated; | |
| 15 | 15 | |
| 16 | -import javax.annotation.Resource; | |
| 17 | -import java.util.Collection; | |
| 18 | -import java.util.List; | |
| 19 | - | |
| 20 | -import static cn.iocoder.yudao.adminserver.modules.tool.enums.ToolErrorCodeConstants.TEST_DEMO_NOT_EXISTS; | |
| 16 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 17 | +import static cn.iocoder.yudao.adminserver.modules.tool.enums.ToolErrorCodeConstants.*; | |
| 21 | 18 | |
| 22 | 19 | /** |
| 23 | 20 | * 字典类型 Service 实现类 |
| ... | ... | @@ -53,13 +50,13 @@ public class ToolTestDemoServiceImpl implements ToolTestDemoService { |
| 53 | 50 | public void deleteTestDemo(Long id) { |
| 54 | 51 | // 校验存在 |
| 55 | 52 | this.validateTestDemoExists(id); |
| 56 | - // 更新 | |
| 53 | + // 删除 | |
| 57 | 54 | testDemoMapper.deleteById(id); |
| 58 | 55 | } |
| 59 | 56 | |
| 60 | 57 | private void validateTestDemoExists(Long id) { |
| 61 | 58 | if (testDemoMapper.selectById(id) == null) { |
| 62 | - throw ServiceExceptionUtil.exception(TEST_DEMO_NOT_EXISTS); | |
| 59 | + throw exception(TEST_DEMO_NOT_EXISTS); | |
| 63 | 60 | } |
| 64 | 61 | } |
| 65 | 62 | |
| ... | ... | @@ -75,12 +72,12 @@ public class ToolTestDemoServiceImpl implements ToolTestDemoService { |
| 75 | 72 | |
| 76 | 73 | @Override |
| 77 | 74 | public PageResult<ToolTestDemoDO> getTestDemoPage(ToolTestDemoPageReqVO pageReqVO) { |
| 78 | - return testDemoMapper.selectPage(pageReqVO); | |
| 75 | + return testDemoMapper.selectPage(pageReqVO); | |
| 79 | 76 | } |
| 80 | 77 | |
| 81 | 78 | @Override |
| 82 | 79 | public List<ToolTestDemoDO> getTestDemoList(ToolTestDemoExportReqVO exportReqVO) { |
| 83 | - return testDemoMapper.selectList(exportReqVO); | |
| 80 | + return testDemoMapper.selectList(exportReqVO); | |
| 84 | 81 | } |
| 85 | 82 | |
| 86 | 83 | } | ... | ... |
yudao-admin-server/src/main/resources/codegen/java/controller/vo/excelVO.vm
| ... | ... | @@ -10,7 +10,6 @@ import com.alibaba.excel.annotation.ExcelProperty; |
| 10 | 10 | import ${DictFormatClassName}; |
| 11 | 11 | import ${DictConvertClassName}; |
| 12 | 12 | |
| 13 | -import static ${SysDictTypeEnumClassName}.*; | |
| 14 | 13 | #break |
| 15 | 14 | #end |
| 16 | 15 | #end |
| ... | ... | @@ -27,7 +26,7 @@ public class ${table.className}ExcelVO { |
| 27 | 26 | #if (${column.listOperationResult})##返回字段 |
| 28 | 27 | #if ("$!column.dictType" != "")##处理枚举值 |
| 29 | 28 | @ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class) |
| 30 | - @DictFormat(${column.dictType.toUpperCase()}) | |
| 29 | + @DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 | |
| 31 | 30 | #else |
| 32 | 31 | @ExcelProperty("${column.columnComment}") |
| 33 | 32 | #end | ... | ... |
yudao-admin-server/src/main/resources/codegen/java/service/serviceImpl.vm
| 1 | 1 | package ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.impl; |
| 2 | 2 | |
| 3 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 4 | 3 | import org.springframework.stereotype.Service; |
| 5 | 4 | import javax.annotation.Resource; |
| 6 | 5 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -14,9 +13,7 @@ import ${basePackage}.modules.${table.moduleName}.convert.${table.businessName}. |
| 14 | 13 | import ${basePackage}.modules.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper; |
| 15 | 14 | import ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.${table.className}Service; |
| 16 | 15 | |
| 17 | -import ${ServiceExceptionUtilClassName}; | |
| 18 | - | |
| 19 | -import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception; | |
| 16 | +import static ${ServiceExceptionUtilClassName}.exception; | |
| 20 | 17 | import static ${basePackage}.modules.${table.moduleName}.enums.${simpleModuleName_upperFirst}ErrorCodeConstants.*; |
| 21 | 18 | |
| 22 | 19 | /** | ... | ... |