定时任务更新项目创建者姓名
parent
a102c1c9b8
commit
552e8b9799
|
@ -1,17 +1,47 @@
|
||||||
package cn.palmte.work.config;
|
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.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Configuration //1.主要用于标记配置类,兼备Component的效果。
|
@Configuration //1.主要用于标记配置类,兼备Component的效果。
|
||||||
@EnableScheduling // 2.开启定时任务
|
@EnableScheduling // 2.开启定时任务
|
||||||
public class StaticScheduleTask {
|
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 * * * ?")
|
@Scheduled(cron = "0 0/5 * * * ?")
|
||||||
private void temp() throws Exception {
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue