From 348c483d9e8cf81c485289a44c717fe1c23f4065 Mon Sep 17 00:00:00 2001
From: shiyj <1098226878@qq.com>
Date: 星期日, 07 七月 2019 17:29:35 +0800
Subject: [PATCH] Merge branch 'master' of https://github.com/java110/MicroCommunity
---
Api/src/main/java/com/java110/api/rest/RestApi.java | 212 +++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 198 insertions(+), 14 deletions(-)
diff --git a/Api/src/main/java/com/java110/api/rest/RestApi.java b/Api/src/main/java/com/java110/api/rest/RestApi.java
index 5cc573b..90141e1 100644
--- a/Api/src/main/java/com/java110/api/rest/RestApi.java
+++ b/Api/src/main/java/com/java110/api/rest/RestApi.java
@@ -1,39 +1,223 @@
package com.java110.api.rest;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.api.smo.IApiServiceSMO;
+import com.java110.common.constant.CommonConstant;
+import com.java110.core.base.controller.BaseController;
+import com.java110.core.smo.user.IUserInnerServiceSMO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
+import java.util.Map;
+
/**
- *
* rest api
* Created by wuxw on 2018/10/16.
*/
@RestController
+@RequestMapping(path = "/api")
+@Api(value = "瀵瑰缁熶竴鎻愪緵鏈嶅姟鎺ュ彛鏈嶅姟")
+public class RestApi extends BaseController {
-@Api(value = "Rest Api 鐢ㄦ埛鏈嶅姟")
-@RequestMapping(path = "/rest")
-public class RestApi {
+ private static Logger logger = LoggerFactory.getLogger(RestApi.class);
+ @Autowired
+ private IApiServiceSMO apiServiceSMOImpl;
+
+ @Autowired
+ private IUserInnerServiceSMO userInnerServiceSMOImpl;
/**
* 鍋ュ悍妫�鏌� 鏈嶅姟
+ *
* @return
*/
- @RequestMapping(path = "/health",method = RequestMethod.GET)
- @ApiOperation(value="鏈嶅姟鍋ュ悍妫�鏌�", notes="test: 杩斿洖 2XX 琛ㄧず鏈嶅姟姝e父")
- //@ApiImplicitParam(paramType="query", name = "userNumber", value = "鐢ㄦ埛缂栧彿", required = true, dataType = "Integer")
- public String health(){
+ @RequestMapping(path = "/health", method = RequestMethod.GET)
+ @ApiOperation(value = "鏈嶅姟鍋ュ悍妫�鏌�", notes = "test: 杩斿洖 2XX 琛ㄧず鏈嶅姟姝e父")
+ public String health() {
return "";
}
- @ApiOperation(value="淇濆瓨鐢ㄦ埛淇℃伅", notes="test: res_code 涓�0000琛ㄧず鎴愬姛锛屽叾浠栬〃绀哄け璐�")
- @ApiImplicitParam(paramType="save", name = "info", value = "鐢ㄦ埛缂栧彿", required = true, dataType = "String")
- @RequestMapping(path = "/saveUser",method = RequestMethod.PUT)
- public String saveUser(@RequestParam("info") String info){
- return "{}";
+ /**
+ * 鍋ュ悍妫�鏌� 鏈嶅姟
+ *
+ * @return
+ */
+ @RequestMapping(path = "/checkUserServiceVersion", method = RequestMethod.GET)
+ @ApiOperation(value = "妫�鏌ョ敤鏈嶅姟鐗堟湰", notes = "test: 杩斿洖 2XX 琛ㄧず鏈嶅姟姝e父")
+ public String checkUserServiceVersion() {
+ return userInnerServiceSMOImpl.getUserServiceVersion("test");
+ }
+
+
+ /**
+ * 璧勬簮璇锋眰 post鏂瑰紡
+ *
+ * @param service 璇锋眰鎺ュ彛鏂瑰紡
+ * @param postInfo post鍐呭
+ * @param request 璇锋眰瀵硅薄 鏌ヨ澶翠俊鎭� url绛変俊鎭�
+ * @return http status 200 鎴愬姛 鍏朵粬澶辫触
+ */
+
+ @RequestMapping(path = "/{service:.+}", method = RequestMethod.POST)
+ @ApiOperation(value = "璧勬簮post璇锋眰", notes = "test: 杩斿洖 2XX 琛ㄧず鏈嶅姟姝e父")
+ @ApiImplicitParam(paramType = "query", name = "service", value = "鐢ㄦ埛缂栧彿", required = true, dataType = "String")
+ public ResponseEntity<String> servicePost(@PathVariable String service,
+ @RequestBody String postInfo,
+ HttpServletRequest request) {
+ ResponseEntity<String> responseEntity = null;
+ try {
+ Map<String, String> headers = new HashMap<String, String>();
+ this.getRequestInfo(request, headers);
+ headers.put(CommonConstant.HTTP_SERVICE, service);
+ headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_POST);
+ logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", service, postInfo, headers);
+ responseEntity = apiServiceSMOImpl.service(postInfo, headers);
+ } catch (Throwable e) {
+ logger.error("璇锋眰post 鏂规硶[" + service + "]澶辫触锛�" + postInfo, e);
+ responseEntity = new ResponseEntity<String>("璇锋眰鍙戠敓寮傚父锛�" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ logger.debug("api锛歿} 杩斿洖淇℃伅涓猴細{}", service, responseEntity);
+
+ return responseEntity;
+ }
+
+ /**
+ * 璧勬簮璇锋眰 get鏂瑰紡
+ *
+ * @param service 璇锋眰鎺ュ彛鏂瑰紡
+ * @param request 璇锋眰瀵硅薄 鏌ヨ澶翠俊鎭� url绛変俊鎭�
+ * @return http status 200 鎴愬姛 鍏朵粬澶辫触
+ */
+
+ @RequestMapping(path = "/{service:.+}", method = RequestMethod.GET)
+ @ApiOperation(value = "璧勬簮get璇锋眰", notes = "test: 杩斿洖 2XX 琛ㄧず鏈嶅姟姝e父")
+ @ApiImplicitParam(paramType = "query", name = "service", value = "鐢ㄦ埛缂栧彿", required = true, dataType = "String")
+ public ResponseEntity<String> serviceGet(@PathVariable String service,
+ HttpServletRequest request) {
+ ResponseEntity<String> responseEntity = null;
+ try {
+ Map<String, String> headers = new HashMap<String, String>();
+ this.getRequestInfo(request, headers);
+ headers.put(CommonConstant.HTTP_SERVICE, service);
+ headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_GET);
+ logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", "", headers);
+ responseEntity = apiServiceSMOImpl.service(JSONObject.toJSONString(getParameterStringMap(request)), headers);
+ } catch (Throwable e) {
+ logger.error("璇锋眰get 鏂规硶[" + service + "]澶辫触锛�", e);
+ responseEntity = new ResponseEntity<String>("璇锋眰鍙戠敓寮傚父锛�" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ logger.debug("api锛歿} 杩斿洖淇℃伅涓猴細{}", service, responseEntity);
+
+ return responseEntity;
+ }
+
+ /**
+ * 璧勬簮璇锋眰 put鏂瑰紡
+ *
+ * @param service 璇锋眰鎺ュ彛鏂瑰紡
+ * @param postInfo 淇敼鍐呭
+ * @param request 璇锋眰瀵硅薄 鏌ヨ澶翠俊鎭� url绛変俊鎭�
+ * @return http status 200 鎴愬姛 鍏朵粬澶辫触
+ */
+
+ @RequestMapping(path = "/{service:.+}", method = RequestMethod.PUT)
+ @ApiOperation(value = "璧勬簮put璇锋眰", notes = "test: 杩斿洖 2XX 琛ㄧず鏈嶅姟姝e父")
+ @ApiImplicitParam(paramType = "query", name = "service", value = "鐢ㄦ埛缂栧彿", required = true, dataType = "String")
+ public ResponseEntity<String> servicePut(@PathVariable String service,
+ @RequestBody String postInfo,
+ HttpServletRequest request) {
+ ResponseEntity<String> responseEntity = null;
+ try {
+ Map<String, String> headers = new HashMap<String, String>();
+ this.getRequestInfo(request, headers);
+ headers.put(CommonConstant.HTTP_SERVICE, service);
+ headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_PUT);
+ logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", service, postInfo, headers);
+ responseEntity = apiServiceSMOImpl.service(postInfo, headers);
+ } catch (Throwable e) {
+ logger.error("璇锋眰put 鏂规硶[" + service + "]澶辫触锛�", e);
+ responseEntity = new ResponseEntity<String>("璇锋眰鍙戠敓寮傚父锛�" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ logger.debug("api锛歿} 杩斿洖淇℃伅涓猴細{}", service, responseEntity);
+ return responseEntity;
+ }
+
+ /**
+ * 璧勬簮璇锋眰 delete鏂瑰紡
+ *
+ * @param service 璇锋眰鎺ュ彛鏂瑰紡
+ * @param request 璇锋眰瀵硅薄 鏌ヨ澶翠俊鎭� url绛変俊鎭�
+ * @return http status 200 鎴愬姛 鍏朵粬澶辫触
+ */
+
+ @RequestMapping(path = "/{service:.+}", method = RequestMethod.DELETE)
+ @ApiOperation(value = "璧勬簮delete璇锋眰", notes = "test: 杩斿洖 2XX 琛ㄧず鏈嶅姟姝e父")
+ @ApiImplicitParam(paramType = "query", name = "service", value = "鐢ㄦ埛缂栧彿", required = true, dataType = "String")
+ public ResponseEntity<String> serviceDelete(@PathVariable String service,
+ HttpServletRequest request) {
+ ResponseEntity<String> responseEntity = null;
+ try {
+ Map<String, String> headers = new HashMap<String, String>();
+ this.getRequestInfo(request, headers);
+ headers.put(CommonConstant.HTTP_SERVICE, service);
+ headers.put(CommonConstant.HTTP_METHOD, CommonConstant.HTTP_METHOD_DELETE);
+ logger.debug("api锛歿} 璇锋眰鎶ユ枃涓猴細{},header淇℃伅涓猴細{}", service, "", headers);
+
+ responseEntity = apiServiceSMOImpl.service(JSONObject.toJSONString(getParameterStringMap(request)), headers);
+ } catch (Throwable e) {
+ logger.error("璇锋眰delete 鏂规硶[" + service + "]澶辫触锛�", e);
+ responseEntity = new ResponseEntity<String>("璇锋眰鍙戠敓寮傚父锛�" + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+
+ logger.debug("api锛歿} 杩斿洖淇℃伅涓猴細{}", service, responseEntity);
+ return responseEntity;
+ }
+
+
+ /**
+ * 鑾峰彇璇锋眰淇℃伅
+ *
+ * @param request
+ * @param headers
+ * @throws RuntimeException
+ */
+ private void getRequestInfo(HttpServletRequest request, Map headers) throws Exception {
+ try {
+ super.initHeadParam(request, headers);
+ super.initUrlParam(request, headers);
+ } catch (Exception e) {
+ logger.error("鍔犺浇澶翠俊鎭け璐�", e);
+ throw e;
+ }
+ }
+
+
+ public IApiServiceSMO getApiServiceSMOImpl() {
+ return apiServiceSMOImpl;
+ }
+
+ public void setApiServiceSMOImpl(IApiServiceSMO apiServiceSMOImpl) {
+ this.apiServiceSMOImpl = apiServiceSMOImpl;
+ }
+
+ public IUserInnerServiceSMO getUserInnerServiceSMOImpl() {
+ return userInnerServiceSMOImpl;
+ }
+
+ public void setUserInnerServiceSMOImpl(IUserInnerServiceSMO userInnerServiceSMOImpl) {
+ this.userInnerServiceSMOImpl = userInnerServiceSMOImpl;
}
}
--
Gitblit v1.8.0