角色权限模块接口编写

hehai
shijie 4 years ago
parent bfc221b9de
commit e3f48ad9b5
  1. 140
      src/main/java/com/msdw/tms/controller/SysPermissionController.java
  2. 4
      src/main/java/com/msdw/tms/dao/SysPermissionMapper.java
  3. 10
      src/main/java/com/msdw/tms/dao/SysRoleMapper.java
  4. 13
      src/main/java/com/msdw/tms/dao/SysRolePermissionMapper.java
  5. 4
      src/main/java/com/msdw/tms/dao/SysUserRoleMapper.java
  6. 10
      src/main/java/com/msdw/tms/entity/SysPermission.java
  7. 83
      src/main/java/com/msdw/tms/entity/request/RolePermissionRequest.java
  8. 3
      src/main/java/com/msdw/tms/entity/response/CommonCode.java
  9. 80
      src/main/java/com/msdw/tms/entity/response/RolePermissionResponse.java
  10. 29
      src/main/java/com/msdw/tms/service/ISysPermissionService.java
  11. 107
      src/main/java/com/msdw/tms/service/impl/SysPermissionServiceImpl.java
  12. 12
      src/main/resources/application.yml
  13. 16
      src/main/resources/mapper/tms/SysPermissionMapper.xml
  14. 26
      src/main/resources/mapper/tms/SysRoleMapper.xml
  15. 28
      src/main/resources/mapper/tms/SysRolePermissionMapper.xml
  16. 9
      src/main/resources/mapper/tms/SysUserRoleMapper.xml

@ -1,9 +1,24 @@
package com.msdw.tms.controller; package com.msdw.tms.controller;
import org.springframework.web.bind.annotation.RequestMapping; import com.msdw.tms.common.exception.ExceptionCast;
import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.entity.SysPermission;
import com.msdw.tms.entity.SysRole;
import com.msdw.tms.entity.SysRolePermission;
import com.msdw.tms.entity.request.RolePermissionRequest;
import com.msdw.tms.entity.response.CommonCode;
import com.msdw.tms.entity.response.ResponseResult;
import com.msdw.tms.entity.response.RolePermissionResponse;
import com.msdw.tms.service.ISysPermissionService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;
/** /**
* <p> * <p>
@ -15,6 +30,127 @@ import org.springframework.web.bind.annotation.RestController;
*/ */
@RestController @RestController
@RequestMapping("/sys-permission") @RequestMapping("/sys-permission")
@Api(tags = {"角色权限管理"})
public class SysPermissionController { public class SysPermissionController {
@Autowired
private ISysPermissionService permissionService;
/**
* 权限菜单树形列表展示
* @return
*/
@GetMapping("/tree")
public ResponseResult tree(){
List<SysPermission> list = permissionService.listWithTree();
return new ResponseResult<List<SysPermission>>().SUCCESS(list);
}
/**
* 新增角色权限
*/
@Transactional
@PostMapping("/saveRolePermission")
public ResponseResult saveRolePermission(@Valid @RequestBody RolePermissionRequest rolePermission) {
Date date = new Date();
rolePermission.setCreateTime(date);
rolePermission.setMotifyTime(date);
//此处要判重,新增的角色名称要唯一
int count = permissionService.uniqueRoleName(rolePermission.getName());
if(count >0){
ExceptionCast.cast(CommonCode.ROLE_NAME_EXIST);
}
//新增角色到角色表
int request = permissionService.addHrmsRole(rolePermission);
//根据选中的permissionId批量新增数据到hrms_role_permission
List<Long> asList = Arrays.asList(rolePermission.getPermissionIds());
List<RolePermissionRequest> rolePermissionList = getRolePermissionList(asList, rolePermission.getRoleId());
boolean result = permissionService.addHrmsRolePermission(rolePermissionList);
return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL();
}
private List<RolePermissionRequest> getRolePermissionList(List<Long> asList, Long roleId) {
return asList.stream().map(permissionId -> {
RolePermissionRequest request = new RolePermissionRequest();
request.setRoleId(roleId);
request.setPermissionId(permissionId);
return request;
}).collect(Collectors.toList());
}
/**
* 修改角色权限
*/
@Transactional
@PostMapping("/updateRolePermission")
public ResponseResult updateRolePermission(@Valid @RequestBody RolePermissionRequest rolePermission) {
Date date = new Date();
rolePermission.setMotifyTime(date);
//根据角色Id修改角色内容
int request = permissionService.updateHrmsRole(rolePermission);
//删除该角色Id对应的所有权限
List<Long> asList = Arrays.asList(rolePermission.getPermissionIds());
permissionService.deleteHrmsRolePermission(rolePermission.getRoleId());
//根据选中的permissionId批量新增数据到hrms_role_permission
List<RolePermissionRequest> rolePermissionList = getRolePermissionList(asList, rolePermission.getRoleId());
boolean result = permissionService.addHrmsRolePermission(rolePermissionList);
return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL();
}
/**
* 删除用户角色权限
*/
@Transactional
@PostMapping("/delRolePermission")
public ResponseResult delRolePermission(@RequestBody RolePermissionRequest rolePermission) {
//根据角色Id查询该角色是否有用户关联
int count = permissionService.queryCountByRoleId(rolePermission.getRoleIds());
if(count >0){
ExceptionCast.cast(CommonCode.ROLE_EMP_EXIST);
}
//没有关联则根据roleId删除hrms_role表对应记录
boolean b = permissionService.deleteHrmsRoleByRoleId(rolePermission.getRoleIds());
//根据角色id删除对应所有权限
boolean result = permissionService.deleteHrmsRolePermission(rolePermission.getRoleIds());
return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL();
}
/**
* 查看权限数组
* @param roleId
* @return
*/
@GetMapping("/queryPermissionArrById")
public ResponseResult queryPermissionArrById(@RequestParam("roleId") Long roleId) {
List<SysRolePermission> list = permissionService.queryPermissionArrById(roleId);
ArrayList<Integer> sb = new ArrayList<Integer>();
for (SysRolePermission rolePermission:list) {
sb.add(rolePermission.getPermissionId().intValue());
}
Integer[] ids = sb.toArray(new Integer[sb.size()]);
//根据roleId查询角色名称和角色描述
SysRole roleMsg = permissionService.queryRoleMsg(roleId);
Map map = new HashMap();
map.put("permissionIds",ids);
map.put("name",roleMsg.getName());
map.put("description",roleMsg.getDescription());
return new ResponseResult<List<RolePermissionResponse>>().SUCCESS(map);
}
/**
* 角色权限列表展示
* @param page
* @param size
* @return
*/
@GetMapping("/rolePermissionList")
public ResponseResult rolePermissionList(@RequestParam("page") Integer page,
@RequestParam("size") Integer size,@RequestParam("name")String name) {
PageUtils data = permissionService.queryPage(page, size, name);
return new ResponseResult<PageUtils>().SUCCESS(data);
}
} }

@ -1,7 +1,10 @@
package com.msdw.tms.dao; package com.msdw.tms.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.msdw.tms.entity.SysPermission; import com.msdw.tms.entity.SysPermission;
import com.msdw.tms.entity.response.RolePermissionResponse;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
@ -15,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SysPermissionMapper extends BaseMapper<SysPermission> { public interface SysPermissionMapper extends BaseMapper<SysPermission> {
IPage<RolePermissionResponse> pageByCondition(Page page,String name);
} }

@ -2,7 +2,11 @@ package com.msdw.tms.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.msdw.tms.entity.SysRole; import com.msdw.tms.entity.SysRole;
import com.msdw.tms.entity.request.RolePermissionRequest;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* <p> * <p>
@ -15,4 +19,10 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SysRoleMapper extends BaseMapper<SysRole> { public interface SysRoleMapper extends BaseMapper<SysRole> {
int addHrmsRole(RolePermissionRequest rolePermission);
int updateHrmsRole(RolePermissionRequest rolePermission);
boolean deleteHrmsRoleByRoleId(@Param("roleIds") List<Long> roleIds);
} }

@ -2,7 +2,11 @@ package com.msdw.tms.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.msdw.tms.entity.SysRolePermission; import com.msdw.tms.entity.SysRolePermission;
import com.msdw.tms.entity.request.RolePermissionRequest;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* <p> * <p>
@ -15,4 +19,13 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SysRolePermissionMapper extends BaseMapper<SysRolePermission> { public interface SysRolePermissionMapper extends BaseMapper<SysRolePermission> {
int uniqueRoleName(String name);
boolean addHrmsRolePermission(@Param("rolePermissionList") List<RolePermissionRequest> rolePermissionList);
boolean deleteHrmsRolePermission(@Param("roleIds") List<Long> roleIds);
boolean deleteHrmsRolePermissionSingle(Long roleId);
List<SysRolePermission> queryPermissionArrById(Long roleId);
} }

@ -3,6 +3,9 @@ package com.msdw.tms.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.msdw.tms.entity.SysUserRole; import com.msdw.tms.entity.SysUserRole;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* <p> * <p>
@ -15,4 +18,5 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> { public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
int queryCountByRoleId(@Param("roleIds") List<Long> roleIds);
} }

@ -1,12 +1,15 @@
package com.msdw.tms.entity; package com.msdw.tms.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date; import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* <p> * <p>
@ -87,4 +90,11 @@ public class SysPermission implements Serializable {
* 更新时间 * 更新时间
*/ */
private Date motifyTime; private Date motifyTime;
/**
* 子权限
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@TableField(exist = false)
private List<SysPermission> children;
} }

@ -0,0 +1,83 @@
package com.msdw.tms.entity.request;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 记录菜单权限
*
* @author gongsj
* @email gongsj@gmail.com
* @date 2020-09-07 17:12:14
*/
@Data
public class RolePermissionRequest implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 角色id
*/
private Long roleId;
/**
* 角色ids
*/
private Long[] roleIds;
/**
* 角色名称
*/
private String name;
/**
* 角色描述
*/
private String description;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date motifyTime;
/**
* 权限ids
*/
@NotEmpty(message = "权限至少选中一项!")
private Long[] permissionIds;
private Long permissionId;
/**
* 拥有权限名称
*/
private String permissionName;
/**
* 父级id
*/
private Long parentId;
/**
* 子权限
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@TableField(exist = false)
private List<RolePermissionRequest> children;
/**
* 排序
*/
private Integer sort;
}

@ -18,6 +18,9 @@ public enum CommonCode implements ResultCode {
REPEAT_INEXCEL(false, 10010, "试题在excel表中重复!"), REPEAT_INEXCEL(false, 10010, "试题在excel表中重复!"),
EVALUATION_QUESTION_NUM_INVALID(false, 10011, "当前测评题数设置为0,请先设置测评题数!"), EVALUATION_QUESTION_NUM_INVALID(false, 10011, "当前测评题数设置为0,请先设置测评题数!"),
FAIL(false, 11111, "操作失败!"), FAIL(false, 11111, "操作失败!"),
ROLE_NAME_EXIST(false,20001,"该角色名称已存在,请重新输入!"),
ROLE_EMP_EXIST(false,44001,"该角色有用户关联,不能删除!"),
SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!");
//操作是否成功 //操作是否成功
boolean success; boolean success;

@ -0,0 +1,80 @@
package com.msdw.tms.entity.response;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 记录菜单权限
*
* @author gongsj
* @email gongsj@gmail.com
* @date 2020-09-07 17:12:14
*/
@Data
@TableName("hrms_permission")
public class RolePermissionResponse implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 角色id
*/
@ApiModelProperty("id")
private Long roleId;
/**
* 角色名称
*/
@ApiModelProperty("名称")
private String name;
/**
* 角色描述
*/
@ApiModelProperty("角色描述")
private String description;
/**
* 权限id
*/
@ApiModelProperty("权限id")
private Long permissionId;
/**
* 拥有权限名称
*/
@ApiModelProperty("权限名称")
private String permissionName;
/**
* 父级id
*/
@ApiModelProperty("父级id")
private Long parentId;
/**
* 子权限
*/
@ApiModelProperty("子权限")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@TableField(exist = false)
private List<RolePermissionResponse> children;
/**
* 排序
*/
@ApiModelProperty("子权限")
private Integer sort;
/**
* 权限标识
*/
private String code;
private boolean disabled=true;
}

@ -1,7 +1,13 @@
package com.msdw.tms.service; package com.msdw.tms.service;
import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.entity.SysPermission; import com.msdw.tms.entity.SysPermission;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.msdw.tms.entity.SysRole;
import com.msdw.tms.entity.SysRolePermission;
import com.msdw.tms.entity.request.RolePermissionRequest;
import java.util.List;
/** /**
* <p> * <p>
@ -13,4 +19,27 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/ */
public interface ISysPermissionService extends IService<SysPermission> { public interface ISysPermissionService extends IService<SysPermission> {
List<SysPermission> listWithTree();
int uniqueRoleName(String name);
int addHrmsRole(RolePermissionRequest rolePermission);
boolean addHrmsRolePermission(List<RolePermissionRequest> rolePermissionList);
int updateHrmsRole(RolePermissionRequest rolePermission);
boolean deleteHrmsRolePermission(Long roleId);
boolean deleteHrmsRolePermission(Long[] roleIds);
int queryCountByRoleId(Long[] roleIds);
boolean deleteHrmsRoleByRoleId(Long[] roleIds);
List<SysRolePermission> queryPermissionArrById(Long roleId);
SysRole queryRoleMsg(Long roleId);
PageUtils queryPage(Integer page, Integer size, String name);
} }

@ -1,11 +1,28 @@
package com.msdw.tms.service.impl; package com.msdw.tms.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.msdw.tms.common.utils.PageUtils;
import com.msdw.tms.dao.SysPermissionMapper; import com.msdw.tms.dao.SysPermissionMapper;
import com.msdw.tms.dao.SysRoleMapper;
import com.msdw.tms.dao.SysRolePermissionMapper;
import com.msdw.tms.dao.SysUserRoleMapper;
import com.msdw.tms.entity.SysPermission; import com.msdw.tms.entity.SysPermission;
import com.msdw.tms.entity.SysRole;
import com.msdw.tms.entity.SysRolePermission;
import com.msdw.tms.entity.request.RolePermissionRequest;
import com.msdw.tms.entity.response.RolePermissionResponse;
import com.msdw.tms.service.ISysPermissionService; import com.msdw.tms.service.ISysPermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* <p> * <p>
* 菜单权限表 服务实现类 * 菜单权限表 服务实现类
@ -17,4 +34,94 @@ import org.springframework.stereotype.Service;
@Service @Service
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements ISysPermissionService { public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements ISysPermissionService {
@Resource
private SysRolePermissionMapper rolePermissionMapper;
@Resource
private SysRoleMapper roleMapper;
@Resource
private SysUserRoleMapper userRoleMapper;
@Override
public List<SysPermission> listWithTree() {
/* List<SysPermission>list = this.getBaseMapper().queryPermissionTree();
return getPermissionTreeList(list,0L);*/
System.out.println("this.list()=================="+this.list());
return getPermissionTreeList(this.list(), 0L);
}
private List<SysPermission> getPermissionTreeList(List<SysPermission> list, Long parentId){
return list.stream()
.filter(item -> parentId.equals(item.getParentId()))
.peek(item -> item.setChildren(getPermissionTreeList(list, item.getId())))
.sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort())))
.collect(Collectors.toList());
}
@Override
public int uniqueRoleName(String name) {
return rolePermissionMapper.uniqueRoleName(name);
}
@Override
public int addHrmsRole(RolePermissionRequest rolePermission) {
int request = roleMapper.addHrmsRole(rolePermission);
return request;
}
@Override
public boolean addHrmsRolePermission(List<RolePermissionRequest> rolePermissionList) {
return rolePermissionMapper.addHrmsRolePermission(rolePermissionList);
}
@Override
public int updateHrmsRole(RolePermissionRequest rolePermission) {
return roleMapper.updateHrmsRole(rolePermission);
}
@Override
public boolean deleteHrmsRolePermission(Long roleId) {
return rolePermissionMapper.deleteHrmsRolePermissionSingle(roleId);
}
@Override
public boolean deleteHrmsRolePermission(Long[] roleIds) {
return rolePermissionMapper.deleteHrmsRolePermission(Arrays.asList(roleIds));
}
@Override
public int queryCountByRoleId(Long[] roleIds) {
int count = userRoleMapper.queryCountByRoleId(Arrays.asList(roleIds));
return count;
}
@Override
public boolean deleteHrmsRoleByRoleId(Long[] roleIds) {
return roleMapper.deleteHrmsRoleByRoleId(Arrays.asList(roleIds));
}
@Override
public List<SysRolePermission> queryPermissionArrById(Long roleId) {
return rolePermissionMapper.queryPermissionArrById(roleId);
}
@Override
public SysRole queryRoleMsg(Long roleId) {
return roleMapper.selectById(roleId);
}
@Override
public PageUtils queryPage(Integer page, Integer size, String name) {
//分页参数
if (page <= 0) {
page = 1;
}
if (size <= 0) {
size = 10;
}
IPage<RolePermissionResponse> systemLogVo = this.getBaseMapper().pageByCondition(new Page(page, size),name);
return new PageUtils(systemLogVo);
}
} }

@ -5,12 +5,12 @@ spring:
# url: jdbc:mysql://www.liuwanr.cn:3306/huoran?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai # url: jdbc:mysql://www.liuwanr.cn:3306/huoran?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
# username: super # username: super
# password: huoran888 # password: huoran888
url: jdbc:mysql://rm-wz9y13wf7u8q8610fwo.mysql.rds.aliyuncs.com:3306/huoran?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai # url: jdbc:mysql://rm-wz9y13wf7u8q8610fwo.mysql.rds.aliyuncs.com:3306/huoran?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: super # username: super
password: huoran888 # password: huoran888
# url: jdbc:mysql://localhost:3306/msdw_tms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://localhost:3306/msdw_tms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
# username: root username: root
# password: root password: root
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
# redis: # redis:
# host: www.liuwanr.cn # host: www.liuwanr.cn

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.msdw.tms.mapper.SysPermissionMapper"> <mapper namespace="com.msdw.tms.dao.SysPermissionMapper">
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.msdw.tms.entity.SysPermission"> <resultMap id="BaseResultMap" type="com.msdw.tms.entity.SysPermission">
@ -19,4 +19,18 @@
<result column="motify_time" property="motifyTime" /> <result column="motify_time" property="motifyTime" />
</resultMap> </resultMap>
<select id="pageByCondition" resultType="com.msdw.tms.entity.response.RolePermissionResponse">
select rp.role_id as roleId, hr.`name`,hr.description,GROUP_CONCAT(hp.`name`separator '/') as permissionName
FROM sys_role_permission rp
LEFT JOIN sys_role hr on hr.id = rp.role_id
LEFT JOIN sys_permission hp on hp.id= rp.permission_id
<where>
hr.del_or_not=0
<if test="name != null and name != ''">
AND hr.name LIKE CONCAT('%' #{name} '%')
</if>
</where>
GROUP BY rp.role_id
</select>
</mapper> </mapper>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.msdw.tms.mapper.SysRoleMapper"> <mapper namespace="com.msdw.tms.dao.SysRoleMapper">
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.msdw.tms.entity.SysRole"> <resultMap id="BaseResultMap" type="com.msdw.tms.entity.SysRole">
@ -13,4 +13,28 @@
<result column="code" property="code" /> <result column="code" property="code" />
</resultMap> </resultMap>
<insert id="addHrmsRole" parameterType="com.msdw.tms.entity.request.RolePermissionRequest"
useGeneratedKeys="true" keyProperty="roleId" keyColumn="id">
INSERT INTO sys_role
(`name`,description,create_time,motify_time)
values (#{name},#{description},#{createTime},#{motifyTime});
</insert>
<update id="updateHrmsRole" parameterType="com.msdw.tms.entity.request.RolePermissionRequest">
UPDATE sys_role
<set>
`name`=#{name},
description=#{description},
motify_time=#{motifyTime},
</set>
WHERE id = #{roleId}
</update>
<delete id="deleteHrmsRoleByRoleId">
update sys_role set del_or_not = 1 where id IN
<foreach collection="roleIds" index="index" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</delete>
</mapper> </mapper>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.msdw.tms.mapper.SysRolePermissionMapper"> <mapper namespace="com.msdw.tms.dao.SysRolePermissionMapper">
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.msdw.tms.entity.SysRolePermission"> <resultMap id="BaseResultMap" type="com.msdw.tms.entity.SysRolePermission">
@ -9,4 +9,30 @@
<result column="permission_id" property="permissionId" /> <result column="permission_id" property="permissionId" />
</resultMap> </resultMap>
<select id="uniqueRoleName" parameterType="string" resultType="java.lang.Integer">
select count(0) from sys_role where `name` = #{name}
</select>
<insert id="addHrmsRolePermission" parameterType="com.msdw.tms.entity.request.RolePermissionRequest">
INSERT INTO sys_role_permission (role_id,permission_id) values
<foreach collection="rolePermissionList" index="index" separator="," item="item">
(#{item.roleId},#{item.permissionId})
</foreach>
</insert>
<delete id="deleteHrmsRolePermission">
delete from sys_role_permission where role_id in
<foreach collection="roleIds" index="index" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</delete>
<delete id="deleteHrmsRolePermissionSingle">
delete from sys_role_permission where role_id=#{roleId}
</delete>
<select id="queryPermissionArrById" resultMap="BaseResultMap">
select id, permission_id from sys_role_permission where role_id = #{roleId}
</select>
</mapper> </mapper>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.msdw.tms.mapper.SysUserRoleMapper"> <mapper namespace="com.msdw.tms.dao.SysUserRoleMapper">
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.msdw.tms.entity.SysUserRole"> <resultMap id="BaseResultMap" type="com.msdw.tms.entity.SysUserRole">
@ -9,4 +9,11 @@
<result column="role_id" property="roleId" /> <result column="role_id" property="roleId" />
</resultMap> </resultMap>
<select id="queryCountByRoleId" resultType="java.lang.Integer">
select count(0) from sys_user_role where role_id in
<foreach collection="roleIds" index="index" open="(" separator="," close=")" item="item">
#{item}
</foreach>
</select>
</mapper> </mapper>

Loading…
Cancel
Save