更新了商品类别
This commit is contained in:
parent
2dba4b00d4
commit
583c3f5007
|
@ -7,4 +7,12 @@ public interface MqConstant {
|
|||
String DELAY_ORDER_QUEUE = "order.delay.queue";
|
||||
|
||||
String DELAY_ORDER_ROUTING_KEY = "order.key";
|
||||
|
||||
String DELAY_COUPON_QUEUE = "coupon.delay.queue";
|
||||
|
||||
String DELAY_COUPON_ROUTING_KEY = "coupon.key";
|
||||
|
||||
String DELAY_USER_COUPON_QUEUE = "userCoupon.delay.queue";
|
||||
|
||||
String DELAY_USER_COUPON_ROUTING_KEY = "userCoupon.key";
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.cultural.heritage.controller.good;
|
||||
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
|
@ -9,34 +11,39 @@ import com.cultural.heritage.annotation.AuthCheck;
|
|||
import com.cultural.heritage.common.BaseResponse;
|
||||
import com.cultural.heritage.common.ErrorCode;
|
||||
import com.cultural.heritage.common.ResultUtils;
|
||||
import com.cultural.heritage.constant.MqConstant;
|
||||
import com.cultural.heritage.constant.UserConstant;
|
||||
import com.cultural.heritage.exception.BusinessException;
|
||||
import com.cultural.heritage.exception.ThrowUtils;
|
||||
import com.cultural.heritage.model.dto.CommonBatchRequest;
|
||||
import com.cultural.heritage.model.dto.CommonRequest;
|
||||
import com.cultural.heritage.model.dto.CommonStringRequest;
|
||||
import com.cultural.heritage.model.dto.coupon.CouponAddRequest;
|
||||
import com.cultural.heritage.model.dto.coupon.CouponQueryRequest;
|
||||
import com.cultural.heritage.model.dto.coupon.CouponUpdateRequest;
|
||||
import com.cultural.heritage.model.dto.coupon.UsableCouponQueryRequest;
|
||||
import com.cultural.heritage.model.entity.Coupon;
|
||||
import com.cultural.heritage.model.entity.Exchange;
|
||||
import com.cultural.heritage.model.entity.User;
|
||||
import com.cultural.heritage.model.entity.UserCoupon;
|
||||
import com.cultural.heritage.model.vo.coupon.CouponVO;
|
||||
import com.cultural.heritage.model.vo.coupon.UserCouponVO;
|
||||
import com.cultural.heritage.service.good.CouponService;
|
||||
import com.cultural.heritage.service.good.ExchangeService;
|
||||
import com.cultural.heritage.service.good.UserCouponService;
|
||||
import com.cultural.heritage.service.user.UserService;
|
||||
import com.cultural.heritage.utils.MultiDelayMessage;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -54,16 +61,16 @@ public class CouponController {
|
|||
private UserService userService;
|
||||
|
||||
|
||||
@Resource
|
||||
private ExchangeService exchangeService;
|
||||
|
||||
|
||||
@Resource
|
||||
private UserCouponService userCouponService;
|
||||
|
||||
|
||||
@Resource
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* 添加优惠券
|
||||
* Web端管理员添加优惠券
|
||||
* @param couponAddRequest 优惠券添加请求体
|
||||
* @return 是否添加成功
|
||||
*/
|
||||
|
@ -92,13 +99,27 @@ public class CouponController {
|
|||
couponService.validCoupon(coupon, false);
|
||||
boolean result = couponService.save(coupon);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "优惠券添加失败");
|
||||
|
||||
// 延迟检查优惠券是否过期
|
||||
MultiDelayMessage<Long> msg = new MultiDelayMessage<>(coupon.getId());
|
||||
rabbitTemplate.convertAndSend(MqConstant.DELAY_EXCHANGE,
|
||||
MqConstant.DELAY_COUPON_ROUTING_KEY, msg, message -> {
|
||||
//计算优惠券截止日期和当前的时间差
|
||||
DateTime now = new DateTime();
|
||||
DateTime end = DateUtil.parse(coupon.getEndTime());
|
||||
long seconds = DateUtil.between(now, end, DateUnit.SECOND);
|
||||
// 添加延迟消息属性
|
||||
message.getMessageProperties().setDelay((int) (seconds * 1000));
|
||||
return message;
|
||||
});
|
||||
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 更新优惠券
|
||||
* Web端管理员更新优惠券
|
||||
* @param couponUpdateRequest 优惠券更新请求体
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
|
@ -128,25 +149,13 @@ public class CouponController {
|
|||
boolean result = couponService.saveOrUpdate(coupon);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "优惠券更新失败");
|
||||
|
||||
QueryWrapper<UserCoupon> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("couponId", coupon.getId());
|
||||
List<UserCoupon> userCouponList = userCouponService.list(queryWrapper);
|
||||
for (UserCoupon userCoupon : userCouponList) {
|
||||
// 更新用户优惠券中的优惠券信息
|
||||
CouponVO couponVO = new CouponVO();
|
||||
BeanUtils.copyProperties(coupon, couponVO);
|
||||
userCoupon.setCouponVO(couponVO);
|
||||
userCoupon.setStatus(coupon.getStatus());
|
||||
}
|
||||
boolean update = userCouponService.updateBatchById(userCouponList);
|
||||
ThrowUtils.throwIf(!CollectionUtils.isEmpty(userCouponList) && !update, ErrorCode.OPERATION_ERROR, "优惠券更新失败");
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 删除优惠券
|
||||
* Web端管理员删除优惠券
|
||||
* @param couponDeleteRequest 优惠券删除请求体
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
|
@ -166,7 +175,7 @@ public class CouponController {
|
|||
|
||||
|
||||
/**
|
||||
* 批量删除优惠券
|
||||
* Web端管理员批量删除优惠券
|
||||
* @param commonBatchRequest 优惠券删除请求体
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
|
@ -203,43 +212,11 @@ public class CouponController {
|
|||
long pageSize = couponQueryRequest.getPageSize();
|
||||
Page<Coupon> page = couponService.page(new Page<>(current, pageSize),
|
||||
couponService.getQueryWrapper(couponQueryRequest));
|
||||
List<Coupon> couponList = page.getRecords();
|
||||
for (Coupon coupon : couponList) {
|
||||
// 比较优惠券有效截止日期
|
||||
String endTime = coupon.getEndTime();
|
||||
String currentTime = DateUtil.now();
|
||||
if (endTime.compareTo(currentTime) <= 0) {
|
||||
coupon.setStatus("已过期");
|
||||
} else {
|
||||
coupon.setStatus("可用");
|
||||
}
|
||||
}
|
||||
boolean update = couponService.updateBatchById(couponList);
|
||||
ThrowUtils.throwIf(!CollectionUtils.isEmpty(couponList) && !update, ErrorCode.OPERATION_ERROR, "优惠券状态更新失败");
|
||||
page.setRecords(couponList);
|
||||
return ResultUtils.success(page);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户删除兑换记录
|
||||
* @param commonRequest 兑换记录删除请求体
|
||||
* @return 是否兑换成功
|
||||
*/
|
||||
@PostMapping("/delRecord")
|
||||
@Operation(summary = "小程序端用户删除兑换记录", description = "参数:兑换记录删除请求体,权限:管理员(admin, boss),方法名:deleteExchangeRecord")
|
||||
public BaseResponse<Boolean> deleteExchangeRecord(@RequestBody CommonRequest commonRequest, HttpServletRequest request) {
|
||||
if (commonRequest == null || commonRequest.getId() <= 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
userService.getLoginUser(request);
|
||||
Long id = commonRequest.getId();
|
||||
boolean result = exchangeService.removeById(id);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "兑换记录删除失败");
|
||||
return ResultUtils.success(true, "删除兑换记录成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -268,31 +245,24 @@ public class CouponController {
|
|||
// 插入一条兑换记录
|
||||
CouponVO couponVO = new CouponVO();
|
||||
BeanUtils.copyProperties(coupon, couponVO);
|
||||
Exchange exchange = new Exchange();
|
||||
exchange.setUserId(userId);
|
||||
exchange.setCouponVO(couponVO);
|
||||
boolean save = exchangeService.save(exchange);
|
||||
UserCoupon userCoupon = new UserCoupon();
|
||||
userCoupon.setUserId(userId);
|
||||
userCoupon.setCouponVO(couponVO);
|
||||
boolean save = userCouponService.save(userCoupon);
|
||||
ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR, "兑换记录插入失败");
|
||||
|
||||
// 更新用户优惠券表
|
||||
QueryWrapper<UserCoupon> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("userId", userId).eq("couponId", coupon.getId());
|
||||
UserCoupon userCoupon = userCouponService.getOne(queryWrapper);
|
||||
if (userCoupon == null) {
|
||||
UserCoupon userCouponSave = new UserCoupon();
|
||||
userCouponSave.setUserId(userId);
|
||||
userCouponSave.setCouponId(coupon.getId());
|
||||
userCouponSave.setCouponVO(couponVO);
|
||||
userCouponSave.setQuantity(1);
|
||||
userCouponSave.setStatus("可用");
|
||||
boolean saveSuccess = userCouponService.save(userCouponSave);
|
||||
ThrowUtils.throwIf(!saveSuccess, ErrorCode.OPERATION_ERROR, "用户优惠券插入失败");
|
||||
} else {
|
||||
UpdateWrapper<UserCoupon> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", userCoupon.getId()).set("quantity", userCoupon.getQuantity() + 1);
|
||||
boolean update = userCouponService.update(updateWrapper);
|
||||
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "用户优惠券更新失败");
|
||||
}
|
||||
// 延迟检查优惠券是否过期
|
||||
MultiDelayMessage<Long> msg = new MultiDelayMessage<>(userCoupon.getId());
|
||||
rabbitTemplate.convertAndSend(MqConstant.DELAY_EXCHANGE,
|
||||
MqConstant.DELAY_USER_COUPON_ROUTING_KEY, msg, message -> {
|
||||
//计算优惠券截止日期和当前的时间差
|
||||
DateTime now = new DateTime();
|
||||
DateTime end = DateUtil.parse(coupon.getEndTime());
|
||||
long seconds = DateUtil.between(now, end, DateUnit.SECOND);
|
||||
// 添加延迟消息属性
|
||||
message.getMessageProperties().setDelay((int) (seconds * 1000));
|
||||
return message;
|
||||
});
|
||||
|
||||
// 更新用户积分
|
||||
loginUser.setPoints(loginUser.getPoints() - requirePoints);
|
||||
|
@ -308,33 +278,25 @@ public class CouponController {
|
|||
|
||||
/**
|
||||
* 小程序端用户查看优惠券
|
||||
* @param commonStringRequest 优惠券状态
|
||||
* @return 当前用户拥有的优惠券列表
|
||||
*/
|
||||
@GetMapping("/list/my")
|
||||
@Operation(summary = "小程序端用户查看优惠券", description = "参数:无,权限:所有人,方法名:pointsExchangeCoupon")
|
||||
public BaseResponse<List<UserCouponVO>> listMyCoupon(HttpServletRequest request) {
|
||||
@PostMapping("/list/my")
|
||||
@Operation(summary = "小程序端用户查看优惠券", description = "参数:无,权限:所有人,方法名:listMyCoupon")
|
||||
public BaseResponse<List<UserCouponVO>> listMyCoupon(@RequestBody CommonStringRequest commonStringRequest, HttpServletRequest request) {
|
||||
if (commonStringRequest == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
String status = commonStringRequest.getType();
|
||||
if (StringUtils.isBlank(status)) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
Long userId = loginUser.getId();
|
||||
QueryWrapper<Exchange> queryWrapper = new QueryWrapper<>();
|
||||
QueryWrapper<UserCoupon> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("userId", userId);
|
||||
List<UserCoupon> userCouponList = userCouponService.list();
|
||||
|
||||
for (UserCoupon userCoupon : userCouponList) {
|
||||
CouponVO couponVO = userCoupon.getCouponVO();
|
||||
// 比较优惠券有效截止日期
|
||||
String endTime = couponVO.getEndTime();
|
||||
String currentTime = DateUtil.now();
|
||||
if (endTime.compareTo(currentTime) <= 0) {
|
||||
couponVO.setStatus("已过期");
|
||||
userCoupon.setStatus("已过期");
|
||||
} else {
|
||||
couponVO.setStatus("可用");
|
||||
userCoupon.setStatus("可用");
|
||||
}
|
||||
}
|
||||
|
||||
boolean update = userCouponService.updateBatchById(userCouponList);
|
||||
ThrowUtils.throwIf(!CollectionUtils.isEmpty(userCouponList) && !update, ErrorCode.OPERATION_ERROR, "优惠券状态更新失败");
|
||||
userCouponList = userCouponList.stream().filter(userCoupon -> userCoupon.getCouponVO().getStatus().equals(status)).toList();
|
||||
|
||||
List<UserCouponVO> userCouponVOS = userCouponList.stream().map(userCoupon -> {
|
||||
UserCouponVO userCouponVO = new UserCouponVO();
|
||||
|
@ -345,6 +307,45 @@ public class CouponController {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序端用户查看商城优惠券
|
||||
* @return 所有可兑换的优惠券列表
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
@Operation(summary = "小程序端用户查看商城优惠券", description = "参数:无,权限:所有人,方法名:listAllCoupon")
|
||||
public BaseResponse<List<CouponVO>> listAllCoupon(HttpServletRequest request) {
|
||||
userService.getLoginUser(request);
|
||||
QueryWrapper<Coupon> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("status", "可用");
|
||||
List<Coupon> coupons = couponService.list(queryWrapper);
|
||||
List<CouponVO> couponVOS = coupons.stream().map(coupon -> {
|
||||
CouponVO couponVO = new CouponVO();
|
||||
BeanUtils.copyProperties(coupon, couponVO);
|
||||
return couponVO;
|
||||
}).toList();
|
||||
return ResultUtils.success(couponVOS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序端用户根据id查看优惠券详情
|
||||
* @param commonRequest 优惠券id
|
||||
* @return 优惠券详情信息
|
||||
*/
|
||||
@PostMapping("/list/id")
|
||||
@Operation(summary = "小程序端用户根据id查看优惠券详情", description = "参数:优惠券id,权限:所有人,方法名:listCouponById")
|
||||
public BaseResponse<CouponVO> listCouponById(@RequestBody CommonRequest commonRequest, HttpServletRequest request) {
|
||||
userService.getLoginUser(request);
|
||||
if (commonRequest == null || commonRequest.getId() <= 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
Long id = commonRequest.getId();
|
||||
Coupon coupon = couponService.getById(id);
|
||||
ThrowUtils.throwIf(coupon == null, ErrorCode.OPERATION_ERROR, "优惠券不存在");
|
||||
CouponVO couponVO = new CouponVO();
|
||||
BeanUtils.copyProperties(coupon, couponVO);
|
||||
return ResultUtils.success(couponVO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -354,7 +355,7 @@ public class CouponController {
|
|||
* @return 是否更新成功
|
||||
*/
|
||||
@PostMapping("/shelves")
|
||||
@Operation(summary = "Web端管理员上(下)架优惠券", description = "参数:优惠券上架状态更新请求体,权限:管理员(admin, boss),方法名:deleteExchangeRecord")
|
||||
@Operation(summary = "Web端管理员上(下)架优惠券", description = "参数:优惠券id,权限:管理员(admin, boss),方法名:deleteExchangeRecord")
|
||||
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
|
||||
public BaseResponse<Boolean> updateCouponShelvesStatus(@RequestBody CommonRequest commonRequest) {
|
||||
if (commonRequest == null || commonRequest.getId() <= 0) {
|
||||
|
@ -376,31 +377,49 @@ public class CouponController {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* 小程序端用户查看(不)能够使用的优惠券
|
||||
* @param usableCouponQueryRequest 可用优惠券请求体
|
||||
* @return 优惠券详情信息
|
||||
*/
|
||||
@PostMapping("/list/use")
|
||||
@Operation(summary = "小程序端用户查看(不)能够使用的优惠券", description = "参数:可用优惠券请求体,权限:所有人,方法名:listUsableCoupon")
|
||||
public BaseResponse<List<UserCouponVO>> listUsableCoupon(@RequestBody UsableCouponQueryRequest usableCouponQueryRequest, HttpServletRequest request) {
|
||||
if (usableCouponQueryRequest == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
BigDecimal conditionAmount = usableCouponQueryRequest.getConditionAmount();
|
||||
if (conditionAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "订单金额参数错误");
|
||||
}
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
Long userId = loginUser.getId();
|
||||
QueryWrapper<UserCoupon> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("userId", userId);
|
||||
List<UserCoupon> userCouponList = userCouponService.list(queryWrapper);
|
||||
userCouponList = userCouponList.stream().filter(userCoupon -> userCoupon.getCouponVO().getStatus().equals("可用")).toList();
|
||||
|
||||
// 获取(不)可使用的优惠券
|
||||
List<UserCoupon> userCoupons = userCouponList.stream().filter(userCoupon -> {
|
||||
CouponVO couponVO = userCoupon.getCouponVO();
|
||||
BigDecimal couponAmount = couponVO.getConditionAmount();
|
||||
Boolean isAvailable = usableCouponQueryRequest.getIsAvailable();
|
||||
int result = conditionAmount.compareTo(couponAmount);
|
||||
return isAvailable == (result >= 0);
|
||||
}).toList();
|
||||
|
||||
List<UserCouponVO> userCouponVOS = userCoupons.stream().map(userCoupon -> {
|
||||
UserCouponVO userCouponVO = new UserCouponVO();
|
||||
BeanUtils.copyProperties(userCoupon, userCouponVO);
|
||||
return userCouponVO;
|
||||
}).toList();
|
||||
|
||||
return ResultUtils.success(userCouponVOS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * 小程序端用户查看兑换记录
|
||||
// * @param commonRequest 优惠券id
|
||||
// * @return 是否更新成功
|
||||
// */
|
||||
// @PostMapping("/get/record")
|
||||
// @Operation(summary = "Web端管理员上(下)架优惠券", description = "参数:优惠券上架状态更新请求体,权限:管理员(admin, boss),方法名:deleteExchangeRecord")
|
||||
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
|
||||
// public BaseResponse<Boolean> updateCouponShelvesStatus(@RequestBody CommonRequest commonRequest) {
|
||||
// if (commonRequest == null || commonRequest.getId() <= 0) {
|
||||
// throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
// }
|
||||
// Long id = commonRequest.getId();
|
||||
// Coupon coupon = couponService.getById(id);
|
||||
// ThrowUtils.throwIf(coupon == null, ErrorCode.OPERATION_ERROR, "优惠券不存在");
|
||||
//
|
||||
// Integer status = coupon.getIsShelves() == 0 ? 1 : 0;
|
||||
// UpdateWrapper<Coupon> updateWrapper = new UpdateWrapper<>();
|
||||
// updateWrapper.eq("id", id);
|
||||
// updateWrapper.set("isShelves", status);
|
||||
// boolean update = couponService.update(updateWrapper);
|
||||
// ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "上架状态更新失败");
|
||||
// return ResultUtils.success(true);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package com.cultural.heritage.listener;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.cultural.heritage.common.ErrorCode;
|
||||
import com.cultural.heritage.constant.MqConstant;
|
||||
import com.cultural.heritage.exception.ThrowUtils;
|
||||
import com.cultural.heritage.model.entity.Coupon;
|
||||
import com.cultural.heritage.service.good.CouponService;
|
||||
import com.cultural.heritage.utils.MultiDelayMessage;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CouponStatusListener {
|
||||
|
||||
|
||||
@Resource
|
||||
private CouponService couponService;
|
||||
|
||||
|
||||
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(MqConstant.DELAY_COUPON_QUEUE),
|
||||
exchange = @Exchange(name = MqConstant.DELAY_EXCHANGE, delayed = "true"),
|
||||
key = MqConstant.DELAY_COUPON_ROUTING_KEY
|
||||
))
|
||||
public void listenDelayMessage(MultiDelayMessage<Long> msg) {
|
||||
System.out.println("\n\n\n\n\nCouponStatusListener.listenerDelayMessage msg-------------------------------->:" + msg);
|
||||
|
||||
// 1.获取消息中的优惠券id
|
||||
Long couponId = msg.getData();
|
||||
// 2.判断优惠券是否存在
|
||||
Coupon coupon = couponService.getById(couponId);
|
||||
if (coupon == null) {
|
||||
return ;
|
||||
}
|
||||
// 3.更新优惠券状态
|
||||
UpdateWrapper<Coupon> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", couponId).set("status", "已过期");
|
||||
boolean update = couponService.update(updateWrapper);
|
||||
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "优惠券状态更新失败");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -61,7 +61,7 @@ public class OrderStatusListener {
|
|||
UpdateWrapper<Order> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", orderId).set("orderStatus", OrderStatusConstant.TRANSACTION_CLOSED);
|
||||
boolean update = orderService.update(updateWrapper);
|
||||
ThrowUtils.throwIf(!update, ErrorCode.SYSTEM_ERROR, "订单状态更新失败");
|
||||
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "订单状态更新失败");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package com.cultural.heritage.listener;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.cultural.heritage.common.ErrorCode;
|
||||
import com.cultural.heritage.constant.MqConstant;
|
||||
import com.cultural.heritage.exception.ThrowUtils;
|
||||
import com.cultural.heritage.model.entity.UserCoupon;
|
||||
import com.cultural.heritage.model.vo.coupon.CouponVO;
|
||||
import com.cultural.heritage.service.good.UserCouponService;
|
||||
import com.cultural.heritage.utils.MultiDelayMessage;
|
||||
import com.google.gson.Gson;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component
|
||||
public class UserCouponStatusListener {
|
||||
|
||||
@Resource
|
||||
private UserCouponService userCouponService;
|
||||
|
||||
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(MqConstant.DELAY_USER_COUPON_QUEUE),
|
||||
exchange = @Exchange(name = MqConstant.DELAY_EXCHANGE, delayed = "true"),
|
||||
key = MqConstant.DELAY_USER_COUPON_ROUTING_KEY
|
||||
))
|
||||
public void listenDelayMessage(MultiDelayMessage<Long> msg) {
|
||||
System.out.println("\n\n\n\n\nUserCouponStatusListener.listenerDelayMessage msg-------------------------------->:" + msg);
|
||||
|
||||
// 1.获取消用户优惠券id
|
||||
Long userCouponId = msg.getData();
|
||||
// 2.获取优惠券信息
|
||||
UserCoupon userCoupon = userCouponService.getById(userCouponId);
|
||||
CouponVO couponVO = userCoupon.getCouponVO();
|
||||
couponVO.setStatus("已过期");
|
||||
// 3.更新优惠券状态
|
||||
UpdateWrapper<UserCoupon> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("id", userCouponId).set("couponVO", new Gson().toJson(couponVO));
|
||||
boolean update = userCouponService.update(updateWrapper);
|
||||
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "用户优惠券状态更新失败");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package com.cultural.heritage.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cultural.heritage.model.entity.Exchange;
|
||||
|
||||
public interface ExchangeMapper extends BaseMapper<Exchange> {
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.cultural.heritage.model.dto.coupon;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@Schema(description = "可用优惠券请求体", requiredProperties =
|
||||
{"conditionAmount", "isAvailable"})
|
||||
public class UsableCouponQueryRequest implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
@Schema(description = "订单金额", example = "50")
|
||||
private BigDecimal conditionAmount;
|
||||
|
||||
|
||||
/**
|
||||
* 是否可用
|
||||
*/
|
||||
@Schema(description = "是否可用", example = "false")
|
||||
private Boolean isAvailable;
|
||||
|
||||
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
package com.cultural.heritage.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.cultural.heritage.model.vo.coupon.CouponVO;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 积分兑换记录
|
||||
* @TableName exchange_record
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "exchange_record", autoResultMap = true)
|
||||
public class Exchange implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 兑换记录id
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券信息
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private CouponVO couponVO;
|
||||
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Integer isDelete;
|
||||
|
||||
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -31,11 +31,6 @@ public class UserCoupon implements Serializable {
|
|||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Long couponId;
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券信息
|
||||
|
@ -44,29 +39,25 @@ public class UserCoupon implements Serializable {
|
|||
private CouponVO couponVO;
|
||||
|
||||
|
||||
/**
|
||||
* 购买数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private Integer isDelete;
|
||||
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,12 @@ import java.math.BigDecimal;
|
|||
public class CouponVO implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
|
|
|
@ -23,17 +23,6 @@ public class UserCouponVO implements Serializable {
|
|||
private CouponVO couponVO;
|
||||
|
||||
|
||||
/**
|
||||
* 拥有数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
|
||||
|
||||
@Serial
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package com.cultural.heritage.model.vo.exchange;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.cultural.heritage.model.vo.coupon.CouponVO;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class ExchangeVO implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 兑换记录id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
|
||||
/**
|
||||
* 优惠券信息
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private CouponVO couponVO;
|
||||
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package com.cultural.heritage.service.good;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.cultural.heritage.model.entity.Exchange;
|
||||
|
||||
public interface ExchangeService extends IService<Exchange> {
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.cultural.heritage.service.good.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.cultural.heritage.mapper.ExchangeMapper;
|
||||
import com.cultural.heritage.model.entity.Exchange;
|
||||
import com.cultural.heritage.service.good.ExchangeService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ExchangeServiceImpl extends ServiceImpl<ExchangeMapper, Exchange> implements ExchangeService{
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cultural.heritage.mapper.ExchangeMapper">
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user