From 5967f7f11b34d3956351987558d66067b01df5a6 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 16:48:00 +0800 Subject: [PATCH 001/191] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E9=AB=98?= =?UTF-8?q?=E5=BA=A6=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/views/login.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-ui/src/views/login.vue b/ruoyi-ui/src/views/login.vue index 4f0bf5e6..64ecbc47 100644 --- a/ruoyi-ui/src/views/login.vue +++ b/ruoyi-ui/src/views/login.vue @@ -201,6 +201,6 @@ export default { letter-spacing: 1px; } .login-code-img { - height: 40px; + height: 38px; } From 59b8df2e90945626e0d94ef5326f6d2729635840 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 17:16:05 +0800 Subject: [PATCH 002/191] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1cro?= =?UTF-8?q?n=E8=A1=A8=E8=BE=BE=E5=BC=8F=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/common/log/aspect/LogAspect.java | 10 ++++++++-- .../com/ruoyi/job/controller/SysJobController.java | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java index 17fbe1e6..4fe7580b 100644 --- a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java +++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java @@ -198,8 +198,14 @@ public class LogAspect { if (!isFilterObject(paramsArray[i])) { - Object jsonObj = JSON.toJSON(paramsArray[i]); - params += jsonObj.toString() + " "; + try + { + Object jsonObj = JSON.toJSON(paramsArray[i]); + params += jsonObj.toString() + " "; + } + catch (Exception e) + { + } } } } diff --git a/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/controller/SysJobController.java b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/controller/SysJobController.java index 12876788..feae6662 100644 --- a/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/controller/SysJobController.java +++ b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/controller/SysJobController.java @@ -21,8 +21,10 @@ import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.page.TableDataInfo; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; +import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.job.domain.SysJob; import com.ruoyi.job.service.ISysJobService; +import com.ruoyi.job.util.CronUtils; /** * 调度任务信息操作处理 @@ -79,6 +81,11 @@ public class SysJobController extends BaseController @PostMapping public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException { + if (!CronUtils.isValid(sysJob.getCronExpression())) + { + return AjaxResult.error("cron表达式不正确"); + } + sysJob.setCreateBy(SecurityUtils.getUsername()); return toAjax(jobService.insertJob(sysJob)); } @@ -90,6 +97,11 @@ public class SysJobController extends BaseController @PutMapping public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException { + if (!CronUtils.isValid(sysJob.getCronExpression())) + { + return AjaxResult.error("cron表达式不正确"); + } + sysJob.setUpdateBy(SecurityUtils.getUsername()); return toAjax(jobService.updateJob(sysJob)); } From 76aa1cda49270a3c244ab3cd0a2c53a1fb7e2c18 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 17:24:41 +0800 Subject: [PATCH 003/191] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=BB=E7=B1=BB=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/views/system/menu/index.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ruoyi-ui/src/views/system/menu/index.vue b/ruoyi-ui/src/views/system/menu/index.vue index 1e36780b..2303a52e 100644 --- a/ruoyi-ui/src/views/system/menu/index.vue +++ b/ruoyi-ui/src/views/system/menu/index.vue @@ -314,8 +314,10 @@ export default { handleAdd(row) { this.reset(); this.getTreeselect(); - if (row != null) { + if (row != null && row.menuId) { this.form.parentId = row.menuId; + } else { + this.form.parentId = 0; } this.open = true; this.title = "添加菜单"; From c7908e1b8ee9c1d3b1339acb1e207d0b1525f5b2 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 17:26:47 +0800 Subject: [PATCH 004/191] =?UTF-8?q?=E5=88=A0=E9=99=A4babel=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E7=BC=96=E8=AF=91=E9=80=9F=E5=BA=A6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index b41c859e..dffbfd60 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -1,6 +1,6 @@ { "name": "ruoyi", - "version": "2.3.0", + "version": "2.0.0", "description": "若依管理系统", "author": "若依", "license": "MIT", @@ -65,9 +65,6 @@ "vuex": "3.1.0" }, "devDependencies": { - "@babel/core": "7.0.0", - "@babel/register": "7.0.0", - "@babel/parser": "^7.7.4", "@vue/cli-plugin-babel": "3.5.3", "@vue/cli-plugin-eslint": "^3.9.1", "@vue/cli-plugin-unit-jest": "3.5.3", From bb5b7466db9d94fa5fe24244ff12152deafeb933 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 17:29:17 +0800 Subject: [PATCH 005/191] =?UTF-8?q?=E5=8D=87=E7=BA=A7element-ui=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=88=B02.13.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/package.json | 2 +- ruoyi-ui/src/utils/index.js | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index dffbfd60..10633984 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -44,7 +44,7 @@ "axios": "0.18.1", "clipboard": "2.0.4", "echarts": "4.2.1", - "element-ui": "2.13.0", + "element-ui": "2.13.2", "file-saver": "2.0.1", "js-beautify": "^1.10.2", "fuse.js": "3.4.4", diff --git a/ruoyi-ui/src/utils/index.js b/ruoyi-ui/src/utils/index.js index 6c3017c7..49897c99 100644 --- a/ruoyi-ui/src/utils/index.js +++ b/ruoyi-ui/src/utils/index.js @@ -124,19 +124,21 @@ export function param(json) { * @returns {Object} */ export function param2Obj(url) { - const search = url.split('?')[1] + const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ') if (!search) { return {} } - return JSON.parse( - '{"' + - decodeURIComponent(search) - .replace(/"/g, '\\"') - .replace(/&/g, '","') - .replace(/=/g, '":"') - .replace(/\+/g, ' ') + - '"}' - ) + const obj = {} + const searchArr = search.split('&') + searchArr.forEach(v => { + const index = v.indexOf('=') + if (index !== -1) { + const name = v.substring(0, index) + const val = v.substring(index + 1, v.length) + obj[name] = val + } + }) + return obj } /** From 57200e5f5de8208d8d8857e604f59bde83fd142c Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 17:30:50 +0800 Subject: [PATCH 006/191] =?UTF-8?q?=E7=A6=81=E6=AD=A2=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E5=AF=86=E6=96=87=E8=BF=94=E5=9B=9E=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/system/api/domain/SysUser.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java index e0b84ce1..e73a0e07 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java @@ -7,6 +7,7 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.ruoyi.common.core.annotation.Excel; import com.ruoyi.common.core.annotation.Excel.ColumnType; @@ -197,6 +198,7 @@ public class SysUser extends BaseEntity this.avatar = avatar; } + @JsonIgnore @JsonProperty public String getPassword() { From 7e2b00b98b57d5058bc5a8360991608483b99e93 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 17:33:54 +0800 Subject: [PATCH 007/191] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/mapper/generator/GenTableMapper.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml index abb636e3..8a04ab3f 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml @@ -62,6 +62,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) + + AND date_format(create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') + + + AND date_format(create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') + From 8ae4f5e90b4d982ae43982dd5e9f832a28a9e792 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 18:09:44 +0800 Subject: [PATCH 008/191] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=89=E6=8B=A9=E4=B8=8A=E7=BA=A7=E8=8F=9C?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/system/api/domain/SysUser.java | 2 - .../common/core/constant/GenConstants.java | 6 +++ .../gateway/RuoYiGatewayApplication.java | 2 +- .../java/com/ruoyi/gen/domain/GenTable.java | 28 +++++++++++++- .../gen/service/GenTableServiceImpl.java | 5 +++ .../com/ruoyi/gen/util/VelocityUtils.java | 34 +++++++++++++++-- .../src/main/resources/vm/sql/sql.vm | 2 +- ruoyi-ui/src/views/tool/gen/editTable.vue | 13 ++++++- ruoyi-ui/src/views/tool/gen/genInfoForm.vue | 37 ++++++++++++++++++- ruoyi-ui/src/views/tool/gen/importTable.vue | 4 +- 10 files changed, 118 insertions(+), 15 deletions(-) diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java index e73a0e07..e0b84ce1 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java @@ -7,7 +7,6 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.ruoyi.common.core.annotation.Excel; import com.ruoyi.common.core.annotation.Excel.ColumnType; @@ -198,7 +197,6 @@ public class SysUser extends BaseEntity this.avatar = avatar; } - @JsonIgnore @JsonProperty public String getPassword() { diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java index 5b0a2c9c..a9178752 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java @@ -22,6 +22,12 @@ public class GenConstants /** 树名称字段 */ public static final String TREE_NAME = "treeName"; + /** 上级菜单ID字段 */ + public static final String PARENT_MENU_ID = "parentMenuId"; + + /** 上级菜单名称字段 */ + public static final String PARENT_MENU_NAME = "parentMenuName"; + /** 数据库字符串类型 */ public static final String[] COLUMNTYPE_STR = { "char", "varchar", "narchar", "varchar2", "tinytext", "text", "mediumtext", "longtext" }; diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/RuoYiGatewayApplication.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/RuoYiGatewayApplication.java index d1f6ec14..af0fcc84 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/RuoYiGatewayApplication.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/RuoYiGatewayApplication.java @@ -28,4 +28,4 @@ public class RuoYiGatewayApplication " | | \\ / \\ / \n" + " ''-' `'-' `-..-' "); } -} \ No newline at end of file +} 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 86fc86ad..cba6c5ac 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 @@ -74,6 +74,12 @@ public class GenTable extends BaseEntity /** 树名称字段 */ private String treeName; + /** 上级菜单ID字段 */ + private String parentMenuId; + + /** 上级菜单名称字段 */ + private String parentMenuName; + public Long getTableId() { return tableId; @@ -234,6 +240,26 @@ public class GenTable extends BaseEntity this.treeName = treeName; } + public String getParentMenuId() + { + return parentMenuId; + } + + public void setParentMenuId(String parentMenuId) + { + this.parentMenuId = parentMenuId; + } + + public String getParentMenuName() + { + return parentMenuName; + } + + public void setParentMenuName(String parentMenuName) + { + this.parentMenuName = parentMenuName; + } + public boolean isTree() { return isTree(this.tplCategory); @@ -268,4 +294,4 @@ public class GenTable extends BaseEntity } return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); } -} \ 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 817dd3a7..cb87a6f3 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 @@ -336,9 +336,14 @@ public class GenTableServiceImpl implements IGenTableService 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); + genTable.setParentMenuId(parentMenuId); + genTable.setParentMenuName(parentMenuName); } } } \ No newline at end of file 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 6902e62c..fc78c332 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 @@ -23,6 +23,9 @@ public class VelocityUtils /** mybatis空间路径 */ private static final String MYBATIS_PATH = "main/resources/mapper"; + + /** 默认上级菜单,系统工具 */ + private static final String DEFAULT_PARENT_MENU_ID = "3"; /** * 设置模板变量信息 @@ -55,12 +58,21 @@ public class VelocityUtils velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); velocityContext.put("columns", genTable.getColumns()); velocityContext.put("table", genTable); + setMenuVelocityContext(velocityContext, genTable); if (GenConstants.TPL_TREE.equals(tplCategory)) { setTreeVelocityContext(velocityContext, genTable); } return velocityContext; } + + 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) { @@ -221,7 +233,21 @@ public class VelocityUtils public static String getPermissionPrefix(String moduleName, String businessName) { return StringUtils.format("{}:{}", moduleName, businessName); + } + /** + * 获取上级菜单ID字段 + * + * @param options 生成其他选项 + * @return 上级菜单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; } /** @@ -236,7 +262,7 @@ public class VelocityUtils { return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); } - return ""; + return StringUtils.EMPTY; } /** @@ -251,7 +277,7 @@ public class VelocityUtils { return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); } - return ""; + return StringUtils.EMPTY; } /** @@ -266,7 +292,7 @@ public class VelocityUtils { return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); } - return ""; + return StringUtils.EMPTY; } /** @@ -295,4 +321,4 @@ public class VelocityUtils } return num; } -} \ No newline at end of file +} diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/sql/sql.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/sql/sql.vm index ab17d1be..5e3c6821 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/sql/sql.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/sql/sql.vm @@ -1,6 +1,6 @@ -- 菜单 SQL insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) -values('${functionName}', '3', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '${functionName}菜单'); +values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '${functionName}菜单'); -- 按钮父菜单ID SELECT @parentId := LAST_INSERT_ID(); diff --git a/ruoyi-ui/src/views/tool/gen/editTable.vue b/ruoyi-ui/src/views/tool/gen/editTable.vue index fb1bba1c..38cbd55d 100644 --- a/ruoyi-ui/src/views/tool/gen/editTable.vue +++ b/ruoyi-ui/src/views/tool/gen/editTable.vue @@ -110,7 +110,7 @@ - + @@ -124,9 +124,11 @@ diff --git a/ruoyi-ui/src/views/tool/gen/importTable.vue b/ruoyi-ui/src/views/tool/gen/importTable.vue index 6c56c771..e48a5f35 100644 --- a/ruoyi-ui/src/views/tool/gen/importTable.vue +++ b/ruoyi-ui/src/views/tool/gen/importTable.vue @@ -28,8 +28,8 @@ - - + + From 337f6fd3dbb2f44be6eabe4d65828fce7a81a42e Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 18:12:39 +0800 Subject: [PATCH 009/191] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20utils/index.js=20?= =?UTF-8?q?=E4=B8=AD=E4=B8=8D=E5=8C=85=E5=90=AB=20parseTime=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/utils/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ruoyi-ui/src/utils/index.js b/ruoyi-ui/src/utils/index.js index 49897c99..2893bc83 100644 --- a/ruoyi-ui/src/utils/index.js +++ b/ruoyi-ui/src/utils/index.js @@ -1,3 +1,5 @@ +import { parseTime } from './ruoyi' + /** * 表格时间格式化 */ @@ -385,4 +387,4 @@ export function camelCase(str) { export function isNumberStr(str) { return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str) } - \ No newline at end of file + From 4126f634baf8be303ac4309b072f413b232e3919 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 18:14:51 +0800 Subject: [PATCH 010/191] =?UTF-8?q?=E4=BC=98=E5=8C=96selectDictLabel?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E6=95=B0=E7=BB=84=E8=BF=AD=E4=BB=A3?= =?UTF-8?q?=E5=99=A8=E6=8D=A2=E4=B8=BAsome?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/utils/ruoyi.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js index f834ddab..80119921 100644 --- a/ruoyi-ui/src/utils/ruoyi.js +++ b/ruoyi-ui/src/utils/ruoyi.js @@ -68,10 +68,10 @@ export function addDateRange(params, dateRange) { // 回显数据字典 export function selectDictLabel(datas, value) { var actions = []; - Object.keys(datas).map((key) => { + Object.keys(datas).some((key) => { if (datas[key].dictValue == ('' + value)) { actions.push(datas[key].dictLabel); - return false; + return true; } }) return actions.join(''); @@ -144,4 +144,4 @@ export function tansParams(params) { } }) return result -} \ No newline at end of file +} From 41cf67da6dff20f68fb82988f16341e378f8d593 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 18:26:52 +0800 Subject: [PATCH 011/191] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=94=AF=E6=8C=81=EF=BC=88=E6=95=B0=E7=BB=84=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E3=80=81=E5=AD=97=E7=AC=A6=E9=AA=8C=E8=AF=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/gateway/config/CaptchaConfig.java | 64 +++++++++++++------ .../service/impl/ValidateCodeServiceImpl.java | 35 +++++++--- 2 files changed, 72 insertions(+), 27 deletions(-) diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/CaptchaConfig.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/CaptchaConfig.java index c642ffeb..963425e6 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/CaptchaConfig.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/CaptchaConfig.java @@ -5,6 +5,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import com.google.code.kaptcha.impl.DefaultKaptcha; import com.google.code.kaptcha.util.Config; +import static com.google.code.kaptcha.Constants.*; /** * 验证码配置 @@ -14,42 +15,67 @@ import com.google.code.kaptcha.util.Config; @Configuration public class CaptchaConfig { + @Bean(name = "captchaProducer") + public DefaultKaptcha getKaptchaBean() + { + DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); + Properties properties = new Properties(); + // 是否有边框 默认为true 我们可以自己设置yes,no + properties.setProperty(KAPTCHA_BORDER, "yes"); + // 验证码文本字符颜色 默认为Color.BLACK + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black"); + // 验证码图片宽度 默认为200 + properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); + // 验证码图片高度 默认为50 + properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); + // 验证码文本字符大小 默认为40 + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "38"); + // KAPTCHA_SESSION_KEY + properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCode"); + // 验证码文本字符长度 默认为5 + properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4"); + // 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); + // 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy + properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); + Config config = new Config(properties); + defaultKaptcha.setConfig(config); + return defaultKaptcha; + } + @Bean(name = "captchaProducerMath") public DefaultKaptcha getKaptchaBeanMath() { DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); Properties properties = new Properties(); // 是否有边框 默认为true 我们可以自己设置yes,no - properties.setProperty("kaptcha.border", "yes"); + properties.setProperty(KAPTCHA_BORDER, "yes"); // 边框颜色 默认为Color.BLACK - properties.setProperty("kaptcha.border.color", "105,179,90"); + properties.setProperty(KAPTCHA_BORDER_COLOR, "105,179,90"); // 验证码文本字符颜色 默认为Color.BLACK - properties.setProperty("kaptcha.textproducer.font.color", "blue"); + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "blue"); // 验证码图片宽度 默认为200 - properties.setProperty("kaptcha.image.width", "160"); + properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); // 验证码图片高度 默认为50 - properties.setProperty("kaptcha.image.height", "60"); + properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); // 验证码文本字符大小 默认为40 - properties.setProperty("kaptcha.textproducer.font.size", "35"); + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "35"); // KAPTCHA_SESSION_KEY - properties.setProperty("kaptcha.session.key", "kaptchaCodeMath"); + properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath"); // 验证码文本生成器 - properties.setProperty("kaptcha.textproducer.impl", "com.ruoyi.gateway.config.KaptchaTextCreator"); + properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.ruoyi.gateway.config.KaptchaTextCreator"); // 验证码文本字符间距 默认为2 - properties.setProperty("kaptcha.textproducer.char.space", "3"); + properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3"); // 验证码文本字符长度 默认为5 - properties.setProperty("kaptcha.textproducer.char.length", "6"); - // 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, - // fontSize) - properties.setProperty("kaptcha.textproducer.font.names", "Arial,Courier"); + properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "6"); + // 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) + properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); // 验证码噪点颜色 默认为Color.BLACK - properties.setProperty("kaptcha.noise.color", "white"); + properties.setProperty(KAPTCHA_NOISE_COLOR, "white"); // 干扰实现类 - properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise"); - // 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple - // 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy - // 阴影com.google.code.kaptcha.impl.ShadowGimpy - properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.ShadowGimpy"); + properties.setProperty(KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise"); + // 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy + properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); Config config = new Config(properties); defaultKaptcha.setConfig(config); return defaultKaptcha; diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/service/impl/ValidateCodeServiceImpl.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/service/impl/ValidateCodeServiceImpl.java index 3af3f25d..873ef39b 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/service/impl/ValidateCodeServiceImpl.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/service/impl/ValidateCodeServiceImpl.java @@ -3,6 +3,7 @@ package com.ruoyi.gateway.service.impl; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.concurrent.TimeUnit; +import javax.annotation.Resource; import javax.imageio.ImageIO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -25,28 +26,46 @@ import com.ruoyi.gateway.service.ValidateCodeService; @Service public class ValidateCodeServiceImpl implements ValidateCodeService { - @Autowired - private Producer producer; + @Resource(name = "captchaProducer") + private Producer captchaProducer; + + @Resource(name = "captchaProducerMath") + private Producer captchaProducerMath; @Autowired private RedisService redisService; + // 验证码类型 + private String captchaType = "math"; + /** * 生成验证码 */ @Override public AjaxResult createCapcha() throws IOException, CaptchaException { - // 生成验证码 - String capText = producer.createText(); - String capStr = capText.substring(0, capText.lastIndexOf("@")); - String verifyCode = capText.substring(capText.lastIndexOf("@") + 1); - BufferedImage image = producer.createImage(capStr); // 保存验证码信息 String uuid = IdUtils.simpleUUID(); String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; - redisService.setCacheObject(verifyKey, verifyCode, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); + String capStr = null, code = null; + BufferedImage image = null; + + // 生成验证码 + if ("math".equals(captchaType)) + { + String capText = captchaProducerMath.createText(); + capStr = capText.substring(0, capText.lastIndexOf("@")); + code = capText.substring(capText.lastIndexOf("@") + 1); + image = captchaProducerMath.createImage(capStr); + } + else if ("char".equals(captchaType)) + { + capStr = code = captchaProducer.createText(); + image = captchaProducer.createImage(capStr); + } + + redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); // 转换流信息写出 FastByteArrayOutputStream os = new FastByteArrayOutputStream(); try From 4a48702ccb729bb47de859ddef159c9bc78e2727 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 18:30:30 +0800 Subject: [PATCH 012/191] =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=B0=8F=E6=95=B0=E7=82=B9&=E9=99=8D?= =?UTF-8?q?=E7=BA=A7=E6=94=B9=E6=88=90=E5=BC=82=E5=B8=B8=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ruoyi/common/core/utils/sql/SqlUtil.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/sql/SqlUtil.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/sql/SqlUtil.java index 25f842e9..b84f4e76 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/sql/SqlUtil.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/sql/SqlUtil.java @@ -1,5 +1,6 @@ package com.ruoyi.common.core.utils.sql; +import com.ruoyi.common.core.exception.BaseException; import com.ruoyi.common.core.utils.StringUtils; /** @@ -10,9 +11,9 @@ import com.ruoyi.common.core.utils.StringUtils; public class SqlUtil { /** - * 仅支持字母、数字、下划线、空格、逗号(支持多个字段排序) + * 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序) */ - public static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,]+"; + public static String SQL_PATTERN = "[a-zA-Z0-9_\\ \\,\\.]+"; /** * 检查字符,防止注入绕过 @@ -21,7 +22,7 @@ public class SqlUtil { if (StringUtils.isNotEmpty(value) && !isValidOrderBySql(value)) { - return StringUtils.EMPTY; + throw new BaseException("参数不符合规范,不能进行查询"); } return value; } From 165a957d672dfbcfb1796954340e45cbd8eb59a9 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 21:17:54 +0800 Subject: [PATCH 013/191] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=8D=E9=80=89=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/redis/service/RedisService.java | 2 +- .../com/ruoyi/gen/util/VelocityUtils.java | 2 +- .../main/resources/vm/vue/index-tree.vue.vm | 32 ++++++++++++++- .../src/main/resources/vm/vue/index.vue.vm | 32 ++++++++++++++- ruoyi-ui/src/main.js | 3 +- ruoyi-ui/src/utils/ruoyi.js | 41 +++++++++++++------ 6 files changed, 94 insertions(+), 18 deletions(-) diff --git a/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/service/RedisService.java b/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/service/RedisService.java index 6c702eaa..3029fe87 100644 --- a/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/service/RedisService.java +++ b/ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/service/RedisService.java @@ -109,7 +109,7 @@ public class RedisService * 缓存List数据 * * @param key 缓存的键值 - * @param values 待缓存的List数据 + * @param dataList 待缓存的List数据 * @return 缓存的对象 */ public long setCacheList(final String key, final List dataList) 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 fc78c332..2830c985 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 @@ -238,7 +238,7 @@ public class VelocityUtils /** * 获取上级菜单ID字段 * - * @param options 生成其他选项 + * @param paramsObj 生成其他选项 * @return 上级菜单ID字段 */ public static String getParentMenuId(JSONObject paramsObj) diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm index fb10ed6d..a6625897 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm @@ -151,6 +151,23 @@ > +#elseif($column.htmlType == "checkbox" && "" != $dictType) + + + + {{dict.dictLabel}} + + + +#elseif($column.htmlType == "checkbox" && $dictType) + + + 请选择字典生成 + + #elseif($column.htmlType == "select" && $dictType) @@ -312,7 +329,7 @@ export default { #end // $comment字典翻译 ${column.javaField}Format(row, column) { - return this.selectDictLabel(this.${column.javaField}Options, row.${column.javaField}); + return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField}); }, #end #end @@ -328,6 +345,9 @@ export default { #if($column.htmlType == "radio") $column.javaField: "0"#if($velocityCount != $columns.size()),#end +#elseif($column.htmlType == "checkbox") + $column.javaField: []#if($velocityCount != $columns.size()),#end + #else $column.javaField: undefined#if($velocityCount != $columns.size()),#end @@ -361,6 +381,11 @@ export default { } get${BusinessName}(row.${pkColumn.javaField}).then(response => { this.form = response.data; +#foreach ($column in $columns) +#if($column.htmlType == "checkbox") + this.form.$column.javaField = this.form.${column.javaField}.split(","); +#end +#end this.open = true; this.title = "修改${functionName}"; }); @@ -369,6 +394,11 @@ export default { submitForm: function() { this.#[[$]]#refs["form"].validate(valid => { if (valid) { +#foreach ($column in $columns) +#if($column.htmlType == "checkbox") + this.form.$column.javaField = this.form.${column.javaField}.join(","); +#end +#end if (this.form.${pkColumn.javaField} != undefined) { update${BusinessName}(this.form).then(response => { if (response.code === 200) { diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm index d8ecac1a..8c61a5d1 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm @@ -185,6 +185,23 @@ +#elseif($column.htmlType == "checkbox" && "" != $dictType) + + + + {{dict.dictLabel}} + + + +#elseif($column.htmlType == "checkbox" && $dictType) + + + 请选择字典生成 + + #elseif($column.htmlType == "radio" && "" != $dictType) @@ -326,7 +343,7 @@ export default { #end // $comment字典翻译 ${column.javaField}Format(row, column) { - return this.selectDictLabel(this.${column.javaField}Options, row.${column.javaField}); + return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField}); }, #end #end @@ -342,6 +359,9 @@ export default { #if($column.htmlType == "radio") $column.javaField: "0"#if($velocityCount != $columns.size()),#end +#elseif($column.htmlType == "checkbox") + $column.javaField: []#if($velocityCount != $columns.size()),#end + #else $column.javaField: undefined#if($velocityCount != $columns.size()),#end @@ -378,6 +398,11 @@ export default { const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids get${BusinessName}(${pkColumn.javaField}).then(response => { this.form = response.data; +#foreach ($column in $columns) +#if($column.htmlType == "checkbox") + this.form.$column.javaField = this.form.${column.javaField}.split(","); +#end +#end this.open = true; this.title = "修改${functionName}"; }); @@ -386,6 +411,11 @@ export default { submitForm: function() { this.#[[$]]#refs["form"].validate(valid => { if (valid) { +#foreach ($column in $columns) +#if($column.htmlType == "checkbox") + this.form.$column.javaField = this.form.${column.javaField}.join(","); +#end +#end if (this.form.${pkColumn.javaField} != undefined) { update${BusinessName}(this.form).then(response => { if (response.code === 200) { diff --git a/ruoyi-ui/src/main.js b/ruoyi-ui/src/main.js index 661ed59d..134d8c7c 100644 --- a/ruoyi-ui/src/main.js +++ b/ruoyi-ui/src/main.js @@ -19,7 +19,7 @@ import './assets/icons' // icon import './permission' // permission control import { getDicts } from "@/api/system/dict/data"; import { getConfigKey } from "@/api/system/config"; -import { parseTime, resetForm, addDateRange, selectDictLabel, handleTree } from "@/utils/ruoyi"; +import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi"; import Pagination from "@/components/Pagination"; // 全局方法挂载 @@ -29,6 +29,7 @@ Vue.prototype.parseTime = parseTime Vue.prototype.resetForm = resetForm Vue.prototype.addDateRange = addDateRange Vue.prototype.selectDictLabel = selectDictLabel +Vue.prototype.selectDictLabels = selectDictLabels Vue.prototype.download = download Vue.prototype.handleTree = handleTree diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js index 80119921..4fe1b1e7 100644 --- a/ruoyi-ui/src/utils/ruoyi.js +++ b/ruoyi-ui/src/utils/ruoyi.js @@ -77,6 +77,21 @@ export function selectDictLabel(datas, value) { return actions.join(''); } +// 回显数据字典(字符串数组) +export function selectDictLabels(datas, value, separator) { + var actions = []; + var currentSeparator = undefined === separator ? "," : separator; + var temp = value.split(currentSeparator); + Object.keys(value.split(currentSeparator)).some((val) => { + Object.keys(datas).some((key) => { + if (datas[key].dictValue == ('' + temp[val])) { + actions.push(datas[key].dictLabel + currentSeparator); + } + }) + }) + return actions.join('').substring(0, actions.join('').length - 1); +} + // 通用下载方法 export function download(fileName) { window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true; @@ -98,10 +113,10 @@ export function sprintf(str) { // 转换字符串,undefined,null等转化为"" export function praseStrEmpty(str) { - if (!str || str == "undefined" || str == "null") { - return ""; - } - return str; + if (!str || str == "undefined" || str == "null") { + return ""; + } + return str; } /** @@ -120,17 +135,17 @@ export function handleTree(data, id, parentId, children, rootId) { //对源数据深度克隆 const cloneData = JSON.parse(JSON.stringify(data)) //循环所有项 - const treeData = cloneData.filter(father => { - let branchArr = cloneData.filter(child => { - //返回每一项的子级数组 - return father[id] === child[parentId] - }); - branchArr.length > 0 ? father.children = branchArr : ''; - //返回第一层 - return father[parentId] === rootId; + const treeData = cloneData.filter(father => { + let branchArr = cloneData.filter(child => { + //返回每一项的子级数组 + return father[id] === child[parentId] + }); + branchArr.length > 0 ? father.children = branchArr : ''; + //返回第一层 + return father[parentId] === rootId; }); return treeData != '' ? treeData : data; - } +} /** * 参数处理 From 9bfe3e532824f1276aaed7e8c1d17175d6409cf5 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 21:23:42 +0800 Subject: [PATCH 014/191] =?UTF-8?q?Excel=E6=94=AF=E6=8C=81=E5=88=86?= =?UTF-8?q?=E5=89=B2=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=BB=84=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/core/annotation/Excel.java | 5 ++ .../common/core/utils/poi/ExcelUtil.java | 65 ++++++++++++------- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java index f6d4cd20..6823f54b 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java @@ -34,6 +34,11 @@ public @interface Excel */ public String readConverterExp() default ""; + /** + * 分隔符,读取字符串组内容 + */ + public String separator() default ","; + /** * 导出类型(0数字 1字符串) */ diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java index 783aa8e4..6e13b2b2 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java @@ -265,7 +265,7 @@ public class ExcelUtil } else if (StringUtils.isNotEmpty(attr.readConverterExp())) { - val = reverseByExp(String.valueOf(val), attr.readConverterExp()); + val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator()); } ReflectUtils.invokeSetter(entity, propertyName, val); } @@ -525,13 +525,14 @@ public class ExcelUtil Object value = getTargetValue(vo, field, attr); String dateFormat = attr.dateFormat(); String readConverterExp = attr.readConverterExp(); + String separator = attr.separator(); if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) { cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value)); } else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) { - cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp)); + cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator)); } else { @@ -609,28 +610,36 @@ public class ExcelUtil * * @param propertyValue 参数值 * @param converterExp 翻译注解 + * @param separator 分隔符 * @return 解析后值 - * @throws Exception */ - public static String convertByExp(String propertyValue, String converterExp) throws Exception + public static String convertByExp(String propertyValue, String converterExp, String separator) { - try + StringBuilder propertyString = new StringBuilder(); + String[] convertSource = converterExp.split(","); + for (String item : convertSource) { - String[] convertSource = converterExp.split(","); - for (String item : convertSource) + String[] itemArray = item.split("="); + if (StringUtils.containsAny(separator, propertyValue)) + { + for (String value : propertyValue.split(separator)) + { + if (itemArray[0].equals(value)) + { + propertyString.append(itemArray[1] + separator); + break; + } + } + } + else { - String[] itemArray = item.split("="); if (itemArray[0].equals(propertyValue)) { return itemArray[1]; } } } - catch (Exception e) - { - throw e; - } - return propertyValue; + return StringUtils.stripEnd(propertyString.toString(), separator); } /** @@ -638,28 +647,36 @@ public class ExcelUtil * * @param propertyValue 参数值 * @param converterExp 翻译注解 + * @param separator 分隔符 * @return 解析后值 - * @throws Exception */ - public static String reverseByExp(String propertyValue, String converterExp) throws Exception + public static String reverseByExp(String propertyValue, String converterExp, String separator) { - try + StringBuilder propertyString = new StringBuilder(); + String[] convertSource = converterExp.split(","); + for (String item : convertSource) { - String[] convertSource = converterExp.split(","); - for (String item : convertSource) + String[] itemArray = item.split("="); + if (StringUtils.containsAny(separator, propertyValue)) + { + for (String value : propertyValue.split(separator)) + { + if (itemArray[1].equals(value)) + { + propertyString.append(itemArray[0] + separator); + break; + } + } + } + else { - String[] itemArray = item.split("="); if (itemArray[1].equals(propertyValue)) { return itemArray[0]; } } } - catch (Exception e) - { - throw e; - } - return propertyValue; + return StringUtils.stripEnd(propertyString.toString(), separator); } /** From 40696a10e3d83ac4a37456388e269c230fd6ff7d Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 21:42:34 +0800 Subject: [PATCH 015/191] =?UTF-8?q?excel=20=E5=AF=BC=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E5=AD=97=E4=B8=8D=E9=9C=80=E8=A6=81=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=20=EF=BC=8C=E5=AF=BC=E5=85=A5=E5=85=81=E8=AE=B8=E5=88=97?= =?UTF-8?q?=E5=92=8C=E5=B1=9E=E6=80=A7=E4=B8=AA=E6=95=B0=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/core/utils/poi/ExcelUtil.java | 15 +++++---------- .../java/com/ruoyi/system/utils/DictUtils.java | 4 ++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java index 6e13b2b2..0d30159a 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java @@ -6,7 +6,6 @@ import java.io.OutputStream; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.math.BigDecimal; -import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -194,7 +193,10 @@ public class ExcelUtil // 设置类的私有字段属性可访问. field.setAccessible(true); Integer column = cellMap.get(attr.name()); - fieldsMap.put(column, field); + if (column != null) + { + fieldsMap.put(column, field); + } } } for (int i = 1; i < rows; i++) @@ -829,14 +831,7 @@ public class ExcelUtil } else { - if ((Double) val % 1 > 0) - { - val = new DecimalFormat("0.00").format(val); - } - else - { - val = new DecimalFormat("0").format(val); - } + val = new BigDecimal(val.toString()); // 浮点格式处理 } } else if (cell.getCellTypeEnum() == CellType.STRING) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/utils/DictUtils.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/utils/DictUtils.java index 4629f30c..b8b04f17 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/utils/DictUtils.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/utils/DictUtils.java @@ -37,8 +37,8 @@ public class DictUtils Object cacheObj = SpringUtils.getBean(RedisService.class).getCacheObject(getCacheKey(key)); if (StringUtils.isNotNull(cacheObj)) { - List DictDatas = StringUtils.cast(cacheObj); - return DictDatas; + List dictDatas = StringUtils.cast(cacheObj); + return dictDatas; } return null; } From 5524d5a0bcff0dfbf802217e9dad6e24ff4eb75f Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 21:44:53 +0800 Subject: [PATCH 016/191] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20node-sass=20?= =?UTF-8?q?=E4=B8=BA=20dart-sass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/package.json | 2 +- ruoyi-ui/src/components/HeaderSearch/index.vue | 2 +- ruoyi-ui/src/layout/components/TagsView/ScrollPane.vue | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index 10633984..51a29ba5 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -84,9 +84,9 @@ "husky": "1.3.1", "lint-staged": "8.1.5", "mockjs": "1.0.1-beta3", - "node-sass": "^4.9.0", "plop": "2.3.0", "runjs": "^4.3.2", + "sass": "^1.26.10", "sass-loader": "^7.1.0", "script-ext-html-webpack-plugin": "2.1.3", "script-loader": "0.7.2", diff --git a/ruoyi-ui/src/components/HeaderSearch/index.vue b/ruoyi-ui/src/components/HeaderSearch/index.vue index 6fe5fd65..114ae041 100644 --- a/ruoyi-ui/src/components/HeaderSearch/index.vue +++ b/ruoyi-ui/src/components/HeaderSearch/index.vue @@ -167,7 +167,7 @@ export default { display: inline-block; vertical-align: middle; - /deep/ .el-input__inner { + ::v-deep .el-input__inner { border-radius: 0; border: 0; padding-left: 0; diff --git a/ruoyi-ui/src/layout/components/TagsView/ScrollPane.vue b/ruoyi-ui/src/layout/components/TagsView/ScrollPane.vue index dd4b77f9..c110bf12 100644 --- a/ruoyi-ui/src/layout/components/TagsView/ScrollPane.vue +++ b/ruoyi-ui/src/layout/components/TagsView/ScrollPane.vue @@ -82,7 +82,7 @@ export default { position: relative; overflow: hidden; width: 100%; - /deep/ { + ::v-deep { .el-scrollbar__bar { bottom: 0px; } From 8b5a16c69299ca94cfbfb3ba67898e3cfe3f177c Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 21:46:24 +0800 Subject: [PATCH 017/191] =?UTF-8?q?=E6=9D=83=E9=99=90=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=EF=BC=88=E8=A7=92=E8=89=B2=E5=AF=BC=E5=87=BA=E6=9D=83=E9=99=90?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/views/system/role/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-ui/src/views/system/role/index.vue b/ruoyi-ui/src/views/system/role/index.vue index 34f1b8c1..cd2ff7ac 100644 --- a/ruoyi-ui/src/views/system/role/index.vue +++ b/ruoyi-ui/src/views/system/role/index.vue @@ -91,7 +91,7 @@ icon="el-icon-download" size="mini" @click="handleExport" - v-hasPermi="['system:post:export']" + v-hasPermi="['system:role:export']" >导出 From 17d5751452e3baa7b2f484ad3e6c5d411236721a Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 30 Jul 2020 21:50:01 +0800 Subject: [PATCH 018/191] =?UTF-8?q?=E8=A1=A8=E5=8D=95=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E4=B8=BAInteger/Long=E8=AE=BE=E7=BD=AE=E6=95=B4=E5=BD=A2?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm | 2 +- ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm index a6625897..c7a3f6ee 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm @@ -343,7 +343,7 @@ export default { this.form = { #foreach ($column in $columns) #if($column.htmlType == "radio") - $column.javaField: "0"#if($velocityCount != $columns.size()),#end + $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end #elseif($column.htmlType == "checkbox") $column.javaField: []#if($velocityCount != $columns.size()),#end diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm index 8c61a5d1..c4ebb525 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm @@ -357,7 +357,7 @@ export default { this.form = { #foreach ($column in $columns) #if($column.htmlType == "radio") - $column.javaField: "0"#if($velocityCount != $columns.size()),#end + $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end #elseif($column.htmlType == "checkbox") $column.javaField: []#if($velocityCount != $columns.size()),#end From 56ea7c9caf2eec22d5a7e9ce84e9ffff09b4d95d Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 31 Jul 2020 11:45:27 +0800 Subject: [PATCH 019/191] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/utils/file/FileUtils.java | 142 ++++++++++++++++++ .../ruoyi/gen/controller/GenController.java | 24 ++- .../java/com/ruoyi/gen/domain/GenTable.java | 26 ++++ .../gen/service/GenTableServiceImpl.java | 72 ++++++++- .../ruoyi/gen/service/IGenTableService.java | 16 +- .../mapper/generator/GenTableMapper.xml | 14 +- ruoyi-ui/src/api/tool/gen.js | 9 ++ ruoyi-ui/src/views/tool/gen/genInfoForm.vue | 48 +++++- ruoyi-ui/src/views/tool/gen/index.vue | 10 +- sql/{ry_20200711.sql => ry_20200730.sql} | 2 + 10 files changed, 340 insertions(+), 23 deletions(-) create mode 100644 ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileUtils.java rename sql/{ry_20200711.sql => ry_20200730.sql} (98%) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileUtils.java new file mode 100644 index 00000000..9c5da0bf --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileUtils.java @@ -0,0 +1,142 @@ +package com.ruoyi.common.core.utils.file; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import javax.servlet.http.HttpServletRequest; + +/** + * 文件处理工具类 + * + * @author ruoyi + */ +public class FileUtils extends org.apache.commons.io.FileUtils +{ + public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+"; + + /** + * 输出指定文件的byte数组 + * + * @param filePath 文件路径 + * @param os 输出流 + * @return + */ + public static void writeBytes(String filePath, OutputStream os) throws IOException + { + FileInputStream fis = null; + try + { + File file = new File(filePath); + if (!file.exists()) + { + throw new FileNotFoundException(filePath); + } + fis = new FileInputStream(file); + byte[] b = new byte[1024]; + int length; + while ((length = fis.read(b)) > 0) + { + os.write(b, 0, length); + } + } + catch (IOException e) + { + throw e; + } + finally + { + if (os != null) + { + try + { + os.close(); + } + catch (IOException e1) + { + e1.printStackTrace(); + } + } + if (fis != null) + { + try + { + fis.close(); + } + catch (IOException e1) + { + e1.printStackTrace(); + } + } + } + } + + /** + * 删除文件 + * + * @param filePath 文件 + * @return + */ + public static boolean deleteFile(String filePath) + { + boolean flag = false; + File file = new File(filePath); + // 路径为文件且不为空则进行删除 + if (file.isFile() && file.exists()) + { + file.delete(); + flag = true; + } + return flag; + } + + /** + * 文件名称验证 + * + * @param filename 文件名称 + * @return true 正常 false 非法 + */ + public static boolean isValidFilename(String filename) + { + return filename.matches(FILENAME_PATTERN); + } + + /** + * 下载文件名重新编码 + * + * @param request 请求对象 + * @param fileName 文件名 + * @return 编码后的文件名 + */ + public static String setFileDownloadHeader(HttpServletRequest request, String fileName) + throws UnsupportedEncodingException + { + final String agent = request.getHeader("USER-AGENT"); + String filename = fileName; + if (agent.contains("MSIE")) + { + // IE浏览器 + filename = URLEncoder.encode(filename, "utf-8"); + filename = filename.replace("+", " "); + } + else if (agent.contains("Firefox")) + { + // 火狐浏览器 + filename = new String(fileName.getBytes(), "ISO8859-1"); + } + else if (agent.contains("Chrome")) + { + // google浏览器 + filename = URLEncoder.encode(filename, "utf-8"); + } + else + { + // 其它浏览器 + filename = URLEncoder.encode(filename, "utf-8"); + } + return filename; + } +} 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 f4492f5d..da2fbbbc 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 @@ -148,17 +148,29 @@ public class GenController extends BaseController } /** - * 生成代码 + * 生成代码(下载方式) */ @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 + @GetMapping("/download/{tableName}") + public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException { - byte[] data = genTableService.generatorCode(tableName); + byte[] data = genTableService.downloadCode(tableName); genCode(response, data); } + /** + * 生成代码(自定义路径) + */ + @PreAuthorize("@ss.hasPermi('tool:gen:code')") + @Log(title = "代码生成", businessType = BusinessType.GENCODE) + @GetMapping("/genCode/{tableName}") + public AjaxResult genCode(HttpServletResponse response, @PathVariable("tableName") String tableName) + { + 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); } @@ -183,4 +195,4 @@ public class GenController extends BaseController response.setContentType("application/octet-stream; charset=UTF-8"); IOUtils.write(data, response.getOutputStream()); } -} \ No newline at end of file +} 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 cba6c5ac..8b62ae74 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 @@ -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; 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 cb87a6f3..f5469c24 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,6 +1,7 @@ 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; @@ -22,7 +23,9 @@ import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.GenConstants; import com.ruoyi.common.core.exception.CustomException; +import com.ruoyi.common.core.text.CharsetKit; import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.core.utils.file.FileUtils; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.gen.domain.GenTable; import com.ruoyi.gen.domain.GenTableColumn; @@ -201,13 +204,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); @@ -217,13 +220,55 @@ public class GenTableServiceImpl implements IGenTableService } /** - * 批量生成代码 + * 生成代码(自定义路径) + * + * @param tableName 表名称 + * @return 数据 + */ + @Override + public void generatorCode(String tableName) + { + // 查询表信息 + GenTable table = genTableMapper.selectGenTableByName(tableName); + // 查询列信息 + List columns = table.getColumns(); + setPkColumn(table, columns); + + VelocityInitializer.initVelocity(); + + VelocityContext context = VelocityUtils.prepareContext(table); + + // 获取模板列表 + 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")) + { + // 渲染模板 + 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); @@ -346,4 +391,21 @@ public class GenTableServiceImpl implements IGenTableService genTable.setParentMenuName(parentMenuName); } } -} \ No newline at end of file + + /** + * 获取代码生成地址 + * + * @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); + } +} 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 050646cc..7d324b25 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 @@ -75,20 +75,28 @@ public interface IGenTableService public Map 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); /** * 修改保存参数校验 diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml index 8a04ab3f..302713b7 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml @@ -15,6 +15,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + @@ -50,7 +52,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, options, create_by, create_time, update_by, update_time, remark from gen_table + select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table