chore: 合并 develop 代码生成分支
This commit is contained in:
@@ -395,4 +395,52 @@ CREATE TABLE `sys_log` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC COMMENT='系统日志表';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci ROW_FORMAT=DYNAMIC COMMENT='系统日志表';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for gen_config
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `gen_config`;
|
||||||
|
CREATE TABLE `gen_config` (
|
||||||
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||||
|
`table_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '表名',
|
||||||
|
`module_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '模块名',
|
||||||
|
`package_name` varchar(255) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '包名',
|
||||||
|
`business_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '业务名',
|
||||||
|
`entity_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '实体类名',
|
||||||
|
`author` varchar(50) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '作者',
|
||||||
|
`parent_menu_id` bigint DEFAULT NULL COMMENT '上级菜单ID,对应sys_menu的id ',
|
||||||
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`is_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `uk_tablename` (`table_name`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='代码生成基础配置表';
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for gen_field_config
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `gen_field_config`;
|
||||||
|
CREATE TABLE `gen_field_config` (
|
||||||
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||||
|
`config_id` bigint NOT NULL COMMENT '关联的配置ID',
|
||||||
|
`column_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
|
||||||
|
`column_type` varchar(50) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
|
||||||
|
`column_length` int DEFAULT NULL,
|
||||||
|
`field_name` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '字段名称',
|
||||||
|
`field_type` varchar(100) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '字段类型',
|
||||||
|
`field_sort` int DEFAULT NULL COMMENT '字段排序',
|
||||||
|
`field_comment` varchar(255) CHARACTER SET utf8 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '字段描述',
|
||||||
|
`is_required` tinyint(1) DEFAULT NULL COMMENT '是否必填',
|
||||||
|
`is_show_in_list` tinyint(1) DEFAULT '0' COMMENT '是否在列表显示',
|
||||||
|
`is_show_in_form` tinyint(1) DEFAULT '0' COMMENT '是否在表单显示',
|
||||||
|
`is_show_in_query` tinyint(1) DEFAULT '0' COMMENT '是否在查询条件显示',
|
||||||
|
`query_type` tinyint DEFAULT NULL COMMENT '查询方式',
|
||||||
|
`form_type` tinyint DEFAULT NULL COMMENT '表单类型',
|
||||||
|
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `config_id` (`config_id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='代码生成字段配置表';
|
||||||
|
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS = 1;
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
|||||||
@@ -395,4 +395,52 @@ CREATE TABLE `sys_log` (
|
|||||||
PRIMARY KEY (`id`) USING BTREE
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='系统日志表';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='系统日志表';
|
||||||
|
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for gen_config
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `gen_config`;
|
||||||
|
CREATE TABLE `gen_config` (
|
||||||
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||||
|
`table_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '表名',
|
||||||
|
`module_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '模块名',
|
||||||
|
`package_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '包名',
|
||||||
|
`business_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '业务名',
|
||||||
|
`entity_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '实体类名',
|
||||||
|
`author` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '作者',
|
||||||
|
`parent_menu_id` bigint DEFAULT NULL COMMENT '上级菜单ID,对应sys_menu的id ',
|
||||||
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`is_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `uk_tablename` (`table_name`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='代码生成基础配置表';
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for gen_field_config
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `gen_field_config`;
|
||||||
|
CREATE TABLE `gen_field_config` (
|
||||||
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||||
|
`config_id` bigint NOT NULL COMMENT '关联的配置ID',
|
||||||
|
`column_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
|
||||||
|
`column_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
|
||||||
|
`column_length` int DEFAULT NULL,
|
||||||
|
`field_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '字段名称',
|
||||||
|
`field_type` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '字段类型',
|
||||||
|
`field_sort` int DEFAULT NULL COMMENT '字段排序',
|
||||||
|
`field_comment` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '字段描述',
|
||||||
|
`is_required` tinyint(1) DEFAULT NULL COMMENT '是否必填',
|
||||||
|
`is_show_in_list` tinyint(1) DEFAULT '0' COMMENT '是否在列表显示',
|
||||||
|
`is_show_in_form` tinyint(1) DEFAULT '0' COMMENT '是否在表单显示',
|
||||||
|
`is_show_in_query` tinyint(1) DEFAULT '0' COMMENT '是否在查询条件显示',
|
||||||
|
`query_type` tinyint DEFAULT NULL COMMENT '查询方式',
|
||||||
|
`form_type` tinyint DEFAULT NULL COMMENT '表单类型',
|
||||||
|
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `config_id` (`config_id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='代码生成字段配置表';
|
||||||
|
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS = 1;
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
|||||||
17
src/main/java/com/youlai/system/config/JacksonConfig.java
Normal file
17
src/main/java/com/youlai/system/config/JacksonConfig.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.youlai.system.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class JacksonConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ObjectMapper objectMapper() {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);
|
||||||
|
return objectMapper;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.youlai.system.config.property;
|
package com.youlai.system.config.property;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.file.FileNameUtil;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@@ -18,18 +19,55 @@ import java.util.Map;
|
|||||||
@Data
|
@Data
|
||||||
public class GeneratorProperties {
|
public class GeneratorProperties {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认配置
|
||||||
|
*/
|
||||||
|
private DefaultConfig defaultConfig ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板配置
|
||||||
|
*/
|
||||||
private Map<String, TemplateConfig> templateConfigs = MapUtil.newHashMap(true);
|
private Map<String, TemplateConfig> templateConfigs = MapUtil.newHashMap(true);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后端应用名
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String backendAppName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前端应用名
|
||||||
|
*/
|
||||||
|
private String frontendAppName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板配置
|
* 模板配置
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public static class TemplateConfig{
|
public static class TemplateConfig {
|
||||||
|
|
||||||
private String templatePath;
|
private String templatePath;
|
||||||
|
|
||||||
private String packageName;
|
private String packageName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件扩展名,如 .java
|
||||||
|
*/
|
||||||
|
private String extension = FileNameUtil.EXT_JAVA;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认配置
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class DefaultConfig {
|
||||||
|
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,22 +3,25 @@ package com.youlai.system.controller;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.youlai.system.common.result.PageResult;
|
import com.youlai.system.common.result.PageResult;
|
||||||
import com.youlai.system.common.result.Result;
|
import com.youlai.system.common.result.Result;
|
||||||
|
import com.youlai.system.model.form.GenConfigForm;
|
||||||
import com.youlai.system.model.query.TablePageQuery;
|
import com.youlai.system.model.query.TablePageQuery;
|
||||||
import com.youlai.system.model.vo.TableColumnVO;
|
import com.youlai.system.model.vo.GeneratorPreviewVO;
|
||||||
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
|
||||||
import com.youlai.system.model.vo.TablePageVO;
|
import com.youlai.system.model.vo.TablePageVO;
|
||||||
import com.youlai.system.service.GeneratorService;
|
import com.youlai.system.service.GeneratorService;
|
||||||
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;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成器控制层
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
@Tag(name = "09.代码生成")
|
@Tag(name = "09.代码生成")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/generator")
|
@RequestMapping("/api/v1/generator")
|
||||||
@@ -36,20 +39,25 @@ public class GeneratorController {
|
|||||||
return PageResult.success(result);
|
return PageResult.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "获取数据表字段列表")
|
@Operation(summary = "获取代码生成配置")
|
||||||
@GetMapping("/table/{tableName}/columns")
|
@GetMapping("/{tableName}/config")
|
||||||
public Result<List<TableColumnVO>> getTableColumns(
|
public Result<GenConfigForm> getGenConfigFormData(
|
||||||
@Parameter(description = "表名", example = "sys_user") @PathVariable String tableName
|
@Parameter(description = "表名", example = "sys_user") @PathVariable String tableName) {
|
||||||
) {
|
GenConfigForm formData = generatorService.getGenConfigFormData(tableName);
|
||||||
List<TableColumnVO> list = generatorService.getTableColumns(tableName);
|
return Result.success(formData);
|
||||||
return Result.success(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "保存代码生成配置")
|
||||||
|
@PostMapping("/{tableName}/config")
|
||||||
|
public Result saveGenConfig(@RequestBody GenConfigForm formData) {
|
||||||
|
generatorService.saveGenConfig(formData);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "获取预览生成代码")
|
@Operation(summary = "获取预览生成代码")
|
||||||
@GetMapping("/table/{tableName}/preview")
|
@GetMapping("/{tableName}/preview")
|
||||||
public Result<List<TableGeneratePreviewVO>> getTablePreviewData(@PathVariable String tableName) {
|
public Result<List<GeneratorPreviewVO>> getTablePreviewData(@PathVariable String tableName) {
|
||||||
List<TableGeneratePreviewVO> list = generatorService.getTablePreviewData(tableName);
|
List<GeneratorPreviewVO> list = generatorService.getTablePreviewData(tableName);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.youlai.system.common.result.PageResult;
|
import com.youlai.system.common.result.PageResult;
|
||||||
import com.youlai.system.common.result.Result;
|
import com.youlai.system.common.result.Result;
|
||||||
import com.youlai.system.common.util.ExcelUtils;
|
import com.youlai.system.util.ExcelUtils;
|
||||||
import com.youlai.system.enums.LogModuleEnum;
|
import com.youlai.system.enums.LogModuleEnum;
|
||||||
import com.youlai.system.model.dto.UserImportDTO;
|
import com.youlai.system.model.dto.UserImportDTO;
|
||||||
import com.youlai.system.plugin.norepeat.annotation.PreventRepeatSubmit;
|
import com.youlai.system.plugin.norepeat.annotation.PreventRepeatSubmit;
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.youlai.system.converter;
|
||||||
|
|
||||||
|
import com.youlai.system.model.entity.GenConfig;
|
||||||
|
import com.youlai.system.model.entity.GenFieldConfig;
|
||||||
|
import com.youlai.system.model.form.GenConfigForm;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成配置转换器
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface GenConfigConverter {
|
||||||
|
|
||||||
|
@Mapping(source = "genConfig.tableName", target = "tableName")
|
||||||
|
@Mapping(source = "genConfig.businessName", target = "businessName")
|
||||||
|
@Mapping(source = "genConfig.moduleName", target = "moduleName")
|
||||||
|
@Mapping(source = "genConfig.packageName", target = "packageName")
|
||||||
|
@Mapping(source = "genConfig.entityName", target = "entityName")
|
||||||
|
@Mapping(source = "genConfig.author", target = "author")
|
||||||
|
@Mapping(source = "fieldConfigs", target = "fieldConfigs")
|
||||||
|
GenConfigForm toGenConfigForm(GenConfig genConfig, List<GenFieldConfig> fieldConfigs);
|
||||||
|
|
||||||
|
List<GenConfigForm.FieldConfig> toGenFieldConfigForm(List<GenFieldConfig> fieldConfigs);
|
||||||
|
|
||||||
|
GenConfigForm.FieldConfig toGenFieldConfigForm(GenFieldConfig genFieldConfig);
|
||||||
|
|
||||||
|
|
||||||
|
GenConfig toGenConfig(GenConfigForm formData);
|
||||||
|
|
||||||
|
List<GenFieldConfig> toGenFieldConfig(List<GenConfigForm.FieldConfig> fieldConfigs);
|
||||||
|
|
||||||
|
GenFieldConfig toGenFieldConfig(GenConfigForm.FieldConfig fieldConfig);
|
||||||
|
|
||||||
|
}
|
||||||
84
src/main/java/com/youlai/system/enums/FormTypeEnum.java
Normal file
84
src/main/java/com/youlai/system/enums/FormTypeEnum.java
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
package com.youlai.system.enums;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import com.youlai.system.common.base.IBaseEnum;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单类型枚举
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum FormTypeEnum implements IBaseEnum<Integer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输入框
|
||||||
|
*/
|
||||||
|
INPUT(1, "输入框"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下拉框
|
||||||
|
*/
|
||||||
|
SELECT(2, "下拉框"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单选框
|
||||||
|
*/
|
||||||
|
RADIO(3, "单选框"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复选框
|
||||||
|
*/
|
||||||
|
CHECK_BOX(4, "复选框"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数字输入框
|
||||||
|
*/
|
||||||
|
INPUT_NUMBER(5, "数字输入框"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开关
|
||||||
|
*/
|
||||||
|
SWITCH(6, "开关"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文本域
|
||||||
|
*/
|
||||||
|
TEXT_AREA(7, "文本域"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期时间框
|
||||||
|
*/
|
||||||
|
DATE_TIME(8, "日期时间框"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期框
|
||||||
|
*/
|
||||||
|
DATE(9, "日期框");
|
||||||
|
|
||||||
|
|
||||||
|
// Mybatis-Plus 提供注解表示插入数据库时插入该值
|
||||||
|
@EnumValue
|
||||||
|
@JsonValue
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
// @JsonValue // 表示对枚举序列化时返回此字段
|
||||||
|
private final String label;
|
||||||
|
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public static QueryTypeEnum fromValue(Integer value) {
|
||||||
|
for (QueryTypeEnum type : QueryTypeEnum.values()) {
|
||||||
|
if (type.getValue().equals(value)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("No enum constant with value " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
84
src/main/java/com/youlai/system/enums/JavaTypeEnum.java
Normal file
84
src/main/java/com/youlai/system/enums/JavaTypeEnum.java
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
package com.youlai.system.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单类型枚举
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum JavaTypeEnum {
|
||||||
|
|
||||||
|
VARCHAR("varchar", "String", "string"),
|
||||||
|
CHAR("char", "String", "string"),
|
||||||
|
BLOB("blob", "byte[]", "Uint8Array"),
|
||||||
|
TEXT("text", "String", "string"),
|
||||||
|
JSON("json", "String", "any"),
|
||||||
|
INTEGER("int", "Integer", "number"),
|
||||||
|
TINYINT("tinyint", "Integer", "number"),
|
||||||
|
SMALLINT("smallint", "Integer", "number"),
|
||||||
|
MEDIUMINT("mediumint", "Integer", "number"),
|
||||||
|
BIGINT("bigint", "Long", "bigint"),
|
||||||
|
FLOAT("float", "Float", "number"),
|
||||||
|
DOUBLE("double", "Double", "number"),
|
||||||
|
DECIMAL("decimal", "BigDecimal", "number"),
|
||||||
|
DATE("date", "LocalDate", "Date"),
|
||||||
|
DATETIME("datetime", "LocalDateTime", "Date");
|
||||||
|
|
||||||
|
// 数据库类型
|
||||||
|
private final String dbType;
|
||||||
|
// Java类型
|
||||||
|
private final String javaType;
|
||||||
|
// TypeScript类型
|
||||||
|
private final String tsType;
|
||||||
|
|
||||||
|
// 数据库类型和Java类型的映射
|
||||||
|
private static final Map<String, JavaTypeEnum> typeMap = new HashMap<>();
|
||||||
|
|
||||||
|
// 初始化映射关系
|
||||||
|
static {
|
||||||
|
for (JavaTypeEnum javaTypeEnum : JavaTypeEnum.values()) {
|
||||||
|
typeMap.put(javaTypeEnum.getDbType(), javaTypeEnum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JavaTypeEnum(String dbType, String javaType, String tsType) {
|
||||||
|
this.dbType = dbType;
|
||||||
|
this.javaType = javaType;
|
||||||
|
this.tsType = tsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据数据库类型获取对应的Java类型
|
||||||
|
*
|
||||||
|
* @param dbType 数据库类型
|
||||||
|
* @return 对应的Java类型
|
||||||
|
*/
|
||||||
|
public static String getJavaTypeByDbType(String dbType) {
|
||||||
|
JavaTypeEnum javaTypeEnum = typeMap.get(dbType);
|
||||||
|
if (javaTypeEnum != null) {
|
||||||
|
return javaTypeEnum.getJavaType();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据Java类型获取对应的TypeScript类型
|
||||||
|
*
|
||||||
|
* @param javaType Java类型
|
||||||
|
* @return 对应的TypeScript类型
|
||||||
|
*/
|
||||||
|
public static String getTsTypeByJavaType(String javaType) {
|
||||||
|
for (JavaTypeEnum javaTypeEnum : JavaTypeEnum.values()) {
|
||||||
|
if (javaTypeEnum.getJavaType().equals(javaType)) {
|
||||||
|
return javaTypeEnum.getTsType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
73
src/main/java/com/youlai/system/enums/QueryTypeEnum.java
Normal file
73
src/main/java/com/youlai/system/enums/QueryTypeEnum.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package com.youlai.system.enums;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import com.youlai.system.common.base.IBaseEnum;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询类型枚举
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum QueryTypeEnum implements IBaseEnum<Integer> {
|
||||||
|
|
||||||
|
/** 等于 */
|
||||||
|
EQ(1, "="),
|
||||||
|
|
||||||
|
/** 模糊匹配 */
|
||||||
|
LIKE(2, "LIKE '%s%'"),
|
||||||
|
|
||||||
|
/** 包含 */
|
||||||
|
IN(3, "IN"),
|
||||||
|
|
||||||
|
/** 范围 */
|
||||||
|
BETWEEN(4, "BETWEEN"),
|
||||||
|
|
||||||
|
/** 大于 */
|
||||||
|
GT(5, ">"),
|
||||||
|
|
||||||
|
/** 大于等于 */
|
||||||
|
GE(6, ">="),
|
||||||
|
|
||||||
|
/** 小于 */
|
||||||
|
LT(7, "<"),
|
||||||
|
|
||||||
|
/** 小于等于 */
|
||||||
|
LE(8, "<="),
|
||||||
|
|
||||||
|
/** 不等于 */
|
||||||
|
NE(9, "!="),
|
||||||
|
|
||||||
|
/** 左模糊匹配 */
|
||||||
|
LIKE_LEFT(10, "LIKE '%s'"),
|
||||||
|
|
||||||
|
/** 右模糊匹配 */
|
||||||
|
LIKE_RIGHT(11, "LIKE 's%'");
|
||||||
|
|
||||||
|
|
||||||
|
// 存储在数据库中的枚举属性值
|
||||||
|
@EnumValue
|
||||||
|
@JsonValue
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
// 序列化成 JSON 时的属性值
|
||||||
|
private final String label;
|
||||||
|
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public static QueryTypeEnum fromValue(Integer value) {
|
||||||
|
for (QueryTypeEnum type : QueryTypeEnum.values()) {
|
||||||
|
if (type.getValue().equals(value)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("No enum constant with value " + value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ import cn.hutool.captcha.generator.CodeGenerator;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.youlai.system.common.constant.SecurityConstants;
|
import com.youlai.system.common.constant.SecurityConstants;
|
||||||
import com.youlai.system.common.result.ResultCode;
|
import com.youlai.system.common.result.ResultCode;
|
||||||
import com.youlai.system.common.util.ResponseUtils;
|
import com.youlai.system.util.ResponseUtils;
|
||||||
import jakarta.servlet.FilterChain;
|
import jakarta.servlet.FilterChain;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import cn.hutool.jwt.JWTUtil;
|
|||||||
import com.youlai.system.common.constant.SecurityConstants;
|
import com.youlai.system.common.constant.SecurityConstants;
|
||||||
import com.youlai.system.common.result.ResultCode;
|
import com.youlai.system.common.result.ResultCode;
|
||||||
import com.youlai.system.security.util.JwtUtils;
|
import com.youlai.system.security.util.JwtUtils;
|
||||||
import com.youlai.system.common.util.ResponseUtils;
|
import com.youlai.system.util.ResponseUtils;
|
||||||
import jakarta.servlet.FilterChain;
|
import jakarta.servlet.FilterChain;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package com.youlai.system.mapper;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.youlai.system.model.bo.ColumnMetaData;
|
||||||
|
import com.youlai.system.model.bo.TableMetaData;
|
||||||
import com.youlai.system.model.entity.SysDept;
|
import com.youlai.system.model.entity.SysDept;
|
||||||
import com.youlai.system.model.query.TablePageQuery;
|
import com.youlai.system.model.query.TablePageQuery;
|
||||||
import com.youlai.system.model.vo.TableColumnVO;
|
|
||||||
import com.youlai.system.model.vo.TablePageVO;
|
import com.youlai.system.model.vo.TablePageVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@@ -17,7 +18,8 @@ public interface DatabaseMapper extends BaseMapper<SysDept> {
|
|||||||
|
|
||||||
Page<TablePageVO> getTablePage(Page<TablePageVO> page, TablePageQuery queryParams);
|
Page<TablePageVO> getTablePage(Page<TablePageVO> page, TablePageQuery queryParams);
|
||||||
|
|
||||||
List<TableColumnVO> getTableColumns(String tableName);
|
List<ColumnMetaData> getTableColumns(String tableName);
|
||||||
|
|
||||||
|
|
||||||
|
TableMetaData getTableMetadata(String tableName);
|
||||||
}
|
}
|
||||||
|
|||||||
50
src/main/java/com/youlai/system/model/bo/ColumnMetaData.java
Normal file
50
src/main/java/com/youlai/system/model/bo/ColumnMetaData.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package com.youlai.system.model.bo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Schema(description = "数据表字段VO")
|
||||||
|
@Data
|
||||||
|
public class ColumnMetaData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段名称
|
||||||
|
*/
|
||||||
|
private String columnName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段类型
|
||||||
|
*/
|
||||||
|
private String dataType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段描述
|
||||||
|
*/
|
||||||
|
private String columnComment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段长度
|
||||||
|
*/
|
||||||
|
private Integer characterMaximumLength;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否主键(1-是 0-否)
|
||||||
|
*/
|
||||||
|
private Integer isPrimaryKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否可为空(1-是 0-否)
|
||||||
|
*/
|
||||||
|
private String isNullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符集
|
||||||
|
*/
|
||||||
|
private String characterSetName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序规则
|
||||||
|
*/
|
||||||
|
private String collationName;
|
||||||
|
|
||||||
|
}
|
||||||
45
src/main/java/com/youlai/system/model/bo/TableMetaData.java
Normal file
45
src/main/java/com/youlai/system/model/bo/TableMetaData.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package com.youlai.system.model.bo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据表元数据
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class TableMetaData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表名称
|
||||||
|
*/
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表描述
|
||||||
|
*/
|
||||||
|
private String tableComment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序规则
|
||||||
|
*/
|
||||||
|
private String tableCollation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储引擎
|
||||||
|
*/
|
||||||
|
private String engine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符集
|
||||||
|
*/
|
||||||
|
private String charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
}
|
||||||
59
src/main/java/com/youlai/system/model/entity/GenConfig.java
Normal file
59
src/main/java/com/youlai/system/model/entity/GenConfig.java
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package com.youlai.system.model.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
|
import com.youlai.system.common.base.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
@TableLogic
|
||||||
|
private Integer isDeleted;
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
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.system.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 String columnLength;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段名称
|
||||||
|
*/
|
||||||
|
private String fieldName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段类型
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,59 +1,85 @@
|
|||||||
package com.youlai.system.model.form;
|
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成配置表单
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
@Schema(description = "代码生成配置表单")
|
@Schema(description = "代码生成配置表单")
|
||||||
@Data
|
@Data
|
||||||
public class GeneratorConfigForm {
|
public class GenConfigForm {
|
||||||
|
|
||||||
@Schema(description = "表名")
|
@Schema(description = "主键",example = "1")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "表名",example = "sys_user")
|
||||||
private String tableName;
|
private String tableName;
|
||||||
|
|
||||||
@Schema(description = "实体名")
|
@Schema(description = "业务名",example = "用户")
|
||||||
private String entityName;
|
private String businessName;
|
||||||
|
|
||||||
@Schema(description = "包名")
|
@Schema(description = "模块名",example = "system")
|
||||||
private String packageName;
|
|
||||||
|
|
||||||
@Schema(description = "模块名")
|
|
||||||
private String moduleName;
|
private String moduleName;
|
||||||
|
|
||||||
@Schema(description = "作者")
|
@Schema(description = "包名",example = "com.youlai.system")
|
||||||
|
private String packageName;
|
||||||
|
|
||||||
|
@Schema(description = "实体名",example = "User")
|
||||||
|
private String entityName;
|
||||||
|
|
||||||
|
@Schema(description = "作者",example = "youlaitech")
|
||||||
private String author;
|
private String author;
|
||||||
|
|
||||||
@Schema(description = "字段配置")
|
@Schema(description = "字段配置列表")
|
||||||
private List<FieldConfig> fieldConfigs;
|
private List<FieldConfig> fieldConfigs;
|
||||||
|
|
||||||
@Schema(description = "字段配置")
|
@Schema(description = "字段配置")
|
||||||
@Data
|
@Data
|
||||||
public static class FieldConfig {
|
public static class FieldConfig {
|
||||||
|
|
||||||
@Schema(description = "字段名称")
|
@Schema(description = "主键")
|
||||||
private String name;
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "列名")
|
||||||
|
private String columnName;
|
||||||
|
|
||||||
|
@Schema(description = "列类型")
|
||||||
|
private String columnType;
|
||||||
|
|
||||||
|
@Schema(description = "字段名")
|
||||||
|
private String fieldName;
|
||||||
|
|
||||||
@Schema(description = "字段类型")
|
@Schema(description = "字段类型")
|
||||||
private String type;
|
private String fieldType;
|
||||||
|
|
||||||
@Schema(description = "字段描述")
|
@Schema(description = "字段描述")
|
||||||
private String description;
|
private String fieldComment;
|
||||||
|
|
||||||
@Schema(description = "是否在列表显示")
|
@Schema(description = "是否在列表显示")
|
||||||
private Boolean showInList;
|
private Integer isShowInList;
|
||||||
|
|
||||||
@Schema(description = "是否在表单显示")
|
@Schema(description = "是否在表单显示")
|
||||||
private Boolean showInForm;
|
private Integer isShowInForm;
|
||||||
|
|
||||||
@Schema(description = "是否在查询条件显示")
|
@Schema(description = "是否在查询条件显示")
|
||||||
private Boolean showInQuery;
|
private Integer isShowInQuery;
|
||||||
|
|
||||||
|
@Schema(description = "是否必填")
|
||||||
|
private Integer isRequired;
|
||||||
|
|
||||||
@Schema(description = "表单类型")
|
@Schema(description = "表单类型")
|
||||||
private String formType;
|
private FormTypeEnum formType;
|
||||||
|
|
||||||
@Schema(description = "查询方式")
|
@Schema(description = "查询类型")
|
||||||
private String queryMethod;
|
private QueryTypeEnum queryType;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.youlai.system.model.vo;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Schema(description = "数据表字段VO")
|
|
||||||
@Data
|
|
||||||
public class TableColumnVO {
|
|
||||||
|
|
||||||
@Schema(description = "字段名称", example = "id")
|
|
||||||
private String columnName;
|
|
||||||
|
|
||||||
@Schema(description = "字段类型", example = "bigint")
|
|
||||||
private String dataType;
|
|
||||||
|
|
||||||
@Schema(description = "字段描述", example = "主键")
|
|
||||||
private String columnComment;
|
|
||||||
|
|
||||||
@Schema(description = "字段长度", example = "20")
|
|
||||||
private Integer characterMaximumLength;
|
|
||||||
|
|
||||||
@Schema(description = "是否主键(1-是 0-否)", example = "1")
|
|
||||||
private Integer isPrimaryKey;
|
|
||||||
|
|
||||||
@Schema(description = "是否可为空(1-是 0-否)", example = "1")
|
|
||||||
private String isNullable;
|
|
||||||
|
|
||||||
@Schema(description = "字符集", example = "utf8mb4")
|
|
||||||
private String characterSetName;
|
|
||||||
|
|
||||||
@Schema(description = "字符集排序规则", example = "utf8mb4_general_ci")
|
|
||||||
private String collationName;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,23 +4,23 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
@Schema(description = "数据表分页VO")
|
@Schema(description = "表视图对象")
|
||||||
@Data
|
@Data
|
||||||
public class TablePageVO {
|
public class TablePageVO {
|
||||||
|
|
||||||
@Schema(description = "数据表名称", example = "sys_user")
|
@Schema(description = "表名称", example = "sys_user")
|
||||||
private String tableName;
|
private String tableName;
|
||||||
|
|
||||||
@Schema(description = "数据表注释",example = "用户表")
|
@Schema(description = "表描述",example = "用户表")
|
||||||
private String tableComment;
|
private String tableComment;
|
||||||
|
|
||||||
@Schema(description = "数据表排序规则",example = "用户表")
|
@Schema(description = "表排序规则",example = "utf8mb4_general_ci")
|
||||||
private String tableCollation;
|
private String tableCollation;
|
||||||
|
|
||||||
@Schema(description = "存储引擎",example = "InnoDB")
|
@Schema(description = "存储引擎",example = "InnoDB")
|
||||||
private String engine;
|
private String engine;
|
||||||
|
|
||||||
@Schema(description = "字符集",example = "utf8mb4_general_ci")
|
@Schema(description = "字符集",example = "utf8mb4")
|
||||||
private String charset;
|
private String charset;
|
||||||
|
|
||||||
@Schema(description = "创建时间",example = "2023-08-08 08:08:08")
|
@Schema(description = "创建时间",example = "2023-08-08 08:08:08")
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ package com.youlai.system.plugin.syslog.aspect;
|
|||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.date.TimeInterval;
|
import cn.hutool.core.date.TimeInterval;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.http.useragent.Browser;
|
|
||||||
import cn.hutool.http.useragent.OS;
|
|
||||||
import cn.hutool.http.useragent.UserAgent;
|
import cn.hutool.http.useragent.UserAgent;
|
||||||
import cn.hutool.http.useragent.UserAgentUtil;
|
import cn.hutool.http.useragent.UserAgentUtil;
|
||||||
import com.youlai.system.common.constant.SecurityConstants;
|
import com.youlai.system.common.constant.SecurityConstants;
|
||||||
import com.youlai.system.common.util.IPUtils;
|
import com.youlai.system.util.IPUtils;
|
||||||
import com.youlai.system.model.entity.SysLog;
|
import com.youlai.system.model.entity.SysLog;
|
||||||
import com.youlai.system.plugin.syslog.annotation.LogAnnotation;
|
import com.youlai.system.plugin.syslog.annotation.LogAnnotation;
|
||||||
import com.youlai.system.security.util.SecurityUtils;
|
import com.youlai.system.security.util.SecurityUtils;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.youlai.system.security.exception;
|
package com.youlai.system.security.exception;
|
||||||
|
|
||||||
import com.youlai.system.common.result.ResultCode;
|
import com.youlai.system.common.result.ResultCode;
|
||||||
import com.youlai.system.common.util.ResponseUtils;
|
import com.youlai.system.util.ResponseUtils;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.youlai.system.security.exception;
|
package com.youlai.system.security.exception;
|
||||||
|
|
||||||
import com.youlai.system.common.result.ResultCode;
|
import com.youlai.system.common.result.ResultCode;
|
||||||
import com.youlai.system.common.util.ResponseUtils;
|
import com.youlai.system.util.ResponseUtils;
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
import org.springframework.security.core.AuthenticationException;
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.youlai.system.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.youlai.system.model.entity.GenConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成配置接口
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
public interface GenConfigService extends IService<GenConfig> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.youlai.system.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.youlai.system.model.entity.GenConfig;
|
||||||
|
import com.youlai.system.model.entity.GenFieldConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成配置接口
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
public interface GenFieldConfigService extends IService<GenFieldConfig> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,22 +1,21 @@
|
|||||||
package com.youlai.system.service;
|
package com.youlai.system.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.youlai.system.model.form.GenConfigForm;
|
||||||
import com.youlai.system.model.query.TablePageQuery;
|
import com.youlai.system.model.query.TablePageQuery;
|
||||||
import com.youlai.system.model.vo.TableColumnVO;
|
import com.youlai.system.model.vo.GeneratorPreviewVO;
|
||||||
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
|
||||||
import com.youlai.system.model.vo.TablePageVO;
|
import com.youlai.system.model.vo.TablePageVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库服务接口
|
* 代码生成配置接口
|
||||||
*
|
*
|
||||||
* @author haoxr
|
* @author Ray
|
||||||
* @since 2.11.0
|
* @since 2.10.0
|
||||||
*/
|
*/
|
||||||
public interface GeneratorService {
|
public interface GeneratorService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取数据表分页列表
|
* 获取数据表分页列表
|
||||||
*
|
*
|
||||||
@@ -25,19 +24,29 @@ public interface GeneratorService {
|
|||||||
*/
|
*/
|
||||||
Page<TablePageVO> getTablePage(TablePageQuery queryParams);
|
Page<TablePageVO> getTablePage(TablePageQuery queryParams);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取数据表字段列表
|
|
||||||
*
|
|
||||||
* @param tableName 表名
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
List<TableColumnVO> getTableColumns(String tableName);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取预览生成代码
|
* 获取预览生成代码
|
||||||
*
|
*
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<TableGeneratePreviewVO> getTablePreviewData(String tableName);
|
List<GeneratorPreviewVO> getTablePreviewData(String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取代码生成配置
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
GenConfigForm getGenConfigFormData(String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存代码生成配置
|
||||||
|
*
|
||||||
|
* @param formData 表单数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void saveGenConfig(GenConfigForm formData);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.youlai.system.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.youlai.system.mapper.GenConfigMapper;
|
||||||
|
import com.youlai.system.model.entity.GenConfig;
|
||||||
|
import com.youlai.system.service.GenConfigService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库服务实现类
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GenConfigServiceImpl extends ServiceImpl<GenConfigMapper, GenConfig> implements GenConfigService {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.youlai.system.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.youlai.system.mapper.GenFieldConfigMapper;
|
||||||
|
import com.youlai.system.model.entity.GenFieldConfig;
|
||||||
|
import com.youlai.system.service.GenFieldConfigService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成字段配置服务实现类
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GenFieldConfigServiceImpl extends ServiceImpl<GenFieldConfigMapper, GenFieldConfig> implements GenFieldConfigService {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,20 +1,37 @@
|
|||||||
package com.youlai.system.service.impl;
|
package com.youlai.system.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.template.Template;
|
import cn.hutool.extra.template.Template;
|
||||||
import cn.hutool.extra.template.TemplateConfig;
|
import cn.hutool.extra.template.TemplateConfig;
|
||||||
import cn.hutool.extra.template.TemplateEngine;
|
import cn.hutool.extra.template.TemplateEngine;
|
||||||
import cn.hutool.extra.template.TemplateUtil;
|
import cn.hutool.extra.template.TemplateUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.youlai.system.SystemApplication;
|
||||||
|
import com.youlai.system.config.property.GeneratorProperties;
|
||||||
|
import com.youlai.system.converter.GenConfigConverter;
|
||||||
|
import com.youlai.system.enums.FormTypeEnum;
|
||||||
|
import com.youlai.system.enums.JavaTypeEnum;
|
||||||
|
import com.youlai.system.enums.QueryTypeEnum;
|
||||||
|
import com.youlai.system.exception.BusinessException;
|
||||||
import com.youlai.system.mapper.DatabaseMapper;
|
import com.youlai.system.mapper.DatabaseMapper;
|
||||||
|
import com.youlai.system.model.bo.ColumnMetaData;
|
||||||
|
import com.youlai.system.model.bo.TableMetaData;
|
||||||
|
import com.youlai.system.model.entity.GenConfig;
|
||||||
|
import com.youlai.system.model.entity.GenFieldConfig;
|
||||||
|
import com.youlai.system.model.form.GenConfigForm;
|
||||||
import com.youlai.system.model.query.TablePageQuery;
|
import com.youlai.system.model.query.TablePageQuery;
|
||||||
import com.youlai.system.model.vo.TableColumnVO;
|
import com.youlai.system.model.vo.GeneratorPreviewVO;
|
||||||
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
|
||||||
import com.youlai.system.model.vo.TablePageVO;
|
import com.youlai.system.model.vo.TablePageVO;
|
||||||
import com.youlai.system.service.GeneratorService;
|
import com.youlai.system.service.GeneratorService;
|
||||||
|
import com.youlai.system.service.GenConfigService;
|
||||||
|
import com.youlai.system.service.GenFieldConfigService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import cn.hutool.extra.template.TemplateConfig.ResourceMode;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -23,13 +40,17 @@ import java.util.*;
|
|||||||
* 数据库服务实现类
|
* 数据库服务实现类
|
||||||
*
|
*
|
||||||
* @author Ray
|
* @author Ray
|
||||||
* @since 2.11.0
|
* @since 2.10.0
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class GeneratorServiceImpl implements GeneratorService {
|
public class GeneratorServiceImpl implements GeneratorService {
|
||||||
|
|
||||||
private final DatabaseMapper databaseMapper;
|
private final DatabaseMapper databaseMapper;
|
||||||
|
private final GeneratorProperties generatorProperties;
|
||||||
|
private final GenConfigService genConfigService;
|
||||||
|
private final GenFieldConfigService genFieldConfigService;
|
||||||
|
private final GenConfigConverter genConfigConverter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据表分页列表
|
* 数据表分页列表
|
||||||
@@ -43,15 +64,114 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取数据表字段列表
|
* 获取代码生成配置
|
||||||
*
|
*
|
||||||
* @param tableName 表名
|
* @param tableName 表名 eg: sys_user
|
||||||
* @return 字段列表
|
* @return 代码生成配置
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<TableColumnVO> getTableColumns(String tableName) {
|
public GenConfigForm getGenConfigFormData(String tableName) {
|
||||||
return databaseMapper.getTableColumns(tableName);
|
// 查询表生成配置
|
||||||
|
GenConfig genConfig = genConfigService.getOne(
|
||||||
|
new LambdaQueryWrapper<>(GenConfig.class)
|
||||||
|
.eq(GenConfig::getTableName, tableName)
|
||||||
|
.last("LIMIT 1")
|
||||||
|
);
|
||||||
|
// 如果没有代码生成配置,则根据表的元数据生成默认配置
|
||||||
|
if (genConfig == null) {
|
||||||
|
TableMetaData tableMetadata = databaseMapper.getTableMetadata(tableName);
|
||||||
|
Assert.isTrue(tableMetadata != null, "未找到表元数据");
|
||||||
|
|
||||||
|
genConfig = new GenConfig();
|
||||||
|
genConfig.setTableName(tableName);
|
||||||
|
|
||||||
|
String tableComment = tableMetadata.getTableComment();
|
||||||
|
if (StrUtil.isNotBlank(tableComment)) {
|
||||||
|
genConfig.setBusinessName(tableComment.replace("表", ""));
|
||||||
}
|
}
|
||||||
|
// 实体类名 = 表名去掉前缀后转驼峰,前缀默认为下划线分割的第一个元素
|
||||||
|
String entityName = StrUtil.toCamelCase(StrUtil.removePrefix(tableName, tableName.split("_")[0]));
|
||||||
|
genConfig.setEntityName(entityName);
|
||||||
|
|
||||||
|
String packageName = SystemApplication.class.getPackageName();
|
||||||
|
genConfig.setPackageName(packageName);
|
||||||
|
|
||||||
|
genConfig.setAuthor(generatorProperties.getDefaultConfig().getAuthor());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据表的列 + 已经存在的字段生成配置 得到 组合后的字段生成配置
|
||||||
|
List<GenFieldConfig> genFieldConfigs = new ArrayList<>();
|
||||||
|
|
||||||
|
// 获取表的列
|
||||||
|
List<ColumnMetaData> tableColumns = databaseMapper.getTableColumns(tableName);
|
||||||
|
if (CollectionUtil.isNotEmpty(tableColumns)) {
|
||||||
|
// 查询字段生成配置
|
||||||
|
List<GenFieldConfig> fieldConfigList = genFieldConfigService.list(
|
||||||
|
new LambdaQueryWrapper<>(GenFieldConfig.class)
|
||||||
|
.eq(GenFieldConfig::getConfigId, genConfig.getId())
|
||||||
|
);
|
||||||
|
for (ColumnMetaData tableColumn : tableColumns) {
|
||||||
|
// 根据列名获取字段生成配置
|
||||||
|
String columnName = tableColumn.getColumnName();
|
||||||
|
GenFieldConfig genFieldConfig = fieldConfigList.stream()
|
||||||
|
.filter(item -> StrUtil.equals(item.getColumnName(), columnName))
|
||||||
|
.findFirst()
|
||||||
|
.orElseGet(() -> createDefaultFieldConfig(tableColumn));
|
||||||
|
|
||||||
|
// 根据列类型设置字段类型
|
||||||
|
String fieldType = genFieldConfig.getFieldType();
|
||||||
|
if (StrUtil.isBlank(fieldType)) {
|
||||||
|
String javaType = JavaTypeEnum.getJavaTypeByDbType(genFieldConfig.getColumnType());
|
||||||
|
genFieldConfig.setFieldType(javaType);
|
||||||
|
}
|
||||||
|
genFieldConfigs.add(genFieldConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GenConfigForm configFormData = genConfigConverter.toGenConfigForm(genConfig, genFieldConfigs);
|
||||||
|
return configFormData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建默认字段配置
|
||||||
|
*
|
||||||
|
* @param tableColumn 表字段元数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private GenFieldConfig createDefaultFieldConfig(ColumnMetaData tableColumn) {
|
||||||
|
GenFieldConfig fieldConfig = new GenFieldConfig();
|
||||||
|
fieldConfig.setColumnName(tableColumn.getColumnName());
|
||||||
|
fieldConfig.setColumnType(tableColumn.getDataType());
|
||||||
|
fieldConfig.setFieldComment(tableColumn.getColumnComment());
|
||||||
|
fieldConfig.setFieldName(StrUtil.toCamelCase(tableColumn.getColumnName()));
|
||||||
|
fieldConfig.setIsRequired("YES".equals(tableColumn.getIsNullable()) ? 1 : 0);
|
||||||
|
fieldConfig.setFormType(FormTypeEnum.INPUT);
|
||||||
|
fieldConfig.setQueryType(QueryTypeEnum.EQ);
|
||||||
|
return fieldConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存代码生成配置
|
||||||
|
*
|
||||||
|
* @param formData 代码生成配置表单
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void saveGenConfig(GenConfigForm formData) {
|
||||||
|
GenConfig genConfig = genConfigConverter.toGenConfig(formData);
|
||||||
|
genConfigService.saveOrUpdate(genConfig);
|
||||||
|
|
||||||
|
List<GenFieldConfig> genFieldConfigs = genConfigConverter.toGenFieldConfig(formData.getFieldConfigs());
|
||||||
|
|
||||||
|
if (CollectionUtil.isEmpty(genFieldConfigs)) {
|
||||||
|
throw new BusinessException("字段配置不能为空");
|
||||||
|
}
|
||||||
|
genFieldConfigs.forEach(genFieldConfig -> {
|
||||||
|
genFieldConfig.setConfigId(genConfig.getId());
|
||||||
|
});
|
||||||
|
genFieldConfigService.saveOrUpdateBatch(genFieldConfigs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取预览生成代码
|
* 获取预览生成代码
|
||||||
@@ -60,49 +180,151 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||||||
* @return 预览数据
|
* @return 预览数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<TableGeneratePreviewVO> getTablePreviewData(String tableName) {
|
public List<GeneratorPreviewVO> getTablePreviewData(String tableName) {
|
||||||
|
|
||||||
List<TableGeneratePreviewVO> list = new ArrayList<>();
|
List<GeneratorPreviewVO> list = new ArrayList<>();
|
||||||
|
|
||||||
TemplateConfig templateConfig = new TemplateConfig("templates" , ResourceMode.CLASSPATH);
|
GenConfig genConfig = genConfigService.getOne(new LambdaQueryWrapper<GenConfig>()
|
||||||
TemplateEngine templateEngine = TemplateUtil.createEngine(templateConfig);
|
.eq(GenConfig::getTableName, tableName)
|
||||||
|
);
|
||||||
|
Assert.isTrue(genConfig != null, "未找到表生成配置");
|
||||||
|
|
||||||
|
List<GenFieldConfig> fieldConfigs = genFieldConfigService.list(new LambdaQueryWrapper<GenFieldConfig>()
|
||||||
|
.eq(GenFieldConfig::getConfigId, genConfig.getId())
|
||||||
|
);
|
||||||
|
Assert.isTrue(CollectionUtil.isNotEmpty(fieldConfigs), "未找到字段生成配置");
|
||||||
|
|
||||||
|
// 遍历模板配置
|
||||||
|
Map<String, GeneratorProperties.TemplateConfig> templateConfigs = generatorProperties.getTemplateConfigs();
|
||||||
|
for (Map.Entry<String, GeneratorProperties.TemplateConfig> templateConfigEntry : templateConfigs.entrySet()) {
|
||||||
|
GeneratorPreviewVO previewVO = new GeneratorPreviewVO();
|
||||||
|
|
||||||
|
GeneratorProperties.TemplateConfig templateConfig = templateConfigEntry.getValue();
|
||||||
|
|
||||||
|
/* 1. 生成文件名 UserController */
|
||||||
|
// User Role Menu Dept
|
||||||
|
String entityName = genConfig.getEntityName();
|
||||||
|
// Controller Service Mapper Entity
|
||||||
|
String templateName = templateConfigEntry.getKey();
|
||||||
|
// .java .ts .vue
|
||||||
|
String extension = templateConfig.getExtension();
|
||||||
|
|
||||||
|
// 文件名 UserController.java
|
||||||
|
String fileName = getFileName(entityName, templateName, extension);
|
||||||
|
previewVO.setFileName(fileName);
|
||||||
|
|
||||||
|
|
||||||
Map<String, Object> bindingMap = new HashMap<>();
|
/* 2. 生成文件路径 */
|
||||||
bindingMap.put("tableName", "sys_user");
|
// com.youlai.system
|
||||||
bindingMap.put("author", "Ray");
|
String packageName = genConfig.getPackageName();
|
||||||
bindingMap.put("date", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm"));
|
// controller
|
||||||
bindingMap.put("entityName", "User" );
|
String subPackageName = templateConfig.getPackageName();
|
||||||
bindingMap.put("lowerFirstEntityName", "user");
|
// 文件路径 com.youlai.system.controller
|
||||||
bindingMap.put("tableComment", "用户");
|
String filePath = getFilePath(templateName, packageName, subPackageName,entityName);
|
||||||
|
previewVO.setPath(filePath);
|
||||||
|
|
||||||
// 包路径
|
/* 3. 生成文件内容 */
|
||||||
bindingMap.put("package", "com.youlai.system");
|
|
||||||
|
|
||||||
Template template = templateEngine.getTemplate("generator" + File.separator + "controller.java.vm");
|
// 生成文件内容
|
||||||
String content = template.render(bindingMap);
|
String content = getCodeContent(templateConfig, genConfig, fieldConfigs);
|
||||||
TableGeneratePreviewVO controller = new TableGeneratePreviewVO();
|
previewVO.setContent(content);
|
||||||
controller.setPath("youlai-boot/controller");
|
|
||||||
controller.setContent(content);
|
|
||||||
controller.setFileName("UserController.java");
|
|
||||||
|
|
||||||
list.add(controller);
|
|
||||||
|
|
||||||
TableGeneratePreviewVO vo = new TableGeneratePreviewVO();
|
|
||||||
vo.setPath("youlai-boot/model/vo");
|
|
||||||
vo.setContent(content);
|
|
||||||
vo.setFileName("UserVO.java");
|
|
||||||
|
|
||||||
list.add(vo);
|
|
||||||
|
|
||||||
|
list.add(previewVO);
|
||||||
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String generatePath(){
|
private String getFileName(String entityName, String templateName, String extension) {
|
||||||
|
if ("Entity".equals(templateName)) {
|
||||||
|
return entityName + extension;
|
||||||
|
}
|
||||||
|
if ("MapperXml".equals(templateName)) {
|
||||||
|
return entityName + "Mapper" + extension;
|
||||||
|
}
|
||||||
|
if ("API".equals(templateName)) {
|
||||||
|
return StrUtil.toSymbolCase(entityName, '-') + extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("VIEW".equals(templateName)) {
|
||||||
|
return "index.vue";
|
||||||
|
}
|
||||||
|
|
||||||
|
return entityName + templateName + extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFilePath(String templateName, String packageName, String subPackageName,String entityName) {
|
||||||
|
String path;
|
||||||
|
if ("MapperXml".equals(templateName)) {
|
||||||
|
path = (generatorProperties.getBackendAppName()
|
||||||
|
+ File.separator
|
||||||
|
+ "src" + File.separator + "main" + File.separator + "resources"
|
||||||
|
+ File.separator + subPackageName
|
||||||
|
);
|
||||||
|
} else if ("API".equals(templateName) ) {
|
||||||
|
path = (generatorProperties.getFrontendAppName()
|
||||||
|
+ File.separator
|
||||||
|
+ "src" + File.separator + subPackageName
|
||||||
|
);
|
||||||
|
} else if("VIEW".equals(templateName)){
|
||||||
|
path = (generatorProperties.getFrontendAppName()
|
||||||
|
+ File.separator
|
||||||
|
+ "src" + File.separator + subPackageName
|
||||||
|
+ File.separator
|
||||||
|
+ StrUtil.toSymbolCase(entityName, '-')
|
||||||
|
);
|
||||||
|
}else {
|
||||||
|
path = (generatorProperties.getBackendAppName()
|
||||||
|
+ File.separator
|
||||||
|
+ "src" + File.separator + "main" + File.separator + "java"
|
||||||
|
+ File.separator + packageName + File.separator + subPackageName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// subPackageName = model.entity => model/entity
|
||||||
|
path = path.replace(".", File.separator);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成代码内容
|
||||||
|
*
|
||||||
|
* @param templateConfig 模板配置
|
||||||
|
* @param genConfig 生成配置
|
||||||
|
* @param fieldConfigs 字段配置
|
||||||
|
* @return 代码内容
|
||||||
|
*/
|
||||||
|
private String getCodeContent(GeneratorProperties.TemplateConfig templateConfig, GenConfig genConfig, List<GenFieldConfig> fieldConfigs) {
|
||||||
|
|
||||||
|
Map<String, Object> bindMap = new HashMap<>();
|
||||||
|
|
||||||
|
String entityName = genConfig.getEntityName();
|
||||||
|
|
||||||
|
bindMap.put("package", genConfig.getPackageName());
|
||||||
|
bindMap.put("subPackage", templateConfig.getPackageName());
|
||||||
|
bindMap.put("date", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm"));
|
||||||
|
bindMap.put("entityName", entityName);
|
||||||
|
bindMap.put("tableName", genConfig.getTableName());
|
||||||
|
bindMap.put("author", genConfig.getAuthor());
|
||||||
|
bindMap.put("lowerFirstEntityName", StrUtil.lowerFirst(entityName));
|
||||||
|
bindMap.put("businessName", genConfig.getBusinessName());
|
||||||
|
bindMap.put("fieldConfigs", fieldConfigs);
|
||||||
|
|
||||||
|
for (GenFieldConfig fieldConfig : fieldConfigs) {
|
||||||
|
bindMap.put("hasLocalDateTime", "LocalDateTime".equals(fieldConfig.getFieldType()));
|
||||||
|
bindMap.put("hasBigDecimal", "BigDecimal".equals(fieldConfig.getFieldType()));
|
||||||
|
bindMap.put("hasRequiredField", ObjectUtil.equals(fieldConfig.getIsRequired(), 1));
|
||||||
|
fieldConfig.setTsType(JavaTypeEnum.getTsTypeByJavaType(fieldConfig.getFieldType()));
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateEngine templateEngine = TemplateUtil.createEngine(new TemplateConfig("templates", TemplateConfig.ResourceMode.CLASSPATH));
|
||||||
|
Template template = templateEngine.getTemplate(templateConfig.getTemplatePath());
|
||||||
|
String content = template.render(bindMap);
|
||||||
|
|
||||||
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.youlai.system.service.impl;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.youlai.system.common.util.DateUtils;
|
import com.youlai.system.util.DateUtils;
|
||||||
import com.youlai.system.model.bo.VisitCount;
|
import com.youlai.system.model.bo.VisitCount;
|
||||||
import com.youlai.system.model.entity.SysLog;
|
import com.youlai.system.model.entity.SysLog;
|
||||||
import com.youlai.system.model.query.LogPageQuery;
|
import com.youlai.system.model.query.LogPageQuery;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.youlai.system.common.constant.SystemConstants;
|
import com.youlai.system.common.constant.SystemConstants;
|
||||||
import com.youlai.system.common.util.DateUtils;
|
import com.youlai.system.util.DateUtils;
|
||||||
import com.youlai.system.converter.UserConverter;
|
import com.youlai.system.converter.UserConverter;
|
||||||
import com.youlai.system.security.util.SecurityUtils;
|
import com.youlai.system.security.util.SecurityUtils;
|
||||||
import com.youlai.system.mapper.SysUserMapper;
|
import com.youlai.system.mapper.SysUserMapper;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
package com.youlai.system.common.util;
|
package com.youlai.system.util;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.youlai.system.common.util;
|
package com.youlai.system.util;
|
||||||
|
|
||||||
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.EasyExcel;
|
||||||
import com.youlai.system.plugin.easyexcel.MyAnalysisEventListener;
|
import com.youlai.system.plugin.easyexcel.MyAnalysisEventListener;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.youlai.system.common.util;
|
package com.youlai.system.util;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.youlai.system.common.util;
|
package com.youlai.system.util;
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.youlai.system.common.result.Result;
|
import com.youlai.system.common.result.Result;
|
||||||
@@ -1,9 +1,50 @@
|
|||||||
### 代码生成器配置
|
# 代码生成器配置
|
||||||
generator:
|
generator:
|
||||||
|
defaultConfig:
|
||||||
|
author: youlaitech
|
||||||
|
backendAppName: youlai-boot
|
||||||
|
frontendAppName: vue3-element-admin
|
||||||
## 模板配置
|
## 模板配置
|
||||||
templateConfigs:
|
templateConfigs:
|
||||||
Controller:
|
Controller:
|
||||||
## 模板路径
|
templatePath: generator/controller.java.vm
|
||||||
templatePath: templates/generator/controller.java.vm
|
|
||||||
## 包名
|
|
||||||
packageName: controller
|
packageName: controller
|
||||||
|
Service:
|
||||||
|
templatePath: generator/service.java.vm
|
||||||
|
packageName: service
|
||||||
|
ServiceImpl:
|
||||||
|
templatePath: generator/serviceImpl.java.vm
|
||||||
|
packageName: service.impl
|
||||||
|
Mapper:
|
||||||
|
templatePath: generator/mapper.java.vm
|
||||||
|
packageName: mapper
|
||||||
|
MapperXml:
|
||||||
|
templatePath: generator/mapper.xml.vm
|
||||||
|
packageName: mapper
|
||||||
|
extension: .xml
|
||||||
|
Converter:
|
||||||
|
templatePath: generator/converter.java.vm
|
||||||
|
packageName: converter
|
||||||
|
Query:
|
||||||
|
templatePath: generator/query.java.vm
|
||||||
|
packageName: model.query
|
||||||
|
Form:
|
||||||
|
templatePath: generator/form.java.vm
|
||||||
|
packageName: model.form
|
||||||
|
VO:
|
||||||
|
templatePath: generator/vo.java.vm
|
||||||
|
packageName: model.vo
|
||||||
|
Entity:
|
||||||
|
templatePath: generator/entity.java.vm
|
||||||
|
packageName: model.entity
|
||||||
|
API:
|
||||||
|
templatePath: generator/api.ts.vm
|
||||||
|
packageName: api
|
||||||
|
extension: .ts
|
||||||
|
VIEW:
|
||||||
|
templatePath: generator/index.vue.vm
|
||||||
|
packageName: views
|
||||||
|
extension: .vue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,21 @@
|
|||||||
CREATE_TIME DESC
|
CREATE_TIME DESC
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getTableColumns" resultType="com.youlai.system.model.vo.TableColumnVO">
|
<select id="getTableMetadata" resultType="com.youlai.system.model.bo.TableMetaData">
|
||||||
|
SELECT
|
||||||
|
TABLE_NAME ,
|
||||||
|
TABLE_COMMENT ,
|
||||||
|
TABLE_COLLATION,
|
||||||
|
ENGINE,
|
||||||
|
CREATE_TIME
|
||||||
|
FROM
|
||||||
|
information_schema.tables
|
||||||
|
WHERE
|
||||||
|
TABLE_SCHEMA = (SELECT DATABASE())
|
||||||
|
AND TABLE_NAME = #{tableName}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getTableColumns" resultType="com.youlai.system.model.bo.ColumnMetaData">
|
||||||
SELECT
|
SELECT
|
||||||
COLUMN_NAME,
|
COLUMN_NAME,
|
||||||
DATA_TYPE,
|
DATA_TYPE,
|
||||||
@@ -40,4 +54,6 @@
|
|||||||
TABLE_SCHEMA = (SELECT DATABASE())
|
TABLE_SCHEMA = (SELECT DATABASE())
|
||||||
AND TABLE_NAME = #{tableName}
|
AND TABLE_NAME = #{tableName}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
7
src/main/resources/mapper/GenFieldConfigMapper.xml
Normal file
7
src/main/resources/mapper/GenFieldConfigMapper.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.youlai.system.mapper.GenFieldConfigMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
93
src/main/resources/templates/generator/api.ts.vm
Normal file
93
src/main/resources/templates/generator/api.ts.vm
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import request from "@/utils/request";
|
||||||
|
|
||||||
|
const ${entityName.toUpperCase()}_BASE_URL = "/api/v1/${entityName.toLowerCase()}s";
|
||||||
|
|
||||||
|
class ${entityName}API {
|
||||||
|
/** 获取${businessName}分页数据 */
|
||||||
|
static getPage(queryParams?: ${entityName}PageQuery) {
|
||||||
|
return request<any, PageResult<${entityName}PageVO[]>>({
|
||||||
|
url: `${${entityName.toUpperCase()}_BASE_URL}/page`,
|
||||||
|
method: "get",
|
||||||
|
params: queryParams,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取${businessName}表单数据
|
||||||
|
*
|
||||||
|
* @param id ${entityName}ID
|
||||||
|
* @returns ${entityName}表单数据
|
||||||
|
*/
|
||||||
|
static getFormData(id: number) {
|
||||||
|
return request<any, ${entityName}Form>({
|
||||||
|
url: `${${entityName.toUpperCase()}_BASE_URL}/${id}/form`,
|
||||||
|
method: "get",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 添加${businessName}*/
|
||||||
|
static add(data: ${entityName}Form) {
|
||||||
|
return request({
|
||||||
|
url: `${${entityName.toUpperCase()}_BASE_URL}`,
|
||||||
|
method: "post",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新${businessName}
|
||||||
|
*
|
||||||
|
* @param id ${entityName}ID
|
||||||
|
* @param data ${entityName}表单数据
|
||||||
|
*/
|
||||||
|
static update(id: number, data: ${entityName}Form) {
|
||||||
|
return request({
|
||||||
|
url: `${${entityName.toUpperCase()}_BASE_URL}/${id}`,
|
||||||
|
method: "put",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除${businessName},多个以英文逗号(,)分割
|
||||||
|
*
|
||||||
|
* @param ids ${businessName}ID字符串,多个以英文逗号(,)分割
|
||||||
|
*/
|
||||||
|
static deleteByIds(ids: string) {
|
||||||
|
return request({
|
||||||
|
url: `${${entityName.toUpperCase()}_BASE_URL}/${ids}`,
|
||||||
|
method: "delete",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ${entityName}API;
|
||||||
|
|
||||||
|
/** $${businessName}分页查询参数 */
|
||||||
|
export interface ${entityName}PageQuery extends PageQuery {
|
||||||
|
/** 搜索关键字 */
|
||||||
|
keywords?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ${businessName}表单对象 */
|
||||||
|
export interface ${entityName}Form {
|
||||||
|
#foreach($fieldConfig in $fieldConfigs)
|
||||||
|
#if($fieldConfig.isShowInForm)
|
||||||
|
#if("$!fieldConfig.fieldComment" != "")
|
||||||
|
/** ${fieldConfig.fieldComment} */
|
||||||
|
#end
|
||||||
|
${fieldConfig.fieldName}?: ${fieldConfig.tsType};
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ${businessName}分页对象 */
|
||||||
|
export interface ${entityName}PageVO {
|
||||||
|
#foreach($fieldConfig in $fieldConfigs)
|
||||||
|
#if($fieldConfig.isShowInList)
|
||||||
|
#if("$!fieldConfig.fieldComment" != "")
|
||||||
|
/** ${fieldConfig.fieldComment} */
|
||||||
|
#end
|
||||||
|
${fieldConfig.fieldName}?: ${fieldConfig.tsType};
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
@@ -17,12 +17,12 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment} 前端控制器
|
* $!{businessName}前端控制层
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
*/
|
*/
|
||||||
@Tag(name = "${tableComment}接口")
|
@Tag(name = "${businessName}接口")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/${lowerFirstEntityName}s")
|
@RequestMapping("/api/v1/${lowerFirstEntityName}s")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -30,41 +30,41 @@ public class ${entityName}Controller {
|
|||||||
|
|
||||||
private final ${entityName}Serivie ${lowerFirstEntityName}Service;
|
private final ${entityName}Serivie ${lowerFirstEntityName}Service;
|
||||||
|
|
||||||
@Operation(summary = "$!{tableComment}分页列表")
|
@Operation(summary = "$!{businessName}分页列表")
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
public PageResult<${entityName}PageVO> get${entityName}Page(${entityName}PageQuery queryParams ) {
|
public PageResult<${entityName}PageVO> get${entityName}Page(${entityName}PageQuery queryParams ) {
|
||||||
IPage<${entityName}PageVO> result = ${lowerFirstEntityName}Service.get${entityName}Page(queryParams);
|
IPage<${entityName}PageVO> result = ${lowerFirstEntityName}Service.get${entityName}Page(queryParams);
|
||||||
return PageResult.success(result);
|
return PageResult.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "新增$!{tableComment}")
|
@Operation(summary = "新增${businessName}")
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public Result save${entityName}(@RequestBody @Valid ${entityName}Form formData ) {
|
public Result save${entityName}(@RequestBody @Valid ${entityName}Form formData ) {
|
||||||
boolean result = ${lowerFirstEntityName}Service.save${entityName}(formData);
|
boolean result = ${lowerFirstEntityName}Service.save${entityName}(formData);
|
||||||
return Result.judge(result);
|
return Result.judge(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "$!{tableComment}表单数据")
|
@Operation(summary = "获取${businessName}表单数据")
|
||||||
@GetMapping("/{id}/form")
|
@GetMapping("/{id}/form")
|
||||||
public Result<${entityName}Form> get${entityName}Form(
|
public Result<${entityName}Form> get${entityName}Form(
|
||||||
@Parameter(description = "$!{tableComment}ID") @PathVariable Long id
|
@Parameter(description = "$!{businessName}ID") @PathVariable Long id
|
||||||
) {
|
) {
|
||||||
${entityName}Form formData = ${lowerFirstEntityName}Service.get${entityName}FormData(id);
|
${entityName}Form formData = ${lowerFirstEntityName}Service.get${entityName}FormData(id);
|
||||||
return Result.success(formData);
|
return Result.success(formData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "修改$!{tableComment}")
|
@Operation(summary = "修改${businessName}")
|
||||||
@PutMapping(value = "/{id}")
|
@PutMapping(value = "/{id}")
|
||||||
public Result update${entityName}(@Parameter(description = "$!{tableComment}ID") @PathVariable Long id,
|
public Result update${entityName}(@Parameter(description = "$!{businessName}ID") @PathVariable Long id,
|
||||||
@RequestBody @Validated ${entityName}Form formData) {
|
@RequestBody @Validated ${entityName}Form formData) {
|
||||||
boolean result = ${lowerFirstEntityName}Service.update${entityName}(id, formData);
|
boolean result = ${lowerFirstEntityName}Service.update${entityName}(id, formData);
|
||||||
return Result.judge(result);
|
return Result.judge(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "删除$!{tableComment}")
|
@Operation(summary = "删除${businessName}")
|
||||||
@DeleteMapping("/{ids}")
|
@DeleteMapping("/{ids}")
|
||||||
public Result delete${entityName}s(
|
public Result delete${entityName}s(
|
||||||
@Parameter(description = "$!{tableComment}ID,多个以英文逗号(,)分割") @PathVariable String ids
|
@Parameter(description = "$!{businessName}ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||||
) {
|
) {
|
||||||
boolean result = ${lowerFirstEntityName}Service.delete${entityName}s(ids);
|
boolean result = ${lowerFirstEntityName}Service.delete${entityName}s(ids);
|
||||||
return Result.judge(result);
|
return Result.judge(result);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import ${package}.model.entity.${entityName};
|
|||||||
import ${package}.model.form.${entityName}Form;
|
import ${package}.model.form.${entityName}Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment}转换器
|
* $!{businessName}对象转换器
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
|||||||
import com.youlai.system.common.base.BaseEntity;
|
import com.youlai.system.common.base.BaseEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment}实体对象
|
* $!{businessName}实体对象
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package ${package}.model.form;
|
package ${package}.${subPackage};
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -11,27 +11,41 @@ import java.time.LocalDateTime;
|
|||||||
#if(${hasBigDecimal})
|
#if(${hasBigDecimal})
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
#end
|
#end
|
||||||
|
#if(${hasRequiredField})
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
#end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment} 表单对象
|
* $!{businessName}表单对象
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Schema(description = "$!{tableComment}表单对象")
|
@Schema(description = "$!{businessName}表单对象")
|
||||||
public class ${entityName}Form implements Serializable {
|
public class ${entityName}Form implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
## ---------- BEGIN 字段循环遍历 ----------
|
## ---------- BEGIN 字段循环遍历 ----------
|
||||||
#foreach($field in ${fields})
|
#if($fieldConfigs)
|
||||||
#if("$!field.comment" != "")
|
#foreach($fieldConfig in ${fieldConfigs})
|
||||||
@Schema(description = "${field.comment}")
|
#if($fieldConfig.isShowInForm)
|
||||||
|
#if($fieldConfig.isRequired)
|
||||||
|
#if($fieldConfig.fieldType == 'String')
|
||||||
|
@NotBlank(message = "$fieldConfig.fieldComment不能为空")
|
||||||
|
#else
|
||||||
|
@NotNull(message = "$fieldConfig.fieldComment不能为空")
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#if("$!fieldConfig.fieldComment" != "")
|
||||||
|
@Schema(description = "${fieldConfig.fieldComment}")
|
||||||
|
#end
|
||||||
|
private ${fieldConfig.fieldType} ${fieldConfig.fieldName};
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
private ${field.propertyType} ${field.propertyName};
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
278
src/main/resources/templates/generator/index.vue.vm
Normal file
278
src/main/resources/templates/generator/index.vue.vm
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<div class="search-container">
|
||||||
|
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
||||||
|
#foreach($fieldConfig in $fieldConfigs)
|
||||||
|
#if($fieldConfig.isShowInQuery == 1)
|
||||||
|
<el-form-item :label="$fieldConfig.fieldComment" :key="$fieldConfig.fieldName">
|
||||||
|
#if($fieldConfig.formType == "INPUT")
|
||||||
|
<el-input v-model="queryParams.$fieldConfig.fieldName" :placeholder="$fieldConfig.fieldComment" clearable @keyup.enter="handleQuery" />
|
||||||
|
#elseif($fieldConfig.formType == "SELECT")
|
||||||
|
<el-select v-model="queryParams.$fieldConfig.fieldName" :placeholder="$fieldConfig.fieldComment" clearable>
|
||||||
|
<!-- 这里可以根据具体需求生成select options -->
|
||||||
|
<el-option v-for="option in $fieldConfig.options" :key="option.value" :label="option.label" :value="option.value"></el-option>
|
||||||
|
</el-select>
|
||||||
|
#elseif($fieldConfig.formType == "RADIO")
|
||||||
|
<el-radio-group v-model="queryParams.$fieldConfig.fieldName">
|
||||||
|
<el-radio v-for="option in $fieldConfig.options" :key="option.value" :label="option.value">{{ option.label }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
#elseif($fieldConfig.formType == "CHECK_BOX")
|
||||||
|
<el-checkbox-group v-model="queryParams.$fieldConfig.fieldName">
|
||||||
|
<el-checkbox v-for="option in $fieldConfig.options" :key="option.value" :label="option.value">{{ option.label }}</el-checkbox>
|
||||||
|
</el-checkbox-group>
|
||||||
|
#elseif($fieldConfig.formType == "INPUT_NUMBER")
|
||||||
|
<el-input-number v-model="queryParams.$fieldConfig.fieldName" :placeholder="$fieldConfig.fieldComment" />
|
||||||
|
#elseif($fieldConfig.formType == "SWITCH")
|
||||||
|
<el-switch v-model="queryParams.$fieldConfig.fieldName" />
|
||||||
|
#elseif($fieldConfig.formType == "TEXT_AREA")
|
||||||
|
<el-input type="textarea" v-model="queryParams.$fieldConfig.fieldName" :placeholder="$fieldConfig.fieldComment" />
|
||||||
|
#elseif($fieldConfig.formType == "DATE_TIME")
|
||||||
|
<el-date-picker v-model="queryParams.$fieldConfig.fieldName" type="datetime" :placeholder="$fieldConfig.fieldComment" />
|
||||||
|
#elseif($fieldConfig.formType == "DATE")
|
||||||
|
<el-date-picker v-model="queryParams.$fieldConfig.fieldName" type="date" :placeholder="$fieldConfig.fieldComment" />
|
||||||
|
#end
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" @click="handleQuery"><i-ep-search />搜索</el-button>
|
||||||
|
<el-button @click="handleResetQuery"><i-ep-refresh />重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-card shadow="never" class="table-container">
|
||||||
|
<template #header>
|
||||||
|
<el-button type="success" @click="handleOpenDialog"><i-ep-plus />新增</el-button>
|
||||||
|
<el-button type="danger" :disabled="ids.length === 0" @click="handleDelete"><i-ep-delete />删除</el-button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<el-table
|
||||||
|
ref="dataTableRef"
|
||||||
|
v-loading="loading"
|
||||||
|
:data="pageData"
|
||||||
|
highlight-current-row
|
||||||
|
border
|
||||||
|
@selection-change="handleSelectionChange"
|
||||||
|
>
|
||||||
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
|
#foreach($fieldConfig in $fieldConfigs)
|
||||||
|
#if($fieldConfig.isShowInList == 1)
|
||||||
|
<el-table-column
|
||||||
|
:key="$fieldConfig.fieldName"
|
||||||
|
:label="$fieldConfig.fieldComment"
|
||||||
|
:prop="$fieldConfig.fieldName"
|
||||||
|
min-width="100"
|
||||||
|
/>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-table-column fixed="right" label="操作" width="220">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button type="primary" size="small" link @click="handleOpenDialog(scope.row.id)"><i-ep-edit />编辑</el-button>
|
||||||
|
<el-button type="danger" size="small" link @click="handleDelete(scope.row.id)"><i-ep-delete />删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination
|
||||||
|
v-if="total > 0"
|
||||||
|
v-model:total="total"
|
||||||
|
v-model:page="queryParams.pageNum"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="handleQuery"
|
||||||
|
/>
|
||||||
|
</el-card>
|
||||||
|
|
||||||
|
<!-- $!{businessName}表单弹窗 -->
|
||||||
|
<el-dialog v-model="dialog.visible" :title="dialog.title" width="500px" @close="handleCloseDialog">
|
||||||
|
<el-form ref="dataFormRef" :model="formData" :rules="rules" label-width="100px">
|
||||||
|
#foreach($fieldConfig in $fieldConfigs)
|
||||||
|
#if($fieldConfig.isShowInForm == 1)
|
||||||
|
<el-form-item :label="$fieldConfig.fieldComment" :key="$fieldConfig.fieldName">
|
||||||
|
#if($fieldConfig.formType == "INPUT")
|
||||||
|
<el-input v-model="formData.$fieldConfig.fieldName" :placeholder="'请输入$fieldConfig.fieldComment" />
|
||||||
|
#elseif($fieldConfig.formType == "SELECT")
|
||||||
|
<el-select v-model="formData.$fieldConfig.fieldName" :placeholder="'请选择$fieldConfig.fieldComment">
|
||||||
|
<!-- 这里可以根据具体需求生成select options -->
|
||||||
|
<el-option v-for="option in $fieldConfig.options" :key="option.value" :label="option.label" :value="option.value"></el-option>
|
||||||
|
</el-select>
|
||||||
|
#elseif($fieldConfig.formType == "RADIO")
|
||||||
|
<el-radio-group v-model="formData.$fieldConfig.fieldName">
|
||||||
|
<el-radio v-for="option in $fieldConfig.options" :key="option.value" :label="option.value">{{ option.label }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
#elseif($fieldConfig.formType == "CHECK_BOX")
|
||||||
|
<el-checkbox-group v-model="formData.$fieldConfig.fieldName">
|
||||||
|
<el-checkbox v-for="option in $fieldConfig.options" :key="option.value" :label="option.value">{{ option.label }}</el-checkbox>
|
||||||
|
</el-checkbox-group>
|
||||||
|
#elseif($fieldConfig.formType == "INPUT_NUMBER")
|
||||||
|
<el-input-number v-model="formData.$fieldConfig.fieldName" :placeholder="'请输入$fieldConfig.fieldComment" />
|
||||||
|
#elseif($fieldConfig.formType == "SWITCH")
|
||||||
|
<el-switch v-model="formData.$fieldConfig.fieldName" />
|
||||||
|
#elseif($fieldConfig.formType == "TEXT_AREA")
|
||||||
|
<el-input type="textarea" v-model="formData.$fieldConfig.fieldName" :placeholder="'请输入$fieldConfig.fieldComment" />
|
||||||
|
#elseif($fieldConfig.formType == "DATE_TIME")
|
||||||
|
<el-date-picker v-model="formData.$fieldConfig.fieldName" type="datetime" :placeholder="'请选择$fieldConfig.fieldComment" />
|
||||||
|
#elseif($fieldConfig.formType == "DATE")
|
||||||
|
<el-date-picker v-model="formData.$fieldConfig.fieldName" type="date" :placeholder="'请选择$fieldConfig.fieldComment" />
|
||||||
|
#end
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button type="primary" @click="handleSubmit">确定</el-button>
|
||||||
|
<el-button @click="handleCloseDialog">取消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineOptions({
|
||||||
|
name: "${entityName}",
|
||||||
|
inheritAttrs: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
import ${entityName}API, { ${entityName}PageVO, ${entityName}Form, ${entityName}PageQuery } from "@/api/${lowerFirstEntityName}";
|
||||||
|
|
||||||
|
const queryFormRef = ref(null);
|
||||||
|
const dataFormRef = ref(null);
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const ids = ref<number[]>([]);
|
||||||
|
const total = ref(0);
|
||||||
|
|
||||||
|
const queryParams = reactive<RolePageQuery>({
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
keywords: '',
|
||||||
|
name: '',
|
||||||
|
code: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
// $!{businessName}表格数据
|
||||||
|
const pageData = ref<RolePageVO[]>([]);
|
||||||
|
|
||||||
|
// 弹窗
|
||||||
|
const dialog = reactive({
|
||||||
|
title: "",
|
||||||
|
visible: false,
|
||||||
|
});
|
||||||
|
// $!{businessName}表单
|
||||||
|
const formData = reactive<RoleForm>({
|
||||||
|
keywords: '',
|
||||||
|
name: '',
|
||||||
|
code: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const rules = reactive({
|
||||||
|
name: [{ required: true, message: "请输入$!{businessName}名称", trigger: "blur" }],
|
||||||
|
code: [{ required: true, message: "请输入$!{businessName}编码", trigger: "blur" }],
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 查询$!{businessName} */
|
||||||
|
function handleQuery() {
|
||||||
|
loading.value = true;
|
||||||
|
${entityName}API.getPage(queryParams)
|
||||||
|
.then((data) => {
|
||||||
|
pageData.value = data.list;
|
||||||
|
total.value = data.total;
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/** 重置$!{businessName}查询 */
|
||||||
|
function handleResetQuery() {
|
||||||
|
queryFormRef.value.resetFields();
|
||||||
|
queryParams.pageNum = 1;
|
||||||
|
handleQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 行复选框选中记录选中ID集合 */
|
||||||
|
function handleSelectionChange(selection: any) {
|
||||||
|
ids.value = selection.map((item: any) => item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 打开$!{businessName}弹窗 */
|
||||||
|
function handleOpenDialog(id?: number) {
|
||||||
|
dialog.visible = true;
|
||||||
|
if (id) {
|
||||||
|
dialog.title = "修改$!{businessName}";
|
||||||
|
${entityName}API.getFormData(id).then((data) => {
|
||||||
|
Object.assign(formData, data);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dialog.title = "新增$!{businessName}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 提交$!{businessName}表单 */
|
||||||
|
function handleSubmit() {
|
||||||
|
dataFormRef.value.validate((valid: any) => {
|
||||||
|
if (valid) {
|
||||||
|
loading.value = true;
|
||||||
|
const id = formData.id;
|
||||||
|
if (id) {
|
||||||
|
${entityName}API.update(id, formData)
|
||||||
|
.then(() => {
|
||||||
|
ElMessage.success("修改成功");
|
||||||
|
handleCloseDialog();
|
||||||
|
handleResetQuery();
|
||||||
|
})
|
||||||
|
.finally(() => (loading.value = false));
|
||||||
|
} else {
|
||||||
|
${entityName}API.add(formData)
|
||||||
|
.then(() => {
|
||||||
|
ElMessage.success("新增成功");
|
||||||
|
handleCloseDialog();
|
||||||
|
handleResetQuery();
|
||||||
|
})
|
||||||
|
.finally(() => (loading.value = false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 关闭$!{businessName}弹窗 */
|
||||||
|
function handleCloseDialog() {
|
||||||
|
dialog.visible = false;
|
||||||
|
dataFormRef.value.resetFields();
|
||||||
|
dataFormRef.value.clearValidate();
|
||||||
|
formData.id = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除$!{businessName} */
|
||||||
|
function handleDelete(id?: number) {
|
||||||
|
const ids = [id || ids.value].join(",");
|
||||||
|
if (!ids) {
|
||||||
|
ElMessage.warning("请勾选删除项");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ElMessageBox.confirm("确认删除已选中的数据项?", "警告", {
|
||||||
|
confirmButtonText: "确定",
|
||||||
|
cancelButtonText: "取消",
|
||||||
|
type: "warning",
|
||||||
|
}).then(
|
||||||
|
() => {
|
||||||
|
loading.value = true;
|
||||||
|
${entityName}API.deleteByIds(ids)
|
||||||
|
.then(() => {
|
||||||
|
ElMessage.success("删除成功");
|
||||||
|
handleResetQuery();
|
||||||
|
})
|
||||||
|
.finally(() => (loading.value = false));
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
ElMessage.info("已取消删除");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
handleQuery();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -7,7 +7,7 @@ import ${package}.model.query.${entityName}Query;
|
|||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment} 数据库访问层
|
* $!{businessName}Mapper接口
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
@@ -16,7 +16,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
public interface ${entityName}Mapper extends BaseMapper<${entityName}> {
|
public interface ${entityName}Mapper extends BaseMapper<${entityName}> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取$!{tableComment}分页数据
|
* 获取${businessName}分页数据
|
||||||
*
|
*
|
||||||
* @param page 分页对象
|
* @param page 分页对象
|
||||||
* @param queryParams 查询参数
|
* @param queryParams 查询参数
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="${package}.mapper.${entityName}Mapper">
|
<mapper namespace="${package}.mapper.${entityName}Mapper">
|
||||||
|
|
||||||
<!-- 获取${tableComment}分页列表 -->
|
<!-- 获取${businessName}分页列表 -->
|
||||||
<select id="listPaged${entityName}s" resultType="${package}.model.entity.${entityName}">
|
<select id="get${entityName}Page" resultType="${package}.model.vo.${entityName}VO">
|
||||||
SELECT
|
SELECT
|
||||||
*
|
*
|
||||||
FROM
|
FROM
|
||||||
|
|||||||
@@ -11,24 +11,26 @@ import java.time.LocalDateTime;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment}分页查询对象
|
* $!{businessName}分页查询对象
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
*/
|
*/
|
||||||
@Schema(description ="$!{tableComment}分页查询对象")
|
@Schema(description ="$!{businessName}查询对象")
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class ${entityName}Query extends BasePageQuery {
|
public class ${entityName}Query extends BasePageQuery {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
#if($fieldConfigs)
|
||||||
#foreach($field in ${fields})
|
#foreach($fieldConfig in ${fieldConfigs})
|
||||||
#if("$!field.comment" != "")
|
#if($fieldConfig.isShowInQuery)
|
||||||
@Schema(description = "${field.comment}")
|
#if("$!fieldConfig.fieldComment" != "")
|
||||||
|
@Schema(description = "${fieldConfig.fieldComment}")
|
||||||
|
#end
|
||||||
|
private ${fieldConfig.fieldType} ${fieldConfig.fieldName};
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
private ${field.propertyType} ${field.propertyName};
|
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,54 +6,51 @@ import ${package}.model.query.${entityName}PageQuery;
|
|||||||
import ${package}.model.vo.${entityName}PageVO;
|
import ${package}.model.vo.${entityName}PageVO;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment} 服务类
|
* $!{businessName}服务类
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
*/
|
*/
|
||||||
public interface ${entityName}Service extends IService<${entityName}> {
|
public interface ${entityName}Service extends IService<${entityName}> {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*$!{tableComment}分页列表
|
*$!{businessName}分页列表
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams);
|
IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取$!{tableComment}表单数据
|
* 获取${businessName}表单数据
|
||||||
*
|
*
|
||||||
* @param id $!{tableComment}ID
|
* @param id $!{businessName}ID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
${entityName}Form get${entityName}FormData(Long id);
|
${entityName}Form get${entityName}FormData(Long id);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增$!{tableComment}
|
* 新增${businessName}
|
||||||
*
|
*
|
||||||
* @param formData $!{tableComment}表单对象
|
* @param formData $!{businessName}表单对象
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean save${entityName}(${entityName}Form formData);
|
boolean save${entityName}(${entityName}Form formData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改$!{tableComment}
|
* 修改${businessName}
|
||||||
*
|
*
|
||||||
* @param id $!{tableComment}ID
|
* @param id $!{businessName}ID
|
||||||
* @param formData $!{tableComment}表单对象
|
* @param formData $!{businessName}表单对象
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean update${entityName}(Long id, ${entityName}Form formData);
|
boolean update${entityName}(Long id, ${entityName}Form formData);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除$!{tableComment}
|
* 删除${businessName}
|
||||||
*
|
*
|
||||||
* @param ids $!{tableComment}ID,多个以英文逗号(,)分割
|
* @param ids $!{businessName}ID,多个以英文逗号(,)分割
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean delete${entityName}s(String ids);
|
boolean delete${entityName}s(String ids);
|
||||||
|
|||||||
@@ -21,22 +21,22 @@ import cn.hutool.core.lang.Assert;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment}服务实现类
|
* $!{businessName}服务实现类
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ${table.serviceImplName} extends ServiceImpl<${entityName}Mapper, ${entityName}> implements ${entityName}Service {
|
public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, ${entityName}> implements ${entityName}Service {
|
||||||
|
|
||||||
private final ${entityName}Converter ${lowerFirstEntityName}Converter;
|
private final ${entityName}Converter ${lowerFirstEntityName}Converter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取$!{tableComment}分页列表
|
* 获取${businessName}分页列表
|
||||||
*
|
*
|
||||||
* @param queryParams 查询参数
|
* @param queryParams 查询参数
|
||||||
* @return {@link IPage<${entityName}PageVO>} $!{tableComment}分页列表
|
* @return {@link IPage<${entityName}PageVO>} $!{businessName}分页列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams) {
|
public IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams) {
|
||||||
@@ -48,9 +48,9 @@ public class ${table.serviceImplName} extends ServiceImpl<${entityName}Mapper, $
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取$!{tableComment}表单数据
|
* 获取${businessName}表单数据
|
||||||
*
|
*
|
||||||
* @param id $!{tableComment}ID
|
* @param id $!{businessName}ID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -60,9 +60,9 @@ public class ${table.serviceImplName} extends ServiceImpl<${entityName}Mapper, $
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增$!{tableComment}
|
* 新增${businessName}
|
||||||
*
|
*
|
||||||
* @param formData $!{tableComment}表单对象
|
* @param formData $!{businessName}表单对象
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -72,10 +72,10 @@ public class ${table.serviceImplName} extends ServiceImpl<${entityName}Mapper, $
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新$!{tableComment}
|
* 更新${businessName}
|
||||||
*
|
*
|
||||||
* @param id $!{tableComment}ID
|
* @param id $!{businessName}ID
|
||||||
* @param formData $!{tableComment}表单对象
|
* @param formData $!{businessName}表单对象
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -85,14 +85,14 @@ public class ${table.serviceImplName} extends ServiceImpl<${entityName}Mapper, $
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除$!{tableComment}
|
* 删除${businessName}
|
||||||
*
|
*
|
||||||
* @param ids $!{tableComment}ID,多个以英文逗号(,)分割
|
* @param ids $!{businessName}ID,多个以英文逗号(,)分割
|
||||||
* @return true|false
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean delete${entityName}s(String ids) {
|
public boolean delete${entityName}s(String ids) {
|
||||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的$!{tableComment}数据为空");
|
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的${businessName}数据为空");
|
||||||
// 逻辑删除
|
// 逻辑删除
|
||||||
List<Long> idList = Arrays.stream(ids.split(","))
|
List<Long> idList = Arrays.stream(ids.split(","))
|
||||||
.map(Long::parseLong)
|
.map(Long::parseLong)
|
||||||
|
|||||||
@@ -14,24 +14,27 @@ import java.math.BigDecimal;
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment} 图对象
|
* $!{businessName}视图对象
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Schema( description = "$!{tableComment}视图对象")
|
@Schema( description = "$!{businessName}视图对象")
|
||||||
public class ${entityName}VO implements Serializable {
|
public class ${entityName}VO implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
#foreach($field in ${fields})
|
#if($fieldConfigs)
|
||||||
#if("$!field.comment" != "")
|
#foreach($fieldConfig in ${fieldConfigs})
|
||||||
@Schema(description = "${field.comment}")
|
#if($fieldConfig.isShowInList)
|
||||||
|
#if("$!fieldConfig.fieldComment" != "")
|
||||||
|
@Schema(description = "${fieldConfig.fieldComment}")
|
||||||
|
#end
|
||||||
|
private ${fieldConfig.fieldType} ${fieldConfig.fieldName};
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
private ${field.propertyType} ${field.propertyName};
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user