wip: 代码生成临时提交
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package com.youlai.system.common.base;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
@@ -25,6 +23,13 @@ public class BaseEntity implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
@@ -3,14 +3,12 @@ package com.youlai.system.controller;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.system.common.result.PageResult;
|
||||
import com.youlai.system.common.result.Result;
|
||||
import com.youlai.system.model.form.GenCodeConfigForm;
|
||||
import com.youlai.system.model.form.GenConfigForm;
|
||||
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.TablePageVO;
|
||||
import com.youlai.system.service.GeneratorService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -44,14 +42,14 @@ public class GeneratorController {
|
||||
|
||||
@Operation(summary = "获取代码生成配置")
|
||||
@GetMapping("/{tableName}/config")
|
||||
public Result<GenCodeConfigForm> getGenCodeConfig(@PathVariable String tableName) {
|
||||
GenCodeConfigForm formData = generatorService.getGenCodeConfig(tableName);
|
||||
public Result<GenConfigForm> getGenConfig(@PathVariable String tableName) {
|
||||
GenConfigForm formData = generatorService.getGenConfig(tableName);
|
||||
return Result.success(formData);
|
||||
}
|
||||
|
||||
@Operation(summary = "保存代码生成配置")
|
||||
@PostMapping("/{tableName}/config")
|
||||
public Result saveGenCodeConfig(@RequestBody GenCodeConfigForm formData) {
|
||||
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);
|
||||
|
||||
DeptVO convertToVo(SysDept entity);
|
||||
DeptVO toVo(SysDept entity);
|
||||
|
||||
SysDept toEntity(DeptForm deptForm);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.youlai.system.model.vo.DictPageVO;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* 字典 对象转换器
|
||||
* 字典对象转换器
|
||||
*
|
||||
* @author Ray Hao
|
||||
* @since 2022/6/8
|
||||
@@ -15,7 +15,7 @@ import org.mapstruct.Mapper;
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface DictConverter {
|
||||
|
||||
Page<DictPageVO> convertToPageVo(Page<SysDict> page);
|
||||
Page<DictPageVO> toPageVo(Page<SysDict> page);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -11,27 +11,12 @@ 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;
|
||||
|
||||
/**
|
||||
* 包名
|
||||
*/
|
||||
@@ -42,6 +27,21 @@ public class GenConfig extends BaseEntity {
|
||||
*/
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 实体名
|
||||
*/
|
||||
private String entityName;
|
||||
|
||||
/**
|
||||
* 类描述
|
||||
*/
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* 上级菜单ID
|
||||
*/
|
||||
private Long parentMenuId;
|
||||
|
||||
/**
|
||||
* 作者
|
||||
*/
|
||||
@@ -49,5 +49,5 @@ public class GenConfig extends BaseEntity {
|
||||
|
||||
|
||||
@TableLogic
|
||||
private Boolean isDeleted;
|
||||
private Integer isDeleted;
|
||||
}
|
||||
@@ -1,38 +1,44 @@
|
||||
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;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 字段配置实体
|
||||
* 字段生成配置实体
|
||||
*
|
||||
* @author Ray
|
||||
* @since 2.10.0
|
||||
*/
|
||||
@TableName(value = "gen_field_config")
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
public class GenFieldConfig extends BaseEntity {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 关联的配置ID
|
||||
*/
|
||||
private Long configId;
|
||||
|
||||
/**
|
||||
* 列名
|
||||
*/
|
||||
private String columnName;
|
||||
|
||||
/**
|
||||
* 列类型
|
||||
*/
|
||||
private String columnType;
|
||||
|
||||
/**
|
||||
* 字段长度
|
||||
*/
|
||||
private String columnLength;
|
||||
|
||||
/**
|
||||
* 字段名称
|
||||
*/
|
||||
@@ -46,7 +52,7 @@ public class GenFieldConfig extends BaseEntity {
|
||||
/**
|
||||
* 字段描述
|
||||
*/
|
||||
private String fieldComment;
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* 表单类型
|
||||
@@ -61,22 +67,22 @@ public class GenFieldConfig extends BaseEntity {
|
||||
/**
|
||||
* 是否在列表显示
|
||||
*/
|
||||
private Boolean isShowInList;
|
||||
private Integer isShowInList;
|
||||
|
||||
/**
|
||||
* 是否在表单显示
|
||||
*/
|
||||
private Boolean isShowInForm;
|
||||
private Integer isShowInForm;
|
||||
|
||||
/**
|
||||
* 是否在查询条件显示
|
||||
*/
|
||||
private Boolean isShowInQuery;
|
||||
private Integer isShowInQuery;
|
||||
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
private Boolean isRequired;
|
||||
private Integer isRequired;
|
||||
|
||||
|
||||
}
|
||||
@@ -17,11 +17,6 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
public class SysDept extends BaseEntity {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
|
||||
@@ -14,11 +14,6 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class SysDict extends BaseEntity {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 类型名称
|
||||
|
||||
@@ -9,52 +9,64 @@ import java.util.List;
|
||||
|
||||
@Schema(description = "代码生成配置表单")
|
||||
@Data
|
||||
public class GenCodeConfigForm {
|
||||
public class GenConfigForm {
|
||||
|
||||
@Schema(description = "表名")
|
||||
private String tableName;
|
||||
|
||||
@Schema(description = "实体名")
|
||||
private String entityName;
|
||||
|
||||
@Schema(description = "包名")
|
||||
private String packageName;
|
||||
@Schema(description = "类描述")
|
||||
private String comment;
|
||||
|
||||
@Schema(description = "模块名")
|
||||
private String moduleName;
|
||||
|
||||
@Schema(description = "包名")
|
||||
private String packageName;
|
||||
|
||||
@Schema(description = "实体名")
|
||||
private String entityName;
|
||||
|
||||
@Schema(description = "作者")
|
||||
private String author;
|
||||
|
||||
@Schema(description = "字段配置")
|
||||
@Schema(description = "字段配置列表")
|
||||
private List<FieldConfig> fieldConfigs;
|
||||
|
||||
@Schema(description = "字段配置")
|
||||
@Data
|
||||
public static class FieldConfig {
|
||||
|
||||
@Schema(description = "字段名称")
|
||||
private String name;
|
||||
@Schema(description = "列名")
|
||||
private String columnName;
|
||||
|
||||
@Schema(description = "列类型")
|
||||
private String columnType;
|
||||
|
||||
@Schema(description = "字段名")
|
||||
private String fieldName;
|
||||
|
||||
@Schema(description = "字段类型")
|
||||
private String type;
|
||||
private String fieldType;
|
||||
|
||||
@Schema(description = "字段描述")
|
||||
private String description;
|
||||
private String comment;
|
||||
|
||||
@Schema(description = "是否在列表显示")
|
||||
private Boolean showInList;
|
||||
private Integer isShowInList;
|
||||
|
||||
@Schema(description = "是否在表单显示")
|
||||
private Boolean showInForm;
|
||||
private Integer isShowInForm;
|
||||
|
||||
@Schema(description = "是否在查询条件显示")
|
||||
private Boolean showInQuery;
|
||||
private Integer isShowInQuery;
|
||||
|
||||
@Schema(description = "是否必填")
|
||||
private Integer isRequired;
|
||||
|
||||
@Schema(description = "表单类型")
|
||||
private FormTypeEnum formType;
|
||||
|
||||
@Schema(description = "查询方式")
|
||||
@Schema(description = "查询类型")
|
||||
private QueryTypeEnum queryType;
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.youlai.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.system.model.form.GenCodeConfigForm;
|
||||
import com.youlai.system.model.form.GenConfigForm;
|
||||
import com.youlai.system.model.query.TablePageQuery;
|
||||
import com.youlai.system.model.vo.TableColumnVO;
|
||||
import com.youlai.system.model.vo.GeneratorPreviewVO;
|
||||
@@ -48,7 +48,7 @@ public interface GeneratorService {
|
||||
* @param tableName 表名
|
||||
* @return
|
||||
*/
|
||||
GenCodeConfigForm getGenCodeConfig(String tableName);
|
||||
GenConfigForm getGenConfig(String tableName);
|
||||
|
||||
/**
|
||||
* 保存代码生成配置
|
||||
@@ -56,5 +56,5 @@ public interface GeneratorService {
|
||||
* @param formData 表单数据
|
||||
* @return
|
||||
*/
|
||||
boolean saveGenCodeConfig(GenCodeConfigForm formData);
|
||||
boolean saveGenCodeConfig(GenConfigForm formData);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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;
|
||||
@@ -17,7 +16,7 @@ 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.GenCodeConfigForm;
|
||||
import com.youlai.system.model.form.GenConfigForm;
|
||||
import com.youlai.system.model.query.TablePageQuery;
|
||||
import com.youlai.system.model.vo.TableColumnVO;
|
||||
import com.youlai.system.model.vo.GeneratorPreviewVO;
|
||||
@@ -75,17 +74,35 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
return databaseMapper.getTableColumns(tableName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取代码生成配置
|
||||
*
|
||||
* @param tableName 表名 eg: sys_user
|
||||
* @return 代码生成配置
|
||||
*/
|
||||
@Override
|
||||
public GenCodeConfigForm getGenCodeConfig(String tableName) {
|
||||
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();
|
||||
|
||||
genConfigMapper.selectOne(new LambdaQueryWrapper<>(GenConfig.class).eq(GenConfig::getTableName, tableName));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveGenCodeConfig(GenCodeConfigForm formData) {
|
||||
public boolean saveGenCodeConfig(GenConfigForm formData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -107,7 +124,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
Assert.isTrue(genConfig != null, "未找到表生成配置");
|
||||
|
||||
List<GenFieldConfig> fieldConfigs = genFieldConfigMapper.selectList(new LambdaQueryWrapper<GenFieldConfig>()
|
||||
.eq(GenFieldConfig::getConfigId, genConfig.getId())
|
||||
.eq(GenFieldConfig::getGenConfigId, genConfig.getId())
|
||||
);
|
||||
Assert.isTrue(CollectionUtil.isNotEmpty(fieldConfigs), "未找到字段生成配置");
|
||||
|
||||
@@ -153,8 +170,6 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private String getFileName(String entityName, String templateName, String extension) {
|
||||
if (templateName.equals("Entity")) {
|
||||
return entityName + extension;
|
||||
@@ -162,8 +177,8 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
if (templateName.equals("MapperXml")) {
|
||||
return entityName + "Mapper" + extension;
|
||||
}
|
||||
if (templateName.equals("API")|| templateName.equals("VIEW")) {
|
||||
return StrUtil.toSymbolCase(entityName,'-') + extension;
|
||||
if (templateName.equals("API") || templateName.equals("VIEW")) {
|
||||
return StrUtil.toSymbolCase(entityName, '-') + extension;
|
||||
}
|
||||
return entityName + templateName + extension;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
return deptList.stream()
|
||||
.filter(dept -> dept.getParentId().equals(parentId))
|
||||
.map(dept -> {
|
||||
DeptVO deptVO = deptConverter.convertToVo(dept);
|
||||
DeptVO deptVO = deptConverter.toVo(dept);
|
||||
List<DeptVO> children = recurDeptList(dept.getId(), deptList);
|
||||
deptVO.setChildren(children);
|
||||
return deptVO;
|
||||
|
||||
Reference in New Issue
Block a user