多实列
parent
f75b91873a
commit
aedd8e0d81
|
@ -15,8 +15,40 @@ public class ActConstant {
|
|||
*/
|
||||
public static final int TASK_INDEX_FIRST_USER_TASK= 1;
|
||||
|
||||
/**
|
||||
* 审批通过
|
||||
*/
|
||||
public static final int TYPE_APPROVE= 1;
|
||||
/**
|
||||
* 审批驳回
|
||||
*/
|
||||
public static final int TYPE_ROLLBACK= 2;
|
||||
|
||||
|
||||
/**
|
||||
* 单实例 或签
|
||||
*/
|
||||
public static final int TASK_TYPE_SINGE= 0;
|
||||
/**
|
||||
* 多实例 会签
|
||||
*/
|
||||
public static final int TASK_TYPE_MULTI= 1;
|
||||
|
||||
|
||||
/**
|
||||
* 会签任务总数
|
||||
*/
|
||||
public static final String NUMBER_OF_INSTANCES = "nrOfInstances";
|
||||
|
||||
/**
|
||||
* 活动的会签任务数
|
||||
*/
|
||||
public static final String NUMBER_OF_ACTIVE_INSTANCES = "nrOfActiveInstances";
|
||||
|
||||
/**
|
||||
* 完成会签任务数
|
||||
*/
|
||||
public static final String NUMBER_OF_COMPLETED_INSTANCES = "nrOfCompletedInstances";
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,5 +14,8 @@ public class ActHisTask {
|
|||
private String duration;
|
||||
private String comments;
|
||||
private String deleteReason;
|
||||
private String procInsId;
|
||||
private String procDefId;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cn.palmte.work.service;
|
|||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.activiti.engine.delegate.DelegateExecution;
|
||||
import org.activiti.engine.delegate.DelegateTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -9,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
|
@ -41,4 +43,24 @@ public class ActListenerService {
|
|||
}
|
||||
|
||||
|
||||
/*public void multiTaskcreate(DelegateTask delegateTask) throws Exception {
|
||||
logger.info("--- {}", JSONObject.toJSONString(delegateTask));
|
||||
|
||||
String procDefId = delegateTask.getProcessDefinitionId();
|
||||
String procInsId = delegateTask.getProcessInstanceId();
|
||||
String taskDefKey = delegateTask.getTaskDefinitionKey();
|
||||
Set<String> candidateUsers = actTaskDefService.findCandidateUsers(procDefId, procInsId, taskDefKey);
|
||||
logger.info("addCandidateUsers : {}", candidateUsers);
|
||||
delegateTask.addCandidateUsers(candidateUsers);
|
||||
}*/
|
||||
|
||||
|
||||
public Set<String> multipleInstanceTask(DelegateExecution delegateExecution) throws Exception {
|
||||
String procInsId = delegateExecution.getProcessInstanceId();
|
||||
String procDefId = delegateExecution.getProcessDefinitionId();
|
||||
String taskDefKey = delegateExecution.getCurrentActivityId();
|
||||
|
||||
return actTaskDefService.findCandidateUsers(procDefId, procInsId, taskDefKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -126,26 +126,30 @@ public class ActModelService {
|
|||
Collection<FlowElement> flowElements = process.getFlowElements();
|
||||
|
||||
int i = 0;
|
||||
ActTaskDef task;
|
||||
ActTaskDef taskDef;
|
||||
ActTaskDef first = null;
|
||||
for (FlowElement element : flowElements) {
|
||||
if (element instanceof UserTask) {
|
||||
UserTask userTask = (UserTask) element;
|
||||
userTask.setTaskListeners(activitiListenerList);
|
||||
UserTask userTaskElement = (UserTask) element;
|
||||
|
||||
task = new ActTaskDef();
|
||||
task.setTaskName(element.getName());
|
||||
task.setTaskKey(element.getId());
|
||||
MultiInstanceLoopCharacteristics loopCharacteristics = ((UserTask) element).getLoopCharacteristics();
|
||||
taskDef = new ActTaskDef();
|
||||
taskDef.setTaskName(element.getName());
|
||||
taskDef.setTaskKey(element.getId());
|
||||
MultiInstanceLoopCharacteristics loopCharacteristics = userTaskElement.getLoopCharacteristics();
|
||||
if (loopCharacteristics != null) {
|
||||
task.setTaskType(1);
|
||||
taskDef.setTaskType(ActConstant.TASK_TYPE_SINGE);
|
||||
loopCharacteristics.setInputDataItem("${actListenerService.multipleInstanceTask(execution)}");
|
||||
loopCharacteristics.setElementVariable("assignee");
|
||||
userTaskElement.setAssignee("${assignee}");
|
||||
}else {
|
||||
userTaskElement.setTaskListeners(activitiListenerList);
|
||||
}
|
||||
|
||||
if (i == 1) {
|
||||
task.setTaskIndex(ActConstant.TASK_INDEX_FIRST_USER_TASK);
|
||||
first = task;
|
||||
taskDef.setTaskIndex(ActConstant.TASK_INDEX_FIRST_USER_TASK);
|
||||
first = taskDef;
|
||||
}
|
||||
taskList.add(task);
|
||||
taskList.add(taskDef);
|
||||
}
|
||||
i ++;
|
||||
}
|
||||
|
|
|
@ -132,7 +132,10 @@ public class ActProcInsService {
|
|||
String[] split = currentTaskId.split(",");
|
||||
String candidateUsers = "";
|
||||
for (String taskId : split) {
|
||||
candidateUsers = actUtil.getAssigneeByIdentityLink(taskId);
|
||||
candidateUsers += actUtil.getAssigneeByIdentityLink(taskId) + ",";
|
||||
}
|
||||
if (candidateUsers.endsWith(",")) {
|
||||
candidateUsers = candidateUsers.substring(0, candidateUsers.length() - 1);
|
||||
}
|
||||
ins.setCandidateUsers(candidateUsers);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import cn.palmte.work.utils.ActUtil;
|
|||
import cn.palmte.work.utils.InterfaceUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.activiti.engine.*;
|
||||
import org.activiti.engine.task.IdentityLink;
|
||||
import org.activiti.engine.impl.persistence.entity.TaskEntity;
|
||||
import org.activiti.engine.task.Task;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -60,9 +60,66 @@ public class ActTaskDefService {
|
|||
Task currentTask = taskService.createTaskQuery().taskId(taskId).singleResult();
|
||||
ActTaskDef actTaskDef = findFirstByProcDefIdAndTaskKey(currentTask.getProcessDefinitionId(), currentTask.getTaskDefinitionKey());
|
||||
|
||||
if (ActConstant.TASK_TYPE_SINGE == actTaskDef.getTaskType()) {
|
||||
//或签处理
|
||||
handleSinge(taskId, procInsId, type, userId, actTaskDef);
|
||||
} else if (ActConstant.TASK_TYPE_MULTI == actTaskDef.getTaskType()) {
|
||||
//会签处理
|
||||
handleMulti(taskId, procInsId, type, userId, actTaskDef);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 会签处理
|
||||
*
|
||||
* @param taskId
|
||||
* @param procInsId
|
||||
* @param type
|
||||
* @param userId
|
||||
* @param actTaskDef
|
||||
*/
|
||||
private void handleMulti(String taskId, String procInsId, int type, String userId, ActTaskDef actTaskDef) {
|
||||
/* Double instanceCount = Double.parseDouble(ActUtil.filterNullToZero(taskService.getVariable(taskId, ActConstant.NUMBER_OF_INSTANCES))); //会签任务总数
|
||||
Double instanceActiveCount = Double.parseDouble(ActUtil.filterNullToZero(taskService.getVariable(taskId, ActConstant.NUMBER_OF_ACTIVE_INSTANCES))); //活动的会签任务数
|
||||
Double instanceCompleteCount = Double.parseDouble(ActUtil.filterNullToZero(taskService.getVariable(taskId, ActConstant.NUMBER_OF_COMPLETED_INSTANCES))); //完成会签任务数*/
|
||||
|
||||
if (ActConstant.TYPE_ROLLBACK == type) {
|
||||
//一个人驳回 整个任务节点驳回
|
||||
List<Task> taskList = taskService.createTaskQuery().processInstanceId(procInsId).list();
|
||||
for (int i = 0; i < taskList.size(); i++) {
|
||||
TaskEntity taskEntity = (TaskEntity) taskList.get(i);
|
||||
if (!taskId.equals(taskEntity.getId())) {
|
||||
taskEntity.setProcessInstanceId(null);
|
||||
taskEntity.setExecutionId(null);
|
||||
taskService.saveTask(taskEntity);
|
||||
taskService.addComment(taskEntity.getId(), procInsId, "会签驳回,任务失效");
|
||||
taskService.deleteTask(taskEntity.getId(), false); // 不删除历史记录
|
||||
}
|
||||
}
|
||||
|
||||
//驳回到配置的节点
|
||||
actUtil.jumpToTargetTask(taskId, actTaskDef.getRollbackTaskKey());
|
||||
return;
|
||||
}
|
||||
|
||||
taskService.complete(taskId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 或签处理
|
||||
*
|
||||
* @param taskId
|
||||
* @param procInsId
|
||||
* @param type
|
||||
* @param userId
|
||||
* @param actTaskDef
|
||||
*/
|
||||
private void handleSinge(String taskId, String procInsId, int type, String userId, ActTaskDef actTaskDef) {
|
||||
if (ActConstant.TYPE_APPROVE == type) {
|
||||
taskService.setAssignee(taskId, userId);
|
||||
//审批通过
|
||||
taskService.setAssignee(taskId, userId);
|
||||
taskService.complete(taskId);
|
||||
|
||||
//执行配置的审批通过脚本
|
||||
|
@ -86,7 +143,6 @@ public class ActTaskDefService {
|
|||
logger.info("未配置驳回脚本 task:{}", actTaskDef.getTaskName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -208,6 +208,20 @@ public class ActUtil {
|
|||
}
|
||||
|
||||
|
||||
public static String filterNull(final Object str) {
|
||||
String rs = (str == null) ? "" : str.toString().trim();
|
||||
return "null".equals(rs) ? "" : rs;
|
||||
}
|
||||
|
||||
public static String filterNullToZero(final Object stro) {
|
||||
String s = filterNull(stro);
|
||||
if ("".equals(s)) {
|
||||
s = "0";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 生成xml流
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
<th class="table-date">结束时间</th>
|
||||
<th class="table-date">用时</th>
|
||||
<th class="table-set am-text-center">意见</th>
|
||||
<th class="table-set am-text-center">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -38,6 +39,29 @@
|
|||
</#if></td>
|
||||
<td>${list.duration!}</td>
|
||||
<td>${list.comments!}</td>
|
||||
|
||||
|
||||
<td>
|
||||
|
||||
<#if !list.endTime??>
|
||||
<button type="button"
|
||||
class="am-btn am-btn-default am-btn-xs am-text-secondary"
|
||||
onclick="completeTask('${list.procInsId}', '${list.taskId}', 1)">
|
||||
<span class="am-icon-pencil-square-o"></span>
|
||||
审批通过
|
||||
</button>
|
||||
|
||||
<button type="button"
|
||||
class="am-btn am-btn-default am-btn-xs am-text-secondary"
|
||||
onclick="completeTask('${list.procInsId}', '${list.taskId}', 2)">
|
||||
<span class="am-icon-pencil-square-o"></span>
|
||||
驳回
|
||||
</button>
|
||||
|
||||
</#if>
|
||||
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</#list>
|
||||
</#if>
|
||||
|
@ -74,8 +98,24 @@
|
|||
var urlBase = "${base}";
|
||||
var url;
|
||||
|
||||
$(function () {
|
||||
|
||||
|
||||
var completeTask = function (procInsId, taskId, type) {
|
||||
var params = {
|
||||
procInsId: procInsId,
|
||||
taskId: taskId,
|
||||
type: type,
|
||||
message: '管理员审批'
|
||||
};
|
||||
$.ajax({
|
||||
url: '${base}/actTaskDef/completeTask',
|
||||
data: JSON.stringify(params),
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
type: 'post',
|
||||
async: false,
|
||||
success: function (data) {
|
||||
alert(data.msg);
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
|
@ -48,21 +48,6 @@
|
|||
撤销流程
|
||||
</button>
|
||||
|
||||
|
||||
<button type="button"
|
||||
class="am-btn am-btn-default am-btn-xs am-text-secondary"
|
||||
onclick="completeTask('${list.procInsId}', '${list.currentTaskId}', 1)">
|
||||
<span class="am-icon-pencil-square-o"></span>
|
||||
审批通过
|
||||
</button>
|
||||
|
||||
<button type="button"
|
||||
class="am-btn am-btn-default am-btn-xs am-text-secondary"
|
||||
onclick="completeTask('${list.procInsId}', '${list.currentTaskId}', 2)">
|
||||
<span class="am-icon-pencil-square-o"></span>
|
||||
驳回
|
||||
</button>
|
||||
|
||||
</#if>
|
||||
<button type="button"
|
||||
class="am-btn am-btn-default am-btn-xs am-text-secondary"
|
||||
|
@ -223,25 +208,4 @@
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
var completeTask = function (procInsId, taskId, type) {
|
||||
var params = {
|
||||
procInsId: procInsId,
|
||||
taskId: taskId,
|
||||
type: type,
|
||||
message: '管理员审批'
|
||||
};
|
||||
$.ajax({
|
||||
url: '${base}/actTaskDef/completeTask',
|
||||
data: JSON.stringify(params),
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
type: 'post',
|
||||
async: false,
|
||||
success: function (data) {
|
||||
alert(data.msg);
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue