2021年9月2日10:07:12 1.增加微信小程序接口 2.4G开关功能接口

This commit is contained in:
xxmfl
2021-09-02 10:08:27 +08:00
parent 5c97293269
commit a8bc50f67c
337 changed files with 16032 additions and 12055 deletions

View File

@@ -28,6 +28,15 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>

View File

@@ -0,0 +1,70 @@
package com.ruoyi.generator;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
public class SggCodeGenerator {
public static void main(String[] args) {
// 1、创建代码生成器
AutoGenerator mpg = new AutoGenerator();
// 2、全局配置
GlobalConfig gc = new GlobalConfig();
String projectPath = System.getProperty("user.dir");
gc.setOutputDir(projectPath + "/ruoyi-system/src/main/java");
gc.setAuthor("wxy");
gc.setOpen(false); //生成后是否打开资源管理器
gc.setFileOverride(false); //重新生成时文件是否覆盖
gc.setServiceName("%sService"); //去掉Service接口的首字母I
gc.setIdType(IdType.ID_WORKER_STR); //主键策略
gc.setDateType(DateType.ONLY_DATE);//定义生成的实体类中日期类型
gc.setSwagger2(false);//开启Swagger2模式
mpg.setGlobalConfig(gc);
// 3、数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://51xy.xyz:3316/develop_xiaoyi_wumei?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("xiaoyi");
dsc.setPassword("123456");
dsc.setDbType(DbType.MYSQL);
mpg.setDataSource(dsc);
// 4、包配置
PackageConfig pc = new PackageConfig();
pc.setModuleName(null); //模块名
pc.setParent("com.ruoyi.common.core");
pc.setController("controller");
pc.setEntity("entity");
pc.setService("service");
pc.setMapper("mapper");
mpg.setPackageInfo(pc);
// 5、策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setTablePrefix("t_%");//对那一张表生成代码
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀
strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
strategy.setRestControllerStyle(true); //restful api风格控制器
strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符
mpg.setStrategy(strategy);
// 6、执行
mpg.execute();
}
}

View File

@@ -7,67 +7,66 @@ import org.springframework.stereotype.Component;
/**
* 读取代码生成相关配置
*
*
* @author ruoyi
*/
@Component
@ConfigurationProperties(prefix = "gen")
@PropertySource(value = { "classpath:generator.yml" })
public class GenConfig
{
/** 作者 */
@PropertySource(value = {"classpath:generator.yml"})
public class GenConfig {
/**
* 作者
*/
public static String author;
/** 生成包路径 */
/**
* 生成包路径
*/
public static String packageName;
/** 自动去除表前缀默认是false */
/**
* 自动去除表前缀默认是false
*/
public static boolean autoRemovePre;
/** 表前缀(类名不会包含表前缀) */
/**
* 表前缀(类名不会包含表前缀)
*/
public static String tablePrefix;
public static String getAuthor()
{
public static String getAuthor() {
return author;
}
@Value("${author}")
public void setAuthor(String author)
{
public void setAuthor(String author) {
GenConfig.author = author;
}
public static String getPackageName()
{
public static String getPackageName() {
return packageName;
}
@Value("${packageName}")
public void setPackageName(String packageName)
{
public void setPackageName(String packageName) {
GenConfig.packageName = packageName;
}
public static boolean getAutoRemovePre()
{
public static boolean getAutoRemovePre() {
return autoRemovePre;
}
@Value("${autoRemovePre}")
public void setAutoRemovePre(boolean autoRemovePre)
{
public void setAutoRemovePre(boolean autoRemovePre) {
GenConfig.autoRemovePre = autoRemovePre;
}
public static String getTablePrefix()
{
public static String getTablePrefix() {
return tablePrefix;
}
@Value("${tablePrefix}")
public void setTablePrefix(String tablePrefix)
{
public void setTablePrefix(String tablePrefix) {
GenConfig.tablePrefix = tablePrefix;
}
}

View File

@@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -30,13 +31,12 @@ import com.ruoyi.generator.service.IGenTableService;
/**
* 代码生成 操作处理
*
*
* @author ruoyi
*/
@RestController
@RequestMapping("/tool/gen")
public class GenController extends BaseController
{
public class GenController extends BaseController {
@Autowired
private IGenTableService genTableService;
@@ -48,8 +48,7 @@ public class GenController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
@GetMapping("/list")
public TableDataInfo genList(GenTable genTable)
{
public TableDataInfo genList(GenTable genTable) {
startPage();
List<GenTable> list = genTableService.selectGenTableList(genTable);
return getDataTable(list);
@@ -60,8 +59,7 @@ public class GenController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('tool:gen:query')")
@GetMapping(value = "/{talbleId}")
public AjaxResult getInfo(@PathVariable Long talbleId)
{
public AjaxResult getInfo(@PathVariable Long talbleId) {
GenTable table = genTableService.selectGenTableById(talbleId);
List<GenTable> tables = genTableService.selectGenTableAll();
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId);
@@ -77,8 +75,7 @@ public class GenController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
@GetMapping("/db/list")
public TableDataInfo dataList(GenTable genTable)
{
public TableDataInfo dataList(GenTable genTable) {
startPage();
List<GenTable> list = genTableService.selectDbTableList(genTable);
return getDataTable(list);
@@ -89,8 +86,7 @@ public class GenController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
@GetMapping(value = "/column/{talbleId}")
public TableDataInfo columnList(Long tableId)
{
public TableDataInfo columnList(Long tableId) {
TableDataInfo dataInfo = new TableDataInfo();
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
dataInfo.setRows(list);
@@ -104,8 +100,7 @@ public class GenController extends BaseController
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
@PostMapping("/importTable")
public AjaxResult importTableSave(String tables)
{
public AjaxResult importTableSave(String tables) {
String[] tableNames = Convert.toStrArray(tables);
// 查询表信息
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
@@ -119,8 +114,7 @@ public class GenController extends BaseController
@PreAuthorize("@ss.hasPermi('tool:gen:edit')")
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult editSave(@Validated @RequestBody GenTable genTable)
{
public AjaxResult editSave(@Validated @RequestBody GenTable genTable) {
genTableService.validateEdit(genTable);
genTableService.updateGenTable(genTable);
return AjaxResult.success();
@@ -132,8 +126,7 @@ public class GenController extends BaseController
@PreAuthorize("@ss.hasPermi('tool:gen:remove')")
@Log(title = "代码生成", businessType = BusinessType.DELETE)
@DeleteMapping("/{tableIds}")
public AjaxResult remove(@PathVariable Long[] tableIds)
{
public AjaxResult remove(@PathVariable Long[] tableIds) {
genTableService.deleteGenTableByIds(tableIds);
return AjaxResult.success();
}
@@ -143,8 +136,7 @@ public class GenController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('tool:gen:preview')")
@GetMapping("/preview/{tableId}")
public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException
{
public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException {
Map<String, String> dataMap = genTableService.previewCode(tableId);
return AjaxResult.success(dataMap);
}
@@ -155,8 +147,7 @@ public class GenController extends BaseController
@PreAuthorize("@ss.hasPermi('tool:gen:code')")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/download/{tableName}")
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
{
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException {
byte[] data = genTableService.downloadCode(tableName);
genCode(response, data);
}
@@ -167,8 +158,7 @@ public class GenController extends BaseController
@PreAuthorize("@ss.hasPermi('tool:gen:code')")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/genCode/{tableName}")
public AjaxResult genCode(@PathVariable("tableName") String tableName)
{
public AjaxResult genCode(@PathVariable("tableName") String tableName) {
genTableService.generatorCode(tableName);
return AjaxResult.success();
}
@@ -179,8 +169,7 @@ public class GenController extends BaseController
@PreAuthorize("@ss.hasPermi('tool:gen:edit')")
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
@GetMapping("/synchDb/{tableName}")
public AjaxResult synchDb(@PathVariable("tableName") String tableName)
{
public AjaxResult synchDb(@PathVariable("tableName") String tableName) {
genTableService.synchDb(tableName);
return AjaxResult.success();
}
@@ -191,8 +180,7 @@ public class GenController extends BaseController
@PreAuthorize("@ss.hasPermi('tool:gen:code')")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/batchGenCode")
public void batchGenCode(HttpServletResponse response, String tables) throws IOException
{
public void batchGenCode(HttpServletResponse response, String tables) throws IOException {
String[] tableNames = Convert.toStrArray(tables);
byte[] data = genTableService.downloadCode(tableNames);
genCode(response, data);
@@ -201,8 +189,7 @@ public class GenController extends BaseController
/**
* 生成zip文件
*/
private void genCode(HttpServletResponse response, byte[] data) throws IOException
{
private void genCode(HttpServletResponse response, byte[] data) throws IOException {
response.reset();
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");

View File

@@ -3,6 +3,7 @@ package com.ruoyi.generator.domain;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import org.apache.commons.lang3.ArrayUtils;
import com.ruoyi.common.constant.GenConstants;
import com.ruoyi.common.core.domain.BaseEntity;
@@ -10,360 +11,350 @@ import com.ruoyi.common.utils.StringUtils;
/**
* 业务表 gen_table
*
*
* @author ruoyi
*/
public class GenTable extends BaseEntity
{
public class GenTable extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 编号 */
/**
* 编号
*/
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;
/** 主键信息 */
/**
* 主键信息
*/
private GenTableColumn pkColumn;
/** 子表信息 */
/**
* 子表信息
*/
private GenTable subTable;
/** 表列信息 */
/**
* 表列信息
*/
@Valid
private List<GenTableColumn> columns;
/** 其它生成选项 */
/**
* 其它生成选项
*/
private String options;
/** 树编码字段 */
/**
* 树编码字段
*/
private String treeCode;
/** 树父编码字段 */
/**
* 树父编码字段
*/
private String treeParentCode;
/** 树名称字段 */
/**
* 树名称字段
*/
private String treeName;
/** 上级菜单ID字段 */
/**
* 上级菜单ID字段
*/
private String parentMenuId;
/** 上级菜单名称字段 */
/**
* 上级菜单名称字段
*/
private String parentMenuName;
public Long getTableId()
{
public Long getTableId() {
return tableId;
}
public void setTableId(Long tableId)
{
public void setTableId(Long tableId) {
this.tableId = tableId;
}
public String getTableName()
{
public String getTableName() {
return tableName;
}
public void setTableName(String tableName)
{
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getTableComment()
{
public String getTableComment() {
return tableComment;
}
public void setTableComment(String tableComment)
{
public void setTableComment(String tableComment) {
this.tableComment = tableComment;
}
public String getSubTableName()
{
public String getSubTableName() {
return subTableName;
}
public void setSubTableName(String subTableName)
{
public void setSubTableName(String subTableName) {
this.subTableName = subTableName;
}
public String getSubTableFkName()
{
public String getSubTableFkName() {
return subTableFkName;
}
public void setSubTableFkName(String subTableFkName)
{
public void setSubTableFkName(String subTableFkName) {
this.subTableFkName = subTableFkName;
}
public String getClassName()
{
public String getClassName() {
return className;
}
public void setClassName(String className)
{
public void setClassName(String className) {
this.className = className;
}
public String getTplCategory()
{
public String getTplCategory() {
return tplCategory;
}
public void setTplCategory(String tplCategory)
{
public void setTplCategory(String tplCategory) {
this.tplCategory = tplCategory;
}
public String getPackageName()
{
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName)
{
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public String getModuleName()
{
public String getModuleName() {
return moduleName;
}
public void setModuleName(String moduleName)
{
public void setModuleName(String moduleName) {
this.moduleName = moduleName;
}
public String getBusinessName()
{
public String getBusinessName() {
return businessName;
}
public void setBusinessName(String businessName)
{
public void setBusinessName(String businessName) {
this.businessName = businessName;
}
public String getFunctionName()
{
public String getFunctionName() {
return functionName;
}
public void setFunctionName(String functionName)
{
public void setFunctionName(String functionName) {
this.functionName = functionName;
}
public String getFunctionAuthor()
{
public String getFunctionAuthor() {
return functionAuthor;
}
public void setFunctionAuthor(String functionAuthor)
{
public void setFunctionAuthor(String functionAuthor) {
this.functionAuthor = functionAuthor;
}
public String getGenType()
{
public String getGenType() {
return genType;
}
public void setGenType(String genType)
{
public void setGenType(String genType) {
this.genType = genType;
}
public String getGenPath()
{
public String getGenPath() {
return genPath;
}
public void setGenPath(String genPath)
{
public void setGenPath(String genPath) {
this.genPath = genPath;
}
public GenTableColumn getPkColumn()
{
public GenTableColumn getPkColumn() {
return pkColumn;
}
public void setPkColumn(GenTableColumn pkColumn)
{
public void setPkColumn(GenTableColumn pkColumn) {
this.pkColumn = pkColumn;
}
public GenTable getSubTable()
{
public GenTable getSubTable() {
return subTable;
}
public void setSubTable(GenTable subTable)
{
public void setSubTable(GenTable subTable) {
this.subTable = subTable;
}
public List<GenTableColumn> getColumns()
{
public List<GenTableColumn> getColumns() {
return columns;
}
public void setColumns(List<GenTableColumn> columns)
{
public void setColumns(List<GenTableColumn> columns) {
this.columns = columns;
}
public String getOptions()
{
public String getOptions() {
return options;
}
public void setOptions(String options)
{
public void setOptions(String options) {
this.options = options;
}
public String getTreeCode()
{
public String getTreeCode() {
return treeCode;
}
public void setTreeCode(String treeCode)
{
public void setTreeCode(String treeCode) {
this.treeCode = treeCode;
}
public String getTreeParentCode()
{
public String getTreeParentCode() {
return treeParentCode;
}
public void setTreeParentCode(String treeParentCode)
{
public void setTreeParentCode(String treeParentCode) {
this.treeParentCode = treeParentCode;
}
public String getTreeName()
{
public String getTreeName() {
return treeName;
}
public void setTreeName(String treeName)
{
public void setTreeName(String treeName) {
this.treeName = treeName;
}
public String getParentMenuId()
{
public String getParentMenuId() {
return parentMenuId;
}
public void setParentMenuId(String parentMenuId)
{
public void setParentMenuId(String parentMenuId) {
this.parentMenuId = parentMenuId;
}
public String getParentMenuName()
{
public String getParentMenuName() {
return parentMenuName;
}
public void setParentMenuName(String parentMenuName)
{
public void setParentMenuName(String parentMenuName) {
this.parentMenuName = 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 && StringUtils.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 && StringUtils.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 && StringUtils.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 StringUtils.equalsAnyIgnoreCase(javaField,
ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY));
}

View File

@@ -1,335 +1,318 @@
package com.ruoyi.generator.domain;
import javax.validation.constraints.NotBlank;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.utils.StringUtils;
/**
* 代码生成业务字段表 gen_table_column
*
*
* @author ruoyi
*/
public class GenTableColumn extends BaseEntity
{
public class GenTableColumn extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 编号 */
/**
* 编号
*/
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;
public void setColumnId(Long columnId)
{
public void setColumnId(Long columnId) {
this.columnId = columnId;
}
public Long getColumnId()
{
public Long getColumnId() {
return columnId;
}
public void setTableId(Long tableId)
{
public void setTableId(Long tableId) {
this.tableId = tableId;
}
public Long getTableId()
{
public Long getTableId() {
return tableId;
}
public void setColumnName(String columnName)
{
public void setColumnName(String columnName) {
this.columnName = columnName;
}
public String getColumnName()
{
public String getColumnName() {
return columnName;
}
public void setColumnComment(String columnComment)
{
public void setColumnComment(String columnComment) {
this.columnComment = columnComment;
}
public String getColumnComment()
{
public String getColumnComment() {
return columnComment;
}
public void setColumnType(String columnType)
{
public void setColumnType(String columnType) {
this.columnType = columnType;
}
public String getColumnType()
{
public String getColumnType() {
return columnType;
}
public void setJavaType(String javaType)
{
public void setJavaType(String javaType) {
this.javaType = javaType;
}
public String getJavaType()
{
public String getJavaType() {
return javaType;
}
public void setJavaField(String javaField)
{
public void setJavaField(String javaField) {
this.javaField = javaField;
}
public String getJavaField()
{
public String getJavaField() {
return javaField;
}
public String getCapJavaField()
{
public String getCapJavaField() {
return StringUtils.capitalize(javaField);
}
public void setIsPk(String isPk)
{
public void setIsPk(String isPk) {
this.isPk = isPk;
}
public String getIsPk()
{
public String getIsPk() {
return isPk;
}
public boolean isPk()
{
public boolean isPk() {
return isPk(this.isPk);
}
public boolean isPk(String isPk)
{
public boolean isPk(String isPk) {
return isPk != null && StringUtils.equals("1", isPk);
}
public String getIsIncrement()
{
public String getIsIncrement() {
return isIncrement;
}
public void setIsIncrement(String isIncrement)
{
public void setIsIncrement(String isIncrement) {
this.isIncrement = isIncrement;
}
public boolean isIncrement()
{
public boolean isIncrement() {
return isIncrement(this.isIncrement);
}
public boolean isIncrement(String isIncrement)
{
public boolean isIncrement(String isIncrement) {
return isIncrement != null && StringUtils.equals("1", isIncrement);
}
public void setIsRequired(String isRequired)
{
public void setIsRequired(String isRequired) {
this.isRequired = isRequired;
}
public String getIsRequired()
{
public String getIsRequired() {
return isRequired;
}
public boolean isRequired()
{
public boolean isRequired() {
return isRequired(this.isRequired);
}
public boolean isRequired(String isRequired)
{
public boolean isRequired(String isRequired) {
return isRequired != null && StringUtils.equals("1", isRequired);
}
public void setIsInsert(String isInsert)
{
public void setIsInsert(String isInsert) {
this.isInsert = isInsert;
}
public String getIsInsert()
{
public String getIsInsert() {
return isInsert;
}
public boolean isInsert()
{
public boolean isInsert() {
return isInsert(this.isInsert);
}
public boolean isInsert(String isInsert)
{
public boolean isInsert(String isInsert) {
return isInsert != null && StringUtils.equals("1", isInsert);
}
public void setIsEdit(String isEdit)
{
public void setIsEdit(String isEdit) {
this.isEdit = isEdit;
}
public String getIsEdit()
{
public String getIsEdit() {
return isEdit;
}
public boolean isEdit()
{
public boolean isEdit() {
return isInsert(this.isEdit);
}
public boolean isEdit(String isEdit)
{
public boolean isEdit(String isEdit) {
return isEdit != null && StringUtils.equals("1", isEdit);
}
public void setIsList(String isList)
{
public void setIsList(String isList) {
this.isList = isList;
}
public String getIsList()
{
public String getIsList() {
return isList;
}
public boolean isList()
{
public boolean isList() {
return isList(this.isList);
}
public boolean isList(String isList)
{
public boolean isList(String isList) {
return isList != null && StringUtils.equals("1", isList);
}
public void setIsQuery(String isQuery)
{
public void setIsQuery(String isQuery) {
this.isQuery = isQuery;
}
public String getIsQuery()
{
public String getIsQuery() {
return isQuery;
}
public boolean isQuery()
{
public boolean isQuery() {
return isQuery(this.isQuery);
}
public boolean isQuery(String isQuery)
{
public boolean isQuery(String isQuery) {
return isQuery != null && StringUtils.equals("1", isQuery);
}
public void setQueryType(String queryType)
{
public void setQueryType(String queryType) {
this.queryType = queryType;
}
public String getQueryType()
{
public String getQueryType() {
return queryType;
}
public String getHtmlType()
{
public String getHtmlType() {
return htmlType;
}
public void setHtmlType(String htmlType)
{
public void setHtmlType(String htmlType) {
this.htmlType = htmlType;
}
public void setDictType(String dictType)
{
public void setDictType(String dictType) {
this.dictType = dictType;
}
public String getDictType()
{
public String getDictType() {
return dictType;
}
public void setSort(Integer sort)
{
public void setSort(Integer sort) {
this.sort = sort;
}
public Integer getSort()
{
public Integer getSort() {
return sort;
}
public boolean isSuperColumn()
{
public boolean isSuperColumn() {
return isSuperColumn(this.javaField);
}
public static boolean isSuperColumn(String javaField)
{
public static boolean isSuperColumn(String javaField) {
return StringUtils.equalsAnyIgnoreCase(javaField,
// BaseEntity
"createBy", "createTime", "updateBy", "updateTime", "remark",
@@ -337,36 +320,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 StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
}
public String readConverterExp()
{
public String readConverterExp() {
String remarks = StringUtils.substringBetween(this.columnComment, "", "");
StringBuffer sb = new StringBuffer();
if (StringUtils.isNotEmpty(remarks))
{
for (String value : remarks.split(" "))
{
if (StringUtils.isNotEmpty(value))
{
if (StringUtils.isNotEmpty(remarks)) {
for (String value : remarks.split(" ")) {
if (StringUtils.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;
}
}

View File

@@ -1,18 +1,18 @@
package com.ruoyi.generator.mapper;
import java.util.List;
import com.ruoyi.generator.domain.GenTableColumn;
/**
* 业务字段 数据层
*
*
* @author ruoyi
*/
public interface GenTableColumnMapper
{
public interface GenTableColumnMapper {
/**
* 根据表名称查询列信息
*
*
* @param tableName 表名称
* @return 列信息
*/
@@ -20,7 +20,7 @@ public interface GenTableColumnMapper
/**
* 查询业务字段列表
*
*
* @param tableId 业务字段编号
* @return 业务字段集合
*/
@@ -28,7 +28,7 @@ public interface GenTableColumnMapper
/**
* 新增业务字段
*
*
* @param genTableColumn 业务字段信息
* @return 结果
*/
@@ -36,7 +36,7 @@ public interface GenTableColumnMapper
/**
* 修改业务字段
*
*
* @param genTableColumn 业务字段信息
* @return 结果
*/
@@ -44,7 +44,7 @@ public interface GenTableColumnMapper
/**
* 删除业务字段
*
*
* @param genTableColumns 列数据
* @return 结果
*/
@@ -52,7 +52,7 @@ public interface GenTableColumnMapper
/**
* 批量删除业务字段
*
*
* @param ids 需要删除的数据ID
* @return 结果
*/

View File

@@ -1,18 +1,18 @@
package com.ruoyi.generator.mapper;
import java.util.List;
import com.ruoyi.generator.domain.GenTable;
/**
* 业务 数据层
*
*
* @author ruoyi
*/
public interface GenTableMapper
{
public interface GenTableMapper {
/**
* 查询业务列表
*
*
* @param genTable 业务信息
* @return 业务集合
*/
@@ -20,7 +20,7 @@ public interface GenTableMapper
/**
* 查询据库列表
*
*
* @param genTable 业务信息
* @return 数据库表集合
*/
@@ -28,7 +28,7 @@ public interface GenTableMapper
/**
* 查询据库列表
*
*
* @param tableNames 表名称组
* @return 数据库表集合
*/
@@ -36,14 +36,14 @@ public interface GenTableMapper
/**
* 查询所有表信息
*
*
* @return 表信息集合
*/
public List<GenTable> selectGenTableAll();
/**
* 查询表ID业务信息
*
*
* @param id 业务ID
* @return 业务信息
*/
@@ -51,7 +51,7 @@ public interface GenTableMapper
/**
* 查询表名称业务信息
*
*
* @param tableName 表名称
* @return 业务信息
*/
@@ -59,7 +59,7 @@ public interface GenTableMapper
/**
* 新增业务
*
*
* @param genTable 业务信息
* @return 结果
*/
@@ -67,7 +67,7 @@ public interface GenTableMapper
/**
* 修改业务
*
*
* @param genTable 业务信息
* @return 结果
*/
@@ -75,7 +75,7 @@ public interface GenTableMapper
/**
* 批量删除业务
*
*
* @param ids 需要删除的数据ID
* @return 结果
*/

View File

@@ -1,6 +1,7 @@
package com.ruoyi.generator.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.text.Convert;
@@ -9,60 +10,55 @@ import com.ruoyi.generator.mapper.GenTableColumnMapper;
/**
* 业务字段 服务层实现
*
*
* @author ruoyi
*/
@Service
public class GenTableColumnServiceImpl implements IGenTableColumnService
{
@Autowired
private GenTableColumnMapper genTableColumnMapper;
public class GenTableColumnServiceImpl implements IGenTableColumnService {
@Autowired
private GenTableColumnMapper genTableColumnMapper;
/**
/**
* 查询业务字段列表
*
*
* @param tableId 业务字段编号
* @return 业务字段集合
*/
@Override
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId)
{
return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
}
@Override
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
}
/**
* 新增业务字段
*
*
* @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 genTableColumnMapper.insertGenTableColumn(genTableColumn);
}
/**
/**
* 修改业务字段
*
* @param genTableColumn 业务字段信息
* @return 结果
*/
@Override
public int updateGenTableColumn(GenTableColumn genTableColumn) {
return genTableColumnMapper.updateGenTableColumn(genTableColumn);
}
/**
* 删除业务字段对象
*
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteGenTableColumnByIds(String ids)
{
return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
}
@Override
public int deleteGenTableColumnByIds(String ids) {
return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
}
}

View File

@@ -10,6 +10,7 @@ import java.util.Map;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
@@ -38,12 +39,11 @@ import com.ruoyi.generator.util.VelocityUtils;
/**
* 业务 服务层实现
*
*
* @author ruoyi
*/
@Service
public class GenTableServiceImpl implements IGenTableService
{
public class GenTableServiceImpl implements IGenTableService {
private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
@Autowired
@@ -54,13 +54,12 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 查询业务信息
*
*
* @param id 业务ID
* @return 业务信息
*/
@Override
public GenTable selectGenTableById(Long id)
{
public GenTable selectGenTableById(Long id) {
GenTable genTable = genTableMapper.selectGenTableById(id);
setTableFromOptions(genTable);
return genTable;
@@ -68,68 +67,61 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 查询业务列表
*
*
* @param genTable 业务信息
* @return 业务集合
*/
@Override
public List<GenTable> selectGenTableList(GenTable genTable)
{
public List<GenTable> selectGenTableList(GenTable genTable) {
return genTableMapper.selectGenTableList(genTable);
}
/**
* 查询据库列表
*
*
* @param genTable 业务信息
* @return 数据库表集合
*/
@Override
public List<GenTable> selectDbTableList(GenTable genTable)
{
public List<GenTable> selectDbTableList(GenTable genTable) {
return genTableMapper.selectDbTableList(genTable);
}
/**
* 查询据库列表
*
*
* @param tableNames 表名称组
* @return 数据库表集合
*/
@Override
public List<GenTable> selectDbTableListByNames(String[] tableNames)
{
public List<GenTable> selectDbTableListByNames(String[] tableNames) {
return genTableMapper.selectDbTableListByNames(tableNames);
}
/**
* 查询所有表信息
*
*
* @return 表信息集合
*/
@Override
public List<GenTable> selectGenTableAll()
{
public List<GenTable> selectGenTableAll() {
return genTableMapper.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())
{
if (row > 0) {
for (GenTableColumn cenTableColumn : genTable.getColumns()) {
genTableColumnMapper.updateGenTableColumn(cenTableColumn);
}
}
@@ -137,62 +129,53 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 删除业务对象
*
*
* @param tableIds 需要删除的数据ID
* @return 结果
*/
@Override
@Transactional
public void deleteGenTableByIds(Long[] tableIds)
{
public void deleteGenTableByIds(Long[] tableIds) {
genTableMapper.deleteGenTableByIds(tableIds);
genTableColumnMapper.deleteGenTableColumnByIds(tableIds);
}
/**
* 导入表结构
*
*
* @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)
{
if (row > 0) {
// 保存列信息
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
for (GenTableColumn column : genTableColumns)
{
for (GenTableColumn column : genTableColumns) {
GenUtils.initColumnField(column, table);
genTableColumnMapper.insertGenTableColumn(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);
@@ -206,8 +189,7 @@ public class GenTableServiceImpl implements IGenTableService
// 获取模板列表
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);
@@ -219,13 +201,12 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 生成代码(下载方式)
*
*
* @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);
@@ -235,12 +216,11 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 生成代码(自定义路径)
*
*
* @param tableName 表名称
*/
@Override
public void generatorCode(String tableName)
{
public void generatorCode(String tableName) {
// 查询表信息
GenTable table = genTableMapper.selectGenTableByName(tableName);
// 设置主子表信息
@@ -254,21 +234,16 @@ public class GenTableServiceImpl implements IGenTableService
// 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
for (String template : templates)
{
if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm"))
{
for (String template : templates) {
if (!StringUtils.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(), CharsetKit.UTF_8);
}
catch (IOException e)
{
} catch (IOException e) {
throw new CustomException("渲染模板失败,表名:" + table.getTableName());
}
}
@@ -277,52 +252,46 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 同步数据库
*
*
* @param tableName 表名称
*/
@Override
@Transactional
public void synchDb(String tableName)
{
public void synchDb(String tableName) {
GenTable table = genTableMapper.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 (StringUtils.isEmpty(dbTableColumns))
{
if (StringUtils.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);
}
});
List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
if (StringUtils.isNotEmpty(delColumns))
{
if (StringUtils.isNotEmpty(delColumns)) {
genTableColumnMapper.deleteGenTableColumns(delColumns);
}
}
/**
* 批量生成代码(下载方式)
*
*
* @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);
@@ -332,8 +301,7 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 查询表信息并生成代码
*/
private void generatorCode(String tableName, ZipOutputStream zip)
{
private void generatorCode(String tableName, ZipOutputStream zip) {
// 查询表信息
GenTable table = genTableMapper.selectGenTableByName(tableName);
// 设置主子表信息
@@ -347,23 +315,19 @@ public class GenTableServiceImpl implements IGenTableService
// 获取模板列表
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);
}
}
@@ -371,36 +335,24 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 修改保存参数校验
*
*
* @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 (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
{
if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) {
throw new CustomException("树编码字段不能为空");
}
else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
{
} else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) {
throw new CustomException("树父编码字段不能为空");
}
else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME)))
{
} else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) {
throw new CustomException("树名称字段不能为空");
}
else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
{
if (StringUtils.isEmpty(genTable.getSubTableName()))
{
} else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) {
if (StringUtils.isEmpty(genTable.getSubTableName())) {
throw new CustomException("关联子表的表名不能为空");
}
else if (StringUtils.isEmpty(genTable.getSubTableFkName()))
{
} else if (StringUtils.isEmpty(genTable.getSubTableFkName())) {
throw new CustomException("子表关联的外键名不能为空");
}
}
@@ -409,35 +361,27 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 设置主键列信息
*
*
* @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 (StringUtils.isNull(table.getPkColumn()))
{
if (StringUtils.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 (StringUtils.isNull(table.getSubTable().getPkColumn()))
{
if (StringUtils.isNull(table.getSubTable().getPkColumn())) {
table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
}
}
@@ -445,34 +389,30 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 设置主子表信息
*
*
* @param table 业务表信息
*/
public void setSubTable(GenTable table)
{
public void setSubTable(GenTable table) {
String subTableName = table.getSubTableName();
if (StringUtils.isNotEmpty(subTableName))
{
if (StringUtils.isNotEmpty(subTableName)) {
table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
}
}
/**
* 设置代码生成其他选项值
*
*
* @param genTable 设置后的生成对象
*/
public void setTableFromOptions(GenTable genTable)
{
public void setTableFromOptions(GenTable genTable) {
JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions());
if (StringUtils.isNotNull(paramsObj))
{
if (StringUtils.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);
@@ -483,16 +423,14 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 获取代码生成地址
*
* @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 (StringUtils.equals(genPath, "/"))
{
if (StringUtils.equals(genPath, "/")) {
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
}
return genPath + File.separator + VelocityUtils.getFileName(template, table);

View File

@@ -1,18 +1,18 @@
package com.ruoyi.generator.service;
import java.util.List;
import com.ruoyi.generator.domain.GenTableColumn;
/**
* 业务字段 服务层
*
*
* @author ruoyi
*/
public interface IGenTableColumnService
{
public interface IGenTableColumnService {
/**
* 查询业务字段列表
*
*
* @param tableId 业务字段编号
* @return 业务字段集合
*/
@@ -20,7 +20,7 @@ public interface IGenTableColumnService
/**
* 新增业务字段
*
*
* @param genTableColumn 业务字段信息
* @return 结果
*/
@@ -28,7 +28,7 @@ public interface IGenTableColumnService
/**
* 修改业务字段
*
*
* @param genTableColumn 业务字段信息
* @return 结果
*/
@@ -36,7 +36,7 @@ public interface IGenTableColumnService
/**
* 删除业务字段信息
*
*
* @param ids 需要删除的数据ID
* @return 结果
*/

View File

@@ -2,18 +2,18 @@ package com.ruoyi.generator.service;
import java.util.List;
import java.util.Map;
import com.ruoyi.generator.domain.GenTable;
/**
* 业务 服务层
*
*
* @author ruoyi
*/
public interface IGenTableService
{
public interface IGenTableService {
/**
* 查询业务列表
*
*
* @param genTable 业务信息
* @return 业务集合
*/
@@ -21,7 +21,7 @@ public interface IGenTableService
/**
* 查询据库列表
*
*
* @param genTable 业务信息
* @return 数据库表集合
*/
@@ -29,7 +29,7 @@ public interface IGenTableService
/**
* 查询据库列表
*
*
* @param tableNames 表名称组
* @return 数据库表集合
*/
@@ -37,14 +37,14 @@ public interface IGenTableService
/**
* 查询所有表信息
*
*
* @return 表信息集合
*/
public List<GenTable> selectGenTableAll();
/**
* 查询业务信息
*
*
* @param id 业务ID
* @return 业务信息
*/
@@ -52,7 +52,7 @@ public interface IGenTableService
/**
* 修改业务
*
*
* @param genTable 业务信息
* @return 结果
*/
@@ -60,7 +60,7 @@ public interface IGenTableService
/**
* 删除业务信息
*
*
* @param tableIds 需要删除的表数据ID
* @return 结果
*/
@@ -68,14 +68,14 @@ public interface IGenTableService
/**
* 导入表结构
*
*
* @param tableList 导入表列表
*/
public void importGenTable(List<GenTable> tableList);
/**
* 预览代码
*
*
* @param tableId 表编号
* @return 预览数据列表
*/
@@ -83,7 +83,7 @@ public interface IGenTableService
/**
* 生成代码(下载方式)
*
*
* @param tableName 表名称
* @return 数据
*/
@@ -91,7 +91,7 @@ public interface IGenTableService
/**
* 生成代码(自定义路径)
*
*
* @param tableName 表名称
* @return 数据
*/
@@ -99,14 +99,14 @@ public interface IGenTableService
/**
* 同步数据库
*
*
* @param tableName 表名称
*/
public void synchDb(String tableName);
/**
* 批量生成代码(下载方式)
*
*
* @param tableNames 表数组
* @return 数据
*/
@@ -114,7 +114,7 @@ public interface IGenTableService
/**
* 修改保存参数校验
*
*
* @param genTable 业务信息
*/
public void validateEdit(GenTable genTable);

View File

@@ -1,6 +1,7 @@
package com.ruoyi.generator.util;
import java.util.Arrays;
import org.apache.commons.lang3.RegExUtils;
import com.ruoyi.common.constant.GenConstants;
import com.ruoyi.common.utils.StringUtils;
@@ -10,16 +11,14 @@ import com.ruoyi.generator.domain.GenTableColumn;
/**
* 代码生成器 工具类
*
*
* @author ruoyi
*/
public class GenUtils
{
public class GenUtils {
/**
* 初始化表信息
*/
public static void initTable(GenTable genTable, String operName)
{
public static void initTable(GenTable genTable, String operName) {
genTable.setClassName(convertClassName(genTable.getTableName()));
genTable.setPackageName(GenConfig.getPackageName());
genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
@@ -32,8 +31,7 @@ public class GenUtils
/**
* 初始化列属性字段
*/
public static void initColumnField(GenTableColumn column, GenTable table)
{
public static void initColumnField(GenTableColumn column, GenTable table) {
String dataType = getDbType(column.getColumnType());
String columnName = column.getColumnName();
column.setTableId(table.getTableId());
@@ -43,36 +41,28 @@ public class GenUtils
// 设置默认类型
column.setJavaType(GenConstants.TYPE_STRING);
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType))
{
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
// 字符串长度超过500设置为文本域
Integer columnLength = getColumnLength(column.getColumnType());
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
column.setHtmlType(htmlType);
}
else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType))
{
} else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
column.setJavaType(GenConstants.TYPE_DATE);
column.setHtmlType(GenConstants.HTML_DATETIME);
}
else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType))
{
} else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
column.setHtmlType(GenConstants.HTML_INPUT);
// 如果是浮点型 统一用BigDecimal
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0)
{
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
}
// 如果是整形
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10)
{
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
column.setJavaType(GenConstants.TYPE_INTEGER);
}
// 长整形
else
{
else {
column.setJavaType(GenConstants.TYPE_LONG);
}
}
@@ -81,74 +71,63 @@ public class GenUtils
column.setIsInsert(GenConstants.REQUIRE);
// 编辑字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk())
{
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) {
column.setIsEdit(GenConstants.REQUIRE);
}
// 列表字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk())
{
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) {
column.setIsList(GenConstants.REQUIRE);
}
// 查询字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk())
{
if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) {
column.setIsQuery(GenConstants.REQUIRE);
}
// 查询字段类型
if (StringUtils.endsWithIgnoreCase(columnName, "name"))
{
if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
column.setQueryType(GenConstants.QUERY_LIKE);
}
// 状态字段设置单选框
if (StringUtils.endsWithIgnoreCase(columnName, "status"))
{
if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
column.setHtmlType(GenConstants.HTML_RADIO);
}
// 类型&性别字段设置下拉框
else if (StringUtils.endsWithIgnoreCase(columnName, "type")
|| StringUtils.endsWithIgnoreCase(columnName, "sex"))
{
|| StringUtils.endsWithIgnoreCase(columnName, "sex")) {
column.setHtmlType(GenConstants.HTML_SELECT);
}
// 图片字段设置图片上传控件
else if (StringUtils.endsWithIgnoreCase(columnName, "image"))
{
else if (StringUtils.endsWithIgnoreCase(columnName, "image")) {
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
}
// 文件字段设置文件上传控件
else if (StringUtils.endsWithIgnoreCase(columnName, "file"))
{
else if (StringUtils.endsWithIgnoreCase(columnName, "file")) {
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
}
// 内容字段设置富文本控件
else if (StringUtils.endsWithIgnoreCase(columnName, "content"))
{
else if (StringUtils.endsWithIgnoreCase(columnName, "content")) {
column.setHtmlType(GenConstants.HTML_EDITOR);
}
}
/**
* 校验数组是否包含指定值
*
* @param arr 数组
*
* @param arr 数组
* @param targetValue 值
* @return 是否包含
*/
public static boolean arraysContains(String[] arr, String targetValue)
{
public static boolean arraysContains(String[] arr, String targetValue) {
return Arrays.asList(arr).contains(targetValue);
}
/**
* 获取模块名
*
*
* @param packageName 包名
* @return 模块名
*/
public static String getModuleName(String packageName)
{
public static String getModuleName(String packageName) {
int lastIndex = packageName.lastIndexOf(".");
int nameLength = packageName.length();
String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength);
@@ -157,12 +136,11 @@ public class GenUtils
/**
* 获取业务名
*
*
* @param tableName 表名
* @return 业务名
*/
public static String getBusinessName(String tableName)
{
public static String getBusinessName(String tableName) {
int lastIndex = tableName.lastIndexOf("_");
int nameLength = tableName.length();
String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength);
@@ -171,16 +149,14 @@ public class GenUtils
/**
* 表名转换成Java类名
*
*
* @param tableName 表名称
* @return 类名
*/
public static String convertClassName(String tableName)
{
public static String convertClassName(String tableName) {
boolean autoRemovePre = GenConfig.getAutoRemovePre();
String tablePrefix = GenConfig.getTablePrefix();
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix))
{
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) {
String[] searchList = StringUtils.split(tablePrefix, ",");
tableName = replaceFirst(tableName, searchList);
}
@@ -189,18 +165,15 @@ public class GenUtils
/**
* 批量替换前缀
*
*
* @param replacementm 替换值
* @param searchList 替换列表
* @param searchList 替换列表
* @return
*/
public static String replaceFirst(String replacementm, String[] searchList)
{
public static String replaceFirst(String replacementm, String[] searchList) {
String text = replacementm;
for (String searchString : searchList)
{
if (replacementm.startsWith(searchString))
{
for (String searchString : searchList) {
if (replacementm.startsWith(searchString)) {
text = replacementm.replaceFirst(searchString, "");
break;
}
@@ -210,48 +183,39 @@ public class GenUtils
/**
* 关键字替换
*
*
* @param text 需要被替换的名字
* @return 替换后的名字
*/
public static String replaceText(String text)
{
public static String replaceText(String text) {
return RegExUtils.replaceAll(text, "(?:表|若依)", "");
}
/**
* 获取数据库类型字段
*
*
* @param columnType 列类型
* @return 截取后的列类型
*/
public static String getDbType(String columnType)
{
if (StringUtils.indexOf(columnType, "(") > 0)
{
public static String getDbType(String columnType) {
if (StringUtils.indexOf(columnType, "(") > 0) {
return StringUtils.substringBefore(columnType, "(");
}
else
{
} else {
return columnType;
}
}
/**
* 获取字段长度
*
*
* @param columnType 列类型
* @return 截取后的列类型
*/
public static Integer getColumnLength(String columnType)
{
if (StringUtils.indexOf(columnType, "(") > 0)
{
public static Integer getColumnLength(String columnType) {
if (StringUtils.indexOf(columnType, "(") > 0) {
String length = StringUtils.substringBetween(columnType, "(", ")");
return Integer.valueOf(length);
}
else
{
} else {
return 0;
}
}

View File

@@ -1,24 +1,22 @@
package com.ruoyi.generator.util;
import java.util.Properties;
import org.apache.velocity.app.Velocity;
import com.ruoyi.common.constant.Constants;
/**
* VelocityEngine工厂
*
*
* @author ruoyi
*/
public class VelocityInitializer
{
public class VelocityInitializer {
/**
* 初始化vm方法
*/
public static void initVelocity()
{
public static void initVelocity() {
Properties p = new Properties();
try
{
try {
// 加载classpath目录下的vm文件
p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
// 定义字符集
@@ -26,9 +24,7 @@ public class VelocityInitializer
p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8);
// 初始化Velocity引擎指定配置Properties
Velocity.init(p);
}
catch (Exception e)
{
} catch (Exception e) {
throw new RuntimeException(e);
}
}

View File

@@ -3,6 +3,7 @@ package com.ruoyi.generator.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.apache.velocity.VelocityContext;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.GenConstants;
@@ -13,18 +14,23 @@ import com.ruoyi.generator.domain.GenTableColumn;
/**
* 模板处理工具类
*
*
* @author ruoyi
*/
public class VelocityUtils
{
/** 项目空间路径 */
public class VelocityUtils {
/**
* 项目空间路径
*/
private static final String PROJECT_PATH = "main/java";
/** mybatis空间路径 */
/**
* mybatis空间路径
*/
private static final String MYBATIS_PATH = "main/resources/mapper";
/** 默认上级菜单,系统工具 */
/**
* 默认上级菜单,系统工具
*/
private static final String DEFAULT_PARENT_MENU_ID = "3";
/**
@@ -32,8 +38,7 @@ public class VelocityUtils
*
* @return 模板列表
*/
public static VelocityContext prepareContext(GenTable genTable)
{
public static VelocityContext prepareContext(GenTable genTable) {
String moduleName = genTable.getModuleName();
String businessName = genTable.getBusinessName();
String packageName = genTable.getPackageName();
@@ -59,27 +64,23 @@ public class VelocityUtils
velocityContext.put("columns", genTable.getColumns());
velocityContext.put("table", genTable);
setMenuVelocityContext(velocityContext, genTable);
if (GenConstants.TPL_TREE.equals(tplCategory))
{
if (GenConstants.TPL_TREE.equals(tplCategory)) {
setTreeVelocityContext(velocityContext, genTable);
}
if (GenConstants.TPL_SUB.equals(tplCategory))
{
if (GenConstants.TPL_SUB.equals(tplCategory)) {
setSubVelocityContext(velocityContext, genTable);
}
return velocityContext;
}
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
{
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
String parentMenuId = getParentMenuId(paramsObj);
context.put("parentMenuId", parentMenuId);
}
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
{
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
String treeCode = getTreecode(paramsObj);
@@ -90,18 +91,15 @@ public class VelocityUtils
context.put("treeParentCode", treeParentCode);
context.put("treeName", treeName);
context.put("expandColumn", getExpandColumn(genTable));
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
{
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
if (paramsObj.containsKey(GenConstants.TREE_NAME))
{
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME));
}
}
public static void setSubVelocityContext(VelocityContext context, GenTable genTable)
{
public static void setSubVelocityContext(VelocityContext context, GenTable genTable) {
GenTable subTable = genTable.getSubTable();
String subTableName = genTable.getSubTableName();
String subTableFkName = genTable.getSubTableFkName();
@@ -123,8 +121,7 @@ public class VelocityUtils
*
* @return 模板列表
*/
public static List<String> getTemplateList(String tplCategory)
{
public static List<String> getTemplateList(String tplCategory) {
List<String> templates = new ArrayList<String>();
templates.add("vm/java/domain.java.vm");
templates.add("vm/java/mapper.java.vm");
@@ -134,16 +131,11 @@ public class VelocityUtils
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))
{
if (GenConstants.TPL_CRUD.equals(tplCategory)) {
templates.add("vm/vue/index.vue.vm");
}
else if (GenConstants.TPL_TREE.equals(tplCategory))
{
} else if (GenConstants.TPL_TREE.equals(tplCategory)) {
templates.add("vm/vue/index-tree.vue.vm");
}
else if (GenConstants.TPL_SUB.equals(tplCategory))
{
} else if (GenConstants.TPL_SUB.equals(tplCategory)) {
templates.add("vm/vue/index.vue.vm");
templates.add("vm/java/sub-domain.java.vm");
}
@@ -153,8 +145,7 @@ public class VelocityUtils
/**
* 获取文件名
*/
public static String getFileName(String template, GenTable genTable)
{
public static String getFileName(String template, GenTable genTable) {
// 文件名称
String fileName = "";
// 包路径
@@ -170,48 +161,28 @@ public class VelocityUtils
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
String vuePath = "vue";
if (template.contains("domain.java.vm"))
{
if (template.contains("domain.java.vm")) {
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
}
if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory()))
{
if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) {
fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName());
}
else if (template.contains("mapper.java.vm"))
{
} else if (template.contains("mapper.java.vm")) {
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
}
else if (template.contains("service.java.vm"))
{
} else if (template.contains("service.java.vm")) {
fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
}
else if (template.contains("serviceImpl.java.vm"))
{
} else if (template.contains("serviceImpl.java.vm")) {
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
}
else if (template.contains("controller.java.vm"))
{
} else if (template.contains("controller.java.vm")) {
fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
}
else if (template.contains("mapper.xml.vm"))
{
} else if (template.contains("mapper.xml.vm")) {
fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
}
else if (template.contains("sql.vm"))
{
} else if (template.contains("sql.vm")) {
fileName = businessName + "Menu.sql";
}
else if (template.contains("api.js.vm"))
{
} else if (template.contains("api.js.vm")) {
fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName);
}
else if (template.contains("index.vue.vm"))
{
} else if (template.contains("index.vue.vm")) {
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
}
else if (template.contains("index-tree.vue.vm"))
{
} else if (template.contains("index-tree.vue.vm")) {
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
}
return fileName;
@@ -223,8 +194,7 @@ public class VelocityUtils
* @param packageName 包名称
* @return 包前缀名称
*/
public static String getPackagePrefix(String packageName)
{
public static String getPackagePrefix(String packageName) {
int lastIndex = packageName.lastIndexOf(".");
String basePackage = StringUtils.substring(packageName, 0, lastIndex);
return basePackage;
@@ -232,28 +202,22 @@ public class VelocityUtils
/**
* 根据列类型获取导入包
*
*
* @param genTable 业务表对象
* @return 返回需要导入的包列表
*/
public static HashSet<String> getImportList(GenTable genTable)
{
public static HashSet<String> getImportList(GenTable genTable) {
List<GenTableColumn> columns = genTable.getColumns();
GenTable subGenTable = genTable.getSubTable();
HashSet<String> importList = new HashSet<String>();
if (StringUtils.isNotNull(subGenTable))
{
if (StringUtils.isNotNull(subGenTable)) {
importList.add("java.util.List");
}
for (GenTableColumn column : columns)
{
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType()))
{
for (GenTableColumn column : columns) {
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
importList.add("java.util.Date");
importList.add("com.fasterxml.jackson.annotation.JsonFormat");
}
else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType()))
{
} else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) {
importList.add("java.math.BigDecimal");
}
}
@@ -263,12 +227,11 @@ public class VelocityUtils
/**
* 获取权限前缀
*
* @param moduleName 模块名称
* @param moduleName 模块名称
* @param businessName 业务名称
* @return 返回权限前缀
*/
public static String getPermissionPrefix(String moduleName, String businessName)
{
public static String getPermissionPrefix(String moduleName, String businessName) {
return StringUtils.format("{}:{}", moduleName, businessName);
}
@@ -278,10 +241,8 @@ public class VelocityUtils
* @param paramsObj 生成其他选项
* @return 上级菜单ID字段
*/
public static String getParentMenuId(JSONObject paramsObj)
{
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID))
{
public static String getParentMenuId(JSONObject paramsObj) {
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)) {
return paramsObj.getString(GenConstants.PARENT_MENU_ID);
}
return DEFAULT_PARENT_MENU_ID;
@@ -293,10 +254,8 @@ public class VelocityUtils
* @param paramsObj 生成其他选项
* @return 树编码
*/
public static String getTreecode(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_CODE))
{
public static String getTreecode(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_CODE)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
}
return StringUtils.EMPTY;
@@ -308,10 +267,8 @@ public class VelocityUtils
* @param paramsObj 生成其他选项
* @return 树父编码
*/
public static String getTreeParentCode(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
{
public static String getTreeParentCode(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
return StringUtils.EMPTY;
@@ -323,10 +280,8 @@ public class VelocityUtils
* @param paramsObj 生成其他选项
* @return 树名称
*/
public static String getTreeName(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_NAME))
{
public static String getTreeName(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
}
return StringUtils.EMPTY;
@@ -338,20 +293,16 @@ public class VelocityUtils
* @param genTable 业务表对象
* @return 展开按钮列序号
*/
public static int getExpandColumn(GenTable genTable)
{
public static int getExpandColumn(GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
int num = 0;
for (GenTableColumn column : genTable.getColumns())
{
if (column.isList())
{
for (GenTableColumn column : genTable.getColumns()) {
if (column.isList()) {
num++;
String columnName = column.getColumnName();
if (columnName.equals(treeName))
{
if (columnName.equals(treeName)) {
break;
}
}

View File

@@ -1,7 +1,7 @@
# 代码生成
gen:
gen:
# 作者
author: ruoyi
author: wxy
# 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
packageName: com.ruoyi.system
# 自动去除表前缀默认是false

View File

@@ -1,94 +1,98 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.generator.mapper.GenTableColumnMapper">
<resultMap type="GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id" />
<result property="tableId" column="table_id" />
<result property="columnName" column="column_name" />
<result property="columnComment" column="column_comment" />
<result property="columnType" column="column_type" />
<result property="javaType" column="java_type" />
<result property="javaField" column="java_field" />
<result property="isPk" column="is_pk" />
<result property="isIncrement" column="is_increment" />
<result property="isRequired" column="is_required" />
<result property="isInsert" column="is_insert" />
<result property="isEdit" column="is_edit" />
<result property="isList" column="is_list" />
<result property="isQuery" column="is_query" />
<result property="queryType" column="query_type" />
<result property="htmlType" column="html_type" />
<result property="dictType" column="dict_type" />
<result property="sort" column="sort" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<id property="columnId" column="column_id"/>
<result property="tableId" column="table_id"/>
<result property="columnName" column="column_name"/>
<result property="columnComment" column="column_comment"/>
<result property="columnType" column="column_type"/>
<result property="javaType" column="java_type"/>
<result property="javaField" column="java_field"/>
<result property="isPk" column="is_pk"/>
<result property="isIncrement" column="is_increment"/>
<result property="isRequired" column="is_required"/>
<result property="isInsert" column="is_insert"/>
<result property="isEdit" column="is_edit"/>
<result property="isList" column="is_list"/>
<result property="isQuery" column="is_query"/>
<result property="queryType" column="query_type"/>
<result property="htmlType" column="html_type"/>
<result property="dictType" column="dict_type"/>
<result property="sort" column="sort"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<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 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>
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()
)
<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>
@@ -111,14 +115,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<delete id="deleteGenTableColumnByIds" parameterType="Long">
delete from gen_table_column where table_id in
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
delete from gen_table_column where column_id in
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item.columnId}
</foreach>

View File

@@ -1,172 +1,183 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.generator.mapper.GenTableMapper">
<resultMap type="GenTable" id="GenTableResult">
<id property="tableId" column="table_id" />
<result property="tableName" column="table_name" />
<result property="tableComment" column="table_comment" />
<result property="subTableName" column="sub_table_name" />
<result property="subTableFkName" column="sub_table_fk_name" />
<result property="className" column="class_name" />
<result property="tplCategory" column="tpl_category" />
<result property="packageName" column="package_name" />
<result property="moduleName" column="module_name" />
<result property="businessName" column="business_name" />
<result property="functionName" column="function_name" />
<result property="functionAuthor" column="function_author" />
<result property="genType" column="gen_type" />
<result property="genPath" column="gen_path" />
<result property="options" column="options" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" />
</resultMap>
<resultMap type="GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id" />
<result property="tableId" column="table_id" />
<result property="columnName" column="column_name" />
<result property="columnComment" column="column_comment" />
<result property="columnType" column="column_type" />
<result property="javaType" column="java_type" />
<result property="javaField" column="java_field" />
<result property="isPk" column="is_pk" />
<result property="isIncrement" column="is_increment" />
<result property="isRequired" column="is_required" />
<result property="isInsert" column="is_insert" />
<result property="isEdit" column="is_edit" />
<result property="isList" column="is_list" />
<result property="isQuery" column="is_query" />
<result property="queryType" column="query_type" />
<result property="htmlType" column="html_type" />
<result property="dictType" column="dict_type" />
<result property="sort" column="sort" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<resultMap type="GenTable" id="GenTableResult">
<id property="tableId" column="table_id"/>
<result property="tableName" column="table_name"/>
<result property="tableComment" column="table_comment"/>
<result property="subTableName" column="sub_table_name"/>
<result property="subTableFkName" column="sub_table_fk_name"/>
<result property="className" column="class_name"/>
<result property="tplCategory" column="tpl_category"/>
<result property="packageName" column="package_name"/>
<result property="moduleName" column="module_name"/>
<result property="businessName" column="business_name"/>
<result property="functionName" column="function_name"/>
<result property="functionAuthor" column="function_author"/>
<result property="genType" column="gen_type"/>
<result property="genPath" column="gen_path"/>
<result property="options" column="options"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult"/>
</resultMap>
<sql id="selectGenTableVo">
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
</sql>
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
<include refid="selectGenTableVo"/>
<where>
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if>
<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
</select>
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_schema = (select database())
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
AND table_name NOT IN (select table_name from gen_table)
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if>
<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</select>
<select id="selectDbTableListByNames" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
and table_name in
<foreach collection="array" item="name" open="(" separator="," close=")">
#{name}
</foreach>
</select>
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database())
and table_name = #{tableName}
</select>
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
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
</select>
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
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_name = #{tableName} order by c.sort
</select>
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
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.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
order by c.sort
</select>
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId">
<resultMap type="GenTableColumn" id="GenTableColumnResult">
<id property="columnId" column="column_id"/>
<result property="tableId" column="table_id"/>
<result property="columnName" column="column_name"/>
<result property="columnComment" column="column_comment"/>
<result property="columnType" column="column_type"/>
<result property="javaType" column="java_type"/>
<result property="javaField" column="java_field"/>
<result property="isPk" column="is_pk"/>
<result property="isIncrement" column="is_increment"/>
<result property="isRequired" column="is_required"/>
<result property="isInsert" column="is_insert"/>
<result property="isEdit" column="is_edit"/>
<result property="isList" column="is_list"/>
<result property="isQuery" column="is_query"/>
<result property="queryType" column="query_type"/>
<result property="htmlType" column="html_type"/>
<result property="dictType" column="dict_type"/>
<result property="sort" column="sort"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<sql id="selectGenTableVo">
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
</sql>
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
<include refid="selectGenTableVo"/>
<where>
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if>
<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
</select>
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_schema = (select database())
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
AND table_name NOT IN (select table_name from gen_table)
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if>
<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</select>
<select id="selectDbTableListByNames" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
and table_name in
<foreach collection="array" item="name" open="(" separator="," close=")">
#{name}
</foreach>
</select>
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database())
and table_name = #{tableName}
</select>
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
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
</select>
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
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_name = #{tableName} order by c.sort
</select>
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
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.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
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()
)
<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>
@@ -190,9 +201,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</set>
where table_id = #{tableId}
</update>
<delete id="deleteGenTableByIds" parameterType="Long">
delete from gen_table where table_id in
delete from gen_table where table_id in
<foreach collection="array" item="tableId" open="(" separator="," close=")">
#{tableId}
</foreach>

View File

@@ -1,6 +1,7 @@
package ${packageName}.controller;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -25,36 +26,33 @@ import com.ruoyi.common.core.page.TableDataInfo;
/**
* ${functionName}Controller
*
*
* @author ${author}
* @date ${datetime}
*/
@RestController
@RequestMapping("/${moduleName}/${businessName}")
public class ${ClassName}Controller extends BaseController
{
public class ${ClassName}Controller extends BaseController {
@Autowired
private I${ClassName}Service ${className}Service;
/**
* 查询${functionName}列表
*/
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
@GetMapping("/list")
#if($table.crud || $table.sub)
public TableDataInfo list(${ClassName} ${className})
{
/**
* 查询${functionName}列表
*/
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
@GetMapping("/list")
#if($table.crud || $table.sub)
public TableDataInfo list(${ClassName} ${className}) {
startPage();
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
return getDataTable(list);
}
#elseif($table.tree)
public AjaxResult list(${ClassName} ${className})
{
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
return AjaxResult.success(list);
}
#end
#elseif($table.tree)
public AjaxResult list(${ClassName} ${className}) {
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
return AjaxResult.success(list);
}
#end
/**
* 导出${functionName}列表
@@ -62,10 +60,9 @@ public class ${ClassName}Controller extends BaseController
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')")
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
@GetMapping("/export")
public AjaxResult export(${ClassName} ${className})
{
public AjaxResult export(${ClassName} ${className}) {
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}. class);
return util.exportExcel(list, "${businessName}");
}
@@ -74,8 +71,7 @@ public class ${ClassName}Controller extends BaseController
*/
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')")
@GetMapping(value = "/{${pkColumn.javaField}}")
public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
{
public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) {
return AjaxResult.success(${className}Service.select${ClassName}ById(${pkColumn.javaField}));
}
@@ -85,8 +81,7 @@ public class ${ClassName}Controller extends BaseController
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')")
@Log(title = "${functionName}", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ${ClassName} ${className})
{
public AjaxResult add(@RequestBody ${ClassName} ${className}) {
return toAjax(${className}Service.insert${ClassName}(${className}));
}
@@ -96,8 +91,7 @@ public class ${ClassName}Controller extends BaseController
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')")
@Log(title = "${functionName}", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ${ClassName} ${className})
{
public AjaxResult edit(@RequestBody ${ClassName} ${className}) {
return toAjax(${className}Service.update${ClassName}(${className}));
}
@@ -106,9 +100,8 @@ public class ${ClassName}Controller extends BaseController
*/
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')")
@Log(title = "${functionName}", businessType = BusinessType.DELETE)
@DeleteMapping("/{${pkColumn.javaField}s}")
public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
{
@DeleteMapping("/{${pkColumn.javaField}s}")
public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) {
return toAjax(${className}Service.delete${ClassName}ByIds(${pkColumn.javaField}s));
}
}

View File

@@ -14,92 +14,92 @@ import com.ruoyi.common.core.domain.TreeEntity;
/**
* ${functionName}对象 ${tableName}
*
*
* @author ${author}
* @date ${datetime}
*/
#if($table.crud || $table.sub)
#set($Entity="BaseEntity")
#set($Entity="BaseEntity")
#elseif($table.tree)
#set($Entity="TreeEntity")
#set($Entity="TreeEntity")
#end
public class ${ClassName} extends ${Entity}
{
private static final long serialVersionUID = 1L;
{
private static final long serialVersionUID=1L;
#foreach ($column in $columns)
#if(!$table.isSuperColumn($column.javaField))
#if(!$table.isSuperColumn($column.javaField))
/** $column.columnComment */
#if($column.list)
#set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else
#set($comment=$column.columnComment)
#end
#if($parentheseIndex != -1)
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
#elseif($column.javaType == 'Date')
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd")
#else
@Excel(name = "${comment}")
#end
#end
#if($column.list)
#set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else
#set($comment=$column.columnComment)
#end
#if($parentheseIndex != -1)
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
#elseif($column.javaType == 'Date')
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd")
#else
@Excel(name = "${comment}")
#end
#end
private $column.javaType $column.javaField;
#end
#end
#end
#if($table.sub)
/** $table.subTable.functionName信息 */
private List<${subClassName}> ${subclassName}List;
/** $table.subTable.functionName信息 */
private List<${subClassName}> ${subclassName}List;
#end
#foreach ($column in $columns)
#if(!$table.isSuperColumn($column.javaField))
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
public void set${AttrName}($column.javaType $column.javaField)
{
this.$column.javaField = $column.javaField;
}
#if(!$table.isSuperColumn($column.javaField))
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
public void set${AttrName}($column.javaType $column.javaField)
{
this.$column.javaField = $column.javaField;
}
public $column.javaType get${AttrName}()
{
return $column.javaField;
}
#end
public $column.javaType get${AttrName}()
{
return $column.javaField;
}
#end
#end
#if($table.sub)
public List<${subClassName}> get${subClassName}List()
{
public List<${subClassName}> get${subClassName}List()
{
return ${subclassName}List;
}
}
public void set${subClassName}List(List<${subClassName}> ${subclassName}List)
{
this.${subclassName}List = ${subclassName}List;
}
public void set${subClassName}List(List<${subClassName}> ${subclassName}List)
{
this.${subclassName}List= ${subclassName}List;
}
#end
@Override
public String toString() {
@Override
public String toString(){
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
#foreach ($column in $columns)
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
.append("${column.javaField}", get${AttrName}())
#end
#if($table.sub)
.append("${subclassName}List", get${subClassName}List())
#end
.toString();
}
}
#foreach ($column in $columns)
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
.append("${column.javaField}",get${AttrName}())
#end
#if($table.sub)
.append("${subclassName}List",get${subClassName}List())
#end
.toString();
}
}

View File

@@ -1,6 +1,7 @@
package ${packageName}.mapper;
import java.util.List;
import ${packageName}.domain.${ClassName};
#if($table.sub)
import ${packageName}.domain.${subClassName};
@@ -8,15 +9,14 @@ import ${packageName}.domain.${subClassName};
/**
* ${functionName}Mapper接口
*
*
* @author ${author}
* @date ${datetime}
*/
public interface ${ClassName}Mapper
{
public interface ${ClassName}Mapper {
/**
* 查询${functionName}
*
*
* @param ${pkColumn.javaField} ${functionName}ID
* @return ${functionName}
*/
@@ -24,7 +24,7 @@ public interface ${ClassName}Mapper
/**
* 查询${functionName}列表
*
*
* @param ${className} ${functionName}
* @return ${functionName}集合
*/
@@ -32,7 +32,7 @@ public interface ${ClassName}Mapper
/**
* 新增${functionName}
*
*
* @param ${className} ${functionName}
* @return 结果
*/
@@ -40,7 +40,7 @@ public interface ${ClassName}Mapper
/**
* 修改${functionName}
*
*
* @param ${className} ${functionName}
* @return 结果
*/
@@ -48,7 +48,7 @@ public interface ${ClassName}Mapper
/**
* 删除${functionName}
*
*
* @param ${pkColumn.javaField} ${functionName}ID
* @return 结果
*/
@@ -56,36 +56,36 @@ public interface ${ClassName}Mapper
/**
* 批量删除${functionName}
*
*
* @param ${pkColumn.javaField}s 需要删除的数据ID
* @return 结果
*/
public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s);
#if($table.sub)
#if($table.sub)
/**
* 批量删除${subTable.functionName}
*
* @param customerIds 需要删除的数据ID
* @return 结果
*/
public int delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
/**
* 批量新增${subTable.functionName}
*
* @param ${subclassName}List ${subTable.functionName}列表
* @return 结果
*/
public int batch${subClassName}(List<${subClassName}> ${subclassName}List);
/**
* 批量删除${subTable.functionName}
*
* @param customerIds 需要删除的数据ID
* @return 结果
*/
public int delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaType}[] ${pkColumn.javaField}s);
/**
* 通过${functionName}ID删除${subTable.functionName}信息
*
* @param roleId 角色ID
* @return 结果
*/
public int delete${subClassName}By${subTableFkClassName}(${pkColumn.javaType} ${pkColumn.javaField});
#end
/**
* 批量新增${subTable.functionName}
*
* @param ${subclassName}List ${subTable.functionName}列表
* @return 结果
*/
public int batch${subClassName}(List<${subClassName}> ${subclassName}List);
/**
* 通过${functionName}ID删除${subTable.functionName}信息
*
* @param roleId 角色ID
* @return 结果
*/
public int delete${subClassName}By${subTableFkClassName}(${pkColumn.javaType} ${pkColumn.javaField});
#end
}

View File

@@ -1,19 +1,19 @@
package ${packageName}.service;
import java.util.List;
import ${packageName}.domain.${ClassName};
/**
* ${functionName}Service接口
*
*
* @author ${author}
* @date ${datetime}
*/
public interface I${ClassName}Service
{
public interface I${ClassName}Service {
/**
* 查询${functionName}
*
*
* @param ${pkColumn.javaField} ${functionName}ID
* @return ${functionName}
*/
@@ -21,7 +21,7 @@ public interface I${ClassName}Service
/**
* 查询${functionName}列表
*
*
* @param ${className} ${functionName}
* @return ${functionName}集合
*/
@@ -29,7 +29,7 @@ public interface I${ClassName}Service
/**
* 新增${functionName}
*
*
* @param ${className} ${functionName}
* @return 结果
*/
@@ -37,7 +37,7 @@ public interface I${ClassName}Service
/**
* 修改${functionName}
*
*
* @param ${className} ${functionName}
* @return 结果
*/
@@ -45,7 +45,7 @@ public interface I${ClassName}Service
/**
* 批量删除${functionName}
*
*
* @param ${pkColumn.javaField}s 需要删除的${functionName}ID
* @return 结果
*/
@@ -53,7 +53,7 @@ public interface I${ClassName}Service
/**
* 删除${functionName}信息
*
*
* @param ${pkColumn.javaField} ${functionName}ID
* @return 结果
*/

View File

@@ -1,166 +1,158 @@
package ${packageName}.service.impl;
import java.util.List;
#foreach ($column in $columns)
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
import com.ruoyi.common.utils.DateUtils;
#break
#end
#end
#foreach ($column in $columns)
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
import com.ruoyi.common.utils.DateUtils;
#break
#end
#end
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
#if($table.sub)
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import ${packageName}.domain.${subClassName};
#end
#if($table.sub)
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import ${packageName}.domain.${subClassName};
#end
import ${packageName}.mapper.${ClassName}Mapper;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service;
/**
* ${functionName}Service业务层处理
*
*
* @author ${author}
* @date ${datetime}
*/
@Service
public class ${ClassName}ServiceImpl implements I${ClassName}Service
{
public class ${ClassName}ServiceImpl implements I${ClassName}Service {
@Autowired
private ${ClassName}Mapper ${className}Mapper;
/**
* 查询${functionName}
*
*
* @param ${pkColumn.javaField} ${functionName}ID
* @return ${functionName}
*/
@Override
public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField})
{
public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) {
return ${className}Mapper.select${ClassName}ById(${pkColumn.javaField});
}
/**
* 查询${functionName}列表
*
*
* @param ${className} ${functionName}
* @return ${functionName}
*/
@Override
public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
{
public List<${ClassName}> select${ClassName}List(${ClassName} ${className}) {
return ${className}Mapper.select${ClassName}List(${className});
}
/**
* 新增${functionName}
*
*
* @param ${className} ${functionName}
* @return 结果
*/
#if($table.sub)
@Transactional
#end
#if($table.sub)
@Transactional
#end
@Override
public int insert${ClassName}(${ClassName} ${className})
{
#foreach ($column in $columns)
#if($column.javaField == 'createTime')
${className}.setCreateTime(DateUtils.getNowDate());
#end
#end
#if($table.sub)
int rows = ${className}Mapper.insert${ClassName}(${className});
insert${subClassName}(${className});
return rows;
#else
return ${className}Mapper.insert${ClassName}(${className});
#end
public int insert${ClassName}(${ClassName} ${className}) {
#foreach ($column in $columns)
#if($column.javaField == 'createTime')
${className}.setCreateTime(DateUtils.getNowDate());
#end
#end
#if($table.sub)
int rows = ${className}Mapper.insert${ClassName}(${className});
insert${subClassName}(${className});
return rows;
#else
return ${className}Mapper.insert${ClassName}(${className});
#end
}
/**
* 修改${functionName}
*
*
* @param ${className} ${functionName}
* @return 结果
*/
#if($table.sub)
@Transactional
#end
#if($table.sub)
@Transactional
#end
@Override
public int update${ClassName}(${ClassName} ${className})
{
#foreach ($column in $columns)
#if($column.javaField == 'updateTime')
${className}.setUpdateTime(DateUtils.getNowDate());
#end
#end
#if($table.sub)
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
insert${subClassName}(${className});
#end
public int update${ClassName}(${ClassName} ${className}) {
#foreach ($column in $columns)
#if($column.javaField == 'updateTime')
${className}.setUpdateTime(DateUtils.getNowDate());
#end
#end
#if($table.sub)
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}())
;
insert${subClassName}(${className});
#end
return ${className}Mapper.update${ClassName}(${className});
}
/**
* 批量删除${functionName}
*
*
* @param ${pkColumn.javaField}s 需要删除的${functionName}ID
* @return 结果
*/
#if($table.sub)
@Transactional
#end
#if($table.sub)
@Transactional
#end
@Override
public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s)
{
#if($table.sub)
${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
#end
public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) {
#if($table.sub)
${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
#end
return ${className}Mapper.delete${ClassName}ByIds(${pkColumn.javaField}s);
}
/**
* 删除${functionName}信息
*
*
* @param ${pkColumn.javaField} ${functionName}ID
* @return 结果
*/
@Override
public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField})
{
#if($table.sub)
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
#end
public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) {
#if($table.sub)
${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
#end
return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField});
}
#if($table.sub)
#if($table.sub)
/**
* 新增${subTable.functionName}信息
*
* @param ${className} ${functionName}对象
*/
public void insert${subClassName}(${ClassName} ${className})
{
List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
if (StringUtils.isNotNull(${subclassName}List))
{
List<${subClassName}> list = new ArrayList<${subClassName}>();
for (${subClassName} ${subclassName} : ${subclassName}List)
{
${subclassName}.set${subTableFkClassName}(${pkColumn.javaField});
list.add(${subclassName});
}
if (list.size() > 0)
{
${className}Mapper.batch${subClassName}(list);
/**
* 新增${subTable.functionName}信息
*
* @param ${className} ${functionName}对象
*/
public void insert${subClassName}(${ClassName} ${className}) {
List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
if (StringUtils.isNotNull(${subclassName}List)) {
List<${subClassName}> list = new ArrayList<${subClassName}>();
for (${subClassName} ${subclassName} :${subclassName}List)
{
${subclassName}.set${subTableFkClassName}(${pkColumn.javaField});
list.add(${subclassName});
}
if (list.size() > 0) {
${className}Mapper.batch${subClassName}(list);
}
}
}
}
#end
#end
}

View File

@@ -1,8 +1,8 @@
package ${packageName}.domain;
#foreach ($import in $subImportList)
import ${import};
#end
#foreach ($import in $subImportList)
import ${import};
#end
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
@@ -10,67 +10,67 @@ import com.ruoyi.common.core.domain.BaseEntity;
/**
* ${subTable.functionName}对象 ${subTableName}
*
*
* @author ${author}
* @date ${datetime}
*/
public class ${subClassName} extends BaseEntity
{
private static final long serialVersionUID = 1L;
{
private static final long serialVersionUID=1L;
#foreach ($column in $subTable.columns)
#if(!$table.isSuperColumn($column.javaField))
#if(!$table.isSuperColumn($column.javaField))
/** $column.columnComment */
#if($column.list)
#set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else
#set($comment=$column.columnComment)
#end
#if($parentheseIndex != -1)
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
#elseif($column.javaType == 'Date')
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd")
#else
@Excel(name = "${comment}")
#end
#end
#if($column.list)
#set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else
#set($comment=$column.columnComment)
#end
#if($parentheseIndex != -1)
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
#elseif($column.javaType == 'Date')
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd")
#else
@Excel(name = "${comment}")
#end
#end
private $column.javaType $column.javaField;
#end
#end
#end
#foreach ($column in $subTable.columns)
#if(!$table.isSuperColumn($column.javaField))
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
public void set${AttrName}($column.javaType $column.javaField)
{
this.$column.javaField = $column.javaField;
}
#if(!$table.isSuperColumn($column.javaField))
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
public void set${AttrName}($column.javaType $column.javaField)
{
this.$column.javaField = $column.javaField;
}
public $column.javaType get${AttrName}()
{
return $column.javaField;
}
#end
public $column.javaType get${AttrName}()
{
return $column.javaField;
}
#end
#end
@Override
public String toString() {
@Override
public String toString(){
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
#foreach ($column in $subTable.columns)
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
.append("${column.javaField}", get${AttrName}())
#end
.toString();
}
}
#foreach ($column in $subTable.columns)
#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]"))
#set($AttrName=$column.javaField)
#else
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#end
.append("${column.javaField}",get${AttrName}())
#end
.toString();
}
}

View File

@@ -2,52 +2,52 @@ import request from '@/utils/request'
// 查询${functionName}列表
export function list${BusinessName}(query) {
return request({
url: '/${moduleName}/${businessName}/list',
method: 'get',
params: query
})
return request({
url: '/${moduleName}/${businessName}/list',
method: 'get',
params: query
})
}
// 查询${functionName}详细
export function get${BusinessName}(${pkColumn.javaField}) {
return request({
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
method: 'get'
})
return request({
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
method: 'get'
})
}
// 新增${functionName}
export function add${BusinessName}(data) {
return request({
url: '/${moduleName}/${businessName}',
method: 'post',
data: data
})
return request({
url: '/${moduleName}/${businessName}',
method: 'post',
data: data
})
}
// 修改${functionName}
export function update${BusinessName}(data) {
return request({
url: '/${moduleName}/${businessName}',
method: 'put',
data: data
})
return request({
url: '/${moduleName}/${businessName}',
method: 'put',
data: data
})
}
// 删除${functionName}
export function del${BusinessName}(${pkColumn.javaField}) {
return request({
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
method: 'delete'
})
return request({
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
method: 'delete'
})
}
// 导出${functionName}
export function export${BusinessName}(query) {
return request({
url: '/${moduleName}/${businessName}/export',
method: 'get',
params: query
})
return request({
url: '/${moduleName}/${businessName}/export',
method: 'get',
params: query
})
}

View File

@@ -1,103 +1,131 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.mapper.${ClassName}Mapper">
<resultMap type="${ClassName}" id="${ClassName}Result">
#foreach ($column in $columns)
<result property="${column.javaField}" column="${column.columnName}" />
#end
#foreach ($column in $columns)
<result property="${column.javaField}" column="${column.columnName}"/>
#end
</resultMap>
#if($table.sub)
#if($table.sub)
<resultMap id="${ClassName}${subClassName}Result" type="${ClassName}" extends="${ClassName}Result">
<collection property="${subclassName}List" notNullColumn="${subTable.pkColumn.columnName}" javaType="java.util.List" resultMap="${subClassName}Result" />
</resultMap>
<resultMap id="${ClassName}${subClassName}Result" type="${ClassName}" extends="${ClassName}Result">
<collection property="${subclassName}List" notNullColumn="${subTable.pkColumn.columnName}"
javaType="java.util.List" resultMap="${subClassName}Result"/>
</resultMap>
<resultMap type="${subClassName}" id="${subClassName}Result">
#foreach ($column in $subTable.columns)
<result property="${column.javaField}" column="${column.columnName}" />
#end
</resultMap>
#end
<resultMap type="${subClassName}" id="${subClassName}Result">
#foreach ($column in $subTable.columns)
<result property="${column.javaField}" column="${column.columnName}"/>
#end
</resultMap>
#end
<sql id="select${ClassName}Vo">
select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName}
select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end
from ${tableName}
</sql>
<select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}Result">
<include refid="select${ClassName}Vo"/>
<where>
#foreach($column in $columns)
#set($queryType=$column.queryType)
#set($javaField=$column.javaField)
#set($javaType=$column.javaType)
#set($columnName=$column.columnName)
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#if($column.query)
#if($column.queryType == "EQ")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if>
#elseif($queryType == "NE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if>
#elseif($queryType == "GT")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt; #{$javaField}</if>
#elseif($queryType == "GTE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &gt;= #{$javaField}</if>
#elseif($queryType == "LT")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt; #{$javaField}</if>
#elseif($queryType == "LTE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName &lt;= #{$javaField}</if>
#elseif($queryType == "LIKE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if>
#elseif($queryType == "BETWEEN")
<if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if>
#end
#end
#end
<where>
#foreach($column in $columns)
#set($queryType=$column.queryType)
#set($javaField=$column.javaField)
#set($javaType=$column.javaType)
#set($columnName=$column.columnName)
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#if($column.query)
#if($column.queryType == "EQ")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end">
and $columnName = #{$javaField}
</if>
#elseif($queryType == "NE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end">
and $columnName != #{$javaField}
</if>
#elseif($queryType == "GT")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end">
and $columnName &gt; #{$javaField}
</if>
#elseif($queryType == "GTE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end">
and $columnName &gt;= #{$javaField}
</if>
#elseif($queryType == "LT")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end">
and $columnName &lt; #{$javaField}
</if>
#elseif($queryType == "LTE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end">
and $columnName &lt;= #{$javaField}
</if>
#elseif($queryType == "LIKE")
<if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end">
and $columnName like concat('%', #{$javaField}, '%')
</if>
#elseif($queryType == "BETWEEN")
<if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''">
and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}
</if>
#end
#end
#end
</where>
</select>
<select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="#if($table.sub)${ClassName}${subClassName}Result#else${ClassName}Result#end">
#if($table.crud || $table.tree)
<include refid="select${ClassName}Vo"/>
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
#elseif($table.sub)
select#foreach($column in $columns) a.$column.columnName#if($velocityCount != $columns.size()),#end#end,
#foreach($column in $subTable.columns) b.$column.columnName#if($velocityCount != $subTable.columns.size()),#end#end
from ${tableName} a
left join ${subTableName} b on b.${subTableFkName} = a.${pkColumn.columnName}
where a.${pkColumn.columnName} = #{${pkColumn.javaField}}
#end
<select id="select${ClassName}ById" parameterType="${pkColumn.javaType}"
resultMap="#if($table.sub)${ClassName}${subClassName}Result#else${ClassName}Result#end">
#if($table.crud || $table.tree)
<include refid="select${ClassName}Vo"/>
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
#elseif($table.sub)
select#foreach($column in $columns) a.$column.columnName#if($velocityCount != $columns.size()),#end#end,
#foreach($column in $subTable.columns) b.$column.columnName#if($velocityCount != $subTable.columns.size())
,#end#end
from ${tableName} a
left join ${subTableName} b on b.${subTableFkName} = a.${pkColumn.columnName}
where a.${pkColumn.columnName} = #{${pkColumn.javaField}}
#end
</select>
<insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end>
<insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true"
keyProperty="$pkColumn.javaField"#end>
insert into ${tableName}
<trim prefix="(" suffix=")" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName,</if>
#end
#end
</trim>
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
<if test="$column.javaField != null#if($column.javaType ==
'String' && $column.required) and $column.javaField != ''#end">$column.columnName,
</if>
#end
#end
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},</if>
#end
#end
</trim>
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment)
<if test="$column.javaField != null#if($column.javaType ==
'String' && $column.required) and $column.javaField != ''#end">#{$column.javaField},
</if>
#end
#end
</trim>
</insert>
<update id="update${ClassName}" parameterType="${ClassName}">
update ${tableName}
<trim prefix="SET" suffixOverrides=",">
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName)
<if test="$column.javaField != null#if($column.javaType == 'String' && $column.required) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if>
#end
#end
#foreach($column in $columns)
#if($column.columnName != $pkColumn.columnName)
<if test="$column.javaField != null#if($column.javaType ==
'String' && $column.required) and $column.javaField != ''#end">$column.columnName =
#{$column.javaField},
</if>
#end
#end
</trim>
where ${pkColumn.columnName} = #{${pkColumn.javaField}}
</update>
@@ -107,29 +135,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<delete id="delete${ClassName}ByIds" parameterType="String">
delete from ${tableName} where ${pkColumn.columnName} in
delete from ${tableName} where ${pkColumn.columnName} in
<foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")">
#{${pkColumn.javaField}}
</foreach>
</delete>
#if($table.sub)
<delete id="delete${subClassName}By${subTableFkClassName}s" parameterType="String">
delete from ${subTableName} where ${subTableFkName} in
<foreach item="${subTableFkclassName}" collection="array" open="(" separator="," close=")">
#{${subTableFkclassName}}
</foreach>
</delete>
#if($table.sub)
<delete id="delete${subClassName}By${subTableFkClassName}" parameterType="Long">
delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}}
</delete>
<delete id="delete${subClassName}By${subTableFkClassName}s" parameterType="String">
delete from ${subTableName} where ${subTableFkName} in
<foreach item="${subTableFkclassName}" collection="array" open="(" separator="," close=")">
#{${subTableFkclassName}}
</foreach>
</delete>
<insert id="batch${subClassName}">
insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($velocityCount != $subTable.columns.size()),#end#end) values
<foreach item="item" index="index" collection="list" separator=",">
(#foreach($column in $subTable.columns) #{item.$column.javaField}#if($velocityCount != $subTable.columns.size()),#end#end)
</foreach>
</insert>
#end
<delete id="delete${subClassName}By${subTableFkClassName}" parameterType="Long">
delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}}
</delete>
<insert id="batch${subClassName}">
insert into ${subTableName}
(#foreach($column in $subTable.columns) $column.columnName#if($velocityCount != $subTable.columns.size())
,#end#end) values
<foreach item="item" index="index" collection="list" separator=",">
(#foreach($column in $subTable.columns) #{item.$column.javaField
}#if($velocityCount != $subTable.columns.size()),#end#end)
</foreach>
</insert>
#end
</mapper>