From 7a8af8c19b40b8028e25ee0b669463d06f723a30 Mon Sep 17 00:00:00 2001
From: 刘帅 <rr.iii@qq.com>
Date: 星期一, 21 九月 2026 15:57:24 +0800
Subject: [PATCH] bug:测试问题统一修改
---
cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 154 insertions(+), 12 deletions(-)
diff --git a/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java b/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java
index 3a637db..0019170 100644
--- a/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java
+++ b/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java
@@ -1,13 +1,20 @@
package com.dsh.other.controller;
+import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.other.entity.*;
+import com.dsh.other.enums.EnableStatusEnum;
+import com.dsh.other.enums.QrLinkTypeEnum;
+import com.dsh.other.enums.SiteBookingStatusEnum;
+import com.dsh.other.mapper.QrLinkMapper;
import com.dsh.other.feignclient.CourseRecordClient;
+import com.dsh.other.feignclient.account.AppUserClient;
import com.dsh.other.feignclient.account.CityManagerClient;
import com.dsh.other.feignclient.activity.UserCouponClient;
import com.dsh.other.feignclient.activity.model.QueryUserCouponByIdAndUserId;
@@ -27,6 +34,7 @@
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
@@ -41,8 +49,12 @@
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
import java.util.*;
+import java.security.SecureRandom;
import java.util.stream.Collectors;
+import java.util.regex.Pattern;
/**
* @author zhibing.pu
@@ -50,7 +62,12 @@
*/
@RestController
@RequestMapping("")
+@Slf4j
public class SiteController {
+
+ private static final char[] ENTRY_CODE_CHARS = "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".toCharArray();
+ private static final Pattern MAINLAND_MOBILE = Pattern.compile("^1[3-9]\\d{9}$");
+ private final SecureRandom entryCodeRandom = new SecureRandom();
@Autowired
private ISiteService siteService;
@@ -68,10 +85,15 @@
private ISiteBookingService siteBookingService;
@Resource
+ private QrLinkMapper qrLinkMapper;
+
+ @Resource
private UserCouponClient userCouponClient;
@Resource
private CityManagerClient cityManagerClient;
+ @Resource
+ private AppUserClient appUserClient;
@Autowired
private IOperatorUserService operatorUserService;
@@ -151,7 +173,10 @@
@RequestMapping("/base/site/getList")
@ResponseBody
public List<Site> getList() {
- return siteService.list(new QueryWrapper<Site>().ne("state", 3));
+ return siteService.list(new QueryWrapper<Site>()
+ .ne("state", 3)
+ .orderByDesc("insertTime")
+ .orderByDesc("id"));
}
/**
@@ -262,7 +287,8 @@
}
}
-
+ @Autowired
+ private ITSitePriceService sitePriceService;
@ResponseBody
@PostMapping("/base/site/querySiteList")
@ApiOperation(value = "获取场地列表", tags = {"用户—预约场地"})
@@ -270,6 +296,8 @@
})
public ResultUtil<List<QuerySiteListVo>> querySiteList(QuerySiteList querySiteList) {
try {
+
+
List<QuerySiteListVo> querySiteListVos = siteService.querySiteList(querySiteList);
return ResultUtil.success(querySiteListVos);
} catch (Exception e) {
@@ -304,11 +332,12 @@
@ApiImplicitParam(value = "场地id", name = "id", dataType = "int", required = true),
@ApiImplicitParam(value = "日期(2023-01-01)", name = "day", dataType = "string", required = true),
@ApiImplicitParam(value = "半场名称", name = "halfName", dataType = "string", required = false),
- @ApiImplicitParam(value = "选择场地的名称", name = "siteName", dataType = "string", required = false)
+ @ApiImplicitParam(value = "选择场地的名称", name = "siteName", dataType = "string", required = false),
+ @ApiImplicitParam(value = "入场方式 1订场 2散客", name = "targetAudience",defaultValue = "1",dataType = "string", required = true),
})
- public ResultUtil<List<QuerySiteTimes>> querySiteTimes(Integer id, String day, String halfName, String siteName) {
+ public ResultUtil<List<QuerySiteTimes>> querySiteTimes(Integer id, String day, String halfName, String siteName,Integer targetAudience) {
try {
- List<QuerySiteTimes> list = siteService.querySiteTimes(id, day, halfName, siteName);
+ List<QuerySiteTimes> list = siteService.querySiteTimes(id, day, halfName, siteName,targetAudience);
return ResultUtil.success(list);
} catch (Exception e) {
e.printStackTrace();
@@ -366,6 +395,20 @@
if (null == uid) {
return ResultUtil.tokenErr();
}
+ String phone = reservationSite.getPhone();
+ if (phone != null && phone.contains("*")) {
+ Map<String, Object> userPhone = appUserClient.siteBookingPhone(uid, "true");
+ Object originalPhone = userPhone == null ? null : userPhone.get("phone");
+ if (!(originalPhone instanceof String) || ((String) originalPhone).trim().isEmpty()) {
+ return ResultUtil.error("未获取到用户原始手机号");
+ }
+ reservationSite.setPhone((String) originalPhone);
+ } else if (phone == null || !MAINLAND_MOBILE.matcher(phone.trim()).matches()) {
+ return ResultUtil.error("请输入正确的手机号");
+ } else {
+ reservationSite.setPhone(phone.trim());
+ }
+// Integer uid = 201;
return siteService.reservationSite(uid, reservationSite);
} catch (Exception e) {
e.printStackTrace();
@@ -514,16 +557,20 @@
String trade_no = map.get("trade_no");
SiteBooking siteBooking = siteBookingService.getOne(new QueryWrapper<SiteBooking>()
.eq("orderNo", code).eq("state", 1));
+ if (siteBooking == null) {
+ throw new IllegalStateException("未找到支付宝回调对应的场地预约订单:" + code);
+ }
if (siteBooking.getStatus() == 0) {
siteBooking.setPayTime(new Date());
siteBooking.setStatus(1);
siteBooking.setPayOrderNo(trade_no);
siteBookingService.updateById(siteBooking);
- PrintWriter out = response.getWriter();
- out.write("success");
- out.flush();
- out.close();
}
+ // 已处理的重复通知也必须确认 success,避免支付宝持续重试。
+ PrintWriter out = response.getWriter();
+ out.write("success");
+ out.flush();
+ out.close();
}
} catch (Exception e) {
e.printStackTrace();
@@ -633,6 +680,7 @@
HashMap<String, Object> map = new HashMap<>();
System.err.println("预约id"+id);
SiteBooking siteBooking = siteBookingService.getById(id);
+ Integer targetAudience = siteBooking.getTargetAudience();
System.err.println("预约"+siteBooking);
Integer storeId = siteBooking.getStoreId();
Store byId1 = service.getById(storeId);
@@ -643,8 +691,15 @@
map.put("siteType", siteType.getName());
map.put("shopName", byId1.getName());
map.put("shopAddress", byId1.getAddress());
+ // 进场二维码新增参数codeType 1=订场 2=散客,3=门票,玩湃惠民卡codeType=4
+ map.put("codeType", targetAudience);
+ map.put("dataId", siteBooking.getId());
+// map.put("siteName", siteBooking.getNextName()==null?"":siteBooking.getNextName());
+// map.put("halfName", siteBooking.getHalfName()==null?"":siteBooking.getHalfName());
+ System.err.println("订场类型:"+targetAudience);
map.put("name", site.getName());
+ map.put("targetAudience", targetAudience);
List<Integer> ids = getIds(siteBooking.getSiteId());
@@ -679,6 +734,69 @@
e.printStackTrace();
return ResultUtil.runErr();
}
+ }
+
+ @ResponseBody
+ @GetMapping("/api/site/entryQr")
+ @ApiOperation(value = "获取订场进场二维码", tags = {"用户—预约场地"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "预约数据 id", name = "bookingId", dataType = "int", required = true),
+ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header")
+ })
+ public ResultUtil<Map<String, Object>> entryQr(Integer bookingId) {
+ try {
+ Integer uid = tokenUtil.getUserIdFormRedis();
+ if (uid == null) return ResultUtil.tokenErr();
+ SiteBooking booking = siteBookingService.getById(bookingId);
+ if (booking == null || !uid.equals(booking.getAppUserId())) return ResultUtil.error("预约记录不存在");
+ if (SiteBookingStatusEnum.EXPIRED.getCode().equals(booking.getStatus())
+ || SiteBookingStatusEnum.CANCELED.getCode().equals(booking.getStatus())) {
+ return ResultUtil.error("当前预约不可使用二维码");
+ }
+ QrLink link = qrLinkMapper.selectOne(new QueryWrapper<QrLink>()
+ .eq("type", QrLinkTypeEnum.BOOKING_ENTRY.getCode())
+ .eq("bookingId", bookingId)
+ .eq("enabled", EnableStatusEnum.ENABLED.getCode())
+ .last("limit 1"));
+ if (link == null || (link.getExpiresAt() != null && link.getExpiresAt().before(new Date()))) {
+ link = createEntryQrLink(booking, bookingId);
+ }
+ Map<String, Object> data = new HashMap<>();
+ data.put("shortCode", link.getShortCode());
+ data.put("url", "https://www.weparklife.com/other/q/" + link.getShortCode());
+ data.put("expiresAt", link.getExpiresAt());
+ return ResultUtil.success(data);
+ } catch (Exception e) {
+ log.error("[SITE_ENTRY_QR] generate failed, bookingId={}", bookingId, e);
+ return ResultUtil.runErr();
+ }
+ }
+
+ /** 创建与预约记录绑定的进场二维码短链。 */
+ private QrLink createEntryQrLink(SiteBooking booking, Integer bookingId) {
+ QrLink link = new QrLink();
+ link.setType(QrLinkTypeEnum.BOOKING_ENTRY.getCode());
+ link.setBookingId(bookingId);
+ link.setStoreId(booking.getStoreId());
+ link.setSiteId(booking.getSiteId());
+ link.setEnabled(EnableStatusEnum.ENABLED.getCode());
+ link.setExpiresAt(booking.getEndTime());
+ link.setShortCode(nextEntryQrCode());
+ qrLinkMapper.insert(link);
+ return link;
+ }
+
+ /** 生成数据库中尚未使用的十位进场二维码短码。 */
+ private String nextEntryQrCode() {
+ String code;
+ do {
+ StringBuilder builder = new StringBuilder(10);
+ for (int index = 0; index < 10; index++) {
+ builder.append(ENTRY_CODE_CHARS[entryCodeRandom.nextInt(ENTRY_CODE_CHARS.length)]);
+ }
+ code = builder.toString();
+ } while (qrLinkMapper.selectCount(new QueryWrapper<QrLink>().eq("shortCode", code)) > 0);
+ return code;
}
public List<Integer> getIds(Integer siteId) {
@@ -941,18 +1059,41 @@
@PostMapping("/base/site/getNewAddSiteList")
public List<SiteVo> getAppUserSiteList(@RequestBody Integer storeId) {
List<SiteVo> siteVos = new ArrayList<>();
-
+ DayOfWeek dayOfWeek = LocalDate.now().getDayOfWeek();
+ Map<Integer, List<TSitePrice>> priceMap = sitePriceService.lambdaQuery().eq(TSitePrice::getDayOfWeek, dayOfWeek.getValue())
+ .list()
+ .stream().collect(Collectors.groupingBy(TSitePrice::getSiteId));
List<Site> list = siteService.list(new QueryWrapper<Site>().eq("state", 1).eq("storeId", storeId)
.orderByDesc("insertTime"));
+ String now = DateUtil.now().substring(11, 19);
+
if (list.size() > 0) {
for (Site site : list) {
+ List<TSitePrice> tSitePrices = priceMap.get(site.getId());
+
SiteVo vo = new SiteVo();
+ vo.setIsCanBeBooked(site.getIsCanBeBooked());
vo.setSiteId(site.getId());
vo.setSiteName(site.getName());
- vo.setSiteTime(site.getAppointmentStartTime() + "-" + site.getAppointmentEndTime());
+ vo.setSiteTime("");
+ vo.setPrice(0.0);
+ if (tSitePrices!=null&& !tSitePrices.isEmpty()){
+ BigDecimal bigDecimal = BigDecimal.ZERO;
+ // 遍历 查询最小的价格
+ for (TSitePrice tSitePrice : tSitePrices) {
+ // 当前时间再范围之内
+ if (tSitePrice.getStartTime().compareTo(now) <= 0 && tSitePrice.getEndTime().compareTo(now) >= 0) {
+ if (tSitePrice.getCashPrice().compareTo(bigDecimal) > 0) {
+ bigDecimal = tSitePrice.getCashPrice();
+ }
+ }
+ }
+ vo.setPrice(bigDecimal.doubleValue());
+ vo.setSiteTime(tSitePrices.get(0).getStartTime() + "-" + tSitePrices.get(tSitePrices.size()-1).getEndTime());
+ }
SiteType byId = siteTypeService.getById(site.getSiteTypeId());
vo.setSiteType(byId.getName());
- vo.setPrice(site.getCashPrice());
+
siteVos.add(vo);
}
}
@@ -960,4 +1101,5 @@
}
+
}
--
Gitblit v1.7.1