AddressController.java
3.4 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
package com.taover.ai.controller.api;
import java.io.BufferedReader;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.taover.ai.bean.normal.ResponseAddress;
import com.taover.ai.service.AddressService;
import com.taover.util.bean.ResultInfo;
import com.taover.util.bean.UtilResultInfo;
import net.sf.json.JSONObject;
@RestController("api.address")
@RequestMapping("/api/address")
public class AddressController {
@Resource
private AddressService addressService;
/**
* @apiDefine ResultInfo
* @apiSuccess {string}
* @apiSuccessExample {json} Success-Response:
* {
* code:ok,
* error:null
* }
* @apiError ThrowException 出现异常
* @apiErrorExample
* {
* code:fail,
* error:null exception
* }
*/
/**
* @api {GET} /v1/address/ 查询ssid对应的demo
* @apiDescription 查询ssid对应demo数据
*
* @apiGroup Demo
* @apiName get实体数据
* @apiVersion 1.0.0
* @apiHeader Authorization
*
* @apiUse ResultInfo
*/
@RequestMapping("/pcdDetail")
public ResponseAddress pcdDetail(HttpServletRequest request){
String address = request.getParameter("address");
JSONObject addressJson = this.getRequestBody(request);
if(StringUtils.isNotEmpty(address)){
return this.addressService.pcdAddress(address);
}else if(addressJson != null && addressJson.containsKey("address")){
String jsonAddress = addressJson.optString("address");
if(StringUtils.isNotEmpty(jsonAddress)){
return this.addressService.pcdAddress(jsonAddress);
}
}
return ResponseAddress.createFail("没有检测到地址信息");
}
private JSONObject getRequestBody(HttpServletRequest request){
try {
BufferedReader reader = request.getReader();
String tempLine = reader.readLine();
StringBuffer sb = new StringBuffer();
while(tempLine != null){
sb.append(tempLine);
tempLine = reader.readLine();
}
return JSONObject.fromObject(sb.toString());
} catch (Exception e) {
return null;
}
}
/**
* @api {POST} /v1/demo 创建demo
* @apiDescription 创建demo
*
* @apiGroup Demo
* @apiName get实体数据
* @apiVersion 1.0.0
* @apiHeader Authorization
*
* @apiUse ResultInfo
*/
@PostMapping
public ResultInfo post(HttpServletRequest request){
return UtilResultInfo.getSuccess("post success");
}
/**
* @api {DELETE} /v1/demo/{ssid} 删除ssid对应的demo
* @apiDescription 删除ssid对应demo数据
*
* @apiGroup Demo
* @apiName 删除实体数据
* @apiVersion 1.0.0
* @apiHeader Authorization
*
* @apiUse ResultInfo
*/
@DeleteMapping("/{ssid}")
public ResultInfo delete(String ssid){
return UtilResultInfo.getSuccess("delete success");
}
/**
* @api {PUT} /v1/demo/{ssid} 修改demo数据
* @apiDescription 修改demo数据
*
* @apiGroup Demo
* @apiName 修改实体数据
* @apiVersion 1.0.0
* @apiHeader Authorization
*
* @apiUse ResultInfo
*/
@PutMapping("/{ssid}")
public ResultInfo put(String ssid, HttpServletRequest request){
return UtilResultInfo.getSuccess("put for ssid success");
}
}