Commit cdc7dcc7 authored by chenhao's avatar chenhao

修改权限校验的方法

parent 72d28df8
...@@ -2,8 +2,6 @@ package com.yeejoin.amos.boot.biz.common.service; ...@@ -2,8 +2,6 @@ package com.yeejoin.amos.boot.biz.common.service;
import java.util.Map; import java.util.Map;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
public interface IWorkflowExcuteService{ public interface IWorkflowExcuteService{
/** /**
...@@ -18,14 +16,14 @@ public interface IWorkflowExcuteService{ ...@@ -18,14 +16,14 @@ public interface IWorkflowExcuteService{
* @param processInstanceId 流程定义的ID * @param processInstanceId 流程定义的ID
* @return true 可以执行,false 无执行权限 * @return true 可以执行,false 无执行权限
*/ */
boolean checkTaskAuth(String processInstanceId,ReginParams userInfo); boolean checkTaskAuth(String processInstanceId);
/** /**
* 检查当前登录人有没有流程操作权限 * 检查当前登录人有没有流程操作权限
* @param processInstanceId 流程定义的ID * @param processInstanceId 流程定义的ID
* @return 包含是否执行的角色权限flag,以及当前任务的id * @return 包含是否执行的角色权限flag,以及当前任务的id
*/ */
Map<String, Object> checkTaskAuthMap(String processInstanceId,ReginParams userInfo); Map<String, Object> checkTaskAuthMap(String processInstanceId);
/** /**
* 设置当前任务的执行人,只支持当前节点流程拥有单个可执行任务的情况,不支持并行网关产生的多条任务设置人的任务情况 * 设置当前任务的执行人,只支持当前节点流程拥有单个可执行任务的情况,不支持并行网关产生的多条任务设置人的任务情况
* @param processInstanceId * @param processInstanceId
...@@ -39,7 +37,7 @@ public interface IWorkflowExcuteService{ ...@@ -39,7 +37,7 @@ public interface IWorkflowExcuteService{
* @param userInfo * @param userInfo
* @return * @return
*/ */
boolean CompleteTask(String processInstanceId,String condition,ReginParams userInfo); boolean CompleteTask(String processInstanceId,String condition);
} }
...@@ -39,55 +39,48 @@ public class WorkflowExcuteServiceImpl implements IWorkflowExcuteService { ...@@ -39,55 +39,48 @@ public class WorkflowExcuteServiceImpl implements IWorkflowExcuteService {
} }
@Override @Override
public boolean checkTaskAuth(String processInstanceId, ReginParams userInfo) { public boolean checkTaskAuth(String processInstanceId) {
Map<String, Object> map= checkTaskAuthMap(processInstanceId,userInfo); Map<String, Object> map = checkTaskAuthMap(processInstanceId);
return Boolean.parseBoolean(map.get("checkFlag").toString()); return Boolean.parseBoolean(map.get("checkFlag").toString());
} }
@Override @Override
public Map<String, Object> checkTaskAuthMap(String processInstanceId, ReginParams userInfo) { public Map<String, Object> checkTaskAuthMap(String processInstanceId) {
// 获取当前登录用户的角色 // 获取当前登录用户的角色
String currentLoginUserRole = userInfo.getRole().getRoleName();
String currentLoginUserId = userInfo.getUserModel().getUserId();
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put("checkFlag", false); map.put("checkFlag", false);
JSONObject teskObject = workflowFeignService.getTaskList(processInstanceId); JSONObject teskObject = workflowFeignService.getTask(processInstanceId);
if (ObjectUtils.isNotEmpty(teskObject)) { if (ObjectUtils.isNotEmpty(teskObject)) {
JSONArray taskDetailArray = teskObject.getJSONArray("data"); map.put("taskId", teskObject.getString("id"));
for (Object obj : taskDetailArray) { map.put("checkFlag", true);
JSONObject detail = JSONObject.parseObject(JSONObject.toJSONString(obj)); map.put("name", teskObject.getString("name"));
JSONObject taskGroupNameObject = workflowFeignService.getTaskGroupName(detail.getString("id"));
// 获取流程中原本设置的当前节点的执行权限
JSONArray taskGroupNameDetail = taskGroupNameObject.getJSONArray("data");
// 如果拿不到当前任务的执行角色,再去获取当前任务有没有默认的执行人,如果都没有则返回校验失败
if (ObjectUtils.isEmpty(taskGroupNameDetail)) {
JSONObject taskAssignObject = workflowFeignService.getTaskAssign(detail.getString("id"));
String assignUser = taskAssignObject.getJSONObject("data").getString("assignee");
if (StringUtils.isNotBlank(assignUser)) {
// 如果当前登录人与当前任务的设定人不一定,则直接返回权限校验失败
if (!currentLoginUserId.equals(assignUser)) {
return map;
} else {
map.put("taskId", detail.getString("id"));
map.put("checkFlag", true);
map.put("name", detail.getString("name"));
map.put("assign", assignUser);
return map;
}
}
continue;
}
String defaultExecutionRoleProcess = taskGroupNameDetail.getJSONObject(0).getString("groupId");
// 判断当前登录人的角色是不是与流程中设置的当前任务节点权限一致,一致则执行,不一致则退出
if (!defaultExecutionRoleProcess.equals(currentLoginUserRole)) {
continue;
}
map.put("taskId", detail.getString("id"));
map.put("checkFlag", true);
map.put("name", detail.getString("name"));
map.put("groupName",currentLoginUserRole);
}
} }
/*
* JSONObject teskObject = workflowFeignService.getTaskList(processInstanceId);
* if (ObjectUtils.isNotEmpty(teskObject)) { JSONArray taskDetailArray =
* teskObject.getJSONArray("data"); for (Object obj : taskDetailArray) {
* JSONObject detail = JSONObject.parseObject(JSONObject.toJSONString(obj));
* JSONObject taskGroupNameObject =
* workflowFeignService.getTaskGroupName(detail.getString("id")); //
* 获取流程中原本设置的当前节点的执行权限 JSONArray taskGroupNameDetail =
* taskGroupNameObject.getJSONArray("data"); //
* 如果拿不到当前任务的执行角色,再去获取当前任务有没有默认的执行人,如果都没有则返回校验失败 if
* (ObjectUtils.isEmpty(taskGroupNameDetail)) { JSONObject taskAssignObject =
* workflowFeignService.getTaskAssign(detail.getString("id")); String assignUser
* = taskAssignObject.getJSONObject("data").getString("assignee"); if
* (StringUtils.isNotBlank(assignUser)) { // 如果当前登录人与当前任务的设定人不一定,则直接返回权限校验失败 if
* (!currentLoginUserId.equals(assignUser)) { return map; } else {
* map.put("taskId", detail.getString("id")); map.put("checkFlag", true);
* map.put("name", detail.getString("name")); map.put("assign", assignUser);
* return map; } } continue; } String defaultExecutionRoleProcess =
* taskGroupNameDetail.getJSONObject(0).getString("groupId"); //
* 判断当前登录人的角色是不是与流程中设置的当前任务节点权限一致,一致则执行,不一致则退出 if
* (!defaultExecutionRoleProcess.equals(currentLoginUserRole)) { continue; }
* map.put("taskId", detail.getString("id")); map.put("checkFlag", true);
* map.put("name", detail.getString("name"));
* map.put("groupName",currentLoginUserRole); } }
*/
return map; return map;
} }
...@@ -107,7 +100,7 @@ public class WorkflowExcuteServiceImpl implements IWorkflowExcuteService { ...@@ -107,7 +100,7 @@ public class WorkflowExcuteServiceImpl implements IWorkflowExcuteService {
} }
@Override @Override
public Object setTaskAssign(String processInstanceId,String userId) { public Object setTaskAssign(String processInstanceId, String userId) {
JSONObject teskObject = workflowFeignService.getTaskList(processInstanceId); JSONObject teskObject = workflowFeignService.getTaskList(processInstanceId);
if (ObjectUtils.isNotEmpty(teskObject)) { if (ObjectUtils.isNotEmpty(teskObject)) {
JSONArray taskDetailArray = teskObject.getJSONArray("data"); JSONArray taskDetailArray = teskObject.getJSONArray("data");
...@@ -124,9 +117,9 @@ public class WorkflowExcuteServiceImpl implements IWorkflowExcuteService { ...@@ -124,9 +117,9 @@ public class WorkflowExcuteServiceImpl implements IWorkflowExcuteService {
} }
@Override @Override
public boolean CompleteTask(String processInstanceId, String condition, ReginParams userInfo) { public boolean CompleteTask(String processInstanceId, String condition) {
Map<String, Object> map= checkTaskAuthMap(processInstanceId,userInfo); Map<String, Object> map = checkTaskAuthMap(processInstanceId);
if(Boolean.parseBoolean(map.get("checkFlag").toString())) { if (Boolean.parseBoolean(map.get("checkFlag").toString())) {
HashMap<String, Object> conditionMap = new HashMap<String, Object>(); HashMap<String, Object> conditionMap = new HashMap<String, Object>();
conditionMap.put("condition", condition); conditionMap.put("condition", condition);
try { try {
...@@ -134,7 +127,7 @@ public class WorkflowExcuteServiceImpl implements IWorkflowExcuteService { ...@@ -134,7 +127,7 @@ public class WorkflowExcuteServiceImpl implements IWorkflowExcuteService {
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("完成任务失败"); throw new RuntimeException("完成任务失败");
} }
}else { } else {
throw new RuntimeException("没有执行权限"); throw new RuntimeException("没有执行权限");
} }
return true; return true;
......
...@@ -145,8 +145,8 @@ public interface WorkflowFeignService { ...@@ -145,8 +145,8 @@ public interface WorkflowFeignService {
* @return * @return
* @throws Exception * @throws Exception
*/ */
@RequestMapping(value = "/setTaskGroupName/{taskId}/{groupName}", method = RequestMethod.GET) @RequestMapping(value = "/task/setTaskGroupName/{taskId}/{groupName}", method = RequestMethod.GET)
Response setTaskGroupName(@PathVariable("taskId") String taskId, @PathVariable("groupName") String groupName) JSONObject setTaskGroupName(@PathVariable("taskId") String taskId, @PathVariable("groupName") String groupName)
throws Exception; throws Exception;
/** /**
...@@ -157,6 +157,13 @@ public interface WorkflowFeignService { ...@@ -157,6 +157,13 @@ public interface WorkflowFeignService {
* @return * @return
* @throws Exception * @throws Exception
*/ */
@RequestMapping(value = "/setTaskAssignUser/{taskId}/{userId}", method = RequestMethod.GET) @RequestMapping(value = "/task/setTaskAssignUser/{taskId}/{userId}", method = RequestMethod.GET)
Response setTaskUser(@PathVariable("taskId") String taskId, @PathVariable("userId") String userId) throws Exception; JSONObject setTaskUser(@PathVariable("taskId") String taskId, @PathVariable("userId") String userId) throws Exception;
/**
* 查询当前登录人所属角色或者id 所能执行的单个任务
* @param processInstanceId
* @return
*/
@RequestMapping(value = "/task/")
JSONObject getTask(@RequestParam(value="processInstanceId") String processInstanceId);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment