refactor: 代码生成模块问题修复

This commit is contained in:
Ray.Hao 2024-09-06 00:36:02 +08:00
parent 496a569dfa
commit c816f64dc5
20 changed files with 97 additions and 330 deletions

View File

@ -14,6 +14,7 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>io.swagger.core.v3</groupId> <groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId> <artifactId>swagger-annotations</artifactId>

View File

@ -23,6 +23,7 @@
<artifactId>spring-boot-starter-aop</artifactId> <artifactId>spring-boot-starter-aop</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.github.openfeign</groupId> <groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId> <artifactId>feign-core</artifactId>
@ -75,16 +76,6 @@
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId> <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -51,7 +51,7 @@ public class ResourceServerConfig {
* 白名单路径列表 * 白名单路径列表
*/ */
@Setter @Setter
private List<String> whitelistPaths; private List<String> ignoreUris;
@Bean @Bean
@ -59,11 +59,11 @@ public class ResourceServerConfig {
MvcRequestMatcher.Builder mvcMatcherBuilder = new MvcRequestMatcher.Builder(introspector); MvcRequestMatcher.Builder mvcMatcherBuilder = new MvcRequestMatcher.Builder(introspector);
log.info("whitelist path:{}", JSONUtil.toJsonStr(whitelistPaths)); log.info("whitelist path:{}", JSONUtil.toJsonStr(ignoreUris));
http.authorizeHttpRequests((requests) -> http.authorizeHttpRequests((requests) ->
{ {
if (CollectionUtil.isNotEmpty(whitelistPaths)) { if (CollectionUtil.isNotEmpty(ignoreUris)) {
for (String whitelistPath : whitelistPaths) { for (String whitelistPath : ignoreUris) {
requests.requestMatchers(mvcMatcherBuilder.pattern(whitelistPath)).permitAll(); requests.requestMatchers(mvcMatcherBuilder.pattern(whitelistPath)).permitAll();
} }
} }

View File

@ -18,13 +18,40 @@
</properties> </properties>
<dependencies> <dependencies>
<!-- Spring Cloud & Alibaba -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<!-- 注册中心 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<artifactId>jsr305</artifactId>
<groupId>com.google.code.findbugs</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<!-- 配置中心 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.youlai</groupId> <groupId>com.youlai</groupId>
<artifactId>common-core</artifactId> <artifactId>common-core</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.youlai</groupId> <groupId>com.youlai</groupId>
<artifactId>common-mybatis</artifactId> <artifactId>common-mybatis</artifactId>
@ -35,6 +62,16 @@
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId> <artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,17 @@
package com.youlai.generator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* 系统服务启动类
*
* @author Ray
* @since 0.0.1
*/
@SpringBootApplication
public class GeneratorApplication {
public static void main(String[] args) {
SpringApplication.run(GeneratorApplication.class, args);
}
}

View File

@ -1,43 +1,49 @@
package com.youlai.generator.controller; package com.youlai.generator.controller;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.common.result.PageResult; import com.youlai.common.result.PageResult;
import com.youlai.common.result.Result;
import com.youlai.generator.model.query.TablePageQuery; import com.youlai.generator.model.query.TablePageQuery;
import com.youlai.generator.model.vo.TablePageVO; import com.youlai.generator.model.vo.TablePageVO;
import com.youlai.generator.service.DatasourceService; import com.youlai.generator.service.DatabaseService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* 数据控制器 * 数据库管理控制器
* *
* @author Ray * @author Ray
* @since 2.10.0 * @since 2.10.0
*/ */
@Tag(name = "数据接口") @Tag(name = "数据库管理接口")
@RestController @RestController
@RequestMapping("/api/v1/datasources") @RequestMapping("/api/v1/database")
@RequiredArgsConstructor @RequiredArgsConstructor
public class DatasourceController { public class DatabaseController {
private final DatasourceService datasourceService; private final DataSource dataSource;
private final DatabaseService databaseService;
@GetMapping("/keys") @GetMapping("/datasource/keys")
@Operation(summary = "获取所有数据源的key") @Operation(summary = "获取所有数据源的key")
public List<String> getAllDatasourceKeys() { public Result<List<String>> getAllDatasourceKeys() {
return datasourceService.getAllDatasourceKeys(); DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
return Result.success(new ArrayList<>(ds.getDataSources().keySet()));
} }
@Operation(summary = "获取数据表分页列表") @Operation(summary = "获取数据表分页列表")
@GetMapping("/tables") @GetMapping("/tables/page")
public PageResult<TablePageVO> getTablePage( public PageResult<TablePageVO> getTablePage(
TablePageQuery queryParams TablePageQuery queryParams
) { ) {
Page<TablePageVO> result = datasourceService.getTablePage(queryParams); Page<TablePageVO> result = databaseService.getTablePage(queryParams);
return PageResult.success(result); return PageResult.success(result);
} }

View File

@ -1,7 +1,7 @@
package com.youlai.generator.model.form; package com.youlai.generator.model.form;
import com.youlai.boot.common.enums.FormTypeEnum; import com.youlai.generator.enums.FormTypeEnum;
import com.youlai.boot.common.enums.QueryTypeEnum; import com.youlai.generator.enums.QueryTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;

View File

@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.generator.model.query.TablePageQuery; import com.youlai.generator.model.query.TablePageQuery;
import com.youlai.generator.model.vo.TablePageVO; import com.youlai.generator.model.vo.TablePageVO;
import java.util.List;
/** /**
* 数据源服务接口 * 数据源服务接口
@ -12,15 +11,7 @@ import java.util.List;
* @author Ray * @author Ray
* @since 4.0.0 * @since 4.0.0
*/ */
public interface DatasourceService { public interface DatabaseService {
/**
* 获取所有数据源
*
* @return
*/
List<String> getAllDatasourceKeys() ;
/** /**
* 获取数据表分页列表 * 获取数据表分页列表

View File

@ -1,17 +1,14 @@
package com.youlai.generator.service.impl; package com.youlai.generator.service.impl;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.generator.config.GeneratorProperties; import com.youlai.generator.config.GeneratorProperties;
import com.youlai.generator.mapper.DatabaseMapper; import com.youlai.generator.mapper.DatabaseMapper;
import com.youlai.generator.model.query.TablePageQuery; import com.youlai.generator.model.query.TablePageQuery;
import com.youlai.generator.model.vo.TablePageVO; import com.youlai.generator.model.vo.TablePageVO;
import com.youlai.generator.service.DatasourceService; import com.youlai.generator.service.DatabaseService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -22,27 +19,13 @@ import java.util.List;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class DatasourceServiceImpl implements DatasourceService { public class DatabaseServiceImpl implements DatabaseService {
private final DataSource dataSource;
private final DatabaseMapper databaseMapper; private final DatabaseMapper databaseMapper;
private final GeneratorProperties generatorProperties; private final GeneratorProperties generatorProperties;
/**
* 获取所有数据源
*
* @return 数据源列表
*/
@Override
public List<String> getAllDatasourceKeys() {
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
return new ArrayList<>(ds.getDataSources().keySet());
}
/** /**
* 数据表分页列表 * 数据表分页列表
* *

View File

@ -1,3 +1,6 @@
server:
port: 8810
spring: spring:
application: application:
name: youlai-generator name: youlai-generator

View File

@ -2,10 +2,10 @@
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youlai.boot.platform.generator.mapper.DatabaseMapper"> <mapper namespace="com.youlai.generator.mapper.DatabaseMapper">
<!-- 查询数据库表分页 --> <!-- 查询数据库表分页 -->
<select id="getTablePage" resultType="com.youlai.boot.system.model.vo.TablePageVO"> <select id="getTablePage" resultType="com.youlai.generator.model.vo.TablePageVO">
SELECT SELECT
t1.TABLE_NAME , t1.TABLE_NAME ,
t1.TABLE_COMMENT , t1.TABLE_COMMENT ,
@ -33,7 +33,7 @@
CREATE_TIME DESC CREATE_TIME DESC
</select> </select>
<select id="getTableMetadata" resultType="com.youlai.boot.system.model.bo.TableMetaData"> <select id="getTableMetadata" resultType="com.youlai.generator.model.bo.TableMetaData">
SELECT SELECT
TABLE_NAME , TABLE_NAME ,
TABLE_COMMENT , TABLE_COMMENT ,
@ -47,7 +47,7 @@
AND TABLE_NAME = #{tableName} AND TABLE_NAME = #{tableName}
</select> </select>
<select id="getTableColumns" resultType="com.youlai.boot.system.model.bo.ColumnMetaData"> <select id="getTableColumns" resultType="com.youlai.generator.model.bo.ColumnMetaData">
SELECT SELECT
COLUMN_NAME, COLUMN_NAME,
DATA_TYPE, DATA_TYPE,

View File

@ -2,6 +2,6 @@
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youlai.boot.platform.generator.mapper.GenConfigMapper"> <mapper namespace="com.youlai.generator.mapper.GenConfigMapper">
</mapper> </mapper>

View File

@ -2,6 +2,6 @@
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youlai.boot.platform.generator.mapper.GenFieldConfigMapper"> <mapper namespace="com.youlai.generator.mapper.GenFieldConfigMapper">
</mapper> </mapper>

View File

@ -8,7 +8,7 @@ import com.youlai.common.core.model.Option;
import com.youlai.system.model.form.DictForm; import com.youlai.system.model.form.DictForm;
import com.youlai.system.model.query.DictPageQuery; import com.youlai.system.model.query.DictPageQuery;
import com.youlai.system.model.vo.DictPageVO; import com.youlai.system.model.vo.DictPageVO;
import com.youlai.system.service.SysDictService; import com.youlai.system.service.DictService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -30,7 +30,7 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class DictController { public class DictController {
private final SysDictService dictService; private final DictService dictService;
@Operation(summary = "字典分页列表") @Operation(summary = "字典分页列表")
@GetMapping("/page") @GetMapping("/page")

View File

@ -13,7 +13,6 @@ import com.youlai.system.model.entity.User;
import com.youlai.system.model.form.UserForm; import com.youlai.system.model.form.UserForm;
import com.youlai.system.model.form.UserRegisterForm; import com.youlai.system.model.form.UserRegisterForm;
import com.youlai.system.model.query.UserPageQuery; import com.youlai.system.model.query.UserPageQuery;
import com.youlai.mall.system.model.vo.*;
import com.youlai.system.model.vo.*; import com.youlai.system.model.vo.*;
import com.youlai.system.service.UserService; import com.youlai.system.service.UserService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;

View File

@ -1,53 +0,0 @@
package com.youlai.system.model.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.youlai.common.base.BaseEntity;
import lombok.Getter;
import lombok.Setter;
/**
* 代码生成基础配置
*
* @author Ray
* @since 2.10.0
*/
@TableName(value = "gen_config")
@Getter
@Setter
public class GenConfig extends BaseEntity {
/**
* 表名
*/
private String tableName;
/**
* 包名
*/
private String packageName;
/**
* 模块名
*/
private String moduleName;
/**
* 实体类名
*/
private String entityName;
/**
* 业务名
*/
private String businessName;
/**
* 父菜单ID
*/
private Long parentMenuId;
/**
* 作者
*/
private String author;
}

View File

@ -1,105 +0,0 @@
package com.youlai.system.model.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.youlai.common.base.BaseEntity;
import com.youlai.system.enums.FormTypeEnum;
import com.youlai.system.enums.QueryTypeEnum;
import lombok.Getter;
import lombok.Setter;
/**
* 字段生成配置实体
*
* @author Ray
* @since 2.10.0
*/
@TableName(value = "gen_field_config")
@Getter
@Setter
public class GenFieldConfig extends BaseEntity {
/**
* 关联的配置ID
*/
private Long configId;
/**
* 列名
*/
private String columnName;
/**
* 列类型
*/
private String columnType;
/**
* 字段长度
*/
private Integer maxLength;
/**
* 字段名称
*/
private String fieldName;
/**
* 字段排序
*/
private Integer fieldSort;
/**
* 字段类型
*/
private String fieldType;
/**
* 字段描述
*/
private String fieldComment;
/**
* 表单类型
*/
private FormTypeEnum formType;
/**
* 查询方式
*/
private QueryTypeEnum queryType;
/**
* 是否在列表显示
*/
private Integer isShowInList;
/**
* 是否在表单显示
*/
private Integer isShowInForm;
/**
* 是否在查询条件显示
*/
private Integer isShowInQuery;
/**
* 是否必填
*/
private Integer isRequired;
/**
* TypeScript类型
*/
@TableField(exist = false)
@JsonIgnore
private String tsType;
/**
* 字典类型
*/
private String dictType;
}

View File

@ -1,103 +0,0 @@
package com.youlai.system.model.form;
import com.youlai.system.enums.FormTypeEnum;
import com.youlai.system.enums.QueryTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
/**
* 代码生成配置表单
*
* @author Ray
* @since 2.10.0
*/
@Schema(description = "代码生成配置表单")
@Data
public class GenConfigForm {
@Schema(description = "主键",example = "1")
private Long id;
@Schema(description = "表名",example = "sys_user")
private String tableName;
@Schema(description = "业务名",example = "用户")
private String businessName;
@Schema(description = "模块名",example = "system")
private String moduleName;
@Schema(description = "包名",example = "com.youlai")
private String packageName;
@Schema(description = "实体名",example = "User")
private String entityName;
@Schema(description = "作者",example = "youlaitech")
private String author;
@Schema(description = "上级菜单ID",example = "1")
private Long parentMenuId;
@Schema(description = "字段配置列表")
private List<FieldConfig> fieldConfigs;
@Schema(description = "后端应用名")
private String backendAppName;
@Schema(description = "前端应用名")
private String frontendAppName;
@Schema(description = "字段配置")
@Data
public static class FieldConfig {
@Schema(description = "主键")
private Long id;
@Schema(description = "列名")
private String columnName;
@Schema(description = "列类型")
private String columnType;
@Schema(description = "字段名")
private String fieldName;
@Schema(description = "字段排序")
private Integer fieldSort;
@Schema(description = "字段类型")
private String fieldType;
@Schema(description = "字段描述")
private String fieldComment;
@Schema(description = "是否在列表显示")
private Integer isShowInList;
@Schema(description = "是否在表单显示")
private Integer isShowInForm;
@Schema(description = "是否在查询条件显示")
private Integer isShowInQuery;
@Schema(description = "是否必填")
private Integer isRequired;
@Schema(description = "最大长度")
private Integer maxLength;
@Schema(description = "表单类型")
private FormTypeEnum formType;
@Schema(description = "查询类型")
private QueryTypeEnum queryType;
@Schema(description = "字典类型")
private String dictType;
}
}

View File

@ -16,7 +16,7 @@ import java.util.List;
* @author haoxr * @author haoxr
* @since 2022/10/12 * @since 2022/10/12
*/ */
public interface SysDictService extends IService<Dict> { public interface DictService extends IService<Dict> {
/** /**
* 字典分页列表 * 字典分页列表

View File

@ -17,7 +17,7 @@ import com.youlai.system.model.form.DictForm;
import com.youlai.system.model.query.DictPageQuery; import com.youlai.system.model.query.DictPageQuery;
import com.youlai.system.model.vo.DictPageVO; import com.youlai.system.model.vo.DictPageVO;
import com.youlai.system.service.DictItemService; import com.youlai.system.service.DictItemService;
import com.youlai.system.service.SysDictService; import com.youlai.system.service.DictService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -33,7 +33,7 @@ import java.util.stream.Collectors;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class SysDictServiceImpl extends ServiceImpl<DictMapper, Dict> implements SysDictService { public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements DictService {
private final DictItemService dictItemService; private final DictItemService dictItemService;
private final DictConverter dictConverter; private final DictConverter dictConverter;