正在显示
11 个修改的文件
包含
113 行增加
和
5 行删除
@@ -242,6 +242,11 @@ | @@ -242,6 +242,11 @@ | ||
242 | <version>0.0.9</version> | 242 | <version>0.0.9</version> |
243 | </dependency> | 243 | </dependency> |
244 | 244 | ||
245 | + <dependency> | ||
246 | + <groupId>cn.hutool</groupId> | ||
247 | + <artifactId>hutool-all</artifactId> | ||
248 | + <version>5.7.14</version> | ||
249 | + </dependency> | ||
245 | </dependencies> | 250 | </dependencies> |
246 | 251 | ||
247 | <dependencyManagement> | 252 | <dependencyManagement> |
@@ -7,6 +7,7 @@ import com.tianbo.warehouse.model.ROLE; | @@ -7,6 +7,7 @@ import com.tianbo.warehouse.model.ROLE; | ||
7 | import com.tianbo.warehouse.model.RoleDataPermission; | 7 | import com.tianbo.warehouse.model.RoleDataPermission; |
8 | import com.tianbo.warehouse.model.RolePermission; | 8 | import com.tianbo.warehouse.model.RolePermission; |
9 | import com.tianbo.warehouse.service.RoleService; | 9 | import com.tianbo.warehouse.service.RoleService; |
10 | +import org.apache.commons.lang.StringUtils; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
11 | import org.springframework.web.bind.annotation.*; | 12 | import org.springframework.web.bind.annotation.*; |
12 | 13 | ||
@@ -121,4 +122,19 @@ public class RoleController { | @@ -121,4 +122,19 @@ public class RoleController { | ||
121 | return resultJson; | 122 | return resultJson; |
122 | } | 123 | } |
123 | 124 | ||
125 | +// @LogAnnotation(moduleName = "岗位/角色管理", operate = "添加组织机构token") | ||
126 | + @PostMapping("/createRoleToken") | ||
127 | + public ResultJson createRoleToken(@RequestParam(value = "roleId") Integer roleId){ | ||
128 | + String roleToken = roleService.createRoleToken(roleId); | ||
129 | + if (StringUtils.isNotBlank(roleToken)){ | ||
130 | + return new ResultJson("200", "success", roleToken); | ||
131 | + } | ||
132 | + return new ResultJson("201","error"); | ||
133 | + } | ||
134 | + | ||
135 | + @PostMapping("/permRoleToken") | ||
136 | + public ResultJson permRoleToken(@RequestBody RolePermission rolePermission){ | ||
137 | + return roleService.permRoleToken(rolePermission); | ||
138 | + } | ||
139 | + | ||
124 | } | 140 | } |
@@ -44,4 +44,6 @@ public interface PERMISSIONMapper { | @@ -44,4 +44,6 @@ public interface PERMISSIONMapper { | ||
44 | List<PERMISSION> getUserMenuTreeByUserId(@Param("userId") Integer userId); | 44 | List<PERMISSION> getUserMenuTreeByUserId(@Param("userId") Integer userId); |
45 | 45 | ||
46 | List<PERMISSION> getChildMenu(Integer parentId); | 46 | List<PERMISSION> getChildMenu(Integer parentId); |
47 | + | ||
48 | + List<PERMISSION> selectByIds(List<Integer> permissionIds); | ||
47 | } | 49 | } |
@@ -46,4 +46,7 @@ public interface ROLEMapper { | @@ -46,4 +46,7 @@ public interface ROLEMapper { | ||
46 | int updateByPrimaryKeySelective(ROLE record); | 46 | int updateByPrimaryKeySelective(ROLE record); |
47 | 47 | ||
48 | int updateByPrimaryKey(ROLE record); | 48 | int updateByPrimaryKey(ROLE record); |
49 | + | ||
50 | + int updateTokenById(@Param("roleId") Integer roleId, | ||
51 | + @Param("token") String token); | ||
49 | } | 52 | } |
@@ -36,6 +36,9 @@ public class ROLE implements GrantedAuthority { | @@ -36,6 +36,9 @@ public class ROLE implements GrantedAuthority { | ||
36 | 36 | ||
37 | private String orgtype; | 37 | private String orgtype; |
38 | 38 | ||
39 | + // 组织机构持久token | ||
40 | + private String ext; | ||
41 | + | ||
39 | private List<ROLE> children; | 42 | private List<ROLE> children; |
40 | 43 | ||
41 | public Integer getRoleId() { | 44 | public Integer getRoleId() { |
@@ -56,4 +56,6 @@ public interface PermissionService { | @@ -56,4 +56,6 @@ public interface PermissionService { | ||
56 | * @return 有为true 没有为false | 56 | * @return 有为true 没有为false |
57 | */ | 57 | */ |
58 | Boolean getPermission(String token,String url,String name); | 58 | Boolean getPermission(String token,String url,String name); |
59 | + | ||
60 | + List<PERMISSION> selectByIds(List<Integer> permissionIds); | ||
59 | } | 61 | } |
1 | package com.tianbo.warehouse.service; | 1 | package com.tianbo.warehouse.service; |
2 | 2 | ||
3 | import com.github.pagehelper.PageInfo; | 3 | import com.github.pagehelper.PageInfo; |
4 | +import com.tianbo.warehouse.controller.response.ResultJson; | ||
4 | import com.tianbo.warehouse.model.ROLE; | 5 | import com.tianbo.warehouse.model.ROLE; |
5 | import com.tianbo.warehouse.model.RoleDataPermission; | 6 | import com.tianbo.warehouse.model.RoleDataPermission; |
6 | import com.tianbo.warehouse.model.RolePermission; | 7 | import com.tianbo.warehouse.model.RolePermission; |
@@ -25,4 +26,8 @@ public interface RoleService { | @@ -25,4 +26,8 @@ public interface RoleService { | ||
25 | int updateByPrimaryKeySelective(ROLE role); | 26 | int updateByPrimaryKeySelective(ROLE role); |
26 | 27 | ||
27 | int deleteByPrimaryKey(Integer departmentId); | 28 | int deleteByPrimaryKey(Integer departmentId); |
29 | + | ||
30 | + String createRoleToken(Integer roleId); | ||
31 | + | ||
32 | + ResultJson permRoleToken(RolePermission rolePermission); | ||
28 | } | 33 | } |
1 | package com.tianbo.warehouse.service.imp; | 1 | package com.tianbo.warehouse.service.imp; |
2 | 2 | ||
3 | +import cn.hutool.core.util.ArrayUtil; | ||
3 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
4 | import com.github.pagehelper.Page; | 5 | import com.github.pagehelper.Page; |
5 | import com.github.pagehelper.PageHelper; | 6 | import com.github.pagehelper.PageHelper; |
@@ -268,4 +269,12 @@ public class PermissionServiceImp implements PermissionService { | @@ -268,4 +269,12 @@ public class PermissionServiceImp implements PermissionService { | ||
268 | return false; | 269 | return false; |
269 | } | 270 | } |
270 | 271 | ||
272 | + @Override | ||
273 | + public List<PERMISSION> selectByIds(List<Integer> permissionIds) { | ||
274 | + List<PERMISSION> permissionList = new ArrayList<>(); | ||
275 | + if (ArrayUtil.isNotEmpty(permissionIds)){ | ||
276 | + permissionList = permissionMapper.selectByIds(permissionIds); | ||
277 | + } | ||
278 | + return permissionList; | ||
279 | + } | ||
271 | } | 280 | } |
1 | package com.tianbo.warehouse.service.imp; | 1 | package com.tianbo.warehouse.service.imp; |
2 | 2 | ||
3 | +import cn.hutool.core.util.IdUtil; | ||
4 | +import com.alibaba.fastjson.JSON; | ||
3 | import com.github.pagehelper.Page; | 5 | import com.github.pagehelper.Page; |
4 | import com.github.pagehelper.PageHelper; | 6 | import com.github.pagehelper.PageHelper; |
5 | import com.github.pagehelper.PageInfo; | 7 | import com.github.pagehelper.PageInfo; |
6 | import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheDelTarget; | 8 | import com.tianbo.warehouse.annotation.cache.annotation.RedisCacheDelTarget; |
9 | +import com.tianbo.warehouse.controller.response.ResultJson; | ||
7 | import com.tianbo.warehouse.dao.DepartmentMapper; | 10 | import com.tianbo.warehouse.dao.DepartmentMapper; |
8 | import com.tianbo.warehouse.dao.ROLEMapper; | 11 | import com.tianbo.warehouse.dao.ROLEMapper; |
9 | import com.tianbo.warehouse.dao.RoleDataPermissionDao; | 12 | import com.tianbo.warehouse.dao.RoleDataPermissionDao; |
10 | import com.tianbo.warehouse.dao.RolePermissionMapper; | 13 | import com.tianbo.warehouse.dao.RolePermissionMapper; |
11 | -import com.tianbo.warehouse.model.Department; | ||
12 | -import com.tianbo.warehouse.model.ROLE; | ||
13 | -import com.tianbo.warehouse.model.RoleDataPermission; | ||
14 | -import com.tianbo.warehouse.model.RolePermission; | 14 | +import com.tianbo.warehouse.model.*; |
15 | import com.tianbo.warehouse.service.PermissionService; | 15 | import com.tianbo.warehouse.service.PermissionService; |
16 | import com.tianbo.warehouse.service.RoleService; | 16 | import com.tianbo.warehouse.service.RoleService; |
17 | +import com.tianbo.warehouse.util.RedisUtils; | ||
18 | +import org.apache.commons.lang.StringUtils; | ||
17 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | +import org.springframework.security.core.userdetails.UserDetails; | ||
18 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
19 | import org.springframework.transaction.annotation.Transactional; | 22 | import org.springframework.transaction.annotation.Transactional; |
20 | 23 | ||
21 | import javax.annotation.Resource; | 24 | import javax.annotation.Resource; |
22 | import java.util.Comparator; | 25 | import java.util.Comparator; |
26 | +import java.util.HashMap; | ||
23 | import java.util.List; | 27 | import java.util.List; |
28 | +import java.util.Map; | ||
24 | import java.util.stream.Collectors; | 29 | import java.util.stream.Collectors; |
25 | 30 | ||
26 | @Service(value = "roleService") | 31 | @Service(value = "roleService") |
@@ -41,6 +46,11 @@ public class RoleServiceImp implements RoleService{ | @@ -41,6 +46,11 @@ public class RoleServiceImp implements RoleService{ | ||
41 | @Autowired | 46 | @Autowired |
42 | PermissionService permissionService; | 47 | PermissionService permissionService; |
43 | 48 | ||
49 | + @Autowired | ||
50 | + RedisUtils redisUtils; | ||
51 | + | ||
52 | + private final String ROLE_TOKEN_HEAD = "TOKEN:ROLE:"; | ||
53 | + | ||
44 | /** | 54 | /** |
45 | * | 55 | * |
46 | * @param pageNum | 56 | * @param pageNum |
@@ -182,6 +192,41 @@ public class RoleServiceImp implements RoleService{ | @@ -182,6 +192,41 @@ public class RoleServiceImp implements RoleService{ | ||
182 | } | 192 | } |
183 | } | 193 | } |
184 | 194 | ||
195 | + @Override | ||
196 | + public String createRoleToken(Integer roleId) { | ||
197 | + ROLE role = roleMapper.selectByPrimaryKey(roleId); | ||
198 | + String oldTokenId = role.getExt(); | ||
199 | + if (StringUtils.isNotBlank(oldTokenId)) { | ||
200 | + String oldToken = ROLE_TOKEN_HEAD + oldTokenId; | ||
201 | + redisUtils.del(oldToken); | ||
202 | + } | ||
203 | + String tokenId = IdUtil.simpleUUID(); | ||
204 | + String token = ROLE_TOKEN_HEAD + tokenId; | ||
205 | + int i = roleMapper.updateTokenById(roleId, token); | ||
206 | + if (i > 0){ | ||
207 | + return token; | ||
208 | + } | ||
209 | + return null; | ||
210 | + } | ||
211 | + | ||
212 | + @Override | ||
213 | + public ResultJson permRoleToken(RolePermission rolePermission) { | ||
214 | + ROLE role = roleMapper.selectByPrimaryKey(rolePermission.getRoleId()); | ||
215 | + String token = role.getExt(); | ||
216 | + if (StringUtils.isBlank(token)) { | ||
217 | + return new ResultJson("201", "请先申请组织机构令牌"); | ||
218 | + } | ||
219 | + List<PERMISSION> permissionList = permissionService.selectByIds(rolePermission.getPermissionIds()); | ||
220 | + USERS users = new USERS(); | ||
221 | + users.setCompanyInfo(role); | ||
222 | + users.setPermissions(permissionList); | ||
223 | + String tokenValue = JSON.toJSONString(users); | ||
224 | + boolean redisSava = redisUtils.set(token, tokenValue, -1); | ||
225 | + if (redisSava){ | ||
226 | + return new ResultJson("200", "权限设置成功"); | ||
227 | + } | ||
228 | + return new ResultJson("202", "系统错误,请稍后重试"); | ||
229 | + } | ||
185 | 230 | ||
186 | //递归查找所有菜单的子菜单 | 231 | //递归查找所有菜单的子菜单 |
187 | private List<ROLE> getChildrens(ROLE root, List<ROLE> listAll) { | 232 | private List<ROLE> getChildrens(ROLE root, List<ROLE> listAll) { |
@@ -380,4 +380,16 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order | @@ -380,4 +380,16 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order | ||
380 | ORDER BY | 380 | ORDER BY |
381 | permission_order | 381 | permission_order |
382 | </select> | 382 | </select> |
383 | + <select id="selectByIds" resultMap="BaseResultMap"> | ||
384 | + SELECT | ||
385 | + <include refid="Base_Column_List" /> | ||
386 | + FROM | ||
387 | + permission | ||
388 | + <where> | ||
389 | + permission_id IN | ||
390 | + <foreach collection="permissionIds" item="id" open="(" close=")" separator=","> | ||
391 | + #{id,jdbcType=INTEGER} | ||
392 | + </foreach> | ||
393 | + </where> | ||
394 | + </select> | ||
383 | </mapper> | 395 | </mapper> |
@@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
14 | <result column="departmentId" jdbcType="VARCHAR" property="departmentid" /> | 14 | <result column="departmentId" jdbcType="VARCHAR" property="departmentid" /> |
15 | <result column="mq_code" jdbcType="VARCHAR" property="mqcode" /> | 15 | <result column="mq_code" jdbcType="VARCHAR" property="mqcode" /> |
16 | <result column="org_type" jdbcType="VARCHAR" property="orgtype" /> | 16 | <result column="org_type" jdbcType="VARCHAR" property="orgtype" /> |
17 | + <result column="ext" jdbcType="VARCHAR" property="ext"/> | ||
17 | </resultMap> | 18 | </resultMap> |
18 | <resultMap id="TreeSqlWithPermResultMap" type="com.tianbo.warehouse.model.ROLE" extends="BaseResultMap"> | 19 | <resultMap id="TreeSqlWithPermResultMap" type="com.tianbo.warehouse.model.ROLE" extends="BaseResultMap"> |
19 | <collection column="role_id" javaType="java.util.ArrayList" ofType="com.tianbo.warehouse.model.PERMISSION" property="permissions" select="com.tianbo.warehouse.dao.PERMISSIONMapper.getRolePermisson" /> | 20 | <collection column="role_id" javaType="java.util.ArrayList" ofType="com.tianbo.warehouse.model.PERMISSION" property="permissions" select="com.tianbo.warehouse.dao.PERMISSIONMapper.getRolePermisson" /> |
@@ -41,7 +42,7 @@ | @@ -41,7 +42,7 @@ | ||
41 | </resultMap> | 42 | </resultMap> |
42 | <sql id="Base_Column_List"> | 43 | <sql id="Base_Column_List"> |
43 | role_id, role_name, role_sign, description, `type`, parentId, rsort, customs_reg_code, | 44 | role_id, role_name, role_sign, description, `type`, parentId, rsort, customs_reg_code, |
44 | - business_license, departmentId, mq_code, org_type | 45 | + business_license, departmentId, mq_code, org_type, ext |
45 | </sql> | 46 | </sql> |
46 | <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> | 47 | <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> |
47 | select | 48 | select |
@@ -231,6 +232,11 @@ WHERE | @@ -231,6 +232,11 @@ WHERE | ||
231 | org_type = #{orgtype,jdbcType=VARCHAR} | 232 | org_type = #{orgtype,jdbcType=VARCHAR} |
232 | where role_id = #{roleId,jdbcType=INTEGER} | 233 | where role_id = #{roleId,jdbcType=INTEGER} |
233 | </update> | 234 | </update> |
235 | + <update id="updateTokenById"> | ||
236 | + update role | ||
237 | + set ext = #{token,jdbcType=VARCHAR} | ||
238 | + where role_id = #{roleId,jdbcType=INTEGER} | ||
239 | + </update> | ||
234 | 240 | ||
235 | <select id="findAll" parameterType="java.lang.String" resultMap="TreeSqlWithPermResultMap"> | 241 | <select id="findAll" parameterType="java.lang.String" resultMap="TreeSqlWithPermResultMap"> |
236 | SELECT | 242 | SELECT |
-
请 注册 或 登录 后发表评论