设置统一入口

master
wj 2 years ago
parent fc898119ed
commit e871f8a9a2

@ -0,0 +1,28 @@
package com.glxp.api.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum BasicExportTypeEnum {
/**
*
*/
BASIC_DATA("basic_data", "基础数据"),
/**
* DI
*/
// COUNTRY_DI_DATA("country_di_data", "国家库DI数据"),
/**
*
*/
OTHER_DATA("other_data", "其他数据"),
;
private String key;
private String remark;
}

@ -0,0 +1,15 @@
package com.glxp.api.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RelaySyncDto {
String taskId;
String fileContent;
}

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.BasicExportTypeEnum;
import com.glxp.api.entity.sync.BasicExportStatusEntity;
import com.glxp.api.entity.sync.IOOrderStatusEntity;
import com.glxp.api.entity.system.SyncDataSetEntity;
@ -23,6 +24,7 @@ import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
@Service
public class SpGetHttpClient {
@ -237,6 +239,18 @@ public class SpGetHttpClient {
return response;
}
/**
* UDI
*
* @return
*/
public String pullData(BasicExportTypeEnum exportType) {
Map<String, String> paramMap = new WeakHashMap<>(1);
paramMap.put("exportType", exportType.name());
String result = okHttpCli.doGet(getIpUrl() + "/sps/sync/data", paramMap, buildHeader());
return result;
}
/**
* UDI
*

@ -3,21 +3,25 @@ package com.glxp.api.service.sync;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.BasicExportTypeEnum;
import com.glxp.api.constant.BasicProcessStatus;
import com.glxp.api.constant.ConstantStatus;
import com.glxp.api.dao.basic.*;
import com.glxp.api.dao.inout.IoCodeLostMapper;
import com.glxp.api.dao.inout.IoCodeRelMapper;
import com.glxp.api.dao.purchase.*;
import com.glxp.api.entity.basic.ProductInfoEntity;
import com.glxp.api.entity.basic.UdiCompanyEntity;
import com.glxp.api.dto.RelaySyncDto;
import com.glxp.api.entity.basic.*;
import com.glxp.api.entity.inout.*;
import com.glxp.api.entity.purchase.*;
import com.glxp.api.entity.sync.BasicDownloadStatusEntity;
import com.glxp.api.entity.sync.BasicExportStatusEntity;
import com.glxp.api.entity.sync.BasicExportStatusTimeEntity;
@ -27,6 +31,7 @@ import com.glxp.api.res.sync.*;
import com.glxp.api.service.inout.*;
import com.glxp.api.util.CustomUtil;
import com.glxp.api.util.DateUtil;
import com.glxp.api.util.JsonUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.ExecutorType;
@ -39,6 +44,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
@Slf4j
@ -91,8 +97,7 @@ public class HeartService {
spsSyncDataRequest.setLastUpdateTime(syncTime);
}
SpsSyncOrderResponse spsSyncOrderResponse = upBasicService.upAllOrder(spsSyncDataRequest);
if (CollUtil.isEmpty(spsSyncOrderResponse.getOrderEntities())
&& CollUtil.isEmpty(spsSyncOrderResponse.getCodeEntities())) {
if (CollUtil.isEmpty(spsSyncOrderResponse.getOrderEntities()) && CollUtil.isEmpty(spsSyncOrderResponse.getCodeEntities())) {
//无数据不记录日志
return ResultVOUtils.success("无数据");
}
@ -151,8 +156,7 @@ public class HeartService {
spsSyncDataRequest.setLastUpdateTime(syncTime);
}
SpsSyncBusOrderResponse spsSyncOrderResponse = upBasicService.upAllBusOrder(spsSyncDataRequest);
if (CollUtil.isEmpty(spsSyncOrderResponse.getPurOrderEntities())
&& CollUtil.isEmpty(spsSyncOrderResponse.getPurOrderDetailEntities())) {
if (CollUtil.isEmpty(spsSyncOrderResponse.getPurOrderEntities()) && CollUtil.isEmpty(spsSyncOrderResponse.getPurOrderDetailEntities())) {
//无数据不记录日志
return ResultVOUtils.success("无数据");
}
@ -209,10 +213,7 @@ public class HeartService {
spsSyncDataRequest.setLastUpdateTime(syncTime);
}
SpsSyncBusResponse spsSyncBusResponse = upBasicService.upAllBus(spsSyncDataRequest);
if (CollUtil.isEmpty(spsSyncBusResponse.getBussinessTypeEntities())
&& CollUtil.isEmpty(spsSyncBusResponse.getBusTypeChangeEntities())
&& CollUtil.isEmpty(spsSyncBusResponse.getThrBusTypeOriginEntities())
) {
if (CollUtil.isEmpty(spsSyncBusResponse.getBussinessTypeEntities()) && CollUtil.isEmpty(spsSyncBusResponse.getBusTypeChangeEntities()) && CollUtil.isEmpty(spsSyncBusResponse.getThrBusTypeOriginEntities())) {
return ResultVOUtils.success("无数据");
}
BasicExportStatusEntity basicExportStatusEntity2 = basicExportService.findByData(ConstantStatus.SYNC_BUS_TYPE, 0);
@ -270,12 +271,7 @@ public class HeartService {
}
SpsSyncDataResponse syncDataResponse = upBasicService.uploadAllUserData(spsSyncDataRequest);
if (CollUtil.isEmpty(syncDataResponse.getInvWarehouseEntities())
&& CollUtil.isEmpty(syncDataResponse.getAuthAdminList())
&& CollUtil.isEmpty(syncDataResponse.getDeptEntityList())
&& CollUtil.isEmpty(syncDataResponse.getWarehouseBussinessTypeEntities())
&& CollUtil.isEmpty(syncDataResponse.getWarehouseUserEntities())
) {
if (CollUtil.isEmpty(syncDataResponse.getInvWarehouseEntities()) && CollUtil.isEmpty(syncDataResponse.getAuthAdminList()) && CollUtil.isEmpty(syncDataResponse.getDeptEntityList()) && CollUtil.isEmpty(syncDataResponse.getWarehouseBussinessTypeEntities()) && CollUtil.isEmpty(syncDataResponse.getWarehouseUserEntities())) {
//数据不记录日志
return ResultVOUtils.success("无数据");
}
@ -508,6 +504,132 @@ public class HeartService {
private final SupManufacturerDao supManufacturerDao;
private final SupProductDao supProductDao;
/**
* UDI
*
* @param exportType
*/
@Transactional(rollbackFor = Exception.class)
public void pullData(BasicExportTypeEnum exportType) {
String data = spGetHttp.pullData(exportType);
cn.hutool.json.JSONObject obj = JSONUtil.parseObj(data);
Integer code = obj.getInt("code");
if (!code.equals(20000)) {
log.error("从UDI自助平台拉取数据错误报文-----{}", data);
return;
}
//数据内容
String dataStr = obj.getStr("data");
if (StrUtil.isNotBlank(dataStr)) {
RelaySyncDto bean = JSONUtil.toBean(dataStr, RelaySyncDto.class);
switch (exportType) {
case BASIC_DATA:
this.insertBasicData(bean.getFileContent());
break;
case OTHER_DATA:
this.insertOtherData(bean.getFileContent());
break;
// case COUNTRY_DI_DATA:
// break;
}
String taskId = bean.getTaskId();
if (StrUtil.isNotBlank(taskId)) {
//插入下载记录
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(taskId);
basicDownloadStatusEntity.setStartTime(new Date());
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_DOWNLOAD_BASIC_DATA);
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS); //下载完成
basicDownloadStatusEntity.setType(BasicProcessStatus.BASIC_DATA);
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
//通知自助平台任务已完成
spGetHttp.finishTask(taskId);
}
//通知自助平台任务已完成
spGetHttp.finishTask(bean.getTaskId());
}
}
/**
*
*
* @param content
*/
@Transactional(propagation = Propagation.NESTED)
public void insertBasicData(String content) {
Dict map = JsonUtils.parseMap(content);
List<BasicHospTypeEntity> hospTypeList = (List<BasicHospTypeEntity>) map.get(BasicHospTypeEntity.class.getSimpleName());
List<UdiRelevanceEntity> udiRelevanceList = (List<UdiRelevanceEntity>) map.get(UdiRelevanceEntity.class.getSimpleName());
List<BasicProductsEntity> productsList = (List<BasicProductsEntity>) map.get(BasicProductsEntity.class.getSimpleName());
List<CompanyProductRelevanceEntity> relevanceList = (List<CompanyProductRelevanceEntity>) map.get(CompanyProductRelevanceEntity.class.getSimpleName());
List<BasicCorpEntity> corpList = (List<BasicCorpEntity>) map.get(BasicCorpEntity.class.getSimpleName());
List<SupCertEntity> supCertList = (List<SupCertEntity>) map.get(SupCertEntity.class.getSimpleName());
List<SupCertSetEntity> supCertSetList = (List<SupCertSetEntity>) map.get(SupCertSetEntity.class.getSimpleName());
List<SupCompanyEntity> supCompanyList = (List<SupCompanyEntity>) map.get(SupCompanyEntity.class.getSimpleName());
List<SupManufacturerEntity> supManufacturerList = (List<SupManufacturerEntity>) map.get(SupManufacturerEntity.class.getSimpleName());
List<SupProductEntity> supProductList = (List<SupProductEntity>) map.get(SupProductEntity.class.getSimpleName());
if (CollectionUtil.isNotEmpty(hospTypeList)) {
basicHospTypeDao.insertOrUpdateBatch(hospTypeList);
}
if (CollectionUtil.isNotEmpty(udiRelevanceList)) {
udiRelevanceDao.insertOrUpdateBatch(udiRelevanceList);
}
if (CollectionUtil.isNotEmpty(productsList)) {
basicProductsDao.insertOrUpdateBatch(productsList);
}
if (CollectionUtil.isNotEmpty(relevanceList)) {
relevanceDao.insertOrUpdateBatch(relevanceList);
}
if (CollectionUtil.isNotEmpty(corpList)) {
corpDao.insertOrUpdateBatch(corpList);
}
if (CollectionUtil.isNotEmpty(supCertList)) {
supCertDao.insertOrUpdateBatch(supCertList);
}
if (CollectionUtil.isNotEmpty(supCertSetList)) {
supCertSetDao.insertOrUpdateBatch(supCertSetList);
}
if (CollectionUtil.isNotEmpty(supCompanyList)) {
supCompanyDao.insertOrUpdateBatch(supCompanyList);
}
if (CollectionUtil.isNotEmpty(supManufacturerList)) {
supManufacturerDao.insertOrUpdateBatch(supManufacturerList);
}
if (CollectionUtil.isNotEmpty(supProductList)) {
supProductDao.insertOrUpdateBatch(supProductList);
}
}
private final IoCodeLostMapper ioCodeLostMapper;
private final IoCodeRelMapper ioCodeRelMapper;
/**
*
*
* @param content
*/
@Transactional(propagation = Propagation.NESTED)
public void insertOtherData(String content) {
Dict map = JsonUtils.parseMap(content);
List<IoCodeLostEntity> ioCodeLostList = (List<IoCodeLostEntity>) map.get(IoCodeLostEntity.class.getSimpleName());
List<IoCodeRelEntity> ioCodeRelList = (List<IoCodeRelEntity>) map.get(IoCodeRelEntity.class.getSimpleName());
if (CollectionUtil.isNotEmpty(ioCodeLostList)) {
ioCodeLostMapper.insertOrUpdateBatch(ioCodeLostList);
}
if (CollectionUtil.isNotEmpty(ioCodeRelList)) {
ioCodeRelMapper.insertOrUpdateBatch(ioCodeRelList);
}
}
/**
* UDI
*/
@ -613,9 +735,6 @@ public class HeartService {
}
}
private final IoCodeLostMapper ioCodeLostMapper;
private final IoCodeRelMapper ioCodeRelMapper;
/**
*
*
@ -709,8 +828,7 @@ public class HeartService {
spsSyncDataRequest.setLastUpdateTime(syncTime);
}
SpsSyncThrDataResponse spsSyncThrDataResponse = upThrDataService.upThrData(spsSyncDataRequest);
if (CollUtil.isEmpty(spsSyncThrDataResponse.getDeptEntities()) && CollUtil.isEmpty(spsSyncThrDataResponse.getInvWarehouseEntities())
&& CollUtil.isEmpty(spsSyncThrDataResponse.getCorpEntities())) {
if (CollUtil.isEmpty(spsSyncThrDataResponse.getDeptEntities()) && CollUtil.isEmpty(spsSyncThrDataResponse.getInvWarehouseEntities()) && CollUtil.isEmpty(spsSyncThrDataResponse.getCorpEntities())) {
//无数据不记录
log.info("无第三方基础数据需要同步");
return ResultVOUtils.success("无数据");

@ -1,5 +1,6 @@
package com.glxp.api.task;
import com.glxp.api.constant.BasicExportTypeEnum;
import com.glxp.api.dao.schedule.ScheduledDao;
import com.glxp.api.dao.system.SyncDataSetDao;
import com.glxp.api.entity.system.ScheduledEntity;
@ -16,6 +17,7 @@ import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Arrays;
//@Component
@ -69,7 +71,7 @@ public class SyncHeartTask implements SchedulingConfigurer {
if (curTime1 - lastTime1 > timeInterval1) {
heartService.uploadAllBus(null);
heartService.uploadAllUserData(null);
// heartService.uploadScheduleList();
// heartService.uploadScheduleList();
heartService.uploadThrData(null);
heartService.uploadThrProducts(null);
heartService.uploadSysSetting(null);
@ -104,8 +106,11 @@ public class SyncHeartTask implements SchedulingConfigurer {
}
if (curTime - lastTime > timeInterval) {
heartService.dlAllOrder();
heartService.pullBasicData();
heartService.pullOtherData();
Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> {
heartService.pullData(i);
});
// heartService.pullBasicData();
// heartService.pullOtherData();
redisUtil.set("SPS_SYNC_DOWNLOAD_DATA", curTime);
}

Loading…
Cancel
Save