|
|
|
@ -1,8 +1,7 @@
|
|
|
|
|
package com.glxp.api.idc.controller;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
@ -28,8 +27,10 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
|
import com.glxp.api.dao.idc.DbDao;
|
|
|
|
|
import com.glxp.api.idc.service.IdcService;
|
|
|
|
|
import com.glxp.api.idc.utils.UriUtils;
|
|
|
|
|
import com.glxp.api.service.system.SystemParamConfigService;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -43,6 +44,8 @@ public class IdcController {
|
|
|
|
|
IdcService idcService;
|
|
|
|
|
@Resource
|
|
|
|
|
DbDao dbDao;
|
|
|
|
|
@Resource
|
|
|
|
|
UriUtils uriUtils;
|
|
|
|
|
|
|
|
|
|
/*通用上传接口*/
|
|
|
|
|
//@Log("中继服务数据接收,下级往上级上传")
|
|
|
|
@ -51,10 +54,10 @@ public class IdcController {
|
|
|
|
|
@RequestParam("content") String content,
|
|
|
|
|
@RequestParam(value = "files", required = false) MultipartFile[] files) {
|
|
|
|
|
//
|
|
|
|
|
return idcService.receive( request, content, files);
|
|
|
|
|
return idcService.receive(request, content, files);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//@Log("数据同步测试")
|
|
|
|
|
@RequestMapping(value = "/spssync/common/test")
|
|
|
|
|
public BaseResponse test(HttpServletRequest request, @RequestBody Map<String, Object> params) {
|
|
|
|
@ -83,10 +86,31 @@ public class IdcController {
|
|
|
|
|
return idcService.downlaodSuccess(request, params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/spssync/common/downloadFile")
|
|
|
|
|
public void downloadFile(HttpServletResponse response,@RequestParam String fileName) throws UnsupportedEncodingException {
|
|
|
|
|
if (fileName != null) {
|
|
|
|
|
response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
|
|
|
|
response.setContentType("application/force-download");
|
|
|
|
|
idcService.downloadFile(fileName, response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/mapi/**")
|
|
|
|
|
public Object mapi(HttpServletRequest request, HttpServletResponse httpServletResponse) {
|
|
|
|
|
String uri = parseUri(request.getRequestURL().toString());
|
|
|
|
|
String uri = uriUtils.parseUri(request.getRequestURL().toString());
|
|
|
|
|
|
|
|
|
|
log.info(uri);
|
|
|
|
|
String isTopService = systemParamConfigService.selectValueByParamKey("is_top_service");
|
|
|
|
|
if (StrUtil.isNotEmpty(isTopService) && isTopService.equals("1")) {
|
|
|
|
|
uri = uri.replace("mapi/", "");
|
|
|
|
|
}
|
|
|
|
|
String upperServerHost = systemParamConfigService.selectValueByParamKey("upper_server_host");
|
|
|
|
|
if (StrUtil.isNotEmpty(upperServerHost)) {
|
|
|
|
|
uri = upperServerHost + "/" + uri;
|
|
|
|
|
}
|
|
|
|
|
log.info(uri);
|
|
|
|
|
if (uri.contains("getImage")) {
|
|
|
|
|
return redirectIamge(request, httpServletResponse, uri);
|
|
|
|
|
} else {
|
|
|
|
@ -95,51 +119,7 @@ public class IdcController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HttpEntity<String> buildHeader(HttpServletRequest request) {
|
|
|
|
|
|
|
|
|
|
log.info(request.getMethod());
|
|
|
|
|
|
|
|
|
|
String bodyContent = "";
|
|
|
|
|
Map<String, Object> headerParam = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
if (request.getMethod().equals(HttpMethod.GET)) {
|
|
|
|
|
Map<String, Object> bodyParam = new HashMap<String, Object>();
|
|
|
|
|
Enumeration pNames = request.getParameterNames();
|
|
|
|
|
while (pNames.hasMoreElements()) {
|
|
|
|
|
String name = (String) pNames.nextElement();
|
|
|
|
|
String value = request.getParameter(name);
|
|
|
|
|
bodyParam.put(name, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bodyContent = JSON.toJSONString(bodyParam);
|
|
|
|
|
} else {
|
|
|
|
|
BufferedReader reader = null;
|
|
|
|
|
try {
|
|
|
|
|
reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
|
|
|
|
|
bodyContent = IoUtil.read(reader);
|
|
|
|
|
log.info(bodyContent);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
Enumeration<String> enumeration = request.getHeaderNames();
|
|
|
|
|
while (enumeration.hasMoreElements()) {
|
|
|
|
|
String name = enumeration.nextElement();
|
|
|
|
|
String value = request.getHeader(name);
|
|
|
|
|
headerParam.put(name, value);
|
|
|
|
|
headers.add(name, value);
|
|
|
|
|
}
|
|
|
|
|
//headers.add("Content-Type", "application/json;charset=UTF-8");
|
|
|
|
|
HttpEntity<String> http = new HttpEntity<>(bodyContent, headers);
|
|
|
|
|
return http;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private byte[] redirectIamge(HttpServletRequest request, HttpServletResponse httpServletResponse, String uri) {
|
|
|
|
|
uri = uri.replace("mapi/", "");
|
|
|
|
|
uri = "http://116.204.106.103:9150/UDI_SPMS_SERVER/" + uri;
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
// HttpEntity<String> httpEntity = buildHeader(request);
|
|
|
|
|
log.info(request.getMethod());
|
|
|
|
@ -186,14 +166,14 @@ public class IdcController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
SystemParamConfigService systemParamConfigService;
|
|
|
|
|
|
|
|
|
|
private JSONObject redirect(HttpServletRequest request, String uri) {
|
|
|
|
|
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
HttpEntity<String> httpEntity = buildHeader(request);
|
|
|
|
|
log.info(uri);
|
|
|
|
|
uri = uri.replace("mapi/", "");
|
|
|
|
|
uri = "http://116.204.106.103:9150/UDI_SPMS_SERVER/" + uri;
|
|
|
|
|
log.info(uri);
|
|
|
|
|
HttpEntity<String> httpEntity = uriUtils.buildHeader(request);
|
|
|
|
|
|
|
|
|
|
ResponseEntity<JSONObject> responseBody = null;
|
|
|
|
|
if (request.getMethod().equals("POST"))
|
|
|
|
|
responseBody = restTemplate.postForEntity(uri, httpEntity, JSONObject.class);
|
|
|
|
@ -209,18 +189,4 @@ public class IdcController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String parseUri(String url) {
|
|
|
|
|
String uri = url;
|
|
|
|
|
int a1 = uri.indexOf("://");
|
|
|
|
|
int a2 = 0;
|
|
|
|
|
if (a1 > 0) {
|
|
|
|
|
a2 = uri.indexOf("/", a1 + 4);
|
|
|
|
|
if (a2 > 0) {
|
|
|
|
|
uri = uri.substring(a2 + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return uri;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|