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

test
anthonywj 2 years ago
commit 4827b7dd1e

@ -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>() {
});
spSyncUdiResponse.setTaskId(basicExportStatusEntity.getTaskId());
}
basicExportService.finished(basicExportStatusRequest.getId());
// basicExportService.finished(basicExportStatusRequest.getId());
return ResultVOUtils.success(spSyncUdiResponse);
}
return ResultVOUtils.error(500, "数据不存在!");

@ -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")) {
//写入日志
@ -347,7 +357,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);
@ -362,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,13 +74,13 @@ 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;
}
JSONObject jsonObject = redirect(request, uri, ConstantStatus.SYNC_SCAN_ORDER, BasicProcessStatus.NEW_ALL_ORDER);
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;
}
@ -235,10 +232,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
@ -265,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) {

@ -77,7 +77,7 @@ public class BasicExportServiceImpl extends ServiceImpl<BasicExportDao,BasicExpo
BasicExportStatusEntity basicExportStatusEntity = basicExportDao.selectById(id);
if (null != basicExportStatusEntity) {
basicExportStatusEntity.setEndTime(DateUtil.getDateTime());
basicExportStatusEntity.setStatus(1);
// basicExportStatusEntity.setStatus(1);
basicExportDao.updateExportStatus(basicExportStatusEntity);
}
}

@ -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;
@ -40,6 +41,7 @@ import java.util.Date;
import java.util.List;
import static com.glxp.sale.admin.constant.BasicProcessStatus.NEW_ALL_UDIS;
import static com.glxp.sale.admin.constant.ConstantStatus.SYNC_SCAN_ORDER;
@Slf4j
@Service
@ -161,8 +163,7 @@ public class DlAllDataService {
public void dllNewAllOrder() {
log.info("下载所有单据---");
BasicExportStatusRequest basicExportStatusRequest = new BasicExportStatusRequest();
basicExportStatusRequest.setIdDatas("AutoDownloadOrder");
basicExportStatusRequest.setStatus(BasicExportStatusEnum.WAIT_BUILT.getCode());
basicExportStatusRequest.setStatus(BasicExportStatusEnum.WAIT_SYNC.getCode());
basicExportStatusRequest.setType(BasicProcessStatus.NEW_ALL_ORDER);
basicExportStatusRequest.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
BaseResponse<List<BasicExportStatusEntity>> basicStatuss = spGetHttp.getBasicStatus(basicExportStatusRequest);
@ -188,34 +189,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<String> syncFiles = fileJson.toJavaList(String.class);
if (CollUtil.isNotEmpty(syncFiles)) {
idcService.batchDownloadFile(spGetHttp.getSpmsUrl(), syncFiles.toArray(new String[syncFiles.size()]));
if (fileJson != null) {
List<String> 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 +237,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());
}
@ -259,9 +267,12 @@ 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);
if (jsonArray != null) {
List<String> list = JSONArray.parseArray(jsonArray.toJSONString(), String.class);
idcService.batchDownloadFile(spGetHttp.getSpmsUrl(), list.toArray(new String[list.size()]));
@ -270,9 +281,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 +296,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 +309,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 +357,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<List<BasicExportStatusEntity>> basicStatuss = spGetHttp.getBasicStatus(basicExportStatusRequest);
@ -390,7 +401,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);

@ -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<UdiCompanyEntity> mUdiCompanyEntities = new ArrayList<>();
int page = 1;
int limit = 300;

@ -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<ProductInfoEntity> mProductInfoEntities = new ArrayList<>();
int page = 1;
int limit = 300;

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

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

@ -16,8 +16,8 @@ cors.allowed-Credentials=true
server.tomcat.max-http-form-post-size=100MB
server.max-http-header-size=100MB
#\u6700\u5927\u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F(10MB)
spring.servlet.multipart.max-file-size=104857600
spring.servlet.multipart.max-request-size=104857600
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
server.connectionTimeout=180000
#logging.level.com.glxp.sale.admin.dao=debug
# \u8F93\u51FA\u65E5\u5FD7\u5230\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u7684springboot.log\u6587\u4EF6\u4E2D // \u914D\u7F6E logback-spring.xml\u65F6 \u6B64\u65E5\u5FD7\u8F93\u51FA\u65B9\u5F0F\u4F1A\u88AB\u8986\u76D6\u3002

Loading…
Cancel
Save