feat(workflow): 实现自定义选择下一个处理人功能
- 在前端增加提示信息,指导用户指定下一个任务的处理人 - 在后端增加逻辑,处理用户选择的下一个处理人 - 修改数据库,增加采购计划详情编号字段- 优化采购计划详情查询条件,支持按详情编号查询
This commit is contained in:
6
klp-admin/src/main/resources/db/migration/V4__newSql.sql
Normal file
6
klp-admin/src/main/resources/db/migration/V4__newSql.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
alter table wms_purchase_plan_detail
|
||||
modify plan_id bigint null comment '采购计划ID';
|
||||
|
||||
alter table wms_purchase_plan_detail
|
||||
add detail_code varchar(64) null comment '详情编码' after plan_id;
|
||||
|
||||
@@ -4,6 +4,8 @@ import org.flowable.engine.delegate.TaskListener;
|
||||
import org.flowable.task.service.delegate.DelegateTask;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户任务监听器
|
||||
*
|
||||
@@ -20,8 +22,24 @@ public class UserTaskListener implements TaskListener {
|
||||
|
||||
@Override
|
||||
public void notify(DelegateTask delegateTask) {
|
||||
//TODO 实现你的任务监听器逻辑
|
||||
System.out.println("执行任务监听器...");
|
||||
|
||||
// 检查是否有指定的下一个处理人
|
||||
Map<String, Object> variables = delegateTask.getVariables();
|
||||
if (variables.containsKey("nextUserIds")) {
|
||||
String nextUserIds = (String) variables.get("nextUserIds");
|
||||
if (nextUserIds != null && !nextUserIds.isEmpty()) {
|
||||
// 设置任务的处理人
|
||||
String[] userIds = nextUserIds.split(",");
|
||||
if (userIds.length > 0) {
|
||||
delegateTask.setAssignee(userIds[0]);
|
||||
}
|
||||
// 如果有多个处理人,可以设置为候选人
|
||||
for (int i = 1; i < userIds.length; i++) {
|
||||
delegateTask.addCandidateUser(userIds[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.klp.flowable.utils;
|
||||
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 下一个处理人选择器
|
||||
* 用于处理用户自定义选择下一个处理人的逻辑
|
||||
*
|
||||
* @author CodeBuddy
|
||||
* @since 2025/8/22
|
||||
*/
|
||||
@Component
|
||||
public class NextUserSelector {
|
||||
|
||||
private final TaskService taskService;
|
||||
private final RuntimeService runtimeService;
|
||||
|
||||
public NextUserSelector(TaskService taskService, RuntimeService runtimeService) {
|
||||
this.taskService = taskService;
|
||||
this.runtimeService = runtimeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置下一个任务的处理人
|
||||
*
|
||||
* @param taskId 当前任务ID
|
||||
* @param nextUserIds 下一个处理人ID,多个用逗号分隔
|
||||
*/
|
||||
public void setNextTaskUsers(String taskId, String nextUserIds) {
|
||||
if (nextUserIds == null || nextUserIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置流程变量,在任务完成后传递给下一个任务
|
||||
Map<String, Object> variables = new HashMap<>();
|
||||
variables.put("nextUserIds", nextUserIds);
|
||||
|
||||
// 更新流程实例变量
|
||||
runtimeService.setVariables(task.getExecutionId(), variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前任务的指定处理人
|
||||
*
|
||||
* @param taskId 任务ID
|
||||
* @return 指定的处理人ID,多个用逗号分隔
|
||||
*/
|
||||
public String getNextTaskUsers(String taskId) {
|
||||
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
|
||||
if (task == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object nextUserIds = runtimeService.getVariable(task.getExecutionId(), "nextUserIds");
|
||||
return nextUserIds != null ? nextUserIds.toString() : null;
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,18 @@ public class WfTaskServiceImpl extends FlowServiceFactory implements IWfTaskServ
|
||||
// 获取 bpmn 模型
|
||||
BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
|
||||
identityService.setAuthenticatedUserId(TaskUtils.getUserId());
|
||||
|
||||
// 处理下一级审批人,将用户选择的下一个处理人保存到流程变量中
|
||||
if (StringUtils.isNotBlank(taskBo.getNextUserIds())) {
|
||||
// 如果有指定下一个处理人,则将其保存到流程变量中
|
||||
Map<String, Object> variables = taskBo.getVariables();
|
||||
if (variables == null) {
|
||||
variables = new HashMap<>();
|
||||
taskBo.setVariables(variables);
|
||||
}
|
||||
variables.put("nextUserIds", taskBo.getNextUserIds());
|
||||
}
|
||||
|
||||
if (DelegationState.PENDING.equals(task.getDelegationState())) {
|
||||
taskService.addComment(taskBo.getTaskId(), taskBo.getProcInsId(), FlowComment.DELEGATE.getType(), taskBo.getComment());
|
||||
taskService.resolveTask(taskBo.getTaskId());
|
||||
|
||||
@@ -42,6 +42,10 @@
|
||||
{{ item.nickName }}
|
||||
</el-tag>
|
||||
<el-button class="button-new-tag" type="primary" icon="el-icon-plus" size="mini" circle @click="onSelectNextUsers" />
|
||||
<div class="form-item-tip">
|
||||
<i class="el-icon-info"></i>
|
||||
<span>您可以指定下一个任务的处理人,系统将自动将任务分配给指定的人员</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-col>
|
||||
@@ -651,4 +655,16 @@ export default {
|
||||
.button-new-tag {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.form-item-tip {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
line-height: 1.5;
|
||||
|
||||
i {
|
||||
margin-right: 4px;
|
||||
color: #E6A23C;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -73,4 +73,9 @@ public class WmsPurchasePlanDetail extends BaseEntity {
|
||||
*/
|
||||
private Long contractId;
|
||||
|
||||
/**
|
||||
* 详情编号
|
||||
*/
|
||||
private String detailCode;
|
||||
|
||||
}
|
||||
|
||||
@@ -75,5 +75,10 @@ public class WmsPurchasePlanDetailBo extends BaseEntity {
|
||||
*/
|
||||
private Long contractId;
|
||||
|
||||
/**
|
||||
* 详情编号
|
||||
*/
|
||||
private String detailCode;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -111,4 +111,9 @@ public class WmsPurchasePlanDetailVo {
|
||||
* 合同编号
|
||||
*/
|
||||
private String contractNo;
|
||||
|
||||
/**
|
||||
* 详情编号
|
||||
*/
|
||||
private String detailCode;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ public class WmsPurchasePlanDetailServiceImpl implements IWmsPurchasePlanDetailS
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getOwner()), WmsPurchasePlanDetail::getOwner, bo.getOwner());
|
||||
lqw.eq(bo.getQuantity() != null, WmsPurchasePlanDetail::getQuantity, bo.getQuantity());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getUnit()), WmsPurchasePlanDetail::getUnit, bo.getUnit());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getDetailCode()), WmsPurchasePlanDetail::getDetailCode, bo.getDetailCode());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
@@ -78,6 +79,7 @@ public class WmsPurchasePlanDetailServiceImpl implements IWmsPurchasePlanDetailS
|
||||
qw.eq(StringUtils.isNotBlank(bo.getOwner()), "wpd.owner", bo.getOwner());
|
||||
qw.eq(bo.getQuantity() != null, "wpd.quantity", bo.getQuantity());
|
||||
qw.eq(StringUtils.isNotBlank(bo.getUnit()), "wpd.unit", bo.getUnit());
|
||||
qw.like(StringUtils.isNotBlank(bo.getDetailCode()), "wpd.detail_code", bo.getDetailCode());
|
||||
return qw;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="contractId" column="contract_id"/>
|
||||
<result property="supplierId" column="supplier_id"/>
|
||||
<result property="detailCode" column="detail_code"/>
|
||||
</resultMap>
|
||||
<select id="selectVoPagePlus" resultType="com.klp.domain.vo.WmsPurchasePlanDetailVo">
|
||||
<!-- 联查材料名称编码 -->
|
||||
|
||||
Reference in New Issue
Block a user