package com.yunzhi.marketing.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunzhi.marketing.common.CommConstant;
import com.yunzhi.marketing.entity.TaRecommendCustomer;
import com.yunzhi.marketing.service.ITaRecommendCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.util.List;

public class CustomerTimeJob {

    @Autowired
    private ITaRecommendCustomerService taRecommendCustomerService;

    @Scheduled(cron = "0 0 0 * * ?")
    private void customerTimeJob() {
        LocalDateTime nowDate = LocalDateTime.now();
        LocalDateTime beforeTime = nowDate.plusDays(-15);
        LambdaQueryWrapper<TaRecommendCustomer> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.between(TaRecommendCustomer::getCirculationTime,beforeTime,nowDate);
        queryWrapper.eq(TaRecommendCustomer::getVerifyStatus, CommConstant.VERIFY_AGREE);
        List<TaRecommendCustomer> list = taRecommendCustomerService.list(queryWrapper);
        list.forEach(e -> {
            e.setBuildingId(null);
            e.setRealtyConsultant(null);
            e.setRecommendPerson(null);
            e.setEntryType(null);
        });
        taRecommendCustomerService.updateBatchById(list);
    }
}
