package com.fastbee.iot.zhanlian;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fastbee.common.exception.ServiceException;
import com.fastbee.deviceData.api.devlink.service.ZhanLianAuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;


public class ZhanLianBaseService {

    /**
     * 基本请求
     * @param body 请求负载
     * @return 请求结果 data
     */
    public JSONObject baseRequest(Map<String,Object> body,String url){
        String jsonStr = JSONUtil.toJsonStr(body);
        String respStr = HttpUtil.post(url,jsonStr);
        JSONObject resp = JSONUtil.parseObj(respStr);
        // System.err.println(resp);
        if(!resp.getStr("code").equals("200")){
            throw new ServiceException("展联基本请求失败！");
        }
        return resp.getJSONObject("data");
    }









    public BigDecimal toBigDecimalValue(String str) {
        if (str == null|| str.isEmpty()) {
            return null;
        }
        return new BigDecimal(str);
    }
    public Long toLongValue(String str) {
        if (str == null|| str.isEmpty()) {
            return null;
        }
        return Long.parseLong(str);
    }

}
