数据同步修改

master
anthonywj 2 years ago
parent c807bfe86e
commit 37ebc5586c

@ -61,6 +61,7 @@ public class SpsSyncDataController {
return filePath;
}
// 连通性测试
@GetMapping("sps/sync/connect/test")
public BaseResponse connectTest(SpsSyncDataRequest spsSyncDataRequest) {
return spGetHttp.testUpConnect(null);

@ -1,6 +1,7 @@
package com.glxp.sale.admin.controller.sync;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.glxp.sale.admin.constant.BasicProcessStatus;
import com.glxp.sale.admin.constant.ConstantStatus;
@ -31,6 +32,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
/**
*
@ -125,6 +127,75 @@ public class SyncController {
}
//UDI管理系统同步数据中转
@RequestMapping("/syncToSpms/**")
public Object syncToSpms(HttpServletRequest request, HttpServletResponse httpServletResponse) {
String uri = uriUtils.parseUri(request.getRequestURL().toString());
String isTopService = systemParamConfigService.selectValueByParamKey("is_top_service");
if (StrUtil.isNotEmpty(isTopService) && isTopService.equals("1")) {
uri = uri.replace("syncToSpms/", "");
}
String upperServerHost = systemParamConfigService.selectValueByParamKey("upper_server_ip");
if (StrUtil.isNotEmpty(upperServerHost)) {
uri = upperServerHost + "/" + uri;
}
JSONObject jsonObject = redirect(request, uri);
return jsonObject;
}
//UDI管理系统同步数据中转
@RequestMapping("/directToSpms/**")
public Object directToSpms(HttpServletRequest request, HttpServletResponse httpServletResponse) {
String uri = uriUtils.parseUri(request.getRequestURL().toString());
String isTopService = systemParamConfigService.selectValueByParamKey("is_top_service");
if (StrUtil.isNotEmpty(isTopService) && isTopService.equals("1")) {
uri = uri.replace("directToSpms/", "");
}
String upperServerHost = systemParamConfigService.selectValueByParamKey("upper_server_ip");
if (StrUtil.isNotEmpty(upperServerHost)) {
uri = upperServerHost + "/" + uri;
}
JSONObject jsonObject = redirectNolog(request, uri);
return jsonObject;
}
private JSONObject redirectNolog(HttpServletRequest request, String uri) {
RestTemplate restTemplate = new RestTemplate();
HttpEntity<String> httpEntity = uriUtils.buildHeader(request);
ResponseEntity<JSONObject> responseBody = null;
if (request.getMethod().equals("POST")) {
responseBody = restTemplate.postForEntity(uri, httpEntity, JSONObject.class);
} else if (request.getMethod().equals("GET")) {
responseBody = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, JSONObject.class);
}
JSONObject result = responseBody.getBody();
return result;
}
private JSONObject redirect(HttpServletRequest request, String uri) {
RestTemplate restTemplate = new RestTemplate();
HttpEntity<String> httpEntity = uriUtils.buildHeader(request);
JSONObject jsonObject = JSONObject.parseObject(httpEntity.getBody());
// JSONArray fileArray = jsonObject.getJSONArray("uploadFiles");
// List<String> syncFiles = fileArray.toJavaList(String.class);
String taskId = jsonObject.getString("taskId");
String idDatas = jsonObject.getString("idDatas");
String type = jsonObject.getString("type");
ResponseEntity<JSONObject> responseBody = null;
if (request.getMethod().equals("POST")) {
//写入日志
writeUploadLog(taskId, httpEntity.getBody(), idDatas, type);
responseBody = restTemplate.postForEntity(uri, httpEntity, JSONObject.class);
} else if (request.getMethod().equals("GET")) {
writeDownloadLog(taskId, httpEntity.getBody(), idDatas, type);
responseBody = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, JSONObject.class);
}
JSONObject result = responseBody.getBody();
return result;
}
private JSONObject redirect(HttpServletRequest request, String uri, String idDatas, String type) {
RestTemplate restTemplate = new RestTemplate();
HttpEntity<String> httpEntity = uriUtils.buildHeader(request);

@ -0,0 +1,17 @@
package com.glxp.sale.admin.res.sync;
import lombok.Data;
import java.util.List;
@Data
public class BaseSyncResponse {
private String taskId;
private List<String> files;
private List<String> uploadFiles;
private String updateTime;
private String type;
private String idDatas;
}

@ -15,8 +15,8 @@ import com.glxp.sale.admin.entity.info.ScheduledEntity;
import com.glxp.sale.admin.idc.service.IdcService;
import com.glxp.sale.admin.req.info.ScheduledRequest;
@Component
@EnableScheduling
//@Component
//@EnableScheduling
public class AsyncFetchTask implements SchedulingConfigurer {
final Logger logger = LoggerFactory.getLogger(AsyncFetchTask.class);

@ -139,7 +139,7 @@ public class DlAllDataService {
}
if (basicExportStatusEntity.getFromType() == 0) {
BasicExportStatusEntity basicExportStatusEntity1 = basicExportStatusEntities.get(0);
basicExportStatusEntity1.setStatus(1);
basicExportStatusEntity1.setStatus(4);
spGetHttp.postUpdateBasicStatus(basicExportStatusEntity1);
spGetHttp.updateLastTime("AutoDownloadAllData", DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
} else {
@ -225,15 +225,13 @@ public class DlAllDataService {
}
if (basicExportStatusEntity.getFromType() == 0) {
BasicExportStatusEntity basicExportStatusEntity1 = basicExportStatusEntities.get(0);
basicExportStatusEntity1.setStatus(1);
basicExportStatusEntity1.setStatus(4);
spGetHttp.postUpdateBasicStatus(basicExportStatusEntity1);
spGetHttp.updateLastTime("AutoDownloadOrder", DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
} else {
spGetHttp.postDeleteBasicStatus(basicExportStatusEntity.getId());
}
}
}
}
@ -302,87 +300,6 @@ public class DlAllDataService {
}
public void dllNewAllBusType() {
log.info("下载所有单据类型---");
BasicExportStatusRequest basicExportStatusRequest = new BasicExportStatusRequest();
basicExportStatusRequest.setIdDatas("AutoDownloadBusType");
basicExportStatusRequest.setStatus(0);
basicExportStatusRequest.setType(BasicProcessStatus.NEW_ALL_BUS);
basicExportStatusRequest.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
BaseResponse<List<BasicExportStatusEntity>> basicStatuss = spGetHttp.getBasicStatus(basicExportStatusRequest);
if (CollUtil.isNotEmpty(basicStatuss.getData())) {
List<BasicExportStatusEntity> basicExportStatusEntities = basicStatuss.getData();
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("sync_upstream_enable");
if (systemParamConfigEntity.getParamValue().equals("1")) {
SystemParamConfigEntity downstream = systemParamConfigService.selectByParamKey("sync_downstream_enable");
for (BasicExportStatusEntity basicExportStatusEntity : basicExportStatusEntities) {
BaseResponse<SpsSyncBusResponse> baseResponse = null;
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
if (basicExportStatusEntity.getFromType() == 0) {
BaseResponse<String> response = spGetHttp.getLastUpdateTime("AutoDownloadBusType");
String lastUpdateTime = response.getData();
spsSyncDataRequest.setLastUpdateTime(lastUpdateTime);
baseResponse = spGetHttp.getAllBus(spsSyncDataRequest);
} else {
spsSyncDataRequest.setId(basicExportStatusEntity.getId());
baseResponse = spGetHttp.getAllBus(spsSyncDataRequest);
}
if (baseResponse.getCode() == 20000) {
SpsSyncBusResponse syncOrderResponse = baseResponse.getData();
if (syncOrderResponse != null &&
(CollUtil.isNotEmpty(syncOrderResponse.getBussinessTypeEntities())
|| CollUtil.isNotEmpty(syncOrderResponse.getBussinessOriginTypeEntities())
|| CollUtil.isNotEmpty(syncOrderResponse.getBussinessLocalTypeEntities())
|| CollUtil.isNotEmpty(syncOrderResponse.getEntrustReceEntities()))
) {
String key = gennerOrderUtils.getBusType();
BasicExportStatusEntity myEntity = new BasicExportStatusEntity();
myEntity.setId(key);
myEntity.setTaskId(syncOrderResponse.getTaskId());
myEntity.setStatus(0);
myEntity.setUpdateTime(new Date());
myEntity.setStartTime(DateUtil.getDateTime());
myEntity.setTransportType(BasicProcessStatus.INTERFACE_TYPE);
myEntity.setType(BasicProcessStatus.NEW_ALL_BUS);
myEntity.setIdDatas(ConstantStatus.SYNC_BUS_TYPE);
myEntity.setRemark(syncOrderResponse.toString());
basicExportService.insertExportStatus(myEntity);
if (downstream.getParamValue().equals("1")) {
redisUtil.set(key, baseResponse.getData());
myEntity.setStatus(Constant.SYNC_STATUS_WAIT_DL);
myEntity.setTransportType(BasicProcessStatus.INTERFACE_TYPE);
basicExportService.updateExportStatus(myEntity);
} else {
String path = getPath();
String fileName = path + FileConstant.upWaitCopy_products + key + ".LowerIn";
String datas = JSON.toJSONString(baseResponse.getData());
FileUtils.SaveFileAs(datas, fileName);
myEntity.setStatus(Constant.SYNC_STATUS_SUCCESS);
myEntity.setEndTime(DateUtil.getDateTime());
myEntity.setTransportType(BasicProcessStatus.FILE_TYPE);
myEntity.setCacheFilePath(fileName);
basicExportService.updateExportStatus(myEntity);
}
}
if (basicExportStatusEntity.getFromType() == 0) {
BasicExportStatusEntity basicExportStatusEntity1 = basicExportStatusEntities.get(0);
basicExportStatusEntity1.setStatus(1);
spGetHttp.postUpdateBasicStatus(basicExportStatusEntity1);
spGetHttp.updateLastTime("AutoDownloadBusType", DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
} else {
spGetHttp.postDeleteBasicStatus(basicExportStatusEntity.getId());
}
}
}
}
}
log.info("下载所有单据类型---结束");
}
public void dlScheduleStatus() {
@ -427,7 +344,6 @@ public class DlAllDataService {
SystemParamConfigEntity downstream = systemParamConfigService.selectByParamKey("sync_downstream_enable");
for (BasicExportStatusEntity basicExportStatusEntity : basicExportStatusEntities) {
if (basicExportStatusEntity.getFromType() == 0) {
BaseResponse<String> response = spGetHttp.getLastUpdateTime("AutoDownloadDiProducts");
String lastUpdateTime = response.getData();
if (lastUpdateTime.equals("1949-01-01 00:00:00")) {
@ -455,11 +371,17 @@ public class DlAllDataService {
myEntity.setRemark("国家库DI信息" + spSyncUdiResponse.getProductInfoEntityList().size() + " 条");
basicExportService.insertExportStatus(myEntity);
if (downstream.getParamValue().equals("1")) {
// String datas = JSON.toJSON(spSyncUdiResponse).toString();
// redisUtil.set(key, datas);
String fileName = filePath + "upload/" + BasicProcessStatus.NEW_ALL_UDIS + "-" + key + ".udi";
String datas = JSON.toJSON(spSyncUdiResponse).toString();
redisUtil.set(key, datas);
FileUtils.SaveFileAs(datas, fileName);
//记录下载日志
myEntity.setCacheFilePath(fileName);
myEntity.setStatus(Constant.SYNC_STATUS_WAIT_DL);
myEntity.setTransportType(BasicProcessStatus.INTERFACE_TYPE);
myEntity.setCacheFilePath(fileName);
basicExportService.updateExportStatus(myEntity);
} else {
String path = getPath();
@ -508,8 +430,11 @@ public class DlAllDataService {
myEntity.setRemark("医疗器械注册人信息:{} " + spSyncUdiResponse.getUdiCompanyEntities().size() + " 条");
basicExportService.insertExportStatus(myEntity);
if (downstream.getParamValue().equals("1")) {
// String datas = JSON.toJSON(spSyncUdiResponse).toString();
// redisUtil.set(key, datas);
String fileName = filePath + "upload/" + BasicProcessStatus.NEW_ALL_UDIS + "-" + key + ".udi";
String datas = JSON.toJSON(spSyncUdiResponse).toString();
redisUtil.set(key, datas);
FileUtils.SaveFileAs(datas, fileName);
myEntity.setStatus(Constant.SYNC_STATUS_WAIT_DL);
myEntity.setTransportType(BasicProcessStatus.INTERFACE_TYPE);
basicExportService.updateExportStatus(myEntity);
@ -537,7 +462,7 @@ public class DlAllDataService {
BasicExportStatusEntity basicExportStatusEntity1 = basicExportStatusEntities.get(0);
basicExportStatusEntity1.setStatus(1);
basicExportStatusEntity1.setStatus(4);
spGetHttp.postUpdateBasicStatus(basicExportStatusEntity1);
spGetHttp.updateLastTime("AutoDownloadDiProducts", DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));

@ -152,7 +152,7 @@ public class HeartTask implements SchedulingConfigurer {
// dlAllDataService.dllNewAllBusType();
// dlAllDataService.dlScheduleStatus();
// dlAllDataService.dlAllDi();
dlAllDataService.dlAllDi();
redisUtil.set("is_doing_download", "false");
}
}

@ -0,0 +1,59 @@
# \u751F\u4EA7\u73AF\u5883
server.port=10001
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.jdbc-url=jdbc:mysql://127.0.0.1:3306/udispsync?allowMultiQueries=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=123456
#spring.datasource.password=xiamenswan
#server.servlet.context-path=
logging.level.com.glxp.sale.admin=debug
# \u8DE8\u57DF\u8BBE\u7F6E
cors.allowed-origins=*
cors.allowed-headers=Content-Type,ADMIN_ID,ADMIN_TOKEN
cors.allowed-methods=GET,POST,PUT,DELETE,PATCH,OPTIONS
cors.allowed-Credentials=true
#\u8BF7\u6C42\u53C2\u6570\u957F\u5EA6
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
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
logging.file=D:/1s/udiwms/udiwms.log
#logging.file=/www/glxpdata/spsyc/
file_path=D:/share/udisps/
#file_path=/share/order/sync
back_file_path=D:/share/udisps/back/
#back_file_path=/share/order/sync_back
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
#UDI管理系统地址
#UDIWMS_IP=http://192.168.0.109:9991
UDIWMS_IP=http://127.0.0.1:9991
#自助平台地址
SPMS_IP=http://127.0.0.1:9906
#SPMS_IP=http://139.9.178.73:8080/SPMS_SERVER
API_KEY=1101
API_SECRET=zBITspLNvuoEd4FaamlSoqxRHmNsmQ9L
#SPMS_IP=http://139.159.187.130:8080/SPMS_SERVER
##端口号
# Redis数据库索引默认为0
spring.redis.database=6
# Redis服务器地址
spring.redis.host=127.0.0.1
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码默认为空
spring.redis.password=
#连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.jedis.timeout=300

@ -1,4 +1,4 @@
spring.profiles.active=dev
spring.profiles.active=pro
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

Loading…
Cancel
Save