Commit 0a2c7bb0 authored by chenhao's avatar chenhao

添加任務角色控制的代碼

parent a8c7b7d9
......@@ -10,33 +10,45 @@ import org.springframework.web.bind.annotation.RequestMethod;
import com.alibaba.fastjson.JSONObject;
@FeignClient(name = "AMOS-API-WORKFLOW",path = "workflow", configuration = {CommonMultipartSupportConfig.class})
@FeignClient(name = "AMOS-API-WORKFLOW", path = "workflow", configuration = { CommonMultipartSupportConfig.class })
public interface WorkflowFeignService {
/**
* 发起流程
* @param params
* @return
*/
@RequestMapping(value = "/task/startProcess", method = RequestMethod.POST)
JSONObject startByVariable(@RequestBody Object params) ;
/**
* 完成任务
* @param taskID
* @param variable
* @return
* @throws Exception
*/
@RequestMapping(value = "/task/pickupAndCompleteTask/{taskId}", method = RequestMethod.POST)
JSONObject pickupAndCompleteTask(@PathVariable("taskId") String taskID, @RequestBody(required = false) HashMap<String, Object> variable) throws Exception;
/**
* 发起流程
*
* @param params
* @return
*/
@RequestMapping(value = "/task/startProcess", method = RequestMethod.POST)
JSONObject startByVariable(@RequestBody Object params);
/**
* 完成任务
*
* @param taskID
* @param variable
* @return
* @throws Exception
*/
@RequestMapping(value = "/task/pickupAndCompleteTask/{taskId}", method = RequestMethod.POST)
JSONObject pickupAndCompleteTask(@PathVariable("taskId") String taskID,
@RequestBody(required = false) HashMap<String, Object> variable) throws Exception;
/**
* 查询当前流程下所有的可执行任务
*
* @param processInstanceId
* @return
*/
@RequestMapping(value = "/task/list/all/{processInstanceId}", method = RequestMethod.GET)
JSONObject getTaskList(@PathVariable("processInstanceId") String processInstanceId) ;
@RequestMapping(value = "/task/list/all/{processInstanceId}", method = RequestMethod.GET)
JSONObject getTaskList(@PathVariable("processInstanceId") String processInstanceId);
/**
* 查询当前任务的执行用户组
*
* @param processInstanceId
* @return
*/
@RequestMapping(value = "/getTaskGroupName/{taskId}", method = RequestMethod.GET)
JSONObject getTaskGroupName(@PathVariable("taskId") String taskId);
}
......@@ -43,7 +43,7 @@ public class FailureDetailsServiceImpl extends BaseService<FailureDetailsDto, Fa
@Autowired
SourceFileServiceImpl sourceFileServiceImpl;
@Autowired
WorkflowFeignService workflowFeignService;
......@@ -83,15 +83,16 @@ public class FailureDetailsServiceImpl extends BaseService<FailureDetailsDto, Fa
/**
* 发起故障保修单
* @throws Exception
*
* @throws Exception
*/
@Transactional
public Object savemodel(FailureDetailsDto failureDetailsDto, ReginParams userInfo) throws Exception {
String businessKey = buildOrderNo();
JSONObject body = new JSONObject();
body.put("businessKey", businessKey);
body.put("processDefinitionKey", processDefinitionKey);
JSONObject jsonObject = workflowFeignService.startByVariable(body);
JSONObject body = new JSONObject();
body.put("businessKey", businessKey);
body.put("processDefinitionKey", processDefinitionKey);
JSONObject jsonObject = workflowFeignService.startByVariable(body);
if (jsonObject == null) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
// return CommonResponseUtil.failure("启动流程失败");
......@@ -116,31 +117,29 @@ public class FailureDetailsServiceImpl extends BaseService<FailureDetailsDto, Fa
// return CommonResponseUtil.failure("添加失败");
}
if (ObjectUtils.isNotEmpty(model)) {
excuteTask( instance.getString("id"), userInfo, null);
excuteTask(instance.getString("id"), userInfo, null);
}
return true;
}
public boolean excuteTask( Long sequenceNbr, ReginParams userInfo,
String condition) {
public boolean excuteTask(Long sequenceNbr, ReginParams userInfo, String condition) {
HashMap<String, Object> conditionMap = new HashMap<String, Object>();
conditionMap.put("condition", condition);
Map<String,Object> map= checkExcuteTaskAuthMap(sequenceNbr,userInfo);
try {
if(Boolean.parseBoolean(map.get("checkFlag").toString())) {
workflowFeignService.pickupAndCompleteTask(map.get("taskId").toString(), conditionMap);
}
Map<String, Object> map = checkExcuteTaskAuthMap(sequenceNbr, userInfo);
try {
if (Boolean.parseBoolean(map.get("checkFlag").toString())) {
workflowFeignService.pickupAndCompleteTask(map.get("taskId").toString(), conditionMap);
}
} catch (Exception e) {
return false;
}
return true;
}
public boolean excuteTask(String procressId, ReginParams userInfo,
String condition) throws Exception {
public boolean excuteTask(String procressId, ReginParams userInfo, String condition) throws Exception {
HashMap<String, Object> conditionMap = new HashMap<String, Object>();
conditionMap.put("condition", condition);
JSONObject teskObject =workflowFeignService.getTaskList(procressId);
JSONObject teskObject = workflowFeignService.getTaskList(procressId);
if (ObjectUtils.isNotEmpty(teskObject)) {
JSONArray taskDetailArray = teskObject.getJSONArray("data");
for (Object obj : taskDetailArray) {
......@@ -150,43 +149,60 @@ public class FailureDetailsServiceImpl extends BaseService<FailureDetailsDto, Fa
}
return true;
}
public boolean checkExcuteTaskAuth(Long sequenceNbr, ReginParams userInfo) {
Map<String,Object> map= this.checkExcuteTaskAuthMap(sequenceNbr,userInfo);
Map<String, Object> map = this.checkExcuteTaskAuthMap(sequenceNbr, userInfo);
return Boolean.parseBoolean(map.get("checkFlag").toString());
}
public Map<String,Object> checkExcuteTaskAuthMap(Long sequenceNbr, ReginParams userInfo) {
Map<String,Object> map = new HashMap<String,Object>();
public Map<String, Object> checkExcuteTaskAuthMap(Long sequenceNbr, ReginParams userInfo) {
String currentLoginUserRole = userInfo.getRole().getRoleName();
Map<String, Object> map = new HashMap<String, Object>();
map.put("checkFlag", false);
FailureDetailsDto failureDetailsDto = this.queryBySeq(sequenceNbr);
// 获取送达部门的ID
Integer failureEquipmentId = failureDetailsDto.getFailureEquipmentId();
//获取上一级操作部门的Id
// 获取上一级操作部门的Id
FailureDetails details = this.baseMapper.selectById(sequenceNbr);
String procressId = details.getProcessId();
Long seq = userInfo.getDepartment().getSequenceNbr();
JSONObject teskObject =workflowFeignService.getTaskList(procressId);
JSONObject teskObject = workflowFeignService.getTaskList(procressId);
if (ObjectUtils.isNotEmpty(teskObject)) {
JSONArray taskDetailArray = teskObject.getJSONArray("data");
for (Object obj : taskDetailArray) {
JSONObject detail = JSONObject.parseObject(JSONObject.toJSONString(obj));
String name = detail.getString("name");
if (name.contains(EMERGENCY_COMMAND) ) {
JSONObject taskGroupNameObject = workflowFeignService.getTaskGroupName(detail.getString("id"));
// 获取流程中原本设置的当前节点的执行权限
JSONArray taskGroupNameDetail = taskGroupNameObject.getJSONArray("data");
// 如果拿不到当前任务的执行角色,则返回校验失败
if (ObjectUtils.isEmpty(taskGroupNameDetail)) {
continue;
}
String defaultExecutionRoleProcess = taskGroupNameDetail.getJSONObject(0).getString("groupId");
// 判断当前登录人的角色是不是与流程中设置的当前任务节点权限一致,一致则执行,不一致则退出
if (!defaultExecutionRoleProcess.equals(currentLoginUserRole)) {
continue;
}
// 当流程节点为应急指挥科时,需要判断当前用户所在的部门id和前面处理的用户部门id是否一致
if (name.contains(EMERGENCY_COMMAND)) {
FailureAudit failureAuditDetail = failureAuditService.findByFaultId(sequenceNbr);
Long auditDepartmentId = failureAuditDetail.getAuditDepartmentId();
if(auditDepartmentId.intValue() == seq.intValue()) {
map.put("taskId", detail.getString("id"));
map.put("checkFlag", true);
return map;
}
Long auditDepartmentId = failureAuditDetail.getAuditDepartmentId();
if (auditDepartmentId.intValue() == seq.intValue()) {
map.put("taskId", detail.getString("id"));
map.put("checkFlag", true);
break;
}
} else {
// 判断当前节点任务属于送达部门节点时需要判断当前登录人所在的部门id是否与表单发起时设置的送达部门一致
if (failureEquipmentId.intValue() == seq.intValue()) {
map.put("taskId", detail.getString("id"));
map.put("checkFlag", true);
return map;
break;
}
}
}
}
map.put("checkFlag", false);
return map;
}
......
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