流程:发起流程,回调接口
This commit is contained in:
6
pom.xml
6
pom.xml
@ -122,6 +122,12 @@
|
|||||||
<artifactId>spring-boot-starter-mail</artifactId>
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle</groupId>
|
||||||
|
<artifactId>bcprov-jdk15to18</artifactId>
|
||||||
|
<version>1.71</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.workflow.client;
|
||||||
|
|
||||||
|
import com.chinaunicom.mall.ebtp.common.workflow.entity.*;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
|
||||||
|
@FeignClient(name = "workflow-service", url = "${spring.workflow.url}")
|
||||||
|
public interface WorkFlowClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取token接口
|
||||||
|
*/
|
||||||
|
@PostMapping("/lcdp/sso/token/lcdp/common/login/loginBySecureInfo")
|
||||||
|
WorkflowBaseResponse<WorkflowTokenResponse> getToken(WorkflowTokenRequest workflowToken);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程发起
|
||||||
|
* @param createWorkflow
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/lcdp/manager/workflow/v2/runtime/process-instances")
|
||||||
|
WorkflowBaseResponse<WorkflowCreateResponse> createWorkflow(
|
||||||
|
@RequestHeader("Cookie") String token,
|
||||||
|
@RequestBody WorkflowCreateRequest createWorkflow
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.workflow.controller;
|
||||||
|
|
||||||
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||||
|
import com.chinaunicom.mall.ebtp.common.workflow.entity.WorkflowCreateResponse;
|
||||||
|
import com.chinaunicom.mall.ebtp.common.workflow.entity.WorkflowBaseResponse;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.workflow.service.WorkflowService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@Api(tags = "流程中心接口")
|
||||||
|
@RequestMapping("/workflow")
|
||||||
|
public class WorkFlowController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private WorkflowService workflowService;
|
||||||
|
|
||||||
|
@GetMapping("/create")
|
||||||
|
public BaseResponse<WorkflowCreateResponse> create(
|
||||||
|
@RequestParam String userEmail,
|
||||||
|
@RequestParam String userName,
|
||||||
|
@RequestParam String userOrgId,
|
||||||
|
@RequestParam String modelId,
|
||||||
|
@RequestParam String businessKey,
|
||||||
|
@RequestParam String url
|
||||||
|
) throws Exception {
|
||||||
|
WorkflowBaseResponse<WorkflowCreateResponse> workflow = workflowService.createWorkflow(userEmail, userName, userOrgId, modelId, businessKey, url);
|
||||||
|
if ("0".equals(workflow.getResultCode())) {
|
||||||
|
return BaseResponse.success(workflow.getResultMsg(), workflow.getResultObject());
|
||||||
|
} else {
|
||||||
|
return BaseResponse.fail(workflow.getResultMsg(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程中心回调接口
|
||||||
|
| busiDataId | string | 是 | 业务数据ID(表单数据) |
|
||||||
|
| businessKey | string | 是 | 同上 |
|
||||||
|
| processInstanceId | string | 是 | 流程实例id |
|
||||||
|
| status | string | 是 | 当前流程实例状态 |
|
||||||
|
回调接口多线程调用需要的业务处理接口,各自业务处理接口需要根据流程实例ID查询是否有对应的业务数据 (类似消息总线模式)
|
||||||
|
*/
|
||||||
|
@GetMapping("/callback")
|
||||||
|
public BaseResponse<String> callback(
|
||||||
|
@RequestParam("busiDataId") String busiDataId,
|
||||||
|
@RequestParam("businessKey") String businessKey,
|
||||||
|
@RequestParam("processInstanceId") String processInstanceId,
|
||||||
|
@RequestParam("status") String status
|
||||||
|
) {
|
||||||
|
log.info("Workflow callback received: busiDataId={}, businessKey={}, processInstanceId={}, status={}",
|
||||||
|
busiDataId, businessKey, processInstanceId, status);
|
||||||
|
return BaseResponse.success();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.workflow.service;
|
||||||
|
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.workflow.client.AESUtils;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.workflow.client.WorkFlowClient;
|
||||||
|
import com.chinaunicom.mall.ebtp.common.workflow.entity.*;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class WorkflowService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private WorkFlowClient workFlowClient;
|
||||||
|
|
||||||
|
@Value("${spring.workflow.client_id:zhongyuan-haiyun}")
|
||||||
|
private String clientId;
|
||||||
|
@Value("${spring.workflow.secret_key:7t8qC8XYRh3AANfhP9Pqjeu5AHZRv19G}")
|
||||||
|
private String secretKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试的默认值等待流程中心对接完用户信息后才可使用真实数据
|
||||||
|
*/
|
||||||
|
private String getToken(String userEmail, String userName, String userOrgId) throws Exception {
|
||||||
|
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
WorkflowUser userVO = WorkflowUser.builder()
|
||||||
|
// 测试用,如果是空的则使用默认值
|
||||||
|
.userMail("dingx23@chinaunicom.cn")
|
||||||
|
// .userMail(userEmail)
|
||||||
|
// 测试用,如果是空的则使用默认值
|
||||||
|
.loginName("dingx23").build();
|
||||||
|
// .loginName(userName).build();
|
||||||
|
WorkflowExchange tokenReq = WorkflowExchange.builder()
|
||||||
|
.dateTime(sf.format(new Date()))
|
||||||
|
// 测试用,如果是空的则使用默认值
|
||||||
|
.userOrgId("ce7d12dd8bcd416aafe3bea5a4e96edd")
|
||||||
|
// .userOrgId(userOrgId)
|
||||||
|
.createUserWhenNotExist(false)
|
||||||
|
.userVo(userVO).build();
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String tokenJson = objectMapper.writeValueAsString(tokenReq);
|
||||||
|
String exchangeRequest = AESUtils.encryptAES(tokenJson, secretKey);
|
||||||
|
WorkflowTokenRequest workflowTokenRequest = new WorkflowTokenRequest();
|
||||||
|
workflowTokenRequest.setClientId(clientId);
|
||||||
|
workflowTokenRequest.setExchangeRequest(exchangeRequest);
|
||||||
|
WorkflowBaseResponse<WorkflowTokenResponse> tokenResponse = workFlowClient.getToken(workflowTokenRequest);
|
||||||
|
if (tokenResponse == null || !"0".equals(tokenResponse.getResultCode())) {
|
||||||
|
throw new RuntimeException("获取token失败");
|
||||||
|
}
|
||||||
|
String token = "lcdpAccessToken=" + tokenResponse.getResultObject().getToken();
|
||||||
|
log.info("获取token成功: {}", token);
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发起流程
|
||||||
|
* <p>
|
||||||
|
* {
|
||||||
|
* "modelId": "1953018896810274817",
|
||||||
|
* "businessKey":"10002",
|
||||||
|
* "variables": [{
|
||||||
|
* "name":"internal_app_env_key",
|
||||||
|
* "value":"env_test"
|
||||||
|
* },{
|
||||||
|
* "name":"url",
|
||||||
|
* "value":"http://10.0.0.125:3000/index"
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
* }
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public WorkflowBaseResponse<WorkflowCreateResponse> createWorkflow(String userEmail, String userName, String userOrgId, String modelId, String businessKey, String url) throws Exception {
|
||||||
|
String token = this.getToken(userEmail, userName, userOrgId);
|
||||||
|
String modelIdValue = modelId != null ? modelId : "1953018896810274817";
|
||||||
|
String businessKeyValue = businessKey != null ? businessKey : "10002";
|
||||||
|
WorkflowVariable var1 = WorkflowVariable.builder().name("internal_app_env_key").value("env_test").build();
|
||||||
|
WorkflowVariable var2 = WorkflowVariable.builder()
|
||||||
|
.name("url")
|
||||||
|
.value(url).build();
|
||||||
|
WorkflowCreateRequest createWorkflow = WorkflowCreateRequest.builder()
|
||||||
|
.modelId(modelIdValue)
|
||||||
|
.businessKey(businessKeyValue)
|
||||||
|
.variables(new WorkflowVariable[]{var1, var2})
|
||||||
|
.build();
|
||||||
|
WorkflowBaseResponse<WorkflowCreateResponse> response = workFlowClient.createWorkflow(token, createWorkflow);
|
||||||
|
log.info("发起流程响应: {}", response);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -139,6 +139,12 @@ spring:
|
|||||||
accountSid: 8aaf070857f4daef0157fe76a1220724
|
accountSid: 8aaf070857f4daef0157fe76a1220724
|
||||||
authToken: fb5198e122fc4d1e9344525e5288029d
|
authToken: fb5198e122fc4d1e9344525e5288029d
|
||||||
appId: 8aaf070857f4daef0157fe76a316072b
|
appId: 8aaf070857f4daef0157fe76a316072b
|
||||||
|
# 流程中心
|
||||||
|
workflow:
|
||||||
|
url: http://59.110.10.99:59999/
|
||||||
|
secret_key: 7t8qC8XYRh3AANfhP9Pqjeu5AHZRv19G
|
||||||
|
client_id: zhongyuan-haiyun
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
@ -224,3 +230,15 @@ management:
|
|||||||
cors:
|
cors:
|
||||||
allowed-origins: "*"
|
allowed-origins: "*"
|
||||||
allowed-methods: "*"
|
allowed-methods: "*"
|
||||||
|
|
||||||
|
check:
|
||||||
|
porject:
|
||||||
|
name-value: 33333
|
||||||
|
num-value: 33333
|
||||||
|
length: 2000
|
||||||
|
checkBoolen: false
|
||||||
|
tokentime:
|
||||||
|
timeLimit: 5000
|
||||||
|
onof: 0
|
||||||
|
checkprivateKey : MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAk7N3OeQS9WJa/v5dX/s9/DCKpJ8kOjR1Zrh1X+TF98udqGbGBWmiyVk2SqGPA4Q9kUCWw46CocjE047gx5AFrQIDAQABAkAIHG/stvCvlxImNLPOBI8X3VaPycmEhML5vCF9/aM9g1SuFa298Q5W8FqAmm8SE5lRpw2yyToWtLbufJtAa7wFAiEAxViJBkLU4wfPCwiPiAn17owXbocC9rj3fAzEH9DYDdcCIQC/mZp4ujO035Qqw2QQeFWpDc/vITx1OTWaxq6/LvvwGwIgXTZLSmzItw9aKOD7QotJ4UnES41zxetp4er5u/leA3MCIGcRw2ZEjII1b+hdOdweT75kfsId9/77apm7Xc/c/4yXAiEAnBrCiVXRNN+slO0MYaxynr4eIiPG/EjYBYxXlwBpeOc=
|
||||||
|
checkpublicKey: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJOzdznkEvViWv7+XV/7PfwwiqSfJDo0dWa4dV/kxffLnahmxgVposlZNkqhjwOEPZFAlsOOgqHIxNOO4MeQBa0CAwEAAQ==
|
||||||
|
Reference in New Issue
Block a user