From 8e6fa3db558ecfed7c6b1a740df3c18b43db4eea Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 3 May 2021 01:17:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=9E=84=E8=B0=83?= =?UTF-8?q?=E6=95=B4=20x=2019=20:=20=E8=A7=A3=E5=86=B3=E5=A4=9A=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=BA=90=E5=90=8E=EF=BC=8C=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E5=AF=BC=E5=87=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/doc/InfDbDocController.java | 13 +++++--- .../convert/test/ToolTestDemoConvert.java | 20 +++++------ .../dal/dataobject/test/ToolTestDemoDO.java | 21 ++++-------- .../dal/mysql/test/ToolTestDemoMapper.java | 13 ++++---- .../tool/enums/ToolDictTypeConstants.java | 12 +++++++ .../codegen/impl/ToolCodegenEngine.java | 2 -- .../service/test/ToolTestDemoService.java | 15 +++------ .../test/impl/ToolTestDemoServiceImpl.java | 33 +++++++++---------- .../codegen/java/controller/vo/excelVO.vm | 3 +- .../codegen/java/service/serviceImpl.vm | 5 +-- 10 files changed, 65 insertions(+), 72 deletions(-) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/enums/ToolDictTypeConstants.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/doc/InfDbDocController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/doc/InfDbDocController.java index 19f72e1b0..48b52f88a 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/controller/doc/InfDbDocController.java +++ b/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; import cn.smallbun.screw.core.engine.EngineTemplateType; import cn.smallbun.screw.core.execute.DocumentationExecute; 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.HikariDataSource; import io.swagger.annotations.Api; @@ -32,7 +34,7 @@ import java.util.Collections; public class InfDbDocController { @Resource - private DataSourceProperties dataSourceProperties; + private DynamicDataSourceProperties dynamicDataSourceProperties; private static final String FILE_OUTPUT_DIR = System.getProperty("java.io.tmpdir") + File.separator + "db-doc"; @@ -114,11 +116,14 @@ public class InfDbDocController { */ // TODO 芋艿:screw 暂时不支持 druid,尴尬 private HikariDataSource buildDataSource() { + // 获得 DataSource 数据源,目前只支持首个 + String primary = dynamicDataSourceProperties.getPrimary(); + DataSourceProperty dataSourceProperty = dynamicDataSourceProperties.getDatasource().get(primary); // 创建 HikariConfig 配置类 HikariConfig hikariConfig = new HikariConfig(); - hikariConfig.setJdbcUrl(dataSourceProperties.getUrl()); - hikariConfig.setUsername(dataSourceProperties.getUsername()); - hikariConfig.setPassword(dataSourceProperties.getPassword()); + hikariConfig.setJdbcUrl(dataSourceProperty.getUrl()); + hikariConfig.setUsername(dataSourceProperty.getUsername()); + hikariConfig.setPassword(dataSourceProperty.getPassword()); hikariConfig.addDataSourceProperty("useInformationSchema", "true"); // 设置可以获取 tables remarks 信息 // 创建数据源 return new HikariDataSource(hikariConfig); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/convert/test/ToolTestDemoConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/convert/test/ToolTestDemoConvert.java index 25f41faa0..8e88c59f4 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/convert/test/ToolTestDemoConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/convert/test/ToolTestDemoConvert.java @@ -1,21 +1,19 @@ package cn.iocoder.yudao.adminserver.modules.tool.convert.test; +import java.util.*; + 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.factory.Mappers; - -import java.util.List; +import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*; +import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; /** -* 字典类型 Convert -* -* @author 芋艿 -*/ + * 字典类型 Convert + * + * @author 芋艿 + */ @Mapper public interface ToolTestDemoConvert { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/dal/dataobject/test/ToolTestDemoDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/dal/dataobject/test/ToolTestDemoDO.java index d77ec22e2..0af46d798 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/dal/dataobject/test/ToolTestDemoDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/dal/dataobject/test/ToolTestDemoDO.java @@ -1,16 +1,15 @@ 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 java.util.*; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; /** -* 字典类型 DO -* -* @author 芋艿 -*/ + * 字典类型 DO + * + * @author 芋艿 + */ @TableName("tool_test_demo") @Data @EqualsAndHashCode(callSuper = true) @@ -31,20 +30,14 @@ public class ToolTestDemoDO extends BaseDO { private String name; /** * 状态 - * - * 枚举 {@link CommonStatusEnum} */ private Integer status; /** * 类型 - * - * 枚举 {@link cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum} */ private Integer type; /** * 分类 - * - * 枚举 {@link cn.iocoder.yudao.framework.redis.core.RedisKeyDefine.TimeoutTypeEnum} */ private Integer category; /** diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/dal/mysql/test/ToolTestDemoMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/dal/mysql/test/ToolTestDemoMapper.java index 937ba07c2..4bee17eb1 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/dal/mysql/test/ToolTestDemoMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/dal/mysql/test/ToolTestDemoMapper.java @@ -1,14 +1,13 @@ 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.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -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.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; import org.apache.ibatis.annotations.Mapper; - -import java.util.List; +import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*; /** * 字典类型 Mapper @@ -26,7 +25,7 @@ public interface ToolTestDemoMapper extends BaseMapperX { .eqIfPresent("category", reqVO.getCategory()) .eqIfPresent("remark", reqVO.getRemark()) .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) - ); + .orderByDesc("id")); } default List selectList(ToolTestDemoExportReqVO reqVO) { @@ -37,7 +36,7 @@ public interface ToolTestDemoMapper extends BaseMapperX { .eqIfPresent("category", reqVO.getCategory()) .eqIfPresent("remark", reqVO.getRemark()) .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) - ); + .orderByDesc("id")); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/enums/ToolDictTypeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/enums/ToolDictTypeConstants.java new file mode 100644 index 000000000..1bf2b7a1d --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/enums/ToolDictTypeConstants.java @@ -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"; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/codegen/impl/ToolCodegenEngine.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/codegen/impl/ToolCodegenEngine.java index 5560c5684..5a75b9914 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/codegen/impl/ToolCodegenEngine.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/codegen/impl/ToolCodegenEngine.java @@ -125,8 +125,6 @@ public class ToolCodegenEngine { // VO 类,独有字段 globalBindingMap.put("PageParamClassName", PageParam.class.getName()); globalBindingMap.put("DictFormatClassName", DictFormat.class.getName()); - // TODO 芋艿:代码生成器,解决下枚举类 -// globalBindingMap.put("SysDictTypeEnumClassName", SysDictTypeEnum.class.getName()); // DO 类,独有字段 globalBindingMap.put("baseDOFields", ToolCodegenBuilder.BASE_DO_FIELDS); globalBindingMap.put("BaseDOClassName", BaseDO.class.getName()); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/test/ToolTestDemoService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/test/ToolTestDemoService.java index 6ad63b7d7..7fff9185d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/test/ToolTestDemoService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/test/ToolTestDemoService.java @@ -1,15 +1,10 @@ package cn.iocoder.yudao.adminserver.modules.tool.service.test; -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 java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*; import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; - -import javax.validation.Valid; -import java.util.Collection; -import java.util.List; +import cn.iocoder.yudao.framework.common.pojo.PageResult; /** * 字典类型 Service 接口 @@ -68,7 +63,7 @@ public interface ToolTestDemoService { * 获得字典类型列表, 用于 Excel 导出 * * @param exportReqVO 查询条件 - * @return 字典类型分页 + * @return 字典类型列表 */ List getTestDemoList(ToolTestDemoExportReqVO exportReqVO); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/test/impl/ToolTestDemoServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/test/impl/ToolTestDemoServiceImpl.java index b894b5fc5..ad8fd1e81 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/test/impl/ToolTestDemoServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/service/test/impl/ToolTestDemoServiceImpl.java @@ -1,23 +1,20 @@ 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 javax.annotation.Resource; import org.springframework.validation.annotation.Validated; -import javax.annotation.Resource; -import java.util.Collection; -import java.util.List; +import java.util.*; +import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*; +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 实现类 @@ -53,13 +50,13 @@ public class ToolTestDemoServiceImpl implements ToolTestDemoService { public void deleteTestDemo(Long id) { // 校验存在 this.validateTestDemoExists(id); - // 更新 + // 删除 testDemoMapper.deleteById(id); } private void validateTestDemoExists(Long id) { if (testDemoMapper.selectById(id) == null) { - throw ServiceExceptionUtil.exception(TEST_DEMO_NOT_EXISTS); + throw exception(TEST_DEMO_NOT_EXISTS); } } @@ -75,12 +72,12 @@ public class ToolTestDemoServiceImpl implements ToolTestDemoService { @Override public PageResult getTestDemoPage(ToolTestDemoPageReqVO pageReqVO) { - return testDemoMapper.selectPage(pageReqVO); + return testDemoMapper.selectPage(pageReqVO); } @Override public List getTestDemoList(ToolTestDemoExportReqVO exportReqVO) { - return testDemoMapper.selectList(exportReqVO); + return testDemoMapper.selectList(exportReqVO); } } diff --git a/yudao-admin-server/src/main/resources/codegen/java/controller/vo/excelVO.vm b/yudao-admin-server/src/main/resources/codegen/java/controller/vo/excelVO.vm index 29f777190..b91e4e178 100644 --- a/yudao-admin-server/src/main/resources/codegen/java/controller/vo/excelVO.vm +++ b/yudao-admin-server/src/main/resources/codegen/java/controller/vo/excelVO.vm @@ -10,7 +10,6 @@ import com.alibaba.excel.annotation.ExcelProperty; import ${DictFormatClassName}; import ${DictConvertClassName}; -import static ${SysDictTypeEnumClassName}.*; #break #end #end @@ -27,7 +26,7 @@ public class ${table.className}ExcelVO { #if (${column.listOperationResult})##返回字段 #if ("$!column.dictType" != "")##处理枚举值 @ExcelProperty(value = "${column.columnComment}", converter = DictConvert.class) - @DictFormat(${column.dictType.toUpperCase()}) + @DictFormat("${column.dictType}") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中 #else @ExcelProperty("${column.columnComment}") #end diff --git a/yudao-admin-server/src/main/resources/codegen/java/service/serviceImpl.vm b/yudao-admin-server/src/main/resources/codegen/java/service/serviceImpl.vm index 9da0f0e19..33201a6d8 100644 --- a/yudao-admin-server/src/main/resources/codegen/java/service/serviceImpl.vm +++ b/yudao-admin-server/src/main/resources/codegen/java/service/serviceImpl.vm @@ -1,6 +1,5 @@ package ${basePackage}.modules.${table.moduleName}.service.${table.businessName}.impl; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; 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}.service.${table.businessName}.${table.className}Service; -import ${ServiceExceptionUtilClassName}; - -import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception; +import static ${ServiceExceptionUtilClassName}.exception; import static ${basePackage}.modules.${table.moduleName}.enums.${simpleModuleName_upperFirst}ErrorCodeConstants.*; /**