Conflicts:
	pom.xml
	ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java
	ruoyi-admin/src/main/resources/application.yml
	ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
	ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
	ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java
	ruoyi-common/src/main/java/com/ruoyi/common/utils/html/EscapeUtil.java
	ruoyi-common/src/main/java/com/ruoyi/common/utils/sql/SqlUtil.java
	ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
	ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java
	ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java
	ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java
	ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
	ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java
	ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java
	ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml
	ruoyi-generator/src/main/resources/vm/vue/index.vue.vm
	ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java
	ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
	ruoyi-ui/babel.config.js
	ruoyi-ui/package.json
	ruoyi-ui/src/api/tool/gen.js
	ruoyi-ui/src/assets/styles/ruoyi.scss
	ruoyi-ui/src/components/HeaderSearch/index.vue
	ruoyi-ui/src/layout/components/TagsView/ScrollPane.vue
	ruoyi-ui/src/main.js
	ruoyi-ui/src/utils/ruoyi.js
	ruoyi-ui/src/views/login.vue
	ruoyi-ui/src/views/monitor/job/index.vue
	ruoyi-ui/src/views/monitor/logininfor/index.vue
	ruoyi-ui/src/views/monitor/online/index.vue
	ruoyi-ui/src/views/monitor/operlog/index.vue
	ruoyi-ui/src/views/system/config/index.vue
	ruoyi-ui/src/views/system/dept/index.vue
	ruoyi-ui/src/views/system/dict/data.vue
	ruoyi-ui/src/views/system/dict/index.vue
	ruoyi-ui/src/views/system/menu/index.vue
	ruoyi-ui/src/views/system/notice/index.vue
	ruoyi-ui/src/views/system/post/index.vue
	ruoyi-ui/src/views/system/role/index.vue
	ruoyi-ui/src/views/system/user/index.vue
	ruoyi-ui/src/views/tool/gen/genInfoForm.vue
	ruoyi-ui/src/views/tool/gen/index.vue
	ruoyi-ui/vue.config.js
	sql/ry_20200724.sql
This commit is contained in:
疯狂的狮子li
2020-08-02 18:31:47 +08:00
56 changed files with 1058 additions and 311 deletions

View File

@ -148,15 +148,27 @@ public class GenController extends BaseController
}
/**
* 生成代码
* 生成代码(下载方式)
*/
@PreAuthorize("@ss.hasPermi('tool:gen:code')")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/download/{tableName}")
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
{
byte[] data = genTableService.downloadCode(tableName);
genCode(response, data);
}
/**
* 生成代码(自定义路径)
*/
@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
public AjaxResult genCode(HttpServletResponse response, @PathVariable("tableName") String tableName)
{
byte[] data = genTableService.generatorCode(tableName);
genCode(response, data);
genTableService.generatorCode(tableName);
return AjaxResult.success();
}
/**
@ -168,7 +180,7 @@ public class GenController extends BaseController
public void batchGenCode(HttpServletResponse response, String tables) throws IOException
{
String[] tableNames = Convert.toStrArray(tables);
byte[] data = genTableService.generatorCode(tableNames);
byte[] data = genTableService.downloadCode(tableNames);
genCode(response, data);
}
@ -185,4 +197,4 @@ public class GenController extends BaseController
response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream());
}
}
}

View File

@ -55,6 +55,12 @@ public class GenTable extends BaseEntity
@NotBlank(message = "作者不能为空")
private String functionAuthor;
/** 生成代码方式0zip压缩包 1自定义路径 */
private String genType;
/** 生成路径(不填默认项目路径) */
private String genPath;
/** 主键信息 */
private GenTableColumn pkColumn;
@ -180,6 +186,26 @@ public class GenTable extends BaseEntity
this.functionAuthor = functionAuthor;
}
public String getGenType()
{
return genType;
}
public void setGenType(String genType)
{
this.genType = genType;
}
public String getGenPath()
{
return genPath;
}
public void setGenPath(String genPath)
{
this.genPath = genPath;
}
public GenTableColumn getPkColumn()
{
return pkColumn;

View File

@ -1,6 +1,7 @@
package com.ruoyi.generator.service;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.LinkedHashMap;
@ -21,9 +22,11 @@ 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.core.text.CharsetKit;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
import com.ruoyi.generator.mapper.GenTableColumnMapper;
@ -202,13 +205,13 @@ public class GenTableServiceImpl implements IGenTableService
}
/**
* 生成代码
* 生成代码(下载方式)
*
* @param tableName 表名称
* @return 数据
*/
@Override
public byte[] generatorCode(String tableName)
public byte[] downloadCode(String tableName)
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
@ -218,13 +221,55 @@ public class GenTableServiceImpl implements IGenTableService
}
/**
* 批量生成代码
* 生成代码(自定义路径)
*
* @param tableName 表名称
* @return 数据
*/
@Override
public void generatorCode(String tableName)
{
// 查询表信息
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)
{
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
{
String path = getGenPath(table, template);
FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8);
}
catch (IOException e)
{
throw new CustomException("渲染模板失败,表名:" + table.getTableName());
}
}
}
}
/**
* 批量生成代码(下载方式)
*
* @param tableNames 表数组
* @return 数据
*/
@Override
public byte[] generatorCode(String[] tableNames)
public byte[] downloadCode(String[] tableNames)
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
@ -347,4 +392,21 @@ public class GenTableServiceImpl implements IGenTableService
genTable.setParentMenuName(parentMenuName);
}
}
/**
* 获取代码生成地址
*
* @param table 业务表信息
* @param template 模板文件路径
* @return 生成地址
*/
public static String getGenPath(GenTable table, String template)
{
String genPath = table.getGenPath();
if (StringUtils.equals(genPath, "/"))
{
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
}
return genPath + File.separator + VelocityUtils.getFileName(template, table);
}
}

View File

@ -75,20 +75,28 @@ public interface IGenTableService
public Map<String, String> previewCode(Long tableId);
/**
* 生成代码
* 生成代码(下载方式)
*
* @param tableName 表名称
* @return 数据
*/
public byte[] generatorCode(String tableName);
public byte[] downloadCode(String tableName);
/**
* 批量生成代码
* 生成代码(自定义路径)
*
* @param tableName 表名称
* @return 数据
*/
public void generatorCode(String tableName);
/**
* 批量生成代码(下载方式)
*
* @param tableNames 表数组
* @return 数据
*/
public byte[] generatorCode(String[] tableNames);
public byte[] downloadCode(String[] tableNames);
/**
* 修改保存参数校验

View File

@ -11,20 +11,25 @@ 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/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)
@ -93,7 +98,7 @@ public class VelocityUtils
/**
* 获取模板信息
*
*
* @return 模板列表
*/
public static List<String> getTemplateList(String tplCategory)
@ -183,7 +188,7 @@ public class VelocityUtils
/**
* 获取包前缀
*
*
* @param packageName 包名称
* @return 包前缀名称
*/
@ -196,8 +201,8 @@ public class VelocityUtils
/**
* 根据列类型获取导入包
*
* @param column 列集合
*
* @param columns 列集合
* @return 返回需要导入的包列表
*/
public static HashSet<String> getImportList(List<GenTableColumn> columns)
@ -220,7 +225,7 @@ public class VelocityUtils
/**
* 获取权限前缀
*
*
* @param moduleName 模块名称
* @param businessName 业务名称
* @return 返回权限前缀
@ -228,13 +233,12 @@ public class VelocityUtils
public static String getPermissionPrefix(String moduleName, String businessName)
{
return StringUtils.format("{}:{}", moduleName, businessName);
}
/**
* 获取上级菜单ID字段
*
* @param options 生成其他选项
*
* @param paramsObj 生成其他选项
* @return 上级菜单ID字段
*/
public static String getParentMenuId(JSONObject paramsObj)
@ -248,8 +252,8 @@ public class VelocityUtils
/**
* 获取树编码
*
* @param options 生成其他选项
*
* @param paramsObj 生成其他选项
* @return 树编码
*/
public static String getTreecode(JSONObject paramsObj)
@ -263,8 +267,8 @@ public class VelocityUtils
/**
* 获取树父编码
*
* @param options 生成其他选项
*
* @param paramsObj 生成其他选项
* @return 树父编码
*/
public static String getTreeParentCode(JSONObject paramsObj)
@ -278,8 +282,8 @@ public class VelocityUtils
/**
* 获取树名称
*
* @param options 生成其他选项
*
* @param paramsObj 生成其他选项
* @return 树名称
*/
public static String getTreeName(JSONObject paramsObj)
@ -293,7 +297,7 @@ public class VelocityUtils
/**
* 获取需要在哪一列上面显示展开按钮
*
*
* @param genTable 业务表对象
* @return 展开按钮列序号
*/
@ -317,4 +321,4 @@ public class VelocityUtils
}
return num;
}
}
}