Skip to content
本页内容

修改流程发送时收件人员

应用场景

在流程传递至下一环节时,接收人员会面临一些条件限制,这些条件下需要对接收人员的数据进行必要的处理,比如过滤掉不符合要求的人员信息,人员昵称的特殊显示等。

扩展接口实现

java
package com.kanq;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.kanq.sdk.config.Macro;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class FlowDemo {

	/**
     * 流程发送查询接收人后置处理
     * @param macroHead
     * @param argv
     * @return
     * @throws JsonProcessingException
     */
    @Macro(name = "FlowSend:DESTROY", describe = "流程发送查询接收人后置处理")
    public static byte[] flowSend_Destroy(byte[] macroHead, byte[][] argv) throws JsonProcessingException {

        //获取parm
        byte[] parm_byte = argv[1];
        String parm = new String(parm_byte,StandardCharsets.UTF_8);

        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode rootNode = null;
        try {
            // 读取 JSON 文件
            rootNode = objectMapper.readTree(parm);
            // 确保根节点是一个对象
            if (rootNode.isObject()) {
                // 获取 "tach" 字段,确保它是一个数组
                JsonNode tachNode = rootNode.path("tach");
                if (tachNode.isArray()) {
                    ArrayNode tachArray = (ArrayNode) tachNode;
                    // 遍历数组中的每个对象
                    for (JsonNode item : tachArray) {
                        // 检查是否是目标对象
                        if (item.isObject()) {
                            // 获取 "children" 字段,确保它是一个数组
                            JsonNode childrenNode = item.path("children");
                            if (childrenNode.isArray()) {
                                ArrayNode childrenArray = (ArrayNode) childrenNode;
                                // 遍历 children 数组中的每个对象
                                for (JsonNode child : childrenArray) {
                                    // 检查是否是目标对象
                                    if (child.isObject()) {
                                        // 获取 "children" 字段,确保它是一个数组
                                        JsonNode innerChildrenNode = child.path("children");
                                        if (innerChildrenNode.isArray()) {
                                            ArrayNode innerChildrenArray = (ArrayNode) innerChildrenNode;
                                            // 遍历 innerChildren 数组中的每个对象
                                            for (JsonNode innerChild : innerChildrenArray) {
                                                // 替换指定 text 值
                                                if (innerChild.isObject()
                                                        && innerChild.has("text")
                                                        && innerChild.get("text").asText().equals("测试人")) {
                                                    ((ObjectNode) innerChild).put("text", "张晓明");
                                                    break; // 替换完成后退出循环
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return objectMapper.writeValueAsBytes(rootNode);
    }
}

package com.kanq;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.kanq.sdk.config.Macro;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class FlowDemo {

	/**
     * 流程发送查询接收人后置处理
     * @param macroHead
     * @param argv
     * @return
     * @throws JsonProcessingException
     */
    @Macro(name = "FlowSend:DESTROY", describe = "流程发送查询接收人后置处理")
    public static byte[] flowSend_Destroy(byte[] macroHead, byte[][] argv) throws JsonProcessingException {

        //获取parm
        byte[] parm_byte = argv[1];
        String parm = new String(parm_byte,StandardCharsets.UTF_8);

        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode rootNode = null;
        try {
            // 读取 JSON 文件
            rootNode = objectMapper.readTree(parm);
            // 确保根节点是一个对象
            if (rootNode.isObject()) {
                // 获取 "tach" 字段,确保它是一个数组
                JsonNode tachNode = rootNode.path("tach");
                if (tachNode.isArray()) {
                    ArrayNode tachArray = (ArrayNode) tachNode;
                    // 遍历数组中的每个对象
                    for (JsonNode item : tachArray) {
                        // 检查是否是目标对象
                        if (item.isObject()) {
                            // 获取 "children" 字段,确保它是一个数组
                            JsonNode childrenNode = item.path("children");
                            if (childrenNode.isArray()) {
                                ArrayNode childrenArray = (ArrayNode) childrenNode;
                                // 遍历 children 数组中的每个对象
                                for (JsonNode child : childrenArray) {
                                    // 检查是否是目标对象
                                    if (child.isObject()) {
                                        // 获取 "children" 字段,确保它是一个数组
                                        JsonNode innerChildrenNode = child.path("children");
                                        if (innerChildrenNode.isArray()) {
                                            ArrayNode innerChildrenArray = (ArrayNode) innerChildrenNode;
                                            // 遍历 innerChildren 数组中的每个对象
                                            for (JsonNode innerChild : innerChildrenArray) {
                                                // 替换指定 text 值
                                                if (innerChild.isObject()
                                                        && innerChild.has("text")
                                                        && innerChild.get("text").asText().equals("测试人")) {
                                                    ((ObjectNode) innerChild).put("text", "张晓明");
                                                    break; // 替换完成后退出循环
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return objectMapper.writeValueAsBytes(rootNode);
    }
}

效果展示

二开前效果: scene-flowsend-destroy-receive-20240611182028

二开后效果: scene-flowsend-destroy-receive-20240611182205

Powerd by Vitepress.