2021-10-28 08:09:50 +00:00
|
|
|
|
package cn.palmte.work.config;
|
|
|
|
|
|
|
2022-04-29 08:03:09 +00:00
|
|
|
|
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;
|
2021-10-28 08:09:50 +00:00
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
|
|
2022-04-29 08:03:09 +00:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
2021-10-28 08:09:50 +00:00
|
|
|
|
@Configuration //1.主要用于标记配置类,兼备Component的效果。
|
|
|
|
|
|
@EnableScheduling // 2.开启定时任务
|
|
|
|
|
|
public class StaticScheduleTask {
|
2022-04-29 08:03:09 +00:00
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(StaticScheduleTask.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
public AdminRepository adminRepository;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
public ProjectRepository projectRepository;
|
|
|
|
|
|
|
2021-10-28 08:09:50 +00:00
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 0/5 * * * ?")
|
|
|
|
|
|
private void temp() throws Exception {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-29 08:03:09 +00:00
|
|
|
|
@Scheduled(cron = "0 0/1 * * * ?")
|
|
|
|
|
|
private void changeUserName() throws Exception {
|
2021-10-28 08:09:50 +00:00
|
|
|
|
|
2022-04-29 08:05:15 +00:00
|
|
|
|
logger.info("更新项目创建者姓名开始");
|
2022-04-29 08:03:09 +00:00
|
|
|
|
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());
|
|
|
|
|
|
}
|
2022-04-29 08:05:15 +00:00
|
|
|
|
logger.info("更新项目创建者姓名结束");
|
2022-04-29 08:03:09 +00:00
|
|
|
|
}
|
2021-10-28 08:09:50 +00:00
|
|
|
|
}
|