Browse Source

http请求统一处理接口逻辑处理方法入参改为map类型

cuixubin 3 years ago
parent
commit
61c27f06bb

+ 4 - 2
src/main/java/com/persagy/framework/construct/RequestProcessor.java

@@ -1,14 +1,16 @@
 package com.persagy.framework.construct;
 
+import java.util.Map;
+
 /**
  * 请求处理接口 
  */
 public interface RequestProcessor {
 	/***
 	 * 请求处理执行逻辑
-	 * @param jsonString json字符串格式参数
+	 * @param paramMap 参数信息
 	 * @return 处理结果
 	 * @throws Exception
 	 */
-	public Object handle(String jsonString) throws Exception;
+	public Object handle(Map<String, Object> paramMap) throws Exception;
 }

+ 3 - 6
src/main/java/com/persagy/framework/web/controller/entrance/UnifierController.java

@@ -106,24 +106,21 @@ public class UnifierController {
 			businessService = (RequestProcessor) serviceBean;
 		}
 		
-		String jsonString = param.toString();
 		try {
-			jsonString = objectMapper.writeValueAsString(param);
-			jsonString = URLDecoder.decode(jsonString, "UTF-8");
 			
-			apiResult.setData(businessService.handle(jsonString));
+			apiResult.setData(businessService.handle(param));
 			
 			apiResult.setResult(ApiResult.result_success);
 		} catch (Exception e) {
 			apiResult.setResult(ApiResult.result_fail);
 			apiResult.setMessage(e.getMessage());
-		    log.error("Request Error! requesterIp="+ip+" API=" + handleType + ", Param=" + jsonString + ", Msg=" + e.getMessage(), e);
+		    log.error("Request Error! requesterIp="+ip+" API=" + handleType + ", Param=" + param + ", Msg=" + e.getMessage(), e);
 		}
 
 		long end = System.currentTimeMillis();
 	    long timeInterval = (end - start.longValue()) / 1000;
 	    if (timeInterval > 5) {
-	    	log.warn("TimeCost Warning! requesterIp=" +ip+ "timeCost=" +timeInterval + "s, API=" + handleType + ", Param=" + jsonString);
+	    	log.warn("TimeCost Warning! requesterIp=" +ip+ "timeCost=" +timeInterval + "s, API=" + handleType + ", Param=" + param);
 	    }
 	    
 	    return apiResult;

+ 3 - 1
src/main/java/com/persagy/functions/common/business/HelloWorld.java

@@ -1,5 +1,7 @@
 package com.persagy.functions.common.business;
 
+import java.util.Map;
+
 import org.springframework.stereotype.Service;
 
 import com.persagy.framework.construct.RequestProcessor;
@@ -8,7 +10,7 @@ import com.persagy.framework.construct.RequestProcessor;
 public class HelloWorld implements RequestProcessor {
 
 	@Override
-	public Object handle(String jsonString) throws Exception {
+	public Object handle(Map<String, Object> paramMap) throws Exception {
 		return "helloworld!";
 	}
 

+ 2 - 6
src/main/java/com/persagy/functions/common/business/HelloWorld2.java

@@ -1,6 +1,5 @@
 package com.persagy.functions.common.business;
 
-import java.util.HashMap;
 import java.util.Map;
 
 import org.springframework.stereotype.Service;
@@ -11,11 +10,8 @@ import com.persagy.framework.construct.RequestProcessor;
 public class HelloWorld2 implements RequestProcessor {
 
 	@Override
-	public Object handle(String jsonString) throws Exception {
-		Map<String, String> data = new HashMap<>();
-		data.put("hello", "world");
-		
-		return data;
+	public Object handle(Map<String, Object> paramMap) throws Exception {
+		return paramMap;
 	}
 
 }

+ 1 - 1
src/main/java/com/persagy/functions/common/business/HelloWorld3.java

@@ -13,7 +13,7 @@ import com.persagy.framework.construct.RequestProcessor;
 public class HelloWorld3 implements RequestProcessor {
 
 	@Override
-	public Object handle(String jsonString) throws Exception {
+	public Object handle(Map<String, Object> paramMap) throws Exception {
 		List<Map<String, String>> list = new ArrayList<>();
 		for(int i=0; i<5; i++) {
 			Map<String, String> item = new HashMap<>();