BusinessTask --定时任务(例如:商户表里商品对应的已售数量,订单表,需要定时同步已售数量 商户表里商品对应的评论星星总数和评论次数 需要定时同步)
注意:订单表需要create_time<同步时的系统时间比较&&create_time>comment的最后一次同步星星时间
BusinessTask类
/**
* 商户相关的定时任务
*/
@Component("BusinessTask")
public class BusinessTask {
private static final Logger logger = LoggerFactory.getLogger(BusinessTask.class);
@Resource
private BusinessDao businessDao;
@Resource
private SysParamDao sysParamDao;
/**
* 同步已售数量
*/
@Transactional
public void synNumber() {
//logger.info("已同步!");
// 先获取上次同步的时间(最后同步时间)
SysParam sysParam = sysParamDao.selectByKey(SysParamKeyConst.LAST_SYNC_NUM_TIME);
Map<String,Date> map = new HashMap<>();
map.put("startTime", sysParam.getParamValue());
businessDao.updateNumber(map);
// 以当前系统时间做为同步的截止时间,同时也做为下次同步的起始时间
Date endTime = new Date();
map.put("endTime", endTime);
// 按这样起始时间-结束时间同步:商户的已售数量
// 如果起始时间为NULL,那说明是第一次同步,需要将历史数据全步同步,一直同步到当前系统时间为止。
businessDao.updateNumber(map);
// 将当前这个系统时间更新到系统参数表中,做为下次同步的起始时间
SysParam sysParamForUpdate = new SysParam();
sysParamForUpdate.setParamKey(SysParamKeyConst.LAST_SYNC_NUM_TIME);
sysParamForUpdate.setParamValue(endTime);
sysParamDao.updateByKey(sysParamForUpdate);
logger.info("synNum end");
System.out.println("******同步已售数量完毕******");
}
/**
* 同步星级
*/
@Transactional
public void synStar() {
logger.info("synStar start");
// 先获取上次同步的时间(最后同步时间)
SysParam sysParam = sysParamDao.selectByKey(SysParamKeyConst.LAST_SYNC_STAR_TIME);
Map<String,Date> map = new HashMap<>();
map.put("startTime", sysParam.getParamValue());
// 以当前系统时间做为同步的截止时间,同时也做为下次同步的起始时间
Date endTime = new Date();
map.put("endTime", endTime);
// 按这样起始时间-结束时间同步:商户对应的【星星总数】、【评论总次数】
// 如果起始时间为NULL,那说明是第一次同步,需要将历史数据全步同步,一直同步到当前系统时间为止。
businessDao.updateStar(map);
// 将当前这个系统时间更新到系统参数表中,做为下次同步的起始时间
SysParam sysParamForUpdate = new SysParam();
sysParamForUpdate.setParamKey(SysParamKeyConst.LAST_SYNC_STAR_TIME);
sysParamForUpdate.setParamValue(endTime);
sysParamDao.updateByKey(sysParamForUpdate);
logger.info("synStar end");
System.out.println("******同步星级完毕******");
}
}