diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index ae4cc11..210d92a 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -34,7 +34,7 @@ mybatis-flex: datasource: # 数据源-1 - PrimaryDS: + ds1: # 指定为HikariDataSource type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.cj.jdbc.Driver @@ -44,7 +44,7 @@ mybatis-flex: hikari: #连接池名 - pool-name: HikariCP-PrimaryDS + pool-name: HikariCP-ds1 #最小空闲连接数 minimum-idle: 5 # 空闲连接存活最大时间,默认10分钟 diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java index c31b2ff..899b5c5 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java @@ -35,26 +35,32 @@ public class GenConstants public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" }; /** 数据库文本类型 */ - public static final String[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext" }; + public static final String[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext", "binary", "varbinary", "blob", + "ntext", "image", "bytea" }; /** 数据库时间类型 */ - public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" }; + public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp", "year", "interval", + "smalldatetime", "datetime2", "datetimeoffset" }; /** 数据库数字类型 */ public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer", - "bit", "bigint", "float", "double", "decimal" }; + "bit", "bigint", "float", "double", "decimal", "numeric", "real", "double precision", + "smallserial", "serial", "bigserial", "money", "smallmoney" }; - /** 页面不需要编辑字段 */ - public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "update_by", - "update_time","del_flag" }; + /** + * BO对象 不需要添加字段 + */ + public static final String[] COLUMNNAME_NOT_ADD = {"create_by", "create_time", "update_by", "update_time" }; - /** 页面不需要显示的列表字段 */ - public static final String[] COLUMNNAME_NOT_LIST = { "id", "create_by", "create_time", "del_flag", "update_by", - "update_time" }; + /** BO对象 不需要编辑字段 */ + public static final String[] COLUMNNAME_NOT_EDIT = { "create_by", "create_time", "update_by", "update_time" }; - /** 页面不需要查询字段 */ - public static final String[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "del_flag", "update_by", - "update_time", "remark" }; + /** VO对象 不需要显示的列表字段 */ + public static final String[] COLUMNNAME_NOT_LIST = { "create_by", "create_time", "update_by", "update_time" }; + + /** BO对象 不需要查询字段 */ + public static final String[] COLUMNNAME_NOT_QUERY = { "create_by", "create_time", "update_by", + "update_time", "del_flag", "remark", "version" }; /** Entity基类字段 */ public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime"}; diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java index 01589cd..0e3160f 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java @@ -31,7 +31,9 @@ import com.ruoyi.generator.service.IGenTableService; * 代码生成 操作处理 * * @author ruoyi + * @author 数据小王子 */ +@Validated @RestController @RequestMapping("/tool/gen") public class GenController extends BaseController @@ -47,11 +49,9 @@ public class GenController extends BaseController */ @SaCheckPermission("tool:gen:list") @GetMapping("/list") - public TableDataInfo genList(GenTable genTable) + public TableDataInfo genList(GenTable genTable) { - startPage(); - List list = genTableService.selectGenTableList(genTable); - return getDataTable(list); + return genTableService.selectPage(genTable); } /** @@ -198,7 +198,7 @@ public class GenController extends BaseController response.reset(); response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); - response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); + response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi-flex.zip\""); response.addHeader("Content-Length", "" + data.length); response.setContentType("application/octet-stream; charset=UTF-8"); IOUtils.write(data, response.getOutputStream()); diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java index 803c4ca..6c32184 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java @@ -2,8 +2,14 @@ package com.ruoyi.generator.domain; import java.io.Serial; import java.util.List; + +import com.mybatisflex.annotation.Column; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.Table; import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; +import lombok.Data; +import lombok.EqualsAndHashCode; import org.apache.commons.lang3.ArrayUtils; import com.ruoyi.common.core.constant.GenConstants; import com.ruoyi.common.orm.core.domain.BaseEntity; @@ -13,13 +19,18 @@ import com.ruoyi.common.core.utils.StringUtils; * 业务表 gen_table * * @author ruoyi + * @author 数据小王子 */ +@Data +@EqualsAndHashCode(callSuper = true) +@Table(value = "gen_table") public class GenTable extends BaseEntity { @Serial private static final long serialVersionUID = 1L; /** 编号 */ + @Id private Long tableId; /** 表名称 */ @@ -70,6 +81,7 @@ public class GenTable extends BaseEntity private String genPath; /** 主键信息 */ + @Column(ignore = true) private GenTableColumn pkColumn; /** 子表信息 */ @@ -83,12 +95,15 @@ public class GenTable extends BaseEntity private String options; /** 树编码字段 */ + @Column(ignore = true) private String treeCode; /** 树父编码字段 */ + @Column(ignore = true) private String treeParentCode; /** 树名称字段 */ + @Column(ignore = true) private String treeName; /* @@ -97,252 +112,16 @@ public class GenTable extends BaseEntity private List menuIds; /** 上级菜单ID字段 */ + @Column(ignore = true) private String parentMenuId; /** 上级菜单名称字段 */ + @Column(ignore = true) private String parentMenuName; /** 备注 */ private String remark; - public Long getTableId() - { - return tableId; - } - - public void setTableId(Long tableId) - { - this.tableId = tableId; - } - - public String getTableName() - { - return tableName; - } - - public void setTableName(String tableName) - { - this.tableName = tableName; - } - - public String getTableComment() - { - return tableComment; - } - - public void setTableComment(String tableComment) - { - this.tableComment = tableComment; - } - - public String getSubTableName() - { - return subTableName; - } - - public void setSubTableName(String subTableName) - { - this.subTableName = subTableName; - } - - public String getSubTableFkName() - { - return subTableFkName; - } - - public void setSubTableFkName(String subTableFkName) - { - this.subTableFkName = subTableFkName; - } - - public String getClassName() - { - return className; - } - - public void setClassName(String className) - { - this.className = className; - } - - public String getTplCategory() - { - return tplCategory; - } - - public void setTplCategory(String tplCategory) - { - this.tplCategory = tplCategory; - } - - public String getPackageName() - { - return packageName; - } - - public void setPackageName(String packageName) - { - this.packageName = packageName; - } - - public String getModuleName() - { - return moduleName; - } - - public void setModuleName(String moduleName) - { - this.moduleName = moduleName; - } - - public String getBusinessName() - { - return businessName; - } - - public void setBusinessName(String businessName) - { - this.businessName = businessName; - } - - public String getFunctionName() - { - return functionName; - } - - public void setFunctionName(String functionName) - { - this.functionName = functionName; - } - - public String getFunctionAuthor() - { - return functionAuthor; - } - - public void setFunctionAuthor(String functionAuthor) - { - this.functionAuthor = functionAuthor; - } - - public String getGenType() - { - return genType; - } - - public void setGenType(String genType) - { - this.genType = genType; - } - - public String getGenPath() - { - return genPath; - } - - public void setGenPath(String genPath) - { - this.genPath = genPath; - } - - public GenTableColumn getPkColumn() - { - return pkColumn; - } - - public void setPkColumn(GenTableColumn pkColumn) - { - this.pkColumn = pkColumn; - } - - public GenTable getSubTable() - { - return subTable; - } - - public void setSubTable(GenTable subTable) - { - this.subTable = subTable; - } - - public List getColumns() - { - return columns; - } - - public void setColumns(List columns) - { - this.columns = columns; - } - - public String getOptions() - { - return options; - } - - public void setOptions(String options) - { - this.options = options; - } - - public String getTreeCode() - { - return treeCode; - } - - public void setTreeCode(String treeCode) - { - this.treeCode = treeCode; - } - - public String getTreeParentCode() - { - return treeParentCode; - } - - public void setTreeParentCode(String treeParentCode) - { - this.treeParentCode = treeParentCode; - } - - public String getTreeName() - { - return treeName; - } - - public void setTreeName(String treeName) - { - this.treeName = treeName; - } - - public List getMenuIds() { - return menuIds; - } - - public void setMenuIds(List menuIds) { - this.menuIds = menuIds; - } - - public String getParentMenuId() - { - return parentMenuId; - } - - public void setParentMenuId(String parentMenuId) - { - this.parentMenuId = parentMenuId; - } - - public String getParentMenuName() - { - return parentMenuName; - } - - public void setParentMenuName(String parentMenuName) - { - this.parentMenuName = parentMenuName; - } - public boolean isSub() { return isSub(this.tplCategory); @@ -388,11 +167,4 @@ public class GenTable extends BaseEntity return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); } - public String getRemark() { - return remark; - } - - public void setRemark(String remark) { - this.remark = remark; - } } diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java index 3b53dd9..42deb37 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java @@ -1,8 +1,12 @@ package com.ruoyi.generator.domain; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.Table; import jakarta.validation.constraints.NotBlank; import com.ruoyi.common.orm.core.domain.BaseEntity; import com.ruoyi.common.core.utils.StringUtils; +import lombok.Data; +import lombok.EqualsAndHashCode; import java.io.Serial; @@ -10,13 +14,18 @@ import java.io.Serial; * 代码生成业务字段表 gen_table_column * * @author ruoyi + * @author 数据小王子 */ +@Data +@EqualsAndHashCode(callSuper = true) +@Table(value = "gen_table_column") public class GenTableColumn extends BaseEntity { @Serial private static final long serialVersionUID = 1L; /** 编号 */ + @Id private Long columnId; /** 归属表编号 */ @@ -71,91 +80,11 @@ public class GenTableColumn extends BaseEntity /** 排序 */ private Integer sort; - public void setColumnId(Long columnId) - { - this.columnId = columnId; - } - - public Long getColumnId() - { - return columnId; - } - - public void setTableId(Long tableId) - { - this.tableId = tableId; - } - - public Long getTableId() - { - return tableId; - } - - public void setColumnName(String columnName) - { - this.columnName = columnName; - } - - public String getColumnName() - { - return columnName; - } - - public void setColumnComment(String columnComment) - { - this.columnComment = columnComment; - } - - public String getColumnComment() - { - return columnComment; - } - - public void setColumnType(String columnType) - { - this.columnType = columnType; - } - - public String getColumnType() - { - return columnType; - } - - public void setJavaType(String javaType) - { - this.javaType = javaType; - } - - public String getJavaType() - { - return javaType; - } - - public void setJavaField(String javaField) - { - this.javaField = javaField; - } - - public String getJavaField() - { - return javaField; - } - public String getCapJavaField() { return StringUtils.capitalize(javaField); } - public void setIsPk(String isPk) - { - this.isPk = isPk; - } - - public String getIsPk() - { - return isPk; - } - public boolean isPk() { return isPk(this.isPk); @@ -166,16 +95,6 @@ public class GenTableColumn extends BaseEntity return isPk != null && StringUtils.equals("1", isPk); } - public String getIsIncrement() - { - return isIncrement; - } - - public void setIsIncrement(String isIncrement) - { - this.isIncrement = isIncrement; - } - public boolean isIncrement() { return isIncrement(this.isIncrement); @@ -186,16 +105,6 @@ public class GenTableColumn extends BaseEntity return isIncrement != null && StringUtils.equals("1", isIncrement); } - public void setIsRequired(String isRequired) - { - this.isRequired = isRequired; - } - - public String getIsRequired() - { - return isRequired; - } - public boolean isRequired() { return isRequired(this.isRequired); @@ -206,16 +115,6 @@ public class GenTableColumn extends BaseEntity return isRequired != null && StringUtils.equals("1", isRequired); } - public void setIsInsert(String isInsert) - { - this.isInsert = isInsert; - } - - public String getIsInsert() - { - return isInsert; - } - public boolean isInsert() { return isInsert(this.isInsert); @@ -226,16 +125,6 @@ public class GenTableColumn extends BaseEntity return isInsert != null && StringUtils.equals("1", isInsert); } - public void setIsEdit(String isEdit) - { - this.isEdit = isEdit; - } - - public String getIsEdit() - { - return isEdit; - } - public boolean isEdit() { return isInsert(this.isEdit); @@ -245,17 +134,6 @@ public class GenTableColumn extends BaseEntity { return isEdit != null && StringUtils.equals("1", isEdit); } - - public void setIsList(String isList) - { - this.isList = isList; - } - - public String getIsList() - { - return isList; - } - public boolean isList() { return isList(this.isList); @@ -266,16 +144,6 @@ public class GenTableColumn extends BaseEntity return isList != null && StringUtils.equals("1", isList); } - public void setIsQuery(String isQuery) - { - this.isQuery = isQuery; - } - - public String getIsQuery() - { - return isQuery; - } - public boolean isQuery() { return isQuery(this.isQuery); @@ -286,46 +154,6 @@ public class GenTableColumn extends BaseEntity return isQuery != null && StringUtils.equals("1", isQuery); } - public void setQueryType(String queryType) - { - this.queryType = queryType; - } - - public String getQueryType() - { - return queryType; - } - - public String getHtmlType() - { - return htmlType; - } - - public void setHtmlType(String htmlType) - { - this.htmlType = htmlType; - } - - public void setDictType(String dictType) - { - this.dictType = dictType; - } - - public String getDictType() - { - return dictType; - } - - public void setSort(Integer sort) - { - this.sort = sort; - } - - public Integer getSort() - { - return sort; - } - public boolean isSuperColumn() { return isSuperColumn(this.javaField); diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java index 951e166..16c90f7 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java @@ -1,60 +1,41 @@ package com.ruoyi.generator.mapper; import java.util.List; + +import com.mybatisflex.core.BaseMapper; import com.ruoyi.generator.domain.GenTableColumn; +import org.apache.ibatis.annotations.Mapper; /** * 业务字段 数据层 - * + * * @author ruoyi + * @author 数据小王子 */ -public interface GenTableColumnMapper +@Mapper +public interface GenTableColumnMapper extends BaseMapper { /** * 根据表名称查询列信息 - * + * * @param tableName 表名称 * @return 列信息 */ - public List selectDbTableColumnsByName(String tableName); - - /** - * 查询业务字段列表 - * - * @param tableId 业务字段编号 - * @return 业务字段集合 - */ - public List selectGenTableColumnListByTableId(Long tableId); - - /** - * 新增业务字段 - * - * @param genTableColumn 业务字段信息 - * @return 结果 - */ - public int insertGenTableColumn(GenTableColumn genTableColumn); - - /** - * 修改业务字段 - * - * @param genTableColumn 业务字段信息 - * @return 结果 - */ - public int updateGenTableColumn(GenTableColumn genTableColumn); + List selectDbTableColumnsByName(String tableName); /** * 删除业务字段 - * + * * @param genTableColumns 列数据 * @return 结果 */ - public int deleteGenTableColumns(List genTableColumns); + int deleteGenTableColumns(List genTableColumns); /** * 批量删除业务字段 - * + * * @param ids 需要删除的数据ID * @return 结果 */ - public int deleteGenTableColumnByIds(Long[] ids); + int deleteGenTableColumnByIds(Long[] ids); } diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java index 9b330df..a4787fb 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java @@ -1,83 +1,44 @@ package com.ruoyi.generator.mapper; import java.util.List; + +import com.mybatisflex.core.BaseMapper; import com.ruoyi.generator.domain.GenTable; +import org.apache.ibatis.annotations.Mapper; /** * 业务 数据层 - * + * * @author ruoyi + * @author 数据小王子 */ -public interface GenTableMapper +@Mapper +public interface GenTableMapper extends BaseMapper { - /** - * 查询业务列表 - * - * @param genTable 业务信息 - * @return 业务集合 - */ - public List selectGenTableList(GenTable genTable); - /** * 查询据库列表 - * + * * @param genTable 业务信息 * @return 数据库表集合 */ - public List selectDbTableList(GenTable genTable); + List selectDbTableList(GenTable genTable); /** * 查询据库列表 - * + * * @param tableNames 表名称组 * @return 数据库表集合 */ - public List selectDbTableListByNames(String[] tableNames); + List selectDbTableListByNames(String[] tableNames); - /** - * 查询所有表信息 - * - * @return 表信息集合 - */ - public List selectGenTableAll(); - /** - * 查询表ID业务信息 - * - * @param id 业务ID - * @return 业务信息 - */ - public GenTable selectGenTableById(Long id); /** * 查询表名称业务信息 - * + * * @param tableName 表名称 * @return 业务信息 */ - public GenTable selectGenTableByName(String tableName); + 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); } diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java index e83f47a..0e43436 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java @@ -2,23 +2,33 @@ package com.ruoyi.generator.service; import java.util.List; +import com.mybatisflex.core.query.QueryWrapper; +import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import com.ruoyi.common.core.core.text.Convert; import com.ruoyi.generator.domain.GenTableColumn; import com.ruoyi.generator.mapper.GenTableColumnMapper; +import static com.ruoyi.generator.domain.table.GenTableColumnTableDef.GEN_TABLE_COLUMN; + /** * 业务字段 服务层实现 * * @author ruoyi + * @author 数据小王子 */ @Service -public class GenTableColumnServiceImpl implements IGenTableColumnService +public class GenTableColumnServiceImpl extends BaseServiceImpl implements IGenTableColumnService { @Resource private GenTableColumnMapper genTableColumnMapper; + @Override + public QueryWrapper query() { + return super.query().from(GEN_TABLE_COLUMN); + } + /** * 查询业务字段列表 * @@ -28,7 +38,11 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService @Override public List selectGenTableColumnListByTableId(Long tableId) { - return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); + QueryWrapper queryWrapper = QueryWrapper.create() + .from(GEN_TABLE_COLUMN) + .where(GEN_TABLE_COLUMN.TABLE_ID.eq(tableId)) + .orderBy(GEN_TABLE_COLUMN.SORT.asc()); + return this.list(queryWrapper); } /** @@ -40,7 +54,8 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService @Override public int insertGenTableColumn(GenTableColumn genTableColumn) { - return genTableColumnMapper.insertGenTableColumn(genTableColumn); + //return genTableColumnMapper.insertGenTableColumn(genTableColumn); + return genTableColumnMapper.insertSelective(genTableColumn); } /** @@ -52,7 +67,7 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService @Override public int updateGenTableColumn(GenTableColumn genTableColumn) { - return genTableColumnMapper.updateGenTableColumn(genTableColumn); + return genTableColumnMapper.update(genTableColumn); } /** diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java index 48b273f..c6a704f 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java @@ -1,24 +1,26 @@ package com.ruoyi.generator.service; import java.io.*; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import com.mybatisflex.core.paginate.Page; +import com.mybatisflex.core.query.QueryMethods; +import com.mybatisflex.core.query.QueryWrapper; import com.ruoyi.common.core.utils.DateUtils; +import com.ruoyi.common.orm.core.page.PageQuery; +import com.ruoyi.common.orm.core.page.TableDataInfo; +import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl; import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; 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.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.alibaba.fastjson2.JSON; @@ -36,23 +38,44 @@ import com.ruoyi.generator.util.GenUtils; import com.ruoyi.generator.util.VelocityInitializer; import com.ruoyi.generator.util.VelocityUtils; +import static com.ruoyi.generator.domain.table.GenTableColumnTableDef.GEN_TABLE_COLUMN; +import static com.ruoyi.generator.domain.table.GenTableTableDef.GEN_TABLE; + /** * 业务 服务层实现 * * @author ruoyi */ +@Slf4j @Service -public class GenTableServiceImpl implements IGenTableService +public class GenTableServiceImpl extends BaseServiceImpl implements IGenTableService { - @Serial - private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); - @Resource private GenTableMapper genTableMapper; @Resource private GenTableColumnMapper genTableColumnMapper; + @Override + public QueryWrapper query() { + return super.query().from(GEN_TABLE); + } + + private QueryWrapper buildQueryWrapper(GenTable genTable) { + QueryWrapper queryWrapper = super.buildBaseQueryWrapper(); + if (StringUtils.isNotBlank(genTable.getTableName())) { + queryWrapper.and(QueryMethods.lower(GEN_TABLE.TABLE_NAME).like(genTable.getTableName().toLowerCase())); + } + if (StringUtils.isNotBlank(genTable.getTableComment())) { + queryWrapper.and(QueryMethods.lower(GEN_TABLE.TABLE_COMMENT).like(genTable.getTableComment().toLowerCase())); + } + Map params = genTable.getParams(); + if (params.get("beginTime") != null && params.get("endTime") != null) { + queryWrapper.and(GEN_TABLE.CREATE_TIME.between(params.get("beginTime"), params.get("endTime"))); + } + return queryWrapper; + } + /** * 查询业务信息 * @@ -62,21 +85,34 @@ public class GenTableServiceImpl implements IGenTableService @Override public GenTable selectGenTableById(Long id) { - GenTable genTable = genTableMapper.selectGenTableById(id); + /*SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark, + c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort + FROM gen_table t + LEFT JOIN gen_table_column c ON t.table_id = c.table_id + where t.table_id = #{tableId} order by c.sort*/ + + QueryWrapper queryWrapper = QueryWrapper.create() + .from(GEN_TABLE) + .leftJoin(GEN_TABLE_COLUMN).on(GEN_TABLE_COLUMN.TABLE_ID.eq(GEN_TABLE.TABLE_ID)) + .where(GEN_TABLE.TABLE_ID.eq(id)) + .orderBy(GEN_TABLE_COLUMN.SORT.asc()); + GenTable genTable = this.getOne(queryWrapper); setTableFromOptions(genTable); return genTable; } /** - * 查询业务列表 + * 分页查询业务列表 * * @param genTable 业务信息 - * @return 业务集合 + * @return 分页集合 */ @Override - public List selectGenTableList(GenTable genTable) + public TableDataInfo selectPage(GenTable genTable) { - return genTableMapper.selectGenTableList(genTable); + QueryWrapper queryWrapper = buildQueryWrapper(genTable); + Page page = this.pageAs(PageQuery.build(), queryWrapper, GenTable.class); + return TableDataInfo.build(page); } /** @@ -111,7 +147,11 @@ public class GenTableServiceImpl implements IGenTableService @Override public List selectGenTableAll() { - return genTableMapper.selectGenTableAll(); + QueryWrapper queryWrapper = QueryWrapper.create() + .from(GEN_TABLE) + .leftJoin(GEN_TABLE_COLUMN).on(GEN_TABLE_COLUMN.TABLE_ID.eq(GEN_TABLE.TABLE_ID)) + .orderBy(GEN_TABLE_COLUMN.SORT.asc()); + return this.list(queryWrapper); } /** @@ -126,12 +166,12 @@ public class GenTableServiceImpl implements IGenTableService { String options = JSON.toJSONString(genTable.getParams()); genTable.setOptions(options); - int row = genTableMapper.updateGenTable(genTable); - if (row > 0) + boolean updated = this.updateById(genTable); + if (updated) { - for (GenTableColumn cenTableColumn : genTable.getColumns()) + for (GenTableColumn genTableColumn : genTable.getColumns()) { - genTableColumnMapper.updateGenTableColumn(cenTableColumn); + genTableColumnMapper.update(genTableColumn); } } } @@ -146,7 +186,7 @@ public class GenTableServiceImpl implements IGenTableService @Transactional public void deleteGenTableByIds(Long[] tableIds) { - genTableMapper.deleteGenTableByIds(tableIds); + genTableMapper.deleteBatchByIds(Arrays.asList(tableIds)); genTableColumnMapper.deleteGenTableColumnByIds(tableIds); } @@ -165,15 +205,16 @@ public class GenTableServiceImpl implements IGenTableService { String tableName = table.getTableName(); GenUtils.initTable(table); - int row = genTableMapper.insertGenTable(table); - if (row > 0) + //int row = genTableMapper.insertGenTable(table); + boolean saved = this.save(table); + if (saved) { // 保存列信息 List genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); for (GenTableColumn column : genTableColumns) { GenUtils.initColumnField(column, table); - genTableColumnMapper.insertGenTableColumn(column); + genTableColumnMapper.insertSelective(column); } } } @@ -195,7 +236,7 @@ public class GenTableServiceImpl implements IGenTableService { Map dataMap = new LinkedHashMap<>(); // 查询表信息 - GenTable table = genTableMapper.selectGenTableById(tableId); + GenTable table = selectGenTableById(tableId); //设置生成的sys_menu6条记录的主键值 setMenuIds(table); // 设置主子表信息 @@ -319,11 +360,11 @@ public class GenTableServiceImpl implements IGenTableService column.setIsRequired(prevColumn.getIsRequired()); column.setHtmlType(prevColumn.getHtmlType()); } - genTableColumnMapper.updateGenTableColumn(column); + genTableColumnMapper.update(column); } else { - genTableColumnMapper.insertGenTableColumn(column); + genTableColumnMapper.insertSelective(column); } }); @@ -362,6 +403,8 @@ public class GenTableServiceImpl implements IGenTableService GenTable table = genTableMapper.selectGenTableByName(tableName); // 设置主子表信息 setSubTable(table); + //设置生成的sys_menu6条记录的主键值 + setMenuIds(table); // 设置主键列信息 setPkColumn(table); diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java index 3037f70..46e78d6 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java @@ -5,40 +5,41 @@ import com.ruoyi.generator.domain.GenTableColumn; /** * 业务字段 服务层 - * + * * @author ruoyi + * @author 数据小王子 */ public interface IGenTableColumnService { /** * 查询业务字段列表 - * + * * @param tableId 业务字段编号 * @return 业务字段集合 */ - public List selectGenTableColumnListByTableId(Long tableId); + List selectGenTableColumnListByTableId(Long tableId); /** * 新增业务字段 - * + * * @param genTableColumn 业务字段信息 * @return 结果 */ - public int insertGenTableColumn(GenTableColumn genTableColumn); + int insertGenTableColumn(GenTableColumn genTableColumn); /** * 修改业务字段 - * + * * @param genTableColumn 业务字段信息 * @return 结果 */ - public int updateGenTableColumn(GenTableColumn genTableColumn); + int updateGenTableColumn(GenTableColumn genTableColumn); /** * 删除业务字段信息 - * + * * @param ids 需要删除的数据ID * @return 结果 */ - public int deleteGenTableColumnByIds(String ids); + int deleteGenTableColumnByIds(String ids); } diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java index 9d53f95..922f0b4 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java @@ -2,34 +2,38 @@ package com.ruoyi.generator.service; import java.util.List; import java.util.Map; + +import com.ruoyi.common.orm.core.page.TableDataInfo; +import com.ruoyi.common.orm.core.service.IBaseService; import com.ruoyi.generator.domain.GenTable; /** * 业务 服务层 - * + * * @author ruoyi + * @author 数据小王子 */ -public interface IGenTableService +public interface IGenTableService extends IBaseService { - /** - * 查询业务列表 - * - * @param genTable 业务信息 - * @return 业务集合 - */ - public List selectGenTableList(GenTable genTable); - /** * 查询据库列表 - * + * * @param genTable 业务信息 * @return 数据库表集合 */ public List selectDbTableList(GenTable genTable); + /** + * 分页查询业务列表 + * + * @param genTable 业务信息 + * @return 分页集合 + */ + TableDataInfo selectPage(GenTable genTable); + /** * 查询据库列表 - * + * * @param tableNames 表名称组 * @return 数据库表集合 */ @@ -37,14 +41,14 @@ public interface IGenTableService /** * 查询所有表信息 - * + * * @return 表信息集合 */ public List selectGenTableAll(); /** * 查询业务信息 - * + * * @param id 业务ID * @return 业务信息 */ @@ -52,7 +56,7 @@ public interface IGenTableService /** * 修改业务 - * + * * @param genTable 业务信息 * @return 结果 */ @@ -60,7 +64,7 @@ public interface IGenTableService /** * 删除业务信息 - * + * * @param tableIds 需要删除的表数据ID * @return 结果 */ @@ -68,14 +72,14 @@ public interface IGenTableService /** * 导入表结构 - * + * * @param tableList 导入表列表 */ public void importGenTable(List tableList); /** * 预览代码 - * + * * @param tableId 表编号 * @return 预览数据列表 */ @@ -83,7 +87,7 @@ public interface IGenTableService /** * 生成代码(下载方式) - * + * * @param tableName 表名称 * @return 数据 */ @@ -91,7 +95,7 @@ public interface IGenTableService /** * 生成代码(自定义路径) - * + * * @param tableName 表名称 * @return 数据 */ @@ -99,14 +103,14 @@ public interface IGenTableService /** * 同步数据库 - * + * * @param tableName 表名称 */ public void synchDb(String tableName); /** * 批量生成代码(下载方式) - * + * * @param tableNames 表数组 * @return 数据 */ @@ -114,7 +118,7 @@ public interface IGenTableService /** * 修改保存参数校验 - * + * * @param genTable 业务信息 */ public void validateEdit(GenTable genTable); diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java index 5f72cb6..32b9efd 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java @@ -14,6 +14,7 @@ import com.ruoyi.generator.domain.GenTableColumn; * 代码生成器 工具类 * * @author ruoyi + * @author 数据小王子 */ public class GenUtils { @@ -80,25 +81,26 @@ public class GenUtils } } - // 插入字段 - if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) - { + // BO对象 默认插入勾选 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_ADD, columnName) && !column.isPk()) { column.setIsInsert(GenConstants.REQUIRE); } - // 编辑字段 - if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName)) - { + // BO对象 默认编辑勾选 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName)) { column.setIsEdit(GenConstants.REQUIRE); } - // 列表字段 - if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) - { + // BO对象 默认是否必填勾选 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName)) { + column.setIsRequired(GenConstants.REQUIRE); + } + + // VO对象 默认返回勾选 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName)) { column.setIsList(GenConstants.REQUIRE); } - // 查询字段 - if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) - { + // BO对象 默认查询勾选 + if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) { column.setIsQuery(GenConstants.REQUIRE); } @@ -168,9 +170,11 @@ public class GenUtils */ public static String getBusinessName(String tableName) { - int lastIndex = tableName.lastIndexOf("_"); + int firstIndex = tableName.indexOf("_"); int nameLength = tableName.length(); - return StringUtils.substring(tableName, lastIndex + 1, nameLength); + String businessName = StringUtils.substring(tableName, firstIndex + 1, nameLength); + businessName = StringUtils.toCamelCase(businessName); + return businessName; } /** diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java index bfddef5..d87a89c 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java @@ -4,6 +4,10 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; + +import cn.hutool.core.collection.CollUtil; +import com.mybatisflex.core.datasource.FlexDataSource; +import com.mybatisflex.core.dialect.DbTypeUtil; import org.apache.velocity.VelocityContext; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; @@ -17,6 +21,7 @@ import com.ruoyi.generator.domain.GenTableColumn; * 模板处理工具类 * * @author ruoyi + * @author 数据小王子 */ public class VelocityUtils { @@ -140,6 +145,7 @@ public class VelocityUtils templates.add("vm/java/serviceImpl.java.vm"); templates.add("vm/java/controller.java.vm"); templates.add("vm/xml/mapper.xml.vm"); + templates.add("vm/sql/sql.vm"); templates.add("vm/js/api.js.vm"); if (GenConstants.TPL_CRUD.equals(tplCategory)) @@ -334,7 +340,7 @@ public class VelocityUtils */ public static String getTreeParentCode(JSONObject paramsObj) { - if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) + if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); } @@ -349,7 +355,7 @@ public class VelocityUtils */ public static String getTreeName(JSONObject paramsObj) { - if (paramsObj.containsKey(GenConstants.TREE_NAME)) + if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) { return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); } diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml index be2acc1..2904b07 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml @@ -33,83 +33,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 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 - - - - insert into gen_table_column ( - 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 - )values( - #{tableId}, - #{columnName}, - #{columnComment}, - #{columnType}, - #{javaType}, - #{javaField}, - #{isPk}, - #{isIncrement}, - #{isRequired}, - #{isInsert}, - #{isEdit}, - #{isList}, - #{isQuery}, - #{queryType}, - #{htmlType}, - #{dictType}, - #{sort}, - #{createBy}, - sysdate() - ) - - - - update gen_table_column - - 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() - - where column_id = #{columnId} - - delete from gen_table_column where table_id in diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml b/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml index b605e90..f842104 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml @@ -27,7 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + @@ -52,33 +52,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table - - - + - + - - - + - - - - - insert into gen_table ( - table_name, - table_comment, - class_name, - tpl_category, - package_name, - module_name, - business_name, - function_name, - function_author, - gen_type, - gen_path, - remark, - create_by, - create_time - )values( - #{tableName}, - #{tableComment}, - #{className}, - #{tplCategory}, - #{packageName}, - #{moduleName}, - #{businessName}, - #{functionName}, - #{functionAuthor}, - #{genType}, - #{genPath}, - #{remark}, - #{createBy}, - sysdate() - ) - - - - update gen_table - - table_name = #{tableName}, - table_comment = #{tableComment}, - sub_table_name = #{subTableName}, - sub_table_fk_name = #{subTableFkName}, - class_name = #{className}, - function_author = #{functionAuthor}, - gen_type = #{genType}, - gen_path = #{genPath}, - tpl_category = #{tplCategory}, - package_name = #{packageName}, - module_name = #{moduleName}, - business_name = #{businessName}, - function_name = #{functionName}, - options = #{options}, - update_by = #{updateBy}, - remark = #{remark}, - update_time = sysdate() - - where table_id = #{tableId} - - - - delete from gen_table where table_id in - - #{tableId} - - - \ No newline at end of file + diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java index 56e2a97..7b290e5 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java @@ -82,11 +82,6 @@ public class SysRole extends BaseEntity { @Column(ignore = true) private Long[] menuIds; - @RelationManyToMany( - selfField = "roleId", targetField = "menuId", - joinTable = "sys_role_menu", - joinSelfColumn = "role_id", joinTargetColumn = "menu_id" - ) private List menuList; /** @@ -95,18 +90,8 @@ public class SysRole extends BaseEntity { @Column(ignore = true) private Long[] deptIds; - @RelationManyToMany( - selfField = "roleId", targetField = "deptId", - joinTable = "sys_role_dept", - joinSelfColumn = "role_id", joinTargetColumn = "dept_id" - ) private List deptList; - @RelationManyToMany( - selfField = "roleId", targetField = "userId", - joinTable = "sys_user_role", - joinSelfColumn = "role_id", joinTargetColumn = "user_id" - ) private List userList; /**