From cbc1f9db3d796683d88d6d30df3659984dfbeda3 Mon Sep 17 00:00:00 2001
From: webapp <webapp@home-server.attdns.com>
Date: 星期一, 30 九月 2019 22:56:12 +0800
Subject: [PATCH] 取消java110-common jar包,提升为CommonService服务,将之前的Java110-common内容变更为Java110-utils包
---
WebService/src/main/java/com/java110/web/controller/CallComponentController.java | 128 ++++++++++++++++++++++++++++++++++++------
1 files changed, 110 insertions(+), 18 deletions(-)
diff --git a/WebService/src/main/java/com/java110/web/controller/CallComponentController.java b/WebService/src/main/java/com/java110/web/controller/CallComponentController.java
index 223e674..fed9afc 100644
--- a/WebService/src/main/java/com/java110/web/controller/CallComponentController.java
+++ b/WebService/src/main/java/com/java110/web/controller/CallComponentController.java
@@ -1,23 +1,24 @@
package com.java110.web.controller;
-import com.java110.common.constant.CommonConstant;
-import com.java110.common.exception.SMOException;
-import com.java110.common.factory.ApplicationContextFactory;
-import com.java110.common.util.Assert;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.utils.constant.CommonConstant;
+import com.java110.utils.exception.SMOException;
+import com.java110.utils.factory.ApplicationContextFactory;
+import com.java110.utils.util.Assert;
import com.java110.core.base.controller.BaseController;
import com.java110.core.context.IPageData;
-import com.java110.web.smo.impl.LoginServiceSMOImpl;
+import com.java110.core.context.PageData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
-import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Map;
/**
@@ -30,15 +31,16 @@
/**
* 璋冪敤缁勪欢鏂规硶
+ *
* @return
*/
- @RequestMapping(path="/callComponent/{componentCode}/{componentMethod}")
+ @RequestMapping(path = "/callComponent/{componentCode}/{componentMethod}")
public ResponseEntity<String> callComponent(
@PathVariable String componentCode,
@PathVariable String componentMethod,
//@RequestBody String info,
- HttpServletRequest request){
+ HttpServletRequest request) {
ResponseEntity<String> responseEntity = null;
try {
Assert.hasLength(componentCode, "鍙傛暟閿欒锛屾湭浼犲叆缁勪欢缂栫爜");
@@ -58,26 +60,116 @@
responseEntity = (ResponseEntity<String>) cMethod.invoke(componentInstance, pd);
- }catch (SMOException e){
- MultiValueMap<String, String> headers = new HttpHeaders();
- headers.add("code",e.getResult().getCode());
- responseEntity = new ResponseEntity<>(e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR);
- }catch (Exception e){
+ } catch (SMOException e) {
+ /*MultiValueMap<String, String> headers = new HttpHeaders();
+ headers.add("code", e.getResult().getCode());*/
+ responseEntity = new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ } catch (Exception e) {
String msg = "";
if (e instanceof InvocationTargetException) {
- Throwable targetEx =((InvocationTargetException)e).getTargetException();
+ Throwable targetEx = ((InvocationTargetException) e).getTargetException();
if (targetEx != null) {
msg = targetEx.getMessage();
}
} else {
msg = e.getMessage();
}
- responseEntity = new ResponseEntity<>(msg,HttpStatus.INTERNAL_SERVER_ERROR);
- }finally {
- logger.debug("缁勪欢璋冪敤杩斿洖淇℃伅涓簕}",responseEntity);
+ responseEntity = new ResponseEntity<>(msg, HttpStatus.INTERNAL_SERVER_ERROR);
+ } finally {
+ logger.debug("缁勪欢璋冪敤杩斿洖淇℃伅涓簕}", responseEntity);
return responseEntity;
}
}
+ //缁勪欢涓婁紶鏂囦欢澶勭悊/callComponent/upload/
+
+ /**
+ * 璋冪敤缁勪欢 鏂囦欢涓婁紶
+ * /callComponent/upload/assetImport/importData
+ *
+ * @return
+ */
+
+ @RequestMapping(path = "/callComponent/upload/{componentCode}/{componentMethod}")
+ public ResponseEntity<String> callComponentUploadFile(
+ @PathVariable String componentCode,
+ @PathVariable String componentMethod,
+ @RequestParam("uploadFile") MultipartFile uploadFile,
+ //@RequestBody String info,
+ HttpServletRequest request) {
+ ResponseEntity<String> responseEntity = null;
+ Map formParam = null;
+ IPageData pd = null;
+ try {
+ Assert.hasLength(componentCode, "鍙傛暟閿欒锛屾湭浼犲叆缁勪欢缂栫爜");
+ Assert.hasLength(componentMethod, "鍙傛暟閿欒锛屾湭浼犲叆璋冪敤缁勪欢鏂规硶");
+
+ Object componentInstance = ApplicationContextFactory.getBean(componentCode);
+
+ Assert.notNull(componentInstance, "鏈壘鍒扮粍浠跺搴旂殑澶勭悊绫伙紝璇风‘璁� " + componentCode);
+
+ Method cMethod = componentInstance.getClass().getDeclaredMethod(componentMethod, IPageData.class, MultipartFile.class);
+
+ Assert.notNull(cMethod, "鏈壘鍒扮粍浠跺搴斿鐞嗙被鐨勬柟娉曪紝璇风‘璁� " + componentCode + "鏂规硶锛�" + componentMethod);
+ pd = freshPageDate(request);
+
+ logger.debug("缁勪欢缂栫爜{}锛岀粍浠舵柟娉晎}锛宲d 涓簕}", componentCode, componentMethod, pd.toString());
+
+ responseEntity = (ResponseEntity<String>) cMethod.invoke(componentInstance, pd, uploadFile);
+
+ } catch (SMOException e) {
+ logger.error("缁勪欢杩愯寮傚父",e);
+ /*MultiValueMap<String, String> headers = new HttpHeaders();
+ headers.add("code", e.getResult().getCode());*/
+ responseEntity = new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ } catch (Exception e) {
+ logger.error("缁勪欢杩愯寮傚父",e);
+ String msg = "";
+ if (e instanceof InvocationTargetException) {
+ Throwable targetEx = ((InvocationTargetException) e).getTargetException();
+ if (targetEx != null) {
+ msg = targetEx.getMessage();
+ }
+ } else {
+ msg = e.getMessage();
+ }
+ responseEntity = new ResponseEntity<>(msg, HttpStatus.INTERNAL_SERVER_ERROR);
+ } finally {
+ logger.debug("缁勪欢璋冪敤杩斿洖淇℃伅涓簕}", responseEntity);
+ return responseEntity;
+ }
+ }
+
+ /**
+ * 鍒锋柊 pd 瀵硅薄
+ *
+ * @param request HttpServletRequest 瀵硅薄
+ * @return pd 瀵硅薄
+ */
+ private IPageData freshPageDate(HttpServletRequest request) {
+ Map<String, String[]> params = request.getParameterMap();
+ IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA);
+ String reqData = "";
+ if (params != null && !params.isEmpty()) {
+ JSONObject paramObj = new JSONObject();
+ for (String key : params.keySet()) {
+ if (params.get(key).length > 0) {
+ String value = "";
+ for (int paramIndex = 0; paramIndex < params.get(key).length; paramIndex++) {
+ value = params.get(key)[paramIndex] + ",";
+ }
+ value = value.endsWith(",") ? value.substring(0, value.length() - 1) : value;
+ paramObj.put(key, value);
+ }
+ continue;
+ }
+ reqData = paramObj.toJSONString();
+ }
+
+ IPageData newPd = PageData.newInstance().builder(pd.getUserId(), pd.getToken(),
+ reqData, pd.getComponentCode(), pd.getComponentMethod(), "", pd.getSessionId());
+ return newPd;
+ }
+
}
--
Gitblit v1.8.0