package com.lightinit.hsdataplatform.common;

import com.lightinit.hsdataplatform.dictionary.DicNewGateway;
import com.lightinit.hsdataplatform.entity.ResourceApiInterfaceWithBLOBs;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GateWayUtils {

    public static String gatewayAuthAdd(String ouyId1, String applicationid, String userId, String remark) {
        String code = null ;
        Map<String, String> params = new HashMap<>();
        params.put("routeId", ouyId1);
        params.put("appId", applicationid);
        params.put("userId", userId);
        params.put("remark", remark);
        try {
            String str = HttpUtil.httpPost(DicNewGateway.AUTHADD, null, params);
            Map<String, Object> map1 = HttpUtil.strToMap(str);
            if (map1.get("code").equals("200")) {
                code = map1.get("code").toString() ;
            }else {
                throw new RuntimeException("新增api鉴权异常:"+map1.get("message"));
            }
            System.out.println("=================" + map1 + "==========================");
        } catch (Exception e) {
            throw new RuntimeException("新增api鉴权异常!");
        }
        return code ;
    }

    public static void gatewayChargeAdd(List<ResourceApiInterfaceWithBLOBs> list, String userId, String remark) throws Exception {
        if (list.size() > 0) {
            for (ResourceApiInterfaceWithBLOBs resourceApiInterfaceWithBLOBs : list) {
                Map<String, String> params = new HashMap<>();
                params.put("routeId", resourceApiInterfaceWithBLOBs.getRouteId());
                params.put("appId", resourceApiInterfaceWithBLOBs.getAppId());
                params.put("userId", userId);
                params.put("remark", remark);
                HttpUtil.httpPost(SysContants.GatewayPath.GATEWAYURL_AUTHSAVE, null, params);
                HttpUtil.httpPost(SysContants.GatewayPath.GATEWAYURL_CHARGESAVE, null, params);
            }
        }
    }

}
