package com.friday.custody.service.trustService.gf.utils;

import com.alibaba.fastjson.JSONObject;
import com.friday.custody.service.trustService.gf.common.GFConstants;
import com.gf.iind.client.web.service.IndexService;
import com.gf.iind.client.web.service.ParamsResult;
import com.gf.iind.client.web.service.ParamsService;
import lombok.extern.slf4j.Slf4j;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

@Slf4j
public class GFUtils {
    //定义命名空间、服务名称及端口名称
    private static String targetNamespace = ParamsService.targetNamespace;
    private static String serviceName = ParamsService.serviceName;
    private static String portName = ParamsService.portName;

    public static HashMap testDatasetByName(String appKey, String userID, String indexName, ParamsResult parResult) throws MalformedURLException {
        try {
            Thread.sleep(1000l);
        } catch (InterruptedException e) {
            e.getStackTrace();
            log.error("GFUtils_sendMessage 睡眠被打断了!");
            Thread.currentThread().interrupt();
        }
        //定义一个Service实例
        Service service = Service.create(new URL(GFConstants.wsdl), new QName(targetNamespace, serviceName));
        //定义一个IndexService实例
        IndexService indexService = service.getPort(new QName(targetNamespace, portName), IndexService.class);
        try {
            //调用获取结果集方法
            String ds = indexService.getDatasetByName(appKey,userID, indexName, parResult);
            HashMap map = JSONObject.parseObject(ds, HashMap.class);
            return map;
        } catch (Exception e) {
            log.error("广发接口调用失败:{}", indexName,e);
            e.printStackTrace();
        }
        return new HashMap();
    }
}
