From 50d6b813c1e88a2047a00cb65242b2eeb6ad5674 Mon Sep 17 00:00:00 2001 From: meng <154040976@qq.com> Date: Tue, 30 Apr 2019 21:57:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/len/controller/ErrorController.java | 6 +- .../com/len/controller/JobController.java | 2 + .../com/len/controller/LogController.java | 2 + .../com/len/controller/LoginController.java | 2 + .../com/len/controller/MenuController.java | 43 +---- .../com/len/controller/PersonController.java | 2 + .../com/len/controller/RoleController.java | 78 +-------- .../com/len/controller/UserController.java | 2 + .../java/com/len/service/MenuService.java | 5 + .../java/com/len/service/RoleService.java | 8 + .../com/len/service/impl/MenuServiceImpl.java | 38 +++++ .../com/len/service/impl/RoleServiceImpl.java | 155 ++++++++++++++---- 12 files changed, 198 insertions(+), 145 deletions(-) diff --git a/len-sys/src/main/java/com/len/controller/ErrorController.java b/len-sys/src/main/java/com/len/controller/ErrorController.java index 98e9699..60859c0 100644 --- a/len-sys/src/main/java/com/len/controller/ErrorController.java +++ b/len-sys/src/main/java/com/len/controller/ErrorController.java @@ -1,7 +1,6 @@ package com.len.controller; -import java.io.UnsupportedEncodingException; - +import io.swagger.annotations.Api; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -16,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; */ @Controller @RequestMapping(value = "/error") +@Api(value = "异常", description = "异常业务类") public class ErrorController { @GetMapping(value = "404") @@ -24,7 +24,7 @@ public class ErrorController { } @GetMapping(value = "403") - public String NotFound(String message, Model model) { + public String notFound(String message, Model model) { if (!StringUtils.isEmpty(message)) { model.addAttribute("message", message); } diff --git a/len-sys/src/main/java/com/len/controller/JobController.java b/len-sys/src/main/java/com/len/controller/JobController.java index 6691999..ad702fc 100644 --- a/len-sys/src/main/java/com/len/controller/JobController.java +++ b/len-sys/src/main/java/com/len/controller/JobController.java @@ -9,6 +9,7 @@ import com.len.exception.MyException; import com.len.service.JobService; import com.len.util.JsonUtil; import com.len.util.ReType; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -29,6 +30,7 @@ import org.springframework.web.bind.annotation.ResponseBody; */ @Controller @RequestMapping("/job") +@Api(value = "定时任务",description="定时任务") public class JobController extends BaseController { @Autowired diff --git a/len-sys/src/main/java/com/len/controller/LogController.java b/len-sys/src/main/java/com/len/controller/LogController.java index 7615002..e3c875d 100644 --- a/len-sys/src/main/java/com/len/controller/LogController.java +++ b/len-sys/src/main/java/com/len/controller/LogController.java @@ -12,6 +12,7 @@ import com.len.util.ReType; import java.util.List; +import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -32,6 +33,7 @@ import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping(value = "/log") @Slf4j +@Api(value = "日志管理",description="操作日志记录") public class LogController extends BaseController { @Autowired private SysLogMapper logMapper; diff --git a/len-sys/src/main/java/com/len/controller/LoginController.java b/len-sys/src/main/java/com/len/controller/LoginController.java index 0221688..56b3bf3 100644 --- a/len-sys/src/main/java/com/len/controller/LoginController.java +++ b/len-sys/src/main/java/com/len/controller/LoginController.java @@ -6,6 +6,7 @@ import com.len.entity.SysUser; import com.len.service.SysUserService; import com.len.util.CustomUsernamePasswordToken; import com.len.util.VerifyCodeUtils; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.shiro.SecurityUtils; @@ -31,6 +32,7 @@ import javax.servlet.http.HttpSession; */ @Controller @Slf4j +@Api(value = "登录业务",description="登录校验处理") public class LoginController { @Autowired diff --git a/len-sys/src/main/java/com/len/controller/MenuController.java b/len-sys/src/main/java/com/len/controller/MenuController.java index 2af7a6d..4c6ed36 100644 --- a/len-sys/src/main/java/com/len/controller/MenuController.java +++ b/len-sys/src/main/java/com/len/controller/MenuController.java @@ -5,19 +5,21 @@ import com.len.base.BaseController; import com.len.core.annotation.Log; import com.len.core.annotation.Log.LOG_TYPE; import com.len.entity.SysMenu; -import com.len.entity.SysRoleMenu; import com.len.exception.MyException; import com.len.service.MenuService; -import com.len.service.RoleMenuService; import com.len.util.BeanUtil; import com.len.util.JsonUtil; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; +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.ResponseBody; /** * @author zhuxiaomeng @@ -27,14 +29,12 @@ import org.springframework.web.bind.annotation.*; */ @RequestMapping("/menu") @Controller +@Api(value = "菜单管理",description="菜单业务处理") public class MenuController extends BaseController { @Autowired private MenuService menuService; - @Autowired - private RoleMenuService roleMenuService; - /** * 展示tree * @@ -119,36 +119,7 @@ public class MenuController extends BaseController { @PostMapping("/menu-del") @ResponseBody public JsonUtil del(String id) { - JsonUtil json = new JsonUtil(); - json.setFlag(false); - if (StringUtils.isEmpty(id)) { - json.setMsg("获取数据失败,请刷新重试!"); - return json; - } - SysRoleMenu sysRoleMenu = new SysRoleMenu(); - sysRoleMenu.setMenuId(id); - int count = roleMenuService.selectCount(sysRoleMenu); - //存在角色绑定不能删除 - if (count > 0) { - json.setMsg("本菜单存在绑定角色,请先解除绑定!"); - return json; - } - //存在下级菜单 不能解除 - SysMenu sysMenu = new SysMenu(); - sysMenu.setPId(id); - if (menuService.selectCount(sysMenu) > 0) { - json.setMsg("存在子菜单,请先删除子菜单!"); - return json; - } - boolean isDel = menuService.deleteByPrimaryKey(id) > 0; - if (isDel) { - json.setMsg("删除成功"); - json.setFlag(true); - } else { - json.setMsg("删除失败"); - } - return json; - + return menuService.del(id); } } diff --git a/len-sys/src/main/java/com/len/controller/PersonController.java b/len-sys/src/main/java/com/len/controller/PersonController.java index 66e98ff..802cad3 100644 --- a/len-sys/src/main/java/com/len/controller/PersonController.java +++ b/len-sys/src/main/java/com/len/controller/PersonController.java @@ -8,6 +8,7 @@ import com.len.service.SysUserService; import com.len.util.BeanUtil; import com.len.util.Checkbox; import com.len.util.JsonUtil; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -26,6 +27,7 @@ import java.util.List; */ @Controller @RequestMapping("/person") +@Api(value = "个人业务",description="个人业务处理") public class PersonController { @Autowired diff --git a/len-sys/src/main/java/com/len/controller/RoleController.java b/len-sys/src/main/java/com/len/controller/RoleController.java index a34e19b..d07b87b 100644 --- a/len-sys/src/main/java/com/len/controller/RoleController.java +++ b/len-sys/src/main/java/com/len/controller/RoleController.java @@ -5,16 +5,12 @@ import com.len.base.BaseController; import com.len.core.annotation.Log; import com.len.core.annotation.Log.LOG_TYPE; import com.len.entity.SysRole; -import com.len.entity.SysRoleMenu; -import com.len.entity.SysRoleUser; -import com.len.exception.MyException; import com.len.service.MenuService; import com.len.service.RoleMenuService; import com.len.service.RoleService; -import com.len.service.RoleUserService; -import com.len.util.BeanUtil; import com.len.util.JsonUtil; import com.len.util.ReType; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -26,8 +22,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; -import java.util.List; - /** * @author zhuxiaomeng * @date 2017/12/19. @@ -36,14 +30,12 @@ import java.util.List; */ @Controller @RequestMapping(value = "/role") +@Api(value = "用户角色管理",description="角色业务处理") public class RoleController extends BaseController { @Autowired private RoleService roleService; - @Autowired - private RoleUserService roleUserService; - @Autowired private MenuService menuService; @@ -88,25 +80,7 @@ public class RoleController extends BaseController { if (StringUtils.isEmpty(sysRole.getRoleName())) { JsonUtil.error("角色名称不能为空"); } - JsonUtil j = new JsonUtil(); - try { - roleService.insertSelective(sysRole); - //操作role-menu data - SysRoleMenu sysRoleMenu = new SysRoleMenu(); - sysRoleMenu.setRoleId(sysRole.getId()); - - if (menus != null) - for (String menu : menus) { - sysRoleMenu.setMenuId(menu); - roleMenuService.insert(sysRoleMenu); - } - j.setMsg("保存成功"); - } catch (MyException e) { - j.setMsg("保存失败"); - j.setFlag(false); - e.printStackTrace(); - } - return j; + return roleService.addRole(sysRole, menus); } @GetMapping(value = "updateRole") @@ -126,35 +100,10 @@ public class RoleController extends BaseController { @PostMapping(value = "updateRole") @ResponseBody public JsonUtil updateUser(SysRole role, String[] menus) { - JsonUtil jsonUtil = new JsonUtil(); - jsonUtil.setFlag(false); if (role == null) { - jsonUtil.setMsg("获取数据失败"); - return jsonUtil; + return JsonUtil.error("获取数据失败"); } - try { - SysRole oldRole = roleService.selectByPrimaryKey(role.getId()); - BeanUtil.copyNotNullBean(role, oldRole); - roleService.updateByPrimaryKeySelective(oldRole); - - SysRoleMenu sysRoleMenu = new SysRoleMenu(); - sysRoleMenu.setRoleId(role.getId()); - List menuList = roleMenuService.selectByCondition(sysRoleMenu); - for (SysRoleMenu sysRoleMenu1 : menuList) { - roleMenuService.deleteByPrimaryKey(sysRoleMenu1); - } - if (menus != null) - for (String menu : menus) { - sysRoleMenu.setMenuId(menu); - roleMenuService.insert(sysRoleMenu); - } - jsonUtil.setFlag(true); - jsonUtil.setMsg("修改成功"); - } catch (MyException e) { - jsonUtil.setMsg("修改失败"); - e.printStackTrace(); - } - return jsonUtil; + return roleService.updateUser(role, menus); } @ApiOperation(value = "/del", httpMethod = "POST", notes = "删除角色") @@ -166,22 +115,7 @@ public class RoleController extends BaseController { if (StringUtils.isEmpty(id)) { return JsonUtil.error("获取数据失败"); } - SysRoleUser sysRoleUser = new SysRoleUser(); - sysRoleUser.setRoleId(id); - JsonUtil j = new JsonUtil(); - try { - int count = roleUserService.selectCountByCondition(sysRoleUser); - if (count > 0) { - return JsonUtil.error("已分配给用户,删除失败"); - } - roleService.deleteByPrimaryKey(id); - j.setMsg("删除成功"); - } catch (MyException e) { - j.setMsg("删除失败"); - j.setFlag(false); - e.printStackTrace(); - } - return j; + return roleService.del(id); } } 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 e9d0055..147e98d 100644 --- a/len-sys/src/main/java/com/len/controller/UserController.java +++ b/len-sys/src/main/java/com/len/controller/UserController.java @@ -14,6 +14,7 @@ import com.len.exception.MyException; import com.len.service.RoleUserService; import com.len.service.SysUserService; import com.len.util.*; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; @@ -36,6 +37,7 @@ import java.util.List; //@Api(value="user") @Controller @RequestMapping(value = "/user") +@Api(value = "用户管理",description="用户管理业务") public class UserController extends BaseController { //private static final Logger diff --git a/len-sys/src/main/java/com/len/service/MenuService.java b/len-sys/src/main/java/com/len/service/MenuService.java index bda8a06..f8ba378 100644 --- a/len-sys/src/main/java/com/len/service/MenuService.java +++ b/len-sys/src/main/java/com/len/service/MenuService.java @@ -3,6 +3,8 @@ package com.len.service; import com.alibaba.fastjson.JSONArray; import com.len.base.BaseService; import com.len.entity.SysMenu; +import com.len.util.JsonUtil; + import java.util.List; /** @@ -29,4 +31,7 @@ public interface MenuService extends BaseService { List getUserMenu(String id); public JSONArray getMenuJsonByUser(List menuList); + + public JsonUtil del(String id); + } diff --git a/len-sys/src/main/java/com/len/service/RoleService.java b/len-sys/src/main/java/com/len/service/RoleService.java index 8597ddb..e34e8a9 100644 --- a/len-sys/src/main/java/com/len/service/RoleService.java +++ b/len-sys/src/main/java/com/len/service/RoleService.java @@ -2,6 +2,8 @@ package com.len.service; import com.len.base.BaseService; import com.len.entity.SysRole; +import com.len.util.JsonUtil; + import java.util.List; /** @@ -32,4 +34,10 @@ public interface RoleService extends BaseService { @Override List selectListByPage(SysRole sysRole); + + public JsonUtil addRole(SysRole sysRole, String[] menus); + + public JsonUtil updateUser(SysRole role, String[] menus); + + public JsonUtil del(String id); } diff --git a/len-sys/src/main/java/com/len/service/impl/MenuServiceImpl.java b/len-sys/src/main/java/com/len/service/impl/MenuServiceImpl.java index d860d21..8e6c9a4 100644 --- a/len-sys/src/main/java/com/len/service/impl/MenuServiceImpl.java +++ b/len-sys/src/main/java/com/len/service/impl/MenuServiceImpl.java @@ -8,6 +8,8 @@ import com.len.entity.SysRoleMenu; import com.len.mapper.SysMenuMapper; import com.len.mapper.SysRoleMenuMapper; import com.len.service.MenuService; +import com.len.service.RoleMenuService; +import com.len.util.JsonUtil; import com.len.util.TreeUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -32,6 +34,9 @@ public class MenuServiceImpl extends BaseServiceImpl implements @Autowired private SysRoleMenuMapper roleMenuMapper; + @Autowired + private RoleMenuService roleMenuService; + @Override public BaseMapper getMappser() { return menuDao; @@ -108,6 +113,39 @@ public class MenuServiceImpl extends BaseServiceImpl implements return jsonArr; } + @Override + public JsonUtil del(String id) { + JsonUtil json = new JsonUtil(); + json.setFlag(false); + if (StringUtils.isEmpty(id)) { + json.setMsg("获取数据失败,请刷新重试!"); + return json; + } + SysRoleMenu sysRoleMenu = new SysRoleMenu(); + sysRoleMenu.setMenuId(id); + int count = roleMenuService.selectCount(sysRoleMenu); + //存在角色绑定不能删除 + if (count > 0) { + json.setMsg("本菜单存在绑定角色,请先解除绑定!"); + return json; + } + //存在下级菜单 不能解除 + SysMenu sysMenu = new SysMenu(); + sysMenu.setPId(id); + if (selectCount(sysMenu) > 0) { + json.setMsg("存在子菜单,请先删除子菜单!"); + return json; + } + boolean isDel = deleteByPrimaryKey(id) > 0; + if (isDel) { + json.setMsg("删除成功"); + json.setFlag(true); + } else { + json.setMsg("删除失败"); + } + return json; + } + public SysMenu getChilds(SysMenu menu, int pNum, int num, List menuList) { for (SysMenu menus : menuList) { if (menu.getId().equals(menus.getPId()) && menus.getMenuType() == 0) { diff --git a/len-sys/src/main/java/com/len/service/impl/RoleServiceImpl.java b/len-sys/src/main/java/com/len/service/impl/RoleServiceImpl.java index 6867a90..69e33e0 100644 --- a/len-sys/src/main/java/com/len/service/impl/RoleServiceImpl.java +++ b/len-sys/src/main/java/com/len/service/impl/RoleServiceImpl.java @@ -3,56 +3,143 @@ package com.len.service.impl; import com.len.base.BaseMapper; import com.len.base.impl.BaseServiceImpl; import com.len.entity.SysRole; +import com.len.entity.SysRoleMenu; +import com.len.entity.SysRoleUser; +import com.len.exception.MyException; import com.len.mapper.SysRoleMapper; +import com.len.service.RoleMenuService; import com.len.service.RoleService; -import java.util.List; +import com.len.service.RoleUserService; +import com.len.util.BeanUtil; +import com.len.util.JsonUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + /** * @author zhuxiaomeng * @date 2017/12/19. * @email 154040976@qq.com */ @Service -public class RoleServiceImpl extends BaseServiceImpl implements RoleService { +public class RoleServiceImpl extends BaseServiceImpl implements RoleService { - @Autowired - private SysRoleMapper roleMapper; + @Autowired + private SysRoleMapper roleMapper; - @Override - public BaseMapper getMappser() { - return roleMapper; - } + @Autowired + private RoleMenuService roleMenuService; - @Override - public int deleteByPrimaryKey(String id) { - return roleMapper.deleteByPrimaryKey(id); - } + @Autowired + private RoleUserService roleUserService; - @Override - public int insert(SysRole record) { - record=super.addValue(record,true); - return roleMapper.insert(record); - } - - @Override - public SysRole selectByPrimaryKey(String id) { - return roleMapper.selectByPrimaryKey(id); - } + @Override + public BaseMapper getMappser() { + return roleMapper; + } - @Override - public int updateByPrimaryKeySelective(SysRole record) { - return roleMapper.updateByPrimaryKeySelective(record); - } + @Override + public int deleteByPrimaryKey(String id) { + return roleMapper.deleteByPrimaryKey(id); + } - @Override - public int updateByPrimaryKey(SysRole record) { - return roleMapper.updateByPrimaryKey(record); - } + @Override + public int insert(SysRole record) { + record = super.addValue(record, true); + return roleMapper.insert(record); + } - @Override - public List selectListByPage(SysRole sysRole) { - return roleMapper.selectListByPage(sysRole); - } + @Override + public SysRole selectByPrimaryKey(String id) { + return roleMapper.selectByPrimaryKey(id); + } + + @Override + public int updateByPrimaryKeySelective(SysRole record) { + return roleMapper.updateByPrimaryKeySelective(record); + } + + @Override + public int updateByPrimaryKey(SysRole record) { + return roleMapper.updateByPrimaryKey(record); + } + + @Override + public List selectListByPage(SysRole sysRole) { + return roleMapper.selectListByPage(sysRole); + } + + @Override + public JsonUtil addRole(SysRole sysRole, String[] menus) { + JsonUtil j = new JsonUtil(); + try { + insertSelective(sysRole); + //操作role-menu data + SysRoleMenu sysRoleMenu = new SysRoleMenu(); + sysRoleMenu.setRoleId(sysRole.getId()); + + if (menus != null) { + for (String menu : menus) { + sysRoleMenu.setMenuId(menu); + roleMenuService.insert(sysRoleMenu); + } + } + j.setMsg("保存成功"); + } catch (MyException e) { + j.setMsg("保存失败"); + j.setFlag(false); + e.printStackTrace(); + } + return j; + } + + @Override + public JsonUtil updateUser(SysRole role, String[] menus) { + JsonUtil jsonUtil = new JsonUtil(); + jsonUtil.setFlag(false); + try { + SysRole oldRole = selectByPrimaryKey(role.getId()); + BeanUtil.copyNotNullBean(role, oldRole); + updateByPrimaryKeySelective(oldRole); + + SysRoleMenu sysRoleMenu = new SysRoleMenu(); + sysRoleMenu.setRoleId(role.getId()); + List menuList = roleMenuService.selectByCondition(sysRoleMenu); + for (SysRoleMenu sysRoleMenu1 : menuList) { + roleMenuService.deleteByPrimaryKey(sysRoleMenu1); + } + if (menus != null) + for (String menu : menus) { + sysRoleMenu.setMenuId(menu); + roleMenuService.insert(sysRoleMenu); + } + jsonUtil.setFlag(true); + jsonUtil.setMsg("修改成功"); + } catch (MyException e) { + jsonUtil.setMsg("修改失败"); + e.printStackTrace(); + } + return jsonUtil; + } + + @Override + public JsonUtil del(String id) { + SysRoleUser sysRoleUser = new SysRoleUser(); + sysRoleUser.setRoleId(id); + JsonUtil j = new JsonUtil(); + try { + int count = roleUserService.selectCountByCondition(sysRoleUser); + if (count > 0) { + return JsonUtil.error("已分配给用户,删除失败"); + } + deleteByPrimaryKey(id); + j.setMsg("删除成功"); + } catch (MyException e) { + j.setMsg("删除失败"); + j.setFlag(false); + e.printStackTrace(); + } + return j; + } }