package com.hzs.third.job;

import com.hzs.sale.wares.IWaresServiceApi;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@ConditionalOnProperty(name = "xxl-job.start", havingValue = "true")
@Component
public class WaresJob {

    @DubboReference
    IWaresServiceApi iWaresServiceApi;

    /**
     * 商品自动上下架
     */
    @XxlJob("waresAutoLoadingJob")
    public void waresAutoLoadingJob() {
        // 获取当前时间
        Date currentTime = new Date();
        // 自动上架
        iWaresServiceApi.updateByAutoStartAndAutoStart(currentTime);
        // 定时自动下架
        iWaresServiceApi.updateByAutoStartAndAutoEnd(currentTime);
    }

}
