mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 07:19:46 +08:00
update mp化
This commit is contained in:
@ -4,13 +4,13 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.constant.GenConstants;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -18,7 +18,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 业务表 gen_table
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
|
||||
@ -26,75 +26,110 @@ import java.util.Map;
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@TableName("gen_table")
|
||||
public class GenTable
|
||||
{
|
||||
public class GenTable implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 编号 */
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId(value = "table_id", type = IdType.AUTO)
|
||||
private Long tableId;
|
||||
|
||||
/** 表名称 */
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
@NotBlank(message = "表名称不能为空")
|
||||
private String tableName;
|
||||
|
||||
/** 表描述 */
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
@NotBlank(message = "表描述不能为空")
|
||||
private String tableComment;
|
||||
|
||||
/** 关联父表的表名 */
|
||||
/**
|
||||
* 关联父表的表名
|
||||
*/
|
||||
private String subTableName;
|
||||
|
||||
/** 本表关联父表的外键名 */
|
||||
/**
|
||||
* 本表关联父表的外键名
|
||||
*/
|
||||
private String subTableFkName;
|
||||
|
||||
/** 实体类名称(首字母大写) */
|
||||
/**
|
||||
* 实体类名称(首字母大写)
|
||||
*/
|
||||
@NotBlank(message = "实体类名称不能为空")
|
||||
private String className;
|
||||
|
||||
/** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */
|
||||
/**
|
||||
* 使用的模板(crud单表操作 tree树表操作 sub主子表操作)
|
||||
*/
|
||||
private String tplCategory;
|
||||
|
||||
/** 生成包路径 */
|
||||
/**
|
||||
* 生成包路径
|
||||
*/
|
||||
@NotBlank(message = "生成包路径不能为空")
|
||||
private String packageName;
|
||||
|
||||
/** 生成模块名 */
|
||||
/**
|
||||
* 生成模块名
|
||||
*/
|
||||
@NotBlank(message = "生成模块名不能为空")
|
||||
private String moduleName;
|
||||
|
||||
/** 生成业务名 */
|
||||
/**
|
||||
* 生成业务名
|
||||
*/
|
||||
@NotBlank(message = "生成业务名不能为空")
|
||||
private String businessName;
|
||||
|
||||
/** 生成功能名 */
|
||||
/**
|
||||
* 生成功能名
|
||||
*/
|
||||
@NotBlank(message = "生成功能名不能为空")
|
||||
private String functionName;
|
||||
|
||||
/** 生成作者 */
|
||||
/**
|
||||
* 生成作者
|
||||
*/
|
||||
@NotBlank(message = "作者不能为空")
|
||||
private String functionAuthor;
|
||||
|
||||
/** 生成代码方式(0zip压缩包 1自定义路径) */
|
||||
/**
|
||||
* 生成代码方式(0zip压缩包 1自定义路径)
|
||||
*/
|
||||
private String genType;
|
||||
|
||||
/** 生成路径(不填默认项目路径) */
|
||||
/**
|
||||
* 生成路径(不填默认项目路径)
|
||||
*/
|
||||
private String genPath;
|
||||
|
||||
/** 主键信息 */
|
||||
/**
|
||||
* 主键信息
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private GenTableColumn pkColumn;
|
||||
|
||||
/** 子表信息 */
|
||||
/**
|
||||
* 子表信息
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private GenTable subTable;
|
||||
|
||||
/** 表列信息 */
|
||||
/**
|
||||
* 表列信息
|
||||
*/
|
||||
@Valid
|
||||
@TableField(exist = false)
|
||||
private List<GenTableColumn> columns;
|
||||
|
||||
/** 其它生成选项 */
|
||||
/**
|
||||
* 其它生成选项
|
||||
*/
|
||||
private String options;
|
||||
|
||||
/**
|
||||
@ -132,65 +167,66 @@ public class GenTable
|
||||
@TableField(exist = false)
|
||||
private Map<String, Object> params = new HashMap<>();
|
||||
|
||||
/** 树编码字段 */
|
||||
/**
|
||||
* 树编码字段
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String treeCode;
|
||||
|
||||
/** 树父编码字段 */
|
||||
/**
|
||||
* 树父编码字段
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String treeParentCode;
|
||||
|
||||
/** 树名称字段 */
|
||||
/**
|
||||
* 树名称字段
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String treeName;
|
||||
|
||||
/** 上级菜单ID字段 */
|
||||
/**
|
||||
* 上级菜单ID字段
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String parentMenuId;
|
||||
|
||||
/** 上级菜单名称字段 */
|
||||
/**
|
||||
* 上级菜单名称字段
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String parentMenuName;
|
||||
|
||||
public boolean isSub()
|
||||
{
|
||||
public boolean isSub() {
|
||||
return isSub(this.tplCategory);
|
||||
}
|
||||
|
||||
public static boolean isSub(String tplCategory)
|
||||
{
|
||||
public static boolean isSub(String tplCategory) {
|
||||
return tplCategory != null && StrUtil.equals(GenConstants.TPL_SUB, tplCategory);
|
||||
}
|
||||
|
||||
public boolean isTree()
|
||||
{
|
||||
public boolean isTree() {
|
||||
return isTree(this.tplCategory);
|
||||
}
|
||||
|
||||
public static boolean isTree(String tplCategory)
|
||||
{
|
||||
public static boolean isTree(String tplCategory) {
|
||||
return tplCategory != null && StrUtil.equals(GenConstants.TPL_TREE, tplCategory);
|
||||
}
|
||||
|
||||
public boolean isCrud()
|
||||
{
|
||||
public boolean isCrud() {
|
||||
return isCrud(this.tplCategory);
|
||||
}
|
||||
|
||||
public static boolean isCrud(String tplCategory)
|
||||
{
|
||||
public static boolean isCrud(String tplCategory) {
|
||||
return tplCategory != null && StrUtil.equals(GenConstants.TPL_CRUD, tplCategory);
|
||||
}
|
||||
|
||||
public boolean isSuperColumn(String javaField)
|
||||
{
|
||||
public boolean isSuperColumn(String javaField) {
|
||||
return isSuperColumn(this.tplCategory, javaField);
|
||||
}
|
||||
|
||||
public static boolean isSuperColumn(String tplCategory, String javaField)
|
||||
{
|
||||
if (isTree(tplCategory))
|
||||
{
|
||||
public static boolean isSuperColumn(String tplCategory, String javaField) {
|
||||
if (isTree(tplCategory)) {
|
||||
return StrUtil.equalsAnyIgnoreCase(javaField,
|
||||
ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY));
|
||||
}
|
||||
|
@ -3,19 +3,18 @@ package com.ruoyi.generator.domain;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 代码生成业务字段表 gen_table_column
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
|
||||
@ -23,64 +22,99 @@ import java.util.Map;
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@TableName("gen_table_column")
|
||||
public class GenTableColumn extends BaseEntity
|
||||
{
|
||||
public class GenTableColumn implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 编号 */
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
@TableId(value = "column_id", type = IdType.AUTO)
|
||||
private Long columnId;
|
||||
|
||||
/** 归属表编号 */
|
||||
/**
|
||||
* 归属表编号
|
||||
*/
|
||||
private Long tableId;
|
||||
|
||||
/** 列名称 */
|
||||
/**
|
||||
* 列名称
|
||||
*/
|
||||
private String columnName;
|
||||
|
||||
/** 列描述 */
|
||||
/**
|
||||
* 列描述
|
||||
*/
|
||||
private String columnComment;
|
||||
|
||||
/** 列类型 */
|
||||
/**
|
||||
* 列类型
|
||||
*/
|
||||
private String columnType;
|
||||
|
||||
/** JAVA类型 */
|
||||
/**
|
||||
* JAVA类型
|
||||
*/
|
||||
private String javaType;
|
||||
|
||||
/** JAVA字段名 */
|
||||
/**
|
||||
* JAVA字段名
|
||||
*/
|
||||
@NotBlank(message = "Java属性不能为空")
|
||||
private String javaField;
|
||||
|
||||
/** 是否主键(1是) */
|
||||
/**
|
||||
* 是否主键(1是)
|
||||
*/
|
||||
private String isPk;
|
||||
|
||||
/** 是否自增(1是) */
|
||||
/**
|
||||
* 是否自增(1是)
|
||||
*/
|
||||
private String isIncrement;
|
||||
|
||||
/** 是否必填(1是) */
|
||||
/**
|
||||
* 是否必填(1是)
|
||||
*/
|
||||
private String isRequired;
|
||||
|
||||
/** 是否为插入字段(1是) */
|
||||
/**
|
||||
* 是否为插入字段(1是)
|
||||
*/
|
||||
private String isInsert;
|
||||
|
||||
/** 是否编辑字段(1是) */
|
||||
/**
|
||||
* 是否编辑字段(1是)
|
||||
*/
|
||||
private String isEdit;
|
||||
|
||||
/** 是否列表字段(1是) */
|
||||
/**
|
||||
* 是否列表字段(1是)
|
||||
*/
|
||||
private String isList;
|
||||
|
||||
/** 是否查询字段(1是) */
|
||||
/**
|
||||
* 是否查询字段(1是)
|
||||
*/
|
||||
private String isQuery;
|
||||
|
||||
/** 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) */
|
||||
/**
|
||||
* 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围)
|
||||
*/
|
||||
private String queryType;
|
||||
|
||||
/** 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件) */
|
||||
/**
|
||||
* 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件)
|
||||
*/
|
||||
private String htmlType;
|
||||
|
||||
/** 字典类型 */
|
||||
/**
|
||||
* 字典类型
|
||||
*/
|
||||
private String dictType;
|
||||
|
||||
/** 排序 */
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
@ -113,88 +147,71 @@ public class GenTableColumn extends BaseEntity
|
||||
@TableField(exist = false)
|
||||
private Map<String, Object> params = new HashMap<>();
|
||||
|
||||
public String getCapJavaField()
|
||||
{
|
||||
public String getCapJavaField() {
|
||||
return StrUtil.upperFirst(javaField);
|
||||
}
|
||||
|
||||
public boolean isPk()
|
||||
{
|
||||
public boolean isPk() {
|
||||
return isPk(this.isPk);
|
||||
}
|
||||
|
||||
public boolean isPk(String isPk)
|
||||
{
|
||||
public boolean isPk(String isPk) {
|
||||
return isPk != null && StrUtil.equals("1", isPk);
|
||||
}
|
||||
|
||||
public boolean isIncrement()
|
||||
{
|
||||
public boolean isIncrement() {
|
||||
return isIncrement(this.isIncrement);
|
||||
}
|
||||
|
||||
public boolean isIncrement(String isIncrement)
|
||||
{
|
||||
public boolean isIncrement(String isIncrement) {
|
||||
return isIncrement != null && StrUtil.equals("1", isIncrement);
|
||||
}
|
||||
|
||||
public boolean isRequired()
|
||||
{
|
||||
public boolean isRequired() {
|
||||
return isRequired(this.isRequired);
|
||||
}
|
||||
|
||||
public boolean isRequired(String isRequired)
|
||||
{
|
||||
public boolean isRequired(String isRequired) {
|
||||
return isRequired != null && StrUtil.equals("1", isRequired);
|
||||
}
|
||||
|
||||
public boolean isInsert()
|
||||
{
|
||||
public boolean isInsert() {
|
||||
return isInsert(this.isInsert);
|
||||
}
|
||||
|
||||
public boolean isInsert(String isInsert)
|
||||
{
|
||||
public boolean isInsert(String isInsert) {
|
||||
return isInsert != null && StrUtil.equals("1", isInsert);
|
||||
}
|
||||
|
||||
public boolean isEdit()
|
||||
{
|
||||
public boolean isEdit() {
|
||||
return isInsert(this.isEdit);
|
||||
}
|
||||
|
||||
public boolean isEdit(String isEdit)
|
||||
{
|
||||
public boolean isEdit(String isEdit) {
|
||||
return isEdit != null && StrUtil.equals("1", isEdit);
|
||||
}
|
||||
|
||||
public boolean isList()
|
||||
{
|
||||
public boolean isList() {
|
||||
return isList(this.isList);
|
||||
}
|
||||
|
||||
public boolean isList(String isList)
|
||||
{
|
||||
public boolean isList(String isList) {
|
||||
return isList != null && StrUtil.equals("1", isList);
|
||||
}
|
||||
|
||||
public boolean isQuery()
|
||||
{
|
||||
public boolean isQuery() {
|
||||
return isQuery(this.isQuery);
|
||||
}
|
||||
|
||||
public boolean isQuery(String isQuery)
|
||||
{
|
||||
public boolean isQuery(String isQuery) {
|
||||
return isQuery != null && StrUtil.equals("1", isQuery);
|
||||
}
|
||||
|
||||
public boolean isSuperColumn()
|
||||
{
|
||||
public boolean isSuperColumn() {
|
||||
return isSuperColumn(this.javaField);
|
||||
}
|
||||
|
||||
public static boolean isSuperColumn(String javaField)
|
||||
{
|
||||
public static boolean isSuperColumn(String javaField) {
|
||||
return StrUtil.equalsAnyIgnoreCase(javaField,
|
||||
// BaseEntity
|
||||
"createBy", "createTime", "updateBy", "updateTime", "remark",
|
||||
@ -202,36 +219,28 @@ public class GenTableColumn extends BaseEntity
|
||||
"parentName", "parentId", "orderNum", "ancestors");
|
||||
}
|
||||
|
||||
public boolean isUsableColumn()
|
||||
{
|
||||
public boolean isUsableColumn() {
|
||||
return isUsableColumn(javaField);
|
||||
}
|
||||
|
||||
public static boolean isUsableColumn(String javaField)
|
||||
{
|
||||
public static boolean isUsableColumn(String javaField) {
|
||||
// isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单
|
||||
return StrUtil.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
|
||||
}
|
||||
|
||||
public String readConverterExp()
|
||||
{
|
||||
public String readConverterExp() {
|
||||
String remarks = StrUtil.subBetween(this.columnComment, "(", ")");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (StrUtil.isNotEmpty(remarks))
|
||||
{
|
||||
for (String value : remarks.split(" "))
|
||||
{
|
||||
if (StrUtil.isNotEmpty(value))
|
||||
{
|
||||
if (StrUtil.isNotEmpty(remarks)) {
|
||||
for (String value : remarks.split(" ")) {
|
||||
if (StrUtil.isNotEmpty(value)) {
|
||||
Object startStr = value.subSequence(0, 1);
|
||||
String endStr = value.substring(1);
|
||||
sb.append("").append(startStr).append("=").append(endStr).append(",");
|
||||
}
|
||||
}
|
||||
return sb.deleteCharAt(sb.length() - 1).toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return this.columnComment;
|
||||
}
|
||||
}
|
||||
|
@ -7,56 +7,16 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 数据层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface GenTableColumnMapper extends BaseMapper<GenTableColumn>
|
||||
{
|
||||
public interface GenTableColumnMapper extends BaseMapper<GenTableColumn> {
|
||||
/**
|
||||
* 根据表名称查询列信息
|
||||
*
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 列信息
|
||||
*/
|
||||
public List<GenTableColumn> selectDbTableColumnsByName(String tableName);
|
||||
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
* @param tableId 业务字段编号
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
|
||||
|
||||
/**
|
||||
* 新增业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 删除业务字段
|
||||
*
|
||||
* @param genTableColumns 列数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGenTableColumns(List<GenTableColumn> genTableColumns);
|
||||
|
||||
/**
|
||||
* 批量删除业务字段
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGenTableColumnByIds(Long[] ids);
|
||||
}
|
||||
|
@ -7,14 +7,13 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务 数据层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface GenTableMapper extends BaseMapper<GenTable>
|
||||
{
|
||||
public interface GenTableMapper extends BaseMapper<GenTable> {
|
||||
/**
|
||||
* 查询业务列表
|
||||
*
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 业务集合
|
||||
*/
|
||||
@ -22,7 +21,7 @@ public interface GenTableMapper extends BaseMapper<GenTable>
|
||||
|
||||
/**
|
||||
* 查询据库列表
|
||||
*
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 数据库表集合
|
||||
*/
|
||||
@ -30,7 +29,7 @@ public interface GenTableMapper extends BaseMapper<GenTable>
|
||||
|
||||
/**
|
||||
* 查询据库列表
|
||||
*
|
||||
*
|
||||
* @param tableNames 表名称组
|
||||
* @return 数据库表集合
|
||||
*/
|
||||
@ -45,7 +44,7 @@ public interface GenTableMapper extends BaseMapper<GenTable>
|
||||
|
||||
/**
|
||||
* 查询表ID业务信息
|
||||
*
|
||||
*
|
||||
* @param id 业务ID
|
||||
* @return 业务信息
|
||||
*/
|
||||
@ -53,33 +52,10 @@ public interface GenTableMapper extends BaseMapper<GenTable>
|
||||
|
||||
/**
|
||||
* 查询表名称业务信息
|
||||
*
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 业务信息
|
||||
*/
|
||||
public GenTable selectGenTableByName(String tableName);
|
||||
|
||||
/**
|
||||
* 新增业务
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertGenTable(GenTable genTable);
|
||||
|
||||
/**
|
||||
* 修改业务
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateGenTable(GenTable genTable);
|
||||
|
||||
/**
|
||||
* 批量删除业务
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGenTableByIds(Long[] ids);
|
||||
}
|
||||
|
@ -1,70 +1,65 @@
|
||||
package com.ruoyi.generator.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.ruoyi.generator.domain.GenTableColumn;
|
||||
import com.ruoyi.generator.mapper.GenTableColumnMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 服务层实现
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService
|
||||
{
|
||||
@Autowired
|
||||
private GenTableColumnMapper genTableColumnMapper;
|
||||
public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn> implements IGenTableColumnService {
|
||||
|
||||
/**
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
*
|
||||
* @param tableId 业务字段编号
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId)
|
||||
{
|
||||
return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
|
||||
return list(new LambdaQueryWrapper<GenTableColumn>()
|
||||
.eq(GenTableColumn::getTableId,tableId)
|
||||
.orderByAsc(GenTableColumn::getSort));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增业务字段
|
||||
*
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn)
|
||||
{
|
||||
return genTableColumnMapper.insertGenTableColumn(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn)
|
||||
{
|
||||
return genTableColumnMapper.updateGenTableColumn(genTableColumn);
|
||||
}
|
||||
@Override
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn) {
|
||||
return baseMapper.insert(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn) {
|
||||
return baseMapper.updateById(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除业务字段对象
|
||||
*
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteGenTableColumnByIds(String ids)
|
||||
{
|
||||
return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
|
||||
}
|
||||
@Override
|
||||
public int deleteGenTableColumnByIds(String ids) {
|
||||
return baseMapper.deleteBatchIds(Arrays.asList(ids.split(",")));
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.constant.GenConstants;
|
||||
@ -18,12 +19,11 @@ import com.ruoyi.generator.mapper.GenTableMapper;
|
||||
import com.ruoyi.generator.util.GenUtils;
|
||||
import com.ruoyi.generator.util.VelocityInitializer;
|
||||
import com.ruoyi.generator.util.VelocityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.Velocity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -32,6 +32,7 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -41,68 +42,60 @@ import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* 业务 服务层实现
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> implements IGenTableService
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private GenTableMapper genTableMapper;
|
||||
public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> implements IGenTableService {
|
||||
|
||||
@Autowired
|
||||
private GenTableColumnMapper genTableColumnMapper;
|
||||
|
||||
/**
|
||||
* 查询业务信息
|
||||
*
|
||||
*
|
||||
* @param id 业务ID
|
||||
* @return 业务信息
|
||||
*/
|
||||
@Override
|
||||
public GenTable selectGenTableById(Long id)
|
||||
{
|
||||
GenTable genTable = genTableMapper.selectGenTableById(id);
|
||||
public GenTable selectGenTableById(Long id) {
|
||||
GenTable genTable = baseMapper.selectGenTableById(id);
|
||||
setTableFromOptions(genTable);
|
||||
return genTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询业务列表
|
||||
*
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 业务集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTable> selectGenTableList(GenTable genTable)
|
||||
{
|
||||
return genTableMapper.selectGenTableList(genTable);
|
||||
public List<GenTable> selectGenTableList(GenTable genTable) {
|
||||
return baseMapper.selectGenTableList(genTable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询据库列表
|
||||
*
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 数据库表集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTable> selectDbTableList(GenTable genTable)
|
||||
{
|
||||
return genTableMapper.selectDbTableList(genTable);
|
||||
public List<GenTable> selectDbTableList(GenTable genTable) {
|
||||
return baseMapper.selectDbTableList(genTable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询据库列表
|
||||
*
|
||||
*
|
||||
* @param tableNames 表名称组
|
||||
* @return 数据库表集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTable> selectDbTableListByNames(String[] tableNames)
|
||||
{
|
||||
return genTableMapper.selectDbTableListByNames(tableNames);
|
||||
public List<GenTable> selectDbTableListByNames(String[] tableNames) {
|
||||
return baseMapper.selectDbTableListByNames(tableNames);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,94 +104,82 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
* @return 表信息集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTable> selectGenTableAll()
|
||||
{
|
||||
return genTableMapper.selectGenTableAll();
|
||||
public List<GenTable> selectGenTableAll() {
|
||||
return baseMapper.selectGenTableAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改业务
|
||||
*
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateGenTable(GenTable genTable)
|
||||
{
|
||||
public void updateGenTable(GenTable genTable) {
|
||||
String options = JSON.toJSONString(genTable.getParams());
|
||||
genTable.setOptions(options);
|
||||
int row = genTableMapper.updateGenTable(genTable);
|
||||
if (row > 0)
|
||||
{
|
||||
for (GenTableColumn cenTableColumn : genTable.getColumns())
|
||||
{
|
||||
genTableColumnMapper.updateGenTableColumn(cenTableColumn);
|
||||
int row = baseMapper.updateById(genTable);
|
||||
if (row > 0) {
|
||||
for (GenTableColumn cenTableColumn : genTable.getColumns()) {
|
||||
genTableColumnMapper.updateById(cenTableColumn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除业务对象
|
||||
*
|
||||
*
|
||||
* @param tableIds 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteGenTableByIds(Long[] tableIds)
|
||||
{
|
||||
genTableMapper.deleteGenTableByIds(tableIds);
|
||||
genTableColumnMapper.deleteGenTableColumnByIds(tableIds);
|
||||
public void deleteGenTableByIds(Long[] tableIds) {
|
||||
List<Long> ids = Arrays.asList(tableIds);
|
||||
removeByIds(ids);
|
||||
genTableColumnMapper.delete(new LambdaQueryWrapper<GenTableColumn>().in(GenTableColumn::getTableId, ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入表结构
|
||||
*
|
||||
*
|
||||
* @param tableList 导入表列表
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void importGenTable(List<GenTable> tableList)
|
||||
{
|
||||
public void importGenTable(List<GenTable> tableList) {
|
||||
String operName = SecurityUtils.getUsername();
|
||||
try
|
||||
{
|
||||
for (GenTable table : tableList)
|
||||
{
|
||||
try {
|
||||
for (GenTable table : tableList) {
|
||||
String tableName = table.getTableName();
|
||||
GenUtils.initTable(table, operName);
|
||||
int row = genTableMapper.insertGenTable(table);
|
||||
if (row > 0)
|
||||
{
|
||||
int row = baseMapper.insert(table);
|
||||
if (row > 0) {
|
||||
// 保存列信息
|
||||
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
||||
for (GenTableColumn column : genTableColumns)
|
||||
{
|
||||
for (GenTableColumn column : genTableColumns) {
|
||||
GenUtils.initColumnField(column, table);
|
||||
genTableColumnMapper.insertGenTableColumn(column);
|
||||
genTableColumnMapper.insert(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw new CustomException("导入失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览代码
|
||||
*
|
||||
*
|
||||
* @param tableId 表编号
|
||||
* @return 预览数据列表
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> previewCode(Long tableId)
|
||||
{
|
||||
public Map<String, String> previewCode(Long tableId) {
|
||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
||||
// 查询表信息
|
||||
GenTable table = genTableMapper.selectGenTableById(tableId);
|
||||
GenTable table = baseMapper.selectGenTableById(tableId);
|
||||
// 设置主子表信息
|
||||
setSubTable(table);
|
||||
// 设置主键列信息
|
||||
@ -209,8 +190,7 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
|
||||
// 获取模板列表
|
||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
||||
for (String template : templates)
|
||||
{
|
||||
for (String template : templates) {
|
||||
// 渲染模板
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||
@ -222,13 +202,12 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
|
||||
/**
|
||||
* 生成代码(下载方式)
|
||||
*
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 数据
|
||||
*/
|
||||
@Override
|
||||
public byte[] downloadCode(String tableName)
|
||||
{
|
||||
public byte[] downloadCode(String tableName) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
generatorCode(tableName, zip);
|
||||
@ -238,14 +217,13 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
|
||||
/**
|
||||
* 生成代码(自定义路径)
|
||||
*
|
||||
*
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@Override
|
||||
public void generatorCode(String tableName)
|
||||
{
|
||||
public void generatorCode(String tableName) {
|
||||
// 查询表信息
|
||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
||||
GenTable table = baseMapper.selectGenTableByName(tableName);
|
||||
// 设置主子表信息
|
||||
setSubTable(table);
|
||||
// 设置主键列信息
|
||||
@ -257,21 +235,16 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
|
||||
// 获取模板列表
|
||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
||||
for (String template : templates)
|
||||
{
|
||||
if (!StrUtil.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm"))
|
||||
{
|
||||
for (String template : templates) {
|
||||
if (!StrUtil.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) {
|
||||
// 渲染模板
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||
tpl.merge(context, sw);
|
||||
try
|
||||
{
|
||||
try {
|
||||
String path = getGenPath(table, template);
|
||||
FileUtils.writeStringToFile(new File(path), sw.toString(), Constants.UTF8);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
throw new CustomException("渲染模板失败,表名:" + table.getTableName());
|
||||
}
|
||||
}
|
||||
@ -280,52 +253,47 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
|
||||
/**
|
||||
* 同步数据库
|
||||
*
|
||||
*
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void synchDb(String tableName)
|
||||
{
|
||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
||||
public void synchDb(String tableName) {
|
||||
GenTable table = baseMapper.selectGenTableByName(tableName);
|
||||
List<GenTableColumn> tableColumns = table.getColumns();
|
||||
List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
|
||||
|
||||
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
||||
if (Validator.isEmpty(dbTableColumns))
|
||||
{
|
||||
if (Validator.isEmpty(dbTableColumns)) {
|
||||
throw new CustomException("同步数据失败,原表结构不存在");
|
||||
}
|
||||
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
|
||||
|
||||
dbTableColumns.forEach(column -> {
|
||||
if (!tableColumnNames.contains(column.getColumnName()))
|
||||
{
|
||||
if (!tableColumnNames.contains(column.getColumnName())) {
|
||||
GenUtils.initColumnField(column, table);
|
||||
genTableColumnMapper.insertGenTableColumn(column);
|
||||
genTableColumnMapper.insert(column);
|
||||
}
|
||||
});
|
||||
|
||||
List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(delColumns))
|
||||
{
|
||||
genTableColumnMapper.deleteGenTableColumns(delColumns);
|
||||
if (CollUtil.isNotEmpty(delColumns)) {
|
||||
List<Long> ids = delColumns.stream().map(GenTableColumn::getColumnId).collect(Collectors.toList());
|
||||
genTableColumnMapper.deleteBatchIds(ids);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量生成代码(下载方式)
|
||||
*
|
||||
*
|
||||
* @param tableNames 表数组
|
||||
* @return 数据
|
||||
*/
|
||||
@Override
|
||||
public byte[] downloadCode(String[] tableNames)
|
||||
{
|
||||
public byte[] downloadCode(String[] tableNames) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||
for (String tableName : tableNames)
|
||||
{
|
||||
for (String tableName : tableNames) {
|
||||
generatorCode(tableName, zip);
|
||||
}
|
||||
IOUtils.closeQuietly(zip);
|
||||
@ -335,10 +303,9 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
/**
|
||||
* 查询表信息并生成代码
|
||||
*/
|
||||
private void generatorCode(String tableName, ZipOutputStream zip)
|
||||
{
|
||||
private void generatorCode(String tableName, ZipOutputStream zip) {
|
||||
// 查询表信息
|
||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
||||
GenTable table = baseMapper.selectGenTableByName(tableName);
|
||||
// 设置主子表信息
|
||||
setSubTable(table);
|
||||
// 设置主键列信息
|
||||
@ -350,23 +317,19 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
|
||||
// 获取模板列表
|
||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
||||
for (String template : templates)
|
||||
{
|
||||
for (String template : templates) {
|
||||
// 渲染模板
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||
tpl.merge(context, sw);
|
||||
try
|
||||
{
|
||||
try {
|
||||
// 添加到zip
|
||||
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
|
||||
IOUtils.write(sw.toString(), zip, Constants.UTF8);
|
||||
IOUtils.closeQuietly(sw);
|
||||
zip.flush();
|
||||
zip.flush();
|
||||
zip.closeEntry();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
log.error("渲染模板失败,表名:" + table.getTableName(), e);
|
||||
}
|
||||
}
|
||||
@ -374,36 +337,24 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
|
||||
/**
|
||||
* 修改保存参数校验
|
||||
*
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
*/
|
||||
@Override
|
||||
public void validateEdit(GenTable genTable)
|
||||
{
|
||||
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
|
||||
{
|
||||
public void validateEdit(GenTable genTable) {
|
||||
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
|
||||
String options = JSON.toJSONString(genTable.getParams());
|
||||
JSONObject paramsObj = JSONObject.parseObject(options);
|
||||
if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
|
||||
{
|
||||
if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) {
|
||||
throw new CustomException("树编码字段不能为空");
|
||||
}
|
||||
else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
|
||||
{
|
||||
} else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) {
|
||||
throw new CustomException("树父编码字段不能为空");
|
||||
}
|
||||
else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_NAME)))
|
||||
{
|
||||
} else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) {
|
||||
throw new CustomException("树名称字段不能为空");
|
||||
}
|
||||
else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
|
||||
{
|
||||
if (Validator.isEmpty(genTable.getSubTableName()))
|
||||
{
|
||||
} else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) {
|
||||
if (Validator.isEmpty(genTable.getSubTableName())) {
|
||||
throw new CustomException("关联子表的表名不能为空");
|
||||
}
|
||||
else if (Validator.isEmpty(genTable.getSubTableFkName()))
|
||||
{
|
||||
} else if (Validator.isEmpty(genTable.getSubTableFkName())) {
|
||||
throw new CustomException("子表关联的外键名不能为空");
|
||||
}
|
||||
}
|
||||
@ -412,35 +363,27 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
|
||||
/**
|
||||
* 设置主键列信息
|
||||
*
|
||||
*
|
||||
* @param table 业务表信息
|
||||
*/
|
||||
public void setPkColumn(GenTable table)
|
||||
{
|
||||
for (GenTableColumn column : table.getColumns())
|
||||
{
|
||||
if (column.isPk())
|
||||
{
|
||||
public void setPkColumn(GenTable table) {
|
||||
for (GenTableColumn column : table.getColumns()) {
|
||||
if (column.isPk()) {
|
||||
table.setPkColumn(column);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Validator.isNull(table.getPkColumn()))
|
||||
{
|
||||
if (Validator.isNull(table.getPkColumn())) {
|
||||
table.setPkColumn(table.getColumns().get(0));
|
||||
}
|
||||
if (GenConstants.TPL_SUB.equals(table.getTplCategory()))
|
||||
{
|
||||
for (GenTableColumn column : table.getSubTable().getColumns())
|
||||
{
|
||||
if (column.isPk())
|
||||
{
|
||||
if (GenConstants.TPL_SUB.equals(table.getTplCategory())) {
|
||||
for (GenTableColumn column : table.getSubTable().getColumns()) {
|
||||
if (column.isPk()) {
|
||||
table.getSubTable().setPkColumn(column);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Validator.isNull(table.getSubTable().getPkColumn()))
|
||||
{
|
||||
if (Validator.isNull(table.getSubTable().getPkColumn())) {
|
||||
table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
|
||||
}
|
||||
}
|
||||
@ -451,31 +394,27 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
*
|
||||
* @param table 业务表信息
|
||||
*/
|
||||
public void setSubTable(GenTable table)
|
||||
{
|
||||
public void setSubTable(GenTable table) {
|
||||
String subTableName = table.getSubTableName();
|
||||
if (Validator.isNotEmpty(subTableName))
|
||||
{
|
||||
table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
|
||||
if (Validator.isNotEmpty(subTableName)) {
|
||||
table.setSubTable(baseMapper.selectGenTableByName(subTableName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置代码生成其他选项值
|
||||
*
|
||||
*
|
||||
* @param genTable 设置后的生成对象
|
||||
*/
|
||||
public void setTableFromOptions(GenTable genTable)
|
||||
{
|
||||
public void setTableFromOptions(GenTable genTable) {
|
||||
JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions());
|
||||
if (Validator.isNotNull(paramsObj))
|
||||
{
|
||||
if (Validator.isNotNull(paramsObj)) {
|
||||
String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
|
||||
String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
|
||||
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
|
||||
String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
|
||||
String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
|
||||
|
||||
|
||||
genTable.setTreeCode(treeCode);
|
||||
genTable.setTreeParentCode(treeParentCode);
|
||||
genTable.setTreeName(treeName);
|
||||
@ -486,16 +425,14 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
|
||||
/**
|
||||
* 获取代码生成地址
|
||||
*
|
||||
* @param table 业务表信息
|
||||
*
|
||||
* @param table 业务表信息
|
||||
* @param template 模板文件路径
|
||||
* @return 生成地址
|
||||
*/
|
||||
public static String getGenPath(GenTable table, String template)
|
||||
{
|
||||
public static String getGenPath(GenTable table, String template) {
|
||||
String genPath = table.getGenPath();
|
||||
if (StrUtil.equals(genPath, "/"))
|
||||
{
|
||||
if (StrUtil.equals(genPath, "/")) {
|
||||
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
|
||||
}
|
||||
return genPath + File.separator + VelocityUtils.getFileName(template, table);
|
||||
|
@ -7,14 +7,13 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 服务层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IGenTableColumnService extends IService<GenTableColumn>
|
||||
{
|
||||
public interface IGenTableColumnService extends IService<GenTableColumn> {
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
*
|
||||
* @param tableId 业务字段编号
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
@ -22,7 +21,7 @@ public interface IGenTableColumnService extends IService<GenTableColumn>
|
||||
|
||||
/**
|
||||
* 新增业务字段
|
||||
*
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@ -30,7 +29,7 @@ public interface IGenTableColumnService extends IService<GenTableColumn>
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@ -38,7 +37,7 @@ public interface IGenTableColumnService extends IService<GenTableColumn>
|
||||
|
||||
/**
|
||||
* 删除业务字段信息
|
||||
*
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -8,14 +8,13 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 业务 服务层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IGenTableService extends IService<GenTable>
|
||||
{
|
||||
public interface IGenTableService extends IService<GenTable> {
|
||||
/**
|
||||
* 查询业务列表
|
||||
*
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 业务集合
|
||||
*/
|
||||
@ -23,7 +22,7 @@ public interface IGenTableService extends IService<GenTable>
|
||||
|
||||
/**
|
||||
* 查询据库列表
|
||||
*
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 数据库表集合
|
||||
*/
|
||||
@ -31,7 +30,7 @@ public interface IGenTableService extends IService<GenTable>
|
||||
|
||||
/**
|
||||
* 查询据库列表
|
||||
*
|
||||
*
|
||||
* @param tableNames 表名称组
|
||||
* @return 数据库表集合
|
||||
*/
|
||||
@ -46,7 +45,7 @@ public interface IGenTableService extends IService<GenTable>
|
||||
|
||||
/**
|
||||
* 查询业务信息
|
||||
*
|
||||
*
|
||||
* @param id 业务ID
|
||||
* @return 业务信息
|
||||
*/
|
||||
@ -54,7 +53,7 @@ public interface IGenTableService extends IService<GenTable>
|
||||
|
||||
/**
|
||||
* 修改业务
|
||||
*
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
* @return 结果
|
||||
*/
|
||||
@ -62,7 +61,7 @@ public interface IGenTableService extends IService<GenTable>
|
||||
|
||||
/**
|
||||
* 删除业务信息
|
||||
*
|
||||
*
|
||||
* @param tableIds 需要删除的表数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@ -70,14 +69,14 @@ public interface IGenTableService extends IService<GenTable>
|
||||
|
||||
/**
|
||||
* 导入表结构
|
||||
*
|
||||
*
|
||||
* @param tableList 导入表列表
|
||||
*/
|
||||
public void importGenTable(List<GenTable> tableList);
|
||||
|
||||
/**
|
||||
* 预览代码
|
||||
*
|
||||
*
|
||||
* @param tableId 表编号
|
||||
* @return 预览数据列表
|
||||
*/
|
||||
@ -85,7 +84,7 @@ public interface IGenTableService extends IService<GenTable>
|
||||
|
||||
/**
|
||||
* 生成代码(下载方式)
|
||||
*
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 数据
|
||||
*/
|
||||
@ -93,7 +92,7 @@ public interface IGenTableService extends IService<GenTable>
|
||||
|
||||
/**
|
||||
* 生成代码(自定义路径)
|
||||
*
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 数据
|
||||
*/
|
||||
@ -101,14 +100,14 @@ public interface IGenTableService extends IService<GenTable>
|
||||
|
||||
/**
|
||||
* 同步数据库
|
||||
*
|
||||
*
|
||||
* @param tableName 表名称
|
||||
*/
|
||||
public void synchDb(String tableName);
|
||||
|
||||
/**
|
||||
* 批量生成代码(下载方式)
|
||||
*
|
||||
*
|
||||
* @param tableNames 表数组
|
||||
* @return 数据
|
||||
*/
|
||||
@ -116,7 +115,7 @@ public interface IGenTableService extends IService<GenTable>
|
||||
|
||||
/**
|
||||
* 修改保存参数校验
|
||||
*
|
||||
*
|
||||
* @param genTable 业务信息
|
||||
*/
|
||||
public void validateEdit(GenTable genTable);
|
||||
|
@ -28,100 +28,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectGenTableColumnVo">
|
||||
select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column
|
||||
</sql>
|
||||
|
||||
<select id="selectGenTableColumnListByTableId" parameterType="Long" resultMap="GenTableColumnResult">
|
||||
<include refid="selectGenTableColumnVo"/>
|
||||
where table_id = #{tableId}
|
||||
order by sort
|
||||
</select>
|
||||
|
||||
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
|
||||
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
|
||||
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
|
||||
order by ordinal_position
|
||||
</select>
|
||||
|
||||
<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
|
||||
insert into gen_table_column (
|
||||
<if test="tableId != null and tableId != ''">table_id,</if>
|
||||
<if test="columnName != null and columnName != ''">column_name,</if>
|
||||
<if test="columnComment != null and columnComment != ''">column_comment,</if>
|
||||
<if test="columnType != null and columnType != ''">column_type,</if>
|
||||
<if test="javaType != null and javaType != ''">java_type,</if>
|
||||
<if test="javaField != null and javaField != ''">java_field,</if>
|
||||
<if test="isPk != null and isPk != ''">is_pk,</if>
|
||||
<if test="isIncrement != null and isIncrement != ''">is_increment,</if>
|
||||
<if test="isRequired != null and isRequired != ''">is_required,</if>
|
||||
<if test="isInsert != null and isInsert != ''">is_insert,</if>
|
||||
<if test="isEdit != null and isEdit != ''">is_edit,</if>
|
||||
<if test="isList != null and isList != ''">is_list,</if>
|
||||
<if test="isQuery != null and isQuery != ''">is_query,</if>
|
||||
<if test="queryType != null and queryType != ''">query_type,</if>
|
||||
<if test="htmlType != null and htmlType != ''">html_type,</if>
|
||||
<if test="dictType != null and dictType != ''">dict_type,</if>
|
||||
<if test="sort != null">sort,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="tableId != null and tableId != ''">#{tableId},</if>
|
||||
<if test="columnName != null and columnName != ''">#{columnName},</if>
|
||||
<if test="columnComment != null and columnComment != ''">#{columnComment},</if>
|
||||
<if test="columnType != null and columnType != ''">#{columnType},</if>
|
||||
<if test="javaType != null and javaType != ''">#{javaType},</if>
|
||||
<if test="javaField != null and javaField != ''">#{javaField},</if>
|
||||
<if test="isPk != null and isPk != ''">#{isPk},</if>
|
||||
<if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
|
||||
<if test="isRequired != null and isRequired != ''">#{isRequired},</if>
|
||||
<if test="isInsert != null and isInsert != ''">#{isInsert},</if>
|
||||
<if test="isEdit != null and isEdit != ''">#{isEdit},</if>
|
||||
<if test="isList != null and isList != ''">#{isList},</if>
|
||||
<if test="isQuery != null and isQuery != ''">#{isQuery},</if>
|
||||
<if test="queryType != null and queryType != ''">#{queryType},</if>
|
||||
<if test="htmlType != null and htmlType != ''">#{htmlType},</if>
|
||||
<if test="dictType != null and dictType != ''">#{dictType},</if>
|
||||
<if test="sort != null">#{sort},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateGenTableColumn" parameterType="GenTableColumn">
|
||||
update gen_table_column
|
||||
<set>
|
||||
column_comment = #{columnComment},
|
||||
java_type = #{javaType},
|
||||
java_field = #{javaField},
|
||||
is_insert = #{isInsert},
|
||||
is_edit = #{isEdit},
|
||||
is_list = #{isList},
|
||||
is_query = #{isQuery},
|
||||
is_required = #{isRequired},
|
||||
query_type = #{queryType},
|
||||
html_type = #{htmlType},
|
||||
dict_type = #{dictType},
|
||||
sort = #{sort},
|
||||
update_by = #{updateBy},
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where column_id = #{columnId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteGenTableColumnByIds" parameterType="Long">
|
||||
delete from gen_table_column where table_id in
|
||||
<foreach collection="array" item="tableId" open="(" separator="," close=")">
|
||||
#{tableId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteGenTableColumns">
|
||||
delete from gen_table_column where column_id in
|
||||
<foreach collection="list" item="item" open="(" separator="," close=")">
|
||||
#{item.columnId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
@ -133,69 +133,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
order by c.sort
|
||||
</select>
|
||||
|
||||
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId">
|
||||
insert into gen_table (
|
||||
<if test="tableName != null">table_name,</if>
|
||||
<if test="tableComment != null and tableComment != ''">table_comment,</if>
|
||||
<if test="className != null and className != ''">class_name,</if>
|
||||
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
|
||||
<if test="packageName != null and packageName != ''">package_name,</if>
|
||||
<if test="moduleName != null and moduleName != ''">module_name,</if>
|
||||
<if test="businessName != null and businessName != ''">business_name,</if>
|
||||
<if test="functionName != null and functionName != ''">function_name,</if>
|
||||
<if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
|
||||
<if test="genType != null and genType != ''">gen_type,</if>
|
||||
<if test="genPath != null and genPath != ''">gen_path,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="tableName != null">#{tableName},</if>
|
||||
<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
|
||||
<if test="className != null and className != ''">#{className},</if>
|
||||
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
|
||||
<if test="packageName != null and packageName != ''">#{packageName},</if>
|
||||
<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
|
||||
<if test="businessName != null and businessName != ''">#{businessName},</if>
|
||||
<if test="functionName != null and functionName != ''">#{functionName},</if>
|
||||
<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
|
||||
<if test="genType != null and genType != ''">#{genType},</if>
|
||||
<if test="genPath != null and genPath != ''">#{genPath},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateGenTable" parameterType="GenTable">
|
||||
update gen_table
|
||||
<set>
|
||||
<if test="tableName != null">table_name = #{tableName},</if>
|
||||
<if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
|
||||
<if test="subTableName != null">sub_table_name = #{subTableName},</if>
|
||||
<if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if>
|
||||
<if test="className != null and className != ''">class_name = #{className},</if>
|
||||
<if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
|
||||
<if test="genType != null and genType != ''">gen_type = #{genType},</if>
|
||||
<if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
|
||||
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
|
||||
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
|
||||
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
|
||||
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
|
||||
<if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
|
||||
<if test="options != null and options != ''">options = #{options},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where table_id = #{tableId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteGenTableByIds" parameterType="Long">
|
||||
delete from gen_table where table_id in
|
||||
<foreach collection="array" item="tableId" open="(" separator="," close=")">
|
||||
#{tableId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
Reference in New Issue
Block a user