package net.yyc.common.qcc.service;


import net.yyc.common.qcc.config.QccConfig;
import net.yyc.common.qcc.entity.EmployeeGetListRequest;
import net.yyc.common.qcc.entity.EmployeeGetListResponse;
import net.yyc.common.qcc.utils.HttpClientUtils;
import net.yyc.common.qcc.utils.JsonUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

@Slf4j
public class QccService {

	@Autowired
	private QccConfig config;


	/**
	 * 查询企业重要人员
	 * @author xyz
	 * @since 1.0
	 * params 示例：
	 * {
	 * "searchKey": "北京朔源科技有限公司",  必输
	 * "pageIndex": "1",    非必输
	 * "pageSize": "10"     非必输  最大支持20
	 * }
	 */
	public EmployeeGetListResponse getList(Map<String, String> params) {

		log.info("******************开启调用企查查接口*******************");
		log.info("**********************getList************************");

		EmployeeGetListRequest request = EmployeeGetListRequest.from(params, config);

		String json = HttpClientUtils.doGet(request);
		log.info("企查查接口getList返回数据: {}", json);
		EmployeeGetListResponse response = JsonUtils.deserializer(json, EmployeeGetListResponse.class);
		if (!response.isSuccess()) {
			log.error("企查查接口, Status: {}, Message: {}", response.getStatus(), response.getMessage());
		}
		return response;
	}

//	public static void main(String[] args) {
//
//		QccConfig config = new QccConfig();
//
//		Map<String, String> params = new HashMap<>();
//		params.put("key", config.getAppKey());
//		params.put("searchKey", "大象慧云信息技术有限公司");
//		params.put("pageIndex", "1");
//		params.put("pageSize", "10");
//
//		EmployeeGetListRequest request = EmployeeGetListRequest.from(params, config);
//		String json = HttpClientUtils.doGet(request);
//
//		System.err.println(json);
//	}


}
