新增数据延时同步功能

fengcang
anthonyywj2 3 years ago
parent c1bd7b21e4
commit 9b00e3d249

@ -19,4 +19,6 @@ public class Constant {
public static String SPTM_TO_DI = "sptm_to_di"; public static String SPTM_TO_DI = "sptm_to_di";
public static String DELAY_SYNC_TIME = "DELAY_SYNC_TIME";
} }

@ -3,11 +3,13 @@ package com.glxp.api.admin.controller.info;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.glxp.api.admin.annotation.AuthRuleAnnotation; import com.glxp.api.admin.annotation.AuthRuleAnnotation;
import com.glxp.api.admin.constant.Constant;
import com.glxp.api.admin.entity.info.SyncDataBustypeEntity; import com.glxp.api.admin.entity.info.SyncDataBustypeEntity;
import com.glxp.api.admin.entity.info.SyncDataSetEntity; import com.glxp.api.admin.entity.info.SyncDataSetEntity;
import com.glxp.api.admin.res.info.SyncDataSetResponse; import com.glxp.api.admin.res.info.SyncDataSetResponse;
import com.glxp.api.admin.service.info.SyncDataBustypeService; import com.glxp.api.admin.service.info.SyncDataBustypeService;
import com.glxp.api.admin.service.info.SyncDataSetService; import com.glxp.api.admin.service.info.SyncDataSetService;
import com.glxp.api.admin.util.RedisUtil;
import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.common.util.ResultVOUtils;
@ -29,12 +31,22 @@ public class SyncDataSetController {
private SyncDataSetService syncDataSetService; private SyncDataSetService syncDataSetService;
@Resource @Resource
private SyncDataBustypeService syncDataBustypeService; private SyncDataBustypeService syncDataBustypeService;
@Resource
private RedisUtil redisUtil;
@AuthRuleAnnotation("system/param/syncData/config") @AuthRuleAnnotation("system/param/syncData/config")
@GetMapping("/system/param/syncData/config") @GetMapping("/system/param/syncData/config")
public BaseResponse list() { public BaseResponse list() {
return ResultVOUtils.success(syncDataSetService.selectSet());
Integer delaySyncTime = (Integer) redisUtil.get(Constant.DELAY_SYNC_TIME);
if (delaySyncTime != null) {
long time = redisUtil.getExpire(Constant.DELAY_SYNC_TIME);
delaySyncTime = Math.toIntExact(time) / 60;
}
SyncDataSetResponse syncDataSetResponse = syncDataSetService.selectSet();
syncDataSetResponse.setDelaySyncTime(delaySyncTime);
return ResultVOUtils.success(syncDataSetResponse);
} }
@AuthRuleAnnotation("system/param/syncData/save") @AuthRuleAnnotation("system/param/syncData/save")
@ -49,10 +61,14 @@ public class SyncDataSetController {
syncDataBustypeService.inserts(busTypes); syncDataBustypeService.inserts(busTypes);
syncDataSetEntity.setBusTypes(null); syncDataSetEntity.setBusTypes(null);
boolean b = syncDataSetService.insert(syncDataSetEntity); boolean b = syncDataSetService.insert(syncDataSetEntity);
if (syncDataSetResponse.getDelaySyncTime() != null &&
syncDataSetResponse.getDelaySyncTime() > 0) {
redisUtil.set(Constant.DELAY_SYNC_TIME, syncDataSetResponse.getDelaySyncTime(), (syncDataSetResponse.getDelaySyncTime() + 1) * 60);
redisUtil.set("SPS_SYNC_GEN_DATA", System.currentTimeMillis() + syncDataSetResponse.getDelaySyncTime() * 60 * 1000);
}
if (!b) { if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK); return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
} }
return ResultVOUtils.success(); return ResultVOUtils.success();
} }
} }

@ -35,5 +35,6 @@ public class SyncDataSetResponse {
private boolean entrustAction; private boolean entrustAction;
private Integer orderSyncTime; private Integer orderSyncTime;
private Integer orderSyncDlTime; private Integer orderSyncDlTime;
private Integer delaySyncTime;
} }

Loading…
Cancel
Save