Authored by mingdan.ge

测试

... ... @@ -25,9 +25,9 @@ public class GlobalRedisValueCache {
@Redis("yohoGlobalRedis")
YHRedisTemplate yHRedisTemplate;
public boolean getLock(String key,int time,TimeUnit timeUnit) {
public boolean getLock(String key,Object value,int time,TimeUnit timeUnit) {
try {
boolean lock = setIfAbsent(key, "lock");
boolean lock = setIfAbsent(key, value);
if (!lock) {
return false;
}
... ...
... ... @@ -33,37 +33,18 @@ public class CpsOrdersSumMessageTask {
@Scheduled(cron = "0 0/5 * * * ?")
// @Scheduled(cron = "0 0 10 * * ?")
public void run() {
//绑定已处理状态
// CpsMessageTaskBo bo = new CpsMessageTaskBo();
// bo.setIp(LocalhostIpFetcher.fetchLocalIP());
// bo.setTime(Long.toString(System.currentTimeMillis()));
// CpsMessageTaskBo cacheBo=redisValueCache.get(TASK_KEY+DateUtil.getToday("yyyyMMdd"), CpsMessageTaskBo.class);
// if (cacheBo != null) {
// logger.info("other get task,it is {}.this is {}.",cacheBo,bo);
// }
// redisValueCache.set(TASK_KEY+DateUtil.getToday("yyyyMMdd"),bo,2, TimeUnit.DAYS);
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// logger.warn("thread sleep error,e is {}",e);
// }
// cacheBo=redisValueCache.get(TASK_KEY+DateUtil.getToday("yyyyMMdd"), CpsMessageTaskBo.class);
// if (cacheBo == null) {
// logger.error("redis error.");
// return;
// }
// if (!cacheBo.getIp().equals(bo.getIp()) || !cacheBo.getTime().equals(bo.getTime())) {
// logger.info("The competition failure,other get task,it is {}.this is {}.",cacheBo,bo);
// return;
// }
//竞争任务处理者
CpsMessageTaskBo bo = new CpsMessageTaskBo();
bo.setIp(LocalhostIpFetcher.fetchLocalIP());
bo.setTime(Long.toString(System.currentTimeMillis()));
String key = TASK_KEY + DateUtil.getToday("yyyyMMdd");
boolean lock = globalRedisValueCache.getLock(key,2, TimeUnit.DAYS);
boolean lock = globalRedisValueCache.getLock(key,bo,2, TimeUnit.DAYS);
if (!lock) {
logger.info("The competition failure,other get task.");
CpsMessageTaskBo cacheBo=globalRedisValueCache.get(key, CpsMessageTaskBo.class);
logger.info("The competition failure,other get task,it is {}.this is {}.",cacheBo,bo);
return;
}
logger.info("get this task,ip is {}",LocalhostIpFetcher.fetchLocalIP());
logger.info("get this task,this is {}",bo);
//昨日
int startTime=DateUtil.getLastDayInt(1);
... ...
... ... @@ -34,36 +34,17 @@ public class CpsSettlementMessageTask {
// @Scheduled(cron = "0 0 10 20,28 * ?")
public void run(){
//竞争任务处理者
// CpsMessageTaskBo bo = new CpsMessageTaskBo();
// bo.setIp(LocalhostIpFetcher.fetchLocalIP());
// bo.setTime(Long.toString(System.currentTimeMillis()));
// CpsMessageTaskBo cacheBo=redisValueCache.get(SETTLEMENT_TASK_KEY+ DateUtil.getToday("yyyyMMdd"), CpsMessageTaskBo.class);
// if (cacheBo != null) {
// logger.info("other get task,it is {}.this is {}.",cacheBo,bo);
// }
// redisValueCache.set(SETTLEMENT_TASK_KEY+DateUtil.getToday("yyyyMMdd"),bo,2, TimeUnit.DAYS);
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// logger.warn("thread sleep error,e is {}",e);
// }
// cacheBo=redisValueCache.get(SETTLEMENT_TASK_KEY+DateUtil.getToday("yyyyMMdd"), CpsMessageTaskBo.class);
// if (cacheBo == null) {
// logger.error("redis error.");
// return;
// }
// if (!cacheBo.getIp().equals(bo.getIp()) || !cacheBo.getTime().equals(bo.getTime())) {
// logger.info("The competition failure,other get task,it is {}.this is {}.",cacheBo,bo);
// return;
// }
CpsMessageTaskBo bo = new CpsMessageTaskBo();
bo.setIp(LocalhostIpFetcher.fetchLocalIP());
bo.setTime(Long.toString(System.currentTimeMillis()));
String key = SETTLEMENT_TASK_KEY + DateUtil.getToday("yyyyMMdd");
boolean lock = globalRedisValueCache.getLock(key,2, TimeUnit.DAYS);
boolean lock = globalRedisValueCache.getLock(key,bo,2, TimeUnit.DAYS);
if (!lock) {
logger.info("The competition failure,other get task.");
CpsMessageTaskBo cacheBo=globalRedisValueCache.get(key, CpsMessageTaskBo.class);
logger.info("The competition failure,other get task,it is {}.this is {}.",cacheBo,bo);
return;
}
logger.info("get this task,ip is {}",LocalhostIpFetcher.fetchLocalIP());
logger.info("get this task,this is {}",bo);
//今天更新的数据
int startTime=DateUtil.getLastDayInt(0);
int endTime= DateUtil.getLastDayInt(-1);
... ...