package mingzuozhibi.service;

import mingzuozhibi.persist.Disc;
import mingzuozhibi.persist.Sakura;
import mingzuozhibi.support.Dao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class EveryHourTask {

    @Autowired
    private Dao dao;

    @Transactional
    public void run() {
        doEveryHourTask();
    }

    private void doEveryHourTask() {
        dao.execute(session -> {
            List<Sakura> sakuras = dao.findAll(Sakura.class).stream()
                    .filter(sakura -> !sakura.isTop100())
                    .collect(Collectors.toList());
            sakuras.forEach(sakura -> {
                List<Disc> toDelete = sakura.getDiscs().stream()
                        .filter(this::isReleasedTenDays)
                        .collect(Collectors.toList());
                sakura.getDiscs().removeAll(toDelete);

                Logger logger = LoggerFactory.getLogger(EveryHourTask.class);
                if (logger.isInfoEnabled() && toDelete.size() > 0) {
                    logger.info("从列表[{}]移除{}个碟片", sakura.getTitle(), toDelete.size());
                    toDelete.forEach(disc -> logger.info("移除碟片{}", disc.getTitle()));
                } else {
                    logger.info("列表[{}]没有需要移除的过期碟片", sakura.getTitle());
                }
            });
        });
    }

    private boolean isReleasedTenDays(Disc disc) {
        LocalDate releaseTenDays = disc.getReleaseDate().plusDays(10);
        return LocalDate.now().isAfter(releaseTenDays);
    }

}

@@ -497,16 +497,103 @@
 Dao dao;
+%0A    public static final Logger LOGGGER = LoggerFactory.getLogger(EveryHourTask.class);
 %0A%0A    @T
@@ -1205,96 +1205,19 @@
     
-Logger logger = LoggerFactory.getLogger(EveryHourTask.class);%0A                if (logger
+if (LOGGGER
 .isI
@@ -1271,30 +1271,31 @@
             
-logger
+LOGGGER
 .info(%22%E4%BB%8E%E5%88%97%E8%A1%A8%5B%7B
@@ -1388,22 +1388,23 @@
 disc -%3E 
-logger
+LOGGGER
 .info(%22%E7%A7%BB
@@ -1479,19 +1479,21 @@
     
-logger.info
+LOGGGER.debug
 (%22%E5%88%97%E8%A1%A8

Update EveryHourTask Logger