Merge branch 'dev' into test

test
wj 2 years ago
commit d22a9f388f

@ -1,15 +1,14 @@
package com.glxp.sale.admin.controller.sync; package com.glxp.sale.admin.controller.sync;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.glxp.sale.admin.constant.*; import com.glxp.sale.admin.constant.*;
import com.glxp.sale.admin.dto.RelaySyncDto;
import com.glxp.sale.admin.entity.param.SystemParamConfigEntity; import com.glxp.sale.admin.entity.param.SystemParamConfigEntity;
import com.glxp.sale.admin.entity.sync.*; import com.glxp.sale.admin.entity.sync.BasicExportStatusEntity;
import com.glxp.sale.admin.entity.sync.BasicUploadStatusEntity;
import com.glxp.sale.admin.http.SpGetHttp; import com.glxp.sale.admin.http.SpGetHttp;
import com.glxp.sale.admin.http.SpPostHttp; import com.glxp.sale.admin.http.SpPostHttp;
import com.glxp.sale.admin.idc.utils.UriUtils; import com.glxp.sale.admin.idc.utils.UriUtils;
@ -257,7 +256,7 @@ public class SpsSyncDataController {
throw new RuntimeException("系统异常,文件名为空"); throw new RuntimeException("系统异常,文件名为空");
} }
relaySyncResponse = RelaySyncResponse.builder() relaySyncResponse = RelaySyncResponse.builder()
.taskId(one.getId()) .taskId(one.getTaskId())
.fileContent(this.readDataFile(one.getCacheFilePath())) .fileContent(this.readDataFile(one.getCacheFilePath()))
.build(); .build();
} }

@ -16,10 +16,6 @@ import com.glxp.sale.admin.idc.service.FileService;
import com.glxp.sale.common.res.BaseResponse; import com.glxp.sale.common.res.BaseResponse;
/** /**
* *
*/ */
@ -32,30 +28,28 @@ public class FileController {
@RequestMapping(value = "/spssync/file/upload") @RequestMapping(value = "/spssync/file/upload")
@ResponseBody @ResponseBody
public BaseResponse upload(HttpServletRequest request, @RequestBody Map<String, Object> params) { public BaseResponse upload(HttpServletRequest request, @RequestBody Map<String, Object> params) {
return fileService.fileUpload(request,params); return fileService.fileUpload(request, params);
} }
@RequestMapping(value = "/spssync/file/download") @RequestMapping(value = "/spssync/file/download")
@ResponseBody @ResponseBody
public BaseResponse download(HttpServletRequest request, @RequestBody Map<String, Object> params) { public BaseResponse download(HttpServletRequest request, @RequestBody Map<String, Object> params) {
return fileService.fileDownload(request,params); return fileService.fileDownload(request, params);
} }
@RequestMapping(value = "/spssync/file/downloadFile") @RequestMapping(value = "/spssync/file/downloadFile")
@ResponseBody @ResponseBody
public BaseResponse downloadFile(HttpServletRequest request, @RequestBody Map<String, Object> params) { public BaseResponse downloadFile(HttpServletRequest request, @RequestBody Map<String, Object> params) {
return fileService.downloadFile(request,params); return fileService.downloadFile(request, params);
} }
@RequestMapping(value = "/spssync/file/uploadFile") @RequestMapping(value = "/spssync/file/uploadFile")
public BaseResponse uploadFile(HttpServletRequest request, public BaseResponse uploadFile(HttpServletRequest request,
@RequestParam(value = "content" , required = false) String content, @RequestParam(value = "content", required = false) String content,
@RequestParam(value = "files", required = false) MultipartFile[] files) { @RequestParam(value = "files", required = false) MultipartFile[] files) {
// //
return fileService.receiveFile(request, content, files); return fileService.receiveFile(request, content, files);
} }
} }

@ -1,37 +1,37 @@
package com.glxp.sale.admin.idc.controller; package com.glxp.sale.admin.idc.controller;
import java.io.UnsupportedEncodingException; import cn.hutool.core.util.StrUtil;
import java.net.URLEncoder; import cn.hutool.http.HttpRequest;
import java.util.Enumeration; import cn.hutool.http.HttpResponse;
import java.util.HashMap; import cn.hutool.http.HttpUtil;
import java.util.Map;
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 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.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.glxp.sale.admin.idc.dao.DbDao; import com.glxp.sale.admin.idc.dao.DbDao;
import com.glxp.sale.admin.idc.service.IdcService; import com.glxp.sale.admin.idc.service.IdcService;
import com.glxp.sale.admin.idc.utils.UriUtils; import com.glxp.sale.admin.idc.utils.UriUtils;
import com.glxp.sale.admin.service.param.SystemParamConfigService; import com.glxp.sale.admin.service.param.SystemParamConfigService;
import com.glxp.sale.admin.util.MyStrUtil;
import com.glxp.sale.common.res.BaseResponse; import com.glxp.sale.common.res.BaseResponse;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j; 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.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
/** /**
@ -149,6 +149,7 @@ public class IdcController {
if (StrUtil.isNotEmpty(upperServerHost)) { if (StrUtil.isNotEmpty(upperServerHost)) {
uri = upperServerHost + "/" + uri; uri = upperServerHost + "/" + uri;
} }
uri = changeUri(uri);
log.info(uri); log.info(uri);
if (uri.contains("getImage")) { if (uri.contains("getImage")) {
return redirectIamge(request, httpServletResponse, uri); return redirectIamge(request, httpServletResponse, uri);
@ -157,6 +158,67 @@ public class IdcController {
} }
} }
// @RequestMapping("/dirImages/**")
// public void images(HttpServletRequest request, HttpServletResponse httpServletResponse) {
// String uri = uriUtils.parseUri(request.getRequestURL().toString());
//
// log.info(uri);
// String imageHost = "http://192.168.0.66:9000";
// String url = "";
//// systemParamConfigService.selectValueByParamKey("is_top_service");
// if (StrUtil.isNotEmpty(imageHost)) {
// String prefix = "dirImages/";
// url = (imageHost.substring(imageHost.length() - 1) == "/" ? imageHost : imageHost + "/")
// + uri.substring(uri.indexOf(prefix) + prefix.length());
//
// }
// log.info(url);
// redirectIamge2(request, httpServletResponse, url);
// }
public String changeUri(String uri) {
String isTopService = systemParamConfigService.selectValueByParamKey("is_top_service");
if (StrUtil.isNotEmpty(isTopService) && isTopService.equals("1")) {
if (uri.contains("SP_SYNC_SERVER")) {
uri = uri.replace("SP_SYNC_SERVER/", "");
}
} else {
uri = MyStrUtil.deDup(uri);
}
log.error("changeUri = " + uri);
return uri;
}
private void redirectIamge2(HttpServletRequest request, HttpServletResponse httpServletResponse, String uri) {
HttpRequest result = HttpUtil.createGet(uri);
HttpResponse execute = result.execute();
execute.headers().forEach((k, v) -> {
httpServletResponse.setHeader(k, v.get(0));
});
ServletOutputStream outputStream = null;
InputStream inputStream = null;
try {
outputStream = httpServletResponse.getOutputStream();
inputStream = execute.bodyStream();
outputStream.write(inputStream.readAllBytes());
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
if (outputStream != null)
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
if (inputStream != null)
inputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
private byte[] redirectIamge(HttpServletRequest request, HttpServletResponse httpServletResponse, String uri) { private byte[] redirectIamge(HttpServletRequest request, HttpServletResponse httpServletResponse, String uri) {
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();

@ -46,7 +46,7 @@ public class FileServiceImpl implements FileService {
private String apiKey; private String apiKey;
@Value("${API_SECRET}") @Value("${API_SECRET}")
private String apiSecret; private String apiSecret;
@Resource @Resource
private DbDao dbDao; private DbDao dbDao;
@Resource @Resource
@ -60,7 +60,7 @@ public class FileServiceImpl implements FileService {
if(map!=null&&map.get("syncIp")!=null) if(map!=null&&map.get("syncIp")!=null)
host = map.get("syncIp").toString(); host = map.get("syncIp").toString();
} catch (Exception ex) { } catch (Exception ex) {
} }
if(StringUtils.isEmpty(host)) { if(StringUtils.isEmpty(host)) {
try { try {
@ -68,7 +68,7 @@ public class FileServiceImpl implements FileService {
if(config!=null&&config.get("paramValue")!=null) if(config!=null&&config.get("paramValue")!=null)
host = config.get("paramValue").toString(); host = config.get("paramValue").toString();
} catch (Exception ex) { } catch (Exception ex) {
} }
} }
if(StringUtils.isEmpty(host)) if(StringUtils.isEmpty(host))
@ -96,9 +96,9 @@ public class FileServiceImpl implements FileService {
} }
return ResultVOUtils.error(9999,"失败"); return ResultVOUtils.error(9999,"失败");
} }
@Override @Override
public BaseResponse fileDownload(HttpServletRequest request,Map<String,Object> params) { public BaseResponse fileDownload(HttpServletRequest request,Map<String,Object> params) {
Map<String, Object> map = dbDao.get("select * from sync_data_set limit 1"); Map<String, Object> map = dbDao.get("select * from sync_data_set limit 1");
@ -109,7 +109,7 @@ public class FileServiceImpl implements FileService {
} }
return ResultVOUtils.success(null); return ResultVOUtils.success(null);
} }
@Override @Override
public BaseResponse receiveFile(HttpServletRequest request,String content,MultipartFile[] files) { public BaseResponse receiveFile(HttpServletRequest request,String content,MultipartFile[] files) {
boolean isRelay = false; boolean isRelay = false;
@ -121,9 +121,9 @@ public class FileServiceImpl implements FileService {
isRelay = true; isRelay = true;
host = config.get("paramValue").toString(); host = config.get("paramValue").toString();
} }
} catch (Exception ex) { } catch (Exception ex) {
} }
ArrayList<String> saveFiles = new ArrayList<>(); ArrayList<String> saveFiles = new ArrayList<>();
Date startTime = new Date(); Date startTime = new Date();
@ -157,12 +157,12 @@ public class FileServiceImpl implements FileService {
} }
return ResultVOUtils.success(null); return ResultVOUtils.success(null);
} }
/*转发图片*/ /*转发图片*/
private String relayFile(ArrayList<String> files, String ip) { private String relayFile(ArrayList<String> files, String ip) {
String host = ip; String host = ip;
String result = ""; String result = "";
if (!StringUtils.isEmpty(host)) { if (!StringUtils.isEmpty(host)) {
host += "/spssync/file/uploadFile"; host += "/spssync/file/uploadFile";
OkHttpClient client = new OkHttpClient().newBuilder() OkHttpClient client = new OkHttpClient().newBuilder()
@ -185,7 +185,7 @@ public class FileServiceImpl implements FileService {
} }
} }
} }
RequestBody body = builder.build(); RequestBody body = builder.build();
Request req = new Request.Builder() Request req = new Request.Builder()
@ -211,8 +211,8 @@ public class FileServiceImpl implements FileService {
} }
return result; return result;
} }
@Override @Override
public BaseResponse downloadFile(HttpServletRequest request,Map<String,Object> params) { public BaseResponse downloadFile(HttpServletRequest request,Map<String,Object> params) {
String host = ""; String host = "";
@ -221,11 +221,11 @@ public class FileServiceImpl implements FileService {
if(config!=null&&config.get("paramValue")!=null) if(config!=null&&config.get("paramValue")!=null)
host = config.get("paramValue").toString(); host = config.get("paramValue").toString();
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace();
} }
if(!StringUtils.isEmpty(host)) { if(!StringUtils.isEmpty(host)) {
String result = IDCUtils.post(host+"/spssync/file/downloadFile", params); String result = IDCUtils.post(host+"/spssync/file/downloadFile", params);
JSONObject object = JSON.parseObject(result); JSONObject object = JSON.parseObject(result);
boolean success = false; boolean success = false;
if(object.getInteger("code")==20000) { if(object.getInteger("code")==20000) {
@ -237,10 +237,10 @@ public class FileServiceImpl implements FileService {
} }
} }
if(!success) if(!success)
ResultVOUtils.error(9999,"失败"); ResultVOUtils.error(9999,"失败");
} }
return ResultVOUtils.success(null); return ResultVOUtils.success(null);
} }
} }

@ -8,7 +8,7 @@ import lombok.Getter;
@Getter @Getter
public enum ResultEnum { public enum ResultEnum {
SUCCESS(0, "success"), SUCCESS(20000, "success"),
NOT_NETWORK(1, "系统繁忙,请稍后再试。"), NOT_NETWORK(1, "系统繁忙,请稍后再试。"),
LOGIN_VERIFY_FALL(2, "登录失效"), LOGIN_VERIFY_FALL(2, "登录失效"),
PARAM_VERIFY_FALL(3, "参数验证错误"), PARAM_VERIFY_FALL(3, "参数验证错误"),

@ -18,7 +18,7 @@ public class ResultVOUtils {
*/ */
public static BaseResponse success(Object data) { public static BaseResponse success(Object data) {
BaseResponse<Object> baseResponse = new BaseResponse<>(); BaseResponse<Object> baseResponse = new BaseResponse<>();
baseResponse.setCode(20000); baseResponse.setCode(ResultEnum.SUCCESS.getCode());
baseResponse.setMessage("success"); baseResponse.setMessage("success");
baseResponse.setData(data); baseResponse.setData(data);
return baseResponse; return baseResponse;

Loading…
Cancel
Save