diff --git a/src/main/java/com/glxp/api/service/sync/HeartService.java b/src/main/java/com/glxp/api/service/sync/HeartService.java deleted file mode 100644 index f5a94f2..0000000 --- a/src/main/java/com/glxp/api/service/sync/HeartService.java +++ /dev/null @@ -1,2224 +0,0 @@ -package com.glxp.api.service.sync; - -import static com.glxp.api.constant.BasicProcessStatus.NEW_ALL_ORDER; -import static com.glxp.api.constant.BasicProcessStatus.NEW_ALL_UDIS; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; -import java.util.function.Function; - -import javax.annotation.Resource; - -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 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.BasicExportStatusTimeEnum; -import com.glxp.api.constant.BasicExportTypeEnum; -import com.glxp.api.constant.BasicProcessStatus; -import com.glxp.api.constant.Constant; -import com.glxp.api.constant.ConstantStatus; -import com.glxp.api.constant.StatusEnum; -import com.glxp.api.dao.basic.BasicBusTypeChangeDao; -import com.glxp.api.dao.basic.BasicBussinessTypeDao; -import com.glxp.api.dao.basic.BasicCorpDao; -import com.glxp.api.dao.basic.BasicHospTypeDao; -import com.glxp.api.dao.basic.BasicProductsDao; -import com.glxp.api.dao.basic.CompanyProductRelevanceDao; -import com.glxp.api.dao.basic.ProductInfoDao; -import com.glxp.api.dao.basic.UdiCompanyDao; -import com.glxp.api.dao.basic.UdiRelevanceDao; -import com.glxp.api.dao.inout.IoCodeLostMapper; -import com.glxp.api.dao.inout.IoCodeRelMapper; -import com.glxp.api.dao.inout.IoOrderDao; -import com.glxp.api.dao.inout.IoOrderDetailBizDao; -import com.glxp.api.dao.inout.IoOrderDetailCodeDao; -import com.glxp.api.dao.inout.IoOrderInvoiceMapper; -import com.glxp.api.dao.purchase.SupCertDao; -import com.glxp.api.dao.purchase.SupCertSetDao; -import com.glxp.api.dao.purchase.SupCompanyDao; -import com.glxp.api.dao.purchase.SupManufacturerDao; -import com.glxp.api.dao.purchase.SupProductDao; -import com.glxp.api.dao.thrsys.ThrBusTypeOriginDao; -import com.glxp.api.dto.RelaySyncDto; -import com.glxp.api.entity.auth.AuthAdmin; -import com.glxp.api.entity.auth.DeptEntity; -import com.glxp.api.entity.auth.DeptUserEntity; -import com.glxp.api.entity.auth.InvBusUserEntity; -import com.glxp.api.entity.auth.InvSpace; -import com.glxp.api.entity.auth.InvWarehouseEntity; -import com.glxp.api.entity.auth.WarehouseBussinessTypeEntity; -import com.glxp.api.entity.auth.WarehouseUserEntity; -import com.glxp.api.entity.basic.BasicBusTypeChangeEntity; -import com.glxp.api.entity.basic.BasicBusTypePreEntity; -import com.glxp.api.entity.basic.BasicBussinessTypeEntity; -import com.glxp.api.entity.basic.BasicCorpEntity; -import com.glxp.api.entity.basic.BasicHospTypeEntity; -import com.glxp.api.entity.basic.BasicProductsEntity; -import com.glxp.api.entity.basic.CompanyProductRelevanceEntity; -import com.glxp.api.entity.basic.EntrustReceEntity; -import com.glxp.api.entity.basic.ProductInfoEntity; -import com.glxp.api.entity.basic.UdiCompanyEntity; -import com.glxp.api.entity.basic.UdiRelevanceEntity; -import com.glxp.api.entity.inout.IoCodeEntity; -import com.glxp.api.entity.inout.IoCodeLostEntity; -import com.glxp.api.entity.inout.IoCodeRelEntity; -import com.glxp.api.entity.inout.IoCodeTempEntity; -import com.glxp.api.entity.inout.IoOrderDetailBizEntity; -import com.glxp.api.entity.inout.IoOrderDetailCodeEntity; -import com.glxp.api.entity.inout.IoOrderDetailResultEntity; -import com.glxp.api.entity.inout.IoOrderEntity; -import com.glxp.api.entity.inout.IoOrderInvoiceEntity; -import com.glxp.api.entity.purchase.SupCertEntity; -import com.glxp.api.entity.purchase.SupCertSetEntity; -import com.glxp.api.entity.purchase.SupCompanyEntity; -import com.glxp.api.entity.purchase.SupManufacturerEntity; -import com.glxp.api.entity.purchase.SupProductEntity; -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.SyncDataSetEntity; -import com.glxp.api.entity.system.SysPdfTemplateRelevanceBizEntity; -import com.glxp.api.entity.system.SysPdfTemplateRelevanceCodeEntity; -import com.glxp.api.entity.system.SysPdfTemplateRelevanceLabelEntity; -import com.glxp.api.entity.system.SysPdfTemplateRelevanceStatemenEntity; -import com.glxp.api.entity.system.SystemPDFModuleEntity; -import com.glxp.api.entity.system.SystemPDFTemplateEntity; -import com.glxp.api.entity.system.SystemParamConfigEntity; -import com.glxp.api.entity.thrsys.ThrBusTypeOriginEntity; -import com.glxp.api.entity.thrsys.ThrCorpEntity; -import com.glxp.api.entity.thrsys.ThrDeptEntity; -import com.glxp.api.entity.thrsys.ThrInvWarehouseEntity; -import com.glxp.api.entity.thrsys.ThrProductsEntity; -import com.glxp.api.http.sync.SpGetHttpClient; -import com.glxp.api.idc.service.FileService; -import com.glxp.api.idc.service.IdcService; -import com.glxp.api.req.sync.SpsSyncDataRequest; -import com.glxp.api.res.sync.BaseSyncResponse; -import com.glxp.api.res.sync.SpSyncUdiResponse; -import com.glxp.api.res.sync.SpsSyncBasicDataResponse; -import com.glxp.api.res.sync.SpsSyncBusOrderResponse; -import com.glxp.api.res.sync.SpsSyncBusResponse; -import com.glxp.api.res.sync.SpsSyncDataResponse; -import com.glxp.api.res.sync.SpsSyncOrderResponse; -import com.glxp.api.res.sync.SpsSyncOtherDataResponse; -import com.glxp.api.res.sync.SpsSyncSysSettingResponse; -import com.glxp.api.res.sync.SpsSyncThrDataResponse; -import com.glxp.api.res.sync.SpsSyncThrProductsResponse; -import com.glxp.api.service.auth.AuthAdminService; -import com.glxp.api.service.auth.DeptService; -import com.glxp.api.service.auth.DeptUserService; -import com.glxp.api.service.auth.InvBusUserService; -import com.glxp.api.service.auth.InvSpaceService; -import com.glxp.api.service.auth.InvWarehouseService; -import com.glxp.api.service.auth.WarehouseBussinessTypeService; -import com.glxp.api.service.auth.WarehouseUserService; -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.IoAddInoutService; -import com.glxp.api.service.inout.IoCheckInoutService; -import com.glxp.api.service.inout.IoCodeTempService; -import com.glxp.api.service.inout.IoOrderDetailBizService; -import com.glxp.api.service.inout.IoOrderDetailCodeService; -import com.glxp.api.service.inout.IoOrderDetailResultService; -import com.glxp.api.service.inout.IoOrderInvoiceService; -import com.glxp.api.service.inout.IoOrderService; -import com.glxp.api.service.system.SystemPDFModuleService; -import com.glxp.api.service.system.SystemPDFTemplateRelevanceBizService; -import com.glxp.api.service.system.SystemPDFTemplateRelevanceCodeService; -import com.glxp.api.service.system.SystemPDFTemplateRelevanceLabelService; -import com.glxp.api.service.system.SystemPDFTemplateRelevanceStatemenService; -import com.glxp.api.service.system.SystemPDFTemplateService; -import com.glxp.api.service.system.SystemParamConfigService; -import com.glxp.api.service.thrsys.IThrBusTypeOriginService; -import com.glxp.api.service.thrsys.ThrCorpService; -import com.glxp.api.service.thrsys.ThrDeptService; -import com.glxp.api.service.thrsys.ThrInvWarehouseService; -import com.glxp.api.service.thrsys.ThrProductsService; -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 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 lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@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); - 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()); - spsSyncOrderResponse.setType(NEW_ALL_ORDER); - BaseResponse 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 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; - case IO_ORDER: - if (needExec()) - break; - } - } - - /** - * 获取基础数据模块数据 - * - * @param info 同步设置 - * @param now 当前时间 - * @param syncTime 同步时间 -- 传入时不操作exportTime表 - * @return - */ - public SpsSyncBasicDataResponse getBasicData(SyncDataSetEntity info, String taskId, Date now, Date syncTime) { - StringBuilder remark = new StringBuilder(); - SpsSyncBasicDataResponse dataResponse = null; - Map syncTimeMap = new WeakHashMap<>(3); - syncTimeMap.put("isNew", true); - //确认有开启物资字典同步 - if (needExec(info.getBasicProducts())) { - Map map; - if (syncTime == null) { - map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_PRODUCTS); - } else { - map = syncTimeMap; - now = syncTime; - } - List 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 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 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 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 map; - if (syncTime == null) { - map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_CORP); - } else { - map = syncTimeMap; - now = syncTime; - } - List 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 map; - if (syncTime == null) { - map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.SUP_CERT); - } else { - map = syncTimeMap; - now = syncTime; - } - List 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 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 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 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 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 syncTimeMap = new WeakHashMap<>(3); - syncTimeMap.put("isNew", true); - //确认有开启udi码补齐同步 - if (needExec(info.getUdiCodeLost())) { - Map map; - if (syncTime == null) { - map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_LOST); - } else { - map = syncTimeMap; - now = syncTime; - } - List 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 map; - if (syncTime == null) { - map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_REL); - } else { - map = syncTimeMap; - now = syncTime; - } - List 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 syncTimeMap = new WeakHashMap<>(3); - syncTimeMap.put("isNew", true); - syncTimeMap.put("oldDate", syncTime); - StringBuffer remark = new StringBuffer(); - boolean ge = false; - if (syncTime != null) { - ge = true; - } - //确认有开启扫码单据类型同步 - if (needExec(info.getTypeScan())) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSSINESS_TYPE); - List bussinessTypeEntities = bussinessTypeService.list(Wrappers.lambdaQuery(BasicBussinessTypeEntity.class) - .le(!ge && (boolean) map.get("isNew"), BasicBussinessTypeEntity::getUpdateTime, now) - .between(ge, BasicBussinessTypeEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BASIC_BUSTYPE_CHANGE); - List busTypeChangeList = busTypeChangeService.list(Wrappers.lambdaQuery(BasicBusTypeChangeEntity.class) - .le(!ge && (boolean) map.get("isNew"), BasicBusTypeChangeEntity::getUpdateTime, now) - .between(ge, BasicBusTypeChangeEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_BUSTYPE_ORIGIN); - List thrBusTypeOriginEntities = thrBusTypeOriginService.list(Wrappers.lambdaQuery(ThrBusTypeOriginEntity.class) - .le(!ge && (boolean) map.get("isNew"), ThrBusTypeOriginEntity::getUpdateTime, now) - .between(ge, ThrBusTypeOriginEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 syncTimeMap = new WeakHashMap<>(3); - syncTimeMap.put("isNew", true); - boolean ge = false; - if (syncTime != null) { - ge = true; - } - StringBuffer remark = new StringBuffer(); - //确认有开启部门信息同步 - if (needExec(info.getBasicDept())) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.DEPT_DATA); - List deptEntityList = deptService.list(Wrappers.lambdaQuery(DeptEntity.class) - .le(!ge && (boolean) map.get("isNew"), DeptEntity::getUpdateTime, now) - .between(ge, DeptEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 deptUserEntityList = deptUserService.list(Wrappers.lambdaQuery(DeptUserEntity.class) - .le(!ge && (boolean) map.get("isNew"), DeptUserEntity::getUpdateTime, now) - .between(ge, DeptUserEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.WAREHOUSE_DICT); - List warehouseEntityList = warehouseService.list(Wrappers.lambdaQuery(InvWarehouseEntity.class) - .le(!ge && (boolean) map.get("isNew"), InvWarehouseEntity::getUpdateTime, now) - .between(ge, InvWarehouseEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 warehouseUserEntities = warehouseUserService.list(Wrappers.lambdaQuery(WarehouseUserEntity.class) - .le(!ge && (boolean) map.get("isNew"), WarehouseUserEntity::getUpdateTime, now) - .between(ge, WarehouseUserEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 warehouseBussinessTypeEntities = warehouseBussinessTypeService.list(Wrappers.lambdaQuery(WarehouseBussinessTypeEntity.class) - .le(!ge && (boolean) map.get("isNew"), WarehouseBussinessTypeEntity::getUpdateTime, now) - .between(ge, WarehouseBussinessTypeEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 invSpaceList = invSpaceService.list(Wrappers.lambdaQuery(InvSpace.class) - .le(!ge && (boolean) map.get("isNew"), InvSpace::getUpdateTime, now) - .between(ge, InvSpace::getUpdateTime, syncTime, now) - .between(!ge && !(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 map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.USER_DATA); - List adminList = adminService.list(Wrappers.lambdaQuery(AuthAdmin.class) - .le(!ge && (boolean) map.get("isNew"), AuthAdmin::getLastModifyTime, now) - .between(ge, AuthAdmin::getLastModifyTime, syncTime, now) - .between(!ge && !(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 busUserEntities = invBusUserService.list(Wrappers.lambdaQuery(InvBusUserEntity.class) - .le(!ge && (boolean) map.get("isNew"), InvBusUserEntity::getUpdateTime, now) - .between(ge, InvBusUserEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 syncTimeMap = new WeakHashMap<>(3); - syncTimeMap.put("isNew", true); - boolean ge = false; - if (syncTime != null) { - ge = true; - } - StringBuffer remark = new StringBuffer(); - //确认有开启第三方部门信息同步 - if (needExec(info.getBasicThirdInv())) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_DEPT); - List deptEntityList = thrDeptService.list(Wrappers.lambdaQuery(ThrDeptEntity.class) - .le(!ge && (boolean) map.get("isNew"), ThrDeptEntity::getUpdateTime, now) - .between(ge, ThrDeptEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_WAREHOUSE); - List warehouseEntityList = thrInvWarehouseService.list(Wrappers.lambdaQuery(ThrInvWarehouseEntity.class) - .le(!ge && (boolean) map.get("isNew"), ThrInvWarehouseEntity::getUpdateTime, now) - .between(ge, ThrInvWarehouseEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_PRODUCTS); - List productsEntityList = thrProductsService.list(Wrappers.lambdaQuery(ThrProductsEntity.class) - .le(!ge && (boolean) map.get("isNew"), ThrProductsEntity::getUpdateTime, now) - .between(ge, ThrProductsEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.THR_CORP); - List corpEntities = thrCorpService.list(Wrappers.lambdaQuery(ThrCorpEntity.class) - .le(!ge && (boolean) map.get("isNew"), ThrCorpEntity::getUpdateTime, now) - .between(ge, ThrCorpEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 syncTimeMap = new WeakHashMap<>(3); - syncTimeMap.put("isNew", true); - boolean ge = false; - if (syncTime != null) { - ge = true; - } - StringBuffer remark = new StringBuffer(); - if (needExec(info.getSystemConfig())) { - Map map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.SYSTEM_PARAM_CONFIG); - List systemParamConfigEntities = systemParamConfigService.list(Wrappers.lambdaQuery(SystemParamConfigEntity.class) - .le(!ge && (boolean) map.get("isNew"), SystemParamConfigEntity::getUpdateTime, now) - .between(ge, SystemParamConfigEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.ENTRUST_ACCEPT); - List entrustReceEntities = entrustReceService.list(Wrappers.lambdaQuery(EntrustReceEntity.class) - .le(!ge && (boolean) map.get("isNew"), EntrustReceEntity::getUpdateTime, now) - .between(ge, EntrustReceEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.PRINT_CONFIG); - List systemPDFModuleEntities = systemPDFModuleService.list(Wrappers.lambdaQuery(SystemPDFModuleEntity.class) - .le(!ge && (boolean) map.get("isNew"), SystemPDFModuleEntity::getUpdate_time, now) - .between(ge, SystemPDFModuleEntity::getUpdate_time, syncTime, now) - .between(!ge && !(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 systemPDFTemplateEntities = systemPDFTemplateService.list(Wrappers.lambdaQuery(SystemPDFTemplateEntity.class) - .le(!ge && (boolean) map.get("isNew"), SystemPDFTemplateEntity::getUpdate_time, now) - .between(ge, SystemPDFTemplateEntity::getUpdate_time, syncTime, now) - .between(!ge && !(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 sysPdfTemplateRelevanceCodeEntities = systemPDFTemplateRelevanceCodeService.list(Wrappers.lambdaQuery(SysPdfTemplateRelevanceCodeEntity.class) - .le(!ge && (boolean) map.get("isNew"), SysPdfTemplateRelevanceCodeEntity::getUpdateTime, now) - .between(ge, SysPdfTemplateRelevanceCodeEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 sysPdfTemplateRelevanceBizEntities = systemPDFTemplateRelevanceBizService.list(Wrappers.lambdaQuery(SysPdfTemplateRelevanceBizEntity.class) - .le(!ge && (boolean) map.get("isNew"), SysPdfTemplateRelevanceBizEntity::getUpdateTime, now) - .between(ge, SysPdfTemplateRelevanceBizEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 sysPdfTemplateRelevanceLabelEntities = systemPDFTemplateRelevanceLabelService.list(Wrappers.lambdaQuery(SysPdfTemplateRelevanceLabelEntity.class) - .le(!ge && (boolean) map.get("isNew"), SysPdfTemplateRelevanceLabelEntity::getUpdateTime, now) - .between(ge, SysPdfTemplateRelevanceLabelEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 sysPdfTemplateRelevanceStatemenEntities = systemPDFTemplateRelevanceStatemenService.list(Wrappers.lambdaQuery(SysPdfTemplateRelevanceStatemenEntity.class) - .le(!ge && (boolean) map.get("isNew"), SysPdfTemplateRelevanceStatemenEntity::getUpdateTime, now) - .between(ge, SysPdfTemplateRelevanceStatemenEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.SCAN_CHANGE); - List basicBusTypePreEntities = iBasicBusTypePreService.list(Wrappers.lambdaQuery(BasicBusTypePreEntity.class) - .le(!ge && (boolean) map.get("isNew"), BasicBusTypePreEntity::getUpdateTime, now) - .between(ge, BasicBusTypePreEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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 map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.BUS_TYPE_CHANGE); - List basicBusTypeChangeEntities = iBasicBusTypeChangeService.list(Wrappers.lambdaQuery(BasicBusTypeChangeEntity.class) - .le(!ge && (boolean) map.get("isNew"), BasicBusTypeChangeEntity::getUpdateTime, now) - .between(ge, BasicBusTypeChangeEntity::getUpdateTime, syncTime, now) - .between(!ge && !(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> list = new ArrayList<>(spsSyncSysSettingResponse.getSystemPDFTemplateEntities().size() * 2); - List list = new ArrayList<>(); - dataResponse.getSystemPDFTemplateEntities().forEach(systemPDFTemplateEntity -> { - list.add(systemPDFTemplateEntity.getPath()); - }); - - BaseResponse 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 dataMethod) { - Date startTime = new Date(); - Integer status = StatusEnum.SUCCESS.getCode(); - Object data = dataMethod.apply(this); - if (data == null) { - return; - } - BaseResponse baseResponse = spGetHttp.postData(taskId, exportType, data); - if (baseResponse.getCode() != 20000) { - 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); - } 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 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 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 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 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(); - } - - @Resource - SyncDataBustypeService syncDataBustypeService; - - //下载最近更新扫码单据--上级服务 - @Transactional(propagation = Propagation.NESTED) - public void dlAllOrder() { - /*Date startTime = new Date(); - BaseResponse> baseResponse = spGetHttp.getBasicStatus(NEW_ALL_ORDER + "", "3"); - List pageSimpleResponse = baseResponse != null ? baseResponse.getData() : new ArrayList<>(); - if (pageSimpleResponse != null) { - List basicExportStatusEntities = pageSimpleResponse; - if (basicExportStatusEntities != null && basicExportStatusEntities.size() > 0) { - for (BasicExportStatusEntity basicExportStatusEntity : basicExportStatusEntities) { - String datas = spGetHttp.getBasicData(basicExportStatusEntity.getId(), NEW_ALL_ORDER); - BaseResponse response = JSONObject.parseObject(datas, new TypeReference>() { - }); - if (response.getCode() == 20000 && response.getData() != null) { - - - JSONArray fileJson = JSONUtil.parseObj(response.getData()).getJSONArray("syncFiles"); - SpsSyncOrderResponse syncDataResponse = JSONObject.parseObject(response.getData(), new TypeReference() { - }); - BasicDownloadStatusEntity basicDownloadStatusEntity = new BasicDownloadStatusEntity(); - basicDownloadStatusEntity.setId(CustomUtil.getId()); - basicDownloadStatusEntity.setTaskId(syncDataResponse.getTaskId()); - basicDownloadStatusEntity.setStartTime(startTime); - basicDownloadStatusEntity.setUpdateTime(startTime); - basicDownloadStatusEntity.setIdDatas(ConstantStatus.SYNC_DOWNLOAD_SCAN_ORDER); - basicDownloadStatusEntity.setStatus(ConstantStatus.SYNC_STATUS_WAIT); //下载中 - basicDownloadStatusEntity.setType(NEW_ALL_ORDER); - basicDownloadStatusEntity.setRemark(syncDataResponse.getSyncRemark()); - basicDownloadStatusEntity.setScheduleType(1); - basicDownloadService.insertDownloadStatus(basicDownloadStatusEntity); - - if (CollUtil.isNotEmpty(syncDataResponse.getOrderEntities())) { - try { - List orderEntities = syncDataResponse.getOrderEntities(); - for (IoOrderEntity orderEntity : orderEntities) { - SyncDataBustypeEntity syncDataBustypeEntity = syncDataBustypeService.findByAction(orderEntity.getAction(), 2); - orderEntity.setUpdateTime(null); - orderEntity.setFromType(ConstantStatus.FROM_UDISP); - orderEntity.setProcessStatus(ConstantStatus.ORDER_DEAL_POST); - orderEntity.setStatus(ConstantStatus.ORDER_STATUS_PROCESS); - if (syncDataBustypeEntity != null) { - if (syncDataBustypeEntity.getSyncStatus() != null && syncDataBustypeEntity.getSyncStatus().compareTo(1) == 0) { - orderEntity.setProcessStatus(ConstantStatus.ORDER_DEAL_DRAFT); - orderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE); - } - if (syncDataBustypeEntity.isSyncChange()) { - orderEntity.setOutChangeEnable(syncDataBustypeEntity.isSyncChange()); - } - } - IoOrderEntity temp = orderService.findByBillNo(orderEntity.getBillNo()); - if (temp == null) { - orderEntity.setId(null); - orderService.insertOrder(orderEntity); - insetOrderDb(syncDataResponse, orderEntity); - orderEntity = orderService.findByBillNo(orderEntity.getBillNo()); - if (orderEntity.getStatus() != ConstantStatus.ORDER_STATUS_TEMP_SAVE) { - addInoutService.dealProcess(orderEntity); - orderEntity = orderService.findByBillNo(orderEntity.getBillNo()); - if (orderEntity.getStatus() != ConstantStatus.ORDER_STATS_ERROR && !ioCheckInoutService.checkManual(orderEntity.getBillNo())) { - ioCheckInoutService.check(orderEntity.getBillNo()); - } - } - } else { - // updateOrderDb(syncDataResponse, orderEntity); - } - } - if (fileJson != null && fileJson.size() > 0) { - List syncFiles = fileJson.toList(String.class); - if (CollUtil.isNotEmpty(syncFiles)) { - idcService.batchDownloadFile(spGetHttp.getIpUrl(), syncFiles.toArray(new String[syncFiles.size()])); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - - - } - spGetHttp.finishTask(basicExportStatusEntity.getId()); - basicDownloadStatusEntity.setUpdateTime(new Date()); - basicDownloadStatusEntity.setEndTime(new Date()); - basicDownloadStatusEntity.setStatus(StatusEnum.SUCCESS.getCode()); - - try { - String fileFullPath = writeFile(filePrefix, NEW_ALL_ORDER, response.getData()); - basicDownloadStatusEntity.setCacheFilePath(fileFullPath); - } catch (IOException e) { - throw new RuntimeException(e); - } - - basicDownloadService.updateDownloadStatus(basicDownloadStatusEntity); - - - } - } - } - }*/ - } - - // 下载最近更新国家库数据-上级服务 - @Transactional(propagation = Propagation.NESTED) - public void dlAllDiProducts() { - Date startTime = new Date(); - BaseResponse> baseResponse = spGetHttp.getBasicStatus(NEW_ALL_UDIS, "3"); - List pageSimpleResponse = baseResponse.getData(); - if (pageSimpleResponse != null) { - List 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_UDIS); -// logger.info("--------等待时间1------" + (System.currentTimeMillis() - curTime) / 1000); - long curTime2 = System.currentTimeMillis(); - BaseResponse response = JSONObject.parseObject(datas, new TypeReference>() { - }); -// 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); //下载中 - 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 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 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); - } - 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) { - switch (exportType) { - case IO_ORDER: - case COUNTRY_DI_DATA: - return; - } - 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); - 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) { - cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(content); - List hospTypeList = JSONUtil.toList(jsonObject.getJSONArray(BasicHospTypeEntity.class.getSimpleName()), BasicHospTypeEntity.class); - List udiRelevanceList = JSONUtil.toList(jsonObject.getJSONArray(UdiRelevanceEntity.class.getSimpleName()), UdiRelevanceEntity.class); - List productsList = JSONUtil.toList(jsonObject.getJSONArray(BasicProductsEntity.class.getSimpleName()), BasicProductsEntity.class); - List relevanceList = JSONUtil.toList(jsonObject.getJSONArray(CompanyProductRelevanceEntity.class.getSimpleName()), CompanyProductRelevanceEntity.class); - List corpList = JSONUtil.toList(jsonObject.getJSONArray(BasicCorpEntity.class.getSimpleName()), BasicCorpEntity.class); - List supCertList = JSONUtil.toList(jsonObject.getJSONArray(SupCertEntity.class.getSimpleName()), SupCertEntity.class); - List supCertSetList = JSONUtil.toList(jsonObject.getJSONArray(SupCertSetEntity.class.getSimpleName()), SupCertSetEntity.class); - List supCompanyList = JSONUtil.toList(jsonObject.getJSONArray(SupCompanyEntity.class.getSimpleName()), SupCompanyEntity.class); - List supManufacturerList = JSONUtil.toList(jsonObject.getJSONArray(SupManufacturerEntity.class.getSimpleName()), SupManufacturerEntity.class); - List supProductList = JSONUtil.toList(jsonObject.getJSONArray(SupProductEntity.class.getSimpleName()), SupProductEntity.class); - - List syncFiles = JSONUtil.toList(jsonObject.getJSONArray("syncFiles"), String.class); - - if (CollectionUtil.isNotEmpty(hospTypeList)) { - basicHospTypeDao.replaceBatch(hospTypeList); - } - if (CollectionUtil.isNotEmpty(udiRelevanceList)) { - udiRelevanceDao.replaceBatch(udiRelevanceList); - } - if (CollectionUtil.isNotEmpty(productsList)) { - basicProductsDao.replaceBatch(productsList); - } - if (CollectionUtil.isNotEmpty(relevanceList)) { - relevanceDao.replaceBatch(relevanceList); - } - if (CollectionUtil.isNotEmpty(corpList)) { - corpDao.replaceBatch(corpList); - } - if (CollectionUtil.isNotEmpty(supCertList)) { - supCertDao.replaceBatch(supCertList); - } - if (CollectionUtil.isNotEmpty(supCertSetList)) { - supCertSetDao.replaceBatch(supCertSetList); - } - if (CollectionUtil.isNotEmpty(supCompanyList)) { - supCompanyDao.replaceBatch(supCompanyList); - } - if (CollectionUtil.isNotEmpty(supManufacturerList)) { - supManufacturerDao.replaceBatch(supManufacturerList); - } - if (CollectionUtil.isNotEmpty(supProductList)) { - supProductDao.replaceBatch(supProductList); - } - if (CollUtil.isNotEmpty(syncFiles)) { -// fileService.download(syncFiles); - idcService.batchDownloadFile(spGetHttp.getIpUrl(), syncFiles.toArray(new String[syncFiles.size()])); - } - } - - @Resource - FileService fileService; - private final IdcService idcService; - - private final IoCodeLostMapper ioCodeLostMapper; - private final IoCodeRelMapper ioCodeRelMapper; - @Resource - private final IoOrderInvoiceMapper ioOrderInvoiceMapper; - - /** - * 设置嵌套事物 - * - * @param content 内容 - */ - @Transactional(propagation = Propagation.NESTED) - public void insertOtherData(String content) { - cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(content); - List ioCodeLostList = JSONUtil.toList(jsonObject.getJSONArray(IoCodeLostEntity.class.getSimpleName()), IoCodeLostEntity.class); - List ioCodeRelList = JSONUtil.toList(jsonObject.getJSONArray(IoCodeRelEntity.class.getSimpleName()), IoCodeRelEntity.class); - List ioOrderInvoiceEntities = JSONUtil.toList(jsonObject.getJSONArray(IoOrderInvoiceEntity.class.getSimpleName()), IoOrderInvoiceEntity.class); - - if (CollectionUtil.isNotEmpty(ioCodeLostList)) { - ioCodeLostMapper.replaceBatch(ioCodeLostList); - } - if (CollectionUtil.isNotEmpty(ioCodeRelList)) { - ioCodeRelMapper.replaceBatch(ioCodeRelList); - } - if (CollUtil.isNotEmpty(ioOrderInvoiceEntities)) { - ioOrderInvoiceMapper.replaceBatch(ioOrderInvoiceEntities); - } - - List 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 bussinessTypeEntities = JSONUtil.toList(jsonObject.getJSONArray(BasicBussinessTypeEntity.class.getSimpleName()), BasicBussinessTypeEntity.class); - List busTypeChangeEntities = JSONUtil.toList(jsonObject.getJSONArray(BasicBusTypeChangeEntity.class.getSimpleName()), BasicBusTypeChangeEntity.class); - List typeOriginEntities = JSONUtil.toList(jsonObject.getJSONArray(ThrBusTypeOriginEntity.class.getSimpleName()), ThrBusTypeOriginEntity.class); - if (CollectionUtil.isNotEmpty(bussinessTypeEntities)) { - bussinessTypeDao.replaceBatch(bussinessTypeEntities); - } - if (CollectionUtil.isNotEmpty(busTypeChangeEntities)) { - busTypeChangeDao.replaceBatch(busTypeChangeEntities); - } - if (CollectionUtil.isNotEmpty(typeOriginEntities)) { - thrBusTypeOriginDao.replaceBatch(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); - 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()); - } - - -// if (CollectionUtil.isNotEmpty(bean.getI())) { -// ioCodeRelMapper.insertOrUpdateBatch(bean.getIoCodeRelList()); -// } - } - - public void insetOrderDb(SpsSyncOrderResponse syncDataResponse, IoOrderEntity orderEntity) { - //更新码详情 - if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities())) { - List 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 orderDetailBizEntities = syncDataResponse.getOrderDetailBizEntities(); - for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { - if (bizEntity.getOrderIdFk().equals(orderEntity.getBillNo())) { - orderDetailBizService.insert(bizEntity); - } - } - } - - //更新码详情 - if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities())) { - List orderDetailCodeEntities = syncDataResponse.getOrderDetailCodeEntities(); - for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { - if (codeEntity.getOrderIdFk().equals(orderEntity.getBillNo())) { - orderDetailCodeService.insert(codeEntity); - } - } - } - - - //更新结果详情 - if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailResultEntities())) { - List 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 orderInvoiceEntities = syncDataResponse.getOrderInvoiceEntities(); - for (IoOrderInvoiceEntity orderInvoiceEntity : orderInvoiceEntities) { - if (orderInvoiceEntity.getOrderIdFk().equals(orderEntity.getBillNo())) { - orderInvoiceService.insertInvoice(orderInvoiceEntity); - } - } - } - } - - @Resource - IoOrderDetailBizDao ioOrderDetailBizDao; - - @Resource - IoOrderDetailCodeDao ioOrderDetailCodeDao; - @Resource - IoOrderDao orderDao; - -/* - @Resource - public void updateOrderDb(SpsSyncOrderResponse syncDataResponse, IoOrderEntity orderEntity) { - orderDao.updateOrder(orderEntity); - //更新业务详情 - if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailBizEntities())) { - List orderDetailBizEntities = syncDataResponse.getOrderDetailBizEntities(); - for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) { - if (bizEntity.getOrderIdFk().equals(orderEntity.getBillNo())) { - ioOrderDetailBizDao.insertOrUpdate(bizEntity); - } - } - } - - //更新码详情 - if (CollUtil.isNotEmpty(syncDataResponse.getOrderDetailCodeEntities())) { - List orderDetailCodeEntities = syncDataResponse.getOrderDetailCodeEntities(); - for (IoOrderDetailCodeEntity codeEntity : orderDetailCodeEntities) { - if (codeEntity.getOrderIdFk().equals(orderEntity.getBillNo())) { - ioOrderDetailCodeDao.insertOrUpdate(codeEntity); - } - } - } - - //更新发票信息 - if (CollUtil.isNotEmpty(syncDataResponse.getOrderInvoiceEntities())) { - List 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 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 baseResponse = spGetHttp.postSysSetting(spsSyncSysSettingResponse); - //若模板记录不为空,则将模板文件同步过去 - String uploadFileLog = ""; - if (CollUtil.isNotEmpty(spsSyncSysSettingResponse.getSystemPDFTemplateEntities())) { -// List> list = new ArrayList<>(spsSyncSysSettingResponse.getSystemPDFTemplateEntities().size() * 2); - List list = new ArrayList<>(); - spsSyncSysSettingResponse.getSystemPDFTemplateEntities().forEach(systemPDFTemplateEntity -> { - list.add(systemPDFTemplateEntity.getPath()); - }); - -// BaseResponse 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 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(); - } -}