diff --git a/oms/src/main/java/com/ydd/oms/task/CopyLessonTask.java b/oms/src/main/java/com/ydd/oms/task/CopyLessonTask.java new file mode 100644 index 0000000..c22b463 --- /dev/null +++ b/oms/src/main/java/com/ydd/oms/task/CopyLessonTask.java @@ -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 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 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; + } + +} diff --git a/oms/src/test/java/com/ydd/oms/task/CopyLessonTaskTest.java b/oms/src/test/java/com/ydd/oms/task/CopyLessonTaskTest.java new file mode 100644 index 0000000..04fca80 --- /dev/null +++ b/oms/src/test/java/com/ydd/oms/task/CopyLessonTaskTest.java @@ -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(); + } + +}