由内向外同步

master
wj 2 years ago
parent 8a9607f690
commit cdfda6af2a

@ -0,0 +1,38 @@
package com.glxp.api.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 线
*/
@Configuration
@EnableAsync
public class TaskPoolConfig {
@Bean(name = "taskExecutor")
public ThreadPoolTaskExecutor taskExecutor() {
// 获取当前主机的cpu核心数
int threadCount = Runtime.getRuntime().availableProcessors();
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
//核心池的大小
taskExecutor.setCorePoolSize(threadCount);
//线程池最大线程数
taskExecutor.setMaxPoolSize(threadCount * 2);
//队列最大长度
taskExecutor.setQueueCapacity(200);
//线程空闲时间
taskExecutor.setKeepAliveSeconds(60);
//配置线程前缀
taskExecutor.setThreadNamePrefix("custom_executor");
//配置拒绝策略
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//执行初始化
taskExecutor.initialize();
return taskExecutor;
}
}

@ -0,0 +1,25 @@
package com.glxp.api.constant;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum BasicExportStatusEnum {
/**
*
*/
FAILED(1, "接收失败"),
/**
*
*/
SUCCESS(2, "接收成功"),
;
@EnumValue
private Integer code;
private String remark;
}

@ -0,0 +1,60 @@
package com.glxp.api.constant;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum BasicExportStatusTimeEnum {
/**
*
*/
BASIC_PRODUCTS("basic_products", "耗材字典"),
/**
*
*/
BASIC_CORP("basic_corp", "往来单位字典"),
/**
* DI
*/
DB_DI_PRODUCTS("db_di_products", "国家库DI数据"),
/**
*
*/
SUP_CERT("sup_cert", "首营资质"),
/**
* UDI
*/
IO_CODE_LOST("io_code_lost", "UDI码补齐"),
/**
* UDI
*/
IO_CODE_REL("io_code_rel", "UDI码关联关系"),
/**
*
*/
BASIC_BUSSINESS_TYPE("basic_bussiness_type","扫码单据类型"),
/**
*
*/
BASIC_BUSTYPE_CHANGE("basic_bustype_change","业务单据类型"),
/**
*
*/
THR_BUSTYPE_ORIGIN("thr_bustype_origin","第三方单据类型"),
;
@EnumValue
private String key;
private String remark;
}

@ -15,7 +15,12 @@ public enum BasicExportTypeEnum {
/**
* DI
*/
// COUNTRY_DI_DATA("country_di_data", "国家库DI数据"),
COUNTRY_DI_DATA("country_di_data", "国家库DI数据"),
/**
*
*/
DOCUMENT_TYPE("document_type", "单据类型"),
/**
*

@ -1,5 +1,6 @@
package com.glxp.api.dao.sync;
import com.glxp.api.dao.BaseMapperPlus;
import com.glxp.api.entity.sync.BasicExportStatusTimeEntity;
import com.glxp.api.req.sync.BasicExportTimeRequest;
import org.apache.ibatis.annotations.Mapper;
@ -7,7 +8,7 @@ import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface BasicExportTimeDao {
public interface BasicExportTimeDao extends BaseMapperPlus<BasicExportTimeDao,BasicExportStatusTimeEntity,BasicExportStatusTimeEntity> {
List<BasicExportStatusTimeEntity> filterExportStatus(BasicExportTimeRequest basicExportStatusRequest);

@ -2,9 +2,16 @@ package com.glxp.api.entity.sync;
import java.util.Date;
import com.glxp.api.constant.BasicExportStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class BasicExportStatusEntity {
private String id;
@ -19,8 +26,8 @@ public class BasicExportStatusEntity {
private String cacheFilePath;
/**
* -1 0 1
* 1 2
*/
private String receiveStatus;
private Integer receiveStatus;
}

@ -1,8 +1,14 @@
package com.glxp.api.entity.sync;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class BasicExportStatusTimeEntity {
private Integer id;

@ -13,6 +13,7 @@ import com.glxp.api.req.inout.ReviewFinishRequest;
import com.glxp.api.req.inout.ReviewSpmsRequest;
import com.glxp.api.req.sync.BasicExportStatusRequest;
import com.glxp.api.req.sync.OrderStatusFilterRequest;
import com.glxp.api.req.sync.SyncUpLoadRequest;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.res.sync.*;
import com.glxp.api.res.system.SyncDataSetResponse;
@ -51,6 +52,13 @@ public class SpGetHttpClient {
return headers;
}
public BaseResponse<String> postData(BasicExportTypeEnum exportType, Object data) {
SyncUpLoadRequest build = SyncUpLoadRequest.builder().exportType(exportType).data(data).build();
String result = okHttpCli.doPostJson(getIpUrl() + "sps/sync/upload/data", JSONUtil.toJsonStr(build), buildHeader());
return JSONObject.parseObject(result, new TypeReference<BaseResponse<String>>() {
});
}
//上传扫码单据
public BaseResponse<String> postAllOrder(SpsSyncOrderResponse spsSyncOrderResponse) {

@ -0,0 +1,19 @@
package com.glxp.api.req.sync;
import com.glxp.api.constant.BasicExportTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SyncUpLoadRequest {
private BasicExportTypeEnum exportType;
private Object data;
}

@ -1,5 +1,6 @@
package com.glxp.api.service.basic;
import com.baomidou.mybatisplus.extension.service.IService;
import com.glxp.api.entity.basic.BasicBusTypeChangeEntity;
import com.glxp.api.req.basic.FilterBusTypeChangeRequest;
import com.glxp.api.res.basic.BasicBusTypeChangeResponse;
@ -10,7 +11,7 @@ import java.util.List;
/**
* Service
*/
public interface IBasicBusTypeChangeService {
public interface IBasicBusTypeChangeService extends IService<BasicBusTypeChangeEntity> {
BasicBusTypeChangeEntity selectByOriginAction(String action);

@ -1,5 +1,6 @@
package com.glxp.api.service.basic;
import com.baomidou.mybatisplus.extension.service.IService;
import com.glxp.api.entity.basic.BasicBussinessTypeEntity;
import com.glxp.api.req.basic.FilterBussinessTypeRequest;
import com.glxp.api.res.basic.BasicBussinessTypeResponse;
@ -10,7 +11,7 @@ import java.util.List;
/**
* Service
*/
public interface IBasicBussinessTypeService {
public interface IBasicBussinessTypeService extends IService<BasicBussinessTypeEntity> {
/**
*

@ -2,6 +2,7 @@ package com.glxp.api.service.basic.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.glxp.api.dao.basic.BasicBusTypeChangeDao;
import com.glxp.api.entity.basic.BasicBusTypeChangeEntity;
@ -21,7 +22,7 @@ import java.util.List;
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class BasicBusTypeChangeServiceImpl implements IBasicBusTypeChangeService {
public class BasicBusTypeChangeServiceImpl extends ServiceImpl<BasicBusTypeChangeDao,BasicBusTypeChangeEntity> implements IBasicBusTypeChangeService {
@Resource
private CustomerService customerService;

@ -3,6 +3,7 @@ package com.glxp.api.service.basic.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.glxp.api.constant.Constant;
import com.glxp.api.constant.ConstantStatus;
@ -27,7 +28,7 @@ import java.util.stream.Collectors;
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class BasicBussinessTypeServiceImpl implements IBasicBussinessTypeService {
public class BasicBussinessTypeServiceImpl extends ServiceImpl<BasicBussinessTypeDao,BasicBussinessTypeEntity> implements IBasicBussinessTypeService {
@Resource
private CustomerService customerService;

@ -2,12 +2,13 @@ package com.glxp.api.service.sync;
import com.baomidou.mybatisplus.extension.service.IService;
import com.glxp.api.entity.sync.BasicExportStatusTimeEntity;
import com.glxp.api.req.sync.BasicExportTimeRequest;
import java.util.List;
public interface BasicExportTimeService {
public interface BasicExportTimeService extends IService<BasicExportStatusTimeEntity> {
BasicExportStatusTimeEntity findByKey(String key);

@ -3,17 +3,14 @@ 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.baomidou.mybatisplus.core.toolkit.Wrappers;
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.constant.*;
import com.glxp.api.dao.basic.*;
import com.glxp.api.dao.inout.IoCodeLostMapper;
import com.glxp.api.dao.inout.IoCodeRelMapper;
@ -25,13 +22,19 @@ 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;
import com.glxp.api.entity.system.SyncDataBustypeEntity;
import com.glxp.api.entity.system.SyncDataSetEntity;
import com.glxp.api.entity.thrsys.ThrBusTypeOriginEntity;
import com.glxp.api.http.sync.SpGetHttpClient;
import com.glxp.api.req.sync.SpsSyncDataRequest;
import com.glxp.api.res.sync.*;
import com.glxp.api.service.basic.IBasicBusTypeChangeService;
import com.glxp.api.service.basic.IBasicBussinessTypeService;
import com.glxp.api.service.inout.*;
import com.glxp.api.service.thrsys.IThrBusTypeOriginService;
import com.glxp.api.util.CustomUtil;
import com.glxp.api.util.DateUtil;
import com.glxp.api.util.JsonUtils;
import com.glxp.api.util.RedisUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.ExecutorType;
@ -44,8 +47,8 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.function.Function;
@Slf4j
@Service
@ -199,6 +202,422 @@ public class HeartService {
return ResultVOUtils.success();
}
private final RedisUtil redisUtil;
@Transactional
public void chooseData(SyncDataSetEntity info, Date syncTime, BasicExportTypeEnum exportType) {
Date now = new Date();
String taskId = CustomUtil.getId();
switch (exportType) {
case BASIC_DATA:
if (needExec(info.getBasicProducts(), info.getBasicCorp(), info.getSupCert())) {
uploadData(exportType, taskId, x -> x.getBasicData(info, taskId, now, syncTime));
}
break;
case OTHER_DATA:
if (needExec(info.getUdiCodeLost(), info.getUdiCodeRel())) {
uploadData(exportType, taskId, x -> x.getOtherData(info, taskId, now, syncTime));
}
break;
case DOCUMENT_TYPE:
if (needExec(info.getTypeBus(), info.getTypeScan(), info.getTypeThird())) {
uploadData(exportType, taskId, x -> x.getDocumentTypeData(info, taskId, now, syncTime));
}
break;
case COUNTRY_DI_DATA:
}
}
/**
*
*
* @param info
* @param now
* @param syncTime -- exportTime
* @return
*/
public SpsSyncBasicDataResponse getBasicData(SyncDataSetEntity info, String taskId, Date now, Date syncTime) {
SpsSyncBasicDataResponse dataResponse = null;
Map<String, Object> syncTimeMap = new WeakHashMap<>(3);
syncTimeMap.put("isNew", true);
syncTimeMap.put("oldDate", syncTime);
//确认有开启物资字典同步
if (needExec(info.getBasicProducts())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_PRODUCTS);
} else {
map = syncTimeMap;
}
List<BasicHospTypeEntity> hospTypeList = basicHospTypeDao.selectList(Wrappers.lambdaQuery(BasicHospTypeEntity.class)
.le((boolean) map.get("isNew"), BasicHospTypeEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), BasicHospTypeEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(hospTypeList)) {
dataResponse = new SpsSyncBasicDataResponse();
dataResponse.setHospTypeList(hospTypeList);
}
List<UdiRelevanceEntity> udiRelevanceList = udiRelevanceDao.selectList(Wrappers.lambdaQuery(UdiRelevanceEntity.class)
.le((boolean) map.get("isNew"), UdiRelevanceEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), UdiRelevanceEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(udiRelevanceList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncBasicDataResponse();
}
dataResponse.setUdiRelevanceList(udiRelevanceList);
}
List<BasicProductsEntity> productsList = basicProductsDao.selectList(Wrappers.lambdaQuery(BasicProductsEntity.class)
.le((boolean) map.get("isNew"), BasicProductsEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), BasicProductsEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(productsList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncBasicDataResponse();
}
dataResponse.setProductsList(productsList);
}
List<CompanyProductRelevanceEntity> relevanceList = relevanceDao.selectList(Wrappers.lambdaQuery(CompanyProductRelevanceEntity.class)
.le((boolean) map.get("isNew"), CompanyProductRelevanceEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), CompanyProductRelevanceEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(relevanceList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncBasicDataResponse();
}
dataResponse.setRelevanceList(relevanceList);
}
}
//确认有开启往来单位字典同步
if (needExec(info.getBasicCorp())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_CORP);
} else {
map = syncTimeMap;
}
List<BasicCorpEntity> corpList = corpDao.selectList(Wrappers.lambdaQuery(BasicCorpEntity.class)
.le((boolean) map.get("isNew"), BasicCorpEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), BasicCorpEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(corpList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncBasicDataResponse();
}
dataResponse.setCorpList(corpList);
}
}
//确认有开启首营资质同步
if (info.getSupCert() == 2) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.SUP_CERT);
} else {
map = syncTimeMap;
}
List<SupCertEntity> supCertList = supCertDao.selectList(Wrappers.lambdaQuery(SupCertEntity.class)
.le((boolean) map.get("isNew"), SupCertEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), SupCertEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(supCertList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncBasicDataResponse();
}
dataResponse.setSupCertList(supCertList);
}
List<SupCertSetEntity> supCertSetList = supCertSetDao.selectList(Wrappers.lambdaQuery(SupCertSetEntity.class)
.le((boolean) map.get("isNew"), SupCertSetEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), SupCertSetEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(supCertSetList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncBasicDataResponse();
}
dataResponse.setSupCertSetList(supCertSetList);
}
List<SupCompanyEntity> supCompanyList = supCompanyDao.selectList(Wrappers.lambdaQuery(SupCompanyEntity.class)
.le((boolean) map.get("isNew"), SupCompanyEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), SupCompanyEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(supCompanyList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncBasicDataResponse();
}
dataResponse.setSupCompanyList(supCompanyList);
}
List<SupManufacturerEntity> supManufacturerList = supManufacturerDao.selectList(Wrappers.lambdaQuery(SupManufacturerEntity.class)
.le((boolean) map.get("isNew"), SupManufacturerEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), SupManufacturerEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(supManufacturerList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncBasicDataResponse();
}
dataResponse.setSupManufacturerList(supManufacturerList);
}
List<SupProductEntity> supProductList = supProductDao.selectList(Wrappers.lambdaQuery(SupProductEntity.class)
.le((boolean) map.get("isNew"), SupProductEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), SupProductEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(supProductList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncBasicDataResponse();
}
dataResponse.setSupProductList(supProductList);
}
}
if (dataResponse != null) {
dataResponse.setTaskId(taskId);
}
return dataResponse;
}
/**
*
*
* @param info
* @param now
* @param syncTime -- exportTime
* @return
*/
public SpsSyncOtherDataResponse getOtherData(SyncDataSetEntity info, String taskId, Date now, Date syncTime) {
SpsSyncOtherDataResponse dataResponse = null;
Map<String, Object> syncTimeMap = new WeakHashMap<>(3);
syncTimeMap.put("isNew", true);
syncTimeMap.put("oldDate", syncTime);
//确认有开启udi码补齐同步
if (needExec(info.getUdiCodeLost())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_PRODUCTS);
} else {
map = syncTimeMap;
}
List<IoCodeLostEntity> ioCodeLostList = ioCodeLostMapper.selectList(Wrappers.lambdaQuery(IoCodeLostEntity.class)
.le((boolean) map.get("isNew"), IoCodeLostEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), IoCodeLostEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(ioCodeLostList)) {
dataResponse = new SpsSyncOtherDataResponse();
dataResponse.setIoCodeLostList(ioCodeLostList);
}
}
//确认有开启udi关联关系同步
if (needExec(info.getUdiCodeRel())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_REL);
} else {
map = syncTimeMap;
}
List<IoCodeRelEntity> ioCodeRelList = ioCodeRelMapper.selectList(Wrappers.lambdaQuery(IoCodeRelEntity.class)
.le((boolean) map.get("isNew"), IoCodeRelEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), IoCodeRelEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(ioCodeRelList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncOtherDataResponse();
}
dataResponse.setIoCodeRelList(ioCodeRelList);
}
}
if (dataResponse != null) {
dataResponse.setTaskId(taskId);
}
return dataResponse;
}
private final IBasicBussinessTypeService bussinessTypeService;
private final IBasicBusTypeChangeService busTypeChangeService;
private final IThrBusTypeOriginService thrBusTypeOriginService;
/**
*
*
* @param info
* @param now
* @param syncTime -- exportTime
* @return
*/
public SpsSyncBusResponse getDocumentTypeData(SyncDataSetEntity info, String taskId, Date now, Date syncTime) {
SpsSyncBusResponse dataResponse = null;
Map<String, Object> syncTimeMap = new WeakHashMap<>(3);
syncTimeMap.put("isNew", true);
syncTimeMap.put("oldDate", syncTime);
//确认有开启业务单据类型同步
if (needExec(info.getTypeBus())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSSINESS_TYPE);
} else {
map = syncTimeMap;
}
List<BasicBussinessTypeEntity> bussinessTypeEntities = bussinessTypeService.list(Wrappers.lambdaQuery(BasicBussinessTypeEntity.class)
.le((boolean) map.get("isNew"), BasicBussinessTypeEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), BasicBussinessTypeEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(bussinessTypeEntities)) {
dataResponse = new SpsSyncBusResponse();
dataResponse.setBussinessTypeEntities(bussinessTypeEntities);
}
}
//确认有开启扫码单据类型同步
if (needExec(info.getTypeScan())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSTYPE_CHANGE);
} else {
map = syncTimeMap;
}
List<BasicBusTypeChangeEntity> busTypeChangeList = busTypeChangeService.list(Wrappers.lambdaQuery(BasicBusTypeChangeEntity.class)
.le((boolean) map.get("isNew"), BasicBusTypeChangeEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), BasicBusTypeChangeEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(busTypeChangeList)) {
if(dataResponse==null){
dataResponse = new SpsSyncBusResponse();
}
dataResponse.setBusTypeChangeEntities(busTypeChangeList);
}
}
//确认有开启第三方单据类型同步
if (needExec(info.getTypeThird())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_BUSTYPE_ORIGIN);
} else {
map = syncTimeMap;
}
List<ThrBusTypeOriginEntity> thrBusTypeOriginEntities = thrBusTypeOriginService.list(Wrappers.lambdaQuery(ThrBusTypeOriginEntity.class)
.le((boolean) map.get("isNew"), ThrBusTypeOriginEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), ThrBusTypeOriginEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(thrBusTypeOriginEntities)) {
if(dataResponse==null){
dataResponse = new SpsSyncBusResponse();
}
dataResponse.setThrBusTypeOriginEntities(thrBusTypeOriginEntities);
}
}
if (dataResponse != null) {
dataResponse.setTaskId(taskId);
}
return dataResponse;
}
/**
*
*
* @param set
* @return
*/
private boolean needExec(int... set) {
return CollectionUtil.contains(Collections.singleton(set), 1);
}
public void uploadData(BasicExportTypeEnum exportType, String taskId, Function<HeartService, Object> dataMethod) {
Integer status = BasicExportStatusEnum.SUCCESS.getCode();
Object data = dataMethod.apply(this);
if (data == null) {
return;
}
BaseResponse<String> baseResponse = spGetHttp.postData(exportType, data);
if (baseResponse.getCode() != 20000) {
status = BasicExportStatusEnum.FAILED.getCode();
}
BasicExportStatusEntity exportStatus = BasicExportStatusEntity.builder()
.id(taskId)
.status(status)
.idDatas(exportType.getKey())
.type(exportType.getRemark())
.startTime(new Date())
.endTime(new Date())
.updateTime(new Date())
.receiveStatus(status)
.scheduleType(BasicProcessStatus.SCHEDULE_NORMAL)
.build();
this.insertExportStatus(exportStatus);
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void insertExportStatus(BasicExportStatusEntity exportStatus) {
basicExportService.insertExportStatus(exportStatus);
}
/**
* basicExportStatusTime
*
* @param date
* @param exportStatusTimeEnum key
* @return date
* @throws Exception
*/
public Map<String, Object> basicExportStatusTimeInfo(Date date, BasicExportStatusTimeEnum exportStatusTimeEnum) {
//防止出现同时调用问题
String redisKey = String.format("spsm-sync-task:%s", exportStatusTimeEnum.getKey());
boolean result = redisUtil.setIfAbsent(redisKey, 1, 10);
if (!result) {
String errorMsg = String.format("syncIdcSps----process------------同步[%s]重复进入", exportStatusTimeEnum.getRemark());
// logger.info(errorMsg);
throw new RuntimeException(errorMsg);
}
boolean isNew = true;
BasicExportStatusTimeEntity timeInfo = basicExportTimeService.getOne(Wrappers.lambdaQuery(BasicExportStatusTimeEntity.class)
.eq(BasicExportStatusTimeEntity::getKey, exportStatusTimeEnum.getKey()));
if (timeInfo == null) {
timeInfo = BasicExportStatusTimeEntity.builder()
.key(exportStatusTimeEnum.getKey())
.lastUpdateTime(DateUtil.formatDateTime(date))
.remark(exportStatusTimeEnum.getRemark())
.build();
basicExportTimeService.save(timeInfo);
} else {
if (StrUtil.isNotEmpty(timeInfo.getLastUpdateTime())) {
isNew = false;
}
basicExportTimeService.update(Wrappers.lambdaUpdate(BasicExportStatusTimeEntity.class)
.set(BasicExportStatusTimeEntity::getLastUpdateTime, DateUtil.formatDateTime(date))
.eq(BasicExportStatusTimeEntity::getKey, exportStatusTimeEnum.getKey())
);
}
redisUtil.del(redisKey);
WeakHashMap<String, Object> returnMap = new WeakHashMap<>(10);
returnMap.put("isNew", isNew);
returnMap.put("oldDate", isNew ? null : timeInfo.getLastUpdateTime());
returnMap.put("id", timeInfo.getId());
return returnMap;
}
//上传最近更新单据类型
public BaseResponse uploadAllBus(String syncTime) {
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();

@ -1,10 +1,11 @@
package com.glxp.api.service.sync;
import com.baomidou.mybatisplus.extension.service.IService;
import com.glxp.api.entity.system.SyncDataBustypeEntity;
import java.util.List;
public interface SyncDataBustypeService {
public interface SyncDataBustypeService extends IService<SyncDataBustypeEntity> {
List<SyncDataBustypeEntity> findAll(Integer direct);

@ -1,6 +1,7 @@
package com.glxp.api.service.sync;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import com.glxp.api.constant.ConstantStatus;
import com.glxp.api.entity.auth.*;
import com.glxp.api.entity.basic.BasicBusTypeChangeEntity;

@ -1,6 +1,7 @@
package com.glxp.api.service.sync.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glxp.api.dao.sync.BasicExportTimeDao;
import com.glxp.api.entity.sync.BasicExportStatusTimeEntity;
import com.glxp.api.req.sync.BasicExportTimeRequest;
@ -14,7 +15,7 @@ import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class BasicExportTimeServiceImpl implements BasicExportTimeService {
public class BasicExportTimeServiceImpl extends ServiceImpl<BasicExportTimeDao,BasicExportStatusTimeEntity> implements BasicExportTimeService {
@Resource
BasicExportTimeDao basicExportTimeDao;

@ -1,6 +1,7 @@
package com.glxp.api.service.sync.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glxp.api.dao.sync.SyncDataBustypeDao;
import com.glxp.api.entity.system.SyncDataBustypeEntity;
import com.glxp.api.service.sync.SyncDataBustypeService;
@ -12,7 +13,7 @@ import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class SyncDataBustypeServiceImpl implements SyncDataBustypeService {
public class SyncDataBustypeServiceImpl extends ServiceImpl<SyncDataBustypeDao,SyncDataBustypeEntity> implements SyncDataBustypeService {
@Resource
SyncDataBustypeDao syncDataBustypeDao;

@ -1,5 +1,6 @@
package com.glxp.api.service.thrsys;
import com.baomidou.mybatisplus.extension.service.IService;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.entity.thrsys.ThrBusTypeOriginEntity;
import com.glxp.api.entity.thrsys.ThrSystemDetailEntity;
@ -12,7 +13,7 @@ import java.util.List;
/**
* Service
*/
public interface IThrBusTypeOriginService {
public interface IThrBusTypeOriginService extends IService<ThrBusTypeOriginEntity> {
/**
*

@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
@ -32,7 +33,7 @@ import java.util.List;
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class ThrBusTypeOriginServiceImpl implements IThrBusTypeOriginService {
public class ThrBusTypeOriginServiceImpl extends ServiceImpl<ThrBusTypeOriginDao,ThrBusTypeOriginEntity> implements IThrBusTypeOriginService {
@Resource
private CustomerService customerService;

@ -75,6 +75,9 @@ public class SyncHeartTask implements SchedulingConfigurer {
heartService.uploadThrData(null);
heartService.uploadThrProducts(null);
heartService.uploadSysSetting(null);
Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> {
heartService.chooseData(syncDataSetEntity, null, i);
});
redisUtil.set("SPS_SYNC_UPLOAD_DATA", curTime1);
}
} catch (Exception e) {

@ -601,4 +601,22 @@ public class RedisUtil {
}
}
/**
* key
*
* @param key
* @param value
* @param time ()
* @return boolean trueset,falsekeyset
*/
public boolean setIfAbsent(String key, Object value, long time) {
if (StrUtil.isEmpty(key)) {
return false;
}
return Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(key, value, time, TimeUnit.SECONDS));
}
}

Loading…
Cancel
Save