From 19acd33048ad2dab354aefe10f3b7fb249342985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BA=91=E5=BF=97?= Date: Thu, 31 Dec 2020 10:59:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E3=80=81=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E6=8E=A5=E5=8F=A3=E4=B9=8B=E5=89=8D=20I=20=E5=AD=97?= =?UTF-8?q?=E6=AF=8D=E3=80=81=E6=B7=BB=E5=8A=A0=20Slf4j?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/gen/RuoYiGenApplication.java | 14 +- .../java/com/ruoyi/gen/config/GenConfig.java | 45 ++- .../ruoyi/gen/controller/GenController.java | 72 ++--- .../java/com/ruoyi/gen/domain/GenTable.java | 241 ++++++++------- .../com/ruoyi/gen/domain/GenTableColumn.java | 279 ++++++++---------- .../gen/mapper/GenTableColumnMapper.java | 20 +- .../com/ruoyi/gen/mapper/GenTableMapper.java | 24 +- .../service/GenTableColumnServiceImpl.java | 72 +++-- .../gen/service/GenTableServiceImpl.java | 222 ++++++-------- .../gen/service/IGenTableColumnService.java | 16 +- .../ruoyi/gen/service/IGenTableService.java | 34 +-- .../java/com/ruoyi/gen/util/GenUtils.java | 127 +++----- .../ruoyi/gen/util/VelocityInitializer.java | 20 +- .../com/ruoyi/gen/util/VelocityUtils.java | 185 +++++------- .../main/resources/vm/java/controller.java.vm | 4 +- .../src/main/resources/vm/java/domain.java.vm | 37 +-- .../main/resources/vm/java/service.java.vm | 2 +- .../resources/vm/java/serviceImpl.java.vm | 6 +- .../src/main/resources/vm/xml/mapper.xml.vm | 4 +- 19 files changed, 602 insertions(+), 822 deletions(-) diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java index 955cbeb4..726c6668 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java @@ -1,24 +1,22 @@ package com.ruoyi.gen; -import org.springframework.boot.SpringApplication; -import org.springframework.cloud.client.SpringCloudApplication; import com.ruoyi.common.security.annotation.EnableCustomConfig; import com.ruoyi.common.security.annotation.EnableRyFeignClients; import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2; +import org.springframework.boot.SpringApplication; +import org.springframework.cloud.client.SpringCloudApplication; /** * 代码生成 - * + * * @author ruoyi */ @EnableCustomConfig -@EnableCustomSwagger2 +@EnableCustomSwagger2 @EnableRyFeignClients @SpringCloudApplication -public class RuoYiGenApplication -{ - public static void main(String[] args) - { +public class RuoYiGenApplication { + public static void main(String[] args) { SpringApplication.run(RuoYiGenApplication.class, args); System.out.println("(♥◠‿◠)ノ゙ 代码生成模块启动成功 ლ(´ڡ`ლ)゙ \n" + " .-------. ____ __ \n" + diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/config/GenConfig.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/config/GenConfig.java index 7bfdfe20..b0d546ef 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/config/GenConfig.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/config/GenConfig.java @@ -5,62 +5,61 @@ import org.springframework.stereotype.Component; /** * 代码生成相关配置 - * + * * @author ruoyi */ @Component @ConfigurationProperties(prefix = "gen") -public class GenConfig -{ - /** 作者 */ +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; } - public void setAuthor(String author) - { + public void setAuthor(String author) { GenConfig.author = author; } - public static String getPackageName() - { + public static String getPackageName() { return packageName; } - public void setPackageName(String packageName) - { + public void setPackageName(String packageName) { GenConfig.packageName = packageName; } - public static boolean getAutoRemovePre() - { + public static boolean getAutoRemovePre() { return autoRemovePre; } - public void setAutoRemovePre(boolean autoRemovePre) - { + public void setAutoRemovePre(boolean autoRemovePre) { GenConfig.autoRemovePre = autoRemovePre; } - public static String getTablePrefix() - { + public static String getTablePrefix() { return tablePrefix; } - public void setTablePrefix(String tablePrefix) - { + public void setTablePrefix(String tablePrefix) { GenConfig.tablePrefix = tablePrefix; } } diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java index bcfe1bb5..2e6027dd 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java @@ -1,21 +1,5 @@ package com.ruoyi.gen.controller; -import java.io.IOException; -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.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.domain.AjaxResult; @@ -27,16 +11,25 @@ import com.ruoyi.gen.domain.GenTable; import com.ruoyi.gen.domain.GenTableColumn; import com.ruoyi.gen.service.IGenTableColumnService; import com.ruoyi.gen.service.IGenTableService; +import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * 代码生成 操作处理 - * + * * @author ruoyi */ @RequestMapping("/gen") @RestController -public class GenController extends BaseController -{ +public class GenController extends BaseController { @Autowired private IGenTableService genTableService; @@ -48,8 +41,7 @@ public class GenController extends BaseController */ @PreAuthorize(hasPermi = "tool:gen:list") @GetMapping("/list") - public TableDataInfo genList(GenTable genTable) - { + public TableDataInfo genList(GenTable genTable) { startPage(); List list = genTableService.selectGenTableList(genTable); return getDataTable(list); @@ -60,8 +52,7 @@ public class GenController extends BaseController */ @PreAuthorize(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 list = genTableColumnService.selectGenTableColumnListByTableId(talbleId); Map map = new HashMap(); @@ -75,8 +66,7 @@ public class GenController extends BaseController */ @PreAuthorize(hasPermi = "tool:gen:list") @GetMapping("/db/list") - public TableDataInfo dataList(GenTable genTable) - { + public TableDataInfo dataList(GenTable genTable) { startPage(); List list = genTableService.selectDbTableList(genTable); return getDataTable(list); @@ -86,8 +76,7 @@ public class GenController extends BaseController * 查询数据表字段列表 */ @GetMapping(value = "/column/{talbleId}") - public TableDataInfo columnList(Long tableId) - { + public TableDataInfo columnList(Long tableId) { TableDataInfo dataInfo = new TableDataInfo(); List list = genTableColumnService.selectGenTableColumnListByTableId(tableId); dataInfo.setRows(list); @@ -101,8 +90,7 @@ public class GenController extends BaseController @PreAuthorize(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 tableList = genTableService.selectDbTableListByNames(tableNames); @@ -116,8 +104,7 @@ public class GenController extends BaseController @PreAuthorize(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(); @@ -129,8 +116,7 @@ public class GenController extends BaseController @PreAuthorize(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(); } @@ -140,8 +126,7 @@ public class GenController extends BaseController */ @PreAuthorize(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 dataMap = genTableService.previewCode(tableId); return AjaxResult.success(dataMap); } @@ -152,8 +137,7 @@ public class GenController extends BaseController @PreAuthorize(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); } @@ -164,8 +148,7 @@ public class GenController extends BaseController @PreAuthorize(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(); } @@ -176,8 +159,7 @@ public class GenController extends BaseController @PreAuthorize(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(); } @@ -188,8 +170,7 @@ public class GenController extends BaseController @PreAuthorize(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); @@ -198,10 +179,9 @@ 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.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); + response.setHeader("Content-Disposition", "attachment; filename=\"code.zip\""); response.addHeader("Content-Length", "" + data.length); response.setContentType("application/octet-stream; charset=UTF-8"); IOUtils.write(data, response.getOutputStream()); diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java index 8b62ae74..768cc203 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java @@ -1,320 +1,313 @@ package com.ruoyi.gen.domain; -import java.util.List; -import javax.validation.Valid; -import javax.validation.constraints.NotBlank; -import org.apache.commons.lang3.ArrayUtils; import com.ruoyi.common.core.constant.GenConstants; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.web.domain.BaseEntity; +import org.apache.commons.lang3.ArrayUtils; + +import javax.validation.Valid; +import javax.validation.constraints.NotBlank; +import java.util.List; /** * 业务表 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; - /** 实体类名称(首字母大写) */ + /** + * 实体类名称(首字母大写) + */ @NotBlank(message = "实体类名称不能为空") private String className; - /** 使用的模板(crud单表操作 tree树表操作) */ + /** + * 使用的模板(crud单表操作 tree树表操作) + */ 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; - /** 表列信息 */ + /** + * 表列信息 + */ @Valid private List 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 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 List getColumns() - { + public List getColumns() { return columns; } - public void setColumns(List columns) - { + public void setColumns(List 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 isTree() - { - return isTree(this.tplCategory); + public boolean isTree() { + return isTree(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() - { - return isCrud(this.tplCategory); + public boolean isCrud() { + return isCrud(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) - { - return isSuperColumn(this.tplCategory, javaField); + public boolean isSuperColumn(String javaField) { + return isSuperColumn(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)); } diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java index 9b364b96..029cf952 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java @@ -1,331 +1,314 @@ package com.ruoyi.gen.domain; -import javax.validation.constraints.NotBlank; - import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.web.domain.BaseEntity; +import javax.validation.constraints.NotBlank; + /** * 代码生成业务字段表 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日期控件、upload上传控件、editor富文本控件) */ + /** + * 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、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 void setIsPk(String isPk) - { + public void setIsPk(String isPk) { this.isPk = isPk; } - public String getIsPk() - { + public String getIsPk() { return isPk; } - public boolean isPk() - { - return isPk(this.isPk); + public boolean isPk() { + return isPk(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() - { - return isIncrement(this.isIncrement); + public boolean isIncrement() { + return isIncrement(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() - { - return isRequired(this.isRequired); + public boolean isRequired() { + return isRequired(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() - { - return isInsert(this.isInsert); + public boolean isInsert() { + return isInsert(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() - { - return isInsert(this.isEdit); + public boolean isEdit() { + return isInsert(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() - { - return isList(this.isList); + public boolean isList() { + return isList(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() - { - return isQuery(this.isQuery); + public boolean isQuery() { + return isQuery(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() - { - return isSuperColumn(this.javaField); + public boolean isSuperColumn() { + return isSuperColumn(javaField); } - public static boolean isSuperColumn(String javaField) - { + public static boolean isSuperColumn(String javaField) { return StringUtils.equalsAnyIgnoreCase(javaField, // BaseEntity "createBy", "createTime", "updateBy", "updateTime", "remark", @@ -333,37 +316,29 @@ 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() - { - String remarks = StringUtils.substringBetween(this.columnComment, "(", ")"); + public String readConverterExp() { + String remarks = StringUtils.substringBetween(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 - { - return this.columnComment; + } else { + return columnComment; } } } \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableColumnMapper.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableColumnMapper.java index e5df0027..407139a7 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableColumnMapper.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableColumnMapper.java @@ -1,18 +1,18 @@ package com.ruoyi.gen.mapper; -import java.util.List; import com.ruoyi.gen.domain.GenTableColumn; +import java.util.List; + /** * 业务字段 数据层 - * + * * @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 结果 */ diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java index b5ef2985..b05fb285 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java @@ -1,18 +1,18 @@ package com.ruoyi.gen.mapper; -import java.util.List; import com.ruoyi.gen.domain.GenTable; +import java.util.List; + /** * 业务 数据层 - * + * * @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,7 +36,7 @@ public interface GenTableMapper /** * 查询表ID业务信息 - * + * * @param id 业务ID * @return 业务信息 */ @@ -44,7 +44,7 @@ public interface GenTableMapper /** * 查询表名称业务信息 - * + * * @param tableName 表名称 * @return 业务信息 */ @@ -52,7 +52,7 @@ public interface GenTableMapper /** * 新增业务 - * + * * @param genTable 业务信息 * @return 结果 */ @@ -60,7 +60,7 @@ public interface GenTableMapper /** * 修改业务 - * + * * @param genTable 业务信息 * @return 结果 */ @@ -68,7 +68,7 @@ public interface GenTableMapper /** * 批量删除业务 - * + * * @param ids 需要删除的数据ID * @return 结果 */ diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableColumnServiceImpl.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableColumnServiceImpl.java index 8aac0e40..d6e8ad8a 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableColumnServiceImpl.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableColumnServiceImpl.java @@ -1,68 +1,64 @@ package com.ruoyi.gen.service; -import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import com.ruoyi.common.core.text.Convert; import com.ruoyi.gen.domain.GenTableColumn; import com.ruoyi.gen.mapper.GenTableColumnMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; /** * 业务字段 服务层实现 - * + * * @author ruoyi */ -@Service -public class GenTableColumnServiceImpl implements IGenTableColumnService -{ - @Autowired - private GenTableColumnMapper genTableColumnMapper; +@Service("genTableColumnService") +public class GenTableColumnServiceImpl implements IGenTableColumnService { + @Autowired + private GenTableColumnMapper genTableColumnMapper; - /** + /** * 查询业务字段列表 - * + * * @param tableId 业务字段编号 * @return 业务字段集合 */ - @Override - public List selectGenTableColumnListByTableId(Long tableId) - { - return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); - } - + @Override + public List selectGenTableColumnListByTableId(Long tableId) { + return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); + } + /** * 新增业务字段 - * + * * @param genTableColumn 业务字段信息 * @return 结果 */ - @Override - public int insertGenTableColumn(GenTableColumn genTableColumn) - { - return genTableColumnMapper.insertGenTableColumn(genTableColumn); - } - - /** + @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 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)); + } } \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java index 34e6d751..5ed9aa57 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java @@ -1,24 +1,5 @@ package com.ruoyi.gen.service; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.StringWriter; -import java.util.LinkedHashMap; -import java.util.List; -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; -import org.apache.velocity.app.Velocity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.constant.Constants; @@ -35,15 +16,34 @@ import com.ruoyi.gen.mapper.GenTableMapper; import com.ruoyi.gen.util.GenUtils; import com.ruoyi.gen.util.VelocityInitializer; import com.ruoyi.gen.util.VelocityUtils; +import org.apache.commons.io.IOUtils; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; /** * 业务 服务层实现 - * + * * @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,57 +67,51 @@ public class GenTableServiceImpl implements IGenTableService /** * 查询业务列表 - * + * * @param genTable 业务信息 * @return 业务集合 */ @Override - public List selectGenTableList(GenTable genTable) - { + public List selectGenTableList(GenTable genTable) { return genTableMapper.selectGenTableList(genTable); } /** * 查询据库列表 - * + * * @param genTable 业务信息 * @return 数据库表集合 */ @Override - public List selectDbTableList(GenTable genTable) - { + public List selectDbTableList(GenTable genTable) { return genTableMapper.selectDbTableList(genTable); } /** * 查询据库列表 - * + * * @param tableNames 表名称组 * @return 数据库表集合 */ @Override - public List selectDbTableListByNames(String[] tableNames) - { + public List selectDbTableListByNames(String[] tableNames) { return genTableMapper.selectDbTableListByNames(tableNames); } /** * 修改业务 - * + * * @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); } } @@ -126,61 +119,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 tableList) - { + public void importGenTable(List 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 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 预览数据列表 */ - public Map previewCode(Long tableId) - { + @Override + public Map previewCode(Long tableId) { Map dataMap = new LinkedHashMap<>(); // 查询表信息 GenTable table = genTableMapper.selectGenTableById(tableId); @@ -193,8 +178,7 @@ public class GenTableServiceImpl implements IGenTableService // 获取模板列表 List templates = VelocityUtils.getTemplateList(table.getTplCategory()); - for (String template : templates) - { + for (String template : templates) { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); @@ -206,13 +190,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); @@ -222,12 +205,11 @@ public class GenTableServiceImpl implements IGenTableService /** * 生成代码(自定义路径) - * + * * @param tableName 表名称 */ @Override - public void generatorCode(String tableName) - { + public void generatorCode(String tableName) { // 查询表信息 GenTable table = genTableMapper.selectGenTableByName(tableName); // 查询列信息 @@ -240,21 +222,16 @@ public class GenTableServiceImpl implements IGenTableService // 获取模板列表 List 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()); } } @@ -263,13 +240,12 @@ 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 tableColumns = table.getColumns(); List tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); @@ -278,33 +254,29 @@ public class GenTableServiceImpl implements IGenTableService List 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 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); @@ -314,8 +286,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); // 查询列信息 @@ -328,23 +299,19 @@ public class GenTableServiceImpl implements IGenTableService // 获取模板列表 List 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); } } @@ -352,26 +319,19 @@ 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("树名称字段不能为空"); } } @@ -379,42 +339,36 @@ public class GenTableServiceImpl implements IGenTableService /** * 设置主键列信息 - * - * @param table 业务表信息 + * + * @param table 业务表信息 * @param columns 业务字段列表 */ - public void setPkColumn(GenTable table, List columns) - { - for (GenTableColumn column : columns) - { - if (column.isPk()) - { + public void setPkColumn(GenTable table, List columns) { + for (GenTableColumn column : columns) { + if (column.isPk()) { table.setPkColumn(column); break; } } - if (StringUtils.isNull(table.getPkColumn())) - { + if (StringUtils.isNull(table.getPkColumn())) { table.setPkColumn(columns.get(0)); } } /** * 设置代码生成其他选项值 - * + * * @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); @@ -425,16 +379,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); diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableColumnService.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableColumnService.java index f7dec848..db3159c5 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableColumnService.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableColumnService.java @@ -1,18 +1,18 @@ package com.ruoyi.gen.service; -import java.util.List; import com.ruoyi.gen.domain.GenTableColumn; +import java.util.List; + /** * 业务字段 服务层 - * + * * @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 结果 */ diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java index 010f92bc..5872c799 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java @@ -1,19 +1,19 @@ package com.ruoyi.gen.service; +import com.ruoyi.gen.domain.GenTable; + import java.util.List; import java.util.Map; -import com.ruoyi.gen.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,7 +37,7 @@ public interface IGenTableService /** * 查询业务信息 - * + * * @param id 业务ID * @return 业务信息 */ @@ -45,7 +45,7 @@ public interface IGenTableService /** * 修改业务 - * + * * @param genTable 业务信息 * @return 结果 */ @@ -53,7 +53,7 @@ public interface IGenTableService /** * 删除业务信息 - * + * * @param tableIds 需要删除的表数据ID * @return 结果 */ @@ -61,14 +61,14 @@ public interface IGenTableService /** * 导入表结构 - * + * * @param tableList 导入表列表 */ public void importGenTable(List tableList); /** * 预览代码 - * + * * @param tableId 表编号 * @return 预览数据列表 */ @@ -76,7 +76,7 @@ public interface IGenTableService /** * 生成代码(下载方式) - * + * * @param tableName 表名称 * @return 数据 */ @@ -84,7 +84,7 @@ public interface IGenTableService /** * 生成代码(自定义路径) - * + * * @param tableName 表名称 * @return 数据 */ @@ -92,14 +92,14 @@ public interface IGenTableService /** * 同步数据库 - * + * * @param tableName 表名称 */ public void synchDb(String tableName); /** * 批量生成代码(下载方式) - * + * * @param tableNames 表数组 * @return 数据 */ @@ -107,7 +107,7 @@ public interface IGenTableService /** * 修改保存参数校验 - * + * * @param genTable 业务信息 */ public void validateEdit(GenTable genTable); diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java index f3860585..9a3c35e0 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java @@ -1,25 +1,24 @@ package com.ruoyi.gen.util; -import java.util.Arrays; -import org.apache.commons.lang3.RegExUtils; import com.ruoyi.common.core.constant.GenConstants; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.gen.config.GenConfig; import com.ruoyi.gen.domain.GenTable; import com.ruoyi.gen.domain.GenTableColumn; +import org.apache.commons.lang3.RegExUtils; + +import java.util.Arrays; /** * 代码生成器 工具类 - * + * * @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()); @@ -41,37 +39,29 @@ public class GenUtils // 设置java字段名 column.setJavaField(StringUtils.toCamelCase(columnName)); - if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType)) - { + if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType)) { column.setJavaType(GenConstants.TYPE_STRING); // 字符串长度超过500设置为文本域 Integer columnLength = getColumnLength(column.getColumnType()); String htmlType = columnLength >= 500 ? 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); // 如果是浮点型 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); } } @@ -80,69 +70,59 @@ 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_UPLOAD_IMAGE); } // 内容字段设置富文本控件 - 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); @@ -151,12 +131,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); @@ -165,16 +144,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); } @@ -183,18 +160,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; } @@ -204,48 +178,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; } } diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityInitializer.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityInitializer.java index 09af096d..8c6e5a79 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityInitializer.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityInitializer.java @@ -1,24 +1,22 @@ package com.ruoyi.gen.util; -import java.util.Properties; -import org.apache.velocity.app.Velocity; import com.ruoyi.common.core.constant.Constants; +import org.apache.velocity.app.Velocity; + +import java.util.Properties; /** * 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); } } diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java index 2830c985..7ebd81a1 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java @@ -1,39 +1,46 @@ package com.ruoyi.gen.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.core.constant.GenConstants; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.gen.domain.GenTable; import com.ruoyi.gen.domain.GenTableColumn; +import lombok.extern.slf4j.Slf4j; +import org.apache.velocity.VelocityContext; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; /** * 模板工具类 - * + * * @author ruoyi */ -public class VelocityUtils -{ - /** 项目空间路径 */ - private static final String PROJECT_PATH = "main/java"; +@Slf4j +public class VelocityUtils { + /** + * 项目空间路径 + */ + private static final String PROJECT_PATH = "java"; + + /** + * mybatis空间路径 + */ + private static final String MYBATIS_PATH = "resources/mapper"; - /** mybatis空间路径 */ - private static final String MYBATIS_PATH = "main/resources/mapper"; - - /** 默认上级菜单,系统工具 */ + /** + * 默认上级菜单,系统工具 + */ private static final String DEFAULT_PARENT_MENU_ID = "3"; /** * 设置模板变量信息 - * + * * @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,23 +66,20 @@ 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); } 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); @@ -86,23 +90,20 @@ 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)); } } /** * 获取模板信息 - * + * * @return 模板列表 */ - public static List getTemplateList(String tplCategory) - { + public static List getTemplateList(String tplCategory) { List templates = new ArrayList(); templates.add("vm/java/domain.java.vm"); templates.add("vm/java/mapper.java.vm"); @@ -112,12 +113,9 @@ 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"); } return templates; @@ -126,8 +124,7 @@ public class VelocityUtils /** * 获取文件名 */ - public static String getFileName(String template, GenTable genTable) - { + public static String getFileName(String template, GenTable genTable) { // 文件名称 String fileName = ""; // 包路径 @@ -143,44 +140,25 @@ 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); - } - 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")) - { - fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); - } - else if (template.contains("serviceImpl.java.vm")) - { + } else if (template.contains("service.java.vm")) { + fileName = StringUtils.format("{}/service/{}Service.java", javaPath, className); + } 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; @@ -188,12 +166,11 @@ 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; @@ -201,22 +178,17 @@ public class VelocityUtils /** * 根据列类型获取导入包 - * + * * @param columns 列集合 * @return 返回需要导入的包列表 */ - public static HashSet getImportList(List columns) - { + public static HashSet getImportList(List columns) { HashSet importList = new HashSet(); - 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"); } } @@ -225,26 +197,23 @@ 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); } /** * 获取上级菜单ID字段 - * + * * @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; @@ -252,14 +221,12 @@ 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; @@ -267,14 +234,12 @@ 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; @@ -282,14 +247,12 @@ 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; @@ -297,24 +260,20 @@ 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; } } diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm index 67d8e6cc..6db308fc 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm @@ -16,7 +16,7 @@ import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.security.annotation.PreAuthorize; import ${packageName}.domain.${ClassName}; -import ${packageName}.service.I${ClassName}Service; +import ${packageName}.service.${ClassName}Service; import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.utils.poi.ExcelUtil; @@ -36,7 +36,7 @@ import com.ruoyi.common.core.web.page.TableDataInfo; public class ${ClassName}Controller extends BaseController { @Autowired - private I${ClassName}Service ${className}Service; + private ${ClassName}Service ${className}Service; /** * 查询${functionName}列表 diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm index 92b089a9..a8bb1211 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm @@ -11,7 +11,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity; #elseif($table.tree) import com.ruoyi.common.core.web.domain.TreeEntity; #end - +import lombok.extern.slf4j.Slf4j; /** * ${functionName}对象 ${tableName} * @@ -23,6 +23,7 @@ import com.ruoyi.common.core.web.domain.TreeEntity; #elseif($table.tree) #set($Entity="TreeEntity") #end +@Slf4j public class ${ClassName} extends ${Entity} { private static final long serialVersionUID = 1L; @@ -50,36 +51,4 @@ public class ${ClassName} extends ${Entity} #end #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; - } - - public $column.javaType get${AttrName}() - { - return $column.javaField; - } -#end -#end - - @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 - .toString(); - } -} +} \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/service.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/service.java.vm index af422f34..18ae63b5 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/service.java.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/service.java.vm @@ -9,7 +9,7 @@ import ${packageName}.domain.${ClassName}; * @author ${author} * @date ${datetime} */ -public interface I${ClassName}Service +public interface ${ClassName}Service { /** * 查询${functionName} diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/serviceImpl.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/serviceImpl.java.vm index f6cc71ce..373cff3b 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/serviceImpl.java.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/serviceImpl.java.vm @@ -11,7 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import ${packageName}.mapper.${ClassName}Mapper; import ${packageName}.domain.${ClassName}; -import ${packageName}.service.I${ClassName}Service; +import ${packageName}.service.${ClassName}Service; /** * ${functionName}Service业务层处理 @@ -19,8 +19,8 @@ import ${packageName}.service.I${ClassName}Service; * @author ${author} * @date ${datetime} */ -@Service -public class ${ClassName}ServiceImpl implements I${ClassName}Service +@Service("${moduleName}${ClassName}Service") +public class ${ClassName}ServiceImpl implements ${ClassName}Service { @Autowired private ${ClassName}Mapper ${className}Mapper; diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/xml/mapper.xml.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/xml/mapper.xml.vm index 6c490a4b..4ebb9c37 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/xml/mapper.xml.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/xml/mapper.xml.vm @@ -1,7 +1,5 @@ - +