JavaAPICtrl.java 3.53 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) {

        Map<String, String> param = new HashMap<String, String>();
        param.put("api_id", "" + req.getApiId());
        param.put("mobj_id", "" + req.getMobjId());
        param.put("start_time", "" + req.getStartTime());
        param.put("end_time", "" + req.getEndTime());
        param.put("page", "" + (req.getCurrentPage() - 1));
        param.put("pageSize", "" + req.getPageSize());

        BaseResponse rep;
        try {
            rep = httpClient.defaultGet(HttpUriContants.JAVA_API_HIS, BaseResponse.class, param);

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

        }
        return rep;
    }
}