修改票务服务节假日数据和历年数据接口

This commit is contained in:
punchhhh 2025-01-26 09:28:12 +08:00
parent 0ceebfdfb3
commit 57303f6a0c
3 changed files with 86 additions and 34 deletions

View File

@ -142,7 +142,6 @@ public class SaleDataApi {
@GetMapping("/thisyear/nianjunCount")
@Operation(summary = "查询某年年度售票数量")
public Integer findCountthisyear(Integer year) {
System.out.println(saleDataService.findEventsByYear(year));
return saleDataService.findEventsByYear(year).size();
}
@ -157,9 +156,8 @@ public class SaleDataApi {
@GetMapping("/holidayCount")
@Operation(summary = "查询节假日售票数量")
public CommonResult<HolidayTree> selectHolidayCount(String year) {
Integer currentYear = Integer.parseInt(year);
return saleDataService.selectHolidayCount(currentYear);
public CommonResult<HolidayTree> selectHolidayCount(String holidayName) {
return saleDataService.selectHolidayCount(holidayName);
}
// @GetMapping("/test")
// public void testMethod(){
@ -167,4 +165,9 @@ public class SaleDataApi {
// webSocketSenderApi.sendObject("1","1","666");
// }
@GetMapping("/yearsSaleCount")
@Operation(summary = "查询历年售票数量")
public CommonResult<Map<String, Integer>> selectYearsSaleCount() {
return saleDataService.selectYearsSaleCount();
}
}

View File

@ -103,5 +103,7 @@ public interface SaleDataService {
Integer selectSaleCountByDate(String dateParam);
CommonResult<HolidayTree> selectHolidayCount(Integer date);
CommonResult<HolidayTree> selectHolidayCount(String holidayName);
CommonResult<Map<String, Integer>> selectYearsSaleCount();
}

View File

@ -453,58 +453,105 @@ public class SaleDataServiceImpl implements SaleDataService {
}
@Override
public CommonResult<HolidayTree> selectHolidayCount(Integer currentYear) {
public CommonResult<HolidayTree> selectHolidayCount(String holidayName) {
HolidayTree holidayTree = new HolidayTree();
// 获取当前年份及前两年
// int startYear = currentYear - 2;
// int endYear = currentYear;
// 获取当前年份及前两年
int currentYear = LocalDate.now().getYear();
int startYear = currentYear - 2;
int endYear = currentYear;
// 节假日名称列表
List<String> holidays = Arrays.asList("五一", "国庆", "春节");
// List<String> holidays = Arrays.asList("五一", "国庆", "春节");
// 遍历每一年
// for (int year = startYear; year <= endYear; year++) {
List<String> holidayDates = getHolidayDates(holidayName, startYear, endYear); // 获取每年的该节假日的五天日期
// for (int i = 0; i < 3; i++) {
// 获取每个节假日的前五天数据
for (String holiday : holidays) {
List<String> holidayDates = getHolidayDates(holiday, currentYear); // 获取节假日的五天日期
// for (String holiday : holidays) {
// System.out.println(holidayDates);
for (String date : holidayDates) {
// 查询每个日期的数量
System.out.println(date);
int count = saleDataRepository.countBySddate(date);
holidayTree.addHolidayData(String.valueOf(currentYear), holiday, Integer.parseInt(date.substring(6)), count);
System.out.println(count);
holidayTree.addHolidayData(date.substring(0,4), Integer.parseInt(date.substring(6)), count);
}
}
// }
// }
return CommonResult.success(holidayTree);
}
// 根据节假日和年份获取节假日及其五天的数据从节假日当天开始的五天
private List<String> getHolidayDates(String holiday, int year) {
// private List<String> getHolidayDates(String holiday, int year) {
// List<String> dates = new ArrayList<>();
//
// if (holiday.equals("五一")) {
// // 五一5月1日到5月5日
// for (int i = 0; i < 5; i++) {
// String date = String.format("%04d05%02d", year, 1 + i); // 构建 20230501 格式的日期
// dates.add(date);
// }
// } else if (holiday.equals("国庆")) {
// // 国庆10月1日到10月5日
// for (int i = 0; i < 5; i++) {
// String date = String.format("%04d10%02d", year, 1 + i); // 构建 20231001 格式的日期
// dates.add(date);
// }
// } else if (holiday.equals("春节")) {
// // 春节假设固定日期2月1日-2月5日
// for (int i = 0; i < 5; i++) {
// String date = String.format("%04d02%02d", year, 1 + i); // 构建 20230201 格式的日期
// dates.add(date);
// }
//
// }
// return dates;
// }
// 根据节假日和起止年份获取年份及其五天的数据从节假日当天开始的五天
private List<String> getHolidayDates(String holiday, int startYear, int endYear) {
List<String> dates = new ArrayList<>();
if (holiday.equals("五一")) {
// 五一5月1日到5月5日
for (int i = 0; i < 5; i++) {
String date = String.format("%04d05%02d", year, 1 + i); // 构建 20230501 格式的日期
dates.add(date);
// 遍历指定年份范围
for (int year = startYear; year <= endYear; year++) {
if (holiday.equals("五一")) {
// 五一5月1日到5月5日
for (int i = 0; i < 5; i++) {
String date = String.format("%04d05%02d", year, 1 + i); // 构建 20230501 格式的日期
dates.add(date);
}
} else if (holiday.equals("国庆")) {
// 国庆10月1日到10月5日
for (int i = 0; i < 5; i++) {
String date = String.format("%04d10%02d", year, 1 + i); // 构建 20231001 格式的日期
dates.add(date);
}
} else if (holiday.equals("春节")) {
// 春节假设固定日期2月1日-2月5日
for (int i = 0; i < 5; i++) {
String date = String.format("%04d02%02d", year, 1 + i); // 构建 20230201 格式的日期
dates.add(date);
}
}
} else if (holiday.equals("国庆")) {
// 国庆10月1日到10月5日
for (int i = 0; i < 5; i++) {
String date = String.format("%04d10%02d", year, 1 + i); // 构建 20231001 格式的日期
dates.add(date);
}
} else if (holiday.equals("春节")) {
// 春节假设固定日期2月1日-2月5日
for (int i = 0; i < 5; i++) {
String date = String.format("%04d02%02d", year, 1 + i); // 构建 20230201 格式的日期
dates.add(date);
}
}
return dates;
}
@Override
public CommonResult<Map<String, Integer>> selectYearsSaleCount() {
// 查询23年开始往后十年的数据
Map<String, Integer> result = new HashMap<>();
for (int i = 2023; i <= 2033; i++) {
int count = saleDataRepository.countBySddateToTime(i + "0101", i + "1231").size();
result.put(String.valueOf(i), count);
}
return CommonResult.success(result);
}
}