package com.docus.server.message.result;

import com.alibaba.fastjson.JSONObject;
import com.docus.core.util.Func;
import com.docus.server.message.dto.Message;
import com.docus.server.message.enums.DataFormatEnum;
import com.docus.server.message.enums.ParametersEnum;
import com.docus.server.message.util.XmlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author wyb
 */
public class ResultUtil {
    private static final Logger logger = LoggerFactory.getLogger(ResultUtil.class);

    private final static Pattern JSON_PLACE_HOLDER_PATTERN = Pattern.compile("\\$\\{\\{json:([A-Za-z0-9._/@]+)}}");
    private final static Pattern XML_PLACE_HOLDER_PATTERN = Pattern.compile("\\$\\{\\{xpath:([A-Za-z0-9._/@]+)}}");
    private final static Pattern SYSTEM_PLACE_HOLDER_PATTERN = Pattern.compile("\\$\\{\\{system:([A-Za-z0-9._/@]+)}}");


    public static String dynamicParameterReplace(MessageInfo messageInfo, String result) {
        result = systemDynamicParameterReplace(result);
        result = requestDynamicParameterReplace(messageInfo, result);
        return result;
    }

    private static String requestDynamicParameterReplace(MessageInfo messageInfo, String result) {
        try {
            switch (messageInfo.getMessageFormat()) {
                case JSON:
                    return dynamicParameterReplaceFromJsonMessage(messageInfo.getMessage(), result);
                case XML:
                    return dynamicParameterReplaceFromXmlMessage(messageInfo.getMessage(), result);
                default:
                    throw new RuntimeException("未实现的message解析填充返回值！");
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            return result;
        }
    }

    private static String dynamicParameterReplaceFromXmlMessage(String message, String result) {
        XmlUtil xmlUtil = XmlUtil.of(message);
        List<PlaceHolder> xmlPlaceHolders = findAllXmlPlaceHolder(result);
        for (PlaceHolder placeHolder : xmlPlaceHolders) {
            Node node = xmlUtil.getNode(placeHolder.getPath());
            String newPlaceHolder = null;
            if (node != null) {
                newPlaceHolder = node.getNodeValue() == null ? node.getTextContent() : node.getNodeValue();
            }
            newPlaceHolder = newPlaceHolder == null ? "" : newPlaceHolder;
            result = result.replace(placeHolder.getPlaceHolder(), newPlaceHolder);
        }
        return result;
    }


    private static String dynamicParameterReplaceFromJsonMessage(String message, String result) {
        JSONObject jsonObject = Func.readJson(message, JSONObject.class);
        List<PlaceHolder> jsonPlaceHolderList = findAllJsonPlaceHolder(result);
        for (PlaceHolder placeHolder : jsonPlaceHolderList) {
            String newPlaceHolder = getVal(jsonObject, placeHolder.getPath());
            newPlaceHolder = newPlaceHolder == null ? "" : newPlaceHolder;
            result = result.replace(placeHolder.getPlaceHolder(), newPlaceHolder);
        }
        return result;
    }

    private static String getVal(JSONObject jsonObject, String path) {
        try {
            String[] split = path.split("\\.");
            return getVal(jsonObject, split);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            return null;
        }


    }

    private static String getVal(JSONObject jsonObject, String[] keys) {
        if (jsonObject == null || jsonObject.size() <= 0) {
            return null;
        }
        if (keys.length == 1) {
            return jsonObject.getString(keys[0]);
        }
        jsonObject = jsonObject.getJSONObject(keys[0]);
        keys = cutFirst(keys);
        return getVal(jsonObject, keys);
    }

    private static String[] cutFirst(String[] oldArrays) {
        int newLength = oldArrays.length - 1;
        String[] newArray = new String[newLength];
        System.arraycopy(oldArrays, 1, newArray, 0, newLength);
        return newArray;
    }

    private static List<PlaceHolder> findAllJsonPlaceHolder(String result) {
        Matcher matcher = JSON_PLACE_HOLDER_PATTERN.matcher(result);
        List<PlaceHolder> placeHolderList = new ArrayList<>();
        while (matcher.find()) {
            String placeholder = matcher.group(0);
            placeHolderList.add(new PlaceHolder(placeholder.replace("${{json:", "").replace("}}", ""), placeholder));
        }
        return placeHolderList;
    }

    private static List<PlaceHolder> findAllXmlPlaceHolder(String result) {
        Matcher matcher = XML_PLACE_HOLDER_PATTERN.matcher(result);
        List<PlaceHolder> placeHolderList = new ArrayList<>();
        while (matcher.find()) {
            String placeholder = matcher.group(0);
            placeHolderList.add(new PlaceHolder(placeholder.replace("${{xpath:", "").replace("}}", ""), placeholder));
        }
        return placeHolderList;
    }


    /**
     * 根据系统枚举的参数类型替换占位
     *
     * @param result 原result
     * @return 新的 result
     */
    private static String systemDynamicParameterReplace(String result) {
        try {
            ParametersEnum[] parameters = ParametersEnum.values();
            for (ParametersEnum parameter : parameters) {
                result = result.replace("${{system:" + parameter.getType() + "}}", parameter.getParam());
            }
            return result;
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            return result;
        }
    }

    public static void main(String[] args) {
        String message = "<PRPA_HIP1011 xmlns=\"urn:hl7-org:v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:v3=\"urn:hl7-org:v3\" ITSVersion=\"XML_1.0\" xsi:schemaLocation=\"urn:hl7-org:v3  file:///E:/hl7/HL7/v3ballot_fullsite_2011MAY/v3ballot/html/processable/multicacheschemas/PRPA _IN400002UV.xsd\"><id extension=\"9ECA98D5C065467A858CA8785BC66AF7\"/><creationTime value=\"20211229152637\"/><interactionId root=\"2.16.840.1.113883.1.6\" extension=\"PRPA_IN400002UV\"/><processingCode code=\"P\"/><processingModeCode/><acceptAckCode code=\"AL\"/><receiver typeCode=\"RCV\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id><item extension=\"Orion-001\"/></id></device></receiver><sender typeCode=\"SND\"><device classCode=\"DEV\" determinerCode=\"INSTANCE\"><id><item extension=\"LIS\"/></id></device></sender><controlActProcess classCode=\"STC\" moodCode=\"EVN\"><code code=\"OutPatientInfoUpdate\"><displayName value=\"检验报告新增\"/></code><subject typeCode=\"SUBJ\"><encounterEvent classCode=\"ENC\" moodCode=\"EVN\"><visitId>1</visitId><inpNo>0020453230001</inpNo><isValid>F</isValid><labReportName value=\"新冠病毒核酸检测(混检免费)▲\"/><labReportLid value=\"20211229G0506000\"/><id root=\"2.16.156.10011.1.33\" extension=\"20211229G0506000\"/><id root=\"2.16.156.10011.1.24\" extension=\"05331000193903\"/><id root=\"2.16.156.10011.1.14\" extension=\"05331000193903\"/><patientType><patienttypeCode code=\"1\" codeSystem=\"2.16.156.10011.2.3.1.271\" codeSystemName=\"患者类型代码表\" displayName=\"门诊\"/></patientType><subject typeCode=\"SBJ\"><patient classCode=\"PAT\"><id root=\"1.2.156.112635.1.2.1.2\" extension=\"4560886379\"/><id><item root=\"2.16.156.10011.0.2.2\" extension=\"002045323000\"/></id><patientPerson classCode=\"PSN\"><id><item extension=\"E96512808\" root=\"2.16.156.10011.1.3\"/><item extension=\"\" root=\"2.16.156.10011.1.15\"/></id><name xsi:type=\"DSET_EN\"><item><part value=\"李伟\"/></item></name><telecom xsi:type=\"BAG_TEL\"><item value=\"18664809919\"/></telecom><administrativeGenderCode code=\"2\" codeSystem=\"2.16.156.10011.2.3.3.4\"><displayName value=\"女\"/></administrativeGenderCode><birthTime value=\"\"><originalText value=\"38岁\"/></birthTime><addr xsi:type=\"BAG_AD\"><item use=\"H\"><part type=\"AL\" value=\"\"/></item></addr></patientPerson></patient></subject><author><time value=\"20211229152628\"/><assignedAuthor><id root=\"1.2.156.112635.1.1.2\" extension=\"3-376\"/><assignedPerson><name>赖永坤</name></assignedPerson></assignedAuthor></author><custodian><assignedCustodian><representedCustodianOrganization><id root=\"1.2.156.112635\" extension=\"4560886379\"/><name>南方医科大学顺德医院</name></representedCustodianOrganization></assignedCustodian></custodian><legalAuthenticator><time value=\"\"/><signatureCode code=\"S\"/><assignedEntity><id extension=\"电子签章号\"/></assignedEntity></legalAuthenticator><authenticator><time value=\"20211229152628\"/><signatureCode code=\"S\"/><assignedEntity><id root=\"1.2.156.112635.1.1.2\" extension=\"3-376\"/><assignedPerson><name>赖永坤</name></assignedPerson></assignedEntity></authenticator><participant typeCode=\"AUT\"><time value=\"20211229080615\"/><associatedEntity classCode=\"ASSIGNED\"><id root=\"1.2.156.112635.1.1.2\" extension=\"1-452\"/><associatedPerson><name>陈晓巧</name></associatedPerson><scopingOrganization><id root=\"1.2.156.112635.1.1.1\" extension=\"M010505\"/><name>发热门诊</name></scopingOrganization></associatedEntity></participant><componentOf><encompassingEncounter><effectiveTime/><location><healthCareFacility><serviceProviderOrganization><asOrganizationPartOf classCode=\"PART\"><wholeOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id extension=\"\"/><asOrganizationPartOf classCode=\"PART\"><wholeOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id extension=\"\"/><asOrganizationPartOf classCode=\"PART\"><wholeOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"1.2.156.112635.1.1.1\" extension=\"M010505\"/><name>发热门诊</name><asOrganizationPartOf classCode=\"PART\"><wholeOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"1.2.156.112635.1.1.33\" extension=\"\"/><name></name></wholeOrganization></asOrganizationPartOf></wholeOrganization></asOrganizationPartOf></wholeOrganization></asOrganizationPartOf></wholeOrganization></asOrganizationPartOf></serviceProviderOrganization></healthCareFacility></location></encompassingEncounter></componentOf><component><structuredBody><component><section><code code=\"20001\" codeSystem=\"2.16.840.1.113883.6.96\"/><entry><observationMedia classCode=\"OBS\" moodCode=\"EVN\"><value xsi:type=\"ED\" mediaType=\"application/pdf\">http://192.168.5.61:16703//2021/12/29/20211229G0506000.pdf</value></observationMedia></entry></section></component><component displayName=\"检验章节\"><section><code code=\"11502-2\" codeSystem=\"2.16.840.1.113883.6.1\" codeSystemName=\"LOINC\" displayName=\"Laboratory report\"/><title>检验</title><text><content ID=\"a1\"/><content ID=\"a2\"/><content ID=\"a3\"/></text><entry><observation classCode=\"OBS\" moodCode=\"EVN\"><code code=\"1\" codeSystem=\"1.2.156.112635.1.1.44\" displayName=\"常规\"/><statusCode code=\"1\"/><priorityCode code=\"03\"/><performer><time value=\"20211229151946\"/><assignedEntity><id root=\"1.2.156.112635.1.1.2\" extension=\"3-527\"/><assignedPerson determinerCode=\"INSTANCE\" classCode=\"PSN\"><name>戴碧云</name></assignedPerson><representedOrganization classCode=\"ORG\" determinerCode=\"INSTANCE\"><id root=\"1.2.156.112635.1.1.1\" extension=\"30\"/><name>检验科</name><asOrganizationPartOf><id extension=\"\"/></asOrganizationPartOf></representedOrganization></assignedEntity></performer><participant typeCode=\"DEV\"><participantRole><playingDevice><manufacturerModelName/></playingDevice></participantRole></participant><entryRelationship typeCode=\"COMP\" displayName=\"检验报告条目\"><organizer classCode=\"BATTERY\" moodCode=\"EVN\"><id root=\"2.16.156.10011.1.24\" extension=\"MZ28077879\"/><code code=\"1000\" codeSystem=\"1.2.156.112635.1.1.46\" displayName=\"新冠病毒核酸检测(混检免费)▲\"/><statusCode code=\"1\"/><cellDivision><cellDivisionStatusCode code=\"\" displayName=\"\"/><cellDivisionValue/></cellDivision><gene><geneCode code=\"\" displayName=\"\"/><geneValue value=\"\"/></gene><component displayName=\"检验常规项目\"><methodCode><item code=\"LIS4063 \"><displayName value=\"Real Time - PCR\"/><desc>Real Time - PCR</desc></item></methodCode><sequenceNumber value=\"3\"/><observation classCode=\"OBS\" moodCode=\"EVN\"><code code=\"8291\" codeSystem=\"1.2.156.112635.1.1.108\" displayName=\"ORF1ab\"><originalText>ORF1ab基因  ORF1ab gene</originalText></code><text>阴性 Negative</text><warnText>阳性</warnText><statusCode code=\"1\"/><value xsi:type=\"PQ\" value=\"阳性 Positive\" unit=\"\"/><value xsi:type=\"ST\">阳性 Positive</value><interpretationCode code=\"2\" displayName=\"???\"><originalText>危急偏高</originalText><translation code=\"数值标识\"/></interpretationCode><interpretationCode code=\"2\" displayName=\"危险\"><translation code=\"危险标识\"/></interpretationCode><referenceRange displayName=\"参考范围值\"><observationRange><code code=\"01\" displayName=\"参考范围值\"/><value xsi:type=\"IVL_PQ\" unit=\"\"><low value=\"阴性 Negative\"/><high value=\"阴性 Negative\"/></value></observationRange></referenceRange><referenceRange displayName=\"危险范围值\"><observationRange><code code=\"02\" displayName=\"危险范围值\"/><value xsi:type=\"IVL_PQ\" unit=\"\"><low value=\"-10000000\"/><high value=\"10000000\"/></value></observationRange></referenceRange><reportMemo/><averageValue value=\"\"/><standardDeviation value=\"\"/><riskValue value=\"\"/><ageRiskValue value=\"\"/><correctMom value=\"\"/></observation></component><component displayName=\"检验常规项目\"><methodCode><item code=\"LIS4063 \"><displayName value=\"Real Time - PCR\"/><desc>Real Time - PCR</desc></item></methodCode><sequenceNumber value=\"2\"/><observation classCode=\"OBS\" moodCode=\"EVN\"><code code=\"8293\" codeSystem=\"1.2.156.112635.1.1.108\" displayName=\"N gene\"><originalText>N基因  N gene</originalText></code><text>阴性 Negative</text><warnText>阳性</warnText><statusCode code=\"1\"/><value xsi:type=\"PQ\" value=\"阳性 Positive\" unit=\"\"/><value xsi:type=\"ST\">阳性 Positive</value><interpretationCode code=\"2\" displayName=\"???\"><originalText>危急偏高</originalText><translation code=\"数值标识\"/></interpretationCode><interpretationCode code=\"2\" displayName=\"危险\"><translation code=\"危险标识\"/></interpretationCode><referenceRange displayName=\"参考范围值\"><observationRange><code code=\"01\" displayName=\"参考范围值\"/><value xsi:type=\"IVL_PQ\" unit=\"\"><low value=\"阴性 Negative\"/><high value=\"阴性 Negative\"/></value></observationRange></referenceRange><referenceRange displayName=\"危险范围值\"><observationRange><code code=\"02\" displayName=\"危险范围值\"/><value xsi:type=\"IVL_PQ\" unit=\"\"><low value=\"-10000000\"/><high value=\"10000000\"/></value></observationRange></referenceRange><reportMemo/><averageValue value=\"\"/><standardDeviation value=\"\"/><riskValue value=\"\"/><ageRiskValue value=\"\"/><correctMom value=\"\"/></observation></component><component displayName=\"检验常规项目\"><methodCode><item code=\"LIS4063 \"><displayName value=\"Real Time - PCR\"/><desc>Real Time - PCR</desc></item></methodCode><sequenceNumber value=\"1\"/><observation classCode=\"OBS\" moodCode=\"EVN\"><code code=\"5430\" codeSystem=\"1.2.156.112635.1.1.108\" displayName=\"2019-nCOV\"><originalText>新型冠状病毒核酸  2019-nCOV</originalText></code><text>阴性 Negative</text><warnText>阳性</warnText><statusCode code=\"1\"/><value xsi:type=\"PQ\" value=\"阳性 Positive\" unit=\"\"/><value xsi:type=\"ST\">阳性 Positive</value><interpretationCode code=\"2\" displayName=\"???\"><originalText>危急偏高</originalText><translation code=\"数值标识\"/></interpretationCode><interpretationCode code=\"2\" displayName=\"危险\"><translation code=\"危险标识\"/></interpretationCode><referenceRange displayName=\"参考范围值\"><observationRange><code code=\"01\" displayName=\"参考范围值\"/><value xsi:type=\"IVL_PQ\" unit=\"\"><low value=\"阴性 Negative\"/><high value=\"阴性 Negative\"/></value></observationRange></referenceRange><referenceRange displayName=\"危险范围值\"><observationRange><code code=\"02\" displayName=\"危险范围值\"/><value xsi:type=\"IVL_PQ\" unit=\"\"><low value=\"-10000000\"/><high value=\"10000000\"/></value></observationRange></referenceRange><reportMemo/><averageValue value=\"\"/><standardDeviation value=\"\"/><riskValue value=\"\"/><ageRiskValue value=\"\"/><correctMom value=\"\"/></observation></component></organizer></entryRelationship><entryRelationship typeCode=\"SAS\" inversionInd=\"true\" displayName=\"标本及其图像信息\"><procedure classCode=\"PROC\" moodCode=\"EVN\"><code/><statusCode code=\"1\"/><effectiveTime value=\"20211229093907\"/><specimen><specimenRole><id extension=\"05331000193903\"/><specimenPlayingEntity><code code=\"\" codeSystem=\"1.2.156.112635.1.1.45\" displayName=\"鼻咽拭子\"/><desc>合格</desc></specimenPlayingEntity></specimenRole></specimen><performer><assignedEntity><id root=\"1.2.156.112635.1.1.2\" extension=\"XG\"/><assignedPerson><name>新冠门诊采集</name></assignedPerson><representedOrganization><id root=\"1.2.156.112635.1.1.1\" extension=\"\"/><name/></representedOrganization><targetSiteCode code=\"\" codeSystem=\"1.2.156.112635.1.1.42\" displayName=\"\"/></assignedEntity></performer><participant typeCode=\"RCV\" displayName=\"标本送检人信息\"><time value=\"\"/><sendSamplePurposeCode code=\"1\" codeSystem=\"\"><displayName value=\"\"/></sendSamplePurposeCode><participantRole><id root=\"1.2.156.112635.1.1.2\" extension=\"\"/><playingEntity><name/></playingEntity></participantRole><representedOrganization><name>南方医科大学顺德医院</name><asOrganizationPartOf><wholeOrganization><name>检验科</name></wholeOrganization></asOrganizationPartOf></representedOrganization></participant><participant typeCode=\"RCV\" displayName=\"标本接收人信息\"><time value=\"20211229104951\"/><participantRole><id root=\"1.2.156.112635.1.1.2\" extension=\"A132\"/><playingEntity><name>A132</name></playingEntity></participantRole><representedOrganization><name>南方医科大学顺德医院</name><asOrganizationPartOf><wholeOrganization><name>检验科</name></wholeOrganization></asOrganizationPartOf></representedOrganization></participant><participant typeCode=\"SBJ\"><participantRole><playingDevice><code code=\"\" displayName=\"一次性无菌拭子\"/></playingDevice></participantRole></participant></procedure></entryRelationship></observation></entry></section></component><component displayName=\"主健康章节\"><section><code code=\"49033-4\" codeSystem=\"2.16.840.1.113883.6.1\" codeSystemName=\"LOINC\" displayName=\"Menstrual History \"/><entry displayName=\"预产年龄\"><observation classCode=\"OBS\" moodCode=\"EVN\"><code code=\"63890-8\" codeSystem=\"2.16.840.1.113883.6.1\" codeSystemName=\"LOINC\" displayName=\"预产年龄\"/><value xsi:type=\"ST\"/></observation></entry><entry displayName=\"胎儿数\"><observation classCode=\"OBS\" moodCode=\"EVN\"><code code=\"63890-8\" codeSystem=\"2.16.840.1.113883.6.1\" codeSystemName=\"LOINC\" displayName=\"胎儿数\"/><value xsi:type=\"ST\"/></observation></entry><entry displayName=\"末次月经时间\"><observation classCode=\"OBS\" moodCode=\"EVN\"><code code=\"8665-2\" codeSystem=\"2.16.840.1.113883.6.1\" codeSystemName=\"LOINC\" displayName=\"末次月经时间\"/><value xsi:type=\"TS\" value=\"\"/></observation></entry><entry displayName=\"绝经标识\"><observation classCode=\"OBS\" moodCode=\"EVN\"><code code=\"63890-8\" codeSystem=\"2.16.840.1.113883.6.1\" codeSystemName=\"LOINC\" displayName=\"绝经标识\"/><value xsi:type=\"ST\"/></observation></entry><entry displayName=\"孕周计算方法\"><observation classCode=\"OBS\" moodCode=\"EVN\"><code code=\"63890-8\" codeSystem=\"2.16.840.1.113883.6.1\" codeSystemName=\"LOINC\" displayName=\"孕周计算方法\"/><value xsi:type=\"ST\"/></observation></entry></section></component><component displayName=\"诊断章节\"><section><code code=\"29308-4\" codeSystem=\"2.16.840.1.113883.6.1\" codeSystemName=\"LOINC\" displayName=\"Diagnosis\"/><title>诊断</title><entry typeCode=\"DRIV\"><act classCode=\"ACT\" moodCode=\"EVN\"><code nullFlavor=\"NA\"/><entryRelationship typeCode=\"SUBJ\"><observation classCode=\"OBS\" moodCode=\"EVN\"><code code=\"\" codeSystem=\"1.2.156.112635.1.1.29\" displayName=\"\"/><statusCode code=\"completed\"/><value xsi:type=\"CD\" code=\"\" codeSystem=\"1.2.156.112635.1.1.30\" displayName=\"\"/></observation></entryRelationship></act></entry></section></component></structuredBody></component></encounterEvent></subject></controlActProcess></PRPA_HIP1011>";
        String template = "<MCCI_IN000002UV01 xmlns=\"urn:hl7-org:v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ITSVersion=\"XML_1.0\" xsi:schemaLocation=\"urn:hl7-org:v3  file:///E:/hl7/HL7/v3ballot_fullsite_2011MAY/v3ballot/html/processable/multicacheschemas/MCCI _IN000002UV01.xsd\">  \n" +
                "  <id extension=\"${{system:STANDARD_NO_CONNECT}}\"/>  \n" +
                "  <creationTime value=\"${{system:DATE_TIME_NO_CONNECT}}\"/>  \n" +
                "  <interactionId root=\"2.16.840.1.113883.1.6\" extension=\"MCCI_IN000002UV01\"/>  \n" +
                "  <processingCode code=\"P\"/>  \n" +
                "  <processingModeCode/>  \n" +
                "  <acceptAckCode code=\"AL\"/>  \n" +
                "  <receiver typeCode=\"RCV\"> \n" +
                "    <device classCode=\"DEV\" determinerCode=\"INSTANCE\"> \n" +
                "      <id> \n" +
                "        <item extension=\"${{xpath:/PRPA_HIP1011/receiver/device/id/item/@extension}}\"/> \n" +
                "      </id> \n" +
                "    </device> \n" +
                "  </receiver>  \n" +
                "  <sender typeCode=\"SND\"> \n" +
                "    <device classCode=\"DEV\" determinerCode=\"INSTANCE\"> \n" +
                "      <id> \n" +
                "        <item extension=\"${{xpath:/PRPA_HIP1011/sender/device/id/item/@extension}}\"/> \n" +
                "      </id> \n" +
                "    </device> \n" +
                "  </sender>  \n" +
                "  <acknowledgement typeCode=\"AA\"> \n" +
                "    <!--请求消息ID-->  \n" +
                "    <targetMessage> \n" +
                "      <id extension=\"${{xpath:/PRPA_HIP1011/id/@extension}}\"/> \n" +
                "    </targetMessage>  \n" +
                "    <acknowledgementDetail> \n" +
                "      <text value=\"处理结果说明\"/> \n" +
                "    </acknowledgementDetail> \n" +
                "  </acknowledgement> \n" +
                "</MCCI_IN000002UV01>\n";
        System.out.println(findAllXmlPlaceHolder(template));
        System.out.println(findAllJsonPlaceHolder(template));
        System.out.println(template);
        System.out.println(dynamicParameterReplace(new MessageInfo(DataFormatEnum.XML, message), template));
        System.out.println(DataFormatEnum.fromValue(2));
        String[] split = "1,2,3,4".split(",");
        String[] one = cutFirst(split);
        String[] two = cutFirst(one);

        System.out.println(Arrays.toString(split));
        System.out.println(Arrays.toString(one));
        System.out.println(Arrays.toString(two));
        Message obj = new Message("method", "message_str");
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("code", 500);

        HashMap<Object, Object> objectObjectHashMap1 = new HashMap<>();
        objectObjectHashMap1.put("data", objectObjectHashMap);
        String json = Func.toJson(objectObjectHashMap1);
        System.out.println(json);
        JSONObject jsonObject = Func.readJson(json, JSONObject.class);
        System.out.println(getVal(jsonObject, "data"));
        System.out.println(getVal(jsonObject, "data.code"));
        System.out.println(ParametersEnum.DATE.getParam());
        System.out.println(ParametersEnum.DATE_NO_CONNECT.getParam());
        System.out.println(ParametersEnum.DATE_TIME.getParam());
        System.out.println(ParametersEnum.DATE_TIME_NO_CONNECT.getParam());
        System.out.println(ParametersEnum.STANDARD_UUID.getParam());
        System.out.println(ParametersEnum.UUID_NO_CONNECT.getParam());
    }

}
