package com.eitc.quartz.task;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.eitc.common.utils.spring.SpringUtils;
import com.eitc.patient.domain.NoticeManage;
import com.eitc.patient.service.INoticeManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * noticeManageTask
 *
 * @author mtx
 * @date: 2024/05/28 16:16
 */
@Component("noticeManageTask")
@Slf4j
public class NoticeManageTask {

    public void checkNoticeManageDisplayStatus() {
        log.info("checkNoticeManageDisplayStatus start");
        INoticeManageService noticeManageService = SpringUtils.getBean(INoticeManageService.class);
        List<NoticeManage> list = noticeManageService.list();
        if (CollectionUtils.isNotEmpty(list)) {
            List<NoticeManage> updateList = new ArrayList<>();
            for (NoticeManage noticeManage : list) {
                Integer status = noticeManageService.checkDisplayStatus(noticeManage);
                if (Objects.equals(noticeManage.getDisplayStatus(), status)) {
                    continue;
                }
                NoticeManage notice = new NoticeManage();
                notice.setDisplayStatus(status);
                notice.setId(noticeManage.getId());
                updateList.add(notice);
            }
            noticeManageService.updateBatchById(updateList);
        }
    }

}
