JavaAPICtrl.java 4.11 KB
package com.ui.ctrl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.req.JavaApiHisReq;
import com.ui.model.req.JavaApiInfoReq;
import com.ui.model.req.JavaApiStatusListReq;
import com.ui.model.req.JavaApiStatusReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

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

/**
 * Created by fruwei on 2016/6/17.
 */
@Controller
@RequestMapping("javaApi")
public class JavaAPICtrl {
    Logger log = LoggerFactory.getLogger(JavaAPICtrl.class);
    @Autowired
    private HttpRestClient httpClient;

    @RequestMapping("/all")
    @ResponseBody
    public String getJavaApiInfo() {
        String strType = "";

        log.debug("get all type");

        strType = httpClient.defaultGet(HttpUriContants.JAVA_API_GET, String.class);

        log.info("all type: {}", strType);

        return strType;
    }


    @RequestMapping("/query")
    @ResponseBody
    public BaseResponse queryApiInfo(JavaApiInfoReq req) {
        BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_API_GET, req, BaseResponse.class);
        return rep;
    }


    @RequestMapping("/save")
    @ResponseBody
    public BaseResponse saveApiInfo(JavaApiInfoReq req) {
        log.info("java api save req : {}", req);
        BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_API_SAVE, req, BaseResponse.class);
        return rep;
    }


    @RequestMapping("/del")
    @ResponseBody
    public BaseResponse delApiInfo(@RequestParam int id) {
        log.info("java api del id : {}", id);
        BaseResponse rep = httpClient.defaultGet(HttpUriContants.JAVA_API_DEL + "?id=" + id, BaseResponse.class);
        return rep;
    }


    @RequestMapping("/status")
    @ResponseBody
    public BaseResponse status(@RequestParam("list") String strList) {
        log.info("status req : {}", strList);
        BaseResponse rep;
        try {
            List<JavaApiStatusReq> req = JSON.parseArray(strList, JavaApiStatusReq.class);
            rep = httpClient.defaultPost(HttpUriContants.JAVA_API_STATUS, req.toArray(), BaseResponse.class);

        } catch (Exception e) {
            rep = new BaseResponse(400);
            rep.setMessage("list format error");

        }
        return rep;
    }

    @RequestMapping("/history")
    @ResponseBody
    public BaseResponse getHistory(JavaApiHisReq req) {

        BaseResponse rep;
        try {
            rep = httpClient.defaultPost(HttpUriContants.JAVA_API_HIS, req, BaseResponse.class);

        } catch (Exception e) {
            rep = new BaseResponse(400);
            rep.setMessage("list format error");

        }
        return rep;
    }

    @RequestMapping("/details")
    @ResponseBody
    public BaseResponse getDetalis(@RequestParam int id) {

        Map<String, String> param = new HashMap<String, String>();

        BaseResponse rep;
        try {
            rep = httpClient.defaultGet(HttpUriContants.JAVA_API_DETAILS + "?id=" + id, BaseResponse.class, param);
        } catch (Exception e) {
            rep = new BaseResponse(400);
            rep.setMessage("list format error");

        }
        return rep;
    }


    /**
     * 获取所有服务状态
     * @return
     */
    @RequestMapping("/allStatus")
    @ResponseBody
    public BaseResponse allStatus() {
        log.info("get  allStatus");
        BaseResponse rep;
        try {
            rep = httpClient.defaultGet(HttpUriContants.JAVA_API_STATUS_ALL, BaseResponse.class);
        } catch (Exception e) {
            rep = new BaseResponse(400);
            rep.setMessage("list format error");

        }
        return rep;
    }

}