# algorithm_scheduling

algorithm_code: 1
algorithm_name: 接收ibmq数据
service_code: 1001
class_name: com.bfkj.unidia.IOUtils.IBMMQHelper
method_name: receiveMessage
description: 接收ibmq
input_data_template:
{
  "mqConfig": {
    "host": "192.168.52.130",
		"userId":"mquser",
		"password":"mquser",
    "port": 13133,
    "channel": "server_channel",
    "queueManager": "mmq_kafka_manager",
    "sendQueueName": "recv",
    "ccsid": 819,
    "receiveTimeout": 300
  },
  "queueName": "recv",
  "maxMessages": 100
}


algorithm_code: 2
algorithm_name: 发送原始报文给Kafka
service_code: 1001
class_name: com.bfkj.unidia.IOUtils.KafkaHelper
method_name: send
description: 将原始报文发送给kafka
input_data_template:
{
  "kafkaConfig": {
    "bootstrap.servers": "localhost:9092"
  },
  "topic": "raw_message_input",
  "data": "@1.returnData"
}


algorithm_code: 3
algorithm_name: Kafka消费数据
service_code: 1002
class_name: com.bfkj.unidia.IOUtils.KafkaHelper
method_name: consume
description: 从Kafka消费数据
input_data_template:
{
  "kafkaConfig": {
    "bootstrap.servers": "localhost:9092"
  },
  "topic": "raw_message_input",
  "groupId": "%algorithm_code",
  "maxRecords": 100
}


algorithm_code: 4
algorithm_name: 解析数据
service_code: 1002
input_data_template: {"data":"@3.returnData"}
description: 解析Kafka消费数据
method_name:
function xmlToJson(xmlString) {
        // 1. 解析 XML 字符串
        const parser = new DOMParser();
        const xmlDoc = parser.parseFromString(xmlString, "text/xml");

        // 2. 递归转换 XML 节点为 JSON
        function parseNode(node) {
            const obj = {};

            // 处理节点属性
            if (node.attributes && node.attributes.length > 0) {
                obj["@attributes"] = {};
                for (let i = 0; i < node.attributes.length; i++) {
                    const attr = node.attributes[i];
                    obj["@attributes"][attr.name] = attr.value;
                }
            }

            // 处理子节点
            if (node.childNodes.length > 0) {
                for (let i = 0; i < node.childNodes.length; i++) {
                    const child = node.childNodes[i];

                    // 跳过空文本节点
                    if (child.nodeType === 3 && child.nodeValue.trim() === "") {
                        continue;
                    }

                    // 处理文本内容（叶子节点）
                    if (child.nodeType === 3) {
                        return child.nodeValue.trim();
                    }

                    // 处理元素节点
                    if (child.nodeType === 1) {
                        const nodeName = child.nodeName;
                        const parsedChild = parseNode(child);

                        // 如果节点已存在，转换为数组
                        if (obj[nodeName]) {
                            if (!Array.isArray(obj[nodeName])) {
                                obj[nodeName] = [obj[nodeName]];
                            }
                            obj[nodeName].push(parsedChild);
                        } else {
                            obj[nodeName] = parsedChild;
                        }
                    }
                }
            }

            return Object.keys(obj).length === 0 ? "" : obj;
        }
        let stringify = JSON.stringify(parseNode(xmlDoc.documentElement));
        console.log(stringify);
        // 3. 从根节点开始转换
        return  parseNode(xmlDoc.documentElement);
    }


