JavaAPICtrl.java
5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
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 {
Logger log = LoggerFactory.getLogger(JavaAPICtrl.class);
@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 = "";
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;
}
/**
* 预留手动执行服务任务
*
* @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;
}
}
}