v3.0.0 springboot3+jdk17版本
This commit is contained in:
1 parent
3aa2c942dc
commit
b3ee447f8e
3676 files changed
+64366
-370384
No files matched your search
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yshop</artifactId>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>yshop-module-marketing</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
||||
营销模块 优惠券 会员卡 分销 拼团
|
||||
</description>
|
||||
|
||||
<modules>
|
||||
<module>yshop-module-coupon-api</module>
|
||||
<module>yshop-module-coupon-biz</module>
|
||||
</modules>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-module-marketing</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>yshop-module-coupon-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
||||
coupon模块 API,暴露给其它模块调用
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 参数校验 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2022
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
|
||||
*/
|
||||
package co.yixiang.yshop.module.coupon.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* 优惠券相关枚举
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum CouponStatusEnum {
|
||||
|
||||
STATUS_0(0,"未使用"),
|
||||
STATUS_1(1,"已使用"),
|
||||
STATUS_2(2,"已失效");
|
||||
|
||||
|
||||
|
||||
private Integer value;
|
||||
private String desc;
|
||||
|
||||
public static CouponStatusEnum toType(int value) {
|
||||
return Stream.of(CouponStatusEnum.values())
|
||||
.filter(p -> p.value == value)
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package co.yixiang.yshop.module.coupon.enums;
|
||||
import co.yixiang.yshop.framework.common.exception.ErrorCode;
|
||||
|
||||
public interface ErrorCodeConstants {
|
||||
ErrorCode COUPON_NOT_EXISTS = new ErrorCode(1008018000, "优惠券不存在");
|
||||
ErrorCode COUPON_USER_NOT_EXISTS = new ErrorCode(1008018001, "用户领的优惠券不存在");
|
||||
ErrorCode COUPON_RECEIVED = new ErrorCode(1008018001, "优惠券已经领取过");
|
||||
ErrorCode COUPON_RECEIVE_ZERO = new ErrorCode(1008018001, "优惠券已经被领完");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-module-marketing</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>yshop-module-coupon-biz</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
||||
优惠券 模块,主要实现商品购物车相关功能
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-module-coupon-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-module-store-biz</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Job 定时任务相关 -->
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-job</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 业务组件 -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>co.yixiang.boot</groupId>-->
|
||||
<!-- <artifactId>yshop-spring-boot-starter-biz-operatelog</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- Web 相关 -->
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- DB 相关 -->
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-mybatis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Test 测试相关 -->
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 工具类相关 -->
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-excel</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.coupon;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.framework.common.pojo.CommonResult;
|
||||
import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import co.yixiang.yshop.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.*;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.coupon.CouponDO;
|
||||
import co.yixiang.yshop.module.coupon.convert.coupon.CouponConvert;
|
||||
import co.yixiang.yshop.module.coupon.service.coupon.CouponService;
|
||||
|
||||
@Tag(name = "管理后台 - 优惠券")
|
||||
@RestController
|
||||
@RequestMapping("/coupon/")
|
||||
@Validated
|
||||
public class CouponController {
|
||||
|
||||
@Resource
|
||||
private CouponService Service;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建优惠券")
|
||||
@PreAuthorize("@ss.hasPermission('coupon::create')")
|
||||
public CommonResult<Long> create(@Valid @RequestBody CouponCreateReqVO createReqVO) {
|
||||
return success(Service.create(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新优惠券")
|
||||
@PreAuthorize("@ss.hasPermission('coupon::update')")
|
||||
public CommonResult<Boolean> update(@Valid @RequestBody CouponUpdateReqVO updateReqVO) {
|
||||
Service.update(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除优惠券")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('coupon::delete')")
|
||||
public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
|
||||
Service.delete(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得优惠券")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('coupon::query')")
|
||||
public CommonResult<CouponRespVO> get(@RequestParam("id") Long id) {
|
||||
CouponDO couponDO = Service.get(id);
|
||||
return success(CouponConvert.INSTANCE.convert(couponDO));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得优惠券列表")
|
||||
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
|
||||
@PreAuthorize("@ss.hasPermission('coupon::query')")
|
||||
public CommonResult<List<CouponRespVO>> getList() {
|
||||
List<CouponDO> list = Service.getList();
|
||||
return success(CouponConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得优惠券分页")
|
||||
@PreAuthorize("@ss.hasPermission('coupon::query')")
|
||||
public CommonResult<PageResult<CouponRespVO>> getPage(@Valid CouponPageReqVO pageVO) {
|
||||
PageResult<CouponDO> pageResult = Service.getPage(pageVO);
|
||||
return success(CouponConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出优惠券 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('coupon::export')")
|
||||
public void exportExcel(@Valid CouponExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<CouponDO> list = Service.getList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<CouponExcelVO> datas = CouponConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "优惠券.xls", "数据", CouponExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.coupon.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import jakarta.validation.constraints.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
/**
|
||||
* 优惠券 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class CouponBaseVO {
|
||||
|
||||
@Schema(description = "店铺id,0表示通用", required = true, example = "8915")
|
||||
private String shopId;
|
||||
|
||||
private String shopName;
|
||||
|
||||
@Schema(description = "优惠券名称", required = true)
|
||||
@NotNull(message = "优惠券名称不能为空")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "是否上架", required = true)
|
||||
@NotNull(message = "是否上架不能为空")
|
||||
private Integer isSwitch;
|
||||
|
||||
@Schema(description = "消费多少可用", required = true)
|
||||
@NotNull(message = "消费多少可用不能为空")
|
||||
private BigDecimal least;
|
||||
|
||||
@Schema(description = "优惠券金额", required = true)
|
||||
@NotNull(message = "优惠券金额不能为空")
|
||||
private BigDecimal value;
|
||||
|
||||
@Schema(description = "开始时间", required = true)
|
||||
@NotNull(message = "开始时间不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Schema(description = "结束时间", required = true)
|
||||
@NotNull(message = "结束时间不能为空")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Schema(description = "权重", required = true)
|
||||
private Integer weigh;
|
||||
|
||||
@Schema(description = "可用类型:0=通用,1=自取,2=外卖", required = true, example = "2")
|
||||
@NotNull(message = "可用类型不能为空")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "兑换码")
|
||||
private String exchangeCode;
|
||||
|
||||
@Schema(description = "已领取", required = true)
|
||||
private Integer receive;
|
||||
|
||||
@Schema(description = "发行数量", required = true)
|
||||
@NotNull(message = "发行数量不能为空")
|
||||
private Integer distribute;
|
||||
|
||||
@Schema(description = "所需积分", required = true)
|
||||
private Integer score;
|
||||
|
||||
@Schema(description = "使用说明", required = true)
|
||||
private String instructions;
|
||||
|
||||
@Schema(description = "图片", required = true)
|
||||
private String image;
|
||||
|
||||
@Schema(description = "限领数量")
|
||||
@NotNull(message = "限领数量不能为空")
|
||||
private Integer limit;
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.coupon.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 优惠券创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CouponCreateReqVO extends CouponBaseVO {
|
||||
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.coupon.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
|
||||
/**
|
||||
* 优惠券 Excel VO
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Data
|
||||
public class CouponExcelVO {
|
||||
|
||||
@ExcelProperty("id")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("店铺id,0表示通用")
|
||||
private String shopId;
|
||||
|
||||
@ExcelProperty("店铺名称逗号隔开")
|
||||
private String shopName;
|
||||
|
||||
@ExcelProperty("优惠券名称")
|
||||
private String title;
|
||||
|
||||
@ExcelProperty("是否上架")
|
||||
private Integer isSwitch;
|
||||
|
||||
@ExcelProperty("消费多少可用")
|
||||
private BigDecimal least;
|
||||
|
||||
@ExcelProperty("优惠券金额")
|
||||
private BigDecimal value;
|
||||
|
||||
@ExcelProperty("开始时间")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@ExcelProperty("结束时间")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@ExcelProperty("权重")
|
||||
private Integer weigh;
|
||||
|
||||
@ExcelProperty("可用类型:0=通用,1=自取,2=外卖")
|
||||
private Integer type;
|
||||
|
||||
@ExcelProperty("兑换码")
|
||||
private String exchangeCode;
|
||||
|
||||
@ExcelProperty("已领取")
|
||||
private Integer receive;
|
||||
|
||||
@ExcelProperty("发行数量")
|
||||
private Integer distribute;
|
||||
|
||||
@ExcelProperty("所需积分")
|
||||
private Integer score;
|
||||
|
||||
@ExcelProperty("使用说明")
|
||||
private String instructions;
|
||||
|
||||
@ExcelProperty("图片")
|
||||
private String image;
|
||||
|
||||
@ExcelProperty("限领数量")
|
||||
private Integer limit;
|
||||
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.coupon.vo;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageParam;
|
||||
import java.time.LocalDateTime;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 优惠券 Excel 导出 Request VO,参数和 CouponPageReqVO 是一致的")
|
||||
@Data
|
||||
public class CouponExportReqVO {
|
||||
|
||||
@Schema(description = "店铺id,0表示通用", example = "8915")
|
||||
private String shopId;
|
||||
|
||||
@Schema(description = "店铺名称逗号隔开", example = "王五")
|
||||
private String shopName;
|
||||
|
||||
@Schema(description = "优惠券名称")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "是否上架")
|
||||
private Integer isSwitch;
|
||||
|
||||
@Schema(description = "消费多少可用")
|
||||
private BigDecimal least;
|
||||
|
||||
@Schema(description = "优惠券金额")
|
||||
private BigDecimal value;
|
||||
|
||||
@Schema(description = "开始时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] startTime;
|
||||
|
||||
@Schema(description = "结束时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] endTime;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
@Schema(description = "权重")
|
||||
private Integer weigh;
|
||||
|
||||
@Schema(description = "可用类型:0=通用,1=自取,2=外卖", example = "2")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "兑换码")
|
||||
private String exchangeCode;
|
||||
|
||||
@Schema(description = "已领取")
|
||||
private Integer receive;
|
||||
|
||||
@Schema(description = "发行数量")
|
||||
private Integer distribute;
|
||||
|
||||
@Schema(description = "所需积分")
|
||||
private Integer score;
|
||||
|
||||
@Schema(description = "使用说明")
|
||||
private String instructions;
|
||||
|
||||
@Schema(description = "图片")
|
||||
private String image;
|
||||
|
||||
@Schema(description = "限领数量")
|
||||
private Integer limit;
|
||||
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.coupon.vo;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 优惠券分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CouponPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "店铺id,0表示通用", example = "8915")
|
||||
private String shopId;
|
||||
|
||||
@Schema(description = "店铺名称逗号隔开", example = "王五")
|
||||
private String shopName;
|
||||
|
||||
@Schema(description = "优惠券名称")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "是否上架")
|
||||
private Integer isSwitch;
|
||||
|
||||
@Schema(description = "消费多少可用")
|
||||
private BigDecimal least;
|
||||
|
||||
@Schema(description = "优惠券金额")
|
||||
private BigDecimal value;
|
||||
|
||||
@Schema(description = "开始时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] startTime;
|
||||
|
||||
@Schema(description = "结束时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] endTime;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
@Schema(description = "权重")
|
||||
private Integer weigh;
|
||||
|
||||
@Schema(description = "可用类型:0=通用,1=自取,2=外卖", example = "2")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "兑换码")
|
||||
private String exchangeCode;
|
||||
|
||||
@Schema(description = "已领取")
|
||||
private Integer receive;
|
||||
|
||||
@Schema(description = "发行数量")
|
||||
private Integer distribute;
|
||||
|
||||
@Schema(description = "所需积分")
|
||||
private Integer score;
|
||||
|
||||
@Schema(description = "使用说明")
|
||||
private String instructions;
|
||||
|
||||
@Schema(description = "图片")
|
||||
private String image;
|
||||
|
||||
@Schema(description = "限领数量")
|
||||
private Integer limit;
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.coupon.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 优惠券 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CouponRespVO extends CouponBaseVO {
|
||||
|
||||
@Schema(description = "id", required = true, example = "1582")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "创建时间", required = true)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.coupon.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 优惠券更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CouponUpdateReqVO extends CouponBaseVO {
|
||||
|
||||
@Schema(description = "id", required = true, example = "1582")
|
||||
@NotNull(message = "id不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.couponuser;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.framework.common.pojo.CommonResult;
|
||||
import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import co.yixiang.yshop.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo.*;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.couponuser.CouponUserDO;
|
||||
import co.yixiang.yshop.module.coupon.convert.couponuser.CouponUserConvert;
|
||||
import co.yixiang.yshop.module.coupon.service.couponuser.CouponUserService;
|
||||
|
||||
@Tag(name = "管理后台 - 用户领的优惠券")
|
||||
@RestController
|
||||
@RequestMapping("/coupon/user")
|
||||
@Validated
|
||||
public class CouponUserController {
|
||||
|
||||
@Resource
|
||||
private CouponUserService userService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建用户领的优惠券")
|
||||
@PreAuthorize("@ss.hasPermission('coupon:user:create')")
|
||||
public CommonResult<Integer> createUser(@Valid @RequestBody CouponUserCreateReqVO createReqVO) {
|
||||
return success(userService.createUser(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新用户领的优惠券")
|
||||
@PreAuthorize("@ss.hasPermission('coupon:user:update')")
|
||||
public CommonResult<Boolean> updateUser(@Valid @RequestBody CouponUserUpdateReqVO updateReqVO) {
|
||||
userService.updateUser(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除用户领的优惠券")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('coupon:user:delete')")
|
||||
public CommonResult<Boolean> deleteUser(@RequestParam("id") Integer id) {
|
||||
userService.deleteUser(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得用户领的优惠券")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('coupon:user:query')")
|
||||
public CommonResult<CouponUserRespVO> getUser(@RequestParam("id") Integer id) {
|
||||
CouponUserDO user = userService.getUser(id);
|
||||
return success(CouponUserConvert.INSTANCE.convert(user));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得用户领的优惠券列表")
|
||||
@Parameter(name = "id", description = "编号列表", required = true, example = "1024")
|
||||
// @PreAuthorize("@ss.hasPermission('coupon:user:query')")
|
||||
public CommonResult<List<CouponUserRespVO>> getUserList(@RequestParam("couponId") Integer couponId) {
|
||||
List<CouponUserDO> list = userService.getUserList(couponId);
|
||||
return success(CouponUserConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得用户领的优惠券分页")
|
||||
//@PreAuthorize("@ss.hasPermission('coupon:user:query')")
|
||||
public CommonResult<PageResult<CouponUserRespVO>> getUserPage(@Valid CouponUserPageReqVO pageVO) {
|
||||
PageResult<CouponUserDO> pageResult = userService.getUserPage(pageVO);
|
||||
return success(CouponUserConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出用户领的优惠券 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('coupon:user:export')")
|
||||
public void exportUserExcel(@Valid CouponUserExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<CouponUserDO> list = userService.getUserList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<CouponUserExcelVO> datas = CouponUserConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "用户领的优惠券.xls", "数据", CouponUserExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* 用户领的优惠券 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class CouponUserBaseVO {
|
||||
|
||||
@Schema(description = "店铺id,0表示通用", required = true, example = "32582")
|
||||
@NotNull(message = "店铺id,0表示通用不能为空")
|
||||
private String shopId;
|
||||
|
||||
@Schema(description = "店铺名称逗号隔开", example = "yshop")
|
||||
private String shopName;
|
||||
|
||||
@Schema(description = "优惠券名称", required = true)
|
||||
@NotNull(message = "优惠券名称不能为空")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "消费多少可用", required = true)
|
||||
@NotNull(message = "消费多少可用不能为空")
|
||||
private BigDecimal least;
|
||||
|
||||
@Schema(description = "优惠券金额", required = true)
|
||||
@NotNull(message = "优惠券金额不能为空")
|
||||
private BigDecimal value;
|
||||
|
||||
@Schema(description = "开始时间", required = true)
|
||||
@NotNull(message = "开始时间不能为空")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Schema(description = "结束时间", required = true)
|
||||
@NotNull(message = "结束时间不能为空")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Schema(description = "创建时间", required = true)
|
||||
@NotNull(message = "创建时间不能为空")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "更新时间", required = true)
|
||||
@NotNull(message = "更新时间不能为空")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@Schema(description = "可用类型:0=通用,1=自取,2=外卖", required = true, example = "2")
|
||||
@NotNull(message = "可用类型:0=通用,1=自取,2=外卖不能为空")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "消耗积分", required = true)
|
||||
@NotNull(message = "消耗积分不能为空")
|
||||
private Integer score;
|
||||
|
||||
@Schema(description = "使用说明", required = true)
|
||||
@NotNull(message = "使用说明不能为空")
|
||||
private String instructions;
|
||||
|
||||
@Schema(description = "图片", required = true)
|
||||
@NotNull(message = "图片不能为空")
|
||||
private String image;
|
||||
|
||||
@Schema(description = "用户id", required = true, example = "20961")
|
||||
@NotNull(message = "用户id不能为空")
|
||||
private Integer userId;
|
||||
|
||||
@Schema(description = "已使用:0=否,1=是", required = true, example = "1")
|
||||
@NotNull(message = "已使用:0=否,1=是不能为空")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "优惠券id", required = true, example = "23870")
|
||||
@NotNull(message = "优惠券id不能为空")
|
||||
private Integer couponId;
|
||||
|
||||
@Schema(description = "兑换码")
|
||||
private String exchangeCode;
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 用户领的优惠券创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CouponUserCreateReqVO extends CouponUserBaseVO {
|
||||
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
|
||||
/**
|
||||
* 用户领的优惠券 Excel VO
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Data
|
||||
public class CouponUserExcelVO {
|
||||
|
||||
@ExcelProperty("id")
|
||||
private Integer id;
|
||||
|
||||
@ExcelProperty("店铺id,0表示通用")
|
||||
private String shopId;
|
||||
|
||||
@ExcelProperty("店铺名称逗号隔开")
|
||||
private String shopName;
|
||||
|
||||
@ExcelProperty("优惠券名称")
|
||||
private String title;
|
||||
|
||||
@ExcelProperty("消费多少可用")
|
||||
private BigDecimal least;
|
||||
|
||||
@ExcelProperty("优惠券金额")
|
||||
private BigDecimal value;
|
||||
|
||||
@ExcelProperty("开始时间")
|
||||
private Integer starttime;
|
||||
|
||||
@ExcelProperty("结束时间")
|
||||
private Integer endtime;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private Integer createtime;
|
||||
|
||||
@ExcelProperty("更新时间")
|
||||
private Integer updatetime;
|
||||
|
||||
@ExcelProperty("可用类型:0=通用,1=自取,2=外卖")
|
||||
private Integer type;
|
||||
|
||||
@ExcelProperty("消耗积分")
|
||||
private Integer score;
|
||||
|
||||
@ExcelProperty("使用说明")
|
||||
private String instructions;
|
||||
|
||||
@ExcelProperty("图片")
|
||||
private String image;
|
||||
|
||||
@ExcelProperty("用户id")
|
||||
private Integer userId;
|
||||
|
||||
@ExcelProperty("已使用:0=否,1=是")
|
||||
private Integer status;
|
||||
|
||||
@ExcelProperty("优惠券id")
|
||||
private Integer couponId;
|
||||
|
||||
@ExcelProperty("兑换码")
|
||||
private String exchangeCode;
|
||||
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 用户领的优惠券 Excel 导出 Request VO,参数和 CouponUserPageReqVO 是一致的")
|
||||
@Data
|
||||
public class CouponUserExportReqVO {
|
||||
|
||||
@Schema(description = "店铺id,0表示通用", example = "32582")
|
||||
private String shopId;
|
||||
|
||||
@Schema(description = "店铺名称逗号隔开", example = "yshop")
|
||||
private String shopName;
|
||||
|
||||
@Schema(description = "优惠券名称")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "消费多少可用")
|
||||
private BigDecimal least;
|
||||
|
||||
@Schema(description = "优惠券金额")
|
||||
private BigDecimal value;
|
||||
|
||||
@Schema(description = "开始时间", required = true)
|
||||
@NotNull(message = "开始时间不能为空")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Schema(description = "结束时间", required = true)
|
||||
@NotNull(message = "结束时间不能为空")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Schema(description = "创建时间", required = true)
|
||||
@NotNull(message = "创建时间不能为空")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "更新时间", required = true)
|
||||
@NotNull(message = "更新时间不能为空")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@Schema(description = "可用类型:0=通用,1=自取,2=外卖", example = "2")
|
||||
private Boolean type;
|
||||
|
||||
@Schema(description = "消耗积分")
|
||||
private Integer score;
|
||||
|
||||
@Schema(description = "使用说明")
|
||||
private String instructions;
|
||||
|
||||
@Schema(description = "图片")
|
||||
private String image;
|
||||
|
||||
@Schema(description = "用户id", example = "20961")
|
||||
private Integer userId;
|
||||
|
||||
@Schema(description = "已使用:0=否,1=是", example = "1")
|
||||
private Boolean status;
|
||||
|
||||
@Schema(description = "优惠券id", example = "23870")
|
||||
private Integer couponId;
|
||||
|
||||
@Schema(description = "兑换码")
|
||||
private String exchangeCode;
|
||||
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 用户领的优惠券分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CouponUserPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "店铺id,0表示通用", example = "32582")
|
||||
private String shopId;
|
||||
|
||||
@Schema(description = "店铺名称逗号隔开", example = "yshop")
|
||||
private String shopName;
|
||||
|
||||
@Schema(description = "优惠券名称")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "消费多少可用")
|
||||
private BigDecimal least;
|
||||
|
||||
@Schema(description = "优惠券金额")
|
||||
private BigDecimal value;
|
||||
|
||||
@Schema(description = "开始时间", required = true)
|
||||
@NotNull(message = "开始时间不能为空")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Schema(description = "结束时间", required = true)
|
||||
@NotNull(message = "结束时间不能为空")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Schema(description = "创建时间", required = true)
|
||||
@NotNull(message = "创建时间不能为空")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "更新时间", required = true)
|
||||
@NotNull(message = "更新时间不能为空")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@Schema(description = "可用类型:0=通用,1=自取,2=外卖", example = "2")
|
||||
private Boolean type;
|
||||
|
||||
@Schema(description = "消耗积分")
|
||||
private Integer score;
|
||||
|
||||
@Schema(description = "使用说明")
|
||||
private String instructions;
|
||||
|
||||
@Schema(description = "图片")
|
||||
private String image;
|
||||
|
||||
@Schema(description = "用户id", example = "20961")
|
||||
private Integer userId;
|
||||
|
||||
@Schema(description = "已使用:0=否,1=是", example = "1")
|
||||
private Boolean status;
|
||||
|
||||
@Schema(description = "优惠券id", example = "23870")
|
||||
private Integer couponId;
|
||||
|
||||
@Schema(description = "兑换码")
|
||||
private String exchangeCode;
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
@Schema(description = "管理后台 - 用户领的优惠券 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CouponUserRespVO extends CouponUserBaseVO {
|
||||
|
||||
@Schema(description = "id", required = true, example = "5159")
|
||||
private Integer id;
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 用户领的优惠券更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CouponUserUpdateReqVO extends CouponUserBaseVO {
|
||||
|
||||
@Schema(description = "id", required = true, example = "5159")
|
||||
@NotNull(message = "id不能为空")
|
||||
private Integer id;
|
||||
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2022
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.yshop.module.coupon.controller.app.coupon;
|
||||
|
||||
import co.yixiang.yshop.framework.common.enums.ShopCommonEnum;
|
||||
import co.yixiang.yshop.framework.common.pojo.CommonResult;
|
||||
import co.yixiang.yshop.framework.security.core.annotations.PreAuthenticated;
|
||||
import co.yixiang.yshop.module.coupon.controller.app.coupon.vo.AppCouponVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.app.coupon.vo.AppMyCouponVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.app.coupon.vo.AppReceVO;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.couponuser.CouponUserDO;
|
||||
import co.yixiang.yshop.module.coupon.service.coupon.AppCouponService;
|
||||
import co.yixiang.yshop.module.coupon.service.couponuser.AppCouponUserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
|
||||
import static co.yixiang.yshop.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 优惠券控制器
|
||||
* </p>
|
||||
*
|
||||
* @author hupeng
|
||||
* @since 2023-8-20
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "用户 APP - 优惠券")
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
@RequestMapping("/coupon")
|
||||
public class AppCouponController {
|
||||
|
||||
private final AppCouponUserService appCouponUserService;
|
||||
private final AppCouponService appCouponService;
|
||||
|
||||
|
||||
@PreAuthenticated
|
||||
@GetMapping("/count")
|
||||
@Operation(summary = "获取可用优惠券数量")
|
||||
public CommonResult<Long> getCount(@RequestParam("shop_id") Integer shopId,
|
||||
@RequestParam("type") Integer type) {
|
||||
Long uid = getLoginUserId();
|
||||
LocalDateTime nowTime = LocalDateTime.now();
|
||||
Long count = appCouponUserService.count(new LambdaQueryWrapper<CouponUserDO>()
|
||||
.eq(CouponUserDO::getUserId,uid)
|
||||
.eq(CouponUserDO::getShopId,shopId)
|
||||
.lt(CouponUserDO::getStartTime,nowTime)
|
||||
.gt(CouponUserDO::getEndTime,nowTime)
|
||||
.and(i->i.eq(CouponUserDO::getType,type).or().eq(CouponUserDO::getType,0))
|
||||
.eq(CouponUserDO::getStatus, ShopCommonEnum.IS_STATUS_0));
|
||||
|
||||
return success(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取我的优惠券
|
||||
*/
|
||||
@PreAuthenticated
|
||||
@GetMapping("/my")
|
||||
@Parameters({
|
||||
@Parameter(name = "shopId", description = "店铺ID",
|
||||
example = "1"),
|
||||
@Parameter(name = "type", description = "0-未使用 1-已使用 2-已过期",
|
||||
example = "1"),
|
||||
@Parameter(name = "page", description = "页码,默认为1",
|
||||
required = true, example = "1"),
|
||||
@Parameter(name = "pagesize", description = "页大小,默认为10",
|
||||
required = true, example = "10 ")
|
||||
})
|
||||
@Operation(summary = "获取我的优惠券")
|
||||
public CommonResult<List<AppMyCouponVO>> myList(@RequestParam(value = "shopId",required = false) Long shopId,
|
||||
@RequestParam(value = "type",defaultValue = "0") int type,
|
||||
@RequestParam(value = "page",defaultValue = "1") int page,
|
||||
@RequestParam(value = "pagesize",defaultValue = "10") int pagesize){
|
||||
Long uid = getLoginUserId();
|
||||
return success(appCouponUserService.getList(uid,shopId,type,page,pagesize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未被领取优惠券
|
||||
*/
|
||||
@PreAuthenticated
|
||||
@GetMapping("/not")
|
||||
@Parameters({
|
||||
@Parameter(name = "shopId", description = "店铺ID",
|
||||
example = "1"),
|
||||
@Parameter(name = "page", description = "页码,默认为1",
|
||||
required = true, example = "1"),
|
||||
@Parameter(name = "pagesize", description = "页大小,默认为10",
|
||||
required = true, example = "10 ")
|
||||
})
|
||||
@Operation(summary = "获取未被领取优惠券")
|
||||
public CommonResult<List<AppCouponVO>> myNotList(@RequestParam(value = "id",required = false) Long shopId,
|
||||
@RequestParam(value = "page",defaultValue = "1") int page,
|
||||
@RequestParam(value = "pagesize",defaultValue = "10") int pagesize){
|
||||
Long uid = getLoginUserId();
|
||||
return success(appCouponService.getNotList(uid,shopId,page,pagesize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取优惠券
|
||||
*/
|
||||
@PreAuthenticated
|
||||
@PostMapping("/receive")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "优惠券ID",
|
||||
example = "1"),
|
||||
@Parameter(name = "code", description = "优惠券兑换码",
|
||||
example = "1")
|
||||
})
|
||||
@Operation(summary = "获取未被领取优惠券")
|
||||
public CommonResult<Boolean> receive(@RequestBody AppReceVO appReceVO){
|
||||
Long uid = getLoginUserId();
|
||||
appCouponService.receive(uid,appReceVO.getId(),appReceVO.getCode());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.app.coupon.vo;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 优惠券 vo
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AppCouponVO {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 店铺id,0表示通用
|
||||
*/
|
||||
private String shopId;
|
||||
/**
|
||||
* 店铺名称逗号隔开
|
||||
*/
|
||||
private String shopName;
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 是否上架
|
||||
*/
|
||||
private Integer isSwitch;
|
||||
/**
|
||||
* 消费多少可用
|
||||
*/
|
||||
private BigDecimal least;
|
||||
/**
|
||||
* 优惠券金额
|
||||
*/
|
||||
private BigDecimal value;
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
/**
|
||||
* 权重
|
||||
*/
|
||||
private Integer weigh;
|
||||
/**
|
||||
* 可用类型:0=通用,1=自取,2=外卖
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 兑换码
|
||||
*/
|
||||
private String exchangeCode;
|
||||
/**
|
||||
* 已领取
|
||||
*/
|
||||
private Integer receive;
|
||||
/**
|
||||
* 发行数量
|
||||
*/
|
||||
private Integer distribute;
|
||||
/**
|
||||
* 所需积分
|
||||
*/
|
||||
private Integer score;
|
||||
/**
|
||||
* 使用说明
|
||||
*/
|
||||
private String instructions;
|
||||
/**
|
||||
* 图片
|
||||
*/
|
||||
private String image;
|
||||
/**
|
||||
* 限领数量
|
||||
*/
|
||||
private Integer limit;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 是否已领取
|
||||
*/
|
||||
private Integer isReceive;
|
||||
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.app.coupon.vo;
|
||||
|
||||
import co.yixiang.yshop.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户领的优惠券vo
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AppMyCouponVO {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 店铺id,0表示通用
|
||||
*/
|
||||
private String shopId;
|
||||
/**
|
||||
* 店铺名称逗号隔开
|
||||
*/
|
||||
private String shopName;
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 消费多少可用
|
||||
*/
|
||||
private BigDecimal least;
|
||||
/**
|
||||
* 优惠券金额
|
||||
*/
|
||||
private BigDecimal value;
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 可用类型:0=通用,1=自取,2=外卖
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 消耗积分
|
||||
*/
|
||||
private Integer score;
|
||||
/**
|
||||
* 使用说明
|
||||
*/
|
||||
private String instructions;
|
||||
/**
|
||||
* 图片
|
||||
*/
|
||||
private String image;
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Integer userId;
|
||||
/**
|
||||
* 已使用:0=否,1=是
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Integer couponId;
|
||||
/**
|
||||
* 兑换码
|
||||
*/
|
||||
private String exchangeCode;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package co.yixiang.yshop.module.coupon.controller.app.coupon.vo;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 领取优惠券 vo
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Data
|
||||
public class AppReceVO {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 优惠券兑换码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package co.yixiang.yshop.module.coupon.convert.coupon;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
|
||||
import co.yixiang.yshop.module.coupon.controller.app.coupon.vo.AppCouponVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.*;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.coupon.CouponDO;
|
||||
|
||||
/**
|
||||
* 优惠券 Convert
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponConvert {
|
||||
|
||||
CouponConvert INSTANCE = Mappers.getMapper(CouponConvert.class);
|
||||
|
||||
CouponDO convert(CouponCreateReqVO bean);
|
||||
|
||||
CouponDO convert(CouponUpdateReqVO bean);
|
||||
|
||||
CouponRespVO convert(CouponDO bean);
|
||||
|
||||
AppCouponVO convert01(CouponDO bean);
|
||||
|
||||
List<CouponRespVO> convertList(List<CouponDO> list);
|
||||
|
||||
List<AppCouponVO> convertList03(List<CouponDO> list);
|
||||
|
||||
PageResult<CouponRespVO> convertPage(PageResult<CouponDO> page);
|
||||
|
||||
List<CouponExcelVO> convertList02(List<CouponDO> list);
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package co.yixiang.yshop.module.coupon.convert.couponuser;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
|
||||
import co.yixiang.yshop.module.coupon.controller.app.coupon.vo.AppMyCouponVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo.*;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.couponuser.CouponUserDO;
|
||||
|
||||
/**
|
||||
* 用户领的优惠券 Convert
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponUserConvert {
|
||||
|
||||
CouponUserConvert INSTANCE = Mappers.getMapper(CouponUserConvert.class);
|
||||
|
||||
CouponUserDO convert(CouponUserCreateReqVO bean);
|
||||
|
||||
CouponUserDO convert(CouponUserUpdateReqVO bean);
|
||||
|
||||
CouponUserRespVO convert(CouponUserDO bean);
|
||||
|
||||
List<AppMyCouponVO> convertList03(List<CouponUserDO> list);
|
||||
|
||||
List<CouponUserRespVO> convertList(List<CouponUserDO> list);
|
||||
|
||||
PageResult<CouponUserRespVO> convertPage(PageResult<CouponUserDO> page);
|
||||
|
||||
List<CouponUserExcelVO> convertList02(List<CouponUserDO> list);
|
||||
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
package co.yixiang.yshop.module.coupon.dal.dataobject.coupon;
|
||||
|
||||
import co.yixiang.yshop.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 优惠券 DO
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@TableName(value = "yshop_coupon")
|
||||
@KeySequence("yshop_coupon_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CouponDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 店铺id,0表示通用
|
||||
*/
|
||||
private String shopId;
|
||||
/**
|
||||
* 店铺名称逗号隔开
|
||||
*/
|
||||
private String shopName;
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 是否上架
|
||||
*/
|
||||
private Integer isSwitch;
|
||||
/**
|
||||
* 消费多少可用
|
||||
*/
|
||||
private BigDecimal least;
|
||||
/**
|
||||
* 优惠券金额
|
||||
*/
|
||||
private BigDecimal value;
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
/**
|
||||
* 权重
|
||||
*/
|
||||
private Integer weigh;
|
||||
/**
|
||||
* 可用类型:0=通用,1=自取,2=外卖
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 兑换码
|
||||
*/
|
||||
private String exchangeCode;
|
||||
/**
|
||||
* 已领取
|
||||
*/
|
||||
private Integer receive;
|
||||
/**
|
||||
* 发行数量
|
||||
*/
|
||||
private Integer distribute;
|
||||
/**
|
||||
* 所需积分
|
||||
*/
|
||||
private Integer score;
|
||||
/**
|
||||
* 使用说明
|
||||
*/
|
||||
private String instructions;
|
||||
/**
|
||||
* 图片
|
||||
*/
|
||||
private String image;
|
||||
/**
|
||||
* 限领数量
|
||||
*/
|
||||
@TableField(value = "`limit`")
|
||||
private Integer limit;
|
||||
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package co.yixiang.yshop.module.coupon.dal.dataobject.couponuser;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import co.yixiang.yshop.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 用户领的优惠券 DO
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@TableName("yshop_coupon_user")
|
||||
@KeySequence("yshop_coupon_user_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CouponUserDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 店铺id,0表示通用
|
||||
*/
|
||||
private String shopId;
|
||||
/**
|
||||
* 店铺名称逗号隔开
|
||||
*/
|
||||
private String shopName;
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 消费多少可用
|
||||
*/
|
||||
private BigDecimal least;
|
||||
/**
|
||||
* 优惠券金额
|
||||
*/
|
||||
private BigDecimal value;
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 可用类型:0=通用,1=自取,2=外卖
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 消耗积分
|
||||
*/
|
||||
private Integer score;
|
||||
/**
|
||||
* 使用说明
|
||||
*/
|
||||
private String instructions;
|
||||
/**
|
||||
* 图片
|
||||
*/
|
||||
private String image;
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Integer userId;
|
||||
/**
|
||||
* 已使用:0=否,1=是
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Integer couponId;
|
||||
/**
|
||||
* 兑换码
|
||||
*/
|
||||
private String exchangeCode;
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package co.yixiang.yshop.module.coupon.dal.mysql.coupon;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import co.yixiang.yshop.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.coupon.CouponDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.*;
|
||||
|
||||
/**
|
||||
* 优惠券 Mapper
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponMapper extends BaseMapperX<CouponDO> {
|
||||
|
||||
default PageResult<CouponDO> selectPage(CouponPageReqVO reqVO) {
|
||||
Long shopId = SecurityFrameworkUtils.getLoginUser().getShopId();
|
||||
if(shopId == 0) {
|
||||
reqVO.setShopId(null);
|
||||
}else {
|
||||
reqVO.setShopId(shopId.toString());
|
||||
}
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<CouponDO>()
|
||||
.eqIfPresent(CouponDO::getShopId, reqVO.getShopId())
|
||||
.likeIfPresent(CouponDO::getShopName, reqVO.getShopName())
|
||||
.eqIfPresent(CouponDO::getTitle, reqVO.getTitle())
|
||||
.orderByDesc(CouponDO::getId));
|
||||
}
|
||||
|
||||
default List<CouponDO> selectList(CouponExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<CouponDO>()
|
||||
.eqIfPresent(CouponDO::getShopId, reqVO.getShopId())
|
||||
.likeIfPresent(CouponDO::getShopName, reqVO.getShopName())
|
||||
.eqIfPresent(CouponDO::getTitle, reqVO.getTitle())
|
||||
.eqIfPresent(CouponDO::getIsSwitch, reqVO.getIsSwitch())
|
||||
.eqIfPresent(CouponDO::getLeast, reqVO.getLeast())
|
||||
.eqIfPresent(CouponDO::getValue, reqVO.getValue())
|
||||
.betweenIfPresent(CouponDO::getStartTime, reqVO.getStartTime())
|
||||
.betweenIfPresent(CouponDO::getCreateTime, reqVO.getCreateTime())
|
||||
.eqIfPresent(CouponDO::getWeigh, reqVO.getWeigh())
|
||||
.eqIfPresent(CouponDO::getType, reqVO.getType())
|
||||
.eqIfPresent(CouponDO::getExchangeCode, reqVO.getExchangeCode())
|
||||
.eqIfPresent(CouponDO::getReceive, reqVO.getReceive())
|
||||
.eqIfPresent(CouponDO::getDistribute, reqVO.getDistribute())
|
||||
.eqIfPresent(CouponDO::getScore, reqVO.getScore())
|
||||
.eqIfPresent(CouponDO::getInstructions, reqVO.getInstructions())
|
||||
.eqIfPresent(CouponDO::getImage, reqVO.getImage())
|
||||
.eqIfPresent(CouponDO::getLimit, reqVO.getLimit())
|
||||
.orderByDesc(CouponDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package co.yixiang.yshop.module.coupon.dal.mysql.couponuser;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.couponuser.CouponUserDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo.*;
|
||||
|
||||
/**
|
||||
* 用户领的优惠券 Mapper
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponUserMapper extends BaseMapperX<CouponUserDO> {
|
||||
|
||||
default PageResult<CouponUserDO> selectPage(CouponUserPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<CouponUserDO>()
|
||||
.eqIfPresent(CouponUserDO::getShopId, reqVO.getShopId())
|
||||
.likeIfPresent(CouponUserDO::getShopName, reqVO.getShopName())
|
||||
.eqIfPresent(CouponUserDO::getTitle, reqVO.getTitle())
|
||||
.eqIfPresent(CouponUserDO::getLeast, reqVO.getLeast())
|
||||
.eqIfPresent(CouponUserDO::getValue, reqVO.getValue())
|
||||
.eqIfPresent(CouponUserDO::getType, reqVO.getType())
|
||||
.eqIfPresent(CouponUserDO::getScore, reqVO.getScore())
|
||||
.eqIfPresent(CouponUserDO::getInstructions, reqVO.getInstructions())
|
||||
.eqIfPresent(CouponUserDO::getImage, reqVO.getImage())
|
||||
.eqIfPresent(CouponUserDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(CouponUserDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(CouponUserDO::getCouponId, reqVO.getCouponId())
|
||||
.eqIfPresent(CouponUserDO::getExchangeCode, reqVO.getExchangeCode())
|
||||
.orderByDesc(CouponUserDO::getId));
|
||||
}
|
||||
|
||||
default List<CouponUserDO> selectList(CouponUserExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<CouponUserDO>()
|
||||
.eqIfPresent(CouponUserDO::getShopId, reqVO.getShopId())
|
||||
.likeIfPresent(CouponUserDO::getShopName, reqVO.getShopName())
|
||||
.eqIfPresent(CouponUserDO::getTitle, reqVO.getTitle())
|
||||
.eqIfPresent(CouponUserDO::getLeast, reqVO.getLeast())
|
||||
.eqIfPresent(CouponUserDO::getValue, reqVO.getValue())
|
||||
.eqIfPresent(CouponUserDO::getType, reqVO.getType())
|
||||
.eqIfPresent(CouponUserDO::getScore, reqVO.getScore())
|
||||
.eqIfPresent(CouponUserDO::getInstructions, reqVO.getInstructions())
|
||||
.eqIfPresent(CouponUserDO::getImage, reqVO.getImage())
|
||||
.eqIfPresent(CouponUserDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(CouponUserDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(CouponUserDO::getCouponId, reqVO.getCouponId())
|
||||
.eqIfPresent(CouponUserDO::getExchangeCode, reqVO.getExchangeCode())
|
||||
.orderByDesc(CouponUserDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package co.yixiang.yshop.module.coupon.service.coupon;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponCreateReqVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponExportReqVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponPageReqVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponUpdateReqVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.app.coupon.vo.AppCouponVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.app.coupon.vo.AppMyCouponVO;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.coupon.CouponDO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券 Service 接口
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
public interface AppCouponService extends IService<CouponDO> {
|
||||
|
||||
/**
|
||||
* 获取未被领取优惠券
|
||||
* @param shopId 店铺id
|
||||
* @param page
|
||||
* @param pagesize
|
||||
* @return
|
||||
*/
|
||||
List<AppCouponVO> getNotList(Long uid, Long shopId, int page, int pagesize);
|
||||
|
||||
/**
|
||||
* 领取优惠券
|
||||
* @param uid 用户ID
|
||||
* @param id 优惠券ID
|
||||
* @param code 兑换码
|
||||
*/
|
||||
void receive(Long uid,Long id,String code);
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package co.yixiang.yshop.module.coupon.service.coupon;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import co.yixiang.yshop.framework.common.enums.ShopCommonEnum;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.framework.common.util.object.ObjectUtils;
|
||||
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponCreateReqVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponExportReqVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponPageReqVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponUpdateReqVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.app.coupon.vo.AppCouponVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.app.coupon.vo.AppMyCouponVO;
|
||||
import co.yixiang.yshop.module.coupon.convert.coupon.CouponConvert;
|
||||
import co.yixiang.yshop.module.coupon.convert.couponuser.CouponUserConvert;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.coupon.CouponDO;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.couponuser.CouponUserDO;
|
||||
import co.yixiang.yshop.module.coupon.dal.mysql.coupon.CouponMapper;
|
||||
import co.yixiang.yshop.module.coupon.dal.mysql.couponuser.CouponUserMapper;
|
||||
import co.yixiang.yshop.module.coupon.service.couponuser.AppCouponUserService;
|
||||
import co.yixiang.yshop.module.store.dal.dataobject.storeshop.StoreShopDO;
|
||||
import co.yixiang.yshop.module.store.dal.mysql.storeshop.StoreShopMapper;
|
||||
import co.yixiang.yshop.module.system.api.logger.dto.OperateLogCreateReqDTO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.module.coupon.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 优惠券 Service 实现类
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class AppCouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> implements AppCouponService {
|
||||
|
||||
@Resource
|
||||
private CouponMapper couponMapper;
|
||||
@Resource
|
||||
private AppCouponUserService appCouponUserService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取未被领取优惠券
|
||||
* @param shopId 店铺id
|
||||
* @param page
|
||||
* @param pagesize
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<AppCouponVO> getNotList(Long uid, Long shopId, int page, int pagesize) {
|
||||
LocalDateTime nowTime = LocalDateTime.now();
|
||||
Page<CouponDO> pageModel = new Page<>(page, pagesize);
|
||||
LambdaQueryWrapperX<CouponDO> wrapper = new LambdaQueryWrapperX<>();
|
||||
wrapper.eqIfPresent(CouponDO::getShopId, shopId)
|
||||
.gt(CouponDO::getEndTime,nowTime)
|
||||
.orderByDesc(CouponDO::getWeigh);
|
||||
IPage<CouponDO> pageList = this.baseMapper.selectPage(pageModel, wrapper);
|
||||
List<AppCouponVO> list = new ArrayList<>();
|
||||
for (CouponDO couponDO : pageList.getRecords()) {
|
||||
AppCouponVO appCouponVO = CouponConvert.INSTANCE.convert01(couponDO);
|
||||
long count = appCouponUserService.count(new LambdaQueryWrapper<CouponUserDO>()
|
||||
.eq(CouponUserDO::getUserId,uid).eq(CouponUserDO::getCouponId,couponDO.getId()));
|
||||
if(count > 0){
|
||||
appCouponVO.setIsReceive(ShopCommonEnum.DEFAULT_1.getValue());
|
||||
}else {
|
||||
appCouponVO.setIsReceive(ShopCommonEnum.DEFAULT_0.getValue());
|
||||
}
|
||||
list.add(appCouponVO);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取优惠券
|
||||
* @param uid 用户ID
|
||||
* @param id 优惠券ID
|
||||
* @param code 兑换码
|
||||
*/
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
||||
public void receive(Long uid, Long id, String code) {
|
||||
CouponDO couponDO = null;
|
||||
if(id != null){
|
||||
couponDO = this.baseMapper.selectById(id);
|
||||
}else {
|
||||
couponDO = couponMapper.selectOne(CouponDO::getExchangeCode,code);
|
||||
}
|
||||
if(couponDO == null){
|
||||
throw exception(COUPON_NOT_EXISTS);
|
||||
}
|
||||
if(couponDO.getReceive() >= couponDO.getDistribute()){
|
||||
throw exception(COUPON_RECEIVE_ZERO);
|
||||
}
|
||||
Long couponCount = appCouponUserService.count(new LambdaQueryWrapper<CouponUserDO>()
|
||||
.eq(CouponUserDO::getUserId,uid).eq(CouponUserDO::getCouponId,couponDO.getId()));
|
||||
if(couponCount > 0){
|
||||
throw exception(COUPON_RECEIVED);
|
||||
}
|
||||
|
||||
|
||||
CouponUserDO couponUserDO = BeanUtil.copyProperties(couponDO,CouponUserDO.class,"id");
|
||||
|
||||
couponUserDO.setUserId(uid.intValue());
|
||||
couponUserDO.setCouponId(couponDO.getId().intValue());
|
||||
couponUserDO.setEndTime(couponDO.getEndTime());
|
||||
couponUserDO.setExchangeCode(code);
|
||||
appCouponUserService.save(couponUserDO);
|
||||
|
||||
int newRecive = couponDO.getReceive() + 1;
|
||||
couponDO.setReceive(newRecive);
|
||||
couponMapper.updateById(couponDO);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package co.yixiang.yshop.module.coupon.service.coupon;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.*;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.coupon.CouponDO;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 优惠券 Service 接口
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
public interface CouponService {
|
||||
|
||||
/**
|
||||
* 创建优惠券
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long create(@Valid CouponCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新优惠券
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void update(@Valid CouponUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除优惠券
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void delete(Long id);
|
||||
|
||||
/**
|
||||
* 获得优惠券
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 优惠券
|
||||
*/
|
||||
CouponDO get(Long id);
|
||||
|
||||
/**
|
||||
* 获得优惠券列表全店铺通用
|
||||
*
|
||||
* @return 优惠券列表
|
||||
*/
|
||||
List<CouponDO> getList();
|
||||
|
||||
/**
|
||||
* 获得优惠券分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 优惠券分页
|
||||
*/
|
||||
PageResult<CouponDO> getPage(CouponPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得优惠券列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 优惠券列表
|
||||
*/
|
||||
List<CouponDO> getList(CouponExportReqVO exportReqVO);
|
||||
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package co.yixiang.yshop.module.coupon.service.coupon;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponCreateReqVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponExportReqVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponPageReqVO;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.coupon.vo.CouponUpdateReqVO;
|
||||
import co.yixiang.yshop.module.coupon.convert.coupon.CouponConvert;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.coupon.CouponDO;
|
||||
import co.yixiang.yshop.module.coupon.dal.mysql.coupon.CouponMapper;
|
||||
import co.yixiang.yshop.module.store.dal.dataobject.storeshop.StoreShopDO;
|
||||
import co.yixiang.yshop.module.store.dal.mysql.storeshop.StoreShopMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.module.coupon.enums.ErrorCodeConstants.COUPON_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 优惠券 Service 实现类
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class CouponServiceImpl implements CouponService {
|
||||
|
||||
@Resource
|
||||
private CouponMapper Mapper;
|
||||
@Resource
|
||||
private StoreShopMapper storeShopMapper;
|
||||
|
||||
@Override
|
||||
public Long create(CouponCreateReqVO createReqVO) {
|
||||
// 插入
|
||||
CouponDO couponDO = CouponConvert.INSTANCE.convert(createReqVO);
|
||||
StoreShopDO storeShopDO = storeShopMapper.selectById(createReqVO.getShopId());
|
||||
couponDO.setShopName(storeShopDO.getName());
|
||||
Mapper.insert(couponDO);
|
||||
// 返回
|
||||
return couponDO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(CouponUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateExists(updateReqVO.getId());
|
||||
// 更新
|
||||
CouponDO updateObj = CouponConvert.INSTANCE.convert(updateReqVO);
|
||||
StoreShopDO storeShopDO = storeShopMapper.selectById(updateReqVO.getShopId());
|
||||
updateObj.setShopName(storeShopDO.getName());
|
||||
Mapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
// 校验存在
|
||||
validateExists(id);
|
||||
// 删除
|
||||
Mapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateExists(Long id) {
|
||||
if (Mapper.selectById(id) == null) {
|
||||
throw exception(COUPON_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CouponDO get(Long id) {
|
||||
return Mapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CouponDO> getList() {
|
||||
return Mapper.selectList(new LambdaQueryWrapper<CouponDO>().eq(CouponDO::getShopId,0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CouponDO> getPage(CouponPageReqVO pageReqVO) {
|
||||
return Mapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CouponDO> getList(CouponExportReqVO exportReqVO) {
|
||||
return Mapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package co.yixiang.yshop.module.coupon.service.couponuser;
|
||||
|
||||
import co.yixiang.yshop.module.coupon.controller.app.coupon.vo.AppMyCouponVO;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.couponuser.CouponUserDO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户领的优惠券 Service 接口
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
public interface AppCouponUserService extends IService<CouponUserDO> {
|
||||
|
||||
/**
|
||||
* 获取我的优惠券列表
|
||||
* @param shopId 店铺id
|
||||
* @param type
|
||||
* @param page
|
||||
* @param pagesize
|
||||
* @return
|
||||
*/
|
||||
List<AppMyCouponVO> getList(Long uid, Long shopId,int type, int page, int pagesize);
|
||||
|
||||
|
||||
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package co.yixiang.yshop.module.coupon.service.couponuser;
|
||||
|
||||
import co.yixiang.yshop.framework.common.enums.ShopCommonEnum;
|
||||
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import co.yixiang.yshop.module.coupon.controller.app.coupon.vo.AppMyCouponVO;
|
||||
import co.yixiang.yshop.module.coupon.convert.couponuser.CouponUserConvert;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.couponuser.CouponUserDO;
|
||||
import co.yixiang.yshop.module.coupon.dal.mysql.couponuser.CouponUserMapper;
|
||||
import co.yixiang.yshop.module.coupon.enums.CouponStatusEnum;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户领的优惠券 Service 实现类
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class AppCouponUserServiceImpl extends ServiceImpl<CouponUserMapper, CouponUserDO> implements AppCouponUserService {
|
||||
|
||||
@Resource
|
||||
private CouponUserMapper userMapper;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取我的优惠券列表
|
||||
* @param shopId 店铺id
|
||||
* @param page
|
||||
* @param pagesize
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<AppMyCouponVO> getList(Long uid, Long shopId, int type, int page, int pagesize) {
|
||||
LocalDateTime nowTime = LocalDateTime.now();
|
||||
Page<CouponUserDO> pageModel = new Page<>(page, pagesize);
|
||||
LambdaQueryWrapperX<CouponUserDO> wrapper = new LambdaQueryWrapperX<>();
|
||||
switch (CouponStatusEnum.toType(type)) {
|
||||
case STATUS_0:
|
||||
wrapper.eq(CouponUserDO::getStatus,CouponStatusEnum.STATUS_0.getValue())
|
||||
.lt(CouponUserDO::getStartTime,nowTime)
|
||||
.gt(CouponUserDO::getEndTime,nowTime);
|
||||
break;
|
||||
case STATUS_1:
|
||||
wrapper.eq(CouponUserDO::getStatus,CouponStatusEnum.STATUS_1.getValue())
|
||||
.lt(CouponUserDO::getStartTime,nowTime)
|
||||
.gt(CouponUserDO::getEndTime,nowTime);
|
||||
break;
|
||||
case STATUS_2:
|
||||
wrapper.lt(CouponUserDO::getEndTime,nowTime);
|
||||
break;
|
||||
default:
|
||||
log.warn("为了遵循阿里巴巴规范");
|
||||
}
|
||||
wrapper.eqIfPresent(CouponUserDO::getShopId, shopId)
|
||||
.eq(CouponUserDO::getUserId,uid);
|
||||
IPage<CouponUserDO> pageList = this.baseMapper.selectPage(pageModel, wrapper);
|
||||
return CouponUserConvert.INSTANCE.convertList03(pageList.getRecords());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package co.yixiang.yshop.module.coupon.service.couponuser;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo.*;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.couponuser.CouponUserDO;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 用户领的优惠券 Service 接口
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
public interface CouponUserService {
|
||||
|
||||
/**
|
||||
* 创建用户领的优惠券
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Integer createUser(@Valid CouponUserCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新用户领的优惠券
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateUser(@Valid CouponUserUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除用户领的优惠券
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteUser(Integer id);
|
||||
|
||||
/**
|
||||
* 获得用户领的优惠券
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 用户领的优惠券
|
||||
*/
|
||||
CouponUserDO getUser(Integer id);
|
||||
|
||||
/**
|
||||
* 获得用户领的优惠券列表
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 用户领的优惠券列表
|
||||
*/
|
||||
List<CouponUserDO> getUserList(Integer id);
|
||||
|
||||
/**
|
||||
* 获得用户领的优惠券分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 用户领的优惠券分页
|
||||
*/
|
||||
PageResult<CouponUserDO> getUserPage(CouponUserPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得用户领的优惠券列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 用户领的优惠券列表
|
||||
*/
|
||||
List<CouponUserDO> getUserList(CouponUserExportReqVO exportReqVO);
|
||||
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package co.yixiang.yshop.module.coupon.service.couponuser;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import co.yixiang.yshop.module.coupon.controller.admin.couponuser.vo.*;
|
||||
import co.yixiang.yshop.module.coupon.dal.dataobject.couponuser.CouponUserDO;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
|
||||
import co.yixiang.yshop.module.coupon.convert.couponuser.CouponUserConvert;
|
||||
import co.yixiang.yshop.module.coupon.dal.mysql.couponuser.CouponUserMapper;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.module.coupon.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 用户领的优惠券 Service 实现类
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class CouponUserServiceImpl implements CouponUserService {
|
||||
|
||||
@Resource
|
||||
private CouponUserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public Integer createUser(CouponUserCreateReqVO createReqVO) {
|
||||
// 插入
|
||||
CouponUserDO user = CouponUserConvert.INSTANCE.convert(createReqVO);
|
||||
userMapper.insert(user);
|
||||
// 返回
|
||||
return user.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(CouponUserUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateUserExists(updateReqVO.getId());
|
||||
// 更新
|
||||
CouponUserDO updateObj = CouponUserConvert.INSTANCE.convert(updateReqVO);
|
||||
userMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUser(Integer id) {
|
||||
// 校验存在
|
||||
validateUserExists(id);
|
||||
// 删除
|
||||
userMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateUserExists(Integer id) {
|
||||
if (userMapper.selectById(id) == null) {
|
||||
throw exception(COUPON_USER_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CouponUserDO getUser(Integer id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CouponUserDO> getUserList(Integer id) {
|
||||
CouponUserExportReqVO exportReqVO = new CouponUserExportReqVO();
|
||||
exportReqVO.setCouponId(id);
|
||||
return userMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CouponUserDO> getUserPage(CouponUserPageReqVO pageReqVO) {
|
||||
return userMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CouponUserDO> getUserList(CouponUserExportReqVO exportReqVO) {
|
||||
return userMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
<?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="co.yixiang.yshop.module.coupon.dal.mysql.coupon.CouponMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.yixiang.co/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in new issue
Block a user