多个中继服务同步相关问题修改

master
anthonywj 2 years ago
parent dce4804d8d
commit 7629c7bd00

@ -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<String> httpEntity = uriUtils.buildHeader(request);
ResponseEntity<JSONObject> 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<SyncUpLoadRequest>() {
});
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;
}

@ -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;
}
}

@ -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) {

@ -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<RelaySyncDto>() {
});
JSONObject jsonObject = JSONObject.parseObject(bean.getFileContent());
JSONArray jsonArray = jsonObject.getJSONArray("syncFiles");
String remark = jsonObject.getString(Constant.SYNC_REMARK);

@ -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 "";
// }
}
/**

@ -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<Character> 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<String>(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"));
}
}
Loading…
Cancel
Save