正在显示
6 个修改的文件
包含
154 行增加
和
0 行删除
| @@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; | @@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; | ||
| 4 | import com.tianbo.warehouse.annotation.LogAnnotation; | 4 | import com.tianbo.warehouse.annotation.LogAnnotation; | 
| 5 | import com.tianbo.warehouse.controller.response.ResultJson; | 5 | import com.tianbo.warehouse.controller.response.ResultJson; | 
| 6 | import com.tianbo.warehouse.model.ROLE; | 6 | import com.tianbo.warehouse.model.ROLE; | 
| 7 | +import com.tianbo.warehouse.model.RoleDataPermission; | ||
| 7 | import com.tianbo.warehouse.model.RolePermission; | 8 | import com.tianbo.warehouse.model.RolePermission; | 
| 8 | import com.tianbo.warehouse.service.RoleService; | 9 | import com.tianbo.warehouse.service.RoleService; | 
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; | 
| @@ -53,6 +54,17 @@ public class RoleController { | @@ -53,6 +54,17 @@ public class RoleController { | ||
| 53 | return i==1 ? new ResultJson("200","设置权限成功") :new ResultJson("500","设置权限失败"); | 54 | return i==1 ? new ResultJson("200","设置权限成功") :new ResultJson("500","设置权限失败"); | 
| 54 | } | 55 | } | 
| 55 | 56 | ||
| 57 | + /** | ||
| 58 | + * 设置角色的的数据权限 | ||
| 59 | + * @return | ||
| 60 | + */ | ||
| 61 | + @LogAnnotation(moduleName = "数据权限设置",operate = "数据权限设置接口") | ||
| 62 | + @PostMapping("/dataPermSet") | ||
| 63 | + public ResultJson dataPermissionSet(@RequestBody RoleDataPermission roleDataPermission){ | ||
| 64 | + int i = roleService.setRoleDataPermissoin(roleDataPermission); | ||
| 65 | + return i==1 ? new ResultJson("200","设置权限成功") :new ResultJson("500","设置权限失败"); | ||
| 66 | + } | ||
| 67 | + | ||
| 56 | @LogAnnotation(moduleName = "岗位/角色管理",operate = "岗位/角色修改") | 68 | @LogAnnotation(moduleName = "岗位/角色管理",operate = "岗位/角色修改") | 
| 57 | @PutMapping("/edit") | 69 | @PutMapping("/edit") | 
| 58 | @ResponseBody | 70 | @ResponseBody | 
| 1 | +package com.tianbo.warehouse.dao; | ||
| 2 | + | ||
| 3 | +import com.tianbo.warehouse.model.RoleDataPermission; | ||
| 4 | + | ||
| 5 | +public interface RoleDataPermissionDao { | ||
| 6 | + int deleteByPrimaryKey(Integer id); | ||
| 7 | + | ||
| 8 | + int delPermByRoleId(Integer id); | ||
| 9 | + | ||
| 10 | + int insert(RoleDataPermission record); | ||
| 11 | + | ||
| 12 | + int insertSelective(RoleDataPermission record); | ||
| 13 | + | ||
| 14 | + int insertRoleDataPerm(RoleDataPermission record); | ||
| 15 | + | ||
| 16 | + RoleDataPermission selectByPrimaryKey(Integer id); | ||
| 17 | + | ||
| 18 | + int updateByPrimaryKeySelective(RoleDataPermission record); | ||
| 19 | + | ||
| 20 | + int updateByPrimaryKey(RoleDataPermission record); | ||
| 21 | +} | 
| 1 | +package com.tianbo.warehouse.model; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | +import java.util.List; | ||
| 5 | + | ||
| 6 | +import lombok.Data; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * role_data_permission | ||
| 10 | + * @author | ||
| 11 | + */ | ||
| 12 | +@Data | ||
| 13 | +public class RoleDataPermission implements Serializable { | ||
| 14 | + private Integer id; | ||
| 15 | + | ||
| 16 | + private Integer roleId; | ||
| 17 | + | ||
| 18 | + private Integer permissionId; | ||
| 19 | + | ||
| 20 | + private List<Integer> permissionIds; | ||
| 21 | + | ||
| 22 | + private static final long serialVersionUID = 1L; | ||
| 23 | +} | 
| @@ -2,6 +2,7 @@ package com.tianbo.warehouse.service; | @@ -2,6 +2,7 @@ package com.tianbo.warehouse.service; | ||
| 2 | 2 | ||
| 3 | import com.github.pagehelper.PageInfo; | 3 | import com.github.pagehelper.PageInfo; | 
| 4 | import com.tianbo.warehouse.model.ROLE; | 4 | import com.tianbo.warehouse.model.ROLE; | 
| 5 | +import com.tianbo.warehouse.model.RoleDataPermission; | ||
| 5 | import com.tianbo.warehouse.model.RolePermission; | 6 | import com.tianbo.warehouse.model.RolePermission; | 
| 6 | 7 | ||
| 7 | import java.util.List; | 8 | import java.util.List; | 
| @@ -17,6 +18,8 @@ public interface RoleService { | @@ -17,6 +18,8 @@ public interface RoleService { | ||
| 17 | 18 | ||
| 18 | int setRolePermissoin(RolePermission record); | 19 | int setRolePermissoin(RolePermission record); | 
| 19 | 20 | ||
| 21 | + int setRoleDataPermissoin(RoleDataPermission record); | ||
| 22 | + | ||
| 20 | int updateByPrimaryKeySelective(ROLE role); | 23 | int updateByPrimaryKeySelective(ROLE role); | 
| 21 | 24 | ||
| 22 | int deleteByPrimaryKey(Integer departmentId); | 25 | int deleteByPrimaryKey(Integer departmentId); | 
| @@ -6,9 +6,11 @@ import com.github.pagehelper.PageInfo; | @@ -6,9 +6,11 @@ import com.github.pagehelper.PageInfo; | ||
| 6 | import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheDelTarget; | 6 | import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheDelTarget; | 
| 7 | import com.tianbo.warehouse.dao.DepartmentMapper; | 7 | import com.tianbo.warehouse.dao.DepartmentMapper; | 
| 8 | import com.tianbo.warehouse.dao.ROLEMapper; | 8 | import com.tianbo.warehouse.dao.ROLEMapper; | 
| 9 | +import com.tianbo.warehouse.dao.RoleDataPermissionDao; | ||
| 9 | import com.tianbo.warehouse.dao.RolePermissionMapper; | 10 | import com.tianbo.warehouse.dao.RolePermissionMapper; | 
| 10 | import com.tianbo.warehouse.model.Department; | 11 | import com.tianbo.warehouse.model.Department; | 
| 11 | import com.tianbo.warehouse.model.ROLE; | 12 | import com.tianbo.warehouse.model.ROLE; | 
| 13 | +import com.tianbo.warehouse.model.RoleDataPermission; | ||
| 12 | import com.tianbo.warehouse.model.RolePermission; | 14 | import com.tianbo.warehouse.model.RolePermission; | 
| 13 | import com.tianbo.warehouse.service.PermissionService; | 15 | import com.tianbo.warehouse.service.PermissionService; | 
| 14 | import com.tianbo.warehouse.service.RoleService; | 16 | import com.tianbo.warehouse.service.RoleService; | 
| @@ -31,6 +33,9 @@ public class RoleServiceImp implements RoleService{ | @@ -31,6 +33,9 @@ public class RoleServiceImp implements RoleService{ | ||
| 31 | private RolePermissionMapper rolePermissionMapper; | 33 | private RolePermissionMapper rolePermissionMapper; | 
| 32 | 34 | ||
| 33 | @Resource | 35 | @Resource | 
| 36 | + private RoleDataPermissionDao roleDataPermissionDao; | ||
| 37 | + | ||
| 38 | + @Resource | ||
| 34 | DepartmentMapper departmentMapper; | 39 | DepartmentMapper departmentMapper; | 
| 35 | 40 | ||
| 36 | @Autowired | 41 | @Autowired | 
| @@ -135,6 +140,19 @@ public class RoleServiceImp implements RoleService{ | @@ -135,6 +140,19 @@ public class RoleServiceImp implements RoleService{ | ||
| 135 | } | 140 | } | 
| 136 | 141 | ||
| 137 | @Override | 142 | @Override | 
| 143 | + @Transactional(rollbackFor = Exception.class) | ||
| 144 | + public int setRoleDataPermissoin(RoleDataPermission record) { | ||
| 145 | + Integer roleId = record.getRoleId(); | ||
| 146 | + List<Integer> permissions = record.getPermissionIds(); | ||
| 147 | + //这里加个判定,如果前端提交的权限列表是空的,代表清空这个角色的所有权限,防止SQL出错 | ||
| 148 | + if (null!=permissions && !permissions.isEmpty()){ | ||
| 149 | + roleDataPermissionDao.delPermByRoleId(roleId); | ||
| 150 | + return roleDataPermissionDao.insertRoleDataPerm(record); | ||
| 151 | + } | ||
| 152 | + return 0; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + @Override | ||
| 138 | public int updateByPrimaryKeySelective(ROLE company) { | 156 | public int updateByPrimaryKeySelective(ROLE company) { | 
| 139 | return roleMapper.updateByPrimaryKeySelective(company); | 157 | return roleMapper.updateByPrimaryKeySelective(company); | 
| 140 | } | 158 | } | 
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 3 | +<mapper namespace="com.tianbo.warehouse.dao.RoleDataPermissionDao"> | ||
| 4 | + <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.RoleDataPermission"> | ||
| 5 | + <id column="id" jdbcType="INTEGER" property="id" /> | ||
| 6 | + <result column="role_id" jdbcType="INTEGER" property="roleId" /> | ||
| 7 | + <result column="permission_id" jdbcType="INTEGER" property="permissionId" /> | ||
| 8 | + </resultMap> | ||
| 9 | + <sql id="Base_Column_List"> | ||
| 10 | + id, role_id, permission_id | ||
| 11 | + </sql> | ||
| 12 | + <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> | ||
| 13 | + select | ||
| 14 | + <include refid="Base_Column_List" /> | ||
| 15 | + from role_data_permission | ||
| 16 | + where id = #{id,jdbcType=INTEGER} | ||
| 17 | + </select> | ||
| 18 | + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> | ||
| 19 | + delete from role_data_permission | ||
| 20 | + where id = #{id,jdbcType=INTEGER} | ||
| 21 | + </delete> | ||
| 22 | + <delete id="delPermByRoleId" parameterType="java.lang.Integer"> | ||
| 23 | + delete from role_data_permission | ||
| 24 | + where role_id = #{roleId,jdbcType=INTEGER} | ||
| 25 | + </delete> | ||
| 26 | + | ||
| 27 | + <insert id="insertRoleDataPerm" parameterType="com.tianbo.warehouse.model.RoleDataPermission"> | ||
| 28 | + insert into role_data_permission(role_id, permission_id) | ||
| 29 | + values | ||
| 30 | + <foreach collection="permissionIds" item="rolePem" index="index" separator=","> | ||
| 31 | + <if test="rolePem !=null"> | ||
| 32 | + (#{roleId,jdbcType=INTEGER},#{rolePem,jdbcType=INTEGER}) | ||
| 33 | + </if> | ||
| 34 | + </foreach> | ||
| 35 | + </insert> | ||
| 36 | + <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.tianbo.warehouse.model.RoleDataPermission" useGeneratedKeys="true"> | ||
| 37 | + insert into role_data_permission (role_id, permission_id) | ||
| 38 | + values (#{roleId,jdbcType=INTEGER}, #{permissionId,jdbcType=INTEGER}) | ||
| 39 | + </insert> | ||
| 40 | + <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.tianbo.warehouse.model.RoleDataPermission" useGeneratedKeys="true"> | ||
| 41 | + insert into role_data_permission | ||
| 42 | + <trim prefix="(" suffix=")" suffixOverrides=","> | ||
| 43 | + <if test="roleId != null"> | ||
| 44 | + role_id, | ||
| 45 | + </if> | ||
| 46 | + <if test="permissionId != null"> | ||
| 47 | + permission_id, | ||
| 48 | + </if> | ||
| 49 | + </trim> | ||
| 50 | + <trim prefix="values (" suffix=")" suffixOverrides=","> | ||
| 51 | + <if test="roleId != null"> | ||
| 52 | + #{roleId,jdbcType=INTEGER}, | ||
| 53 | + </if> | ||
| 54 | + <if test="permissionId != null"> | ||
| 55 | + #{permissionId,jdbcType=INTEGER}, | ||
| 56 | + </if> | ||
| 57 | + </trim> | ||
| 58 | + </insert> | ||
| 59 | + <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.RoleDataPermission"> | ||
| 60 | + update role_data_permission | ||
| 61 | + <set> | ||
| 62 | + <if test="roleId != null"> | ||
| 63 | + role_id = #{roleId,jdbcType=INTEGER}, | ||
| 64 | + </if> | ||
| 65 | + <if test="permissionId != null"> | ||
| 66 | + permission_id = #{permissionId,jdbcType=INTEGER}, | ||
| 67 | + </if> | ||
| 68 | + </set> | ||
| 69 | + where id = #{id,jdbcType=INTEGER} | ||
| 70 | + </update> | ||
| 71 | + <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.RoleDataPermission"> | ||
| 72 | + update role_data_permission | ||
| 73 | + set role_id = #{roleId,jdbcType=INTEGER}, | ||
| 74 | + permission_id = #{permissionId,jdbcType=INTEGER} | ||
| 75 | + where id = #{id,jdbcType=INTEGER} | ||
| 76 | + </update> | ||
| 77 | +</mapper> | 
- 
请 注册 或 登录 后发表评论