多实列
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 TASK_INDEX_FIRST_USER_TASK= 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 审批通过
|
||||||
|
*/
|
||||||
public static final int TYPE_APPROVE= 1;
|
public static final int TYPE_APPROVE= 1;
|
||||||
|
/**
|
||||||
|
* 审批驳回
|
||||||
|
*/
|
||||||
public static final int TYPE_ROLLBACK= 2;
|
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 duration;
|
||||||
private String comments;
|
private String comments;
|
||||||
private String deleteReason;
|
private String deleteReason;
|
||||||
|
private String procInsId;
|
||||||
|
private String procDefId;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cn.palmte.work.service;
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.activiti.engine.delegate.DelegateExecution;
|
||||||
import org.activiti.engine.delegate.DelegateTask;
|
import org.activiti.engine.delegate.DelegateTask;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -9,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
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();
|
Collection<FlowElement> flowElements = process.getFlowElements();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
ActTaskDef task;
|
ActTaskDef taskDef;
|
||||||
ActTaskDef first = null;
|
ActTaskDef first = null;
|
||||||
for (FlowElement element : flowElements) {
|
for (FlowElement element : flowElements) {
|
||||||
if (element instanceof UserTask) {
|
if (element instanceof UserTask) {
|
||||||
UserTask userTask = (UserTask) element;
|
UserTask userTaskElement = (UserTask) element;
|
||||||
userTask.setTaskListeners(activitiListenerList);
|
|
||||||
|
|
||||||
task = new ActTaskDef();
|
taskDef = new ActTaskDef();
|
||||||
task.setTaskName(element.getName());
|
taskDef.setTaskName(element.getName());
|
||||||
task.setTaskKey(element.getId());
|
taskDef.setTaskKey(element.getId());
|
||||||
MultiInstanceLoopCharacteristics loopCharacteristics = ((UserTask) element).getLoopCharacteristics();
|
MultiInstanceLoopCharacteristics loopCharacteristics = userTaskElement.getLoopCharacteristics();
|
||||||
if (loopCharacteristics != null) {
|
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) {
|
if (i == 1) {
|
||||||
task.setTaskIndex(ActConstant.TASK_INDEX_FIRST_USER_TASK);
|
taskDef.setTaskIndex(ActConstant.TASK_INDEX_FIRST_USER_TASK);
|
||||||
first = task;
|
first = taskDef;
|
||||||
}
|
}
|
||||||
taskList.add(task);
|
taskList.add(taskDef);
|
||||||
}
|
}
|
||||||
i ++;
|
i ++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class ActProcInsService {
|
||||||
* @param variables
|
* @param variables
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String startProcessInstance(String procDefKey, Map<String, Object> variables) throws Exception{
|
public String startProcessInstance(String procDefKey, Map<String, Object> variables) throws Exception {
|
||||||
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().processDefinitionKey(procDefKey).active().orderByProcessDefinitionVersion().desc().list();
|
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().processDefinitionKey(procDefKey).active().orderByProcessDefinitionVersion().desc().list();
|
||||||
if (list == null || list.isEmpty()) {
|
if (list == null || list.isEmpty()) {
|
||||||
throw new Exception("procDefKey(" + procDefKey + ")未定义");
|
throw new Exception("procDefKey(" + procDefKey + ")未定义");
|
||||||
|
@ -132,7 +132,10 @@ public class ActProcInsService {
|
||||||
String[] split = currentTaskId.split(",");
|
String[] split = currentTaskId.split(",");
|
||||||
String candidateUsers = "";
|
String candidateUsers = "";
|
||||||
for (String taskId : split) {
|
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);
|
ins.setCandidateUsers(candidateUsers);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import cn.palmte.work.utils.ActUtil;
|
||||||
import cn.palmte.work.utils.InterfaceUtil;
|
import cn.palmte.work.utils.InterfaceUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.activiti.engine.*;
|
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.activiti.engine.task.Task;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -60,9 +60,66 @@ public class ActTaskDefService {
|
||||||
Task currentTask = taskService.createTaskQuery().taskId(taskId).singleResult();
|
Task currentTask = taskService.createTaskQuery().taskId(taskId).singleResult();
|
||||||
ActTaskDef actTaskDef = findFirstByProcDefIdAndTaskKey(currentTask.getProcessDefinitionId(), currentTask.getTaskDefinitionKey());
|
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) {
|
if (ActConstant.TYPE_APPROVE == type) {
|
||||||
taskService.setAssignee(taskId, userId);
|
|
||||||
//审批通过
|
//审批通过
|
||||||
|
taskService.setAssignee(taskId, userId);
|
||||||
taskService.complete(taskId);
|
taskService.complete(taskId);
|
||||||
|
|
||||||
//执行配置的审批通过脚本
|
//执行配置的审批通过脚本
|
||||||
|
@ -86,7 +143,6 @@ public class ActTaskDefService {
|
||||||
logger.info("未配置驳回脚本 task:{}", actTaskDef.getTaskName());
|
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流
|
* 生成xml流
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
<th class="table-date">结束时间</th>
|
<th class="table-date">结束时间</th>
|
||||||
<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>
|
||||||
|
<th class="table-set am-text-center">操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -35,9 +36,32 @@
|
||||||
<td>${list.startTime?datetime}</td>
|
<td>${list.startTime?datetime}</td>
|
||||||
<td><#if list.endTime??>
|
<td><#if list.endTime??>
|
||||||
${list.endTime?datetime}
|
${list.endTime?datetime}
|
||||||
</#if></td>
|
</#if></td>
|
||||||
<td>${list.duration!}</td>
|
<td>${list.duration!}</td>
|
||||||
<td>${list.comments!}</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>
|
</tr>
|
||||||
</#list>
|
</#list>
|
||||||
</#if>
|
</#if>
|
||||||
|
@ -74,8 +98,24 @@
|
||||||
var urlBase = "${base}";
|
var urlBase = "${base}";
|
||||||
var url;
|
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>
|
</script>
|
|
@ -48,21 +48,6 @@
|
||||||
撤销流程
|
撤销流程
|
||||||
</button>
|
</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>
|
</#if>
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="am-btn am-btn-default am-btn-xs am-text-secondary"
|
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>
|
</script>
|
Loading…
Reference in New Issue