package com.pj.xml;


import cn.hutool.log.StaticLog;
import com.pj.api.dto.CompanyDto;
import com.pj.api.dto.PaymentDto;
import com.pj.api.dto.PaymentTwoDto;
import com.pj.bank_info.BankInfo;
import com.pj.utils.CryptoUtil;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

public class MessageXML {
    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss sss");

    /**
     * 结关报文：海关数据中心--->银行
     */
    public static String CXB001(PaymentDto paymentDto) {
        paymentDto.setFieldCode("861501");
        String date = sdf.format(new Date());
        String payload =
                "<payload xsi:type=\"responseDTO\">\n" +
                        "<code>200</code>\n" +                                 //回执代码
                        "<source>" + paymentDto.getTradeNo() + "</source>\n" + //订单编号
                        "<note>结关成功</note>\n" +                             //回执内容
                        "<date>" + paymentDto.getDeclTime() + "</date>\n" +    //结关时间	YYYY-MM—DD HH：MM：DD SSS
                "</payload>";
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message title=\"一级市场\" xsi:schemaLocation=\"\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
                "<headers>\n" +
                "        <item>\n" +
                "               <key>sn</key>\n" +
                "              <value>" + UUID.randomUUID() + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>date</key>\n" +
                "              <value>" + date + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>organization</key>\n" +
                "              <value>" + paymentDto.getFieldCode() + "</value>\n" +//互市点机构代码
                "       </item>\n" +
                "        <item>\n" +
                "            <key>bankCode</key>\n" +
                "            <value>MRCCCNB1</value>\n" +//银行标识
                "        </item>\n" +
                "        <item>\n" +
                "               <key>operation</key>\n" +
                "              <value>CXB001</value>\n" +
                "       </item>\n" +
                "</headers>\n" +
                payload +
                //"<plain>" +
                //CryptoUtil.encrypt(payload)+
                //"</plain>" +
                "</message>";
        StaticLog.info("\n --------发送报文--------CXB001--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }

    /**
     * ※ 边民备案验证查询（边民已备案）：一级市场--->银行
     */
    public static String SXB003(BankInfo bankInfo) {
        String date = sdf.format(new Date());
        String payload =" <payload xsi:type=\"responseDTO\">" +
                        "         <code>200</code>\n" +                                 //消息回执代码
                        "         <source>" + bankInfo.getSn() + "</source>\n" +        //源报文编号
                        "         <note>边民已备案</note>\n" +                           //回执内容
                        "<results xsi:type=\"vendeeDTO\">\n" +
                        "         <name>" + bankInfo.getName() + "</name>\n" +                          //边民姓名
                        "         <papersType>" + bankInfo.getPapersType() + "</papersType>\n" +        //证件类型  0001 身份证
                        "         <papersNo>" + bankInfo.getPapersNo() + "</papersNo>\n" +              //边民证件号
                        "         <nationality>" + bankInfo.getNationality() + "</nationality>\n" +     //国籍
                        "</results>\n" +
                        "</payload>";
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"\">\n" +
                "<headers>\n" +
                "        <item>\n" +
                "               <key>sn</key>\n" +
                "              <value>" + UUID.randomUUID() + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>date</key>\n" +
                "              <value>" + date + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>organization</key>\n" +
                "              <value>" + bankInfo.getOrganization() + "</value>\n" +//互市点机构代码
                "       </item>\n" +
                "        <item>\n" +
                "            <key>bankCode</key>\n" +
                "            <value>" + bankInfo.getBankCode() + "</value>\n" +//银行标识
                "        </item>\n" +
                "        <item>\n" +
                "               <key>operation</key>\n" +
                "              <value>SXB003</value>\n" +
                "       </item>\n" +
                "</headers>\n" +
                "<plain>" +
                CryptoUtil.encrypt(payload)+
                "</plain>" +
                "</message>";
        StaticLog.info("\n --------发送报文--------SXB003--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }

    /**
     * ※ 边民备案验证查询（边民未备案）：一级市场--->银行
     */
    public static String SXB004(BankInfo bankInfo) {
        String date = sdf.format(new Date());
        String payload =" <payload xsi:type=\"responseDTO\">" +
                "         <code>500</code>\n" +                                 //消息回执代码
                "         <source>" + bankInfo.getSn() + "</source>\n" +        //源报文编号
                "         <note>边民未备案</note>\n" +                           //回执内容
                "</payload>";
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"\">\n" +
                "<headers>\n" +
                "        <item>\n" +
                "               <key>sn</key>\n" +
                "              <value>" + UUID.randomUUID() + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>date</key>\n" +
                "              <value>" + date + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>organization</key>\n" +
                "              <value>" + bankInfo.getOrganization() + "</value>\n" +//互市点机构代码
                "       </item>\n" +
                "        <item>\n" +
                "            <key>bankCode</key>\n" +
                "            <value>" + bankInfo.getBankCode() + "</value>\n" +//银行标识
                "        </item>\n" +
                "        <item>\n" +
                "               <key>operation</key>\n" +
                "              <value>SXB004</value>\n" +
                "       </item>\n" +
                "</headers>\n" +
                "<plain>" +
                CryptoUtil.encrypt(payload)+
                "</plain>" +
                "</message>";
        StaticLog.info("\n --------发送报文--------SXB004--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }

    /**
     * ※ 商家备案验证查询（商铺已备案）：一级市场--->银行
     */
    public static String SXB007(BankInfo bankInfo) {
        String date = sdf.format(new Date());
        String payload =
                " <payload xsi:type=\"responseDTO\">" +
                "         <code>200</code>\n" +                                 //消息回执代码
                "         <source>" + bankInfo.getSn() + "</source>\n" +        //源报文编号
                "         <note>商铺已备案</note>\n" +                           //回执内容
                "<results xsi:type=\"vendeeDTO\">\n" +
                "         <name>" + bankInfo.getName() + "</name>\n" +                          //商铺所属人姓名
                "         <papersType>" + bankInfo.getPapersType() + "</papersType>\n" +        //所属人证件类型  0001 身份证
                "         <papersNo>" + bankInfo.getPapersNo() + "</papersNo>\n" +              //所属人证件号
                "         <nationality>" + bankInfo.getNationality() + "</nationality>\n" +     //国籍
                "</results>\n" +
                "</payload>";
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"\">\n" +
                "<headers>\n" +
                "        <item>\n" +
                "               <key>sn</key>\n" +
                "              <value>" + UUID.randomUUID() + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>date</key>\n" +
                "              <value>" + date + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>organization</key>\n" +
                "              <value>" + bankInfo.getOrganization() + "</value>\n" +//互市点机构代码
                "       </item>\n" +
                "        <item>\n" +
                "            <key>bankCode</key>\n" +
                "            <value>" + bankInfo.getBankCode() + "</value>\n" +//银行标识
                "        </item>\n" +
                "        <item>\n" +
                "               <key>operation</key>\n" +
                "              <value>SXB007</value>\n" +
                "       </item>\n" +
                "</headers>\n" +
                "<plain>" +
                CryptoUtil.encrypt(payload)+
                "</plain>" +
                "</message>";
        StaticLog.info("\n --------发送报文--------SXB007--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }

    /**
     * ※ 商家备案验证查询（商铺未备案）：一级市场--->银行
     */
    public static String SXB008(BankInfo bankInfo) {
        String date = sdf.format(new Date());
        String payload =
                " <payload xsi:type=\"responseDTO\">" +
                "         <code>500</code>\n" +                                 //消息回执代码
                "         <source>" + bankInfo.getSn() + "</source>\n" +    //源报文编号
                "         <note>商铺未备案</note>\n" +                           //回执内容
                "</payload>";
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"\">\n" +
                "<headers>\n" +
                "        <item>\n" +
                "               <key>sn</key>\n" +
                "              <value>" + UUID.randomUUID() + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>date</key>\n" +
                "              <value>" + date + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>organization</key>\n" +
                "              <value>" + bankInfo.getOrganization() + "</value>\n" +//互市点机构代码
                "       </item>\n" +
                "        <item>\n" +
                "            <key>bankCode</key>\n" +
                "            <value>" + bankInfo.getBankCode() + "</value>\n" +//银行标识
                "        </item>\n" +
                "        <item>\n" +
                "               <key>operation</key>\n" +
                "              <value>SXB008</value>\n" +
                "       </item>\n" +
                "</headers>\n" +
                "<plain>" +
                CryptoUtil.encrypt(payload)+
                "</plain>" +
                "</message>";
        StaticLog.info("\n --------发送报文--------SXB008--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }

    /**
     * 订单扣款：一级市场--->银行
     */
    public static String SXB010(PaymentDto paymentDto) {
        paymentDto.setFieldCode("861501");
        String date = sdf.format(new Date());
        String payload =
                "<payload xsi:type=\"orderDTO\">" +
                "         <sn>" + paymentDto.getTradeNo() + "</sn>\n" +                         //订单号
                "         <export>false</export>\n" +                                           //出口标识	true：出口，false：进口
                "         <organization>" + paymentDto.getFieldCode() + "</organization>\n" +   //互市点机构代码
                //"         <currency>" + paymentDto.getCurrCode() + "</currency>\n" +          //币种
                "         <currency>RMB</currency>\n" +                                         //币种
                "         <type>001</type>\n" +                                                  //业务类型	01 代表扣款报文
                //"         <charging>" + paymentDto.getResalePrice() + "</charging>\n" +       //计费金额(二级市场转售总金额):charging送0
                "         <charging>0</charging>\n" +                                           //一级市场订单还没有上架计费:charging送0
                "         <total>" + paymentDto.getTotalPrice() + "</total>\n" +                //总金额8000.00(一级市场边民订单金额)
                "         <date>" + paymentDto.getDeclTime() + "</date>\n" +                    //订单时间	YYYY-MM—DD HH：MM：DD SSS
                "<vendee>\n" +
                "         <name>" + paymentDto.getBorderName() + "</name>\n" +                  //边民姓名
                "         <papersType>" + paymentDto.getPapersType() + "</papersType>\n" +      //证件类型  0001 身份证
                "         <papersNo>" + paymentDto.getBorderidno() + "</papersNo>\n" +          //边民证件号
                "         <nationality>" + paymentDto.getBorderNationality() + "</nationality>\n" +  //国籍
                "         <account>" + paymentDto.getBankCode() + "</account>\n" +              //银行账号
                "         <bankCode>" + paymentDto.getBankNo() + "</bankCode>\n" +              //开户行代码
                "         <tel>" + paymentDto.getBorderTel() + "</tel>\n" +                     //联系电话
                "         <enAddress></enAddress>\n" +
                "         <bankSignTime></bankSignTime>\n" +
                "</vendee>\n" +
                "<vendor>\n" +
                "         <title></title>\n" +
                "         <enTitle></enTitle>\n" +
                "         <name>" + paymentDto.getOwnerName() + "</name>\n" +                   //商铺所属人姓名
                "         <papersType>" + paymentDto.getOwnerIdtype() + "</papersType>\n" +     //所属人证件类型
                "         <papersNo>" + paymentDto.getShopSccd() + "</papersNo>\n" +            //所属人证件号
                "         <nationality>" + paymentDto.getNationality() + "</nationality>\n" +   //国籍
                "         <account>" + paymentDto.getBankAccount() + "</account>\n" +           //银行账号
                "         <bankCode>" + paymentDto.getBank() + "</bankCode>\n" +                //开户行代码
                "         <tel>" + paymentDto.getOwnerTel() + "</tel>\n" +                      //联系电话
                "         <address></address>\n" +
                "         <enAddress></enAddress>\n" +
                "         <abroad></abroad>\n" +
                "</vendor>\n" +
                "<items>\n" +
                "         <code>" + paymentDto.getCodeTs() + "</code>\n" +                      //商品编码
                "         <name>" + paymentDto.getGoodsName() + "</name>\n" +                   //商品名称
                //"         <unit>" + paymentDto.getGoodsUnit() + "</unit>\n" +                 //商品单位
                "         <unit>0001</unit>\n" +                                                //商品单位——KG
                "         <price>" + paymentDto.getDeclPrice() + "</price>\n" +                 //商品单价
                "         <quantity>" + paymentDto.getBuyQty() + "</quantity>\n" +              //商品数量
                "         <weight>" + paymentDto.getNetWt() + "</weight>\n" +                   //商品重量(净重)
                "         <amount>" + paymentDto.getTotalPrice() + "</amount>\n" +              //金额
                "</items>\n" +
                "</payload>";
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"\">\n" +
                "<headers>\n" +
                "        <item>\n" +
                "               <key>sn</key>\n" +
                "              <value>" + UUID.randomUUID() + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>date</key>\n" +
                "              <value>" + date + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>organization</key>\n" +
                "              <value>" + paymentDto.getFieldCode() + "</value>\n" +//互市点机构代码
                "       </item>\n" +
                "        <item>\n" +
                "            <key>bankCode</key>\n" +
                "            <value>MRCCCNB1</value>\n" +//银行标识
                "        </item>\n" +
                "        <item>\n" +
                "               <key>operation</key>\n" +
                "              <value>SXB010</value>\n" +
                "       </item>\n" +
                "</headers>\n" +
                "<plain>" +
                CryptoUtil.encrypt(payload)+
                "</plain>" +
                "</message>";
        StaticLog.info("\n --------发送报文--------SXB010--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }

    /**
     * 订单退款：一级市场--->银行
     */
    public static String SXB013(PaymentDto paymentDto) {
        paymentDto.setFieldCode("861501");
        String date = sdf.format(new Date());
        String payload =
                "<payload xsi:type=\"orderDTO\">" +
                "         <sn>" + paymentDto.getTradeNo() + "</sn>\n" +                         //订单号
                "         <organization>" + paymentDto.getFieldCode() + "</organization>\n" +   //互市点机构代码
                //"         <currency>" + paymentDto.getCurrCode() + "</currency>\n" +            //币种
                "         <currency>RMB</currency>\n" +                                         //币种
                "         <type>002</type>\n" +                                                  //业务类型	02代表退款报文
                //"         <charging>" + paymentDto.getResalePrice() + "</charging>\n" +       //计费金额(二级市场转售总金额):charging送0
                "         <charging>0</charging>\n" +                                           //一级市场订单还没有上架计费:charging送0
                "         <total>" + paymentDto.getTotalPrice() + "</total>\n" +                //总金额8000.00(一级市场边民订单金额)
                "         <date>" + paymentDto.getDeclTime() + "</date>\n" +                    //订单时间	YYYY-MM—DD HH：MM：DD SSS
                "<vendee>\n" +
                "         <name>" + paymentDto.getBorderName() + "</name>\n" +                  //边民姓名
                "         <papersType>" + paymentDto.getPapersType() + "</papersType>\n" +      //证件类型  0001 身份证
                "         <papersNo>" + paymentDto.getBorderidno() + "</papersNo>\n" +          //边民证件号
                "         <nationality>" + paymentDto.getBorderNationality() + "</nationality>\n" +  //国籍
                "         <account>" + paymentDto.getBankCode() + "</account>\n" +              //银行账号
                "         <bankCode>" + paymentDto.getBankNo() + "</bankCode>\n" +              //开户行代码
                "         <tel>" + paymentDto.getBorderTel() + "</tel>\n" +                     //联系电话
                "         <enAddress></enAddress>\n" +
                "         <bankSignTime></bankSignTime>\n" +
                "</vendee>\n" +
                "<vendor>\n" +
                "         <title></title>\n" +
                "         <enTitle></enTitle>\n" +
                "         <name>" + paymentDto.getOwnerName() + "</name>\n" +                   //商铺所属人姓名
                "         <papersType>" + paymentDto.getOwnerIdtype() + "</papersType>\n" +     //所属人证件类型
                "         <papersNo>" + paymentDto.getShopSccd() + "</papersNo>\n" +            //所属人证件号
                "         <nationality>" + paymentDto.getNationality() + "</nationality>\n" +   //国籍
                "         <account>" + paymentDto.getBankAccount() + "</account>\n" +           //银行账号
                "         <bankCode>" + paymentDto.getBank() + "</bankCode>\n" +                //开户行代码
                "         <tel>" + paymentDto.getOwnerTel() + "</tel>\n" +                      //联系电话
                "         <address></address>\n" +
                "         <enAddress></enAddress>\n" +
                "         <abroad></abroad>\n" +
                "</vendor>\n" +
                "<items>\n" +
                "         <code>" + paymentDto.getCodeTs() + "</code>\n" +                      //商品编码
                "         <name>" + paymentDto.getGoodsName() + "</name>\n" +                   //商品名称
                //"         <unit>" + paymentDto.getGoodsUnit() + "</unit>\n" +                   //商品单位
                "         <unit>0001</unit>\n" +                                                //商品单位——KG
                "         <price>" + paymentDto.getDeclPrice() + "</price>\n" +                 //商品单价
                "         <quantity>" + paymentDto.getBuyQty() + "</quantity>\n" +              //商品数量
                "         <weight>" + paymentDto.getNetWt() + "</weight>\n" +                   //商品重量(净重)
                "         <amount>" + paymentDto.getTotalPrice() + "</amount>\n" +              //金额
                "</items>\n" +
                "</payload>";

        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"\">\n" +
                "<headers>\n" +
                "        <item>\n" +
                "               <key>sn</key>\n" +
                "              <value>" + UUID.randomUUID() + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>date</key>\n" +
                "              <value>" + date + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>organization</key>\n" +
                "              <value>" + paymentDto.getFieldCode() + "</value>\n" +//互市点机构代码
                "       </item>\n" +
                "        <item>\n" +
                "            <key>bankCode</key>\n" +
                "            <value>MRCCCNB1</value>\n" +//银行标识
                "        </item>\n" +
                "        <item>\n" +
                "               <key>operation</key>\n" +
                "              <value>SXB013</value>\n" +
                "       </item>\n" +
                "</headers>\n" +
                "<plain>" +
                CryptoUtil.encrypt(payload)+
                "</plain>" +
                "</message>";
        StaticLog.info("\n --------发送报文--------SXB013--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }

    /**
     * 通关车批信息同步(车出一级市场时)：一级市场--->银行
     */
    public static String SXB023(PaymentDto paymentDto) {
        paymentDto.setFieldCode("861501");
        String date = sdf.format(new Date());
        List<String> tradeNoList = Arrays.stream(paymentDto.getTradeNos().split(",")).collect(Collectors.toList());
        String orderXml = "";
        for (String tradeNo: tradeNoList) {
            orderXml = orderXml + "<Order>" + tradeNo + "</Order>\n";
        }
        String payload=
                "<payload xsi:type=\"carpoolDTO\">" +
                "<registration>" + paymentDto.getVoyageNo() + "</registration>\n" +  //车辆批号
                "<plateNumber>" + paymentDto.getVeNo() + "</plateNumber>\n" +        //车牌号
                        orderXml +//订单号	n个
                "</payload>";
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"\">\n" +
                "<headers>\n" +
                "        <item>\n" +
                "               <key>sn</key>\n" +
                "              <value>" + UUID.randomUUID() + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>date</key>\n" +
                "              <value>" + date + "</value>\n" +
                "       </item>\n" +
                "        <item>\n" +
                "               <key>organization</key>\n" +
                "              <value>" + paymentDto.getFieldCode() + "</value>\n" +//互市点机构代码
                "       </item>\n" +
                "        <item>\n" +
                "            <key>bankCode</key>\n" +
                "            <value>MRCCCNB1</value>\n" +//银行标识
                "        </item>\n" +
                "        <item>\n" +
                "               <key>operationItem</key>\n" +
                "              <value>SXB023</value>\n" +
                "       </item>\n" +
                "</headers>\n" +
                "<plain>" +
                CryptoUtil.encrypt(payload)+
                "</plain>" +
                "</message>\n";
        StaticLog.info("\n --------发送报文--------SXB023--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }


    /**
     * ※ 卖家账号认证(边民)：二级市场--->银行
     */
    public static String MKT002(PaymentTwoDto paymentTwoDto) {
        String date = sdf.format(new Date());
        String payload =
                " <payload xsi:type=\"vendorDTO\"" +
                " name=\"" + paymentTwoDto.getBorderName() + "\"" +           //卖家姓名
                " papersType=\"0001\"" +                                //证件类型  0001 身份证
                " papersNo=\"" + paymentTwoDto.getBorderidno() + "\"" +   //证件号
                " nationality=\"0001\"" +                              //国籍
                " accountNo=\"" + paymentTwoDto.getBankCode() + "\"" +       //银行账号
                " bankCode=\"MRCCCNB1\"" +                                //开户行代码
                " tel=\"" + paymentTwoDto.getBorderTel() + "\"" +              //联系电话
                "></payload>";
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"\" title=\"二级市场\">\n" +
                "<headers>\n" +
                "<item key=\"sn\">" + UUID.randomUUID() + "</item>\n" +
                "<item key=\"date\">" + date + "</item>\n" +
                "<item key=\"organization\">" + paymentTwoDto.getFieldCode() + "</item>\n" +
                "<item key=\"bankCode\">MRCCCNB1</item>\n" +
                "<item key=\"operation\">MKT002</item>\n" +
                "</headers>\n" +
                "<plain>" +
                CryptoUtil.encrypt(payload)+
                "</plain>" +
                "</message>";
        StaticLog.info("\n --------发送报文--------MKT002--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }

    /**
     * ※ 买家账号认证(收购商)：二级市场--->银行
     */
    public static String MKT004(PaymentTwoDto paymentTwoDto) {
        String date = sdf.format(new Date());
        String payload =
                " <payload xsi:type=\"vendorDTO\"" +
                        " name=\"" + paymentTwoDto.getOwnerName() + "\"" +         //企业名称
                        " papersType=\"0008\"" +                                    //证件类型  0008 社会统一信用代码（默认）
                        " papersNo=\"78509372-8\"" +                                //证件号
                        " nationality=\"0001\"" +                                   //国籍
                        " accountNo=\"" + paymentTwoDto.getBankAccount() + "\"" +      //银行账号
                        " bankCode=\"MRCCCNB1\"" +                                  //开户行代码
                        " tel=\"" + paymentTwoDto.getOwnerTel() + "\"" +           //联系电话
                        "></payload>";
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"\" title=\"二级市场\">\n" +
                "<headers>\n" +
                "<item key=\"sn\">" + UUID.randomUUID() + "</item>\n" +
                "<item key=\"date\">" + date + "</item>\n" +
                "<item key=\"organization\">" + paymentTwoDto.getFieldCode() + "</item>\n" +
                "<item key=\"bankCode\">MRCCCNB1</item>\n" +
                "<item key=\"operation\">MKT004</item>\n" +
                "</headers>\n" +
                "<plain>" +
                CryptoUtil.encrypt(payload)+
                "</plain>" +
                "</message>";
        StaticLog.info("\n --------发送报文--------MKT004--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }

    /**
     * 订单扣款（无手续费）：二级市场--->银行
     */
    public static String MKT006_NoCommission(PaymentTwoDto paymentTwoDto) {
        paymentTwoDto.setFieldCode("861501");
        String date = sdf.format(new Date());
        String purchaserXml = "<vendee" +//买方基本信息（采购企业）
                " name=\"" + paymentTwoDto.getPcName() + "\"" +                 //企业名称
                " papersType=\"0008\"" +                                        //证件类型  0008 社会统一信用代码（默认）
                " papersNo=\"" + paymentTwoDto.getDutyParagraph() + "\"" +      //证件号
                " nationality=\"0001\"" +                                       //国籍
                " accountNo=\"" + paymentTwoDto.getPcBankAccount() + "\"" +     //银行账号
                " bankCode=\"" + paymentTwoDto.getPcBankNo() + "\"" +           //开户行代码
                " tel=\"" + paymentTwoDto.getPcContact() + "\"" +               //联系电话
                "/>\n";
        if(paymentTwoDto.getPcType() == 2) {
            purchaserXml = "<vendee" +//买方基本信息（个人采购商）
                    " name=\"" + paymentTwoDto.getPcName() + "\"" +                 //企业名称
                    " papersType=\"0001\"" +                                        //证件类型  0001 身份证
                    " papersNo=\"" + paymentTwoDto.getPcIdCard() + "\"" +           //证件号
                    " nationality=\"0001\"" +                                       //国籍
                    " accountNo=\"" + paymentTwoDto.getPcBankAccount() + "\"" +     //银行账号
                    " bankCode=\"" + paymentTwoDto.getPcBankNo() + "\"" +           //开户行代码
                    " tel=\"" + paymentTwoDto.getPcContact() + "\"" +               //联系电话
                    "/>\n";
        }
        String payload=
                "<payload xsi:type=\"orderDTO\"" +
                " sn=\"" + paymentTwoDto.getOrderNo() + "\"" +                  //订单号
                " organization=\"" + paymentTwoDto.getFieldCode() + "\"" +      //互市点机构代码
                " currency=\"RMB\"" +                                           //币种
                " type=\"001\"" +                                               //业务类型	001 代表扣款订单
                " total=\"" + paymentTwoDto.getResalePrice() + "\"" +           //订单总金额 8150.00 【买方总支付金额】(转售金额)
                //" actualTotal=\"</actualTotal>\n" +                           //扣除手续费边民实际到账金额  actualTotal忽略
                " dateTime=\"" + date + "\"" +                                  //订单时间	YYYY-MM—DD HH：MM：DD SSS
                ">" +

                purchaserXml +

                "<vendor" +//卖方基础信息（边民）
                " name=\"" + paymentTwoDto.getBorderName() + "\"" +             //边民姓名
                " papersType=\"" + paymentTwoDto.getPapersType() + "\"" +       //证件类型  0001 身份证
                " papersNo=\"" + paymentTwoDto.getBorderidno() + "\"" +         //边民证件号
                " nationality=\"" + paymentTwoDto.getBorderNationality() + "\"" +  //国籍
                " accountNo=\"" + paymentTwoDto.getBankCode() + "\"" +          //银行账号
                " bankCode=\"" + paymentTwoDto.getBankNo() + "\"" +             //开户行代码
                " tel=\"" + paymentTwoDto.getBorderTel() + "\"" +               //联系电话
                "/>\n" +

                "<items" +//商品明细
                " code=\"" + paymentTwoDto.getCodeTs() + "\"" +             //商品编码
                " name=\"" + paymentTwoDto.getGoodsName() + "\"" +          //商品名称
                //" unit=\"" + paymentTwoDto.getGoodsUnit() + "\"" +          //商品单位
                " unit=\"0001\"" +                                          //商品单位——KG
                " price=\"" + paymentTwoDto.getDeclPrice() + "\"" +         //商品单价
                " quantity=\"" + paymentTwoDto.getBuyQty() + "\"" +         //商品数量
                " weight=\"" + paymentTwoDto.getNetWt() + "\"" +            //商品重量
                " amount=\"0\"" +                                           //金额
                "/>\n" +

                "</payload>";
        String xml =
                "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"\">\n" +
                    "<headers>\n" +
                        " <item key=\"sn\">" + UUID.randomUUID() + "</item>\n" +
                        " <item key=\"date\">" + date + "</item> \n" +
                        " <item key=\"organization\">" + paymentTwoDto.getFieldCode() + "</item>\n" +
                        " <item key=\"bankCode\">MRCCCNB1</item>\n" +
                        " <item key=\"operation\">MKT006</item>\n" +
                    "</headers>\n" +
                    "<plain>" +
                         CryptoUtil.encrypt(payload)+
                    "</plain>" +
                "</message>";
        StaticLog.info("\n --------发送报文--------MKT006(无计费)--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }


    /**
     * 订单扣款（+手续费）：二级市场--->银行
     */
    public static String MKT006(PaymentTwoDto paymentTwoDto) {
        paymentTwoDto.setFieldCode("861501");
        paymentTwoDto.setDeclTime("2024-01-17 10:11:55 876");
        paymentTwoDto.setCurrCode("RMB");
        String date = sdf.format(new Date());
        String chargesXml = chargesXml(paymentTwoDto.getCompanyDtoList(), paymentTwoDto.getOrderNo());
        String payload=
                "<payload xsi:type=\"orderDTO\"" +
                " sn=\"" + paymentTwoDto.getOrderNo() + "\"" +                         //订单号
                " organization=\"" + paymentTwoDto.getFieldCode() + "\"" +   //互市点机构代码
                " currency=\"" + paymentTwoDto.getCurrCode() + "\"" +            //币种
                " type=\"001\"" +                                                //业务类型	001 代表扣款订单
                " total=\"" + paymentTwoDto.getResalePrice() + "\"" +               //订单总金额 8150.00 【买方总支付金额】(转售金额)
                " actualTotal=\"7490.05\"" +      //扣除手续费边民实际到账金额  actualTotal忽略
                " dateTime=\"" + paymentTwoDto.getDeclTime() + "\"" +            //订单时间	YYYY-MM—DD HH：MM：DD SSS
                ">" +

                /*"<vendee" +//买方基本信息（采购企业）
                " name=\"" + paymentTwoDto.getPcName() + "\"" +                       //企业名称
                " papersType=\"0008\"" +                                      //证件类型  0008 社会统一信用代码（默认）
                " papersNo=\"" + paymentTwoDto.getBusinessLicense() + "\"" +        //证件号
                " nationality=\"0001\"" +                                  //国籍
                " accountNo=\"" + paymentTwoDto.getPcBankAccount() + "\"" +     //银行账号
                " bankCode=\"MRCCCNB1\"" +                                   //开户行代码
                " tel=\"" + paymentTwoDto.getPcContact() + "\"" +                     //联系电话
                "/>\n" +*/
                "<vendee" +//买方基本信息（采购企业）
                " name=\"云南跨境贸易公司\"" +                       //企业名称
                " papersType=\"0008\"" +                                      //证件类型  0008 社会统一信用代码（默认）
                " papersNo=\"12312312-3\"" +        //证件号
                " nationality=\"0001\"" +                                  //国籍
                " accountNo=\"0100028613124012\"" +     //银行账号
                " bankCode=\"MRCCCNB1\"" +                                   //开户行代码
                " tel=\"15195882701\"" +                     //联系电话
                "/>\n" +

                "<vendor" +//卖方基础信息（边民）
                " name=\"" + paymentTwoDto.getBorderName() + "\"" +                 //边民姓名
                " papersType=\"0001\"" +                                    //证件类型  0001 身份证
                " papersNo=\"" + paymentTwoDto.getBorderidno() + "\"" +           //边民证件号
                " nationality=\"0001\"" +                                //国籍
                " accountNo=\"" + paymentTwoDto.getBankCode() + "\"" +        //银行账号
                " bankCode=\"MRCCCNB1\"" +                                 //开户行代码
                " tel=\"" + paymentTwoDto.getBorderTel() + "\"" +                   //联系电话
                "/>\n" +

                "<items" +//商品明细
                " code=\"" + paymentTwoDto.getCodeTs() + "\"" +                      //商品编码
                " name=\"" + paymentTwoDto.getGoodsName() + "\"" +                   //商品名称
                " unit=\"" + paymentTwoDto.getGoodsUnit() + "\"" +                   //商品单位
                " price=\"" + paymentTwoDto.getDeclPrice() + "\"" +                 //商品单价
                " quantity=\"" + paymentTwoDto.getBuyQty() + "\"" +              //商品数量
                " weight=\"" + paymentTwoDto.getGrossWt() + "\"" +                 //商品重量
                " amount=\"" + paymentTwoDto.getTotalPrice() + "\"" +              //金额
                "/>\n" +
                chargesXml +//父级手续费(无子级手续费）;
                "</payload>";
        String xml =
                "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"\">\n" +
                    "<headers>\n" +
                        " <item key=\"sn\">" + UUID.randomUUID() + "</item>\n" +
                        " <item key=\"date\">" + date + "</item> \n" +
                        " <item key=\"organization\">" + paymentTwoDto.getFieldCode() + "</item>\n" +
                        " <item key=\"bankCode\">MRCCCNB1</item>\n" +
                        " <item key=\"operation\">MKT006</item>\n" +
                    "</headers>\n" +
                    "<plain>" +
                        CryptoUtil.encrypt(payload)+
                    "</plain>" +
                "</message>";
        StaticLog.info("\n --------发送报文--------MKT006(有计费)--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }

    /**
     * 订单退款：二级市场--->银行
     */
    public static String MKT007_NoCommission(PaymentTwoDto paymentTwoDto) {
        String date = sdf.format(new Date());
        String payload=
                "<payload xsi:type=\"orderDTO\"" +
                        " sn=\"" + paymentTwoDto.getOrderNo() + "\"" +                         //订单号
                        " organization=\"" + paymentTwoDto.getFieldCode() + "\"" +   //互市点机构代码
                        " currency=\"" + paymentTwoDto.getCurrCode() + "\"" +            //币种
                        " type=\"002\"" +                                                //业务类型	001 代表扣款订单
                        " total=\"" + paymentTwoDto.getResalePrice() + "\"" +               //订单总金额 8150.00 【买方总支付金额】(转售金额)
                        " actualTotal=\"" + paymentTwoDto.getTotalPrice() + "\"" +      //扣除手续费边民实际到账金额  actualTotal忽略
                        " dateTime=\"" + paymentTwoDto.getDeclTime() + "\"" +            //订单时间	YYYY-MM—DD HH：MM：DD SSS
                        ">" +


                        /*"<vendee" +//买方基本信息（采购企业）
                        " name=\"" + paymentTwoDto.getPcName() + "\"" +                       //企业名称
                        " papersType=\"0008\"" +                                      //证件类型  0008 社会统一信用代码（默认）
                        " papersNo=\"" + paymentTwoDto.getBusinessLicense() + "\"" +        //证件号
                        " nationality=\"0001\"" +                                  //国籍
                        " accountNo=\"" + paymentTwoDto.getPcBankAccount() + "\"" +     //银行账号
                        " bankCode=\"MRCCCNB1\"" +                                   //开户行代码
                        " tel=\"" + paymentTwoDto.getPcContact() + "\"" +                     //联系电话
                        "/>\n" +

                        "<vendor" +//卖方基础信息（边民）
                        " name=\"" + paymentTwoDto.getBorderName() + "\"" +                 //边民姓名
                        " papersType=\"0001\"" +                                    //证件类型  0001 身份证
                        " papersNo=\"" + paymentTwoDto.getBorderidno() + "\"" +           //边民证件号
                        " nationality=\"0001\"" +                                //国籍
                        " accountNo=\"" + paymentTwoDto.getBankCode() + "\"" +        //银行账号
                        " bankCode=\"MRCCCNB1\"" +                                 //开户行代码
                        " tel=\"" + paymentTwoDto.getBorderTel() + "\"" +                   //联系电话
                        "/>\n" +*/

                        "<vendee" +//买方基本信息（采购企业）
                        " name=\"云南跨境贸易公司\"" +                       //企业名称
                        " papersType=\"0008\"" +                           //证件类型  0008 社会统一信用代码（默认）
                        " papersNo=\"12312312-3\"" +                       //证件号
                        " nationality=\"0001\"" +                          //国籍
                        " accountNo=\"0100028613124012\"" +                //银行账号
                        " bankCode=\"MRCCCNB1\"" +                         //开户行代码
                        " tel=\"15195882701\"" +                           //联系电话
                        "/>\n" +

                        "<vendor" +//卖方基础信息（边民）
                        " name=\"" + paymentTwoDto.getBorderName() + "\"" +                 //边民姓名
                        " papersType=\"0001\"" +                                    //证件类型  0001 身份证
                        " papersNo=\"" + paymentTwoDto.getBorderidno() + "\"" +           //边民证件号
                        " nationality=\"0001\"" +                                //国籍
                        " accountNo=\"" + paymentTwoDto.getBankCode() + "\"" +        //银行账号
                        " bankCode=\"MRCCCNB1\"" +                                 //开户行代码
                        " tel=\"" + paymentTwoDto.getBorderTel() + "\"" +                   //联系电话
                        "/>\n" +

                        "<items" +//商品明细
                        " code=\"" + paymentTwoDto.getCodeTs() + "\"" +                      //商品编码
                        " name=\"" + paymentTwoDto.getGoodsName() + "\"" +                   //商品名称
                        " unit=\"" + paymentTwoDto.getGoodsUnit() + "\"" +                   //商品单位
                        " price=\"" + paymentTwoDto.getDeclPrice() + "\"" +                 //商品单价
                        " quantity=\"" + paymentTwoDto.getBuyQty() + "\"" +              //商品数量
                        " weight=\"" + paymentTwoDto.getGrossWt() + "\"" +                 //商品重量
                        " amount=\"" + paymentTwoDto.getTotalPrice() + "\"" +              //金额
                        "/>\n" +
                        "</payload>";

        String xml =
                "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
                        "<message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"\">\n" +
                        "<headers>\n" +
                        " <item key=\"sn\">" + UUID.randomUUID() + "</item>\n" +
                        " <item key=\"date\">" + date + "</item> \n" +
                        " <item key=\"organization\">" + paymentTwoDto.getFieldCode() + "</item>\n" +
                        " <item key=\"bankCode\">MRCCCNB1</item>\n" +
                        " <item key=\"operation\">MKT007</item>\n" +
                        "</headers>\n" +
                        "<plain>" +
                        CryptoUtil.encrypt(payload)+
                        "</plain>" +
                        "</message>";
        StaticLog.info("\n --------发送报文--------MKT007--------" + "\n payload=" + payload +"\n xml=" + xml);
        return xml;
    }

    private static String chargesXml(List<CompanyDto> companyDtoList, String orderNo) {
        String xml = "";
        for (CompanyDto companyDto : companyDtoList) {
            companyDto.setName("云南跨境贸易公司");
            companyDto.setUsci("12312312-3");
            companyDto.setBankAccount("0100028613124012");
            companyDto.setContact("15195882701");
            xml += "<charges" +//父级手续费(无子级手续费）
                    " type=\"OPERATING\"" +                                     //手续费类型	数据字典：ChargeType
                    " sn=\"" + orderNo + "\"" +                                 //订单号
                    " name=\"" + companyDto.getName() + "\"" +                  //企业名称
                    " papersType=\"0008\"" +                                    //证件类型  0008 社会统一信用代码（默认）
                    " papersNo=\"" + companyDto.getUsci() + "\"" +              //证件号
                    " nationality=\"0001\"" +                                   //国籍
                    " accountNo=\"" + companyDto.getBankAccount() + "\"" +      //银行账号
                    " bankCode=\"MRCCCNB1\"" +                                  //开户行代码
                    " bankNo=\"\"" +                                            //开户行行号	非必填
                    " tel=\"" + companyDto.getContact() + "\"" +                //联系电话
                    " total=\"" + companyDto.getChargesPrice() + "\"" +         //手续费金额
                    "></charges>\n";
        }
        return xml;
    }


}
