运营周报 根据指定周获取时间
正在显示
1 个修改的文件
包含
42 行增加
和
16 行删除
... | @@ -15,7 +15,9 @@ import com.skua.modules.custom.vo.DepartEquipRemarkVO; | ... | @@ -15,7 +15,9 @@ import com.skua.modules.custom.vo.DepartEquipRemarkVO; |
15 | import com.skua.modules.custom.vo.DepartWeekReportVO; | 15 | import com.skua.modules.custom.vo.DepartWeekReportVO; |
16 | import com.skua.modules.custom.vo.FCustomReportDatasetVO; | 16 | import com.skua.modules.custom.vo.FCustomReportDatasetVO; |
17 | import java.text.DecimalFormat; | 17 | import java.text.DecimalFormat; |
18 | import java.time.DayOfWeek; | ||
18 | import java.time.LocalDate; | 19 | import java.time.LocalDate; |
20 | import java.time.YearMonth; | ||
19 | import java.time.format.DateTimeFormatter; | 21 | import java.time.format.DateTimeFormatter; |
20 | import java.time.temporal.TemporalAdjusters; | 22 | import java.time.temporal.TemporalAdjusters; |
21 | import java.time.temporal.WeekFields; | 23 | import java.time.temporal.WeekFields; |
... | @@ -226,23 +228,47 @@ public class FCustomReportDatasetServiceImpl extends ServiceImpl<FCustomReportDa | ... | @@ -226,23 +228,47 @@ public class FCustomReportDatasetServiceImpl extends ServiceImpl<FCustomReportDa |
226 | */ | 228 | */ |
227 | public static Map<String,String> getWeekDate(String yearMonth,String week) { | 229 | public static Map<String,String> getWeekDate(String yearMonth,String week) { |
228 | Map<String,String> map = new HashMap<>(); | 230 | Map<String,String> map = new HashMap<>(); |
229 | int weekOfMonth = Integer.valueOf(week); // 输入的第几周 | 231 | // int weekOfMonth = Integer.valueOf(week); // 输入的第几周 |
230 | try { | 232 | // try { |
231 | // 解析年月并构造本月的第一天日期 | 233 | // // 解析年月并构造本月的第一天日期 |
232 | LocalDate firstOfMonth = LocalDate.parse(yearMonth + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd")); | 234 | // LocalDate firstOfMonth = LocalDate.parse(yearMonth + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
233 | // 获取本月的第一个星期一 | 235 | // // 获取本月的第一个星期一 |
234 | WeekFields weekFields = WeekFields.of(Locale.getDefault()); | 236 | // WeekFields weekFields = WeekFields.of(Locale.getDefault()); |
235 | LocalDate firstMondayOfMonth = firstOfMonth.with(TemporalAdjusters.firstInMonth(weekFields.getFirstDayOfWeek())); | 237 | // LocalDate firstMondayOfMonth = firstOfMonth.with(TemporalAdjusters.firstInMonth(weekFields.getFirstDayOfWeek())); |
236 | // 计算目标周的开始和结束日期 | 238 | // // 计算目标周的开始和结束日期 |
237 | LocalDate startOfWeek = firstMondayOfMonth.plusWeeks(weekOfMonth - 1).plusDays(1); | 239 | // LocalDate startOfWeek = firstMondayOfMonth.plusWeeks(weekOfMonth - 1).plusDays(1); |
238 | LocalDate endOfWeek = startOfWeek.plusDays(6); | 240 | // LocalDate endOfWeek = startOfWeek.plusDays(6); |
239 | DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | 241 | // DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
240 | map.put("start", startOfWeek.format(dateFormatter)); | 242 | // map.put("start", startOfWeek.format(dateFormatter)); |
241 | map.put("end", endOfWeek.format(dateFormatter)); | 243 | // map.put("end", endOfWeek.format(dateFormatter)); |
242 | } catch (Exception e) { | 244 | // } catch (Exception e) { |
243 | map.put("start", ""); | 245 | // map.put("start", ""); |
244 | map.put("end", ""); | 246 | // map.put("end", ""); |
247 | // } | ||
248 | int year = Integer.parseInt(yearMonth.split("-")[0]); | ||
249 | int month = Integer.parseInt(yearMonth.split("-")[1]); | ||
250 | int weekNumber = Integer.parseInt(week); | ||
251 | YearMonth yearMonth0 = YearMonth.of(year, month); | ||
252 | LocalDate firstDayOfMonth = yearMonth0.atDay(1); | ||
253 | // 计算该月第一周的开始日期 | ||
254 | LocalDate firstWeekStart = firstDayOfMonth.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); | ||
255 | // 计算指定周次的开始日期 | ||
256 | LocalDate startDate = firstWeekStart.plusWeeks(weekNumber - 1); | ||
257 | // 如果开始日期超出了该月范围,说明该月没有指定的周次 | ||
258 | // if (startDate.getMonthValue() != month) { | ||
259 | // throw new IllegalArgumentException("该月没有第 " + weekNumber + " 周"); | ||
260 | // } | ||
261 | // 计算结束日期 | ||
262 | LocalDate endDate = startDate.plusDays(6); | ||
263 | if (endDate.getMonthValue() != month) { | ||
264 | endDate = yearMonth0.atEndOfMonth(); | ||
245 | } | 265 | } |
266 | |||
267 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
268 | String startDateStr = startDate.format(formatter); | ||
269 | String endDateStr = endDate.format(formatter); | ||
270 | map.put("start", startDateStr); | ||
271 | map.put("end", endDateStr); | ||
246 | return map; | 272 | return map; |
247 | } | 273 | } |
248 | //节能环保报表数据 | 274 | //节能环保报表数据 | ... | ... |
-
请 注册 或 登录 后发表评论