package cn.cslg.report.service;

import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.model.PASPatentVO;
import cn.cslg.report.common.model.ProjectSourceVO;
import cn.cslg.report.common.model.dto.EventAddNewDTO;
import cn.cslg.report.common.model.dto.PasUserDTO;
import cn.cslg.report.common.model.vo.*;
import cn.cslg.report.common.utils.CacheUtils;
import cn.cslg.report.common.utils.JsonUtils;
import cn.cslg.report.common.utils.SecurityUtils.LoginUtils;
import cn.cslg.report.entity.ImportTask;
import cn.cslg.report.entity.Report;
import cn.cslg.report.service.business.ImportTaskService;
import cn.cslg.report.service.business.ReportService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.gson.Gson;

import lombok.RequiredArgsConstructor;

import okhttp3.*;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * @author 沈永艺
 * @description 调用外部接口的Service类 PCS:权限系统 PAS:专利分析系统
 * @date 2022-10-31
 */
@SuppressWarnings({"all"})
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class OutInterfaceService {
    @Value("${PCSUrl}")
    private String PCSUrl;
    @Value("${PASUrl}")
    private String PASUrl;
    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
    private final CacheUtils cacheUtils;
    private final LoginUtils loginUtils;
    private final ReportService reportService;
    private final ImportTaskService importTaskService;

    /**
     * @title 获取验证码
     * @description 接口来源:PCS
     */
    public String getVerifyCodeFromPCS() throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .pingInterval(400, TimeUnit.SECONDS) // 设置 PING 帧发送间隔
                .connectTimeout(300, TimeUnit.SECONDS)//设置连接超时时间
                .readTimeout(300, TimeUnit.SECONDS)//设置读取超时时间
                .build();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/admin/verifyCode")
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 登录接口
     * @description 接口来源:PCS
     */
    public String loginFromPCS(LoginVO loginVO) throws IOException {
        Map<String, Object> map = new HashMap<>();
        map.put("code", loginVO.getCode());
        map.put("uuid", loginVO.getUuid());
        map.put("username", loginVO.getUsername());
        map.put("password", loginVO.getPassword());
        JSONObject json = new JSONObject(map);
        RequestBody requestBody = RequestBody.create(JSON, String.valueOf(json));
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/admin/login")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 登录人信息
     * @description 接口来源:PCS
     */
    public String userInfoFromPCS() throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/userinfo")
                .get()
                .addHeader("Cookie", LoginUtils.getToken())
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 获取字典项
     * @description 接口来源:PCS PAS
     */
    public Map<String, Object> dictMessageFromPCS() throws IOException {
        //从PCS取字典项
        OkHttpClient okHttpClient1 = new OkHttpClient();
        Request request1 = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/getDict")
                .get()
                .build();
        String pcsDictMessage = Objects.requireNonNull(okHttpClient1.newCall(request1).execute().body()).string();
        //从PAS取字典项
        OkHttpClient okHttpClient2 = new OkHttpClient();
        Request request2 = new Request.Builder()
                .url(PASUrl + "/api/v2/common/getDictMessage")
                .get()
                .build();
        String pasDictMessage = Objects.requireNonNull(okHttpClient2.newCall(request2).execute().body()).string();

        JSONObject jsonObject1 = JSONObject.parseObject(pcsDictMessage);
        JSONObject jsonObject2 = JSONObject.parseObject(pasDictMessage);
        Map<String, Object> map = new HashMap<>();
        map.putAll(JsonUtils.jsonToMap(String.valueOf(jsonObject1.get("data"))));
        map.putAll(JsonUtils.jsonToMap(String.valueOf(jsonObject2.get("data"))));
        return map;
    }

    /**
     * @title 获取权限列表
     * @description 接口来源:PCS
     */
    public String getPermissionListFromPCS(String code) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/getPermissionList?code=" + code)
                .addHeader("Cookie", LoginUtils.getToken())
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 获取所有部门(无权限控制)
     * @description 接口来源:PCS
     */
    public String getAllDepartmentFromPCS() throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/getAllDepartment")
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 获取部分部门(有权限控制)
     * @description 接口来源:PCS
     */

    public String getPartDepartmentFromPCS() throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/getPartDepartment")
                .addHeader("Cookie", LoginUtils.getToken())
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 获取所有人员(无权限控制)
     * @description 接口来源:PCS
     */
    public String getPartPersonnelID(Integer ID) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/personnel/getPerson?id=" + ID)
                .addHeader("Cookie", LoginUtils.getToken())
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    public String getAllPersonnelFromPCS() throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/getAllPersonnel")
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 分页查询人员
     * @description 接口来源:PCS
     */
    public String getPartPersonnelFromPCS(PersonnelVO personnelVO) throws IOException {
        Map<String, Object> map = new HashMap<>();
        if (personnelVO.getName() == null) {
            personnelVO.setName("");
        }
        map.put("name", personnelVO.getName());
        map.put("tenant", personnelVO.getTenant());
        map.put("size", personnelVO.getSize());
        map.put("current", personnelVO.getCurrent());
        map.put("notInPersonIds", personnelVO.getNotInPersonIds());
        JSONObject json = new JSONObject(map);
        RequestBody requestBody = RequestBody.create(JSON, String.valueOf(json));
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/queryPageList")
                .addHeader("Cookie", LoginUtils.getToken())
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }


    /**
     * @title 根据ID查询人员
     * @description 接口来源:PCS
     */
    public String getPersonnelByIdsFromPCS(List<Integer> ids) throws IOException {
        String param = new Gson().toJson(ids);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .build();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/getPersonnelByIds")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 获取所有客户(无权限控制)
     * @description 接口来源:PCS
     */
    public String getAllClientFromPCS() throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/client/getAllClient?id=" + cacheUtils.getLoginUser(loginUtils.getId()).getTenantId())
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 获取部分客户(有权限控制)
     * @description 接口来源:PCS
     */
    // TODO: 2022/11/2 未开发
    public String getPartClientFromPCS() throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/client/getPartClient")
                .addHeader("Cookie", LoginUtils.getToken())
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 根据专利号获得专利信息
     * @description 接口来源:PCS
     */
    public String getPatentFromPAS(String patentNo) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/patent/patentNo?patentNo=" + patentNo)
//                .addHeader("Cookie", LoginUtils.getToken())
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 根据专利号获得专利信息
     * @description 接口来源:PCS
     */
    public String getPatentRightFromPAS(String patentNo) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/patent/right?patentNo=" + patentNo)
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    public String getDeparts(List<Integer> ids) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .build();
        String param = new Gson().toJson(ids);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/getDeparts")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    public String getClientNameFromPCS(List<Integer> ids) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        String param = new Gson().toJson(ids);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/client/getByIds")
                .addHeader("Cookie", LoginUtils.getToken())
                .post(requestBody)
                .build();

        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    public String getPatentNos(Integer projectId) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/patent/getPatentNos?projectId=" + projectId)
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    public String getDictsFromPAS() throws IOException {
        List<String> dicts = new ArrayList<>();
        dicts.add(Constants.ENTERPRISE_APPLICATION_SCENARIO);
        String param = new Gson().toJson(dicts);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .build();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/system/dict")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    public String getPatentFromPAS(PatentVO patentVO, int type) throws IOException {
        LambdaQueryWrapper<ImportTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ImportTask::getReportId, patentVO.getReportId());
        List<ImportTask> importTasks = importTaskService.list(queryWrapper);
        List<Integer> taskIds = importTasks.stream().map(ImportTask::getId).collect(Collectors.toList());
        Report report = reportService.getById(patentVO.getReportId());
        if (type == 0) {
            patentVO.setProjectId(report.getProjectId());
            patentVO.setImportTaskId(taskIds);
        }
        String param = new Gson().toJson(patentVO);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .build();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/system/patentList")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * 调用分析系统新增事件接口
     *
     * @param eventAddNewDTOs
     * @return
     */
    public String getEventIdsFromPAS(List<EventAddNewDTO> eventAddNewDTOs) throws IOException {
        String param = new Gson().toJson(eventAddNewDTOs);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .build();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/event/addNew")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    public String getConPantentNos(PatentVO patentVO, int type) throws IOException {
        LambdaQueryWrapper<ImportTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ImportTask::getReportId, patentVO.getReportId());
        List<ImportTask> importTasks = importTaskService.list(queryWrapper);
        List<Integer> taskIds = importTasks.stream().map(ImportTask::getId).collect(Collectors.toList());
        Map<String, Object> map = new HashMap<>();
        Report report = reportService.getById(patentVO.getReportId());
        if (type == 0) {
            map.put("projectId", report.getProjectId());
            map.put("importTaskId", taskIds);
            map.put("startNumber", patentVO.getStartNumber());
            map.put("endNumber", patentVO.getEndNumber());
        }
        //专利名称
        map.put("patentName", patentVO.getPatentName());
        //专利摘要
        map.put("abstractStr", patentVO.getAbstractStr());
        map.put("size", patentVO.getSize());
        map.put("current", patentVO.getCurrent());
        map.put("patentNos", patentVO.getPatentNos());
        //申请人名字
        map.put("applicationName", patentVO.getApplicationName());
        //申请号
        map.put("applicationNo", patentVO.getApplicationNo());
        //专利号
        map.put("patentNo", patentVO.getPatentNo());
        //权利人名字
        map.put("obligeeName", patentVO.getObligeeName());
        map.put("notInPatentNos", patentVO.getNotInPatentNos());
        //分类号（IPC,UPC,CPC)
        map.put("numberCpc", patentVO.getNumberCpc());
        map.put("numberIpc", patentVO.getNumberIpc());
        map.put("numberUpc", patentVO.getNumberUpc());
        JSONObject json = new JSONObject(map);
        RequestBody requestBody = RequestBody.create(JSON, String.valueOf(json));
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .build();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/system/getConPantentNos")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    //根据专利号列表获得专利详情
    public String getPatentDTOListForRMS(PatentVO patentVO) throws IOException {
        Map<String, Object> map = new HashMap<>();
        map.put("patentNos", patentVO.getPatentNos());
        JSONObject json = new JSONObject(map);
        RequestBody requestBody = RequestBody.create(JSON, String.valueOf(json));
        OkHttpClient okHttpClient = new OkHttpClient
                .Builder()
                .connectTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .build();
        ;
        ;
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/system/getPatentDTOListForRMS")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();


    }

    public String getComPatentNos(PatentVO patentVO) throws IOException {
        if (patentVO.getReportId() != null) {
            LambdaQueryWrapper<ImportTask> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(ImportTask::getReportId, patentVO.getReportId());
            Report report = reportService.getById(patentVO.getReportId());
            List<ImportTask> importTasks = importTaskService.list(queryWrapper);
            List<Integer> taskIds = importTasks.stream().map(ImportTask::getId).collect(Collectors.toList());
            patentVO.setProjectId(report.getProjectId());
            patentVO.setImportTaskId(taskIds);
        }
        String param = new Gson().toJson(patentVO);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/system/getComPantentNos")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @params 传对象
     * @title 导入专利
     * @description 导入专利
     * @author lrj
     */
    public String importPatents(TaskParams taskParams) throws IOException {
        OkHttpClient httpClient = new OkHttpClient.Builder()
                .pingInterval(400, TimeUnit.SECONDS) // 设置 PING 帧发送间隔
                .connectTimeout(300, TimeUnit.SECONDS)//设置连接超时时间
                .readTimeout(300, TimeUnit.SECONDS)//设置读取超时时间
                .build();
        String param = new Gson().toJson(taskParams);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/project/import/sysPatent")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(httpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 获得分析系统自定义字段
     * @description 获得分析系统自定义字段
     * @autor lrj
     */
    public String getfieldFromPAS(Integer projectId) throws IOException {
        if (projectId == null) {
            projectId = 0;
        }
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/system/field/list?projectId=" + projectId)
//                .addHeader("Cookie", LoginUtils.getToken())
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 获得分析系统自定义字段选项
     * @description 获得分析系统自定义字段选项
     * @autor lrj
     */
    public String getSourceFromPAS(ProjectSourceVO params) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        String param = new Gson().toJson(params);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/patent/query/source")
//                .addHeader("Cookie", LoginUtils.getToken())
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 获得分析系统自定义字段选项
     * @description 获得分析系统自定义字段选项
     * @autor lrj
     */
    public String getPatentQueryTree(Integer projectId) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/project/field/tree?projectId=" + projectId)
                .get()
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 获得专题库筛选列表
     * @description 获得分析系统自定义字段选项
     * @autor lrj
     */

    public String getPatentListFromPAS(PASPatentVO params) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        LambdaQueryWrapper<ImportTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ImportTask::getReportId, params.getReportId());
        String param = new Gson().toJson(params);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        List<ImportTask> importTasks = importTaskService.list(queryWrapper);
        List<Integer> taskIds = importTasks.stream().map(ImportTask::getId).collect(Collectors.toList());
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/patent/list")
//                .addHeader("Cookie", LoginUtils.getToken())
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    public String getPersonIdByNamePCS(String personName) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/getPersonIdByName?personName=" + personName)
                .get()
                .build();

        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    public List<Integer> getDutyDepartsFromPCS(Integer personId) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/getDutyDeparts?personId=" + personId)
                .get()
                .build();
        String resBody = okHttpClient.newCall(request).execute().body().string();

        List<Integer> ids = JSONArray.parseArray(resBody, Integer.class);
        return ids;

    }

    /**
     * @title 获得专题库成员列表
     * @description 获得专题库成员列表
     * @autor lrj
     */

    public String getPASAssignedUser(PasUserDTO params) throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        String param = new Gson().toJson(params);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        Request request = new Request.Builder()
                .url(PCSUrl + "/permission/api/system/getPASAssignedUser")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

    /**
     * @title 根据条件获得专利信息
     * @description 根据条件获得专利信息
     * @autor lrj
     */
    public String getConPantents(PatentVO patentVO, int type) throws IOException {
        LambdaQueryWrapper<ImportTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ImportTask::getReportId, patentVO.getReportId());
        List<ImportTask> importTasks = importTaskService.list(queryWrapper);
        List<Integer> taskIds = importTasks.stream().map(ImportTask::getId).collect(Collectors.toList());
        Report report = reportService.getById(patentVO.getReportId());
        if (type == 0) {
            patentVO.setProjectId(report.getProjectId());
            patentVO.setImportTaskId(taskIds);

        }
        String param = new Gson().toJson(patentVO);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .build();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/system/getConPantents")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
    }

}
