From a9c7628017a57a2d772f8fe6c4776fc2d850dafe Mon Sep 17 00:00:00 2001 From: anthonywj Date: Mon, 1 May 2023 15:02:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D=EF=BC=8C=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=A4=87=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sync/BasicDownloadController.java | 6 ++- .../sync/SpsSyncDataController.java | 3 +- .../admin/controller/sync/SyncController.java | 7 ++- .../sync/impl/BasicExportServiceImpl.java | 2 +- .../sale/admin/thread/DlAllDataService.java | 48 +++++++++++-------- .../com/glxp/sale/admin/util/Constant.java | 3 ++ .../src/main/resources/application.properties | 2 +- 7 files changed, 44 insertions(+), 27 deletions(-) diff --git a/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/BasicDownloadController.java b/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/BasicDownloadController.java index 0a105bc..bd9146d 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/BasicDownloadController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/BasicDownloadController.java @@ -112,14 +112,16 @@ public class BasicDownloadController { return ResultVOUtils.success(json); } else if (basicExportStatusRequest.getType().equals(BasicProcessStatus.NEW_ALL_UDIS)) {//国家库信息 BasicExportStatusEntity basicExportStatusEntity = basicExportService.findById(basicExportStatusRequest.getId()); - String data = (String) redisUtil.get(basicExportStatusRequest.getId() + ""); +// String data = (String) redisUtil.get(basicExportStatusRequest.getId() + ""); + String fileName = basicExportStatusEntity.getCacheFilePath(); + String data = FileUtils.readFileAll(fileName); SpSyncUdiResponse spSyncUdiResponse = null; if (StrUtil.isNotEmpty(data)) { spSyncUdiResponse = JSONObject.parseObject(data, new TypeReference() { }); spSyncUdiResponse.setTaskId(basicExportStatusEntity.getTaskId()); } - basicExportService.finished(basicExportStatusRequest.getId()); +// basicExportService.finished(basicExportStatusRequest.getId()); return ResultVOUtils.success(spSyncUdiResponse); } return ResultVOUtils.error(500, "数据不存在!"); 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 0880d9e..a1033b9 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 @@ -347,7 +347,8 @@ public class SpsSyncDataController { basicUploadStatusEntity.setIdDatas(exportType.getKey()); basicUploadStatusEntity.setType(exportType.getRemark()); basicUploadStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL); -// basicUploadStatusEntity.setRemark(); + JSONObject jsonObject = JSONObject.parseObject(content).getJSONObject("data"); + basicUploadStatusEntity.setRemark(jsonObject.getString(Constant.SYNC_REMARK)); FileUtils.makeDirectory(filePath + "upload/"); String fileName = filePath + "upload/" + exportType.getRemark() + "-" + taskId + ".udi"; FileUtils.SaveFileAs(content, fileName); diff --git a/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SyncController.java b/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SyncController.java index 9a8157f..01dc180 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SyncController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SyncController.java @@ -83,7 +83,7 @@ public class SyncController { if (StrUtil.isNotEmpty(upperServerHost)) { uri = upperServerHost + "/" + uri; } - JSONObject jsonObject = redirect(request, uri, ConstantStatus.SYNC_SCAN_ORDER, BasicProcessStatus.NEW_ALL_ORDER); + JSONObject jsonObject = redirect(request, uri); return jsonObject; } @@ -235,10 +235,13 @@ public class SyncController { basicUploadStatusEntity.setIdDatas(idDatas); basicUploadStatusEntity.setType(type); basicUploadStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL); - basicUploadService.insertDownloadStatus(basicUploadStatusEntity); + JSONObject jsonObject = JSONObject.parseObject(content); + basicUploadStatusEntity.setRemark(jsonObject.getString(Constant.SYNC_REMARK)); FileUtils.makeDirectory(filePath + "upload/"); String fileName = filePath + "upload/" + type + "-" + taskId + ".udi"; FileUtils.SaveFileAs(content, fileName); + basicUploadStatusEntity.setCacheFilePath(fileName); + basicUploadService.insertDownloadStatus(basicUploadStatusEntity); } @Async diff --git a/api-admin/src/main/java/com/glxp/sale/admin/service/sync/impl/BasicExportServiceImpl.java b/api-admin/src/main/java/com/glxp/sale/admin/service/sync/impl/BasicExportServiceImpl.java index 87dbb47..2c24f24 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/service/sync/impl/BasicExportServiceImpl.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/service/sync/impl/BasicExportServiceImpl.java @@ -77,7 +77,7 @@ public class BasicExportServiceImpl extends ServiceImpl> basicStatuss = spGetHttp.getBasicStatus(basicExportStatusRequest); @@ -188,34 +188,40 @@ public class DlAllDataService { JSONObject syncOrderResponse = JSON.parseObject(baseResponse.getData()); if (syncOrderResponse != null) { - String key = gennerOrderUtils.getOrders(); +// String key = gennerOrderUtils.getOrders(); BasicExportStatusEntity myEntity = new BasicExportStatusEntity(); - myEntity.setId(key); + String taskId = syncOrderResponse.getString("taskId"); + myEntity.setId(taskId); JSONArray fileJson = syncOrderResponse.getJSONArray("files"); - List syncFiles = fileJson.toJavaList(String.class); - if (CollUtil.isNotEmpty(syncFiles)) { - idcService.batchDownloadFile(spGetHttp.getSpmsUrl(), syncFiles.toArray(new String[syncFiles.size()])); + if (fileJson != null) { + List syncFiles = fileJson.toJavaList(String.class); + if (CollUtil.isNotEmpty(syncFiles)) { + idcService.batchDownloadFile(spGetHttp.getSpmsUrl(), syncFiles.toArray(new String[syncFiles.size()])); + } } + String remark = syncOrderResponse.getString(Constant.SYNC_REMARK); myEntity.setTaskId(taskId); - myEntity.setStatus(0); + myEntity.setStatus(BasicExportStatusEnum.WAIT_BUILT.getCode()); myEntity.setUpdateTime(new Date()); myEntity.setStartTime(DateUtil.getDateTime()); - myEntity.setIdDatas(ConstantStatus.SYNC_SCAN_ORDER); + myEntity.setRemark(remark); + myEntity.setIdDatas(SYNC_SCAN_ORDER); myEntity.setType(BasicProcessStatus.NEW_ALL_ORDER); basicExportService.insertExportStatus(myEntity); myEntity.setStatus(Constant.SYNC_STATUS_WAIT); if (downstream.getParamValue().equals("1")) { FileUtils.makeDirectory(filePath + "upload/"); - String fileName = filePath + "upload/" + BasicProcessStatus.NEW_ALL_ORDER + "-" + key + ".udi"; + String fileName = filePath + "upload/" + BasicProcessStatus.NEW_ALL_ORDER + "-" + taskId + ".udi"; FileUtils.SaveFileAs(baseResponse.getData(), fileName); myEntity.setTransportType(BasicProcessStatus.INTERFACE_TYPE); - myEntity.setStatus(Constant.SYNC_STATUS_WAIT_DL); + myEntity.setCacheFilePath(fileName); + myEntity.setStatus(BasicExportStatusEnum.WAIT_SYNC.getCode()); basicExportService.updateExportStatus(myEntity); } else { String path = getPath(); - String fileName = path + FileConstant.upWaitCopy_products + key + ".LowerIn"; + String fileName = path + FileConstant.upWaitCopy_products + taskId + ".LowerIn"; String datas = JSON.toJSONString(baseResponse.getData()); FileUtils.SaveFileAs(datas, fileName); myEntity.setStatus(Constant.SYNC_STATUS_SUCCESS); @@ -230,7 +236,8 @@ public class DlAllDataService { BasicExportStatusEntity basicExportStatusEntity1 = basicExportStatusEntities.get(0); basicExportStatusEntity1.setStatus(4); spGetHttp.postUpdateBasicStatus(basicExportStatusEntity1); - spGetHttp.updateLastTime("AutoDownloadOrder", DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); + spGetHttp.finishTask(basicExportStatusEntity1.getId()); + spGetHttp.updateLastTime(SYNC_SCAN_ORDER, DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss")); } else { spGetHttp.postDeleteBasicStatus(basicExportStatusEntity.getId()); } @@ -262,6 +269,7 @@ public class DlAllDataService { RelaySyncDto bean = JSONUtil.toBean(dataStr, RelaySyncDto.class); JSONObject jsonObject = JSONObject.parseObject(bean.getFileContent()); JSONArray jsonArray = jsonObject.getJSONArray("syncFiles"); + String remark = jsonObject.getString(Constant.SYNC_REMARK); if (jsonArray != null) { List list = JSONArray.parseArray(jsonArray.toJSONString(), String.class); idcService.batchDownloadFile(spGetHttp.getSpmsUrl(), list.toArray(new String[list.size()])); @@ -270,9 +278,9 @@ public class DlAllDataService { // 将数据写入文件 // try { - FileUtils.makeDirectory(filePath + "sync/"); - String fileName = filePath + "sync/" + exportType.getRemark() + "-" + bean.getTaskId() + ".udi"; - FileUtils.SaveFileAs(bean.getFileContent(), fileName); + FileUtils.makeDirectory(filePath + "sync/"); + String fileName = filePath + "sync/" + exportType.getRemark() + "-" + bean.getTaskId() + ".udi"; + FileUtils.SaveFileAs(bean.getFileContent(), fileName); // } catch (IOException e) { // log.error("从UDI自助平台拉取基础数据 文件[{}]写入异常----{}",bean.getFilePath(), e.getMessage()); // throw new RuntimeException(e); @@ -285,7 +293,7 @@ public class DlAllDataService { .type(exportType.getRemark()) .transportType(1) .scheduleType(0) - .fromType(1) + .fromType(1).remark(remark) .startTime(DateUtil.getDateTime()) .updateTime(new Date()) .cacheFilePath(fileName) @@ -298,7 +306,7 @@ public class DlAllDataService { } private void writeFile(String filePath, String content) throws IOException { - String folder = filePath.substring(0,filePath.lastIndexOf('/')-1); + String folder = filePath.substring(0, filePath.lastIndexOf('/') - 1); File file = new File(folder); if (!file.exists()) { file.mkdirs(); @@ -346,7 +354,7 @@ public class DlAllDataService { log.info("下载所有国家库DI信息--"); BasicExportStatusRequest basicExportStatusRequest = new BasicExportStatusRequest(); basicExportStatusRequest.setIdDatas(ConstantStatus.SYNC_DI_PRODUCTS); - basicExportStatusRequest.setStatus(BasicExportStatusEnum.WAIT_BUILT.getCode()); + basicExportStatusRequest.setStatus(BasicExportStatusEnum.WAIT_SYNC.getCode()); basicExportStatusRequest.setType(NEW_ALL_UDIS); basicExportStatusRequest.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL); BaseResponse> basicStatuss = spGetHttp.getBasicStatus(basicExportStatusRequest); @@ -390,7 +398,7 @@ public class DlAllDataService { //记录下载日志 myEntity.setCacheFilePath(fileName); - myEntity.setStatus(Constant.SYNC_STATUS_WAIT_DL); + myEntity.setStatus(BasicExportStatusEnum.WAIT_SYNC.getCode()); myEntity.setTransportType(BasicProcessStatus.INTERFACE_TYPE); myEntity.setCacheFilePath(fileName); basicExportService.updateExportStatus(myEntity); diff --git a/api-admin/src/main/java/com/glxp/sale/admin/util/Constant.java b/api-admin/src/main/java/com/glxp/sale/admin/util/Constant.java index ac0c3f1..bf6f0bf 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/util/Constant.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/util/Constant.java @@ -16,4 +16,7 @@ public class Constant { public static final int SYNC_STATUS_FAIL = 2; //处理失败 public static final int SYNC_STATUS_WAIT = 0; //等待处理 public static final int SYNC_STATUS_WAIT_DL = 3; //等待下游下载 + + + public static final String SYNC_REMARK = "syncRemark"; } diff --git a/api-admin/src/main/resources/application.properties b/api-admin/src/main/resources/application.properties index 1ca0009..e23c510 100644 --- a/api-admin/src/main/resources/application.properties +++ b/api-admin/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.profiles.active=pro +spring.profiles.active=dev spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver mybatis.config-location=classpath:mybatis/mybatis-config.xml mybatis.mapper-locations=classpath:mybatis/mapper/*/*.xml From dce4804d8df71a4efb365310fd83be7894ee9b57 Mon Sep 17 00:00:00 2001 From: anthonywj Date: Mon, 1 May 2023 15:28:21 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=9B=BD=E5=AE=B6?= =?UTF-8?q?=E5=BA=93=E4=BC=81=E4=B8=9A=E4=BF=A1=E6=81=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../glxp/sale/admin/thread/didl/AsyncCompanyDlService.java | 4 ++-- .../com/glxp/sale/admin/thread/didl/AsyncDiDlService.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api-admin/src/main/java/com/glxp/sale/admin/thread/didl/AsyncCompanyDlService.java b/api-admin/src/main/java/com/glxp/sale/admin/thread/didl/AsyncCompanyDlService.java index 33b125c..e06c799 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/thread/didl/AsyncCompanyDlService.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/thread/didl/AsyncCompanyDlService.java @@ -30,6 +30,8 @@ public class AsyncCompanyDlService { RedisUtil redisUtil; @Resource BasicExportService basicExportService; + @Resource + AsyncDiDlHelper asyncDiDlHelper; public String getPath() { SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("share_folder"); @@ -41,8 +43,6 @@ public class AsyncCompanyDlService { public void asyncDiByTime(String updateTime) { SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("sync_upstream_enable"); if (systemParamConfigEntity.getParamValue().equals("1")) { - - AsyncDiDlHelper asyncDiDlHelper = new AsyncDiDlHelper(); List mUdiCompanyEntities = new ArrayList<>(); int page = 1; int limit = 300; diff --git a/api-admin/src/main/java/com/glxp/sale/admin/thread/didl/AsyncDiDlService.java b/api-admin/src/main/java/com/glxp/sale/admin/thread/didl/AsyncDiDlService.java index 15ca806..f2846eb 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/thread/didl/AsyncDiDlService.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/thread/didl/AsyncDiDlService.java @@ -34,7 +34,8 @@ public class AsyncDiDlService { RedisUtil redisUtil; @Resource BasicExportService basicExportService; - + @Resource + AsyncDiDlHelper asyncDiDlHelper; private static final Logger logger = LoggerFactory.getLogger(AsyncDiDlService.class); public void dlSyncUdi(String updateTime) { @@ -43,7 +44,6 @@ public class AsyncDiDlService { //更新DI信息 if (systemParamConfigEntity.getParamValue().equals("1")) { - AsyncDiDlHelper asyncDiDlHelper = new AsyncDiDlHelper(); List mProductInfoEntities = new ArrayList<>(); int page = 1; int limit = 300; From 7629c7bd0028b7c32c46d2576fc4e67dcd3a3229 Mon Sep 17 00:00:00 2001 From: anthonywj Date: Wed, 3 May 2023 21:55:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A4=9A=E4=B8=AA=E4=B8=AD=E7=BB=A7?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=90=8C=E6=AD=A5=E7=9B=B8=E5=85=B3=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sync/SpsSyncDataController.java | 15 +++++++- .../admin/controller/sync/SyncController.java | 18 ++++----- .../glxp/sale/admin/idc/utils/UriUtils.java | 3 +- .../sale/admin/thread/DlAllDataService.java | 5 ++- .../com/glxp/sale/admin/util/FileUtils.java | 15 ++++---- .../com/glxp/sale/admin/util/MyStrUtil.java | 37 +++++++++++++++++++ 6 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 api-admin/src/main/java/com/glxp/sale/admin/util/MyStrUtil.java 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 a1033b9..0142a40 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 @@ -4,8 +4,10 @@ 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.http.SpGetHttp; @@ -22,6 +24,7 @@ import com.glxp.sale.common.enums.ResultEnum; import com.glxp.sale.common.res.BaseResponse; import com.glxp.sale.common.util.ResultVOUtils; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -43,6 +46,7 @@ import java.io.FileReader; import java.io.IOException; import java.util.Date; +@Slf4j @RestController @RequiredArgsConstructor public class SpsSyncDataController { @@ -73,6 +77,7 @@ public class SpsSyncDataController { // 连通性测试 @GetMapping("sps/sync/connect/test") public BaseResponse connectTest(SpsSyncDataRequest spsSyncDataRequest) { + return spGetHttp.testUpConnect(null); } @@ -322,7 +327,12 @@ public class SpsSyncDataController { HttpEntity httpEntity = uriUtils.buildHeader(request); ResponseEntity responseBody = null; - SyncUpLoadRequest bean = JSONUtil.toBean(httpEntity.getBody(), SyncUpLoadRequest.class); +// SyncUpLoadRequest bean = JSONUtil.toBean(httpEntity.getBody(), SyncUpLoadRequest.class); + + SyncUpLoadRequest bean = + JSONObject.parseObject(httpEntity.getBody(), new TypeReference() { + }); + String taskId = bean.getTaskId(); if (request.getMethod().equals("POST")) { //写入日志 @@ -363,7 +373,10 @@ public class SpsSyncDataController { if (uri.contains("SP_SYNC_SERVER")) { uri = uri.replace("SP_SYNC_SERVER/", ""); } + } else { + uri = MyStrUtil.deDup(uri); } + log.error("changeUri = " + uri); return uri; } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SyncController.java b/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SyncController.java index 01dc180..4aba568 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SyncController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/controller/sync/SyncController.java @@ -11,10 +11,7 @@ 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.admin.util.*; import com.glxp.sale.common.res.BaseResponse; import com.glxp.sale.common.util.ResultVOUtils; import lombok.extern.slf4j.Slf4j; @@ -77,12 +74,12 @@ public class SyncController { String isTopService = systemParamConfigService.selectValueByParamKey("is_top_service"); if (StrUtil.isNotEmpty(isTopService) && isTopService.equals("1")) { uri = uri.replace("orderApi/", ""); - uri = changeUri(uri); } String upperServerHost = systemParamConfigService.selectValueByParamKey("upper_server_ip"); if (StrUtil.isNotEmpty(upperServerHost)) { uri = upperServerHost + "/" + uri; } + uri = changeUri(uri); JSONObject jsonObject = redirect(request, uri); return jsonObject; } @@ -95,13 +92,12 @@ public class SyncController { String isTopService = systemParamConfigService.selectValueByParamKey("is_top_service"); if (StrUtil.isNotEmpty(isTopService) && isTopService.equals("1")) { uri = uri.replace("busOrderApi/", ""); - uri = changeUri(uri); - } String upperServerHost = systemParamConfigService.selectValueByParamKey("upper_server_ip"); if (StrUtil.isNotEmpty(upperServerHost)) { uri = upperServerHost + "/" + uri; } + uri = changeUri(uri); JSONObject jsonObject = redirect(request, uri); return jsonObject; } @@ -143,12 +139,12 @@ public class SyncController { String isTopService = systemParamConfigService.selectValueByParamKey("is_top_service"); if (StrUtil.isNotEmpty(isTopService) && isTopService.equals("1")) { uri = uri.replace("syncToSpms/", ""); - uri = changeUri(uri); } String upperServerHost = systemParamConfigService.selectValueByParamKey("upper_server_ip"); if (StrUtil.isNotEmpty(upperServerHost)) { uri = upperServerHost + "/" + uri; } + uri = changeUri(uri); JSONObject jsonObject = redirect(request, uri); return jsonObject; } @@ -160,12 +156,13 @@ public class SyncController { String isTopService = systemParamConfigService.selectValueByParamKey("is_top_service"); if (StrUtil.isNotEmpty(isTopService) && isTopService.equals("1")) { uri = uri.replace("directToSpms/", ""); - uri = changeUri(uri); } String upperServerHost = systemParamConfigService.selectValueByParamKey("upper_server_ip"); if (StrUtil.isNotEmpty(upperServerHost)) { uri = upperServerHost + "/" + uri; } + uri = changeUri(uri); + log.error(uri); JSONObject jsonObject = redirectNolog(request, uri); return jsonObject; } @@ -268,9 +265,12 @@ public class SyncController { if (uri.contains("SP_SYNC_SERVER")) { uri = uri.replace("SP_SYNC_SERVER/", ""); } + } else { + uri = MyStrUtil.deDup(uri); } log.error("changeUri = " + uri); return uri; } + } diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/utils/UriUtils.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/utils/UriUtils.java index 4adcfa9..1b3cbd2 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/utils/UriUtils.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/utils/UriUtils.java @@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletRequest; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -53,7 +54,7 @@ public class UriUtils { } else { BufferedReader reader = null; try { - reader = new BufferedReader(new InputStreamReader(request.getInputStream())); + reader = new BufferedReader(new InputStreamReader(request.getInputStream(), "utf-8")); bodyContent = IoUtil.read(reader); log.info(bodyContent); } catch (IOException e) { diff --git a/api-admin/src/main/java/com/glxp/sale/admin/thread/DlAllDataService.java b/api-admin/src/main/java/com/glxp/sale/admin/thread/DlAllDataService.java index 79aedf6..44e3c38 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/thread/DlAllDataService.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/thread/DlAllDataService.java @@ -7,6 +7,7 @@ import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; import com.glxp.sale.admin.constant.*; import com.glxp.sale.admin.dto.RelaySyncDto; import com.glxp.sale.admin.entity.param.SystemParamConfigEntity; @@ -266,7 +267,9 @@ public class DlAllDataService { //需要写入文件的内容 String dataStr = obj.getStr("data"); if (StrUtil.isNotBlank(dataStr)) { - RelaySyncDto bean = JSONUtil.toBean(dataStr, RelaySyncDto.class); + RelaySyncDto bean = + JSONObject.parseObject(dataStr, new TypeReference() { + }); JSONObject jsonObject = JSONObject.parseObject(bean.getFileContent()); JSONArray jsonArray = jsonObject.getJSONArray("syncFiles"); String remark = jsonObject.getString(Constant.SYNC_REMARK); diff --git a/api-admin/src/main/java/com/glxp/sale/admin/util/FileUtils.java b/api-admin/src/main/java/com/glxp/sale/admin/util/FileUtils.java index 31fba4a..7f0c390 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/util/FileUtils.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/util/FileUtils.java @@ -781,7 +781,7 @@ public class FileUtils { public static boolean SaveFileAs(String content, String path) { FileWriter fw = null; try { - fw = new FileWriter(path, Charset.forName("UTF8")); + fw = new FileWriter(path); if (content != null) { fw.write(content); } @@ -977,13 +977,12 @@ public class FileUtils { } catch (IOException e) { e.printStackTrace(); } - try { - return new String(filecontent, encoding); - } catch (UnsupportedEncodingException e) { - System.err.println("The OS does not support " + encoding); - e.printStackTrace(); - return ""; - } + return new String(filecontent); +// } catch (UnsupportedEncodingException e) { +// System.err.println("The OS does not support " + encoding); +// e.printStackTrace(); +// return ""; +// } } /** diff --git a/api-admin/src/main/java/com/glxp/sale/admin/util/MyStrUtil.java b/api-admin/src/main/java/com/glxp/sale/admin/util/MyStrUtil.java new file mode 100644 index 0000000..89920aa --- /dev/null +++ b/api-admin/src/main/java/com/glxp/sale/admin/util/MyStrUtil.java @@ -0,0 +1,37 @@ +package com.glxp.sale.admin.util; + +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.LinkedHashSet; + +public class MyStrUtil { + + public static String removeDuplicates(String S) { + //ArrayDeque会比LinkedList在除了删除元素这一点外会快一点 + ArrayDeque deque = new ArrayDeque<>(); + char ch; + for (int i = 0; i < S.length(); i++) { + ch = S.charAt(i); + //peek()方法用于返回此双端队列表示的队列的头元素,但不删除该元素。 + if (deque.isEmpty() || deque.peek() != ch) { + deque.push(ch); + } else { + //pop()方法用于从此双端队列中弹出头元素,并删除该元素。 + deque.pop(); + } + } + String str = ""; + //剩余的元素即为不重复的元素 + while (!deque.isEmpty()) { + str = deque.pop() + str; + } + return str; + } + public static String deDup(String s) { + return new LinkedHashSet(Arrays.asList(s.split("/"))).toString().replaceAll("(^\\[|\\]$)", "").replace(", ", "/"); + } + public static void main(String[] args) { + System.out.println(deDup("http://192.168.6.3:9150/SP_SYNC_SERVER/SP_SYNC_SERVER/directToSpms/system/param/syncData/save")); + } + +}