若依 3.0
This commit is contained in:
		| @@ -0,0 +1,73 @@ | ||||
| package com.ruoyi.generator.config; | ||||
|  | ||||
| import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||||
| import org.springframework.context.annotation.PropertySource; | ||||
| import org.springframework.stereotype.Component; | ||||
|  | ||||
| /** | ||||
|  * 读取代码生成相关配置 | ||||
|  *  | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| @Component | ||||
| @ConfigurationProperties(prefix = "gen") | ||||
| @PropertySource(value = { "classpath:generator.yml" }) | ||||
| public class GenConfig | ||||
| { | ||||
|     /** 作者 */ | ||||
|     public static String author; | ||||
|  | ||||
|     /** 生成包路径 */ | ||||
|     public static String packageName; | ||||
|  | ||||
|     /** 自动去除表前缀,默认是false */ | ||||
|     public static boolean autoRemovePre; | ||||
|  | ||||
|     /** 表前缀(类名不会包含表前缀) */ | ||||
|     public static String tablePrefix; | ||||
|  | ||||
|     public static String getAuthor() | ||||
|     { | ||||
|         return author; | ||||
|     } | ||||
|  | ||||
|     @Value("${author}") | ||||
|     public void setAuthor(String author) | ||||
|     { | ||||
|         GenConfig.author = author; | ||||
|     } | ||||
|  | ||||
|     public static String getPackageName() | ||||
|     { | ||||
|         return packageName; | ||||
|     } | ||||
|  | ||||
|     @Value("${packageName}") | ||||
|     public void setPackageName(String packageName) | ||||
|     { | ||||
|         GenConfig.packageName = packageName; | ||||
|     } | ||||
|  | ||||
|     public static boolean getAutoRemovePre() | ||||
|     { | ||||
|         return autoRemovePre; | ||||
|     } | ||||
|  | ||||
|     @Value("${autoRemovePre}") | ||||
|     public void setAutoRemovePre(boolean autoRemovePre) | ||||
|     { | ||||
|         GenConfig.autoRemovePre = autoRemovePre; | ||||
|     } | ||||
|  | ||||
|     public static String getTablePrefix() | ||||
|     { | ||||
|         return tablePrefix; | ||||
|     } | ||||
|  | ||||
|     @Value("${tablePrefix}") | ||||
|     public void setTablePrefix(String tablePrefix) | ||||
|     { | ||||
|         GenConfig.tablePrefix = tablePrefix; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,186 @@ | ||||
| package com.ruoyi.generator.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.security.access.prepost.PreAuthorize; | ||||
| 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.annotation.Log; | ||||
| import com.ruoyi.common.core.controller.BaseController; | ||||
| import com.ruoyi.common.core.domain.AjaxResult; | ||||
| import com.ruoyi.common.core.page.TableDataInfo; | ||||
| import com.ruoyi.common.core.text.Convert; | ||||
| import com.ruoyi.common.enums.BusinessType; | ||||
| import com.ruoyi.generator.domain.GenTable; | ||||
| import com.ruoyi.generator.domain.GenTableColumn; | ||||
| import com.ruoyi.generator.service.IGenTableColumnService; | ||||
| import com.ruoyi.generator.service.IGenTableService; | ||||
|  | ||||
| /** | ||||
|  * 代码生成 操作处理 | ||||
|  *  | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| @RestController | ||||
| @RequestMapping("/tool/gen") | ||||
| public class GenController extends BaseController | ||||
| { | ||||
|     @Autowired | ||||
|     private IGenTableService genTableService; | ||||
|  | ||||
|     @Autowired | ||||
|     private IGenTableColumnService genTableColumnService; | ||||
|  | ||||
|     /** | ||||
|      * 查询代码生成列表 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||||
|     @GetMapping("/list") | ||||
|     public TableDataInfo genList(GenTable genTable) | ||||
|     { | ||||
|         startPage(); | ||||
|         List<GenTable> list = genTableService.selectGenTableList(genTable); | ||||
|         return getDataTable(list); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改代码生成业务 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:query')") | ||||
|     @GetMapping(value = "/{talbleId}") | ||||
|     public AjaxResult getInfo(@PathVariable Long talbleId) | ||||
|     { | ||||
|         GenTable table = genTableService.selectGenTableById(talbleId); | ||||
|         List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId); | ||||
|         Map<String, Object> map = new HashMap<String, Object>(); | ||||
|         map.put("info", table); | ||||
|         map.put("rows", list); | ||||
|         return AjaxResult.success(map); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询数据库列表 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||||
|     @GetMapping("/db/list") | ||||
|     public TableDataInfo dataList(GenTable genTable) | ||||
|     { | ||||
|         startPage(); | ||||
|         List<GenTable> list = genTableService.selectDbTableList(genTable); | ||||
|         return getDataTable(list); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询数据表字段列表 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||||
|     @GetMapping(value = "/column/{talbleId}") | ||||
|     public TableDataInfo columnList(Long tableId) | ||||
|     { | ||||
|         TableDataInfo dataInfo = new TableDataInfo(); | ||||
|         List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); | ||||
|         dataInfo.setRows(list); | ||||
|         dataInfo.setTotal(list.size()); | ||||
|         return dataInfo; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 导入表结构(保存) | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||||
|     @Log(title = "代码生成", businessType = BusinessType.IMPORT) | ||||
|     @PostMapping("/importTable") | ||||
|     public AjaxResult importTableSave(String tables) | ||||
|     { | ||||
|         String[] tableNames = Convert.toStrArray(tables); | ||||
|         // 查询表信息 | ||||
|         List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); | ||||
|         genTableService.importGenTable(tableList); | ||||
|         return AjaxResult.success(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改保存代码生成业务 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:edit')") | ||||
|     @Log(title = "代码生成", businessType = BusinessType.UPDATE) | ||||
|     @PutMapping | ||||
|     public AjaxResult editSave(@Validated @RequestBody GenTable genTable) | ||||
|     { | ||||
|         genTableService.validateEdit(genTable); | ||||
|         genTableService.updateGenTable(genTable); | ||||
|         return AjaxResult.success(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除代码生成 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:remove')") | ||||
|     @Log(title = "代码生成", businessType = BusinessType.DELETE) | ||||
|     @DeleteMapping("/{tableIds}") | ||||
|     public AjaxResult remove(@PathVariable Long[] tableIds) | ||||
|     { | ||||
|         genTableService.deleteGenTableByIds(tableIds); | ||||
|         return AjaxResult.success(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 预览代码 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:preview')") | ||||
|     @GetMapping("/preview/{tableId}") | ||||
|     public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException | ||||
|     { | ||||
|         Map<String, String> dataMap = genTableService.previewCode(tableId); | ||||
|         return AjaxResult.success(dataMap); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 生成代码 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:code')") | ||||
|     @Log(title = "代码生成", businessType = BusinessType.GENCODE) | ||||
|     @GetMapping("/genCode/{tableName}") | ||||
|     public void genCode(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException | ||||
|     { | ||||
|         byte[] data = genTableService.generatorCode(tableName); | ||||
|         genCode(response, data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 批量生成代码 | ||||
|      */ | ||||
|     @PreAuthorize("@ss.hasPermi('tool:gen:code')") | ||||
|     @Log(title = "代码生成", businessType = BusinessType.GENCODE) | ||||
|     @GetMapping("/batchGenCode") | ||||
|     public void batchGenCode(HttpServletResponse response, String tables) throws IOException | ||||
|     { | ||||
|         String[] tableNames = Convert.toStrArray(tables); | ||||
|         byte[] data = genTableService.generatorCode(tableNames); | ||||
|         genCode(response, data); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 生成zip文件 | ||||
|      */ | ||||
|     private void genCode(HttpServletResponse response, byte[] data) throws IOException | ||||
|     { | ||||
|         response.reset(); | ||||
|         response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); | ||||
|         response.addHeader("Content-Length", "" + data.length); | ||||
|         response.setContentType("application/octet-stream; charset=UTF-8"); | ||||
|         IOUtils.write(data, response.getOutputStream()); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,271 @@ | ||||
| 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; | ||||
| import com.ruoyi.common.utils.StringUtils; | ||||
|  | ||||
| /** | ||||
|  * 业务表 gen_table | ||||
|  *  | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| 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树表操作) */ | ||||
|     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; | ||||
|  | ||||
|     /** 主键信息 */ | ||||
|     private GenTableColumn pkColumn; | ||||
|  | ||||
|     /** 表列信息 */ | ||||
|     @Valid | ||||
|     private List<GenTableColumn> columns; | ||||
|  | ||||
|     /** 其它生成选项 */ | ||||
|     private String options; | ||||
|  | ||||
|     /** 树编码字段 */ | ||||
|     private String treeCode; | ||||
|  | ||||
|     /** 树父编码字段 */ | ||||
|     private String treeParentCode; | ||||
|  | ||||
|     /** 树名称字段 */ | ||||
|     private String treeName; | ||||
|  | ||||
|     public Long getTableId() | ||||
|     { | ||||
|         return tableId; | ||||
|     } | ||||
|  | ||||
|     public void setTableId(Long tableId) | ||||
|     { | ||||
|         this.tableId = tableId; | ||||
|     } | ||||
|  | ||||
|     public String getTableName() | ||||
|     { | ||||
|         return tableName; | ||||
|     } | ||||
|  | ||||
|     public void setTableName(String tableName) | ||||
|     { | ||||
|         this.tableName = tableName; | ||||
|     } | ||||
|  | ||||
|     public String getTableComment() | ||||
|     { | ||||
|         return tableComment; | ||||
|     } | ||||
|  | ||||
|     public void setTableComment(String tableComment) | ||||
|     { | ||||
|         this.tableComment = tableComment; | ||||
|     } | ||||
|  | ||||
|     public String getClassName() | ||||
|     { | ||||
|         return className; | ||||
|     } | ||||
|  | ||||
|     public void setClassName(String className) | ||||
|     { | ||||
|         this.className = className; | ||||
|     } | ||||
|  | ||||
|     public String getTplCategory() | ||||
|     { | ||||
|         return tplCategory; | ||||
|     } | ||||
|  | ||||
|     public void setTplCategory(String tplCategory) | ||||
|     { | ||||
|         this.tplCategory = tplCategory; | ||||
|     } | ||||
|  | ||||
|     public String getPackageName() | ||||
|     { | ||||
|         return packageName; | ||||
|     } | ||||
|  | ||||
|     public void setPackageName(String packageName) | ||||
|     { | ||||
|         this.packageName = packageName; | ||||
|     } | ||||
|  | ||||
|     public String getModuleName() | ||||
|     { | ||||
|         return moduleName; | ||||
|     } | ||||
|  | ||||
|     public void setModuleName(String moduleName) | ||||
|     { | ||||
|         this.moduleName = moduleName; | ||||
|     } | ||||
|  | ||||
|     public String getBusinessName() | ||||
|     { | ||||
|         return businessName; | ||||
|     } | ||||
|  | ||||
|     public void setBusinessName(String businessName) | ||||
|     { | ||||
|         this.businessName = businessName; | ||||
|     } | ||||
|  | ||||
|     public String getFunctionName() | ||||
|     { | ||||
|         return functionName; | ||||
|     } | ||||
|  | ||||
|     public void setFunctionName(String functionName) | ||||
|     { | ||||
|         this.functionName = functionName; | ||||
|     } | ||||
|  | ||||
|     public String getFunctionAuthor() | ||||
|     { | ||||
|         return functionAuthor; | ||||
|     } | ||||
|  | ||||
|     public void setFunctionAuthor(String functionAuthor) | ||||
|     { | ||||
|         this.functionAuthor = functionAuthor; | ||||
|     } | ||||
|  | ||||
|     public GenTableColumn getPkColumn() | ||||
|     { | ||||
|         return pkColumn; | ||||
|     } | ||||
|  | ||||
|     public void setPkColumn(GenTableColumn pkColumn) | ||||
|     { | ||||
|         this.pkColumn = pkColumn; | ||||
|     } | ||||
|  | ||||
|     public List<GenTableColumn> getColumns() | ||||
|     { | ||||
|         return columns; | ||||
|     } | ||||
|  | ||||
|     public void setColumns(List<GenTableColumn> columns) | ||||
|     { | ||||
|         this.columns = columns; | ||||
|     } | ||||
|  | ||||
|     public String getOptions() | ||||
|     { | ||||
|         return options; | ||||
|     } | ||||
|  | ||||
|     public void setOptions(String options) | ||||
|     { | ||||
|         this.options = options; | ||||
|     } | ||||
|  | ||||
|     public String getTreeCode() | ||||
|     { | ||||
|         return treeCode; | ||||
|     } | ||||
|  | ||||
|     public void setTreeCode(String treeCode) | ||||
|     { | ||||
|         this.treeCode = treeCode; | ||||
|     } | ||||
|  | ||||
|     public String getTreeParentCode() | ||||
|     { | ||||
|         return treeParentCode; | ||||
|     } | ||||
|  | ||||
|     public void setTreeParentCode(String treeParentCode) | ||||
|     { | ||||
|         this.treeParentCode = treeParentCode; | ||||
|     } | ||||
|  | ||||
|     public String getTreeName() | ||||
|     { | ||||
|         return treeName; | ||||
|     } | ||||
|  | ||||
|     public void setTreeName(String treeName) | ||||
|     { | ||||
|         this.treeName = treeName; | ||||
|     } | ||||
|  | ||||
|     public boolean isTree() | ||||
|     { | ||||
|         return isTree(this.tplCategory); | ||||
|     } | ||||
|  | ||||
|     public static boolean isTree(String tplCategory) | ||||
|     { | ||||
|         return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory); | ||||
|     } | ||||
|  | ||||
|     public boolean isCrud() | ||||
|     { | ||||
|         return isCrud(this.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 static boolean isSuperColumn(String tplCategory, String javaField) | ||||
|     { | ||||
|         if (isTree(tplCategory)) | ||||
|         { | ||||
|             return StringUtils.equalsAnyIgnoreCase(javaField, | ||||
|                     ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY)); | ||||
|         } | ||||
|         return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,368 @@ | ||||
| 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 | ||||
| { | ||||
|     private static final long serialVersionUID = 1L; | ||||
|  | ||||
|     /** 编号 */ | ||||
|     private Long columnId; | ||||
|  | ||||
|     /** 归属表编号 */ | ||||
|     private Long tableId; | ||||
|  | ||||
|     /** 列名称 */ | ||||
|     private String columnName; | ||||
|  | ||||
|     /** 列描述 */ | ||||
|     private String columnComment; | ||||
|  | ||||
|     /** 列类型 */ | ||||
|     private String columnType; | ||||
|  | ||||
|     /** JAVA类型 */ | ||||
|     private String javaType; | ||||
|  | ||||
|     /** JAVA字段名 */ | ||||
|     @NotBlank(message = "Java属性不能为空") | ||||
|     private String javaField; | ||||
|  | ||||
|     /** 是否主键(1是) */ | ||||
|     private String isPk; | ||||
|  | ||||
|     /** 是否自增(1是) */ | ||||
|     private String isIncrement; | ||||
|  | ||||
|     /** 是否必填(1是) */ | ||||
|     private String isRequired; | ||||
|  | ||||
|     /** 是否为插入字段(1是) */ | ||||
|     private String isInsert; | ||||
|  | ||||
|     /** 是否编辑字段(1是) */ | ||||
|     private String isEdit; | ||||
|  | ||||
|     /** 是否列表字段(1是) */ | ||||
|     private String isList; | ||||
|  | ||||
|     /** 是否查询字段(1是) */ | ||||
|     private String isQuery; | ||||
|  | ||||
|     /** 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) */ | ||||
|     private String queryType; | ||||
|  | ||||
|     /** 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件) */ | ||||
|     private String htmlType; | ||||
|  | ||||
|     /** 字典类型 */ | ||||
|     private String dictType; | ||||
|  | ||||
|     /** 排序 */ | ||||
|     private Integer sort; | ||||
|  | ||||
|     public void setColumnId(Long columnId) | ||||
|     { | ||||
|         this.columnId = columnId; | ||||
|     } | ||||
|  | ||||
|     public Long getColumnId() | ||||
|     { | ||||
|         return columnId; | ||||
|     } | ||||
|  | ||||
|     public void setTableId(Long tableId) | ||||
|     { | ||||
|         this.tableId = tableId; | ||||
|     } | ||||
|  | ||||
|     public Long getTableId() | ||||
|     { | ||||
|         return tableId; | ||||
|     } | ||||
|  | ||||
|     public void setColumnName(String columnName) | ||||
|     { | ||||
|         this.columnName = columnName; | ||||
|     } | ||||
|  | ||||
|     public String getColumnName() | ||||
|     { | ||||
|         return columnName; | ||||
|     } | ||||
|  | ||||
|     public void setColumnComment(String columnComment) | ||||
|     { | ||||
|         this.columnComment = columnComment; | ||||
|     } | ||||
|  | ||||
|     public String getColumnComment() | ||||
|     { | ||||
|         return columnComment; | ||||
|     } | ||||
|  | ||||
|     public void setColumnType(String columnType) | ||||
|     { | ||||
|         this.columnType = columnType; | ||||
|     } | ||||
|  | ||||
|     public String getColumnType() | ||||
|     { | ||||
|         return columnType; | ||||
|     } | ||||
|  | ||||
|     public void setJavaType(String javaType) | ||||
|     { | ||||
|         this.javaType = javaType; | ||||
|     } | ||||
|  | ||||
|     public String getJavaType() | ||||
|     { | ||||
|         return javaType; | ||||
|     } | ||||
|  | ||||
|     public void setJavaField(String javaField) | ||||
|     { | ||||
|         this.javaField = javaField; | ||||
|     } | ||||
|  | ||||
|     public String getJavaField() | ||||
|     { | ||||
|         return javaField; | ||||
|     } | ||||
|  | ||||
|     public void setIsPk(String isPk) | ||||
|     { | ||||
|         this.isPk = isPk; | ||||
|     } | ||||
|  | ||||
|     public String getIsPk() | ||||
|     { | ||||
|         return isPk; | ||||
|     } | ||||
|  | ||||
|     public boolean isPk() | ||||
|     { | ||||
|         return isPk(this.isPk); | ||||
|     } | ||||
|  | ||||
|     public boolean isPk(String isPk) | ||||
|     { | ||||
|         return isPk != null && StringUtils.equals("1", isPk); | ||||
|     } | ||||
|  | ||||
|     public String getIsIncrement() | ||||
|     { | ||||
|         return isIncrement; | ||||
|     } | ||||
|  | ||||
|     public void setIsIncrement(String isIncrement) | ||||
|     { | ||||
|         this.isIncrement = isIncrement; | ||||
|     } | ||||
|  | ||||
|     public boolean isIncrement() | ||||
|     { | ||||
|         return isIncrement(this.isIncrement); | ||||
|     } | ||||
|  | ||||
|     public boolean isIncrement(String isIncrement) | ||||
|     { | ||||
|         return isIncrement != null && StringUtils.equals("1", isIncrement); | ||||
|     } | ||||
|  | ||||
|     public void setIsRequired(String isRequired) | ||||
|     { | ||||
|         this.isRequired = isRequired; | ||||
|     } | ||||
|  | ||||
|     public String getIsRequired() | ||||
|     { | ||||
|         return isRequired; | ||||
|     } | ||||
|  | ||||
|     public boolean isRequired() | ||||
|     { | ||||
|         return isRequired(this.isRequired); | ||||
|     } | ||||
|  | ||||
|     public boolean isRequired(String isRequired) | ||||
|     { | ||||
|         return isRequired != null && StringUtils.equals("1", isRequired); | ||||
|     } | ||||
|  | ||||
|     public void setIsInsert(String isInsert) | ||||
|     { | ||||
|         this.isInsert = isInsert; | ||||
|     } | ||||
|  | ||||
|     public String getIsInsert() | ||||
|     { | ||||
|         return isInsert; | ||||
|     } | ||||
|  | ||||
|     public boolean isInsert() | ||||
|     { | ||||
|         return isInsert(this.isInsert); | ||||
|     } | ||||
|  | ||||
|     public boolean isInsert(String isInsert) | ||||
|     { | ||||
|         return isInsert != null && StringUtils.equals("1", isInsert); | ||||
|     } | ||||
|  | ||||
|     public void setIsEdit(String isEdit) | ||||
|     { | ||||
|         this.isEdit = isEdit; | ||||
|     } | ||||
|  | ||||
|     public String getIsEdit() | ||||
|     { | ||||
|         return isEdit; | ||||
|     } | ||||
|  | ||||
|     public boolean isEdit() | ||||
|     { | ||||
|         return isInsert(this.isEdit); | ||||
|     } | ||||
|  | ||||
|     public boolean isEdit(String isEdit) | ||||
|     { | ||||
|         return isEdit != null && StringUtils.equals("1", isEdit); | ||||
|     } | ||||
|  | ||||
|     public void setIsList(String isList) | ||||
|     { | ||||
|         this.isList = isList; | ||||
|     } | ||||
|  | ||||
|     public String getIsList() | ||||
|     { | ||||
|         return isList; | ||||
|     } | ||||
|  | ||||
|     public boolean isList() | ||||
|     { | ||||
|         return isList(this.isList); | ||||
|     } | ||||
|  | ||||
|     public boolean isList(String isList) | ||||
|     { | ||||
|         return isList != null && StringUtils.equals("1", isList); | ||||
|     } | ||||
|  | ||||
|     public void setIsQuery(String isQuery) | ||||
|     { | ||||
|         this.isQuery = isQuery; | ||||
|     } | ||||
|  | ||||
|     public String getIsQuery() | ||||
|     { | ||||
|         return isQuery; | ||||
|     } | ||||
|  | ||||
|     public boolean isQuery() | ||||
|     { | ||||
|         return isQuery(this.isQuery); | ||||
|     } | ||||
|  | ||||
|     public boolean isQuery(String isQuery) | ||||
|     { | ||||
|         return isQuery != null && StringUtils.equals("1", isQuery); | ||||
|     } | ||||
|  | ||||
|     public void setQueryType(String queryType) | ||||
|     { | ||||
|         this.queryType = queryType; | ||||
|     } | ||||
|  | ||||
|     public String getQueryType() | ||||
|     { | ||||
|         return queryType; | ||||
|     } | ||||
|  | ||||
|     public String getHtmlType() | ||||
|     { | ||||
|         return htmlType; | ||||
|     } | ||||
|  | ||||
|     public void setHtmlType(String htmlType) | ||||
|     { | ||||
|         this.htmlType = htmlType; | ||||
|     } | ||||
|  | ||||
|     public void setDictType(String dictType) | ||||
|     { | ||||
|         this.dictType = dictType; | ||||
|     } | ||||
|  | ||||
|     public String getDictType() | ||||
|     { | ||||
|         return dictType; | ||||
|     } | ||||
|  | ||||
|     public void setSort(Integer sort) | ||||
|     { | ||||
|         this.sort = sort; | ||||
|     } | ||||
|  | ||||
|     public Integer getSort() | ||||
|     { | ||||
|         return sort; | ||||
|     } | ||||
|  | ||||
|     public boolean isSuperColumn() | ||||
|     { | ||||
|         return isSuperColumn(this.javaField); | ||||
|     } | ||||
|  | ||||
|     public static boolean isSuperColumn(String javaField) | ||||
|     { | ||||
|         return StringUtils.equalsAnyIgnoreCase(javaField, | ||||
|                 // BaseEntity | ||||
|                 "createBy", "createTime", "updateBy", "updateTime", "remark", | ||||
|                 // TreeEntity | ||||
|                 "parentName", "parentId", "orderNum", "ancestors"); | ||||
|     } | ||||
|  | ||||
|     public boolean isUsableColumn() | ||||
|     { | ||||
|         return isUsableColumn(javaField); | ||||
|     } | ||||
|  | ||||
|     public static boolean isUsableColumn(String javaField) | ||||
|     { | ||||
|         // isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单 | ||||
|         return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum"); | ||||
|     } | ||||
|  | ||||
|     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)) | ||||
|                 { | ||||
|                     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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,52 @@ | ||||
| package com.ruoyi.generator.mapper; | ||||
|  | ||||
| import java.util.List; | ||||
| import com.ruoyi.generator.domain.GenTableColumn; | ||||
|  | ||||
| /** | ||||
|  * 业务字段 数据层 | ||||
|  *  | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| public interface GenTableColumnMapper | ||||
| { | ||||
|     /** | ||||
|      * 根据表名称查询列信息 | ||||
|      *  | ||||
|      * @param tableName 表名称 | ||||
|      * @return 列信息 | ||||
|      */ | ||||
|     public List<GenTableColumn> selectDbTableColumnsByName(String tableName); | ||||
|      | ||||
|     /** | ||||
|      * 查询业务字段列表 | ||||
|      *  | ||||
|      * @param tableId 业务字段编号 | ||||
|      * @return 业务字段集合 | ||||
|      */ | ||||
|     public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId); | ||||
|  | ||||
|     /** | ||||
|      * 新增业务字段 | ||||
|      *  | ||||
|      * @param genTableColumn 业务字段信息 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int insertGenTableColumn(GenTableColumn genTableColumn); | ||||
|  | ||||
|     /** | ||||
|      * 修改业务字段 | ||||
|      *  | ||||
|      * @param genTableColumn 业务字段信息 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int updateGenTableColumn(GenTableColumn genTableColumn); | ||||
|  | ||||
|     /** | ||||
|      * 批量删除业务字段 | ||||
|      *  | ||||
|      * @param ids 需要删除的数据ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteGenTableColumnByIds(Long[] ids); | ||||
| } | ||||
| @@ -0,0 +1,76 @@ | ||||
| package com.ruoyi.generator.mapper; | ||||
|  | ||||
| import java.util.List; | ||||
| import com.ruoyi.generator.domain.GenTable; | ||||
|  | ||||
| /** | ||||
|  * 业务 数据层 | ||||
|  *  | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| public interface GenTableMapper | ||||
| { | ||||
|     /** | ||||
|      * 查询业务列表 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      * @return 业务集合 | ||||
|      */ | ||||
|     public List<GenTable> selectGenTableList(GenTable genTable); | ||||
|  | ||||
|     /** | ||||
|      * 查询据库列表 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      * @return 数据库表集合 | ||||
|      */ | ||||
|     public List<GenTable> selectDbTableList(GenTable genTable); | ||||
|  | ||||
|     /** | ||||
|      * 查询据库列表 | ||||
|      *  | ||||
|      * @param tableNames 表名称组 | ||||
|      * @return 数据库表集合 | ||||
|      */ | ||||
|     public List<GenTable> selectDbTableListByNames(String[] tableNames); | ||||
|  | ||||
|     /** | ||||
|      * 查询表ID业务信息 | ||||
|      *  | ||||
|      * @param id 业务ID | ||||
|      * @return 业务信息 | ||||
|      */ | ||||
|     public GenTable selectGenTableById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询表名称业务信息 | ||||
|      *  | ||||
|      * @param tableName 表名称 | ||||
|      * @return 业务信息 | ||||
|      */ | ||||
|     public GenTable selectGenTableByName(String tableName); | ||||
|  | ||||
|     /** | ||||
|      * 新增业务 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int insertGenTable(GenTable genTable); | ||||
|  | ||||
|     /** | ||||
|      * 修改业务 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int updateGenTable(GenTable genTable); | ||||
|  | ||||
|     /** | ||||
|      * 批量删除业务 | ||||
|      *  | ||||
|      * @param ids 需要删除的数据ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteGenTableByIds(Long[] ids); | ||||
| } | ||||
| @@ -0,0 +1,68 @@ | ||||
| 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; | ||||
| import com.ruoyi.generator.domain.GenTableColumn; | ||||
| import com.ruoyi.generator.mapper.GenTableColumnMapper; | ||||
|  | ||||
| /** | ||||
|  * 业务字段 服务层实现 | ||||
|  *  | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| @Service | ||||
| public class GenTableColumnServiceImpl implements IGenTableColumnService  | ||||
| { | ||||
| 	@Autowired | ||||
| 	private GenTableColumnMapper genTableColumnMapper; | ||||
|  | ||||
| 	/** | ||||
|      * 查询业务字段列表 | ||||
|      *  | ||||
|      * @param tableId 业务字段编号 | ||||
|      * @return 业务字段集合 | ||||
|      */ | ||||
| 	@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); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
|      * 删除业务字段对象 | ||||
|      *  | ||||
|      * @param ids 需要删除的数据ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
| 	@Override | ||||
| 	public int deleteGenTableColumnByIds(String ids) | ||||
| 	{ | ||||
| 		return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,345 @@ | ||||
| package com.ruoyi.generator.service; | ||||
|  | ||||
| import java.io.ByteArrayOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.StringWriter; | ||||
| import java.util.LinkedHashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 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.constant.Constants; | ||||
| import com.ruoyi.common.constant.GenConstants; | ||||
| import com.ruoyi.common.exception.CustomException; | ||||
| import com.ruoyi.common.utils.SecurityUtils; | ||||
| import com.ruoyi.common.utils.StringUtils; | ||||
| import com.ruoyi.generator.domain.GenTable; | ||||
| import com.ruoyi.generator.domain.GenTableColumn; | ||||
| import com.ruoyi.generator.mapper.GenTableColumnMapper; | ||||
| import com.ruoyi.generator.mapper.GenTableMapper; | ||||
| import com.ruoyi.generator.util.GenUtils; | ||||
| import com.ruoyi.generator.util.VelocityInitializer; | ||||
| import com.ruoyi.generator.util.VelocityUtils; | ||||
|  | ||||
| /** | ||||
|  * 业务 服务层实现 | ||||
|  *  | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| @Service | ||||
| public class GenTableServiceImpl implements IGenTableService | ||||
| { | ||||
|     private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); | ||||
|  | ||||
|     @Autowired | ||||
|     private GenTableMapper genTableMapper; | ||||
|  | ||||
|     @Autowired | ||||
|     private GenTableColumnMapper genTableColumnMapper; | ||||
|  | ||||
|     /** | ||||
|      * 查询业务信息 | ||||
|      *  | ||||
|      * @param id 业务ID | ||||
|      * @return 业务信息 | ||||
|      */ | ||||
|     @Override | ||||
|     public GenTable selectGenTableById(Long id) | ||||
|     { | ||||
|         GenTable genTable = genTableMapper.selectGenTableById(id); | ||||
|         setTableFromOptions(genTable); | ||||
|         return genTable; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询业务列表 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      * @return 业务集合 | ||||
|      */ | ||||
|     @Override | ||||
|     public List<GenTable> selectGenTableList(GenTable genTable) | ||||
|     { | ||||
|         return genTableMapper.selectGenTableList(genTable); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询据库列表 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      * @return 数据库表集合 | ||||
|      */ | ||||
|     @Override | ||||
|     public List<GenTable> selectDbTableList(GenTable genTable) | ||||
|     { | ||||
|         return genTableMapper.selectDbTableList(genTable); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询据库列表 | ||||
|      *  | ||||
|      * @param tableNames 表名称组 | ||||
|      * @return 数据库表集合 | ||||
|      */ | ||||
|     @Override | ||||
|     public List<GenTable> selectDbTableListByNames(String[] tableNames) | ||||
|     { | ||||
|         return genTableMapper.selectDbTableListByNames(tableNames); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改业务 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     @Transactional | ||||
|     public void updateGenTable(GenTable genTable) | ||||
|     { | ||||
|         String options = JSON.toJSONString(genTable.getParams()); | ||||
|         genTable.setOptions(options); | ||||
|         int row = genTableMapper.updateGenTable(genTable); | ||||
|         if (row > 0) | ||||
|         { | ||||
|             for (GenTableColumn cenTableColumn : genTable.getColumns()) | ||||
|             { | ||||
|                 genTableColumnMapper.updateGenTableColumn(cenTableColumn); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除业务对象 | ||||
|      *  | ||||
|      * @param tableIds 需要删除的数据ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     @Override | ||||
|     @Transactional | ||||
|     public void deleteGenTableByIds(Long[] tableIds) | ||||
|     { | ||||
|         genTableMapper.deleteGenTableByIds(tableIds); | ||||
|         genTableColumnMapper.deleteGenTableColumnByIds(tableIds); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 导入表结构 | ||||
|      *  | ||||
|      * @param tableList 导入表列表 | ||||
|      */ | ||||
|     @Override | ||||
|     @Transactional | ||||
|     public void importGenTable(List<GenTable> tableList) | ||||
|     { | ||||
|         String operName = SecurityUtils.getUsername(); | ||||
|         try | ||||
|         { | ||||
|             for (GenTable table : tableList) | ||||
|             { | ||||
|                 String tableName = table.getTableName(); | ||||
|                 GenUtils.initTable(table, operName); | ||||
|                 int row = genTableMapper.insertGenTable(table); | ||||
|                 if (row > 0) | ||||
|                 { | ||||
|                     // 保存列信息 | ||||
|                     List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); | ||||
|                     for (GenTableColumn column : genTableColumns) | ||||
|                     { | ||||
|                         GenUtils.initColumnField(column, table); | ||||
|                         genTableColumnMapper.insertGenTableColumn(column); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             throw new CustomException("导入失败:" + e.getMessage()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 预览代码 | ||||
|      *  | ||||
|      * @param tableId 表编号 | ||||
|      * @return 预览数据列表 | ||||
|      */ | ||||
|     @Override | ||||
|     public Map<String, String> previewCode(Long tableId) | ||||
|     { | ||||
|         Map<String, String> dataMap = new LinkedHashMap<>(); | ||||
|         // 查询表信息 | ||||
|         GenTable table = genTableMapper.selectGenTableById(tableId); | ||||
|         // 查询列信息 | ||||
|         List<GenTableColumn> columns = table.getColumns(); | ||||
|         setPkColumn(table, columns); | ||||
|         VelocityInitializer.initVelocity(); | ||||
|  | ||||
|         VelocityContext context = VelocityUtils.prepareContext(table); | ||||
|  | ||||
|         // 获取模板列表 | ||||
|         List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); | ||||
|         for (String template : templates) | ||||
|         { | ||||
|             // 渲染模板 | ||||
|             StringWriter sw = new StringWriter(); | ||||
|             Template tpl = Velocity.getTemplate(template, Constants.UTF8); | ||||
|             tpl.merge(context, sw); | ||||
|             dataMap.put(template, sw.toString()); | ||||
|         } | ||||
|         return dataMap; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 生成代码 | ||||
|      *  | ||||
|      * @param tableName 表名称 | ||||
|      * @return 数据 | ||||
|      */ | ||||
|     @Override | ||||
|     public byte[] generatorCode(String tableName) | ||||
|     { | ||||
|         ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||||
|         ZipOutputStream zip = new ZipOutputStream(outputStream); | ||||
|         generatorCode(tableName, zip); | ||||
|         IOUtils.closeQuietly(zip); | ||||
|         return outputStream.toByteArray(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 批量生成代码 | ||||
|      *  | ||||
|      * @param tableNames 表数组 | ||||
|      * @return 数据 | ||||
|      */ | ||||
|     @Override | ||||
|     public byte[] generatorCode(String[] tableNames) | ||||
|     { | ||||
|         ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||||
|         ZipOutputStream zip = new ZipOutputStream(outputStream); | ||||
|         for (String tableName : tableNames) | ||||
|         { | ||||
|             generatorCode(tableName, zip); | ||||
|         } | ||||
|         IOUtils.closeQuietly(zip); | ||||
|         return outputStream.toByteArray(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询表信息并生成代码 | ||||
|      */ | ||||
|     private void generatorCode(String tableName, ZipOutputStream zip) | ||||
|     { | ||||
|         // 查询表信息 | ||||
|         GenTable table = genTableMapper.selectGenTableByName(tableName); | ||||
|         // 查询列信息 | ||||
|         List<GenTableColumn> columns = table.getColumns(); | ||||
|         setPkColumn(table, columns); | ||||
|  | ||||
|         VelocityInitializer.initVelocity(); | ||||
|  | ||||
|         VelocityContext context = VelocityUtils.prepareContext(table); | ||||
|  | ||||
|         // 获取模板列表 | ||||
|         List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); | ||||
|         for (String template : templates) | ||||
|         { | ||||
|             // 渲染模板 | ||||
|             StringWriter sw = new StringWriter(); | ||||
|             Template tpl = Velocity.getTemplate(template, Constants.UTF8); | ||||
|             tpl.merge(context, sw); | ||||
|             try | ||||
|             { | ||||
|                 // 添加到zip | ||||
|                 zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); | ||||
|                 IOUtils.write(sw.toString(), zip, Constants.UTF8); | ||||
|                 IOUtils.closeQuietly(sw); | ||||
| 				zip.flush(); | ||||
|                 zip.closeEntry(); | ||||
|             } | ||||
|             catch (IOException e) | ||||
|             { | ||||
|                 log.error("渲染模板失败,表名:" + table.getTableName(), e); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改保存参数校验 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      */ | ||||
|     @Override | ||||
|     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))) | ||||
|             { | ||||
|                 throw new CustomException("树编码字段不能为空"); | ||||
|             } | ||||
|             else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) | ||||
|             { | ||||
|                 throw new CustomException("树父编码字段不能为空"); | ||||
|             } | ||||
|             else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) | ||||
|             { | ||||
|                 throw new CustomException("树名称字段不能为空"); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 设置主键列信息 | ||||
|      *  | ||||
|      * @param table 业务表信息 | ||||
|      * @param columns 业务字段列表 | ||||
|      */ | ||||
|     public void setPkColumn(GenTable table, List<GenTableColumn> columns) | ||||
|     { | ||||
|         for (GenTableColumn column : columns) | ||||
|         { | ||||
|             if (column.isPk()) | ||||
|             { | ||||
|                 table.setPkColumn(column); | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|         if (StringUtils.isNull(table.getPkColumn())) | ||||
|         { | ||||
|             table.setPkColumn(columns.get(0)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 设置代码生成其他选项值 | ||||
|      *  | ||||
|      * @param genTable 设置后的生成对象 | ||||
|      */ | ||||
|     public void setTableFromOptions(GenTable genTable) | ||||
|     { | ||||
|         JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions()); | ||||
|         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); | ||||
|             genTable.setTreeCode(treeCode); | ||||
|             genTable.setTreeParentCode(treeParentCode); | ||||
|             genTable.setTreeName(treeName); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,44 @@ | ||||
| package com.ruoyi.generator.service; | ||||
|  | ||||
| import java.util.List; | ||||
| import com.ruoyi.generator.domain.GenTableColumn; | ||||
|  | ||||
| /** | ||||
|  * 业务字段 服务层 | ||||
|  *  | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| public interface IGenTableColumnService | ||||
| { | ||||
|     /** | ||||
|      * 查询业务字段列表 | ||||
|      *  | ||||
|      * @param tableId 业务字段编号 | ||||
|      * @return 业务字段集合 | ||||
|      */ | ||||
|     public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId); | ||||
|  | ||||
|     /** | ||||
|      * 新增业务字段 | ||||
|      *  | ||||
|      * @param genTableColumn 业务字段信息 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int insertGenTableColumn(GenTableColumn genTableColumn); | ||||
|  | ||||
|     /** | ||||
|      * 修改业务字段 | ||||
|      *  | ||||
|      * @param genTableColumn 业务字段信息 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int updateGenTableColumn(GenTableColumn genTableColumn); | ||||
|  | ||||
|     /** | ||||
|      * 删除业务字段信息 | ||||
|      *  | ||||
|      * @param ids 需要删除的数据ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public int deleteGenTableColumnByIds(String ids); | ||||
| } | ||||
| @@ -0,0 +1,99 @@ | ||||
| package com.ruoyi.generator.service; | ||||
|  | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import com.ruoyi.generator.domain.GenTable; | ||||
|  | ||||
| /** | ||||
|  * 业务 服务层 | ||||
|  *  | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| public interface IGenTableService | ||||
| { | ||||
|     /** | ||||
|      * 查询业务列表 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      * @return 业务集合 | ||||
|      */ | ||||
|     public List<GenTable> selectGenTableList(GenTable genTable); | ||||
|  | ||||
|     /** | ||||
|      * 查询据库列表 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      * @return 数据库表集合 | ||||
|      */ | ||||
|     public List<GenTable> selectDbTableList(GenTable genTable); | ||||
|  | ||||
|     /** | ||||
|      * 查询据库列表 | ||||
|      *  | ||||
|      * @param tableNames 表名称组 | ||||
|      * @return 数据库表集合 | ||||
|      */ | ||||
|     public List<GenTable> selectDbTableListByNames(String[] tableNames); | ||||
|  | ||||
|     /** | ||||
|      * 查询业务信息 | ||||
|      *  | ||||
|      * @param id 业务ID | ||||
|      * @return 业务信息 | ||||
|      */ | ||||
|     public GenTable selectGenTableById(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 修改业务 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public void updateGenTable(GenTable genTable); | ||||
|  | ||||
|     /** | ||||
|      * 删除业务信息 | ||||
|      *  | ||||
|      * @param tableIds 需要删除的表数据ID | ||||
|      * @return 结果 | ||||
|      */ | ||||
|     public void deleteGenTableByIds(Long[] tableIds); | ||||
|  | ||||
|     /** | ||||
|      * 导入表结构 | ||||
|      *  | ||||
|      * @param tableList 导入表列表 | ||||
|      */ | ||||
|     public void importGenTable(List<GenTable> tableList); | ||||
|  | ||||
|     /** | ||||
|      * 预览代码 | ||||
|      *  | ||||
|      * @param tableId 表编号 | ||||
|      * @return 预览数据列表 | ||||
|      */ | ||||
|     public Map<String, String> previewCode(Long tableId); | ||||
|  | ||||
|     /** | ||||
|      * 生成代码 | ||||
|      *  | ||||
|      * @param tableName 表名称 | ||||
|      * @return 数据 | ||||
|      */ | ||||
|     public byte[] generatorCode(String tableName); | ||||
|  | ||||
|     /** | ||||
|      * 批量生成代码 | ||||
|      *  | ||||
|      * @param tableNames 表数组 | ||||
|      * @return 数据 | ||||
|      */ | ||||
|     public byte[] generatorCode(String[] tableNames); | ||||
|  | ||||
|     /** | ||||
|      * 修改保存参数校验 | ||||
|      *  | ||||
|      * @param genTable 业务信息 | ||||
|      */ | ||||
|     public void validateEdit(GenTable genTable); | ||||
| } | ||||
| @@ -0,0 +1,242 @@ | ||||
| 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; | ||||
| import com.ruoyi.generator.config.GenConfig; | ||||
| import com.ruoyi.generator.domain.GenTable; | ||||
| import com.ruoyi.generator.domain.GenTableColumn; | ||||
|  | ||||
| /** | ||||
|  * 代码生成器 工具类 | ||||
|  *  | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| public class GenUtils | ||||
| { | ||||
|     /** | ||||
|      * 初始化表信息 | ||||
|      */ | ||||
|     public static void initTable(GenTable genTable, String operName) | ||||
|     { | ||||
|         genTable.setClassName(convertClassName(genTable.getTableName())); | ||||
|         genTable.setPackageName(GenConfig.getPackageName()); | ||||
|         genTable.setModuleName(getModuleName(GenConfig.getPackageName())); | ||||
|         genTable.setBusinessName(getBusinessName(genTable.getTableName())); | ||||
|         genTable.setFunctionName(replaceText(genTable.getTableComment())); | ||||
|         genTable.setFunctionAuthor(GenConfig.getAuthor()); | ||||
|         genTable.setCreateBy(operName); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 初始化列属性字段 | ||||
|      */ | ||||
|     public static void initColumnField(GenTableColumn column, GenTable table) | ||||
|     { | ||||
|         String dataType = getDbType(column.getColumnType()); | ||||
|         String columnName = column.getColumnName(); | ||||
|         column.setTableId(table.getTableId()); | ||||
|         column.setCreateBy(table.getCreateBy()); | ||||
|         // 设置java字段名 | ||||
|         column.setJavaField(StringUtils.toCamelCase(columnName)); | ||||
|  | ||||
|         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)) | ||||
|         { | ||||
|             column.setJavaType(GenConstants.TYPE_DATE); | ||||
|             column.setHtmlType(GenConstants.HTML_DATETIME); | ||||
|         } | ||||
|         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) | ||||
|             { | ||||
|                 column.setJavaType(GenConstants.TYPE_BIGDECIMAL); | ||||
|             } | ||||
|             // 如果是整形 | ||||
|             else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) | ||||
|             { | ||||
|                 column.setJavaType(GenConstants.TYPE_INTEGER); | ||||
|             } | ||||
|             // 长整形 | ||||
|             else | ||||
|             { | ||||
|                 column.setJavaType(GenConstants.TYPE_LONG); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // 插入字段(默认所有字段都需要插入) | ||||
|         column.setIsInsert(GenConstants.REQUIRE); | ||||
|  | ||||
|         // 编辑字段 | ||||
|         if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) | ||||
|         { | ||||
|             column.setIsEdit(GenConstants.REQUIRE); | ||||
|         } | ||||
|         // 列表字段 | ||||
|         if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) | ||||
|         { | ||||
|             column.setIsList(GenConstants.REQUIRE); | ||||
|         } | ||||
|         // 查询字段 | ||||
|         if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) | ||||
|         { | ||||
|             column.setIsQuery(GenConstants.REQUIRE); | ||||
|         } | ||||
|  | ||||
|         // 查询字段类型 | ||||
|         if (StringUtils.endsWithIgnoreCase(columnName, "name")) | ||||
|         { | ||||
|             column.setQueryType(GenConstants.QUERY_LIKE); | ||||
|         } | ||||
|         // 状态字段设置单选框 | ||||
|         if (StringUtils.endsWithIgnoreCase(columnName, "status")) | ||||
|         { | ||||
|             column.setHtmlType(GenConstants.HTML_RADIO); | ||||
|         } | ||||
|         // 类型&性别字段设置下拉框 | ||||
|         else if (StringUtils.endsWithIgnoreCase(columnName, "type") | ||||
|                 || StringUtils.endsWithIgnoreCase(columnName, "sex")) | ||||
|         { | ||||
|             column.setHtmlType(GenConstants.HTML_SELECT); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 校验数组是否包含指定值 | ||||
|      *  | ||||
|      * @param arr 数组 | ||||
|      * @param targetValue 值 | ||||
|      * @return 是否包含 | ||||
|      */ | ||||
|     public static boolean arraysContains(String[] arr, String targetValue) | ||||
|     { | ||||
|         return Arrays.asList(arr).contains(targetValue); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取模块名 | ||||
|      *  | ||||
|      * @param packageName 包名 | ||||
|      * @return 模块名 | ||||
|      */ | ||||
|     public static String getModuleName(String packageName) | ||||
|     { | ||||
|         int lastIndex = packageName.lastIndexOf("."); | ||||
|         int nameLength = packageName.length(); | ||||
|         String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength); | ||||
|         return moduleName; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取业务名 | ||||
|      *  | ||||
|      * @param tableName 表名 | ||||
|      * @return 业务名 | ||||
|      */ | ||||
|     public static String getBusinessName(String tableName) | ||||
|     { | ||||
|         int lastIndex = tableName.lastIndexOf("_"); | ||||
|         int nameLength = tableName.length(); | ||||
|         String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength); | ||||
|         return businessName; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 表名转换成Java类名 | ||||
|      *  | ||||
|      * @param tableName 表名称 | ||||
|      * @return 类名 | ||||
|      */ | ||||
|     public static String convertClassName(String tableName) | ||||
|     { | ||||
|         boolean autoRemovePre = GenConfig.getAutoRemovePre(); | ||||
|         String tablePrefix = GenConfig.getTablePrefix(); | ||||
|         if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) | ||||
|         { | ||||
|             String[] searchList = StringUtils.split(tablePrefix, ","); | ||||
|             tableName = replaceFirst(tableName, searchList); | ||||
|         } | ||||
|         return StringUtils.convertToCamelCase(tableName); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 批量替换前缀 | ||||
|      *  | ||||
|      * @param replacementm 替换值 | ||||
|      * @param searchList 替换列表 | ||||
|      * @return | ||||
|      */ | ||||
|     public static String replaceFirst(String replacementm, String[] searchList) | ||||
|     { | ||||
|         String text = replacementm; | ||||
|         for (String searchString : searchList) | ||||
|         { | ||||
|             if (replacementm.startsWith(searchString)) | ||||
|             { | ||||
|                 text = replacementm.replaceFirst(searchString, ""); | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|         return text; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 关键字替换 | ||||
|      *  | ||||
|      * @param name 需要被替换的名字 | ||||
|      * @return 替换后的名字 | ||||
|      */ | ||||
|     public static String replaceText(String text) | ||||
|     { | ||||
|         return RegExUtils.replaceAll(text, "(?:表|若依)", ""); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取数据库类型字段 | ||||
|      *  | ||||
|      * @param columnType 列类型 | ||||
|      * @return 截取后的列类型 | ||||
|      */ | ||||
|     public static String getDbType(String columnType) | ||||
|     { | ||||
|         if (StringUtils.indexOf(columnType, "(") > 0) | ||||
|         { | ||||
|             return StringUtils.substringBefore(columnType, "("); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return columnType; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取字段长度 | ||||
|      *  | ||||
|      * @param columnType 列类型 | ||||
|      * @return 截取后的列类型 | ||||
|      */ | ||||
|     public static Integer getColumnLength(String columnType) | ||||
|     { | ||||
|         if (StringUtils.indexOf(columnType, "(") > 0) | ||||
|         { | ||||
|             String length = StringUtils.substringBetween(columnType, "(", ")"); | ||||
|             return Integer.valueOf(length); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             return 0; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,35 @@ | ||||
| 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 | ||||
| { | ||||
|     /** | ||||
|      * 初始化vm方法 | ||||
|      */ | ||||
|     public static void initVelocity() | ||||
|     { | ||||
|         Properties p = new Properties(); | ||||
|         try | ||||
|         { | ||||
|             // 加载classpath目录下的vm文件 | ||||
|             p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); | ||||
|             // 定义字符集 | ||||
|             p.setProperty(Velocity.ENCODING_DEFAULT, Constants.UTF8); | ||||
|             p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8); | ||||
|             // 初始化Velocity引擎,指定配置Properties | ||||
|             Velocity.init(p); | ||||
|         } | ||||
|         catch (Exception e) | ||||
|         { | ||||
|             throw new RuntimeException(e); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,298 @@ | ||||
| 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; | ||||
| import com.ruoyi.common.utils.DateUtils; | ||||
| import com.ruoyi.common.utils.StringUtils; | ||||
| import com.ruoyi.generator.domain.GenTable; | ||||
| import com.ruoyi.generator.domain.GenTableColumn; | ||||
|  | ||||
| /** | ||||
|  * 代码生成模板处理 | ||||
|  *  | ||||
|  * @author ruoyi | ||||
|  */ | ||||
| public class VelocityUtils | ||||
| { | ||||
|     /** 项目空间路径 */ | ||||
|     private static final String PROJECT_PATH = "main/java"; | ||||
|  | ||||
|     /** mybatis空间路径 */ | ||||
|     private static final String MYBATIS_PATH = "main/resources/mapper"; | ||||
|  | ||||
|     /** | ||||
|      * 设置模板变量信息 | ||||
|      *  | ||||
|      * @return 模板列表 | ||||
|      */ | ||||
|     public static VelocityContext prepareContext(GenTable genTable) | ||||
|     { | ||||
|         String moduleName = genTable.getModuleName(); | ||||
|         String businessName = genTable.getBusinessName(); | ||||
|         String packageName = genTable.getPackageName(); | ||||
|         String tplCategory = genTable.getTplCategory(); | ||||
|         String functionName = genTable.getFunctionName(); | ||||
|  | ||||
|         VelocityContext velocityContext = new VelocityContext(); | ||||
|         velocityContext.put("tplCategory", genTable.getTplCategory()); | ||||
|         velocityContext.put("tableName", genTable.getTableName()); | ||||
|         velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】"); | ||||
|         velocityContext.put("ClassName", genTable.getClassName()); | ||||
|         velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); | ||||
|         velocityContext.put("moduleName", genTable.getModuleName()); | ||||
|         velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); | ||||
|         velocityContext.put("businessName", genTable.getBusinessName()); | ||||
|         velocityContext.put("basePackage", getPackagePrefix(packageName)); | ||||
|         velocityContext.put("packageName", packageName); | ||||
|         velocityContext.put("author", genTable.getFunctionAuthor()); | ||||
|         velocityContext.put("datetime", DateUtils.getDate()); | ||||
|         velocityContext.put("pkColumn", genTable.getPkColumn()); | ||||
|         velocityContext.put("importList", getImportList(genTable.getColumns())); | ||||
|         velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); | ||||
|         velocityContext.put("columns", genTable.getColumns()); | ||||
|         velocityContext.put("table", genTable); | ||||
|         if (GenConstants.TPL_TREE.equals(tplCategory)) | ||||
|         { | ||||
|             setTreeVelocityContext(velocityContext, genTable); | ||||
|         } | ||||
|         return velocityContext; | ||||
|     } | ||||
|  | ||||
|     public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) | ||||
|     { | ||||
|         String options = genTable.getOptions(); | ||||
|         JSONObject paramsObj = JSONObject.parseObject(options); | ||||
|         String treeCode = getTreecode(paramsObj); | ||||
|         String treeParentCode = getTreeParentCode(paramsObj); | ||||
|         String treeName = getTreeName(paramsObj); | ||||
|  | ||||
|         context.put("treeCode", treeCode); | ||||
|         context.put("treeParentCode", treeParentCode); | ||||
|         context.put("treeName", treeName); | ||||
|         context.put("expandColumn", getExpandColumn(genTable)); | ||||
|         if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) | ||||
|         { | ||||
|             context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE)); | ||||
|         } | ||||
|         if (paramsObj.containsKey(GenConstants.TREE_NAME)) | ||||
|         { | ||||
|             context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取模板信息 | ||||
|      *  | ||||
|      * @return 模板列表 | ||||
|      */ | ||||
|     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"); | ||||
|         templates.add("vm/java/service.java.vm"); | ||||
|         templates.add("vm/java/serviceImpl.java.vm"); | ||||
|         templates.add("vm/java/controller.java.vm"); | ||||
|         templates.add("vm/xml/mapper.xml.vm"); | ||||
|         templates.add("vm/sql/sql.vm"); | ||||
|         templates.add("vm/js/api.js.vm"); | ||||
|         if (GenConstants.TPL_CRUD.equals(tplCategory)) | ||||
|         { | ||||
|             templates.add("vm/vue/index.vue.vm"); | ||||
|         } | ||||
|         else if (GenConstants.TPL_TREE.equals(tplCategory)) | ||||
|         { | ||||
|             templates.add("vm/vue/index-tree.vue.vm"); | ||||
|         } | ||||
|         return templates; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取文件名 | ||||
|      */ | ||||
|     public static String getFileName(String template, GenTable genTable) | ||||
|     { | ||||
|         // 文件名称 | ||||
|         String fileName = ""; | ||||
|         // 包路径 | ||||
|         String packageName = genTable.getPackageName(); | ||||
|         // 模块名 | ||||
|         String moduleName = genTable.getModuleName(); | ||||
|         // 大写类名 | ||||
|         String className = genTable.getClassName(); | ||||
|         // 业务名称 | ||||
|         String businessName = genTable.getBusinessName(); | ||||
|  | ||||
|         String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); | ||||
|         String mybatisPath = MYBATIS_PATH + "/" + moduleName; | ||||
|         String vuePath = "vue"; | ||||
|  | ||||
|         if (template.contains("domain.java.vm")) | ||||
|         { | ||||
|             fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); | ||||
|         } | ||||
|         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")) | ||||
|         { | ||||
|             fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); | ||||
|         } | ||||
|         else if (template.contains("controller.java.vm")) | ||||
|         { | ||||
|             fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); | ||||
|         } | ||||
|         else if (template.contains("mapper.xml.vm")) | ||||
|         { | ||||
|             fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); | ||||
|         } | ||||
|         else if (template.contains("sql.vm")) | ||||
|         { | ||||
|             fileName = businessName + "Menu.sql"; | ||||
|         } | ||||
|         else if (template.contains("api.js.vm")) | ||||
|         { | ||||
|             fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); | ||||
|         } | ||||
|         else if (template.contains("index.vue.vm")) | ||||
|         { | ||||
|             fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); | ||||
|         } | ||||
|         else if (template.contains("index-tree.vue.vm")) | ||||
|         { | ||||
|             fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); | ||||
|         } | ||||
|         return fileName; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取包前缀 | ||||
|      *  | ||||
|      * @param packageName 包名称 | ||||
|      * @return 包前缀名称 | ||||
|      */ | ||||
|     public static String getPackagePrefix(String packageName) | ||||
|     { | ||||
|         int lastIndex = packageName.lastIndexOf("."); | ||||
|         String basePackage = StringUtils.substring(packageName, 0, lastIndex); | ||||
|         return basePackage; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据列类型获取导入包 | ||||
|      *  | ||||
|      * @param column 列集合 | ||||
|      * @return 返回需要导入的包列表 | ||||
|      */ | ||||
|     public static HashSet<String> getImportList(List<GenTableColumn> columns) | ||||
|     { | ||||
|         HashSet<String> importList = new HashSet<String>(); | ||||
|         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())) | ||||
|             { | ||||
|                 importList.add("java.math.BigDecimal"); | ||||
|             } | ||||
|         } | ||||
|         return importList; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取权限前缀 | ||||
|      *  | ||||
|      * @param moduleName 模块名称 | ||||
|      * @param businessName 业务名称 | ||||
|      * @return 返回权限前缀 | ||||
|      */ | ||||
|     public static String getPermissionPrefix(String moduleName, String businessName) | ||||
|     { | ||||
|         return StringUtils.format("{}:{}", moduleName, businessName); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取树编码 | ||||
|      *  | ||||
|      * @param options 生成其他选项 | ||||
|      * @return 树编码 | ||||
|      */ | ||||
|     public static String getTreecode(JSONObject paramsObj) | ||||
|     { | ||||
|         if (paramsObj.containsKey(GenConstants.TREE_CODE)) | ||||
|         { | ||||
|             return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); | ||||
|         } | ||||
|         return ""; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取树父编码 | ||||
|      *  | ||||
|      * @param options 生成其他选项 | ||||
|      * @return 树父编码 | ||||
|      */ | ||||
|     public static String getTreeParentCode(JSONObject paramsObj) | ||||
|     { | ||||
|         if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) | ||||
|         { | ||||
|             return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); | ||||
|         } | ||||
|         return ""; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取树名称 | ||||
|      *  | ||||
|      * @param options 生成其他选项 | ||||
|      * @return 树名称 | ||||
|      */ | ||||
|     public static String getTreeName(JSONObject paramsObj) | ||||
|     { | ||||
|         if (paramsObj.containsKey(GenConstants.TREE_NAME)) | ||||
|         { | ||||
|             return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); | ||||
|         } | ||||
|         return ""; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取需要在哪一列上面显示展开按钮 | ||||
|      *  | ||||
|      * @param genTable 业务表对象 | ||||
|      * @return 展开按钮列序号 | ||||
|      */ | ||||
|     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()) | ||||
|             { | ||||
|                 num++; | ||||
|                 String columnName = column.getColumnName(); | ||||
|                 if (columnName.equals(treeName)) | ||||
|                 { | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         return num; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user