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

1026 lines
55 KiB
Java

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.glxp.api.service.sync;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.BasicExportTypeEnum;
import com.glxp.api.constant.BasicProcessStatus;
import com.glxp.api.constant.ConstantStatus;
import com.glxp.api.dao.basic.*;
import com.glxp.api.dao.inout.IoCodeLostMapper;
import com.glxp.api.dao.inout.IoCodeRelMapper;
import com.glxp.api.dao.purchase.*;
import com.glxp.api.dto.RelaySyncDto;
import com.glxp.api.entity.basic.*;
import com.glxp.api.entity.inout.*;
import com.glxp.api.entity.purchase.*;
import com.glxp.api.entity.sync.BasicDownloadStatusEntity;
import com.glxp.api.entity.sync.BasicExportStatusEntity;
import com.glxp.api.entity.sync.BasicExportStatusTimeEntity;
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.inout.*;
import com.glxp.api.util.CustomUtil;
import com.glxp.api.util.DateUtil;
import com.glxp.api.util.JsonUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.ExecutorType;
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.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
@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;
//上传最近更新扫码单据
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);
orderStatusEntity.setType(BasicProcessStatus.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());
BaseResponse<String> baseResponse1 = spGetHttp.postAllOrder(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.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());
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());
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();
}
//上传最近更新单据类型
public BaseResponse uploadAllBus(String syncTime) {
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(new Date());
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();
}
// 上传系统参数设置
public BaseResponse uploadAllConfig(String syncTime) {
return null;
}
//
// //上传最近更新第三方基础数据
// public BaseResponse uploadThirdData(String syncTime) {
//
// }
//下载最近更新扫码单据--上级服务
public void dlAllOrder() {
BaseResponse<List<BasicExportStatusEntity>> baseResponse = spGetHttp.getBasicStatus(BasicProcessStatus.NEW_ALL_ORDER + "");
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) {
String datas = spGetHttp.getBasicData(basicExportStatusEntity.getId(), BasicProcessStatus.NEW_ALL_ORDER);
BaseResponse<String> response = JSONObject.parseObject(datas, new TypeReference<BaseResponse<String>>() {
});
if (response.getCode() == 20000 && response.getData() != null) {
SpsSyncOrderResponse syncDataResponse = JSONObject.parseObject(response.getData(), new TypeReference<SpsSyncOrderResponse>() {
});
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(syncDataResponse.getTaskId());
basicDownloadStatusEntity.setStartTime(new Date());
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_DOWNLOAD_SCAN_ORDER);
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT); //下载中
basicDownloadStatusEntity.setType(BasicProcessStatus.NEW_ALL_ORDER);
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
StringBuffer remark = new StringBuffer();
if (CollUtil.isNotEmpty(syncDataResponse.getOrderEntities())) {
try {
List<IoOrderEntity> orderEntities = syncDataResponse.getOrderEntities();
for (IoOrderEntity orderEntity : orderEntities) {
orderEntity.setUpdateTime(null);
orderEntity.setFromType(ConstantStatus.FROM_UDISP);
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_PROCESS);
IoOrderEntity temp = orderService.findByBillNo(orderEntity.getBillNo());
if (temp == null) {
orderEntity.setId(null);
orderService.insertOrder(orderEntity);
insetOrderDb(syncDataResponse, orderEntity);
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());
}
}
}
String logs = "";
if (CollUtil.isNotEmpty(syncDataResponse.getOrderEntities()))
logs = logs + "单据:" + syncDataResponse.getOrderEntities().size() + "条\n";
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailBizEntities()))
logs = logs + "业务详情:" + syncDataResponse.getOrderDetailBizEntities().size() + "条\n";
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities()))
logs = logs + "单据扫码详情:" + syncDataResponse.getOrderDetailCodeEntities().size() + "条\n";
if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailResultEntities()))
logs = logs + "单据结果详情:" + syncDataResponse.getOrderDetailResultEntities().size() + "条\n";
if (CollUtil.isNotEmpty(syncDataResponse.getCodeEntities()))
logs = logs + "单据条码信息:" + syncDataResponse.getCodeEntities().size() + "条\n";
remark.append(logs);
} catch (Exception e) {
e.printStackTrace();
}
}
spGetHttp.postBasicStatus(basicExportStatusEntity.getId());
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setRemark(remark.toString());
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity);
}
}
}
}
}
// 下载最近更新国家库数据-上级服务
public void dlAllDiProducts() {
BaseResponse<List<BasicExportStatusEntity>> baseResponse = spGetHttp.getBasicStatus(BasicProcessStatus.NEW_ALL_DI + "");
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);
String datas = spGetHttp.getBasicData(basicExportStatusEntity.getId(), BasicProcessStatus.NEW_ALL_DI);
// 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(new Date());
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_DOWNLOAD_DI_PRODUCTS);
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT); //下载中
basicDownloadStatusEntity.setType(BasicProcessStatus.NEW_ALL_DI);
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());
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setRemark(remark.toString());
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS);
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;
/**
* 从UDI自助平台拉取 统一方法
*
* @param exportType 任务类型
*/
@Transactional(rollbackFor = Exception.class)
public void pullData(BasicExportTypeEnum exportType) {
String data = spGetHttp.pullData(exportType);
cn.hutool.json.JSONObject obj = JSONUtil.parseObj(data);
Integer code = obj.getInt("code");
if (!code.equals(20000)) {
log.error("从UDI自助平台拉取数据错误报文-----{}", data);
return;
}
//数据内容
String dataStr = obj.getStr("data");
if (StrUtil.isNotBlank(dataStr)) {
RelaySyncDto bean = JSONUtil.toBean(dataStr, RelaySyncDto.class);
switch (exportType) {
case BASIC_DATA:
this.insertBasicData(bean.getFileContent());
break;
case OTHER_DATA:
this.insertOtherData(bean.getFileContent());
break;
// case COUNTRY_DI_DATA:
// break;
}
String taskId = bean.getTaskId();
if (StrUtil.isNotBlank(taskId)) {
//插入下载记录
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(taskId);
basicDownloadStatusEntity.setStartTime(new Date());
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_DOWNLOAD_BASIC_DATA);
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS); //下载完成
basicDownloadStatusEntity.setType(BasicProcessStatus.BASIC_DATA);
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
//通知自助平台任务已完成
spGetHttp.finishTask(taskId);
}
}
}
/**
* 设置嵌套事物
*
* @param content 内容
*/
@Transactional(propagation = Propagation.NESTED)
public void insertBasicData(String content) {
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);
if (CollectionUtil.isNotEmpty(hospTypeList)) {
basicHospTypeDao.insertOrUpdateBatch(hospTypeList);
}
if (CollectionUtil.isNotEmpty(udiRelevanceList)) {
udiRelevanceDao.insertOrUpdateBatch(udiRelevanceList);
}
if (CollectionUtil.isNotEmpty(productsList)) {
basicProductsDao.insertOrUpdateBatch(productsList);
}
if (CollectionUtil.isNotEmpty(relevanceList)) {
relevanceDao.insertOrUpdateBatch(relevanceList);
}
if (CollectionUtil.isNotEmpty(corpList)) {
corpDao.insertOrUpdateBatch(corpList);
}
if (CollectionUtil.isNotEmpty(supCertList)) {
supCertDao.insertOrUpdateBatch(supCertList);
}
if (CollectionUtil.isNotEmpty(supCertSetList)) {
supCertSetDao.insertOrUpdateBatch(supCertSetList);
}
if (CollectionUtil.isNotEmpty(supCompanyList)) {
supCompanyDao.insertOrUpdateBatch(supCompanyList);
}
if (CollectionUtil.isNotEmpty(supManufacturerList)) {
supManufacturerDao.insertOrUpdateBatch(supManufacturerList);
}
if (CollectionUtil.isNotEmpty(supProductList)) {
supProductDao.insertOrUpdateBatch(supProductList);
}
}
private final IoCodeLostMapper ioCodeLostMapper;
private final IoCodeRelMapper ioCodeRelMapper;
/**
* 设置嵌套事物
*
* @param content 内容
*/
@Transactional(propagation = Propagation.NESTED)
public void insertOtherData(String content) {
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);
if (CollectionUtil.isNotEmpty(ioCodeLostList)) {
ioCodeLostMapper.insertOrUpdateBatch(ioCodeLostList);
}
if (CollectionUtil.isNotEmpty(ioCodeRelList)) {
ioCodeRelMapper.insertOrUpdateBatch(ioCodeRelList);
}
}
/**
* 从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);
String taskId = bean.getTaskId();
if (StrUtil.isNotBlank(taskId)) {
//插入下载记录
BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity();
basicDownloadStatusEntity.setId(CustomUtil.getId());
basicDownloadStatusEntity.setTaskId(taskId);
basicDownloadStatusEntity.setStartTime(new Date());
basicDownloadStatusEntity.setUpdateTime(new Date());
basicDownloadStatusEntity.setEndTime(new Date());
basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_DOWNLOAD_BASIC_DATA);
basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_SUCCESS); //下载完成
basicDownloadStatusEntity.setType(BasicProcessStatus.BASIC_DATA);
basicDownloadStatusEntity.setScheduleType(1);
basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity);
//通知自助平台任务已完成
spGetHttp.finishTask(taskId);
}
}
/**
* 从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());
}
}
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())) {
orderInvoiceService.insertInvoice(orderInvoiceEntity);
}
}
}
}
/**
* 同步第三方基础数据
*
* @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);
spsSyncSysSettingResponse.getSystemPDFTemplateEntities().forEach(systemPDFTemplateEntity -> {
//分切文件并封装参数
Map<String, String> pathFileMap = new HashMap<>(1);
pathFileMap.put("fileName", StrUtil.split(systemPDFTemplateEntity.getPath(), "template/").get(1));
list.add(pathFileMap);
Map<String, String> jrxmlPathFileMap = new HashMap<>(1);
jrxmlPathFileMap.put("fileName", StrUtil.split(systemPDFTemplateEntity.getJrxmlPath(), "template/").get(1));
list.add(jrxmlPathFileMap);
});
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();
}
}