diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 22f510edf8..6ad7b1f192 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -44,7 +44,9 @@ public interface ErrorCodeConstants { ErrorCode REWARD_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1_013_006_004, "满减送活动已关闭,不能重复关闭"); ErrorCode REWARD_ACTIVITY_SCOPE_EXISTS = new ErrorCode(1_013_006_005, "与该时间段满减送活动【{}】商品范围冲突,原因:{}"); - // ========== TODO 空着 1-013-007-000 ============ + // ========== 积分商城活动 1-013-007-000 ========== + ErrorCode POINT_ACTIVITY_NOT_EXISTS = new ErrorCode(1_013_007_000, "积分商城活动不存在"); + ErrorCode POINT_PRODUCT_NOT_EXISTS = new ErrorCode(1_013_007_100, "积分商城商品不存在"); // ========== 秒杀活动 1-013-008-000 ========== ErrorCode SECKILL_ACTIVITY_NOT_EXISTS = new ErrorCode(1_013_008_000, "秒杀活动不存在"); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/PointActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/PointActivityController.java new file mode 100644 index 0000000000..4b76a22d4a --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/PointActivityController.java @@ -0,0 +1,93 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.point; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivitySaveReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointActivityDO; +import cn.iocoder.yudao.module.promotion.service.point.PointActivityService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; +import java.util.List; + +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - 积分商城活动") +@RestController +@RequestMapping("/promotion/point-activity") +@Validated +public class PointActivityController { + + @Resource + private PointActivityService pointActivityService; + + @PostMapping("/create") + @Operation(summary = "创建积分商城活动") + @PreAuthorize("@ss.hasPermission('promotion:point-activity:create')") + public CommonResult createPointActivity(@Valid @RequestBody PointActivitySaveReqVO createReqVO) { + return success(pointActivityService.createPointActivity(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新积分商城活动") + @PreAuthorize("@ss.hasPermission('promotion:point-activity:update')") + public CommonResult updatePointActivity(@Valid @RequestBody PointActivitySaveReqVO updateReqVO) { + pointActivityService.updatePointActivity(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除积分商城活动") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('promotion:point-activity:delete')") + public CommonResult deletePointActivity(@RequestParam("id") Long id) { + pointActivityService.deletePointActivity(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得积分商城活动") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('promotion:point-activity:query')") + public CommonResult getPointActivity(@RequestParam("id") Long id) { + PointActivityDO pointActivity = pointActivityService.getPointActivity(id); + return success(BeanUtils.toBean(pointActivity, PointActivityRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得积分商城活动分页") + @PreAuthorize("@ss.hasPermission('promotion:point-activity:query')") + public CommonResult> getPointActivityPage(@Valid PointActivityPageReqVO pageReqVO) { + PageResult pageResult = pointActivityService.getPointActivityPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, PointActivityRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出积分商城活动 Excel") + @PreAuthorize("@ss.hasPermission('promotion:point-activity:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportPointActivityExcel(@Valid PointActivityPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = pointActivityService.getPointActivityPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "积分商城活动.xls", "数据", PointActivityRespVO.class, + BeanUtils.toBean(list, PointActivityRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivityPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivityPageReqVO.java new file mode 100644 index 0000000000..89786c2ded --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivityPageReqVO.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.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 PointActivityPageReqVO extends PageParam { + + @Schema(description = "积分商城活动商品", example = "19509") + private Long spuId; + + @Schema(description = "活动状态", example = "2") + private Integer status; + + @Schema(description = "备注", example = "你说的对") + private String remark; + + @Schema(description = "排序") + private Integer sort; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivityRespVO.java new file mode 100644 index 0000000000..1aa3b98ea0 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivityRespVO.java @@ -0,0 +1,67 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity; + +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product.PointProductSaveReqVO; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.List; + +@Schema(description = "管理后台 - 积分商城活动 Response VO") +@Data +@ExcelIgnoreUnannotated +public class PointActivityRespVO { + + @Schema(description = "积分商城活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11373") + @ExcelProperty("积分商城活动编号") + private Long id; + + @Schema(description = "积分商城活动商品", requiredMode = Schema.RequiredMode.REQUIRED, example = "19509") + @ExcelProperty("积分商城活动商品") + private Long spuId; + + @Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @ExcelProperty("活动状态") + private Integer status; + + @Schema(description = "备注", example = "你说的对") + @ExcelProperty("备注") + private String remark; + + @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("排序") + private Integer sort; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + + @Schema(description = "积分商城商品", requiredMode = Schema.RequiredMode.REQUIRED) + private List products; + + // ========== 商品字段 ========== + + @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 name 读取 + example = "618大促") + private String spuName; + @Schema(description = "商品主图", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 picUrl 读取 + example = "https://www.iocoder.cn/xx.png") + private String picUrl; + @Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, // 从 SPU 的 marketPrice 读取 + example = "50") + private Integer marketPrice; + + //======================= 显示所需兑换积分最少的 sku 信息 ======================= + + @Schema(description = "可兑换数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "3926") + private Integer maxCount; + + @Schema(description = "兑换积分", requiredMode = Schema.RequiredMode.REQUIRED) + private Integer point; + + @Schema(description = "兑换金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "15860") + private Integer price; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivitySaveReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivitySaveReqVO.java new file mode 100644 index 0000000000..06dc61c0fd --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivitySaveReqVO.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity; + +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product.PointProductSaveReqVO; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.List; + +@Schema(description = "管理后台 - 积分商城活动新增/修改 Request VO") +@Data +public class PointActivitySaveReqVO { + + @Schema(description = "积分商城活动编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11373") + private Long id; + + @Schema(description = "积分商城活动商品", requiredMode = Schema.RequiredMode.REQUIRED, example = "19509") + @NotNull(message = "积分商城活动商品不能为空") + private Long spuId; + + @Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @NotNull(message = "活动状态不能为空") + private Integer status; + + @Schema(description = "备注", example = "你说的对") + private String remark; + + @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "排序不能为空") + private Integer sort; + + @Schema(description = "积分商城商品", requiredMode = Schema.RequiredMode.REQUIRED) + private List products; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/product/PointProductPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/product/PointProductPageReqVO.java new file mode 100644 index 0000000000..d94654e0e3 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/product/PointProductPageReqVO.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.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 PointProductPageReqVO extends PageParam { + + @Schema(description = "积分商城活动 id", example = "29388") + private Long activityId; + + @Schema(description = "商品 SPU 编号", example = "8112") + private Long spuId; + + @Schema(description = "商品 SKU 编号", example = "2736") + private Long skuId; + + @Schema(description = "可兑换数量", example = "3926") + private Integer maxCount; + + @Schema(description = "兑换积分") + private Integer point; + + @Schema(description = "兑换金额,单位:分", example = "15860") + private Integer price; + + @Schema(description = "兑换类型", example = "2") + private Integer type; + + @Schema(description = "积分商城商品状态", example = "2") + private Integer activityStatus; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/product/PointProductRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/product/PointProductRespVO.java new file mode 100644 index 0000000000..0710a137c3 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/product/PointProductRespVO.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 积分商城商品 Response VO") +@Data +@ExcelIgnoreUnannotated +public class PointProductRespVO { + + @Schema(description = "积分商城商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31718") + @ExcelProperty("积分商城商品编号") + private Long id; + + @Schema(description = "积分商城活动 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "29388") + @ExcelProperty("积分商城活动 id") + private Long activityId; + + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8112") + @ExcelProperty("商品 SPU 编号") + private Long spuId; + + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2736") + @ExcelProperty("商品 SKU 编号") + private Long skuId; + + @Schema(description = "可兑换数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "3926") + @ExcelProperty("可兑换数量") + private Integer maxCount; + + @Schema(description = "兑换积分", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("兑换积分") + private Integer point; + + @Schema(description = "兑换金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "15860") + @ExcelProperty("兑换金额,单位:分") + private Integer price; + + @Schema(description = "兑换类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @ExcelProperty("兑换类型") + private Integer type; + + @Schema(description = "积分商城商品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @ExcelProperty("积分商城商品状态") + private Integer activityStatus; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/product/PointProductSaveReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/product/PointProductSaveReqVO.java new file mode 100644 index 0000000000..671ee57dab --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/product/PointProductSaveReqVO.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Schema(description = "管理后台 - 积分商城商品新增/修改 Request VO") +@Data +public class PointProductSaveReqVO { + + @Schema(description = "积分商城商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31718") + private Long id; + + @Schema(description = "积分商城活动 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "29388") + @NotNull(message = "积分商城活动 id不能为空") + private Long activityId; + + @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8112") + @NotNull(message = "商品 SPU 编号不能为空") + private Long spuId; + + @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2736") + @NotNull(message = "商品 SKU 编号不能为空") + private Long skuId; + + @Schema(description = "可兑换数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "3926") + @NotNull(message = "可兑换数量不能为空") + private Integer maxCount; + + @Schema(description = "兑换积分", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "兑换积分不能为空") + private Integer point; + + @Schema(description = "兑换金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "15860") + @NotNull(message = "兑换金额,单位:分不能为空") + private Integer price; + + @Schema(description = "兑换类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @NotNull(message = "兑换类型不能为空") + private Integer type; + + @Schema(description = "积分商城商品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @NotNull(message = "积分商城商品状态不能为空") + private Integer activityStatus; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java index 18b2170e3d..4694c677f6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityRespVO.java @@ -54,7 +54,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO { example = "50") private Integer marketPrice; - @Schema(description = "拼团金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") + @Schema(description = "秒杀金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") private Integer seckillPrice; // 从 products 获取最小 price 读取 } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/pointproduct/PointProductDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/pointproduct/PointProductDO.java new file mode 100644 index 0000000000..4ffcdbdbef --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/pointproduct/PointProductDO.java @@ -0,0 +1,62 @@ +package cn.iocoder.yudao.module.promotion.dal.dataobject.pointproduct; + +import cn.iocoder.yudao.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.*; + +/** + * 积分商城商品 DO + * + * @author HUIHUI + */ +@TableName("promotion_point_product") +@KeySequence("promotion_point_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PointProductDO extends BaseDO { + + /** + * 积分商城商品编号 + */ + @TableId + private Long id; + /** + * 积分商城活动 id + */ + private Long activityId; + /** + * 商品 SPU 编号 + */ + private Long spuId; + /** + * 商品 SKU 编号 + */ + private Long skuId; + /** + * 可兑换数量 + */ + private Integer maxCount; + /** + * 兑换积分 + */ + private Integer point; + /** + * 兑换金额,单位:分 + */ + private Integer price; + /** + * 兑换类型 + */ + private Integer type; + /** + * 积分商城商品状态 + */ + private Integer activityStatus; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/point/PointActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/point/PointActivityMapper.java new file mode 100644 index 0000000000..46db5841e8 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/point/PointActivityMapper.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.promotion.dal.mysql.point; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointActivityDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 积分商城活动 Mapper + * + * @author HUIHUI + */ +@Mapper +public interface PointActivityMapper extends BaseMapperX { + + default PageResult selectPage(PointActivityPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(PointActivityDO::getSpuId, reqVO.getSpuId()) + .eqIfPresent(PointActivityDO::getStatus, reqVO.getStatus()) + .eqIfPresent(PointActivityDO::getRemark, reqVO.getRemark()) + .eqIfPresent(PointActivityDO::getSort, reqVO.getSort()) + .betweenIfPresent(PointActivityDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(PointActivityDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/point/PointProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/point/PointProductMapper.java new file mode 100644 index 0000000000..230980544d --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/point/PointProductMapper.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.promotion.dal.mysql.point; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product.PointProductPageReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.pointproduct.PointProductDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 积分商城商品 Mapper + * + * @author HUIHUI + */ +@Mapper +public interface PointProductMapper extends BaseMapperX { + + default PageResult selectPage(PointProductPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(PointProductDO::getActivityId, reqVO.getActivityId()) + .eqIfPresent(PointProductDO::getSpuId, reqVO.getSpuId()) + .eqIfPresent(PointProductDO::getSkuId, reqVO.getSkuId()) + .eqIfPresent(PointProductDO::getMaxCount, reqVO.getMaxCount()) + .eqIfPresent(PointProductDO::getPoint, reqVO.getPoint()) + .eqIfPresent(PointProductDO::getPrice, reqVO.getPrice()) + .eqIfPresent(PointProductDO::getType, reqVO.getType()) + .eqIfPresent(PointProductDO::getActivityStatus, reqVO.getActivityStatus()) + .betweenIfPresent(PointProductDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(PointProductDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/point/PointActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/point/PointActivityService.java new file mode 100644 index 0000000000..a9dac3eb8c --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/point/PointActivityService.java @@ -0,0 +1,54 @@ +package cn.iocoder.yudao.module.promotion.service.point; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivitySaveReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointActivityDO; +import jakarta.validation.Valid; + +/** + * 积分商城活动 Service 接口 + * + * @author HUIHUI + */ +public interface PointActivityService { + + /** + * 创建积分商城活动 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createPointActivity(@Valid PointActivitySaveReqVO createReqVO); + + /** + * 更新积分商城活动 + * + * @param updateReqVO 更新信息 + */ + void updatePointActivity(@Valid PointActivitySaveReqVO updateReqVO); + + /** + * 删除积分商城活动 + * + * @param id 编号 + */ + void deletePointActivity(Long id); + + /** + * 获得积分商城活动 + * + * @param id 编号 + * @return 积分商城活动 + */ + PointActivityDO getPointActivity(Long id); + + /** + * 获得积分商城活动分页 + * + * @param pageReqVO 分页查询 + * @return 积分商城活动分页 + */ + PageResult getPointActivityPage(PointActivityPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/point/PointActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/point/PointActivityServiceImpl.java new file mode 100644 index 0000000000..c1040a2e73 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/point/PointActivityServiceImpl.java @@ -0,0 +1,120 @@ +package cn.iocoder.yudao.module.promotion.service.point; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityPageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivitySaveReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product.PointProductSaveReqVO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointActivityDO; +import cn.iocoder.yudao.module.promotion.dal.mysql.point.PointActivityMapper; +import cn.iocoder.yudao.module.promotion.dal.mysql.point.PointProductMapper; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.POINT_ACTIVITY_NOT_EXISTS; +import static java.util.Collections.singletonList; + +// TODO @puhui999: 下次提交完善 + +/** + * 积分商城活动 Service 实现类 + * + * @author HUIHUI + */ +@Service +@Validated +public class PointActivityServiceImpl implements PointActivityService { + + @Resource + private PointActivityMapper pointActivityMapper; + @Resource + private PointProductMapper pointProductMapper; + + @Resource + private ProductSpuApi productSpuApi; + @Resource + private ProductSkuApi productSkuApi; + + @Override + public Long createPointActivity(PointActivitySaveReqVO createReqVO) { + // 1. 校验商品是否存在 + validateProductExists(createReqVO.getSpuId(), createReqVO.getProducts()); + // 插入 + PointActivityDO pointActivity = BeanUtils.toBean(createReqVO, PointActivityDO.class); + pointActivityMapper.insert(pointActivity); + // 返回 + return pointActivity.getId(); + } + + @Override + public void updatePointActivity(PointActivitySaveReqVO updateReqVO) { + // 1.1 校验存在 + validatePointActivityExists(updateReqVO.getId()); + // 1.2 校验商品是否存在 + validateProductExists(updateReqVO.getSpuId(), updateReqVO.getProducts()); + + // 更新 + PointActivityDO updateObj = BeanUtils.toBean(updateReqVO, PointActivityDO.class); + pointActivityMapper.updateById(updateObj); + } + + @Override + public void deletePointActivity(Long id) { + // 校验存在 + validatePointActivityExists(id); + // 删除 + pointActivityMapper.deleteById(id); + } + + private void validatePointActivityExists(Long id) { + if (pointActivityMapper.selectById(id) == null) { + throw exception(POINT_ACTIVITY_NOT_EXISTS); + } + } + + /** + * 校验秒杀商品是否都存在 + * + * @param spuId 商品 SPU 编号 + * @param products 秒杀商品 + */ + private void validateProductExists(Long spuId, List products) { + // 1. 校验商品 spu 是否存在 + ProductSpuRespDTO spu = productSpuApi.getSpu(spuId); + if (spu == null) { + throw exception(SPU_NOT_EXISTS); + } + + // 2. 校验商品 sku 都存在 + List skus = productSkuApi.getSkuListBySpuId(singletonList(spuId)); + Map skuMap = convertMap(skus, ProductSkuRespDTO::getId); + products.forEach(product -> { + if (!skuMap.containsKey(product.getSkuId())) { + throw exception(SKU_NOT_EXISTS); + } + }); + } + + @Override + public PointActivityDO getPointActivity(Long id) { + return pointActivityMapper.selectById(id); + } + + @Override + public PageResult getPointActivityPage(PointActivityPageReqVO pageReqVO) { + return pointActivityMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file