You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-wms-java/src/main/java/com/glxp/api/service/sync/HeartService.java

2091 lines
108 KiB
Java

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.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
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.*;
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.inout.IoOrderInvoiceMapper;
import com.glxp.api.dao.purchase.*;
import com.glxp.api.dao.thrsys.ThrBusTypeOriginDao;
import com.glxp.api.dto.RelaySyncDto;
import com.glxp.api.entity.auth.*;
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;
import com.glxp.api.entity.system.*;
import com.glxp.api.entity.thrsys.*;
import com.glxp.api.http.sync.SpGetHttpClient;
2 years ago
import com.glxp.api.idc.service.FileService;
import com.glxp.api.req.sync.SpsSyncDataRequest;
import com.glxp.api.res.sync.*;
import com.glxp.api.service.auth.*;
import com.glxp.api.service.basic.EntrustReceService;
import com.glxp.api.service.basic.IBasicBusTypeChangeService;
import com.glxp.api.service.basic.IBasicBusTypePreService;
import com.glxp.api.service.basic.IBasicBussinessTypeService;
import com.glxp.api.service.inout.*;
import com.glxp.api.service.system.*;
import com.glxp.api.service.thrsys.*;
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;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.TransactionIsolationLevel;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.function.Function;
2 years ago
import static com.glxp.api.constant.BasicProcessStatus.NEW_ALL_ORDER;
2 years ago
import static com.glxp.api.constant.BasicProcessStatus.NEW_ALL_UDIS;
2 years ago
@Slf4j
@Service
@RequiredArgsConstructor
public class HeartService {
@Resource
BasicExportService basicExportService;
@Resource
UpBasicService upBasicService;
@Resource
SpGetHttpClient spGetHttp;
@Resource
BasicExportTimeService basicExportTimeService;
@Resource
BasicDownloadService basicDownloadService;
@Resource
SqlSessionFactory sqlSessionFactory;
@Resource
IoOrderService orderService;
@Resource
IoAddInoutService addInoutService;
@Resource
IoCheckInoutService ioCheckInoutService;
@Resource
private UpThrDataService upThrDataService;
@Resource
IoCodeTempService codeTempService;
@Resource
IoOrderDetailBizService orderDetailBizService;
@Resource
IoOrderDetailCodeService orderDetailCodeService;
@Resource
IoOrderDetailResultService orderDetailResultService;
@Resource
IoOrderInvoiceService orderInvoiceService;
private final ApplicationContext applicationContext;
//上传最近更新扫码单据
public BaseResponse uploadAllOrder(String syncTime) {
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
if (syncTime == null) {
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_SCAN_ORDER);
if (basicExportStatusTimeEntity == null) {
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
}
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
} else {
spsSyncDataRequest.setLastUpdateTime(syncTime);
}
SpsSyncOrderResponse spsSyncOrderResponse = upBasicService.upAllOrder(spsSyncDataRequest);
if (CollUtil.isEmpty(spsSyncOrderResponse.getOrderEntities()) && CollUtil.isEmpty(spsSyncOrderResponse.getCodeEntities())) {
//无数据不记录日志
return ResultVOUtils.success("无数据");
}
BasicExportStatusEntity basicExportStatusEntity1 = basicExportService.findByData(ConstantStatus.SYNC_SCAN_ORDER, 0);
if (basicExportStatusEntity1 == null) {
BasicExportStatusEntity orderStatusEntity = new BasicExportStatusEntity();
orderStatusEntity.setId(CustomUtil.getId());
orderStatusEntity.setIdDatas(ConstantStatus.SYNC_SCAN_ORDER);
2 years ago
orderStatusEntity.setType(NEW_ALL_ORDER);
orderStatusEntity.setUpdateTime(new Date());
orderStatusEntity.setStartTime(new Date());
orderStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT);
orderStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
basicExportService.insertExportStatus(orderStatusEntity);
basicExportStatusEntity1 = orderStatusEntity;
}
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_SCAN_ORDER);
spsSyncOrderResponse.setTaskId(basicExportStatusEntity1.getId());
2 years ago
spsSyncOrderResponse.setType(NEW_ALL_ORDER);
BaseResponse<String> baseResponse1 = spGetHttp.postAllOrder(spsSyncOrderResponse);
if (baseResponse1.getCode() == 20000) {
basicExportStatusEntity1.setStatus(2);
} else {
basicExportStatusEntity1.setStatus(1);
}
basicExportStatusEntity1.setEndTime(new Date());
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
//拼接日志
String logs = "";
if (CollUtil.isNotEmpty(spsSyncOrderResponse.getOrderEntities()))
logs = logs + "单据:" + spsSyncOrderResponse.getOrderEntities().size() + "条\n";
if (CollUtil.isNotEmpty(spsSyncOrderResponse.getOrderDetailBizEntities()))
logs = logs + "单据详情:" + spsSyncOrderResponse.getOrderDetailBizEntities().size() + "条\n";
if (CollUtil.isNotEmpty(spsSyncOrderResponse.getCodeEntities()))
logs = logs + "单据条码信息:" + spsSyncOrderResponse.getCodeEntities().size() + "条\n";
basicExportStatusEntity1.setRemark(logs);
basicExportStatusEntity1.setUpdateTime(new Date());
try {
String fileFullPath = writeFile(filePrefix, NEW_ALL_ORDER, JsonUtils.toJsonString(spsSyncOrderResponse));
basicExportStatusEntity1.setCacheFilePath(fileFullPath);
} catch (IOException e) {
throw new RuntimeException(e);
}
basicExportService.updateExportStatus(basicExportStatusEntity1);
return ResultVOUtils.success();
}
//上传最近更新业务单据
public BaseResponse uploadAllBusOrder(String syncTime) {
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
if (syncTime == null) {
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_BUS_ORDER);
if (basicExportStatusTimeEntity == null) {
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
}
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
} else {
spsSyncDataRequest.setLastUpdateTime(syncTime);
}
SpsSyncBusOrderResponse spsSyncOrderResponse = upBasicService.upAllBusOrder(spsSyncDataRequest);
if (CollUtil.isEmpty(spsSyncOrderResponse.getPurOrderEntities()) && CollUtil.isEmpty(spsSyncOrderResponse.getPurOrderDetailEntities())) {
//无数据不记录日志
return ResultVOUtils.success("无数据");
}
BasicExportStatusEntity basicExportStatusEntity1 = basicExportService.findByData(ConstantStatus.SYNC_BUS_ORDER, 0);
if (basicExportStatusEntity1 == null) {
BasicExportStatusEntity orderStatusEntity = new BasicExportStatusEntity();
orderStatusEntity.setId(CustomUtil.getId());
orderStatusEntity.setIdDatas(ConstantStatus.SYNC_BUS_ORDER);
orderStatusEntity.setType(BasicProcessStatus.ALL_BUS_ORDER);
orderStatusEntity.setUpdateTime(new Date());
orderStatusEntity.setStartTime(new Date());
orderStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT);
orderStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
basicExportService.insertExportStatus(orderStatusEntity);
basicExportStatusEntity1 = orderStatusEntity;
}
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_BUS_ORDER);
spsSyncOrderResponse.setTaskId(basicExportStatusEntity1.getId());
spsSyncOrderResponse.setType(BasicProcessStatus.ALL_BUS_ORDER);
BaseResponse<String> baseResponse1 = spGetHttp.postAllBusOrder(spsSyncOrderResponse);
if (baseResponse1.getCode() == 20000) {
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
} else {
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
}
basicExportStatusEntity1.setEndTime(new Date());
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
//拼接日志
String logs = "";
if (CollUtil.isNotEmpty(spsSyncOrderResponse.getPurOrderEntities()))
logs = logs + "采购订单单据:" + spsSyncOrderResponse.getPurOrderEntities().size() + "条\n";
if (CollUtil.isNotEmpty(spsSyncOrderResponse.getPurOrderDetailEntities()))
logs = logs + "采购订单详情:" + spsSyncOrderResponse.getPurOrderDetailEntities().size() + "条\n";
basicExportStatusEntity1.setRemark(logs);
basicExportStatusEntity1.setUpdateTime(new Date());
basicExportService.updateExportStatus(basicExportStatusEntity1);
return ResultVOUtils.success();
}
private final RedisUtil redisUtil;
@Transactional(rollbackFor = Exception.class)
public void pushData(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_DATA:
if (needExec(info.getTypeBus(), info.getTypeScan(), info.getTypeThird())) {
uploadData(exportType, taskId, x -> x.getDocumentTypeData(info, taskId, now, syncTime));
}
break;
case USER_DATA:
if (needExec(info.getBasicDept(), info.getBasicInv(), info.getSysUser())) {
uploadData(exportType, taskId, x -> x.getUserData(info, taskId, now, syncTime));
}
break;
case THIRD_DATA:
if (needExec(info.getBasicThirdDept(), info.getBasicThirdInv(), info.getBasicThirdProducts(), info.getBasicThirdCorp())) {
uploadData(exportType, taskId, x -> x.getThirdData(info, taskId, now, syncTime));
}
break;
case SYS_SET_DATA:
if (needExec(info.getSystemConfig(), info.getEntrustAction(), info.getPrintConfig(), info.getScanChangeConfig(), info.getBusChangeConfig())) {
uploadData(exportType, taskId, x -> x.getSysSettingData(info, taskId, now, syncTime));
}
break;
}
}
/**
*
*
* @param info
* @param now
* @param syncTime -- exportTime
* @return
*/
public SpsSyncBasicDataResponse getBasicData(SyncDataSetEntity info, String taskId, Date now, Date syncTime) {
2 years ago
StringBuilder remark = new StringBuilder();
SpsSyncBasicDataResponse dataResponse = null;
Map<String, Object> syncTimeMap = new WeakHashMap<>(3);
syncTimeMap.put("isNew", true);
//确认有开启物资字典同步
if (needExec(info.getBasicProducts())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_PRODUCTS);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
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);
remark.append("物资字典分类信息:").append(hospTypeList.size()).append("条\n");
}
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);
remark.append("物资字典主表信息:").append(udiRelevanceList.size()).append("条\n");
}
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);
remark.append("物资字典子表信息:").append(udiRelevanceList.size()).append("条\n");
}
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);
remark.append("供应商物资字典信息:").append(relevanceList.size()).append("条\n");
}
}
//确认有开启往来单位字典同步
if (needExec(info.getBasicCorp())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_CORP);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
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);
remark.append("往来单位信息:").append(corpList.size()).append("条\n");
}
}
//确认有开启首营资质同步
if (info.getSupCert() == 2) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.SUP_CERT);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
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);
remark.append("资质证书信息:").append(supCertList.size()).append("条\n");
}
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);
remark.append("资质证书要求设置信息:").append(supCertSetList.size()).append("条\n");
}
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);
remark.append("供应商资质信息:").append(supCompanyList.size()).append("条\n");
}
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);
remark.append("生产企业资质信息:").append(supManufacturerList.size()).append("条\n");
}
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);
remark.append("配送产品资质信息:").append(supProductList.size()).append("条\n");
}
}
if (dataResponse != null) {
dataResponse.setTaskId(taskId);
dataResponse.setType(BasicExportTypeEnum.BASIC_DATA.getRemark());
dataResponse.setSyncRemark(remark.toString());
}
return dataResponse;
}
/**
*
*
* @param info
* @param now
* @param syncTime -- exportTime
* @return
*/
public SpsSyncOtherDataResponse getOtherData(SyncDataSetEntity info, String taskId, Date now, Date syncTime) {
StringBuffer remark = new StringBuffer();
SpsSyncOtherDataResponse dataResponse = null;
Map<String, Object> syncTimeMap = new WeakHashMap<>(3);
syncTimeMap.put("isNew", true);
//确认有开启udi码补齐同步
if (needExec(info.getUdiCodeLost())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_LOST);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
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);
remark.append("UDI码补齐信息").append(ioCodeLostList.size()).append("条\n");
}
}
//确认有开启udi关联关系同步
if (needExec(info.getUdiCodeRel())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_REL);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
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);
remark.append("UDI码关联关系").append(ioCodeRelList.size()).append("条\n");
}
}
if (dataResponse != null) {
dataResponse.setTaskId(taskId);
dataResponse.setType(BasicExportTypeEnum.OTHER_DATA.getRemark());
dataResponse.setSyncRemark(remark.toString());
}
return dataResponse;
}
private String writeFile(String filePath, String fileDesc, String content) throws IOException {
filePath = String.format("%s/%s", filePath, DateUtil.getDate());
String fileFullPath = String.format("%s/%s-%s.udi", filePath, fileDesc, IdUtil.fastSimpleUUID());
File file = new File(filePath);
if (!file.exists()) {
file.mkdirs();
}
file = new File(fileFullPath);
while (!file.createNewFile()) {
fileFullPath = String.format("%s/%s/%s-%s.udi", filePath, DateUtil.getDate(), fileDesc, IdUtil.fastSimpleUUID());
file = new File(fileFullPath);
}
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(content);
fileWriter.flush();
fileWriter.close();
return fileFullPath;
}
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);
StringBuffer remark = new StringBuffer();
//确认有开启扫码单据类型同步
if (needExec(info.getTypeScan())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSSINESS_TYPE);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
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);
remark.append("扫码单据类型信息:").append(bussinessTypeEntities.size()).append("条\n");
}
}
//确认有开启业务单据类型同步
if (needExec(info.getTypeBus())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSTYPE_CHANGE);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
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);
remark.append("业务单据类型:").append(busTypeChangeList.size()).append("条\n");
}
}
//确认有开启第三方单据类型同步
if (needExec(info.getTypeThird())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_BUSTYPE_ORIGIN);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
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);
remark.append("第三方单据类型信息:").append(thrBusTypeOriginEntities.size()).append("条\n");
}
}
if (dataResponse != null) {
dataResponse.setTaskId(taskId);
dataResponse.setType(BasicExportTypeEnum.DOCUMENT_TYPE_DATA.getRemark());
dataResponse.setSyncRemark(remark.toString());
}
return dataResponse;
}
private final DeptService deptService;
private final DeptUserService deptUserService;
private final InvWarehouseService warehouseService;
private final WarehouseUserService warehouseUserService;
private final WarehouseBussinessTypeService warehouseBussinessTypeService;
private final InvSpaceService invSpaceService;
private final AuthAdminService adminService;
private final InvBusUserService invBusUserService;
/**
*
*
* @param info
* @param now
* @param syncTime -- exportTime
* @return
*/
public SpsSyncDataResponse getUserData(SyncDataSetEntity info, String taskId, Date now, Date syncTime) {
SpsSyncDataResponse dataResponse = null;
Map<String, Object> syncTimeMap = new WeakHashMap<>(3);
syncTimeMap.put("isNew", true);
StringBuffer remark = new StringBuffer();
//确认有开启部门信息同步
if (needExec(info.getBasicDept())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.DEPT_DATA);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<DeptEntity> deptEntityList = deptService.list(Wrappers.lambdaQuery(DeptEntity.class)
.le((boolean) map.get("isNew"), DeptEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), DeptEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(deptEntityList)) {
dataResponse = new SpsSyncDataResponse();
dataResponse.setDeptEntityList(deptEntityList);
remark.append("部门信息:").append(deptEntityList.size()).append("条\n");
}
List<DeptUserEntity> deptUserEntityList = deptUserService.list(Wrappers.lambdaQuery(DeptUserEntity.class)
.le((boolean) map.get("isNew"), DeptUserEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), DeptUserEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(deptUserEntityList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncDataResponse();
}
dataResponse.setDeptUserEntities(deptUserEntityList);
remark.append("部门用户信息:").append(deptEntityList.size()).append("条\n");
}
}
//确认有开启仓库字典同步
if (needExec(info.getBasicInv())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.WAREHOUSE_DICT);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<InvWarehouseEntity> warehouseEntityList = warehouseService.list(Wrappers.lambdaQuery(InvWarehouseEntity.class)
.le((boolean) map.get("isNew"), InvWarehouseEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), InvWarehouseEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(warehouseEntityList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncDataResponse();
}
remark.append("仓库字典信息:").append(warehouseEntityList.size()).append("条\n");
dataResponse.setInvWarehouseEntities(warehouseEntityList);
}
List<WarehouseUserEntity> warehouseUserEntities = warehouseUserService.list(Wrappers.lambdaQuery(WarehouseUserEntity.class)
.le((boolean) map.get("isNew"), WarehouseUserEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), WarehouseUserEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(warehouseUserEntities)) {
if (dataResponse == null) {
dataResponse = new SpsSyncDataResponse();
}
remark.append("仓库用户信息:").append(warehouseUserEntities.size()).append("条\n");
dataResponse.setWarehouseUserEntities(warehouseUserEntities);
}
List<WarehouseBussinessTypeEntity> warehouseBussinessTypeEntities = warehouseBussinessTypeService.list(Wrappers.lambdaQuery(WarehouseBussinessTypeEntity.class)
.le((boolean) map.get("isNew"), WarehouseBussinessTypeEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), WarehouseBussinessTypeEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(warehouseBussinessTypeEntities)) {
if (dataResponse == null) {
dataResponse = new SpsSyncDataResponse();
}
dataResponse.setWarehouseBussinessTypeEntities(warehouseBussinessTypeEntities);
remark.append("仓库单据类型信息:").append(warehouseBussinessTypeEntities.size()).append("条\n");
}
List<InvSpace> invSpaceList = invSpaceService.list(Wrappers.lambdaQuery(InvSpace.class)
.le((boolean) map.get("isNew"), InvSpace::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), InvSpace::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(invSpaceList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncDataResponse();
}
dataResponse.setInvSpaces(invSpaceList);
remark.append("货位信息:").append(invSpaceList.size()).append("条\n");
}
}
//确认有开启用户信息同步
if (needExec(info.getSysUser())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.USER_DATA);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<AuthAdmin> adminList = adminService.list(Wrappers.lambdaQuery(AuthAdmin.class)
.le((boolean) map.get("isNew"), AuthAdmin::getLastModifyTime, now)
.between(!(boolean) map.get("isNew"), AuthAdmin::getLastModifyTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(adminList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncDataResponse();
}
dataResponse.setAuthAdminList(adminList);
remark.append("系统用户信息:").append(adminList.size()).append("条\n");
}
List<InvBusUserEntity> busUserEntities = invBusUserService.list(Wrappers.lambdaQuery(InvBusUserEntity.class)
.le((boolean) map.get("isNew"), InvBusUserEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), InvBusUserEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(busUserEntities)) {
if (dataResponse == null) {
dataResponse = new SpsSyncDataResponse();
}
dataResponse.setInvBusUserEntities(busUserEntities);
remark.append("用户关联单据信息:").append(busUserEntities.size()).append("条\n");
}
}
if (dataResponse != null) {
dataResponse.setTaskId(taskId);
dataResponse.setType(BasicExportTypeEnum.USER_DATA.getRemark());
dataResponse.setSyncRemark(remark.toString());
}
return dataResponse;
}
private final ThrDeptService thrDeptService;
private final ThrInvWarehouseService thrInvWarehouseService;
private final ThrProductsService thrProductsService;
private final ThrCorpService thrCorpService;
/**
*
*
* @param info
* @param now
* @param syncTime -- exportTime
* @return
*/
private SpsSyncThrDataResponse getThirdData(SyncDataSetEntity info, String taskId, Date now, Date syncTime) {
SpsSyncThrDataResponse dataResponse = null;
Map<String, Object> syncTimeMap = new WeakHashMap<>(3);
syncTimeMap.put("isNew", true);
StringBuffer remark = new StringBuffer();
//确认有开启第三方部门信息同步
if (needExec(info.getBasicThirdInv())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_DEPT);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<ThrDeptEntity> deptEntityList = thrDeptService.list(Wrappers.lambdaQuery(ThrDeptEntity.class)
.le((boolean) map.get("isNew"), ThrDeptEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), ThrDeptEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(deptEntityList)) {
dataResponse = new SpsSyncThrDataResponse();
dataResponse.setDeptEntities(deptEntityList);
remark.append("第三方部门信息:").append(deptEntityList.size()).append("条\n");
}
}
//确认有开启第三方仓库信息同步
if (needExec(info.getBasicThirdInv())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_WAREHOUSE);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<ThrInvWarehouseEntity> warehouseEntityList = thrInvWarehouseService.list(Wrappers.lambdaQuery(ThrInvWarehouseEntity.class)
.le((boolean) map.get("isNew"), ThrInvWarehouseEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), ThrInvWarehouseEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(warehouseEntityList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncThrDataResponse();
}
dataResponse.setInvWarehouseEntities(warehouseEntityList);
remark.append("第三方仓库信息:").append(warehouseEntityList.size()).append("条\n");
}
}
//确认有开启仓库字典同步
if (needExec(info.getBasicThirdProducts())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_PRODUCTS);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<ThrProductsEntity> productsEntityList = thrProductsService.list(Wrappers.lambdaQuery(ThrProductsEntity.class)
.le((boolean) map.get("isNew"), ThrProductsEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), ThrProductsEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(productsEntityList)) {
if (dataResponse == null) {
dataResponse = new SpsSyncThrDataResponse();
}
dataResponse.setProductsEntityList(productsEntityList);
remark.append("第三方产品信息:").append(productsEntityList.size()).append("条\n");
}
}
//确认有开启第三方往来单位信息同步
if (needExec(info.getBasicThirdCorp())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_CORP);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<ThrCorpEntity> corpEntities = thrCorpService.list(Wrappers.lambdaQuery(ThrCorpEntity.class)
.le((boolean) map.get("isNew"), ThrCorpEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), ThrCorpEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(corpEntities)) {
if (dataResponse == null) {
dataResponse = new SpsSyncThrDataResponse();
}
dataResponse.setCorpEntities(corpEntities);
remark.append("第三方往来信息:").append(corpEntities.size()).append("条\n");
}
}
if (dataResponse != null) {
dataResponse.setTaskId(taskId);
dataResponse.setType(BasicExportTypeEnum.THIRD_DATA.getRemark());
dataResponse.setSyncRemark(remark.toString());
}
return dataResponse;
}
private final SystemParamConfigService systemParamConfigService;
private final EntrustReceService entrustReceService;
private final SystemPDFModuleService systemPDFModuleService;
private final SystemPDFTemplateService systemPDFTemplateService;
private final SystemPDFTemplateRelevanceCodeService systemPDFTemplateRelevanceCodeService;
private final SystemPDFTemplateRelevanceBizService systemPDFTemplateRelevanceBizService;
private final SystemPDFTemplateRelevanceLabelService systemPDFTemplateRelevanceLabelService;
private final SystemPDFTemplateRelevanceStatemenService systemPDFTemplateRelevanceStatemenService;
private final IBasicBusTypePreService iBasicBusTypePreService;
private final IBasicBusTypeChangeService iBasicBusTypeChangeService;
/**
*
*
* @param info
* @param now
* @param syncTime -- exportTime
* @return
*/
private SpsSyncSysSettingResponse getSysSettingData(SyncDataSetEntity info, String taskId, Date now, Date syncTime) {
SpsSyncSysSettingResponse dataResponse = null;
Map<String, Object> syncTimeMap = new WeakHashMap<>(3);
syncTimeMap.put("isNew", true);
StringBuffer remark = new StringBuffer();
if (needExec(info.getSystemConfig())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.SYSTEM_PARAM_CONFIG);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<SystemParamConfigEntity> systemParamConfigEntities = systemParamConfigService.list(Wrappers.lambdaQuery(SystemParamConfigEntity.class)
.le((boolean) map.get("isNew"), SystemParamConfigEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), SystemParamConfigEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(systemParamConfigEntities)) {
dataResponse = new SpsSyncSysSettingResponse();
dataResponse.setSystemParamConfigEntities(systemParamConfigEntities);
remark.append("运行参数设置信息:").append(systemParamConfigEntities.size()).append("条\n");
}
}
if (needExec(info.getEntrustAction())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.ENTRUST_ACCEPT);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<EntrustReceEntity> entrustReceEntities = entrustReceService.list(Wrappers.lambdaQuery(EntrustReceEntity.class)
.le((boolean) map.get("isNew"), EntrustReceEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), EntrustReceEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(entrustReceEntities)) {
if (dataResponse == null) {
dataResponse = new SpsSyncSysSettingResponse();
}
dataResponse.setEntrustReceEntities(entrustReceEntities);
remark.append("委托验收设置信息:").append(entrustReceEntities.size()).append("条\n");
}
}
if (needExec(info.getPrintConfig())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.PRINT_CONFIG);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<SystemPDFModuleEntity> systemPDFModuleEntities = systemPDFModuleService.list(Wrappers.lambdaQuery(SystemPDFModuleEntity.class)
.le((boolean) map.get("isNew"), SystemPDFModuleEntity::getUpdate_time, now)
.between(!(boolean) map.get("isNew"), SystemPDFModuleEntity::getUpdate_time
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(systemPDFModuleEntities)) {
if (dataResponse == null) {
dataResponse = new SpsSyncSysSettingResponse();
}
dataResponse.setSystemPDFModuleEntities(systemPDFModuleEntities);
remark.append("系统模板模块信息:").append(systemPDFModuleEntities.size()).append("条\n");
}
List<SystemPDFTemplateEntity> systemPDFTemplateEntities = systemPDFTemplateService.list(Wrappers.lambdaQuery(SystemPDFTemplateEntity.class)
.le((boolean) map.get("isNew"), SystemPDFTemplateEntity::getUpdate_time, now)
.between(!(boolean) map.get("isNew"), SystemPDFTemplateEntity::getUpdate_time
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(systemPDFTemplateEntities)) {
if (dataResponse == null) {
dataResponse = new SpsSyncSysSettingResponse();
}
dataResponse.setSystemPDFTemplateEntities(systemPDFTemplateEntities);
remark.append("模板信息:").append(systemPDFTemplateEntities.size()).append("条\n");
}
List<SysPdfTemplateRelevanceCodeEntity> sysPdfTemplateRelevanceCodeEntities = systemPDFTemplateRelevanceCodeService.list(Wrappers.lambdaQuery(SysPdfTemplateRelevanceCodeEntity.class)
.le((boolean) map.get("isNew"), SysPdfTemplateRelevanceCodeEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), SysPdfTemplateRelevanceCodeEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(sysPdfTemplateRelevanceCodeEntities)) {
if (dataResponse == null) {
dataResponse = new SpsSyncSysSettingResponse();
}
dataResponse.setSysPdfTemplateRelevanceCodeEntities(sysPdfTemplateRelevanceCodeEntities);
remark.append("扫码单据关联模板信息:").append(sysPdfTemplateRelevanceCodeEntities.size()).append("条\n");
}
List<SysPdfTemplateRelevanceBizEntity> sysPdfTemplateRelevanceBizEntities = systemPDFTemplateRelevanceBizService.list(Wrappers.lambdaQuery(SysPdfTemplateRelevanceBizEntity.class)
.le((boolean) map.get("isNew"), SysPdfTemplateRelevanceBizEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), SysPdfTemplateRelevanceBizEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(sysPdfTemplateRelevanceBizEntities)) {
if (dataResponse == null) {
dataResponse = new SpsSyncSysSettingResponse();
}
dataResponse.setSysPdfTemplateRelevanceBizEntities(sysPdfTemplateRelevanceBizEntities);
remark.append("业务单据关联模板信息:").append(sysPdfTemplateRelevanceBizEntities.size()).append("条\n");
}
List<SysPdfTemplateRelevanceLabelEntity> sysPdfTemplateRelevanceLabelEntities = systemPDFTemplateRelevanceLabelService.list(Wrappers.lambdaQuery(SysPdfTemplateRelevanceLabelEntity.class)
.le((boolean) map.get("isNew"), SysPdfTemplateRelevanceLabelEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), SysPdfTemplateRelevanceLabelEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(sysPdfTemplateRelevanceLabelEntities)) {
if (dataResponse == null) {
dataResponse = new SpsSyncSysSettingResponse();
}
dataResponse.setSysPdfTemplateRelevanceLabelEntities(sysPdfTemplateRelevanceLabelEntities);
remark.append("标签关联模板信息:").append(sysPdfTemplateRelevanceLabelEntities.size()).append("条\n");
}
List<SysPdfTemplateRelevanceStatemenEntity> sysPdfTemplateRelevanceStatemenEntities = systemPDFTemplateRelevanceStatemenService.list(Wrappers.lambdaQuery(SysPdfTemplateRelevanceStatemenEntity.class)
.le((boolean) map.get("isNew"), SysPdfTemplateRelevanceStatemenEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), SysPdfTemplateRelevanceStatemenEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(sysPdfTemplateRelevanceStatemenEntities)) {
if (dataResponse == null) {
dataResponse = new SpsSyncSysSettingResponse();
}
dataResponse.setSysPdfTemplateRelevanceStatemenEntities(sysPdfTemplateRelevanceStatemenEntities);
remark.append("报表关联模板信息:").append(sysPdfTemplateRelevanceStatemenEntities.size()).append("条\n");
}
}
if (needExec(info.getScanChangeConfig())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.SCAN_CHANGE);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<BasicBusTypePreEntity> basicBusTypePreEntities = iBasicBusTypePreService.list(Wrappers.lambdaQuery(BasicBusTypePreEntity.class)
.le((boolean) map.get("isNew"), BasicBusTypePreEntity::getUpdateTime, now)
.between(!(boolean) map.get("isNew"), BasicBusTypePreEntity::getUpdateTime
, map.get("oldDate"), now)
);
if (CollectionUtil.isNotEmpty(basicBusTypePreEntities)) {
dataResponse = new SpsSyncSysSettingResponse();
dataResponse.setBasicBusTypePreEntities(basicBusTypePreEntities);
remark.append("出入库单自动补单设置信息:").append(basicBusTypePreEntities.size()).append("条\n");
}
}
if (needExec(info.getBusChangeConfig())) {
Map<String, Object> map;
if (syncTime == null) {
map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BUS_TYPE_CHANGE);
} else {
map = syncTimeMap;
2 years ago
now = syncTime;
}
List<BasicBusTypeChangeEntity> basicBusTypeChangeEntities = iBasicBusTypeChangeService.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(basicBusTypeChangeEntities)) {
dataResponse = new SpsSyncSysSettingResponse();
dataResponse.setBasicBusTypeChangeEntities(basicBusTypeChangeEntities);
remark.append("业务单自动补单设置信息:").append(basicBusTypeChangeEntities.size()).append("条\n");
}
}
if (dataResponse != null) {
dataResponse.setTaskId(taskId);
dataResponse.setType(BasicExportTypeEnum.SYS_SET_DATA.getRemark());
dataResponse.setSyncRemark(remark.toString());
if (CollUtil.isNotEmpty(dataResponse.getSystemPDFTemplateEntities())) {
// List<Map<String, String>> list = new ArrayList<>(spsSyncSysSettingResponse.getSystemPDFTemplateEntities().size() * 2);
List<String> list = new ArrayList<>();
dataResponse.getSystemPDFTemplateEntities().forEach(systemPDFTemplateEntity -> {
list.add(systemPDFTemplateEntity.getPath());
});
BaseResponse<String> response = spGetHttp.postTemplateFile(list);
if (response.getCode() == 20000) {
log.info("模板文件列表上传成功");
// uploadFileLog = "\n模板文件列表上传成功";
} else {
log.info("模板文件上传失败,响应信息:{}", response.getMessage());
// uploadFileLog = "\n模板文件列表上传失败错误信息" + response.getMessage();
}
}
}
return dataResponse;
}
/**
*
*
* @param set
* @return
*/
private boolean needExec(int... set) {
return Arrays.stream(set).filter(i -> i == 1).findAny().isPresent();
}
@Transactional(rollbackFor = Exception.class)
public void uploadData(BasicExportTypeEnum exportType, String taskId, Function<HeartService, Object> dataMethod) {
Date startTime = new Date();
2 years ago
Integer status = StatusEnum.SUCCESS.getCode();
Object data = dataMethod.apply(this);
if (data == null) {
return;
}
2 years ago
BaseResponse<String> baseResponse = spGetHttp.postData(taskId, exportType, data);
if (baseResponse.getCode() != 20000) {
2 years ago
status = StatusEnum.FAILED.getCode();
}
BaseSyncResponse baseSyncResponse = (BaseSyncResponse) data;
BasicExportStatusEntity exportStatus = BasicExportStatusEntity.builder()
.id(taskId)
.status(status)
.idDatas(exportType.getKey())
.type(exportType.getRemark())
.startTime(startTime)
.endTime(new Date())
.updateTime(new Date())
.receiveStatus(String.valueOf(status))
.scheduleType(BasicProcessStatus.SCHEDULE_NORMAL)
.remark(baseSyncResponse.getSyncRemark())
.build();
try {
String fileFullPath = writeFile(filePrefix, exportType.getRemark(), JsonUtils.toJsonString(data));
exportStatus.setCacheFilePath(fileFullPath);
} catch (IOException e) {
throw new RuntimeException(e);
2 years ago
} finally {
applicationContext.getBean(this.getClass()).insertExportStatus(exportStatus);
}
if (baseResponse.getCode() != 20000) {
throw new RuntimeException(baseResponse.getMessage());
}
}
@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) {
Date startTime = new Date();
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
if (syncTime == null) {
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_BUS_TYPE);
if (basicExportStatusTimeEntity == null) {
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
}
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
} else {
spsSyncDataRequest.setLastUpdateTime(syncTime);
}
SpsSyncBusResponse spsSyncBusResponse = upBasicService.upAllBus(spsSyncDataRequest);
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);
if (basicExportStatusEntity2 == null) {
BasicExportStatusEntity busTypetatusEntity = new BasicExportStatusEntity();
busTypetatusEntity.setId(CustomUtil.getId());
busTypetatusEntity.setIdDatas(ConstantStatus.SYNC_BUS_TYPE);
busTypetatusEntity.setType(BasicProcessStatus.NEW_ALL_BUS);
busTypetatusEntity.setUpdateTime(startTime);
busTypetatusEntity.setStartTime(new Date());
busTypetatusEntity.setStatus(0);
busTypetatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
basicExportService.insertExportStatus(busTypetatusEntity);
basicExportStatusEntity2 = busTypetatusEntity;
}
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_BUS_TYPE);
spsSyncBusResponse.setTaskId(basicExportStatusEntity2.getId());
BaseResponse<String> baseResponse2 = spGetHttp.postAllBusType(spsSyncBusResponse);
if (baseResponse2.getCode() == 20000) {
basicExportStatusEntity2.setStatus(1);
} else {
basicExportStatusEntity2.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
}
basicExportStatusEntity2.setEndTime(new Date());
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
//拼接日志
String logs = "";
if (CollUtil.isNotEmpty(spsSyncBusResponse.getBussinessTypeEntities()))
logs = logs + "扫码单据类型:" + spsSyncBusResponse.getBussinessTypeEntities().size() + "条\n";
if (CollUtil.isNotEmpty(spsSyncBusResponse.getBusTypeChangeEntities()))
logs = logs + "业务单据类型:" + spsSyncBusResponse.getBusTypeChangeEntities().size() + "条\n";
if (CollUtil.isNotEmpty(spsSyncBusResponse.getThrBusTypeOriginEntities()))
logs = logs + "第三方单据类型:" + spsSyncBusResponse.getThrBusTypeOriginEntities().size() + "条\n";
basicExportStatusEntity2.setRemark(logs);
basicExportStatusEntity2.setUpdateTime(new Date());
basicExportService.updateExportStatus(basicExportStatusEntity2);
return ResultVOUtils.success();
}
//上传用户信息
public BaseResponse uploadAllUserData(String syncTime) {
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
if (syncTime == null) {
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_BASIC_DATA);
if (basicExportStatusTimeEntity == null) {
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
}
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
} else {
spsSyncDataRequest.setLastUpdateTime(syncTime);
}
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())) {
//数据不记录日志
return ResultVOUtils.success("无数据");
}
BasicExportStatusEntity basicExportStatusEntity3 = basicExportService.findByData(ConstantStatus.SYNC_BASIC_DATA, 0);
if (basicExportStatusEntity3 == null) {
BasicExportStatusEntity basicExportStatusEntity = new BasicExportStatusEntity();
basicExportStatusEntity.setId(CustomUtil.getId());
basicExportStatusEntity.setIdDatas(ConstantStatus.SYNC_BASIC_DATA);
basicExportStatusEntity.setType(BasicProcessStatus.NEW_ALL_DATA);
basicExportStatusEntity.setUpdateTime(new Date());
basicExportStatusEntity.setStartTime(new Date());
basicExportStatusEntity.setStatus(0);
basicExportStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
basicExportService.insertExportStatus(basicExportStatusEntity);
basicExportStatusEntity3 = basicExportStatusEntity;
}
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_BASIC_DATA);
syncDataResponse.setTaskId(basicExportStatusEntity3.getId());
BaseResponse<String> baseResponse = spGetHttp.postAllUser(syncDataResponse);
if (baseResponse.getCode() == 20000) {
basicExportStatusEntity3.setStatus(1);
} else {
basicExportStatusEntity3.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
}
basicExportStatusEntity3.setEndTime(new Date());
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
String logs = "";
if (CollUtil.isNotEmpty(syncDataResponse.getInvWarehouseEntities()))
logs = logs + "仓库字典:" + syncDataResponse.getInvWarehouseEntities().size() + "条\n";
if (CollUtil.isNotEmpty(syncDataResponse.getWarehouseUserEntities())) {
logs = logs + "仓库用户信息:" + syncDataResponse.getWarehouseUserEntities().size() + "条\n";
}
if (CollUtil.isNotEmpty(syncDataResponse.getWarehouseBussinessTypeEntities())) {
logs = logs + "仓库单据类型:" + syncDataResponse.getWarehouseBussinessTypeEntities().size() + "条\n";
}
if (CollUtil.isNotEmpty(syncDataResponse.getAuthAdminList()))
logs = logs + "系统用户信息:" + syncDataResponse.getAuthAdminList().size() + "条\n";
if (CollUtil.isNotEmpty(syncDataResponse.getInvBusUserEntities()))
logs = logs + "用户关联单据类型信息:" + syncDataResponse.getInvBusUserEntities().size() + "条\n";
if (CollUtil.isNotEmpty(syncDataResponse.getDeptEntityList()))
logs = logs + "部门信息:" + syncDataResponse.getDeptEntityList().size() + "条\n";
if (CollUtil.isNotEmpty(syncDataResponse.getDeptUserEntities()))
logs = logs + "部门用户信息:" + syncDataResponse.getDeptUserEntities().size() + "条\n";
if (CollUtil.isNotEmpty(syncDataResponse.getInvSpaces()))
logs = logs + "货位信息:" + syncDataResponse.getInvSpaces().size() + "条\n";
basicExportStatusEntity3.setRemark(logs);
basicExportStatusEntity3.setUpdateTime(new Date());
basicExportService.updateExportStatus(basicExportStatusEntity3);
return ResultVOUtils.success();
}
2 years ago
//下载最近更新扫码单据--上级服务
@Transactional(propagation = Propagation.NESTED)
public void dlAllOrder() {
Date startTime = new Date();
BaseResponse<List<BasicExportStatusEntity>> baseResponse = spGetHttp.getBasicStatus(NEW_ALL_ORDER + "", "3");
2 years ago
List<BasicExportStatusEntity> pageSimpleResponse = baseResponse != null ? baseResponse.getData() : new ArrayList<>();
if (pageSimpleResponse != null) {
List<BasicExportStatusEntity> basicExportStatusEntities = pageSimpleResponse;
if (basicExportStatusEntities != null && basicExportStatusEntities.size() > 0) {
for (BasicExportStatusEntity basicExportStatusEntity : basicExportStatusEntities) {
2 years ago
String datas = spGetHttp.getBasicData(basicExportStatusEntity.getId(), NEW_ALL_ORDER);
2 years ago
BaseResponse<String> response = JSONObject.parseObject(datas, new TypeReference<BaseResponse<String>>() {
});
if (response.getCode() == 20000 && response.getData() != null) {
2 years ago
SpsSyncOrderResponse syncDataResponse = JSONObject.parseObject(response.getData(), new TypeReference<SpsSyncOrderResponse>() {
});
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(syncDataResponse.getTaskId());
basicDownloadStatusEntity.setStartTime(startTime);
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_DOWNLOAD_SCAN_ORDER);
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT); //下载中
2 years ago
basicDownloadStatusEntity.setType(NEW_ALL_ORDER);
basicDownloadStatusEntity.setRemark(syncDataResponse.getSyncRemark());
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
if (CollUtil.isNotEmpty(syncDataResponse.getOrderEntities())) {
try {
List<IoOrderEntity> orderEntities = syncDataResponse.getOrderEntities();
for (IoOrderEntity orderEntity : orderEntities) {
orderEntity.setUpdateTime(null);
orderEntity.setFromType(ConstantStatus.FROM_UDISP);
orderEntity.setProcessStatus(ConstantStatus.ORDER_DEAL_POST);
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_PROCESS);
2 years ago
IoOrderEntity temp = orderService.findByBillNo(orderEntity.getBillNo());
if (temp == null) {
orderEntity.setId(null);
orderService.insertOrder(orderEntity);
insetOrderDb(syncDataResponse, orderEntity);
2 years ago
orderEntity = orderService.findByBillNo(orderEntity.getBillNo());
addInoutService.dealProcess(orderEntity);
orderEntity = orderService.findByBillNo(orderEntity.getBillNo());
if (orderEntity.getStatus() != ConstantStatus.ORDER_STATS_ERROR && !ioCheckInoutService.checkManual(orderEntity.getBillNo())) {
ioCheckInoutService.check(orderEntity.getBillNo());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
2 years ago
}
spGetHttp.finishTask(basicExportStatusEntity.getId());
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
2 years ago
basicDownloadStatusEntity.setStatus(StatusEnum.SUCCESS.getCode());
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
2 years ago
}
}
}
}
}
// 下载最近更新国家库数据-上级服务
@Transactional(propagation = Propagation.NESTED)
public void dlAllDiProducts() {
Date startTime = new Date();
BaseResponse<List<BasicExportStatusEntity>> baseResponse = spGetHttp.getBasicStatus(NEW_ALL_UDIS, "3");
List<BasicExportStatusEntity> pageSimpleResponse = baseResponse.getData();
if (pageSimpleResponse != null) {
List<BasicExportStatusEntity> basicExportStatusEntities = pageSimpleResponse;
if (basicExportStatusEntities != null && basicExportStatusEntities.size() > 0) {
for (BasicExportStatusEntity basicExportStatusEntity : basicExportStatusEntities) {
long curTime = System.currentTimeMillis();
// log.info("--------等待时间------" + curTime);
2 years ago
String datas = spGetHttp.getBasicData(basicExportStatusEntity.getId(), BasicProcessStatus.NEW_ALL_UDIS);
// logger.info("--------等待时间1------" + (System.currentTimeMillis() - curTime) / 1000);
long curTime2 = System.currentTimeMillis();
BaseResponse<SpSyncUdiResponse> response = JSONObject.parseObject(datas, new TypeReference<BaseResponse<SpSyncUdiResponse>>() {
});
// logger.info("--------等待时间2------" + (System.currentTimeMillis() - curTime2) / 1000);
if (response.getCode() == 20000 && response.getData() != null) {
SpSyncUdiResponse spSyncUdiResponse = response.getData();
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(spSyncUdiResponse.getTaskId());
basicDownloadStatusEntity.setStartTime(startTime);
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_DOWNLOAD_DI_PRODUCTS);
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT); //下载中
2 years ago
basicDownloadStatusEntity.setType(BasicProcessStatus.NEW_ALL_UDIS);
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
StringBuffer remark = new StringBuffer();
SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
if (CollUtil.isNotEmpty(spSyncUdiResponse.getUdiCompanyEntities())) {
List<UdiCompanyEntity> udiCompanyEntities = spSyncUdiResponse.getUdiCompanyEntities();
UdiCompanyDao mapper = batchSession.getMapper(UdiCompanyDao.class);
for (UdiCompanyEntity udiCompanyEntity : udiCompanyEntities) {
mapper.insertUdiCompany(udiCompanyEntity);
}
batchSession.commit();
remark.append("公司信息:").append(spSyncUdiResponse.getUdiCompanyEntities().size()).append("条\n");
}
if (CollUtil.isNotEmpty(spSyncUdiResponse.getProductInfoEntityList())) {
List<ProductInfoEntity> productInfoEntities = spSyncUdiResponse.getProductInfoEntityList();
ProductInfoDao mapper = batchSession.getMapper(ProductInfoDao.class);
for (ProductInfoEntity productInfoEntity : productInfoEntities) {
mapper.insertProductInfo(productInfoEntity);
}
batchSession.commit();
remark.append("产品信息:").append(spSyncUdiResponse.getProductInfoEntityList().size()).append("条\n");
}
batchSession.close();
// spGetHttp.postBasicStatus(basicExportStatusEntity.getId());
spGetHttp.finishTask(basicExportStatusEntity.getId());
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setRemark(remark.toString());
try {
String fileFullPath = writeFile(filePrefix, NEW_ALL_UDIS, JSONUtil.toJsonStr(response.getData()));
basicDownloadStatusEntity.setCacheFilePath(fileFullPath);
} catch (IOException e) {
throw new RuntimeException(e);
}
2 years ago
basicDownloadStatusEntity.setStatus(StatusEnum.SUCCESS.getCode());
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
}
}
}
}
}
private final BasicHospTypeDao basicHospTypeDao;
private final UdiRelevanceDao udiRelevanceDao;
private final BasicProductsDao basicProductsDao;
private final CompanyProductRelevanceDao relevanceDao;
private final BasicCorpDao corpDao;
private final SupCertDao supCertDao;
private final SupCertSetDao supCertSetDao;
private final SupCompanyDao supCompanyDao;
private final SupManufacturerDao supManufacturerDao;
private final SupProductDao supProductDao;
@Value("${file_path}")
private String filePrefix;
/**
* UDI
*
* @param exportType
*/
@Transactional(rollbackFor = Exception.class)
public void pullData(BasicExportTypeEnum exportType) {
Date startTime = new Date();
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 DOCUMENT_TYPE_DATA:
this.insertDocumentTypeData(bean.getFileContent());
break;
}
String taskId = bean.getTaskId();
if (StrUtil.isNotBlank(taskId)) {
//插入下载记录
cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(bean.getFileContent());
String remark = jsonObject.getStr(Constant.SYNC_REMARK);
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(taskId);
basicDownloadStatusEntity.setStartTime(startTime);
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setIdDatas(exportType.getKey());
basicDownloadStatusEntity.setRemark(remark);
2 years ago
basicDownloadStatusEntity.setStatus(StatusEnum.SUCCESS.getCode()); //下载完成
basicDownloadStatusEntity.setType(exportType.getRemark());
basicDownloadStatusEntity.setScheduleType(1);
try {
String fileFullPath = writeFile(filePrefix, exportType.getRemark(), bean.getFileContent());
basicDownloadStatusEntity.setCacheFilePath(fileFullPath);
} catch (IOException e) {
throw new RuntimeException(e);
}
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
//通知自助平台任务已完成
spGetHttp.finishTask(taskId);
}
}
}
/**
*
*
* @param content
*/
@Transactional(propagation = Propagation.NESTED)
public void insertBasicData(String content) {
2 years ago
cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(content);
List<BasicHospTypeEntity> hospTypeList = JSONUtil.toList(jsonObject.getJSONArray(BasicHospTypeEntity.class.getSimpleName()), BasicHospTypeEntity.class);
List<UdiRelevanceEntity> udiRelevanceList = JSONUtil.toList(jsonObject.getJSONArray(UdiRelevanceEntity.class.getSimpleName()), UdiRelevanceEntity.class);
List<BasicProductsEntity> productsList = JSONUtil.toList(jsonObject.getJSONArray(BasicProductsEntity.class.getSimpleName()), BasicProductsEntity.class);
List<CompanyProductRelevanceEntity> relevanceList = JSONUtil.toList(jsonObject.getJSONArray(CompanyProductRelevanceEntity.class.getSimpleName()), CompanyProductRelevanceEntity.class);
List<BasicCorpEntity> corpList = JSONUtil.toList(jsonObject.getJSONArray(BasicCorpEntity.class.getSimpleName()), BasicCorpEntity.class);
List<SupCertEntity> supCertList = JSONUtil.toList(jsonObject.getJSONArray(SupCertEntity.class.getSimpleName()), SupCertEntity.class);
List<SupCertSetEntity> supCertSetList = JSONUtil.toList(jsonObject.getJSONArray(SupCertSetEntity.class.getSimpleName()), SupCertSetEntity.class);
List<SupCompanyEntity> supCompanyList = JSONUtil.toList(jsonObject.getJSONArray(SupCompanyEntity.class.getSimpleName()), SupCompanyEntity.class);
List<SupManufacturerEntity> supManufacturerList = JSONUtil.toList(jsonObject.getJSONArray(SupManufacturerEntity.class.getSimpleName()), SupManufacturerEntity.class);
List<SupProductEntity> supProductList = JSONUtil.toList(jsonObject.getJSONArray(SupProductEntity.class.getSimpleName()), SupProductEntity.class);
2 years ago
List<String> syncFiles = JSONUtil.toList(jsonObject.getJSONArray("syncFiles"), String.class);
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);
}
2 years ago
if (CollUtil.isNotEmpty(syncFiles)) {
fileService.download(syncFiles);
}
}
2 years ago
@Resource
FileService fileService;
private final IoCodeLostMapper ioCodeLostMapper;
private final IoCodeRelMapper ioCodeRelMapper;
@Resource
private final IoOrderInvoiceMapper ioOrderInvoiceMapper;
/**
*
*
* @param content
*/
@Transactional(propagation = Propagation.NESTED)
public void insertOtherData(String content) {
2 years ago
cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(content);
List<IoCodeLostEntity> ioCodeLostList = JSONUtil.toList(jsonObject.getJSONArray(IoCodeLostEntity.class.getSimpleName()), IoCodeLostEntity.class);
List<IoCodeRelEntity> ioCodeRelList = JSONUtil.toList(jsonObject.getJSONArray(IoCodeRelEntity.class.getSimpleName()), IoCodeRelEntity.class);
List<IoOrderInvoiceEntity> ioOrderInvoiceEntities = JSONUtil.toList(jsonObject.getJSONArray(IoOrderInvoiceEntity.class.getSimpleName()), IoOrderInvoiceEntity.class);
if (CollectionUtil.isNotEmpty(ioCodeLostList)) {
ioCodeLostMapper.insertOrUpdateBatch(ioCodeLostList);
}
if (CollectionUtil.isNotEmpty(ioCodeRelList)) {
ioCodeRelMapper.insertOrUpdateBatch(ioCodeRelList);
}
if (CollUtil.isNotEmpty(ioOrderInvoiceEntities)) {
ioOrderInvoiceMapper.insertOrUpdateBatch(ioOrderInvoiceEntities);
}
List<String> syncFiles = JSONUtil.toList(jsonObject.getJSONArray("syncFiles"), String.class);
if (CollUtil.isNotEmpty(syncFiles)) {
fileService.download(syncFiles);
}
}
private final BasicBussinessTypeDao bussinessTypeDao;
private final BasicBusTypeChangeDao busTypeChangeDao;
private final ThrBusTypeOriginDao thrBusTypeOriginDao;
/**
*
*
* @param content
*/
@Transactional(propagation = Propagation.NESTED)
public void insertDocumentTypeData(String content) {
cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(content);
List<BasicBussinessTypeEntity> bussinessTypeEntities = JSONUtil.toList(jsonObject.getJSONArray(BasicBussinessTypeEntity.class.getSimpleName()), BasicBussinessTypeEntity.class);
List<BasicBusTypeChangeEntity> busTypeChangeEntities = JSONUtil.toList(jsonObject.getJSONArray(BasicBusTypeChangeEntity.class.getSimpleName()), BasicBusTypeChangeEntity.class);
List<ThrBusTypeOriginEntity> typeOriginEntities = JSONUtil.toList(jsonObject.getJSONArray(ThrBusTypeOriginEntity.class.getSimpleName()), ThrBusTypeOriginEntity.class);
if (CollectionUtil.isNotEmpty(bussinessTypeEntities)) {
bussinessTypeDao.insertOrUpdateBatch(bussinessTypeEntities);
}
if (CollectionUtil.isNotEmpty(busTypeChangeEntities)) {
busTypeChangeDao.insertOrUpdateBatch(busTypeChangeEntities);
}
if (CollectionUtil.isNotEmpty(typeOriginEntities)) {
thrBusTypeOriginDao.insertOrUpdateBatch(typeOriginEntities);
}
}
/**
* UDI
*/
@Transactional(rollbackFor = Exception.class)
public void pullBasicData() {
String data = spGetHttp.pullBasicData();
cn.hutool.json.JSONObject obj = JSONUtil.parseObj(data);
Integer code = obj.getInt("code");
if (!code.equals(ResultVOUtils.success().getCode())) {
log.error("从UDI自助平台拉取基础数据错误报文-----{}", data);
return;
}
SpsSyncBasicDataResponse bean = obj.get("data", SpsSyncBasicDataResponse.class);
this.insertBasicData(bean);
2 years ago
String taskId = bean.getTaskId();
if (StrUtil.isNotBlank(taskId)) {
2 years ago
//插入下载记录
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);
}
}
/**
* UDI
*/
@Transactional(rollbackFor = Exception.class)
public void pullOtherData() {
String data = spGetHttp.pullOtherData();
cn.hutool.json.JSONObject obj = JSONUtil.parseObj(data);
Integer code = obj.getInt("code");
if (!code.equals(ResultVOUtils.success().getCode())) {
log.error("从UDI自助平台拉取其他数据报文-----{}", data);
return;
}
SpsSyncOtherDataResponse bean = obj.get("data", SpsSyncOtherDataResponse.class);
this.insertOtherData(bean);
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_OTHER_DATA);
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS); //下载完成
basicDownloadStatusEntity.setType(BasicProcessStatus.OTHER_DATA);
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
//通知自助平台任务已完成
spGetHttp.finishTask(taskId);
}
}
/**
*
*
* @param bean
*/
@Transactional(propagation = Propagation.NESTED)
public void insertBasicData(SpsSyncBasicDataResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getHospTypeList())) {
basicHospTypeDao.insertOrUpdateBatch(bean.getHospTypeList());
}
if (CollectionUtil.isNotEmpty(bean.getUdiRelevanceList())) {
udiRelevanceDao.insertOrUpdateBatch(bean.getUdiRelevanceList());
}
if (CollectionUtil.isNotEmpty(bean.getProductsList())) {
basicProductsDao.insertOrUpdateBatch(bean.getProductsList());
}
if (CollectionUtil.isNotEmpty(bean.getRelevanceList())) {
relevanceDao.insertOrUpdateBatch(bean.getRelevanceList());
}
if (CollectionUtil.isNotEmpty(bean.getCorpList())) {
corpDao.insertOrUpdateBatch(bean.getCorpList());
}
if (CollectionUtil.isNotEmpty(bean.getSupCertList())) {
supCertDao.insertOrUpdateBatch(bean.getSupCertList());
}
if (CollectionUtil.isNotEmpty(bean.getSupCertSetList())) {
supCertSetDao.insertOrUpdateBatch(bean.getSupCertSetList());
}
if (CollectionUtil.isNotEmpty(bean.getSupCompanyList())) {
supCompanyDao.insertOrUpdateBatch(bean.getSupCompanyList());
}
if (CollectionUtil.isNotEmpty(bean.getSupManufacturerList())) {
supManufacturerDao.insertOrUpdateBatch(bean.getSupManufacturerList());
}
if (CollectionUtil.isNotEmpty(bean.getSupProductList())) {
supProductDao.insertOrUpdateBatch(bean.getSupProductList());
}
}
/**
*
*
* @param bean
*/
@Transactional(propagation = Propagation.NESTED)
public void insertOtherData(SpsSyncOtherDataResponse bean) {
if (CollectionUtil.isNotEmpty(bean.getIoCodeLostList())) {
ioCodeLostMapper.insertOrUpdateBatch(bean.getIoCodeLostList());
}
if (CollectionUtil.isNotEmpty(bean.getIoCodeRelList())) {
ioCodeRelMapper.insertOrUpdateBatch(bean.getIoCodeRelList());
}
// if (CollectionUtil.isNotEmpty(bean.getI())) {
// ioCodeRelMapper.insertOrUpdateBatch(bean.getIoCodeRelList());
// }
}
public void insetOrderDb(SpsSyncOrderResponse syncDataResponse, IoOrderEntity orderEntity) {
//更新码详情
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities())) {
List<IoCodeEntity> warehouseEntityList = syncDataResponse.getCodeEntities();
for (IoCodeEntity warehouseEntity : warehouseEntityList) {
if (warehouseEntity.getOrderId().equals(orderEntity.getBillNo())) {
IoCodeTempEntity codeTempEntity = new IoCodeTempEntity();
BeanUtils.copyProperties(warehouseEntity, codeTempEntity);
codeTempEntity.setId(null);
codeTempService.insert(codeTempEntity);
}
}
}
//更新业务详情
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailBizEntities())) {
List<IoOrderDetailBizEntity> orderDetailBizEntities = syncDataResponse.getOrderDetailBizEntities();
for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) {
if (bizEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
bizEntity.setId(null);
orderDetailBizService.insert(bizEntity);
}
}
}
//更新码详情
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities())) {
List<IoOrderDetailCodeEntity> orderDetailCodeEntities = syncDataResponse.getOrderDetailCodeEntities();
for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) {
if (codeEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
codeEntity.setId(null);
orderDetailCodeService.insert(codeEntity);
}
}
}
//更新结果详情
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailResultEntities())) {
List<IoOrderDetailResultEntity> orderDetailResultEntities = syncDataResponse.getOrderDetailResultEntities();
for (IoOrderDetailResultEntity detailResultEntity : orderDetailResultEntities) {
if (detailResultEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
detailResultEntity.setId(null);
orderDetailResultService.insert(detailResultEntity);
}
}
}
//更新发票信息
if (CollUtil.isNotEmpty(syncDataResponse.getOrderInvoiceEntities())) {
List<IoOrderInvoiceEntity> orderInvoiceEntities = syncDataResponse.getOrderInvoiceEntities();
for (IoOrderInvoiceEntity orderInvoiceEntity : orderInvoiceEntities) {
if (orderInvoiceEntity.getOrderIdFk().equals(orderEntity.getBillNo())) {
orderInvoiceEntity.setId(IdUtil.getSnowflakeNextId());
orderInvoiceService.insertInvoice(orderInvoiceEntity);
}
}
}
}
2 years ago
/**
*
*
* @param syncTime
*/
public BaseResponse uploadThrData(String syncTime) {
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
if (syncTime == null) {
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_THR_DATA);
if (basicExportStatusTimeEntity == null) {
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
}
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
} else {
spsSyncDataRequest.setLastUpdateTime(syncTime);
}
SpsSyncThrDataResponse spsSyncThrDataResponse = upThrDataService.upThrData(spsSyncDataRequest);
if (CollUtil.isEmpty(spsSyncThrDataResponse.getDeptEntities()) && CollUtil.isEmpty(spsSyncThrDataResponse.getInvWarehouseEntities()) && CollUtil.isEmpty(spsSyncThrDataResponse.getCorpEntities())) {
//无数据不记录
log.info("无第三方基础数据需要同步");
return ResultVOUtils.success("无数据");
}
BasicExportStatusEntity basicExportStatusEntity1 = basicExportService.findByData(ConstantStatus.SYNC_THR_DATA, 0);
if (basicExportStatusEntity1 == null) {
BasicExportStatusEntity thrDataStatusEntity = new BasicExportStatusEntity();
thrDataStatusEntity.setId(CustomUtil.getId());
thrDataStatusEntity.setIdDatas(ConstantStatus.SYNC_THR_DATA);
thrDataStatusEntity.setType(BasicProcessStatus.NEW_ALL_THR_DATA);
thrDataStatusEntity.setUpdateTime(new Date());
thrDataStatusEntity.setStartTime(new Date());
thrDataStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT);
thrDataStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
basicExportService.insertExportStatus(thrDataStatusEntity);
basicExportStatusEntity1 = thrDataStatusEntity;
}
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_THR_DATA);
spsSyncThrDataResponse.setTaskId(basicExportStatusEntity1.getId());
BaseResponse<String> baseResponse = spGetHttp.postThrData(spsSyncThrDataResponse);
if (baseResponse.getCode() == 20000) {
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
} else {
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
}
basicExportStatusEntity1.setEndTime(new Date());
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
//拼接日志
StringBuilder logs = new StringBuilder();
if (CollUtil.isNotEmpty(spsSyncThrDataResponse.getDeptEntities())) {
logs.append("第三方部门信息:").append(spsSyncThrDataResponse.getDeptEntities().size()).append("条\n");
}
if (CollUtil.isNotEmpty(spsSyncThrDataResponse.getInvWarehouseEntities())) {
logs.append("第三方仓库信息:").append(spsSyncThrDataResponse.getInvWarehouseEntities().size()).append("条\n");
}
if (CollUtil.isNotEmpty(spsSyncThrDataResponse.getCorpEntities())) {
logs.append("第三方往来单位信息:").append(spsSyncThrDataResponse.getCorpEntities().size()).append("条\n");
}
basicExportStatusEntity1.setRemark(logs.toString());
basicExportStatusEntity1.setUpdateTime(new Date());
basicExportService.updateExportStatus(basicExportStatusEntity1);
return ResultVOUtils.success();
}
/**
*
*
* @param syncTime
* @return
*/
public BaseResponse uploadSysSetting(String syncTime) {
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
if (syncTime == null) {
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_SYS_SETTING);
if (basicExportStatusTimeEntity == null) {
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
}
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
} else {
spsSyncDataRequest.setLastUpdateTime(syncTime);
}
SpsSyncSysSettingResponse spsSyncSysSettingResponse = upBasicService.upSysSetting(spsSyncDataRequest);
if (BeanUtil.isEmpty(spsSyncSysSettingResponse)) {
//无数据不记录
log.info("无第系统设置需要同步");
return ResultVOUtils.success("无数据");
}
BasicExportStatusEntity basicExportStatusEntity1 = basicExportService.findByData(ConstantStatus.SYNC_SYS_SETTING, 0);
if (basicExportStatusEntity1 == null) {
BasicExportStatusEntity thrDataStatusEntity = new BasicExportStatusEntity();
thrDataStatusEntity.setId(CustomUtil.getId());
thrDataStatusEntity.setIdDatas(ConstantStatus.SYNC_SYS_SETTING);
thrDataStatusEntity.setType(BasicProcessStatus.NEW_ALL_SYS_SETTING);
thrDataStatusEntity.setUpdateTime(new Date());
thrDataStatusEntity.setStartTime(new Date());
thrDataStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT);
thrDataStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
basicExportService.insertExportStatus(thrDataStatusEntity);
basicExportStatusEntity1 = thrDataStatusEntity;
}
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_SYS_SETTING);
spsSyncSysSettingResponse.setTaskId(basicExportStatusEntity1.getId());
spsSyncSysSettingResponse.setType(basicExportStatusEntity1.getType());
spsSyncSysSettingResponse.setIdDatas(basicExportStatusEntity1.getIdDatas());
BaseResponse<String> baseResponse = spGetHttp.postSysSetting(spsSyncSysSettingResponse);
//若模板记录不为空,则将模板文件同步过去
String uploadFileLog = "";
if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getSystemPDFTemplateEntities())) {
// List<Map<String, String>> list = new ArrayList<>(spsSyncSysSettingResponse.getSystemPDFTemplateEntities().size() * 2);
List<String> list = new ArrayList<>();
spsSyncSysSettingResponse.getSystemPDFTemplateEntities().forEach(systemPDFTemplateEntity -> {
list.add(systemPDFTemplateEntity.getPath());
});
// BaseResponse<String> response = spGetHttp.postTemplateFile(list);
// if (response.getCode() == 20000) {
// log.info("模板文件列表上传成功");
// uploadFileLog = "\n模板文件列表上传成功";
// } else {
// log.info("模板文件上传失败,响应信息:{}", response.getMessage());
// uploadFileLog = "\n模板文件列表上传失败错误信息" + response.getMessage();
// }
}
if (baseResponse.getCode() == 20000) {
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
} else {
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
}
basicExportStatusEntity1.setEndTime(new Date());
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
basicExportStatusEntity1.setRemark(spsSyncSysSettingResponse.logs() + uploadFileLog);
basicExportStatusEntity1.setUpdateTime(new Date());
basicExportService.updateExportStatus(basicExportStatusEntity1);
return ResultVOUtils.success();
}
/**
*
*
* @param syncTime
* @return
*/
public BaseResponse uploadThrProducts(String syncTime) {
SpsSyncDataRequest spsSyncDataRequest = new SpsSyncDataRequest();
if (syncTime == null) {
BasicExportStatusTimeEntity basicExportStatusTimeEntity = basicExportTimeService.findByKey(ConstantStatus.SYNC_THR_PRODUCTS);
if (basicExportStatusTimeEntity == null) {
basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime("1949-10-01 09:00:00");
}
spsSyncDataRequest.setLastUpdateTime(basicExportStatusTimeEntity.getLastUpdateTime());
} else {
spsSyncDataRequest.setLastUpdateTime(syncTime);
}
SpsSyncThrProductsResponse spsSyncThrProductsResponse = upThrDataService.upThrProducts(spsSyncDataRequest);
if (CollUtil.isEmpty(spsSyncThrProductsResponse.getProductsEntities())) {
//无数据不记录
log.info("无第三方产品数据需要同步");
return ResultVOUtils.success("无数据");
}
BasicExportStatusEntity basicExportStatusEntity1 = basicExportService.findByData(ConstantStatus.SYNC_THR_PRODUCTS, 0);
if (basicExportStatusEntity1 == null) {
BasicExportStatusEntity thrDataStatusEntity = new BasicExportStatusEntity();
thrDataStatusEntity.setId(CustomUtil.getId());
thrDataStatusEntity.setIdDatas(ConstantStatus.SYNC_THR_PRODUCTS);
thrDataStatusEntity.setType(BasicProcessStatus.NEW_ALL_THR_PRODUCTS);
thrDataStatusEntity.setUpdateTime(new Date());
thrDataStatusEntity.setStartTime(new Date());
thrDataStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT);
thrDataStatusEntity.setScheduleType(BasicProcessStatus.SCHEDULE_NORMAL);
basicExportService.insertExportStatus(thrDataStatusEntity);
basicExportStatusEntity1 = thrDataStatusEntity;
}
BasicExportStatusTimeEntity basicExportStatusTimeEntity = new BasicExportStatusTimeEntity();
basicExportStatusTimeEntity.setLastUpdateTime(DateUtil.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
basicExportStatusTimeEntity.setKey(ConstantStatus.SYNC_THR_PRODUCTS);
spsSyncThrProductsResponse.setTaskId(basicExportStatusEntity1.getId());
BaseResponse<String> baseResponse = spGetHttp.postThrProducts(spsSyncThrProductsResponse);
if (baseResponse.getCode() == 20000) {
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
} else {
basicExportStatusEntity1.setStatus(ConstantStatus.SYNC_STATUS_FAIL);
}
basicExportStatusEntity1.setEndTime(new Date());
basicExportTimeService.insertExportStatus(basicExportStatusTimeEntity);
//拼接日志
StringBuilder logs = new StringBuilder();
if (CollUtil.isNotEmpty(spsSyncThrProductsResponse.getProductsEntities())) {
logs.append("第三方产品信息:").append(spsSyncThrProductsResponse.getProductsEntities().size()).append("条\n");
}
basicExportStatusEntity1.setRemark(logs.toString());
basicExportStatusEntity1.setUpdateTime(new Date());
basicExportService.updateExportStatus(basicExportStatusEntity1);
return ResultVOUtils.success();
}
}