package com.iformall.schedule;

import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.WxCUserBasicInfo;
import com.iformall.enums.EnumAssignTagsTrigger;
import com.iformall.service.WxCUserBasicInfoService;
import com.iformall.service.WxCUserTagsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


@Component
public class WxCUserTagsSchedule {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    WxCUserTagsService wxCUserTagsService;

    @Autowired
    WxCUserBasicInfoService wxCUserBasicInfoService;

    @Scheduled(cron = "0 0 3 * * ?") // 每天凌晨03:00对会员列表扫描补录标签
    //@Scheduled(cron = "0 */5 * * * ?") // 测试1分钟一次
    public void wxCUserTagsSchedule() {
        WxCUserBasicInfo  wxCUserBasicInfo = new WxCUserBasicInfo();

        int pageIndex = 1;
        final int pageSize = 1000;

        PageInfo page;
        do{
            page = wxCUserBasicInfoService.listAsPage(wxCUserBasicInfo, pageIndex++, pageSize);
            page.getList().parallelStream().forEach(cubi -> {
                wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_SCAN, cubi);
            });
        } while ((page.isHasNextPage()));
    }
}