@Component
@RequiredArgsConstructor
@Slf4j
public class CronAll {
private final static SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private final BaseProvinceMapper baseProvinceMapper;
private final BaseDateMapper baseDateMapper;
private final AllMapper allMapper;
private final ISysConfigService configService;
/**
* tj_3 重置+叠加
*/
@Transactional
public void tj_3() throws ParseException {
log.info("cron tj_3 begin");
String tjDateStr = configService.selectConfigByKey("base.tj_all_date");
Date tjDate = SDF.parse(tjDateStr);
boolean exists = baseDateMapper.exists(
new LambdaQueryWrapper<BaseDate>().eq(BaseDate::getTimeDate, tjDate).eq(BaseDate::getTj3, "1"));
if (!exists) {
log.info("cron tj_3 init by tjDate , date {}", tjDate);
return;
}
Date now = new Date();
Date endDate = DateUtil.beginOfDay(now);
Date beginDate = DateUtils.addDays(endDate, -1);
BaseDate baseDate = baseDateMapper.getTempAll(tjDate, endDate, "tj3");
Date baseDateTimeDate = baseDate.getTimeDate();
if (baseDate == null) {
log.info("cron tj_3 end null, date {}", beginDate);
return;
}
Long count = baseDateMapper.selectCount(
new LambdaQueryWrapper<BaseDate>().between(BaseDate::getTimeDate, tjDate, baseDateTimeDate).eq(
BaseDate::getTj3, "1"));
long count_ = DateUtil.betweenDay(tjDate, baseDateTimeDate, true);
if (count != count_) {
baseDateMapper.update(
new LambdaUpdateWrapper<BaseDate>().set(BaseDate::getTj3, "0").gt(BaseDate::getTimeDate, tjDate).le(
BaseDate::getTimeDate,
baseDateTimeDate));
allMapper.delete(
new LambdaQueryWrapper<TjZp>().gt(TjZp::getTimeDate, tjDate).le(TjZp::getTimeDate, now));
Date currentDate = DateUtils.addDays(tjDate, 1);
//todo
allMapper.insertCron(tjDate, currentDate);
baseDateMapper.update(
new LambdaUpdateWrapper<BaseDate>().eq(BaseDate::getTimeDate, currentDate).set(BaseDate::getTj3, "1"));
log.info("cron tj_3 end reset {}", baseDate);
return;
}
allMapper.insertCron(tjDate, baseDateTimeDate);
baseDateMapper.update(
new LambdaUpdateWrapper<BaseDate>().eq(BaseDate::getTimeDate, baseDateTimeDate).set(BaseDate::getTj3, "1"));
log.info("cron tj_3 end now {}", baseDateTimeDate);
}
/**
* tj_4 昨日叠加
*/
@Transactional
public void tj_4() throws ParseException {
log.info("cron tj_4 begin");
Date now = new Date();
String tjDateStr = configService.selectConfigByKey("base.tj_all_date");
Date tjDate = SDF.parse(tjDateStr);
Date endDate = DateUtil.beginOfDay(now);
Date beginDate = DateUtils.addDays(endDate, -1);
BaseDate baseDate = baseDateMapper.getTempAll(tjDate, endDate, "tj4");
Date baseDateTimeDate = baseDate.getTimeDate();
if (baseDate == null) {
log.info("cron tj_4 end null, date {}", beginDate);
return;
}
allMapper.insertCron(tjDate, baseDateTimeDate);
baseDateMapper.update(
new LambdaUpdateWrapper<BaseDate>().eq(BaseDate::getTimeDate, baseDateTimeDate).set(BaseDate::getTj4, "1"));
log.info("cron tj_4 end now {}", baseDateTimeDate);
}
}
相关文章
优先推荐同专题、同标签和同作者内容,补足热门文章。
评论 0
登录 后参与评论
评论
成为第一个评论的人