@@ -1,8 +1,6 @@
|
|||||||
package com.youlai.system.common.base;
|
package com.youlai.system.common.base;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -14,7 +12,7 @@ import java.time.LocalDateTime;
|
|||||||
/**
|
/**
|
||||||
* 基础实体类
|
* 基础实体类
|
||||||
*
|
*
|
||||||
* <p>实体类的基类,包含了实体类的公共属性,如创建时间、更新时间、逻辑删除标识等</p>
|
* <p>实体类的基类,包含了实体类的公共属性,如创建时间、更新时间</p>
|
||||||
*
|
*
|
||||||
* @author Ray
|
* @author Ray
|
||||||
* @since 2024/6/23
|
* @since 2024/6/23
|
||||||
@@ -25,6 +23,13 @@ public class BaseEntity implements Serializable {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
@@ -41,9 +46,5 @@ public class BaseEntity implements Serializable {
|
|||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* 逻辑删除标识 (0-未删除 1-已删除)
|
|
||||||
*/
|
|
||||||
@TableLogic(value = "0", delval = "1")
|
|
||||||
private Integer isDeleted;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -30,6 +31,11 @@ public class GeneratorProperties {
|
|||||||
|
|
||||||
private String packageName;
|
private String packageName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件扩展名,如 .java
|
||||||
|
*/
|
||||||
|
private String extension= FileNameUtil.EXT_JAVA;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,19 +3,15 @@ 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.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;
|
||||||
|
|
||||||
@@ -36,21 +32,26 @@ public class GeneratorController {
|
|||||||
return PageResult.success(result);
|
return PageResult.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "获取数据表字段列表")
|
@Operation(summary = "获取预览生成代码")
|
||||||
@GetMapping("/table/{tableName}/columns")
|
@GetMapping("/{tableName}/preview")
|
||||||
public Result<List<TableColumnVO>> getTableColumns(
|
public Result<List<GeneratorPreviewVO>> getTablePreviewData(@PathVariable String tableName) {
|
||||||
@Parameter(description = "表名", example = "sys_user") @PathVariable String tableName
|
List<GeneratorPreviewVO> list = generatorService.getTablePreviewData(tableName);
|
||||||
) {
|
|
||||||
List<TableColumnVO> list = generatorService.getTableColumns(tableName);
|
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "获取预览生成代码")
|
@Operation(summary = "获取代码生成配置")
|
||||||
@GetMapping("/table/{tableName}/preview")
|
@GetMapping("/{tableName}/config")
|
||||||
public Result<List<TableGeneratePreviewVO>> getTablePreviewData(@PathVariable String tableName) {
|
public Result<GenConfigForm> getGenConfig(@PathVariable String tableName) {
|
||||||
List<TableGeneratePreviewVO> list = generatorService.getTablePreviewData(tableName);
|
GenConfigForm formData = generatorService.getGenConfig(tableName);
|
||||||
return Result.success(list);
|
return Result.success(formData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "保存代码生成配置")
|
||||||
|
@PostMapping("/{tableName}/config")
|
||||||
|
public Result saveGenCodeConfig(@RequestBody GenConfigForm formData) {
|
||||||
|
boolean result = generatorService.saveGenCodeConfig(formData);
|
||||||
|
return Result.judge(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public interface DeptConverter {
|
|||||||
|
|
||||||
DeptForm toForm(SysDept entity);
|
DeptForm toForm(SysDept entity);
|
||||||
|
|
||||||
DeptVO convertToVo(SysDept entity);
|
DeptVO toVo(SysDept entity);
|
||||||
|
|
||||||
SysDept toEntity(DeptForm deptForm);
|
SysDept toEntity(DeptForm deptForm);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.youlai.system.model.vo.DictPageVO;
|
|||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字典 对象转换器
|
* 字典对象转换器
|
||||||
*
|
*
|
||||||
* @author Ray Hao
|
* @author Ray Hao
|
||||||
* @since 2022/6/8
|
* @since 2022/6/8
|
||||||
@@ -15,7 +15,7 @@ import org.mapstruct.Mapper;
|
|||||||
@Mapper(componentModel = "spring")
|
@Mapper(componentModel = "spring")
|
||||||
public interface DictConverter {
|
public interface DictConverter {
|
||||||
|
|
||||||
Page<DictPageVO> convertToPageVo(Page<SysDict> page);
|
Page<DictPageVO> toPageVo(Page<SysDict> page);
|
||||||
|
|
||||||
DictForm toForm(SysDict entity);
|
DictForm toForm(SysDict entity);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
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.comment", target = "comment")
|
||||||
|
@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> toFieldConfigList(List<GenFieldConfig> fieldConfigs);
|
||||||
|
|
||||||
|
@Mapping(source = "configId", target = "configId")
|
||||||
|
@Mapping(source = "columnName", target = "columnName")
|
||||||
|
@Mapping(source = "columnType", target = "columnType")
|
||||||
|
@Mapping(source = "fieldName", target = "fieldName")
|
||||||
|
@Mapping(source = "fieldType", target = "fieldType")
|
||||||
|
@Mapping(source = "comment", target = "comment")
|
||||||
|
@Mapping(source = "formType", target = "formType")
|
||||||
|
@Mapping(source = "queryType", target = "queryType")
|
||||||
|
@Mapping(source = "isShowInList", target = "isShowInList")
|
||||||
|
@Mapping(source = "isShowInForm", target = "isShowInForm")
|
||||||
|
@Mapping(source = "isShowInQuery", target = "isShowInQuery")
|
||||||
|
@Mapping(source = "isRequired", target = "isRequired")
|
||||||
|
GenConfigForm.FieldConfig toFieldConfig(GenFieldConfig genFieldConfig);
|
||||||
|
|
||||||
|
}
|
||||||
70
src/main/java/com/youlai/system/enums/FormTypeEnum.java
Normal file
70
src/main/java/com/youlai/system/enums/FormTypeEnum.java
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package com.youlai.system.enums;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||||
|
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, "单选框"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数字输入框
|
||||||
|
*/
|
||||||
|
INPUT_NUMBER(4, "数字输入框"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开关
|
||||||
|
*/
|
||||||
|
SWITCH(5, "开关"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复选框
|
||||||
|
*/
|
||||||
|
CHECK_BOX(6, "复选框"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文本域
|
||||||
|
*/
|
||||||
|
TEXT_AREA(7, "文本域"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期时间框
|
||||||
|
*/
|
||||||
|
DATE_TIME(8, "日期时间框"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期框
|
||||||
|
*/
|
||||||
|
DATE(9, "日期框"),;
|
||||||
|
|
||||||
|
|
||||||
|
// Mybatis-Plus 提供注解表示插入数据库时插入该值
|
||||||
|
@EnumValue
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
// @JsonValue // 表示对枚举序列化时返回此字段
|
||||||
|
private final String label;
|
||||||
|
}
|
||||||
58
src/main/java/com/youlai/system/enums/QueryTypeEnum.java
Normal file
58
src/main/java/com/youlai/system/enums/QueryTypeEnum.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package com.youlai.system.enums;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||||
|
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, "="),
|
||||||
|
|
||||||
|
|
||||||
|
NE(2, "!="),
|
||||||
|
|
||||||
|
|
||||||
|
GT(3, ">"),
|
||||||
|
|
||||||
|
|
||||||
|
GE(4, ">="),
|
||||||
|
|
||||||
|
LT(5, "<"),
|
||||||
|
|
||||||
|
LE(6, "<="),
|
||||||
|
|
||||||
|
BETWEEN(7, "BETWEEN"),
|
||||||
|
|
||||||
|
LIKE(8, "LIKE '%s%'"),
|
||||||
|
|
||||||
|
LIKE_LEFT(9, "LIKE '%s'"),
|
||||||
|
|
||||||
|
LIKE_RIGHT(10, "LIKE 's%'"),
|
||||||
|
|
||||||
|
IN(11, "IN"),
|
||||||
|
|
||||||
|
NOT_IN(12, "NOT IN"),
|
||||||
|
|
||||||
|
IS_NULL(13, "IS NULL"),
|
||||||
|
|
||||||
|
IS_NOT_NULL(14, "IS NOT NULL")
|
||||||
|
;
|
||||||
|
|
||||||
|
// Mybatis-Plus 提供注解表示插入数据库时插入该值
|
||||||
|
@EnumValue
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
// @JsonValue // 表示对枚举序列化时返回此字段
|
||||||
|
private final String label;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,6 +11,12 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库 Mapper 接口
|
||||||
|
*
|
||||||
|
* @author ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DatabaseMapper extends BaseMapper<SysDept> {
|
public interface DatabaseMapper extends BaseMapper<SysDept> {
|
||||||
|
|
||||||
|
|||||||
20
src/main/java/com/youlai/system/mapper/GenConfigMapper.java
Normal file
20
src/main/java/com/youlai/system/mapper/GenConfigMapper.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package com.youlai.system.mapper;
|
||||||
|
|
||||||
|
import com.youlai.system.model.entity.GenConfig;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成基础配置访问层
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface GenConfigMapper extends BaseMapper<GenConfig> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.youlai.system.mapper;
|
||||||
|
|
||||||
|
import com.youlai.system.model.entity.GenFieldConfig;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成字段配置访问层
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 2.10.0
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface GenFieldConfigMapper extends BaseMapper<GenFieldConfig> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
53
src/main/java/com/youlai/system/model/entity/GenConfig.java
Normal file
53
src/main/java/com/youlai/system/model/entity/GenConfig.java
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package com.youlai.system.model.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
|
import com.youlai.system.common.base.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代码生成基础配置
|
||||||
|
*/
|
||||||
|
@TableName(value ="gen_config")
|
||||||
|
@Data
|
||||||
|
public class GenConfig extends BaseEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表名
|
||||||
|
*/
|
||||||
|
private String tableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 包名
|
||||||
|
*/
|
||||||
|
private String packageName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模块名
|
||||||
|
*/
|
||||||
|
private String moduleName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实体名
|
||||||
|
*/
|
||||||
|
private String entityName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类描述
|
||||||
|
*/
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上级菜单ID
|
||||||
|
*/
|
||||||
|
private Long parentMenuId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 作者
|
||||||
|
*/
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
|
||||||
|
@TableLogic
|
||||||
|
private Integer isDeleted;
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package com.youlai.system.model.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
|
||||||
|
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 comment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单类型
|
||||||
|
*/
|
||||||
|
private FormTypeEnum formType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询方式
|
||||||
|
*/
|
||||||
|
private QueryTypeEnum queryType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否在列表显示
|
||||||
|
*/
|
||||||
|
private Integer isShowInList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否在表单显示
|
||||||
|
*/
|
||||||
|
private Integer isShowInForm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否在查询条件显示
|
||||||
|
*/
|
||||||
|
private Integer isShowInQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否必填
|
||||||
|
*/
|
||||||
|
private Integer isRequired;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.youlai.system.model.entity;
|
|||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
import com.youlai.system.common.base.BaseEntity;
|
import com.youlai.system.common.base.BaseEntity;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -16,11 +17,6 @@ import lombok.Setter;
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class SysDept extends BaseEntity {
|
public class SysDept extends BaseEntity {
|
||||||
/**
|
|
||||||
* 主键
|
|
||||||
*/
|
|
||||||
@TableId(type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门名称
|
* 部门名称
|
||||||
@@ -62,4 +58,10 @@ public class SysDept extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
private Long updateBy;
|
private Long updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 逻辑删除标识 (0-未删除 1-已删除)
|
||||||
|
*/
|
||||||
|
@TableLogic
|
||||||
|
private Boolean isDeleted;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.youlai.system.model.entity;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
import com.youlai.system.common.base.BaseEntity;
|
import com.youlai.system.common.base.BaseEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -13,11 +14,6 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class SysDict extends BaseEntity {
|
public class SysDict extends BaseEntity {
|
||||||
/**
|
|
||||||
* 主键
|
|
||||||
*/
|
|
||||||
@TableId(type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类型名称
|
* 类型名称
|
||||||
@@ -39,4 +35,10 @@ public class SysDict extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 逻辑删除标识 (0-未删除 1-已删除)
|
||||||
|
*/
|
||||||
|
@TableLogic(value = "0", delval = "1")
|
||||||
|
private Integer isDeleted;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.youlai.system.model.entity;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
import com.youlai.system.common.base.BaseEntity;
|
import com.youlai.system.common.base.BaseEntity;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -55,4 +56,10 @@ public class SysRole extends BaseEntity {
|
|||||||
* 更新人 ID
|
* 更新人 ID
|
||||||
*/
|
*/
|
||||||
private Long updateBy;
|
private Long updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 逻辑删除标识 (0-未删除 1-已删除)
|
||||||
|
*/
|
||||||
|
@TableLogic(value = "0", delval = "1")
|
||||||
|
private Boolean isDeleted;
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.youlai.system.model.entity;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
import com.youlai.system.common.base.BaseEntity;
|
import com.youlai.system.common.base.BaseEntity;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -72,4 +73,10 @@ public class SysUser extends BaseEntity {
|
|||||||
* 更新人 ID
|
* 更新人 ID
|
||||||
*/
|
*/
|
||||||
private Long updateBy;
|
private Long updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 逻辑删除标识 (0-未删除 1-已删除)
|
||||||
|
*/
|
||||||
|
@TableLogic(value = "0", delval = "1")
|
||||||
|
private Integer isDeleted;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
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;
|
||||||
|
|
||||||
@@ -7,53 +9,67 @@ import java.util.List;
|
|||||||
|
|
||||||
@Schema(description = "代码生成配置表单")
|
@Schema(description = "代码生成配置表单")
|
||||||
@Data
|
@Data
|
||||||
public class GeneratorConfigForm {
|
public class GenConfigForm {
|
||||||
|
|
||||||
@Schema(description = "表名")
|
@Schema(description = "表名")
|
||||||
private String tableName;
|
private String tableName;
|
||||||
|
|
||||||
@Schema(description = "实体名")
|
@Schema(description = "类描述")
|
||||||
private String entityName;
|
private String comment;
|
||||||
|
|
||||||
@Schema(description = "包名")
|
|
||||||
private String packageName;
|
|
||||||
|
|
||||||
@Schema(description = "模块名")
|
@Schema(description = "模块名")
|
||||||
private String moduleName;
|
private String moduleName;
|
||||||
|
|
||||||
|
@Schema(description = "包名")
|
||||||
|
private String packageName;
|
||||||
|
|
||||||
|
@Schema(description = "实体名")
|
||||||
|
private String entityName;
|
||||||
|
|
||||||
@Schema(description = "作者")
|
@Schema(description = "作者")
|
||||||
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 = "ID")
|
||||||
|
private Long configId;
|
||||||
|
|
||||||
@Schema(description = "字段名称")
|
@Schema(description = "列名")
|
||||||
private String name;
|
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 comment;
|
||||||
|
|
||||||
@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;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ import lombok.Data;
|
|||||||
|
|
||||||
@Schema(description = "表生成代码预览VO")
|
@Schema(description = "表生成代码预览VO")
|
||||||
@Data
|
@Data
|
||||||
public class TableGeneratePreviewVO {
|
public class GeneratorPreviewVO {
|
||||||
|
|
||||||
@Schema(description = "生成文件路径")
|
@Schema(description = "生成文件路径")
|
||||||
private String path;
|
private String path;
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
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.TableColumnVO;
|
||||||
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
import com.youlai.system.model.vo.GeneratorPreviewVO;
|
||||||
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 haoxr
|
||||||
* @since 2.11.0
|
* @since 2.11.0
|
||||||
@@ -39,5 +40,21 @@ public interface GeneratorService {
|
|||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<TableGeneratePreviewVO> getTablePreviewData(String tableName);
|
List<GeneratorPreviewVO> getTablePreviewData(String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取代码生成配置
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
GenConfigForm getGenConfig(String tableName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存代码生成配置
|
||||||
|
*
|
||||||
|
* @param formData 表单数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean saveGenCodeConfig(GenConfigForm formData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,30 @@
|
|||||||
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.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.config.property.GeneratorProperties;
|
||||||
import com.youlai.system.mapper.DatabaseMapper;
|
import com.youlai.system.mapper.DatabaseMapper;
|
||||||
|
import com.youlai.system.mapper.GenConfigMapper;
|
||||||
|
import com.youlai.system.mapper.GenFieldConfigMapper;
|
||||||
|
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.TableColumnVO;
|
||||||
import com.youlai.system.model.vo.TableGeneratePreviewVO;
|
import com.youlai.system.model.vo.GeneratorPreviewVO;
|
||||||
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 lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.logging.log4j.util.Strings;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import cn.hutool.extra.template.TemplateConfig.ResourceMode;
|
import cn.hutool.extra.template.TemplateConfig.ResourceMode;
|
||||||
|
|
||||||
@@ -31,6 +43,15 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||||||
|
|
||||||
private final DatabaseMapper databaseMapper;
|
private final DatabaseMapper databaseMapper;
|
||||||
|
|
||||||
|
private final GeneratorProperties generatorProperties;
|
||||||
|
|
||||||
|
private final GenConfigMapper genConfigMapper;
|
||||||
|
private final GenFieldConfigMapper genFieldConfigMapper;
|
||||||
|
|
||||||
|
// 注入 spring.application.name
|
||||||
|
@Value("${spring.application.name}")
|
||||||
|
private String applicationName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据表分页列表
|
* 数据表分页列表
|
||||||
*
|
*
|
||||||
@@ -53,6 +74,39 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||||||
return databaseMapper.getTableColumns(tableName);
|
return databaseMapper.getTableColumns(tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取代码生成配置
|
||||||
|
*
|
||||||
|
* @param tableName 表名 eg: sys_user
|
||||||
|
* @return 代码生成配置
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GenConfigForm getGenConfig(String tableName) {
|
||||||
|
// 查询表生成配置
|
||||||
|
GenConfig genConfig = genConfigMapper.selectOne(
|
||||||
|
new LambdaQueryWrapper<>(GenConfig.class)
|
||||||
|
.eq(GenConfig::getTableName, tableName)
|
||||||
|
.last("LIMIT 1")
|
||||||
|
);
|
||||||
|
|
||||||
|
// 查询字段生成配置
|
||||||
|
List<GenFieldConfig> fieldConfigs = genFieldConfigMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<>(GenFieldConfig.class)
|
||||||
|
.eq(GenFieldConfig::getConfigId, genConfig.getId())
|
||||||
|
);
|
||||||
|
|
||||||
|
GenConfigForm genConfigForm = new GenConfigForm();
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean saveGenCodeConfig(GenConfigForm formData) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取预览生成代码
|
* 获取预览生成代码
|
||||||
*
|
*
|
||||||
@@ -60,49 +114,133 @@ 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 = genConfigMapper.selectOne(new LambdaQueryWrapper<GenConfig>()
|
||||||
TemplateEngine templateEngine = TemplateUtil.createEngine(templateConfig);
|
.eq(GenConfig::getTableName, tableName)
|
||||||
|
);
|
||||||
|
Assert.isTrue(genConfig != null, "未找到表生成配置");
|
||||||
|
|
||||||
|
List<GenFieldConfig> fieldConfigs = genFieldConfigMapper.selectList(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);
|
||||||
|
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 (templateName.equals("Entity")) {
|
||||||
|
return entityName + extension;
|
||||||
|
}
|
||||||
|
if (templateName.equals("MapperXml")) {
|
||||||
|
return entityName + "Mapper" + extension;
|
||||||
|
}
|
||||||
|
if (templateName.equals("API") || templateName.equals("VIEW")) {
|
||||||
|
return StrUtil.toSymbolCase(entityName, '-') + extension;
|
||||||
|
}
|
||||||
|
return entityName + templateName + extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getFilePath(String templateName, String packageName, String subPackageName) {
|
||||||
|
String path;
|
||||||
|
if (templateName.equals("MapperXml")) {
|
||||||
|
path = (applicationName
|
||||||
|
+ File.separator
|
||||||
|
+ "src" + File.separator + "main" + File.separator + "resources"
|
||||||
|
+ File.separator + subPackageName
|
||||||
|
).replace(".", File.separator);
|
||||||
|
} else if (templateName.equals("API") || templateName.equals("VIEW")) {
|
||||||
|
path = ("vue3-element-admin"
|
||||||
|
+ File.separator
|
||||||
|
+ "src" + File.separator + subPackageName
|
||||||
|
).replace(".", File.separator);
|
||||||
|
} else {
|
||||||
|
path = (applicationName
|
||||||
|
+ File.separator
|
||||||
|
+ "src" + File.separator + "main" + File.separator + "java"
|
||||||
|
+ File.separator + packageName + File.separator + subPackageName
|
||||||
|
).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("tableComment", StrUtil.replace(genConfig.getComment(), "表", Strings.EMPTY));
|
||||||
|
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", Boolean.TRUE.equals(fieldConfig.getIsRequired()));
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateEngine templateEngine = TemplateUtil.createEngine(new TemplateConfig("templates", ResourceMode.CLASSPATH));
|
||||||
|
Template template = templateEngine.getTemplate(templateConfig.getTemplatePath());
|
||||||
|
String content = template.render(bindMap);
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
return deptList.stream()
|
return deptList.stream()
|
||||||
.filter(dept -> dept.getParentId().equals(parentId))
|
.filter(dept -> dept.getParentId().equals(parentId))
|
||||||
.map(dept -> {
|
.map(dept -> {
|
||||||
DeptVO deptVO = deptConverter.convertToVo(dept);
|
DeptVO deptVO = deptConverter.toVo(dept);
|
||||||
List<DeptVO> children = recurDeptList(dept.getId(), deptList);
|
List<DeptVO> children = recurDeptList(dept.getId(), deptList);
|
||||||
deptVO.setChildren(children);
|
deptVO.setChildren(children);
|
||||||
return deptVO;
|
return deptVO;
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
* 删除用户
|
* 删除用户
|
||||||
*
|
*
|
||||||
* @param idsStr 用户ID,多个以英文逗号(,)分割
|
* @param idsStr 用户ID,多个以英文逗号(,)分割
|
||||||
* @return true|false
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteUsers(String idsStr) {
|
public boolean deleteUsers(String idsStr) {
|
||||||
@@ -175,7 +175,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param password 用户密码
|
* @param password 用户密码
|
||||||
* @return true|false
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean updatePassword(Long userId, String password) {
|
public boolean updatePassword(Long userId, String password) {
|
||||||
|
|||||||
@@ -3,7 +3,41 @@ generator:
|
|||||||
## 模板配置
|
## 模板配置
|
||||||
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
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
7
src/main/resources/mapper/GenConfigMapper.xml
Normal file
7
src/main/resources/mapper/GenConfigMapper.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.GenConfigMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
28
src/main/resources/mapper/GenFieldConfigMapper.xml
Normal file
28
src/main/resources/mapper/GenFieldConfigMapper.xml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.youlai.system.model.entity.GenFieldConfig">
|
||||||
|
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||||
|
<result property="configId" column="config_id" jdbcType="BIGINT"/>
|
||||||
|
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||||
|
<result property="type" column="type" jdbcType="VARCHAR"/>
|
||||||
|
<result property="description" column="description" jdbcType="VARCHAR"/>
|
||||||
|
<result property="showInList" column="show_in_list" jdbcType="TINYINT"/>
|
||||||
|
<result property="showInForm" column="show_in_form" jdbcType="TINYINT"/>
|
||||||
|
<result property="showInQuery" column="show_in_query" jdbcType="TINYINT"/>
|
||||||
|
<result property="formType" column="form_type" jdbcType="VARCHAR"/>
|
||||||
|
<result property="queryMethod" column="query_method" jdbcType="VARCHAR"/>
|
||||||
|
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,config_id,name,
|
||||||
|
type,description,show_in_list,
|
||||||
|
show_in_form,show_in_query,form_type,
|
||||||
|
query_method,create_time,update_time
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
||||||
121
src/main/resources/templates/generator/api.ts.vm
Normal file
121
src/main/resources/templates/generator/api.ts.vm
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
import request from "@/utils/request";
|
||||||
|
|
||||||
|
const ${className.toUpperCase()}_BASE_URL = "/api/v1/${className.toLowerCase()}s";
|
||||||
|
|
||||||
|
class ${className}API {
|
||||||
|
/** 获取${className}分页数据 */
|
||||||
|
static getPage(queryParams?: ${className}PageQuery) {
|
||||||
|
return request<any, PageResult<${className}PageVO[]>>({
|
||||||
|
url: `${${className.toUpperCase()}_BASE_URL}/page`,
|
||||||
|
method: "get",
|
||||||
|
params: queryParams,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取${className}下拉数据源 */
|
||||||
|
static getOptions() {
|
||||||
|
return request<any, OptionType[]>({
|
||||||
|
url: `${${className.toUpperCase()}_BASE_URL}/options`,
|
||||||
|
method: "get",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取${className}的菜单ID集合
|
||||||
|
*
|
||||||
|
* @param ${className.toLowerCase()}Id ${className}ID
|
||||||
|
* @returns ${className}的菜单ID集合
|
||||||
|
*/
|
||||||
|
static get${className}MenuIds(${className.toLowerCase()}Id: number) {
|
||||||
|
return request<any, number[]>({
|
||||||
|
url: `${${className.toUpperCase()}_BASE_URL}/${${className.toLowerCase()}Id}/menuIds`,
|
||||||
|
method: "get",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分配菜单权限
|
||||||
|
*
|
||||||
|
* @param ${className.toLowerCase()}Id ${className}ID
|
||||||
|
* @param data 菜单ID集合
|
||||||
|
*/
|
||||||
|
static update${className}Menus(${className.toLowerCase()}Id: number, data: number[]) {
|
||||||
|
return request({
|
||||||
|
url: `${${className.toUpperCase()}_BASE_URL}/${${className.toLowerCase()}Id}/menus`,
|
||||||
|
method: "put",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取${className}表单数据
|
||||||
|
*
|
||||||
|
* @param id ${className}ID
|
||||||
|
* @returns ${className}表单数据
|
||||||
|
*/
|
||||||
|
static getFormData(id: number) {
|
||||||
|
return request<any, ${className}Form>({
|
||||||
|
url: `${${className.toUpperCase()}_BASE_URL}/${id}/form`,
|
||||||
|
method: "get",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 添加${className} */
|
||||||
|
static add(data: ${className}Form) {
|
||||||
|
return request({
|
||||||
|
url: `${${className.toUpperCase()}_BASE_URL}`,
|
||||||
|
method: "post",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新${className}
|
||||||
|
*
|
||||||
|
* @param id ${className}ID
|
||||||
|
* @param data ${className}表单数据
|
||||||
|
*/
|
||||||
|
static update(id: number, data: ${className}Form) {
|
||||||
|
return request({
|
||||||
|
url: `${${className.toUpperCase()}_BASE_URL}/${id}`,
|
||||||
|
method: "put",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除${className},多个以英文逗号(,)分割
|
||||||
|
*
|
||||||
|
* @param ids ${className}ID字符串,多个以英文逗号(,)分割
|
||||||
|
*/
|
||||||
|
static deleteByIds(ids: string) {
|
||||||
|
return request({
|
||||||
|
url: `${${className.toUpperCase()}_BASE_URL}/${ids}`,
|
||||||
|
method: "delete",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ${className}API;
|
||||||
|
|
||||||
|
/** ${className}分页查询参数 */
|
||||||
|
export interface ${className}PageQuery extends PageQuery {
|
||||||
|
/** 搜索关键字 */
|
||||||
|
keywords?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ${className}分页对象 */
|
||||||
|
export interface ${className}PageVO {
|
||||||
|
#foreach($field in $fields)
|
||||||
|
/** ${field.comment} */
|
||||||
|
${field.name}?: ${field.type};
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ${className}表单对象 */
|
||||||
|
export interface ${className}Form {
|
||||||
|
#foreach($field in $fields)
|
||||||
|
/** ${field.comment} */
|
||||||
|
${field.name}?: ${field.type};
|
||||||
|
#end
|
||||||
|
}
|
||||||
@@ -7,8 +7,8 @@ import ${package}.model.form.${entityName}Form;
|
|||||||
import ${package}.model.query.${entityName}PageQuery;
|
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.youlai.common.result.PageResult;
|
import com.youlai.system.common.result.PageResult;
|
||||||
import com.youlai.common.result.Result;
|
import com.youlai.system.common.result.Result;
|
||||||
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 io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment} 前端控制器
|
* $!{tableComment}前端控制层
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
@@ -44,7 +44,7 @@ public class ${entityName}Controller {
|
|||||||
return Result.judge(result);
|
return Result.judge(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "$!{tableComment}表单数据")
|
@Operation(summary = "获取$!{tableComment}表单数据")
|
||||||
@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 = "$!{tableComment}ID") @PathVariable Long id
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import ${package}.model.entity.${entityName};
|
|||||||
import ${package}.model.form.${entityName}Form;
|
import ${package}.model.form.${entityName}Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment}转换器
|
* $!{tableComment}对象转换器
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
|
|||||||
@@ -23,13 +23,14 @@ import com.youlai.system.common.base.BaseEntity;
|
|||||||
public class ${entityName} extends BaseEntity {
|
public class ${entityName} extends BaseEntity {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
#if($fieldConfigs)
|
||||||
#foreach($field in ${table.fields})
|
#foreach($fieldConfig in ${fieldConfigs})
|
||||||
#if("$!field.comment" != "")
|
#if("$!fieldConfig.fieldComment" != "")
|
||||||
/**
|
/**
|
||||||
* ${field.comment}
|
* ${fieldConfig.fieldComment}
|
||||||
*/
|
*/
|
||||||
#end
|
#end
|
||||||
private ${field.propertyType} ${field.propertyName};
|
private ${fieldConfig.fieldType} ${fieldConfig.fieldName};
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,10 +11,12 @@ 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} 表单对象
|
* $!{tableComment}表单对象
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
@@ -28,10 +30,22 @@ public class ${entityName}Form implements Serializable {
|
|||||||
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.showInForm)
|
||||||
|
#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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
178
src/main/resources/templates/generator/index.vue.vm
Normal file
178
src/main/resources/templates/generator/index.vue.vm
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<div class="search-container">
|
||||||
|
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
||||||
|
<el-form-item prop="keywords" label="关键字">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.keywords"
|
||||||
|
placeholder="${className}名称"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<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="${className.toLowerCase()}List"
|
||||||
|
highlight-current-row
|
||||||
|
border
|
||||||
|
@selection-change="handleSelectionChange"
|
||||||
|
>
|
||||||
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
|
#foreach($field in $fields)
|
||||||
|
<el-table-column label="${field.comment}" prop="${field.name}" min-width="100" />
|
||||||
|
#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>
|
||||||
|
|
||||||
|
<!-- ${className}表单弹窗 -->
|
||||||
|
<el-dialog
|
||||||
|
v-model="dialog.visible"
|
||||||
|
:title="dialog.title"
|
||||||
|
width="500px"
|
||||||
|
@close="handleCloseDialog"
|
||||||
|
>
|
||||||
|
<el-form
|
||||||
|
ref="${className.toLowerCase()}FormRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="100px"
|
||||||
|
>
|
||||||
|
#foreach($field in $fields)
|
||||||
|
<el-form-item label="${field.comment}" prop="${field.name}">
|
||||||
|
<el-input v-model="formData.${field.name}" placeholder="请输入${field.comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#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: "${className}",
|
||||||
|
inheritAttrs: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
import ${className}API, { ${className}PageVO, ${className}Form, ${className}PageQuery } from "@/api/${className.toLowerCase()}";
|
||||||
|
|
||||||
|
const queryFormRef = ref(ElForm);
|
||||||
|
const ${className.toLowerCase()}FormRef = ref(ElForm);
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const ids = ref<number[]>([]);
|
||||||
|
const total = ref(0);
|
||||||
|
|
||||||
|
const queryParams = reactive<${className}PageQuery>({
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
});
|
||||||
|
|
||||||
|
// ${className}表格数据
|
||||||
|
const ${className.toLowerCase()}List = ref<${className}PageVO[]>();
|
||||||
|
|
||||||
|
// 弹窗
|
||||||
|
const dialog = reactive({
|
||||||
|
title: "",
|
||||||
|
visible: false,
|
||||||
|
});
|
||||||
|
// ${className}表单
|
||||||
|
const formData = reactive<${className}Form>({});
|
||||||
|
|
||||||
|
const rules = reactive({
|
||||||
|
#foreach($field in $fields)
|
||||||
|
${field.name}: [{ required: true, message: "请输入${field.comment}", trigger: "blur" }],
|
||||||
|
#end
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 查询 */
|
||||||
|
function handleQuery() {
|
||||||
|
loading.value = true;
|
||||||
|
${className}API.getPage(queryParams)
|
||||||
|
.then((data) => {
|
||||||
|
${className.toLowerCase()}List.value = data.list;
|
||||||
|
total.value = data.total;
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置查询 */
|
||||||
|
function handleResetQuery() {
|
||||||
|
queryFormRef.value.resetFields();
|
||||||
|
queryParams.pageNum = 1;
|
||||||
|
handleQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 行复选框选中记录选中ID集合 */
|
||||||
|
function handleSelectionChange(selection: any) {
|
||||||
|
ids.value = selection.map((item: any
|
||||||
@@ -7,7 +7,7 @@ import ${package}.model.query.${entityName}Query;
|
|||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment} 数据库访问层
|
* $!{tableComment}Mapper接口
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<mapper namespace="${package}.mapper.${entityName}Mapper">
|
<mapper namespace="${package}.mapper.${entityName}Mapper">
|
||||||
|
|
||||||
<!-- 获取${tableComment}分页列表 -->
|
<!-- 获取${tableComment}分页列表 -->
|
||||||
<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,7 +11,6 @@ import java.time.LocalDateTime;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment}分页查询对象
|
* $!{tableComment}分页查询对象
|
||||||
*
|
*
|
||||||
@@ -24,11 +23,14 @@ import java.math.BigDecimal;
|
|||||||
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.showInQuery)
|
||||||
@Schema(description = "${field.comment}")
|
#if("$!fieldConfig.fieldComment" != "")
|
||||||
|
@Schema(description = "${field.fieldComment}")
|
||||||
|
#end
|
||||||
|
private ${fieldConfig.fieldType} ${fieldConfig.fieldName};
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
private ${field.propertyType} ${field.propertyName};
|
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ 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} 服务类
|
* $!{tableComment}服务类
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
*/
|
*/
|
||||||
public interface ${entityName}Service extends IService<${entityName}> {
|
public interface ${entityName}Service extends IService<${entityName}> {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*$!{tableComment}分页列表
|
*$!{tableComment}分页列表
|
||||||
*
|
*
|
||||||
@@ -22,7 +22,6 @@ public interface ${entityName}Service extends IService<${entityName}> {
|
|||||||
*/
|
*/
|
||||||
IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams);
|
IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取$!{tableComment}表单数据
|
* 获取$!{tableComment}表单数据
|
||||||
*
|
*
|
||||||
@@ -31,7 +30,6 @@ public interface ${entityName}Service extends IService<${entityName}> {
|
|||||||
*/
|
*/
|
||||||
${entityName}Form get${entityName}FormData(Long id);
|
${entityName}Form get${entityName}FormData(Long id);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增$!{tableComment}
|
* 新增$!{tableComment}
|
||||||
*
|
*
|
||||||
@@ -49,7 +47,6 @@ public interface ${entityName}Service extends IService<${entityName}> {
|
|||||||
*/
|
*/
|
||||||
boolean update${entityName}(Long id, ${entityName}Form formData);
|
boolean update${entityName}(Long id, ${entityName}Form formData);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除$!{tableComment}
|
* 删除$!{tableComment}
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
*/
|
*/
|
||||||
@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;
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ public class ${table.serviceImplName} extends ServiceImpl<${entityName}Mapper, $
|
|||||||
* 删除$!{tableComment}
|
* 删除$!{tableComment}
|
||||||
*
|
*
|
||||||
* @param ids $!{tableComment}ID,多个以英文逗号(,)分割
|
* @param ids $!{tableComment}ID,多个以英文逗号(,)分割
|
||||||
* @return true|false
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean delete${entityName}s(String ids) {
|
public boolean delete${entityName}s(String ids) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.math.BigDecimal;
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $!{tableComment} 图对象
|
* $!{tableComment}视图对象
|
||||||
*
|
*
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
* @since ${date}
|
* @since ${date}
|
||||||
@@ -27,11 +27,12 @@ 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.fieldComment" != "")
|
||||||
|
@Schema(description = "${fieldConfig.fieldComment}")
|
||||||
|
#end
|
||||||
|
private ${fieldConfig.fieldType} ${fieldConfig.fieldName};
|
||||||
#end
|
#end
|
||||||
private ${field.propertyType} ${field.propertyName};
|
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user