课程自动复制批处理

This commit is contained in:
limqhz
2022-02-09 17:19:38 +08:00
parent a2adc8b62f
commit 99a4cd94aa
2 changed files with 115 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
package com.ydd.oms.task;
import com.enums.VenueTypeEnum;
import com.sv.entity.Venue;
import com.sv.entity.VenueLesson;
import com.sv.service.api.util.DateUtilCard;
import com.sv.service.oms.VenueLessonService;
import com.sv.service.oms.VenueService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
/**
* Controller - 修改用户会员卡
*
* @author lihong
* @since 2018-08-25
*/
@Component
public class CopyLessonTask {
private final Logger logger = LoggerFactory.getLogger(CopyLessonTask.class);
@Resource
private VenueService venueService;
@Resource
private VenueLessonService venueLessonService;
private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
/**
* 每周一九点
*/
@Scheduled(cron = "0 */1 * * * ?")
public void execute(){
logger.info("开始执行拷贝课程批处理");
LocalTime time = LocalTime.now();
LocalDate date = LocalDate.now();
logger.info(time.toString());
logger.info(date.toString());
int cWeek = date.getDayOfWeek().getValue();
List<Venue> venueList = venueService.findAlls();
for (Venue venue : venueList) {
if (VenueTypeEnum.BASKETBALL.value != venue.getType()
&& venue.getCopyWeek() != null && cWeek == venue.getCopyWeek()){
// 非篮球馆有课程
LocalTime copyTime = venue.getCopyTime();
if (checkTime(time,copyTime)){
LocalDate startDate = date.plusDays(-7);
LocalDate endDate = date.plusDays(-1);
String startTime = dtf.format(startDate);
String endTime = dtf.format(endDate);
List<VenueLesson> allForCopy = venueLessonService.findAllForCopy(startTime, endTime);
if (allForCopy!= null && allForCopy.size()>0){
logger.info("需要操作的课程数为:" + allForCopy.size());
int count = 0;
for (VenueLesson venueLesson : allForCopy) {
count ++;
Date copyDate = DateUtilCard.addDays(venueLesson.getDate(), 7);
venueLessonService.copy(venueLesson.getId(),copyDate,copyDate);
}
logger.info("拷贝的课程数量为:" + count);
}
}
}
}
}
private boolean checkTime(LocalTime time, LocalTime copyTime) {
int cHour = time.getHour();
int cMinute = time.getMinute();
if (copyTime == null){
copyTime = LocalTime.parse("00:00");
}
int sHour = copyTime.getHour();
int sMinute = copyTime.getMinute();
if (cHour == sHour && cMinute == sMinute){
return true;
}
return false;
}
}

View File

@@ -0,0 +1,23 @@
package com.ydd.oms.task;
import com.OmsApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@SpringBootTest(classes={OmsApplication.class})
public class CopyLessonTaskTest {
@Resource
CopyLessonTask copyLessonTask;
@Test
public void testTask(){
copyLessonTask.execute();
}
}