Merge remote-tracking branch 'origin/master'

version1
admin 2 years ago
commit 9a5f78c42b

@ -1,17 +1,58 @@
package com.glxp.sale.admin.controller.sync;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.glxp.sale.admin.constant.BasicProcessStatus;
import com.glxp.sale.admin.constant.ConstantStatus;
import com.glxp.sale.admin.entity.sync.BasicExportStatusEntity;
import com.glxp.sale.admin.entity.sync.BasicUploadStatusEntity;
import com.glxp.sale.admin.idc.utils.UriUtils;
import com.glxp.sale.admin.service.param.SystemParamConfigService;
import com.glxp.sale.admin.service.sync.BasicExportService;
import com.glxp.sale.admin.service.sync.BasicUploadService;
import com.glxp.sale.admin.util.Constant;
import com.glxp.sale.admin.util.DateUtil;
import com.glxp.sale.admin.util.FileUtils;
import com.glxp.sale.admin.util.GennerOrderUtils;
import com.glxp.sale.common.res.BaseResponse;
import com.glxp.sale.common.util.ResultVOUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
/**
*
*
*/
@Slf4j
@RestController
public class SyncController {
@Resource
UriUtils uriUtils;
@Resource
SystemParamConfigService systemParamConfigService;
@Resource
private GennerOrderUtils gennerOrderUtils;
@Resource
private BasicUploadService basicUploadService;
@Value("${file_path}")
private String filePath;
@Resource
BasicExportService basicExportService;
/**
*
*
@ -22,5 +63,66 @@ public class SyncController {
return ResultVOUtils.success("连接成功");
}
//单据接口直连
@RequestMapping("/orderApi/**")
public Object orderApi(HttpServletRequest request, HttpServletResponse httpServletResponse) {
String uri = uriUtils.parseUri(request.getRequestURL().toString());
log.info(uri);
JSONObject jsonObject = redirect(request, uri);
return jsonObject;
}
private JSONObject redirect(HttpServletRequest request, String uri) {
RestTemplate restTemplate = new RestTemplate();
HttpEntity<String> httpEntity = uriUtils.buildHeader(request);
String taskId = request.getHeader("taskId");
ResponseEntity<JSONObject> responseBody = null;
if (request.getMethod().equals("POST")) {
//写入日志
writeUploadLog(taskId, httpEntity.getBody());
responseBody = restTemplate.postForEntity(uri, httpEntity, JSONObject.class);
} else if (request.getMethod().equals("GET")) {
writeDownloadLog(taskId, httpEntity.getBody());
responseBody = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, JSONObject.class);
}
JSONObject result = responseBody.getBody();
return result;
}
@Async
public void writeUploadLog(String taskId, String content) {
String key = gennerOrderUtils.getOrders();
BasicUploadStatusEntity basicUploadStatusEntity = new BasicUploadStatusEntity();
basicUploadStatusEntity.setId(key);
basicUploadStatusEntity.setTaskId(taskId);
basicUploadStatusEntity.setStartTime(DateUtil.getDateTime());
basicUploadStatusEntity.setIdDatas(ConstantStatus.SYNC_SCAN_ORDER);
basicUploadStatusEntity.setType(BasicProcessStatus.NEW_ALL_ORDER);
basicUploadStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
basicUploadService.insertDownloadStatus(basicUploadStatusEntity);
FileUtils.makeDirectory(filePath + "upload/");
String fileName = filePath + "upload/" + BasicProcessStatus.NEW_ALL_ORDER + "-" + taskId + ".udi";
FileUtils.SaveFileAs(content, fileName);
}
@Async
public void writeDownloadLog(String taskId, String content) {
String key = gennerOrderUtils.getOrders();
BasicExportStatusEntity myEntity = new BasicExportStatusEntity();
myEntity.setId(key);
myEntity.setUpdateTime(new Date());
myEntity.setType(BasicProcessStatus.NEW_ALL_DATA);
myEntity.setIdDatas(ConstantStatus.SYNC_SCAN_ORDER);
myEntity.setStartTime(DateUtil.getDateTime());
myEntity.setTaskId(taskId);
myEntity.setStatus(Constant.SYNC_STATUS_WAIT);
basicExportService.insertExportStatus(myEntity);
FileUtils.makeDirectory(filePath + "download/");
String fileName = filePath + "/download/" + BasicProcessStatus.NEW_ALL_ORDER + "-" + taskId + ".udi";
FileUtils.SaveFileAs(content, fileName);
}
}

@ -2,24 +2,39 @@ package com.glxp.sale.admin.idc.controller;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import com.glxp.sale.admin.idc.service.DownloadRestTemplate;
import com.glxp.sale.admin.idc.utils.UriUtils;
import com.glxp.sale.admin.service.param.SystemParamConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.*;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RequestCallback;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
@ -29,9 +44,6 @@ import com.glxp.sale.admin.idc.dao.DbDao;
import com.glxp.sale.admin.idc.service.IdcService;
import com.glxp.sale.common.res.BaseResponse;
import cn.hutool.core.io.IoUtil;
import lombok.extern.slf4j.Slf4j;
/**
*
@ -43,6 +55,8 @@ public class IdcController {
IdcService idcService;
@Resource
DbDao dbDao;
@Resource
UriUtils uriUtils;
/*通用上传接口*/
//@Log("中继服务数据接收,下级往上级上传")
@ -51,10 +65,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) {
@ -84,8 +98,18 @@ public class IdcController {
@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 {
@ -94,51 +118,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());
@ -185,14 +165,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);
@ -208,18 +188,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;
}
}

@ -0,0 +1,77 @@
package com.glxp.sale.admin.idc.utils;
import cn.hutool.core.io.IoUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Service
public class UriUtils {
public 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;
}
public 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;
}
}

@ -1 +1,7 @@
CALL Pro_Temp_ColumnWork ('basic_export_status','receiveStatus','varchar(255) ', 1);
CALL Pro_Temp_ColumnWork('basic_export_status', 'receiveStatus', 'varchar(255) ', 1);
INSERT ignore INTO `system_param_config`(`id`, `parentId`, `paramName`, `paramKey`, `paramValue`, `paramStatus`,
`paramType`, `paramExplain`)
VALUES (516, NULL, '是否顶级中继服务', 'is_top_service', '1', 1, 0, '0:否1');

Loading…
Cancel
Save