更新了商品类别

This commit is contained in:
chen-xin-zhi 2025-02-02 14:59:14 +08:00
parent 1e00e5f6fd
commit ba104286ef
15 changed files with 275 additions and 352 deletions

View File

@ -1,13 +0,0 @@
package com.cultural.heritage.constant;
public interface CouponStatus {
String IS_NOT_ENABLED = "未启用";
String IS_ENABLED = "可使用";
String IS_OVERDUE = "已过期";
}

View File

@ -1,7 +1,6 @@
package com.cultural.heritage.controller.good;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@ -10,23 +9,23 @@ 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.CouponStatus;
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.coupon.CouponAddRequest;
import com.cultural.heritage.model.dto.coupon.CouponQueryRequest;
import com.cultural.heritage.model.dto.coupon.CouponShelvesUpdateRequest;
import com.cultural.heritage.model.dto.coupon.CouponUpdateRequest;
import com.cultural.heritage.model.dto.exchange.ExchangeAddRequest;
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.exchange.ExchangeVO;
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 io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -35,10 +34,10 @@ import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@ -59,6 +58,10 @@ public class CouponController {
private ExchangeService exchangeService;
@Resource
private UserCouponService userCouponService;
/**
* 添加优惠券
* @param couponAddRequest 优惠券添加请求体
@ -73,10 +76,22 @@ public class CouponController {
}
Coupon coupon = new Coupon();
BeanUtils.copyProperties(couponAddRequest, coupon);
// 填充优惠券有效开始日期
String startTime = DateUtil.format(DateUtil.date(), "yyyy-MM-dd 00:00:00");
coupon.setStartTime(startTime);
// 比较优惠券有效截止日期
String endTime = coupon.getEndTime();
String currentTime = DateUtil.now();
if (endTime.compareTo(currentTime) <= 0) {
coupon.setStatus("已过期");
} else {
coupon.setStatus("可用");
}
// 校验
couponService.validCoupon(coupon, false);
boolean result = couponService.save(coupon);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "优惠券添加失败");
return ResultUtils.success(true);
}
@ -94,12 +109,37 @@ public class CouponController {
if (couponUpdateRequest == null || couponUpdateRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Coupon coupon = new Coupon();
Long id = couponUpdateRequest.getId();
Coupon coupon = couponService.getById(id);
ThrowUtils.throwIf(coupon == null, ErrorCode.OPERATION_ERROR, "优惠券不存在");
BeanUtils.copyProperties(couponUpdateRequest, coupon);
// 比较优惠券有效截止日期
String endTime = coupon.getEndTime();
String currentTime = DateUtil.now();
if (endTime.compareTo(currentTime) <= 0) {
coupon.setStatus("已过期");
} else {
coupon.setStatus("可用");
}
// 校验
couponService.validCoupon(coupon, true);
boolean result = couponService.updateById(coupon);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
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);
}
@ -119,13 +159,34 @@ public class CouponController {
}
Long id = couponDeleteRequest.getId();
boolean result = couponService.removeById(id);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "优惠券删除失败");
return ResultUtils.success(true);
}
/**
* 查询优惠券列表
* 批量删除优惠券
* @param commonBatchRequest 优惠券删除请求体
* @return 是否删除成功
*/
@PostMapping("/del/Batch")
@Operation(summary = "Web端管理员批量删除优惠券", description = "参数:优惠券删除请求体,权限:管理员(admin, boss)方法名deleteCoupon")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> deleteCoupon(@RequestBody CommonBatchRequest commonBatchRequest) {
if (commonBatchRequest == null || CollectionUtils.isEmpty(commonBatchRequest.getIdList())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数为null或数组为空");
}
List<Long> idList = commonBatchRequest.getIdList();
boolean result = couponService.removeBatchByIds(idList);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "优惠券批量删除失败");
return ResultUtils.success(true);
}
/**
* Web端管理员分页查询优惠券
* @param couponQueryRequest 优惠券查询请求体
* @return 优惠券列表
*/
@ -136,14 +197,31 @@ public class CouponController {
if (couponQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// 对优惠券是否过期预处理
long current = couponQueryRequest.getCurrent();
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 兑换记录删除请求体
@ -158,75 +236,66 @@ public class CouponController {
userService.getLoginUser(request);
Long id = commonRequest.getId();
boolean result = exchangeService.removeById(id);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "兑换记录删除失败");
return ResultUtils.success(true, "删除兑换记录成功");
}
/**
* 小程序端用户积分兑换优惠券
* @param exchangeAddRequest 兑换记录添加请求体
* @param commonRequest 兑换记录添加请求体
* @return
*/
@PostMapping("/exchange")
@Operation(summary = "小程序端用户积分兑换优惠券", description = "参数兑换记录添加请求体权限所有人方法名pointsExchangeCoupon")
@Transactional(rollbackFor = Exception.class)
public BaseResponse<Boolean> pointsExchangeCoupon(@RequestBody ExchangeAddRequest exchangeAddRequest, HttpServletRequest request) {
public BaseResponse<Boolean> pointsExchangeCoupon(@RequestBody CommonRequest commonRequest, HttpServletRequest request) {
// 获取当前用户信息
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
Integer points = loginUser.getPoints();
// 获取当前优惠券信息
Long couponId = exchangeAddRequest.getCouponId();
Integer quantity = exchangeAddRequest.getQuantity();
Coupon coupon = couponService.getById(couponId);
Long id = commonRequest.getId();
Coupon coupon = couponService.getById(id);
ThrowUtils.throwIf(coupon == null, ErrorCode.OPERATION_ERROR, "优惠券不存在");
Integer limitNum = coupon.getLimitNum();
Integer residueNum = coupon.getResidueNum();
// 判断优惠券库存是否足够
if (quantity > residueNum) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "库存不足");
}
// 判断用户限领量是否已达标
QueryWrapper<Exchange> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userId", userId).eq("couponId", couponId);
List<Exchange> exchangeList = exchangeService.list(queryWrapper);
int sum = 0;
for (int i = 0; i < exchangeList.size(); i ++ ) {
Exchange exchange = exchangeList.get(i);
sum += exchange.getQuantity();
}
if (sum + quantity > limitNum) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "当前优惠券的限领量已达标");
}
// 判断用户积分是否充足
Integer requirePoints = coupon.getRequirePoints();
if (points < quantity * requirePoints) throw new BusinessException(ErrorCode.OPERATION_ERROR, "积分不足");
// 更新优惠券库存量
coupon.setResidueNum(coupon.getResidueNum() - quantity);
boolean result = couponService.updateById(coupon);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "更新优惠券库存失败");
if (points < requirePoints) throw new BusinessException(ErrorCode.OPERATION_ERROR, "积分不足");
// 插入一条兑换记录
CouponVO couponVO = new CouponVO();
BeanUtils.copyProperties(coupon, couponVO);
Exchange exchange = new Exchange();
exchange.setUserId(userId);
exchange.setQuantity(quantity);
exchange.setRestNum(quantity);
exchange.setRequirePoints(requirePoints);
exchange.setCouponId(couponId);
exchange.setCouponDetail(couponVO);
exchange.setCouponVO(couponVO);
boolean save = exchangeService.save(exchange);
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, "用户优惠券更新失败");
}
// 更新用户积分
loginUser.setPoints(loginUser.getPoints() - quantity * requirePoints);
loginUser.setPoints(loginUser.getPoints() - requirePoints);
boolean isSuccess = userService.updateById(loginUser);
ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR, "更新用户积分信息失败");
@ -243,33 +312,36 @@ public class CouponController {
*/
@GetMapping("/list/my")
@Operation(summary = "小程序端用户查看优惠券", description = "参数权限所有人方法名pointsExchangeCoupon")
public BaseResponse<List<ExchangeVO>> listMyCoupon(HttpServletRequest request) {
public BaseResponse<List<UserCouponVO>> listMyCoupon(HttpServletRequest request) {
User loginUser = userService.getLoginUser(request);
Long userId = loginUser.getId();
QueryWrapper<Exchange> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userId", userId);
List<Exchange> exchangeList = exchangeService.list(queryWrapper);
List<ExchangeVO> exchangeVOS = exchangeList.stream().map(exchange -> {
ExchangeVO exchangeVO = new ExchangeVO();
BeanUtils.copyProperties(exchange, exchangeVO);
String startTime = exchange.getCouponDetail().getStartTime();
String endTime = exchange.getCouponDetail().getEndTime();
DateTime start = DateUtil.parse(startTime);
DateTime end = DateUtil.parse(endTime);
DateTime current = DateUtil.date();
List<UserCoupon> userCouponList = userCouponService.list();
boolean isBefore = current.isBefore(start);
boolean isAfter = current.isAfter(end);
boolean isInRange = current.isAfterOrEquals(start) && current.isBeforeOrEquals(end);
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("可用");
}
}
if (isBefore) exchangeVO.setCouponStatus(CouponStatus.IS_NOT_ENABLED);
if (isAfter) exchangeVO.setCouponStatus(CouponStatus.IS_OVERDUE);
if (isInRange) exchangeVO.setCouponStatus(CouponStatus.IS_ENABLED);
return exchangeVO;
boolean update = userCouponService.updateBatchById(userCouponList);
ThrowUtils.throwIf(!CollectionUtils.isEmpty(userCouponList) && !update, ErrorCode.OPERATION_ERROR, "优惠券状态更新失败");
List<UserCouponVO> userCouponVOS = userCouponList.stream().map(userCoupon -> {
UserCouponVO userCouponVO = new UserCouponVO();
BeanUtils.copyProperties(userCoupon, userCouponVO);
return userCouponVO;
}).toList();
List<ExchangeVO> exchangeVOList = exchangeVOS.stream().filter(exchangeVO -> exchangeVO.getRestNum() != 0)
.collect(Collectors.toList());
return ResultUtils.success(exchangeVOList);
return ResultUtils.success(userCouponVOS);
}
@ -278,21 +350,24 @@ public class CouponController {
/**
* Web端管理员上()架优惠券
* @param couponShelvesUpdateRequest 优惠券上架状态更新请求体
* @param commonRequest 优惠券id
* @return 是否更新成功
*/
@PostMapping("/shelves")
@Operation(summary = "Web端管理员上(下)架优惠券", description = "参数:优惠券上架状态更新请求体,权限:管理员(admin, boss)方法名deleteExchangeRecord")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> updateCouponShelvesStatus(@RequestBody CouponShelvesUpdateRequest couponShelvesUpdateRequest) {
if (couponShelvesUpdateRequest == null || couponShelvesUpdateRequest.getId() <= 0) {
public BaseResponse<Boolean> updateCouponShelvesStatus(@RequestBody CommonRequest commonRequest) {
if (commonRequest == null || commonRequest.getId() <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = couponShelvesUpdateRequest.getId();
Integer isShelves = couponShelvesUpdateRequest.getIsShelves();
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", isShelves);
updateWrapper.set("isShelves", status);
boolean update = couponService.update(updateWrapper);
ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "上架状态更新失败");
return ResultUtils.success(true);

View File

@ -9,7 +9,7 @@ import java.math.BigDecimal;
@Data
@Schema(description = "优惠券添加请求体", requiredProperties =
{"name", "conditionAmount", "requirePoints", "totalNum", "residueNum", "limitNum", "useScope", "startTime", "endTime", "image", "description"})
{"name", "conditionAmount", "requirePoints", "content", "startTime", "endTime", "description"})
public class CouponAddRequest implements Serializable {
@ -32,45 +32,14 @@ public class CouponAddRequest implements Serializable {
@Schema(description = "兑换需要的积分", example = "1000")
private Integer requirePoints;
/**
* 优惠券简介
* 优惠券内容
*/
@Schema(description = "优惠券简介", example = "满200减50超值优惠")
private String intro;
private String content;
/**
* 发放数量
*/
@Schema(description = "发放数量", example = "10")
private Integer totalNum;
/**
* 剩余数量
*/
@Schema(description = "剩余数量", example = "5")
private Integer residueNum;
/**
* 用户限领量
*/
@Schema(description = "用户限领量", example = "3")
private Integer limitNum;
/**
* 作用范围
*/
@Schema(description = "作用范围(商品类别名)", example = "材料包;手持物;头饰")
private String useScope;
/**
* 有效开始日期
*/
@Schema(description = "有效开始日期", example = "2024-11-04 15:00:00")
private String startTime;
/**
* 有效截止日期
@ -79,13 +48,6 @@ public class CouponAddRequest implements Serializable {
private String endTime;
/**
* 优惠券图片
*/
@Schema(description = "优惠券图片地址", example = "https://xxx/xxx.jpg")
private String image;
/**
* 使用说明
*/

View File

@ -1,30 +0,0 @@
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;
@Data
@Schema(description = "优惠券上架状态更新请求体", requiredProperties = {"id", "isShelves"})
public class CouponShelvesUpdateRequest implements Serializable {
/**
* 订单id
*/
@Schema(description = "优惠券id(id > 0)", example = "8")
private Long id;
/**
* 优惠券上架状态
*/
@Schema(description = "优惠券上架状态", example = "1")
private Integer isShelves;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -9,7 +9,7 @@ import java.math.BigDecimal;
@Data
@Schema(description = "优惠券更新请求体", requiredProperties =
{"id", "name", "conditionAmount", "requirePoints", "totalNum", "residueNum", "limitNum", "useScope", "startTime", "endTime", "image", "description"})
{"id", "name", "conditionAmount", "requirePoints", "content", "startTime", "endTime", "description"})
public class CouponUpdateRequest implements Serializable {
/**
@ -38,52 +38,12 @@ public class CouponUpdateRequest implements Serializable {
private Integer requirePoints;
/**
* 发放数量
*/
@Schema(description = "发放数量", example = "10")
private Integer totalNum;
/**
* 剩余数量
*/
@Schema(description = "剩余数量", example = "5")
private Integer residueNum;
/**
* 用户限领量
*/
@Schema(description = "用户限领量", example = "3")
private Integer limitNum;
/**
* 有效开始日期
*/
@Schema(description = "有效开始日期", example = "2024-11-04 15:00:00")
private String startTime;
/**
* 有效截止日期
*/
@Schema(description = "有效截止日期", example = "2024-12-04 15:00:00")
private String endTime;
/**
* 优惠券图片
*/
@Schema(description = "优惠券图片地址", example = "https://xxx/xxx.jpg")
private String image;
/**
* 作用范围
*/
@Schema(description = "作用范围(商品类别名)", example = "材料包;手持物;头饰")
private String useScope;
/**
* 使用说明
@ -92,12 +52,6 @@ public class CouponUpdateRequest implements Serializable {
private String description;
/**
* 是否上架
*/
@Schema(description = "是否上架", example = "1")
private Integer isShelves;
@Serial
private static final long serialVersionUID = 1L;

View File

@ -1,33 +0,0 @@
package com.cultural.heritage.model.dto.exchange;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 积分兑换优惠券请求
*/
@Data
@Schema(description = "积分兑换优惠券请求体", requiredProperties = {"userId", "couponId", "quantity", "requirePoints"})
public class ExchangeAddRequest implements Serializable {
/**
* 优惠券id
*/
@Schema(description = "优惠券id(id > 0)", example = "4")
private Long couponId;
/**
* 数量
*/
@Schema(description = "购买数量", example = "10")
private Integer quantity;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -27,11 +27,19 @@ public class Coupon implements Serializable {
@TableId(type = IdType.AUTO)
private Long id;
/**
* 优惠券名称
*/
private String name;
/**
* 优惠内容
*/
private String content;
/**
* 满减金额
*/
@ -44,33 +52,6 @@ public class Coupon implements Serializable {
private Integer requirePoints;
/**
* 发放数量
*/
private Integer totalNum;
/**
* 剩余数量
*/
private Integer residueNum;
/**
* 用户限领量
*/
private Integer limitNum;
/**
* 优惠券简介
*/
private String intro;
/**
* 优惠券图片
*/
private String image;
/**
* 有效开始日期
*/
@ -82,10 +63,6 @@ public class Coupon implements Serializable {
*/
private String endTime;
/**
* 作用范围
*/
private String useScope;
/**
* 使用说明
@ -113,6 +90,12 @@ public class Coupon implements Serializable {
private Date updateTime;
/**
* 优惠券状态
*/
private String status;
/**
* 是否删除
*/

View File

@ -34,34 +34,12 @@ public class Exchange implements Serializable {
private Long userId;
/**
* 优惠券id
*/
private Long couponId;
/**
* 优惠券信息
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private CouponVO couponDetail;
private CouponVO couponVO;
/**
* 数量
*/
private Integer quantity;
/**
* 剩余数量
*/
private Integer restNum;
/**
* 优惠券积分价格
*/
private Integer requirePoints;
/**
* 创建时间

View File

@ -1,8 +1,11 @@
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 lombok.Data;
import java.io.Serial;
@ -14,7 +17,7 @@ import java.util.Date;
* @TableName user_coupon
*/
@Data
@TableName("user_coupon")
@TableName(value = "user_coupon", autoResultMap = true)
public class UserCoupon implements Serializable {
/**
@ -33,10 +36,24 @@ public class UserCoupon implements Serializable {
*/
private Long couponId;
/**
* 优惠券状态(0, 1, 2分别代表未使用已使用已过期)
* 优惠券信息
*/
private Integer status;
@TableField(typeHandler = JacksonTypeHandler.class)
private CouponVO couponVO;
/**
* 购买数量
*/
private Integer quantity;
/**
* 优惠券状态
*/
private String status;
/**

View File

@ -15,6 +15,13 @@ public class CouponVO implements Serializable {
*/
private String name;
/**
* 优惠内容
*/
private String content;
/**
* 满减金额
*/
@ -22,14 +29,10 @@ public class CouponVO implements Serializable {
/**
* 优惠券简介
* 需要的积分
*/
private String intro;
private Integer requirePoints;
/**
* 优惠券图片
*/
private String image;
/**
* 有效开始日期
@ -42,10 +45,6 @@ public class CouponVO implements Serializable {
*/
private String endTime;
/**
* 作用范围
*/
private String useScope;
/**
* 使用说明
@ -53,6 +52,12 @@ public class CouponVO implements Serializable {
private String description;
/**
* 优惠券状态
*/
private String status;
@Serial
private static final long serialVersionUID = 1L;

View File

@ -0,0 +1,41 @@
package com.cultural.heritage.model.vo.coupon;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class UserCouponVO implements Serializable {
/**
* id
*/
private Long id;
/**
* 优惠券信息
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private CouponVO couponVO;
/**
* 拥有数量
*/
private Integer quantity;
/**
* 优惠券状态
*/
private String status;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -20,40 +20,11 @@ public class ExchangeVO implements Serializable {
private Long id;
/**
* 优惠券id
*/
private Long couponId;
/**
* 优惠券信息
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private CouponVO couponDetail;
/**
* 数量
*/
private Integer quantity;
/**
* 剩余数量
*/
private Integer restNum;
/**
* 优惠券积分价格
*/
private Integer requirePoints;
/**
* 优惠券状态(未开始可使用已过期)
*/
private String couponStatus;
private CouponVO couponVO;
/**

View File

@ -42,6 +42,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
return queryWrapper;
}
@Override
public Integer verifyIsReachTheUpperLimit(Long userId, Long couponId) {
return this.baseMapper.verifyIsReachTheUpperLimit(userId, couponId);
@ -57,15 +58,12 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
String name = coupon.getName();
BigDecimal conditionAmount = coupon.getConditionAmount();
Integer requirePoints = coupon.getRequirePoints();
Integer totalNum = coupon.getTotalNum();
Integer residueNum = coupon.getResidueNum();
Integer limitNum = coupon.getLimitNum();
String useScope = coupon.getUseScope();
String startTime = coupon.getStartTime();
String endTime = coupon.getEndTime();
String intro = coupon.getIntro();
String image = coupon.getImage();
String description = coupon.getDescription();
String content = coupon.getContent();
String status = coupon.getStatus();
if (update) {
if (id == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数id错误");
@ -77,14 +75,11 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
if (ObjectUtils.isEmpty(requirePoints) || requirePoints <= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "积分参数错误");
}
if (ObjectUtils.isEmpty(totalNum) || ObjectUtils.isEmpty(residueNum) || ObjectUtils.isEmpty(limitNum)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "优惠券数量参数为null");
}
if (totalNum <= 0 || residueNum < 0 || residueNum > totalNum || limitNum <= 0 || limitNum > totalNum) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "优惠券数量参数错误");
}
if (StringUtils.isAnyBlank(name, useScope, startTime, endTime, intro, image, description)) {
if (StringUtils.isAnyBlank(name, startTime, endTime, description, content, status)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "存在参数为空");
}
if (startTime.compareTo(endTime) >= 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "有效期开始时间晚于有效期截止时间");
}
}
}

View File

@ -3,7 +3,7 @@ spring:
# 生产环境
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://154.8.193.216:3306/feiyi?serverTimezone=Asia/Shanghai
username: feiyi0
username: feiyi
password: 123456asd
hikari:
maximum-pool-size: 20

View File

@ -0,0 +1,18 @@
package com.cultural.heritage.test;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date date1 = new Date();
Date date2 = new Date(date1.getTime() + 1000); // date2 date1 1
if (date1.before(date2)) {
System.out.println("date1 早于 date2");
}
if (date1.after(date2)) {
System.out.println("date1 晚于 date2");
}
}
}