| | |
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | /**
|
| | | * 更新渠道订单(最多20分钟)
|
| | | * |
| | | * @param startTime
|
| | | */
|
| | | private void updateRelationOrder(long startTime) {
|
| | | String startTimeStr = TimeUtil.getGernalTime(startTime, "yyyy-MM-dd HH:mm:ss");
|
| | | List<TaoBaoOrder> orderList = TaoKeApiUtil.getTaoBaoRelationOrder(startTimeStr, Constant.TAOBAO_AUTH_APPKEY,
|
| | |
| | | addRelationAndSpecialOrder(orderList);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 按天更新
|
| | | * |
| | | * @param day
|
| | | */
|
| | | private void updateRelationOrderByDay(String day) {
|
| | | long timestamp = TimeUtil.convertToTimeTemp(day, "yyyy-MM-dd");
|
| | | for (int i = 0; i < 72; i++) {
|
| | | updateRelationOrder(timestamp + 1000 * 60 * 20L * i);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 更新会员订单(最多20分钟)
|
| | | * |
| | | * @param startTime
|
| | | */
|
| | | private void updateSpecialOrder(long startTime) {
|
| | | String startTimeStr = TimeUtil.getGernalTime(startTime, "yyyy-MM-dd HH:mm:ss");
|
| | | List<TaoBaoOrder> orderList = TaoKeApiUtil.getTaoBaoSpecialOrder(startTimeStr, Constant.TAOBAO_AUTH_APPKEY,
|
| | | Constant.TAOBAO_AUTH_APPSECRET);
|
| | | addRelationAndSpecialOrder(orderList);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 按天更新
|
| | | * |
| | | * @param day
|
| | | */
|
| | | private void updateSpecialOrderByDay(String day) {
|
| | | long timestamp = TimeUtil.convertToTimeTemp(day, "yyyy-MM-dd");
|
| | | for (int i = 0; i < 72; i++) {
|
| | | updateSpecialOrder(timestamp + 1000 * 60 * 20L * i);
|
| | | }
|
| | | }
|
| | |
|
| | | private void addRelationAndSpecialOrder(List<TaoBaoOrder> orderList) {
|
| | |
| | | // 每30s爬取一次
|
| | | @Scheduled(cron = "0/30 * * * * ? ")
|
| | | public void doJob1() {
|
| | | // if (!Constant.IS_TASK)
|
| | | // return;
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | long currentTime = System.currentTimeMillis();
|
| | | // 爬取21分钟之前到现在的
|
| | | updateRelationOrder(currentTime - 1000 * 60 * 20L);
|
| | | updateSpecialOrder(currentTime - 1000 * 60 * 20L);
|
| | | }
|
| | |
|
| | | // 每16分钟更新一次一天的(每天可更新近90天的数据)
|
| | | @Scheduled(cron = "0 0/16 * * * ? ")
|
| | | public void doJob2() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | long currentTime = System.currentTimeMillis();
|
| | | long dayStartTime = TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"), "yyyy-MM-dd");
|
| | | int pos = (int) ((currentTime - dayStartTime) / 1000 * 60 * 16L);
|
| | |
|
| | | long time = dayStartTime - (pos + 1) * 1000 * 60 * 60 * 24L;
|
| | |
|
| | | // 只能更新最近90天的
|
| | | if (currentTime - time > 1000 * 60 * 60 * 24L * 90)
|
| | | return;
|
| | | updateRelationOrderByDay(TimeUtil.getGernalTime(time, "yyyy-MM-dd"));
|
| | | updateSpecialOrderByDay(TimeUtil.getGernalTime(time, "yyyy-MM-dd"));
|
| | | }
|
| | |
|
| | | // 每个小时更新最近1天的数据
|
| | | @Scheduled(cron = "0 0 0/1 * * ? ")
|
| | | public void doJob3() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | long startTime = System.currentTimeMillis() - 1000 * 60 * 60 * 24L;
|
| | | for (int i = 0; i < 71; i++) {
|
| | | updateRelationOrder(startTime + 1000 * 60 * 20L * i);
|
| | | updateSpecialOrder(startTime + 1000 * 60 * 20L * i);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|