package com.legalPersonMonitor.monitor;

import com.legalPersonMonitor.config.ParameterConfig;
import com.legalPersonMonitor.connections.HttpClientPool;
import com.legalPersonMonitor.data.*;
import net.sf.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by gaoxiang on 2018/1/22.
 * 服务状态监控
 */
public class ServiceStateMonitoring {
   private static String msgDescription="";
   private static PreAuthResponseBean preAuthResponseBean;
   public static String serviceStateMonitoringServer(){
    try {
        String preAuthRespStr = HttpClientPool.postRequest("http://121.22.111.251:9002/legalPerson/v2.0/auth_app", ParameterConfig.PREAUTH_JSONSTR);
        JSONObject preAuthApply = JSONObject.fromObject(preAuthRespStr);
         preAuthResponseBean = (PreAuthResponseBean) JSONObject.toBean(preAuthApply, PreAuthResponseBean.class);
        if (!preAuthResponseBean.getSuccess()) {
            msgDescription = preAuthResponseBean.getErrorDesc();
        }
       JSONObject jsonObject = JSONObject.fromObject(ParameterConfig.AUTH_JSONSTR);
       Map config = new HashMap();
       config.put("authApplyRetainData", AuthApplyRetainBean.class);
       AuthRequestBean authRequestBean= (AuthRequestBean) JSONObject.toBean(jsonObject, AuthRequestBean.class, config);
       authRequestBean.setBusinessSerialNumber(preAuthResponseBean.getBusinessSerialNumber());
       String authResStr=JSONObject.fromObject(authRequestBean).toString();
       String authRespStr = HttpClientPool.postRequest("http://121.22.111.251:9002/legalPerson/v2.0/authen_req",authResStr);
       JSONObject authApply = JSONObject.fromObject(authRespStr);
       AuthResponseBean authResponseBean= (AuthResponseBean) JSONObject.toBean(authApply, AuthResponseBean.class);
      if(!authResponseBean.getSuccess()){
         msgDescription=authResponseBean.getErrorDesc();
      }
      msgDescription=authResponseBean.getAuthResult();
    }catch (Exception e){
        msgDescription="服务状态监控超时错误";
    }
      return msgDescription;

   }




}
