跨系统调用Controller

本文涉及的产品
应用实时监控服务-应用监控,每月50GB免费额度
可观测监控 Prometheus 版,每月50GB免费额度
性能测试 PTS,5000VUM额度
简介: 跨系统调用Controller

 请求端方法:

Controller:

@Override
    public ResultData saveData(long userId, TemplateManage templateManage) {
        //改变状态入湖中
        cloudFlowUtil.updateLakeStatusIng(templateManage.getFormId());
        ltCloudUtil.updateLakeStatusIng(templateManage.getDataSourceId());
        TemplateManage templateManageNew = new TemplateManage();
        templateManageNew.setId(SnowflakeIdGenerator.getId());
        templateManageNew.setName(templateManage.getName());
        templateManageNew.setDesign(templateManage.getDesign());
        templateManageNew.setParentId(templateManage.getParentId());
        templateManageNew.setParentCode(templateManage.getParentCode());
        templateManageNew.setGroupId(templateManage.getGroupId());
        templateManageNew.setDataSourceId(templateManage.getDataSourceId());
        templateManageNew.setDataSourceType(templateManage.getDataSourceType());
        templateManageNew.setCreateUserName(templateManage.getCreateUserName());
        templateManageNew.setFormId(templateManage.getFormId());
        templateManageNew.setIsDeleted("0");
        templateManageNew.setSpStatus("1");
        templateManageNew.setLakeType(templateManage.getLakeType());
        templateManageNew.setCreateTime(LocalDateTime.now());
        templateManageNew.setCreateUserId(userId);
        List<DfsFormAppro> dfsFormApproList = dfsFormApproMapper.selectList(null);
        Boolean flag = false;
        //1.找到DfsFormAppro里有没有表单id templateManage.getFormId()
        DfsTaskAppro listByFormId = dfsTaskApproService.getListByFormId(templateManage.getFormId());
        //2.如果有就再次提交
        if (listByFormId != null){
            cloudFlowUtil.reExecute(listByFormId.getTaskCloudFlowOrderId());
        }else {
            //3.如果没有就初次提交
            DfsFormAppro dfsFormAppro = new DfsFormAppro();
            // 首次提交
            dfsFormAppro.setId(SnowflakeIdGenerator.getId());
            dfsFormAppro.setTaskFormId(templateManage.getFormId());
            String orderId = "";
            JSONObject appro = new JSONObject();
            if (templateManage.getLakeType().equalsIgnoreCase("1")) {
                // 直报提交到审批流
                appro = cloudFlowUtil.startAndExecute("35aef0a551384210a7b2be4df7008269");
            } else if (templateManage.getLakeType().equalsIgnoreCase("2")) {
                // 爬虫提交到审批流
                appro = cloudFlowUtil.startAndExecute("39fe7a406bff4f1a8afb94a68754172d");
            } else if (templateManage.getLakeType().equalsIgnoreCase("3")) {
                // 同步提交到审批流
                appro = cloudFlowUtil.startAndExecute("ca1f66846f9b4697992418cd2072f102");
            } else if (templateManage.getLakeType().equalsIgnoreCase("4")) {
                // 集成提交到审批流
                appro = cloudFlowUtil.startAndExecute("91a789b3f6864c09a9d4350e50ee25a8");
            } else if (templateManage.getLakeType().equalsIgnoreCase("5")) {
                // 提交到审批流
                appro = cloudFlowUtil.startAndExecute("4083c7761cf24a60a2199657950d3576");
            }
            if (appro.getInteger("code") == 20000) {
                JSONObject taskOrder = JSONObject.parseObject(appro.getString("data"));
                orderId = taskOrder.getString("id");
                dfsFormAppro.setTaskCloudFlowOrderId(orderId);
            }
            dfsFormAppro.setTemplateManageId(templateManageNew.getId());
            dfsFormAppro.setCreateTime(LocalDateTime.now());
            dfsFormAppro.setCreateUser(userId);
            // 向数据库中保存数据
            formApproService.save(dfsFormAppro);
        }
        templateManageMapper.insert(templateManageNew);
        return ResultData.success("ok");
    }

image.gif

调用的CloudFlowUtil:

package com.todod.utils;
import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSONObject;
import com.todod.dto.FormFillFieldReq;
import com.todod.entity.QueryEntry;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
@Component
public class CloudFlowUtil {
    @Value("${remote.cloud.flow.url}")
    private String BASE_CLOW_FLOW_URL;
    @Autowired
    private RestTemplate restTemplate;
    @Value("${remote.fill.in.url}")
    private String BASE_FILL_IN_URL;
    
    /**
     * @Title: getUserList
     * @Description: 获取流程列表,用来针对不同的云平台的用户显示
     * @author: wgb
     * @date 2023-07-26
     * @return JSONObject
     **/
    public JSONObject getFlowList(){
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue());
        ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "flow/getProcessList", headers, String.class);
        JSONObject reData = JSONObject.parseObject(postForEntity.getBody());
        return reData;
    }
    
    /**
     * @Title: startAndExecute
     * @Description: 执行"执行任务接口"(传入审核流id)
     * @param: processId 任务绑定审核流id
     * @author: wgb
     * @date 2023-07-26
     * @return JSONObject
     **/
    public JSONObject startAndExecute(String processId){
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue());
        
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("processId", processId);
        map.put("processName", null);
        map.put("args", null);
        
        ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "/flow/startAndExecute", new HttpEntity<>(map, headers), String.class);
        JSONObject reData = JSONObject.parseObject(postForEntity.getBody());
        return reData;
    }
    /**
     * @Title: reExecute
     * @Description: 驳回或撤回后再次提交
     * @param: orderId 审核流实例id
     * @author: wgb
     * @date 2023-07-26
     * @return JSONObject
     **/
    public JSONObject reExecute(String orderId) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue());
        Map<String, Object> map = new HashMap<String, Object>();
        ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "/flow/task/reExecute?orderId="+orderId,
                new HttpEntity<>(map, headers), String.class);
        JSONObject reData = JSONObject.parseObject(postForEntity.getBody());
        return reData;
    }
    /**
     * @Title: getTodoList
     * @Description: 获取待审批列表
     * @param query
     * @return
     */
  public JSONObject getTodoList(QueryEntry query) {
    HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue());
        
        ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "/flow/task/todoList", new HttpEntity<>(query, headers), String.class);
        JSONObject reData = JSONObject.parseObject(postForEntity.getBody());
        return reData;
  }
  /**
   * @Title: getDoneList
     * @Description: 获取已完成列表
   * @param query
   * @return
   */
  public JSONObject getDoneList(QueryEntry query) {
    HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue());
        
        ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "/flow/task/doneList", new HttpEntity<>(query, headers), String.class);
        JSONObject reData = JSONObject.parseObject(postForEntity.getBody());
        return reData;
  }
  
  /**
     * @Title: getUserList
     * @Description: 获取获取审批完成后列表
     * @param: orderIds 审批实例id列表字符串
     * @author: wgb
     * @date 2023-07-26
     * @return JSONObject
     **/
    public JSONObject getOrdercompletionList(String orderIds){
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
//        headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue());
        ResponseEntity<String> postForEntity = restTemplate.postForEntity(BASE_CLOW_FLOW_URL + "/ordercompletion/getOrderByIds?orderIds=" + orderIds, headers, String.class);
        JSONObject reData = JSONObject.parseObject(postForEntity.getBody());
        return reData;
    }
    public JSONObject updateLakeStatus(Long formId) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue());
        ResponseEntity<String> postForEntity = restTemplate.postForEntity(
                BASE_FILL_IN_URL + "ltcloud/form/updateLakeStatus?id=" + formId, headers, String.class);
        JSONObject reData = JSONObject.parseObject(postForEntity.getBody());
        return reData;
    }
    //入湖驳回
    public JSONObject updateLakeStatusBack(Long formId) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue());
        ResponseEntity<String> postForEntity = restTemplate.postForEntity(
                BASE_FILL_IN_URL + "ltcloud/form/updateLakeStatusBack?id=" + formId, headers, String.class);
        JSONObject reData = JSONObject.parseObject(postForEntity.getBody());
        return reData;
    }
    //入湖中
    public JSONObject updateLakeStatusIng(Long formId) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add(StpUtil.getTokenName(), StpUtil.getTokenValue());
        ResponseEntity<String> postForEntity = restTemplate.postForEntity(
                BASE_FILL_IN_URL + "ltcloud/form/updateLakeStatusIng?id=" + formId, headers, String.class);
        JSONObject reData = JSONObject.parseObject(postForEntity.getBody());
        return reData;
    }
}

image.gif

在yaml文件中配置好对应的路径即可:remote.cloud.flow.url = http://localhost:8083/cloud_flow/

被调用方Controller:

/**
   * @title startAndExecute
     * @description 启动并执行第一个任务节点
     * @param param
     * @param userId 当前用户id
     * @return
     */
  public Order startAndExecute(WfOrderParam param, Long userId) {
//    Process process = this.getProcessByProcessId(param.getProcessId());
    
    param.setArgs(param.getArgs()!=null?param.getArgs():new HashMap<String,Object>());
    param.getArgs().put("reason", "提交");
    
//        param.getArgs().put(TododConstants.INSTANCE_URL, process.getInstanceUrl());
//        // 设置业务ID
//        param.getArgs().put(SnakerEngine.ID, UUID.randomUUID().toString().replaceAll("-",""));
//        // 创建流程实例用户名
//        param.getArgs().put(TododConstants.ORDER_USER_NAME_KEY, "");
//        // 创建流程实例姓名
//        param.getArgs().put(TododConstants.ORDER_USER_REAL_NAME_KEY, "");
        Order order = snakerEngineFacets.startInstanceById(param.getProcessId(), userId.toString(), param.getArgs());
        
        // 获取流程实例的所有任务
        List<Task> tasks = snakerEngineFacets.getEngine().query().getActiveTasks(new QueryFilter().setOrderId(order.getId()));
        List<Task> newTasks = new ArrayList<Task>();
        if (tasks != null && tasks.size() > 0) {
            Task task = tasks.get(0);
            
         // 保存审批记录
          ApproRecords records = new ApproRecords();
          records.setId(task.getId());
          records.setOrderId(order.getId());
          records.setPerformType("0");
          records.setOperator(userId.toString());
          records.setRemark("提交");
          records.setFinishTime(LocalDateTime.now());
          recordsService.save(records);
          
            newTasks.addAll(snakerEngineFacets.getEngine().executeTask(task.getId(), userId.toString(), param.getArgs()));
        }
        return order;
  }

image.gif


目录
相关文章
|
8月前
|
设计模式 算法 测试技术
C++ 创建兼容多个IPC机制的上层接口
C++ 创建兼容多个IPC机制的上层接口
146 1
|
8月前
|
消息中间件 Unix Linux
Linux进程间通信(IPC)介绍:详细解析IPC的执行流程、状态和通信机制
Linux进程间通信(IPC)介绍:详细解析IPC的执行流程、状态和通信机制
414 1
|
前端开发 Java 微服务
微服务之间调用的异常应该如何处理
在分布式服务的场景下,业务服务都将进行拆分,不同服务之间都会相互调用,如何做好异常处理是比较关键的,可以让业务人员在页面使用系统报错后,很清楚的看到服务报错的原因,而不是返回代码级别的异常报错,比如NullException、IllegalArgumentException、FeignExecption等异常报错,这样就会让非技术人员看到了一头雾水,从而很降低用户的体验感。
|
存储 Java Linux
【Linux】基础IO --- 系统级文件接口、文件描述符表、文件控制块、fd分配规则、重定向…
【Linux】基础IO --- 系统级文件接口、文件描述符表、文件控制块、fd分配规则、重定向…
|
数据库
操作系统第五章_01 IO设备的基本概念和分类 IO控制器 IO控制方式
操作系统第五章_01 IO设备的基本概念和分类 IO控制器 IO控制方式
480 0
操作系统第五章_01 IO设备的基本概念和分类 IO控制器 IO控制方式
|
JSON API 数据格式
BentoML核心概念(二):API 和 IO 描述符
APIs 是在服务定义中定义的函数,它们作为 HTTP 或 gRPC 端点暴露出去。 如果一个函数用 @svc.api 装饰器装饰,它就是 APIs 的一部分。 APIs 可以定义为 Python 中的同步函数或异步协程。 APIs 通过调用服务定义中创建的函数和模型运行器(runners)中的预处理和后处理逻辑来满足请求。
|
网络协议 Dubbo 应用服务中间件
基于内存通信的gRPC调用
通过内存调用gRPC服务
基于内存通信的gRPC调用
【Binder 机制】AIDL 分析 ( 创建 Service 服务 | 绑定 Service 远程服务 )
【Binder 机制】AIDL 分析 ( 创建 Service 服务 | 绑定 Service 远程服务 )
188 0
|
存储 虚拟化 内存技术