Commit 0a2c7bb0 authored by chenhao's avatar chenhao

添加任務角色控制的代碼

parent a8c7b7d9
...@@ -10,33 +10,45 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -10,33 +10,45 @@ import org.springframework.web.bind.annotation.RequestMethod;
import com.alibaba.fastjson.JSONObject; 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 { public interface WorkflowFeignService {
/** /**
* 发起流程 * 发起流程
* @param params *
* @return * @param params
*/ * @return
@RequestMapping(value = "/task/startProcess", method = RequestMethod.POST) */
JSONObject startByVariable(@RequestBody Object params) ; @RequestMapping(value = "/task/startProcess", method = RequestMethod.POST)
/** JSONObject startByVariable(@RequestBody Object params);
* 完成任务
* @param taskID /**
* @param variable * 完成任务
* @return *
* @throws Exception * @param taskID
*/ * @param variable
@RequestMapping(value = "/task/pickupAndCompleteTask/{taskId}", method = RequestMethod.POST) * @return
JSONObject pickupAndCompleteTask(@PathVariable("taskId") String taskID, @RequestBody(required = false) HashMap<String, Object> variable) throws Exception; * @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 * @param processInstanceId
* @return * @return
*/ */
@RequestMapping(value = "/task/list/all/{processInstanceId}", method = RequestMethod.GET) @RequestMapping(value = "/task/list/all/{processInstanceId}", method = RequestMethod.GET)
JSONObject getTaskList(@PathVariable("processInstanceId") String processInstanceId) ; 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 ...@@ -43,7 +43,7 @@ public class FailureDetailsServiceImpl extends BaseService<FailureDetailsDto, Fa
@Autowired @Autowired
SourceFileServiceImpl sourceFileServiceImpl; SourceFileServiceImpl sourceFileServiceImpl;
@Autowired @Autowired
WorkflowFeignService workflowFeignService; WorkflowFeignService workflowFeignService;
...@@ -83,15 +83,16 @@ public class FailureDetailsServiceImpl extends BaseService<FailureDetailsDto, Fa ...@@ -83,15 +83,16 @@ public class FailureDetailsServiceImpl extends BaseService<FailureDetailsDto, Fa
/** /**
* 发起故障保修单 * 发起故障保修单
* @throws Exception *
* @throws Exception
*/ */
@Transactional @Transactional
public Object savemodel(FailureDetailsDto failureDetailsDto, ReginParams userInfo) throws Exception { public Object savemodel(FailureDetailsDto failureDetailsDto, ReginParams userInfo) throws Exception {
String businessKey = buildOrderNo(); String businessKey = buildOrderNo();
JSONObject body = new JSONObject(); JSONObject body = new JSONObject();
body.put("businessKey", businessKey); body.put("businessKey", businessKey);
body.put("processDefinitionKey", processDefinitionKey); body.put("processDefinitionKey", processDefinitionKey);
JSONObject jsonObject = workflowFeignService.startByVariable(body); JSONObject jsonObject = workflowFeignService.startByVariable(body);
if (jsonObject == null) { if (jsonObject == null) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
// return CommonResponseUtil.failure("启动流程失败"); // return CommonResponseUtil.failure("启动流程失败");
...@@ -116,31 +117,29 @@ public class FailureDetailsServiceImpl extends BaseService<FailureDetailsDto, Fa ...@@ -116,31 +117,29 @@ public class FailureDetailsServiceImpl extends BaseService<FailureDetailsDto, Fa
// return CommonResponseUtil.failure("添加失败"); // return CommonResponseUtil.failure("添加失败");
} }
if (ObjectUtils.isNotEmpty(model)) { if (ObjectUtils.isNotEmpty(model)) {
excuteTask( instance.getString("id"), userInfo, null); excuteTask(instance.getString("id"), userInfo, null);
} }
return true; return true;
} }
public boolean excuteTask( Long sequenceNbr, ReginParams userInfo, public boolean excuteTask(Long sequenceNbr, ReginParams userInfo, String condition) {
String condition) {
HashMap<String, Object> conditionMap = new HashMap<String, Object>(); HashMap<String, Object> conditionMap = new HashMap<String, Object>();
conditionMap.put("condition", condition); conditionMap.put("condition", condition);
Map<String,Object> map= checkExcuteTaskAuthMap(sequenceNbr,userInfo); Map<String, Object> map = checkExcuteTaskAuthMap(sequenceNbr, userInfo);
try { try {
if(Boolean.parseBoolean(map.get("checkFlag").toString())) { if (Boolean.parseBoolean(map.get("checkFlag").toString())) {
workflowFeignService.pickupAndCompleteTask(map.get("taskId").toString(), conditionMap); workflowFeignService.pickupAndCompleteTask(map.get("taskId").toString(), conditionMap);
} }
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
return true; return true;
} }
public boolean excuteTask(String procressId, ReginParams userInfo, public boolean excuteTask(String procressId, ReginParams userInfo, String condition) throws Exception {
String condition) throws Exception {
HashMap<String, Object> conditionMap = new HashMap<String, Object>(); HashMap<String, Object> conditionMap = new HashMap<String, Object>();
conditionMap.put("condition", condition); conditionMap.put("condition", condition);
JSONObject teskObject =workflowFeignService.getTaskList(procressId); JSONObject teskObject = workflowFeignService.getTaskList(procressId);
if (ObjectUtils.isNotEmpty(teskObject)) { if (ObjectUtils.isNotEmpty(teskObject)) {
JSONArray taskDetailArray = teskObject.getJSONArray("data"); JSONArray taskDetailArray = teskObject.getJSONArray("data");
for (Object obj : taskDetailArray) { for (Object obj : taskDetailArray) {
...@@ -150,43 +149,60 @@ public class FailureDetailsServiceImpl extends BaseService<FailureDetailsDto, Fa ...@@ -150,43 +149,60 @@ public class FailureDetailsServiceImpl extends BaseService<FailureDetailsDto, Fa
} }
return true; return true;
} }
public boolean checkExcuteTaskAuth(Long sequenceNbr, ReginParams userInfo) { 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()); 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); FailureDetailsDto failureDetailsDto = this.queryBySeq(sequenceNbr);
// 获取送达部门的ID // 获取送达部门的ID
Integer failureEquipmentId = failureDetailsDto.getFailureEquipmentId(); Integer failureEquipmentId = failureDetailsDto.getFailureEquipmentId();
//获取上一级操作部门的Id // 获取上一级操作部门的Id
FailureDetails details = this.baseMapper.selectById(sequenceNbr); FailureDetails details = this.baseMapper.selectById(sequenceNbr);
String procressId = details.getProcessId(); String procressId = details.getProcessId();
Long seq = userInfo.getDepartment().getSequenceNbr(); Long seq = userInfo.getDepartment().getSequenceNbr();
JSONObject teskObject =workflowFeignService.getTaskList(procressId); JSONObject teskObject = workflowFeignService.getTaskList(procressId);
if (ObjectUtils.isNotEmpty(teskObject)) { if (ObjectUtils.isNotEmpty(teskObject)) {
JSONArray taskDetailArray = teskObject.getJSONArray("data"); JSONArray taskDetailArray = teskObject.getJSONArray("data");
for (Object obj : taskDetailArray) { for (Object obj : taskDetailArray) {
JSONObject detail = JSONObject.parseObject(JSONObject.toJSONString(obj)); JSONObject detail = JSONObject.parseObject(JSONObject.toJSONString(obj));
String name = detail.getString("name"); 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); FailureAudit failureAuditDetail = failureAuditService.findByFaultId(sequenceNbr);
Long auditDepartmentId = failureAuditDetail.getAuditDepartmentId(); Long auditDepartmentId = failureAuditDetail.getAuditDepartmentId();
if(auditDepartmentId.intValue() == seq.intValue()) { if (auditDepartmentId.intValue() == seq.intValue()) {
map.put("taskId", detail.getString("id")); map.put("taskId", detail.getString("id"));
map.put("checkFlag", true); map.put("checkFlag", true);
return map; break;
} }
} else { } else {
// 判断当前节点任务属于送达部门节点时需要判断当前登录人所在的部门id是否与表单发起时设置的送达部门一致
if (failureEquipmentId.intValue() == seq.intValue()) { if (failureEquipmentId.intValue() == seq.intValue()) {
map.put("taskId", detail.getString("id")); map.put("taskId", detail.getString("id"));
map.put("checkFlag", true); map.put("checkFlag", true);
return map; break;
} }
} }
} }
} }
map.put("checkFlag", false);
return map; 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