| | |
| | | package com.stylefeng.guns.modular.code.controller; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.google.gson.Gson; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.stylefeng.guns.core.cache.CacheKit; |
| | | import com.stylefeng.guns.core.common.annotion.BussinessLog; |
| | | import com.stylefeng.guns.core.common.constant.Const; |
| | |
| | | import com.stylefeng.guns.core.node.ZTreeNode; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.dto.DeptQuery; |
| | | import com.stylefeng.guns.modular.system.dto.TreeBean; |
| | | import com.stylefeng.guns.modular.system.model.Dept; |
| | | import com.stylefeng.guns.modular.system.model.Role; |
| | | import com.stylefeng.guns.modular.system.model.User; |
| | | import com.stylefeng.guns.modular.system.service.IMenuService; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @GetMapping(value = "/list") |
| | | @ApiOperation(value = "列表", tags = {"后台-角色管理"}) |
| | | @ResponseBody |
| | | public Object list(@RequestParam(required = false) String roleName) { |
| | | List<Map<String, Object>> roles = this.roleService.selectRoles(roleName); |
| | | return roles; |
| | | public ResultUtil<PageInfo<Map>> list(DeptQuery req) { |
| | | // PageHelper.startPage(req.getPageNum(),req.getPageSize()); |
| | | List<Map<String, Object>> roles = this.roleService.selectRoles(req.getDeptName()); |
| | | PageInfo<Map> info=new PageInfo<>(roles); |
| | | return ResultUtil.success(info); |
| | | } |
| | | |
| | | |
| | | @PostMapping(value = "/add") |
| | | @BussinessLog(value = "添加角色", key = "name", dict = RoleDict.class) |
| | | @ApiOperation(value = "添加角色", tags = {"后台-角色管理"}) |
| | | @ResponseBody |
| | | public ResultUtil add(@Valid Role role, BindingResult result) { |
| | | public ResultUtil add(@Valid Role role, @RequestParam("ids") String ids,BindingResult result) { |
| | | if (result.hasErrors()) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | |
| | | role.setDeptid(0); |
| | | role.setPid(0); |
| | | role.setInsertTime(new Date()); |
| | | |
| | | role.setCreateBy(Objects.requireNonNull(ShiroKit.getUser()).id); |
| | | |
| | | this.roleService.insert(role); |
| | | this.roleService.setAuthority(role.getId(), ids); |
| | | return ResultUtil.success("添加成功"); |
| | | } |
| | | |
| | |
| | | @BussinessLog(value = "修改角色", key = "name", dict = RoleDict.class) |
| | | @ApiOperation(value = "修改角色", tags = {"后台-角色管理"}) |
| | | @ResponseBody |
| | | public ResultUtil edit(@Valid Role role, BindingResult result) { |
| | | if (result.hasErrors()) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | public ResultUtil edit(@RequestParam("id") Integer roleId, @RequestParam("name") String name,@RequestParam("ids") String ids) { |
| | | |
| | | Role role = roleService.selectById(roleId); |
| | | role.setDeptid(0); |
| | | role.setName(name); |
| | | role.setPid(0); |
| | | this.roleService.updateById(role); |
| | | this.roleService.setAuthority(role.getId(), ids); |
| | | return ResultUtil.success("修改成功"); |
| | | } |
| | | |
| | | |
| | | @PostMapping(value = "/delete") |
| | | @BussinessLog(value = "删除角色", key = "name", dict = RoleDict.class) |
| | |
| | | @ApiOperation(value = "角色分配权限获取列表", tags = {"后台-角色管理"}) |
| | | @ResponseBody |
| | | public List<TreeBean> menuTreeListByRoleId(@PathVariable Integer roleId) { |
| | | |
| | | List<Long> menuIds = this.menuService.getMenuIdsByRoleId(roleId); |
| | | if (ToolUtil.isEmpty(menuIds)) { |
| | | List<ZTreeNode> roleTreeList = this.menuService.menuTreeList(); |
| | | // List<ZTreeNode> parent = roleTreeList.stream().filter(e -> e.getpId() == 0).collect(Collectors.toList()); |
| | | List<TreeBean> root = ListToTreeUtil.toTree(roleTreeList, "root"); |
| | | return root; |
| | | }else { |
| | | for (Long menuId : menuIds) { |
| | | System.err.println("菜单id:"+menuId); |
| | | } |
| | | List<ZTreeNode> roleTreeListByUserId = this.menuService.menuTreeListByMenuIds(menuIds); |
| | | // List<ZTreeNode> parent = roleTreeListByUserId.stream().filter(e -> e.getpId() == 0).collect(Collectors.toList()); |
| | | List<TreeBean> root = ListToTreeUtil.toTree(roleTreeListByUserId, "root"); |
| | | return root; |
| | | } |
| | | } |
| | | |
| | | @DataSource(name = "dataSourceGuns") |
| | | @RequestMapping("/setAuthority") |
| | | @BussinessLog(value = "配置权限操作", key = "roleId,ids", dict = RoleDict.class) |
| | | @ResponseBody |
| | | public ResultUtil setAuthority(@RequestParam("roleId") Integer roleId, @RequestParam("ids") String ids) { |
| | | if (ToolUtil.isOneEmpty(roleId)) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | this.roleService.setAuthority(roleId, ids); |
| | | Role role = roleService.selectById(roleId); |
| | | return ResultUtil.success("分配成功"); |
| | | } |
| | | private List<ZTreeNode> getParent(List<ZTreeNode> roleTreeListByUserId,List<ZTreeNode> parent){ |
| | | List<ZTreeNode> result = new ArrayList<>(); |
| | | for (ZTreeNode zTreeNode : parent) { |
| | |
| | | } |
| | | |
| | | |
| | | @DataSource(name = "dataSourceGuns") |
| | | @RequestMapping("/setAuthority") |
| | | @BussinessLog(value = "配置权限操作", key = "roleId,ids", dict = RoleDict.class) |
| | | @ResponseBody |
| | | public ResultUtil setAuthority(@RequestParam("roleId") Integer roleId, @RequestParam("ids") String ids) { |
| | | if (ToolUtil.isOneEmpty(roleId)) { |
| | | throw new GunsException(BizExceptionEnum.REQUEST_NULL); |
| | | } |
| | | this.roleService.setAuthority(roleId, ids); |
| | | Role role = roleService.selectById(roleId); |
| | | return ResultUtil.success("分配成功"); |
| | | } |
| | | |
| | | |
| | | |
| | | |