From 5b94d2461f929a363a48a63e448f0c0f4238d99d Mon Sep 17 00:00:00 2001
From: administrator <2316696377@qq.com>
Date: Thu, 24 Sep 2020 18:46:59 +0800
Subject: [PATCH] =?UTF-8?q?=E5=86=B2=E7=AA=81=E8=A7=A3=E5=86=B3=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 13 +
ruoyi-admin/pom.xml | 30 +
.../com/ruoyi/logger/MyConsoleAppender.java | 35 ++
.../system/SysConfigController.java | 80 +--
.../controller/system/SysDeptController.java | 109 ++--
.../system/SysDictTypeController.java | 154 +++--
.../controller/system/SysUserController.java | 233 ++++---
.../src/main/resources/application-druid.yml | 4 +-
.../src/main/resources/application.yml | 24 -
ruoyi-admin/src/main/resources/banner.txt | 26 +-
.../migration/mysql/v001__init_sys_tables.sql | 70 +--
.../mysql/v002__init_quartz_tables.sql | 24 +-
.../src/main/resources/logback-spring.xml | 35 ++
ruoyi-admin/src/main/resources/logback.xml | 93 ---
.../main/resources/mybatis/mybatis-config.xml | 15 -
ruoyi-common/pom.xml | 6 -
.../com/ruoyi/common/base/BaseRepository.java | 3 +
.../com/ruoyi/common/base/BaseService.java | 27 +
.../com/ruoyi/common/core/text/Convert.java | 36 +-
.../framework/aspectj/DataScopeAspect.java | 10 +-
.../framework/aspectj/DataSourceAspect.java | 3 +-
.../shiro/service/SysRegisterService.java | 160 ++---
.../generator/controller/GenController.java | 183 ++----
.../com/ruoyi/generator/domain/GenTable.java | 318 ++++------
.../generator/domain/GenTableColumn.java | 403 ++++---------
.../generator/service/IGenTableService.java | 74 +--
.../service/impl/GenTableServiceImpl.java | 570 +++++++-----------
.../com/ruoyi/generator/util/GenUtils.java | 153 ++---
.../ruoyi/generator/util/VelocityUtils.java | 263 +++-----
.../mapper/generator/GenTableColumnMapper.xml | 127 ----
.../mapper/generator/GenTableMapper.xml | 189 ------
.../quartz/controller/SysJobController.java | 69 +--
.../controller/SysJobLogController.java | 46 +-
.../service/impl/SysJobServiceImpl.java | 204 +++----
.../com/ruoyi/system/domain/SysDictData.java | 8 +
.../java/com/ruoyi/system/domain/SysRole.java | 203 ++++---
.../com/ruoyi/system/domain/SysRoleDept.java | 45 --
.../java/com/ruoyi/system/domain/SysUser.java | 439 ++++----------
.../ruoyi/system/mapper/SysDeptMapper.java | 117 ----
.../system/mapper/SysUserRoleMapper.java | 70 ---
.../system/service/ISysConfigService.java | 31 +-
.../ruoyi/system/service/ISysDeptService.java | 58 +-
.../system/service/ISysDictDataService.java | 43 +-
.../system/service/ISysDictTypeService.java | 56 +-
.../ruoyi/system/service/ISysUserService.java | 121 ++--
.../service/impl/SysConfigServiceImpl.java | 191 +++---
.../service/impl/SysDeptServiceImpl.java | 282 ++++-----
.../service/impl/SysDictDataServiceImpl.java | 130 ++--
.../service/impl/SysDictTypeServiceImpl.java | 225 +++----
.../impl/SysLogininforServiceImpl.java | 2 -
.../service/impl/SysMenuServiceImpl.java | 330 +++++-----
.../service/impl/SysRoleServiceImpl.java | 331 ++++------
.../service/impl/SysUserServiceImpl.java | 520 +++++++---------
.../com/ruoyi/system/utils/DictUtils.java | 106 ++--
.../mapper/system/SysConfigMapper.xml | 108 ----
.../resources/mapper/system/SysDeptMapper.xml | 158 -----
.../mapper/system/SysDictDataMapper.xml | 123 ----
.../mapper/system/SysDictTypeMapper.xml | 105 ----
.../resources/mapper/system/SysMenuMapper.xml | 180 ------
.../resources/mapper/system/SysPostMapper.xml | 110 ----
.../resources/mapper/system/SysRoleMapper.xml | 131 ----
.../resources/mapper/system/SysUserMapper.xml | 223 -------
.../mapper/system/SysUserRoleMapper.xml | 48 --
63 files changed, 2697 insertions(+), 5586 deletions(-)
create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/logger/MyConsoleAppender.java
create mode 100644 ruoyi-admin/src/main/resources/logback-spring.xml
delete mode 100644 ruoyi-admin/src/main/resources/logback.xml
delete mode 100644 ruoyi-admin/src/main/resources/mybatis/mybatis-config.xml
delete mode 100644 ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml
delete mode 100644 ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml
delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleDept.java
delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java
delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java
delete mode 100644 ruoyi-system/src/main/resources/mapper/system/SysConfigMapper.xml
delete mode 100644 ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
delete mode 100644 ruoyi-system/src/main/resources/mapper/system/SysDictDataMapper.xml
delete mode 100644 ruoyi-system/src/main/resources/mapper/system/SysDictTypeMapper.xml
delete mode 100644 ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml
delete mode 100644 ruoyi-system/src/main/resources/mapper/system/SysPostMapper.xml
delete mode 100644 ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml
delete mode 100644 ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
delete mode 100644 ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml
diff --git a/pom.xml b/pom.xml
index d9ae53d8c..8b1839c14 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,6 +30,7 @@
3.17
1.7
4.2.1
+ 2.3.0.1
@@ -256,6 +257,18 @@
${project.build.sourceEncoding}
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 1.8
+ 1.8
+ UTF-8
+ true
+
+
diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml
index 94e6abf6f..e07c2a2c2 100644
--- a/ruoyi-admin/pom.xml
+++ b/ruoyi-admin/pom.xml
@@ -90,6 +90,36 @@
jackson-datatype-hibernate5
2.10.1
+
+
+ com.sun.xml.bind
+ jaxb-impl
+ ${jaxb.version}
+
+
+
+ com.sun.xml.bind
+ jaxb-core
+ ${jaxb.version}
+
+
+
+ org.fusesource.jansi
+ jansi
+ 1.18
+
+
+
+ junit
+ junit
+ test
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/logger/MyConsoleAppender.java b/ruoyi-admin/src/main/java/com/ruoyi/logger/MyConsoleAppender.java
new file mode 100644
index 000000000..cda7318ad
--- /dev/null
+++ b/ruoyi-admin/src/main/java/com/ruoyi/logger/MyConsoleAppender.java
@@ -0,0 +1,35 @@
+package com.ruoyi.logger;
+
+import ch.qos.logback.core.ConsoleAppender;
+import ch.qos.logback.core.util.EnvUtil;
+import ch.qos.logback.core.util.OptionHelper;
+
+import java.io.OutputStream;
+
+public class MyConsoleAppender extends ConsoleAppender {
+
+ private final static String WindowsAnsiOutputStream_CLASS_NAME = "org.fusesource.jansi.WindowsAnsiPrintStream";
+
+ @Override
+ public void start() {
+ OutputStream targetStream = target.getStream();
+ // enable jansi only on Windows and only if withJansi set to true
+ if (EnvUtil.isWindows() && withJansi) {
+ targetStream = getTargetStreamForWindows(targetStream);
+ }
+ setOutputStream(targetStream);
+ super.start();
+ }
+
+ private OutputStream getTargetStreamForWindows(OutputStream targetStream) {
+ try {
+ addInfo("Enabling JANSI WindowsAnsiOutputStream for the console.");
+ Object windowsAnsiOutputStream = OptionHelper.instantiateByClassNameAndParameter(WindowsAnsiOutputStream_CLASS_NAME, Object.class, context,
+ OutputStream.class, targetStream);
+ return (OutputStream) windowsAnsiOutputStream;
+ } catch (Exception e) {
+ addWarn("Failed to create WindowsAnsiOutputStream. Falling back on the default stream.", e);
+ }
+ return targetStream;
+ }
+}
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
index 086b764bc..d18da6542 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
@@ -1,16 +1,5 @@
package com.ruoyi.web.controller.system;
-import java.util.List;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-import org.springframework.validation.annotation.Validated;
-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.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
@@ -21,16 +10,24 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
/**
* 参数配置 信息操作处理
- *
+ *
* @author ruoyi
*/
@Controller
@RequestMapping("/system/config")
-public class SysConfigController extends BaseController
-{
+public class SysConfigController extends BaseController {
private String prefix = "system/config";
@Autowired
@@ -38,8 +35,7 @@ public class SysConfigController extends BaseController
@RequiresPermissions("system:config:view")
@GetMapping()
- public String config()
- {
+ public String config() {
return prefix + "/config";
}
@@ -49,20 +45,16 @@ public class SysConfigController extends BaseController
@RequiresPermissions("system:config:list")
@PostMapping("/list")
@ResponseBody
- public TableDataInfo list(SysConfig config)
- {
- startPage();
- List list = configService.selectConfigList(config);
- return getDataTable(list);
+ public TableDataInfo list(SysConfig config) {
+ return getDataTable(configService.selectConfigList(config, getPageRequest()));
}
@Log(title = "参数管理", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:config:export")
@PostMapping("/export")
@ResponseBody
- public AjaxResult export(SysConfig config)
- {
- List list = configService.selectConfigList(config);
+ public AjaxResult export(SysConfig config) {
+ List list = configService.selectConfigList(config, Pageable.unpaged()).getContent();
ExcelUtil util = new ExcelUtil(SysConfig.class);
return util.exportExcel(list, "参数数据");
}
@@ -71,8 +63,7 @@ public class SysConfigController extends BaseController
* 新增参数配置
*/
@GetMapping("/add")
- public String add()
- {
+ public String add() {
return prefix + "/add";
}
@@ -83,10 +74,8 @@ public class SysConfigController extends BaseController
@Log(title = "参数管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
- public AjaxResult addSave(@Validated SysConfig config)
- {
- if (UserConstants.CONFIG_KEY_NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
- {
+ public AjaxResult addSave(@Validated SysConfig config) {
+ if (UserConstants.CONFIG_KEY_NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {
return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
config.setCreateBy(ShiroUtils.getLoginName());
@@ -97,8 +86,7 @@ public class SysConfigController extends BaseController
* 修改参数配置
*/
@GetMapping("/edit/{configId}")
- public String edit(@PathVariable("configId") Long configId, ModelMap mmap)
- {
+ public String edit(@PathVariable("configId") Long configId, ModelMap mmap) {
mmap.put("config", configService.selectConfigById(configId));
return prefix + "/edit";
}
@@ -110,10 +98,8 @@ public class SysConfigController extends BaseController
@Log(title = "参数管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
- public AjaxResult editSave(@Validated SysConfig config)
- {
- if (UserConstants.CONFIG_KEY_NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
- {
+ public AjaxResult editSave(@Validated SysConfig config) {
+ if (UserConstants.CONFIG_KEY_NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config))) {
return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
config.setUpdateBy(ShiroUtils.getLoginName());
@@ -127,11 +113,19 @@ public class SysConfigController extends BaseController
@Log(title = "参数管理", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
- public AjaxResult remove(String ids)
- {
+ public AjaxResult remove(String ids) {
return toAjax(configService.deleteConfigByIds(ids));
}
+ /**
+ * 校验参数键名
+ */
+ @PostMapping("/checkConfigKeyUnique")
+ @ResponseBody
+ public String checkConfigKeyUnique(SysConfig config) {
+ return configService.checkConfigKeyUnique(config);
+ }
+
/**
* 清空缓存
*/
@@ -144,14 +138,4 @@ public class SysConfigController extends BaseController
configService.clearCache();
return success();
}
-
- /**
- * 校验参数键名
- */
- @PostMapping("/checkConfigKeyUnique")
- @ResponseBody
- public String checkConfigKeyUnique(SysConfig config)
- {
- return configService.checkConfigKeyUnique(config);
- }
}
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java
index 55362e6e6..bf26d7c98 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java
@@ -1,16 +1,5 @@
package com.ruoyi.web.controller.system;
-import java.util.List;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-import org.springframework.validation.annotation.Validated;
-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.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
@@ -22,16 +11,24 @@ import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.domain.SysRole;
import com.ruoyi.system.service.ISysDeptService;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
/**
* 部门信息
- *
+ *
* @author ruoyi
*/
@Controller
@RequestMapping("/system/dept")
-public class SysDeptController extends BaseController
-{
+public class SysDeptController extends BaseController {
private String prefix = "system/dept";
@Autowired
@@ -39,26 +36,22 @@ public class SysDeptController extends BaseController
@RequiresPermissions("system:dept:view")
@GetMapping()
- public String dept()
- {
+ public String dept() {
return prefix + "/dept";
}
@RequiresPermissions("system:dept:list")
@PostMapping("/list")
@ResponseBody
- public List list(SysDept dept)
- {
- List deptList = deptService.selectDeptList(dept);
- return deptList;
+ public List list(SysDept dept) {
+ return deptService.selectDeptList(dept, Pageable.unpaged()).getContent();
}
/**
* 新增部门
*/
@GetMapping("/add/{parentId}")
- public String add(@PathVariable("parentId") Long parentId, ModelMap mmap)
- {
+ public String add(@PathVariable("parentId") Long parentId, ModelMap mmap) {
mmap.put("dept", deptService.selectDeptById(parentId));
return prefix + "/add";
}
@@ -70,27 +63,20 @@ public class SysDeptController extends BaseController
@RequiresPermissions("system:dept:add")
@PostMapping("/add")
@ResponseBody
- public AjaxResult addSave(@Validated SysDept dept)
- {
- if (UserConstants.DEPT_NAME_NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
- {
+ public AjaxResult addSave(@Validated SysDept dept) {
+ if (UserConstants.DEPT_NAME_NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
dept.setCreateBy(ShiroUtils.getLoginName());
- return toAjax(deptService.insertDept(dept));
+ return success(deptService.insertDept(dept));
}
/**
* 修改
*/
@GetMapping("/edit/{deptId}")
- public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap)
- {
+ public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap) {
SysDept dept = deptService.selectDeptById(deptId);
- if (StringUtils.isNotNull(dept) && 100L == deptId)
- {
- dept.setParentName("无");
- }
mmap.put("dept", dept);
return prefix + "/edit";
}
@@ -102,23 +88,18 @@ public class SysDeptController extends BaseController
@RequiresPermissions("system:dept:edit")
@PostMapping("/edit")
@ResponseBody
- public AjaxResult editSave(@Validated SysDept dept)
- {
- if (UserConstants.DEPT_NAME_NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
- {
+ public AjaxResult editSave(@Validated SysDept dept) {
+ if (UserConstants.DEPT_NAME_NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept))) {
return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
- }
- else if (dept.getParentId().equals(dept.getDeptId()))
- {
+ } else if (dept.getParentId().equals(dept.getDeptId())) {
return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
- }
- else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
- && deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)
- {
+ }else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
+ && deptService.countChildren(dept.getDeptId()) > 0){
return AjaxResult.error("该部门包含未停用的子部门!");
}
dept.setUpdateBy(ShiroUtils.getLoginName());
- return toAjax(deptService.updateDept(dept));
+ deptService.updateDept(dept);
+ return success();
}
/**
@@ -128,17 +109,15 @@ public class SysDeptController extends BaseController
@RequiresPermissions("system:dept:remove")
@GetMapping("/remove/{deptId}")
@ResponseBody
- public AjaxResult remove(@PathVariable("deptId") Long deptId)
- {
- if (deptService.selectDeptCount(deptId) > 0)
- {
+ public AjaxResult remove(@PathVariable("deptId") Long deptId) {
+ if (deptService.countChildren(deptId) > 0) {
return AjaxResult.warn("存在下级部门,不允许删除");
}
- if (deptService.checkDeptExistUser(deptId))
- {
+ if (deptService.checkDeptExistUser(deptId)) {
return AjaxResult.warn("部门存在用户,不允许删除");
}
- return toAjax(deptService.deleteDeptById(deptId));
+ deptService.deleteDeptById(deptId);
+ return success();
}
/**
@@ -146,20 +125,19 @@ public class SysDeptController extends BaseController
*/
@PostMapping("/checkDeptNameUnique")
@ResponseBody
- public String checkDeptNameUnique(SysDept dept)
- {
+ public String checkDeptNameUnique(SysDept dept) {
return deptService.checkDeptNameUnique(dept);
}
/**
* 选择部门树
- *
+ *
* @param deptId 部门ID
* @param excludeId 排除ID
*/
@GetMapping(value = { "/selectDeptTree/{deptId}", "/selectDeptTree/{deptId}/{excludeId}" })
public String selectDeptTree(@PathVariable("deptId") Long deptId,
- @PathVariable(value = "excludeId", required = false) String excludeId, ModelMap mmap)
+ @PathVariable(value = "excludeId", required = false) String excludeId, ModelMap mmap)
{
mmap.put("dept", deptService.selectDeptById(deptId));
mmap.put("excludeId", excludeId);
@@ -171,32 +149,17 @@ public class SysDeptController extends BaseController
*/
@GetMapping("/treeData")
@ResponseBody
- public List treeData()
- {
+ public List treeData() {
List ztrees = deptService.selectDeptTree(new SysDept());
return ztrees;
}
- /**
- * 加载部门列表树(排除下级)
- */
- @GetMapping("/treeData/{excludeId}")
- @ResponseBody
- public List treeDataExcludeChild(@PathVariable(value = "excludeId", required = false) Long excludeId)
- {
- SysDept dept = new SysDept();
- dept.setDeptId(excludeId);
- List ztrees = deptService.selectDeptTreeExcludeChild(dept);
- return ztrees;
- }
-
/**
* 加载角色部门(数据权限)列表树
*/
@GetMapping("/roleDeptTreeData")
@ResponseBody
- public List deptTreeData(SysRole role)
- {
+ public List deptTreeData(SysRole role) {
List ztrees = deptService.roleDeptTreeData(role);
return ztrees;
}
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java
index 4769dc74e..68a8872b0 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java
@@ -1,16 +1,5 @@
package com.ruoyi.web.controller.system;
-import java.util.List;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-import org.springframework.validation.annotation.Validated;
-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.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
@@ -22,16 +11,24 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysDictType;
import com.ruoyi.system.service.ISysDictTypeService;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
/**
* 数据字典信息
- *
+ *
* @author ruoyi
*/
@Controller
@RequestMapping("/system/dict")
-public class SysDictTypeController extends BaseController
-{
+public class SysDictTypeController extends BaseController {
private String prefix = "system/dict/type";
@Autowired
@@ -39,29 +36,23 @@ public class SysDictTypeController extends BaseController
@RequiresPermissions("system:dict:view")
@GetMapping()
- public String dictType()
- {
+ public String dictType() {
return prefix + "/type";
}
@PostMapping("/list")
@RequiresPermissions("system:dict:list")
@ResponseBody
- public TableDataInfo list(SysDictType dictType)
- {
- startPage();
- List list = dictTypeService.selectDictTypeList(dictType);
- return getDataTable(list);
+ public TableDataInfo list(SysDictType dictType) {
+ return getDataTable(dictTypeService.selectDictTypeList(dictType, getPageRequest()));
}
@Log(title = "字典类型", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:dict:export")
@PostMapping("/export")
@ResponseBody
- public AjaxResult export(SysDictType dictType)
- {
-
- List list = dictTypeService.selectDictTypeList(dictType);
+ public AjaxResult export(SysDictType dictType) {
+ List list = dictTypeService.selectDictTypeList(dictType, Pageable.unpaged()).getContent();
ExcelUtil util = new ExcelUtil(SysDictType.class);
return util.exportExcel(list, "字典类型");
}
@@ -70,8 +61,7 @@ public class SysDictTypeController extends BaseController
* 新增字典类型
*/
@GetMapping("/add")
- public String add()
- {
+ public String add() {
return prefix + "/add";
}
@@ -82,10 +72,8 @@ public class SysDictTypeController extends BaseController
@RequiresPermissions("system:dict:add")
@PostMapping("/add")
@ResponseBody
- public AjaxResult addSave(@Validated SysDictType dict)
- {
- if (UserConstants.DICT_TYPE_NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
- {
+ public AjaxResult addSave(@Validated SysDictType dict) {
+ if (UserConstants.DICT_TYPE_NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict))) {
return error("新增字典'" + dict.getDictName() + "'失败,字典类型已存在");
}
dict.setCreateBy(ShiroUtils.getLoginName());
@@ -96,8 +84,7 @@ public class SysDictTypeController extends BaseController
* 修改字典类型
*/
@GetMapping("/edit/{dictId}")
- public String edit(@PathVariable("dictId") Long dictId, ModelMap mmap)
- {
+ public String edit(@PathVariable("dictId") Long dictId, ModelMap mmap) {
mmap.put("dict", dictTypeService.selectDictTypeById(dictId));
return prefix + "/edit";
}
@@ -109,10 +96,8 @@ public class SysDictTypeController extends BaseController
@RequiresPermissions("system:dict:edit")
@PostMapping("/edit")
@ResponseBody
- public AjaxResult editSave(@Validated SysDictType dict)
- {
- if (UserConstants.DICT_TYPE_NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict)))
- {
+ public AjaxResult editSave(@Validated SysDictType dict) {
+ if (UserConstants.DICT_TYPE_NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict))) {
return error("修改字典'" + dict.getDictName() + "'失败,字典类型已存在");
}
dict.setUpdateBy(ShiroUtils.getLoginName());
@@ -123,9 +108,53 @@ public class SysDictTypeController extends BaseController
@RequiresPermissions("system:dict:remove")
@PostMapping("/remove")
@ResponseBody
- public AjaxResult remove(String ids)
- {
- return toAjax(dictTypeService.deleteDictTypeByIds(ids));
+ public AjaxResult remove(String ids) {
+ try {
+ return toAjax(dictTypeService.deleteDictTypeByIds(ids));
+ } catch (Exception e) {
+ return error(e.getMessage());
+ }
+ }
+
+ /**
+ * 查询字典详细
+ */
+ @RequiresPermissions("system:dict:list")
+ @GetMapping("/detail/{dictId}")
+ public String detail(@PathVariable("dictId") Long dictId, ModelMap mmap) {
+ mmap.put("dict", dictTypeService.selectDictTypeById(dictId));
+ mmap.put("dictList", dictTypeService.selectDictTypeAll());
+ return "system/dict/data/data";
+ }
+
+ /**
+ * 校验字典类型
+ */
+ @PostMapping("/checkDictTypeUnique")
+ @ResponseBody
+ public String checkDictTypeUnique(SysDictType dictType) {
+ return dictTypeService.checkDictTypeUnique(dictType);
+ }
+
+ /**
+ * 选择字典树
+ */
+ @GetMapping("/selectDictTree/{columnId}/{dictType}")
+ public String selectDeptTree(@PathVariable("columnId") Long columnId, @PathVariable("dictType") String dictType,
+ ModelMap mmap) {
+ mmap.put("columnId", columnId);
+ mmap.put("dict", dictTypeService.selectDictTypeByType(dictType));
+ return prefix + "/tree";
+ }
+
+ /**
+ * 加载字典列表树
+ */
+ @GetMapping("/treeData")
+ @ResponseBody
+ public List treeData() {
+ List ztrees = dictTypeService.selectDictTree(new SysDictType());
+ return ztrees;
}
/**
@@ -140,49 +169,4 @@ public class SysDictTypeController extends BaseController
dictTypeService.clearCache();
return success();
}
-
- /**
- * 查询字典详细
- */
- @RequiresPermissions("system:dict:list")
- @GetMapping("/detail/{dictId}")
- public String detail(@PathVariable("dictId") Long dictId, ModelMap mmap)
- {
- mmap.put("dict", dictTypeService.selectDictTypeById(dictId));
- mmap.put("dictList", dictTypeService.selectDictTypeAll());
- return "system/dict/data/data";
- }
-
- /**
- * 校验字典类型
- */
- @PostMapping("/checkDictTypeUnique")
- @ResponseBody
- public String checkDictTypeUnique(SysDictType dictType)
- {
- return dictTypeService.checkDictTypeUnique(dictType);
- }
-
- /**
- * 选择字典树
- */
- @GetMapping("/selectDictTree/{columnId}/{dictType}")
- public String selectDeptTree(@PathVariable("columnId") Long columnId, @PathVariable("dictType") String dictType,
- ModelMap mmap)
- {
- mmap.put("columnId", columnId);
- mmap.put("dict", dictTypeService.selectDictTypeByType(dictType));
- return prefix + "/tree";
- }
-
- /**
- * 加载字典列表树
- */
- @GetMapping("/treeData")
- @ResponseBody
- public List treeData()
- {
- List ztrees = dictTypeService.selectDictTree(new SysDictType());
- return ztrees;
- }
}
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java
index fc768b49a..a6ab51dc9 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java
@@ -1,22 +1,10 @@
package com.ruoyi.web.controller.system;
-import java.util.List;
-import java.util.stream.Collectors;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-import org.springframework.validation.annotation.Validated;
-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.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
@@ -24,19 +12,31 @@ import com.ruoyi.framework.shiro.service.SysPasswordService;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysRole;
import com.ruoyi.system.domain.SysUser;
+import com.ruoyi.system.domain.SysUserRole;
import com.ruoyi.system.service.ISysPostService;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+import java.util.Set;
/**
* 用户信息
- *
+ *
* @author ruoyi
*/
@Controller
@RequestMapping("/system/user")
-public class SysUserController extends BaseController
-{
+public class SysUserController extends BaseController {
private String prefix = "system/user";
@Autowired
@@ -53,38 +53,32 @@ public class SysUserController extends BaseController
@RequiresPermissions("system:user:view")
@GetMapping()
- public String user()
- {
+ public String user() {
return prefix + "/user";
}
@RequiresPermissions("system:user:list")
@PostMapping("/list")
@ResponseBody
- public TableDataInfo list(SysUser user)
- {
- startPage();
- List list = userService.selectUserList(user);
- return getDataTable(list);
+ public TableDataInfo list(SysUser user) {
+ return getDataTable(userService.selectUserList(user, getPageRequest()));
}
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
@RequiresPermissions("system:user:export")
@PostMapping("/export")
@ResponseBody
- public AjaxResult export(SysUser user)
- {
- List list = userService.selectUserList(user);
+ public AjaxResult export(SysUser user) {
+ Page page = userService.selectUserList(user, Pageable.unpaged());
ExcelUtil util = new ExcelUtil(SysUser.class);
- return util.exportExcel(list, "用户数据");
+ return util.exportExcel(page.getContent(), "用户数据");
}
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
@RequiresPermissions("system:user:import")
@PostMapping("/importData")
@ResponseBody
- public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
- {
+ public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
ExcelUtil util = new ExcelUtil(SysUser.class);
List userList = util.importExcel(file.getInputStream());
String operName = ShiroUtils.getSysUser().getLoginName();
@@ -95,8 +89,7 @@ public class SysUserController extends BaseController
@RequiresPermissions("system:user:view")
@GetMapping("/importTemplate")
@ResponseBody
- public AjaxResult importTemplate()
- {
+ public AjaxResult importTemplate() {
ExcelUtil util = new ExcelUtil(SysUser.class);
return util.importTemplateExcel("用户数据");
}
@@ -105,9 +98,8 @@ public class SysUserController extends BaseController
* 新增用户
*/
@GetMapping("/add")
- public String add(ModelMap mmap)
- {
- mmap.put("roles", roleService.selectRoleAll().stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
+ public String add(ModelMap mmap) {
+ mmap.put("roles", roleService.selectRoleAll());
mmap.put("posts", postService.selectPostAll());
return prefix + "/add";
}
@@ -119,36 +111,28 @@ public class SysUserController extends BaseController
@Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
- public AjaxResult addSave(@Validated SysUser user)
- {
- if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(user.getLoginName())))
- {
+ public AjaxResult addSave(@Validated SysUser user) {
+ if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(user.getLoginName()))) {
return error("新增用户'" + user.getLoginName() + "'失败,登录账号已存在");
- }
- else if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
- {
+ } else if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
return error("新增用户'" + user.getLoginName() + "'失败,手机号码已存在");
- }
- else if (UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
- {
+ } else if (UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
}
user.setSalt(ShiroUtils.randomSalt());
user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
user.setCreateBy(ShiroUtils.getLoginName());
- return toAjax(userService.insertUser(user));
+ return success(userService.insertUser(user));
}
/**
* 修改用户
*/
@GetMapping("/edit/{userId}")
- public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
- {
- List roles = roleService.selectRolesByUserId(userId);
- mmap.put("user", userService.selectUserById(userId));
- mmap.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
- mmap.put("posts", postService.selectPostsByUserId(userId));
+ public String edit(@PathVariable("userId") Long userId, ModelMap mmap) {
+ mmap.put("user", userService.selectUserWithRolesAndPostsById(userId));
+ mmap.put("roles", roleService.selectRoleAll());
+ mmap.put("posts", postService.selectPostAll());
return prefix + "/edit";
}
@@ -159,25 +143,22 @@ public class SysUserController extends BaseController
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
- public AjaxResult editSave(@Validated SysUser user)
- {
+ public AjaxResult editSave(@Validated SysUser user) {
userService.checkUserAllowed(user);
- if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
- {
+ if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
return error("修改用户'" + user.getLoginName() + "'失败,手机号码已存在");
- }
- else if (UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
- {
+ } else if (UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
return error("修改用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
}
user.setUpdateBy(ShiroUtils.getLoginName());
- return toAjax(userService.updateUser(user));
+ userService.updateUser(user);
+ return success();
}
@RequiresPermissions("system:user:resetPwd")
+ @Log(title = "重置密码", businessType = BusinessType.UPDATE)
@GetMapping("/resetPwd/{userId}")
- public String resetPwd(@PathVariable("userId") Long userId, ModelMap mmap)
- {
+ public String resetPwd(@PathVariable("userId") Long userId, ModelMap mmap) {
mmap.put("user", userService.selectUserById(userId));
return prefix + "/resetPwd";
}
@@ -186,20 +167,67 @@ public class SysUserController extends BaseController
@Log(title = "重置密码", businessType = BusinessType.UPDATE)
@PostMapping("/resetPwd")
@ResponseBody
- public AjaxResult resetPwdSave(SysUser user)
- {
+ public AjaxResult resetPwdSave(SysUser user) {
userService.checkUserAllowed(user);
user.setSalt(ShiroUtils.randomSalt());
user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
- if (userService.resetUserPwd(user) > 0)
- {
- if (ShiroUtils.getUserId().longValue() == user.getUserId().longValue())
- {
- ShiroUtils.setSysUser(userService.selectUserById(user.getUserId()));
- }
- return success();
+ userService.resetUserPwd(user);
+ if (ShiroUtils.getUserId() == user.getUserId()) {
+ ShiroUtils.setSysUser(userService.selectUserById(user.getUserId()));
}
- return error();
+ return success();
+ }
+
+ @RequiresPermissions("system:user:remove")
+ @Log(title = "用户管理", businessType = BusinessType.DELETE)
+ @PostMapping("/remove")
+ @ResponseBody
+ public AjaxResult remove(String ids) {
+ try {
+ return toAjax(userService.deleteUserByIds(ids));
+ } catch (Exception e) {
+ return error(e.getMessage());
+ }
+ }
+
+ /**
+ * 校验用户名
+ */
+ @PostMapping("/checkLoginNameUnique")
+ @ResponseBody
+ public String checkLoginNameUnique(SysUser user) {
+ return userService.checkLoginNameUnique(user.getLoginName());
+ }
+
+ /**
+ * 校验手机号码
+ */
+ @PostMapping("/checkPhoneUnique")
+ @ResponseBody
+ public String checkPhoneUnique(SysUser user) {
+ return userService.checkPhoneUnique(user);
+ }
+
+ /**
+ * 校验email邮箱
+ */
+ @PostMapping("/checkEmailUnique")
+ @ResponseBody
+ public String checkEmailUnique(SysUser user) {
+ return userService.checkEmailUnique(user);
+ }
+
+ /**
+ * 用户状态修改
+ */
+ @Log(title = "用户管理", businessType = BusinessType.UPDATE)
+ @RequiresPermissions("system:user:edit")
+ @PostMapping("/changeStatus")
+ @ResponseBody
+ public AjaxResult changeStatus(SysUser user) {
+ userService.checkUserAllowed(user);
+ userService.changeStatus(user);
+ return success();
}
/**
@@ -210,9 +238,9 @@ public class SysUserController extends BaseController
{
SysUser user = userService.selectUserById(userId);
// 获取用户所属的角色列表
- List roles = roleService.selectRolesByUserId(userId);
+ Set userRoles = userService.selectUserById(userId).getRoles();
mmap.put("user", user);
- mmap.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
+ mmap.put("userRoles", userRoles);
return prefix + "/authRole";
}
@@ -228,63 +256,4 @@ public class SysUserController extends BaseController
userService.insertUserAuth(userId, roleIds);
return success();
}
-
- @RequiresPermissions("system:user:remove")
- @Log(title = "用户管理", businessType = BusinessType.DELETE)
- @PostMapping("/remove")
- @ResponseBody
- public AjaxResult remove(String ids)
- {
- try
- {
- return toAjax(userService.deleteUserByIds(ids));
- }
- catch (Exception e)
- {
- return error(e.getMessage());
- }
- }
-
- /**
- * 校验用户名
- */
- @PostMapping("/checkLoginNameUnique")
- @ResponseBody
- public String checkLoginNameUnique(SysUser user)
- {
- return userService.checkLoginNameUnique(user.getLoginName());
- }
-
- /**
- * 校验手机号码
- */
- @PostMapping("/checkPhoneUnique")
- @ResponseBody
- public String checkPhoneUnique(SysUser user)
- {
- return userService.checkPhoneUnique(user);
- }
-
- /**
- * 校验email邮箱
- */
- @PostMapping("/checkEmailUnique")
- @ResponseBody
- public String checkEmailUnique(SysUser user)
- {
- return userService.checkEmailUnique(user);
- }
-
- /**
- * 用户状态修改
- */
- @Log(title = "用户管理", businessType = BusinessType.UPDATE)
- @RequiresPermissions("system:user:edit")
- @PostMapping("/changeStatus")
- @ResponseBody
- public AjaxResult changeStatus(SysUser user)
- {
- userService.checkUserAllowed(user);
- return toAjax(userService.changeStatus(user));
- }
}
\ No newline at end of file
diff --git a/ruoyi-admin/src/main/resources/application-druid.yml b/ruoyi-admin/src/main/resources/application-druid.yml
index e865580dd..670e12d09 100644
--- a/ruoyi-admin/src/main/resources/application-druid.yml
+++ b/ruoyi-admin/src/main/resources/application-druid.yml
@@ -2,7 +2,7 @@
db:
# mysql, oracle, sqlserver
type: mysql
- name: framework
+ name: framework_jpa
username: root
password: root
# 数据源配置
@@ -13,7 +13,7 @@ spring:
druid:
# 主库数据源
master:
- url: jdbc:mysql://localhost:3306/${db.name}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+ url: jdbc:mysql://localhost:3306/${db.name}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
username: ${db.username}
password: ${db.password}
# 从库数据源
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index 93486cf4c..4e8f8e60e 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -27,14 +27,6 @@ server:
max-threads: 800
# Tomcat启动初始化的线程数,默认值25
min-spare-threads: 30
-
-# 日志配置
-logging:
- level:
- root: warn
- com.ruoyi: debug
- com.ruoyi.quartz.mapper: warn
- com.ruoyi.system.mapper: warn
# 用户配置
user:
@@ -86,22 +78,6 @@ spring:
jcache:
provider: org.ehcache.jsr107.EhcacheCachingProvider
-# MyBatis
-mybatis:
- # 搜索指定包别名
- typeAliasesPackage: com.ruoyi.**.domain
- # 配置mapper的扫描,找到所有的mapper.xml映射文件
- mapperLocations: classpath*:mapper/**/*Mapper.xml
- # 加载全局的配置文件
- configLocation: classpath:mybatis/mybatis-config.xml
-
-# PageHelper分页插件
-pagehelper:
- helperDialect: mysql
- reasonable: true
- supportMethodsArguments: true
- params: count=countSql
-
# Shiro
shiro:
user:
diff --git a/ruoyi-admin/src/main/resources/banner.txt b/ruoyi-admin/src/main/resources/banner.txt
index 94662592f..fee1ce3b5 100644
--- a/ruoyi-admin/src/main/resources/banner.txt
+++ b/ruoyi-admin/src/main/resources/banner.txt
@@ -1,24 +1,2 @@
-Application Version: ${ruoyi.version}
-Spring Boot Version: ${spring-boot.version}
-////////////////////////////////////////////////////////////////////
-// _ooOoo_ //
-// o8888888o //
-// 88" . "88 //
-// (| ^_^ |) //
-// O\ = /O //
-// ____/`---'\____ //
-// .' \\| |// `. //
-// / \\||| : |||// \ //
-// / _||||| -:- |||||- \ //
-// | | \\\ - /// | | //
-// | \_| ''\---/'' | | //
-// \ .-\__ `-` ___/-. / //
-// ___`. .' /--.--\ `. . ___ //
-// ."" '< `.___\_<|>_/___.' >'"". //
-// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
-// \ \ `-. \_ __\ /__ _/ .-` / / //
-// ========`-.____`-.___\_____/___.-`____.-'======== //
-// `=---=' //
-// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
-// 佛祖保佑 永不宕机 永无BUG //
-////////////////////////////////////////////////////////////////////
\ No newline at end of file
+Application Version: ${ruoyi.version}
+Spring Boot Version: ${spring-boot.version}
\ No newline at end of file
diff --git a/ruoyi-admin/src/main/resources/db/migration/mysql/v001__init_sys_tables.sql b/ruoyi-admin/src/main/resources/db/migration/mysql/v001__init_sys_tables.sql
index c6b0b3865..fa4a87427 100644
--- a/ruoyi-admin/src/main/resources/db/migration/mysql/v001__init_sys_tables.sql
+++ b/ruoyi-admin/src/main/resources/db/migration/mysql/v001__init_sys_tables.sql
@@ -3,11 +3,11 @@
-- ----------------------------
drop table if exists sys_dept;
create table sys_dept (
- dept_id bigint(20) not null auto_increment comment '部门id',
- parent_id bigint(20) default 0 comment '父部门id',
+ dept_id bigint not null auto_increment comment '部门id',
+ parent_id bigint default 0 comment '父部门id',
ancestors varchar(50) default '' comment '祖级列表',
dept_name varchar(30) default '' comment '部门名称',
- order_num int(4) default 0 comment '显示顺序',
+ order_num int default 0 comment '显示顺序',
leader varchar(20) default null comment '负责人',
phone varchar(11) default null comment '联系电话',
email varchar(50) default null comment '邮箱',
@@ -40,8 +40,8 @@ insert into sys_dept values(109, 102, '0,100,102', '财务部门', 2, '若
-- ----------------------------
drop table if exists sys_user;
create table sys_user (
- user_id bigint(20) not null auto_increment comment '用户ID',
- dept_id bigint(20) default null comment '部门ID',
+ user_id bigint not null auto_increment comment '用户ID',
+ dept_id bigint default null comment '部门ID',
login_name varchar(30) not null comment '登录账号',
user_name varchar(30) default '' comment '用户昵称',
user_type varchar(2) default '00' comment '用户类型(00系统用户 01注册用户)',
@@ -76,10 +76,10 @@ insert into sys_user values(2, 105, 'ry', '若依', '00', 'ry@qq.com', '156
drop table if exists sys_post;
create table sys_post
(
- post_id bigint(20) not null auto_increment comment '岗位ID',
+ post_id bigint not null auto_increment comment '岗位ID',
post_code varchar(64) not null comment '岗位编码',
post_name varchar(50) not null comment '岗位名称',
- post_sort int(4) not null comment '显示顺序',
+ post_sort int not null comment '显示顺序',
status char(1) not null comment '状态(0正常 1停用)',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
@@ -103,10 +103,10 @@ insert into sys_post values(4, 'user', '普通员工', 4, '0', 'admin', '2018-0
-- ----------------------------
drop table if exists sys_role;
create table sys_role (
- role_id bigint(20) not null auto_increment comment '角色ID',
+ role_id bigint not null auto_increment comment '角色ID',
role_name varchar(30) not null comment '角色名称',
role_key varchar(100) not null comment '角色权限字符串',
- role_sort int(4) not null comment '显示顺序',
+ role_sort int not null comment '显示顺序',
data_scope char(1) default '1' comment '数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)',
status char(1) not null comment '角色状态(0正常 1停用)',
del_flag char(1) default '0' comment '删除标志(0代表存在 2代表删除)',
@@ -130,10 +130,10 @@ insert into sys_role values('2', '普通角色', 'common', 2, 2, '0', '0', 'ad
-- ----------------------------
drop table if exists sys_menu;
create table sys_menu (
- menu_id bigint(20) not null auto_increment comment '菜单ID',
+ menu_id bigint not null auto_increment comment '菜单ID',
menu_name varchar(50) not null comment '菜单名称',
- parent_id bigint(20) default 0 comment '父菜单ID',
- order_num int(4) default 0 comment '显示顺序',
+ parent_id bigint default 0 comment '父菜单ID',
+ order_num int default 0 comment '显示顺序',
url varchar(200) default '#' comment '请求地址',
target varchar(20) default '' comment '打开方式(menuItem页签 menuBlank新窗口)',
menu_type char(1) default '' comment '菜单类型(M目录 C菜单 F按钮)',
@@ -258,8 +258,8 @@ insert into sys_menu values('1061', '生成代码', '114', '5', '#', '', 'F', '
-- ----------------------------
drop table if exists sys_user_role;
create table sys_user_role (
- user_id bigint(20) not null comment '用户ID',
- role_id bigint(20) not null comment '角色ID',
+ user_id bigint not null comment '用户ID',
+ role_id bigint not null comment '角色ID',
primary key(user_id, role_id)
) engine=innodb comment = '用户和角色关联表';
@@ -275,8 +275,8 @@ insert into sys_user_role values ('2', '2');
-- ----------------------------
drop table if exists sys_role_menu;
create table sys_role_menu (
- role_id bigint(20) not null comment '角色ID',
- menu_id bigint(20) not null comment '菜单ID',
+ role_id bigint not null comment '角色ID',
+ menu_id bigint not null comment '菜单ID',
primary key(role_id, menu_id)
) engine=innodb comment = '角色和菜单关联表';
@@ -373,8 +373,8 @@ insert into sys_role_menu values ('2', '1061');
-- ----------------------------
drop table if exists sys_role_dept;
create table sys_role_dept (
- role_id bigint(20) not null comment '角色ID',
- dept_id bigint(20) not null comment '部门ID',
+ role_id bigint not null comment '角色ID',
+ dept_id bigint not null comment '部门ID',
primary key(role_id, dept_id)
) engine=innodb comment = '角色和部门关联表';
@@ -391,8 +391,8 @@ insert into sys_role_dept values ('2', '105');
drop table if exists sys_user_post;
create table sys_user_post
(
- user_id bigint(20) not null comment '用户ID',
- post_id bigint(20) not null comment '岗位ID',
+ user_id bigint not null comment '用户ID',
+ post_id bigint not null comment '岗位ID',
primary key (user_id, post_id)
) engine=innodb comment = '用户与岗位关联表';
@@ -408,12 +408,12 @@ insert into sys_user_post values ('2', '2');
-- ----------------------------
drop table if exists sys_oper_log;
create table sys_oper_log (
- oper_id bigint(20) not null auto_increment comment '日志主键',
+ oper_id bigint not null auto_increment comment '日志主键',
title varchar(50) default '' comment '模块标题',
- business_type int(2) default 0 comment '业务类型(0其它 1新增 2修改 3删除)',
+ business_type int default 0 comment '业务类型(0其它 1新增 2修改 3删除)',
method varchar(100) default '' comment '方法名称',
request_method varchar(10) default '' comment '请求方式',
- operator_type int(1) default 0 comment '操作类别(0其它 1后台用户 2手机端用户)',
+ operator_type int default 0 comment '操作类别(0其它 1后台用户 2手机端用户)',
oper_name varchar(50) default '' comment '操作人员',
dept_name varchar(50) default '' comment '部门名称',
oper_url varchar(255) default '' comment '请求URL',
@@ -421,7 +421,7 @@ create table sys_oper_log (
oper_location varchar(255) default '' comment '操作地点',
oper_param varchar(2000) default '' comment '请求参数',
json_result varchar(2000) default '' comment '返回参数',
- status int(1) default 0 comment '操作状态(0正常 1异常)',
+ status int default 0 comment '操作状态(0正常 1异常)',
error_msg varchar(2000) default '' comment '错误消息',
oper_time datetime comment '操作时间',
primary key (oper_id)
@@ -434,7 +434,7 @@ create table sys_oper_log (
drop table if exists sys_dict_type;
create table sys_dict_type
(
- dict_id bigint(20) not null auto_increment comment '字典主键',
+ dict_id bigint not null auto_increment comment '字典主键',
dict_name varchar(100) default '' comment '字典名称',
dict_type varchar(100) default '' comment '字典类型',
status char(1) default '0' comment '状态(0正常 1停用)',
@@ -465,8 +465,8 @@ insert into sys_dict_type values(10, '系统状态', 'sys_common_status', '0',
drop table if exists sys_dict_data;
create table sys_dict_data
(
- dict_code bigint(20) not null auto_increment comment '字典编码',
- dict_sort int(4) default 0 comment '字典排序',
+ dict_code bigint not null auto_increment comment '字典编码',
+ dict_sort int default 0 comment '字典排序',
dict_label varchar(100) default '' comment '字典标签',
dict_value varchar(100) default '' comment '字典键值',
dict_type varchar(100) default '' comment '字典类型',
@@ -518,7 +518,7 @@ insert into sys_dict_data values(29, 2, '失败', '1', 'sys_common_st
-- ----------------------------
drop table if exists sys_config;
create table sys_config (
- config_id int(5) not null auto_increment comment '参数主键',
+ config_id int not null auto_increment comment '参数主键',
config_name varchar(100) default '' comment '参数名称',
config_key varchar(100) default '' comment '参数键名',
config_value varchar(500) default '' comment '参数键值',
@@ -545,7 +545,7 @@ insert into sys_config values(7, '主框架页-是否开启页脚', 'sys
-- ----------------------------
drop table if exists sys_logininfor;
create table sys_logininfor (
- info_id bigint(20) not null auto_increment comment '访问ID',
+ info_id bigint not null auto_increment comment '访问ID',
login_name varchar(50) default '' comment '登录账号',
ipaddr varchar(50) default '' comment '登录IP地址',
login_location varchar(255) default '' comment '登录地点',
@@ -573,7 +573,7 @@ create table sys_user_online (
status varchar(10) default '' comment '在线状态on_line在线off_line离线',
start_timestamp datetime comment 'session创建时间',
last_access_time datetime comment 'session最后访问时间',
- expire_time int(5) default 0 comment '超时时间,单位为分钟',
+ expire_time int default 0 comment '超时时间,单位为分钟',
primary key (sessionId)
) engine=innodb comment = '在线用户记录';
@@ -583,7 +583,7 @@ create table sys_user_online (
-- ----------------------------
drop table if exists sys_job;
create table sys_job (
- job_id bigint(20) not null auto_increment comment '任务ID',
+ job_id bigint not null auto_increment comment '任务ID',
job_name varchar(64) default '' comment '任务名称',
job_group varchar(64) default 'DEFAULT' comment '任务组名',
invoke_target varchar(500) not null comment '调用目标字符串',
@@ -609,7 +609,7 @@ insert into sys_job values(3, '系统默认(多参)', 'DEFAULT', 'ryTask.ryM
-- ----------------------------
drop table if exists sys_job_log;
create table sys_job_log (
- job_log_id bigint(20) not null auto_increment comment '任务日志ID',
+ job_log_id bigint not null auto_increment comment '任务日志ID',
job_name varchar(64) not null comment '任务名称',
job_group varchar(64) not null comment '任务组名',
invoke_target varchar(500) not null comment '调用目标字符串',
@@ -626,7 +626,7 @@ create table sys_job_log (
-- ----------------------------
drop table if exists sys_notice;
create table sys_notice (
- notice_id int(4) not null auto_increment comment '公告ID',
+ notice_id int not null auto_increment comment '公告ID',
notice_title varchar(50) not null comment '公告标题',
notice_type char(1) not null comment '公告类型(1通知 2公告)',
notice_content varchar(2000) default null comment '公告内容',
@@ -651,7 +651,7 @@ insert into sys_notice values('2', '维护通知:2018-07-01 若依系统凌晨
-- ----------------------------
drop table if exists gen_table;
create table gen_table (
- table_id bigint(20) not null auto_increment comment '编号',
+ table_id bigint not null auto_increment comment '编号',
table_name varchar(200) default '' comment '表名称',
table_comment varchar(500) default '' comment '表描述',
sub_table_name varchar(64) default null comment '关联子表的表名',
@@ -680,7 +680,7 @@ create table gen_table (
-- ----------------------------
drop table if exists gen_table_column;
create table gen_table_column (
- column_id bigint(20) not null auto_increment comment '编号',
+ column_id bigint not null auto_increment comment '编号',
table_id varchar(64) comment '归属表编号',
column_name varchar(200) comment '列名称',
column_comment varchar(500) comment '列描述',
diff --git a/ruoyi-admin/src/main/resources/db/migration/mysql/v002__init_quartz_tables.sql b/ruoyi-admin/src/main/resources/db/migration/mysql/v002__init_quartz_tables.sql
index 55665e2b9..ff74c608c 100644
--- a/ruoyi-admin/src/main/resources/db/migration/mysql/v002__init_quartz_tables.sql
+++ b/ruoyi-admin/src/main/resources/db/migration/mysql/v002__init_quartz_tables.sql
@@ -27,15 +27,15 @@ create table QRTZ_TRIGGERS (
job_name varchar(200) not null,
job_group varchar(200) not null,
description varchar(250) null,
- next_fire_time bigint(13) null,
- prev_fire_time bigint(13) null,
+ next_fire_time bigint null,
+ prev_fire_time bigint null,
priority integer null,
trigger_state varchar(16) not null,
trigger_type varchar(8) not null,
- start_time bigint(13) not null,
- end_time bigint(13) null,
+ start_time bigint not null,
+ end_time bigint null,
calendar_name varchar(200) null,
- misfire_instr smallint(2) null,
+ misfire_instr smallint null,
job_data blob null,
primary key (sched_name,trigger_name,trigger_group),
foreign key (sched_name,job_name,job_group) references QRTZ_JOB_DETAILS(sched_name,job_name,job_group)
@@ -49,9 +49,9 @@ create table QRTZ_SIMPLE_TRIGGERS (
sched_name varchar(120) not null,
trigger_name varchar(200) not null,
trigger_group varchar(200) not null,
- repeat_count bigint(7) not null,
- repeat_interval bigint(12) not null,
- times_triggered bigint(10) not null,
+ repeat_count bigint not null,
+ repeat_interval bigint not null,
+ times_triggered bigint not null,
primary key (sched_name,trigger_name,trigger_group),
foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group)
) engine=innodb;
@@ -114,8 +114,8 @@ create table QRTZ_FIRED_TRIGGERS (
trigger_name varchar(200) not null,
trigger_group varchar(200) not null,
instance_name varchar(200) not null,
- fired_time bigint(13) not null,
- sched_time bigint(13) not null,
+ fired_time bigint not null,
+ sched_time bigint not null,
priority integer not null,
state varchar(16) not null,
job_name varchar(200) null,
@@ -132,8 +132,8 @@ drop table if exists QRTZ_SCHEDULER_STATE;
create table QRTZ_SCHEDULER_STATE (
sched_name varchar(120) not null,
instance_name varchar(200) not null,
- last_checkin_time bigint(13) not null,
- checkin_interval bigint(13) not null,
+ last_checkin_time bigint not null,
+ checkin_interval bigint not null,
primary key (sched_name,instance_name)
) engine=innodb;
diff --git a/ruoyi-admin/src/main/resources/logback-spring.xml b/ruoyi-admin/src/main/resources/logback-spring.xml
new file mode 100644
index 000000000..afdccd024
--- /dev/null
+++ b/ruoyi-admin/src/main/resources/logback-spring.xml
@@ -0,0 +1,35 @@
+
+
+
+
+ true
+
+
+ %black(%d) %highlight(%-5level) [%boldYellow(%t)] %boldGreen(%C{1.}:%method:%line) %msg%n%throwable
+
+
+
+
+
+
+ D:/dustmonitor/logs/%d{yyyy-MM-dd}-%i.log
+ 10MB
+
+ 60
+
+
+ %d{HH:mm:ss} [%thread] %-5level %C{1.}:%method:%line - %msg%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ruoyi-admin/src/main/resources/logback.xml b/ruoyi-admin/src/main/resources/logback.xml
deleted file mode 100644
index d69a57207..000000000
--- a/ruoyi-admin/src/main/resources/logback.xml
+++ /dev/null
@@ -1,93 +0,0 @@
-
-
-
-
-
-
-
-
-
-
- ${log.pattern}
-
-
-
-
-
- ${log.path}/sys-info.log
-
-
-
- ${log.path}/sys-info.%d{yyyy-MM-dd}.log
-
- 60
-
-
- ${log.pattern}
-
-
-
- INFO
-
- ACCEPT
-
- DENY
-
-
-
-
- ${log.path}/sys-error.log
-
-
-
- ${log.path}/sys-error.%d{yyyy-MM-dd}.log
-
- 60
-
-
- ${log.pattern}
-
-
-
- ERROR
-
- ACCEPT
-
- DENY
-
-
-
-
-
- ${log.path}/sys-user.log
-
-
- ${log.path}/sys-user.%d{yyyy-MM-dd}.log
-
- 60
-
-
- ${log.pattern}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/ruoyi-admin/src/main/resources/mybatis/mybatis-config.xml b/ruoyi-admin/src/main/resources/mybatis/mybatis-config.xml
deleted file mode 100644
index 2b1811312..000000000
--- a/ruoyi-admin/src/main/resources/mybatis/mybatis-config.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml
index 31f7a433c..d4dbb815f 100644
--- a/ruoyi-common/pom.xml
+++ b/ruoyi-common/pom.xml
@@ -41,12 +41,6 @@
shiro-ehcache
-
-
- com.github.pagehelper
- pagehelper-spring-boot-starter
-
-
javax.validation
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/base/BaseRepository.java b/ruoyi-common/src/main/java/com/ruoyi/common/base/BaseRepository.java
index 6bce9515b..895016844 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/base/BaseRepository.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/base/BaseRepository.java
@@ -1,9 +1,11 @@
package com.ruoyi.common.base;
+import com.ruoyi.common.core.text.Convert;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.NoRepositoryBean;
+import org.springframework.transaction.annotation.Transactional;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
@@ -12,4 +14,5 @@ import javax.persistence.criteria.Predicate;
public interface BaseRepository extends JpaRepository,
JpaSpecificationExecutor,
QuerydslPredicateExecutor {
+
}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/base/BaseService.java b/ruoyi-common/src/main/java/com/ruoyi/common/base/BaseService.java
index 59c0a5ed4..1d9c75f30 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/base/BaseService.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/base/BaseService.java
@@ -1,8 +1,14 @@
package com.ruoyi.common.base;
import com.querydsl.core.types.dsl.*;
+import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.querydsl.ExpressionUtils;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
public class BaseService {
protected BooleanExpression buildLike(StringPath path, String value){
@@ -32,4 +38,25 @@ public class BaseService {
protected BooleanExpression notStartWith(StringPath path, String value){
return ExpressionUtils.notStartWith(path, value);
}
+
+ public static Collection toLongIterable(String str){
+ return Arrays.stream(Convert.toStrArray(str))
+ .map(Long::parseLong)
+ .collect(Collectors.toSet());
+ }
+
+ public static Collection toIntegerIterable(String str){
+ return Arrays.stream(Convert.toStrArray(str))
+ .map(Integer::parseInt)
+ .collect(Collectors.toSet());
+ }
+
+ public static Collection toStringIterable(String str){
+ return Arrays.stream(Convert.toStrArray(str))
+ .collect(Collectors.toSet());
+ }
+
+ protected Collection toEntityIterable(Collection ids, Function function){
+ return Convert.toEntityIterable(ids, function);
+ }
}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java
index f9dce907c..e552583e5 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/text/Convert.java
@@ -1,13 +1,17 @@
package com.ruoyi.common.core.text;
+import com.ruoyi.common.utils.StringUtils;
+
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.text.NumberFormat;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Set;
-
-import com.ruoyi.common.utils.StringUtils;
+import java.util.function.Function;
+import java.util.stream.Collectors;
/**
* 类型转换器
@@ -314,6 +318,34 @@ public class Convert {
return toStrArray(",", str);
}
+ public static Collection toLongIterable(String str){
+ return toIdIterable(str, Long::parseLong);
+ }
+
+ public static Collection toIntegerIterable(String str){
+ return toIdIterable(str, Integer::parseInt);
+ }
+
+ public static Collection toStringIterable(String str){
+ return toIdIterable(str, s -> s);
+ }
+
+ public static Collection toIdIterable(String str, Function function){
+ return Arrays.stream(toStrArray(str))
+ .map(function)
+ .collect(Collectors.toSet());
+ }
+
+ public static Collection toIdIterable(String ids, Function toIDFunction, Function idToEntityFunction){
+ return toEntityIterable(toIdIterable(ids, toIDFunction), idToEntityFunction);
+ }
+
+ public static Collection toEntityIterable(Collection ids, Function function){
+ return ids.stream()
+ .map(function)
+ .collect(Collectors.toSet());
+ }
+
/**
* 转换为String数组
*
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
index fff3cdd33..7412b9047 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
@@ -1,6 +1,14 @@
package com.ruoyi.framework.aspectj;
-import java.lang.reflect.Method;
+import com.querydsl.core.types.ExpressionUtils;
+import com.querydsl.core.types.Predicate;
+import com.ruoyi.common.annotation.DataScope;
+import com.ruoyi.common.core.domain.BaseEntity;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.framework.util.ShiroUtils;
+import com.ruoyi.system.domain.SysRole;
+import com.ruoyi.system.domain.SysUser;
+import com.ruoyi.system.service.ISysUserService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.After;
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java
index 4b053de30..55f0d6837 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java
@@ -1,6 +1,6 @@
package com.ruoyi.framework.aspectj;
-import java.lang.reflect.Method;
+import java.util.Objects;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
@@ -9,6 +9,7 @@ import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import com.ruoyi.common.annotation.DataSource;
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/shiro/service/SysRegisterService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/shiro/service/SysRegisterService.java
index 97dfd1022..868a31d30 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/shiro/service/SysRegisterService.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/shiro/service/SysRegisterService.java
@@ -1,80 +1,80 @@
-package com.ruoyi.framework.shiro.service;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import org.springframework.util.StringUtils;
-import com.ruoyi.common.constant.Constants;
-import com.ruoyi.common.constant.ShiroConstants;
-import com.ruoyi.common.constant.UserConstants;
-import com.ruoyi.common.utils.MessageUtils;
-import com.ruoyi.common.utils.ServletUtils;
-import com.ruoyi.framework.manager.AsyncManager;
-import com.ruoyi.framework.manager.factory.AsyncFactory;
-import com.ruoyi.framework.util.ShiroUtils;
-import com.ruoyi.system.domain.SysUser;
-import com.ruoyi.system.service.ISysUserService;
-
-/**
- * 注册校验方法
- *
- * @author ruoyi
- */
-@Component
-public class SysRegisterService
-{
- @Autowired
- private ISysUserService userService;
-
- @Autowired
- private SysPasswordService passwordService;
-
- /**
- * 注册
- */
- public String register(SysUser user)
- {
- String msg = "", username = user.getLoginName(), password = user.getPassword();
-
- if (!StringUtils.isEmpty(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA)))
- {
- msg = "验证码错误";
- }
- else if (StringUtils.isEmpty(username))
- {
- msg = "用户名不能为空";
- }
- else if (StringUtils.isEmpty(password))
- {
- msg = "用户密码不能为空";
- }
- else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
- || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
- {
- msg = "密码长度必须在5到20个字符之间";
- }
- else if (username.length() < UserConstants.USERNAME_MIN_LENGTH
- || username.length() > UserConstants.USERNAME_MAX_LENGTH)
- {
- msg = "账户长度必须在2到20个字符之间";
- }
- else if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(username)))
- {
- msg = "保存用户'" + username + "'失败,注册账号已存在";
- }
- else
- {
- user.setSalt(ShiroUtils.randomSalt());
- user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
- boolean regFlag = userService.registerUser(user);
- if (!regFlag)
- {
- msg = "注册失败,请联系系统管理人员";
- }
- else
- {
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.register.success")));
- }
- }
- return msg;
- }
-}
+package com.ruoyi.framework.shiro.service;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.constant.ShiroConstants;
+import com.ruoyi.common.constant.UserConstants;
+import com.ruoyi.common.utils.MessageUtils;
+import com.ruoyi.common.utils.ServletUtils;
+import com.ruoyi.framework.manager.AsyncManager;
+import com.ruoyi.framework.manager.factory.AsyncFactory;
+import com.ruoyi.framework.util.ShiroUtils;
+import com.ruoyi.system.domain.SysUser;
+import com.ruoyi.system.service.ISysUserService;
+
+/**
+ * 注册校验方法
+ *
+ * @author ruoyi
+ */
+@Component
+public class SysRegisterService
+{
+ @Autowired
+ private ISysUserService userService;
+
+ @Autowired
+ private SysPasswordService passwordService;
+
+ /**
+ * 注册
+ */
+ public String register(SysUser user)
+ {
+ String msg = "", username = user.getLoginName(), password = user.getPassword();
+
+ if (!StringUtils.isEmpty(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA)))
+ {
+ msg = "验证码错误";
+ }
+ else if (StringUtils.isEmpty(username))
+ {
+ msg = "用户名不能为空";
+ }
+ else if (StringUtils.isEmpty(password))
+ {
+ msg = "用户密码不能为空";
+ }
+ else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
+ || password.length() > UserConstants.PASSWORD_MAX_LENGTH)
+ {
+ msg = "密码长度必须在5到20个字符之间";
+ }
+ else if (username.length() < UserConstants.USERNAME_MIN_LENGTH
+ || username.length() > UserConstants.USERNAME_MAX_LENGTH)
+ {
+ msg = "账户长度必须在2到20个字符之间";
+ }
+ else if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(username)))
+ {
+ msg = "保存用户'" + username + "'失败,注册账号已存在";
+ }
+ else
+ {
+ user.setSalt(ShiroUtils.randomSalt());
+ user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
+ user = userService.registerUser(user);
+ if (user == null)
+ {
+ msg = "注册失败,请联系系统管理人员";
+ }
+ else
+ {
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.register.success")));
+ }
+ }
+ return msg;
+ }
+}
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java
index e60c27a1d..7656e97ae 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java
@@ -1,45 +1,37 @@
package com.ruoyi.generator.controller;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import javax.servlet.http.HttpServletResponse;
+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.common.utils.security.PermissionUtils;
+import com.ruoyi.generator.domain.GenTable;
+import com.ruoyi.generator.domain.GenTableColumn;
+import com.ruoyi.generator.service.IGenTableColumnService;
+import com.ruoyi.generator.service.IGenTableService;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
-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.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import com.alibaba.fastjson.JSON;
-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.domain.CxSelect;
-import com.ruoyi.common.core.page.TableDataInfo;
-import com.ruoyi.common.core.text.Convert;
-import com.ruoyi.common.enums.BusinessType;
-import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.security.PermissionUtils;
-import com.ruoyi.generator.domain.GenTable;
-import com.ruoyi.generator.domain.GenTableColumn;
-import com.ruoyi.generator.service.IGenTableColumnService;
-import com.ruoyi.generator.service.IGenTableService;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
/**
* 代码生成 操作处理
- *
+ *
* @author ruoyi
*/
@Controller
@RequestMapping("/tool/gen")
-public class GenController extends BaseController
-{
+public class GenController extends BaseController {
private String prefix = "tool/gen";
@Autowired
@@ -50,8 +42,7 @@ public class GenController extends BaseController
@RequiresPermissions("tool:gen:view")
@GetMapping()
- public String gen()
- {
+ public String gen() {
return prefix + "/gen";
}
@@ -61,11 +52,8 @@ public class GenController extends BaseController
@RequiresPermissions("tool:gen:list")
@PostMapping("/list")
@ResponseBody
- public TableDataInfo genList(GenTable genTable)
- {
- startPage();
- List list = genTableService.selectGenTableList(genTable);
- return getDataTable(list);
+ public TableDataInfo genList(GenTable genTable) {
+ return getDataTable(genTableService.selectGenTableList(genTable, getPageRequest()));
}
/**
@@ -74,11 +62,8 @@ public class GenController extends BaseController
@RequiresPermissions("tool:gen:list")
@PostMapping("/db/list")
@ResponseBody
- public TableDataInfo dataList(GenTable genTable)
- {
- startPage();
- List list = genTableService.selectDbTableList(genTable);
- return getDataTable(list);
+ public TableDataInfo dataList(GenTable genTable) {
+ return getDataTable(genTableService.selectDbTableList(genTable, getPageRequest()));
}
/**
@@ -87,10 +72,9 @@ public class GenController extends BaseController
@RequiresPermissions("tool:gen:list")
@PostMapping("/column/list")
@ResponseBody
- public TableDataInfo columnList(GenTableColumn genTableColumn)
- {
+ public TableDataInfo columnList(GenTable genTable) {
TableDataInfo dataInfo = new TableDataInfo();
- List list = genTableColumnService.selectGenTableColumnListByTableId(genTableColumn);
+ List list = genTableService.selectGenTableById(genTable.getTableId()).getColumns();
dataInfo.setRows(list);
dataInfo.setTotal(list.size());
return dataInfo;
@@ -101,8 +85,7 @@ public class GenController extends BaseController
*/
@RequiresPermissions("tool:gen:list")
@GetMapping("/importTable")
- public String importTable()
- {
+ public String importTable() {
return prefix + "/importTable";
}
@@ -113,8 +96,7 @@ public class GenController extends BaseController
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
@PostMapping("/importTable")
@ResponseBody
- public AjaxResult importTableSave(String tables)
- {
+ public AjaxResult importTableSave(String tables) {
String[] tableNames = Convert.toStrArray(tables);
// 查询表信息
List tableList = genTableService.selectDbTableListByNames(tableNames);
@@ -127,27 +109,9 @@ public class GenController extends BaseController
* 修改代码生成业务
*/
@GetMapping("/edit/{tableId}")
- public String edit(@PathVariable("tableId") Long tableId, ModelMap mmap)
- {
+ public String edit(@PathVariable("tableId") Long tableId, ModelMap mmap) {
GenTable table = genTableService.selectGenTableById(tableId);
- List genTables = genTableService.selectGenTableAll();
- List cxSelect = new ArrayList();
- for (GenTable genTable : genTables)
- {
- if (!StringUtils.equals(table.getTableName(), genTable.getTableName()))
- {
- CxSelect cxTable = new CxSelect(genTable.getTableName(), genTable.getTableName() + ':' + genTable.getTableComment());
- List cxColumns = new ArrayList();
- for (GenTableColumn tableColumn : genTable.getColumns())
- {
- cxColumns.add(new CxSelect(tableColumn.getColumnName(), tableColumn.getColumnName() + ':' + tableColumn.getColumnComment()));
- }
- cxTable.setS(cxColumns);
- cxSelect.add(cxTable);
- }
- }
mmap.put("table", table);
- mmap.put("data", JSON.toJSON(cxSelect));
return prefix + "/edit";
}
@@ -158,60 +122,12 @@ public class GenController extends BaseController
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
- public AjaxResult editSave(@Validated GenTable genTable)
- {
+ public AjaxResult editSave(@Validated GenTable genTable) {
genTableService.validateEdit(genTable);
genTableService.updateGenTable(genTable);
return AjaxResult.success();
}
- @RequiresPermissions("tool:gen:remove")
- @Log(title = "代码生成", businessType = BusinessType.DELETE)
- @PostMapping("/remove")
- @ResponseBody
- public AjaxResult remove(String ids)
- {
- genTableService.deleteGenTableByIds(ids);
- return AjaxResult.success();
- }
-
- /**
- * 预览代码
- */
- @RequiresPermissions("tool:gen:preview")
- @GetMapping("/preview/{tableId}")
- @ResponseBody
- public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException
- {
- Map dataMap = genTableService.previewCode(tableId);
- return AjaxResult.success(dataMap);
- }
-
- /**
- * 生成代码(下载方式)
- */
- @RequiresPermissions("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);
- }
-
- /**
- * 生成代码(自定义路径)
- */
- @RequiresPermissions("tool:gen:code")
- @Log(title = "代码生成", businessType = BusinessType.GENCODE)
- @GetMapping("/genCode/{tableName}")
- @ResponseBody
- public AjaxResult genCode(@PathVariable("tableName") String tableName)
- {
- genTableService.generatorCode(tableName);
- return AjaxResult.success();
- }
-
/**
* 同步数据库
*/
@@ -225,6 +141,37 @@ public class GenController extends BaseController
return AjaxResult.success();
}
+ @RequiresPermissions("tool:gen:remove")
+ @Log(title = "代码生成", businessType = BusinessType.DELETE)
+ @PostMapping("/remove")
+ @ResponseBody
+ public AjaxResult remove(String ids) {
+ genTableService.deleteGenTableByIds(ids);
+ return AjaxResult.success();
+ }
+
+ /**
+ * 预览代码
+ */
+ @RequiresPermissions("tool:gen:preview")
+ @GetMapping("/preview/{tableId}")
+ @ResponseBody
+ public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException {
+ Map dataMap = genTableService.previewCode(tableId);
+ return AjaxResult.success(dataMap);
+ }
+
+ /**
+ * 生成代码
+ */
+ @RequiresPermissions("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);
+ }
+
/**
* 批量生成代码
*/
@@ -232,18 +179,16 @@ public class GenController extends BaseController
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/batchGenCode")
@ResponseBody
- public void batchGenCode(HttpServletResponse response, String tables) throws IOException
- {
+ public void batchGenCode(HttpServletResponse response, String tables) throws IOException {
String[] tableNames = Convert.toStrArray(tables);
- byte[] data = genTableService.downloadCode(tableNames);
+ byte[] data = genTableService.generatorCode(tableNames);
genCode(response, data);
}
/**
* 生成zip文件
*/
- private void genCode(HttpServletResponse response, byte[] data) throws IOException
- {
+ private void genCode(HttpServletResponse response, byte[] data) throws IOException {
response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
response.addHeader("Content-Length", "" + data.length);
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java
index 269779cf2..087fe1127 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java
@@ -1,372 +1,278 @@
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;
+import javax.persistence.*;
+import javax.validation.Valid;
+import javax.validation.constraints.NotBlank;
+import java.util.List;
+
/**
* 业务表 gen_table
- *
+ *
* @author ruoyi
*/
-public class GenTable extends BaseEntity
-{
+@Entity
+@Table(name = "gen_table")
+public class GenTable extends BaseEntity {
private static final long serialVersionUID = 1L;
- /** 编号 */
+ /**
+ * 编号
+ */
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long tableId;
- /** 表名称 */
+ /**
+ * 表名称
+ */
@NotBlank(message = "表名称不能为空")
private String tableName;
- /** 表描述 */
- @NotBlank(message = "表描述不能为空")
+ /**
+ * 表描述
+ */
private String tableComment;
- /** 关联父表的表名 */
- private String subTableName;
-
- /** 本表关联父表的外键名 */
- private String subTableFkName;
-
- /** 实体类名称(首字母大写) */
+ /**
+ * 实体类名称(首字母大写)
+ */
@NotBlank(message = "实体类名称不能为空")
private String className;
- /** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */
+ /**
+ * 使用的模板(crud单表操作 tree树表操作)
+ */
private String tplCategory;
- /** 生成包路径 */
+ /**
+ * 生成包路径
+ */
@NotBlank(message = "生成包路径不能为空")
private String packageName;
- /** 生成模块名 */
+ /**
+ * 生成模块名
+ */
@NotBlank(message = "生成模块名不能为空")
private String moduleName;
- /** 生成业务名 */
+ /**
+ * 生成业务名
+ */
@NotBlank(message = "生成业务名不能为空")
private String businessName;
- /** 生成功能名 */
- @NotBlank(message = "生成功能名不能为空")
+ /**
+ * 生成功能名
+ */
private String functionName;
- /** 生成作者 */
+ /**
+ * 生成作者
+ */
@NotBlank(message = "作者不能为空")
private String functionAuthor;
- /** 生成代码方式(0zip压缩包 1自定义路径) */
- private String genType;
-
- /** 生成路径(不填默认项目路径) */
- private String genPath;
-
- /** 主键信息 */
+ /**
+ * 主键信息
+ */
+ @Transient
private GenTableColumn pkColumn;
- /** 子表信息 */
- private GenTable subTable;
-
- /** 表列信息 */
+ /**
+ * 表列信息
+ */
@Valid
+ @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
+ @JoinTable(name = "gen_table_columns",
+ joinColumns = @JoinColumn(name = "genTableTableId", referencedColumnName = "tableId"),
+ inverseJoinColumns = @JoinColumn(name = "columnsColumnId", referencedColumnName = "columnId"))
+ @org.hibernate.annotations.ForeignKey(name = "none")
private List columns;
- /** 其它生成选项 */
+ /**
+ * 其它生成选项
+ */
private String options;
- /** 树编码字段 */
+ /**
+ * 树编码字段
+ */
private String treeCode;
- /** 树父编码字段 */
+ /**
+ * 树父编码字段
+ */
private String treeParentCode;
- /** 树名称字段 */
+ /**
+ * 树名称字段
+ */
private String treeName;
- /** 上级菜单ID字段 */
- private String parentMenuId;
-
- /** 上级菜单名称字段 */
- private String parentMenuName;
-
- public Long getTableId()
- {
+ public Long getTableId() {
return tableId;
}
- public void setTableId(Long tableId)
- {
+ public void setTableId(Long tableId) {
this.tableId = tableId;
}
- public String getTableName()
- {
+ public String getTableName() {
return tableName;
}
- public void setTableName(String tableName)
- {
+ public void setTableName(String tableName) {
this.tableName = tableName;
}
- public String getTableComment()
- {
+ public String getTableComment() {
return tableComment;
}
- public void setTableComment(String tableComment)
- {
+ public void setTableComment(String tableComment) {
this.tableComment = tableComment;
}
- public String getSubTableName()
- {
- return subTableName;
- }
-
- public void setSubTableName(String subTableName)
- {
- this.subTableName = subTableName;
- }
-
- public String getSubTableFkName()
- {
- return subTableFkName;
- }
-
- public void setSubTableFkName(String subTableFkName)
- {
- this.subTableFkName = subTableFkName;
- }
-
- public String getClassName()
- {
+ public String getClassName() {
return className;
}
- public void setClassName(String className)
- {
+ public void setClassName(String className) {
this.className = className;
}
- public String getTplCategory()
- {
+ public String getTplCategory() {
return tplCategory;
}
- public void setTplCategory(String tplCategory)
- {
+ public void setTplCategory(String tplCategory) {
this.tplCategory = tplCategory;
}
- public String getPackageName()
- {
+ public String getPackageName() {
return packageName;
}
- public void setPackageName(String packageName)
- {
+ public void setPackageName(String packageName) {
this.packageName = packageName;
}
- public String getModuleName()
- {
+ public String getModuleName() {
return moduleName;
}
- public void setModuleName(String moduleName)
- {
+ public void setModuleName(String moduleName) {
this.moduleName = moduleName;
}
- public String getBusinessName()
- {
+ public String getBusinessName() {
return businessName;
}
- public void setBusinessName(String businessName)
- {
+ public void setBusinessName(String businessName) {
this.businessName = businessName;
}
- public String getFunctionName()
- {
+ public String getFunctionName() {
return functionName;
}
- public void setFunctionName(String functionName)
- {
+ public void setFunctionName(String functionName) {
this.functionName = functionName;
}
- public String getFunctionAuthor()
- {
+ public String getFunctionAuthor() {
return functionAuthor;
}
- public void setFunctionAuthor(String functionAuthor)
- {
+ public void setFunctionAuthor(String functionAuthor) {
this.functionAuthor = functionAuthor;
}
- public String getGenType()
- {
- 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()
- {
+ public GenTableColumn getPkColumn() {
return pkColumn;
}
- public void setPkColumn(GenTableColumn pkColumn)
- {
+ public void setPkColumn(GenTableColumn pkColumn) {
this.pkColumn = pkColumn;
}
- public GenTable getSubTable()
- {
- return subTable;
- }
-
- public void setSubTable(GenTable subTable)
- {
- this.subTable = subTable;
- }
-
- public List getColumns()
- {
+ public List getColumns() {
return columns;
}
- public void setColumns(List columns)
- {
+ public void setColumns(List columns) {
this.columns = columns;
}
- public String getOptions()
- {
+ public String getOptions() {
return options;
}
- public void setOptions(String options)
- {
+ public void setOptions(String options) {
this.options = options;
}
- public String getTreeCode()
- {
+ public String getTreeCode() {
return treeCode;
}
- public void setTreeCode(String treeCode)
- {
+ public void setTreeCode(String treeCode) {
this.treeCode = treeCode;
}
- public String getTreeParentCode()
- {
+ public String getTreeParentCode() {
return treeParentCode;
}
- public void setTreeParentCode(String treeParentCode)
- {
+ public void setTreeParentCode(String treeParentCode) {
this.treeParentCode = treeParentCode;
}
- public String getTreeName()
- {
+ public String getTreeName() {
return treeName;
}
- public void setTreeName(String treeName)
- {
+ public void setTreeName(String treeName) {
this.treeName = treeName;
}
- public String getParentMenuId()
- {
- 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 isSub()
- {
- return isSub(this.tplCategory);
- }
-
- public static boolean isSub(String tplCategory)
- {
- return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory);
- }
-
- public boolean isTree()
- {
+ public boolean isTree() {
return isTree(this.tplCategory);
}
- public static boolean isTree(String tplCategory)
- {
+ public static boolean isTree(String tplCategory) {
return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory);
}
- public boolean isCrud()
- {
+ public boolean isCrud() {
return isCrud(this.tplCategory);
}
- public static boolean isCrud(String tplCategory)
- {
+ public static boolean isCrud(String tplCategory) {
return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory);
}
- public boolean isSuperColumn(String javaField)
- {
+ public boolean isSuperColumn(String javaField) {
return isSuperColumn(this.tplCategory, javaField);
}
- public static boolean isSuperColumn(String tplCategory, String javaField)
- {
- if (isTree(tplCategory))
- {
- return StringUtils.equalsAnyIgnoreCase(javaField,
- ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY));
+ public static boolean isSuperColumn(String tplCategory, String javaField) {
+ if (isTree(tplCategory)) {
+ StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.TREE_ENTITY);
}
return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
}
+
+ public GenTable() {
+ }
+
+ public GenTable(Long tableId) {
+ this.tableId = tableId;
+ }
}
\ No newline at end of file
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java
index f421da864..30bdc2769 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java
@@ -1,373 +1,172 @@
package com.ruoyi.generator.domain;
-import javax.validation.constraints.NotBlank;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.utils.StringUtils;
+import lombok.Data;
+
+import javax.persistence.*;
+import javax.validation.constraints.NotBlank;
/**
* 代码生成业务字段表 gen_table_column
- *
+ *
* @author ruoyi
*/
-public class GenTableColumn extends BaseEntity
-{
+@Data
+@Entity
+@Table(name = "gen_table_column")
+public class GenTableColumn extends BaseEntity {
private static final long serialVersionUID = 1L;
- /** 编号 */
+ /**
+ * 编号
+ */
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long columnId;
- /** 归属表编号 */
- private Long tableId;
-
- /** 列名称 */
+ /**
+ * 列名称
+ */
private String columnName;
- /** 列描述 */
+ /**
+ * 列描述
+ */
private String columnComment;
- /** 列类型 */
+ /**
+ * 列类型
+ */
private String columnType;
- /** JAVA类型 */
+ /**
+ * JAVA类型
+ */
private String javaType;
- /** JAVA字段名 */
+ /**
+ * JAVA字段名
+ */
@NotBlank(message = "Java属性不能为空")
private String javaField;
- /** 是否主键(1是) */
+ /**
+ * 是否主键(1是)
+ */
private String isPk;
- /** 是否自增(1是) */
+ /**
+ * 是否自增(1是)
+ */
private String isIncrement;
- /** 是否必填(1是) */
+ /**
+ * 是否必填(1是)
+ */
private String isRequired;
- /** 是否为插入字段(1是) */
+ /**
+ * 是否为插入字段(1是)
+ */
private String isInsert;
- /** 是否编辑字段(1是) */
+ /**
+ * 是否编辑字段(1是)
+ */
private String isEdit;
- /** 是否列表字段(1是) */
+ /**
+ * 是否列表字段(1是)
+ */
private String isList;
- /** 是否查询字段(1是) */
+ /**
+ * 是否查询字段(1是)
+ */
private String isQuery;
- /** 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) */
+ /**
+ * 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围)
+ */
private String queryType;
- /** 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、upload上传控件、summernote富文本控件) */
+ /**
+ * 显示类型(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 String getCapJavaField()
- {
- return StringUtils.capitalize(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()
- {
+ @Transient
+ public boolean isSuperColumn() {
return isSuperColumn(this.javaField);
}
- public static boolean isSuperColumn(String javaField)
- {
+ public static boolean isSuperColumn(String javaField) {
return StringUtils.equalsAnyIgnoreCase(javaField,
- // BaseEntity
+ //BaseEntity
"createBy", "createTime", "updateBy", "updateTime", "remark",
- // TreeEntity
+ //TreeEntity
"parentName", "parentId", "orderNum", "ancestors");
}
- public boolean isUsableColumn()
- {
+ @Transient
+ public boolean isUsableColumn() {
return isUsableColumn(javaField);
}
- public static boolean isUsableColumn(String javaField)
- {
- // isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单
- return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
+ public static boolean isUsableColumn(String javaField) {
+ //isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单
+ return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum");
}
- public String readConverterExp()
- {
+ public String readConverterExp() {
String remarks = StringUtils.substringBetween(this.columnComment, "(", ")");
StringBuffer sb = new StringBuffer();
- if (StringUtils.isNotEmpty(remarks))
- {
- for (String value : remarks.split(" "))
- {
- if (StringUtils.isNotEmpty(value))
- {
+ if (StringUtils.isNotEmpty(remarks)) {
+ for (String value : remarks.split(" ")) {
+ if (StringUtils.isNotEmpty(value)) {
Object startStr = value.subSequence(0, 1);
String endStr = value.substring(1);
sb.append("").append(startStr).append("=").append(endStr).append(",");
}
}
return sb.deleteCharAt(sb.length() - 1).toString();
- }
- else
- {
+ } else {
return this.columnComment;
}
}
+
+ public String capital(){
+ return StringUtils.capitalize(this.javaField);
+ }
+
+ @Transient
+ public boolean isList() {
+ return isList(this.isList);
+ }
+
+ @Transient
+ public boolean isList(String isList) {
+ return isList != null && StringUtils.equals("1", isList);
+ }
+
+ @Transient
+ public boolean isPk() {
+ return isPk(this.isPk);
+ }
+
+ @Transient
+ public boolean isPk(String isPk) {
+ return isPk != null && StringUtils.equals("1", isPk);
+ }
}
\ No newline at end of file
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java
index 50e75e88b..3486e2b4c 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java
@@ -1,50 +1,45 @@
package com.ruoyi.generator.service;
+import com.ruoyi.generator.domain.GenTable;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
import java.util.List;
import java.util.Map;
-import com.ruoyi.generator.domain.GenTable;
/**
* 业务 服务层
- *
+ *
* @author ruoyi
*/
-public interface IGenTableService
-{
+public interface IGenTableService {
/**
* 查询业务列表
- *
+ *
* @param genTable 业务信息
* @return 业务集合
*/
- public List selectGenTableList(GenTable genTable);
+ public Page selectGenTableList(GenTable genTable, Pageable pageable);
/**
* 查询据库列表
- *
+ *
* @param genTable 业务信息
* @return 数据库表集合
*/
- public List selectDbTableList(GenTable genTable);
+ public Page selectDbTableList(GenTable genTable, Pageable pageable);
/**
* 查询据库列表
- *
+ *
* @param tableNames 表名称组
* @return 数据库表集合
*/
public List selectDbTableListByNames(String[] tableNames);
- /**
- * 查询所有表信息
- *
- * @return 表信息集合
- */
- public List selectGenTableAll();
-
/**
* 查询业务信息
- *
+ *
* @param id 业务ID
* @return 业务信息
*/
@@ -52,7 +47,7 @@ public interface IGenTableService
/**
* 修改业务
- *
+ *
* @param genTable 业务信息
* @return 结果
*/
@@ -60,7 +55,7 @@ public interface IGenTableService
/**
* 删除业务信息
- *
+ *
* @param ids 需要删除的数据ID
* @return 结果
*/
@@ -68,54 +63,47 @@ public interface IGenTableService
/**
* 导入表结构
- *
+ *
* @param tableList 导入表列表
- * @param operName 操作人员
+ * @param operName 操作人员
*/
public void importGenTable(List tableList, String operName);
/**
* 预览代码
- *
+ *
* @param tableId 表编号
* @return 预览数据列表
*/
public Map previewCode(Long tableId);
/**
- * 生成代码(下载方式)
- *
+ * 生成代码
+ *
* @param tableName 表名称
* @return 数据
*/
- public byte[] downloadCode(String tableName);
+ public byte[] generatorCode(String tableName);
/**
- * 生成代码(自定义路径)
- *
- * @param tableName 表名称
- */
- public void generatorCode(String tableName);
-
- /**
- * 同步数据库
- *
- * @param tableName 表名称
- */
- public void synchDb(String tableName);
-
- /**
- * 批量生成代码(下载方式)
- *
+ * 批量生成代码
+ *
* @param tableNames 表数组
* @return 数据
*/
- public byte[] downloadCode(String[] tableNames);
+ public byte[] generatorCode(String[] tableNames);
/**
* 修改保存参数校验
- *
+ *
* @param genTable 业务信息
*/
public void validateEdit(GenTable genTable);
+
+ /**
+ * 同步数据库
+ *
+ * @param tableName 表名称
+ */
+ public void synchDb(String tableName);
}
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/GenTableServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/GenTableServiceImpl.java
index 7274cf065..ae751fd3e 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/GenTableServiceImpl.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/GenTableServiceImpl.java
@@ -1,15 +1,24 @@
package com.ruoyi.generator.service.impl;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.querydsl.core.types.ExpressionUtils;
+import com.querydsl.core.types.Predicate;
+import com.ruoyi.common.base.BaseService;
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.constant.GenConstants;
+import com.ruoyi.common.core.text.Convert;
+import com.ruoyi.common.exception.BusinessException;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.generator.domain.GenTable;
+import com.ruoyi.generator.domain.GenTableColumn;
+import com.ruoyi.generator.domain.QGenTable;
+import com.ruoyi.generator.repository.GenTableColumnRepository;
+import com.ruoyi.generator.repository.GenTableRepository;
+import com.ruoyi.generator.service.IGenTableService;
+import com.ruoyi.generator.util.GenUtils;
+import com.ruoyi.generator.util.VelocityInitializer;
+import com.ruoyi.generator.util.VelocityUtils;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
@@ -17,198 +26,214 @@ import org.apache.velocity.app.Velocity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.Pageable;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
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.core.text.CharsetKit;
-import com.ruoyi.common.core.text.Convert;
-import com.ruoyi.common.exception.BusinessException;
-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;
-import com.ruoyi.generator.mapper.GenTableMapper;
-import com.ruoyi.generator.service.IGenTableService;
-import com.ruoyi.generator.util.GenUtils;
-import com.ruoyi.generator.util.VelocityInitializer;
-import com.ruoyi.generator.util.VelocityUtils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
/**
* 业务 服务层实现
- *
+ *
* @author ruoyi
*/
@Service
-public class GenTableServiceImpl implements IGenTableService
-{
+public class GenTableServiceImpl extends BaseService implements IGenTableService {
+
+ private static final String QUARTZ_TABLE_PREFIX = "qrtz_";
+ private static final String GEN_TABLE_PREFIX = "gen_";
private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
@Autowired
- private GenTableMapper genTableMapper;
-
+ private GenTableRepository genTableRepository;
@Autowired
- private GenTableColumnMapper genTableColumnMapper;
+ private JdbcTemplate jdbcTemplate;
+ @Autowired
+ private GenTableColumnRepository genTableColumnRepository;
/**
* 查询业务信息
- *
+ *
* @param id 业务ID
* @return 业务信息
*/
@Override
- public GenTable selectGenTableById(Long id)
- {
- GenTable genTable = genTableMapper.selectGenTableById(id);
+ public GenTable selectGenTableById(Long id) {
+ GenTable genTable = genTableRepository.findById(id).get();
setTableFromOptions(genTable);
return genTable;
}
/**
* 查询业务列表
- *
+ *
* @param genTable 业务信息
* @return 业务集合
*/
@Override
- public List selectGenTableList(GenTable genTable)
- {
- return genTableMapper.selectGenTableList(genTable);
+ public Page selectGenTableList(GenTable genTable, Pageable pageable) {
+ return genTableRepository.findAll(getPredicate(genTable), pageable);
}
/**
* 查询据库列表
- *
+ *
* @param genTable 业务信息
* @return 数据库表集合
*/
- @Override
- public List selectDbTableList(GenTable genTable)
- {
- return genTableMapper.selectDbTableList(genTable);
+ public Page selectDbTableList(GenTable genTable, Pageable pageable) {
+ String sql = " select table_name, table_comment, create_time, update_time from information_schema.tables " +
+ " where table_schema = (select database()) " +
+ " AND table_name NOT LIKE '"+QUARTZ_TABLE_PREFIX+"%' AND table_name NOT LIKE '"+GEN_TABLE_PREFIX+"%' " +
+ " AND table_name NOT IN (select table_name from gen_table) ";
+ if(StringUtils.isNotEmpty(genTable.getTableName())){
+ sql += " AND lower(table_name) like lower(concat('%', " + genTable.getTableName()+ ", '%')) ";
+ }
+ if(StringUtils.isNotEmpty(genTable.getTableName())){
+ sql += " AND lower(table_comment) like lower(concat('%', " + genTable.getTableComment() + ", '%'))";
+ }
+ String countSql = "select count(0) from ( " + sql + " ) t";
+ if(pageable.isPaged()){
+ int page = pageable.getPageNumber();
+ int size = pageable.getPageSize();
+ int start = 0;
+ if(page > 0){
+ start = page * size ;
+ }
+ sql += " limit " + start + "," + size;
+ }
+ List tables = jdbcTemplate.query(sql, new BeanPropertyRowMapper(GenTable.class));
+ int count = jdbcTemplate.queryForObject(countSql, Integer.class);
+ return new PageImpl(tables, pageable, count);
+ }
+
+ private Predicate getPredicate(GenTable genTable){
+ QGenTable qGenTable = QGenTable.genTable;
+ List predicates = new ArrayList<>();
+ predicates.add(notStartWith(qGenTable.tableName, QUARTZ_TABLE_PREFIX));
+ predicates.add(notStartWith(qGenTable.tableName, GEN_TABLE_PREFIX));
+ if(StringUtils.isNotEmpty(genTable.getTableName())){
+ predicates.add(buildLike(qGenTable.tableName, genTable.getTableName()));
+ }
+ if(StringUtils.isNotEmpty(genTable.getTableComment())){
+ predicates.add(buildLike(qGenTable.tableComment, genTable.getTableComment()));
+ }
+ return ExpressionUtils.allOf(predicates);
}
/**
* 查询据库列表
- *
+ *
* @param tableNames 表名称组
* @return 数据库表集合
*/
- @Override
- public List selectDbTableListByNames(String[] tableNames)
- {
- return genTableMapper.selectDbTableListByNames(tableNames);
- }
-
- /**
- * 查询所有表信息
- *
- * @return 表信息集合
- */
- @Override
- public List selectGenTableAll()
- {
- return genTableMapper.selectGenTableAll();
+ public List selectDbTableListByNames(String[] tableNames) {
+ String sql = "select table_name, table_comment, create_time, update_time from information_schema.tables " +
+ " where table_name NOT LIKE '"+QUARTZ_TABLE_PREFIX+"%' and table_name NOT LIKE '"+GEN_TABLE_PREFIX+"%' and table_schema = (select database()) " +
+ " and table_name in (";
+ for(int i=0;i(GenTable.class));
}
/**
* 修改业务
- *
+ *
* @param genTable 业务信息
* @return 结果
*/
@Override
@Transactional
- public void updateGenTable(GenTable genTable)
- {
+ public void updateGenTable(GenTable genTable) {
String options = JSON.toJSONString(genTable.getParams());
genTable.setOptions(options);
- int row = genTableMapper.updateGenTable(genTable);
- if (row > 0)
- {
- for (GenTableColumn cenTableColumn : genTable.getColumns())
- {
- genTableColumnMapper.updateGenTableColumn(cenTableColumn);
- }
+ genTableRepository.save(genTable);
+ for (GenTableColumn cenTableColumn : genTable.getColumns()) {
+ genTableColumnRepository.save(cenTableColumn);
}
}
/**
* 删除业务对象
- *
+ *
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
@Transactional
- public void deleteGenTableByIds(String ids)
- {
- genTableMapper.deleteGenTableByIds(Convert.toLongArray(ids));
- genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
+ public void deleteGenTableByIds(String ids) {
+ for(Long id : Convert.toLongArray(ids)){
+ genTableRepository.deleteById(id);
+ }
}
/**
* 导入表结构
- *
+ *
* @param tableList 导入表列表
- * @param operName 操作人员
+ * @param operName 操作人员
*/
@Override
@Transactional
- public void importGenTable(List tableList, String operName)
- {
- try
- {
- for (GenTable table : tableList)
- {
- String tableName = table.getTableName();
+ public void importGenTable(List tableList, String operName) {
+ for (GenTable table : tableList) {
+ try {
GenUtils.initTable(table, operName);
- int row = genTableMapper.insertGenTable(table);
- if (row > 0)
- {
- // 保存列信息
- List genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
- for (GenTableColumn column : genTableColumns)
- {
- GenUtils.initColumnField(column, table);
- genTableColumnMapper.insertGenTableColumn(column);
- }
+ List columns = new ArrayList<>();
+ String sql = "select column_name, (case when (is_nullable = 'no' && column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type " +
+ " from information_schema.columns where table_schema = (select database()) and table_name = '" + table.getTableName() + "'" +
+ " order by ordinal_position";
+ List genTableColumns = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(GenTableColumn.class));
+ for (GenTableColumn column : genTableColumns) {
+ GenUtils.initColumnField(column, table);
+ columns.add(column);
}
+ table.setColumns(columns);
+ genTableRepository.save(table);
+ } catch (Exception e) {
+ log.error("表名 " + table.getTableName() + " 导入失败:", e);
}
}
- catch (Exception e)
- {
- throw new BusinessException("导入失败:" + e.getMessage());
- }
}
/**
* 预览代码
- *
+ *
* @param tableId 表编号
* @return 预览数据列表
*/
- @Override
- public Map previewCode(Long tableId)
- {
+ public Map previewCode(Long tableId) {
Map dataMap = new LinkedHashMap<>();
// 查询表信息
- GenTable table = genTableMapper.selectGenTableById(tableId);
- // 设置主子表信息
- setSubTable(table);
- // 设置主键列信息
- setPkColumn(table);
+ GenTable table = genTableRepository.findById(tableId).get();
+ // 查询列信息
+ List columns = table.getColumns();
+ setPkColumn(table, columns);
VelocityInitializer.initVelocity();
VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表
List templates = VelocityUtils.getTemplateList(table.getTplCategory());
- for (String template : templates)
- {
+ for (String template : templates) {
// 渲染模板
StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
@@ -219,35 +244,46 @@ public class GenTableServiceImpl implements IGenTableService
}
/**
- * 生成代码(下载方式)
- *
+ * 生成代码
+ *
* @param tableName 表名称
* @return 数据
*/
@Override
- public byte[] downloadCode(String tableName)
- {
+ public byte[] generatorCode(String tableName) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
generatorCode(tableName, zip);
IOUtils.closeQuietly(zip);
return outputStream.toByteArray();
}
-
+
/**
- * 生成代码(自定义路径)
- *
- * @param tableName 表名称
+ * 批量生成代码
+ *
+ * @param tableNames 表数组
+ * @return 数据
*/
@Override
- public void generatorCode(String tableName)
- {
+ 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);
- // 设置主子表信息
- setSubTable(table);
- // 设置主键列信息
- setPkColumn(table);
+ GenTable table = genTableRepository.findFirstByTableName(tableName);
+ // 查询列信息
+ List columns = table.getColumns();
+ setPkColumn(table, columns);
VelocityInitializer.initVelocity();
@@ -255,41 +291,91 @@ public class GenTableServiceImpl implements IGenTableService
// 获取模板列表
List templates = VelocityUtils.getTemplateList(table.getTplCategory());
- for (String template : templates)
- {
- if (!StringUtils.contains(template, "sql.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 BusinessException("渲染模板失败,表名:" + table.getTableName());
- }
+ 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.closeEntry();
+ } catch (IOException e) {
+ log.error("渲染模板失败,表名:" + table.getTableName(), e);
}
}
}
+ /**
+ * 修改保存参数校验
+ *
+ * @param genTable 业务信息
+ */
+ 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 BusinessException("树编码字段不能为空");
+ } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) {
+ throw new BusinessException("树父编码字段不能为空");
+ } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) {
+ throw new BusinessException("树名称字段不能为空");
+ }
+ }
+ }
+
+ /**
+ * 设置主键列信息
+ *
+ * @param table 业务表信息
+ * @param columns 业务字段列表
+ */
+ public void setPkColumn(GenTable table, List 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);
+ }
+ }
+
/**
* 同步数据库
- *
+ *
* @param tableName 表名称
*/
@Override
@Transactional
public void synchDb(String tableName)
{
- GenTable table = genTableMapper.selectGenTableByName(tableName);
+ GenTable table = genTableRepository.findFirstByTableName(tableName);
List tableColumns = table.getColumns();
List tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
- List dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
+ List dbTableColumns = table.getColumns();
if (StringUtils.isEmpty(dbTableColumns))
{
throw new BusinessException("同步数据失败,原表结构不存在");
@@ -300,7 +386,7 @@ public class GenTableServiceImpl implements IGenTableService
if (!tableColumnNames.contains(column.getColumnName()))
{
GenUtils.initColumnField(column, table);
- genTableColumnMapper.insertGenTableColumn(column);
+ genTableColumnRepository.save(column);
}
});
@@ -308,195 +394,7 @@ public class GenTableServiceImpl implements IGenTableService
.filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
if (StringUtils.isNotEmpty(delColumns))
{
- genTableColumnMapper.deleteGenTableColumns(delColumns);
+ genTableColumnRepository.deleteAll(delColumns);
}
}
-
- /**
- * 批量生成代码
- *
- * @param tableNames 表数组
- * @return 数据
- */
- @Override
- public byte[] downloadCode(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);
- // 设置主子表信息
- setSubTable(table);
- // 设置主键列信息
- setPkColumn(table);
-
- VelocityInitializer.initVelocity();
-
- VelocityContext context = VelocityUtils.prepareContext(table);
-
- // 获取模板列表
- List 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 BusinessException("树编码字段不能为空");
- }
- else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
- {
- throw new BusinessException("树父编码字段不能为空");
- }
- else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME)))
- {
- throw new BusinessException("树名称字段不能为空");
- }
- }
- else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
- {
- if (StringUtils.isEmpty(genTable.getSubTableName()))
- {
- throw new BusinessException("关联子表的表名不能为空");
- }
- else if (StringUtils.isEmpty(genTable.getSubTableFkName()))
- {
- throw new BusinessException("子表关联的外键名不能为空");
- }
- }
- }
-
- /**
- * 设置主键列信息
- *
- * @param table 业务表信息
- */
- public void setPkColumn(GenTable table)
- {
- for (GenTableColumn column : table.getColumns())
- {
- if (column.isPk())
- {
- table.setPkColumn(column);
- break;
- }
- }
- if (StringUtils.isNull(table.getPkColumn()))
- {
- table.setPkColumn(table.getColumns().get(0));
- }
- if (GenConstants.TPL_SUB.equals(table.getTplCategory()))
- {
- for (GenTableColumn column : table.getSubTable().getColumns())
- {
- if (column.isPk())
- {
- table.getSubTable().setPkColumn(column);
- break;
- }
- }
- if (StringUtils.isNull(table.getSubTable().getPkColumn()))
- {
- table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
- }
- }
- }
-
- /**
- * 设置主子表信息
- *
- * @param table 业务表信息
- */
- public void setSubTable(GenTable table)
- {
- String subTableName = table.getSubTableName();
- if (StringUtils.isNotEmpty(subTableName))
- {
- table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
- }
- }
-
- /**
- * 设置代码生成其他选项值
- *
- * @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);
- 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);
- }
- }
-
- /**
- * 获取代码生成地址
- *
- * @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);
- }
}
\ No newline at end of file
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java
index baf461755..192a50415 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java
@@ -1,25 +1,24 @@
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;
+import org.apache.commons.lang3.RegExUtils;
+
+import java.util.Arrays;
/**
* 代码生成器 工具类
- *
+ *
* @author ruoyi
*/
-public class GenUtils
-{
+public class GenUtils {
/**
* 初始化表信息
*/
- public static void initTable(GenTable genTable, String operName)
- {
+ public static void initTable(GenTable genTable, String operName) {
genTable.setClassName(convertClassName(genTable.getTableName()));
genTable.setPackageName(GenConfig.getPackageName());
genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
@@ -32,46 +31,36 @@ public class GenUtils
/**
* 初始化列属性字段
*/
- public static void initColumnField(GenTableColumn column, GenTable table)
- {
+ public static void initColumnField(GenTableColumn column, GenTable table) {
String dataType = getDbType(column.getColumnType());
String columnName = column.getColumnName();
- column.setTableId(table.getTableId());
column.setCreateBy(table.getCreateBy());
// 设置java字段名
column.setJavaField(StringUtils.toCamelCase(columnName));
- if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType))
- {
+ if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType)) {
column.setJavaType(GenConstants.TYPE_STRING);
// 字符串长度超过500设置为文本域
Integer columnLength = getColumnLength(column.getColumnType());
String htmlType = columnLength >= 500 ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
column.setHtmlType(htmlType);
- }
- else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType))
- {
+ } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
column.setJavaType(GenConstants.TYPE_DATE);
column.setHtmlType(GenConstants.HTML_DATETIME);
- }
- else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType))
- {
+ } else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
column.setHtmlType(GenConstants.HTML_INPUT);
// 如果是浮点型
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
- if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0)
- {
- column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
+ if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
+ column.setJavaType(GenConstants.TYPE_DOUBLE);
}
// 如果是整形
- else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10)
- {
+ else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
column.setJavaType(GenConstants.TYPE_INTEGER);
}
// 长整形
- else
- {
+ else {
column.setJavaType(GenConstants.TYPE_LONG);
}
}
@@ -80,69 +69,51 @@ public class GenUtils
column.setIsInsert(GenConstants.REQUIRE);
// 编辑字段
- if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk())
- {
+ if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) {
column.setIsEdit(GenConstants.REQUIRE);
}
// 列表字段
- if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk())
- {
+ if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) {
column.setIsList(GenConstants.REQUIRE);
}
// 查询字段
- if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk())
- {
+ if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) {
column.setIsQuery(GenConstants.REQUIRE);
}
// 查询字段类型
- if (StringUtils.endsWithIgnoreCase(columnName, "name"))
- {
+ if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
column.setQueryType(GenConstants.QUERY_LIKE);
}
// 状态字段设置单选框
- if (StringUtils.endsWithIgnoreCase(columnName, "status"))
- {
+ if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
column.setHtmlType(GenConstants.HTML_RADIO);
}
// 类型&性别字段设置下拉框
else if (StringUtils.endsWithIgnoreCase(columnName, "type")
- || StringUtils.endsWithIgnoreCase(columnName, "sex"))
- {
+ || StringUtils.endsWithIgnoreCase(columnName, "sex")) {
column.setHtmlType(GenConstants.HTML_SELECT);
}
- // 文件字段设置上传控件
- else if (StringUtils.endsWithIgnoreCase(columnName, "file"))
- {
- column.setHtmlType(GenConstants.HTML_UPLOAD);
- }
- // 内容字段设置富文本控件
- else if (StringUtils.endsWithIgnoreCase(columnName, "content"))
- {
- column.setHtmlType(GenConstants.HTML_SUMMERNOTE);
- }
}
/**
* 校验数组是否包含指定值
- *
- * @param arr 数组
+ *
+ * @param arr 数组
* @param targetValue 值
* @return 是否包含
*/
- public static boolean arraysContains(String[] arr, String targetValue)
- {
+ public static boolean arraysContains(String[] arr, String targetValue) {
return Arrays.asList(arr).contains(targetValue);
}
/**
* 获取模块名
- *
+ *
* @param packageName 包名
* @return 模块名
*/
- public static String getModuleName(String packageName)
- {
+ public static String getModuleName(String packageName) {
int lastIndex = packageName.lastIndexOf(".");
int nameLength = packageName.length();
String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength);
@@ -151,12 +122,11 @@ public class GenUtils
/**
* 获取业务名
- *
+ *
* @param tableName 表名
* @return 业务名
*/
- public static String getBusinessName(String tableName)
- {
+ public static String getBusinessName(String tableName) {
int lastIndex = tableName.lastIndexOf("_");
int nameLength = tableName.length();
String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength);
@@ -165,102 +135,69 @@ public class GenUtils
/**
* 表名转换成Java类名
- *
+ *
* @param tableName 表名称
* @return 类名
*/
- public static String convertClassName(String tableName)
- {
+ public static String convertClassName(String tableName) {
boolean autoRemovePre = GenConfig.getAutoRemovePre();
String tablePrefix = GenConfig.getTablePrefix();
- if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix))
- {
+ if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) {
String[] searchList = StringUtils.split(tablePrefix, ",");
- tableName = replaceFirst(tableName, searchList);
+ String[] replacementList = emptyList(searchList.length);
+ tableName = StringUtils.replaceEach(tableName, searchList, replacementList);
}
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 text 需要被替换的名字
* @return 替换后的名字
*/
- public static String replaceText(String text)
- {
+ public static String replaceText(String text) {
return RegExUtils.replaceAll(text, "(?:表|若依)", "");
}
/**
* 获取数据库类型字段
- *
+ *
* @param columnType 列类型
* @return 截取后的列类型
*/
- public static String getDbType(String columnType)
- {
- if (StringUtils.indexOf(columnType, "(") > 0)
- {
+ public static String getDbType(String columnType) {
+ if (StringUtils.indexOf(columnType, "(") > 0) {
return StringUtils.substringBefore(columnType, "(");
- }
- else
- {
+ } else {
return columnType;
}
}
/**
* 获取字段长度
- *
+ *
* @param columnType 列类型
* @return 截取后的列类型
*/
- public static Integer getColumnLength(String columnType)
- {
- if (StringUtils.indexOf(columnType, "(") > 0)
- {
+ public static Integer getColumnLength(String columnType) {
+ if (StringUtils.indexOf(columnType, "(") > 0) {
String length = StringUtils.substringBetween(columnType, "(", ")");
return Integer.valueOf(length);
- }
- else
- {
+ } else {
return 0;
}
}
/**
* 获取空数组列表
- *
+ *
* @param length 长度
* @return 数组信息
*/
- public static String[] emptyList(int length)
- {
+ public static String[] emptyList(int length) {
String[] values = new String[length];
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
values[i] = StringUtils.EMPTY;
}
return values;
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java
index 798768110..e41368fd4 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java
@@ -1,9 +1,5 @@
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;
@@ -11,28 +7,34 @@ import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.generator.config.GenConfig;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
+import org.apache.velocity.VelocityContext;
-public class VelocityUtils
-{
- /** 项目空间路径 */
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+public class VelocityUtils {
+ /**
+ * 项目空间路径
+ */
private static final String PROJECT_PATH = "main/java";
- /** mybatis空间路径 */
+ /**
+ * mybatis空间路径
+ */
private static final String MYBATIS_PATH = "main/resources/mapper";
- /** html空间路径 */
+ /**
+ * html空间路径
+ */
private static final String TEMPLATES_PATH = "main/resources/templates";
-
- /** 默认上级菜单,系统工具 */
- private static final String DEFAULT_PARENT_MENU_ID = "3";
/**
* 设置模板变量信息
- *
+ *
* @return 模板列表
*/
- public static VelocityContext prepareContext(GenTable genTable)
- {
+ public static VelocityContext prepareContext(GenTable genTable) {
String moduleName = genTable.getModuleName();
String businessName = genTable.getBusinessName();
String packageName = genTable.getPackageName();
@@ -45,6 +47,7 @@ public class VelocityUtils
velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】");
velocityContext.put("ClassName", genTable.getClassName());
velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName()));
+ velocityContext.put("classname", StringUtils.uncapitalize(genTable.getClassName()));
velocityContext.put("moduleName", genTable.getModuleName());
velocityContext.put("businessName", genTable.getBusinessName());
velocityContext.put("basePackage", getPackagePrefix(packageName));
@@ -52,32 +55,18 @@ public class VelocityUtils
velocityContext.put("author", genTable.getFunctionAuthor());
velocityContext.put("datetime", DateUtils.getDate());
velocityContext.put("pkColumn", genTable.getPkColumn());
- velocityContext.put("importList", getImportList(genTable));
+ velocityContext.put("primaryKeyType", genTable.getPkColumn().getJavaType());
+ velocityContext.put("importList", getImportList(genTable.getColumns()));
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
velocityContext.put("columns", genTable.getColumns());
velocityContext.put("table", genTable);
- setMenuVelocityContext(velocityContext, genTable);
- if (GenConstants.TPL_TREE.equals(tplCategory))
- {
+ if (GenConstants.TPL_TREE.equals(tplCategory)) {
setTreeVelocityContext(velocityContext, genTable);
}
- if (GenConstants.TPL_SUB.equals(tplCategory))
- {
- setSubVelocityContext(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)
- {
+ public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
String treeCode = getTreecode(paramsObj);
@@ -88,62 +77,32 @@ public class VelocityUtils
context.put("treeParentCode", treeParentCode);
context.put("treeName", treeName);
context.put("expandColumn", getExpandColumn(genTable));
- if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
- {
+ if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
- if (paramsObj.containsKey(GenConstants.TREE_NAME))
- {
+ if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME));
}
}
- public static void setSubVelocityContext(VelocityContext context, GenTable genTable)
- {
- GenTable subTable = genTable.getSubTable();
- String subTableName = genTable.getSubTableName();
- String subTableFkName = genTable.getSubTableFkName();
- String subClassName = genTable.getSubTable().getClassName();
- String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName);
-
- context.put("subTable", subTable);
- context.put("subTableName", subTableName);
- context.put("subTableFkName", subTableFkName);
- context.put("subTableFkClassName", subTableFkClassName);
- context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName));
- context.put("subClassName", subClassName);
- context.put("subclassName", StringUtils.uncapitalize(subClassName));
- context.put("subImportList", getImportList(genTable.getSubTable()));
- }
-
/**
* 获取模板信息
- *
+ *
* @return 模板列表
*/
- public static List getTemplateList(String tplCategory)
- {
+ public static List getTemplateList(String tplCategory) {
List templates = new ArrayList();
templates.add("vm/java/domain.java.vm");
- templates.add("vm/java/mapper.java.vm");
+ templates.add("vm/java/repository.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");
- if (GenConstants.TPL_CRUD.equals(tplCategory))
- {
+ if (GenConstants.TPL_CRUD.equals(tplCategory)) {
templates.add("vm/html/list.html.vm");
- }
- else if (GenConstants.TPL_TREE.equals(tplCategory))
- {
+ } else if (GenConstants.TPL_TREE.equals(tplCategory)) {
templates.add("vm/html/tree.html.vm");
templates.add("vm/html/list-tree.html.vm");
}
- else if (GenConstants.TPL_SUB.equals(tplCategory))
- {
- templates.add("vm/html/list.html.vm");
- templates.add("vm/java/sub-domain.java.vm");
- }
templates.add("vm/html/add.html.vm");
templates.add("vm/html/edit.html.vm");
templates.add("vm/sql/sql.vm");
@@ -153,8 +112,7 @@ public class VelocityUtils
/**
* 获取文件名
*/
- public static String getFileName(String template, GenTable genTable)
- {
+ public static String getFileName(String template, GenTable genTable) {
// 文件名称
String fileName = "";
// 包路径
@@ -170,56 +128,31 @@ public class VelocityUtils
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
String htmlPath = TEMPLATES_PATH + "/" + moduleName + "/" + businessName;
- if (template.contains("domain.java.vm"))
- {
- fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
- }
- if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory()))
- {
- fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName());
- }
- else if (template.contains("mapper.java.vm"))
- {
+ if (template.contains("domain.java.vm")) {
+ fileName = StringUtils.format("{}/entity/{}.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"))
- {
+ } else if (template.contains("repository.java.vm")) {
+ fileName = StringUtils.format("{}/repository/{}Repository.java", javaPath, className);
+ } else if (template.contains("service.java.vm")) {
+ fileName = StringUtils.format("{}/service/{}Service.java", javaPath, className);
+ } else if (template.contains("serviceImpl.java.vm")) {
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
- }
- else if (template.contains("controller.java.vm"))
- {
+ } else if (template.contains("controller.java.vm")) {
fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
- }
- else if (template.contains("mapper.xml.vm"))
- {
+ } else if (template.contains("mapper.xml.vm")) {
fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
- }
- else if (template.contains("list.html.vm"))
- {
+ } else if (template.contains("list.html.vm")) {
fileName = StringUtils.format("{}/{}.html", htmlPath, businessName);
- }
- else if (template.contains("list-tree.html.vm"))
- {
+ } else if (template.contains("list-tree.html.vm")) {
fileName = StringUtils.format("{}/{}.html", htmlPath, businessName);
- }
- else if (template.contains("tree.html.vm"))
- {
+ } else if (template.contains("tree.html.vm")) {
fileName = StringUtils.format("{}/tree.html", htmlPath);
- }
- else if (template.contains("add.html.vm"))
- {
+ } else if (template.contains("add.html.vm")) {
fileName = StringUtils.format("{}/add.html", htmlPath);
- }
- else if (template.contains("edit.html.vm"))
- {
+ } else if (template.contains("edit.html.vm")) {
fileName = StringUtils.format("{}/edit.html", htmlPath);
- }
- else if (template.contains("sql.vm"))
- {
+ } else if (template.contains("sql.vm")) {
fileName = businessName + "Menu.sql";
}
return fileName;
@@ -227,11 +160,10 @@ public class VelocityUtils
/**
* 获取项目文件路径
- *
+ *
* @return 路径
*/
- public static String getProjectPath()
- {
+ public static String getProjectPath() {
String packageName = GenConfig.getPackageName();
StringBuffer projectPath = new StringBuffer();
projectPath.append("main/java/");
@@ -242,12 +174,11 @@ public class VelocityUtils
/**
* 获取包前缀
- *
+ *
* @param packageName 包名称
* @return 包前缀名称
*/
- public static String getPackagePrefix(String packageName)
- {
+ public static String getPackagePrefix(String packageName) {
int lastIndex = packageName.lastIndexOf(".");
String basePackage = StringUtils.substring(packageName, 0, lastIndex);
return basePackage;
@@ -255,27 +186,16 @@ public class VelocityUtils
/**
* 根据列类型获取导入包
- *
- * @param genTable 业务表对象
+ *
+ * @param columns 列集合
* @return 返回需要导入的包列表
*/
- public static HashSet getImportList(GenTable genTable)
- {
- List columns = genTable.getColumns();
- GenTable subGenTable = genTable.getSubTable();
+ public static HashSet getImportList(List columns) {
HashSet importList = new HashSet();
- if (StringUtils.isNotNull(subGenTable))
- {
- importList.add("java.util.List");
- }
- for (GenTableColumn column : columns)
- {
- if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType()))
- {
+ for (GenTableColumn column : columns) {
+ if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
importList.add("java.util.Date");
- }
- else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType()))
- {
+ } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) {
importList.add("java.math.BigDecimal");
}
}
@@ -284,96 +204,71 @@ public class VelocityUtils
/**
* 获取权限前缀
- *
- * @param moduleName 模块名称
+ *
+ * @param moduleName 模块名称
* @param businessName 业务名称
* @return 返回权限前缀
*/
- public static String getPermissionPrefix(String moduleName, String businessName)
- {
+ public static String getPermissionPrefix(String moduleName, String businessName) {
return StringUtils.format("{}:{}", moduleName, businessName);
- }
- /**
- * 获取上级菜单ID字段
- *
- * @param 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;
}
/**
* 获取树编码
- *
- * @param options 生成其他选项
+ *
+ * @param paramsObj 生成其他选项
* @return 树编码
*/
- public static String getTreecode(JSONObject paramsObj)
- {
- if (paramsObj.containsKey(GenConstants.TREE_CODE))
- {
+ public static String getTreecode(JSONObject paramsObj) {
+ if (paramsObj.containsKey(GenConstants.TREE_CODE)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
}
- return StringUtils.EMPTY;
+ return "";
}
/**
* 获取树父编码
- *
- * @param options 生成其他选项
+ *
+ * @param paramsObj 生成其他选项
* @return 树父编码
*/
- public static String getTreeParentCode(JSONObject paramsObj)
- {
- if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
- {
+ public static String getTreeParentCode(JSONObject paramsObj) {
+ if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
- return StringUtils.EMPTY;
+ return "";
}
/**
* 获取树名称
- *
- * @param options 生成其他选项
+ *
+ * @param paramsObj 生成其他选项
* @return 树名称
*/
- public static String getTreeName(JSONObject paramsObj)
- {
- if (paramsObj.containsKey(GenConstants.TREE_NAME))
- {
+ public static String getTreeName(JSONObject paramsObj) {
+ if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
}
- return StringUtils.EMPTY;
+ return "";
}
/**
* 获取需要在哪一列上面显示展开按钮
- *
+ *
* @param genTable 业务表对象
* @return 展开按钮列序号
*/
- public static int getExpandColumn(GenTable genTable)
- {
+ public static int getExpandColumn(GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
int num = 0;
- for (GenTableColumn column : genTable.getColumns())
- {
- if (column.isList())
- {
+ for (GenTableColumn column : genTable.getColumns()) {
+ if (column.isList()) {
num++;
String columnName = column.getColumnName();
- if (columnName.equals(treeName))
- {
+ if (columnName.equals(treeName)) {
break;
}
}
diff --git a/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml
deleted file mode 100644
index 86f62deda..000000000
--- a/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml
+++ /dev/null
@@ -1,127 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column
-
-
-
-
-
-
-
- insert into gen_table_column (
- table_id,
- column_name,
- column_comment,
- column_type,
- java_type,
- java_field,
- is_pk,
- is_increment,
- is_required,
- is_insert,
- is_edit,
- is_list,
- is_query,
- query_type,
- html_type,
- dict_type,
- sort,
- create_by,
- create_time
- )values(
- #{tableId},
- #{columnName},
- #{columnComment},
- #{columnType},
- #{javaType},
- #{javaField},
- #{isPk},
- #{isIncrement},
- #{isRequired},
- #{isInsert},
- #{isEdit},
- #{isList},
- #{isQuery},
- #{queryType},
- #{htmlType},
- #{dictType},
- #{sort},
- #{createBy},
- sysdate()
- )
-
-
-
- update gen_table_column
-
- column_comment = #{columnComment},
- java_type = #{javaType},
- java_field = #{javaField},
- is_insert = #{isInsert},
- is_edit = #{isEdit},
- is_list = #{isList},
- is_query = #{isQuery},
- is_required = #{isRequired},
- query_type = #{queryType},
- html_type = #{htmlType},
- dict_type = #{dictType},
- sort = #{sort},
- update_by = #{updateBy},
- update_time = sysdate()
-
- where column_id = #{columnId}
-
-
-
- delete from gen_table_column where table_id in
-
- #{tableId}
-
-
-
-
- delete from gen_table_column where column_id in
-
- #{item.columnId}
-
-
-
-
\ No newline at end of file
diff --git a/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml b/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml
deleted file mode 100644
index 934210c2d..000000000
--- a/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml
+++ /dev/null
@@ -1,189 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- insert into gen_table (
- table_name,
- table_comment,
- class_name,
- tpl_category,
- package_name,
- module_name,
- business_name,
- function_name,
- function_author,
- gen_type,
- gen_path,
- remark,
- create_by,
- create_time
- )values(
- #{tableName},
- #{tableComment},
- #{className},
- #{tplCategory},
- #{packageName},
- #{moduleName},
- #{businessName},
- #{functionName},
- #{functionAuthor},
- #{genType},
- #{genPath},
- #{remark},
- #{createBy},
- sysdate()
- )
-
-
-
- update gen_table
-
- table_name = #{tableName},
- table_comment = #{tableComment},
- sub_table_name = #{subTableName},
- sub_table_fk_name = #{subTableFkName},
- class_name = #{className},
- function_author = #{functionAuthor},
- gen_type = #{genType},
- gen_path = #{genPath},
- tpl_category = #{tplCategory},
- package_name = #{packageName},
- module_name = #{moduleName},
- business_name = #{businessName},
- function_name = #{functionName},
- options = #{options},
- update_by = #{updateBy},
- remark = #{remark},
- update_time = sysdate()
-
- where table_id = #{tableId}
-
-
-
- delete from gen_table where table_id in
-
- #{tableId}
-
-
-
-
\ No newline at end of file
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java
index 5aea5c16e..72513e214 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java
@@ -1,17 +1,5 @@
package com.ruoyi.quartz.controller;
-import java.util.List;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.quartz.SchedulerException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-import org.springframework.validation.annotation.Validated;
-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.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
@@ -22,16 +10,25 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.quartz.domain.SysJob;
import com.ruoyi.quartz.service.ISysJobService;
import com.ruoyi.quartz.util.CronUtils;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.quartz.SchedulerException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
/**
* 调度任务信息操作处理
- *
+ *
* @author ruoyi
*/
@Controller
@RequestMapping("/monitor/job")
-public class SysJobController extends BaseController
-{
+public class SysJobController extends BaseController {
private String prefix = "monitor/job";
@Autowired
@@ -39,28 +36,23 @@ public class SysJobController extends BaseController
@RequiresPermissions("monitor:job:view")
@GetMapping()
- public String job()
- {
+ public String job() {
return prefix + "/job";
}
@RequiresPermissions("monitor:job:list")
@PostMapping("/list")
@ResponseBody
- public TableDataInfo list(SysJob job)
- {
- startPage();
- List list = jobService.selectJobList(job);
- return getDataTable(list);
+ public TableDataInfo list(SysJob job) {
+ return getDataTable(jobService.selectJobList(job, getPageRequest()));
}
@Log(title = "定时任务", businessType = BusinessType.EXPORT)
@RequiresPermissions("monitor:job:export")
@PostMapping("/export")
@ResponseBody
- public AjaxResult export(SysJob job)
- {
- List list = jobService.selectJobList(job);
+ public AjaxResult export(SysJob job) {
+ List list = jobService.selectJobList(job, Pageable.unpaged()).getContent();
ExcelUtil util = new ExcelUtil(SysJob.class);
return util.exportExcel(list, "定时任务");
}
@@ -69,16 +61,14 @@ public class SysJobController extends BaseController
@RequiresPermissions("monitor:job:remove")
@PostMapping("/remove")
@ResponseBody
- public AjaxResult remove(String ids) throws SchedulerException
- {
+ public AjaxResult remove(String ids) throws SchedulerException {
jobService.deleteJobByIds(ids);
return success();
}
@RequiresPermissions("monitor:job:detail")
@GetMapping("/detail/{jobId}")
- public String detail(@PathVariable("jobId") Long jobId, ModelMap mmap)
- {
+ public String detail(@PathVariable("jobId") Long jobId, ModelMap mmap) {
mmap.put("name", "job");
mmap.put("job", jobService.selectJobById(jobId));
return prefix + "/detail";
@@ -91,8 +81,7 @@ public class SysJobController extends BaseController
@RequiresPermissions("monitor:job:changeStatus")
@PostMapping("/changeStatus")
@ResponseBody
- public AjaxResult changeStatus(SysJob job) throws SchedulerException
- {
+ public AjaxResult changeStatus(SysJob job) throws SchedulerException {
SysJob newJob = jobService.selectJobById(job.getJobId());
newJob.setStatus(job.getStatus());
return toAjax(jobService.changeStatus(newJob));
@@ -105,8 +94,7 @@ public class SysJobController extends BaseController
@RequiresPermissions("monitor:job:changeStatus")
@PostMapping("/run")
@ResponseBody
- public AjaxResult run(SysJob job) throws SchedulerException
- {
+ public AjaxResult run(SysJob job) throws SchedulerException {
jobService.run(job);
return success();
}
@@ -115,8 +103,7 @@ public class SysJobController extends BaseController
* 新增调度
*/
@GetMapping("/add")
- public String add()
- {
+ public String add() {
return prefix + "/add";
}
@@ -127,8 +114,7 @@ public class SysJobController extends BaseController
@RequiresPermissions("monitor:job:add")
@PostMapping("/add")
@ResponseBody
- public AjaxResult addSave(@Validated SysJob job) throws SchedulerException, TaskException
- {
+ public AjaxResult addSave(@Validated SysJob job) throws SchedulerException, TaskException {
if (!CronUtils.isValid(job.getCronExpression()))
{
return AjaxResult.error("cron表达式不正确");
@@ -140,8 +126,7 @@ public class SysJobController extends BaseController
* 修改调度
*/
@GetMapping("/edit/{jobId}")
- public String edit(@PathVariable("jobId") Long jobId, ModelMap mmap)
- {
+ public String edit(@PathVariable("jobId") Long jobId, ModelMap mmap) {
mmap.put("job", jobService.selectJobById(jobId));
return prefix + "/edit";
}
@@ -153,8 +138,7 @@ public class SysJobController extends BaseController
@RequiresPermissions("monitor:job:edit")
@PostMapping("/edit")
@ResponseBody
- public AjaxResult editSave(@Validated SysJob job) throws SchedulerException, TaskException
- {
+ public AjaxResult editSave(@Validated SysJob job) throws SchedulerException, TaskException {
if (!CronUtils.isValid(job.getCronExpression()))
{
return AjaxResult.error("cron表达式不正确");
@@ -167,8 +151,7 @@ public class SysJobController extends BaseController
*/
@PostMapping("/checkCronExpressionIsValid")
@ResponseBody
- public boolean checkCronExpressionIsValid(SysJob job)
- {
+ public boolean checkCronExpressionIsValid(SysJob job) {
return jobService.checkCronExpressionIsValid(job.getCronExpression());
}
}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobLogController.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobLogController.java
index f44533c94..8575aafcc 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobLogController.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobLogController.java
@@ -1,16 +1,5 @@
package com.ruoyi.quartz.controller;
-import java.util.List;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-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.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
@@ -22,21 +11,27 @@ import com.ruoyi.quartz.domain.SysJob;
import com.ruoyi.quartz.domain.SysJobLog;
import com.ruoyi.quartz.service.ISysJobLogService;
import com.ruoyi.quartz.service.ISysJobService;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
/**
* 调度日志操作处理
- *
+ *
* @author ruoyi
*/
@Controller
@RequestMapping("/monitor/jobLog")
-public class SysJobLogController extends BaseController
-{
+public class SysJobLogController extends BaseController {
private String prefix = "monitor/job";
@Autowired
private ISysJobService jobService;
-
@Autowired
private ISysJobLogService jobLogService;
@@ -55,20 +50,16 @@ public class SysJobLogController extends BaseController
@RequiresPermissions("monitor:job:list")
@PostMapping("/list")
@ResponseBody
- public TableDataInfo list(SysJobLog jobLog)
- {
- startPage();
- List list = jobLogService.selectJobLogList(jobLog);
- return getDataTable(list);
+ public TableDataInfo list(SysJobLog jobLog) {
+ return getDataTable(jobLogService.selectJobLogList(jobLog, getPageRequest()));
}
@Log(title = "调度日志", businessType = BusinessType.EXPORT)
@RequiresPermissions("monitor:job:export")
@PostMapping("/export")
@ResponseBody
- public AjaxResult export(SysJobLog jobLog)
- {
- List list = jobLogService.selectJobLogList(jobLog);
+ public AjaxResult export(SysJobLog jobLog) {
+ List list = jobLogService.selectJobLogList(jobLog, Pageable.unpaged()).getContent();
ExcelUtil util = new ExcelUtil(SysJobLog.class);
return util.exportExcel(list, "调度日志");
}
@@ -77,15 +68,13 @@ public class SysJobLogController extends BaseController
@RequiresPermissions("monitor:job:remove")
@PostMapping("/remove")
@ResponseBody
- public AjaxResult remove(String ids)
- {
+ public AjaxResult remove(String ids) {
return toAjax(jobLogService.deleteJobLogByIds(ids));
}
@RequiresPermissions("monitor:job:detail")
@GetMapping("/detail/{jobLogId}")
- public String detail(@PathVariable("jobLogId") Long jobLogId, ModelMap mmap)
- {
+ public String detail(@PathVariable("jobLogId") Long jobLogId, ModelMap mmap) {
mmap.put("name", "jobLog");
mmap.put("jobLog", jobLogService.selectJobLogById(jobLogId));
return prefix + "/detail";
@@ -95,8 +84,7 @@ public class SysJobLogController extends BaseController
@RequiresPermissions("monitor:job:remove")
@PostMapping("/clean")
@ResponseBody
- public AjaxResult clean()
- {
+ public AjaxResult clean() {
jobLogService.cleanJobLog();
return success();
}
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java
index ea83b2e24..4d4e0547b 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java
@@ -1,170 +1,173 @@
package com.ruoyi.quartz.service.impl;
-import java.util.List;
-import javax.annotation.PostConstruct;
+import com.querydsl.core.types.ExpressionUtils;
+import com.querydsl.core.types.Predicate;
+import com.ruoyi.common.base.BaseService;
+import com.ruoyi.common.constant.ScheduleConstants;
+import com.ruoyi.common.core.text.Convert;
+import com.ruoyi.common.exception.job.TaskException;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.quartz.domain.QSysJob;
+import com.ruoyi.quartz.domain.SysJob;
+import com.ruoyi.quartz.repository.SysJobRepository;
+import com.ruoyi.quartz.service.ISysJobService;
+import com.ruoyi.quartz.util.CronUtils;
+import com.ruoyi.quartz.util.ScheduleUtils;
import org.quartz.JobDataMap;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import com.ruoyi.common.constant.ScheduleConstants;
-import com.ruoyi.common.core.text.Convert;
-import com.ruoyi.common.exception.job.TaskException;
-import com.ruoyi.quartz.domain.SysJob;
-import com.ruoyi.quartz.mapper.SysJobMapper;
-import com.ruoyi.quartz.service.ISysJobService;
-import com.ruoyi.quartz.util.CronUtils;
-import com.ruoyi.quartz.util.ScheduleUtils;
+
+import javax.annotation.PostConstruct;
+import java.util.ArrayList;
+import java.util.List;
/**
* 定时任务调度信息 服务层
- *
+ *
* @author ruoyi
*/
@Service
-public class SysJobServiceImpl implements ISysJobService
-{
+public class SysJobServiceImpl extends BaseService implements ISysJobService {
@Autowired
private Scheduler scheduler;
-
@Autowired
- private SysJobMapper jobMapper;
+ private SysJobRepository sysJobRepository;
/**
- * 项目启动时,初始化定时器
- 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
+ * 项目启动时,初始化定时器
+ * 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
*/
@PostConstruct
- public void init() throws SchedulerException, TaskException
- {
- scheduler.clear();
- List jobList = jobMapper.selectJobAll();
- for (SysJob job : jobList)
- {
- ScheduleUtils.createScheduleJob(scheduler, job);
+ public void init() throws SchedulerException, TaskException {
+ List jobList = sysJobRepository.findAll();
+ for (SysJob job : jobList) {
+ updateSchedulerJob(job, job.getJobGroup());
}
}
/**
* 获取quartz调度器的计划任务列表
- *
+ *
* @param job 调度信息
* @return
*/
@Override
- public List selectJobList(SysJob job)
- {
- return jobMapper.selectJobList(job);
+ public Page selectJobList(SysJob job, Pageable pageable) {
+ return sysJobRepository.findAll(getPredicate(job), pageable);
+ }
+
+ private Predicate getPredicate(SysJob job){
+ QSysJob qSysJob = QSysJob.sysJob;
+ List predicates = new ArrayList<>();
+ if(StringUtils.isNotEmpty(job.getJobName())){
+ predicates.add(buildLike(qSysJob.jobName, job.getJobName()));
+ }
+ if(StringUtils.isNotEmpty(job.getJobGroup())){
+ predicates.add(buildEqual(qSysJob.jobGroup, job.getJobGroup()));
+ }
+ if(StringUtils.isNotEmpty(job.getStatus())){
+ predicates.add(buildEqual(qSysJob.status, job.getStatus()));
+ }
+ if(StringUtils.isNotEmpty(job.getInvokeTarget())){
+ predicates.add(buildLike(qSysJob.invokeTarget, job.getInvokeTarget()));
+ }
+ return ExpressionUtils.allOf(predicates);
}
/**
* 通过调度任务ID查询调度信息
- *
+ *
* @param jobId 调度任务ID
* @return 调度任务对象信息
*/
@Override
- public SysJob selectJobById(Long jobId)
- {
- return jobMapper.selectJobById(jobId);
+ public SysJob selectJobById(Long jobId) {
+ return sysJobRepository.findById(jobId).get();
}
/**
* 暂停任务
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public int pauseJob(SysJob job) throws SchedulerException
- {
+ public int pauseJob(SysJob job) throws SchedulerException {
Long jobId = job.getJobId();
String jobGroup = job.getJobGroup();
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
- int rows = jobMapper.updateJob(job);
- if (rows > 0)
- {
- scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
- }
- return rows;
+ sysJobRepository.updateStatus(job.getStatus(), jobId);
+ scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
+ return 1;
}
/**
* 恢复任务
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public int resumeJob(SysJob job) throws SchedulerException
- {
+ public int resumeJob(SysJob job) throws SchedulerException {
Long jobId = job.getJobId();
String jobGroup = job.getJobGroup();
job.setStatus(ScheduleConstants.Status.NORMAL.getValue());
- int rows = jobMapper.updateJob(job);
- if (rows > 0)
- {
- scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
- }
- return rows;
+ sysJobRepository.updateStatus(job.getStatus(), jobId);
+ scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
+ return 1;
}
/**
* 删除任务后,所对应的trigger也将被删除
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public int deleteJob(SysJob job) throws SchedulerException
- {
+ public int deleteJob(SysJob job) throws SchedulerException {
Long jobId = job.getJobId();
String jobGroup = job.getJobGroup();
- int rows = jobMapper.deleteJobById(jobId);
- if (rows > 0)
- {
- scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
- }
- return rows;
+ sysJobRepository.deleteById(jobId);
+ scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
+ return 1;
}
/**
* 批量删除调度信息
- *
+ *
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
@Transactional
- public void deleteJobByIds(String ids) throws SchedulerException
- {
+ public void deleteJobByIds(String ids) throws SchedulerException {
Long[] jobIds = Convert.toLongArray(ids);
- for (Long jobId : jobIds)
- {
- SysJob job = jobMapper.selectJobById(jobId);
+ for (Long jobId : jobIds) {
+ SysJob job = selectJobById(jobId);
deleteJob(job);
}
}
/**
* 任务调度状态修改
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public int changeStatus(SysJob job) throws SchedulerException
- {
+ public int changeStatus(SysJob job) throws SchedulerException {
int rows = 0;
String status = job.getStatus();
- if (ScheduleConstants.Status.NORMAL.getValue().equals(status))
- {
+ if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) {
rows = resumeJob(job);
- }
- else if (ScheduleConstants.Status.PAUSE.getValue().equals(status))
- {
+ } else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) {
rows = pauseJob(job);
}
return rows;
@@ -172,70 +175,60 @@ public class SysJobServiceImpl implements ISysJobService
/**
* 立即运行任务
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public void run(SysJob job) throws SchedulerException
- {
+ public void run(SysJob job) throws SchedulerException {
Long jobId = job.getJobId();
- SysJob tmpObj = selectJobById(job.getJobId());
+ String jobGroup = job.getJobGroup();
+ SysJob properties = selectJobById(job.getJobId());
// 参数
JobDataMap dataMap = new JobDataMap();
- dataMap.put(ScheduleConstants.TASK_PROPERTIES, tmpObj);
- scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, tmpObj.getJobGroup()), dataMap);
+ dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties);
+ scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap);
}
/**
* 新增任务
- *
+ *
* @param job 调度信息 调度信息
*/
@Override
@Transactional
- public int insertJob(SysJob job) throws SchedulerException, TaskException
- {
+ public int insertJob(SysJob job) throws SchedulerException, TaskException {
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
- int rows = jobMapper.insertJob(job);
- if (rows > 0)
- {
- ScheduleUtils.createScheduleJob(scheduler, job);
- }
- return rows;
+ sysJobRepository.save(job);
+ ScheduleUtils.createScheduleJob(scheduler, job);
+ return 1;
}
/**
* 更新任务的时间表达式
- *
+ *
* @param job 调度信息
*/
@Override
@Transactional
- public int updateJob(SysJob job) throws SchedulerException, TaskException
- {
+ public int updateJob(SysJob job) throws SchedulerException, TaskException {
SysJob properties = selectJobById(job.getJobId());
- int rows = jobMapper.updateJob(job);
- if (rows > 0)
- {
- updateSchedulerJob(job, properties.getJobGroup());
- }
- return rows;
+ BeanUtils.copyProperties(job, properties);
+ updateSchedulerJob(job, properties.getJobGroup());
+ return 1;
}
/**
* 更新任务
- *
- * @param job 任务对象
+ *
+ * @param job 任务对象
* @param jobGroup 任务组名
*/
- public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException
- {
+ public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException {
Long jobId = job.getJobId();
// 判断是否存在
JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
- if (scheduler.checkExists(jobKey))
- {
+ if (scheduler.checkExists(jobKey)) {
// 防止创建时存在数据问题 先移除,然后在执行创建操作
scheduler.deleteJob(jobKey);
}
@@ -244,13 +237,12 @@ public class SysJobServiceImpl implements ISysJobService
/**
* 校验cron表达式是否有效
- *
+ *
* @param cronExpression 表达式
* @return 结果
*/
@Override
- public boolean checkCronExpressionIsValid(String cronExpression)
- {
+ public boolean checkCronExpressionIsValid(String cronExpression) {
return CronUtils.isValid(cronExpression);
}
}
\ No newline at end of file
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictData.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictData.java
index 5bd7f6b4b..3d6ae3ae8 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictData.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDictData.java
@@ -19,6 +19,14 @@ import javax.validation.constraints.Size;
@Entity
@Table(name = "sys_dict_data")
public class SysDictData extends BaseEntity {
+
+ public SysDictData() {
+ }
+
+ public SysDictData(Long id) {
+ this.dictCode = id;
+ }
+
private static final long serialVersionUID = 1L;
/**
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java
index 331a37931..9a9fd1950 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java
@@ -1,197 +1,222 @@
package com.ruoyi.system.domain;
-import javax.validation.constraints.*;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
+import com.ruoyi.common.annotation.DataScopes;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.ColumnType;
import com.ruoyi.common.core.domain.BaseEntity;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+import javax.persistence.*;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
/**
* 角色表 sys_role
- *
+ *
* @author ruoyi
*/
-public class SysRole extends BaseEntity
-{
+@Entity
+@Table(name = "sys_role")
+public class SysRole extends BaseEntity {
private static final long serialVersionUID = 1L;
- /** 角色ID */
+ /**
+ * 角色ID
+ */
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
@Excel(name = "角色序号", cellType = ColumnType.NUMERIC)
private Long roleId;
- /** 角色名称 */
+ /**
+ * 角色名称
+ */
@Excel(name = "角色名称")
private String roleName;
- /** 角色权限 */
+ /**
+ * 角色权限
+ */
@Excel(name = "角色权限")
private String roleKey;
- /** 角色排序 */
+ /**
+ * 角色排序
+ */
@Excel(name = "角色排序", cellType = ColumnType.NUMERIC)
- private String roleSort;
+ private Integer roleSort;
- /** 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限) */
+ /**
+ * 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限)
+ */
@Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限")
- private String dataScope;
+ @Enumerated(value = EnumType.ORDINAL)
+ private DataScopes dataScope;
- /** 角色状态(0正常 1停用) */
+ /**
+ * 角色状态(0正常 1停用)
+ */
@Excel(name = "角色状态", readConverterExp = "0=正常,1=停用")
private String status;
- /** 删除标志(0代表存在 2代表删除) */
- private String delFlag;
+ /**
+ * 删除标志(0代表存在 2代表删除)
+ */
+ private String delFlag = BaseEntity.NOT_DELETED;
- /** 用户是否存在此角色标识 默认不存在 */
+ /**
+ * 用户是否存在此角色标识 默认不存在
+ */
+ @Transient
private boolean flag = false;
- /** 菜单组 */
- private Long[] menuIds;
+ @OneToMany(fetch = FetchType.LAZY)
+ @JoinTable(name = "sys_role_dept",
+ joinColumns = @JoinColumn(name = "roleId", referencedColumnName = "roleId"),
+ inverseJoinColumns = @JoinColumn(name = "deptId", referencedColumnName = "deptId"))
+ @org.hibernate.annotations.ForeignKey(name = "none")
+ private List depts;
- /** 部门组(数据权限) */
- private Long[] deptIds;
+ @ManyToMany(fetch = FetchType.LAZY)
+ @JoinTable(name = "sys_role_menu",
+ joinColumns = @JoinColumn(name = "roleId", referencedColumnName = "roleId"),
+ inverseJoinColumns = @JoinColumn(name = "menuId", referencedColumnName = "menuId"))
+ @org.hibernate.annotations.ForeignKey(name = "none")
+ private Set menus;
- public SysRole()
- {
+ public SysRole() {
}
- public SysRole(Long roleId)
- {
+ public SysRole(Long roleId) {
this.roleId = roleId;
}
- public Long getRoleId()
- {
+ public Long getRoleId() {
return roleId;
}
- public void setRoleId(Long roleId)
- {
+ public void setRoleId(Long roleId) {
this.roleId = roleId;
}
- public boolean isAdmin()
- {
+ public boolean isAdmin() {
return isAdmin(this.roleId);
}
- public static boolean isAdmin(Long roleId)
- {
+ public static boolean isAdmin(Long roleId) {
return roleId != null && 1L == roleId;
}
- public String getDataScope()
- {
+ public DataScopes getDataScope() {
return dataScope;
}
- public void setDataScope(String dataScope)
- {
+ public void setDataScope(DataScopes dataScope) {
this.dataScope = dataScope;
}
@NotBlank(message = "角色名称不能为空")
@Size(min = 0, max = 30, message = "角色名称长度不能超过30个字符")
- public String getRoleName()
- {
+ public String getRoleName() {
return roleName;
}
- public void setRoleName(String roleName)
- {
+ public void setRoleName(String roleName) {
this.roleName = roleName;
}
@NotBlank(message = "权限字符不能为空")
@Size(min = 0, max = 100, message = "权限字符长度不能超过100个字符")
- public String getRoleKey()
- {
+ public String getRoleKey() {
return roleKey;
}
- public void setRoleKey(String roleKey)
- {
+ public void setRoleKey(String roleKey) {
this.roleKey = roleKey;
}
- @NotBlank(message = "显示顺序不能为空")
- public String getRoleSort()
- {
+ @NotNull(message = "显示顺序不能为空")
+ public Integer getRoleSort() {
return roleSort;
}
- public void setRoleSort(String roleSort)
- {
+ public void setRoleSort(Integer roleSort) {
this.roleSort = roleSort;
}
- public String getStatus()
- {
+ public String getStatus() {
return status;
}
- public String getDelFlag()
- {
+ public String getDelFlag() {
return delFlag;
}
- public void setDelFlag(String delFlag)
- {
+ public void setDelFlag(String delFlag) {
this.delFlag = delFlag;
}
- public void setStatus(String status)
- {
+ public void setStatus(String status) {
this.status = status;
}
- public boolean isFlag()
- {
+ public boolean isFlag() {
return flag;
}
- public void setFlag(boolean flag)
- {
+ public void setFlag(boolean flag) {
this.flag = flag;
}
- public Long[] getMenuIds()
- {
- return menuIds;
+ public List getDepts() {
+ return depts;
}
- public void setMenuIds(Long[] menuIds)
- {
- this.menuIds = menuIds;
+ public void setDepts(List depts) {
+ this.depts = depts;
}
- public Long[] getDeptIds()
- {
- return deptIds;
+ public Set getMenus() {
+ return menus;
}
- public void setDeptIds(Long[] deptIds)
- {
- this.deptIds = deptIds;
+ public void setMenus(Set menus) {
+ this.menus = menus;
+ }
+
+ public String toString() {
+ return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+ .append("roleId", getRoleId())
+ .append("roleName", getRoleName())
+ .append("roleKey", getRoleKey())
+ .append("roleSort", getRoleSort())
+ .append("dataScope", getDataScope())
+ .append("status", getStatus())
+ .append("delFlag", getDelFlag())
+ .append("createBy", getCreateBy())
+ .append("createTime", getCreateTime())
+ .append("updateBy", getUpdateBy())
+ .append("updateTime", getUpdateTime())
+ .append("remark", getRemark())
+ .toString();
}
@Override
- public String toString() {
- return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
- .append("roleId", getRoleId())
- .append("roleName", getRoleName())
- .append("roleKey", getRoleKey())
- .append("roleSort", getRoleSort())
- .append("dataScope", getDataScope())
- .append("status", getStatus())
- .append("delFlag", getDelFlag())
- .append("createBy", getCreateBy())
- .append("createTime", getCreateTime())
- .append("updateBy", getUpdateBy())
- .append("updateTime", getUpdateTime())
- .append("remark", getRemark())
- .toString();
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ SysRole sysRole = (SysRole) o;
+ return Objects.equals(roleId, sysRole.roleId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(roleId);
}
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleDept.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleDept.java
deleted file mode 100644
index aaaa06e4c..000000000
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleDept.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.ruoyi.system.domain;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
-/**
- * 角色和部门关联 sys_role_dept
- *
- * @author ruoyi
- */
-public class SysRoleDept {
- /**
- * 角色ID
- */
- private Long roleId;
-
- /**
- * 部门ID
- */
- private Long deptId;
-
- public Long getRoleId() {
- return roleId;
- }
-
- public void setRoleId(Long roleId) {
- this.roleId = roleId;
- }
-
- public Long getDeptId() {
- return deptId;
- }
-
- public void setDeptId(Long deptId) {
- this.deptId = deptId;
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
- .append("roleId", getRoleId())
- .append("deptId", getDeptId())
- .toString();
- }
-}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java
index 10d8ea9a0..b3bc52e3a 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java
@@ -1,366 +1,173 @@
package com.ruoyi.system.domain;
-import java.util.Date;
-import java.util.List;
-import javax.validation.constraints.*;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.ColumnType;
import com.ruoyi.common.annotation.Excel.Type;
import com.ruoyi.common.annotation.Excels;
import com.ruoyi.common.core.domain.BaseEntity;
+import lombok.Data;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import org.hibernate.annotations.DynamicUpdate;
+import org.hibernate.annotations.ForeignKey;
+import org.hibernate.annotations.SelectBeforeUpdate;
+
+import javax.persistence.*;
+import javax.validation.constraints.Email;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Size;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
/**
* 用户对象 sys_user
- *
+ *
* @author ruoyi
*/
-public class SysUser extends BaseEntity
-{
+@Data
+@Entity
+@Table(name = "sys_user")
+@DynamicUpdate
+@SelectBeforeUpdate
+public class SysUser extends BaseEntity {
private static final long serialVersionUID = 1L;
- /** 用户ID */
+ /**
+ * 用户ID
+ */
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
@Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
private Long userId;
- /** 部门ID */
- @Excel(name = "部门编号", type = Type.IMPORT)
- private Long deptId;
-
- /** 部门父ID */
- private Long parentId;
-
- /** 角色ID */
- private Long roleId;
-
- /** 登录名称 */
+ /**
+ * 登录名称
+ */
+ @NotBlank(message = "登录账号不能为空")
+ @Size(min = 0, max = 30, message = "登录账号长度不能超过30个字符")
@Excel(name = "登录名称")
private String loginName;
- /** 用户名称 */
+ /**
+ * 用户名称
+ */
+ @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
@Excel(name = "用户名称")
private String userName;
+ /**
+ * 用户邮箱
+ */
+ @Email(message = "邮箱格式不正确")
+ @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
+ @Excel(name = "用户邮箱")
+ private String email;
+
+ /**
+ * 手机号码
+ */
+ @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
+ @Excel(name = "手机号码")
+ private String phonenumber;
+
+ /**
+ * 用户性别
+ */
+ @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
+ private String sex;
+
+ /**
+ * 用户头像
+ */
+ private String avatar;
+
+ /**
+ * 密码
+ */
+ private String password;
+
+ /**
+ * 盐加密
+ */
+ private String salt;
+
+ /**
+ * 帐号状态(0正常 1停用)
+ */
+ @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
+ private String status;
+
+ /**
+ * 删除标志(0代表存在 2代表删除)
+ */
+ private String delFlag;
+
+ /**
+ * 最后登陆IP
+ */
+ @Excel(name = "最后登陆IP", type = Type.EXPORT)
+ private String loginIp;
+
+ /**
+ * 最后登陆时间
+ */
+ @Excel(name = "最后登陆时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
+ private Date loginDate;
+
/** 用户类型 */
private String userType;
- /** 用户邮箱 */
- @Excel(name = "用户邮箱")
- private String email;
-
- /** 手机号码 */
- @Excel(name = "手机号码")
- private String phonenumber;
-
- /** 用户性别 */
- @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
- private String sex;
-
- /** 用户头像 */
- private String avatar;
-
- /** 密码 */
- private String password;
-
- /** 盐加密 */
- private String salt;
-
- /** 帐号状态(0正常 1停用) */
- @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
- private String status;
-
- /** 删除标志(0代表存在 2代表删除) */
- private String delFlag;
-
- /** 最后登陆IP */
- @Excel(name = "最后登陆IP", type = Type.EXPORT)
- private String loginIp;
-
- /** 最后登陆时间 */
- @Excel(name = "最后登陆时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
- private Date loginDate;
-
- /** 部门对象 */
+ /**
+ * 部门对象
+ */
@Excels({
- @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
- @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
+ @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
+ @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
})
+ @ManyToOne
+ @JoinColumn(name = "dept_id", referencedColumnName = "deptId")
+ @ForeignKey(name = "none")
private SysDept dept;
- private List roles;
+ @ManyToMany(fetch = FetchType.LAZY)
+ @JoinTable(name = "sys_user_role",
+ joinColumns = @JoinColumn(name = "userId", referencedColumnName = "userId"),
+ inverseJoinColumns = @JoinColumn(name = "roleId", referencedColumnName = "roleId"))
+ @ForeignKey(name = "none")
+ private Set roles = new HashSet<>();
- /** 角色组 */
- private Long[] roleIds;
+ @ManyToMany(fetch = FetchType.LAZY)
+ @JoinTable(name = "sys_user_post",
+ inverseJoinColumns = @JoinColumn(name = "postId", referencedColumnName = "postId"),
+ joinColumns = @JoinColumn(name = "userId", referencedColumnName = "userId"))
+ @org.hibernate.annotations.ForeignKey(name = "none")
+ private Set posts = new HashSet<>();
- /** 岗位组 */
- private Long[] postIds;
- public SysUser()
- {
+
+ public SysUser() {
}
- public SysUser(Long userId)
- {
+ public SysUser(Long userId) {
this.userId = userId;
}
- public Long getUserId()
- {
- return userId;
- }
-
- public void setUserId(Long userId)
- {
- this.userId = userId;
- }
-
- public boolean isAdmin()
- {
+ @Transient
+ public boolean isAdmin() {
return isAdmin(this.userId);
}
- public static boolean isAdmin(Long userId)
- {
+ @Transient
+ public static boolean isAdmin(Long userId) {
return userId != null && 1L == userId;
}
- public Long getDeptId()
- {
- return deptId;
- }
-
- public void setDeptId(Long deptId)
- {
- this.deptId = deptId;
- }
-
- public Long getParentId()
- {
- return parentId;
- }
-
- public void setParentId(Long parentId)
- {
- this.parentId = parentId;
- }
-
- public Long getRoleId()
- {
- return roleId;
- }
-
- public void setRoleId(Long roleId)
- {
- this.roleId = roleId;
- }
-
- @NotBlank(message = "登录账号不能为空")
- @Size(min = 0, max = 30, message = "登录账号长度不能超过30个字符")
- public String getLoginName()
- {
- return loginName;
- }
-
- public void setLoginName(String loginName)
- {
- this.loginName = loginName;
- }
-
- @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
- public String getUserName()
- {
- return userName;
- }
-
- public void setUserName(String userName)
- {
- this.userName = userName;
- }
-
- public String getUserType()
- {
- return userType;
- }
-
- public void setUserType(String userType)
- {
- this.userType = userType;
- }
-
- @Email(message = "邮箱格式不正确")
- @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
- public String getEmail()
- {
- return email;
- }
-
- public void setEmail(String email)
- {
- this.email = email;
- }
-
- @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
- public String getPhonenumber()
- {
- return phonenumber;
- }
-
- public void setPhonenumber(String phonenumber)
- {
- this.phonenumber = phonenumber;
- }
-
- public String getSex()
- {
- return sex;
- }
-
- public void setSex(String sex)
- {
- this.sex = sex;
- }
-
- public String getAvatar()
- {
- return avatar;
- }
-
- public void setAvatar(String avatar)
- {
- this.avatar = avatar;
- }
-
- public String getPassword()
- {
- return password;
- }
-
- public void setPassword(String password)
- {
- this.password = password;
- }
-
- public String getSalt()
- {
- return salt;
- }
-
- public void setSalt(String salt)
- {
- this.salt = salt;
- }
-
- public String getStatus()
- {
- return status;
- }
-
- public void setStatus(String status)
- {
- this.status = status;
- }
-
- public String getDelFlag()
- {
- return delFlag;
- }
-
- public void setDelFlag(String delFlag)
- {
- this.delFlag = delFlag;
- }
-
- public String getLoginIp()
- {
- return loginIp;
- }
-
- public void setLoginIp(String loginIp)
- {
- this.loginIp = loginIp;
- }
-
- public Date getLoginDate()
- {
- return loginDate;
- }
-
- public void setLoginDate(Date loginDate)
- {
- this.loginDate = loginDate;
- }
-
- public SysDept getDept()
- {
- if (dept == null)
- {
+ public SysDept getDept() {
+ if (dept == null) {
dept = new SysDept();
}
return dept;
}
-
- public void setDept(SysDept dept)
- {
- this.dept = dept;
- }
-
- public List getRoles()
- {
- return roles;
- }
-
- public void setRoles(List roles)
- {
- this.roles = roles;
- }
-
- public Long[] getRoleIds()
- {
- return roleIds;
- }
-
- public void setRoleIds(Long[] roleIds)
- {
- this.roleIds = roleIds;
- }
-
- public Long[] getPostIds()
- {
- return postIds;
- }
-
- public void setPostIds(Long[] postIds)
- {
- this.postIds = postIds;
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
- .append("userId", getUserId())
- .append("deptId", getDeptId())
- .append("loginName", getLoginName())
- .append("userName", getUserName())
- .append("userType", getUserType())
- .append("email", getEmail())
- .append("phonenumber", getPhonenumber())
- .append("sex", getSex())
- .append("avatar", getAvatar())
- .append("password", getPassword())
- .append("salt", getSalt())
- .append("status", getStatus())
- .append("delFlag", getDelFlag())
- .append("loginIp", getLoginIp())
- .append("loginDate", getLoginDate())
- .append("createBy", getCreateBy())
- .append("createTime", getCreateTime())
- .append("updateBy", getUpdateBy())
- .append("updateTime", getUpdateTime())
- .append("remark", getRemark())
- .append("dept", getDept())
- .append("roles", getRoles())
- .toString();
- }
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java
deleted file mode 100644
index 894ee9a84..000000000
--- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java
+++ /dev/null
@@ -1,117 +0,0 @@
-package com.ruoyi.system.mapper;
-
-import java.util.List;
-import org.apache.ibatis.annotations.Param;
-import com.ruoyi.system.domain.SysDept;
-
-/**
- * 部门管理 数据层
- *
- * @author ruoyi
- */
-public interface SysDeptMapper
-{
- /**
- * 查询部门人数
- *
- * @param dept 部门信息
- * @return 结果
- */
- public int selectDeptCount(SysDept dept);
-
- /**
- * 查询部门是否存在用户
- *
- * @param deptId 部门ID
- * @return 结果
- */
- public int checkDeptExistUser(Long deptId);
-
- /**
- * 查询部门管理数据
- *
- * @param dept 部门信息
- * @return 部门信息集合
- */
- public List selectDeptList(SysDept dept);
-
- /**
- * 删除部门管理信息
- *
- * @param deptId 部门ID
- * @return 结果
- */
- public int deleteDeptById(Long deptId);
-
- /**
- * 新增部门信息
- *
- * @param dept 部门信息
- * @return 结果
- */
- public int insertDept(SysDept dept);
-
- /**
- * 修改部门信息
- *
- * @param dept 部门信息
- * @return 结果
- */
- public int updateDept(SysDept dept);
-
- /**
- * 修改子元素关系
- *
- * @param depts 子元素
- * @return 结果
- */
- public int updateDeptChildren(@Param("depts") List depts);
-
- /**
- * 根据部门ID查询信息
- *
- * @param deptId 部门ID
- * @return 部门信息
- */
- public SysDept selectDeptById(Long deptId);
-
- /**
- * 校验部门名称是否唯一
- *
- * @param deptName 部门名称
- * @param parentId 父部门ID
- * @return 结果
- */
- public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId);
-
- /**
- * 根据角色ID查询部门
- *
- * @param roleId 角色ID
- * @return 部门列表
- */
- public List selectRoleDeptTree(Long roleId);
-
- /**
- * 修改所在部门的父级部门状态
- *
- * @param dept 部门
- */
- public void updateDeptStatus(SysDept dept);
-
- /**
- * 根据ID查询所有子部门
- *
- * @param deptId 部门ID
- * @return 部门列表
- */
- public List selectChildrenDeptById(Long deptId);
-
- /**
- * 根据ID查询所有子部门(正常状态)
- *
- * @param deptId 部门ID
- * @return 子部门数
- */
- public int selectNormalChildrenDeptById(Long deptId);
-}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java
deleted file mode 100644
index 669d1ec3d..000000000
--- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package com.ruoyi.system.mapper;
-
-import java.util.List;
-import org.apache.ibatis.annotations.Param;
-import com.ruoyi.system.domain.SysUserRole;
-
-/**
- * 用户与角色关联表 数据层
- *
- * @author ruoyi
- */
-public interface SysUserRoleMapper
-{
- /**
- * 通过用户ID查询用户和角色关联
- *
- * @param userId 用户ID
- * @return 用户和角色关联列表
- */
- public List selectUserRoleByUserId(Long userId);
-
- /**
- * 通过用户ID删除用户和角色关联
- *
- * @param userId 用户ID
- * @return 结果
- */
- public int deleteUserRoleByUserId(Long userId);
-
- /**
- * 批量删除用户和角色关联
- *
- * @param ids 需要删除的数据ID
- * @return 结果
- */
- public int deleteUserRole(Long[] ids);
-
- /**
- * 通过角色ID查询角色使用数量
- *
- * @param roleId 角色ID
- * @return 结果
- */
- public int countUserRoleByRoleId(Long roleId);
-
- /**
- * 批量新增用户角色信息
- *
- * @param userRoleList 用户角色列表
- * @return 结果
- */
- public int batchUserRole(List userRoleList);
-
- /**
- * 删除用户和角色关联信息
- *
- * @param userRole 用户和角色关联信息
- * @return 结果
- */
- public int deleteUserRoleInfo(SysUserRole userRole);
-
- /**
- * 批量取消授权用户角色
- *
- * @param roleId 角色ID
- * @param userIds 需要删除的用户数据ID
- * @return 结果
- */
- public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
-}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
index c70db288a..f86ece9e7 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
@@ -1,18 +1,20 @@
package com.ruoyi.system.service;
import java.util.List;
+
import com.ruoyi.system.domain.SysConfig;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
/**
* 参数配置 服务层
- *
+ *
* @author ruoyi
*/
-public interface ISysConfigService
-{
+public interface ISysConfigService {
/**
* 查询参数配置信息
- *
+ *
* @param configId 参数配置ID
* @return 参数配置信息
*/
@@ -20,7 +22,7 @@ public interface ISysConfigService
/**
* 根据键名查询参数配置信息
- *
+ *
* @param configKey 参数键名
* @return 参数键值
*/
@@ -28,15 +30,15 @@ public interface ISysConfigService
/**
* 查询参数配置列表
- *
+ *
* @param config 参数配置信息
* @return 参数配置集合
*/
- public List selectConfigList(SysConfig config);
+ public Page selectConfigList(SysConfig config, Pageable pageable);
/**
* 新增参数配置
- *
+ *
* @param config 参数配置信息
* @return 结果
*/
@@ -44,7 +46,7 @@ public interface ISysConfigService
/**
* 修改参数配置
- *
+ *
* @param config 参数配置信息
* @return 结果
*/
@@ -52,22 +54,19 @@ public interface ISysConfigService
/**
* 批量删除参数配置信息
- *
+ *
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteConfigByIds(String ids);
- /**
- * 清空缓存数据
- */
- public void clearCache();
-
/**
* 校验参数键名是否唯一
- *
+ *
* @param config 参数信息
* @return 结果
*/
public String checkConfigKeyUnique(SysConfig config);
+
+ void clearCache();
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
index d7fa5f501..9373bb839 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
@@ -1,41 +1,35 @@
package com.ruoyi.system.service;
-import java.util.List;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.domain.SysRole;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
/**
* 部门管理 服务层
- *
+ *
* @author ruoyi
*/
-public interface ISysDeptService
-{
+public interface ISysDeptService {
/**
* 查询部门管理数据
- *
+ *
* @param dept 部门信息
* @return 部门信息集合
*/
- public List selectDeptList(SysDept dept);
+ public Page selectDeptList(SysDept dept, Pageable pageable);
/**
* 查询部门管理树
- *
+ *
* @param dept 部门信息
* @return 所有部门信息
*/
public List selectDeptTree(SysDept dept);
- /**
- * 查询部门管理树(排除下级)
- *
- * @param dept 部门信息
- * @return 所有部门信息
- */
- public List selectDeptTreeExcludeChild(SysDept dept);
-
/**
* 根据角色ID查询菜单
*
@@ -45,16 +39,16 @@ public interface ISysDeptService
public List roleDeptTreeData(SysRole role);
/**
- * 查询部门人数
- *
- * @param parentId 父部门ID
+ * 查询下级部门数量
+ *
+ * @param deptId 部门ID
* @return 结果
*/
- public int selectDeptCount(Long parentId);
+ public int countChildren(Long deptId);
/**
* 查询部门是否存在用户
- *
+ *
* @param deptId 部门ID
* @return 结果 true 存在 false 不存在
*/
@@ -62,47 +56,39 @@ public interface ISysDeptService
/**
* 删除部门管理信息
- *
+ *
* @param deptId 部门ID
* @return 结果
*/
- public int deleteDeptById(Long deptId);
+ public void deleteDeptById(Long deptId);
/**
* 新增保存部门信息
- *
+ *
* @param dept 部门信息
* @return 结果
*/
- public int insertDept(SysDept dept);
+ public SysDept insertDept(SysDept dept);
/**
* 修改保存部门信息
- *
+ *
* @param dept 部门信息
* @return 结果
*/
- public int updateDept(SysDept dept);
+ public SysDept updateDept(SysDept dept);
/**
* 根据部门ID查询信息
- *
+ *
* @param deptId 部门ID
* @return 部门信息
*/
public SysDept selectDeptById(Long deptId);
- /**
- * 根据ID查询所有子部门(正常状态)
- *
- * @param deptId 部门ID
- * @return 子部门数
- */
- public int selectNormalChildrenDeptById(Long deptId);
-
/**
* 校验部门名称是否唯一
- *
+ *
* @param dept 部门信息
* @return 结果
*/
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java
index a92936992..74b2a09c2 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java
@@ -1,27 +1,38 @@
package com.ruoyi.system.service;
-import java.util.List;
import com.ruoyi.system.domain.SysDictData;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
/**
* 字典 业务层
- *
+ *
* @author ruoyi
*/
-public interface ISysDictDataService
-{
+public interface ISysDictDataService {
/**
* 根据条件分页查询字典数据
- *
+ *
* @param dictData 字典数据信息
* @return 字典数据集合信息
*/
- public List selectDictDataList(SysDictData dictData);
+ public Page selectDictDataList(SysDictData dictData, Pageable pageable);
+
+ /**
+ * 根据字典类型查询字典数据
+ *
+ * @param dictType 字典类型
+ * @return 字典数据集合信息
+ */
+ public List selectDictDataByType(String dictType);
+
/**
* 根据字典类型和字典键值查询字典数据信息
- *
- * @param dictType 字典类型
+ *
+ * @param dictType 字典类型
* @param dictValue 字典键值
* @return 字典标签
*/
@@ -29,15 +40,23 @@ public interface ISysDictDataService
/**
* 根据字典数据ID查询信息
- *
+ *
* @param dictCode 字典数据ID
* @return 字典数据
*/
public SysDictData selectDictDataById(Long dictCode);
+ /**
+ * 通过字典ID删除字典数据信息
+ *
+ * @param dictCode 字典数据ID
+ * @return 结果
+ */
+ public int deleteDictDataById(Long dictCode);
+
/**
* 批量删除字典数据
- *
+ *
* @param ids 需要删除的数据
* @return 结果
*/
@@ -45,7 +64,7 @@ public interface ISysDictDataService
/**
* 新增保存字典数据信息
- *
+ *
* @param dictData 字典数据信息
* @return 结果
*/
@@ -53,7 +72,7 @@ public interface ISysDictDataService
/**
* 修改保存字典数据信息
- *
+ *
* @param dictData 字典数据信息
* @return 结果
*/
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java
index 495f0a8fd..d9447465b 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java
@@ -1,43 +1,36 @@
package com.ruoyi.system.service;
-import java.util.List;
import com.ruoyi.common.core.domain.Ztree;
-import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.domain.SysDictType;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
/**
* 字典 业务层
- *
+ *
* @author ruoyi
*/
-public interface ISysDictTypeService
-{
+public interface ISysDictTypeService {
/**
* 根据条件分页查询字典类型
- *
+ *
* @param dictType 字典类型信息
* @return 字典类型集合信息
*/
- public List selectDictTypeList(SysDictType dictType);
+ public Page selectDictTypeList(SysDictType dictType, Pageable pageable);
/**
* 根据所有字典类型
- *
+ *
* @return 字典类型集合信息
*/
public List selectDictTypeAll();
- /**
- * 根据字典类型查询字典数据
- *
- * @param dictType 字典类型
- * @return 字典数据集合信息
- */
- public List selectDictDataByType(String dictType);
-
/**
* 根据字典类型ID查询信息
- *
+ *
* @param dictId 字典类型ID
* @return 字典类型
*/
@@ -45,29 +38,32 @@ public interface ISysDictTypeService
/**
* 根据字典类型查询信息
- *
+ *
* @param dictType 字典类型
* @return 字典类型
*/
public SysDictType selectDictTypeByType(String dictType);
+ /**
+ * 通过字典ID删除字典信息
+ *
+ * @param dictId 字典ID
+ * @return 结果
+ */
+ public int deleteDictTypeById(Long dictId);
+
/**
* 批量删除字典类型
- *
+ *
* @param ids 需要删除的数据
* @return 结果
* @throws Exception 异常
*/
- public int deleteDictTypeByIds(String ids);
-
- /**
- * 清空缓存数据
- */
- public void clearCache();
+ public int deleteDictTypeByIds(String ids) throws Exception;
/**
* 新增保存字典类型信息
- *
+ *
* @param dictType 字典类型信息
* @return 结果
*/
@@ -75,7 +71,7 @@ public interface ISysDictTypeService
/**
* 修改保存字典类型信息
- *
+ *
* @param dictType 字典类型信息
* @return 结果
*/
@@ -83,7 +79,7 @@ public interface ISysDictTypeService
/**
* 校验字典类型称是否唯一
- *
+ *
* @param dictType 字典类型
* @return 结果
*/
@@ -91,9 +87,11 @@ public interface ISysDictTypeService
/**
* 查询字典类型树
- *
+ *
* @param dictType 字典类型
* @return 所有字典类型
*/
public List selectDictTree(SysDictType dictType);
+
+ void clearCache();
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
index db698cd24..5eb625dfd 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java
@@ -1,43 +1,48 @@
package com.ruoyi.system.service;
-import java.util.List;
+import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.domain.SysUser;
-import com.ruoyi.system.domain.SysUserRole;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+import java.util.Set;
/**
* 用户 业务层
- *
+ *
* @author ruoyi
*/
-public interface ISysUserService
-{
+public interface ISysUserService {
/**
* 根据条件分页查询用户列表
- *
+ *
* @param user 用户信息
+ * @param pageRequest
* @return 用户信息集合信息
*/
- public List selectUserList(SysUser user);
+ public Page selectUserList(SysUser user, Pageable pageRequest);
/**
* 根据条件分页查询已分配用户角色列表
- *
+ *
* @param user 用户信息
+ * @param pageRequest
* @return 用户信息集合信息
*/
- public List selectAllocatedList(SysUser user);
+ public Page selectAllocatedList(SysUser user, Pageable pageRequest);
/**
* 根据条件分页查询未分配用户角色列表
- *
+ *
* @param user 用户信息
* @return 用户信息集合信息
*/
- public List selectUnallocatedList(SysUser user);
+ public Page selectUnallocatedList(SysUser user, Pageable pageable);
/**
* 通过用户名查询用户
- *
+ *
* @param userName 用户名
* @return 用户对象信息
*/
@@ -45,7 +50,7 @@ public interface ISysUserService
/**
* 通过手机号码查询用户
- *
+ *
* @param phoneNumber 手机号码
* @return 用户对象信息
*/
@@ -53,7 +58,7 @@ public interface ISysUserService
/**
* 通过邮箱查询用户
- *
+ *
* @param email 邮箱
* @return 用户对象信息
*/
@@ -61,23 +66,17 @@ public interface ISysUserService
/**
* 通过用户ID查询用户
- *
+ *
* @param userId 用户ID
* @return 用户对象信息
*/
public SysUser selectUserById(Long userId);
- /**
- * 通过用户ID查询用户和角色关联
- *
- * @param userId 用户ID
- * @return 用户和角色关联列表
- */
- public List selectUserRoleByUserId(Long userId);
+ public SysUser selectUserWithRolesAndPostsById(Long userId);
/**
* 通过用户ID删除用户
- *
+ *
* @param userId 用户ID
* @return 结果
*/
@@ -85,7 +84,7 @@ public interface ISysUserService
/**
* 批量删除用户信息
- *
+ *
* @param ids 需要删除的数据ID
* @return 结果
* @throws Exception 异常
@@ -94,55 +93,39 @@ public interface ISysUserService
/**
* 保存用户信息
- *
+ *
* @param user 用户信息
* @return 结果
*/
- public int insertUser(SysUser user);
-
- /**
- * 注册用户信息
- *
- * @param user 用户信息
- * @return 结果
- */
- public boolean registerUser(SysUser user);
+ public SysUser insertUser(SysUser user);
/**
* 保存用户信息
- *
+ *
* @param user 用户信息
* @return 结果
*/
- public int updateUser(SysUser user);
+ public SysUser updateUser(SysUser user);
/**
* 修改用户详细信息
- *
+ *
* @param user 用户信息
* @return 结果
*/
- public int updateUserInfo(SysUser user);
-
- /**
- * 用户授权角色
- *
- * @param userId 用户ID
- * @param roleIds 角色组
- */
- public void insertUserAuth(Long userId, Long[] roleIds);
+ public SysUser updateUserInfo(SysUser user);
/**
* 修改用户密码信息
- *
+ *
* @param user 用户信息
* @return 结果
*/
- public int resetUserPwd(SysUser user);
+ public SysUser resetUserPwd(SysUser user);
/**
* 校验用户名称是否唯一
- *
+ *
* @param loginName 登录名称
* @return 结果
*/
@@ -166,42 +149,38 @@ public interface ISysUserService
/**
* 校验用户是否允许操作
- *
+ *
* @param user 用户信息
*/
public void checkUserAllowed(SysUser user);
- /**
- * 根据用户ID查询用户所属角色组
- *
- * @param userId 用户ID
- * @return 结果
- */
- public String selectUserRoleGroup(Long userId);
-
- /**
- * 根据用户ID查询用户所属岗位组
- *
- * @param userId 用户ID
- * @return 结果
- */
- public String selectUserPostGroup(Long userId);
-
/**
* 导入用户数据
- *
- * @param userList 用户数据列表
+ *
+ * @param userList 用户数据列表
* @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
- * @param operName 操作用户
+ * @param operName 操作用户
* @return 结果
*/
public String importUser(List userList, Boolean isUpdateSupport, String operName);
/**
* 用户状态修改
- *
+ *
* @param user 用户信息
* @return 结果
*/
- public int changeStatus(SysUser user);
+ public void changeStatus(SysUser user);
+
+ Set getUserRoleDepts(Long userId);
+
+ /**
+ * 注册用户信息
+ *
+ * @param user 用户信息
+ * @return 结果
+ */
+ public SysUser registerUser(SysUser user);
+
+ void insertUserAuth(Long userId, Long[] roleIds);
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
index 9ba91957c..f44bd3a1b 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
@@ -1,200 +1,147 @@
package com.ruoyi.system.service.impl;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import com.ruoyi.common.constant.Constants;
+import com.querydsl.core.types.ExpressionUtils;
+import com.querydsl.core.types.Predicate;
+import com.ruoyi.common.base.BaseService;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.text.Convert;
-import com.ruoyi.common.exception.BusinessException;
-import com.ruoyi.common.utils.CacheUtils;
import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.domain.QSysConfig;
import com.ruoyi.system.domain.SysConfig;
-import com.ruoyi.system.mapper.SysConfigMapper;
+import com.ruoyi.system.repository.SysConfigRepository;
import com.ruoyi.system.service.ISysConfigService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
/**
* 参数配置 服务层实现
- *
+ *
* @author ruoyi
*/
@Service
-public class SysConfigServiceImpl implements ISysConfigService
-{
+public class SysConfigServiceImpl extends BaseService implements ISysConfigService {
@Autowired
- private SysConfigMapper configMapper;
-
- /**
- * 项目启动时,初始化参数到缓存
- */
- @PostConstruct
- public void init()
- {
- List configsList = configMapper.selectConfigList(new SysConfig());
- for (SysConfig config : configsList)
- {
- CacheUtils.put(getCacheName(), getCacheKey(config.getConfigKey()), config.getConfigValue());
- }
- }
+ private SysConfigRepository sysConfigRepository;
/**
* 查询参数配置信息
- *
+ *
* @param configId 参数配置ID
* @return 参数配置信息
*/
@Override
- public SysConfig selectConfigById(Long configId)
- {
- SysConfig config = new SysConfig();
- config.setConfigId(configId);
- return configMapper.selectConfig(config);
+ public SysConfig selectConfigById(Long configId) {
+ return sysConfigRepository.findById(configId).get();
}
/**
* 根据键名查询参数配置信息
- *
+ *
* @param configKey 参数key
* @return 参数键值
*/
@Override
- public String selectConfigByKey(String configKey)
- {
- String configValue = Convert.toStr(CacheUtils.get(getCacheName(), getCacheKey(configKey)));
- if (StringUtils.isNotEmpty(configValue))
- {
- return configValue;
- }
- SysConfig config = new SysConfig();
- config.setConfigKey(configKey);
- SysConfig retConfig = configMapper.selectConfig(config);
- if (StringUtils.isNotNull(retConfig))
- {
- CacheUtils.put(getCacheName(), getCacheKey(configKey), retConfig.getConfigValue());
- return retConfig.getConfigValue();
- }
- return StringUtils.EMPTY;
+ public String selectConfigByKey(String configKey) {
+ SysConfig retConfig = sysConfigRepository.findFirstByConfigKey(configKey);
+ return StringUtils.isNotNull(retConfig) ? retConfig.getConfigValue() : "";
}
/**
* 查询参数配置列表
- *
+ *
* @param config 参数配置信息
* @return 参数配置集合
*/
@Override
- public List selectConfigList(SysConfig config)
- {
- return configMapper.selectConfigList(config);
+ public Page selectConfigList(SysConfig config, Pageable pageable) {
+ return sysConfigRepository.findAll(getPredicate(config), pageable);
+ }
+
+ private Predicate getPredicate(SysConfig config){
+ QSysConfig qSysConfig = QSysConfig.sysConfig;
+ List predicates = new ArrayList<>();
+ if(StringUtils.isNotEmpty(config.getConfigName())){
+ predicates.add(buildLike(qSysConfig.configName, config.getConfigName()));
+ }
+ if(StringUtils.isNotEmpty(config.getConfigType())){
+ predicates.add(buildEqual(qSysConfig.configType, config.getConfigType()));
+ }
+ if(StringUtils.isNotEmpty(config.getConfigKey())){
+ predicates.add(buildLike(qSysConfig.configKey, config.getConfigKey()));
+ }
+ if(config.getStartTime() != null){
+ predicates.add(buildGreaterThanOrEqualTo(qSysConfig.createTime, config.getStartTime()));
+ }
+ if(config.getEndTime() != null){
+ predicates.add(buildLessThanOrEqualTo(qSysConfig.createTime, config.getEndTime()));
+ }
+ return ExpressionUtils.allOf(predicates);
}
/**
* 新增参数配置
- *
+ *
* @param config 参数配置信息
* @return 结果
*/
@Override
- public int insertConfig(SysConfig config)
- {
- int row = configMapper.insertConfig(config);
- if (row > 0)
- {
- CacheUtils.put(getCacheName(), getCacheKey(config.getConfigKey()), config.getConfigValue());
- }
- return row;
+ public int insertConfig(SysConfig config) {
+ sysConfigRepository.save(config);
+ return 1;
}
/**
* 修改参数配置
- *
+ *
* @param config 参数配置信息
* @return 结果
*/
@Override
- public int updateConfig(SysConfig config)
- {
- int row = configMapper.updateConfig(config);
- if (row > 0)
- {
- CacheUtils.put(getCacheName(), getCacheKey(config.getConfigKey()), config.getConfigValue());
- }
- return row;
+ public int updateConfig(SysConfig config) {
+ sysConfigRepository.save(config);
+ return 1;
}
/**
* 批量删除参数配置对象
- *
+ *
* @param ids 需要删除的数据ID
* @return 结果
*/
+ @Transactional
@Override
- public int deleteConfigByIds(String ids)
- {
- Long[] configIds = Convert.toLongArray(ids);
- for (Long configId : configIds)
- {
- SysConfig config = selectConfigById(configId);
- if (StringUtils.equals(UserConstants.YES, config.getConfigType()))
- {
- throw new BusinessException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
- }
- }
- int count = configMapper.deleteConfigByIds(Convert.toStrArray(ids));
- if (count > 0)
- {
-
- CacheUtils.removeAll(getCacheName());
- }
- return count;
- }
-
- /**
- * 清空缓存数据
- */
- @Override
- public void clearCache()
- {
- CacheUtils.removeAll(getCacheName());
+ public int deleteConfigByIds(String ids) {
+ sysConfigRepository.deleteByConfigIdIn(Arrays.asList(Convert.toLongArray(ids)));
+ return 1;
}
/**
* 校验参数键名是否唯一
- *
+ *
* @param config 参数配置信息
* @return 结果
*/
@Override
- public String checkConfigKeyUnique(SysConfig config)
- {
+ public String checkConfigKeyUnique(SysConfig config) {
Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId();
- SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey());
- if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue())
- {
+ SysConfig info = sysConfigRepository.findFirstByConfigKey(config.getConfigKey());
+ if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) {
return UserConstants.CONFIG_KEY_NOT_UNIQUE;
}
return UserConstants.CONFIG_KEY_UNIQUE;
}
- /**
- * 获取cache name
- *
- * @return 缓存名
- */
- private String getCacheName()
- {
- return Constants.SYS_CONFIG_CACHE;
- }
+ @CacheEvict(allEntries = true)
+ @Override
+ public void clearCache() {
- /**
- * 设置cache key
- *
- * @param configKey 参数键
- * @return 缓存键key
- */
- private String getCacheKey(String configKey)
- {
- return Constants.SYS_CONFIG_KEY + configKey;
}
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
index 6fcedb6d5..9bce70d19 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
@@ -1,83 +1,87 @@
package com.ruoyi.system.service.impl;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import org.apache.commons.lang3.ArrayUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import com.ruoyi.common.annotation.DataScope;
+import com.ruoyi.common.base.BaseService;
import com.ruoyi.common.constant.UserConstants;
+import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.domain.SysRole;
-import com.ruoyi.system.mapper.SysDeptMapper;
+import com.ruoyi.system.repository.SysDeptRepository;
+import com.ruoyi.system.repository.SysRoleRepository;
+import com.ruoyi.system.repository.SysUserRepository;
import com.ruoyi.system.service.ISysDeptService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import java.util.ArrayList;
+import java.util.List;
/**
* 部门管理 服务实现
- *
+ *
* @author ruoyi
*/
@Service
-public class SysDeptServiceImpl implements ISysDeptService
-{
+public class SysDeptServiceImpl extends BaseService implements ISysDeptService {
@Autowired
- private SysDeptMapper deptMapper;
+ private SysDeptRepository sysDeptRepository;
+ @Autowired
+ private SysUserRepository sysUserRepository;
+ @Autowired
+ private SysRoleRepository sysRoleRepository;
/**
* 查询部门管理数据
- *
+ *
* @param dept 部门信息
* @return 部门信息集合
*/
@Override
- @DataScope(deptAlias = "d")
- public List selectDeptList(SysDept dept)
- {
- return deptMapper.selectDeptList(dept);
+ public Page selectDeptList(SysDept dept, Pageable pageable) {
+ return sysDeptRepository.findAll(getSpecification(dept), pageable);
+ }
+
+ private Specification getSpecification(SysDept sysDept){
+ return new Specification() {
+ @Override
+ public Predicate toPredicate(Root root, CriteriaQuery> criteriaQuery, CriteriaBuilder criteriaBuilder) {
+ List predicates = new ArrayList<>();
+ if(StringUtils.isNotEmpty(sysDept.getDelFlag())){
+ predicates.add(criteriaBuilder.equal(root.get("delFlag").as(String.class), sysDept.getDelFlag()));
+ }
+ if(StringUtils.isNotEmpty(sysDept.getStatus())){
+ predicates.add(criteriaBuilder.equal(root.get("status").as(String.class), sysDept.getStatus()));
+ }
+ if(StringUtils.isNotEmpty(sysDept.getDeptName())){
+ predicates.add(criteriaBuilder.equal(root.get("deptName").as(String.class), "%" + sysDept.getDeptName() + "%"));
+ }
+ if(sysDept.getParent() != null && sysDept.getParent().getDeptId() != null){
+ predicates.add(criteriaBuilder.equal(root.get("parent").get("deptId").as(Long.class), sysDept.getParent().getDeptId()));
+ }
+ return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
+ }
+ };
}
/**
* 查询部门管理树
- *
+ *
* @param dept 部门信息
* @return 所有部门信息
*/
@Override
- @DataScope(deptAlias = "d")
- public List selectDeptTree(SysDept dept)
- {
- List deptList = deptMapper.selectDeptList(dept);
- List ztrees = initZtree(deptList);
- return ztrees;
- }
-
- /**
- * 查询部门管理树(排除下级)
- *
- * @param deptId 部门ID
- * @return 所有部门信息
- */
- @Override
- @DataScope(deptAlias = "d")
- public List selectDeptTreeExcludeChild(SysDept dept)
- {
- Long deptId = dept.getDeptId();
- List deptList = deptMapper.selectDeptList(dept);
- Iterator it = deptList.iterator();
- while (it.hasNext())
- {
- SysDept d = (SysDept) it.next();
- if (d.getDeptId().intValue() == deptId
- || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))
- {
- it.remove();
- }
- }
+ public List selectDeptTree(SysDept dept) {
+ List deptList = sysDeptRepository.findAll(getSpecification(dept));
List ztrees = initZtree(deptList);
return ztrees;
}
@@ -89,18 +93,14 @@ public class SysDeptServiceImpl implements ISysDeptService
* @return 部门列表(数据权限)
*/
@Override
- public List roleDeptTreeData(SysRole role)
- {
+ public List roleDeptTreeData(SysRole role) {
Long roleId = role.getRoleId();
- List ztrees = new ArrayList();
- List deptList = selectDeptList(new SysDept());
- if (StringUtils.isNotNull(roleId))
- {
- List roleDeptList = deptMapper.selectRoleDeptTree(roleId);
- ztrees = initZtree(deptList, roleDeptList);
- }
- else
- {
+ List ztrees;
+ List deptList = sysDeptRepository.findAll(getSpecification(new SysDept()));
+ if (StringUtils.isNotNull(roleId)) {
+ SysRole sysRole = sysRoleRepository.findByRoleId(roleId);
+ ztrees = initZtree(deptList, sysRole.getDepts());
+ } else {
ztrees = initZtree(deptList);
}
return ztrees;
@@ -112,35 +112,29 @@ public class SysDeptServiceImpl implements ISysDeptService
* @param deptList 部门列表
* @return 树结构列表
*/
- public List initZtree(List deptList)
- {
+ public List initZtree(List deptList) {
return initZtree(deptList, null);
}
/**
* 对象转部门树
*
- * @param deptList 部门列表
+ * @param deptList 部门列表
* @param roleDeptList 角色已存在菜单列表
* @return 树结构列表
*/
- public List initZtree(List deptList, List roleDeptList)
- {
-
+ public List initZtree(List deptList, List roleDeptList) {
List ztrees = new ArrayList();
boolean isCheck = StringUtils.isNotNull(roleDeptList);
- for (SysDept dept : deptList)
- {
- if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
- {
+ for (SysDept dept : deptList) {
+ if (UserConstants.DEPT_NORMAL.equals(dept.getStatus())) {
Ztree ztree = new Ztree();
ztree.setId(dept.getDeptId());
ztree.setpId(dept.getParentId());
ztree.setName(dept.getDeptName());
ztree.setTitle(dept.getDeptName());
- if (isCheck)
- {
- ztree.setChecked(roleDeptList.contains(dept.getDeptId() + dept.getDeptName()));
+ if (isCheck) {
+ ztree.setChecked(roleDeptList.contains(new SysDept(dept.getDeptId())));
}
ztrees.add(ztree);
}
@@ -149,163 +143,127 @@ public class SysDeptServiceImpl implements ISysDeptService
}
/**
- * 查询部门人数
- *
- * @param parentId 部门ID
+ * 查询下级部门数量
+ *
+ * @param deptId 部门ID
* @return 结果
*/
@Override
- public int selectDeptCount(Long parentId)
- {
- SysDept dept = new SysDept();
- dept.setParentId(parentId);
- return deptMapper.selectDeptCount(dept);
+ public int countChildren(Long deptId) {
+ return sysDeptRepository.countByDelFlagAndParent(BaseEntity.NOT_DELETED, new SysDept(deptId));
}
/**
* 查询部门是否存在用户
- *
+ *
* @param deptId 部门ID
* @return 结果 true 存在 false 不存在
*/
@Override
- public boolean checkDeptExistUser(Long deptId)
- {
- int result = deptMapper.checkDeptExistUser(deptId);
- return result > 0 ? true : false;
+ public boolean checkDeptExistUser(Long deptId) {
+ return sysUserRepository.countByDelFlagAndDept(BaseEntity.NOT_DELETED, new SysDept(deptId)) > 0;
}
/**
* 删除部门管理信息
- *
+ *
* @param deptId 部门ID
* @return 结果
*/
+ @Transactional
@Override
- public int deleteDeptById(Long deptId)
- {
- return deptMapper.deleteDeptById(deptId);
+ public void deleteDeptById(Long deptId) {
+ sysDeptRepository.updateDelFlagByDeptId(BaseEntity.DELETED, deptId);
}
/**
* 新增保存部门信息
- *
+ *
* @param dept 部门信息
* @return 结果
*/
+ @Transactional
@Override
- public int insertDept(SysDept dept)
- {
- SysDept info = deptMapper.selectDeptById(dept.getParentId());
+ public SysDept insertDept(SysDept dept) {
+ SysDept info = sysDeptRepository.findById(dept.getParentId()).get();
// 如果父节点不为"正常"状态,则不允许新增子节点
- if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
- {
+ if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
throw new BusinessException("部门停用,不允许新增");
}
- dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
- return deptMapper.insertDept(dept);
+ setDeptCode(dept);
+ return sysDeptRepository.save(dept);
}
/**
* 修改保存部门信息
- *
+ *
* @param dept 部门信息
* @return 结果
*/
@Override
@Transactional
- public int updateDept(SysDept dept)
- {
- SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
- SysDept oldDept = selectDeptById(dept.getDeptId());
- if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
- {
- String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
- String oldAncestors = oldDept.getAncestors();
- dept.setAncestors(newAncestors);
- updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
- }
- int result = deptMapper.updateDept(dept);
- if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
- {
+ public SysDept updateDept(SysDept dept) {
+ setDeptCode(dept);
+ sysDeptRepository.save(dept);
+ if (UserConstants.DEPT_NORMAL.equals(dept.getStatus())) {
// 如果该部门是启用状态,则启用该部门的所有上级部门
updateParentDeptStatus(dept);
}
- return result;
+ return dept;
}
/**
* 修改该部门的父级部门状态
- *
+ *
* @param dept 当前部门
*/
- private void updateParentDeptStatus(SysDept dept)
- {
- String updateBy = dept.getUpdateBy();
- dept = deptMapper.selectDeptById(dept.getDeptId());
- dept.setUpdateBy(updateBy);
- deptMapper.updateDeptStatus(dept);
+ private void updateParentDeptStatus(SysDept dept) {
+ SysDept parent = null;
+ while ( (parent = dept.getParent()) != null ){
+ sysDeptRepository.updateStatusByDeptId(SysDept.STATUS_NORMAL, dept.getDeptId());
+ dept = parent;
+ }
}
- /**
- * 修改子元素关系
- *
- * @param deptId 被修改的部门ID
- * @param newAncestors 新的父ID集合
- * @param oldAncestors 旧的父ID集合
- */
- public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors)
- {
- List children = deptMapper.selectChildrenDeptById(deptId);
- for (SysDept child : children)
- {
- child.setAncestors(child.getAncestors().replace(oldAncestors, newAncestors));
- }
- if (children.size() > 0)
- {
- deptMapper.updateDeptChildren(children);
- }
- }
/**
* 根据部门ID查询信息
- *
+ *
* @param deptId 部门ID
* @return 部门信息
*/
@Override
- public SysDept selectDeptById(Long deptId)
- {
- return deptMapper.selectDeptById(deptId);
- }
-
- /**
- * 根据ID查询所有子部门(正常状态)
- *
- * @param deptId 部门ID
- * @return 子部门数
- */
- @Override
- public int selectNormalChildrenDeptById(Long deptId)
- {
- return deptMapper.selectNormalChildrenDeptById(deptId);
+ public SysDept selectDeptById(Long deptId) {
+ return sysDeptRepository.findById(deptId).orElseThrow(() -> new IllegalArgumentException("无效的数据"));
}
/**
* 校验部门名称是否唯一
- *
+ *
* @param dept 部门信息
* @return 结果
*/
@Override
- public String checkDeptNameUnique(SysDept dept)
- {
+ public String checkDeptNameUnique(SysDept dept) {
Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
- SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());
- if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue())
- {
+ SysDept info = sysDeptRepository.findFirstByDelFlagAndDeptNameAndParent(BaseEntity.NOT_DELETED, dept.getDeptName(), dept.getParent());
+ if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) {
return UserConstants.DEPT_NAME_NOT_UNIQUE;
}
return UserConstants.DEPT_NAME_UNIQUE;
}
+
+ public void setDeptCode(SysDept dept){
+ SysDept parent = dept.getParent();
+ String parentCode = parent.getCode();
+ SysDept max = sysDeptRepository.findFirstByParentOrderByCodeDesc(parent);
+ int next = 001;
+ if(max != null){
+ String maxCode = max.getCode();
+ String sequence = maxCode.substring(maxCode.length() - 3);
+ next = Integer.parseInt(sequence) + 1;
+ }
+ String code = String.format("%s%03d", parentCode, next);
+ dept.setCode(code);
+ }
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
index 0a7716960..5c01aeee9 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
@@ -1,110 +1,144 @@
package com.ruoyi.system.service.impl;
-import java.util.List;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
+import com.querydsl.core.types.ExpressionUtils;
+import com.querydsl.core.types.Predicate;
+import com.ruoyi.common.base.BaseService;
import com.ruoyi.common.core.text.Convert;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.domain.QSysDictData;
import com.ruoyi.system.domain.SysDictData;
-import com.ruoyi.system.mapper.SysDictDataMapper;
+import com.ruoyi.system.repository.SysDictDataRepository;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.utils.DictUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
/**
* 字典 业务层处理
- *
+ *
* @author ruoyi
*/
@Service
-public class SysDictDataServiceImpl implements ISysDictDataService
-{
+public class SysDictDataServiceImpl extends BaseService implements ISysDictDataService {
@Autowired
- private SysDictDataMapper dictDataMapper;
+ private SysDictDataRepository sysDictDataRepository;
/**
* 根据条件分页查询字典数据
- *
+ *
* @param dictData 字典数据信息
* @return 字典数据集合信息
*/
@Override
- public List selectDictDataList(SysDictData dictData)
- {
- return dictDataMapper.selectDictDataList(dictData);
+ public Page selectDictDataList(SysDictData dictData, Pageable pageable) {
+ return sysDictDataRepository.findAll(getPredicate(dictData), pageable);
+ }
+
+ private Predicate getPredicate(SysDictData dictData){
+ QSysDictData qSysDictData = QSysDictData.sysDictData;
+ List predicates = new ArrayList<>();
+ if(StringUtils.isNotEmpty(dictData.getDictType())){
+ predicates.add(buildEqual(qSysDictData.dictType, dictData.getDictType()));
+ }
+ if(StringUtils.isNotEmpty(dictData.getDictLabel())){
+ predicates.add(buildLike(qSysDictData.status, dictData.getDictLabel()));
+ }
+ if(StringUtils.isNotEmpty(dictData.getStatus())){
+ predicates.add(buildEqual(qSysDictData.status, dictData.getStatus()));
+ }
+ return ExpressionUtils.allOf(predicates);
+ }
+
+ /**
+ * 根据字典类型查询字典数据
+ *
+ * @param dictType 字典类型
+ * @return 字典数据集合信息
+ */
+ @Override
+ public List selectDictDataByType(String dictType) {
+ return sysDictDataRepository.findByDictType(dictType);
}
/**
* 根据字典类型和字典键值查询字典数据信息
- *
- * @param dictType 字典类型
+ *
+ * @param dictType 字典类型
* @param dictValue 字典键值
* @return 字典标签
*/
@Override
- public String selectDictLabel(String dictType, String dictValue)
- {
- return dictDataMapper.selectDictLabel(dictType, dictValue);
+ public String selectDictLabel(String dictType, String dictValue) {
+ SysDictData dictData = sysDictDataRepository.findFirstByDictTypeAndDictLabel(dictType, dictType);
+ return dictData == null ? dictData.getDictValue() : "";
}
/**
* 根据字典数据ID查询信息
- *
+ *
* @param dictCode 字典数据ID
* @return 字典数据
*/
@Override
- public SysDictData selectDictDataById(Long dictCode)
- {
- return dictDataMapper.selectDictDataById(dictCode);
+ public SysDictData selectDictDataById(Long dictCode) {
+ return sysDictDataRepository.findById(dictCode).get();
+ }
+
+ /**
+ * 通过字典ID删除字典数据信息
+ *
+ * @param dictCode 字典数据ID
+ * @return 结果
+ */
+ @Transactional
+ @Override
+ public int deleteDictDataById(Long dictCode) {
+ sysDictDataRepository.deleteById(dictCode);
+ return 1;
}
/**
* 批量删除字典数据
- *
+ *
* @param ids 需要删除的数据
* @return 结果
*/
+ @Transactional
@Override
- public int deleteDictDataByIds(String ids)
- {
- int row = dictDataMapper.deleteDictDataByIds(Convert.toStrArray(ids));
- if (row > 0)
- {
- DictUtils.clearDictCache();
- }
- return row;
+ public int deleteDictDataByIds(String ids) {
+ Collection collection = toEntityIterable(toLongIterable(ids), id -> new SysDictData(id));
+ sysDictDataRepository.deleteAll(collection);
+ return collection.size();
}
/**
* 新增保存字典数据信息
- *
+ *
* @param dictData 字典数据信息
* @return 结果
*/
@Override
- public int insertDictData(SysDictData dictData)
- {
- int row = dictDataMapper.insertDictData(dictData);
- if (row > 0)
- {
- DictUtils.clearDictCache();
- }
- return row;
+ public int insertDictData(SysDictData dictData) {
+ sysDictDataRepository.save(dictData);
+ return 1;
}
/**
* 修改保存字典数据信息
- *
+ *
* @param dictData 字典数据信息
* @return 结果
*/
@Override
- public int updateDictData(SysDictData dictData)
- {
- int row = dictDataMapper.updateDictData(dictData);
- if (row > 0)
- {
- DictUtils.clearDictCache();
- }
- return row;
+ public int updateDictData(SysDictData dictData) {
+ sysDictDataRepository.save(dictData);
+ return 1;
}
}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
index 5c2bf7d73..7396ef005 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
@@ -1,206 +1,174 @@
package com.ruoyi.system.service.impl;
-import java.util.ArrayList;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
+import com.querydsl.core.types.ExpressionUtils;
+import com.querydsl.core.types.Predicate;
+import com.ruoyi.common.base.BaseService;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.system.domain.SysDictData;
+import com.ruoyi.system.domain.QSysDictType;
import com.ruoyi.system.domain.SysDictType;
-import com.ruoyi.system.mapper.SysDictDataMapper;
-import com.ruoyi.system.mapper.SysDictTypeMapper;
+import com.ruoyi.system.repository.SysDictDataRepository;
+import com.ruoyi.system.repository.SysDictTypeRepository;
import com.ruoyi.system.service.ISysDictTypeService;
-import com.ruoyi.system.utils.DictUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.List;
/**
* 字典 业务层处理
- *
+ *
* @author ruoyi
*/
@Service
-public class SysDictTypeServiceImpl implements ISysDictTypeService
-{
+public class SysDictTypeServiceImpl extends BaseService implements ISysDictTypeService {
@Autowired
- private SysDictTypeMapper dictTypeMapper;
-
+ private SysDictTypeRepository sysDictTypeRepository;
@Autowired
- private SysDictDataMapper dictDataMapper;
-
- /**
- * 项目启动时,初始化字典到缓存
- */
- @PostConstruct
- public void init()
- {
- List dictTypeList = dictTypeMapper.selectDictTypeAll();
- for (SysDictType dictType : dictTypeList)
- {
- List dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType());
- DictUtils.setDictCache(dictType.getDictType(), dictDatas);
- }
- }
+ private SysDictDataRepository sysDictDataRepository;
/**
* 根据条件分页查询字典类型
- *
+ *
* @param dictType 字典类型信息
* @return 字典类型集合信息
*/
@Override
- public List selectDictTypeList(SysDictType dictType)
- {
- return dictTypeMapper.selectDictTypeList(dictType);
+ public Page selectDictTypeList(SysDictType dictType, Pageable pageable) {
+ return sysDictTypeRepository.findAll(getPredicate(dictType), pageable);
+ }
+
+ private Predicate getPredicate(SysDictType sysDictType){
+ QSysDictType qSysDictType = QSysDictType.sysDictType;
+ List predicates = new ArrayList<>();
+ if(StringUtils.isNotEmpty(sysDictType.getDictName())){
+ predicates.add(buildLike(qSysDictType.dictName, sysDictType.getDictName()));
+ }
+ if(StringUtils.isNotEmpty(sysDictType.getStatus())){
+ predicates.add(buildEqual(qSysDictType.status, sysDictType.getStatus()));
+ }
+ if(StringUtils.isNotEmpty(sysDictType.getDictType())){
+ predicates.add(buildLike(qSysDictType.dictType, sysDictType.getDictType()));
+ }
+ if(sysDictType.getStartTime() != null){
+ predicates.add(buildGreaterThanOrEqualTo(qSysDictType.createTime, sysDictType.getStartTime()));
+ }
+ if(sysDictType.getEndTime() != null){
+ predicates.add(buildLessThanOrEqualTo(qSysDictType.createTime, sysDictType.getEndTime()));
+ }
+ return ExpressionUtils.allOf(predicates);
}
/**
* 根据所有字典类型
- *
+ *
* @return 字典类型集合信息
*/
@Override
- public List selectDictTypeAll()
- {
- return dictTypeMapper.selectDictTypeAll();
- }
-
- /**
- * 根据字典类型查询字典数据
- *
- * @param dictType 字典类型
- * @return 字典数据集合信息
- */
- @Override
- public List selectDictDataByType(String dictType)
- {
- List dictDatas = DictUtils.getDictCache(dictType);
- if (StringUtils.isNotEmpty(dictDatas))
- {
- return dictDatas;
- }
- dictDatas = dictDataMapper.selectDictDataByType(dictType);
- if (StringUtils.isNotEmpty(dictDatas))
- {
- DictUtils.setDictCache(dictType, dictDatas);
- return dictDatas;
- }
- return null;
+ public List selectDictTypeAll() {
+ return sysDictTypeRepository.findAll();
}
/**
* 根据字典类型ID查询信息
- *
+ *
* @param dictId 字典类型ID
* @return 字典类型
*/
@Override
- public SysDictType selectDictTypeById(Long dictId)
- {
- return dictTypeMapper.selectDictTypeById(dictId);
+ public SysDictType selectDictTypeById(Long dictId) {
+ return sysDictTypeRepository.findById(dictId).get();
}
/**
* 根据字典类型查询信息
- *
+ *
* @param dictType 字典类型
* @return 字典类型
*/
+ public SysDictType selectDictTypeByType(String dictType) {
+ return sysDictTypeRepository.findFirstByDictType(dictType);
+ }
+
+ /**
+ * 通过字典ID删除字典信息
+ *
+ * @param dictId 字典ID
+ * @return 结果
+ */
+ @Transactional
@Override
- public SysDictType selectDictTypeByType(String dictType)
- {
- return dictTypeMapper.selectDictTypeByType(dictType);
+ public int deleteDictTypeById(Long dictId) {
+ sysDictTypeRepository.deleteById(dictId);
+ return 1;
}
/**
* 批量删除字典类型
- *
+ *
* @param ids 需要删除的数据
* @return 结果
*/
+ @Transactional
@Override
- public int deleteDictTypeByIds(String ids)
- {
+ public int deleteDictTypeByIds(String ids) throws BusinessException {
Long[] dictIds = Convert.toLongArray(ids);
- for (Long dictId : dictIds)
- {
+ for (Long dictId : dictIds) {
SysDictType dictType = selectDictTypeById(dictId);
- if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0)
- {
+ if (sysDictDataRepository.countByDictType(dictType.getDictType()) > 0) {
throw new BusinessException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
}
+ deleteDictTypeById(dictId);
}
- int count = dictTypeMapper.deleteDictTypeByIds(dictIds);
- if (count > 0)
- {
- DictUtils.clearDictCache();
- }
- return count;
- }
-
- /**
- * 清空缓存数据
- */
- @Override
- public void clearCache()
- {
- DictUtils.clearDictCache();
+ return dictIds.length;
}
/**
* 新增保存字典类型信息
- *
+ *
* @param dictType 字典类型信息
* @return 结果
*/
@Override
- public int insertDictType(SysDictType dictType)
- {
- int row = dictTypeMapper.insertDictType(dictType);
- if (row > 0)
- {
- DictUtils.clearDictCache();
- }
- return row;
+ public int insertDictType(SysDictType dictType) {
+ sysDictTypeRepository.save(dictType);
+ return 1;
}
/**
* 修改保存字典类型信息
- *
+ *
* @param dictType 字典类型信息
* @return 结果
*/
@Override
@Transactional
- public int updateDictType(SysDictType dictType)
- {
- SysDictType oldDict = dictTypeMapper.selectDictTypeById(dictType.getDictId());
- dictDataMapper.updateDictDataType(oldDict.getDictType(), dictType.getDictType());
- int row = dictTypeMapper.updateDictType(dictType);
- if (row > 0)
- {
- DictUtils.clearDictCache();
- }
- return row;
+ public int updateDictType(SysDictType dictType) {
+ SysDictType oldDict = sysDictTypeRepository.findById(dictType.getDictId()).get();
+ sysDictDataRepository.updateDictType(dictType.getDictType(), oldDict.getDictType());
+ sysDictTypeRepository.save(dictType);
+ return 1;
}
/**
* 校验字典类型称是否唯一
- *
+ *
* @param dict 字典类型
* @return 结果
*/
@Override
- public String checkDictTypeUnique(SysDictType dict)
- {
+ public String checkDictTypeUnique(SysDictType dict) {
Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId();
- SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType());
- if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue())
- {
+ SysDictType dictType = sysDictTypeRepository.findFirstByDictType(dict.getDictType());
+ if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) {
return UserConstants.DICT_TYPE_NOT_UNIQUE;
}
return UserConstants.DICT_TYPE_UNIQUE;
@@ -208,19 +176,15 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
/**
* 查询字典类型树
- *
+ *
* @param dictType 字典类型
* @return 所有字典类型
*/
- @Override
- public List selectDictTree(SysDictType dictType)
- {
+ public List selectDictTree(SysDictType dictType) {
List ztrees = new ArrayList();
- List dictList = dictTypeMapper.selectDictTypeList(dictType);
- for (SysDictType dict : dictList)
- {
- if (UserConstants.DICT_NORMAL.equals(dict.getStatus()))
- {
+ List dictList = sysDictTypeRepository.findAll();
+ for (SysDictType dict : dictList) {
+ if (UserConstants.DICT_NORMAL.equals(dict.getStatus())) {
Ztree ztree = new Ztree();
ztree.setId(dict.getDictId());
ztree.setName(transDictName(dict));
@@ -231,8 +195,13 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
return ztrees;
}
- public String transDictName(SysDictType dictType)
- {
+ @CacheEvict(allEntries = true)
+ @Override
+ public void clearCache() {
+
+ }
+
+ public String transDictName(SysDictType dictType) {
StringBuffer sb = new StringBuffer();
sb.append("(" + dictType.getDictName() + ")");
sb.append(" " + dictType.getDictType());
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysLogininforServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysLogininforServiceImpl.java
index 61d92a560..e37950ffd 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysLogininforServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysLogininforServiceImpl.java
@@ -33,8 +33,6 @@ public class SysLogininforServiceImpl extends BaseService implements ISysLoginin
private SysLogininfoRepository sysLogininfoRepository;
@Autowired
private JdbcTemplate jdbcTemplate;
- @Autowired
- private EntityManager entityManager;
/**
* 新增系统登录日志
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java
index e81130b51..67ac1a679 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java
@@ -1,120 +1,174 @@
package com.ruoyi.system.service.impl;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
+import com.google.common.collect.Lists;
+import com.ruoyi.common.base.BaseService;
import com.ruoyi.common.constant.UserConstants;
+import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysMenu;
import com.ruoyi.system.domain.SysRole;
import com.ruoyi.system.domain.SysUser;
-import com.ruoyi.system.mapper.SysMenuMapper;
-import com.ruoyi.system.mapper.SysRoleMenuMapper;
+import com.ruoyi.system.repository.SysMenuRepository;
+import com.ruoyi.system.repository.SysRoleRepository;
+import com.ruoyi.system.repository.SysUserRepository;
import com.ruoyi.system.service.ISysMenuService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.persistence.criteria.*;
+import java.text.MessageFormat;
+import java.util.*;
/**
* 菜单 业务层处理
- *
+ *
* @author ruoyi
*/
@Service
-public class SysMenuServiceImpl implements ISysMenuService
-{
+public class SysMenuServiceImpl extends BaseService implements ISysMenuService {
public static final String PREMISSION_STRING = "perms[\"{0}\"]";
@Autowired
- private SysMenuMapper menuMapper;
-
+ private SysMenuRepository sysMenuRepository;
@Autowired
- private SysRoleMenuMapper roleMenuMapper;
+ private SysUserRepository sysUserRepository;
+ @Autowired
+ private SysRoleRepository sysRoleRepository;
/**
* 根据用户查询菜单
- *
+ *
* @param user 用户信息
* @return 菜单列表
*/
@Override
- public List selectMenusByUser(SysUser user)
- {
+ public List selectMenusByUser(SysUser user) {
List menus = new LinkedList();
// 管理员显示所有菜单信息
- if (user.isAdmin())
- {
- menus = menuMapper.selectMenuNormalAll();
+ if (user.isAdmin()) {
+ menus = sysMenuRepository.findAllByMenuTypeInAndVisibleOrderByOrderNum(
+ Lists.newArrayList(SysMenu.MENU_TYPE_PRIMARY, SysMenu.MENU_TYPE_SECONDARY), SysMenu.MENU_VISIABLE);
+ } else {
+ user = sysUserRepository.findSysUserByDelFlagAndUserId(BaseEntity.NOT_DELETED, user.getUserId());
+ Set roles = user.getRoles();
+ menus = sysMenuRepository.findAll(new Specification() {
+ @Override
+ public Predicate toPredicate(Root root, CriteriaQuery> query, CriteriaBuilder criteriaBuilder) {
+ List predicates = new ArrayList<>();
+ if(!roles.isEmpty()){
+ for(SysRole role : roles){
+ predicates.add(criteriaBuilder.isMember(role, root.get("roles")));
+ }
+ }
+
+ Expression