Browse Source

增加流程变量调用

test
smallchill 6 years ago
parent
commit
5684fe425b
  1. 10
      blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/constant/ProcessConstant.java
  2. 21
      blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/feign/IFlowClient.java
  3. 10
      blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/feign/IFlowClientFallback.java
  4. 13
      blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/feign/FlowClient.java
  5. 5
      blade-service/blade-desk/pom.xml
  6. 14
      blade-service/blade-desk/src/main/java/org/springblade/desk/controller/LeaveController.java
  7. 2
      blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/LeaveServiceImpl.java

10
blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/constant/ProcessConstant.java

@ -28,6 +28,11 @@ public interface ProcessConstant {
*/
String LEAVE_KEY = "Leave";
/**
* 报销流程标识
*/
String Expense_KEY = "Expense";
/**
* 同意默认批复
*/
@ -38,4 +43,9 @@ public interface ProcessConstant {
*/
String NOT_PASS_COMMENT = "驳回";
/**
* 创建人变量名
*/
String TASK_VARIABLE_CREATE_USER = "createUser";
}

21
blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/feign/IFlowClient.java

@ -20,6 +20,7 @@ import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.tool.api.R;
import org.springblade.flowable.core.entity.BladeFlow;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
@ -41,6 +42,8 @@ public interface IFlowClient {
String START_PROCESS_INSTANCE_BY_ID = API_PREFIX + "start-process-instance-by-id";
String START_PROCESS_INSTANCE_BY_KEY = API_PREFIX + "start-process-instance-by-key";
String COMPLETE_TASK = API_PREFIX + "complete-task";
String TASK_VARIABLE = API_PREFIX + "task-variable";
String TASK_VARIABLES = API_PREFIX + "task-variables";
/**
* 开启流程
@ -76,4 +79,22 @@ public interface IFlowClient {
@PostMapping(COMPLETE_TASK)
R completeTask(@RequestParam("taskId") String taskId, @RequestParam("processInstanceId") String processInstanceId, @RequestParam("comment") String comment, @RequestBody Map<String, Object> variables);
/**
* 获取流程变量
*
* @param taskId 任务id
* @param variableName 变量名
* @return R
*/
@GetMapping(TASK_VARIABLE)
R<Object> taskVariable(@RequestParam("taskId") String taskId, @RequestParam("variableName") String variableName);
/**
* 获取流程变量集合
*
* @param taskId 任务id
* @return R
*/
@GetMapping(TASK_VARIABLES)
R<Map<String, Object>> taskVariables(@RequestParam("taskId") String taskId);
}

10
blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/feign/IFlowClientFallback.java

@ -45,4 +45,14 @@ public class IFlowClientFallback implements IFlowClient {
return R.fail("远程调用失败");
}
@Override
public R<Object> taskVariable(String taskId, String variableName) {
return R.fail("远程调用失败");
}
@Override
public R<Map<String, Object>> taskVariables(String taskId) {
return R.fail("远程调用失败");
}
}

13
blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/feign/FlowClient.java

@ -28,6 +28,7 @@ import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.flowable.core.entity.BladeFlow;
import org.springblade.flowable.core.feign.IFlowClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@ -89,4 +90,16 @@ public class FlowClient implements IFlowClient {
return R.success("流程提交成功");
}
@Override
@GetMapping(TASK_VARIABLE)
public R<Object> taskVariable(String taskId, String variableName) {
return R.data(taskService.getVariable(taskId, variableName));
}
@Override
@GetMapping(TASK_VARIABLES)
public R<Map<String, Object>> taskVariables(String taskId) {
return R.data(taskService.getVariables(taskId));
}
}

5
blade-service/blade-desk/pom.xml

@ -37,11 +37,6 @@
<artifactId>blade-dict-api</artifactId>
<version>${bladex.project.version}</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-user-api</artifactId>
<version>${bladex.project.version}</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-flow-api</artifactId>

14
blade-service/blade-desk/src/main/java/org/springblade/desk/controller/LeaveController.java

@ -20,10 +20,12 @@ import lombok.AllArgsConstructor;
import org.springblade.common.cache.CacheNames;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.desk.entity.ProcessLeave;
import org.springblade.desk.service.ILeaveService;
import org.springblade.flowable.core.constant.ProcessConstant;
import org.springblade.flowable.core.entity.BladeFlow;
import org.springblade.system.user.cache.UserCache;
import org.springblade.flowable.core.feign.IFlowClient;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
@ -39,17 +41,21 @@ import springfox.documentation.annotations.ApiIgnore;
public class LeaveController extends BladeController implements CacheNames {
private ILeaveService leaveService;
private IFlowClient flowClient;
/**
* 详情
*
* @param taskId 任务主键
* @param businessId 主键
*/
@GetMapping("detail")
public R<ProcessLeave> detail(Integer businessId) {
public R<ProcessLeave> detail(String taskId, Integer businessId) {
ProcessLeave detail = leaveService.getById(businessId);
String name = UserCache.getUser(detail.getCreateUser()).getName();
detail.getFlow().setAssigneeName(name);
R<Object> result = flowClient.taskVariable(taskId, ProcessConstant.TASK_VARIABLE_CREATE_USER);
if (result.isSuccess()) {
detail.getFlow().setAssigneeName(Func.toStr(result.getData(), "暂无"));
}
return R.data(detail);
}

2
blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/LeaveServiceImpl.java

@ -20,6 +20,7 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
@ -58,6 +59,7 @@ public class LeaveServiceImpl extends BaseServiceImpl<LeaveMapper, ProcessLeave>
save(leave);
// 启动流程
Kv variables = Kv.create()
.set(ProcessConstant.TASK_VARIABLE_CREATE_USER, SecureUtil.getUserName())
.set("taskUser", leave.getTaskUser())
.set("days", Duration.between(leave.getStartTime(), leave.getEndTime()).toDays());
R<BladeFlow> result = flowClient.startProcessInstanceById(leave.getProcessDefinitionId(), FlowUtil.getBusinessKey(businessTable, String.valueOf(leave.getId())), variables);

Loading…
Cancel
Save