fix(health):修复已预约人数没有跟随订单变化的bug
This commit is contained in:
parent
9d3d19ef7a
commit
084455fd76
@ -17,8 +17,8 @@ import java.util.List;
|
||||
* @since 2023-11-01
|
||||
*/
|
||||
public interface ReservationSettingMapper extends BaseMapper<ReservationSetting> {
|
||||
@Update("UPDATE reservation_setting SET reservations = reservations + 1 WHERE id = #{id} AND reservations < number")
|
||||
Integer updateReservations(@Param("id") Integer id);
|
||||
@Update("UPDATE reservation_setting SET reservations = reservations + #{count} WHERE order_date = #{time} AND reservations < number")
|
||||
Integer plusReservationCount(@Param("time") LocalDate time, @Param("count") Integer count);
|
||||
|
||||
@Select("SELECT order_date FROM reservation_setting WHERE #{start} <= order_date AND order_date <= #{end}")
|
||||
List<String> getReservationDate(@Param("start") LocalDate start, @Param("end") LocalDate end);
|
||||
|
||||
@ -7,6 +7,7 @@ import com.jzo2o.health.model.dto.response.ReservationDateResDTO;
|
||||
import com.jzo2o.health.model.dto.response.ReservationSettingResDTO;
|
||||
import com.jzo2o.health.model.excel.ReservationImportData;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.util.List;
|
||||
|
||||
@ -36,4 +37,11 @@ public interface IReservationSettingService extends IService<ReservationSetting>
|
||||
* 获取当前月份可用预约日期
|
||||
*/
|
||||
ReservationDateResDTO getReservationDateByMonth(YearMonth yearMonth);
|
||||
|
||||
/**
|
||||
* 增加已预约人数数量
|
||||
* @param time
|
||||
* @param count 数量
|
||||
*/
|
||||
void plusReservationCount(LocalDate time, Integer count);
|
||||
}
|
||||
@ -16,6 +16,7 @@ import com.jzo2o.health.model.domain.OrdersCancelled;
|
||||
import com.jzo2o.health.model.dto.request.OrdersCancelReqDTO;
|
||||
import com.jzo2o.health.service.IOrderCancelService;
|
||||
import com.jzo2o.health.service.IOrderCommonService;
|
||||
import com.jzo2o.health.service.IReservationSettingService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -30,6 +31,8 @@ import java.time.LocalDateTime;
|
||||
public class OrderCancelServiceImpl extends ServiceImpl<OrdersCancelledMapper, OrdersCancelled> implements IOrderCancelService {
|
||||
@Resource
|
||||
private IOrderCommonService orderCommonService;
|
||||
@Resource
|
||||
private IReservationSettingService reservationSettingService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@ -57,6 +60,9 @@ public class OrderCancelServiceImpl extends ServiceImpl<OrdersCancelledMapper, O
|
||||
.cancellerId(currentUser.getId())
|
||||
.cancellerType(currentUser.getUserType())
|
||||
.build());
|
||||
|
||||
// 已预约人数 - 1
|
||||
reservationSettingService.plusReservationCount(orders.getReservationDate(), -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -29,13 +29,11 @@ import com.jzo2o.health.model.dto.request.PlaceOrderReqDTO;
|
||||
import com.jzo2o.health.model.dto.response.OrdersPayResDTO;
|
||||
import com.jzo2o.health.model.dto.response.PlaceOrderResDTO;
|
||||
import com.jzo2o.health.properties.TradeProperties;
|
||||
import com.jzo2o.health.service.IMemberService;
|
||||
import com.jzo2o.health.service.IOrderCreateService;
|
||||
import com.jzo2o.health.service.IOrderCommonService;
|
||||
import com.jzo2o.health.service.ISetmealService;
|
||||
import com.jzo2o.health.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
@ -55,6 +53,8 @@ public class OrderCreateServiceImpl extends ServiceImpl<OrdersMapper, Orders> im
|
||||
@Resource
|
||||
private IOrderCommonService ordersCommonService;
|
||||
@Resource
|
||||
private IReservationSettingService reservationSettingService;
|
||||
@Resource
|
||||
private TradingApi tradingApi;
|
||||
@Resource
|
||||
private NativePayApi nativePayApi;
|
||||
@ -62,6 +62,8 @@ public class OrderCreateServiceImpl extends ServiceImpl<OrdersMapper, Orders> im
|
||||
private TradeProperties tradeProperties;
|
||||
@Resource
|
||||
private RedisTemplate<String, Long> redisTemplate;
|
||||
@Resource
|
||||
private TransactionTemplate transactionTemplate;
|
||||
|
||||
/**
|
||||
* 生成订单号(2位年+2位月+2位日+13位序号)
|
||||
@ -95,28 +97,33 @@ public class OrderCreateServiceImpl extends ServiceImpl<OrdersMapper, Orders> im
|
||||
throw new ServerErrorException("生成订单id失败无法下单");
|
||||
}
|
||||
|
||||
if (!SqlHelper.retBool(baseMapper.insert(Orders.builder()
|
||||
.id(orderId)
|
||||
.orderStatus(OrderStatusEnum.NO_PAY)
|
||||
.payStatus(OrderPayStatusEnum.NO_PAY)
|
||||
.setmealId(setmeal.getId())
|
||||
.setmealName(setmeal.getName())
|
||||
.setmealPrice(setmeal.getPrice())
|
||||
.setmealSex(setmeal.getSex())
|
||||
.setmealAge(setmeal.getAge())
|
||||
.setmealImg(setmeal.getImg())
|
||||
.setmealRemark(setmeal.getRemark())
|
||||
.reservationDate(placeOrderReqDTO.getReservationDate())
|
||||
.checkupPersonName(placeOrderReqDTO.getCheckupPersonName())
|
||||
.checkupPersonSex(placeOrderReqDTO.getCheckupPersonSex())
|
||||
.checkupPersonPhone(placeOrderReqDTO.getCheckupPersonPhone())
|
||||
.checkupPersonIdcard(placeOrderReqDTO.getCheckupPersonIdcard())
|
||||
.memberId(member.getId())
|
||||
.memberPhone(member.getPhone())
|
||||
.sortBy(DateUtils.toEpochMilli(LocalDateTime.now()))
|
||||
.build()))) {
|
||||
throw new DBException("订单表插入失败下单失败");
|
||||
}
|
||||
transactionTemplate.executeWithoutResult(status -> {
|
||||
if (!SqlHelper.retBool(baseMapper.insert(Orders.builder()
|
||||
.id(orderId)
|
||||
.orderStatus(OrderStatusEnum.NO_PAY)
|
||||
.payStatus(OrderPayStatusEnum.NO_PAY)
|
||||
.setmealId(setmeal.getId())
|
||||
.setmealName(setmeal.getName())
|
||||
.setmealPrice(setmeal.getPrice())
|
||||
.setmealSex(setmeal.getSex())
|
||||
.setmealAge(setmeal.getAge())
|
||||
.setmealImg(setmeal.getImg())
|
||||
.setmealRemark(setmeal.getRemark())
|
||||
.reservationDate(placeOrderReqDTO.getReservationDate())
|
||||
.checkupPersonName(placeOrderReqDTO.getCheckupPersonName())
|
||||
.checkupPersonSex(placeOrderReqDTO.getCheckupPersonSex())
|
||||
.checkupPersonPhone(placeOrderReqDTO.getCheckupPersonPhone())
|
||||
.checkupPersonIdcard(placeOrderReqDTO.getCheckupPersonIdcard())
|
||||
.memberId(member.getId())
|
||||
.memberPhone(member.getPhone())
|
||||
.sortBy(DateUtils.toEpochMilli(LocalDateTime.now()))
|
||||
.build()))) {
|
||||
throw new DBException("订单表插入失败下单失败");
|
||||
}
|
||||
|
||||
// 已预约人数 + 1
|
||||
reservationSettingService.plusReservationCount(placeOrderReqDTO.getReservationDate(), 1);
|
||||
});
|
||||
|
||||
return new PlaceOrderResDTO(orderId);
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ import com.jzo2o.health.model.dto.response.OrdersDetailResDTO;
|
||||
import com.jzo2o.health.model.dto.response.OrdersResDTO;
|
||||
import com.jzo2o.health.service.IOrderCancelService;
|
||||
import com.jzo2o.health.service.IOrderManagerService;
|
||||
import com.jzo2o.health.service.IReservationSettingService;
|
||||
import com.jzo2o.mysql.utils.PageUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -40,6 +41,8 @@ import java.util.stream.Collectors;
|
||||
public class OrderManagerServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements IOrderManagerService {
|
||||
@Resource
|
||||
private IOrderCancelService orderCancelService;
|
||||
@Resource
|
||||
private IReservationSettingService reservationSettingService;
|
||||
|
||||
@Override
|
||||
public PageResult<OrdersResDTO> pageQuery(OrdersPageQueryReqDTO ordersPageQueryReqDTO) {
|
||||
@ -152,6 +155,9 @@ public class OrderManagerServiceImpl extends ServiceImpl<OrdersMapper, Orders> i
|
||||
.cancellerType(UserType.SYSTEM)
|
||||
.build());
|
||||
|
||||
// 已预约人数 - 1
|
||||
reservationSettingService.plusReservationCount(orders.getReservationDate(), -1);
|
||||
|
||||
ordersDetailResDTO.setOrderStatus(OrderStatusEnum.CANCELLED);
|
||||
}
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import com.jzo2o.health.model.dto.request.OrdersCancelReqDTO;
|
||||
import com.jzo2o.health.service.IOrderCancelService;
|
||||
import com.jzo2o.health.service.IOrderCommonService;
|
||||
import com.jzo2o.health.service.IOrderRefundService;
|
||||
import com.jzo2o.health.service.IReservationSettingService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
@ -45,6 +46,8 @@ public class OrderRefundServiceImpl extends ServiceImpl<OrdersRefundMapper, Orde
|
||||
private TransactionTemplate transactionTemplate;
|
||||
@Resource
|
||||
private RefundRecordApi refundRecordApi;
|
||||
@Resource
|
||||
private IReservationSettingService reservationSettingService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@ -93,6 +96,9 @@ public class OrderRefundServiceImpl extends ServiceImpl<OrdersRefundMapper, Orde
|
||||
throw new DBException("更新退款表失败");
|
||||
}
|
||||
|
||||
// 已预约人数 - 1
|
||||
reservationSettingService.plusReservationCount(orders.getReservationDate(), -1);
|
||||
|
||||
new Thread(() -> this.refundOrder(ordersRefund)).start();
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package com.jzo2o.health.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import com.jzo2o.common.expcetions.CommonException;
|
||||
import com.jzo2o.common.expcetions.DBException;
|
||||
import com.jzo2o.common.utils.CollUtils;
|
||||
import com.jzo2o.health.mapper.ReservationSettingMapper;
|
||||
@ -96,4 +97,11 @@ public class ReservationSettingServiceImpl extends ServiceImpl<ReservationSettin
|
||||
List<String> dates = baseMapper.getReservationDate(yearMonth.atDay(1), yearMonth.atEndOfMonth());
|
||||
return new ReservationDateResDTO(dates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void plusReservationCount(LocalDate time, Integer count) {
|
||||
if (SqlHelper.retBool(baseMapper.plusReservationCount(time, count))) {
|
||||
throw new CommonException("预约人数已满不能预约");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user