Commit 816bd579 by 毛树良

<fix>:优化

1 parent e173bc41
......@@ -7,6 +7,7 @@ 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;
......@@ -14,6 +15,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
......@@ -71,17 +73,50 @@ public class Gb1400Controller {
* @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 JSONObject unSubscribes(@PathVariable String ID, @RequestBody String params){
log.info("收到请求[unSubscribes.request]:{}-{}", ID, params);
JsonMessage vo = gb1400Service.unSubscribes(ID, params);
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()) {
return Gb1400ResponseUtil.success("/VIID/Subscribes/" + ID);
result = Gb1400ResponseUtil.success(ID,"/VIID/Subscribes/" + ID);
} else {
return Gb1400ResponseUtil.error(1, vo.getMsg(),"/VIID/Subscribes/" + ID);
result = Gb1400ResponseUtil.error(ID, 1, vo.getMsg(),"/VIID/Subscribes/" + ID);
}
response.getWriter().write(result.toJSONString());
}
......
......@@ -85,4 +85,16 @@ public class Gb1400ResponseUtil {
result.put("ResponseStatusObject", response);
return result;
}
public static JSONObject error(String id, Integer errorNo, String errorMsg, String requestURL) {
JSONObject response = new JSONObject();
response.put("Id", id);
response.put("LocalTime", new Date());
response.put("RequestURL", requestURL);
response.put("StatusCode", errorNo);
response.put("StatusString", errorMsg);
JSONObject result = new JSONObject();
result.put("ResponseStatusObject", response);
return result;
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!