多模块重构 6:tool 模块的迁移完成

This commit is contained in:
YunaiV 2022-01-31 19:26:39 +08:00
parent fffd023d31
commit e7e3b18704
77 changed files with 791 additions and 641 deletions

View File

@ -17,6 +17,7 @@
<!-- <module>yudao-module-bpm</module>--> <!-- <module>yudao-module-bpm</module>-->
<module>yudao-module-system</module> <module>yudao-module-system</module>
<module>yudao-module-infra</module> <module>yudao-module-infra</module>
<module>yudao-module-tool</module>
</modules> </modules>
<name>${artifactId}</name> <name>${artifactId}</name>

View File

@ -1,21 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.column.ToolCodegenColumnRespVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table.ToolCodegenTableRespVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@ApiModel("代码生成表和字段的明细 Response VO")
@Data
public class ToolCodegenDetailRespVO {
@ApiModelProperty("表定义")
private ToolCodegenTableRespVO table;
@ApiModelProperty("字段定义")
private List<ToolCodegenColumnRespVO> columns;
}

View File

@ -1,70 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.tool.convert.codegen;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.ToolCodegenDetailRespVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.ToolCodegenPreviewRespVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.ToolCodegenUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.column.ToolCodegenColumnRespVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table.ToolCodegenTableRespVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table.ToolSchemaTableRespVO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Mapper
public interface ToolCodegenConvert {
ToolCodegenConvert INSTANCE = Mappers.getMapper(ToolCodegenConvert.class);
// ========== ToolInformationSchemaTableDO ToolInformationSchemaColumnDO 相关 ==========
ToolCodegenTableDO convert(ToolSchemaTableDO bean);
List<ToolCodegenColumnDO> convertList(List<ToolSchemaColumnDO> list);
ToolCodegenTableRespVO convert(ToolSchemaColumnDO bean);
// ========== ToolCodegenTableDO 相关 ==========
// List<ToolCodegenTableRespVO> convertList02(List<ToolCodegenTableDO> list);
ToolCodegenTableRespVO convert(ToolCodegenTableDO bean);
PageResult<ToolCodegenTableRespVO> convertPage(PageResult<ToolCodegenTableDO> page);
// ========== ToolCodegenTableDO 相关 ==========
List<ToolCodegenColumnRespVO> convertList02(List<ToolCodegenColumnDO> list);
ToolCodegenTableDO convert(ToolCodegenUpdateReqVO.Table bean);
List<ToolCodegenColumnDO> convertList03(List<ToolCodegenUpdateReqVO.Column> columns);
List<ToolSchemaTableRespVO> convertList04(List<ToolSchemaTableDO> list);
// ========== 其它 ==========
default ToolCodegenDetailRespVO convert(ToolCodegenTableDO table, List<ToolCodegenColumnDO> columns) {
ToolCodegenDetailRespVO respVO = new ToolCodegenDetailRespVO();
respVO.setTable(convert(table));
respVO.setColumns(convertList02(columns));
return respVO;
}
default List<ToolCodegenPreviewRespVO> convert(Map<String, String> codes) {
return codes.entrySet().stream().map(entry -> {
ToolCodegenPreviewRespVO respVO = new ToolCodegenPreviewRespVO();
respVO.setFilePath(entry.getKey());
respVO.setCode(entry.getValue());
return respVO;
}).collect(Collectors.toList());
}
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.tool.convert.test;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO;
/**
* 字典类型 Convert
*
* @author 芋艿
*/
@Mapper
public interface ToolTestDemoConvert {
ToolTestDemoConvert INSTANCE = Mappers.getMapper(ToolTestDemoConvert.class);
ToolTestDemoDO convert(ToolTestDemoCreateReqVO bean);
ToolTestDemoDO convert(ToolTestDemoUpdateReqVO bean);
ToolTestDemoRespVO convert(ToolTestDemoDO bean);
List<ToolTestDemoRespVO> convertList(List<ToolTestDemoDO> list);
PageResult<ToolTestDemoRespVO> convertPage(PageResult<ToolTestDemoDO> page);
List<ToolTestDemoExcelVO> convertList02(List<ToolTestDemoDO> list);
}

View File

@ -1,22 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ToolCodegenColumnMapper extends BaseMapperX<ToolCodegenColumnDO> {
default List<ToolCodegenColumnDO> selectListByTableId(Long tableId) {
return selectList(new QueryWrapper<ToolCodegenColumnDO>().eq("table_id", tableId)
.orderByAsc("ordinal_position"));
}
default void deleteListByTableId(Long tableId) {
delete(new QueryWrapper<ToolCodegenColumnDO>().eq("table_id", tableId));
}
}

View File

@ -1,25 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen;
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.codegen.vo.table.ToolCodegenTablePageReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ToolCodegenTableMapper extends BaseMapperX<ToolCodegenTableDO> {
default ToolCodegenTableDO selectByTableName(String tableName) {
return selectOne(new QueryWrapper<ToolCodegenTableDO>().eq("table_name", tableName));
}
default PageResult<ToolCodegenTableDO> selectPage(ToolCodegenTablePageReqVO pageReqVO) {
return selectPage(pageReqVO, new QueryWrapperX<ToolCodegenTableDO>()
.likeIfPresent("table_name", pageReqVO.getTableName())
.likeIfPresent("table_comment", pageReqVO.getTableComment())
.betweenIfPresent("create_time", pageReqVO.getBeginCreateTime(), pageReqVO.getEndCreateTime()));
}
}

View File

@ -1,19 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ToolSchemaColumnMapper extends BaseMapperX<ToolSchemaColumnDO> {
default List<ToolSchemaColumnDO> selectListByTableName(String tableSchema, String tableName) {
return selectList(new QueryWrapper<ToolSchemaColumnDO>().eq("table_name", tableName)
.eq("table_schema", tableSchema)
.orderByAsc("ordinal_position"));
}
}

View File

@ -1,26 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen;
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.dal.dataobject.codegen.ToolSchemaTableDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
@Mapper
public interface ToolSchemaTableMapper extends BaseMapperX<ToolSchemaTableDO> {
default List<ToolSchemaTableDO> selectList(Collection<String> tableSchemas, String tableName, String tableComment) {
return selectList(new QueryWrapperX<ToolSchemaTableDO>().in("table_schema", tableSchemas)
.likeIfPresent("table_name", tableName)
.likeIfPresent("table_comment", tableComment));
}
default ToolSchemaTableDO selectByTableSchemaAndTableName(String tableSchema, String tableName) {
return selectOne(new QueryWrapper<ToolSchemaTableDO>().eq("table_schema",tableSchema)
.eq("table_name", tableName));
}
}

View File

@ -1,4 +0,0 @@
/**
* 代码生成器
*/
package cn.iocoder.yudao.adminserver.modules.tool.framework.codegen;

View File

@ -1,7 +0,0 @@
/**
* tool 包下我们放研发工具提升研发效率与质量
* 例如说代码生成器接口文档等等
*
* 缩写tool
*/
package cn.iocoder.yudao.adminserver.modules.tool;

View File

@ -1,83 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.test.impl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
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 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 实现类
*
* @author 芋艿
*/
@Service
@Validated
public class ToolTestDemoServiceImpl implements ToolTestDemoService {
@Resource
private ToolTestDemoMapper testDemoMapper;
@Override
public Long createTestDemo(ToolTestDemoCreateReqVO createReqVO) {
// 插入
ToolTestDemoDO testDemo = ToolTestDemoConvert.INSTANCE.convert(createReqVO);
testDemoMapper.insert(testDemo);
// 返回
return testDemo.getId();
}
@Override
public void updateTestDemo(ToolTestDemoUpdateReqVO updateReqVO) {
// 校验存在
this.validateTestDemoExists(updateReqVO.getId());
// 更新
ToolTestDemoDO updateObj = ToolTestDemoConvert.INSTANCE.convert(updateReqVO);
testDemoMapper.updateById(updateObj);
}
@Override
public void deleteTestDemo(Long id) {
// 校验存在
this.validateTestDemoExists(id);
// 删除
testDemoMapper.deleteById(id);
}
private void validateTestDemoExists(Long id) {
if (testDemoMapper.selectById(id) == null) {
throw exception(TEST_DEMO_NOT_EXISTS);
}
}
@Override
public ToolTestDemoDO getTestDemo(Long id) {
return testDemoMapper.selectById(id);
}
@Override
public List<ToolTestDemoDO> getTestDemoList(Collection<Long> ids) {
return testDemoMapper.selectBatchIds(ids);
}
@Override
public PageResult<ToolTestDemoDO> getTestDemoPage(ToolTestDemoPageReqVO pageReqVO) {
return testDemoMapper.selectPage(pageReqVO);
}
@Override
public List<ToolTestDemoDO> getTestDemoList(ToolTestDemoExportReqVO exportReqVO) {
return testDemoMapper.selectList(exportReqVO);
}
}

View File

@ -100,7 +100,7 @@ apollo:
eagerLoad: eagerLoad:
enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置
jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 jdbc: # 自定义的 JDBC 配置项,用于数据库的地址
dao: cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigCoreDAOImpl dao: cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigDAOImpl
url: ${spring.datasource.dynamic.datasource.master.url} url: ${spring.datasource.dynamic.datasource.master.url}
username: ${spring.datasource.dynamic.datasource.master.username} username: ${spring.datasource.dynamic.datasource.master.username}
password: ${spring.datasource.dynamic.datasource.master.password} password: ${spring.datasource.dynamic.datasource.master.password}

View File

@ -113,7 +113,7 @@ apollo:
eagerLoad: eagerLoad:
enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置
jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 jdbc: # 自定义的 JDBC 配置项,用于数据库的地址
dao: cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigCoreDAOImpl dao: cn.iocoder.yudao.module.infra.dal.mysql.config.ConfigDAOImpl
url: ${spring.datasource.dynamic.datasource.master.url} url: ${spring.datasource.dynamic.datasource.master.url}
username: ${spring.datasource.dynamic.datasource.master.username} username: ${spring.datasource.dynamic.datasource.master.username}
password: ${spring.datasource.dynamic.datasource.master.password} password: ${spring.datasource.dynamic.datasource.master.password}

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen; package cn.iocoder.yudao.module.tool.dal.mysql.codegen;
import cn.iocoder.yudao.adminserver.BaseDbUnitTest; import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javax.annotation.Resource; import javax.annotation.Resource;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen; package cn.iocoder.yudao.module.tool.dal.mysql.codegen;
import cn.iocoder.yudao.adminserver.BaseDbUnitTest; import cn.iocoder.yudao.adminserver.BaseDbUnitTest;

View File

@ -1,11 +1,11 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.codegen; package cn.iocoder.yudao.module.tool.service.codegen;
import cn.iocoder.yudao.adminserver.BaseDbUnitTest; import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.ToolCodegenTableDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen.ToolCodegenColumnMapper; import cn.iocoder.yudao.module.tool.dal.mysql.codegen.ToolCodegenColumnMapper;
import cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen.ToolCodegenTableMapper; import cn.iocoder.yudao.module.tool.dal.mysql.codegen.ToolCodegenTableMapper;
import cn.iocoder.yudao.adminserver.modules.tool.service.codegen.impl.ToolCodegenEngine; import cn.iocoder.yudao.module.tool.service.codegen.impl.ToolCodegenEngine;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javax.annotation.Resource; import javax.annotation.Resource;

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.codegen; package cn.iocoder.yudao.module.tool.service.codegen;
import cn.iocoder.yudao.adminserver.BaseDbUnitTest; import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
import cn.iocoder.yudao.adminserver.modules.tool.service.codegen.impl.ToolCodegenSQLParser; import cn.iocoder.yudao.module.tool.service.codegen.impl.ToolCodegenSQLParser;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class ToolCodegenSQLParserTest extends BaseDbUnitTest { public class ToolCodegenSQLParserTest extends BaseDbUnitTest {

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.codegen; package cn.iocoder.yudao.module.tool.service.codegen;
import cn.iocoder.yudao.adminserver.BaseDbUnitTest; import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
import cn.iocoder.yudao.adminserver.modules.tool.service.codegen.impl.ToolCodegenServiceImpl; import cn.iocoder.yudao.module.tool.service.codegen.impl.ToolCodegenServiceImpl;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javax.annotation.Resource; import javax.annotation.Resource;

View File

@ -137,7 +137,6 @@ public class AdminAuthServiceImpl implements AdminAuthService {
// 在其内部会调用到 loadUserByUsername 方法获取 User 信息 // 在其内部会调用到 loadUserByUsername 方法获取 User 信息
authentication = authenticationManager.authenticate(new MultiUsernamePasswordAuthenticationToken( authentication = authenticationManager.authenticate(new MultiUsernamePasswordAuthenticationToken(
username, password, getUserType())); username, password, getUserType()));
// org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId(username);
} catch (BadCredentialsException badCredentialsException) { } catch (BadCredentialsException badCredentialsException) {
this.createLoginLog(username, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS); this.createLoginLog(username, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
throw exception(AUTH_LOGIN_BAD_CREDENTIALS); throw exception(AUTH_LOGIN_BAD_CREDENTIALS);

24
yudao-module-tool/pom.xml Normal file
View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<modules>
<module>yudao-module-tool-api</module>
<module>yudao-module-tool-impl</module>
</modules>
<artifactId>yudao-module-tool</artifactId>
<packaging>pom</packaging>
<name>${artifactId}</name>
<description>
tool 模块,我们放研发工具,提升研发效率与质量。
例如说:代码生成器、接口文档等等
</description>
</project>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-tool</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yudao-module-tool-api</artifactId>
<packaging>jar</packaging>
<name>${artifactId}</name>
<description>
tool 模块 API暴露给其它模块调用
</description>
<dependencies>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-common</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,4 @@
/**
* Tool API 定义暴露给其它模块的 API
*/
package cn.iocoder.yudao.module.tool.api;

View File

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

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.enums; package cn.iocoder.yudao.module.tool.enums;
import cn.iocoder.yudao.framework.common.exception.ErrorCode; import cn.iocoder.yudao.framework.common.exception.ErrorCode;
@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
* *
* tool 系统使用 1-003-000-000 * tool 系统使用 1-003-000-000
*/ */
public interface ToolErrorCodeConstants { public interface ErrorCodeConstants {
// ========== 字典类型测试 1003000000 ========== // ========== 字典类型测试 1003000000 ==========
ErrorCode TEST_DEMO_NOT_EXISTS = new ErrorCode(1003000000, "测试示例不存在"); ErrorCode TEST_DEMO_NOT_EXISTS = new ErrorCode(1003000000, "测试示例不存在");

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.module.tool;

View File

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>yudao-module-tool</artifactId>
<groupId>cn.iocoder.boot</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yudao-module-tool-impl</artifactId>
<packaging>jar</packaging>
<name>${artifactId}</name>
<description>
tool 模块,我们放研发工具,提升研发效率与质量。
例如说:代码生成器、接口文档等等
</description>
<dependencies>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-tool-api</artifactId>
<version>${revision}</version>
</dependency>
<!-- 业务组件 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-dict</artifactId>
</dependency>
<!-- Web 相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-security</artifactId>
</dependency>
<!-- DB 相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-mybatis</artifactId>
</dependency>
<!-- Test 测试相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 工具类相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-excel</artifactId>
</dependency>
</dependencies>
<build>
<!-- 设置构建的 jar 包名 -->
<finalName>${artifactId}</finalName>
<plugins>
<!-- 打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal> <!-- 将引入的 jar 打入其中 -->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,20 +1,20 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.codegen; package cn.iocoder.yudao.module.tool.controller.admin.codegen;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ZipUtil; import cn.hutool.core.util.ZipUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.ToolCodegenDetailRespVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.CodegenDetailRespVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.ToolCodegenPreviewRespVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.CodegenPreviewRespVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.ToolCodegenUpdateReqVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.CodegenUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table.ToolCodegenTablePageReqVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table.CodegenTablePageReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table.ToolCodegenTableRespVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table.CodegenTableRespVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table.ToolSchemaTableRespVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table.SchemaTableRespVO;
import cn.iocoder.yudao.adminserver.modules.tool.convert.codegen.ToolCodegenConvert; import cn.iocoder.yudao.module.tool.convert.codegen.CodegenConvert;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenColumnDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenTableDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaTableDO;
import cn.iocoder.yudao.adminserver.modules.tool.service.codegen.ToolCodegenService; import cn.iocoder.yudao.module.tool.service.codegen.CodegenService;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -37,14 +37,14 @@ import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Api(tags = "代码生成器") @Api(tags = "管理后台 - 代码生成器")
@RestController @RestController
@RequestMapping("/tool/codegen") @RequestMapping("/tool/codegen")
@Validated @Validated
public class ToolCodegenController { public class CodegenController {
@Resource @Resource
private ToolCodegenService codegenService; private CodegenService codegenService;
@GetMapping("/db/table/list") @GetMapping("/db/table/list")
@ApiOperation(value = "获得数据库自带的表定义列表", notes = "会过滤掉已经导入 Codegen 的表") @ApiOperation(value = "获得数据库自带的表定义列表", notes = "会过滤掉已经导入 Codegen 的表")
@ -53,34 +53,34 @@ public class ToolCodegenController {
@ApiImplicitParam(name = "tableComment", value = "描述,模糊匹配", required = true, example = "芋道", dataTypeClass = String.class) @ApiImplicitParam(name = "tableComment", value = "描述,模糊匹配", required = true, example = "芋道", dataTypeClass = String.class)
}) })
@PreAuthorize("@ss.hasPermission('tool:codegen:query')") @PreAuthorize("@ss.hasPermission('tool:codegen:query')")
public CommonResult<List<ToolSchemaTableRespVO>> getSchemaTableList( public CommonResult<List<SchemaTableRespVO>> getSchemaTableList(
@RequestParam(value = "tableName", required = false) String tableName, @RequestParam(value = "tableName", required = false) String tableName,
@RequestParam(value = "tableComment", required = false) String tableComment) { @RequestParam(value = "tableComment", required = false) String tableComment) {
// 获得数据库自带的表定义列表 // 获得数据库自带的表定义列表
List<ToolSchemaTableDO> schemaTables = codegenService.getSchemaTableList(tableName, tableComment); List<SchemaTableDO> schemaTables = codegenService.getSchemaTableList(tableName, tableComment);
// 移除在 Codegen 已经存在的 // 移除在 Codegen 已经存在的
Set<String> existsTables = CollectionUtils.convertSet(codegenService.getCodeGenTableList(), ToolCodegenTableDO::getTableName); Set<String> existsTables = CollectionUtils.convertSet(codegenService.getCodeGenTableList(), CodegenTableDO::getTableName);
schemaTables.removeIf(table -> existsTables.contains(table.getTableName())); schemaTables.removeIf(table -> existsTables.contains(table.getTableName()));
return success(ToolCodegenConvert.INSTANCE.convertList04(schemaTables)); return success(CodegenConvert.INSTANCE.convertList04(schemaTables));
} }
@GetMapping("/table/page") @GetMapping("/table/page")
@ApiOperation("获得表定义分页") @ApiOperation("获得表定义分页")
@PreAuthorize("@ss.hasPermission('tool:codegen:query')") @PreAuthorize("@ss.hasPermission('tool:codegen:query')")
public CommonResult<PageResult<ToolCodegenTableRespVO>> getCodeGenTablePage(@Valid ToolCodegenTablePageReqVO pageReqVO) { public CommonResult<PageResult<CodegenTableRespVO>> getCodeGenTablePage(@Valid CodegenTablePageReqVO pageReqVO) {
PageResult<ToolCodegenTableDO> pageResult = codegenService.getCodegenTablePage(pageReqVO); PageResult<CodegenTableDO> pageResult = codegenService.getCodegenTablePage(pageReqVO);
return success(ToolCodegenConvert.INSTANCE.convertPage(pageResult)); return success(CodegenConvert.INSTANCE.convertPage(pageResult));
} }
@GetMapping("/detail") @GetMapping("/detail")
@ApiOperation("获得表和字段的明细") @ApiOperation("获得表和字段的明细")
@ApiImplicitParam(name = "tableId", value = "表编号", required = true, example = "1024", dataTypeClass = Long.class) @ApiImplicitParam(name = "tableId", value = "表编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('tool:codegen:query')") @PreAuthorize("@ss.hasPermission('tool:codegen:query')")
public CommonResult<ToolCodegenDetailRespVO> getCodegenDetail(@RequestParam("tableId") Long tableId) { public CommonResult<CodegenDetailRespVO> getCodegenDetail(@RequestParam("tableId") Long tableId) {
ToolCodegenTableDO table = codegenService.getCodegenTablePage(tableId); CodegenTableDO table = codegenService.getCodegenTablePage(tableId);
List<ToolCodegenColumnDO> columns = codegenService.getCodegenColumnListByTableId(tableId); List<CodegenColumnDO> columns = codegenService.getCodegenColumnListByTableId(tableId);
// 拼装返回 // 拼装返回
return success(ToolCodegenConvert.INSTANCE.convert(table, columns)); return success(CodegenConvert.INSTANCE.convert(table, columns));
} }
@ApiOperation("基于数据库的表结构,创建代码生成器的表和字段定义") @ApiOperation("基于数据库的表结构,创建代码生成器的表和字段定义")
@ -102,7 +102,7 @@ public class ToolCodegenController {
@ApiOperation("更新数据库的表和字段定义") @ApiOperation("更新数据库的表和字段定义")
@PutMapping("/update") @PutMapping("/update")
@PreAuthorize("@ss.hasPermission('tool:codegen:update')") @PreAuthorize("@ss.hasPermission('tool:codegen:update')")
public CommonResult<Boolean> updateCodegen(@Valid @RequestBody ToolCodegenUpdateReqVO updateReqVO) { public CommonResult<Boolean> updateCodegen(@Valid @RequestBody CodegenUpdateReqVO updateReqVO) {
codegenService.updateCodegen(updateReqVO); codegenService.updateCodegen(updateReqVO);
return success(true); return success(true);
} }
@ -142,9 +142,9 @@ public class ToolCodegenController {
@GetMapping("/preview") @GetMapping("/preview")
@ApiImplicitParam(name = "tableId", value = "表编号", required = true, example = "1024", dataTypeClass = Long.class) @ApiImplicitParam(name = "tableId", value = "表编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('tool:codegen:preview')") @PreAuthorize("@ss.hasPermission('tool:codegen:preview')")
public CommonResult<List<ToolCodegenPreviewRespVO>> previewCodegen(@RequestParam("tableId") Long tableId) { public CommonResult<List<CodegenPreviewRespVO>> previewCodegen(@RequestParam("tableId") Long tableId) {
Map<String, String> codes = codegenService.generationCodes(tableId); Map<String, String> codes = codegenService.generationCodes(tableId);
return success(ToolCodegenConvert.INSTANCE.convert(codes)); return success(CodegenConvert.INSTANCE.convert(codes));
} }
@ApiOperation("下载生成代码") @ApiOperation("下载生成代码")

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.tool.controller.admin.codegen.vo;
import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.column.CodegenColumnRespVO;
import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table.CodegenTableRespVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@ApiModel("管理后台 - 代码生成表和字段的明细 Response VO")
@Data
public class CodegenDetailRespVO {
@ApiModelProperty("表定义")
private CodegenTableRespVO table;
@ApiModelProperty("字段定义")
private List<CodegenColumnRespVO> columns;
}

View File

@ -1,12 +1,12 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo; package cn.iocoder.yudao.module.tool.controller.admin.codegen.vo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ApiModel(value = "代码生成预览 Response VO", description ="注意,每个文件都是一个该对象") @ApiModel(value = "管理后台 - 代码生成预览 Response VO", description ="注意,每个文件都是一个该对象")
@Data @Data
public class ToolCodegenPreviewRespVO { public class CodegenPreviewRespVO {
@ApiModelProperty(value = "文件路径", required = true, example = "java/cn/iocoder/yudao/adminserver/modules/system/controller/test/SysTestDemoController.java") @ApiModelProperty(value = "文件路径", required = true, example = "java/cn/iocoder/yudao/adminserver/modules/system/controller/test/SysTestDemoController.java")
private String filePath; private String filePath;

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo; package cn.iocoder.yudao.module.tool.controller.admin.codegen.vo;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.column.ToolCodegenColumnBaseVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table.CodegenTableBaseVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table.ToolCodegenTableBaseVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.column.CodegenColumnBaseVO;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -12,9 +12,9 @@ import javax.validation.Valid;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
@ApiModel("代码生成表和字段的修改 Request VO") @ApiModel("管理后台 - 代码生成表和字段的修改 Request VO")
@Data @Data
public class ToolCodegenUpdateReqVO { public class CodegenUpdateReqVO {
@Valid // 校验内嵌的字段 @Valid // 校验内嵌的字段
@NotNull(message = "表定义不能为空") @NotNull(message = "表定义不能为空")
@ -28,7 +28,7 @@ public class ToolCodegenUpdateReqVO {
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public static class Table extends ToolCodegenTableBaseVO { public static class Table extends CodegenTableBaseVO {
@ApiModelProperty(value = "编号", required = true, example = "1") @ApiModelProperty(value = "编号", required = true, example = "1")
private Long id; private Long id;
@ -39,7 +39,7 @@ public class ToolCodegenUpdateReqVO {
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public static class Column extends ToolCodegenColumnBaseVO { public static class Column extends CodegenColumnBaseVO {
@ApiModelProperty(value = "编号", required = true, example = "1") @ApiModelProperty(value = "编号", required = true, example = "1")
private Long id; private Long id;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.column; package cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.column;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -10,7 +10,7 @@ import javax.validation.constraints.NotNull;
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成 * 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/ */
@Data @Data
public class ToolCodegenColumnBaseVO { public class CodegenColumnBaseVO {
@ApiModelProperty(value = "表编号", required = true, example = "1") @ApiModelProperty(value = "表编号", required = true, example = "1")
@NotNull(message = "表编号不能为空") @NotNull(message = "表编号不能为空")
@ -70,7 +70,7 @@ public class ToolCodegenColumnBaseVO {
@NotNull(message = "是否为 List 查询操作的字段不能为空") @NotNull(message = "是否为 List 查询操作的字段不能为空")
private Boolean listOperation; private Boolean listOperation;
@ApiModelProperty(value = "List 查询操作的条件类型", required = true, example = "LIKE", notes = "参见 ToolCodegenColumnListConditionEnum 枚举") @ApiModelProperty(value = "List 查询操作的条件类型", required = true, example = "LIKE", notes = "参见 CodegenColumnListConditionEnum 枚举")
@NotNull(message = "List 查询操作的条件类型不能为空") @NotNull(message = "List 查询操作的条件类型不能为空")
private String listOperationCondition; private String listOperationCondition;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.column; package cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.column;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -8,11 +8,11 @@ import lombok.ToString;
import java.util.Date; import java.util.Date;
@ApiModel("代码生成字段定义 Response VO") @ApiModel("管理后台 - 代码生成字段定义 Response VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class ToolCodegenColumnRespVO extends ToolCodegenColumnBaseVO { public class CodegenColumnRespVO extends CodegenColumnBaseVO {
@ApiModelProperty(value = "编号", required = true, example = "1") @ApiModelProperty(value = "编号", required = true, example = "1")
private Long id; private Long id;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table; package cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -10,9 +10,9 @@ import javax.validation.constraints.NotNull;
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成 * 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/ */
@Data @Data
public class ToolCodegenTableBaseVO { public class CodegenTableBaseVO {
@ApiModelProperty(value = "导入类型", required = true, example = "1", notes = "参见 ToolCodegenImportTypeEnum 枚举") @ApiModelProperty(value = "导入类型", required = true, example = "1", notes = "参见 CodegenImportTypeEnum 枚举")
@NotNull(message = "导入类型不能为空") @NotNull(message = "导入类型不能为空")
private Integer importType; private Integer importType;
@ -35,7 +35,7 @@ public class ToolCodegenTableBaseVO {
@NotNull(message = "业务名不能为空") @NotNull(message = "业务名不能为空")
private String businessName; private String businessName;
@ApiModelProperty(value = "类名称", required = true, example = "ToolCodegenTable") @ApiModelProperty(value = "类名称", required = true, example = "CodegenTable")
@NotNull(message = "类名称不能为空") @NotNull(message = "类名称不能为空")
private String className; private String className;
@ -47,7 +47,7 @@ public class ToolCodegenTableBaseVO {
@NotNull(message = "作者不能为空") @NotNull(message = "作者不能为空")
private String author; private String author;
@ApiModelProperty(value = "模板类型", required = true, example = "1", notes = "参见 ToolCodegenTemplateTypeEnum 枚举") @ApiModelProperty(value = "模板类型", required = true, example = "1", notes = "参见 CodegenTemplateTypeEnum 枚举")
@NotNull(message = "模板类型不能为空") @NotNull(message = "模板类型不能为空")
private Integer templateType; private Integer templateType;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table; package cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
@ -12,11 +12,11 @@ import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel("表定义分页 Request VO") @ApiModel("管理后台 - 表定义分页 Request VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class ToolCodegenTablePageReqVO extends PageParam { public class CodegenTablePageReqVO extends PageParam {
@ApiModelProperty(value = "表名称", example = "yudao", notes = "模糊匹配") @ApiModelProperty(value = "表名称", example = "yudao", notes = "模糊匹配")
private String tableName; private String tableName;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table; package cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -8,11 +8,11 @@ import lombok.ToString;
import java.util.Date; import java.util.Date;
@ApiModel("代码生成表定义 Response VO") @ApiModel("管理后台 - 代码生成表定义 Response VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class ToolCodegenTableRespVO extends ToolCodegenTableBaseVO { public class CodegenTableRespVO extends CodegenTableBaseVO {
@ApiModelProperty(value = "编号", required = true, example = "1") @ApiModelProperty(value = "编号", required = true, example = "1")
private Long id; private Long id;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table; package cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -6,9 +6,9 @@ import lombok.Data;
import java.util.Date; import java.util.Date;
@ApiModel("数据字典的表定义 Response VO") @ApiModel("管理后台 - 数据字典的表定义 Response VO")
@Data @Data
public class ToolSchemaTableRespVO { public class SchemaTableRespVO {
@ApiModelProperty(value = "数据库", required = true, example = "yudao") @ApiModelProperty(value = "数据库", required = true, example = "yudao")
private String tableSchema; private String tableSchema;

View File

@ -1,7 +1,9 @@
### 请求 /tool/test-demo/get 接口 => 成功 ### 请求 /tool/test-demo/get 接口 => 成功
GET {{baseUrl}}/tool/test-demo/get?id=1 GET {{baseUrl}}/tool/test-demo/get?id=1
Authorization: Bearer {{token}} Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}
### 请求 /tool/test-demo/list 接口 => 成功 ### 请求 /tool/test-demo/list 接口 => 成功
GET {{baseUrl}}/tool/test-demo/list?ids=1 GET {{baseUrl}}/tool/test-demo/list?ids=1
Authorization: Bearer {{token}} Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}

View File

@ -1,15 +1,13 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.test; package cn.iocoder.yudao.module.tool.controller.admin.test;
import cn.hutool.core.thread.ThreadUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.framework.tracer.core.annotation.BizTrace; import cn.iocoder.yudao.module.tool.controller.admin.test.vo.*;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*; import cn.iocoder.yudao.module.tool.convert.test.TestDemoConvert;
import cn.iocoder.yudao.adminserver.modules.tool.convert.test.ToolTestDemoConvert; import cn.iocoder.yudao.module.tool.dal.dataobject.test.TestDemoDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; import cn.iocoder.yudao.module.tool.service.test.TestDemoService;
import cn.iocoder.yudao.adminserver.modules.tool.service.test.ToolTestDemoService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -23,31 +21,30 @@ import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Api(tags = "测试示例") @Api(tags = "管理后台 - 测试示例")
@RestController @RestController
@RequestMapping("/tool/test-demo") @RequestMapping("/tool/test-demo")
@Validated @Validated
public class ToolTestDemoController { public class TestDemoController {
@Resource @Resource
private ToolTestDemoService testDemoService; private TestDemoService testDemoService;
@PostMapping("/create") @PostMapping("/create")
@ApiOperation("创建测试示例") @ApiOperation("创建测试示例")
@PreAuthorize("@ss.hasPermission('tool:test-demo:create')") @PreAuthorize("@ss.hasPermission('tool:test-demo:create')")
public CommonResult<Long> createTestDemo(@Valid @RequestBody ToolTestDemoCreateReqVO createReqVO) { public CommonResult<Long> createTestDemo(@Valid @RequestBody TestDemoCreateReqVO createReqVO) {
return success(testDemoService.createTestDemo(createReqVO)); return success(testDemoService.createTestDemo(createReqVO));
} }
@PutMapping("/update") @PutMapping("/update")
@ApiOperation("更新测试示例") @ApiOperation("更新测试示例")
@PreAuthorize("@ss.hasPermission('tool:test-demo:update')") @PreAuthorize("@ss.hasPermission('tool:test-demo:update')")
public CommonResult<Boolean> updateTestDemo(@Valid @RequestBody ToolTestDemoUpdateReqVO updateReqVO) { public CommonResult<Boolean> updateTestDemo(@Valid @RequestBody TestDemoUpdateReqVO updateReqVO) {
testDemoService.updateTestDemo(updateReqVO); testDemoService.updateTestDemo(updateReqVO);
return success(true); return success(true);
} }
@ -66,12 +63,9 @@ public class ToolTestDemoController {
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('tool:test-demo:query')") @PreAuthorize("@ss.hasPermission('tool:test-demo:query')")
// @Lock4j // 分布式锁 // @Lock4j // 分布式锁
public CommonResult<ToolTestDemoRespVO> getTestDemo(@RequestParam("id") Long id) { public CommonResult<TestDemoRespVO> getTestDemo(@RequestParam("id") Long id) {
if (true) { // 测试分布式锁 TestDemoDO testDemo = testDemoService.getTestDemo(id);
ThreadUtil.sleep(5, TimeUnit.SECONDS); return success(TestDemoConvert.INSTANCE.convert(testDemo));
}
ToolTestDemoDO testDemo = testDemoService.getTestDemo(id);
return success(ToolTestDemoConvert.INSTANCE.convert(testDemo));
} }
@GetMapping("/list") @GetMapping("/list")
@ -79,30 +73,29 @@ public class ToolTestDemoController {
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, dataTypeClass = List.class) @ApiImplicitParam(name = "ids", value = "编号列表", required = true, dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('tool:test-demo:query')") @PreAuthorize("@ss.hasPermission('tool:test-demo:query')")
// @RateLimiter(name = "backendA") // @RateLimiter(name = "backendA")
@BizTrace(id = "#ids", type = "'user'") public CommonResult<List<TestDemoRespVO>> getTestDemoList(@RequestParam("ids") Collection<Long> ids) {
public CommonResult<List<ToolTestDemoRespVO>> getTestDemoList(@RequestParam("ids") Collection<Long> ids) { List<TestDemoDO> list = testDemoService.getTestDemoList(ids);
List<ToolTestDemoDO> list = testDemoService.getTestDemoList(ids); return success(TestDemoConvert.INSTANCE.convertList(list));
return success(ToolTestDemoConvert.INSTANCE.convertList(list));
} }
@GetMapping("/page") @GetMapping("/page")
@ApiOperation("获得测试示例分页") @ApiOperation("获得测试示例分页")
@PreAuthorize("@ss.hasPermission('tool:test-demo:query')") @PreAuthorize("@ss.hasPermission('tool:test-demo:query')")
public CommonResult<PageResult<ToolTestDemoRespVO>> getTestDemoPage(@Valid ToolTestDemoPageReqVO pageVO) { public CommonResult<PageResult<TestDemoRespVO>> getTestDemoPage(@Valid TestDemoPageReqVO pageVO) {
PageResult<ToolTestDemoDO> pageResult = testDemoService.getTestDemoPage(pageVO); PageResult<TestDemoDO> pageResult = testDemoService.getTestDemoPage(pageVO);
return success(ToolTestDemoConvert.INSTANCE.convertPage(pageResult)); return success(TestDemoConvert.INSTANCE.convertPage(pageResult));
} }
@GetMapping("/export-excel") @GetMapping("/export-excel")
@ApiOperation("导出测试示例 Excel") @ApiOperation("导出测试示例 Excel")
@PreAuthorize("@ss.hasPermission('tool:test-demo:export')") @PreAuthorize("@ss.hasPermission('tool:test-demo:export')")
@OperateLog(type = EXPORT) @OperateLog(type = EXPORT)
public void exportTestDemoExcel(@Valid ToolTestDemoExportReqVO exportReqVO, public void exportTestDemoExcel(@Valid TestDemoExportReqVO exportReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
List<ToolTestDemoDO> list = testDemoService.getTestDemoList(exportReqVO); List<TestDemoDO> list = testDemoService.getTestDemoList(exportReqVO);
// 导出 Excel // 导出 Excel
List<ToolTestDemoExcelVO> datas = ToolTestDemoConvert.INSTANCE.convertList02(list); List<TestDemoExcelVO> datas = TestDemoConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "测试示例.xls", "数据", ToolTestDemoExcelVO.class, datas); ExcelUtils.write(response, "测试示例.xls", "数据", TestDemoExcelVO.class, datas);
} }
} }

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo; package cn.iocoder.yudao.module.tool.controller.admin.test.vo;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@ -10,7 +10,7 @@ import javax.validation.constraints.NotNull;
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成 * 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/ */
@Data @Data
public class ToolTestDemoBaseVO { public class TestDemoBaseVO {
@ApiModelProperty(value = "名字", required = true, example = "芋道") @ApiModelProperty(value = "名字", required = true, example = "芋道")
@NotNull(message = "名字不能为空") @NotNull(message = "名字不能为空")

View File

@ -1,14 +1,14 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo; package cn.iocoder.yudao.module.tool.controller.admin.test.vo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ApiModel("字典类型创建 Request VO") @ApiModel("管理后台 - 字典类型创建 Request VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class ToolTestDemoCreateReqVO extends ToolTestDemoBaseVO { public class TestDemoCreateReqVO extends TestDemoBaseVO {
} }

View File

@ -1,8 +1,7 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo; package cn.iocoder.yudao.module.tool.controller.admin.test.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data; import lombok.Data;
@ -14,7 +13,7 @@ import java.util.Date;
* @author 芋艿 * @author 芋艿
*/ */
@Data @Data
public class ToolTestDemoExcelVO { public class TestDemoExcelVO {
@ExcelProperty("编号") @ExcelProperty("编号")
private Long id; private Long id;
@ -23,15 +22,15 @@ public class ToolTestDemoExcelVO {
private String name; private String name;
@ExcelProperty(value = "状态", converter = DictConvert.class) @ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.COMMON_STATUS) @DictFormat("")
private Integer status; private Integer status;
@ExcelProperty(value = "类型", converter = DictConvert.class) @ExcelProperty(value = "类型", converter = DictConvert.class)
@DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.OPERATE_TYPE) @DictFormat("sys_common_status")
private Integer type; private Integer type;
@ExcelProperty(value = "分类", converter = DictConvert.class) @ExcelProperty(value = "分类", converter = DictConvert.class)
@DictFormat(DictTypeConstants.REDIS_TIMEOUT_TYPE) @DictFormat("inf_redis_timeout_type")
private Integer category; private Integer category;
@ExcelProperty("备注") @ExcelProperty("备注")

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo; package cn.iocoder.yudao.module.tool.controller.admin.test.vo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -9,9 +9,9 @@ import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel(value = "字典类型 Excel 导出 Request VO", description = "参数和 ToolTestDemoPageReqVO 是一致的") @ApiModel(value = "管理后台 - 字典类型 Excel 导出 Request VO", description = "参数和 TestDemoPageReqVO 是一致的")
@Data @Data
public class ToolTestDemoExportReqVO { public class TestDemoExportReqVO {
@ApiModelProperty(value = "名字", example = "芋道") @ApiModelProperty(value = "名字", example = "芋道")
private String name; private String name;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo; package cn.iocoder.yudao.module.tool.controller.admin.test.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
@ -12,11 +12,11 @@ import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel("字典类型分页 Request VO") @ApiModel("管理后台 - 字典类型分页 Request VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class ToolTestDemoPageReqVO extends PageParam { public class TestDemoPageReqVO extends PageParam {
@ApiModelProperty(value = "名字", example = "芋道") @ApiModelProperty(value = "名字", example = "芋道")
private String name; private String name;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo; package cn.iocoder.yudao.module.tool.controller.admin.test.vo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -8,11 +8,11 @@ import lombok.ToString;
import java.util.Date; import java.util.Date;
@ApiModel("字典类型 Response VO") @ApiModel("管理后台 - 字典类型 Response VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class ToolTestDemoRespVO extends ToolTestDemoBaseVO { public class TestDemoRespVO extends TestDemoBaseVO {
@ApiModelProperty(value = "编号", required = true, example = "1") @ApiModelProperty(value = "编号", required = true, example = "1")
private Long id; private Long id;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo; package cn.iocoder.yudao.module.tool.controller.admin.test.vo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -8,11 +8,11 @@ import lombok.ToString;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@ApiModel("字典类型更新 Request VO") @ApiModel("管理后台 - 字典类型更新 Request VO")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
public class ToolTestDemoUpdateReqVO extends ToolTestDemoBaseVO { public class TestDemoUpdateReqVO extends TestDemoBaseVO {
@ApiModelProperty(value = "编号", required = true, example = "1") @ApiModelProperty(value = "编号", required = true, example = "1")
@NotNull(message = "编号不能为空") @NotNull(message = "编号不能为空")

View File

@ -0,0 +1,4 @@
/**
* 占位避免 package 无法提交到 Git 仓库
*/
package cn.iocoder.yudao.module.tool.controller.app;

View File

@ -0,0 +1,6 @@
/**
* 提供 RESTful API 给前端
* 1. admin 提供给管理后台 yudao-ui-admin 前端项目
* 2. app 提供给用户 APP yudao-ui-app 前端项目它的 Controller VO 都要添加 App 前缀用于和管理后台进行区分
*/
package cn.iocoder.yudao.module.tool.controller;

View File

@ -0,0 +1,70 @@
package cn.iocoder.yudao.module.tool.convert.codegen;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.CodegenDetailRespVO;
import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.CodegenPreviewRespVO;
import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.CodegenUpdateReqVO;
import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.column.CodegenColumnRespVO;
import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table.CodegenTableRespVO;
import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table.SchemaTableRespVO;
import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenColumnDO;
import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenTableDO;
import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaColumnDO;
import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaTableDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Mapper
public interface CodegenConvert {
CodegenConvert INSTANCE = Mappers.getMapper(CodegenConvert.class);
// ========== InformationSchemaTableDO InformationSchemaColumnDO 相关 ==========
CodegenTableDO convert(SchemaTableDO bean);
List<CodegenColumnDO> convertList(List<SchemaColumnDO> list);
CodegenTableRespVO convert(SchemaColumnDO bean);
// ========== CodegenTableDO 相关 ==========
// List<CodegenTableRespVO> convertList02(List<CodegenTableDO> list);
CodegenTableRespVO convert(CodegenTableDO bean);
PageResult<CodegenTableRespVO> convertPage(PageResult<CodegenTableDO> page);
// ========== CodegenTableDO 相关 ==========
List<CodegenColumnRespVO> convertList02(List<CodegenColumnDO> list);
CodegenTableDO convert(CodegenUpdateReqVO.Table bean);
List<CodegenColumnDO> convertList03(List<CodegenUpdateReqVO.Column> columns);
List<SchemaTableRespVO> convertList04(List<SchemaTableDO> list);
// ========== 其它 ==========
default CodegenDetailRespVO convert(CodegenTableDO table, List<CodegenColumnDO> columns) {
CodegenDetailRespVO respVO = new CodegenDetailRespVO();
respVO.setTable(convert(table));
respVO.setColumns(convertList02(columns));
return respVO;
}
default List<CodegenPreviewRespVO> convert(Map<String, String> codes) {
return codes.entrySet().stream().map(entry -> {
CodegenPreviewRespVO respVO = new CodegenPreviewRespVO();
respVO.setFilePath(entry.getKey());
respVO.setCode(entry.getValue());
return respVO;
}).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.tool.convert.test;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoCreateReqVO;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoExcelVO;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoRespVO;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoUpdateReqVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.tool.dal.dataobject.test.TestDemoDO;
@Mapper
public interface TestDemoConvert {
TestDemoConvert INSTANCE = Mappers.getMapper(TestDemoConvert.class);
TestDemoDO convert(TestDemoCreateReqVO bean);
TestDemoDO convert(TestDemoUpdateReqVO bean);
TestDemoRespVO convert(TestDemoDO bean);
List<TestDemoRespVO> convertList(List<TestDemoDO> list);
PageResult<TestDemoRespVO> convertPage(PageResult<TestDemoDO> page);
List<TestDemoExcelVO> convertList02(List<TestDemoDO> list);
}

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen; package cn.iocoder.yudao.module.tool.dal.dataobject.codegen;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.adminserver.modules.tool.enums.codegen.ToolCodegenColumnHtmlTypeEnum; import cn.iocoder.yudao.module.tool.enums.codegen.CodegenColumnHtmlTypeEnum;
import cn.iocoder.yudao.adminserver.modules.tool.enums.codegen.ToolCodegenColumnListConditionEnum; import cn.iocoder.yudao.module.tool.enums.codegen.CodegenColumnListConditionEnum;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
@ -18,7 +18,7 @@ import lombok.experimental.Accessors;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class ToolCodegenColumnDO extends BaseDO { public class CodegenColumnDO extends BaseDO {
/** /**
* ID 编号 * ID 编号
@ -28,7 +28,7 @@ public class ToolCodegenColumnDO extends BaseDO {
/** /**
* 表编号 * 表编号
* *
* 关联 {@link ToolCodegenTableDO#getId()} * 关联 {@link CodegenTableDO#getId()}
*/ */
private Long tableId; private Long tableId;
@ -104,7 +104,7 @@ public class ToolCodegenColumnDO extends BaseDO {
/** /**
* List 查询操作的条件类型 * List 查询操作的条件类型
* *
* 枚举 {@link ToolCodegenColumnListConditionEnum} * 枚举 {@link CodegenColumnListConditionEnum}
*/ */
private String listOperationCondition; private String listOperationCondition;
/** /**
@ -117,7 +117,7 @@ public class ToolCodegenColumnDO extends BaseDO {
/** /**
* 显示类型 * 显示类型
* *
* 枚举 {@link ToolCodegenColumnHtmlTypeEnum} * 枚举 {@link CodegenColumnHtmlTypeEnum}
*/ */
private String htmlType; private String htmlType;

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen; package cn.iocoder.yudao.module.tool.dal.dataobject.codegen;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.adminserver.modules.tool.enums.codegen.ToolCodegenTemplateTypeEnum; import cn.iocoder.yudao.module.tool.enums.codegen.CodegenTemplateTypeEnum;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -16,7 +16,7 @@ import lombok.experimental.Accessors;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class ToolCodegenTableDO extends BaseDO { public class CodegenTableDO extends BaseDO {
/** /**
* ID 编号 * ID 编号
@ -26,7 +26,7 @@ public class ToolCodegenTableDO extends BaseDO {
/** /**
* 导入类型 * 导入类型
* *
* 枚举 {@link ToolCodegenTemplateTypeEnum} * 枚举 {@link CodegenTemplateTypeEnum}
*/ */
private Integer importType; private Integer importType;
@ -79,7 +79,7 @@ public class ToolCodegenTableDO extends BaseDO {
/** /**
* 模板类型 * 模板类型
* *
* 枚举 {@link ToolCodegenTemplateTypeEnum} * 枚举 {@link CodegenTemplateTypeEnum}
*/ */
private Integer templateType; private Integer templateType;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen; package cn.iocoder.yudao.module.tool.dal.dataobject.codegen;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
@ -13,7 +13,7 @@ import lombok.Data;
@TableName(value = "information_schema.columns", autoResultMap = true) @TableName(value = "information_schema.columns", autoResultMap = true)
@Data @Data
@Builder @Builder
public class ToolSchemaColumnDO { public class SchemaColumnDO {
/** /**
* 表名称 * 表名称

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen; package cn.iocoder.yudao.module.tool.dal.dataobject.codegen;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Builder; import lombok.Builder;
@ -14,7 +14,7 @@ import java.util.Date;
@TableName(value = "information_schema.tables", autoResultMap = true) @TableName(value = "information_schema.tables", autoResultMap = true)
@Data @Data
@Builder @Builder
public class ToolSchemaTableDO { public class SchemaTableDO {
/** /**
* 数据库 * 数据库

View File

@ -1,12 +1,11 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test; package cn.iocoder.yudao.module.tool.dal.dataobject.test;
import lombok.*; import lombok.*;
import java.util.*;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/** /**
* 字典类型 DO * 测试示例 DO
* *
* @author 芋艿 * @author 芋艿
*/ */
@ -17,7 +16,7 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class ToolTestDemoDO extends BaseDO { public class TestDemoDO extends BaseDO {
/** /**
* 编号 * 编号

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.tool.dal.mysql.codegen;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenColumnDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface CodegenColumnMapper extends BaseMapperX<CodegenColumnDO> {
default List<CodegenColumnDO> selectListByTableId(Long tableId) {
return selectList(new QueryWrapper<CodegenColumnDO>().eq("table_id", tableId)
.orderByAsc("ordinal_position"));
}
default void deleteListByTableId(Long tableId) {
delete(new QueryWrapper<CodegenColumnDO>().eq("table_id", tableId));
}
}

View File

@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.tool.dal.mysql.codegen;
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.module.tool.controller.admin.codegen.vo.table.CodegenTablePageReqVO;
import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenTableDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface CodegenTableMapper extends BaseMapperX<CodegenTableDO> {
default CodegenTableDO selectByTableName(String tableName) {
return selectOne(new QueryWrapper<CodegenTableDO>().eq("table_name", tableName));
}
default PageResult<CodegenTableDO> selectPage(CodegenTablePageReqVO pageReqVO) {
return selectPage(pageReqVO, new QueryWrapperX<CodegenTableDO>()
.likeIfPresent("table_name", pageReqVO.getTableName())
.likeIfPresent("table_comment", pageReqVO.getTableComment())
.betweenIfPresent("create_time", pageReqVO.getBeginCreateTime(), pageReqVO.getEndCreateTime()));
}
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.tool.dal.mysql.codegen;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaColumnDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface SchemaColumnMapper extends BaseMapperX<SchemaColumnDO> {
default List<SchemaColumnDO> selectListByTableName(String tableSchema, String tableName) {
return selectList(new QueryWrapper<SchemaColumnDO>().eq("table_name", tableName)
.eq("table_schema", tableSchema)
.orderByAsc("ordinal_position"));
}
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.tool.dal.mysql.codegen;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaTableDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
@Mapper
public interface SchemaTableMapper extends BaseMapperX<SchemaTableDO> {
default List<SchemaTableDO> selectList(Collection<String> tableSchemas, String tableName, String tableComment) {
return selectList(new QueryWrapperX<SchemaTableDO>().in("table_schema", tableSchemas)
.likeIfPresent("table_name", tableName)
.likeIfPresent("table_comment", tableComment));
}
default SchemaTableDO selectByTableSchemaAndTableName(String tableSchema, String tableName) {
return selectOne(new QueryWrapper<SchemaTableDO>().eq("table_schema",tableSchema)
.eq("table_name", tableName));
}
}

View File

@ -1,24 +1,20 @@
package cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.test; package cn.iocoder.yudao.module.tool.dal.mysql.test;
import java.util.*; 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.query.QueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.test.ToolTestDemoDO; import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoExportReqVO;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoPageReqVO;
import cn.iocoder.yudao.module.tool.dal.dataobject.test.TestDemoDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.adminserver.modules.tool.controller.test.vo.*;
/**
* 字典类型 Mapper
*
* @author 芋艿
*/
@Mapper @Mapper
public interface ToolTestDemoMapper extends BaseMapperX<ToolTestDemoDO> { public interface TestDemoMapper extends BaseMapperX<TestDemoDO> {
default PageResult<ToolTestDemoDO> selectPage(ToolTestDemoPageReqVO reqVO) { default PageResult<TestDemoDO> selectPage(TestDemoPageReqVO reqVO) {
return selectPage(reqVO, new QueryWrapperX<ToolTestDemoDO>() return selectPage(reqVO, new QueryWrapperX<TestDemoDO>()
.likeIfPresent("name", reqVO.getName()) .likeIfPresent("name", reqVO.getName())
.eqIfPresent("status", reqVO.getStatus()) .eqIfPresent("status", reqVO.getStatus())
.eqIfPresent("type", reqVO.getType()) .eqIfPresent("type", reqVO.getType())
@ -28,8 +24,8 @@ public interface ToolTestDemoMapper extends BaseMapperX<ToolTestDemoDO> {
.orderByDesc("id")); .orderByDesc("id"));
} }
default List<ToolTestDemoDO> selectList(ToolTestDemoExportReqVO reqVO) { default List<TestDemoDO> selectList(TestDemoExportReqVO reqVO) {
return selectList(new QueryWrapperX<ToolTestDemoDO>() return selectList(new QueryWrapperX<TestDemoDO>()
.likeIfPresent("name", reqVO.getName()) .likeIfPresent("name", reqVO.getName())
.eqIfPresent("status", reqVO.getStatus()) .eqIfPresent("status", reqVO.getStatus())
.eqIfPresent("type", reqVO.getType()) .eqIfPresent("type", reqVO.getType())

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.enums.codegen; package cn.iocoder.yudao.module.tool.enums.codegen;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -8,7 +8,7 @@ import lombok.Getter;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum ToolCodegenColumnHtmlTypeEnum { public enum CodegenColumnHtmlTypeEnum {
INPUT("input"), // 文本框 INPUT("input"), // 文本框
TEXTAREA("textarea"), // 文本域 TEXTAREA("textarea"), // 文本域

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.enums.codegen; package cn.iocoder.yudao.module.tool.enums.codegen;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -8,7 +8,7 @@ import lombok.Getter;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum ToolCodegenColumnListConditionEnum { public enum CodegenColumnListConditionEnum {
EQ("="), EQ("="),
NE("!="), NE("!="),

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.enums.codegen; package cn.iocoder.yudao.module.tool.enums.codegen;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -10,7 +10,7 @@ import lombok.Getter;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum ToolCodegenImportTypeEnum { public enum CodegenImportTypeEnum {
DB(1), // information_schema table columns 表导入 DB(1), // information_schema table columns 表导入
SQL(2); // 基于建表 SQL 语句导入 SQL(2); // 基于建表 SQL 语句导入

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.enums.codegen; package cn.iocoder.yudao.module.tool.enums.codegen;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -10,7 +10,7 @@ import lombok.Getter;
*/ */
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public enum ToolCodegenTemplateTypeEnum { public enum CodegenTemplateTypeEnum {
CRUD(1), // 单表增删改查 CRUD(1), // 单表增删改查
TREE(2), // 树表增删改查 TREE(2), // 树表增删改查

View File

@ -0,0 +1,4 @@
/**
* 占位
*/
package cn.iocoder.yudao.module.tool.enums;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.framework.codegen.config; package cn.iocoder.yudao.module.tool.framework.codegen.config;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.framework.codegen.config; package cn.iocoder.yudao.module.tool.framework.codegen.config;
import lombok.Data; import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;

View File

@ -0,0 +1,4 @@
/**
* 代码生成器
*/
package cn.iocoder.yudao.module.tool.framework.codegen;

View File

@ -3,4 +3,4 @@
* *
* @author 芋道源码 * @author 芋道源码
*/ */
package cn.iocoder.yudao.adminserver.modules.tool.framework; package cn.iocoder.yudao.module.tool.framework;

View File

@ -0,0 +1,8 @@
/**
* tool 模块下我们放研发工具提升研发效率与质量
* 例如说代码生成器接口文档等等
*
* 1. Controller URL /tool/ 开头避免和其它 Module 冲突
* 2. DataObject 表名 tool_ 开头方便在数据库中区分
*/
package cn.iocoder.yudao.module.tool;

View File

@ -1,11 +1,11 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.codegen; package cn.iocoder.yudao.module.tool.service.codegen;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.ToolCodegenUpdateReqVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.CodegenUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table.ToolCodegenTablePageReqVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table.CodegenTablePageReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenColumnDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenTableDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaTableDO;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -15,7 +15,7 @@ import java.util.Map;
* *
* @author 芋道源码 * @author 芋道源码
*/ */
public interface ToolCodegenService { public interface CodegenService {
/** /**
* 基于 SQL 建表语句创建代码生成器的表定义 * 基于 SQL 建表语句创建代码生成器的表定义
@ -46,7 +46,7 @@ public interface ToolCodegenService {
* *
* @param updateReqVO 更新信息 * @param updateReqVO 更新信息
*/ */
void updateCodegen(ToolCodegenUpdateReqVO updateReqVO); void updateCodegen(CodegenUpdateReqVO updateReqVO);
/** /**
* 基于数据库的表结构同步数据库的表和字段定义 * 基于数据库的表结构同步数据库的表和字段定义
@ -76,7 +76,7 @@ public interface ToolCodegenService {
* @param pageReqVO 分页条件 * @param pageReqVO 分页条件
* @return 表定义分页 * @return 表定义分页
*/ */
PageResult<ToolCodegenTableDO> getCodegenTablePage(ToolCodegenTablePageReqVO pageReqVO); PageResult<CodegenTableDO> getCodegenTablePage(CodegenTablePageReqVO pageReqVO);
/** /**
* 获得表定义 * 获得表定义
@ -84,14 +84,14 @@ public interface ToolCodegenService {
* @param id 表编号 * @param id 表编号
* @return 表定义 * @return 表定义
*/ */
ToolCodegenTableDO getCodegenTablePage(Long id); CodegenTableDO getCodegenTablePage(Long id);
/** /**
* 获得全部表定义 * 获得全部表定义
* *
* @return 表定义数组 * @return 表定义数组
*/ */
List<ToolCodegenTableDO> getCodeGenTableList(); List<CodegenTableDO> getCodeGenTableList();
/** /**
* 获得指定表的字段定义数组 * 获得指定表的字段定义数组
@ -99,7 +99,7 @@ public interface ToolCodegenService {
* @param tableId 表编号 * @param tableId 表编号
* @return 字段定义数组 * @return 字段定义数组
*/ */
List<ToolCodegenColumnDO> getCodegenColumnListByTableId(Long tableId); List<CodegenColumnDO> getCodegenColumnListByTableId(Long tableId);
/** /**
* 执行指定表的代码生成 * 执行指定表的代码生成
@ -116,6 +116,6 @@ public interface ToolCodegenService {
* @param tableComment 表描述 * @param tableComment 表描述
* @return 表定义列表 * @return 表定义列表
*/ */
List<ToolSchemaTableDO> getSchemaTableList(String tableName, String tableComment); List<SchemaTableDO> getSchemaTableList(String tableName, String tableComment);
} }

View File

@ -1,22 +1,24 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.codegen.impl; package cn.iocoder.yudao.module.tool.service.codegen;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.tool.framework.codegen.config.CodegenProperties; import cn.iocoder.yudao.module.tool.framework.codegen.config.CodegenProperties;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.ToolCodegenUpdateReqVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.CodegenUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.controller.codegen.vo.table.ToolCodegenTablePageReqVO; import cn.iocoder.yudao.module.tool.controller.admin.codegen.vo.table.CodegenTablePageReqVO;
import cn.iocoder.yudao.adminserver.modules.tool.convert.codegen.ToolCodegenConvert; import cn.iocoder.yudao.module.tool.convert.codegen.CodegenConvert;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenColumnDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenTableDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaColumnDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaTableDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen.ToolCodegenColumnMapper; import cn.iocoder.yudao.module.tool.dal.mysql.codegen.CodegenColumnMapper;
import cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen.ToolCodegenTableMapper; import cn.iocoder.yudao.module.tool.dal.mysql.codegen.CodegenTableMapper;
import cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen.ToolSchemaColumnMapper; import cn.iocoder.yudao.module.tool.dal.mysql.codegen.SchemaColumnMapper;
import cn.iocoder.yudao.adminserver.modules.tool.dal.mysql.codegen.ToolSchemaTableMapper; import cn.iocoder.yudao.module.tool.dal.mysql.codegen.SchemaTableMapper;
import cn.iocoder.yudao.adminserver.modules.tool.enums.codegen.ToolCodegenImportTypeEnum; import cn.iocoder.yudao.module.tool.enums.codegen.CodegenImportTypeEnum;
import cn.iocoder.yudao.adminserver.modules.tool.service.codegen.ToolCodegenService;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.tool.service.codegen.inner.CodegenBuilder;
import cn.iocoder.yudao.module.tool.service.codegen.inner.CodegenEngine;
import cn.iocoder.yudao.module.tool.service.codegen.inner.CodegenSQLParser;
import org.apache.commons.collections4.KeyValue; import org.apache.commons.collections4.KeyValue;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -29,7 +31,7 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.adminserver.modules.tool.enums.ToolErrorCodeConstants.*; import static cn.iocoder.yudao.module.tool.enums.ErrorCodeConstants.*;
/** /**
* 代码生成 Service 实现类 * 代码生成 Service 实现类
@ -37,27 +39,27 @@ import static cn.iocoder.yudao.adminserver.modules.tool.enums.ToolErrorCodeConst
* @author 芋道源码 * @author 芋道源码
*/ */
@Service @Service
public class ToolCodegenServiceImpl implements ToolCodegenService { public class CodegenServiceImpl implements CodegenService {
@Resource @Resource
private ToolSchemaTableMapper schemaTableMapper; private SchemaTableMapper schemaTableMapper;
@Resource @Resource
private ToolSchemaColumnMapper schemaColumnMapper; private SchemaColumnMapper schemaColumnMapper;
@Resource @Resource
private ToolCodegenTableMapper codegenTableMapper; private CodegenTableMapper codegenTableMapper;
@Resource @Resource
private ToolCodegenColumnMapper codegenColumnMapper; private CodegenColumnMapper codegenColumnMapper;
@Resource @Resource
private ToolCodegenBuilder codegenBuilder; private CodegenBuilder codegenBuilder;
@Resource @Resource
private ToolCodegenEngine codegenEngine; private CodegenEngine codegenEngine;
@Resource @Resource
private CodegenProperties codegenProperties; private CodegenProperties codegenProperties;
private Long createCodegen0(ToolCodegenImportTypeEnum importType, private Long createCodegen0(CodegenImportTypeEnum importType,
ToolSchemaTableDO schemaTable, List<ToolSchemaColumnDO> schemaColumns) { SchemaTableDO schemaTable, List<SchemaColumnDO> schemaColumns) {
// 校验导入的表和字段非空 // 校验导入的表和字段非空
if (schemaTable == null) { if (schemaTable == null) {
throw exception(CODEGEN_IMPORT_TABLE_NULL); throw exception(CODEGEN_IMPORT_TABLE_NULL);
@ -70,12 +72,12 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
throw exception(CODEGEN_TABLE_EXISTS); throw exception(CODEGEN_TABLE_EXISTS);
} }
// 构建 ToolCodegenTableDO 对象插入到 DB // 构建 CodegenTableDO 对象插入到 DB
ToolCodegenTableDO table = codegenBuilder.buildTable(schemaTable); CodegenTableDO table = codegenBuilder.buildTable(schemaTable);
table.setImportType(importType.getType()); table.setImportType(importType.getType());
codegenTableMapper.insert(table); codegenTableMapper.insert(table);
// 构建 ToolCodegenColumnDO 数组插入到 DB // 构建 CodegenColumnDO 数组插入到 DB
List<ToolCodegenColumnDO> columns = codegenBuilder.buildColumns(schemaColumns); List<CodegenColumnDO> columns = codegenBuilder.buildColumns(schemaColumns);
columns.forEach(column -> { columns.forEach(column -> {
column.setTableId(table.getId()); column.setTableId(table.getId());
codegenColumnMapper.insert(column); // TODO 批量插入 codegenColumnMapper.insert(column); // TODO 批量插入
@ -86,17 +88,17 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
@Override @Override
public Long createCodegenListFromSQL(String sql) { public Long createCodegenListFromSQL(String sql) {
// SQL 获得数据库表结构 // SQL 获得数据库表结构
ToolSchemaTableDO schemaTable; SchemaTableDO schemaTable;
List<ToolSchemaColumnDO> schemaColumns; List<SchemaColumnDO> schemaColumns;
try { try {
KeyValue<ToolSchemaTableDO, List<ToolSchemaColumnDO>> result = ToolCodegenSQLParser.parse(sql); KeyValue<SchemaTableDO, List<SchemaColumnDO>> result = CodegenSQLParser.parse(sql);
schemaTable = result.getKey(); schemaTable = result.getKey();
schemaColumns = result.getValue(); schemaColumns = result.getValue();
} catch (Exception ex) { } catch (Exception ex) {
throw exception(CODEGEN_PARSE_SQL_ERROR); throw exception(CODEGEN_PARSE_SQL_ERROR);
} }
// 导入 // 导入
return this.createCodegen0(ToolCodegenImportTypeEnum.SQL, schemaTable, schemaColumns); return this.createCodegen0(CodegenImportTypeEnum.SQL, schemaTable, schemaColumns);
} }
@Override @Override
@ -104,10 +106,10 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
// 获取当前schema // 获取当前schema
String tableSchema = codegenProperties.getDbSchemas().iterator().next(); String tableSchema = codegenProperties.getDbSchemas().iterator().next();
// 从数据库中获得数据库表结构 // 从数据库中获得数据库表结构
ToolSchemaTableDO schemaTable = schemaTableMapper.selectByTableSchemaAndTableName(tableSchema, tableName); SchemaTableDO schemaTable = schemaTableMapper.selectByTableSchemaAndTableName(tableSchema, tableName);
List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableSchema, tableName); List<SchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableSchema, tableName);
// 导入 // 导入
return this.createCodegen0(ToolCodegenImportTypeEnum.DB, schemaTable, schemaColumns); return this.createCodegen0(CodegenImportTypeEnum.DB, schemaTable, schemaColumns);
} }
@Override @Override
@ -121,17 +123,17 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateCodegen(ToolCodegenUpdateReqVO updateReqVO) { public void updateCodegen(CodegenUpdateReqVO updateReqVO) {
// 校验是否已经存在 // 校验是否已经存在
if (codegenTableMapper.selectById(updateReqVO.getTable().getId()) == null) { if (codegenTableMapper.selectById(updateReqVO.getTable().getId()) == null) {
throw exception(CODEGEN_TABLE_NOT_EXISTS); throw exception(CODEGEN_TABLE_NOT_EXISTS);
} }
// 更新 table 表定义 // 更新 table 表定义
ToolCodegenTableDO updateTableObj = ToolCodegenConvert.INSTANCE.convert(updateReqVO.getTable()); CodegenTableDO updateTableObj = CodegenConvert.INSTANCE.convert(updateReqVO.getTable());
codegenTableMapper.updateById(updateTableObj); codegenTableMapper.updateById(updateTableObj);
// 更新 column 字段定义 // 更新 column 字段定义
List<ToolCodegenColumnDO> updateColumnObjs = ToolCodegenConvert.INSTANCE.convertList03(updateReqVO.getColumns()); List<CodegenColumnDO> updateColumnObjs = CodegenConvert.INSTANCE.convertList03(updateReqVO.getColumns());
updateColumnObjs.forEach(updateColumnObj -> codegenColumnMapper.updateById(updateColumnObj)); updateColumnObjs.forEach(updateColumnObj -> codegenColumnMapper.updateById(updateColumnObj));
} }
@ -139,13 +141,13 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void syncCodegenFromDB(Long tableId) { public void syncCodegenFromDB(Long tableId) {
// 校验是否已经存在 // 校验是否已经存在
ToolCodegenTableDO table = codegenTableMapper.selectById(tableId); CodegenTableDO table = codegenTableMapper.selectById(tableId);
if (table == null) { if (table == null) {
throw exception(CODEGEN_TABLE_NOT_EXISTS); throw exception(CODEGEN_TABLE_NOT_EXISTS);
} }
String tableSchema = codegenProperties.getDbSchemas().iterator().next(); String tableSchema = codegenProperties.getDbSchemas().iterator().next();
// 从数据库中获得数据库表结构 // 从数据库中获得数据库表结构
List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableSchema, table.getTableName()); List<SchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableSchema, table.getTableName());
// 执行同步 // 执行同步
this.syncCodegen0(tableId, schemaColumns); this.syncCodegen0(tableId, schemaColumns);
@ -155,14 +157,14 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void syncCodegenFromSQL(Long tableId, String sql) { public void syncCodegenFromSQL(Long tableId, String sql) {
// 校验是否已经存在 // 校验是否已经存在
ToolCodegenTableDO table = codegenTableMapper.selectById(tableId); CodegenTableDO table = codegenTableMapper.selectById(tableId);
if (table == null) { if (table == null) {
throw exception(CODEGEN_TABLE_NOT_EXISTS); throw exception(CODEGEN_TABLE_NOT_EXISTS);
} }
// SQL 获得数据库表结构 // SQL 获得数据库表结构
List<ToolSchemaColumnDO> schemaColumns; List<SchemaColumnDO> schemaColumns;
try { try {
KeyValue<ToolSchemaTableDO, List<ToolSchemaColumnDO>> result = ToolCodegenSQLParser.parse(sql); KeyValue<SchemaTableDO, List<SchemaColumnDO>> result = CodegenSQLParser.parse(sql);
schemaColumns = result.getValue(); schemaColumns = result.getValue();
} catch (Exception ex) { } catch (Exception ex) {
throw exception(CODEGEN_PARSE_SQL_ERROR); throw exception(CODEGEN_PARSE_SQL_ERROR);
@ -172,27 +174,27 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
this.syncCodegen0(tableId, schemaColumns); this.syncCodegen0(tableId, schemaColumns);
} }
private void syncCodegen0(Long tableId, List<ToolSchemaColumnDO> schemaColumns) { private void syncCodegen0(Long tableId, List<SchemaColumnDO> schemaColumns) {
// 校验导入的字段不为空 // 校验导入的字段不为空
if (CollUtil.isEmpty(schemaColumns)) { if (CollUtil.isEmpty(schemaColumns)) {
throw exception(CODEGEN_SYNC_COLUMNS_NULL); throw exception(CODEGEN_SYNC_COLUMNS_NULL);
} }
Set<String> schemaColumnNames = CollectionUtils.convertSet(schemaColumns, ToolSchemaColumnDO::getColumnName); Set<String> schemaColumnNames = CollectionUtils.convertSet(schemaColumns, SchemaColumnDO::getColumnName);
// 构建 ToolCodegenColumnDO 数组只同步新增的字段 // 构建 CodegenColumnDO 数组只同步新增的字段
List<ToolCodegenColumnDO> codegenColumns = codegenColumnMapper.selectListByTableId(tableId); List<CodegenColumnDO> codegenColumns = codegenColumnMapper.selectListByTableId(tableId);
Set<String> codegenColumnNames = CollectionUtils.convertSet(codegenColumns, ToolCodegenColumnDO::getColumnName); Set<String> codegenColumnNames = CollectionUtils.convertSet(codegenColumns, CodegenColumnDO::getColumnName);
// 移除已经存在的字段 // 移除已经存在的字段
schemaColumns.removeIf(column -> codegenColumnNames.contains(column.getColumnName())); schemaColumns.removeIf(column -> codegenColumnNames.contains(column.getColumnName()));
// 计算需要删除的字段 // 计算需要删除的字段
Set<Long> deleteColumnIds = codegenColumns.stream().filter(column -> !schemaColumnNames.contains(column.getColumnName())) Set<Long> deleteColumnIds = codegenColumns.stream().filter(column -> !schemaColumnNames.contains(column.getColumnName()))
.map(ToolCodegenColumnDO::getId).collect(Collectors.toSet()); .map(CodegenColumnDO::getId).collect(Collectors.toSet());
if (CollUtil.isEmpty(schemaColumns) && CollUtil.isEmpty(deleteColumnIds)) { if (CollUtil.isEmpty(schemaColumns) && CollUtil.isEmpty(deleteColumnIds)) {
throw exception(CODEGEN_SYNC_NONE_CHANGE); throw exception(CODEGEN_SYNC_NONE_CHANGE);
} }
// 插入新增的字段 // 插入新增的字段
List<ToolCodegenColumnDO> columns = codegenBuilder.buildColumns(schemaColumns); List<CodegenColumnDO> columns = codegenBuilder.buildColumns(schemaColumns);
columns.forEach(column -> { columns.forEach(column -> {
column.setTableId(tableId); column.setTableId(tableId);
codegenColumnMapper.insert(column); // TODO 批量插入 codegenColumnMapper.insert(column); // TODO 批量插入
@ -218,33 +220,33 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
} }
@Override @Override
public PageResult<ToolCodegenTableDO> getCodegenTablePage(ToolCodegenTablePageReqVO pageReqVO) { public PageResult<CodegenTableDO> getCodegenTablePage(CodegenTablePageReqVO pageReqVO) {
return codegenTableMapper.selectPage(pageReqVO); return codegenTableMapper.selectPage(pageReqVO);
} }
@Override @Override
public ToolCodegenTableDO getCodegenTablePage(Long id) { public CodegenTableDO getCodegenTablePage(Long id) {
return codegenTableMapper.selectById(id); return codegenTableMapper.selectById(id);
} }
@Override @Override
public List<ToolCodegenTableDO> getCodeGenTableList() { public List<CodegenTableDO> getCodeGenTableList() {
return codegenTableMapper.selectList(); return codegenTableMapper.selectList();
} }
@Override @Override
public List<ToolCodegenColumnDO> getCodegenColumnListByTableId(Long tableId) { public List<CodegenColumnDO> getCodegenColumnListByTableId(Long tableId) {
return codegenColumnMapper.selectListByTableId(tableId); return codegenColumnMapper.selectListByTableId(tableId);
} }
@Override @Override
public Map<String, String> generationCodes(Long tableId) { public Map<String, String> generationCodes(Long tableId) {
// 校验是否已经存在 // 校验是否已经存在
ToolCodegenTableDO table = codegenTableMapper.selectById(tableId); CodegenTableDO table = codegenTableMapper.selectById(tableId);
if (codegenTableMapper.selectById(tableId) == null) { if (codegenTableMapper.selectById(tableId) == null) {
throw exception(CODEGEN_TABLE_NOT_EXISTS); throw exception(CODEGEN_TABLE_NOT_EXISTS);
} }
List<ToolCodegenColumnDO> columns = codegenColumnMapper.selectListByTableId(tableId); List<CodegenColumnDO> columns = codegenColumnMapper.selectListByTableId(tableId);
if (CollUtil.isEmpty(columns)) { if (CollUtil.isEmpty(columns)) {
throw exception(CODEGEN_COLUMN_NOT_EXISTS); throw exception(CODEGEN_COLUMN_NOT_EXISTS);
} }
@ -254,8 +256,8 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
} }
@Override @Override
public List<ToolSchemaTableDO> getSchemaTableList(String tableName, String tableComment) { public List<SchemaTableDO> getSchemaTableList(String tableName, String tableComment) {
List<ToolSchemaTableDO> tables = schemaTableMapper.selectList(codegenProperties.getDbSchemas(), tableName, tableComment); List<SchemaTableDO> tables = schemaTableMapper.selectList(codegenProperties.getDbSchemas(), tableName, tableComment);
// TODO 强制移除 Quartz 的表未来做成可配置 // TODO 强制移除 Quartz 的表未来做成可配置
tables.removeIf(table -> table.getTableName().startsWith("QRTZ_")); tables.removeIf(table -> table.getTableName().startsWith("QRTZ_"));
tables.removeIf(table -> table.getTableName().startsWith("ACT_")); tables.removeIf(table -> table.getTableName().startsWith("ACT_"));

View File

@ -1,16 +1,16 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.codegen.impl; package cn.iocoder.yudao.module.tool.service.codegen.inner;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.adminserver.modules.tool.convert.codegen.ToolCodegenConvert; import cn.iocoder.yudao.module.tool.convert.codegen.CodegenConvert;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenColumnDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenTableDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaColumnDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaTableDO;
import cn.iocoder.yudao.adminserver.modules.tool.enums.codegen.ToolCodegenColumnHtmlTypeEnum; import cn.iocoder.yudao.module.tool.enums.codegen.CodegenColumnHtmlTypeEnum;
import cn.iocoder.yudao.adminserver.modules.tool.enums.codegen.ToolCodegenColumnListConditionEnum; import cn.iocoder.yudao.module.tool.enums.codegen.CodegenColumnListConditionEnum;
import cn.iocoder.yudao.adminserver.modules.tool.enums.codegen.ToolCodegenTemplateTypeEnum; import cn.iocoder.yudao.module.tool.enums.codegen.CodegenTemplateTypeEnum;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -21,11 +21,11 @@ import static cn.hutool.core.text.CharSequenceUtil.*;
/** /**
* 代码生成器的 Builder负责 * 代码生成器的 Builder负责
* 1. 将数据库的表 {@link ToolSchemaTableDO} 定义构建成 {@link ToolCodegenTableDO} * 1. 将数据库的表 {@link SchemaTableDO} 定义构建成 {@link CodegenTableDO}
* 2. 将数据库的列 {@link ToolSchemaColumnDO} 构定义建成 {@link ToolCodegenColumnDO} * 2. 将数据库的列 {@link SchemaColumnDO} 构定义建成 {@link CodegenColumnDO}
*/ */
@Component @Component
public class ToolCodegenBuilder { public class CodegenBuilder {
/** /**
* Module 名字的映射 TODO 后续梳理到配置类 * Module 名字的映射 TODO 后续梳理到配置类
@ -40,30 +40,30 @@ public class ToolCodegenBuilder {
.build(); .build();
/** /**
* 字段名与 {@link ToolCodegenColumnListConditionEnum} 的默认映射 * 字段名与 {@link CodegenColumnListConditionEnum} 的默认映射
* 注意字段的匹配以后缀的方式 * 注意字段的匹配以后缀的方式
*/ */
private static final Map<String, ToolCodegenColumnListConditionEnum> columnListOperationConditionMappings = private static final Map<String, CodegenColumnListConditionEnum> columnListOperationConditionMappings =
MapUtil.<String, ToolCodegenColumnListConditionEnum>builder() MapUtil.<String, CodegenColumnListConditionEnum>builder()
.put("name", ToolCodegenColumnListConditionEnum.LIKE) .put("name", CodegenColumnListConditionEnum.LIKE)
.put("time", ToolCodegenColumnListConditionEnum.BETWEEN) .put("time", CodegenColumnListConditionEnum.BETWEEN)
.put("date", ToolCodegenColumnListConditionEnum.BETWEEN) .put("date", CodegenColumnListConditionEnum.BETWEEN)
.build(); .build();
/** /**
* 字段名与 {@link ToolCodegenColumnHtmlTypeEnum} 的默认映射 * 字段名与 {@link CodegenColumnHtmlTypeEnum} 的默认映射
* 注意字段的匹配以后缀的方式 * 注意字段的匹配以后缀的方式
*/ */
private static final Map<String, ToolCodegenColumnHtmlTypeEnum> columnHtmlTypeMappings = private static final Map<String, CodegenColumnHtmlTypeEnum> columnHtmlTypeMappings =
MapUtil.<String, ToolCodegenColumnHtmlTypeEnum>builder() MapUtil.<String, CodegenColumnHtmlTypeEnum>builder()
.put("status", ToolCodegenColumnHtmlTypeEnum.RADIO) .put("status", CodegenColumnHtmlTypeEnum.RADIO)
.put("sex", ToolCodegenColumnHtmlTypeEnum.RADIO) .put("sex", CodegenColumnHtmlTypeEnum.RADIO)
.put("type", ToolCodegenColumnHtmlTypeEnum.SELECT) .put("type", CodegenColumnHtmlTypeEnum.SELECT)
.put("image", ToolCodegenColumnHtmlTypeEnum.UPLOAD_IMAGE) .put("image", CodegenColumnHtmlTypeEnum.UPLOAD_IMAGE)
.put("file", ToolCodegenColumnHtmlTypeEnum.UPLOAD_FILE) .put("file", CodegenColumnHtmlTypeEnum.UPLOAD_FILE)
.put("content", ToolCodegenColumnHtmlTypeEnum.EDITOR) .put("content", CodegenColumnHtmlTypeEnum.EDITOR)
.put("time", ToolCodegenColumnHtmlTypeEnum.DATETIME) .put("time", CodegenColumnHtmlTypeEnum.DATETIME)
.put("date", ToolCodegenColumnHtmlTypeEnum.DATETIME) .put("date", CodegenColumnHtmlTypeEnum.DATETIME)
.build(); .build();
/** /**
@ -113,8 +113,8 @@ public class ToolCodegenBuilder {
LIST_OPERATION_RESULT_EXCLUDE_COLUMN.remove("createTime"); // 创建时间还是需要返回的 LIST_OPERATION_RESULT_EXCLUDE_COLUMN.remove("createTime"); // 创建时间还是需要返回的
} }
public ToolCodegenTableDO buildTable(ToolSchemaTableDO schemaTable) { public CodegenTableDO buildTable(SchemaTableDO schemaTable) {
ToolCodegenTableDO table = ToolCodegenConvert.INSTANCE.convert(schemaTable); CodegenTableDO table = CodegenConvert.INSTANCE.convert(schemaTable);
initTableDefault(table); initTableDefault(table);
return table; return table;
} }
@ -124,7 +124,7 @@ public class ToolCodegenBuilder {
* *
* @param table 表定义 * @param table 表定义
*/ */
private void initTableDefault(ToolCodegenTableDO table) { private void initTableDefault(CodegenTableDO table) {
table.setModuleName(getFullModuleName(StrUtil.subBefore(table.getTableName(), table.setModuleName(getFullModuleName(StrUtil.subBefore(table.getTableName(),
'_', false))); // 第一个 _ 前缀的前面作为 module 名字 '_', false))); // 第一个 _ 前缀的前面作为 module 名字
table.setBusinessName(toCamelCase(subAfter(table.getTableName(), table.setBusinessName(toCamelCase(subAfter(table.getTableName(),
@ -133,11 +133,11 @@ public class ToolCodegenBuilder {
table.setClassComment(subBefore(table.getTableComment(), // 去除结尾的表作为类描述 table.setClassComment(subBefore(table.getTableComment(), // 去除结尾的表作为类描述
'表', true)); '表', true));
table.setAuthor("芋艿"); // TODO 稍后改成创建人 table.setAuthor("芋艿"); // TODO 稍后改成创建人
table.setTemplateType(ToolCodegenTemplateTypeEnum.CRUD.getType()); table.setTemplateType(CodegenTemplateTypeEnum.CRUD.getType());
} }
public List<ToolCodegenColumnDO> buildColumns(List<ToolSchemaColumnDO> schemaColumns) { public List<CodegenColumnDO> buildColumns(List<SchemaColumnDO> schemaColumns) {
List<ToolCodegenColumnDO> columns = ToolCodegenConvert.INSTANCE.convertList(schemaColumns); List<CodegenColumnDO> columns = CodegenConvert.INSTANCE.convertList(schemaColumns);
columns.forEach(this::initColumnDefault); columns.forEach(this::initColumnDefault);
return columns; return columns;
} }
@ -147,7 +147,7 @@ public class ToolCodegenBuilder {
* *
* @param column 列定义 * @param column 列定义
*/ */
private void initColumnDefault(ToolCodegenColumnDO column) { private void initColumnDefault(CodegenColumnDO column) {
// 处理 Java 相关的字段的默认值 // 处理 Java 相关的字段的默认值
processColumnJava(column); processColumnJava(column);
// 处理 CRUD 相关的字段的默认值 // 处理 CRUD 相关的字段的默认值
@ -156,7 +156,7 @@ public class ToolCodegenBuilder {
processColumnUI(column); processColumnUI(column);
} }
private void processColumnJava(ToolCodegenColumnDO column) { private void processColumnJava(CodegenColumnDO column) {
// 处理 javaField 字段 // 处理 javaField 字段
column.setJavaField(toCamelCase(column.getColumnName())); column.setJavaField(toCamelCase(column.getColumnName()));
// 处理 dictType 字段暂无 // 处理 dictType 字段暂无
@ -171,7 +171,7 @@ public class ToolCodegenBuilder {
} }
} }
private void processColumnOperation(ToolCodegenColumnDO column) { private void processColumnOperation(CodegenColumnDO column) {
// 处理 createOperation 字段 // 处理 createOperation 字段
column.setCreateOperation(!CREATE_OPERATION_EXCLUDE_COLUMN.contains(column.getJavaField()) column.setCreateOperation(!CREATE_OPERATION_EXCLUDE_COLUMN.contains(column.getJavaField())
&& !column.getPrimaryKey()); // 对于主键创建时无需传递 && !column.getPrimaryKey()); // 对于主键创建时无需传递
@ -186,13 +186,13 @@ public class ToolCodegenBuilder {
.filter(entry -> StrUtil.endWithIgnoreCase(column.getJavaField(), entry.getKey())) .filter(entry -> StrUtil.endWithIgnoreCase(column.getJavaField(), entry.getKey()))
.findFirst().ifPresent(entry -> column.setListOperationCondition(entry.getValue().getCondition())); .findFirst().ifPresent(entry -> column.setListOperationCondition(entry.getValue().getCondition()));
if (column.getListOperationCondition() == null) { if (column.getListOperationCondition() == null) {
column.setListOperationCondition(ToolCodegenColumnListConditionEnum.EQ.getCondition()); column.setListOperationCondition(CodegenColumnListConditionEnum.EQ.getCondition());
} }
// 处理 listOperationResult 字段 // 处理 listOperationResult 字段
column.setListOperationResult(!LIST_OPERATION_RESULT_EXCLUDE_COLUMN.contains(column.getJavaField())); column.setListOperationResult(!LIST_OPERATION_RESULT_EXCLUDE_COLUMN.contains(column.getJavaField()));
} }
private void processColumnUI(ToolCodegenColumnDO column) { private void processColumnUI(CodegenColumnDO column) {
// 基于后缀进行匹配 // 基于后缀进行匹配
columnHtmlTypeMappings.entrySet().stream() columnHtmlTypeMappings.entrySet().stream()
.filter(entry -> StrUtil.endWithIgnoreCase(column.getJavaField(), entry.getKey())) .filter(entry -> StrUtil.endWithIgnoreCase(column.getJavaField(), entry.getKey()))
@ -200,11 +200,11 @@ public class ToolCodegenBuilder {
// 如果是 Boolean 类型时设置为 radio 类型. // 如果是 Boolean 类型时设置为 radio 类型.
// 其它类型因为字段名可以相对保障所以不进行处理例如说 date 对应 datetime 类型. // 其它类型因为字段名可以相对保障所以不进行处理例如说 date 对应 datetime 类型.
if (Boolean.class.getSimpleName().equals(column.getJavaType())) { if (Boolean.class.getSimpleName().equals(column.getJavaType())) {
column.setHtmlType(ToolCodegenColumnHtmlTypeEnum.RADIO.getType()); column.setHtmlType(CodegenColumnHtmlTypeEnum.RADIO.getType());
} }
// 兜底设置默认为 input 类型 // 兜底设置默认为 input 类型
if (column.getHtmlType() == null) { if (column.getHtmlType() == null) {
column.setHtmlType(ToolCodegenColumnHtmlTypeEnum.INPUT.getType()); column.setHtmlType(CodegenColumnHtmlTypeEnum.INPUT.getType());
} }
} }

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.codegen.impl; package cn.iocoder.yudao.module.tool.service.codegen.inner;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@ -9,7 +9,7 @@ import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.adminserver.modules.tool.framework.codegen.config.CodegenProperties; import cn.iocoder.yudao.module.tool.framework.codegen.config.CodegenProperties;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@ -19,8 +19,8 @@ import cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 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.dal.dataobject.codegen.ToolCodegenColumnDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenColumnDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.CodegenTableDO;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@ -45,7 +45,7 @@ import static cn.hutool.core.text.CharSequenceUtil.*;
* @author 芋道源码 * @author 芋道源码
*/ */
@Component @Component
public class ToolCodegenEngine { public class CodegenEngine {
/** /**
* 模板配置 * 模板配置
@ -95,7 +95,7 @@ public class ToolCodegenEngine {
.build(); .build();
@Resource @Resource
private ToolCodegenBuilder codegenBuilder; private CodegenBuilder codegenBuilder;
@Resource @Resource
private CodegenProperties codegenProperties; private CodegenProperties codegenProperties;
@ -109,7 +109,7 @@ public class ToolCodegenEngine {
*/ */
private final Map<String, Object> globalBindingMap = new HashMap<>(); private final Map<String, Object> globalBindingMap = new HashMap<>();
public ToolCodegenEngine() { public CodegenEngine() {
// 初始化 TemplateEngine 属性 // 初始化 TemplateEngine 属性
TemplateConfig config = new TemplateConfig(); TemplateConfig config = new TemplateConfig();
config.setResourceMode(TemplateConfig.ResourceMode.CLASSPATH); config.setResourceMode(TemplateConfig.ResourceMode.CLASSPATH);
@ -129,7 +129,7 @@ public class ToolCodegenEngine {
globalBindingMap.put("PageParamClassName", PageParam.class.getName()); globalBindingMap.put("PageParamClassName", PageParam.class.getName());
globalBindingMap.put("DictFormatClassName", DictFormat.class.getName()); globalBindingMap.put("DictFormatClassName", DictFormat.class.getName());
// DO 独有字段 // DO 独有字段
globalBindingMap.put("baseDOFields", ToolCodegenBuilder.BASE_DO_FIELDS); globalBindingMap.put("baseDOFields", CodegenBuilder.BASE_DO_FIELDS);
globalBindingMap.put("BaseDOClassName", BaseDO.class.getName()); globalBindingMap.put("BaseDOClassName", BaseDO.class.getName());
globalBindingMap.put("QueryWrapperClassName", QueryWrapperX.class.getName()); globalBindingMap.put("QueryWrapperClassName", QueryWrapperX.class.getName());
globalBindingMap.put("BaseMapperClassName", BaseMapperX.class.getName()); globalBindingMap.put("BaseMapperClassName", BaseMapperX.class.getName());
@ -143,12 +143,12 @@ public class ToolCodegenEngine {
globalBindingMap.put("OperateTypeEnumClassName", OperateTypeEnum.class.getName()); globalBindingMap.put("OperateTypeEnumClassName", OperateTypeEnum.class.getName());
} }
public Map<String, String> execute(ToolCodegenTableDO table, List<ToolCodegenColumnDO> columns) { public Map<String, String> execute(CodegenTableDO table, List<CodegenColumnDO> columns) {
// 创建 bindingMap // 创建 bindingMap
Map<String, Object> bindingMap = new HashMap<>(globalBindingMap); Map<String, Object> bindingMap = new HashMap<>(globalBindingMap);
bindingMap.put("table", table); bindingMap.put("table", table);
bindingMap.put("columns", columns); bindingMap.put("columns", columns);
bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, ToolCodegenColumnDO::getPrimaryKey)); // 主键字段 bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, CodegenColumnDO::getPrimaryKey)); // 主键字段
// moduleName 相关 // moduleName 相关
String simpleModuleName = codegenBuilder.getSimpleModuleName(table.getModuleName()); String simpleModuleName = codegenBuilder.getSimpleModuleName(table.getModuleName());
bindingMap.put("simpleModuleName", simpleModuleName); // system 转成 sys bindingMap.put("simpleModuleName", simpleModuleName); // system 转成 sys
@ -183,7 +183,7 @@ public class ToolCodegenEngine {
getStr(bindingMap, "classNameVar")); getStr(bindingMap, "classNameVar"));
// table 包含的字段 // table 包含的字段
ToolCodegenTableDO table = (ToolCodegenTableDO) bindingMap.get("table"); CodegenTableDO table = (CodegenTableDO) bindingMap.get("table");
filePath = StrUtil.replace(filePath, "${table.moduleName}", table.getModuleName()); filePath = StrUtil.replace(filePath, "${table.moduleName}", table.getModuleName());
filePath = StrUtil.replace(filePath, "${table.businessName}", table.getBusinessName()); filePath = StrUtil.replace(filePath, "${table.businessName}", table.getBusinessName());
filePath = StrUtil.replace(filePath, "${table.className}", table.getClassName()); filePath = StrUtil.replace(filePath, "${table.className}", table.getClassName());

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.codegen.impl; package cn.iocoder.yudao.module.tool.service.codegen.inner;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaColumnDO;
import cn.iocoder.yudao.adminserver.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO; import cn.iocoder.yudao.module.tool.dal.dataobject.codegen.SchemaTableDO;
import com.alibaba.druid.DbType; import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.ast.expr.SQLCharExpr; import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition; import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
@ -21,26 +21,26 @@ import java.util.Objects;
import static com.alibaba.druid.sql.SQLUtils.normalize; import static com.alibaba.druid.sql.SQLUtils.normalize;
/** /**
* SQL 解析器将创建表的 SQL解析成 {@link ToolSchemaTableDO} {@link ToolSchemaColumnDO} 对象 * SQL 解析器将创建表的 SQL解析成 {@link SchemaTableDO} {@link SchemaColumnDO} 对象
* 后续可以基于它们生成代码~ * 后续可以基于它们生成代码~
* *
* @author 芋道源码 * @author 芋道源码
*/ */
public class ToolCodegenSQLParser { public class CodegenSQLParser {
/** /**
* 解析建表 SQL 语句返回 {@link ToolSchemaTableDO} {@link ToolSchemaColumnDO} 对象 * 解析建表 SQL 语句返回 {@link SchemaTableDO} {@link SchemaColumnDO} 对象
* *
* @param sql 建表 SQL 语句 * @param sql 建表 SQL 语句
* @return 解析结果 * @return 解析结果
*/ */
public static KeyValue<ToolSchemaTableDO, List<ToolSchemaColumnDO>> parse(String sql) { public static KeyValue<SchemaTableDO, List<SchemaColumnDO>> parse(String sql) {
// 解析 SQL Statement // 解析 SQL Statement
SQLCreateTableStatement statement = parseCreateSQL(sql); SQLCreateTableStatement statement = parseCreateSQL(sql);
// 解析 Table // 解析 Table
ToolSchemaTableDO table = parseTable(statement); SchemaTableDO table = parseTable(statement);
// 解析 Column 字段 // 解析 Column 字段
List<ToolSchemaColumnDO> columns = parseColumns(statement); List<SchemaColumnDO> columns = parseColumns(statement);
columns.forEach(column -> column.setTableName(table.getTableName())); columns.forEach(column -> column.setTableName(table.getTableName()));
// 返回 // 返回
return new DefaultKeyValue<>(table, columns); return new DefaultKeyValue<>(table, columns);
@ -61,8 +61,8 @@ public class ToolCodegenSQLParser {
return (MySqlCreateTableStatement) repository.findTable(tableName).getStatement(); return (MySqlCreateTableStatement) repository.findTable(tableName).getStatement();
} }
private static ToolSchemaTableDO parseTable(SQLCreateTableStatement statement) { private static SchemaTableDO parseTable(SQLCreateTableStatement statement) {
return ToolSchemaTableDO.builder() return SchemaTableDO.builder()
.tableName(statement.getTableSource().getTableName(true)) .tableName(statement.getTableSource().getTableName(true))
.tableComment(getCommentText(statement)) .tableComment(getCommentText(statement))
.build(); .build();
@ -75,13 +75,13 @@ public class ToolCodegenSQLParser {
return ((SQLCharExpr) statement.getComment()).getText(); return ((SQLCharExpr) statement.getComment()).getText();
} }
private static List<ToolSchemaColumnDO> parseColumns(SQLCreateTableStatement statement) { private static List<SchemaColumnDO> parseColumns(SQLCreateTableStatement statement) {
List<ToolSchemaColumnDO> columns = new ArrayList<>(); List<SchemaColumnDO> columns = new ArrayList<>();
statement.getTableElementList().forEach(element -> parseColumn(columns, element)); statement.getTableElementList().forEach(element -> parseColumn(columns, element));
return columns; return columns;
} }
private static void parseColumn(List<ToolSchemaColumnDO> columns, SQLTableElement element) { private static void parseColumn(List<SchemaColumnDO> columns, SQLTableElement element) {
// 处理主键 // 处理主键
if (element instanceof SQLPrimaryKey) { if (element instanceof SQLPrimaryKey) {
parsePrimaryKey(columns, (SQLPrimaryKey) element); parsePrimaryKey(columns, (SQLPrimaryKey) element);
@ -93,16 +93,16 @@ public class ToolCodegenSQLParser {
} }
} }
private static void parsePrimaryKey(List<ToolSchemaColumnDO> columns, SQLPrimaryKey primaryKey) { private static void parsePrimaryKey(List<SchemaColumnDO> columns, SQLPrimaryKey primaryKey) {
String columnName = normalize(primaryKey.getColumns().get(0).toString()); // 暂时不考虑联合主键 String columnName = normalize(primaryKey.getColumns().get(0).toString()); // 暂时不考虑联合主键
// 匹配 columns 主键字段设置为 primary // 匹配 columns 主键字段设置为 primary
columns.stream().filter(column -> column.getColumnName().equals(columnName)) columns.stream().filter(column -> column.getColumnName().equals(columnName))
.forEach(column -> column.setPrimaryKey(true)); .forEach(column -> column.setPrimaryKey(true));
} }
private static void parseColumnDefinition(List<ToolSchemaColumnDO> columns, SQLColumnDefinition definition) { private static void parseColumnDefinition(List<SchemaColumnDO> columns, SQLColumnDefinition definition) {
String text = definition.toString().toUpperCase(); String text = definition.toString().toUpperCase();
columns.add(ToolSchemaColumnDO.builder() columns.add(SchemaColumnDO.builder()
.columnName(normalize(definition.getColumnName())) .columnName(normalize(definition.getColumnName()))
.columnType(definition.getDataType().toString()) .columnType(definition.getDataType().toString())
.columnComment(Objects.isNull(definition.getComment()) ? "" .columnComment(Objects.isNull(definition.getComment()) ? ""

View File

@ -1,17 +1,21 @@
package cn.iocoder.yudao.adminserver.modules.tool.service.test; package cn.iocoder.yudao.module.tool.service.test;
import java.util.*; import java.util.*;
import javax.validation.*; 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 cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoCreateReqVO;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoExportReqVO;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoPageReqVO;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoUpdateReqVO;
import cn.iocoder.yudao.module.tool.dal.dataobject.test.TestDemoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
/** /**
* 字典类型 Service 接口 * 测试示例 Service 接口
* *
* @author 芋艿 * @author 芋艿
*/ */
public interface ToolTestDemoService { public interface TestDemoService {
/** /**
* 创建字典类型 * 创建字典类型
@ -19,14 +23,14 @@ public interface ToolTestDemoService {
* @param createReqVO 创建信息 * @param createReqVO 创建信息
* @return 编号 * @return 编号
*/ */
Long createTestDemo(@Valid ToolTestDemoCreateReqVO createReqVO); Long createTestDemo(@Valid TestDemoCreateReqVO createReqVO);
/** /**
* 更新字典类型 * 更新字典类型
* *
* @param updateReqVO 更新信息 * @param updateReqVO 更新信息
*/ */
void updateTestDemo(@Valid ToolTestDemoUpdateReqVO updateReqVO); void updateTestDemo(@Valid TestDemoUpdateReqVO updateReqVO);
/** /**
* 删除字典类型 * 删除字典类型
@ -41,7 +45,7 @@ public interface ToolTestDemoService {
* @param id 编号 * @param id 编号
* @return 字典类型 * @return 字典类型
*/ */
ToolTestDemoDO getTestDemo(Long id); TestDemoDO getTestDemo(Long id);
/** /**
* 获得字典类型列表 * 获得字典类型列表
@ -49,7 +53,7 @@ public interface ToolTestDemoService {
* @param ids 编号 * @param ids 编号
* @return 字典类型列表 * @return 字典类型列表
*/ */
List<ToolTestDemoDO> getTestDemoList(Collection<Long> ids); List<TestDemoDO> getTestDemoList(Collection<Long> ids);
/** /**
* 获得字典类型分页 * 获得字典类型分页
@ -57,7 +61,7 @@ public interface ToolTestDemoService {
* @param pageReqVO 分页查询 * @param pageReqVO 分页查询
* @return 字典类型分页 * @return 字典类型分页
*/ */
PageResult<ToolTestDemoDO> getTestDemoPage(ToolTestDemoPageReqVO pageReqVO); PageResult<TestDemoDO> getTestDemoPage(TestDemoPageReqVO pageReqVO);
/** /**
* 获得字典类型列表, 用于 Excel 导出 * 获得字典类型列表, 用于 Excel 导出
@ -65,6 +69,6 @@ public interface ToolTestDemoService {
* @param exportReqVO 查询条件 * @param exportReqVO 查询条件
* @return 字典类型列表 * @return 字典类型列表
*/ */
List<ToolTestDemoDO> getTestDemoList(ToolTestDemoExportReqVO exportReqVO); List<TestDemoDO> getTestDemoList(TestDemoExportReqVO exportReqVO);
} }

View File

@ -0,0 +1,86 @@
package cn.iocoder.yudao.module.tool.service.test;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoCreateReqVO;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoExportReqVO;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoPageReqVO;
import cn.iocoder.yudao.module.tool.controller.admin.test.vo.TestDemoUpdateReqVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import cn.iocoder.yudao.module.tool.dal.dataobject.test.TestDemoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.tool.convert.test.TestDemoConvert;
import cn.iocoder.yudao.module.tool.dal.mysql.test.TestDemoMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.tool.enums.ErrorCodeConstants.*;
/**
* 测试示例 Service 实现类
*
* @author 芋艿
*/
@Service
@Validated
public class TestDemoServiceImpl implements TestDemoService {
@Resource
private TestDemoMapper testDemoMapper;
@Override
public Long createTestDemo(TestDemoCreateReqVO createReqVO) {
// 插入
TestDemoDO testDemo = TestDemoConvert.INSTANCE.convert(createReqVO);
testDemoMapper.insert(testDemo);
// 返回
return testDemo.getId();
}
@Override
public void updateTestDemo(TestDemoUpdateReqVO updateReqVO) {
// 校验存在
this.validateTestDemoExists(updateReqVO.getId());
// 更新
TestDemoDO updateObj = TestDemoConvert.INSTANCE.convert(updateReqVO);
testDemoMapper.updateById(updateObj);
}
@Override
public void deleteTestDemo(Long id) {
// 校验存在
this.validateTestDemoExists(id);
// 删除
testDemoMapper.deleteById(id);
}
private void validateTestDemoExists(Long id) {
if (testDemoMapper.selectById(id) == null) {
throw exception(TEST_DEMO_NOT_EXISTS);
}
}
@Override
public TestDemoDO getTestDemo(Long id) {
return testDemoMapper.selectById(id);
}
@Override
public List<TestDemoDO> getTestDemoList(Collection<Long> ids) {
return testDemoMapper.selectBatchIds(ids);
}
@Override
public PageResult<TestDemoDO> getTestDemoPage(TestDemoPageReqVO pageReqVO) {
return testDemoMapper.selectPage(pageReqVO);
}
@Override
public List<TestDemoDO> getTestDemoList(TestDemoExportReqVO exportReqVO) {
return testDemoMapper.selectList(exportReqVO);
}
}