刘帅
7 天以前 d41e0da5df20d559b0b9b8c180d1bf70ba7c1845
cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/BallController.java
@@ -60,6 +60,8 @@
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Controller
@@ -290,7 +292,9 @@
        User user = UserExt.getUser();
        ballQueryDto.setType(user.getObjectType());
        ballQueryDto.setId(user.getObjectId());
        return ballClient.list(ballQueryDto);
        List<Game> games = ballClient.list(ballQueryDto);
        games.sort(Comparator.comparing(Game::getId, Comparator.nullsLast(Comparator.reverseOrder())));
        return games;
    }
    @ResponseBody
@@ -1680,33 +1684,52 @@
        // times格式示例: 2025-10-14 19:00-19:30;2025-10-14 19:30-20:00;2025-10-14 20:00-20:30;2025-10-14 20:30-21:00
        // targetAudience字段会由Spring MVC自动绑定(1=订场,2=散客)
        String times = siteBooking.getTimes();
        if (ToolUtil.isEmpty(times)) {
            return ResultUtil.error("请选择预约时间段");
        }
        String[] dates = times.split(";");
        if (dates.length == 0) {
            return ResultUtil.error("请选择预约时间段");
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        format.setLenient(false);
        try {
            // 提取最早的开始时间
            Pattern timeSlotPattern = Pattern.compile("^(\\d{4}-\\d{2}-\\d{2})\\s+(\\d{2}:\\d{2})-(\\d{2}:\\d{2})$");
            // dates[0] 格式: 2025-10-14 19:00-19:30
            String start = dates[0];
            String startDateStr = start.substring(0, start.lastIndexOf("-"));
            Date startDate = format.parse(startDateStr);
            // 提取最晚的结束时间
            Matcher startMatcher = timeSlotPattern.matcher(dates[0].trim());
            // dates[dates.length - 1] 格式: 2025-10-14 20:30-21:00
            String end = dates[dates.length - 1];
            String[] str = end.split(" ");
            String endDateStr = str[0] + " " + str[1].substring(str[1].indexOf("-") + 1);
            Date endDate = format.parse(endDateStr);
            Matcher endMatcher = timeSlotPattern.matcher(dates[dates.length - 1].trim());
            if (!startMatcher.matches() || !endMatcher.matches()) {
                return ResultUtil.error("预约时间段格式错误,请重新选择");
            }
            Date startDate = format.parse(startMatcher.group(1) + " " + startMatcher.group(2));
            Date endDate = format.parse(endMatcher.group(1) + " " + endMatcher.group(3));
            if (!endDate.after(startDate)) {
                return ResultUtil.error("预约结束时间必须晚于开始时间");
            }
            
            siteBooking.setStartTime(startDate);
            siteBooking.setEndTime(endDate);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("预约时间段格式错误,请重新选择");
        }
        siteBooking.setPayType(2);
        //存多少钱
        String money = siteBooking.getMoney();
        if (ToolUtil.isEmpty(money)) {
            return ResultUtil.error("请输入预约金额");
        }
        String[] moneys = money.split(",");
        siteBooking.setPayMoney(Double.valueOf(moneys[0]));
        if (moneys.length == 0 || ToolUtil.isEmpty(moneys[0])) {
            return ResultUtil.error("预约金额格式错误");
        }
        try {
            siteBooking.setPayMoney(Double.valueOf(moneys[0]));
        } catch (NumberFormatException e) {
            return ResultUtil.error("预约金额格式错误");
        }
        siteBooking.setMoney(money);
        // 查询当前预约人是否是会员
        String phone = siteBooking.getPhone();