From f44a6d49d7ce95a45a01bdb93675a583bfe0f850 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 7 May 2019 20:23:20 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BF=83=E9=94=80=E6=B4=BB=E5=8A=A8=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/biz/service/CartServiceImpl.java | 15 +---- .../AdminsProductRecommendController.java | 4 +- .../AdminsPromotionActivityController.java | 58 +++++++++++++++++++ .../api/PromotionActivityService.java | 11 ++-- .../api/bo/PromotionActivityPageBO.java | 24 ++++++++ .../api/dto/PromotionActivityPageDTO.java | 37 ++++++++++++ .../biz/dao/PromotionActivityMapper.java | 12 +++- .../service/PromotionActivityServiceImpl.java | 29 ++++++++-- .../mapper/PromotionActivityMapper.xml | 50 ++++++++-------- 9 files changed, 192 insertions(+), 48 deletions(-) create mode 100644 promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsPromotionActivityController.java create mode 100644 promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/PromotionActivityPageBO.java create mode 100644 promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/PromotionActivityPageDTO.java diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java index 0719ef374..51203a125 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java @@ -158,13 +158,9 @@ public class CartServiceImpl implements CartService { } // TODO 库存相关 // 查询促销活动 - CommonResult> activityListResult = promotionActivityService.getPromotionActivityListBySpuIds( + List activityList = promotionActivityService.getPromotionActivityListBySpuIds( skus.stream().map(sku -> sku.getSpu().getId()).collect(Collectors.toSet()), Collections.singletonList(PromotionActivityStatusEnum.RUN.getValue())); - if (activityListResult.isError()) { - return CommonResult.error(activityListResult); - } - List activityList = activityListResult.getData(); // 拼装结果(主要是计算价格) CalcOrderPriceBO calcOrderPriceBO = new CalcOrderPriceBO(); // 1. 创建初始的每一项的数组 @@ -208,14 +204,9 @@ public class CartServiceImpl implements CartService { return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); } // 查询促销活动 - CommonResult> activityListResult = promotionActivityService.getPromotionActivityListBySpuId(sku.getSpuId(), + List activityList = promotionActivityService.getPromotionActivityListBySpuId(sku.getSpuId(), Arrays.asList(PromotionActivityStatusEnum.WAIT.getValue(), PromotionActivityStatusEnum.RUN.getValue())); - if (activityListResult.isError()) { - return CommonResult.error(activityListResult); - } - // 如果无促销活动,则直接返回默认结果即可 - List activityList = activityListResult.getData(); - if (activityList.isEmpty()) { + if (activityList.isEmpty()) { // 如果无促销活动,则直接返回默认结果即可 return CommonResult.success(new CalcSkuPriceBO().setOriginalPrice(sku.getPrice()).setBuyPrice(sku.getPrice())); } // 如果有促销活动,则开始做计算 TODO 芋艿,因为现在暂时只有限时折扣 + 满减送。所以写的比较简单先 diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java index 7f117ec7c..245e67d13 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java @@ -44,8 +44,8 @@ public class AdminsProductRecommendController { @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), }) public CommonResult page(@RequestParam(value = "type", required = false) Integer type, - @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, - @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { ProductRecommendPageBO result = productRecommendService.getProductRecommendPage(new ProductRecommendPageDTO().setType(type).setPageNo(pageNo).setPageSize(pageSize)); // 获得商品集合 List spus = productSpuService.getProductSpuList( diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsPromotionActivityController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsPromotionActivityController.java new file mode 100644 index 000000000..8071b1a84 --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsPromotionActivityController.java @@ -0,0 +1,58 @@ +package cn.iocoder.mall.promotion.application.controller.admins; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.promotion.api.PromotionActivityService; +import cn.iocoder.mall.promotion.api.bo.PromotionActivityPageBO; +import cn.iocoder.mall.promotion.api.constant.PromotionActivityStatusEnum; +import cn.iocoder.mall.promotion.api.dto.PromotionActivityPageDTO; +import io.swagger.annotations.Api; +import org.apache.dubbo.config.annotation.Reference; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Arrays; +import java.util.Collections; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +@RestController +@RequestMapping("admins/promotion_activity") +@Api("促销活动模块") +public class AdminsPromotionActivityController { + + @Reference(validation = "true", version = "${dubbo.provider.PromotionActivityService.version}") + private PromotionActivityService promotionActivityService; + + @GetMapping("/page") // TODO 芋艿,BO => VO + public CommonResult page(@RequestParam("title") String title, + @RequestParam("activityType") Integer activityType, + @RequestParam(value = "status") String status, + @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + PromotionActivityPageDTO promotionActivityPageDTO = new PromotionActivityPageDTO() + .setTitle(title).setActivityType(activityType).setPageNo(pageNo).setPageSize(pageSize); + switch (status) { + case "WAIT": + promotionActivityPageDTO.setStatuses(Collections.singleton(PromotionActivityStatusEnum.WAIT.getValue())); + break; + case "RUN": + promotionActivityPageDTO.setStatuses(Collections.singleton(PromotionActivityStatusEnum.RUN.getValue())); + break; + case "END": + promotionActivityPageDTO.setStatuses(Collections.singleton(PromotionActivityStatusEnum.END.getValue())); + break; + case "INVALID": + promotionActivityPageDTO.setStatuses(Collections.singleton(PromotionActivityStatusEnum.INVALID.getValue())); + break; + default: + promotionActivityPageDTO.setStatuses(Arrays.asList(PromotionActivityStatusEnum.WAIT.getValue(), + PromotionActivityStatusEnum.RUN.getValue(), PromotionActivityStatusEnum.END.getValue(), + PromotionActivityStatusEnum.INVALID.getValue())); + } + // 执行查询 + return success(promotionActivityService.getPromotionActivityPage(promotionActivityPageDTO)); + } + +} diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/PromotionActivityService.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/PromotionActivityService.java index 63bc91b91..94fa9e0eb 100644 --- a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/PromotionActivityService.java +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/PromotionActivityService.java @@ -1,17 +1,20 @@ package cn.iocoder.mall.promotion.api; -import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.promotion.api.bo.PromotionActivityBO; +import cn.iocoder.mall.promotion.api.bo.PromotionActivityPageBO; +import cn.iocoder.mall.promotion.api.dto.PromotionActivityPageDTO; import java.util.Collection; import java.util.List; public interface PromotionActivityService { - CommonResult> getPromotionActivityListBySpuId(Integer spuId, + List getPromotionActivityListBySpuId(Integer spuId, Collection activityStatuses); - CommonResult> getPromotionActivityListBySpuIds(Collection spuIds, - Collection activityStatuses); + List getPromotionActivityListBySpuIds(Collection spuIds, + Collection activityStatuses); + + PromotionActivityPageBO getPromotionActivityPage(PromotionActivityPageDTO promotionActivityPageDTO); } diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/PromotionActivityPageBO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/PromotionActivityPageBO.java new file mode 100644 index 000000000..dfd227fb1 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/PromotionActivityPageBO.java @@ -0,0 +1,24 @@ +package cn.iocoder.mall.promotion.api.bo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.List; + +/** + * 促销活动分页 BO + */ +@Data +@Accessors(chain = true) +public class PromotionActivityPageBO { + + /** + * PromotionActivityBO 数组 + */ + private List list; + /** + * 总量 + */ + private Integer total; + +} diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/PromotionActivityPageDTO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/PromotionActivityPageDTO.java new file mode 100644 index 000000000..c2f06ff0c --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/PromotionActivityPageDTO.java @@ -0,0 +1,37 @@ +package cn.iocoder.mall.promotion.api.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.Collection; + +/** + * 商品推荐分页 DTO + */ +@Data +@Accessors(chain = true) +public class PromotionActivityPageDTO implements Serializable { + + /** + * 标题 + * + * 模糊匹配 + */ + private String title; + /** + * 活动类型 + */ + private Integer activityType; + /** + * 状态 + */ + private Collection statuses; + + @NotNull(message = "页码不能为空") + private Integer pageNo; + @NotNull(message = "每页条数不能为空") + private Integer pageSize; + +} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/PromotionActivityMapper.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/PromotionActivityMapper.java index 24b0dd0f0..fd5ba7fdf 100644 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/PromotionActivityMapper.java +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/PromotionActivityMapper.java @@ -12,8 +12,18 @@ public interface PromotionActivityMapper { PromotionActivityDO selectById(@Param("id") Integer id); - List selectListByStatus(@Param("statuses")Collection statuses); + List selectListByStatus(@Param("statuses") Collection statuses); void insert(PromotionActivityDO activity); + List selectListByPage(@Param("title") String title, + @Param("activityType") Integer activityType, + @Param("statuses") Collection statuses, + @Param("offset") Integer offset, + @Param("limit") Integer limit); + + Integer selectCountByPage(@Param("title") String title, + @Param("activityType") Integer activityType, + @Param("statuses") Collection statuses); + } diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/PromotionActivityServiceImpl.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/PromotionActivityServiceImpl.java index a2afb8131..3e84a1de3 100644 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/PromotionActivityServiceImpl.java +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/PromotionActivityServiceImpl.java @@ -1,10 +1,11 @@ package cn.iocoder.mall.promotion.biz.service; -import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.promotion.api.PromotionActivityService; import cn.iocoder.mall.promotion.api.bo.PromotionActivityBO; +import cn.iocoder.mall.promotion.api.bo.PromotionActivityPageBO; import cn.iocoder.mall.promotion.api.constant.PromotionActivityTypeEnum; import cn.iocoder.mall.promotion.api.constant.RangeTypeEnum; +import cn.iocoder.mall.promotion.api.dto.PromotionActivityPageDTO; import cn.iocoder.mall.promotion.biz.convert.PromotionActivityConvert; import cn.iocoder.mall.promotion.biz.dao.PromotionActivityMapper; import cn.iocoder.mall.promotion.biz.dataobject.PromotionActivityDO; @@ -25,19 +26,19 @@ public class PromotionActivityServiceImpl implements PromotionActivityService { private PromotionActivityMapper promotionActivityMapper; @Override - public CommonResult> getPromotionActivityListBySpuId(Integer spuId, Collection activityStatuses) { + public List getPromotionActivityListBySpuId(Integer spuId, Collection activityStatuses) { return this.getPromotionActivityListBySpuIds(Collections.singleton(spuId), activityStatuses); } @Override - public CommonResult> getPromotionActivityListBySpuIds(Collection spuIds, Collection activityStatuses) { + public List getPromotionActivityListBySpuIds(Collection spuIds, Collection activityStatuses) { if (spuIds.isEmpty() || activityStatuses.isEmpty()) { - return CommonResult.success(Collections.emptyList()); + return Collections.emptyList(); } // 查询指定状态的促销活动 List activityList = promotionActivityMapper.selectListByStatus(activityStatuses); if (activityList.isEmpty()) { - return CommonResult.success(Collections.emptyList()); + return Collections.emptyList(); } // 匹配商品 for (Iterator iterator = activityList.iterator(); iterator.hasNext();) { @@ -64,7 +65,23 @@ public class PromotionActivityServiceImpl implements PromotionActivityService { } } // 返回最终结果 - return CommonResult.success(PromotionActivityConvert.INSTANCE.convertToBO(activityList)); + return PromotionActivityConvert.INSTANCE.convertToBO(activityList); + } + + @Override + public PromotionActivityPageBO getPromotionActivityPage(PromotionActivityPageDTO promotionActivityPageDTO) { + PromotionActivityPageBO promotionActivityPageBO = new PromotionActivityPageBO(); + // 查询分页数据 + int offset = (promotionActivityPageDTO.getPageNo() - 1) * promotionActivityPageDTO.getPageSize(); + promotionActivityPageBO.setList(PromotionActivityConvert.INSTANCE.convertToBO(promotionActivityMapper.selectListByPage( + promotionActivityPageDTO.getTitle(), promotionActivityPageDTO.getActivityType(), + promotionActivityPageDTO.getStatuses(), + offset, promotionActivityPageDTO.getPageSize()))); + // 查询分页总数 + promotionActivityPageBO.setTotal(promotionActivityMapper.selectCountByPage( + promotionActivityPageDTO.getTitle(), promotionActivityPageDTO.getActivityType(), + promotionActivityPageDTO.getStatuses())); + return promotionActivityPageBO; } private boolean isSpuMatchTimeLimitDiscount(Integer spuId, PromotionActivityDO activity) { diff --git a/promotion/promotion-service-impl/src/main/resources/mapper/PromotionActivityMapper.xml b/promotion/promotion-service-impl/src/main/resources/mapper/PromotionActivityMapper.xml index afc40c6a4..4518b97f1 100644 --- a/promotion/promotion-service-impl/src/main/resources/mapper/PromotionActivityMapper.xml +++ b/promotion/promotion-service-impl/src/main/resources/mapper/PromotionActivityMapper.xml @@ -59,30 +59,34 @@ - - - - - - - - - - - - + - - - - - - - - - - - + INSERT INTO promotion_activity (