|
|
|
@ -6,9 +6,12 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
@ -28,12 +31,14 @@ import com.glxp.sale.common.res.BaseResponse;
|
|
|
|
|
/**
|
|
|
|
|
* 中继服务接口
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@RestController
|
|
|
|
|
public class IdcController {
|
|
|
|
|
@Resource
|
|
|
|
|
IdcService idcService;
|
|
|
|
|
@Resource
|
|
|
|
|
DbDao dbDao;
|
|
|
|
|
|
|
|
|
|
/*通用上传接口*/
|
|
|
|
|
//@Log("中继服务数据接收,下级往上级上传")
|
|
|
|
|
@RequestMapping(value = "/spssync/common/upload")
|
|
|
|
@ -41,8 +46,9 @@ public class IdcController {
|
|
|
|
|
@RequestParam("content") String content,
|
|
|
|
|
@RequestParam(value = "files", required = false) MultipartFile[] files) {
|
|
|
|
|
//
|
|
|
|
|
return idcService.receive("U",request, content, files);
|
|
|
|
|
return idcService.receive("U", request, content, files);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*通用下发接口*/
|
|
|
|
|
//@Log("中继服务数据接收,上级往下级下发")
|
|
|
|
|
@RequestMapping(value = "/spssync/common/issued")
|
|
|
|
@ -50,57 +56,57 @@ public class IdcController {
|
|
|
|
|
@RequestParam("content") String content,
|
|
|
|
|
@RequestParam(value = "files", required = false) MultipartFile[] files) {
|
|
|
|
|
//
|
|
|
|
|
return idcService.receive("I",request, content, files);
|
|
|
|
|
return idcService.receive("I", request, content, files);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//@Log("数据同步测试")
|
|
|
|
|
@RequestMapping(value = "/spssync/common/test")
|
|
|
|
|
public BaseResponse test(HttpServletRequest request,@RequestBody Map<String, Object> params) {
|
|
|
|
|
public BaseResponse test(HttpServletRequest request, @RequestBody Map<String, Object> params) {
|
|
|
|
|
//
|
|
|
|
|
return idcService.send(params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//@Log("数据同步任务列表拉取")
|
|
|
|
|
@RequestMapping(value = "/spssync/common/list")
|
|
|
|
|
public BaseResponse list(HttpServletRequest request,@RequestBody(required = false) Map<String, Object> params) {
|
|
|
|
|
return idcService.taskList(request,params);
|
|
|
|
|
public BaseResponse list(HttpServletRequest request, @RequestBody(required = false) Map<String, Object> params) {
|
|
|
|
|
return idcService.taskList(request, params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//@Log("数据同步任务根据任务ID下载数据")
|
|
|
|
|
@RequestMapping(value = "/spssync/common/download")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public BaseResponse download(HttpServletRequest request,@RequestBody Map<String, Object> params) {
|
|
|
|
|
return idcService.download(request,params);
|
|
|
|
|
public BaseResponse download(HttpServletRequest request, @RequestBody Map<String, Object> params) {
|
|
|
|
|
return idcService.download(request, params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//@Log("数据同步任务根据任务ID,返回下载成功标记")
|
|
|
|
|
@RequestMapping(value = "/spssync/common/success")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public BaseResponse success(HttpServletRequest request,@RequestBody Map<String, Object> params) {
|
|
|
|
|
return idcService.downlaodSuccess(request,params);
|
|
|
|
|
public BaseResponse success(HttpServletRequest request, @RequestBody Map<String, Object> params) {
|
|
|
|
|
return idcService.downlaodSuccess(request, params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/mapi/**")
|
|
|
|
|
public JSONObject mapi(HttpServletRequest request) {
|
|
|
|
|
public Object mapi(HttpServletRequest request) {
|
|
|
|
|
String uri = parseUri(request.getRequestURL().toString());
|
|
|
|
|
|
|
|
|
|
return redirect(request);
|
|
|
|
|
if (uri.contains("image")) {
|
|
|
|
|
return redirectIamge(request, uri);
|
|
|
|
|
} else {
|
|
|
|
|
return redirect(request, uri);
|
|
|
|
|
}
|
|
|
|
|
@RequestMapping("/zapi/**")
|
|
|
|
|
public JSONObject zapi(HttpServletRequest request) {
|
|
|
|
|
|
|
|
|
|
return redirect(request);
|
|
|
|
|
}
|
|
|
|
|
private JSONObject redirect(HttpServletRequest request) {
|
|
|
|
|
String uri = parseUri(request.getRequestURL().toString());
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String,Object> headerParam = new HashMap<>();
|
|
|
|
|
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);
|
|
|
|
|
HttpEntity<String> buildHeader(HttpServletRequest request) {
|
|
|
|
|
|
|
|
|
|
log.info(request.getMethod());
|
|
|
|
|
Map<String, Object> headerParam = new HashMap<>();
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
@ -111,28 +117,80 @@ public class IdcController {
|
|
|
|
|
headerParam.put(name, value);
|
|
|
|
|
headers.add(name, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//headers.add("Content-Type", "application/json;charset=UTF-8");
|
|
|
|
|
HttpEntity<String> http = new HttpEntity<>(JSON.toJSONString(bodyParam), headers);
|
|
|
|
|
return http;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.print(JSON.toJSONString(headerParam));
|
|
|
|
|
System.out.print(JSON.toJSONString(bodyParam));
|
|
|
|
|
private Resource redirectIamge(HttpServletRequest request, String uri) {
|
|
|
|
|
uri = uri.replace("mapi/", "");
|
|
|
|
|
uri = "http://127.0.0.1:9993/" + uri;
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
// HttpEntity<String> httpEntity = buildHeader(request);
|
|
|
|
|
log.info(request.getMethod());
|
|
|
|
|
Map<String, Object> headerParam = new HashMap<>();
|
|
|
|
|
Map<String, Object> bodyParam = new HashMap<String, Object>();
|
|
|
|
|
Enumeration pNames = request.getParameterNames();
|
|
|
|
|
String parm = "";
|
|
|
|
|
while (pNames.hasMoreElements()) {
|
|
|
|
|
String name = (String) pNames.nextElement();
|
|
|
|
|
String value = request.getParameter(name);
|
|
|
|
|
bodyParam.put(name, value);
|
|
|
|
|
parm = parm + name + "=" + value + "&";
|
|
|
|
|
}
|
|
|
|
|
uri = uri + "?" + parm.substring(0, parm.length() - 1);
|
|
|
|
|
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<>(JSON.toJSONString(bodyParam), headers);
|
|
|
|
|
ResponseEntity<JSONObject> responseBody = restTemplate.postForEntity("http://127.0.0.1:8090/"+uri, http, JSONObject.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info(uri);
|
|
|
|
|
// ResponseEntity<Resource> entity = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, Resource.class);
|
|
|
|
|
ResponseEntity<Resource> responseEntity = restTemplate.exchange(uri,
|
|
|
|
|
HttpMethod.GET, http, Resource.class, new Object[0]);
|
|
|
|
|
// ResponseEntity<HttpServletResponse> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, http, HttpServletResponse.class);
|
|
|
|
|
return responseEntity.getBody();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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://127.0.0.1:9993/" + uri;
|
|
|
|
|
log.info(uri);
|
|
|
|
|
ResponseEntity<JSONObject> responseBody = null;
|
|
|
|
|
if (request.getMethod().equals("POST"))
|
|
|
|
|
responseBody = restTemplate.postForEntity(uri, httpEntity, JSONObject.class);
|
|
|
|
|
else if (request.getMethod().equals("GET")) {
|
|
|
|
|
responseBody = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, JSONObject.class);
|
|
|
|
|
} else if (request.getMethod().equals("PUT")) {
|
|
|
|
|
responseBody = restTemplate.exchange(uri, HttpMethod.PUT, httpEntity, JSONObject.class);
|
|
|
|
|
} else if (request.getMethod().equals("DELETE")) {
|
|
|
|
|
responseBody = restTemplate.exchange(uri, HttpMethod.DELETE, httpEntity, JSONObject.class);
|
|
|
|
|
}
|
|
|
|
|
JSONObject result = responseBody.getBody();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
if (a1 > 0) {
|
|
|
|
|
a2 = uri.indexOf("/", a1 + 4);
|
|
|
|
|
if (a2 > 0) {
|
|
|
|
|
uri = uri.substring(a2 + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return uri;
|
|
|
|
|