Commit 2fb55f3649fa7e03347d30bdcaa49b08986c2d53
Committed by
Gitee
!1092 【代码优化】商城: 完善积分商城
Merge pull request !1092 from puhui999/develop
Showing
7 changed files
with
84 additions
and
50 deletions
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/ProductSpuApi.java
| @@ -4,6 +4,9 @@ import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | @@ -4,6 +4,9 @@ import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | ||
| 4 | 4 | ||
| 5 | import java.util.Collection; | 5 | import java.util.Collection; |
| 6 | import java.util.List; | 6 | import java.util.List; |
| 7 | +import java.util.Map; | ||
| 8 | + | ||
| 9 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | ||
| 7 | 10 | ||
| 8 | /** | 11 | /** |
| 9 | * 商品 SPU API 接口 | 12 | * 商品 SPU API 接口 |
| @@ -22,6 +25,16 @@ public interface ProductSpuApi { | @@ -22,6 +25,16 @@ public interface ProductSpuApi { | ||
| 22 | List<ProductSpuRespDTO> getSpuList(Collection<Long> ids); | 25 | List<ProductSpuRespDTO> getSpuList(Collection<Long> ids); |
| 23 | 26 | ||
| 24 | /** | 27 | /** |
| 28 | + * 批量查询 SPU MAP | ||
| 29 | + * | ||
| 30 | + * @param ids SPU 编号列表 | ||
| 31 | + * @return SPU MAP | ||
| 32 | + */ | ||
| 33 | + default Map<Long, ProductSpuRespDTO> getSpusMap(Collection<Long> ids) { | ||
| 34 | + return convertMap(getSpuList(ids), ProductSpuRespDTO::getId); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + /** | ||
| 25 | * 批量查询 SPU 数组,并且校验是否 SPU 是否有效。 | 38 | * 批量查询 SPU 数组,并且校验是否 SPU 是否有效。 |
| 26 | * | 39 | * |
| 27 | * 如下情况,视为无效: | 40 | * 如下情况,视为无效: |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/PointActivityController.java
| 1 | package cn.iocoder.yudao.module.promotion.controller.admin.point; | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.point; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; | 3 | +import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 8 | +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; |
| 9 | +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | ||
| 9 | import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityPageReqVO; | 10 | import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityPageReqVO; |
| 10 | import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityRespVO; | 11 | import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityRespVO; |
| 11 | import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivitySaveReqVO; | 12 | import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivitySaveReqVO; |
| 13 | +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product.PointProductRespVO; | ||
| 12 | import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointActivityDO; | 14 | import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointActivityDO; |
| 15 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointProductDO; | ||
| 13 | import cn.iocoder.yudao.module.promotion.service.point.PointActivityService; | 16 | import cn.iocoder.yudao.module.promotion.service.point.PointActivityService; |
| 14 | import io.swagger.v3.oas.annotations.Operation; | 17 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | import io.swagger.v3.oas.annotations.Parameter; | 18 | import io.swagger.v3.oas.annotations.Parameter; |
| 16 | import io.swagger.v3.oas.annotations.tags.Tag; | 19 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 17 | import jakarta.annotation.Resource; | 20 | import jakarta.annotation.Resource; |
| 18 | -import jakarta.servlet.http.HttpServletResponse; | ||
| 19 | import jakarta.validation.Valid; | 21 | import jakarta.validation.Valid; |
| 20 | import org.springframework.security.access.prepost.PreAuthorize; | 22 | import org.springframework.security.access.prepost.PreAuthorize; |
| 21 | import org.springframework.validation.annotation.Validated; | 23 | import org.springframework.validation.annotation.Validated; |
| 22 | import org.springframework.web.bind.annotation.*; | 24 | import org.springframework.web.bind.annotation.*; |
| 23 | 25 | ||
| 24 | -import java.io.IOException; | 26 | +import java.util.Collections; |
| 25 | import java.util.List; | 27 | import java.util.List; |
| 28 | +import java.util.Map; | ||
| 26 | 29 | ||
| 27 | -import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; | ||
| 28 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 30 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 31 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; | ||
| 32 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 29 | 33 | ||
| 30 | @Tag(name = "管理后台 - 积分商城活动") | 34 | @Tag(name = "管理后台 - 积分商城活动") |
| 31 | @RestController | 35 | @RestController |
| @@ -35,6 +39,8 @@ public class PointActivityController { | @@ -35,6 +39,8 @@ public class PointActivityController { | ||
| 35 | 39 | ||
| 36 | @Resource | 40 | @Resource |
| 37 | private PointActivityService pointActivityService; | 41 | private PointActivityService pointActivityService; |
| 42 | + @Resource | ||
| 43 | + private ProductSpuApi productSpuApi; | ||
| 38 | 44 | ||
| 39 | @PostMapping("/create") | 45 | @PostMapping("/create") |
| 40 | @Operation(summary = "创建积分商城活动") | 46 | @Operation(summary = "创建积分商城活动") |
| @@ -75,7 +81,14 @@ public class PointActivityController { | @@ -75,7 +81,14 @@ public class PointActivityController { | ||
| 75 | @PreAuthorize("@ss.hasPermission('promotion:point-activity:query')") | 81 | @PreAuthorize("@ss.hasPermission('promotion:point-activity:query')") |
| 76 | public CommonResult<PointActivityRespVO> getPointActivity(@RequestParam("id") Long id) { | 82 | public CommonResult<PointActivityRespVO> getPointActivity(@RequestParam("id") Long id) { |
| 77 | PointActivityDO pointActivity = pointActivityService.getPointActivity(id); | 83 | PointActivityDO pointActivity = pointActivityService.getPointActivity(id); |
| 78 | - return success(BeanUtils.toBean(pointActivity, PointActivityRespVO.class)); | 84 | + if (pointActivity == null) { |
| 85 | + return success(null); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds(Collections.singletonList(id)); | ||
| 89 | + PointActivityRespVO respVO = BeanUtils.toBean(pointActivity, PointActivityRespVO.class); | ||
| 90 | + respVO.setProducts(BeanUtils.toBean(products, PointProductRespVO.class)); | ||
| 91 | + return success(respVO); | ||
| 79 | } | 92 | } |
| 80 | 93 | ||
| 81 | @GetMapping("/page") | 94 | @GetMapping("/page") |
| @@ -83,20 +96,24 @@ public class PointActivityController { | @@ -83,20 +96,24 @@ public class PointActivityController { | ||
| 83 | @PreAuthorize("@ss.hasPermission('promotion:point-activity:query')") | 96 | @PreAuthorize("@ss.hasPermission('promotion:point-activity:query')") |
| 84 | public CommonResult<PageResult<PointActivityRespVO>> getPointActivityPage(@Valid PointActivityPageReqVO pageReqVO) { | 97 | public CommonResult<PageResult<PointActivityRespVO>> getPointActivityPage(@Valid PointActivityPageReqVO pageReqVO) { |
| 85 | PageResult<PointActivityDO> pageResult = pointActivityService.getPointActivityPage(pageReqVO); | 98 | PageResult<PointActivityDO> pageResult = pointActivityService.getPointActivityPage(pageReqVO); |
| 86 | - return success(BeanUtils.toBean(pageResult, PointActivityRespVO.class)); | ||
| 87 | - } | 99 | + if (CollUtil.isEmpty(pageResult.getList())) { |
| 100 | + return success(PageResult.empty(pageResult.getTotal())); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + // 拼接数据 | ||
| 104 | + List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds( | ||
| 105 | + convertSet(pageResult.getList(), PointActivityDO::getId)); | ||
| 106 | + Map<Long, List<PointProductDO>> productsMap = convertMultiMap(products, PointProductDO::getActivityId); | ||
| 107 | + Map<Long, ProductSpuRespDTO> spuMap = productSpuApi.getSpusMap( | ||
| 108 | + convertSet(pageResult.getList(), PointActivityDO::getSpuId)); | ||
| 109 | + PageResult<PointActivityRespVO> result = BeanUtils.toBean(pageResult, PointActivityRespVO.class); | ||
| 110 | + result.getList().forEach(activity -> { | ||
| 111 | + activity.setProducts(BeanUtils.toBean(productsMap.get(activity.getId()), PointProductRespVO.class)); | ||
| 112 | + MapUtils.findAndThen(spuMap, activity.getSpuId(), | ||
| 113 | + spu -> activity.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); | ||
| 88 | 114 | ||
| 89 | - @GetMapping("/export-excel") | ||
| 90 | - @Operation(summary = "导出积分商城活动 Excel") | ||
| 91 | - @PreAuthorize("@ss.hasPermission('promotion:point-activity:export')") | ||
| 92 | - @ApiAccessLog(operateType = EXPORT) | ||
| 93 | - public void exportPointActivityExcel(@Valid PointActivityPageReqVO pageReqVO, | ||
| 94 | - HttpServletResponse response) throws IOException { | ||
| 95 | - pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | ||
| 96 | - List<PointActivityDO> list = pointActivityService.getPointActivityPage(pageReqVO).getList(); | ||
| 97 | - // 导出 Excel | ||
| 98 | - ExcelUtils.write(response, "积分商城活动.xls", "数据", PointActivityRespVO.class, | ||
| 99 | - BeanUtils.toBean(list, PointActivityRespVO.class)); | 115 | + }); |
| 116 | + return success(result); | ||
| 100 | } | 117 | } |
| 101 | 118 | ||
| 102 | } | 119 | } |
| 103 | \ No newline at end of file | 120 | \ No newline at end of file |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivityRespVO.java
| 1 | package cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity; | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product.PointProductSaveReqVO; | 3 | +import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product.PointProductRespVO; |
| 4 | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | 4 | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
| 5 | import com.alibaba.excel.annotation.ExcelProperty; | 5 | import com.alibaba.excel.annotation.ExcelProperty; |
| 6 | import io.swagger.v3.oas.annotations.media.Schema; | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| @@ -39,7 +39,7 @@ public class PointActivityRespVO { | @@ -39,7 +39,7 @@ public class PointActivityRespVO { | ||
| 39 | private LocalDateTime createTime; | 39 | private LocalDateTime createTime; |
| 40 | 40 | ||
| 41 | @Schema(description = "积分商城商品", requiredMode = Schema.RequiredMode.REQUIRED) | 41 | @Schema(description = "积分商城商品", requiredMode = Schema.RequiredMode.REQUIRED) |
| 42 | - private List<PointProductSaveReqVO> products; | 42 | + private List<PointProductRespVO> products; |
| 43 | 43 | ||
| 44 | // ========== 商品字段 ========== | 44 | // ========== 商品字段 ========== |
| 45 | 45 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/activity/PointActivitySaveReqVO.java
| @@ -18,10 +18,6 @@ public class PointActivitySaveReqVO { | @@ -18,10 +18,6 @@ public class PointActivitySaveReqVO { | ||
| 18 | @NotNull(message = "积分商城活动商品不能为空") | 18 | @NotNull(message = "积分商城活动商品不能为空") |
| 19 | private Long spuId; | 19 | private Long spuId; |
| 20 | 20 | ||
| 21 | - @Schema(description = "活动状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ||
| 22 | - @NotNull(message = "活动状态不能为空") | ||
| 23 | - private Integer status; | ||
| 24 | - | ||
| 25 | @Schema(description = "备注", example = "你说的对") | 21 | @Schema(description = "备注", example = "你说的对") |
| 26 | private String remark; | 22 | private String remark; |
| 27 | 23 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/vo/product/PointProductRespVO.java
| 1 | package cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product; | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.point.vo.product; |
| 2 | 2 | ||
| 3 | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | 3 | import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; |
| 4 | -import com.alibaba.excel.annotation.ExcelProperty; | ||
| 5 | import io.swagger.v3.oas.annotations.media.Schema; | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 6 | import lombok.Data; | 5 | import lombok.Data; |
| 7 | 6 | ||
| 8 | -import java.time.LocalDateTime; | ||
| 9 | - | ||
| 10 | @Schema(description = "管理后台 - 积分商城商品 Response VO") | 7 | @Schema(description = "管理后台 - 积分商城商品 Response VO") |
| 11 | @Data | 8 | @Data |
| 12 | @ExcelIgnoreUnannotated | 9 | @ExcelIgnoreUnannotated |
| 13 | public class PointProductRespVO { | 10 | public class PointProductRespVO { |
| 14 | 11 | ||
| 15 | @Schema(description = "积分商城商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31718") | 12 | @Schema(description = "积分商城商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31718") |
| 16 | - @ExcelProperty("积分商城商品编号") | ||
| 17 | private Long id; | 13 | private Long id; |
| 18 | 14 | ||
| 19 | @Schema(description = "积分商城活动 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "29388") | 15 | @Schema(description = "积分商城活动 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "29388") |
| 20 | - @ExcelProperty("积分商城活动 id") | ||
| 21 | private Long activityId; | 16 | private Long activityId; |
| 22 | 17 | ||
| 23 | @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8112") | 18 | @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8112") |
| 24 | - @ExcelProperty("商品 SPU 编号") | ||
| 25 | private Long spuId; | 19 | private Long spuId; |
| 26 | 20 | ||
| 27 | @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2736") | 21 | @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2736") |
| 28 | - @ExcelProperty("商品 SKU 编号") | ||
| 29 | private Long skuId; | 22 | private Long skuId; |
| 30 | 23 | ||
| 31 | @Schema(description = "可兑换数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "3926") | 24 | @Schema(description = "可兑换数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "3926") |
| 32 | - @ExcelProperty("可兑换数量") | ||
| 33 | - private Integer maxCount; | 25 | + private Integer count; |
| 34 | 26 | ||
| 35 | @Schema(description = "兑换积分", requiredMode = Schema.RequiredMode.REQUIRED) | 27 | @Schema(description = "兑换积分", requiredMode = Schema.RequiredMode.REQUIRED) |
| 36 | - @ExcelProperty("兑换积分") | ||
| 37 | private Integer point; | 28 | private Integer point; |
| 38 | 29 | ||
| 39 | @Schema(description = "兑换金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "15860") | 30 | @Schema(description = "兑换金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "15860") |
| 40 | - @ExcelProperty("兑换金额,单位:分") | ||
| 41 | private Integer price; | 31 | private Integer price; |
| 42 | 32 | ||
| 43 | - @Schema(description = "兑换类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ||
| 44 | - @ExcelProperty("兑换类型") | ||
| 45 | - private Integer type; | 33 | + @Schema(description = "积分商城商品库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") |
| 34 | + private Integer stock; | ||
| 46 | 35 | ||
| 47 | @Schema(description = "积分商城商品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | 36 | @Schema(description = "积分商城商品状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") |
| 48 | - @ExcelProperty("积分商城商品状态") | ||
| 49 | private Integer activityStatus; | 37 | private Integer activityStatus; |
| 50 | 38 | ||
| 51 | - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 52 | - @ExcelProperty("创建时间") | ||
| 53 | - private LocalDateTime createTime; | ||
| 54 | - | ||
| 55 | } | 39 | } |
| 56 | \ No newline at end of file | 40 | \ No newline at end of file |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/point/PointActivityService.java
| @@ -4,8 +4,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | @@ -4,8 +4,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityPageReqVO; | 4 | import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityPageReqVO; |
| 5 | import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivitySaveReqVO; | 5 | import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivitySaveReqVO; |
| 6 | import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointActivityDO; | 6 | import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointActivityDO; |
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointProductDO; | ||
| 7 | import jakarta.validation.Valid; | 8 | import jakarta.validation.Valid; |
| 8 | 9 | ||
| 10 | +import java.util.Collection; | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 9 | /** | 13 | /** |
| 10 | * 积分商城活动 Service 接口 | 14 | * 积分商城活动 Service 接口 |
| 11 | * | 15 | * |
| @@ -58,4 +62,12 @@ public interface PointActivityService { | @@ -58,4 +62,12 @@ public interface PointActivityService { | ||
| 58 | */ | 62 | */ |
| 59 | PageResult<PointActivityDO> getPointActivityPage(PointActivityPageReqVO pageReqVO); | 63 | PageResult<PointActivityDO> getPointActivityPage(PointActivityPageReqVO pageReqVO); |
| 60 | 64 | ||
| 65 | + /** | ||
| 66 | + * 获得活动商品 | ||
| 67 | + * | ||
| 68 | + * @param activityIds 活动编号 | ||
| 69 | + * @return 获得活动商品 | ||
| 70 | + */ | ||
| 71 | + List<PointProductDO> getPointProductListByActivityIds(Collection<Long> activityIds); | ||
| 72 | + | ||
| 61 | } | 73 | } |
| 62 | \ No newline at end of file | 74 | \ No newline at end of file |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/point/PointActivityServiceImpl.java
| @@ -17,8 +17,10 @@ import cn.iocoder.yudao.module.promotion.dal.mysql.point.PointActivityMapper; | @@ -17,8 +17,10 @@ import cn.iocoder.yudao.module.promotion.dal.mysql.point.PointActivityMapper; | ||
| 17 | import cn.iocoder.yudao.module.promotion.dal.mysql.point.PointProductMapper; | 17 | import cn.iocoder.yudao.module.promotion.dal.mysql.point.PointProductMapper; |
| 18 | import jakarta.annotation.Resource; | 18 | import jakarta.annotation.Resource; |
| 19 | import org.springframework.stereotype.Service; | 19 | import org.springframework.stereotype.Service; |
| 20 | +import org.springframework.transaction.annotation.Transactional; | ||
| 20 | import org.springframework.validation.annotation.Validated; | 21 | import org.springframework.validation.annotation.Validated; |
| 21 | 22 | ||
| 23 | +import java.util.Collection; | ||
| 22 | import java.util.List; | 24 | import java.util.List; |
| 23 | import java.util.Map; | 25 | import java.util.Map; |
| 24 | 26 | ||
| @@ -51,7 +53,14 @@ public class PointActivityServiceImpl implements PointActivityService { | @@ -51,7 +53,14 @@ public class PointActivityServiceImpl implements PointActivityService { | ||
| 51 | @Resource | 53 | @Resource |
| 52 | private ProductSkuApi productSkuApi; | 54 | private ProductSkuApi productSkuApi; |
| 53 | 55 | ||
| 56 | + private static List<PointProductDO> buildPointProductDO(PointActivityDO pointActivity, List<PointProductSaveReqVO> products) { | ||
| 57 | + return BeanUtils.toBean(products, PointProductDO.class, product -> | ||
| 58 | + product.setSpuId(pointActivity.getSpuId()).setActivityId(pointActivity.getId()) | ||
| 59 | + .setActivityStatus(pointActivity.getStatus())); | ||
| 60 | + } | ||
| 61 | + | ||
| 54 | @Override | 62 | @Override |
| 63 | + @Transactional(rollbackFor = Exception.class) | ||
| 55 | public Long createPointActivity(PointActivitySaveReqVO createReqVO) { | 64 | public Long createPointActivity(PointActivitySaveReqVO createReqVO) { |
| 56 | // 1.1 校验商品是否存在 | 65 | // 1.1 校验商品是否存在 |
| 57 | validateProductExists(createReqVO.getSpuId(), createReqVO.getProducts()); | 66 | validateProductExists(createReqVO.getSpuId(), createReqVO.getProducts()); |
| @@ -69,12 +78,8 @@ public class PointActivityServiceImpl implements PointActivityService { | @@ -69,12 +78,8 @@ public class PointActivityServiceImpl implements PointActivityService { | ||
| 69 | return pointActivity.getId(); | 78 | return pointActivity.getId(); |
| 70 | } | 79 | } |
| 71 | 80 | ||
| 72 | - private static List<PointProductDO> buildPointProductDO(PointActivityDO pointActivity, List<PointProductSaveReqVO> products) { | ||
| 73 | - return BeanUtils.toBean(products, PointProductDO.class, product -> | ||
| 74 | - product.setActivityId(pointActivity.getId()).setActivityStatus(pointActivity.getStatus())); | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | @Override | 81 | @Override |
| 82 | + @Transactional(rollbackFor = Exception.class) | ||
| 78 | public void updatePointActivity(PointActivitySaveReqVO updateReqVO) { | 83 | public void updatePointActivity(PointActivitySaveReqVO updateReqVO) { |
| 79 | // 1.1 校验存在 | 84 | // 1.1 校验存在 |
| 80 | PointActivityDO activity = validatePointActivityExists(updateReqVO.getId()); | 85 | PointActivityDO activity = validatePointActivityExists(updateReqVO.getId()); |
| @@ -98,6 +103,7 @@ public class PointActivityServiceImpl implements PointActivityService { | @@ -98,6 +103,7 @@ public class PointActivityServiceImpl implements PointActivityService { | ||
| 98 | } | 103 | } |
| 99 | 104 | ||
| 100 | @Override | 105 | @Override |
| 106 | + @Transactional(rollbackFor = Exception.class) | ||
| 101 | public void closePointActivity(Long id) { | 107 | public void closePointActivity(Long id) { |
| 102 | // 校验存在 | 108 | // 校验存在 |
| 103 | PointActivityDO pointActivity = validatePointActivityExists(id); | 109 | PointActivityDO pointActivity = validatePointActivityExists(id); |
| @@ -143,6 +149,7 @@ public class PointActivityServiceImpl implements PointActivityService { | @@ -143,6 +149,7 @@ public class PointActivityServiceImpl implements PointActivityService { | ||
| 143 | } | 149 | } |
| 144 | 150 | ||
| 145 | @Override | 151 | @Override |
| 152 | + @Transactional(rollbackFor = Exception.class) | ||
| 146 | public void deletePointActivity(Long id) { | 153 | public void deletePointActivity(Long id) { |
| 147 | // 校验存在 | 154 | // 校验存在 |
| 148 | PointActivityDO pointActivity = validatePointActivityExists(id); | 155 | PointActivityDO pointActivity = validatePointActivityExists(id); |
| @@ -227,4 +234,9 @@ public class PointActivityServiceImpl implements PointActivityService { | @@ -227,4 +234,9 @@ public class PointActivityServiceImpl implements PointActivityService { | ||
| 227 | return pointActivityMapper.selectPage(pageReqVO); | 234 | return pointActivityMapper.selectPage(pageReqVO); |
| 228 | } | 235 | } |
| 229 | 236 | ||
| 237 | + @Override | ||
| 238 | + public List<PointProductDO> getPointProductListByActivityIds(Collection<Long> activityIds) { | ||
| 239 | + return pointProductMapper.selectListByActivityId(activityIds); | ||
| 240 | + } | ||
| 241 | + | ||
| 230 | } | 242 | } |
| 231 | \ No newline at end of file | 243 | \ No newline at end of file |