package cn.palmte.work.config;

import cn.palmte.work.model.Admin;
import cn.palmte.work.model.AdminRepository;
import cn.palmte.work.model.Project;
import cn.palmte.work.model.ProjectRepository;
import cn.palmte.work.service.ActProcDefService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class StaticScheduleTask {
    private static final Logger logger = LoggerFactory.getLogger(StaticScheduleTask.class);

    @Autowired
    public AdminRepository adminRepository;

    @Autowired
    public ProjectRepository projectRepository;


    @Scheduled(cron = "0 0/5 * * * ?")
    private void temp() throws Exception {
    }

    /*@Scheduled(cron = "0 0/1 * * * ?")
    private void changeUserName() throws Exception {

        logger.info("更新项目创建者姓名开始");
        List<Project> all = projectRepository.findAll();
        for (Project project : all) {
            logger.info("更新前："+project.getCreatorName());
            Admin one = adminRepository.findOne(project.getCreatorId());
            project.setCreatorName(one.getRealName());
            Project project1 = projectRepository.saveAndFlush(project);
            logger.info("更新后："+project1.getCreatorName());
        }
        logger.info("更新项目创建者姓名结束");
    }*/
}
