|
@@ -10,6 +10,7 @@ import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.sop.business.activiti.service.ActivitiService;
|
|
|
import com.qmth.sop.business.bean.bean.FormPropertyBean;
|
|
|
import com.qmth.sop.business.bean.result.*;
|
|
|
+import com.qmth.sop.business.cache.CommonCacheService;
|
|
|
import com.qmth.sop.business.entity.*;
|
|
|
import com.qmth.sop.business.mapper.SysUserMapper;
|
|
|
import com.qmth.sop.business.service.*;
|
|
@@ -31,6 +32,7 @@ import org.activiti.engine.history.HistoricTaskInstance;
|
|
|
import org.activiti.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior;
|
|
|
import org.activiti.engine.repository.DeploymentBuilder;
|
|
|
import org.activiti.engine.runtime.ProcessInstance;
|
|
|
+import org.activiti.engine.task.IdentityLink;
|
|
|
import org.activiti.engine.task.Task;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -93,6 +95,9 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
@Resource
|
|
|
SysUserService sysUserService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ CommonCacheService commonCacheService;
|
|
|
+
|
|
|
/**
|
|
|
* 根据deploymentId查找processDefinitionId
|
|
|
*
|
|
@@ -170,9 +175,9 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
List<String> approveUserIds,
|
|
|
String approveRemark,
|
|
|
Map<String, Object> map) {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
if (CollectionUtils.isEmpty(approveUserIds) && (approve == FlowApprovePassEnum.START || approve == FlowApprovePassEnum.DRAFT || approve == FlowApprovePassEnum.PASS)) {
|
|
|
approveUserIds = new ArrayList<>();
|
|
|
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
approveUserIds.add(String.valueOf(sysUser.getId()));//否则是当前登录用户
|
|
|
}
|
|
|
String processFlowId = null;
|
|
@@ -187,8 +192,8 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
map.put(SystemConstant.DEFAULT_ASSIGNEE_LIST + 1, approveUserIds);
|
|
|
ProcessInstance processInstance = runtimeService.startProcessInstanceById(tfCustomFlow.getFlowDefinitionId(), map);
|
|
|
processFlowId = processInstance.getId();
|
|
|
- tfCustomFlowEntity = new TFCustomFlowEntity(tfCustomFlow.getId(), null);
|
|
|
- tfFlowApprove = new TFFlowApprove(null, Long.parseLong(approveUserIds.get(approveUserIds.size() - 1)), FlowStatusEnum.valueOf(approve.name()), null);
|
|
|
+ tfCustomFlowEntity = new TFCustomFlowEntity(tfCustomFlow.getId(), sysUser.getId());
|
|
|
+ tfFlowApprove = new TFFlowApprove(sysUser.getOrgId(), Long.parseLong(approveUserIds.get(approveUserIds.size() - 1)), FlowStatusEnum.valueOf(approve.name()), null);
|
|
|
flowResult = JSONObject.parseObject(tfCustomFlow.getFlowProcessVar(), FlowResult.class);
|
|
|
} else if (Objects.nonNull(taskId)) {
|
|
|
taskTemp = taskService.createTaskQuery().taskId(String.valueOf(taskId)).singleResult();
|
|
@@ -243,9 +248,8 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
if (currSetup != 2 && approve == FlowApprovePassEnum.CANCEL) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("只有流程第二步才能撤回!");
|
|
|
}
|
|
|
-// List<IdentityLink> identityLinkList = taskService.getIdentityLinksForTask(task.getId());
|
|
|
//流程流水日志
|
|
|
- TFFlowLog tfFlowLog = new TFFlowLog(null, Long.parseLong(task.getAssignee()), null,
|
|
|
+ TFFlowLog tfFlowLog = new TFFlowLog(sysUser.getOrgId(), sysUser.getId(), sysUser.getId(),
|
|
|
currFlowTaskResult.getSetup(), Long.parseLong(processFlowId),
|
|
|
Long.parseLong(task.getId()), tfCustomFlowEntity.getId(), approveUserIds.toString().replaceAll("\\[", "").replaceAll("\\]", ""));
|
|
|
if (approve == FlowApprovePassEnum.PASS || approve == FlowApprovePassEnum.DRAFT || approve == FlowApprovePassEnum.START) {
|
|
@@ -305,6 +309,7 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
Set<String> approveIdSet = new LinkedHashSet<>();
|
|
|
for (int i = historicTaskInstanceList.size() - 1; i >= 0; i--) {
|
|
|
HistoricTaskInstance historicTaskInstance = historicTaskInstanceList.get(i);
|
|
|
+// List<HistoricIdentityLink> historicIdentityLinkList = historyService.getHistoricIdentityLinksForTask(task.getId());
|
|
|
if (Objects.equals(historicTaskInstance.getTaskDefinitionKey(), nextFlowTaskResult.getTaskKey())) {
|
|
|
approveIdSet.add(historicTaskInstance.getAssignee());
|
|
|
}
|
|
@@ -318,7 +323,16 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
if (!CollectionUtils.isEmpty(tasks)) {
|
|
|
Set<String> approveIdSet = new LinkedHashSet<>();
|
|
|
for (Task t : tasks) {
|
|
|
- approveIdSet.add(t.getAssignee());
|
|
|
+ if (Objects.isNull(t.getAssignee())) {
|
|
|
+ List<IdentityLink> identityLinkList = taskService.getIdentityLinksForTask(t.getId());
|
|
|
+ if (!CollectionUtils.isEmpty(identityLinkList)) {
|
|
|
+ for (IdentityLink i : identityLinkList) {
|
|
|
+ approveIdSet.add(i.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ approveIdSet.add(t.getAssignee());
|
|
|
+ }
|
|
|
}
|
|
|
tfFlowLog.setPendApproveId(approveIdSet.toString().replaceAll("\\[", "").replaceAll("\\]", ""));
|
|
|
}
|
|
@@ -427,6 +441,11 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Boolean taskApproverExchange(Long userId, Long taskId) {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ SysOrg sysOrg = commonCacheService.orgCache(sysUser.getOrgId());
|
|
|
+ if (Objects.equals(String.valueOf(sysUser.getId()), String.valueOf(userId))) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("不能转给自己!");
|
|
|
+ }
|
|
|
boolean lock = memoryLock.lock(SystemConstant.LOCK_FLOW_EXCHANGE_PREFIX + taskId, taskId, SystemConstant.LOCK_FLOW_TIME_OUT);
|
|
|
if (!lock) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("正在转审中,请稍候再试!");
|
|
@@ -435,25 +454,36 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
Task task = taskService.createTaskQuery().taskId(String.valueOf(taskId)).singleResult();
|
|
|
Optional.ofNullable(task).orElseThrow(() -> ExceptionResultEnum.FLOW_TASK_NO_DATA.exception());
|
|
|
|
|
|
- if (Objects.equals(task.getAssignee(), String.valueOf(userId))) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("不能转给自己!");
|
|
|
- } else {
|
|
|
- List<HistoricTaskInstance> historicTaskInstanceList = historyService.createHistoricTaskInstanceQuery()
|
|
|
- .processInstanceId(task.getProcessInstanceId()).orderByHistoricTaskInstanceEndTime().desc().list();
|
|
|
- if (!CollectionUtils.isEmpty(historicTaskInstanceList)) {
|
|
|
- Set<String> approveIdSet = new LinkedHashSet<>();
|
|
|
- for (int i = historicTaskInstanceList.size() - 1; i >= 0; i--) {
|
|
|
- HistoricTaskInstance historicTaskInstance = historicTaskInstanceList.get(i);
|
|
|
- if (Objects.equals(historicTaskInstance.getTaskDefinitionKey(), task.getTaskDefinitionKey())) {
|
|
|
- approveIdSet.add(historicTaskInstance.getAssignee());
|
|
|
- }
|
|
|
- }
|
|
|
- if (approveIdSet.contains(String.valueOf(userId))) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("该审批人已有审批权限!");
|
|
|
- }
|
|
|
+ BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
|
|
|
+ FlowNode currFlow = (FlowNode) bpmnModel.getMainProcess().getFlowElement(task.getTaskDefinitionKey());
|
|
|
+ Integer nrOfCompletedInstances = null, nrOfInstances = null;
|
|
|
+ boolean multiInstance = false;
|
|
|
+ if (currFlow.getBehavior() instanceof MultiInstanceActivityBehavior) {//会签
|
|
|
+ nrOfCompletedInstances = (Integer) taskService.getVariable(task.getId(), SystemConstant.NR_OF_COMPLETED_INSTANCES);
|
|
|
+ nrOfInstances = (Integer) taskService.getVariable(task.getId(), SystemConstant.NR_OF_INSTANCES);
|
|
|
+ multiInstance = true;
|
|
|
+
|
|
|
+ List<Task> taskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).list();
|
|
|
+ List<String> taskApproveList = new ArrayList<>();
|
|
|
+ for (Task t : taskList) {
|
|
|
+ taskApproveList.add(t.getAssignee());
|
|
|
+ }
|
|
|
+ if (taskApproveList.contains(userId)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("该审批人已有审批权限,无需流转");
|
|
|
+ }
|
|
|
+ } else {//或签
|
|
|
+ Task taskUser = taskService.createTaskQuery().taskId(String.valueOf(taskId)).taskCandidateOrAssigned(String.valueOf(userId)).singleResult();
|
|
|
+ if (Objects.nonNull(taskUser)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("该审批人已有审批权限,无需流转");
|
|
|
}
|
|
|
}
|
|
|
- taskService.setAssignee(String.valueOf(taskId), String.valueOf(userId));
|
|
|
+
|
|
|
+ if (!multiInstance) {
|
|
|
+ taskService.deleteCandidateUser(String.valueOf(taskId), String.valueOf(sysUser.getId()));
|
|
|
+ taskService.addCandidateUser(String.valueOf(taskId), String.valueOf(userId));
|
|
|
+ } else {
|
|
|
+ taskService.setAssignee(String.valueOf(taskId), String.valueOf(userId));
|
|
|
+ }
|
|
|
|
|
|
TFCustomFlowEntity tfCustomFlowEntity = tfCustomFlowEntityService.getOne(new QueryWrapper<TFCustomFlowEntity>().lambda().eq(TFCustomFlowEntity::getFlowId, Long.parseLong(task.getProcessInstanceId())));
|
|
|
Optional.ofNullable(tfCustomFlowEntity).orElseThrow(() -> ExceptionResultEnum.FLOW_ENTITY_NO_DATA.exception());
|
|
@@ -461,11 +491,13 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
FlowResult flowResult = JSONObject.parseObject(tfCustomFlowEntity.getFlowProcessVar(), FlowResult.class);
|
|
|
LinkedHashMap<String, FlowTaskResult> setupMap = flowResult.getSetupMap();
|
|
|
FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(setupMap.get(task.getTaskDefinitionKey())), FlowTaskResult.class);
|
|
|
- TFFlowLog tfFlowLog = new TFFlowLog(null, Long.parseLong(task.getAssignee()), null,
|
|
|
+ TFFlowLog tfFlowLog = new TFFlowLog(sysUser.getOrgId(), sysUser.getId(), sysUser.getId(),
|
|
|
currFlowTaskResult.getSetup(), Long.parseLong(task.getProcessInstanceId()),
|
|
|
Long.parseLong(task.getId()), tfCustomFlowEntity.getId(), String.valueOf(userId));
|
|
|
tfFlowLog.setApproveOperation(FlowApproveOperationEnum.EXCHANGE);
|
|
|
- tfFlowLog.setApproveRemark(task.getAssignee() + "转" + userId + "审批");
|
|
|
+ SysUser exchangeUser = sysUserService.getById(userId);
|
|
|
+ SysOrg exchangeOrg = commonCacheService.orgCache(exchangeUser.getOrgId());
|
|
|
+ tfFlowLog.setApproveRemark(sysUser.getRealName() + "(" + sysOrg.getName() + ")转" + exchangeUser.getRealName() + "(" + exchangeOrg.getName() + ")审批");
|
|
|
tfFlowLogService.save(tfFlowLog);
|
|
|
} catch (Exception e) {
|
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
@@ -489,6 +521,7 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Boolean flowEnd(Long flowId) {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
boolean lock = memoryLock.lock(SystemConstant.LOCK_FLOW_END_PREFIX + flowId, flowId, SystemConstant.LOCK_FLOW_TIME_OUT);
|
|
|
if (!lock) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("正在终止中,请稍候再试!");
|
|
@@ -508,11 +541,11 @@ public class ActivitiServiceImpl implements ActivitiService {
|
|
|
}
|
|
|
FlowTaskResult currFlowTaskResult = GsonUtil.fromJson(GsonUtil.toJson(setupMap.get(taskList.get(0).getTaskDefinitionKey())), FlowTaskResult.class);
|
|
|
|
|
|
- TFFlowLog tfFlowLog = new TFFlowLog(null, Long.parseLong(taskList.get(0).getAssignee()), null,
|
|
|
+ TFFlowLog tfFlowLog = new TFFlowLog(sysUser.getOrgId(), sysUser.getId(), sysUser.getId(),
|
|
|
currFlowTaskResult.getSetup(), flowId,
|
|
|
Long.parseLong(taskList.get(0).getId()), tfCustomFlowEntity.getId(), null);
|
|
|
tfFlowLog.setApproveOperation(FlowApproveOperationEnum.END);
|
|
|
- tfFlowLog.setApproveRemark(taskList.get(0).getAssignee() + "终止流程");
|
|
|
+ tfFlowLog.setApproveRemark(sysUser.getRealName() + "终止流程");
|
|
|
tfFlowLogService.save(tfFlowLog);
|
|
|
|
|
|
tfFlowApprove.setStatus(FlowStatusEnum.END);
|