From 30da1e50dec9532729aa02f96fb2f3b0690c023a Mon Sep 17 00:00:00 2001 From: meng <154040976@qq.com> Date: Tue, 11 Dec 2018 23:11:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=9B=9E=E6=BB=9A=E4=BA=86?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/len/base/BaseService.java | 2 + .../com/len/base/impl/BaseServiceImpl.java | 62 +++++++++++++++++++ .../com/len/controller/UserController.java | 31 ++++------ .../java/com/len/mapper/SysUserMapper.java | 3 +- .../java/com/len/service/SysUserService.java | 4 +- .../len/service/impl/SysUserServiceImpl.java | 53 ++++++++++++++-- .../main/resources/mapper/SysUserMapper.xml | 6 +- 7 files changed, 129 insertions(+), 32 deletions(-) diff --git a/len-core/src/main/java/com/len/base/BaseService.java b/len-core/src/main/java/com/len/base/BaseService.java index d649f89..263bf0e 100644 --- a/len-core/src/main/java/com/len/base/BaseService.java +++ b/len-core/src/main/java/com/len/base/BaseService.java @@ -69,5 +69,7 @@ public interface BaseService { public ReType show(T t, int page, int limit); + public ReType getList(T t, int page, int limit); + public String showAll(T t); } diff --git a/len-core/src/main/java/com/len/base/impl/BaseServiceImpl.java b/len-core/src/main/java/com/len/base/impl/BaseServiceImpl.java index 279ae82..691b473 100644 --- a/len-core/src/main/java/com/len/base/impl/BaseServiceImpl.java +++ b/len-core/src/main/java/com/len/base/impl/BaseServiceImpl.java @@ -9,6 +9,7 @@ import com.len.base.CurrentUser; import com.len.exception.MyException; import com.len.util.ReType; import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.session.RowBounds; import org.apache.shiro.SecurityUtils; import java.io.Serializable; @@ -66,6 +67,7 @@ public abstract class BaseServiceImpl implements Base } + @Override public int deleteByPrimaryKey(E id) { return getMappser().deleteByPrimaryKey(id); } @@ -236,4 +238,64 @@ public abstract class BaseServiceImpl implements Base return JSON.toJSONString(tList); } + @Override + public ReType getList(T t, int page, int limit) { + List tList = null; + Page tPage = PageHelper.startPage(page, limit); + try { + tList = getMappser().selectListByPage(t); + } catch (MyException e) { + log.error("class:BaseServiceImpl ->method:getList->message:" + e.getMessage()); + e.printStackTrace(); + } + return new ReType(tPage.getTotal(),tPage.getPageNum(), tList); + } + + + @Override + public int deleteByExample(Object o) { + return getMappser().deleteByExample(o); + } + + + @Override + public List selectByExample(Object o) { + return getMappser().selectByExample(o); + } + + + @Override + public int selectCountByExample(Object o) { + return getMappser().selectCountByExample(o); + } + + + @Override + public T selectOneByExample(Object o) { + return getMappser().selectOneByExample(o); + } + + + @Override + public int updateByExample(T t, Object o) { + return getMappser().updateByExample(t,o); + } + + + @Override + public int updateByExampleSelective(T t, Object o) { + return getMappser().updateByExampleSelective(t,o); + } + + + @Override + public List selectByExampleAndRowBounds(Object o, RowBounds rowBounds) { + return getMappser().selectByExampleAndRowBounds(o,rowBounds); + } + + + @Override + public List selectByRowBounds(T t, RowBounds rowBounds) { + return getMappser().selectByRowBounds(t,rowBounds); + } } diff --git a/len-sys/src/main/java/com/len/controller/UserController.java b/len-sys/src/main/java/com/len/controller/UserController.java index 14e07dc..bd12920 100644 --- a/len-sys/src/main/java/com/len/controller/UserController.java +++ b/len-sys/src/main/java/com/len/controller/UserController.java @@ -2,6 +2,8 @@ package com.len.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import com.len.base.BaseController; import com.len.core.annotation.Log; import com.len.core.annotation.Log.LOG_TYPE; @@ -13,27 +15,18 @@ import com.len.service.RoleUserService; import com.len.service.SysUserService; import com.len.util.*; import io.swagger.annotations.ApiOperation; - -import java.io.*; -import java.util.List; -import java.util.UUID; -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.GetMapping; -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 org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; +import java.util.List; + /** * @author zhuxiaomeng * @date 2017/12/6. @@ -79,12 +72,12 @@ public class UserController extends BaseController { @GetMapping(value = "listByRoleId") @ResponseBody @RequiresPermissions("user:show") - public String showUser(Model model, String roleId,int page, int limit) { + public String showUser(Model model, String roleId, int page, int limit) { JSONObject returnValue = new JSONObject(); - List users = userService.getUserByRoleId(roleId,page,limit); - int counts = userService.countUserByRoleId(roleId,page,limit); - returnValue.put("users",users); - returnValue.put("totals",counts); + Page startPage = PageHelper.startPage(page, limit); + List users = userService.getUserByRoleId(roleId); + returnValue.put("users", users); + returnValue.put("totals", startPage.getTotal()); return JSON.toJSONString(returnValue); } @@ -256,7 +249,7 @@ public class UserController extends BaseController { @ResponseBody public JsonUtil imgUpload(HttpServletRequest req, @RequestParam("file") MultipartFile file, ModelMap model) { - String fileName=uploadUtil.upload(file); + String fileName = uploadUtil.upload(file); JsonUtil j = new JsonUtil(); j.setMsg(fileName); return j; diff --git a/len-sys/src/main/java/com/len/mapper/SysUserMapper.java b/len-sys/src/main/java/com/len/mapper/SysUserMapper.java index 2365167..fd0c24b 100644 --- a/len-sys/src/main/java/com/len/mapper/SysUserMapper.java +++ b/len-sys/src/main/java/com/len/mapper/SysUserMapper.java @@ -27,6 +27,5 @@ public interface SysUserMapper extends com.len.base.BaseMapper { */ int rePass(SysUser user); - List getUserByRoleId(Map map); - int countUserByRoleId(Map map); + List getUserByRoleId(@Param("roleId")String roleId); } \ No newline at end of file diff --git a/len-sys/src/main/java/com/len/service/SysUserService.java b/len-sys/src/main/java/com/len/service/SysUserService.java index c2b44be..e1e7e8f 100644 --- a/len-sys/src/main/java/com/len/service/SysUserService.java +++ b/len-sys/src/main/java/com/len/service/SysUserService.java @@ -63,7 +63,7 @@ public interface SysUserService extends BaseService { int rePass(SysUser user); - List getUserByRoleId(String roleId,int page,int limit); + List getUserByRoleId(String roleId); - int countUserByRoleId(String roleId,int page,int limit); + public void setMenuAndRoles(String username); } diff --git a/len-sys/src/main/java/com/len/service/impl/SysUserServiceImpl.java b/len-sys/src/main/java/com/len/service/impl/SysUserServiceImpl.java index fbb8d33..fe1020f 100644 --- a/len-sys/src/main/java/com/len/service/impl/SysUserServiceImpl.java +++ b/len-sys/src/main/java/com/len/service/impl/SysUserServiceImpl.java @@ -197,8 +197,53 @@ public class SysUserServiceImpl extends BaseServiceImpl impleme return checkboxList; } - @Override - public int rePass(SysUser user) { - return sysUserMapper.rePass(user); - } + @Override + public int rePass(SysUser user) { + return sysUserMapper.rePass(user); + } + + @Override + public List getUserByRoleId(String roleId) { + return sysUserMapper.getUserByRoleId(roleId); + } + + + + @Override + public void setMenuAndRoles(String username) { + SysUser s = new SysUser(); + s.setUsername(username); + s = this.selectOne(s); + CurrentUser currentUser = new CurrentUser(s.getId(), s.getUsername(), s.getAge(), s.getEmail(), s.getPhoto(), s.getRealName()); + Subject subject = ShiroUtil.getSubject(); + /*角色权限封装进去*/ + //根据用户获取菜单 + Session session = subject.getSession(); + + List menuList = menuService.getUserMenu(s.getId()); + JSONArray json = menuService.getMenuJsonByUser(menuList); + session.setAttribute("menu", json); + + + List currentMenuList = new ArrayList<>(); + List roleList = new ArrayList<>(); + for (SysMenu m : menuList) { + CurrentMenu currentMenu = new CurrentMenu(); + BeanUtil.copyNotNullBean(m, currentMenu); + currentMenuList.add(currentMenu); + roleList.addAll(m.getRoleList()); + } + + roleList = new ArrayList<>(new HashSet<>(roleList)); + List currentRoleList = new ArrayList<>(); + + for (SysRole r : roleList) { + CurrentRole role = new CurrentRole(); + BeanUtil.copyNotNullBean(r, role); + currentRoleList.add(role); + } + currentUser.setCurrentRoleList(currentRoleList); + currentUser.setCurrentMenuList(currentMenuList); + session.setAttribute("curentUser", currentUser); + } } diff --git a/len-sys/src/main/resources/mapper/SysUserMapper.xml b/len-sys/src/main/resources/mapper/SysUserMapper.xml index 7b7f830..7dde9d2 100644 --- a/len-sys/src/main/resources/mapper/SysUserMapper.xml +++ b/len-sys/src/main/resources/mapper/SysUserMapper.xml @@ -141,13 +141,9 @@ - select sysuser.id,sysuser.real_name,sysuser.username from sys_user sysuser inner join sys_role_user roleuser on sysuser.id = roleuser.user_id and roleuser.role_id = #{roleId,jdbcType=VARCHAR} - limit #{page},#{limit} - - \ No newline at end of file