package com.dayou.message.schedule;

import com.dayou.configuration.AsyncManager;
import com.dayou.entity.Item;
import com.dayou.enums.ItemStateEnum;
import com.dayou.message.handler.SystemMessageHandler;
import com.dayou.service.IItemService;
import com.dayou.service.IMessageService;
import com.dayou.vo.ItemVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 类说明：项目状态监听定时器
 *
 * @author: wucl
 * @since: 2023/7/6
 * created with IntelliJ IDEA.
 */
@Slf4j
@Component
public class ItemStatusSchedule {

    @Autowired
    private IItemService itemService;

    @Autowired
    private IMessageService messageService;

    @Scheduled(cron = "0 0 1 * * ?")
    public void sendMessage2Manager()
    {
        AsyncManager.me().execute(new AsyncManager.BizHandler() {
            List<ItemVO> completedNotEvaluateItem = itemService.getCompletedNotEvaluateItem();
            @Override
            public Boolean validBefore() {
                return CollectionUtils.isNotEmpty(completedNotEvaluateItem);
            }

            @Override
            public Object doCustom() {
                messageService.packagingEvaluateRemind(completedNotEvaluateItem);
                return null;
            }
        }, AsyncManager.AsyncLockStrategy.LOCK_BIZ, AsyncManager.AsyncBiz.PACKAGING_EVALUATE_REMAIN);

    }
}
