diff --git a/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SpsSyncDataController.java b/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SpsSyncDataController.java index 0142a40..2d270d4 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SpsSyncDataController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SpsSyncDataController.java @@ -1,15 +1,14 @@ package com.glxp.sale.admin.controller.sync; import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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.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.SpPostHttp; import com.glxp.sale.admin.idc.utils.UriUtils; @@ -257,7 +256,7 @@ public class SpsSyncDataController { throw new RuntimeException("系统异常,文件名为空"); } relaySyncResponse = RelaySyncResponse.builder() - .taskId(one.getId()) + .taskId(one.getTaskId()) .fileContent(this.readDataFile(one.getCacheFilePath())) .build(); } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/FileController.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/FileController.java index 2be613c..00dcc56 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/FileController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/FileController.java @@ -16,10 +16,6 @@ import com.glxp.sale.admin.idc.service.FileService; import com.glxp.sale.common.res.BaseResponse; - - - - /** * 中继服务接口 */ @@ -32,30 +28,28 @@ public class FileController { @RequestMapping(value = "/spssync/file/upload") @ResponseBody 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") @ResponseBody 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") @ResponseBody 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") public BaseResponse uploadFile(HttpServletRequest request, - @RequestParam(value = "content" , required = false) String content, - @RequestParam(value = "files", required = false) MultipartFile[] files) { + @RequestParam(value = "content", required = false) String content, + @RequestParam(value = "files", required = false) MultipartFile[] files) { // return fileService.receiveFile(request, content, files); } - - } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java index 6cf93fa..7994ed9 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java @@ -1,37 +1,37 @@ package com.glxp.sale.admin.idc.controller; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.Enumeration; -import java.util.HashMap; -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 cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.glxp.sale.admin.idc.dao.DbDao; import com.glxp.sale.admin.idc.service.IdcService; import com.glxp.sale.admin.idc.utils.UriUtils; import com.glxp.sale.admin.service.param.SystemParamConfigService; +import com.glxp.sale.admin.util.MyStrUtil; import com.glxp.sale.common.res.BaseResponse; - -import cn.hutool.core.util.StrUtil; 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)) { uri = upperServerHost + "/" + uri; } + uri = changeUri(uri); log.info(uri); if (uri.contains("getImage")) { 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) { RestTemplate restTemplate = new RestTemplate(); diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/FileServiceImpl.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/FileServiceImpl.java index 74bebd4..bdc492e 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/FileServiceImpl.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/FileServiceImpl.java @@ -46,7 +46,7 @@ public class FileServiceImpl implements FileService { private String apiKey; @Value("${API_SECRET}") private String apiSecret; - + @Resource private DbDao dbDao; @Resource @@ -60,7 +60,7 @@ public class FileServiceImpl implements FileService { if(map!=null&&map.get("syncIp")!=null) host = map.get("syncIp").toString(); } catch (Exception ex) { - + } if(StringUtils.isEmpty(host)) { try { @@ -68,7 +68,7 @@ public class FileServiceImpl implements FileService { if(config!=null&&config.get("paramValue")!=null) host = config.get("paramValue").toString(); } catch (Exception ex) { - + } } if(StringUtils.isEmpty(host)) @@ -96,9 +96,9 @@ public class FileServiceImpl implements FileService { } return ResultVOUtils.error(9999,"失败"); } - - - + + + @Override public BaseResponse fileDownload(HttpServletRequest request,Map<String,Object> params) { 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); } - + @Override public BaseResponse receiveFile(HttpServletRequest request,String content,MultipartFile[] files) { boolean isRelay = false; @@ -121,9 +121,9 @@ public class FileServiceImpl implements FileService { isRelay = true; host = config.get("paramValue").toString(); } - + } catch (Exception ex) { - + } ArrayList<String> saveFiles = new ArrayList<>(); Date startTime = new Date(); @@ -157,12 +157,12 @@ public class FileServiceImpl implements FileService { } return ResultVOUtils.success(null); } - + /*转发图片*/ private String relayFile(ArrayList<String> files, String ip) { String host = ip; String result = ""; - + if (!StringUtils.isEmpty(host)) { host += "/spssync/file/uploadFile"; OkHttpClient client = new OkHttpClient().newBuilder() @@ -185,7 +185,7 @@ public class FileServiceImpl implements FileService { } } } - + RequestBody body = builder.build(); Request req = new Request.Builder() @@ -211,8 +211,8 @@ public class FileServiceImpl implements FileService { } return result; } - - + + @Override public BaseResponse downloadFile(HttpServletRequest request,Map<String,Object> params) { String host = ""; @@ -221,11 +221,11 @@ public class FileServiceImpl implements FileService { if(config!=null&&config.get("paramValue")!=null) host = config.get("paramValue").toString(); } catch (Exception ex) { - + ex.printStackTrace(); } 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); boolean success = false; if(object.getInteger("code")==20000) { @@ -237,10 +237,10 @@ public class FileServiceImpl implements FileService { } } if(!success) - ResultVOUtils.error(9999,"失败"); - + ResultVOUtils.error(9999,"失败"); + } - return ResultVOUtils.success(null); + return ResultVOUtils.success(null); } - -} \ No newline at end of file + +} diff --git a/api-common/src/main/java/com/glxp/sale/common/enums/ResultEnum.java b/api-common/src/main/java/com/glxp/sale/common/enums/ResultEnum.java index 0fed18d..8fc34c8 100644 --- a/api-common/src/main/java/com/glxp/sale/common/enums/ResultEnum.java +++ b/api-common/src/main/java/com/glxp/sale/common/enums/ResultEnum.java @@ -8,7 +8,7 @@ import lombok.Getter; @Getter public enum ResultEnum { - SUCCESS(0, "success"), + SUCCESS(20000, "success"), NOT_NETWORK(1, "系统繁忙,请稍后再试。"), LOGIN_VERIFY_FALL(2, "登录失效"), PARAM_VERIFY_FALL(3, "参数验证错误"), diff --git a/api-common/src/main/java/com/glxp/sale/common/util/ResultVOUtils.java b/api-common/src/main/java/com/glxp/sale/common/util/ResultVOUtils.java index 7702da5..20368a6 100644 --- a/api-common/src/main/java/com/glxp/sale/common/util/ResultVOUtils.java +++ b/api-common/src/main/java/com/glxp/sale/common/util/ResultVOUtils.java @@ -18,7 +18,7 @@ public class ResultVOUtils { */ public static BaseResponse success(Object data) { BaseResponse<Object> baseResponse = new BaseResponse<>(); - baseResponse.setCode(20000); + baseResponse.setCode(ResultEnum.SUCCESS.getCode()); baseResponse.setMessage("success"); baseResponse.setData(data); return baseResponse;