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

import com.alibaba.fastjson.JSON;
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.JavaApiStatusReq;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

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 {
    @Autowired
    private HttpRestClient httpClient;

    @RequestMapping("/toJavaApi")
    public ModelAndView toJavaApi() {
        return new ModelAndView("javaapi/javaApi");
    }

    @RequestMapping("/toJavaApiList")
    public ModelAndView toJavaApiList(Model model, String api_type) {
        if (StringUtils.isBlank(api_type)) {
            model.addAttribute("api_type", "ALL");
        } else {
            model.addAttribute("api_type", api_type);
        }
        return new ModelAndView("javaapi/javaApiList");
    }

    @RequestMapping("/all")
    @ResponseBody
    public String getJavaApiInfo() {
        String strType = "";
        strType = httpClient.defaultGet(HttpUriContants.JAVA_API_GET, String.class);
        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) {
        BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_API_SAVE, req, BaseResponse.class);
        return rep;
    }


    @RequestMapping("/del")
    @ResponseBody
    public BaseResponse delApiInfo(@RequestParam int 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) {
        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;
    }


    /**
     * 预留手动执行服务任务
     *
     * @return
     */
    @RequestMapping("/tasktest")
    @ResponseBody
    public String taskTest() {
        String rep = httpClient.defaultGet(HttpUriContants.JAVA_API_TASK_TEST, String.class);
        return rep;
    }


    /**
     * 预留调用接口
     *
     * @return
     */
    @RequestMapping("/test")
    @ResponseBody
    public void taskTest(@RequestParam int mark) {
        if (mark == 0) {
            int i = (1 / 0);
        } else {
            return;
        }
    }

}