| | |
| | | package com.yuanchu.mom; |
| | | |
| | | import com.yuanchu.mom.service.PerformanceShiftService; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import java.util.Map; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.time.temporal.WeekFields; |
| | | import java.util.Locale; |
| | | |
| | | |
| | | @SpringBootTest |
| | | class SystemRunApplicationTest { |
| | | |
| | | private static String fileName = "D:\\" + System.currentTimeMillis() + ".xlsx"; |
| | | |
| | | @Autowired |
| | | private PerformanceShiftService performanceShiftService; |
| | | |
| | | @Test |
| | | void contextLoads() { |
| | | Map<Object, Object> header = performanceShiftService.exportToExcel("2024-05-04 00:00:00", null, null); |
| | | // 获取当前日期 |
| | | LocalDate today = LocalDate.now(); |
| | | |
| | | // EasyExcel.write(fileName) |
| | | // .head(header) |
| | | // // 合并策略:合并相同数据的行。第一个参数表示从哪一行开始进行合并,由于表头占了两行,因此从第2行开始(索引从0开始) |
| | | // // 第二个参数是指定哪些列要进行合并 |
| | | //// .registerWriteHandler(new MergeSameRowsStrategy(2, new int[]{0, 1, 2, 3, 8, 9})) |
| | | // // 注意:需要先调用registerWriteHandler()再调用sheet()方法才能使合并策略生效!!! |
| | | // .sheet("模板") |
| | | // .doWrite(data()); |
| | | // 获取本月的第一天和最后一天 |
| | | LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth()); |
| | | LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth()); |
| | | |
| | | // 获取周字段信息(根据区域设置) |
| | | WeekFields weekFields = WeekFields.of(Locale.getDefault()); |
| | | |
| | | // 获取本月第一天的周一 |
| | | LocalDate startOfWeek = firstDayOfMonth.with(TemporalAdjusters.previousOrSame(weekFields.getFirstDayOfWeek())); |
| | | |
| | | // 遍历本月所有天数,找出每周的第一天和最后一天 |
| | | LocalDate endOfWeek; |
| | | while (startOfWeek.isBefore(firstDayOfMonth.plusMonths(1))) { |
| | | endOfWeek = startOfWeek.plusDays(6); |
| | | LocalDateTime startDateTime = LocalDateTime.of(startOfWeek, LocalTime.MIDNIGHT); |
| | | LocalDateTime endDateTime = LocalDateTime.of(endOfWeek, LocalTime.MIDNIGHT); |
| | | |
| | | System.out.println("Week starts on " + startDateTime + " and ends on " + endDateTime); |
| | | |
| | | startOfWeek = startOfWeek.plusWeeks(1); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |