From 3a3119796eaa88900c39afc03a9bf1b66d3a8a80 Mon Sep 17 00:00:00 2001 From: efren <79289982@qq.com> Date: Thu, 7 Aug 2025 10:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E7=A8=8B=EF=BC=9A=E5=8F=91=E8=B5=B7?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=EF=BC=8C=E5=9B=9E=E8=B0=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 ++ .../workflow/client/WorkFlowClient.java | 30 ++++++ .../controller/WorkFlowController.java | 59 ++++++++++++ .../workflow/service/WorkflowService.java | 96 +++++++++++++++++++ src/main/resources/application-dev.yml | 18 ++++ 5 files changed, 209 insertions(+) create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/client/WorkFlowClient.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/controller/WorkFlowController.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/service/WorkflowService.java diff --git a/pom.xml b/pom.xml index 12ad2e2..c849d80 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,12 @@ spring-boot-starter-mail + + org.bouncycastle + bcprov-jdk15to18 + 1.71 + + diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/client/WorkFlowClient.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/client/WorkFlowClient.java new file mode 100644 index 0000000..b772765 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/client/WorkFlowClient.java @@ -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 getToken(WorkflowTokenRequest workflowToken); + + /** + * 流程发起 + * @param createWorkflow + * @param token + * @return + */ + @PostMapping("/lcdp/manager/workflow/v2/runtime/process-instances") + WorkflowBaseResponse createWorkflow( + @RequestHeader("Cookie") String token, + @RequestBody WorkflowCreateRequest createWorkflow + ); + +} \ No newline at end of file diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/controller/WorkFlowController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/controller/WorkFlowController.java new file mode 100644 index 0000000..ae0826a --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/controller/WorkFlowController.java @@ -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 create( + @RequestParam String userEmail, + @RequestParam String userName, + @RequestParam String userOrgId, + @RequestParam String modelId, + @RequestParam String businessKey, + @RequestParam String url + ) throws Exception { + WorkflowBaseResponse 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 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(); + } +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/service/WorkflowService.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/service/WorkflowService.java new file mode 100644 index 0000000..cffa99a --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/workflow/service/WorkflowService.java @@ -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 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; + } + + /** + * 发起流程 + *

+ * { + * "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 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 response = workFlowClient.createWorkflow(token, createWorkflow); + log.info("发起流程响应: {}", response); + return response; + } + +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index b616a12..34b91ae 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -139,6 +139,12 @@ spring: accountSid: 8aaf070857f4daef0157fe76a1220724 authToken: fb5198e122fc4d1e9344525e5288029d appId: 8aaf070857f4daef0157fe76a316072b + # 流程中心 + workflow: + url: http://59.110.10.99:59999/ + secret_key: 7t8qC8XYRh3AANfhP9Pqjeu5AHZRv19G + client_id: zhongyuan-haiyun + mybatis-plus: @@ -224,3 +230,15 @@ management: cors: allowed-origins: "*" 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==