角色管理
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
@@ -41,7 +42,7 @@ class SysParamController {
|
||||
@ApiOperation("查询系统参数")
|
||||
//@SaCheckPermission("param:list")
|
||||
public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery page){
|
||||
return new ResponseEntity<>(paramService.queryAll(whereJson, page), HttpStatus.OK);
|
||||
return new ResponseEntity<>(TableDataInfo.build(paramService.queryAll(whereJson, page)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
package org.nl.system.controller.role;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
import org.nl.system.service.role.ISysRoleService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -52,5 +55,23 @@ public class SysRoleController {
|
||||
roleService.update(param);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除角色")
|
||||
@ApiOperation("删除角色")
|
||||
@DeleteMapping
|
||||
@SaCheckPermission("roles:del")
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
|
||||
roleService.deleteBatchByIds(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("修改角色菜单")
|
||||
@ApiOperation("修改角色菜单")
|
||||
@PutMapping(value = "/menu")
|
||||
// @SaCheckPermission("roles:edit")
|
||||
public ResponseEntity<Object> updateMenu(@RequestBody JSONObject form) {
|
||||
roleService.updateMenu(form);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.nl.system.controller.role;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单关联 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-16
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sysRolesMenus")
|
||||
public class SysRolesMenusController {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.nl.system.service.dict.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
@@ -24,6 +26,7 @@ public class Dict implements Serializable {
|
||||
/**
|
||||
* 字典标识
|
||||
*/
|
||||
@TableId
|
||||
private Long dictId;
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@ import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
@@ -14,9 +13,7 @@ import org.nl.modules.tools.MapOf;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.nl.system.service.param.dao.Param;
|
||||
import org.nl.system.service.param.dao.mapper.SysParamMapper;
|
||||
import org.nl.system.service.param.dto.ParamQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.system.service.dict.dao.Dict;
|
||||
import org.nl.system.service.role.dao.SysRole;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -26,4 +26,22 @@ public interface ISysRoleService extends IService<SysRole> {
|
||||
* @param param
|
||||
*/
|
||||
void create(JSONObject param);
|
||||
|
||||
/**
|
||||
* 更新角色
|
||||
* @param param
|
||||
*/
|
||||
void update(JSONObject param);
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
* @param ids
|
||||
*/
|
||||
void deleteBatchByIds(Set<Long> ids);
|
||||
|
||||
/**
|
||||
* 更新角色菜单
|
||||
* @param form
|
||||
*/
|
||||
void updateMenu(JSONObject form);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.nl.system.service.role;
|
||||
|
||||
import org.nl.system.service.role.dao.SysRolesMenus;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单关联 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-16
|
||||
*/
|
||||
public interface ISysRolesMenusService extends IService<SysRolesMenus> {
|
||||
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package org.nl.system.service.role.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -25,7 +28,8 @@ public class SysRole implements Serializable {
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
private Long roleId;
|
||||
@TableId
|
||||
private String roleId;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
@@ -75,17 +79,23 @@ public class SysRole implements Serializable {
|
||||
/**
|
||||
* 修改人标识
|
||||
*/
|
||||
private Long updateOptid;
|
||||
private Long updateId;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String updateOptname;
|
||||
private String updateName;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private String updateTime;
|
||||
|
||||
/**
|
||||
* 角色菜单
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<SysRolesMenus> menus;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.nl.system.service.role.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单关联
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-16
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_roles_menus")
|
||||
public class SysRolesMenus implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
private String menuId;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private String roleId;
|
||||
|
||||
|
||||
}
|
||||
@@ -14,5 +14,5 @@ import java.util.List;
|
||||
* @since 2022-12-15
|
||||
*/
|
||||
public interface SysRoleMapper extends BaseMapper<SysRole> {
|
||||
List<SysRole> list();
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,4 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.role.dao.mapper.SysRoleMapper">
|
||||
|
||||
<select id="list" resultType="org.nl.system.service.role.dao.SysRole">
|
||||
SELECT * FROM sys_role
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.nl.system.service.role.dao.mapper;
|
||||
|
||||
import org.nl.system.service.role.dao.SysRolesMenus;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单关联 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-16
|
||||
*/
|
||||
public interface SysRolesMenusMapper extends BaseMapper<SysRolesMenus> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.role.dao.mapper.SysRolesMenusMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -4,7 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -13,15 +13,17 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
import org.nl.system.service.dict.dao.Dict;
|
||||
import org.nl.system.service.role.ISysRoleService;
|
||||
import org.nl.system.service.role.dao.SysRole;
|
||||
import org.nl.system.service.role.dao.SysRolesMenus;
|
||||
import org.nl.system.service.role.dao.mapper.SysRoleMapper;
|
||||
import org.nl.system.service.role.dao.mapper.SysRolesMenusMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -37,18 +39,25 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
@Autowired
|
||||
private SysRoleMapper roleMapper;
|
||||
|
||||
@Autowired
|
||||
private SysRolesMenusMapper rolesMenusMapper;
|
||||
|
||||
@Override
|
||||
public IPage<SysRole> query(Map param, PageQuery page) {
|
||||
String blurry = null;
|
||||
if (ObjectUtil.isNotEmpty(param.get("blurry"))) blurry = param.get("blurry").toString();
|
||||
LambdaQueryWrapper<SysRole> lam = new LambdaQueryWrapper<>();
|
||||
lam.like(ObjectUtil.isNotEmpty(blurry), SysRole::getName, blurry);
|
||||
IPage<SysRole> pages = new Page<>(page.getPage(), page.getSize());
|
||||
IPage<SysRole> pages = new Page<>(page.getPage() + 1, page.getSize());
|
||||
roleMapper.selectPage(pages, lam);
|
||||
// 需要吧menus反回去
|
||||
pages.getRecords().forEach(sysRole -> sysRole.setMenus(rolesMenusMapper.selectList(new LambdaQueryWrapper<SysRolesMenus>()
|
||||
.eq(SysRolesMenus::getRoleId, sysRole.getRoleId()))));
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(JSONObject param) {
|
||||
//判断角色名字是否存在
|
||||
String name = param.getString("name");
|
||||
@@ -62,13 +71,60 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
// 插入
|
||||
sysRole.setRoleId(IdUtil.getSnowflake(1,1).nextId());
|
||||
sysRole.setRoleId(IdUtil.getSnowflake(1,1).nextIdStr());
|
||||
sysRole.setCreateId(userId);
|
||||
sysRole.setCreateName(nickName);
|
||||
sysRole.setCreateTime(now);
|
||||
sysRole.setUpdateOptid(userId);
|
||||
sysRole.setUpdateOptname(nickName);
|
||||
sysRole.setUpdateId(userId);
|
||||
sysRole.setUpdateName(nickName);
|
||||
sysRole.setUpdateTime(now);
|
||||
roleMapper.insert(sysRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(JSONObject param) {
|
||||
SysRole sysRole = JSONObject.parseObject(JSONObject.toJSONString(param), SysRole.class);
|
||||
//判断角色名字是否存在
|
||||
String name = sysRole.getName();
|
||||
if (StrUtil.isEmpty(name)) throw new BadRequestException("角色名字不能为空!");
|
||||
|
||||
//判断角色名字是否存在
|
||||
SysRole role = roleMapper.selectOne(new LambdaQueryWrapper<SysRole>().eq(SysRole::getName, sysRole.getName())
|
||||
.ne(SysRole::getRoleId, sysRole.getRoleId()));
|
||||
if (ObjectUtil.isNotEmpty(role)) throw new BadRequestException("角色【" + name + "】已存在!");
|
||||
Long userId = SecurityUtils.getCurrentUserId();
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
sysRole.setUpdateId(userId);
|
||||
sysRole.setUpdateName(nickName);
|
||||
sysRole.setUpdateTime(now);
|
||||
roleMapper.updateById(sysRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteBatchByIds(Set<Long> ids) {
|
||||
// 删除角色表
|
||||
roleMapper.deleteBatchIds(ids);
|
||||
|
||||
// 删除角色用户表
|
||||
rolesMenusMapper.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateMenu(JSONObject form) {
|
||||
Long roleId = form.getLong("roleId");
|
||||
JSONArray menus = form.getJSONArray("menus");
|
||||
// 删除
|
||||
rolesMenusMapper.delete(new LambdaQueryWrapper<SysRolesMenus>().eq(SysRolesMenus::getRoleId, roleId));
|
||||
for (int i = 0; i < menus.size(); i++) {
|
||||
JSONObject rmObj = menus.getJSONObject(i);
|
||||
SysRolesMenus rolesMenus = new SysRolesMenus();
|
||||
rolesMenus.setRoleId(roleId.toString());
|
||||
rolesMenus.setMenuId(rmObj.getString("menuId"));
|
||||
rolesMenusMapper.insert(rolesMenus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.nl.system.service.role.impl;
|
||||
|
||||
import org.nl.system.service.role.dao.SysRolesMenus;
|
||||
import org.nl.system.service.role.dao.mapper.SysRolesMenusMapper;
|
||||
import org.nl.system.service.role.ISysRolesMenusService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单关联 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-16
|
||||
*/
|
||||
@Service
|
||||
public class SysRolesMenusServiceImpl extends ServiceImpl<SysRolesMenusMapper, SysRolesMenus> implements ISysRolesMenusService {
|
||||
|
||||
}
|
||||
@@ -9,13 +9,10 @@ import org.nl.AppRun;
|
||||
import org.nl.system.service.dict.ISysDictService;
|
||||
import org.nl.system.service.dict.dao.Dict;
|
||||
import org.nl.system.service.dict.dao.mapper.SysDictMapper;
|
||||
import org.nl.system.service.role.dao.SysRole;
|
||||
import org.nl.system.service.role.dao.mapper.SysRoleMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description:
|
||||
|
||||
Reference in New Issue
Block a user