跨系统调用Controller

简介: 跨系统调用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


目录
相关文章
|
Rust JavaScript Unix
Nodejs 常见版本管理工具(nvm、n、fnm、nvs、nodenv)
Nodejs 常见版本管理工具(nvm、n、fnm、nvs、nodenv)
15163 0
|
9月前
|
人工智能 JavaScript Linux
OpenClaw阿里云/本地部署保姆级图文指南:免费大模型APi配置+核心命令详解+高效使用技巧
OpenClaw作为轻量化AI智能体框架,除自然语言交互外,命令行操作可大幅提升会话管理、模型切换、服务监控效率,以下10组高频命令覆盖日常使用全场景,配合飞书等IM工具可实现无感高效协作。
2650 1
|
人工智能 移动开发 JavaScript
如何用uniapp打包桌面客户端exe包,vue或者uni项目如何打包桌面客户端之electron开发-优雅草央千澈以开源蜻蜓AI工具为例子演示完整教程-开源代码附上
如何用uniapp打包桌面客户端exe包,vue或者uni项目如何打包桌面客户端之electron开发-优雅草央千澈以开源蜻蜓AI工具为例子演示完整教程-开源代码附上
2318 18
|
存储 数据采集 NoSQL
数据为什么要分层?一文带你全面了解数仓分层
数据分层旨在实现数据的有序与可控,通过ODS(贴源)、DWD(明细)、DIM(维表)、DWS(服务)、DWT(主题)、ADS(应用)六层架构,逐级清洗、整合、聚合,提升质量、复用性与可追溯性,支撑高效、可信的数据分析。
|
存储 数据管理 关系型数据库
YashanDB多模数据融合管理技术探索与实践
本文基于李伟超在“2024年国产数据库创新生态大会”的演讲,介绍了YashanDB如何通过创新架构设计应对AI+时代的多模态数据融合管理挑战。YashanDB采用存算分离架构、联邦查询等技术,实现了对空间、BIM、图、向量等多种类型数据的高效统一管理,支持智慧城市和大模型训练等应用场景。未来,YashanDB将继续优化多模数据管理策略,推动数据价值的最大化释放。
|
12月前
|
人工智能 自然语言处理 监控
盘点 2025 电商自动化利器:Agent 产品实力排行,降本增效不空谈
电商进入存量竞争时代,获客难、运营重、跨境壁垒高。智能Agent成破局关键,尤以融合大模型与自动化的“数字员工”为代表。实在Agent凭RPA进化基因与“一句话生成流程”能力,实现跨系统协同、全场景覆盖;瓴羊Quick Service擅全渠道客服,扛大促峰值;探迹·探域智能体轻量零配置,中小商家首选。选型需按规模、场景匹配,聚焦易用性、兼容性与数据安全,让AI真正赋能增长。
1701 8
|
监控 Cloud Native 调度
《云原生架构从崩溃失控到稳定自愈的实践方案》
本文以某大型电商供应链系统“618”大促期间的“服务雪崩”故障为切入点,剖析了云原生架构在极端流量下的稳定性短板。故障根源在于库存调度服务接口设计缺陷导致数据库连接池耗尽,且服务间缺乏熔断隔离机制,引发全链路瘫痪。技术团队通过重构核心接口、引入“熔断-隔离-降级”防护体系、搭建三位一体监控闭环、设计全流程流量管控方案,并开展常态化故障注入演练,实现架构从“事后救火”到“事前防御”的转变。改造后系统故障恢复时间大幅缩短,核心业务零中断,同时沉淀出云原生架构抗风险建设的实战方法论。
495 5
|
前端开发 JavaScript Android开发
做Docx预览,一定要做这个神库!!
本文来自【沉浸式趣谈】,个人博客 *https://yaolifeng.com* 同步更新。分享 `docx-preview` 和 `mammoth` 两大流行 Word 文档预览库的使用与对比。`docx-preview` 还原度极高,适合高保真文档预览;`mammoth` 转换为简洁语义化 HTML,适用于内容提取场景。两者轻量高效,无需依赖外部服务。根据需求选择工具,提升开发效率!
2479 4
|
Shell Linux iOS开发
macOS 命令行工具
Mac新手学习编程必掌握的常用Shell命令,涵盖目录导航(cd、pwd、ls)、文件操作(mkdir、cp、mv、rm)及文本处理(cat)等基础指令,提升效率,助力开发。
925 0