项目结构调整 x 19 : 解决多数据源后,数据库文档导出问题

This commit is contained in:
YunaiV 2021-05-03 01:17:34 +08:00
parent 8a13470f9c
commit 8e6fa3db55
10 changed files with 65 additions and 72 deletions

View File

@ -9,6 +9,8 @@ import cn.smallbun.screw.core.engine.EngineFileType;
import cn.smallbun.screw.core.engine.EngineTemplateType; import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.execute.DocumentationExecute; import cn.smallbun.screw.core.execute.DocumentationExecute;
import cn.smallbun.screw.core.process.ProcessConfig; import cn.smallbun.screw.core.process.ProcessConfig;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -32,7 +34,7 @@ import java.util.Collections;
public class InfDbDocController { public class InfDbDocController {
@Resource @Resource
private DataSourceProperties dataSourceProperties; private DynamicDataSourceProperties dynamicDataSourceProperties;
private static final String FILE_OUTPUT_DIR = System.getProperty("java.io.tmpdir") + File.separator private static final String FILE_OUTPUT_DIR = System.getProperty("java.io.tmpdir") + File.separator
+ "db-doc"; + "db-doc";
@ -114,11 +116,14 @@ public class InfDbDocController {
*/ */
// TODO 芋艿screw 暂时不支持 druid尴尬 // TODO 芋艿screw 暂时不支持 druid尴尬
private HikariDataSource buildDataSource() { private HikariDataSource buildDataSource() {
// 获得 DataSource 数据源目前只支持首个
String primary = dynamicDataSourceProperties.getPrimary();
DataSourceProperty dataSourceProperty = dynamicDataSourceProperties.getDatasource().get(primary);
// 创建 HikariConfig 配置类 // 创建 HikariConfig 配置类
HikariConfig hikariConfig = new HikariConfig(); HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(dataSourceProperties.getUrl()); hikariConfig.setJdbcUrl(dataSourceProperty.getUrl());
hikariConfig.setUsername(dataSourceProperties.getUsername()); hikariConfig.setUsername(dataSourceProperty.getUsername());
hikariConfig.setPassword(dataSourceProperties.getPassword()); hikariConfig.setPassword(dataSourceProperty.getPassword());
hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息 hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息
// 创建数据源 // 创建数据源
return new HikariDataSource(hikariConfig); return new HikariDataSource(hikariConfig);

View File

@ -1,15 +1,13 @@
package cn.iocoder.yudao.adminserver.modules.tool.convert.test; package cn.iocoder.yudao.adminserver.modules.tool.convert.test;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoExcelVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoRespVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*;
import java.util.List; import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO;
/** /**
* 字典类型 Convert * 字典类型 Convert

View File

@ -1,10 +1,9 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test; package cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*; import lombok.*;
import java.util.*;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/** /**
* 字典类型 DO * 字典类型 DO
@ -31,20 +30,14 @@ public class ToolTestDemoDO extends BaseDO {
private String name; private String name;
/** /**
* 状态 * 状态
*
* 枚举 {@link CommonStatusEnum}
*/ */
private Integer status; private Integer status;
/** /**
* 类型 * 类型
*
* 枚举 {@link cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum}
*/ */
private Integer type; private Integer type;
/** /**
* 分类 * 分类
*
* 枚举 {@link cn.iocoder.yudao.framework.redis.core.RedisKeyDefine.TimeoutTypeEnum}
*/ */
private Integer category; private Integer category;
/** /**

View File

@ -1,14 +1,13 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.test; package cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.test;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoExportReqVO; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoPageReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*;
import java.util.List;
/** /**
* 字典类型 Mapper * 字典类型 Mapper
@ -26,7 +25,7 @@ public interface ToolTestDemoMapper extends BaseMapperX<ToolTestDemoDO> {
.eqIfPresent("category", reqVO.getCategory()) .eqIfPresent("category", reqVO.getCategory())
.eqIfPresent("remark", reqVO.getRemark()) .eqIfPresent("remark", reqVO.getRemark())
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
); .orderByDesc("id"));
} }
default List<ToolTestDemoDO> selectList(ToolTestDemoExportReqVO reqVO) { default List<ToolTestDemoDO> selectList(ToolTestDemoExportReqVO reqVO) {
@ -37,7 +36,7 @@ public interface ToolTestDemoMapper extends BaseMapperX<ToolTestDemoDO> {
.eqIfPresent("category", reqVO.getCategory()) .eqIfPresent("category", reqVO.getCategory())
.eqIfPresent("remark", reqVO.getRemark()) .eqIfPresent("remark", reqVO.getRemark())
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
); .orderByDesc("id"));
} }
} }

View File

@ -0,0 +1,12 @@
package cn.iocoder.yudao.adminserver.modules.tool.enums;
/**
* Tool 字典类型的枚举类
*
* @author 芋道源码
*/
public interface ToolDictTypeConstants {
String TEST_DEMO_TYPE = "tool_test_demo_type";
}

View File

@ -125,8 +125,6 @@ public class ToolCodegenEngine {
// VO 独有字段 // VO 独有字段
globalBindingMap.put("PageParamClassName", PageParam.class.getName()); globalBindingMap.put("PageParamClassName", PageParam.class.getName());
globalBindingMap.put("DictFormatClassName", DictFormat.class.getName()); globalBindingMap.put("DictFormatClassName", DictFormat.class.getName());
// TODO 芋艿代码生成器解决下枚举类
// globalBindingMap.put("SysDictTypeEnumClassName", SysDictTypeEnum.class.getName());
// DO 独有字段 // DO 独有字段
globalBindingMap.put("baseDOFields", ToolCodegenBuilder.BASE_DO_FIELDS); globalBindingMap.put("baseDOFields", ToolCodegenBuilder.BASE_DO_FIELDS);
globalBindingMap.put("BaseDOClassName", BaseDO.class.getName()); globalBindingMap.put("BaseDOClassName", BaseDO.class.getName());

View File

@ -1,15 +1,10 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.test; package cn.iocoder.yudao.adminserver.modules.tool.service.test;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import java.util.*;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoCreateReqVO; import javax.validation.*;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoExportReqVO; import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoPageReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/** /**
* 字典类型 Service 接口 * 字典类型 Service 接口
@ -68,7 +63,7 @@ public interface ToolTestDemoService {
* 获得字典类型列表, 用于 Excel 导出 * 获得字典类型列表, 用于 Excel 导出
* *
* @param exportReqVO 查询条件 * @param exportReqVO 查询条件
* @return 字典类型分页 * @return 字典类型列表
*/ */
List<ToolTestDemoDO> getTestDemoList(ToolTestDemoExportReqVO exportReqVO); List<ToolTestDemoDO> getTestDemoList(ToolTestDemoExportReqVO exportReqVO);

View File

@ -1,23 +1,20 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.test.impl; package cn.iocoder.yudao.adminserver.modules.tool.service.test.impl;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoCreateReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoExportReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoPageReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.ToolTestDemoUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.convert.test.ToolTestDemoConvert;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.test.ToolTestDemoMapper;
import cn.iocoder.yudao.adminserver.modules.tool.service.test.ToolTestDemoService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import java.util.*;
import java.util.Collection; import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*;
import java.util.List; import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import static cn.iocoder.yudao.adminserver.modules.tool.enums.ToolErrorCodeConstants.TEST_DEMO_NOT_EXISTS; import cn.iocoder.yudao.adminserver.modules.tool.convert.test.ToolTestDemoConvert;
import cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.test.ToolTestDemoMapper;
import cn.iocoder.yudao.adminserver.modules.tool.service.test.ToolTestDemoService;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.adminserver.modules.tool.enums.ToolErrorCodeConstants.*;
/** /**
* 字典类型 Service 实现类 * 字典类型 Service 实现类
@ -53,13 +50,13 @@ public class ToolTestDemoServiceImpl implements ToolTestDemoService {
public void deleteTestDemo(Long id) { public void deleteTestDemo(Long id) {
// 校验存在 // 校验存在
this.validateTestDemoExists(id); this.validateTestDemoExists(id);
// 更新 // 删除
testDemoMapper.deleteById(id); testDemoMapper.deleteById(id);
} }
private void validateTestDemoExists(Long id) { private void validateTestDemoExists(Long id) {
if (testDemoMapper.selectById(id) == null) { if (testDemoMapper.selectById(id) == null) {
throw ServiceExceptionUtil.exception(TEST_DEMO_NOT_EXISTS); throw exception(TEST_DEMO_NOT_EXISTS);
} }
} }

View File

@ -10,7 +10,6 @@ import com.alibaba.excel.annotation.ExcelProperty;
import ${DictFormatClassName}; import ${DictFormatClassName};
import ${DictConvertClassName}; import ${DictConvertClassName};
import static ${SysDictTypeEnumClassName}.*;
#break #break
#end #end
#end #end
@ -27,7 +26,7 @@ public class ${table.className}ExcelVO {
#if (${column.listOperationResult})##返回字段 #if (${column.listOperationResult})##返回字段
#if ("$!column.dictType" != "")##处理枚举值 #if ("$!column.dictType" != "")##处理枚举值
@ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class) @ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class)
@DictFormat(${column.dictType.toUpperCase()}) @DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
#else #else
@ExcelProperty("${column.columnComment}") @ExcelProperty("${column.columnComment}")
#end #end

View File

@ -1,6 +1,5 @@
package ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.impl; package ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -14,9 +13,7 @@ import ${basePackage}.modules.${table.moduleName}.convert.${table.businessName}.
import ${basePackage}.modules.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper; import ${basePackage}.modules.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper;
import ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.${table.className}Service; import ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.${table.className}Service;
import ${ServiceExceptionUtilClassName}; import static ${ServiceExceptionUtilClassName}.exception;
import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception;
import static ${basePackage}.modules.${table.moduleName}.enums.${simpleModuleName_upperFirst}ErrorCodeConstants.*; import static ${basePackage}.modules.${table.moduleName}.enums.${simpleModuleName_upperFirst}ErrorCodeConstants.*;
/** /**