Gb1400Controller.java
5.31 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
package com.viontech.controller;
import com.alibaba.fastjson.JSONObject;
import com.viontech.constant.SystemConstants;
import com.viontech.service.Gb1400Service;
import com.viontech.utils.Gb1400ResponseUtil;
import com.viontech.utils.JsonMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.HandlerMapping;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/VIID")
public class Gb1400Controller {
@Resource
private Gb1400Service gb1400Service;
/**
* 批量订阅
* @param params
* @return
*/
// @RequestMapping(value = "/Subscribes" ,method = RequestMethod.POST)
// @ResponseBody
// public JSONObject subscribes(@RequestBody String params){
// log.info("收到请求[Subscribes.request]:{}", params);
// JsonMessage vo = gb1400Service.subscribes(params);
// log.info("响应[Subscribes.request]:{}", JSONObject.toJSONString(vo));
// if (SystemConstants.APP_CODE_SUCCESS == vo.getCode()) {
// return Gb1400ResponseUtil.responseStatusListObject((List<JSONObject>) vo.getData());
// } else {
// return Gb1400ResponseUtil.error(1, vo.getMsg(),"/VIID/Subscribes");
// }
// }
/**
* 批量订阅
* @return
*/
@RequestMapping(value = "/Subscribes" ,method = RequestMethod.POST)
public void subscribes(HttpServletRequest request, HttpServletResponse response) throws IOException {
BufferedReader br = request.getReader();
String str;
StringBuilder params = new StringBuilder();
while((str = br.readLine()) != null){
params.append(str);
}
log.info("收到请求[Subscribes.request]:{}", params.toString());
JsonMessage vo = gb1400Service.subscribes(params.toString());
log.info("响应[Subscribes.request]:{}", JSONObject.toJSONString(vo));
JSONObject result = null;
response.setContentType("application/VIID+JSON;charset=utf-8");
if (SystemConstants.APP_CODE_SUCCESS == vo.getCode()) {
result = Gb1400ResponseUtil.responseStatusListObject((List<JSONObject>) vo.getData());
} else {
result = Gb1400ResponseUtil.error(1, vo.getMsg(),"/VIID/Subscribes");
}
response.getWriter().write(result.toJSONString());
}
/**
* 取消订阅
* @param ID
* @return
*/
// @RequestMapping(value = "/Subscribes/{ID}" ,method = RequestMethod.PUT)
// @ResponseBody
// public JSONObject unSubscribes(@PathVariable String ID, @RequestBody String params){
// log.info("收到请求[unSubscribes.request]:{}-{}", ID, params);
// JsonMessage vo = gb1400Service.unSubscribes(ID, params);
// log.info("响应[unSubscribes.request]:{}-{}", ID, JSONObject.toJSONString(vo));
// if (SystemConstants.APP_CODE_SUCCESS == vo.getCode()) {
// return Gb1400ResponseUtil.success("/VIID/Subscribes/" + ID);
// } else {
// return Gb1400ResponseUtil.error(1, vo.getMsg(),"/VIID/Subscribes/" + ID);
// }
// }
/**
* 取消订阅
* @return
*/
@RequestMapping(value = "/Subscribes/{ID}" ,method = RequestMethod.PUT)
@ResponseBody
public void unSubscribes(HttpServletRequest request, HttpServletResponse response) throws IOException {
Map attribute = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
String ID = "";
if (attribute != null && attribute.containsKey("ID")) {
ID = (String) attribute.get("ID");
}
BufferedReader br = request.getReader();
String str;
StringBuilder params = new StringBuilder();
while((str = br.readLine()) != null){
params.append(str);
}
log.info("收到请求[unSubscribes.request]:{}-{}", ID, params.toString());
JsonMessage vo = gb1400Service.unSubscribes(ID, params.toString());
log.info("响应[unSubscribes.request]:{}-{}", ID, JSONObject.toJSONString(vo));
JSONObject result = null;
response.setContentType("application/VIID+JSON;charset=utf-8");
if (SystemConstants.APP_CODE_SUCCESS == vo.getCode()) {
result = Gb1400ResponseUtil.success(ID,"/VIID/Subscribes/" + ID);
} else {
result = Gb1400ResponseUtil.error(ID, 1, vo.getMsg(),"/VIID/Subscribes/" + ID);
}
response.getWriter().write(result.toJSONString());
}
/**
* 注册接口
* @param params
* @return
*/
@RequestMapping(value = "/System/Register" ,method = RequestMethod.POST)
@ResponseBody
public JSONObject Register(@RequestBody String params){
log.info("收到请求[Register.request]:{}", params);
JsonMessage vo = gb1400Service.registerToMySystem(params);
log.info("响应[Register.request]:{}", JSONObject.toJSONString(vo));
if (SystemConstants.APP_CODE_SUCCESS == vo.getCode()) {
return Gb1400ResponseUtil.success("/VIID/System/Register");
} else {
return Gb1400ResponseUtil.error(1, vo.getMsg(),"/VIID/System/Register");
}
}
}