package com.fkzy.warn.common.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fkzy.warn.common.constants.LawResearchUrlConstants;
import org.springframework.http.*;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

/**
 * @author zhangjing
 * @date 2024/09/19 09:58
 * @description
 */
public class LawResearchUtil {

//    code 1000 请求成功
//    code 2001 客户端请求参数有误，服务器无法理解
//    code 2002 ticket 无效。客户端未能提供有效的认证信息
//    code 2003 authorize 无效。服务器拒绝执行此请求
//    code 3001 请求失败


    /**
     * 司法模型
     *
     * @param name
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String querySssxxg(String name, String creditCode) {

        //默认测试数据
        if (name == null) {
//            name = "四川无声信息技术有限公司";
//            creditCode = "915101007234134581";
            name = "徐州协能建材科技有限公司";
            creditCode = "91320301MA20TF8T84";
        }

        JSONArray array = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", name);
        jsonObject.put("creditCode", creditCode);
        jsonObject.put("authorize", 1);
        array.add(jsonObject);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.QUERY_SSSXXG,
            array, null, null,
            "AmL92u2kCHjcCwcF",
            "Pv+mA1v2LRkgsZWqg2mAQDYM1hToAr3JmDZRYQRhZ07tHXJ2wSYEnFTWRp2ly+"
        );
    }
    //-------------------------------新接口--------------------
    public String querySxx(String name, String creditCode) {

        //默认测试数据
        if (name == null) {
//            name = "四川无声信息技术有限公司";
//            creditCode = "915101007234134581";
//            name = "徐州协能建材科技有限公司";
//            creditCode = "91320301MA20TF8T84";
//            name = "驻马店福强实业有限公司";
//            creditCode = "91411728MA47Q0KJ5B";
            name = "北京图灵高斯科技服务有限公司";
            creditCode = "91110102MACPFACT41";
//            name = "恒大集团有限公司";
//            creditCode = "91440300087909371X";
        }

        JSONArray array = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", name);
        jsonObject.put("creditCode", creditCode);
        jsonObject.put("authorize", 1);
        array.add(jsonObject);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.QUERY_SXX,
            array, null, null,
            "AmL92u2kCHjcCwcF",
            "Pv+mA1v2LRkgsZWqg2mAQDYM1hToAr3JmDZRYQRhZ07tHXJ2wSYEnFTWRp2Iy+OI"
        );
    }

    public String queryDishonest(String companyName, String fromDate, String legalPersionName, String creditcode) {
        //默认测试数据
        if (companyName == null) {
//            companyName = "恒大集团有限公司";
//            fromDate = "2022/01/01";
            legalPersionName = "杨贵单";
//            creditcode = "91440300087909371X";
        }

        JSONArray array = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", legalPersionName);
//        jsonObject.put("creditCode", creditcode);
        jsonObject.put("authorize", 1);
        jsonObject.put("id", "623021198104204013");
        jsonObject.put("type","0");
        array.add(jsonObject);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.QUERY_DISHONEST,
            array, null, null
            ,"xsXnjpCBbwKYU1d5"
            ,"Pv+mA1v2LRkgsZWqg2mAQJPn6o18VQagRlJny8DmuavlIoK6ZY6SG9CFBpFX0Ce5"
        );
    }

    public String queryLimitConsumption(String companyName, String fromDate, String legalPersionName, String creditcode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "恒大集团有限公司";
//            fromDate = "2022/01/01";
            legalPersionName = "施新桃";
            creditcode = "91440300087909371X";
        }

        JSONArray array = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", companyName);
        jsonObject.put("creditCode", creditcode);
        jsonObject.put("authorize", 1);
        array.add(jsonObject);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.QUERY_LIMITCONSUMPTION,
            array, null, null
            ,"Ju000$LbdkX@tjTK"
            ,"Pv+mA1v2LRkgsZWqg2mAQONIs4+TPrj8Zi7WRB8+xjBfG5HByVFpyzjoWwn0Wsi6"
        );
    }


    //-------------------------------新接口上面--------------------
    /**
     * 工商模型
     *
     * @param name
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String queryEntInfo(String name, String creditCode) {
        //默认测试数据
        if (name == null) {
            name = "四川无声信息技术有限公司";
            creditCode = "915101007234134581";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", name);
        jsonObject.put("creditCode", creditCode);
        jsonObject.put("authorize", 1);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.QUERY_ENT_INFO,
            null, jsonObject, null
        );
    }
    /**
     * 工商基础
     *
     * @param name
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String entInfo(String name, String creditCode) {
        //默认测试数据
        if (name == null) {
            name = "四川无声信息技术有限公司";
            creditCode = "915101007234134581";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", name);
        jsonObject.put("creditCode", creditCode);
        jsonObject.put("authorize", 1);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.COMPANY_ENTINFO,
            null, jsonObject, null
        );
    }

    /**
     * 制裁实体详情接口
     *
     * @param name
     * @param pageSize
     * @param pageNum
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String sanctionName(String name, Integer pageSize, Integer pageNum) {
        //默认测试数据
        if (name == null) {
            name = "华为";
            pageSize = 20;
            pageNum = 1;
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", name);
        jsonObject.put("pageSize", pageSize);
        jsonObject.put("pageNum", pageNum);
        jsonObject.put("authorize", 1);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.SANCTION_NAME,
            null, jsonObject, null
        );
    }

    /**
     * 一般纳税人
     *
     * @param name
     * @param pageSize
     * @param pageNum
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String generalTaxpayer(String name, Integer pageSize, Integer pageNum) {
        //默认测试数据
        if (name == null) {
            name = "小米科技有限责任公司";
            pageSize = 20;
            pageNum = 1;
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", name);
        jsonObject.put("pageSize", pageSize);
        jsonObject.put("pageNum", pageNum);
        jsonObject.put("authorize", 1);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.GENERAL_TAXPAYER,
            null, jsonObject, null
        );
    }
    /**
     * 股权图谱接口
     *
     * @param companyName
     * @param fromDate         开始日期 yyyy/MM/dd
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String atlas(String companyName, String fromDate) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            fromDate = "2022/01/01";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("fromDate", fromDate);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.ATLAS,
            null, jsonObject, null
        );
    }
    /**
     * 关联人物图谱接口
     *
     * @param companyName
     * @param fromDate         开始日期 yyyy/MM/dd
     * @param legalPersionName 法人或者高管
     * @param creditcode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String riskCompany(String companyName, String fromDate, String legalPersionName, String creditcode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            fromDate = "2022/01/01";
            legalPersionName = "雷军";
            creditcode = "91110108551385082Q";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("fromDate", fromDate);
        jsonObject.put("legalPersionName", legalPersionName);
        jsonObject.put("creditcode", creditcode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.RISK_COMPANY,
            null, jsonObject, null
        );
    }

    /**
     * 债权债务趋势图接口
     *
     * @param companyName
     * @param minDate     开始日期(2019-07)
     * @param maxDate     结束日期(2022-07)
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String caseTrendMap(String companyName, String minDate, String maxDate, String creditCode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            minDate = "2019/01";
            maxDate = "2022/01";
            creditCode = "91110108551385082Q";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("minDate", minDate);
        jsonObject.put("maxDate", maxDate);
        jsonObject.put("creditCode", creditCode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.CASE_TREND_MAP,
            null, jsonObject, null
        );
    }

    /**
     * 企业司法画像-审理程序分布接口
     *
     * @param companyName
     * @param minDate     开始日期(2019-07)
     * @param maxDate     结束日期(2022-07)
     * @param type        3 刑事，4 民事，5 行政，6 执行
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String getCaseAnalysisInfo(String companyName, String minDate, String maxDate, Integer type, String creditCode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            minDate = "2019/01";
            maxDate = "2022/01";
            type = 4;
            creditCode = "91110108551385082Q";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("minDate", minDate);
        jsonObject.put("maxDate", maxDate);
        jsonObject.put("type", type);
        jsonObject.put("creditCode", creditCode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.GET_CASE_TREND_MAP,
            null, jsonObject, null
        );
    }

    /**
     * 企业司法画像-诉讼地位分布接口
     *
     * @param companyName
     * @param minDate
     * @param maxDate
     * @param type        3 刑事，4 民事，5 行政，6 执行
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String getCaseSsdwInfo(String companyName, String minDate, String maxDate, Integer type, String creditCode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            minDate = "2019/01";
            maxDate = "2022/01";
            type = 4;
            creditCode = "91110108551385082Q";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("minDate", minDate);
        jsonObject.put("maxDate", maxDate);
        jsonObject.put("type", type);
        jsonObject.put("creditCode", creditCode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.GET_CASE_SSDW_INFO,
            null, jsonObject, null
        );
    }

    /**
     * 企业司法画像-主诉/被诉诉讼结果接口
     *
     * @param companyName
     * @param minDate
     * @param maxDate
     * @param type             3 刑事，4 民事，5 行政，6 执行
     * @param litigationStatus 主诉/被诉
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String getCaseSsjgInfo(String companyName, String minDate, String maxDate, Integer type,
                                  String litigationStatus, String creditCode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            minDate = "2019/01";
            maxDate = "2022/01";
            type = 4;
            litigationStatus = "被诉";
            creditCode = "91110108551385082Q";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("minDate", minDate);
        jsonObject.put("maxDate", maxDate);
        jsonObject.put("type", type);
        jsonObject.put("litigationStatus", litigationStatus);
        jsonObject.put("creditCode", creditCode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.GET_CASE_SSJG_INFO,
            null, jsonObject, null
        );
    }

    /**
     * 企业司法画像-案件走势图接口
     *
     * @param companyName
     * @param minDate
     * @param maxDate
     * @param type        3 刑事，4 民事，5 行政，6 执行
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String getCountAllCaseNumber(String companyName, String minDate, String maxDate, Integer type,
                                        String creditCode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            minDate = "2019/01";
            maxDate = "2022/01";
            type = 4;
            creditCode = "91110108551385082Q";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("minDate", minDate);
        jsonObject.put("maxDate", maxDate);
        jsonObject.put("type", type);
        jsonObject.put("creditCode", creditCode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.COUNT_ALL_CASE_NUMBER,
            null, jsonObject, null
        );
    }
    /**
     * 
     * 企业司法画像-涉诉关系图接口
     * @param companyName
     * @param minDate
     * @param maxDate
     * @param orderByField 排序字段：count 数量，amount 金额
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/

    public String litigationRelationship(String companyName, String minDate, String maxDate,
                                         String orderByField, String creditCode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            minDate = "2019/01";
            maxDate = "2022/01";
            orderByField = "count";
            creditCode = "91110108551385082Q";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("minDate", minDate);
        jsonObject.put("maxDate", maxDate);
        jsonObject.put("orderByField", orderByField);
        jsonObject.put("creditCode", creditCode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.LITIGATION_RELATIONSHIP,
            null, jsonObject, null
        );
    }
    /**
     * 
     * 企业司法画像-涉诉标的额接口
     * @param companyName
     * @param minDate
     * @param maxDate
     * @param isCaseClosed 已结案、未结案（不传查全部）
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String countCaseLitigationAmountAll(String companyName, String minDate, String maxDate,
                                         String isCaseClosed, String creditCode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            minDate = "2019/01";
            maxDate = "2022/01";
            isCaseClosed = "已结案";
            creditCode = "91110108551385082Q";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("minDate", minDate);
        jsonObject.put("maxDate", maxDate);
        jsonObject.put("isCaseClosed", isCaseClosed);
        jsonObject.put("creditCode", creditCode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.COUNT_CASE_LITIGATION,
            null, jsonObject, null
        );
    }
    /**
     *
     * 企业司法画像-地域分布图接口
     * @param companyName
     * @param minDate
     * @param maxDate
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String countCaseProvince(String companyName, String minDate, String maxDate,
                                          String creditCode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            minDate = "2019/01";
            maxDate = "2022/01";
            creditCode = "91110108551385082Q";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("minDate", minDate);
        jsonObject.put("maxDate", maxDate);
        jsonObject.put("creditCode", creditCode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.COUNT_CASE_PROVINCE,
            null, jsonObject, null
        );
    }
    /**
     *
     * 企业司法画像-案由分布图接口
     * @param companyName
     * @param minDate
     * @param maxDate
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String countSummary(String companyName, String minDate, String maxDate,
                                          String creditCode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            minDate = "2019/01";
            maxDate = "2022/01";
            creditCode = "91110108551385082Q";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("minDate", minDate);
        jsonObject.put("maxDate", maxDate);
        jsonObject.put("creditCode", creditCode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.COUNT_SUMMARY,
            null, jsonObject, null
        );
    }
    /**
     *
     * 投融资风险审查接口
     * @param companyName
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String riskReview(String companyName,
                                          String creditCode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            creditCode = "91110108551385082Q";
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("creditCode", creditCode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.RISK_REVIEW,
            null, jsonObject, null
        );
    }
    /**
     *
     * 投融资风险详情接口
     * @param companyName
     * @param pageIndex
     * @param pageSize
     * @param type 11 是否存在公司高管频繁变动
     * 12 是否存在股权结构异动
     * 13 当前是否存在股权抵押、质押等
     * 21 近五年与股东诉讼记录
     * 22 近五年与投资企业诉讼记录
     * 31 是否被列入制裁名单
     * 41 是否存在知产产权侵权风险
     * 42 是否不正当竞争风险
     * 51 股东/投资公司是否存在同业竞争
     * 61 是否存在重大风险
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String pageInfo(String companyName,Integer pageIndex,Integer pageSize,
                                          String type) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
//            creditCode = "91110108551385082Q";
            pageIndex = 1;
            pageSize = 20;
            type = "11";
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("pageIndex", pageIndex);
        jsonObject.put("pageSize", pageSize);
        jsonObject.put("type", type);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.RISK_REVIEW_PAGE_INFO,
            null, jsonObject, null
        );
    }
    /**
     *
     * 投融资风险详情接口
     * @param companyName
     * @param creditCode
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String overview(String companyName,
                                          String creditCode) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
            creditCode = "91110108551385082Q";

        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("creditCode", creditCode);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.OVERVIEW,
            null, jsonObject, null
        );
    }
    /**
     * 
     * 合同履约风险列表接口
     * @param companyName
     * @param pageIndex
     * @param pageSize
     * @param type 1002 是否被列入异常记录
     * 1003 是否被列入严重违法记录
     * 2001 被破产重组
     * 2002 是否有可执行财产
     * 2003 行政处罚
     * 2004 司法涉诉债务情况
     * 2005 股权出质
     * 2006 动产
     * 3001 否被列入为限制高消费
     * 3002 是否被列入为失信记录
     * 3003 否被列入为历史限制高消费
     * 3004 是否被列入为历史失信记录
     * 3005 近三年是否被存在行政处罚
     * 3006 近三年是否被存在税收处罚
     * 3007 近三年是否被存在环保处罚
     * 4001 大额违约记录
     * 4002 合同违约情况
     * 5001 近三年是否存在产品质量风险
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String overviewPageInfo(String companyName,Integer pageIndex,Integer pageSize,
                                   String type) {
        //默认测试数据
        if (companyName == null) {
            companyName = "小米科技有限责任公司";
//            creditCode = "91110108551385082Q";
            pageIndex = 1;
            pageSize = 20;
            type ="1002";
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("type", type);
        jsonObject.put("pageIndex", pageIndex);
        jsonObject.put("pageSize", pageSize);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.OVERVIEW_PAGE_INFO,
            null, jsonObject, null
        );
    }
    /**
     *
     * 监控名单添加接口
     * @param name
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String addpublic(String name) {
        //默认测试数据
        if (name == null) {
            name = "平凉市宏建煤炭有限责任公司";
//            creditCode = "91110108551385082Q";
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", name);
        JSONArray array = new JSONArray();
        array.add(jsonObject);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.ADD_PUBLIC,
            array, null, null
            ,"Cdi9CIzt0AnWucOe"
            ,"Pv+mA1v2LRkgsZWqg2mAQL/te4UiH52wshn/McsdLfmn+SBZ3LV86JM1jNjZIxqv"
        );
    }
    /**
     *
     * 监控名单删除接口
     * @param name
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String delcompany(String name) {
        //默认测试数据
        if (name == null) {
//            name = "小米科技有限责任公司";
            name = "恒大集团有限公司";
//            creditCode = "91110108551385082Q";
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", name);
        JSONArray array = new JSONArray();
        array.add(jsonObject);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.DEL_COMPANY,
            array, null, null
            ,"Cdi9CIzt0AnWucOe"
            ,"Pv+mA1v2LRkgsZWqg2mAQL/te4UiH52wshn/McsdLfmn+SBZ3LV86JM1jNjZIxqv"
        );
    }
    /**
     *
     * 监控名单查询接口
     * @param pageIndex
     * @param pageSize
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String monitorQuery(Integer pageIndex,Integer pageSize) {
        //默认测试数据
        if (pageIndex == null) {
            pageIndex = 1;
            pageSize = 20;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("pageIndex", pageIndex);
        jsonObject.put("pageSize", pageSize);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.MONITOR_QUERY,
            null, jsonObject, null
            ,"Cdi9CIzt0AnWucOe"
            ,"Pv+mA1v2LRkgsZWqg2mAQL/te4UiH52wshn/McsdLfmn+SBZ3LV86JM1jNjZIxqv"
        );
    }
    /**
     *
     * 监控信息获取
     * @param queryDate
     * @param pageIndex
     * @param pageSize
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public static String queryMonitorCases(String queryDate,Integer pageIndex,Integer pageSize) {
        //默认测试数据
        if (queryDate == null) {
//            queryDate="2022-07-06";
            queryDate="2026-02-08";
//            pageIndex = 1;
//            pageSize = 20;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("queryDate", queryDate);
//        jsonObject.put("pageIndex", pageIndex);
//        jsonObject.put("pageSize", pageSize);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.QUERY_MONITOR_CASES,
            null, jsonObject,null
            ,"Cdi9CIzt0AnWucOe"
            ,"Pv+mA1v2LRkgsZWqg2mAQL/te4UiH52wshn/McsdLfmn+SBZ3LV86JM1jNjZIxqv"
        );
    }
    /**
     *
     * 不良记录审查结果接口
     * @param name
     * @param id 身份证号
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String badrecord(String name,String id) {
        //默认测试数据
        if (name == null) {
            name="文敏钊";
            id = "511133197301240418";
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", name);
        jsonObject.put("id", id);
        jsonObject.put("authorize", 1);
        JSONArray arr = new JSONArray();
        arr.add(jsonObject);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.BADRECORD,
            arr, jsonObject, null
        );
    }
    /**
     *
     * 类案诉讼实体接口
     * @param enterprise
     * @param startPublishDate yyyy-MM-dd
     * @param endPublishDate yyyy-MM-dd
     * @param pageNum
     * @param pageSize
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String listByEnterprise(String enterprise,String startPublishDate,
    String endPublishDate,Integer pageNum,Integer pageSize) {
        //默认测试数据
        if (enterprise == null) {
            enterprise ="恒大地产集团有限公司";
            startPublishDate="2020-01-01";
            endPublishDate="2024-01-01";
            pageNum = 1;
            pageSize = 20;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("pageNum", pageNum);
        jsonObject.put("pageSize", pageSize);
        jsonObject.put("enterprise", enterprise);
        jsonObject.put("startPublishDate", startPublishDate);
        jsonObject.put("endPublishDate", endPublishDate);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.LIST_BY_ENTERPRISE,
            null, jsonObject, null
        );
    }
    /**
     *
     * 类案详情查询接口
     * @param docId 文书唯一id
     * @param casecause
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String showById(String docId,String casecause) {
        //默认测试数据
        if (docId == null) {
            docId ="c95f296f-353a-4741-ba94-aac0009f877e";
            casecause="盗窃罪";
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("docId", docId);

        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.QUERY_WS_SHOW_BY_ID,
            null, jsonObject, null
        );
    }
    /**
     * 
     * 类案详情列表接口
     * @param casecause
     * @param pageNum
     * @param pageSize
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String detailsList(String casecause,Integer pageNum,Integer pageSize) {
        //默认测试数据
        if (casecause == null) {
            casecause="盗窃罪";
            pageNum = 1;
            pageSize = 20;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("casecause", casecause);
        jsonObject.put("pageNum", pageNum);
        jsonObject.put("pageSize", pageSize);

        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.QUERY_WS_DETAILS_LIST,
            null, jsonObject, null
        );
    }
    /**
     *
     * 获取文书接口
     * @param id 案号或文书id
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String queryws(String id) {
        //默认测试数据
        if (id == null) {
            id="(2022)黑民申4571号";

        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", id);

        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.QUERYWS,
            null, jsonObject, null
        );
    }
    /**
     *
     * 专利查询列表接口
     * @param companyName
     * @param pageNum
     * @param pageSize
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String zlQuery(String companyName,Integer pageNum,Integer pageSize) {
        //默认测试数据
        if (companyName == null) {
            companyName="小米科技有限责任公司";
            pageNum = 1;
            pageSize = 20;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("companyName", companyName);
        jsonObject.put("pageNum", pageNum);
        jsonObject.put("pageSize", pageSize);

        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.ZL_QUERY,
            null, jsonObject, null
        );
    }
    /**
     *
     * 专利详情查询接口
     * @param id 专利id
     * @return java.lang.String
     * @author zhangjing
     * @create 2024/9/19
     **/
    public String zlDetails(String id) {
        //默认测试数据
        if (id == null) {
            id="ac9djeeb5ad2ci5ec68jcdb52df2id6cb4jefb57dadiacc00";
  
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", id);
        return getData(LawResearchUrlConstants.BASE_URL + LawResearchUrlConstants.ZL_DETAILS,
            null, jsonObject, null
        );
    }
    private String getData(String apiUrl, JSONArray array, JSONObject jsonObject, String method
    ) {
        return "";
    }


    private static String getData(String apiUrl, JSONArray array, JSONObject jsonObject, String method,
    String key,String ticket
    ) {
        RestTemplate restTemplate = new RestTemplate();
        HttpComponentsClientHttpRequestFactory requestFactory
            = new HttpComponentsClientHttpRequestFactory();
        requestFactory.setConnectionRequestTimeout(60000);
        requestFactory.setConnectTimeout(60000);
        requestFactory.setReadTimeout(60000);
        restTemplate.setRequestFactory(requestFactory);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("ticket", ticket);
        headers.set("Authorization", ticket);
        String request = (array != null) ? array.toJSONString() : jsonObject.toJSONString();
        try {
            //需要对入参进行 aes 加密
            String requestBody = AES.aesEncrypt(request, key);
            System.out.println("requestBody=====" + requestBody);
            //设置访问的 Entity
            HttpEntity entity = new HttpEntity<>(requestBody, headers);
            //执行  请求

            ResponseEntity<String> result =
                restTemplate.exchange(apiUrl, method == null ? HttpMethod.POST : HttpMethod.GET, entity,
                    String.class);
            // 指定文件路径
            String filePath = "output.txt";
            String resultData=null;
            try (PrintWriter writer = new PrintWriter(new File(filePath))) {
                //接收到返回结果需要进行 aes 解密
                resultData = AES.aesDecrypt(result.getBody(), key);
                //写入内容
                writer.println(resultData);

                // 自动关闭，因为使用了 try-with-resources 语句
            } catch (FileNotFoundException e) {
                System.err.println("文件未找到: " + e.getMessage());
            }
            return resultData;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
