From 54cd807d8e8a2e045b9a7f32c8e2fa4470ae554f Mon Sep 17 00:00:00 2001 From: luoyijiucheng <1784525940@qq.com> Date: Mon, 2 Dec 2019 19:47:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=94=A8=E6=88=B7=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=9A=84=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yeqifu/sys/cache/CacheAspect.java | 140 ++++++- .../java/com/yeqifu/sys/common/Constast.java | 3 +- .../sys/controller/SystemController.java | 9 + .../yeqifu/sys/controller/UserController.java | 58 ++- src/main/java/com/yeqifu/sys/entity/User.java | 13 + .../java/com/yeqifu/sys/realm/UserRealm.java | 5 + .../sys/service/impl/DeptServiceImpl.java | 9 +- .../sys/service/impl/RoleServiceImpl.java | 2 + .../sys/service/impl/UserServiceImpl.java | 22 ++ src/main/java/com/yeqifu/sys/vo/UserVo.java | 17 + .../resources/layui_ext/dtree/dtree.css | 2 +- .../templates/system/user/userManager.html | 352 ++++++++++++++++++ 12 files changed, 617 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/yeqifu/sys/vo/UserVo.java create mode 100644 src/main/resources/templates/system/user/userManager.html diff --git a/src/main/java/com/yeqifu/sys/cache/CacheAspect.java b/src/main/java/com/yeqifu/sys/cache/CacheAspect.java index 469982b..3036bdd 100644 --- a/src/main/java/com/yeqifu/sys/cache/CacheAspect.java +++ b/src/main/java/com/yeqifu/sys/cache/CacheAspect.java @@ -1,7 +1,11 @@ package com.yeqifu.sys.cache; import com.yeqifu.sys.entity.Dept; +import com.yeqifu.sys.entity.User; import com.yeqifu.sys.vo.DeptVo; +import com.yeqifu.sys.vo.UserVo; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @@ -21,31 +25,59 @@ import java.util.Map; @EnableAspectJAutoProxy public class CacheAspect { - //声明一个缓存容器 + /** + * 日志出处 + */ + private Log log = LogFactory.getLog(CacheAspect.class); + + /** + * 声明一个缓存容器 + */ private Map CACHE_CONTAINER = new HashMap<>(); - //声明切面表达式 + + /** + * 声明部门的切面表达式 + */ + private static final String POINTCUT_DEPT_ADD="execution(* com.yeqifu.sys.service.impl.DeptServiceImpl.save(..))"; private static final String POINTCUT_DEPT_UPDATE="execution(* com.yeqifu.sys.service.impl.DeptServiceImpl.updateById(..))"; - private static final String POINTCUT_DEPT_GET="execution(* com.yeqifu.sys.service.impl.DeptServiceImpl.getOne(..))"; + private static final String POINTCUT_DEPT_GET="execution(* com.yeqifu.sys.service.impl.DeptServiceImpl.getById(..))"; private static final String POINTCUT_DEPT_DELETE="execution(* com.yeqifu.sys.service.impl.DeptServiceImpl.removeById(..))"; private static final String CACHE_DEPT_PROFIX="dept:"; /** - * 查询切入 + * 添加部门切入 + * @param joinPoint + * @return + */ + @Around(value = POINTCUT_DEPT_ADD) + public Object cacheDeptAdd(ProceedingJoinPoint joinPoint) throws Throwable { + //取出第一个参数 + Dept object = (Dept) joinPoint.getArgs()[0]; + Boolean res = (Boolean) joinPoint.proceed(); + if (res){ + CACHE_CONTAINER.put(CACHE_DEPT_PROFIX + object.getId(),object); + } + return res; + } + + /** + * 查询部门切入 * @param joinPoint * @return */ @Around(value = POINTCUT_DEPT_GET) public Object cacheDeptGet(ProceedingJoinPoint joinPoint) throws Throwable { - //取出第一个参数 Integer object = (Integer) joinPoint.getArgs()[0]; //从缓存里面取 Object res1 = CACHE_CONTAINER.get(CACHE_DEPT_PROFIX + object); if (res1!=null){ + log.info("已从缓存里面找到部门对象"+CACHE_DEPT_PROFIX + object); return res1; }else { + log.info("未从缓存里面找到部门对象,从数据库中查询并放入缓存"); Dept res2 =(Dept) joinPoint.proceed(); CACHE_CONTAINER.put(CACHE_DEPT_PROFIX+res2.getId(),res2); return res2; @@ -53,13 +85,12 @@ public class CacheAspect { } /** - * 更新切入 + * 更新部门切入 * @param joinPoint * @return */ @Around(value = POINTCUT_DEPT_UPDATE) public Object cacheDeptUpdate(ProceedingJoinPoint joinPoint) throws Throwable { - //取出第一个参数 DeptVo deptVo = (DeptVo) joinPoint.getArgs()[0]; Boolean isSuccess = (Boolean) joinPoint.proceed(); @@ -67,15 +98,16 @@ public class CacheAspect { Dept dept =(Dept) CACHE_CONTAINER.get(CACHE_DEPT_PROFIX + deptVo.getId()); if (null==dept){ dept=new Dept(); - BeanUtils.copyProperties(deptVo,dept); - CACHE_CONTAINER.put(CACHE_DEPT_PROFIX+dept.getId(),dept); } + BeanUtils.copyProperties(deptVo,dept); + log.info("部门对象缓存已更新"+CACHE_DEPT_PROFIX + deptVo.getId()); + CACHE_CONTAINER.put(CACHE_DEPT_PROFIX+dept.getId(),dept); } return isSuccess; } /** - * 删除切入 + * 删除部门切入 * @param joinPoint * @return */ @@ -92,4 +124,92 @@ public class CacheAspect { return isSuccess; } + /** + * 声明用户的切面表达式 + */ + private static final String POINTCUT_USER_UPDATE="execution(* com.yeqifu.sys.service.impl.UserServiceImpl.updateById(..))"; + private static final String POINTCUT_USER_ADD="execution(* com.yeqifu.sys.service.impl.UserServiceImpl.updateById(..))"; + private static final String POINTCUT_USER_GET="execution(* com.yeqifu.sys.service.impl.UserServiceImpl.getById(..))"; + private static final String POINTCUT_USER_DELETE="execution(* com.yeqifu.sys.service.impl.UserServiceImpl.removeById(..))"; + + private static final String CACHE_USER_PROFIX="user:"; + + /** + * 添加用户切入 + * @param joinPoint + * @return + */ + @Around(value = POINTCUT_USER_ADD) + public Object cacheUserAdd(ProceedingJoinPoint joinPoint) throws Throwable { + //取出第一个参数 + User object = (User) joinPoint.getArgs()[0]; + Boolean res = (Boolean) joinPoint.proceed(); + if (res){ + CACHE_CONTAINER.put(CACHE_USER_PROFIX + object.getId(),object); + } + return res; + } + + /** + * 查询用户切入 + * @param joinPoint + * @return + */ + @Around(value = POINTCUT_USER_GET) + public Object cacheUserGet(ProceedingJoinPoint joinPoint) throws Throwable { + //取出第一个参数 + Integer object = (Integer) joinPoint.getArgs()[0]; + //从缓存里面取 + Object res1 = CACHE_CONTAINER.get(CACHE_USER_PROFIX + object); + if (res1!=null){ + log.info("已从缓存里面找到用户对象"+CACHE_USER_PROFIX + object); + return res1; + }else { + log.info("未从缓存里面找到用户对象,从数据库中查询并放入缓存"); + User res2 =(User) joinPoint.proceed(); + CACHE_CONTAINER.put(CACHE_USER_PROFIX+res2.getId(),res2); + return res2; + } + } + + /** + * 更新用户切入 + * @param joinPoint + * @return + */ + @Around(value = POINTCUT_USER_UPDATE) + public Object cacheUserUpdate(ProceedingJoinPoint joinPoint) throws Throwable { + //取出第一个参数 + UserVo deptVo = (UserVo) joinPoint.getArgs()[0]; + Boolean isSuccess = (Boolean) joinPoint.proceed(); + if (isSuccess){ + User dept =(User) CACHE_CONTAINER.get(CACHE_USER_PROFIX + deptVo.getId()); + if (null==dept){ + dept=new User(); + } + BeanUtils.copyProperties(deptVo,dept); + log.info("用户对象缓存已更新"+CACHE_USER_PROFIX + deptVo.getId()); + CACHE_CONTAINER.put(CACHE_USER_PROFIX+dept.getId(),dept); + } + return isSuccess; + } + + /** + * 删除用户切入 + * @param joinPoint + * @return + */ + @Around(value = POINTCUT_USER_DELETE) + public Object cacheUserDelete(ProceedingJoinPoint joinPoint) throws Throwable { + + //取出第一个参数 + Integer id = (Integer) joinPoint.getArgs()[0]; + Boolean isSuccess = (Boolean) joinPoint.proceed(); + if (isSuccess){ + //删除缓存 + CACHE_CONTAINER.remove(CACHE_USER_PROFIX+id); + } + return isSuccess; + } + } diff --git a/src/main/java/com/yeqifu/sys/common/Constast.java b/src/main/java/com/yeqifu/sys/common/Constast.java index 3267389..9971571 100644 --- a/src/main/java/com/yeqifu/sys/common/Constast.java +++ b/src/main/java/com/yeqifu/sys/common/Constast.java @@ -25,9 +25,10 @@ public class Constast { public static final String TYPE_PERMISSION = "permission"; /** - * 用户类型 0 超级管理员 1 管理员 2普通用户 + * 用户类型 0 超级管理员 1 系统用户 */ public static final Integer USER_TYPE_SUPER = 0; + public static final Integer USER_TYPE_NORMAL = 1; /** * 菜单是否展开 0不展开 1展开 diff --git a/src/main/java/com/yeqifu/sys/controller/SystemController.java b/src/main/java/com/yeqifu/sys/controller/SystemController.java index 9bec565..1cac65a 100644 --- a/src/main/java/com/yeqifu/sys/controller/SystemController.java +++ b/src/main/java/com/yeqifu/sys/controller/SystemController.java @@ -146,5 +146,14 @@ public class SystemController { public String toRoleManager(){ return "system/role/roleManager"; } + + /** + * 跳转到用户管理 + * @return + */ + @RequestMapping("toUserManager") + public String toUserManager(){ + return "system/user/userManager"; + } } diff --git a/src/main/java/com/yeqifu/sys/controller/UserController.java b/src/main/java/com/yeqifu/sys/controller/UserController.java index 10a7dc2..c8694af 100644 --- a/src/main/java/com/yeqifu/sys/controller/UserController.java +++ b/src/main/java/com/yeqifu/sys/controller/UserController.java @@ -1,10 +1,25 @@ package com.yeqifu.sys.controller; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.yeqifu.sys.common.Constast; +import com.yeqifu.sys.common.DataGridView; +import com.yeqifu.sys.entity.Dept; +import com.yeqifu.sys.entity.User; +import com.yeqifu.sys.service.IDeptService; +import com.yeqifu.sys.service.IUserService; +import com.yeqifu.sys.vo.UserVo; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + /** *

* InnoDB free: 9216 kB; (`deptid`) REFER `warehouse/sys_dept`(`id`) ON UPDATE CASC 前端控制器 @@ -14,8 +29,49 @@ import org.springframework.web.bind.annotation.RestController; * @since 2019-11-21 */ @RestController -@RequestMapping("/sys/user") +@RequestMapping("/user") public class UserController { + @Autowired + private IUserService userService; + + @Autowired + private IDeptService deptService; + + /** + * 查询所有用户 + * @param userVo + * @return + */ + @RequestMapping("loadAllUser") + public DataGridView loadAllUser(UserVo userVo){ + IPage page = new Page(userVo.getPage(),userVo.getLimit()); + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq(StringUtils.isNotBlank(userVo.getName()),"loginname",userVo.getName()).or().eq(StringUtils.isNotBlank(userVo.getName()),"name",userVo.getName()); + queryWrapper.eq(StringUtils.isNotBlank(userVo.getAddress()),"address",userVo.getAddress()); + //查询系统用户 + queryWrapper.eq("type", Constast.USER_TYPE_NORMAL); + queryWrapper.eq(userVo.getDeptid()!=null,"deptid",userVo.getDeptid()); + userService.page(page,queryWrapper); + + //将所有用户数据放入list中 + List list = page.getRecords(); + for (User user : list) { + Integer deptid = user.getDeptid(); + if (deptid!=null){ + //先从缓存中去取,如果缓存中没有就去数据库中取 + Dept one = deptService.getById(deptid); + //设置user的部门名称 + user.setDeptname(one.getName()); + } + Integer mgr = user.getMgr(); + if (mgr!=null){ + User one = userService.getById(mgr); + //设置user的领导名称 + user.setLeadername(one.getName()); + } + } + return new DataGridView(page.getTotal(),list); + } } diff --git a/src/main/java/com/yeqifu/sys/entity/User.java b/src/main/java/com/yeqifu/sys/entity/User.java index a129874..0e25ccf 100644 --- a/src/main/java/com/yeqifu/sys/entity/User.java +++ b/src/main/java/com/yeqifu/sys/entity/User.java @@ -1,5 +1,6 @@ package com.yeqifu.sys.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; @@ -76,5 +77,17 @@ public class User implements Serializable { */ private String salt; + /** + * 领导名称 + */ + @TableField(exist = false) + private String leadername; + + /** + * 部门名称 + */ + @TableField(exist = false) + private String deptname; + } diff --git a/src/main/java/com/yeqifu/sys/realm/UserRealm.java b/src/main/java/com/yeqifu/sys/realm/UserRealm.java index c21238c..3a2606f 100644 --- a/src/main/java/com/yeqifu/sys/realm/UserRealm.java +++ b/src/main/java/com/yeqifu/sys/realm/UserRealm.java @@ -13,6 +13,7 @@ import org.apache.shiro.realm.AuthorizingRealm; import org.apache.shiro.subject.PrincipalCollection; import org.apache.shiro.util.ByteSource; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; /** * @Author: 落亦- @@ -21,6 +22,10 @@ import org.springframework.beans.factory.annotation.Autowired; public class UserRealm extends AuthorizingRealm { @Autowired + /** + * 当需要使用的时候,才加载。 即:当CacheAspect被解析之后,userService才会解析,要不然切面会不生效 + */ + @Lazy private IUserService userService; @Override diff --git a/src/main/java/com/yeqifu/sys/service/impl/DeptServiceImpl.java b/src/main/java/com/yeqifu/sys/service/impl/DeptServiceImpl.java index 4a099aa..600bff2 100644 --- a/src/main/java/com/yeqifu/sys/service/impl/DeptServiceImpl.java +++ b/src/main/java/com/yeqifu/sys/service/impl/DeptServiceImpl.java @@ -23,8 +23,8 @@ import java.io.Serializable; public class DeptServiceImpl extends ServiceImpl implements IDeptService { @Override - public Dept getOne(Wrapper queryWrapper) { - return super.getOne(queryWrapper); + public Dept getById(Serializable id) { + return super.getById(id); } @Override @@ -41,4 +41,9 @@ public class DeptServiceImpl extends ServiceImpl implements ID public boolean removeById(Serializable id){ return super.removeById(id); } + + @Override + public boolean save(Dept entity) { + return super.save(entity); + } } diff --git a/src/main/java/com/yeqifu/sys/service/impl/RoleServiceImpl.java b/src/main/java/com/yeqifu/sys/service/impl/RoleServiceImpl.java index 2ca6ed5..daeaf64 100644 --- a/src/main/java/com/yeqifu/sys/service/impl/RoleServiceImpl.java +++ b/src/main/java/com/yeqifu/sys/service/impl/RoleServiceImpl.java @@ -5,6 +5,7 @@ import com.yeqifu.sys.mapper.RoleMapper; import com.yeqifu.sys.service.IRoleService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.io.Serializable; import java.util.List; @@ -18,6 +19,7 @@ import java.util.List; * @since 2019-11-28 */ @Service +@Transactional public class RoleServiceImpl extends ServiceImpl implements IRoleService { @Override diff --git a/src/main/java/com/yeqifu/sys/service/impl/UserServiceImpl.java b/src/main/java/com/yeqifu/sys/service/impl/UserServiceImpl.java index 8cd2d3d..8873543 100644 --- a/src/main/java/com/yeqifu/sys/service/impl/UserServiceImpl.java +++ b/src/main/java/com/yeqifu/sys/service/impl/UserServiceImpl.java @@ -1,5 +1,6 @@ package com.yeqifu.sys.service.impl; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.yeqifu.sys.entity.User; import com.yeqifu.sys.mapper.UserMapper; import com.yeqifu.sys.service.IUserService; @@ -7,6 +8,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.io.Serializable; + /** *

* InnoDB free: 9216 kB; (`deptid`) REFER `warehouse/sys_dept`(`id`) ON UPDATE CASC 服务实现类 @@ -19,4 +22,23 @@ import org.springframework.transaction.annotation.Transactional; @Transactional public class UserServiceImpl extends ServiceImpl implements IUserService { + @Override + public boolean save(User entity) { + return super.save(entity); + } + + @Override + public boolean updateById(User entity) { + return super.updateById(entity); + } + + @Override + public User getById(Serializable id) { + return super.getById(id); + } + + @Override + public boolean removeById(Serializable id) { + return super.removeById(id); + } } diff --git a/src/main/java/com/yeqifu/sys/vo/UserVo.java b/src/main/java/com/yeqifu/sys/vo/UserVo.java new file mode 100644 index 0000000..d461789 --- /dev/null +++ b/src/main/java/com/yeqifu/sys/vo/UserVo.java @@ -0,0 +1,17 @@ +package com.yeqifu.sys.vo; + +import com.yeqifu.sys.entity.User; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @Author: 落亦- + * @Date: 2019/12/2 8:21 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class UserVo extends User { + + private Integer page=1; + private Integer limit=10; +} diff --git a/src/main/resources/static/resources/layui_ext/dtree/dtree.css b/src/main/resources/static/resources/layui_ext/dtree/dtree.css index 3e5364d..6da7c01 100644 --- a/src/main/resources/static/resources/layui_ext/dtree/dtree.css +++ b/src/main/resources/static/resources/layui_ext/dtree/dtree.css @@ -99,7 +99,7 @@ /** 下拉树属性*/ -.dtree-select{position: absolute;max-height: 500px;height: 350px;overflow: auto;width: 99%;z-index: 123;display: none;border:1px solid silver;top: 42px;} +.dtree-select{position: absolute;max-height: 500px;height: 350px;overflow: auto;width: 99%;z-index: 900;display: none;border:1px solid silver;top: 42px;} .dtree-select-show{display: block!important;} /* 简单适配*/ diff --git a/src/main/resources/templates/system/user/userManager.html b/src/main/resources/templates/system/user/userManager.html new file mode 100644 index 0000000..5282359 --- /dev/null +++ b/src/main/resources/templates/system/user/userManager.html @@ -0,0 +1,352 @@ + + + + + 用户管理 + + + + + + + + + + + + + + + +

+ 搜索条件 +
+
+
+
+ +
+ +
    +
    +
    + +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    +
    + + +
    +
    +
    + + +
    +
    + + +
    + + + + + + + + + + \ No newline at end of file