package come.dxhy.test;

import com.dxhy.common.constant.ConfigurerInfo;
import com.dxhy.common.utils.Base64Encoding;
import com.dxhy.common.utils.RandomUtils;
import com.dxhy.erp.entity.V5.DxhyInterfaceRequest;
import com.dxhy.erp.utils.HmacSHA1Util;
import com.dxhy.erp.utils.JsonUtils;

import java.util.*;

/**
 * @ClassName ErpInterfaceTest.java
 * @author Allen
 * @version 1.0.0
 * @Description TODO
 * @createTime 2024年03月22日 10:28:00
 */public class ErpInterfaceTest {
    public static void main(String[] args) {
        String interfaceCode = "ZZSDKDJWSPZ.RZSQ";
        String signUrl = "POST10.1.29.135:18094/invoice/jxpt/api/v5/"+interfaceCode+"?";
        String secretId = "4VJzXVmyu/fFc2uepVHb7WjFwVM=";
        String secretKey = "c2FucWljZXNoaUFwcHNlY0tleVBybw==";
        String dataExchangeId = UUID.randomUUID().toString();
        String zipCode = "0";
        String encreypCOde = "0";
        String content = Base64Encoding.encode(JsonUtils.getInstance().toJsonString(dkdjwspzRzsq(new HashMap<>())));

        TreeMap<String, String> sortMap = new TreeMap<>();
        sortMap.put(ConfigurerInfo.SECRETID, secretId);
        sortMap.put(ConfigurerInfo.DATA_EXCHANGE_ID, dataExchangeId);
        sortMap.put(ConfigurerInfo.ENCRYPTCODE, encreypCOde);
        sortMap.put(ConfigurerInfo.ZIPCODE, zipCode);
        sortMap.put(ConfigurerInfo.CONTENT, content);

        DxhyInterfaceRequest req = new DxhyInterfaceRequest();
        req.setContent(content);
        req.setSignature(HmacSHA1Util.genSign(signUrl, sortMap, secretKey));
        req.setEncryptCode(encreypCOde);
        req.setZipCode(zipCode);
        req.setDataExchangeId(dataExchangeId);
        req.setSecretId(secretId);
        System.out.println("===========================================================================");
        System.out.println(JsonUtils.getInstance().toJsonString(req));
    }

    private static Object dkdjwspzRzsq(HashMap<Object, Object> contentMap) {
        contentMap.put("buyerTaxNo", "31310116MA1JCJWQXF");
        contentMap.put("batchNo", RandomUtils.getRandomCode(32));
        contentMap.put("rzlx", "5");
        contentMap.put("rzssq", "202403");
        contentMap.put("czr", "cyh");
        List<String> list = new ArrayList<>();
        list.add("202312121948000001");
        contentMap.put("wspzs", list);
        return contentMap;
    }

    /**
     * @description   全票面发票采集
     * @author  Allen
     * @date    2024/3/22 13:55
     * @return
     */
    private static Object getFpqpmCj(HashMap<Object, Object> contentMap) {
        contentMap.put("buyerTaxNo", "9111112222333344DD");
        contentMap.put("batchNo", RandomUtils.getRandomCode(32));
        contentMap.put("invoiceType", "161");
        contentMap.put("createDateBegin", "20230121161559");
        contentMap.put("createDateEnd", "20240321171559");
        contentMap.put("startRow", "1");
        contentMap.put("status", "1");
        return contentMap;
    }

    /**
     * @description   代扣代缴完税凭证采集
     * @author  Allen
     * @date    2024/3/22 13:55
     * @return
     */
    private static Object getDkdjwspzCj(HashMap<Object, Object> contentMap) {
        contentMap.put("buyerTaxNo", "91310116MA1JCJWQXF");
        contentMap.put("batchNo", RandomUtils.getRandomCode(32));
        contentMap.put("dkdjwspzbh", null);
        contentMap.put("createDateBegin", "20240321161559");
        contentMap.put("createDateEnd", "20250321171559");
        contentMap.put("rzzt", "0");
        contentMap.put("pageNum", 1);
        contentMap.put("pageCount", 20);
        return contentMap;
    }

    /**
     * @description  单张发票查询报文
     * @author  Allen
     * @date    2024/3/22 13:55
     * @return
     */
    private static Object getDzfpcx(HashMap<Object, Object> contentMap) {
        contentMap.put("buyerTaxNo", "91110108MA004CPN95");
        contentMap.put("invoiceCode", "1100182130");
        contentMap.put("invoiceNo", "58140650");
        return contentMap;
    }

    /**
     * @description  海关缴款书状态采集报文
     * @author  Allen
     * @date    2024/3/22 13:55
     * @return
    */
    private static Map<String, Object> getHgjksZtcj(Map<String, Object> contentMap) {
        contentMap.put("buyerTaxNo", "91110108MA004CPN95");
        contentMap.put("batchNo", RandomUtils.getRandomCode(32));
        contentMap.put("statusChangeDateBegin", "20230101010130");
        contentMap.put("statusChangeDateEnd", "20240101010130");
        contentMap.put("status", "1");
        contentMap.put("startRow", "1");
        return contentMap;
    }
}
