同步设置--其他数据

master
wj 2 years ago
parent 5e59141826
commit bf4c254cd3

@ -28,6 +28,16 @@ public enum BasicExportStatusTimeEnum {
*
*/
SUP_CERT("sup_cert", "首营资质"),
/**
* UDI
*/
IO_CODE_LOST("io_code_lost", "UDI码补齐"),
/**
* UDI
*/
IO_CODE_REL("io_code_rel", "UDI码关联关系"),
;
@EnumValue
private String key;

@ -17,6 +17,11 @@ public enum BasicExportTypeEnum {
* DI
*/
COUNTRY_DI_DATA("country_di_data", "国家库DI数据"),
/**
*
*/
OTHER_DATA("other_data", "其他数据"),
;
@EnumValue
private String key;

@ -210,6 +210,60 @@ public class SpsSyncDownloadController {
return baseResponse;
}
// 下发基础数据 供给中继服务UDI管理系统下载
@AuthRuleAnnotation("")
@GetMapping("sps/sync/otherData")
public BaseResponse getOtherData() {
BaseResponse<SpsSyncOtherDataResponse> baseResponse = new BaseResponse<>();
SpsSyncOtherDataResponse spsSyncOtherDataResponse = new SpsSyncOtherDataResponse();
BasicExportStatusEntity one = basicExportService.getOne(Wrappers.lambdaQuery(BasicExportStatusEntity.class)
.eq(BasicExportStatusEntity::getType, BasicExportTypeEnum.OTHER_DATA.getRemark())
.orderByDesc(BasicExportStatusEntity::getStartTime)
.last("limit 1")
);
if (one != null) {
if (BasicExportStatusEnum.WAIT_TRIGGERED.getCode().equals(one.getStatus())) {
basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class)
.set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_BUILT.getCode())
.set(BasicExportStatusEntity::getUpdateTime, new Date())
.eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_TRIGGERED.getCode())
.eq(BasicExportStatusEntity::getId, one.getId())
);
} else if (BasicExportStatusEnum.WAIT_SYNC.getCode().equals(one.getStatus())) {
// 读取文件数据
try {
FileReader reader = new FileReader(one.getCacheFilePath());
StringBuilder str = new StringBuilder();
int data;
while ((data = reader.read()) != -1) {
str.append((char) data);
}
reader.close();
Dict map = JsonUtils.parseMap(str.toString());
// 组装返回数据
spsSyncOtherDataResponse.setTaskId(one.getId());
spsSyncOtherDataResponse.setIoCodeLostList((List<IoCodeLostEntity>) map.get(IoCodeLostEntity.class.getSimpleName()));
spsSyncOtherDataResponse.setIoCodeRelList((List<IoCodeRelEntity>) map.get(IoCodeRelEntity.class.getSimpleName()));
} catch (FileNotFoundException e) {
throw new RuntimeException("系统异常,未找到对应数据文件");
} catch (IOException e) {
throw new RuntimeException(e);
}
// 修改任务状态
// basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class)
// .set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.COMPLETED.getCode())
// .set(BasicExportStatusEntity::getUpdateTime, new Date())
// .set(BasicExportStatusEntity::getEndTime, new Date())
// .eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode())
// .eq(BasicExportStatusEntity::getId, one.getId())
// );
}
}
baseResponse.setData(spsSyncOtherDataResponse);
return baseResponse;
}
//接收中继服务、UDI管理系统上传单据
@AuthRuleAnnotation("sps/sync/order/upload")
@PostMapping("/sps/sync/order/upload")

@ -20,6 +20,10 @@ public class SyncDataSetEntity {
private int basicThirdInv; //第三方仓库信息
private int basicThirdBusOrder; //第三方业务单据
private int dbDiProducts; //DI产品信息
private int udiCodeLost; // UDI码补齐
private int udiCodeRel; //UDI码关联关系
private boolean downstreamEnable; //上游是否联通
private Integer syncTime; //数据上传间隔时间
private Integer syncDownloadTime; //数据下载间隔时间

@ -0,0 +1,20 @@
package com.glxp.api.res.sync;
import com.glxp.api.entity.basic.*;
import com.glxp.api.entity.inout.IoCodeLostEntity;
import com.glxp.api.entity.inout.IoCodeRelEntity;
import com.glxp.api.entity.purchase.*;
import lombok.Data;
import java.util.List;
/**
* --
*/
@Data
public class SpsSyncOtherDataResponse extends BaseSyncResponse {
List<IoCodeLostEntity> ioCodeLostList;
List<IoCodeRelEntity> ioCodeRelList;
}

@ -21,6 +21,10 @@ public class SyncDataSetResponse {
private int basicThirdInv;
private int basicThirdBusOrder;
private int dbDiProducts;
private int udiCodeLost; // UDI码补齐
private int udiCodeRel; //UDI码关联关系
private boolean downstreamEnable;
private int orderScanFinish;
private int orderUnReceive;

@ -1,11 +1,12 @@
package com.glxp.api.service.inout;
import com.baomidou.mybatisplus.extension.service.IService;
import com.glxp.api.entity.inout.IoCodeLostEntity;
import com.glxp.api.res.inout.IoCodeLostResponse;
import java.util.List;
public interface IoCodeLostService {
public interface IoCodeLostService extends IService<IoCodeLostEntity> {
List<IoCodeLostResponse> selectLost(IoCodeLostEntity ioCodeLostEntity);

@ -1,12 +1,13 @@
package com.glxp.api.service.inout;
import com.baomidou.mybatisplus.extension.service.IService;
import com.glxp.api.entity.inout.IoCodeRelEntity;
import com.glxp.api.req.inout.IoOrderRelRequest;
import com.glxp.api.res.inout.IoCodeRelResponse;
import java.util.List;
public interface IoCodeRelService {
public interface IoCodeRelService extends IService<IoCodeRelEntity> {
List<IoCodeRelResponse> selectIoCodeRelList(IoOrderRelRequest ioOrderRelRequest);

@ -1,6 +1,7 @@
package com.glxp.api.service.inout.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glxp.api.res.inout.IoCodeLostResponse;
import org.springframework.stereotype.Service;
@ -15,7 +16,7 @@ import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class IoCodeLostServiceImpl implements IoCodeLostService {
public class IoCodeLostServiceImpl extends ServiceImpl<IoCodeLostMapper,IoCodeLostEntity> implements IoCodeLostService {
@Resource
IoCodeLostMapper codeLostEntityMapper;

@ -2,6 +2,7 @@ package com.glxp.api.service.inout.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.glxp.api.dao.inout.IoCodeRelMapper;
import com.glxp.api.entity.inout.IoCodeRelEntity;
@ -17,7 +18,7 @@ import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class IoCodeRelServiceImpl implements IoCodeRelService {
public class IoCodeRelServiceImpl extends ServiceImpl<IoCodeRelMapper, IoCodeRelEntity> implements IoCodeRelService {
@Resource
IoCodeRelMapper ioCodeRelMapper;
@ -77,6 +78,7 @@ public class IoCodeRelServiceImpl implements IoCodeRelService {
int count = ioCodeRelMapper.delete(ew);
return count;
}
@Override
public List<IoCodeRelResponse> selectIoCodeRelDetailList(IoOrderRelRequest ioOrderRelRequest) {
if (ioOrderRelRequest == null) {

@ -172,14 +172,35 @@ public class SpsSyncDownloadService {
}
/**
* TODO
*
* @param info
*/
public void syncOtherData(SyncDataSetResponse info) {
Date now = new Date();
//是否需要执行
boolean needExec = info.getUdiCodeLost() == 2 || info.getUdiCodeRel() == 2;
if (!needExec) {
return;
}
try {
basicExportInfoCreate(BasicExportTypeEnum.OTHER_DATA, now, this.getClass()
, x -> x.generateOtherDataFile(info, now, false)
, x -> x.generateOtherDataFile(info, now, true));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
*
*
* @param exportEnum
* @param hasDataMethod
* @param createFileMethod
* @return
* @throws Exception
*/
private void basicExportInfoCreate(BasicExportTypeEnum exportEnum, Date now
, Class<? extends SpsSyncDownloadService> clazz, Function<SpsSyncDownloadService, Boolean> hasDataMethod, Function<SpsSyncDownloadService, Boolean> createFileMethod) throws Exception {
@ -371,6 +392,93 @@ public class SpsSyncDownloadService {
}
}
private final IoCodeLostService ioCodeLostService;
private final IoCodeRelService ioCodeRelService;
/**
*
*
* @param info
* @param now
* @param createFile
* @return true/false /
*/
protected boolean generateOtherDataFile(SyncDataSetResponse info, Date now, boolean createFile) {
//文件数据
Map<String, List> jsonMap = new WeakHashMap<>(4);
Map<BasicExportStatusTimeEnum, Map<String, Object>> totalTimeMap = new WeakHashMap<>(10);
try {
//确认有开启物资字典由外向内同步
if (info.getUdiCodeLost() == 2) {
Map<String, Object> map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_LOST, createFile);
totalTimeMap.put(BasicExportStatusTimeEnum.IO_CODE_LOST, map);
List<IoCodeLostEntity> ioCodeLostList = ioCodeLostService.list(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)) {
jsonMap.put(BasicExportStatusTimeEntity.class.getSimpleName(), ioCodeLostList);
}
}
//确认有开启udi关联关系同步
if (info.getUdiCodeRel() == 2) {
Map<String, Object> map = basicExportStatusTimeInfo(now, BasicExportStatusTimeEnum.IO_CODE_REL, createFile);
totalTimeMap.put(BasicExportStatusTimeEnum.IO_CODE_REL, map);
List<IoCodeRelEntity> ioCodeRelList = ioCodeRelService.list(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)) {
jsonMap.put(IoCodeRelEntity.class.getSimpleName(), ioCodeRelList);
}
}
if (jsonMap.size() > 0) {
if (!createFile) {
return true;
}
try {
String fileFullPath = writeFile(filePath, BasicExportTypeEnum.BASIC_DATA.getRemark(), JsonUtils.toJsonString(jsonMap));
//计算总数
int total = 0;
for (List l : jsonMap.values()) {
total += l.size();
}
try {
//插入一条任务数据
boolean update = basicExportService.update(Wrappers.lambdaUpdate(BasicExportStatusEntity.class)
.set(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_SYNC.getCode())
.set(BasicExportStatusEntity::getUpdateTime, new Date())
.set(BasicExportStatusEntity::getCacheFilePath, fileFullPath)
.set(BasicExportStatusEntity::getRemark, String.format("%s: %s条", BasicExportTypeEnum.BASIC_DATA.getRemark(), total))
.eq(BasicExportStatusEntity::getType, BasicExportTypeEnum.BASIC_DATA.getRemark())
.eq(BasicExportStatusEntity::getStatus, BasicExportStatusEnum.WAIT_BUILT.getCode())
.isNull(BasicExportStatusEntity::getCacheFilePath)
);
} catch (Exception e) {
// 异常回滚
this.exportTimeRollback(totalTimeMap, BasicExportTypeEnum.BASIC_DATA, fileFullPath);
}
return true;
} catch (IOException e) {
logger.error(String.format("syncIdcSps----process------------生成[%s]文件及更改库操作异常,异常信息<%s>"
, BasicExportTypeEnum.BASIC_DATA.getRemark(), e.getMessage()));
// 异常回滚
this.exportTimeRollback(totalTimeMap, BasicExportTypeEnum.BASIC_DATA, null);
}
}
return false;
} catch (Exception e) {
logger.error(e.getMessage());
return false;
}
}
/**
* basicExportStatusTime
*

@ -68,6 +68,7 @@ public class AsyncHeartTask implements SchedulingConfigurer {
spsSyncDownloadService.syncDiProductsTask();
// todo 生成任务都写在这
spsSyncDownloadService.syncBasicData(syncDataSetEntity);
spsSyncDownloadService.syncOtherData(syncDataSetEntity);
redisUtil.set("SPS_SYNC_GEN_DATA", curTime);
}
}

Loading…
Cancel
Save