|
@@ -0,0 +1,262 @@
|
|
|
+package beilv.web.controller.bootacourse;
|
|
|
+
|
|
|
+import beilv.admissionticket.domain.AdmissionTicket;
|
|
|
+import beilv.admissionticket.service.IAdmissionTicketService;
|
|
|
+import beilv.bootacourse.domain.BootACourse;
|
|
|
+import beilv.bootacourse.domain.BootACourseBO;
|
|
|
+import beilv.bootacourse.service.IBootACourseService;
|
|
|
+import beilv.cardpurchaserecord.domain.CardPurchaseRecord;
|
|
|
+import beilv.cardpurchaserecord.service.ICardPurchaseRecordService;
|
|
|
+import beilv.carinformation.domain.CarInformation;
|
|
|
+import beilv.carinformation.service.ICarInformationService;
|
|
|
+import beilv.common.core.controller.BaseController;
|
|
|
+import beilv.common.core.domain.AjaxResult;
|
|
|
+import beilv.common.utils.DictUtils;
|
|
|
+import beilv.common.utils.uuid.IdUtils;
|
|
|
+import beilv.site.domain.BeilvSite;
|
|
|
+import beilv.site.service.IBeilvSiteService;
|
|
|
+import beilv.usermembershipcard.domain.MemberStream;
|
|
|
+import beilv.usermembershipcard.service.IUserMembershipCardService;
|
|
|
+import beilv.venue.domain.BeilvVenue;
|
|
|
+import beilv.venue.service.IBeilvVenueService;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/bootACourse")
|
|
|
+public class bootACourseController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBeilvVenueService venueService;
|
|
|
+ @Autowired
|
|
|
+ private IBeilvSiteService siteService;
|
|
|
+ @Autowired
|
|
|
+ private IAdmissionTicketService ticketService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICardPurchaseRecordService recordService;
|
|
|
+ @Autowired
|
|
|
+ private IUserMembershipCardService cardService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBootACourseService courseService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询基础信息
|
|
|
+ */
|
|
|
+ @PostMapping("/getVenueList")
|
|
|
+ public AjaxResult getVenueList(){
|
|
|
+ //获取球场列表
|
|
|
+ List<BeilvVenue> resultList = venueService.selectBeilvVenueList(new BeilvVenue());
|
|
|
+ return AjaxResult.success(resultList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据场馆id获取下面的球场信息
|
|
|
+ * @param beilvSite venueId(场馆id)
|
|
|
+ */
|
|
|
+ @PostMapping("/getSiteList")
|
|
|
+ public AjaxResult getSiteList(@RequestBody BeilvSite beilvSite){
|
|
|
+ //根据球场id, 获取下面所有的场地信息
|
|
|
+ List<BeilvSite> beilvSites = siteService.selectBeilvSiteList(beilvSite);
|
|
|
+ Set<String> siteTypeSite = new HashSet<>();
|
|
|
+
|
|
|
+ //遍历场地信息, 获取球场下所有的场地类型
|
|
|
+ beilvSites.forEach(site->{
|
|
|
+ siteTypeSite.add(site.getSiteType());
|
|
|
+ });
|
|
|
+
|
|
|
+ List<String> siteTypeList = new ArrayList<>();
|
|
|
+ //遍历场地类型, 获取场地类型的Label
|
|
|
+ siteTypeSite.forEach(siteType->{
|
|
|
+ siteTypeList.add(DictUtils.getDictLabel("site_type",siteType));
|
|
|
+ });
|
|
|
+
|
|
|
+ HashMap<String, Object> result = new HashMap<>();
|
|
|
+ //放入LabelList
|
|
|
+ result.put("siteType", siteTypeList);
|
|
|
+ //放入球场List
|
|
|
+ result.put("siteList", beilvSites);
|
|
|
+ return AjaxResult.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据球场类型, 判断用户是否具有此类会员卡
|
|
|
+ * 有返回会员卡信息集合
|
|
|
+ * 没有返回空集合
|
|
|
+ */
|
|
|
+ @PostMapping("/hasClubCard")
|
|
|
+ public AjaxResult hasClubCard(@RequestBody BootACourseBO course){
|
|
|
+ CardPurchaseRecord cardPurchaseRecord = new CardPurchaseRecord();
|
|
|
+ cardPurchaseRecord.setUserId(course.getUserId());
|
|
|
+ cardPurchaseRecord.setCardType(course.getTicketType());
|
|
|
+ cardPurchaseRecord.setType("1");
|
|
|
+ return AjaxResult.success(recordService.selectCardPurchaseRecordList(cardPurchaseRecord));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询可购票的场次信息
|
|
|
+ * 请求参数:
|
|
|
+ * 日期: yyyy-MM-dd
|
|
|
+ * 场地类型: site_type字典
|
|
|
+ * 球场id:
|
|
|
+ */
|
|
|
+ @PostMapping("/getTicketList")
|
|
|
+ public AjaxResult getTicketList(@RequestBody AdmissionTicket admissionTicket){
|
|
|
+ //设置查询状态: 可以预定的时段
|
|
|
+ admissionTicket.setAdmissionTicketStatus("0");
|
|
|
+ //查询可用时段
|
|
|
+ List<AdmissionTicket> admissionTickets = ticketService.selectBeilvAdmissionTicketList(admissionTicket);
|
|
|
+ return AjaxResult.success(admissionTickets);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 购票接口
|
|
|
+ * 用户id, 场次id, 会员卡id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/addCourse")
|
|
|
+ public AjaxResult addCourse(@RequestBody BootACourseBO course){
|
|
|
+ //根据场次id 关联球馆表, 获取球馆允许提前多少分钟可以退票
|
|
|
+ Date refund = calculationTime(ticketService.getThresholdValue(course.getTicketId()));
|
|
|
+
|
|
|
+
|
|
|
+ //生成订单编号
|
|
|
+ String orderId = IdUtils.fastSimpleUUID();
|
|
|
+ //生成订单信息
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ BootACourse bootACourse = new BootACourse(
|
|
|
+ course.getUserId(), //用户id
|
|
|
+ course.getContactPeople(), //联系人
|
|
|
+ course.getContactNumber(), //联系电话
|
|
|
+ simpleDateFormat.format(new Date()), //下单时间
|
|
|
+ "payment_status_to_be_paid", //支付状态
|
|
|
+ orderId, //订单比那好
|
|
|
+ course.getTicketId(), //场次id
|
|
|
+ course.getTicketType(), //场地类型
|
|
|
+ course.getClubCardId(), //会员卡号
|
|
|
+ refund); //最晚退单时间
|
|
|
+
|
|
|
+
|
|
|
+ //验证场次是否可用
|
|
|
+ if(courseService.isOk(course)){
|
|
|
+ //调用会员卡接口减少次数
|
|
|
+ MemberStream memberStream = new MemberStream();
|
|
|
+ memberStream.setUserCardId(course.getClubCardId());
|
|
|
+ memberStream.setType("0");
|
|
|
+ memberStream.setOrderId(orderId);
|
|
|
+
|
|
|
+ cardService.addStream(memberStream);
|
|
|
+
|
|
|
+ //扣除成功后, 修改订单状态为已付款.
|
|
|
+ bootACourse.setPaymentTime(simpleDateFormat.format(new Date()));
|
|
|
+ bootACourse.setPaymentStatus("payment_status_have_paid");
|
|
|
+
|
|
|
+ //将门票信息修改为2: 线上预约的时段;
|
|
|
+ AdmissionTicket admissionTicket = new AdmissionTicket();
|
|
|
+ admissionTicket.setId(course.getTicketId());
|
|
|
+ admissionTicket.setAdmissionTicketStatus("2");
|
|
|
+ ticketService.updateBeilvAdmissionTicket(admissionTicket);
|
|
|
+
|
|
|
+ return toAjax(courseService.addCourse(bootACourse));
|
|
|
+ }else{
|
|
|
+ return AjaxResult.error("当前场次已被预订");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询订单
|
|
|
+ */
|
|
|
+ @PostMapping("/getCourseList")
|
|
|
+ public AjaxResult getCourseList(@RequestBody BootACourseBO courseBO){
|
|
|
+ return AjaxResult.success(courseService.getCourseList(courseBO));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退票接口
|
|
|
+ * 用户id, 订单编号,
|
|
|
+ * @return
|
|
|
+ * 1: 订单已核销
|
|
|
+ * 2: 退票成功
|
|
|
+ */
|
|
|
+ @PostMapping("/remofeCourse")
|
|
|
+ public AjaxResult remofeCourse(@RequestBody BootACourseBO courseBo){
|
|
|
+ //通过orderId查询订单信息
|
|
|
+ BootACourse course = courseService.getCourseInfo(courseBo);
|
|
|
+
|
|
|
+ //判断最晚退单时间是否大于当前时间, 大于返回true
|
|
|
+ if(course.getRefund().after(new Date())){
|
|
|
+ //根据订单信息中的会员卡退次数
|
|
|
+ //调用会员卡接口减少次数
|
|
|
+ MemberStream memberStream = new MemberStream();
|
|
|
+ memberStream.setUserCardId(course.getClubCardId());
|
|
|
+ memberStream.setType("1");
|
|
|
+ cardService.addStream(memberStream);
|
|
|
+
|
|
|
+
|
|
|
+ //修改场次信息状态为0: 可以预定的时段;
|
|
|
+ AdmissionTicket admissionTicket = new AdmissionTicket();
|
|
|
+ admissionTicket.setId(course.getTicketId());
|
|
|
+ admissionTicket.setAdmissionTicketStatus("0");
|
|
|
+ ticketService.updateBeilvAdmissionTicket(admissionTicket);
|
|
|
+
|
|
|
+ //修改订单信息状态为退款,
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ course.setRefundTime(simpleDateFormat.format(new Date()));
|
|
|
+ course.setRefundInstructions(courseBo.getRefundInstructions());
|
|
|
+ course.setPaymentStatus("payment_status_refunded");
|
|
|
+ return toAjax(courseService.updateCourse(course));
|
|
|
+ }else{
|
|
|
+ return AjaxResult.error("当前订单超过最晚退单时间, 不允许退单");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Date calculationTime(Map<String, Object> map){
|
|
|
+
|
|
|
+ String sessionStr = MapUtils.getString(map, "session").split("-")[0]; //12:15
|
|
|
+
|
|
|
+ String thresholdValueStr = MapUtils.getString(map, "thresholdValue");// 120
|
|
|
+
|
|
|
+ String ticketDate = MapUtils.getString(map, "ticketDate");// 2025-01-07
|
|
|
+
|
|
|
+ // 拼接 ticketDate 和 sessionStr 形成完整的时间字符串
|
|
|
+ String fullTimeStr = ticketDate + " " + sessionStr + ":00"; // 例如 "2025-01-07 12:15:00"
|
|
|
+
|
|
|
+ // 将完整的时间字符串解析为 Date 对象
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Date date = null;
|
|
|
+ try {
|
|
|
+ date = dateFormat.parse(fullTimeStr);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null; // 如果解析失败,返回 null
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将 thresholdValueStr 转换为整数
|
|
|
+ int thresholdValue = Integer.parseInt(thresholdValueStr);
|
|
|
+
|
|
|
+ // 使用 Calendar 类来减去 thresholdValue 分钟
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(date);
|
|
|
+ calendar.add(Calendar.MINUTE, -thresholdValue);
|
|
|
+
|
|
|
+ // 返回计算后的 Date 对象
|
|
|
+ return calendar.getTime();
|
|
|
+ }
|
|
|
+}
|