LightPoollingAuctionSchedule.java 1.49 KB
package com.glsx.usedcar.task;

import com.glsx.usedcar.module.auction.service.AuctionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 *
 */
@Slf4j
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class LightPoollingAuctionSchedule {
    private final AuctionService auctionService;

    /**
     * 自动竞价定时任务
     * 500毫秒更新一次
     */
    @Scheduled(fixedDelay = 1000, initialDelay = 1000 * 5)
    public void autoBidding() {
//        log.info("自动竞价定时任务");
        long start = System.currentTimeMillis();
        try {
            auctionService.autoBidding();
        } catch (Exception e) {
            log.error("自动竞价定时任务异常", e);
        } finally {
//            long end = System.currentTimeMillis();
//            log.info("自动竞价定时任务耗时{}ms", end - start);
        }
    }

    /**
     * 明拍竞价中模式为轮询出价的车辆更新为拍卖中
     */
    @Scheduled(fixedDelay = 1000, initialDelay = 1000 * 5)
    public void switchNextAuctionVehicle() {
        try {
            auctionService.switchNextAuctionVehicle();
        } catch (Exception e) {
            log.error("自动更新明拍竞价中模式为轮询出价的车辆更新为拍卖中出现异常", e);
        }
    }

}