wip: 代码生成临时提交
This commit is contained in:
@@ -14,7 +14,7 @@ import java.time.LocalDateTime;
|
||||
/**
|
||||
* 基础实体类
|
||||
*
|
||||
* <p>实体类的基类,包含了实体类的公共属性,如创建时间、更新时间、逻辑删除标识等</p>
|
||||
* <p>实体类的基类,包含了实体类的公共属性,如创建时间、更新时间</p>
|
||||
*
|
||||
* @author Ray
|
||||
* @since 2024/6/23
|
||||
@@ -41,9 +41,5 @@ public class BaseEntity implements Serializable {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除标识 (0-未删除 1-已删除)
|
||||
*/
|
||||
@TableLogic(value = "0", delval = "1")
|
||||
private Integer isDeleted;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.youlai.system.config.property;
|
||||
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -30,6 +31,11 @@ public class GeneratorProperties {
|
||||
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* 文件扩展名,如 .java
|
||||
*/
|
||||
private String extension= FileNameUtil.EXT_JAVA;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.youlai.system.common.result.PageResult;
|
||||
import com.youlai.system.common.result.Result;
|
||||
import com.youlai.system.model.query.TablePageQuery;
|
||||
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.service.GeneratorService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -48,8 +48,8 @@ public class GeneratorController {
|
||||
|
||||
@Operation(summary = "获取预览生成代码")
|
||||
@GetMapping("/table/{tableName}/preview")
|
||||
public Result<List<TableGeneratePreviewVO>> getTablePreviewData(@PathVariable String tableName) {
|
||||
List<TableGeneratePreviewVO> list = generatorService.getTablePreviewData(tableName);
|
||||
public Result<List<GeneratorPreviewVO>> getTablePreviewData(@PathVariable String tableName) {
|
||||
List<GeneratorPreviewVO> list = generatorService.getTablePreviewData(tableName);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* 数据库 Mapper 接口
|
||||
*
|
||||
* @author ray
|
||||
* @since 2.10.0
|
||||
*/
|
||||
@Mapper
|
||||
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 {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 表名
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 表注释
|
||||
*/
|
||||
private String tableComment;
|
||||
|
||||
/**
|
||||
* 实体名
|
||||
*/
|
||||
private String entityName;
|
||||
|
||||
/**
|
||||
* 包名
|
||||
*/
|
||||
private String packageName;
|
||||
|
||||
/**
|
||||
* 模块名
|
||||
*/
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 作者
|
||||
*/
|
||||
private String author;
|
||||
|
||||
|
||||
@TableLogic
|
||||
private Boolean isDeleted;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.youlai.system.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
import com.youlai.system.enums.FormTypeEnum;
|
||||
import com.youlai.system.enums.QueryTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 字段配置实体
|
||||
*
|
||||
* @author Ray
|
||||
* @since 2.10.0
|
||||
*/
|
||||
@TableName(value = "gen_field_config")
|
||||
@Data
|
||||
public class GenFieldConfig extends BaseEntity {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 关联的配置ID
|
||||
*/
|
||||
private Long configId;
|
||||
|
||||
/**
|
||||
* 字段名称
|
||||
*/
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 字段类型
|
||||
*/
|
||||
private String fieldType;
|
||||
|
||||
/**
|
||||
* 字段描述
|
||||
*/
|
||||
private String fieldComment;
|
||||
|
||||
/**
|
||||
* 表单类型
|
||||
*/
|
||||
private FormTypeEnum formType;
|
||||
|
||||
/**
|
||||
* 查询方式
|
||||
*/
|
||||
private QueryTypeEnum queryType;
|
||||
|
||||
/**
|
||||
* 是否在列表显示
|
||||
*/
|
||||
private Boolean isShowInList;
|
||||
|
||||
/**
|
||||
* 是否在表单显示
|
||||
*/
|
||||
private Boolean isShowInForm;
|
||||
|
||||
/**
|
||||
* 是否在查询条件显示
|
||||
*/
|
||||
private Boolean isShowInQuery;
|
||||
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
private Boolean isRequired;
|
||||
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.youlai.system.model.entity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -62,4 +63,10 @@ public class SysDept extends BaseEntity {
|
||||
*/
|
||||
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.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -39,4 +40,10 @@ public class SysDict extends BaseEntity {
|
||||
*/
|
||||
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.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -55,4 +56,10 @@ public class SysRole extends BaseEntity {
|
||||
* 更新人 ID
|
||||
*/
|
||||
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.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.youlai.system.common.base.BaseEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -72,4 +73,10 @@ public class SysUser extends BaseEntity {
|
||||
* 更新人 ID
|
||||
*/
|
||||
private Long updateBy;
|
||||
|
||||
/**
|
||||
* 逻辑删除标识 (0-未删除 1-已删除)
|
||||
*/
|
||||
@TableLogic(value = "0", delval = "1")
|
||||
private Integer isDeleted;
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import lombok.Data;
|
||||
|
||||
@Schema(description = "表生成代码预览VO")
|
||||
@Data
|
||||
public class TableGeneratePreviewVO {
|
||||
public class GeneratorPreviewVO {
|
||||
|
||||
@Schema(description = "生成文件路径")
|
||||
private String path;
|
||||
@@ -3,7 +3,7 @@ package com.youlai.system.service;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.system.model.query.TablePageQuery;
|
||||
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 java.util.List;
|
||||
@@ -39,5 +39,5 @@ public interface GeneratorService {
|
||||
* @param tableName 表名
|
||||
* @return
|
||||
*/
|
||||
List<TableGeneratePreviewVO> getTablePreviewData(String tableName);
|
||||
List<GeneratorPreviewVO> getTablePreviewData(String tableName);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
package com.youlai.system.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
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.TemplateConfig;
|
||||
import cn.hutool.extra.template.TemplateEngine;
|
||||
import cn.hutool.extra.template.TemplateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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.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.query.TablePageQuery;
|
||||
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.service.GeneratorService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import cn.hutool.extra.template.TemplateConfig.ResourceMode;
|
||||
|
||||
@@ -31,6 +43,15 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 数据表分页列表
|
||||
*
|
||||
@@ -60,49 +81,133 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
* @return 预览数据
|
||||
*/
|
||||
@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);
|
||||
TemplateEngine templateEngine = TemplateUtil.createEngine(templateConfig);
|
||||
GenConfig genConfig = genConfigMapper.selectOne(new LambdaQueryWrapper<GenConfig>()
|
||||
.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<>();
|
||||
bindingMap.put("tableName", "sys_user");
|
||||
bindingMap.put("author", "Ray");
|
||||
bindingMap.put("date", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm"));
|
||||
bindingMap.put("entityName", "User" );
|
||||
bindingMap.put("lowerFirstEntityName", "user");
|
||||
bindingMap.put("tableComment", "用户");
|
||||
/* 2. 生成文件路径 */
|
||||
// com.youlai.system
|
||||
String packageName = genConfig.getPackageName();
|
||||
// controller
|
||||
String subPackageName = templateConfig.getPackageName();
|
||||
// 文件路径 com.youlai.system.controller
|
||||
String filePath = getFilePath(templateName, packageName, subPackageName);
|
||||
previewVO.setPath(filePath);
|
||||
|
||||
// 包路径
|
||||
bindingMap.put("package", "com.youlai.system");
|
||||
/* 3. 生成文件内容 */
|
||||
|
||||
Template template = templateEngine.getTemplate("generator" + File.separator + "controller.java.vm");
|
||||
String content = template.render(bindingMap);
|
||||
TableGeneratePreviewVO controller = new TableGeneratePreviewVO();
|
||||
controller.setPath("youlai-boot/controller");
|
||||
controller.setContent(content);
|
||||
controller.setFileName("UserController.java");
|
||||
// 生成文件内容
|
||||
String content = getCodeContent(templateConfig, genConfig, fieldConfigs);
|
||||
previewVO.setContent(content);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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.getTableComment(), "表", 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
* 删除用户
|
||||
*
|
||||
* @param idsStr 用户ID,多个以英文逗号(,)分割
|
||||
* @return true|false
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUsers(String idsStr) {
|
||||
@@ -175,7 +175,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param password 用户密码
|
||||
* @return true|false
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean updatePassword(Long userId, String password) {
|
||||
|
||||
Reference in New Issue
Block a user