完成树表重构“代码生成”模块,支持mybatis-flex

This commit is contained in:
dataprince 2023-11-23 11:16:35 +08:00
parent faebcb7a6a
commit 630881c1d7
10 changed files with 52 additions and 246 deletions

View File

@ -45,7 +45,8 @@ public class GenConstants
"bit", "bigint", "float", "double", "decimal" }; "bit", "bigint", "float", "double", "decimal" };
/** 页面不需要编辑字段 */ /** 页面不需要编辑字段 */
public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" }; public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "update_by",
"update_time","del_flag" };
/** 页面不需要显示的列表字段 */ /** 页面不需要显示的列表字段 */
public static final String[] COLUMNNAME_NOT_LIST = { "id", "create_by", "create_time", "del_flag", "update_by", public static final String[] COLUMNNAME_NOT_LIST = { "id", "create_by", "create_time", "del_flag", "update_by",
@ -56,7 +57,7 @@ public class GenConstants
"update_time", "remark" }; "update_time", "remark" };
/** Entity基类字段 */ /** Entity基类字段 */
public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" }; public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime"};
/** Tree基类字段 */ /** Tree基类字段 */
public static final String[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors", "children" }; public static final String[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors", "children" };

View File

@ -2,6 +2,7 @@ package com.ruoyi.common.orm.core.domain;
import com.mybatisflex.annotation.Column; import com.mybatisflex.annotation.Column;
import java.io.Serial;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -12,6 +13,7 @@ import java.util.List;
*/ */
public class TreeEntity extends BaseEntity public class TreeEntity extends BaseEntity
{ {
@Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 父菜单名称 */ /** 父菜单名称 */
@ -22,7 +24,6 @@ public class TreeEntity extends BaseEntity
private Long parentId; private Long parentId;
/** 显示顺序 */ /** 显示顺序 */
@Column(ignore = true)
private Integer orderNum; private Integer orderNum;
/** 祖级列表 */ /** 祖级列表 */
@ -31,7 +32,7 @@ public class TreeEntity extends BaseEntity
/** 子部门 */ /** 子部门 */
@Column(ignore = true) @Column(ignore = true)
private List<?> children = new ArrayList<>(); private List<Object> children = new ArrayList<>();
public String getParentName() public String getParentName()
{ {
@ -73,12 +74,12 @@ public class TreeEntity extends BaseEntity
this.ancestors = ancestors; this.ancestors = ancestors;
} }
public List<?> getChildren() public List<Object> getChildren()
{ {
return children; return children;
} }
public void setChildren(List<?> children) public void setChildren(List<Object> children)
{ {
this.children = children; this.children = children;
} }

View File

@ -335,7 +335,7 @@ public class GenTableColumn extends BaseEntity
{ {
return StringUtils.equalsAnyIgnoreCase(javaField, return StringUtils.equalsAnyIgnoreCase(javaField,
// BaseEntity // BaseEntity
"createBy", "createTime", "updateBy", "updateTime", "remark", "createBy", "createTime", "updateBy", "updateTime",
// TreeEntity // TreeEntity
"parentName", "parentId", "orderNum", "ancestors"); "parentName", "parentId", "orderNum", "ancestors");
} }
@ -348,7 +348,7 @@ public class GenTableColumn extends BaseEntity
public static boolean isUsableColumn(String javaField) public static boolean isUsableColumn(String javaField)
{ {
// isSuperColumn()中的名单用于避免生成多余Domain属性若某些属性在生成页面时需要用到不能忽略则放在此处白名单 // isSuperColumn()中的名单用于避免生成多余Domain属性若某些属性在生成页面时需要用到不能忽略则放在此处白名单
return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum");
} }
public String readConverterExp() public String readConverterExp()

View File

@ -87,7 +87,7 @@ public class GenUtils
} }
// 编辑字段 // 编辑字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName))
{ {
column.setIsEdit(GenConstants.REQUIRE); column.setIsEdit(GenConstants.REQUIRE);
} }
@ -114,7 +114,7 @@ public class GenUtils
} }
// 类型&性别字段设置下拉框 // 类型&性别字段设置下拉框
else if (StringUtils.endsWithIgnoreCase(columnName, "type") else if (StringUtils.endsWithIgnoreCase(columnName, "type")
|| StringUtils.endsWithIgnoreCase(columnName, "sex")) || StringUtils.endsWithIgnoreCase(columnName, "gender"))
{ {
column.setHtmlType(GenConstants.HTML_SELECT); column.setHtmlType(GenConstants.HTML_SELECT);
} }

View File

@ -1,7 +1,6 @@
package ${packageName}.domain.bo; package ${packageName}.domain.bo;
import ${packageName}.domain.${ClassName}; import ${packageName}.domain.${ClassName};
import com.ruoyi.common.orm.core.domain.BaseEntity;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -9,6 +8,11 @@ import jakarta.validation.constraints.*;
#foreach ($import in $importList) #foreach ($import in $importList)
import ${import}; import ${import};
#end #end
#if($table.crud || $table.sub)
import com.ruoyi.common.orm.core.domain.BaseEntity;
#elseif($table.tree)
import com.ruoyi.common.orm.core.domain.TreeEntity;
#end
/** /**
* ${functionName}业务对象 ${tableName} * ${functionName}业务对象 ${tableName}
@ -16,10 +20,16 @@ import ${import};
* @author ${author} * @author ${author}
* @date ${datetime} * @date ${datetime}
*/ */
#if($table.crud || $table.sub)
#set($Entity="BaseEntity")
#elseif($table.tree)
#set($Entity="TreeEntity")
#end
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@AutoMapper(target = ${ClassName}.class, reverseConvertGenerate = false) @AutoMapper(target = ${ClassName}.class, reverseConvertGenerate = false)
public class ${ClassName}Bo extends BaseEntity { public class ${ClassName}Bo extends ${Entity}
{
#foreach ($column in $columns) #foreach ($column in $columns)
#if(!$table.isSuperColumn($column.javaField) && ($column.query || $column.insert || $column.edit)) #if(!$table.isSuperColumn($column.javaField) && ($column.query || $column.insert || $column.edit))

View File

@ -10,6 +10,7 @@ import lombok.EqualsAndHashCode;
#if($table.crud || $table.sub) #if($table.crud || $table.sub)
import com.ruoyi.common.orm.core.domain.BaseEntity; import com.ruoyi.common.orm.core.domain.BaseEntity;
#elseif($table.tree) #elseif($table.tree)
import com.ruoyi.common.orm.core.domain.TreeEntity;
#end #end
/** /**

View File

@ -10,6 +10,7 @@ import com.ruoyi.common.excel.annotation.ExcelDictFormat;
import com.ruoyi.common.excel.convert.ExcelDictConvert; import com.ruoyi.common.excel.convert.ExcelDictConvert;
import io.github.linpeilie.annotations.AutoMapper; import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
@ -17,19 +18,25 @@ import java.util.Date;
#if($table.crud || $table.sub) #if($table.crud || $table.sub)
import com.ruoyi.common.orm.core.domain.BaseEntity; import com.ruoyi.common.orm.core.domain.BaseEntity;
#elseif($table.tree) #elseif($table.tree)
import com.ruoyi.common.orm.core.domain.TreeEntity;
#end #end
/** /**
* ${functionName}视图对象 ${tableName} * ${functionName}视图对象 ${tableName}
* *
* @author ${author} * @author ${author}
* @date ${datetime} * @date ${datetime}
*/ */
#if($table.crud || $table.sub)
#set($Entity="BaseEntity")
#elseif($table.tree)
#set($Entity="TreeEntity")
#end
@Data @Data
@ExcelIgnoreUnannotated @ExcelIgnoreUnannotated
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = ${ClassName}.class) @AutoMapper(target = ${ClassName}.class)
public class ${ClassName}Vo extends BaseEntity implements Serializable public class ${ClassName}Vo extends ${Entity} implements Serializable
{ {
@Serial @Serial

View File

@ -84,6 +84,15 @@
@click="toggleExpandAll" @click="toggleExpandAll"
>展开/折叠</el-button> >展开/折叠</el-button>
</el-col> </el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="Download"
@click="handleExport"
v-hasPermi="['${moduleName}:${businessName}:export']"
>导出</el-button>
</el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
@ -472,5 +481,12 @@ function handleDelete(row) {
}).catch(() => {}); }).catch(() => {});
} }
/** 导出按钮操作 */
function handleExport() {
proxy.download('${moduleName}/${businessName}/export', {
...queryParams.value
}, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
}
getList(); getList();
</script> </script>

View File

@ -1,20 +1,13 @@
package com.ruoyi.system.domain; package com.ruoyi.system.domain;
import java.io.Serial;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.mybatisflex.annotation.Column; import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.Table;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.orm.core.domain.BaseEntity; import com.ruoyi.common.orm.core.domain.BaseEntity;
/** /**
@ -64,151 +57,5 @@ public class SysDept extends BaseEntity
private String parentName; private String parentName;
/** 子部门 */ /** 子部门 */
private List<SysDept> children = new ArrayList<SysDept>(); private List<SysDept> children = new ArrayList<>();
// public Long getDeptId()
// {
// return deptId;
// }
//
// public void setDeptId(Long deptId)
// {
// this.deptId = deptId;
// }
//
// public Long getParentId()
// {
// return parentId;
// }
//
// public void setParentId(Long parentId)
// {
// this.parentId = parentId;
// }
//
// public String getAncestors()
// {
// return ancestors;
// }
//
// public void setAncestors(String ancestors)
// {
// this.ancestors = ancestors;
// }
//
// @NotBlank(message = "部门名称不能为空")
// @Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符")
// public String getDeptName()
// {
// return deptName;
// }
//
// public void setDeptName(String deptName)
// {
// this.deptName = deptName;
// }
//
// @NotBlank(message = "显示顺序不能为空")
// public String getOrderNum()
// {
// return orderNum;
// }
//
// public void setOrderNum(String orderNum)
// {
// this.orderNum = orderNum;
// }
//
// public String getLeader()
// {
// return leader;
// }
//
// public void setLeader(String leader)
// {
// this.leader = leader;
// }
//
// @Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符")
// public String getPhone()
// {
// return phone;
// }
//
// public void setPhone(String phone)
// {
// this.phone = phone;
// }
//
// @Email(message = "邮箱格式不正确")
// @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
// public String getEmail()
// {
// return email;
// }
//
// public void setEmail(String email)
// {
// this.email = email;
// }
//
// public String getStatus()
// {
// return status;
// }
//
// public void setStatus(String status)
// {
// this.status = status;
// }
//
// public String getDelFlag()
// {
// return delFlag;
// }
//
// public void setDelFlag(String delFlag)
// {
// this.delFlag = delFlag;
// }
//
// public String getParentName()
// {
// return parentName;
// }
//
// public void setParentName(String parentName)
// {
// this.parentName = parentName;
// }
//
// public List<SysDept> getChildren()
// {
// return children;
// }
//
// public void setChildren(List<SysDept> children)
// {
// this.children = children;
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
// .append("deptId", getDeptId())
// .append("parentId", getParentId())
// .append("ancestors", getAncestors())
// .append("deptName", getDeptName())
// .append("orderNum", getOrderNum())
// .append("leader", getLeader())
// .append("phone", getPhone())
// .append("email", getEmail())
// .append("status", getStatus())
// .append("delFlag", getDelFlag())
// .append("createBy", getCreateBy())
// .append("createTime", getCreateTime())
// .append("updateBy", getUpdateBy())
// .append("updateTime", getUpdateTime())
// .toString();
// }
} }

View File

@ -1,77 +0,0 @@
package com.ruoyi.system.domain;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonInclude;
/**
* Treeselect树结构实体类
*
* @author ruoyi
*/
public class TreeSelect implements Serializable
{
@Serial
private static final long serialVersionUID = 1L;
/** 节点ID */
private Long id;
/** 节点名称 */
private String label;
/** 子节点 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeSelect> children;
public TreeSelect()
{
}
public TreeSelect(SysDept dept)
{
this.id = dept.getDeptId();
this.label = dept.getDeptName();
this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
public TreeSelect(SysMenu menu)
{
this.id = menu.getMenuId();
this.label = menu.getMenuName();
this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public String getLabel()
{
return label;
}
public void setLabel(String label)
{
this.label = label;
}
public List<TreeSelect> getChildren()
{
return children;
}
public void setChildren(List<TreeSelect> children)
{
this.children = children;
}
}