From 5b3c464fafd55ee4ef15e165adc3fcd7730ae8aa Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Thu, 20 Aug 2020 19:47:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=8A=B5=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/constant/AdminErrorCodeEnum.java | 85 ------- .../controller/cart/UsersCartController.java | 72 ------ .../order/UsersOrderController.java | 20 +- .../mall/order/rest/convert/CartConvert.java | 30 --- .../order/rest/convert/OrderConvertAPP.java | 46 ---- .../rest/convert/OrderDeliveryConvert.java | 17 -- .../rest/convert/OrderReturnConvert.java | 22 -- order/order-rest/src/main/resources/rest.yaml | 12 - .../iocoder/mall/order/api/CartService.java | 17 -- .../mall/order/api/bo/CalcSkuPriceBO.java | 33 --- .../iocoder/mall/order/api/bo/CartItemBO.java | 100 -------- .../mall/order/api/dto/CalcOrderPriceDTO.java | 57 ----- .../biz/config/DatabaseConfiguration.java | 12 - .../config/ServiceExceptionConfiguration.java | 20 -- .../mall/order/biz/convert/CartConvert.java | 21 -- .../order/biz/service/CartServiceImpl.java | 54 ----- .../PromotionActivityStatusEnum.java | 2 +- .../PromotionActivityTypeEnum.java | 2 +- .../card}/CouponCardStatusEnum.java | 2 +- .../card}/CouponCardTakeTypeEnum.java | 2 +- .../template}/CouponTemplateDateTypeEnum.java | 2 +- .../template}/CouponTemplateStatusEnum.java | 2 +- .../template}/CouponTemplateTypeEnum.java | 2 +- .../ProductRecommendTypeEnum.java | 2 +- .../dto/PromotionActivityRespDTO.java | 6 +- .../api/rpc/coupon/CouponCardRpc.java | 54 +++++ .../promotion/api/rpc/coupon/CouponRpc.java | 68 +----- .../coupon/dto/CouponCardDetailRespDTO.java | 143 ------------ .../rpc/coupon/dto/CouponCardPageReqDTO.java | 30 --- .../rpc/coupon/dto/CouponCardPageRespDTO.java | 25 -- .../api/rpc/coupon/dto/CouponCardReqDTO.java | 112 --------- .../dto/CouponCardTemplateAddReqDTO.java | 2 +- .../card/CouponCardAvailableListReqDTO.java | 68 ++++++ .../CouponCardAvailableRespDTO.java | 6 +- .../dto/card/CouponCardCancelUseReqDTO.java | 27 +++ .../dto/card/CouponCardCreateReqDTO.java | 27 +++ .../coupon/dto/card/CouponCardPageReqDTO.java | 25 ++ .../coupon/dto/card/CouponCardUseReqDTO.java | 27 +++ .../rpc/price/dto/PriceProductCalcReqDTO.java | 1 - .../price/dto/PriceProductCalcRespDTO.java | 2 +- .../dto/ProductRecommendAddReqDTO.java | 2 +- .../dto/ProductRecommendRespDTO.java | 2 +- .../dto/ProductRecommendUpdateReqDTO.java | 2 +- .../convert/coupon/CouponCardConvert.java | 35 --- .../coupon/card/CouponCardConvert.java | 11 + .../activity/PromotionActivityDO.java | 6 +- .../mysql/dataobject/coupon/CouponCardDO.java | 4 + .../dataobject/coupon/CouponTemplateDO.java | 7 +- .../recommend/ProductRecommendDO.java | 2 +- .../mysql/mapper/coupon/CouponCardMapper.java | 46 ++-- .../mapper/coupon/CouponTemplateMapper.java | 20 +- .../coupon/card/CouponCardManager.java | 41 ++++ .../manager/price/PriceManager.java | 2 + .../rpc/coupon/CouponCardRpcImpl.java | 46 ++++ .../activity/PromotionActivityService.java | 2 +- .../activity/bo/PromotionActivityBO.java | 6 +- .../service/coupon/CouponCardService.java | 219 ++++++++++++++++- .../service/coupon/CouponService.java | 217 +---------------- .../coupon/bo/CouponCardAvailableBO.java | 25 -- .../service/coupon/bo/CouponCardDetailBO.java | 143 ------------ .../service/coupon/bo/CouponCardPageBO.java | 26 --- .../service/coupon/bo/CouponCardSpuBO.java | 40 ---- .../coupon/bo/CouponCardTemplateAddBO.java | 2 +- .../recommend/bo/ProductRecommendAddBO.java | 2 +- .../recommend/bo/ProductRecommendBO.java | 2 +- .../bo/ProductRecommendUpdateBO.java | 2 +- .../resources/mapper/CouponTemplateMapper.xml | 12 + .../activity/PromotionActivityMapperTest.java | 2 +- .../promotion/biz/dao/CouponCardMapper.java | 36 --- .../biz/dao/CouponTemplateMapper.java | 35 --- .../biz/dataobject/CouponCardDO.java | 119 ---------- .../biz/dataobject/CouponCodeDO.java | 43 ---- .../biz/dataobject/CouponTemplateDO.java | 220 ------------------ .../promotion/biz/mybatis/TestHandler.java | 12 - .../biz/scheduler/CouponCardExpireJob.java | 9 - .../main/resources/config/application.yaml | 76 ------ .../resources/mapper/CouponCardMapper.xml | 134 ----------- .../resources/mapper/CouponTemplateMapper.xml | 169 -------------- .../mall/promotion/biz/Application.java | 7 - .../biz/dao/PromotionActivityMapperTest.java | 94 -------- .../application/PromotionApplication.java | 13 -- .../convert/CouponCardConvert.java | 28 --- .../convert/CouponTemplateConvert.java | 43 ---- .../vo/users/UsersCouponCardPageVO.java | 20 -- .../controller/order/CartController.java | 2 +- .../controller/order/OrderController.http | 11 + .../controller/order/OrderController.java | 49 ++++ .../order/vo/cart/CartDetailVO.java | 2 +- .../order/OrderConfirmCreateInfoRespVO.java | 45 ++-- .../product/ProductSkuController.http | 5 + .../product/ProductSkuController.java | 33 +++ .../vo/sku/ProductSkuCalcPriceRespVO.java | 35 +++ .../promotion/CouponCardController.http | 23 ++ .../promotion/CouponCardController.java | 43 ++++ .../vo/coupon/card/CouponCardPageReqVO.java | 17 ++ .../vo/coupon/card/CouponCardRespVO.java | 11 +- .../shopweb/convert/order/OrderConvert.java | 33 +++ .../convert/product/ProductSkuConvert.java | 20 ++ .../convert/promotion/CouponCardConvert.java | 23 ++ .../enums/ShopWebErrorCodeConstants.java | 16 ++ .../manager/order/{cart => }/CartManager.java | 6 +- .../shopweb/manager/order/OrderManager.java | 160 +++++++++++++ .../manager/product/ProductSkuManager.java | 60 +++++ .../manager/promotion/CouponCardManager.java | 51 ++++ .../src/main/resources/application.yml | 4 + ...ontroller.java => PassportController.java} | 8 +- 106 files changed, 1277 insertions(+), 2621 deletions(-) delete mode 100644 moved/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/AdminErrorCodeEnum.java delete mode 100644 order/order-rest/src/main/java/cn/iocoder/mall/order/rest/controller/cart/UsersCartController.java delete mode 100644 order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/CartConvert.java delete mode 100644 order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderConvertAPP.java delete mode 100644 order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderDeliveryConvert.java delete mode 100644 order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderReturnConvert.java delete mode 100644 order/order-rest/src/main/resources/rest.yaml delete mode 100644 order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/CartService.java delete mode 100644 order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/bo/CalcSkuPriceBO.java delete mode 100644 order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/bo/CartItemBO.java delete mode 100644 order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/dto/CalcOrderPriceDTO.java delete mode 100644 order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/DatabaseConfiguration.java delete mode 100644 order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/ServiceExceptionConfiguration.java delete mode 100644 order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/CartConvert.java delete mode 100644 order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java rename promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/{ => activity}/PromotionActivityStatusEnum.java (93%) rename promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/{ => activity}/PromotionActivityTypeEnum.java (90%) rename promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/{ => coupon/card}/CouponCardStatusEnum.java (93%) rename promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/{ => coupon/card}/CouponCardTakeTypeEnum.java (93%) rename promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/{ => coupon/template}/CouponTemplateDateTypeEnum.java (92%) rename promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/{ => coupon/template}/CouponTemplateStatusEnum.java (93%) rename promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/{ => coupon/template}/CouponTemplateTypeEnum.java (90%) rename promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/{ => recommend}/ProductRecommendTypeEnum.java (94%) create mode 100644 promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/CouponCardRpc.java delete mode 100644 promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardDetailRespDTO.java delete mode 100644 promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardPageReqDTO.java delete mode 100644 promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardPageRespDTO.java delete mode 100644 promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardReqDTO.java create mode 100644 promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardAvailableListReqDTO.java rename promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/{ => card}/CouponCardAvailableRespDTO.java (65%) create mode 100644 promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardCancelUseReqDTO.java create mode 100644 promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardCreateReqDTO.java create mode 100644 promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardPageReqDTO.java create mode 100644 promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardUseReqDTO.java delete mode 100644 promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/coupon/CouponCardConvert.java create mode 100644 promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/coupon/card/CouponCardManager.java create mode 100644 promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/rpc/coupon/CouponCardRpcImpl.java delete mode 100644 promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardAvailableBO.java delete mode 100644 promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardDetailBO.java delete mode 100644 promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardPageBO.java delete mode 100644 promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardSpuBO.java create mode 100644 promotion-service-project/promotion-service-app/src/main/resources/mapper/CouponTemplateMapper.xml delete mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java delete mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponTemplateMapper.java delete mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCardDO.java delete mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCodeDO.java delete mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponTemplateDO.java delete mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/mybatis/TestHandler.java delete mode 100644 promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/scheduler/CouponCardExpireJob.java delete mode 100644 promotion/promotion-service-impl/src/main/resources/config/application.yaml delete mode 100644 promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml delete mode 100644 promotion/promotion-service-impl/src/main/resources/mapper/CouponTemplateMapper.xml delete mode 100644 promotion/promotion-service-impl/src/test/java/cn/iocoder/mall/promotion/biz/Application.java delete mode 100644 promotion/promotion-service-impl/src/test/java/cn/iocoder/mall/promotion/biz/dao/PromotionActivityMapperTest.java delete mode 100644 promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/PromotionApplication.java delete mode 100644 promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java delete mode 100644 promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponTemplateConvert.java delete mode 100644 promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardPageVO.java create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/OrderController.http create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/OrderController.java rename order/order-rest/src/main/java/cn/iocoder/mall/order/rest/response/UsersOrderConfirmCreateResponse.java => shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/vo/order/OrderConfirmCreateInfoRespVO.java (74%) create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSkuController.http create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSkuController.java create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/sku/ProductSkuCalcPriceRespVO.java create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/CouponCardController.http create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/CouponCardController.java create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/vo/coupon/card/CouponCardPageReqVO.java rename promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardVO.java => shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/vo/coupon/card/CouponCardRespVO.java (89%) create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/order/OrderConvert.java create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/product/ProductSkuConvert.java create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/promotion/CouponCardConvert.java create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/enums/ShopWebErrorCodeConstants.java rename shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/order/{cart => }/CartManager.java (98%) create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/order/OrderManager.java create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/product/ProductSkuManager.java create mode 100644 shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/promotion/CouponCardManager.java rename user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/{UserPassportController.java => PassportController.java} (86%) diff --git a/moved/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/AdminErrorCodeEnum.java b/moved/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/AdminErrorCodeEnum.java deleted file mode 100644 index 404706fa3..000000000 --- a/moved/system/system-service-api/src/main/java/cn/iocoder/mall/system/api/constant/AdminErrorCodeEnum.java +++ /dev/null @@ -1,85 +0,0 @@ -package cn.iocoder.mall.system.api.constant; - -/** - * 错误码枚举类 - * - * 管理员系统,使用 1-002-000-000 段 - */ -public enum AdminErrorCodeEnum { - - // ========== OAUTH2 模块 ========== - OAUTH2_UNKNOWN(1002001000, "未知错误"), // 预留 -// OAUTH2_INVALID_GRANT_BAD_CREDENTIALS(1001001001, "密码不正确"), // 暂时没用到 -// OAUTH2_INVALID_GRANT_USERNAME_NOT_FOUND(1001001002, "账号不存在"), // 暂时没用到 -// OAUTH2_INVALID_GRANT(1001001010, ""), // 预留 - OAUTH2_INVALID_TOKEN_NOT_FOUND(1002001011, "访问令牌不存在"), - OAUTH2_INVALID_TOKEN_EXPIRED(1002001012, "访问令牌已过期"), - OAUTH2_INVALID_TOKEN_INVALID(1002001013, "访问令牌已失效"), - OAUTH2_NOT_LOGIN(1002001015, "账号未登陆"), - OAUTH2_INVALID_TOKEN_ERROR_USER_TYPE(1002001016, "访问令牌用户类型不正确"), - OAUTH_INVALID_REFRESH_TOKEN_NOT_FOUND(1002001017, "刷新令牌不存在"), - OAUTH_INVALID_REFRESH_TOKEN_EXPIRED(1002001018, "访问令牌已过期"), - OAUTH_INVALID_REFRESH_TOKEN_INVALID(1002001019, "刷新令牌已失效"), - - // ========== 管理员模块 1002002000 ========== - ADMIN_USERNAME_NOT_REGISTERED(1002002000, "账号不存在"), - ADMIN_PASSWORD_ERROR(1002002001, "密码不正确"), - ADMIN_IS_DISABLE(1002002002, "账号被禁用"), - ADMIN_USERNAME_EXISTS(1002002002, "账号已经存在"), - ADMIN_STATUS_EQUALS(1002002003, "账号已经是该状态"), - ADMIN_DELETE_ONLY_DISABLE(1002002004, "只有关闭的账号才可以删除"), - ADMIN_ADMIN_STATUS_CAN_NOT_UPDATE(1002002005, "管理员的账号状态不允许变更"), - ADMIN_ASSIGN_ROLE_NOT_EXISTS(1002002006, "分配员工角色时,有角色不存在"), - ADMIN_INVALID_PERMISSION(1002002007, "没有该操作权限"), - ADMIN_ADMIN_CAN_NOT_UPDATE(1002002008, "管理员的账号不允许变更"), - ADMIN_DEMO_CAN_NOT_WRITE(1002002009, "演示账号,暂不允许写操作。欢迎加入我们的交流群:http://t.cn/EKEr5WE"), - - // ========== 资源模块 1002003000 ========== - RESOURCE_NAME_DUPLICATE(1002003000, "已经存在该名字的资源"), - RESOURCE_PARENT_NOT_EXISTS(1002003001, "父资源不存在"), - RESOURCE_PARENT_ERROR(1002003002, "不能设置自己为父资源"), - RESOURCE_NOT_EXISTS(1002003003, "资源不存在"), - RESOURCE_EXISTS_CHILDREN(1002003004, "存在子资源,无法删除"), - RESOURCE_PARENT_NOT_MENU(1002003005, "父资源的类型必须是菜单"), - - // ========== 角色模块 1002004000 ========== - ROLE_NOT_EXISTS(1002004000, "角色不存在"), - ROLE_ASSIGN_RESOURCE_NOT_EXISTS(1002004001, "分配角色资源时,有资源不存在"), - - // ========== 数据字典模块 1002005000 ========== - DATA_DICT_EXISTS(1002005000, "该数据字典已经存在"), - DATA_DICT_NOT_EXISTS(1002005001, "该数据字典不存在"), - - // ========== 短信模板 1002006000 ========== - SMS_PLATFORM_FAIL(1002006000, "短信平台调用失败【具体错误会动态替换】"), - SMS_SIGN_NOT_EXISTENT(1002006001, "短信签名不存在"), - SMS_SIGN_IS_EXISTENT(1002006002, "短信签名已存在"), - SMS_TEMPLATE_NOT_EXISTENT(1002006020, "短信签名不存在"), - SMS_TEMPLATE_IS_EXISTENT(1002006021, "短信签名不存在"), - SMS_NOT_SEND_CLIENT(1002006030, "短信没有发送的client"), - - // ========== 部门模块 1002007000 ========== - DEPT_SAME_LEVEL_NAME_EXITS(1002007001,"当前级别部门名字已存在"), - DEPT_PARENT_NOT_EXITS(1002007002,"父级部门不存在"), - DEPT_NOT_EXITS(1002007003, "当前部门不存在"), - DEPT_EXITS_CHILDREN(1002007004, "当前部门存在子部门"), - DEPT_PARENT_NOT_LEGAL(1002007005, "父级部门不合法"), - ; - - private final int code; - private final String message; - - AdminErrorCodeEnum(int code, String message) { - this.code = code; - this.message = message; - } - - public int getCode() { - return code; - } - - public String getMessage() { - return message; - } - -} diff --git a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/controller/cart/UsersCartController.java b/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/controller/cart/UsersCartController.java deleted file mode 100644 index b5278b047..000000000 --- a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/controller/cart/UsersCartController.java +++ /dev/null @@ -1,72 +0,0 @@ -package cn.iocoder.mall.order.rest.controller.cart; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("users/cart") -public class UsersCartController { - -// @Reference(validation = "true", version = "${dubbo.provider.CartService.version}") -// private CartService cartService; -// -// @Reference(validation = "true", version = "${dubbo.provider.OrderService.version}") -// private OrderService orderService; -// -// @Reference(validation = "true", version = "${dubbo.consumer.CouponService.version}") -// private CouponService couponService; -// - - - -// -// @GetMapping("/confirm_create_order") -// public CommonResult getConfirmCreateOrder(@RequestParam(value = "couponCardId", required = false) Integer couponCardId) { -// Integer userId = UserSecurityContextHolder.getContext().getUserId(); -// // 获得购物车中选中的 -// List cartItems = cartService.list(userId, true); -// // 购物车为空时,构造空的 UsersOrderConfirmCreateVO 返回 -// if (cartItems.isEmpty()) { -// UsersOrderConfirmCreateVO result = new UsersOrderConfirmCreateVO(); -// result.setItemGroups(Collections.emptyList()); -// result.setFee(new UsersOrderConfirmCreateVO.Fee(0, 0, 0, 0)); -// return success(result); -// } -// // 计算商品价格 -// CalcOrderPriceBO calcOrderPrice = list0(cartItems, couponCardId); -// // 获得优惠劵 -// List couponCards = couponService.getCouponCardList(userId, -// CartConvert.INSTANCE.convertList(calcOrderPrice.getItemGroups())); -// // 执行数据拼装 -// return success(CartConvert.INSTANCE.convert(calcOrderPrice).setCouponCards(couponCards)); -// } -// -// private CalcOrderPriceBO list0(List cartItems, Integer couponCardId) { -// // 创建计算的 DTO -// CalcOrderPriceDTO calcOrderPriceDTO = new CalcOrderPriceDTO() -// .setUserId(UserSecurityContextHolder.getContext().getUserId()) -// .setItems(new ArrayList<>(cartItems.size())) -// .setCouponCardId(couponCardId); -// for (CartItemBO item : cartItems) { -// calcOrderPriceDTO.getItems().add(new CalcOrderPriceDTO.Item(item.getSkuId(), item.getQuantity(), item.getSelected())); -// } -// // 执行计算 -// return cartService.calcOrderPrice(calcOrderPriceDTO); -// } -// -// @GetMapping("/calc_sku_price") -// public CommonResult calcSkuPrice(@RequestParam("skuId") Integer skuId) { -// // 计算 sku 的价格 -// CalcSkuPriceBO calcSkuPrice = cartService.calcSkuPrice(skuId); -// return success(CartConvert.INSTANCE.convert2(calcSkuPrice)); -// } -// -// public CommonResult confirmOrder() { -// // 查询购物车列表(选中的) -//// cartService.list(userId, true); -// // 查询确认订单信息的明细 -// -// return null; -// } - -} diff --git a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/controller/order/UsersOrderController.java b/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/controller/order/UsersOrderController.java index 925d8592b..3e0087f18 100644 --- a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/controller/order/UsersOrderController.java +++ b/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/controller/order/UsersOrderController.java @@ -76,25 +76,7 @@ public class UsersOrderController { // return createResult; // } // -// @GetMapping("confirm_create_order") -// @RequiresLogin -// @ApiOperation("确认创建订单") -// public CommonResult getConfirmCreateOrder(@RequestParam("skuId") Integer skuId, -// @RequestParam("quantity") Integer quantity, -// @RequestParam(value = "couponCardId", required = false) Integer couponCardId) { -// Integer userId = UserSecurityContextHolder.getContext().getUserId(); -// // 创建 CalcOrderPriceDTO 对象,并执行价格计算 -// CalcOrderPriceDTO calcOrderPriceDTO = new CalcOrderPriceDTO() -// .setUserId(userId) -// .setItems(Collections.singletonList(new CalcOrderPriceDTO.Item(skuId, quantity, true))) -// .setCouponCardId(couponCardId); -// CalcOrderPriceBO calcOrderPrice = cartService.calcOrderPrice(calcOrderPriceDTO); -// // 获得优惠劵 -// List couponCards = couponService.getCouponCardList(userId, -// CartConvert.INSTANCE.convertList(calcOrderPrice.getItemGroups())); -// // 执行数据拼装 -// return success(CartConvert.INSTANCE.convert(calcOrderPrice).setCouponCards(couponCards)); -// } + // // @PostMapping("confirm_receiving") // @RequiresLogin diff --git a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/CartConvert.java b/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/CartConvert.java deleted file mode 100644 index 432f602c4..000000000 --- a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/CartConvert.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.mall.order.rest.convert; - -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface CartConvert { - - CartConvert INSTANCE = Mappers.getMapper(CartConvert.class); - -// UsersOrderConfirmCreateVO convert(CalcOrderPriceBO calcOrderPriceBO); -// -// UsersCartDetailVO convert2(CalcOrderPriceBO calcOrderPriceBO); -// -// UsersCalcSkuPriceVO convert2(CalcSkuPriceBO calcSkuPriceBO); -// -// default List convertList(List itemGroups) { -// List items = new ArrayList<>(); -// itemGroups.forEach(itemGroup -> items.addAll(itemGroup.getItems().stream().map( -// item -> new CouponCardSpuDTO() -// .setSpuId(item.getSpu().getId()) -// .setSkuId(item.getId()) -// .setCategoryId(item.getSpu().getCid()) -// .setPrice(item.getBuyPrice()) -// .setQuantity(item.getBuyQuantity())) -// .collect(Collectors.toList()))); -// return items; -// } - -} diff --git a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderConvertAPP.java b/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderConvertAPP.java deleted file mode 100644 index 67deea991..000000000 --- a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderConvertAPP.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.iocoder.mall.order.rest.convert; - -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -/** - * application 订单 convert - * - * TODO 这种方式 文件名不能一样哈! - * - * @author Sin - * @time 2019-03-24 10:45 - */ -@Mapper -public interface OrderConvertAPP { - - OrderConvertAPP INSTANCE = Mappers.getMapper(OrderConvertAPP.class); - -// @Mappings({}) -// OrderQueryDTO convert(OrderPageQueryPO orderPageQueryVO); -// -// @Mappings({}) -// OrderLogisticsUpdateDTO convert(OrderLogisticsPO orderLogisticsVO); -// -// @Mappings({}) -// OrderItemUpdateDTO convert(OrderItemUpdatePO orderItemUpdateVO); -// -// @Mappings({}) -// OrderCreateDTO convert(OrderCreatePO orderCreatePO); -// -// @Mappings({}) -// List convert(List cartItems); -// -// default OrderCreateDTO createOrderCreateDTO(Integer userId, Integer userAddressId, -// String remark, String ip, -// List cartItems, Integer couponCardId) { -// return new OrderCreateDTO() -// .setUserId(userId) -// .setUserAddressId(userAddressId) -// .setRemark(remark) -// .setIp(ip) -// .setOrderItems(this.convert(cartItems)) -// .setCouponCardId(couponCardId); -// } - -} diff --git a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderDeliveryConvert.java b/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderDeliveryConvert.java deleted file mode 100644 index d6c8d6ec5..000000000 --- a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderDeliveryConvert.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.mall.order.rest.convert; - -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -/** - * @author Sin - * @time 2019-04-05 17:00 - */ -@Mapper -public interface OrderDeliveryConvert { - - OrderDeliveryConvert INSTANCE = Mappers.getMapper(OrderDeliveryConvert.class); - -// @Mappings({}) -// OrderDeliveryDTO convert(OrderDeliverPO orderDeliverPO); -} diff --git a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderReturnConvert.java b/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderReturnConvert.java deleted file mode 100644 index 90997321d..000000000 --- a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/convert/OrderReturnConvert.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.mall.order.rest.convert; - -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -/** - * 订单退货 - * - * @author Sin - * @time 2019-04-25 21:54 - */ -@Mapper -public interface OrderReturnConvert { - - OrderReturnConvert INSTANCE = Mappers.getMapper(OrderReturnConvert.class); - -// @Mappings({}) -// OrderReturnApplyDTO convert(OrderReturnApplyPO orderReturnApplyPO); -// -// @Mappings({}) -// OrderReturnQueryDTO convert(OrderReturnQueryPO orderReturnQueryPO); -} diff --git a/order/order-rest/src/main/resources/rest.yaml b/order/order-rest/src/main/resources/rest.yaml deleted file mode 100644 index 460ca2af0..000000000 --- a/order/order-rest/src/main/resources/rest.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# 服务器的配置项 -server: - port: 18088 - servlet: - context-path: /order-api/ - -# Swagger 配置项 -swagger: - title: 订单子系统 - description: 订单子系统 - version: 1.0.0 - base-package: cn.iocoder.mall.order.rest.controller diff --git a/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/CartService.java b/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/CartService.java deleted file mode 100644 index a7129c88c..000000000 --- a/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/CartService.java +++ /dev/null @@ -1,17 +0,0 @@ -package cn.iocoder.mall.order.api; - -import cn.iocoder.mall.order.api.bo.CalcSkuPriceBO; - -public interface CartService { - - /** - * 计算指定商品 SKU 的金额,并返回计算结果 - * - * TODO 芋艿,此处只会计算,限时折扣带来的价格变化。 - * - * @param skuId 商品 SKU 编号 - * @return 计算订单金额结果 - */ - CalcSkuPriceBO calcSkuPrice(Integer skuId); - -} diff --git a/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/bo/CalcSkuPriceBO.java b/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/bo/CalcSkuPriceBO.java deleted file mode 100644 index 38281274d..000000000 --- a/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/bo/CalcSkuPriceBO.java +++ /dev/null @@ -1,33 +0,0 @@ -package cn.iocoder.mall.order.api.bo; - -import cn.iocoder.mall.promotion.api.bo.PromotionActivityBO; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; - -/** - * 计算商品 SKU 价格结果 BO - */ -@Data -@Accessors(chain = true) -public class CalcSkuPriceBO implements Serializable { - - /** - * 满减送促销活动 - */ - private PromotionActivityBO fullPrivilege; - /** - * 限时折扣促销活动 - */ - private PromotionActivityBO timeLimitedDiscount; - /** - * 原价格,单位:分。 - */ - private Integer originalPrice; - /** - * 购买价格,单位:分。 - */ - private Integer buyPrice; - -} diff --git a/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/bo/CartItemBO.java b/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/bo/CartItemBO.java deleted file mode 100644 index bb8f2bb94..000000000 --- a/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/bo/CartItemBO.java +++ /dev/null @@ -1,100 +0,0 @@ -package cn.iocoder.mall.order.api.bo; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Date; - -/** - * 购物车的商品信息 DO - */ -@Data -@Accessors(chain = true) -public class CartItemBO { - - // ========= 基础字段 BEGIN ========= - - /** - * 编号,唯一自增。 - */ - private Integer id; - /** - * 状态 - * - * 1-正常 - * 2-主动删除 - * 3-下单删除 - */ - private Integer status; - /** - * 是否选中 - */ - private Boolean selected; - - // ========= 基础字段 END ========= - - // ========= 买家信息 BEGIN ========= - - /** - * 用户编号 - */ - private Integer userId; -// /** -// * 会话 key -// */ -// private String nobody; - - // ========= 买家信息 END ========= - - // ========= 商品信息 BEGIN ========= - - /** - * 商品 SPU 编号 - */ - private Integer spuId; - /** - * 商品 SKU 编号 - */ - private Integer skuId; - /** - * 商品购买数量 - */ - private Integer quantity; - - // TODO 冗余字段 - - - // ========= 商品信息 END ========= - - // ========= 交易信息 BEGIN ========= - - /** - * 订单编号 - */ - private Integer orderId; - /** - * 订单创建时间 - */ - private Date orderCreateTime; - - // ========= 交易信息 BEGIN ========= - - // ========= 优惠信息 BEGIN ========= - -// /** -// * 商品营销活动编号 -// */ -// private Integer activityId; -// /** -// * 商品营销活动类型 -// */ -// private Integer activityType; - - // ========= 优惠信息 END ========= - - /** - * 创建时间 - */ - private Date createTime; - -} diff --git a/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/dto/CalcOrderPriceDTO.java b/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/dto/CalcOrderPriceDTO.java deleted file mode 100644 index 80ea92859..000000000 --- a/order/order-service-api02/src/main/java/cn/iocoder/mall/order/api/dto/CalcOrderPriceDTO.java +++ /dev/null @@ -1,57 +0,0 @@ -package cn.iocoder.mall.order.api.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; -import java.util.List; - -/** - * 计算订单价格 DTO - */ -@Data -@Accessors(chain = true) -@Deprecated -public class CalcOrderPriceDTO { - - @NotNull(message = "用户编号不能为空") - private Integer userId; - - /** - * 优惠劵编号 - */ - private Integer couponCardId; - - @NotNull(message = "商品数组不能为空") - private List items; - - @Data - @Accessors(chain = true) - public static class Item { - - /** - * SKU 编号 - */ - private Integer skuId; - /** - * 数量 - */ - private Integer quantity; - /** - * 是否选中 - * - * 注意下,目前只有在购物车的时候,才可能出现该属性为 false 。其它情况下,都会为 true 为主。 - */ - private Boolean selected; - - public Item() { - } - - public Item(Integer skuId, Integer quantity, Boolean selected) { - this.skuId = skuId; - this.quantity = quantity; - this.selected = selected; - } - } - -} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/DatabaseConfiguration.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/DatabaseConfiguration.java deleted file mode 100644 index 22c0fbcf6..000000000 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/DatabaseConfiguration.java +++ /dev/null @@ -1,12 +0,0 @@ -package cn.iocoder.mall.order.biz.config; - -import org.mybatis.spring.annotation.MapperScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -@Configuration -@MapperScan("cn.iocoder.mall.order.biz.dao") // 扫描对应的 Mapper 接口 -@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。为什么使用 proxyTargetClass 参数,参见 https://blog.csdn.net/huang_550/article/details/76492600 -public class DatabaseConfiguration { - -} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/ServiceExceptionConfiguration.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/ServiceExceptionConfiguration.java deleted file mode 100644 index b3f95e545..000000000 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/config/ServiceExceptionConfiguration.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.mall.order.biz.config; - -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.event.EventListener; - -@Configuration -public class ServiceExceptionConfiguration { - - @EventListener(ApplicationReadyEvent.class) // 可参考 https://www.cnblogs.com/ssslinppp/p/7607509.html - public void initMessages() { -// 从 service_exception_message.properties 加载错误码的方案 -// Properties properties; -// try { -// properties = PropertiesLoaderUtils.loadAllProperties("classpath:service_exception_message.properties"); -// } catch (IOException e) { -// throw new RuntimeException(e); -// } - } // TODO FROM 芋艿 to 小范,这里记得配置下,不然错误提示不出去呀。 -} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/CartConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/CartConvert.java deleted file mode 100644 index 0c6cf8989..000000000 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/CartConvert.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.mall.order.biz.convert; - -import cn.iocoder.mall.order.api.bo.CalcOrderPriceBO; -import cn.iocoder.mall.order.api.bo.CartItemBO; -import cn.iocoder.mall.order.biz.dataobject.CartItemDO; -import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface CartConvert { - - CartConvert INSTANCE = Mappers.getMapper(CartConvert.class); - - CalcOrderPriceBO.Item convert(ProductSkuDetailBO sku); - - List convert(List items); - -} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java deleted file mode 100644 index 344a544ce..000000000 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.iocoder.mall.order.biz.service; - -import org.springframework.stereotype.Service; - -/** - * 购物车服务 Service 实现类 - */ -@Service -@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.CartService.version}") -public class CartServiceImpl { - - -// @Override -// @SuppressWarnings("Duplicates") -// public CalcSkuPriceBO calcSkuPrice(Integer skuId) { -// // 查询 SKU 是否合法 -// ProductSkuBO sku = productSpuService.getProductSku(skuId); -// if (sku == null -// || CommonStatusEnum.DISABLE.getValue().equals(sku.getStatus())) { // sku 被禁用 -// throw ServiceExceptionUtil.exception(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); -// } -// // 查询促销活动 -// List activityList = promotionActivityService.getPromotionActivityListBySpuId(sku.getSpuId(), -// Arrays.asList(PromotionActivityStatusEnum.WAIT.getValue(), PromotionActivityStatusEnum.RUN.getValue())); -// if (activityList.isEmpty()) { // 如果无促销活动,则直接返回默认结果即可 -// return new CalcSkuPriceBO().setOriginalPrice(sku.getPrice()).setBuyPrice(sku.getPrice()); -// } -// // 如果有促销活动,则开始做计算 TODO 芋艿,因为现在暂时只有限时折扣 + 满减送。所以写的比较简单先 -// PromotionActivityBO fullPrivilege = findPromotionActivityByType(activityList, PromotionActivityTypeEnum.FULL_PRIVILEGE); -// PromotionActivityBO timeLimitedDiscount = findPromotionActivityByType(activityList, PromotionActivityTypeEnum.TIME_LIMITED_DISCOUNT); -// Integer presentPrice = calcSkuPriceByTimeLimitDiscount(sku, timeLimitedDiscount); -// // 返回结果 -// return new CalcSkuPriceBO().setFullPrivilege(fullPrivilege).setTimeLimitedDiscount(timeLimitedDiscount) -// .setOriginalPrice(sku.getPrice()).setBuyPrice(presentPrice); -// } -// -// -// -// -// private PromotionActivityBO findPromotionActivityByType(List activityList, PromotionActivityTypeEnum type) { -// return activityList.stream() -// .filter(activity -> type.getValue().equals(activity.getActivityType())) -// .findFirst().orElse(null); -// } -// -// private List findPromotionActivityListByType(List activityList, PromotionActivityTypeEnum type) { -// return activityList.stream() -// .filter(activity -> type.getValue().equals(activity.getActivityType())) -// .collect(Collectors.toList()); -// } - - - -} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/PromotionActivityStatusEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/activity/PromotionActivityStatusEnum.java similarity index 93% rename from promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/PromotionActivityStatusEnum.java rename to promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/activity/PromotionActivityStatusEnum.java index 2b22fb7a0..885d9d8c5 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/PromotionActivityStatusEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/activity/PromotionActivityStatusEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.promotion.api.enums; +package cn.iocoder.mall.promotion.api.enums.activity; /** * 促销活动状态枚举 diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/PromotionActivityTypeEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/activity/PromotionActivityTypeEnum.java similarity index 90% rename from promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/PromotionActivityTypeEnum.java rename to promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/activity/PromotionActivityTypeEnum.java index 01d8a415c..ae66aef18 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/PromotionActivityTypeEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/activity/PromotionActivityTypeEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.promotion.api.enums; +package cn.iocoder.mall.promotion.api.enums.activity; /** * 推广活动类型枚举 diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponCardStatusEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/card/CouponCardStatusEnum.java similarity index 93% rename from promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponCardStatusEnum.java rename to promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/card/CouponCardStatusEnum.java index 717aa01f8..50557f606 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponCardStatusEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/card/CouponCardStatusEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.promotion.api.enums; +package cn.iocoder.mall.promotion.api.enums.coupon.card; import cn.iocoder.common.framework.core.IntArrayValuable; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponCardTakeTypeEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/card/CouponCardTakeTypeEnum.java similarity index 93% rename from promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponCardTakeTypeEnum.java rename to promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/card/CouponCardTakeTypeEnum.java index 3717c74b2..d254af4b5 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponCardTakeTypeEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/card/CouponCardTakeTypeEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.promotion.api.enums; +package cn.iocoder.mall.promotion.api.enums.coupon.card; import cn.iocoder.common.framework.core.IntArrayValuable; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponTemplateDateTypeEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateDateTypeEnum.java similarity index 92% rename from promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponTemplateDateTypeEnum.java rename to promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateDateTypeEnum.java index 784dce778..cce189ff1 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponTemplateDateTypeEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateDateTypeEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.promotion.api.enums; +package cn.iocoder.mall.promotion.api.enums.coupon.template; import cn.iocoder.common.framework.core.IntArrayValuable; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponTemplateStatusEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateStatusEnum.java similarity index 93% rename from promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponTemplateStatusEnum.java rename to promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateStatusEnum.java index 87a27a594..eb309599a 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponTemplateStatusEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateStatusEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.promotion.api.enums; +package cn.iocoder.mall.promotion.api.enums.coupon.template; import cn.iocoder.common.framework.core.IntArrayValuable; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponTemplateTypeEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateTypeEnum.java similarity index 90% rename from promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponTemplateTypeEnum.java rename to promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateTypeEnum.java index 9d3cc8da4..d34bb998c 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/CouponTemplateTypeEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/coupon/template/CouponTemplateTypeEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.promotion.api.enums; +package cn.iocoder.mall.promotion.api.enums.coupon.template; import java.util.Arrays; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/ProductRecommendTypeEnum.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/recommend/ProductRecommendTypeEnum.java similarity index 94% rename from promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/ProductRecommendTypeEnum.java rename to promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/recommend/ProductRecommendTypeEnum.java index e01a3de6d..359f0861d 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/ProductRecommendTypeEnum.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/enums/recommend/ProductRecommendTypeEnum.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.promotion.api.enums; +package cn.iocoder.mall.promotion.api.enums.recommend; import cn.iocoder.common.framework.core.IntArrayValuable; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/activity/dto/PromotionActivityRespDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/activity/dto/PromotionActivityRespDTO.java index 26154270a..e0f76ca80 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/activity/dto/PromotionActivityRespDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/activity/dto/PromotionActivityRespDTO.java @@ -1,5 +1,7 @@ package cn.iocoder.mall.promotion.api.rpc.activity.dto; +import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityStatusEnum; +import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityTypeEnum; import lombok.Data; import lombok.experimental.Accessors; @@ -25,13 +27,13 @@ public class PromotionActivityRespDTO implements Serializable { /** * 活动类型 * - * 参见 {@link cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum} 枚举 + * 参见 {@link PromotionActivityTypeEnum} 枚举 */ private Integer activityType; /** * 活动状态 * - * 参见 {@link cn.iocoder.mall.promotion.api.enums.PromotionActivityStatusEnum} 枚举 + * 参见 {@link PromotionActivityStatusEnum} 枚举 */ private Integer status; /** diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/CouponCardRpc.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/CouponCardRpc.java new file mode 100644 index 000000000..555fb55e3 --- /dev/null +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/CouponCardRpc.java @@ -0,0 +1,54 @@ +package cn.iocoder.mall.promotion.api.rpc.coupon; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.*; + +import java.util.List; + +/** + * 优惠劵 Rpc 接口 + */ +public interface CouponCardRpc { + + /** + * 获得优惠劵分页 + * + * @param pageReqDTO 优惠劵分页查询 + * @return 优惠劵分页结果 + */ + CommonResult> pageCouponCard(CouponCardPageReqDTO pageReqDTO); + + /** + * 给用户添加优惠劵 + * + * @param createReqDTO 创建信息 + * @return 优惠劵编号 + */ + CommonResult createCouponCard(CouponCardCreateReqDTO createReqDTO); + + /** + * 用户使用优惠劵 + * + * @param useReqDTO 使用信息 + * @return 成功 + */ + CommonResult useCouponCard(CouponCardUseReqDTO useReqDTO); + + /** + * 用户取消使用优惠劵 + * + * @param cancelUseReqDTO 取消使用信息 + * @return 成功 + */ + CommonResult cancelUseCouponCard(CouponCardCancelUseReqDTO cancelUseReqDTO); + + /** + * 获得用户优惠劵的可用信息列表 + * + * @param listReqDTO 查询信息 + * @return 优惠劵的可用信息列表 + */ + CommonResult> listAvailableCouponCards(CouponCardAvailableListReqDTO listReqDTO); + +} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/CouponRpc.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/CouponRpc.java index 98f5cd27c..42ca8b3cd 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/CouponRpc.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/CouponRpc.java @@ -1,12 +1,9 @@ package cn.iocoder.mall.promotion.api.rpc.coupon; import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.promotion.api.enums.CouponTemplateStatusEnum; +import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateStatusEnum; import cn.iocoder.mall.promotion.api.rpc.coupon.dto.*; -import javax.validation.constraints.NotNull; -import java.util.List; - public interface CouponRpc { // ========== 优惠劵(码)模板 ========== @@ -58,67 +55,4 @@ public interface CouponRpc { Boolean updateCouponTemplateStatus(Integer adminId, Integer couponTemplateId, @InEnum(value = CouponTemplateStatusEnum.class, message = "修改状态必须是 {value}") Integer status); - // ========== 优惠劵 ========== - - CouponCardPageRespDTO getCouponCardPage(CouponCardPageReqDTO couponCardPageDTO); - - /** - * 基于优惠劵模板,领取优惠劵 - * - * @param userId 用户编号 - * @param couponTemplateId 优惠劵模板 - * @return 优惠劵 - */ - CouponCardReqDTO addCouponCard(Integer userId, Integer couponTemplateId); - - /** - * 使用优惠劵下单 - * - * @param userId 用户编号 - * @param couponCardId 优惠劵编号 - * @return 是否成功 - */ - Boolean useCouponCard(Integer userId, - @NotNull(message = "优惠劵编号不能为空") Integer couponCardId); - - /** - * 取消优惠劵的使用 - * - * @param userId 用户编号 - * @param couponCardId 优惠劵编号 - * @return 是否成功 - */ - Boolean cancelUseCouponCard(Integer userId, Integer couponCardId); - - /** - * 获得指定优惠劵 - * - * @param userId 用户编号 - * @param couponCardId 优惠劵编号 - * @return 优惠劵 - */ - CouponCardDetailRespDTO getCouponCardDetail(Integer userId, Integer couponCardId); - - /** - * 获得用户所有优惠劵,并标明是否可用 - *

- * 注意,spus 是作为条件,判断优惠劵是否可用 - * - * @param userId 用户编号 - * @param spus 匹配的商品/分类 - * @return 优惠劵列表 - */ - List getCouponCardList(Integer userId, List spus); - - // ========== 优惠码 ========== - - /** - * 使用优惠码,兑换优惠劵 - * - * @param userId 用户编号 - * @param code 优惠码 - * @return 优惠劵 - */ - CouponCardReqDTO useCouponCode(Integer userId, String code); - } diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardDetailRespDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardDetailRespDTO.java deleted file mode 100644 index d82d9f1ab..000000000 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardDetailRespDTO.java +++ /dev/null @@ -1,143 +0,0 @@ -package cn.iocoder.mall.promotion.api.rpc.coupon.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; - -/** - * 优惠劵明细 BO 。 - * - * 主要是,会带上 {@link CouponTemplateReqDTO} 的信息 - */ -@Data -@Accessors(chain = true) -public class CouponCardDetailRespDTO implements Serializable { - - // ========== 基本信息 BEGIN ========== - /** - * 优惠劵编号 - */ - private Integer id; - /** - * 优惠劵(码)分组编号 - */ - private Integer templateId; - /** - * 优惠劵名 - */ - private String title; -// /** -// * 核销码 -// */ -// private String verifyCode; - /** - * 优惠码状态 - * - * 1-未使用 - * 2-已使用 - * 3-已失效 - */ - private Integer status; - - // ========== 基本信息 END ========== - - // ========== 领取情况 BEGIN ========== - /** - * 用户编号 - */ - private Integer userId; - /** - * 领取类型 - * - * 1 - 用户主动领取 - * 2 - 后台自动发放 - */ - private Integer takeType; - // ========== 领取情况 END ========== - - // ========== 使用规则 BEGIN ========== - /** - * 是否设置满多少金额可用,单位:分 - */ - private Integer priceAvailable; - /** - * 生效开始时间 - */ - private Date validStartTime; - /** - * 生效结束时间 - */ - private Date validEndTime; - // ========== 使用规则 END ========== - - // ========== 使用效果 BEGIN ========== - /** - * 优惠类型 - * - * 1-代金卷 - * 2-折扣卷 - */ - private Integer preferentialType; - /** - * 折扣 - */ - private Integer percentOff; - /** - * 优惠金额,单位:分。 - */ - private Integer priceOff; - /** - * 折扣上限,仅在 {@link #preferentialType} 等于 2 时生效。 - * - * 例如,折扣上限为 20 元,当使用 8 折优惠券,订单金额为 1000 元时,最高只可折扣 20 元,而非 80 元。 - */ - private Integer discountPriceLimit; - // ========== 使用效果 END ========== - - // ========== 使用情况 BEGIN ========== - /** - * 是否使用 - */ - private Boolean used; - /** - * 使用订单号 - */ - private Integer usedOrderId; - /** - * 订单中优惠面值,单位:分 - */ - private Integer usedPrice; - /** - * 使用时间 - */ - private Date usedTime; - - // TODO 芋艿,后续要加优惠劵的使用日志,因为下单后,可能会取消。 - - // ========== 使用情况 END ========== - - /** - * 创建时间 - */ - private Date createTime; - - // ========== FROM template 使用规则 BEGIN ========== - /** - * 可用范围的类型 - * - * 10-全部(ALL):所有可用 - * 20-部分(PART):部分商品可用,或指定商品可用 - * 21-部分(PART):部分商品不可用,或指定商品可用 - * 30-部分(PART):部分分类可用,或指定商品可用 - * 31-部分(PART):部分分类不可用,或指定商品可用 - */ - private Integer rangeType; - /** - * 指定商品 / 分类列表,使用逗号分隔商品编号 - */ - private List rangeValues; - -} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardPageReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardPageReqDTO.java deleted file mode 100644 index 273678663..000000000 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardPageReqDTO.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.mall.promotion.api.rpc.coupon.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * 优惠劵分页 DTO - */ -@Data -@Accessors(chain = true) -public class CouponCardPageReqDTO implements Serializable { - - /** - * 用户编号 - */ - private Integer userId; - /** - * 状态 - */ - private Integer status; - - @NotNull(message = "页码不能为空") - private Integer pageNo; - @NotNull(message = "每页条数不能为空") - private Integer pageSize; - -} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardPageRespDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardPageRespDTO.java deleted file mode 100644 index ad7416e00..000000000 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardPageRespDTO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.mall.promotion.api.rpc.coupon.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.List; - -/** - * 优惠劵分页 BO - */ -@Data -@Accessors(chain = true) -public class CouponCardPageRespDTO implements Serializable { - - /** - * 优惠劵数组 - */ - private List list; - /** - * 总量 - */ - private Integer total; - -} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardReqDTO.java deleted file mode 100644 index d1bae56b0..000000000 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardReqDTO.java +++ /dev/null @@ -1,112 +0,0 @@ -package cn.iocoder.mall.promotion.api.rpc.coupon.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.Date; - -/** - * 优惠劵 BO - */ -@Data -@Accessors(chain = true) -public class CouponCardReqDTO implements Serializable { - - // ========== 基本信息 BEGIN ========== - /** - * 优惠劵编号 - */ - private Integer id; - /** - * 优惠劵(码)分组编号 - */ - private Integer templateId; - /** - * 优惠劵名 - */ - private String title; -// /** -// * 核销码 -// */ -// private String verifyCode; - /** - * 优惠码状态 - * - * 1-未使用 - * 2-已使用 - * 3-已失效 - */ - private Integer status; - - // ========== 基本信息 END ========== - - // ========== 领取情况 BEGIN ========== - /** - * 用户编号 - */ - private Integer userId; - /** - * 领取类型 - * - * 1 - 用户主动领取 - * 2 - 后台自动发放 - */ - private Integer takeType; - // ========== 领取情况 END ========== - - // ========== 使用规则 BEGIN ========== - /** - * 是否设置满多少金额可用,单位:分 - */ - private Integer priceAvailable; - /** - * 生效开始时间 - */ - private Date validStartTime; - /** - * 生效结束时间 - */ - private Date validEndTime; - // ========== 使用规则 END ========== - - // ========== 使用效果 BEGIN ========== - /** - * 优惠类型 - * - * 1-代金卷 - * 2-折扣卷 - */ - private Integer preferentialType; - /** - * 折扣 - */ - private Integer percentOff; - /** - * 优惠金额,单位:分。 - */ - private Integer priceOff; - /** - * 折扣上限,仅在 {@link #preferentialType} 等于 2 时生效。 - * - * 例如,折扣上限为 20 元,当使用 8 折优惠券,订单金额为 1000 元时,最高只可折扣 20 元,而非 80 元。 - */ - private Integer discountPriceLimit; - // ========== 使用效果 END ========== - - // ========== 使用情况 BEGIN ========== - /** - * 使用时间 - */ - private Date usedTime; - - // TODO 芋艿,后续要加优惠劵的使用日志,因为下单后,可能会取消。 - - // ========== 使用情况 END ========== - - /** - * 创建时间 - */ - private Date createTime; - -} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardTemplateAddReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardTemplateAddReqDTO.java index 5ec3e0c2a..afc629e3d 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardTemplateAddReqDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardTemplateAddReqDTO.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.promotion.api.rpc.coupon.dto; import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.promotion.api.enums.CouponTemplateDateTypeEnum; +import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateDateTypeEnum; import cn.iocoder.mall.promotion.api.enums.PreferentialTypeEnum; import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum; import lombok.Data; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardAvailableListReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardAvailableListReqDTO.java new file mode 100644 index 000000000..a8bc17345 --- /dev/null +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardAvailableListReqDTO.java @@ -0,0 +1,68 @@ +package cn.iocoder.mall.promotion.api.rpc.coupon.dto.card; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** + * 优惠劵可用信息列表 Request DTO + */ +@Data +@Accessors(chain = true) +public class CouponCardAvailableListReqDTO implements Serializable { + + /** + * 用户编号 + */ + @NotNull(message = "用户编号不能为空") + private Integer userId; + /** + * 商品数组 + */ + @NotEmpty(message = "商品数组不能为空") + private List items; + + /** + * 商品 + */ + @Data + @Accessors(chain = true) + public static class Item implements Serializable { + + /** + * 商品 SPU 编号 + */ + @NotNull(message = "商品 SPU 编号不能为空") + private Integer spuId; + /** + * 商品 SKU 编号 + */ + @NotNull(message = "商品 SKU 编号不能为空") + private Integer skuId; + /** + * 商品 SKU 编号 + */ + @NotNull(message = "商品 Category 编号不能为空") + private Integer cid; + /** + * 商品数量 + */ + @NotNull(message = "商品数量不能为空") + @Min(value = 1L, message = "最小商品数量 1") + private Integer quantity; + /** + * 商品价格,单位:分 + * + * 为什么需要传递价格?因为商品的价格是经过计算,部署商品原始价格 + */ + @NotNull(message = "商品价格不能为空") + private Integer price; + + } + +} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardAvailableRespDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardAvailableRespDTO.java similarity index 65% rename from promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardAvailableRespDTO.java rename to promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardAvailableRespDTO.java index 5050eb406..cd09bbebd 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/CouponCardAvailableRespDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardAvailableRespDTO.java @@ -1,6 +1,7 @@ -package cn.iocoder.mall.promotion.api.rpc.coupon.dto; +package cn.iocoder.mall.promotion.api.rpc.coupon.dto.card; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; /** @@ -9,8 +10,9 @@ import lombok.experimental.Accessors; * 注意,如果优惠劵不可用,标记 available = false ,并写明 unavailableReason 原因 */ @Data +@EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -public class CouponCardAvailableRespDTO extends CouponCardReqDTO { +public class CouponCardAvailableRespDTO extends CouponCardRespDTO { /** * 是否可用 diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardCancelUseReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardCancelUseReqDTO.java new file mode 100644 index 000000000..987f43d22 --- /dev/null +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardCancelUseReqDTO.java @@ -0,0 +1,27 @@ +package cn.iocoder.mall.promotion.api.rpc.coupon.dto.card; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * 优惠劵取消使用 Request DTO + */ +@Data +@Accessors(chain = true) +public class CouponCardCancelUseReqDTO implements Serializable { + + /** + * 用户编号 + */ + @NotNull(message = "用户编号不能为空") + private Integer userId; + /** + * 优惠劵编号 + */ + @NotNull(message = "优惠劵编号不能为空") + private Integer couponCardId; + +} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardCreateReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardCreateReqDTO.java new file mode 100644 index 000000000..8b7cdf2ab --- /dev/null +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardCreateReqDTO.java @@ -0,0 +1,27 @@ +package cn.iocoder.mall.promotion.api.rpc.coupon.dto.card; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * 优惠劵创建 Request DTO + */ +@Data +@Accessors(chain = true) +public class CouponCardCreateReqDTO implements Serializable { + + /** + * 用户编号 + */ + @NotNull(message = "用户编号不能为空") + private Integer userId; + /** + * 优惠劵模板编号 + */ + @NotNull(message = "优惠劵模板编号不能为空") + private Integer couponTemplateId; + +} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardPageReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardPageReqDTO.java new file mode 100644 index 000000000..4dcf5a23c --- /dev/null +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardPageReqDTO.java @@ -0,0 +1,25 @@ +package cn.iocoder.mall.promotion.api.rpc.coupon.dto.card; + +import cn.iocoder.common.framework.vo.PageParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * 优惠劵分页 DTO + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +public class CouponCardPageReqDTO extends PageParam { + + /** + * 用户编号 + */ + private Integer userId; + /** + * 状态 + */ + private Integer status; + +} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardUseReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardUseReqDTO.java new file mode 100644 index 000000000..534b7fc0b --- /dev/null +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/coupon/dto/card/CouponCardUseReqDTO.java @@ -0,0 +1,27 @@ +package cn.iocoder.mall.promotion.api.rpc.coupon.dto.card; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * 优惠劵使用 Request DTO + */ +@Data +@Accessors(chain = true) +public class CouponCardUseReqDTO implements Serializable { + + /** + * 用户编号 + */ + @NotNull(message = "用户编号不能为空") + private Integer userId; + /** + * 优惠劵编号 + */ + @NotNull(message = "优惠劵编号不能为空") + private Integer couponCardId; + +} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/price/dto/PriceProductCalcReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/price/dto/PriceProductCalcReqDTO.java index 6790fde72..1943d7c38 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/price/dto/PriceProductCalcReqDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/price/dto/PriceProductCalcReqDTO.java @@ -17,7 +17,6 @@ public class PriceProductCalcReqDTO implements Serializable { /** * 用户编号 */ - @NotNull(message = "用户编号不能为空") private Integer userId; /** diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/price/dto/PriceProductCalcRespDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/price/dto/PriceProductCalcRespDTO.java index d6e9c71ec..d3225698f 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/price/dto/PriceProductCalcRespDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/price/dto/PriceProductCalcRespDTO.java @@ -1,6 +1,6 @@ package cn.iocoder.mall.promotion.api.rpc.price.dto; -import cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum; +import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityTypeEnum; import lombok.Data; import lombok.experimental.Accessors; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendAddReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendAddReqDTO.java index df3732c90..89d03b7a4 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendAddReqDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendAddReqDTO.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.promotion.api.rpc.recommend.dto; import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.promotion.api.enums.ProductRecommendTypeEnum; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendRespDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendRespDTO.java index 342802715..e0a02f6f1 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendRespDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendRespDTO.java @@ -1,6 +1,6 @@ package cn.iocoder.mall.promotion.api.rpc.recommend.dto; -import cn.iocoder.mall.promotion.api.enums.ProductRecommendTypeEnum; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; import lombok.Data; import lombok.experimental.Accessors; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendUpdateReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendUpdateReqDTO.java index 0dee22b28..8f5a1c439 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendUpdateReqDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendUpdateReqDTO.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.promotion.api.rpc.recommend.dto; import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.promotion.api.enums.ProductRecommendTypeEnum; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/coupon/CouponCardConvert.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/coupon/CouponCardConvert.java deleted file mode 100644 index b6ce9f74d..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/coupon/CouponCardConvert.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.mall.promotionservice.convert.coupon; - -import cn.iocoder.mall.promotion.api.rpc.coupon.dto.CouponCardDetailRespDTO; -import cn.iocoder.mall.promotion.api.rpc.coupon.dto.CouponCardReqDTO; -import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponCardDO; -import cn.iocoder.mall.promotionservice.service.coupon.bo.CouponCardAvailableBO; -import org.mapstruct.Mapper; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface CouponCardConvert { - - CouponCardConvert INSTANCE = Mappers.getMapper(CouponCardConvert.class); - -// @Mappings({}) -// CouponCardBO convertToBO(CouponCardDO banner); - - - - List convertToDTO(List cardList); - - CouponCardReqDTO convertToSingleDTO(CouponCardDO card); - - @Mappings({}) - CouponCardDetailRespDTO convert2(CouponCardDO card); - - CouponCardAvailableBO convertAvailBO(CouponCardDO card,boolean x); - - //@Mappings({}) - //CouponCardAvailableBO convert2(CouponCardDO card, boolean x); // TODO 芋艿,临时用来解决 mapstruct 无法正确匹配方法的问题 - -} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/coupon/card/CouponCardConvert.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/coupon/card/CouponCardConvert.java index c4837576f..1d23fcf31 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/coupon/card/CouponCardConvert.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/coupon/card/CouponCardConvert.java @@ -1,8 +1,13 @@ package cn.iocoder.mall.promotionservice.convert.coupon.card; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableRespDTO; import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardRespDTO; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponCardDO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; import org.mapstruct.factory.Mappers; @Mapper @@ -12,4 +17,10 @@ public interface CouponCardConvert { CouponCardRespDTO convert(CouponCardDO bean); + @Mapping(source = "records", target = "list") + PageResult convertPage(IPage page); + + @Named("convertCouponCardDOToCouponCardAvailableRespDTO") // 避免生成的方法名的冲突 + CouponCardAvailableRespDTO convert01(CouponCardDO bean); + } diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/activity/PromotionActivityDO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/activity/PromotionActivityDO.java index 2096e94a6..d570d5daa 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/activity/PromotionActivityDO.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/activity/PromotionActivityDO.java @@ -1,6 +1,8 @@ package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity; import cn.iocoder.mall.mybatis.core.dataobject.BaseDO; +import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityStatusEnum; +import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityTypeEnum; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler; @@ -31,7 +33,7 @@ public class PromotionActivityDO extends BaseDO { /** * 活动类型 * - * 参见 {@link cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum} 枚举 + * 参见 {@link PromotionActivityTypeEnum} 枚举 */ private Integer activityType; // /** @@ -42,7 +44,7 @@ public class PromotionActivityDO extends BaseDO { /** * 活动状态 * - * 参见 {@link cn.iocoder.mall.promotion.api.enums.PromotionActivityStatusEnum} 枚举 + * 参见 {@link PromotionActivityStatusEnum} 枚举 */ private Integer status; /** diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/coupon/CouponCardDO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/coupon/CouponCardDO.java index 666b3e90f..1d6a94517 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/coupon/CouponCardDO.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/coupon/CouponCardDO.java @@ -1,7 +1,9 @@ package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon; import cn.iocoder.mall.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import java.util.Date; @@ -9,7 +11,9 @@ import java.util.Date; /** * 优惠劵 DO */ +@TableName("coupon_card") @Data +@EqualsAndHashCode(callSuper = true) @Accessors(chain = true) public class CouponCardDO extends BaseDO { diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/coupon/CouponTemplateDO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/coupon/CouponTemplateDO.java index 23661d1c3..24b763918 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/coupon/CouponTemplateDO.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/coupon/CouponTemplateDO.java @@ -1,7 +1,10 @@ package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon; import cn.iocoder.mall.mybatis.core.dataobject.BaseDO; +import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateStatusEnum; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; import java.util.Date; @@ -11,7 +14,9 @@ import java.util.Date; * * 当用户领取时,会生成 {@link CouponCardDO} 优惠劵(码)。 */ +@TableName("coupon_template") @Data +@EqualsAndHashCode(callSuper = true) @Accessors(chain = true) public class CouponTemplateDO extends BaseDO { @@ -38,7 +43,7 @@ public class CouponTemplateDO extends BaseDO { /** * 优惠码状态 * - * {@link cn.iocoder.mall.promotion.api.enums.CouponTemplateStatusEnum} + * {@link CouponTemplateStatusEnum} * * 当优惠劵(码)开启中,可以手动操作,设置禁用中。 */ diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/recommend/ProductRecommendDO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/recommend/ProductRecommendDO.java index ae114f13e..ad7a701b0 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/recommend/ProductRecommendDO.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/recommend/ProductRecommendDO.java @@ -2,7 +2,7 @@ package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.recommend; import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO; -import cn.iocoder.mall.promotion.api.enums.ProductRecommendTypeEnum; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; import lombok.Data; import lombok.experimental.Accessors; diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/coupon/CouponCardMapper.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/coupon/CouponCardMapper.java index 496fd0014..cea36848b 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/coupon/CouponCardMapper.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/coupon/CouponCardMapper.java @@ -1,36 +1,38 @@ package cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon; +import cn.iocoder.mall.mybatis.core.query.QueryWrapperX; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardPageReqDTO; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponCardDO; -import org.apache.ibatis.annotations.Param; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.stereotype.Repository; import java.util.List; @Repository -public interface CouponCardMapper { +public interface CouponCardMapper extends BaseMapper { - CouponCardDO selectById(@Param("id") Integer id); + default List selectListByUserIdAndStatus(Integer userId, Integer status) { + return selectList(new QueryWrapper().eq("user_id", userId) + .eq("status", status)); + } - List selectListByUserIdAndStatus(@Param("userId") Integer userId, - @Param("status") Integer status); + default int selectCountByUserIdAndTemplateId(Integer userId, Integer templateId) { + return selectCount(new QueryWrapper().eq("user_id", userId) + .eq("template_id", templateId)); + } - List selectListByPage(@Param("userId") Integer userId, - @Param("status") Integer status, - @Param("offset") Integer offset, - @Param("limit") Integer limit); + default int updateByIdAndStatus(Integer id, Integer status, CouponCardDO updateObj) { + return update(updateObj, new QueryWrapper().eq("id", id) + .eq("status", status)); + } - Integer selectCountByPage(@Param("userId") Integer userId, - @Param("status") Integer status); - - int selectCountByUserIdAndTemplateId(@Param("userId") Integer userId, - @Param("templateId") Integer templateId); - - void insert(CouponCardDO couponCardDO); - - int update(CouponCardDO couponCardDO); - - int updateByIdAndStatus(@Param("id") Integer id, - @Param("status") Integer status, - @Param("updateObj") CouponCardDO updateObj); + default IPage selectPage(CouponCardPageReqDTO pageReqDTO) { + return selectPage(new Page<>(pageReqDTO.getPageNo(), pageReqDTO.getPageSize()), + new QueryWrapperX().eqIfPresent("user_id", pageReqDTO.getUserId()) + .eqIfPresent("status", pageReqDTO.getStatus())); + } } diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/coupon/CouponTemplateMapper.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/coupon/CouponTemplateMapper.java index ed0bf1b34..bd7d73c65 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/coupon/CouponTemplateMapper.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/coupon/CouponTemplateMapper.java @@ -1,18 +1,14 @@ package cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponTemplateDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; -import java.util.Collection; import java.util.List; @Repository -public interface CouponTemplateMapper { - - CouponTemplateDO selectById(@Param("id") Integer id); - - List selectListByIds(@Param("ids") Collection ids); +public interface CouponTemplateMapper extends BaseMapper { List selectListByPage(@Param("type") Integer type, @Param("title") String title, @@ -26,10 +22,14 @@ public interface CouponTemplateMapper { @Param("status") Integer status, @Param("preferentialType") Integer preferentialType); - void insert(CouponTemplateDO couponTemplate); - - int update(CouponTemplateDO couponTemplate); - + /** + * 更新优惠劵模板已领取的数量 + * + * 如果超过领取上限,则返回 0 + * + * @param id 优惠劵模板编号 + * @return 更新数量 + */ int updateStatFetchNumIncr(@Param("id") Integer id); } diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/coupon/card/CouponCardManager.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/coupon/card/CouponCardManager.java new file mode 100644 index 000000000..f0c4159e8 --- /dev/null +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/coupon/card/CouponCardManager.java @@ -0,0 +1,41 @@ +package cn.iocoder.mall.promotionservice.manager.coupon.card; + +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.*; +import cn.iocoder.mall.promotionservice.service.coupon.CouponCardService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.List; + +@Service +@Validated +public class CouponCardManager { + + @Autowired + private CouponCardService couponCardService; + + public PageResult pageCouponCard(CouponCardPageReqDTO pageReqDTO) { + return couponCardService.pageCouponCard(pageReqDTO); + } + + public Integer createCouponCard(CouponCardCreateReqDTO createReqDTO) { + return couponCardService.createCouponCard(createReqDTO.getUserId(), createReqDTO.getCouponTemplateId()); + } + + public Boolean useCouponCard(CouponCardUseReqDTO useReqDTO) { + couponCardService.useCouponCard(useReqDTO.getUserId(), useReqDTO.getCouponCardId()); + return true; + } + + public Boolean cancelUseCouponCard(CouponCardCancelUseReqDTO cancelUseReqDTO) { + couponCardService.cancelUseCouponCard(cancelUseReqDTO.getUserId(), cancelUseReqDTO.getCouponCardId()); + return true; + } + + public List listAvailableCouponCards(CouponCardAvailableListReqDTO listReqDTO) { + return couponCardService.listAvailableCouponCards(listReqDTO); + } + +} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/price/PriceManager.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/price/PriceManager.java index 98b2d2fab..c63aab764 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/price/PriceManager.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/price/PriceManager.java @@ -9,6 +9,8 @@ import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO; import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc; import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO; import cn.iocoder.mall.promotion.api.enums.*; +import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityStatusEnum; +import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityTypeEnum; import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO; import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardRespDTO; import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponTemplateRespDTO; diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/rpc/coupon/CouponCardRpcImpl.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/rpc/coupon/CouponCardRpcImpl.java new file mode 100644 index 000000000..bdd523759 --- /dev/null +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/rpc/coupon/CouponCardRpcImpl.java @@ -0,0 +1,46 @@ +package cn.iocoder.mall.promotionservice.rpc.coupon; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.coupon.CouponCardRpc; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.*; +import cn.iocoder.mall.promotionservice.manager.coupon.card.CouponCardManager; +import org.apache.dubbo.config.annotation.DubboService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +@DubboService +public class CouponCardRpcImpl implements CouponCardRpc { + + @Autowired + private CouponCardManager couponCardManager; + + @Override + public CommonResult> pageCouponCard(CouponCardPageReqDTO pageReqDTO) { + return success(couponCardManager.pageCouponCard(pageReqDTO)); + } + + @Override + public CommonResult createCouponCard(CouponCardCreateReqDTO createReqDTO) { + return success(couponCardManager.createCouponCard(createReqDTO)); + } + + @Override + public CommonResult useCouponCard(CouponCardUseReqDTO useReqDTO) { + return success(couponCardManager.useCouponCard(useReqDTO)); + } + + @Override + public CommonResult cancelUseCouponCard(CouponCardCancelUseReqDTO cancelUseReqDTO) { + return success(couponCardManager.cancelUseCouponCard(cancelUseReqDTO)); + } + + @Override + public CommonResult> listAvailableCouponCards(CouponCardAvailableListReqDTO listReqDTO) { + return success(couponCardManager.listAvailableCouponCards(listReqDTO)); + } + +} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/activity/PromotionActivityService.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/activity/PromotionActivityService.java index 011a8a7b7..baab7260d 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/activity/PromotionActivityService.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/activity/PromotionActivityService.java @@ -1,6 +1,6 @@ package cn.iocoder.mall.promotionservice.service.activity; -import cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum; +import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityTypeEnum; import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum; import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO; import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO; diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/activity/bo/PromotionActivityBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/activity/bo/PromotionActivityBO.java index 3c5d34b1e..513a01c0b 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/activity/bo/PromotionActivityBO.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/activity/bo/PromotionActivityBO.java @@ -1,5 +1,7 @@ package cn.iocoder.mall.promotionservice.service.activity.bo; +import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityStatusEnum; +import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityTypeEnum; import lombok.Data; import lombok.experimental.Accessors; @@ -22,13 +24,13 @@ public class PromotionActivityBO implements Serializable { /** * 活动类型 * - * 参见 {@link cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum} 枚举 + * 参见 {@link PromotionActivityTypeEnum} 枚举 */ private Integer activityType; /** * 活动状态 * - * 参见 {@link cn.iocoder.mall.promotion.api.enums.PromotionActivityStatusEnum} 枚举 + * 参见 {@link PromotionActivityStatusEnum} 枚举 */ private Integer status; /** diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponCardService.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponCardService.java index 51f35616b..b2b7d60b2 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponCardService.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponCardService.java @@ -1,14 +1,34 @@ package cn.iocoder.mall.promotionservice.service.coupon; +import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.util.CollectionUtils; +import cn.iocoder.common.framework.util.DateUtil; +import cn.iocoder.common.framework.util.StringUtils; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants; +import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum; +import cn.iocoder.mall.promotion.api.enums.coupon.card.CouponCardStatusEnum; +import cn.iocoder.mall.promotion.api.enums.coupon.card.CouponCardTakeTypeEnum; +import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateDateTypeEnum; +import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateStatusEnum; +import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateTypeEnum; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableListReqDTO; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableRespDTO; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardPageReqDTO; import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardRespDTO; import cn.iocoder.mall.promotionservice.convert.coupon.card.CouponCardConvert; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponCardDO; +import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponTemplateDO; import cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon.CouponCardMapper; +import cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon.CouponTemplateMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; -import java.util.Objects; +import java.util.*; +import java.util.stream.Collectors; /** * 优惠劵 Service @@ -19,6 +39,8 @@ public class CouponCardService { @Autowired private CouponCardMapper couponCardMapper; + @Autowired + private CouponTemplateMapper couponTemplateMapper; public CouponCardRespDTO getCouponCard(Integer userId, Integer couponCardId) { CouponCardDO card = couponCardMapper.selectById(couponCardId); @@ -31,4 +53,199 @@ public class CouponCardService { return CouponCardConvert.INSTANCE.convert(card); } + /** + * 获得优惠劵分页 + * + * @param pageReqDTO 优惠劵分页查询 + * @return 优惠劵分页结果 + */ + public PageResult pageCouponCard(CouponCardPageReqDTO pageReqDTO) { + IPage couponCardDOPage = couponCardMapper.selectPage(pageReqDTO); + return CouponCardConvert.INSTANCE.convertPage(couponCardDOPage); + } + + /** + * 给用户添加优惠劵 + * + * @param userId 用户编号 + * @param couponTemplateId 优惠劵模板编号 + * @return 优惠劵编号 + */ + @Transactional + public Integer createCouponCard(Integer userId, Integer couponTemplateId) { + // 校验 CouponCardTemplate 存在 + CouponTemplateDO template = couponTemplateMapper.selectById(couponTemplateId); + if (template == null) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_NOT_EXISTS.getCode()); + } + // 校验 CouponCardTemplate 是 CARD + if (!CouponTemplateTypeEnum.CARD.getValue().equals(template.getType())) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_NOT_CARD.getCode()); + } + // 校验 CouponCardTemplate 状态是否开启 + if (!CouponTemplateStatusEnum.ENABLE.getValue().equals(template.getStatus())) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_STATUS_NOT_ENABLE.getCode()); + } + // 校验 CouponCardTemplate 是否到达可领取的上限 + if (template.getStatFetchNum() > template.getTotal()) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_TOTAL_NOT_ENOUGH.getCode()); + } + // 校验单人可领取优惠劵是否到达上限 + if (couponCardMapper.selectCountByUserIdAndTemplateId(userId, couponTemplateId) > template.getQuota()) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_CARD_ADD_EXCEED_QUOTA.getCode()); + } + // 增加优惠劵已领取量 + int updateTemplateCount = couponTemplateMapper.updateStatFetchNumIncr(couponTemplateId); + if (updateTemplateCount == 0) { // 超过 CouponCardTemplate 发放量 + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_CARD_ADD_EXCEED_QUOTA.getCode()); + } + // 创建优惠劵 + // 1. 基本信息 + 领取情况 + CouponCardDO card = new CouponCardDO() + .setTemplateId(couponTemplateId) + .setTitle(template.getTitle()) + .setStatus(CouponCardStatusEnum.UNUSED.getValue()) + .setUserId(userId) + .setTakeType(CouponCardTakeTypeEnum.BY_USER.getValue()); // TODO 需要改 + // 2. 使用规则 + card.setPriceAvailable(template.getPriceAvailable()); + setCouponCardValidTime(card, template); + // 3. 使用效果 + card.setPreferentialType(template.getPreferentialType()) + .setPriceOff(template.getPriceOff()) + .setPercentOff(template.getPercentOff()).setDiscountPriceLimit(template.getDiscountPriceLimit()); + // 保存优惠劵模板到数据库 + couponCardMapper.insert(card); + // 返回成功 + return card.getId(); + } + + /** + * 用户使用优惠劵 + * + * @param userId 用户编号 + * @param couponCardId 优惠劵编号 + */ + public void useCouponCard(Integer userId, Integer couponCardId) { + // 查询优惠劵 + CouponCardDO card = couponCardMapper.selectById(couponCardId); + if (card == null) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_NOT_EXISTS.getCode()); + } + if (!userId.equals(card.getUserId())) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_ERROR_USER.getCode()); + } + if (!CouponCardStatusEnum.UNUSED.getValue().equals(card.getStatus())) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_UNUSED.getCode()); + } + if (DateUtil.isBetween(card.getValidStartTime(), card.getValidEndTime())) { // 为避免定时器没跑,实际优惠劵已经过期 + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_UNUSED.getCode()); + } + // 更新优惠劵已使用 + int updateCount = couponCardMapper.updateByIdAndStatus(card.getId(), CouponCardStatusEnum.UNUSED.getValue(), + new CouponCardDO().setStatus(CouponCardStatusEnum.USED.getValue()).setUsedTime(new Date())); + if (updateCount == 0) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_UNUSED.getCode()); + } + } + + /** + * 用户取消使用优惠劵 + * + * @param userId 用户编号 + * @param couponCardId 优惠劵编号 + */ + public void cancelUseCouponCard(Integer userId, Integer couponCardId) { + // 查询优惠劵 + CouponCardDO card = couponCardMapper.selectById(couponCardId); + if (card == null) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_NOT_EXISTS.getCode()); + } + if (!userId.equals(card.getUserId())) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_ERROR_USER.getCode()); + } + if (!CouponCardStatusEnum.USED.getValue().equals(card.getStatus())) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_USED.getCode()); + } + // 更新优惠劵已使用 + int updateCount = couponCardMapper.updateByIdAndStatus(card.getId(), CouponCardStatusEnum.USED.getValue(), + new CouponCardDO().setStatus(CouponCardStatusEnum.UNUSED.getValue())); // TODO 芋艿,usedTime 未设置空,后面处理。 + if (updateCount == 0) { + throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_USED.getCode()); + } + // 有一点要注意,更新会未使用时,优惠劵可能已经过期了,直接让定时器跑过期,这里不做处理。 + } + + /** + * 获得用户优惠劵的可用信息列表 + * + * @param listReqDTO 查询信息 + * @return 优惠劵的可用信息列表 + */ + public List listAvailableCouponCards(CouponCardAvailableListReqDTO listReqDTO) { + // 查询用户未使用的优惠劵列表 + List cards = couponCardMapper.selectListByUserIdAndStatus(listReqDTO.getUserId(), CouponCardStatusEnum.UNUSED.getValue()); + if (cards.isEmpty()) { + return Collections.emptyList(); + } + // 查询优惠劵模板集合 + Map templates = CollectionUtils.convertMap( + couponTemplateMapper.selectBatchIds(CollectionUtils.convertSet(cards, CouponCardDO::getTemplateId)), + CouponTemplateDO::getId); + // 逐个判断是否可用 + return cards.stream().map(card -> { + CouponCardAvailableRespDTO availableCard = CouponCardConvert.INSTANCE.convert01(card); + availableCard.setUnavailableReason(isMatch(card, templates.get(card.getTemplateId()), listReqDTO.getItems())); + availableCard.setAvailable(availableCard.getUnavailableReason() == null); + return availableCard; + }).collect(Collectors.toList()); + } + + /** + * 匹配商品是否可以使用指定优惠劵 + * + * @param card 优惠劵 + * @param template 优惠劵模板 + * @param items 商品 SKU 数组 + * @return 如果不匹配,返回原因 + */ + private String isMatch(CouponCardDO card, CouponTemplateDO template, List items) { + int totalPrice = 0; + if (RangeTypeEnum.ALL.getValue().equals(template.getRangeType())) { + totalPrice = items.stream().mapToInt(spu -> spu.getPrice() * spu.getQuantity()).sum(); + } else if (RangeTypeEnum.PRODUCT_INCLUDE_PART.getValue().equals(template.getRangeType())) { + List spuIds = StringUtils.splitToInt(template.getRangeValues(), ","); + totalPrice = items.stream().mapToInt(spu -> spuIds.contains(spu.getSpuId()) ? spu.getPrice() * spu.getQuantity() : 0).sum(); + } else if (RangeTypeEnum.PRODUCT_EXCLUDE_PART.getValue().equals(template.getRangeType())) { + List spuIds = StringUtils.splitToInt(template.getRangeValues(), ","); + totalPrice = items.stream().mapToInt(spu -> !spuIds.contains(spu.getSpuId()) ? spu.getPrice() * spu.getQuantity() : 0).sum(); + } else if (RangeTypeEnum.CATEGORY_INCLUDE_PART.getValue().equals(template.getRangeType())) { + List spuIds = StringUtils.splitToInt(template.getRangeValues(), ","); + totalPrice = items.stream().mapToInt(spu -> spuIds.contains(spu.getCid()) ? spu.getPrice() * spu.getQuantity() : 0).sum(); + } else if (RangeTypeEnum.CATEGORY_EXCLUDE_PART.getValue().equals(template.getRangeType())) { + List spuIds = StringUtils.splitToInt(template.getRangeValues(), ","); + totalPrice = items.stream().mapToInt(spu -> !spuIds.contains(spu.getCid()) ? spu.getPrice() * spu.getQuantity() : 0).sum(); + } + // 总价为 0 时,说明优惠劵丫根不匹配 + if (totalPrice == 0) { + return "优惠劵不匹配"; + } + // 如果不满足金额 + if (totalPrice < card.getPriceAvailable()) { + return String.format("差 %1$,.2f 元可用优惠劵", (card.getPriceAvailable() - totalPrice) / 100D); + } + return null; + } + + private void setCouponCardValidTime(CouponCardDO card, CouponTemplateDO template) { + if (CouponTemplateDateTypeEnum.FIXED_DATE.getValue().equals(template.getDateType())) { + card.setValidStartTime(template.getValidStartTime()).setValidEndTime(template.getValidEndTime()); + } else if (CouponTemplateDateTypeEnum.FIXED_TERM.getValue().equals(template.getDateType())) { + Date validStartTime = DateUtil.getDayBegin(new Date()); + card.setValidStartTime(DateUtil.addDate(validStartTime, Calendar.DAY_OF_YEAR, template.getFixedStartTerm())); + Date validEndTime = DateUtil.getDayEnd(card.getValidStartTime()); + card.setValidEndTime(DateUtil.addDate(validEndTime, Calendar.DAY_OF_YEAR, template.getFixedEndTerm() - 1)); + } + } + } diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponService.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponService.java index d3a0a0f84..62b699832 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponService.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/CouponService.java @@ -1,24 +1,23 @@ package cn.iocoder.mall.promotionservice.service.coupon; import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil; -import cn.iocoder.common.framework.util.DateUtil; -import cn.iocoder.mall.promotion.api.enums.*; -import cn.iocoder.mall.promotion.api.rpc.coupon.dto.*; -import cn.iocoder.mall.promotionservice.convert.coupon.CouponCardConvert; +import cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants; +import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateStatusEnum; +import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateTypeEnum; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.CouponTemplatePageReqDTO; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.CouponTemplatePageRespDTO; import cn.iocoder.mall.promotionservice.convert.coupon.card.CouponTemplateConvert; -import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponCardDO; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.coupon.CouponTemplateDO; import cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon.CouponCardMapper; import cn.iocoder.mall.promotionservice.dal.mysql.mapper.coupon.CouponTemplateMapper; -import cn.iocoder.mall.promotionservice.service.coupon.bo.*; -import cn.iocoder.common.framework.util.*; +import cn.iocoder.mall.promotionservice.service.coupon.bo.CouponCardTemplateAddBO; +import cn.iocoder.mall.promotionservice.service.coupon.bo.CouponCardTemplateUpdateBO; +import cn.iocoder.mall.promotionservice.service.coupon.bo.CouponCodeTemplateUpdateBO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; -import java.util.*; -import java.util.stream.Collectors; +import java.util.Date; @Service @Validated @@ -86,7 +85,7 @@ public class CouponService { } // 更新优惠劵模板到数据库 CouponTemplateDO updateTemplateDO = CouponTemplateConvert.INSTANCE.convert(couponCardTemplateUpdateDTO); - couponTemplateMapper.update(updateTemplateDO); + couponTemplateMapper.updateById(updateTemplateDO); // 返回成功 return true; } @@ -99,7 +98,7 @@ public class CouponService { } // 更新到数据库 CouponTemplateDO updateTemplateDO = new CouponTemplateDO().setId(couponTemplateId).setStatus(status); - couponTemplateMapper.update(updateTemplateDO); + couponTemplateMapper.updateById(updateTemplateDO); // 返回成功 return true; } @@ -149,200 +148,6 @@ public class CouponService { // ========== 优惠劵 ========== - public CouponCardPageRespDTO getCouponCardPage(CouponCardPageReqDTO couponCardPageDTO) { - CouponCardPageRespDTO pageBO = new CouponCardPageRespDTO(); - // 查询分页数据 - int offset = (couponCardPageDTO.getPageNo() - 1) * couponCardPageDTO.getPageSize(); - pageBO.setList(CouponCardConvert.INSTANCE.convertToDTO(couponCardMapper.selectListByPage( - couponCardPageDTO.getUserId(), couponCardPageDTO.getStatus(), - offset, couponCardPageDTO.getPageSize()))); - // 查询分页总数 - pageBO.setTotal(couponCardMapper.selectCountByPage( - couponCardPageDTO.getUserId(), couponCardPageDTO.getStatus())); - return pageBO; - } - @Transactional - public CouponCardReqDTO addCouponCard(Integer userId, Integer couponTemplateId) { - // 校验 CouponCardTemplate 存在 - CouponTemplateDO template = couponTemplateMapper.selectById(couponTemplateId); - if (template == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_NOT_EXISTS.getCode()); - } - // 校验 CouponCardTemplate 是 CARD - if (!CouponTemplateTypeEnum.CARD.getValue().equals(template.getType())) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_NOT_CARD.getCode()); - } - // 校验 CouponCardTemplate 状态是否开启 - if (!CouponTemplateStatusEnum.ENABLE.getValue().equals(template.getStatus())) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_STATUS_NOT_ENABLE.getCode()); - } - // 校验 CouponCardTemplate 是否到达可领取的上限 - if (template.getStatFetchNum() > template.getTotal()) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_TOTAL_NOT_ENOUGH.getCode()); - } - // 校验单人可领取优惠劵是否到达上限 - if (couponCardMapper.selectCountByUserIdAndTemplateId(userId, couponTemplateId) > template.getQuota()) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_CARD_ADD_EXCEED_QUOTA.getCode()); - } - // 增加优惠劵已领取量 - int updateTemplateCount = couponTemplateMapper.updateStatFetchNumIncr(couponTemplateId); - if (updateTemplateCount == 0) { // 超过 CouponCardTemplate 发放量 - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_CARD_ADD_EXCEED_QUOTA.getCode()); - } - // 创建优惠劵 - // 1. 基本信息 + 领取情况 - CouponCardDO card = new CouponCardDO() - .setTemplateId(couponTemplateId) - .setTitle(template.getTitle()) - .setStatus(CouponCardStatusEnum.UNUSED.getValue()) - .setUserId(userId) - .setTakeType(CouponCardTakeTypeEnum.BY_USER.getValue()); // TODO 需要改 - // 2. 使用规则 - card.setPriceAvailable(template.getPriceAvailable()); - setCouponCardValidTime(card, template); - // 3. 使用效果 - card.setPreferentialType(template.getPreferentialType()) - .setPriceOff(template.getPriceOff()) - .setPercentOff(template.getPercentOff()).setDiscountPriceLimit(template.getDiscountPriceLimit()); - // 保存优惠劵模板到数据库 - card.setCreateTime(new Date()); - couponCardMapper.insert(card); - // 返回成功 - return CouponCardConvert.INSTANCE.convertToSingleDTO(card); - } - - public Boolean useCouponCard(Integer userId, Integer couponCardId) { - // 查询优惠劵 - CouponCardDO card = couponCardMapper.selectById(couponCardId); - if (card == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_NOT_EXISTS.getCode()); - } - if (!userId.equals(card.getUserId())) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_ERROR_USER.getCode()); - } - if (!CouponCardStatusEnum.UNUSED.getValue().equals(card.getStatus())) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_UNUSED.getCode()); - } - if (DateUtil.isBetween(card.getValidStartTime(), card.getValidEndTime())) { // 为避免定时器没跑,实际优惠劵已经过期 - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_UNUSED.getCode()); - } - // 更新优惠劵已使用 - int updateCount = couponCardMapper.updateByIdAndStatus(card.getId(), CouponCardStatusEnum.UNUSED.getValue(), - new CouponCardDO().setStatus(CouponCardStatusEnum.USED.getValue()).setUsedTime(new Date())); - if (updateCount == 0) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_UNUSED.getCode()); - } - return true; - } - - public Boolean cancelUseCouponCard(Integer userId, Integer couponCardId) { - // 查询优惠劵 - CouponCardDO card = couponCardMapper.selectById(couponCardId); - if (card == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_NOT_EXISTS.getCode()); - } - if (!userId.equals(card.getUserId())) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_ERROR_USER.getCode()); - } - if (!CouponCardStatusEnum.USED.getValue().equals(card.getStatus())) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_USED.getCode()); - } - // 更新优惠劵已使用 - int updateCount = couponCardMapper.updateByIdAndStatus(card.getId(), CouponCardStatusEnum.USED.getValue(), - new CouponCardDO().setStatus(CouponCardStatusEnum.UNUSED.getValue())); // TODO 芋艿,usedTime 未设置空,后面处理。 - if (updateCount == 0) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_STATUS_NOT_USED.getCode()); - } - // 有一点要注意,更新会未使用时,优惠劵可能已经过期了,直接让定时器跑过期,这里不做处理。 - return true; - } - - public CouponCardDetailRespDTO getCouponCardDetail(Integer userId, Integer couponCardId) { - // 查询优惠劵 - CouponCardDO card = couponCardMapper.selectById(couponCardId); - if (card == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_NOT_EXISTS.getCode()); - } - if (!userId.equals(card.getUserId())) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_CARD_ERROR_USER.getCode()); - } - // 查询优惠劵模板 - CouponTemplateDO template = couponTemplateMapper.selectById(card.getTemplateId()); - if (template == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.COUPON_TEMPLATE_NOT_EXISTS.getCode()); - } - // 拼接结果 - CouponCardDetailRespDTO detail = CouponCardConvert.INSTANCE.convert2(card); - detail.setRangeType(template.getRangeType()); - detail.setRangeValues(StringUtils.splitToInt(template.getRangeValues(), ",")); - return detail; - } - - public List getCouponCardList(Integer userId, List spus) { - // 查询用户未使用的优惠劵列表 - List cards = couponCardMapper.selectListByUserIdAndStatus(userId, CouponCardStatusEnum.UNUSED.getValue()); - if (cards.isEmpty()) { - return Collections.emptyList(); - } - // 查询优惠劵模板集合 - Map templates = couponTemplateMapper.selectListByIds(cards.stream().map(CouponCardDO::getTemplateId).collect(Collectors.toSet())) - .stream().collect(Collectors.toMap(CouponTemplateDO::getId, template -> template)); - // 逐个判断是否可用 - List availableCards = cards.stream().map(card -> { - CouponCardAvailableBO availableCard = CouponCardConvert.INSTANCE.convertAvailBO(card, true); - availableCard.setUnavailableReason(isMatch(card, templates.get(card.getTemplateId()), spus)); - availableCard.setAvailable(availableCard.getUnavailableReason() == null); - return availableCard; - }).collect(Collectors.toList()); - // 返回结果 - return availableCards; - } - - private void setCouponCardValidTime(CouponCardDO card, CouponTemplateDO template) { - if (CouponTemplateDateTypeEnum.FIXED_DATE.getValue().equals(template.getDateType())) { - card.setValidStartTime(template.getValidStartTime()).setValidEndTime(template.getValidEndTime()); - } else if (CouponTemplateDateTypeEnum.FIXED_TERM.getValue().equals(template.getDateType())) { - Date validStartTime = DateUtil.getDayBegin(new Date()); - card.setValidStartTime(DateUtil.addDate(validStartTime, Calendar.DAY_OF_YEAR, template.getFixedStartTerm())); - Date validEndTime = DateUtil.getDayEnd(card.getValidStartTime()); - card.setValidEndTime(DateUtil.addDate(validEndTime, Calendar.DAY_OF_YEAR, template.getFixedEndTerm() - 1)); - } - } - - // 如果匹配,则返回 null 即可。 - private String isMatch(CouponCardDO card, CouponTemplateDO template, List spus) { - int totalPrice = 0; - if (RangeTypeEnum.ALL.getValue().equals(template.getRangeType())) { - totalPrice = spus.stream().mapToInt(spu -> spu.getPrice() * spu.getQuantity()).sum(); - } else if (RangeTypeEnum.PRODUCT_INCLUDE_PART.getValue().equals(template.getRangeType())) { - List spuIds = StringUtils.splitToInt(template.getRangeValues(), ","); - totalPrice = spus.stream().mapToInt(spu -> spuIds.contains(spu.getSpuId()) ? spu.getPrice() * spu.getQuantity() : 0).sum(); - } else if (RangeTypeEnum.PRODUCT_EXCLUDE_PART.getValue().equals(template.getRangeType())) { - List spuIds = StringUtils.splitToInt(template.getRangeValues(), ","); - totalPrice = spus.stream().mapToInt(spu -> !spuIds.contains(spu.getSpuId()) ? spu.getPrice() * spu.getQuantity() : 0).sum(); - } else if (RangeTypeEnum.CATEGORY_INCLUDE_PART.getValue().equals(template.getRangeType())) { - List spuIds = StringUtils.splitToInt(template.getRangeValues(), ","); - totalPrice = spus.stream().mapToInt(spu -> spuIds.contains(spu.getCategoryId()) ? spu.getPrice() * spu.getQuantity() : 0).sum(); - } else if (RangeTypeEnum.CATEGORY_EXCLUDE_PART.getValue().equals(template.getRangeType())) { - List spuIds = StringUtils.splitToInt(template.getRangeValues(), ","); - totalPrice = spus.stream().mapToInt(spu -> !spuIds.contains(spu.getCategoryId()) ? spu.getPrice() * spu.getQuantity() : 0).sum(); - } - // 总价为 0 时,说明优惠劵丫根不匹配 - if (totalPrice == 0) { - return "优惠劵不匹配"; - } - // 如果不满足金额 - if (totalPrice < card.getPriceAvailable()) { - return String.format("差 %1$,.2f 元可用优惠劵", (card.getPriceAvailable() - totalPrice) / 100D); - } - return null; - } - - // ========== 优惠码 ========== - - public CouponCardReqDTO useCouponCode(Integer userId, String code) { - return null; - } } diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardAvailableBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardAvailableBO.java deleted file mode 100644 index 2500fcc3a..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardAvailableBO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.mall.promotionservice.service.coupon.bo; - -import cn.iocoder.mall.promotion.api.rpc.coupon.dto.CouponCardReqDTO; -import lombok.Data; -import lombok.experimental.Accessors; - -/** - * 可用优惠劵 BO - * - * 注意,如果优惠劵不可用,标记 available = false ,并写明 unavailableReason 原因 - */ -@Data -@Accessors(chain = true) -public class CouponCardAvailableBO extends CouponCardReqDTO { - - /** - * 是否可用 - */ - private Boolean available; - /** - * 不可用原因 - */ - private String unavailableReason; - -} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardDetailBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardDetailBO.java deleted file mode 100644 index e664d98ce..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardDetailBO.java +++ /dev/null @@ -1,143 +0,0 @@ -package cn.iocoder.mall.promotionservice.service.coupon.bo; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; - -/** - * 优惠劵明细 BO 。 - * - * 主要是,会带上 {@link CouponTemplateBO} 的信息 - */ -@Data -@Accessors(chain = true) -public class CouponCardDetailBO implements Serializable { - - // ========== 基本信息 BEGIN ========== - /** - * 优惠劵编号 - */ - private Integer id; - /** - * 优惠劵(码)分组编号 - */ - private Integer templateId; - /** - * 优惠劵名 - */ - private String title; -// /** -// * 核销码 -// */ -// private String verifyCode; - /** - * 优惠码状态 - * - * 1-未使用 - * 2-已使用 - * 3-已失效 - */ - private Integer status; - - // ========== 基本信息 END ========== - - // ========== 领取情况 BEGIN ========== - /** - * 用户编号 - */ - private Integer userId; - /** - * 领取类型 - * - * 1 - 用户主动领取 - * 2 - 后台自动发放 - */ - private Integer takeType; - // ========== 领取情况 END ========== - - // ========== 使用规则 BEGIN ========== - /** - * 是否设置满多少金额可用,单位:分 - */ - private Integer priceAvailable; - /** - * 生效开始时间 - */ - private Date validStartTime; - /** - * 生效结束时间 - */ - private Date validEndTime; - // ========== 使用规则 END ========== - - // ========== 使用效果 BEGIN ========== - /** - * 优惠类型 - * - * 1-代金卷 - * 2-折扣卷 - */ - private Integer preferentialType; - /** - * 折扣 - */ - private Integer percentOff; - /** - * 优惠金额,单位:分。 - */ - private Integer priceOff; - /** - * 折扣上限,仅在 {@link #preferentialType} 等于 2 时生效。 - * - * 例如,折扣上限为 20 元,当使用 8 折优惠券,订单金额为 1000 元时,最高只可折扣 20 元,而非 80 元。 - */ - private Integer discountPriceLimit; - // ========== 使用效果 END ========== - - // ========== 使用情况 BEGIN ========== - /** - * 是否使用 - */ - private Boolean used; - /** - * 使用订单号 - */ - private Integer usedOrderId; - /** - * 订单中优惠面值,单位:分 - */ - private Integer usedPrice; - /** - * 使用时间 - */ - private Date usedTime; - - // TODO 芋艿,后续要加优惠劵的使用日志,因为下单后,可能会取消。 - - // ========== 使用情况 END ========== - - /** - * 创建时间 - */ - private Date createTime; - - // ========== FROM template 使用规则 BEGIN ========== - /** - * 可用范围的类型 - * - * 10-全部(ALL):所有可用 - * 20-部分(PART):部分商品可用,或指定商品可用 - * 21-部分(PART):部分商品不可用,或指定商品可用 - * 30-部分(PART):部分分类可用,或指定商品可用 - * 31-部分(PART):部分分类不可用,或指定商品可用 - */ - private Integer rangeType; - /** - * 指定商品 / 分类列表,使用逗号分隔商品编号 - */ - private List rangeValues; - -} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardPageBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardPageBO.java deleted file mode 100644 index 59d0eff56..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardPageBO.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.mall.promotionservice.service.coupon.bo; - -import cn.iocoder.mall.promotion.api.rpc.coupon.dto.CouponCardReqDTO; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.List; - -/** - * 优惠劵分页 BO - */ -@Data -@Accessors(chain = true) -public class CouponCardPageBO implements Serializable { - - /** - * 优惠劵数组 - */ - private List list; - /** - * 总量 - */ - private Integer total; - -} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardSpuBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardSpuBO.java deleted file mode 100644 index 32f45d52b..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardSpuBO.java +++ /dev/null @@ -1,40 +0,0 @@ -package cn.iocoder.mall.promotionservice.service.coupon.bo; - -import cn.iocoder.mall.promotion.api.rpc.coupon.CouponRpc; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.List; - -/** - * 优惠劵商品 DTO - * - * 主要用于 {@link CouponRpc#getCouponCardList(Integer, List)} - */ -@Data -@Accessors(chain = true) -public class CouponCardSpuBO implements Serializable { - - /** - * 商品 SPU 编号 - */ - private Integer spuId; - /** - * 商品 SKU 编号 - */ - private Integer skuId; - /** - * 分类编号 - */ - private Integer categoryId; - /** - * 价格 - */ - private Integer price; - /** - * 数量 - */ - private Integer quantity; - -} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardTemplateAddBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardTemplateAddBO.java index 47d149a4a..0f096b254 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardTemplateAddBO.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/coupon/bo/CouponCardTemplateAddBO.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.promotionservice.service.coupon.bo; import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.promotion.api.enums.CouponTemplateDateTypeEnum; +import cn.iocoder.mall.promotion.api.enums.coupon.template.CouponTemplateDateTypeEnum; import cn.iocoder.mall.promotion.api.enums.PreferentialTypeEnum; import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum; import lombok.Data; diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendAddBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendAddBO.java index 5914c0fa9..011e965fa 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendAddBO.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendAddBO.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.promotionservice.service.recommend.bo; import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.promotion.api.enums.ProductRecommendTypeEnum; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendBO.java index da689a69e..99b67ae6d 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendBO.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendBO.java @@ -1,6 +1,6 @@ package cn.iocoder.mall.promotionservice.service.recommend.bo; -import cn.iocoder.mall.promotion.api.enums.ProductRecommendTypeEnum; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; import lombok.Data; import lombok.experimental.Accessors; diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendUpdateBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendUpdateBO.java index 8e8ec9e8f..572a6daba 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendUpdateBO.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendUpdateBO.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.promotionservice.service.recommend.bo; import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.promotion.api.enums.ProductRecommendTypeEnum; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; diff --git a/promotion-service-project/promotion-service-app/src/main/resources/mapper/CouponTemplateMapper.xml b/promotion-service-project/promotion-service-app/src/main/resources/mapper/CouponTemplateMapper.xml new file mode 100644 index 000000000..ee7580f45 --- /dev/null +++ b/promotion-service-project/promotion-service-app/src/main/resources/mapper/CouponTemplateMapper.xml @@ -0,0 +1,12 @@ + + + + + + UPDATE coupon_template + SET stat_fetch_Num = stat_fetch_Num + 1 + WHERE id = #{id} + AND total > stat_fetch_Num + + + diff --git a/promotion-service-project/promotion-service-app/src/test/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/activity/PromotionActivityMapperTest.java b/promotion-service-project/promotion-service-app/src/test/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/activity/PromotionActivityMapperTest.java index ef897ad94..3a5596b0d 100644 --- a/promotion-service-project/promotion-service-app/src/test/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/activity/PromotionActivityMapperTest.java +++ b/promotion-service-project/promotion-service-app/src/test/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/activity/PromotionActivityMapperTest.java @@ -1,6 +1,6 @@ package cn.iocoder.mall.promotionservice.dal.mysql.mapper.activity; -import cn.iocoder.mall.promotion.api.enums.PromotionActivityStatusEnum; +import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityStatusEnum; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity.PromotionActivityDO; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java deleted file mode 100644 index 74c52e38c..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponCardMapper.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.mall.promotion.biz.dao; - -import cn.iocoder.mall.promotion.biz.dataobject.CouponCardDO; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface CouponCardMapper { - - CouponCardDO selectById(@Param("id") Integer id); - - List selectListByUserIdAndStatus(@Param("userId") Integer userId, - @Param("status") Integer status); - - List selectListByPage(@Param("userId") Integer userId, - @Param("status") Integer status, - @Param("offset") Integer offset, - @Param("limit") Integer limit); - - Integer selectCountByPage(@Param("userId") Integer userId, - @Param("status") Integer status); - - int selectCountByUserIdAndTemplateId(@Param("userId") Integer userId, - @Param("templateId") Integer templateId); - - void insert(CouponCardDO couponCardDO); - - int update(CouponCardDO couponCardDO); - - int updateByIdAndStatus(@Param("id") Integer id, - @Param("status") Integer status, - @Param("updateObj") CouponCardDO updateObj); - -} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponTemplateMapper.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponTemplateMapper.java deleted file mode 100644 index a6d727609..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/CouponTemplateMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.mall.promotion.biz.dao; - -import cn.iocoder.mall.promotion.biz.dataobject.CouponTemplateDO; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.Collection; -import java.util.List; - -@Repository -public interface CouponTemplateMapper { - - CouponTemplateDO selectById(@Param("id") Integer id); - - List selectListByIds(@Param("ids") Collection ids); - - List selectListByPage(@Param("type") Integer type, - @Param("title") String title, - @Param("status") Integer status, - @Param("preferentialType") Integer preferentialType, - @Param("offset") Integer offset, - @Param("limit") Integer limit); - - Integer selectCountByPage(@Param("type") Integer type, - @Param("title") String title, - @Param("status") Integer status, - @Param("preferentialType") Integer preferentialType); - - void insert(CouponTemplateDO couponTemplate); - - int update(CouponTemplateDO couponTemplate); - - int updateStatFetchNumIncr(@Param("id") Integer id); - -} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCardDO.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCardDO.java deleted file mode 100644 index b28d9f305..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCardDO.java +++ /dev/null @@ -1,119 +0,0 @@ -package cn.iocoder.mall.promotion.biz.dataobject; - -import cn.iocoder.mall.mybatis.core.dataobject.BaseDO; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Date; - -/** - * 优惠劵 DO - */ -@Data -@Accessors(chain = true) -public class CouponCardDO extends BaseDO { - - // ========== 基本信息 BEGIN ========== - /** - * 优惠劵编号 - */ - private Integer id; - /** - * 优惠劵(码)分组编号,{@link CouponTemplateDO} 的 id - */ - private Integer templateId; - /** - * 优惠劵名 - * - * 冗余自 {@link CouponTemplateDO} 的 title - * - * TODO 芋艿,暂时不考虑冗余的更新 - */ - private String title; -// /** -// * 核销码 -// */ -// private String verifyCode; - /** - * 优惠码状态 - * - * 1-未使用 - * 2-已使用 - * 3-已失效 - */ - private Integer status; - - // ========== 基本信息 END ========== - - // ========== 领取情况 BEGIN ========== - /** - * 用户编号 - */ - private Integer userId; - /** - * 领取类型 - * - * 1 - 用户主动领取 - * 2 - 后台自动发放 - */ - private Integer takeType; - // ========== 领取情况 END ========== - - // ========== 使用规则 BEGIN ========== - /** - * 是否设置满多少金额可用,单位:分 - */ - private Integer priceAvailable; - /** - * 生效开始时间 - */ - private Date validStartTime; - /** - * 生效结束时间 - */ - private Date validEndTime; - // ========== 使用规则 END ========== - - // ========== 使用效果 BEGIN ========== - /** - * 优惠类型 - * - * 1-代金卷 - * 2-折扣卷 - */ - private Integer preferentialType; - /** - * 折扣 - */ - private Integer percentOff; - /** - * 优惠金额,单位:分。 - */ - private Integer priceOff; - /** - * 折扣上限,仅在 {@link #preferentialType} 等于 2 时生效。 - * - * 例如,折扣上限为 20 元,当使用 8 折优惠券,订单金额为 1000 元时,最高只可折扣 20 元,而非 80 元。 - */ - private Integer discountPriceLimit; - // ========== 使用效果 END ========== - - // ========== 使用情况 BEGIN ========== -// /** -// * 使用订单号 -// */ -// private Integer usedOrderId; // TODO 芋艿,暂时不考虑这个字段 -// /** -// * 订单中优惠面值,单位:分 -// */ -// private Integer usedPrice; // TODO 芋艿,暂时不考虑这个字段 - /** - * 使用时间 - */ - private Date usedTime; - - // TODO 芋艿,后续要加优惠劵的使用日志,因为下单后,可能会取消。 - - // ========== 使用情况 END ========== - -} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCodeDO.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCodeDO.java deleted file mode 100644 index 76693d3e0..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponCodeDO.java +++ /dev/null @@ -1,43 +0,0 @@ -package cn.iocoder.mall.promotion.biz.dataobject; - -import cn.iocoder.mall.mybatis.core.dataobject.BaseDO; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Date; - -/** - * 优惠码 - */ -@Data -@Accessors(chain = true) -public class CouponCodeDO extends BaseDO { - - /** - * 编号 - */ - private Integer id; - /** - * 模板编号 {@link CouponTemplateDO} 的 id - */ - private Integer templateId; - /** - * 优惠码 - */ - private Integer code; - /** - * 领取时间 - */ - private Date takeTime; - /** - * 领取用户编号 - */ - private Integer userId; - /** - * 领取的优惠劵编号 - */ - private Integer couponId; - - // TODO 芋艿,后续要考虑状态的追踪 - -} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponTemplateDO.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponTemplateDO.java deleted file mode 100644 index 5ddc020a2..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/CouponTemplateDO.java +++ /dev/null @@ -1,220 +0,0 @@ -package cn.iocoder.mall.promotion.biz.dataobject; - -import cn.iocoder.mall.mybatis.core.dataobject.BaseDO; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Date; - -/** - * 优惠劵(码)模板 DO - * - * 当用户领取时,会生成 {@link CouponCardDO} 优惠劵(码)。 - */ -@Data -@Accessors(chain = true) -public class CouponTemplateDO extends BaseDO { - - // ========== 基本信息 BEGIN ========== - /** - * 模板编号,自增唯一。 - */ - private Integer id; - /** - * 标题 - */ - private String title; - /** - * 使用说明 - */ - private String description; - /** - * 类型 - * - * 1-优惠劵 - * 2-优惠码 - */ - private Integer type; - /** - * 优惠码状态 - * - * {@link cn.iocoder.mall.promotion.api.enums.CouponTemplateStatusEnum} - * - * 当优惠劵(码)开启中,可以手动操作,设置禁用中。 - */ - private Integer status; -// /** -// * 是否可分享领取链接 -// */ -// private Boolean isShare; -// /** -// * 设置为失效时间 -// */ -// private Date invalidTime; -// /** -// * 删除时间 -// */ -// private Date deleteTime; - - // ========== 基本信息 END ========== - - // ========== 领取规则 BEGIN ========== -// /** -// * 是否限制领用者的等级 -// * -// * 0-不限制 -// * 大于0-领用者必须是这个等级编号 -// * -// * 【优惠劵独有】 -// */ -// private Integer needUserLevel; - /** - * 每人限领个数 - * - * null - 则表示不限制 - */ - private Integer quota; - /** - * 发行总量 - */ - private Integer total; - // ========== 领取规则 END ========== - - // ========== 使用规则 BEGIN ========== -// /** -// * 是否仅原价购买商品时可用 -// * -// * true-是 -// * false-否 -// */ -// private Boolean isForbidPreference; - /** - * 是否设置满多少金额可用,单位:分 - * - * 0-不限制 - * 大于0-多少金额可用 - */ - private Integer priceAvailable; - /** - * 可用范围的类型 - * - * 10-全部(ALL):所有可用 - * 20-部分(PART):部分商品可用,或指定商品可用 - * 21-部分(PART):部分商品不可用,或指定商品可用 - * 30-部分(PART):部分分类可用,或指定商品可用 - * 31-部分(PART):部分分类不可用,或指定商品可用 - */ - private Integer rangeType; - /** - * 指定商品 / 分类列表,使用逗号分隔商品编号 - */ - private String rangeValues; - /** - * 生效日期类型 - * - * 1-固定日期 - * 2-领取日期:领到券 {@link #fixedStartTerm} 日开始 N 天内有效 - */ - private Integer dateType; - /** - * 固定日期-生效开始时间 - */ - private Date validStartTime; - /** - * 固定日期-生效结束时间 - */ - private Date validEndTime; - /** - * 领取日期-开始天数 - * - * 例如,0-当天;1-次天 - */ - private Integer fixedStartTerm; - /** - * 领取日期-结束天数 - */ - private Integer fixedEndTerm; -// /** -// * 是否到期前4天发送提醒 -// * -// * true-发送 -// * false-不发送 -// */ -// private Boolean expireNotice; - // ========== 使用规则 END ========== - - // ========== 使用效果 BEGIN ========== - /** - * 优惠类型 - * - * 1-代金卷 - * 2-折扣卷 - */ - private Integer preferentialType; - /** - * 折扣百分比。 - * - * 例如,80% 为 80。 - * 当 100% 为 100 ,则代表免费。 - */ - private Integer percentOff; -// /** -// * 是否是随机优惠券 -// * -// * true-随机 -// * false-不随机 -// * -// * 【优惠劵独有】 -// */ -// private Boolean isRandom; - /** - * 优惠金额,单位:分 - */ -// * 当 {@link #isRandom} 为 true 时,代表随机优惠金额的下限 - private Integer priceOff; -// /** -// * 优惠金额上限 -// * -// * 【优惠劵独有】 -// */ -// private Integer valueRandomTo; - /** - * 折扣上限,仅在 {@link #preferentialType} 等于 2 时生效。 - * - * 例如,折扣上限为 20 元,当使用 8 折优惠券,订单金额为 1000 元时,最高只可折扣 20 元,而非 80 元。 - */ - private Integer discountPriceLimit; - // ========== 使用效果 END ========== - - // ========== 统计信息 BEGIN ========== -// /** -// * 领取优惠券的人数 -// */ -// private Integer statFetchUserNum; - /** - * 领取优惠券的次数 - */ - private Integer statFetchNum; -// /** -// * 使用优惠券的次数 -// */ -// private Integer statUseNum; - // ========== 统计信息 END ========== - - // ========== 优惠码 BEGIN ========== - /** - * 码类型 - * - * 1-一卡一码(UNIQUE) - * 2-通用码(GENERAL) - * - * 【优惠码独有】 @see CouponCodeDO - */ - private Integer codeType; - /** - * 通用码 - */ - private String commonCode; - // ========== 优惠码 BEGIN ========== - -} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/mybatis/TestHandler.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/mybatis/TestHandler.java deleted file mode 100644 index e0a7cd47b..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/mybatis/TestHandler.java +++ /dev/null @@ -1,12 +0,0 @@ -package cn.iocoder.mall.promotion.biz.mybatis; - -import cn.iocoder.mall.mybatis.core.type.JSONTypeHandler; -import cn.iocoder.mall.promotion.biz.dataobject.PromotionActivityDO; - -public class TestHandler extends JSONTypeHandler { - - public TestHandler(Class clazz) { - super(clazz); - } - -} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/scheduler/CouponCardExpireJob.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/scheduler/CouponCardExpireJob.java deleted file mode 100644 index 21bfe32eb..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/scheduler/CouponCardExpireJob.java +++ /dev/null @@ -1,9 +0,0 @@ -package cn.iocoder.mall.promotion.biz.scheduler; - -/** - * 优惠劵过期 Job - * - * TODO 芋艿 - */ -public class CouponCardExpireJob { -} diff --git a/promotion/promotion-service-impl/src/main/resources/config/application.yaml b/promotion/promotion-service-impl/src/main/resources/config/application.yaml deleted file mode 100644 index 048cbd1ea..000000000 --- a/promotion/promotion-service-impl/src/main/resources/config/application.yaml +++ /dev/null @@ -1,76 +0,0 @@ -spring: - # datasource - datasource: - type: com.alibaba.druid.pool.DruidDataSource - url: jdbc:mysql://s1.iocoder.cn:3306/mall_promotion?useSSL=false&useUnicode=true&characterEncoding=UTF-8 - driver-class-name: com.mysql.jdbc.Driver - username: root - password: 3WLiVUBEwTbvAfsh - - # Spring Cloud 配置项 - cloud: - nacos: - # Spring Cloud Nacos Discovery 配置项 - discovery: - server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址 - -# mybatis-plus -mybatis-plus: - configuration: - map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。 - global-config: - db-config: - id-type: auto - mapper-locations: classpath*:mapper/*.xml - type-aliases-package: cn.iocoder.mall.promotion.biz.dataobject - -# Dubbo 配置项 -dubbo: - # Dubbo 注册中心 - registry: - address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址 - # Spring Cloud Alibaba Dubbo 专属配置 - cloud: - subscribed-services: admin-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用 - # Dubbo 提供者的协议 - protocol: - name: dubbo - port: -1 - # Dubbo 提供服务的扫描基础包 - scan: - base-packages: cn.iocoder.mall.promotion.biz.service - consumer: - ProductSpuService: - version: 1.0.0 - # Dubbo 服务提供者的配置 - provider: - filter: -exception - BannerService: - version: 1.0.0 - CouponService: - version: 1.0.0 - ProductRecommendService: - version: 1.0.0 - PromotionActivityService: - version: 1.0.0 - -# Seata 配置项 -seata: - tx-service-group: default # Seata 事务组编号,用于 TC 集群名 - # 服务配置项,对应 ServiceProperties 类 - service: - # 虚拟组和分组的映射 - vgroup-mapping: - default: default - # Seata 注册中心配置项 - registry: - type: nacos # 注册中心类型 - nacos: - serverAddr: ${spring.cloud.nacos.discovery.server-addr} # Nacos 服务地址 - namespace: # Nacos 命名空间 - cluster: default # 使用的 Seata 分组 - -# logging -logging: - level: - cn.iocoder.mall.promotion.dao: debug diff --git a/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml b/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml deleted file mode 100644 index 1bde18757..000000000 --- a/promotion/promotion-service-impl/src/main/resources/mapper/CouponCardMapper.xml +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - id, template_id, title, status, user_id, take_type, - price_available, valid_start_time, valid_end_time, preferential_type, percent_off, price_off, - discount_price_limit, used_time, - create_time - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - INSERT INTO coupon_card ( - template_id, title, status, user_id, take_type, - price_available, valid_start_time, valid_end_time, preferential_type, percent_off, price_off, - discount_price_limit, used_time, - create_time - ) VALUES ( - #{templateId}, #{title}, #{status}, #{userId}, #{takeType}, - #{priceAvailable}, #{validStartTime}, #{validEndTime}, #{preferentialType}, #{percentOff}, #{priceOff}, - #{discountPriceLimit}, #{usedTime}, - #{createTime} - ) - - - - UPDATE coupon_card - - - status = #{status}, - - - used_time = #{usedTime}, - - - WHERE id = #{id} - - - - UPDATE coupon_card - - - status = #{updateObj.status}, - - - used_time = #{updateObj.usedTime}, - - - WHERE id = #{id} - AND status = #{status} - - - diff --git a/promotion/promotion-service-impl/src/main/resources/mapper/CouponTemplateMapper.xml b/promotion/promotion-service-impl/src/main/resources/mapper/CouponTemplateMapper.xml deleted file mode 100644 index 4e2c9c294..000000000 --- a/promotion/promotion-service-impl/src/main/resources/mapper/CouponTemplateMapper.xml +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - id, title, description, type, code_type, - status, quota, total, price_available, range_type, - range_values, date_type, valid_start_time, valid_end_time, fixed_start_term, fixed_end_term, - preferential_type, percent_off, price_off, discount_price_limit, stat_fetch_num, - create_time - - - - - - - - - - - - - - - - - - - - - - - - - - - - - INSERT INTO coupon_template ( - title, description, type, code_type, - status, quota, total, price_available, range_type, - range_values, date_type, valid_start_time, valid_end_time, fixed_start_term, fixed_end_term, - preferential_type, percent_off, price_off, discount_price_limit, stat_fetch_num, - create_time - ) VALUES ( - #{title}, #{description}, #{type}, #{codeType}, - #{status}, #{quota}, #{total}, #{priceAvailable}, #{rangeType}, - #{rangeValues}, #{dateType}, #{validStartTime}, #{validEndTime}, #{fixedStartTerm}, #{fixedEndTerm} - #{preferentialType}, #{percentOff}, #{priceOff}, #{discountPriceLimit}, #{statFetchNum}, - #{createTime} - ) - - - - UPDATE coupon_template - - - title = #{title}, - - - description = #{description}, - - - status = #{status}, - - - quota = #{quota}, - - - total = #{total}, - - - price_available = #{priceAvailable}, - - - range_type = #{rangeType}, - - - range_values = #{rangeValues}, - - - date_type = #{dateType}, - - - valid_start_time = #{validStartTime}, - - - valid_end_time = #{validEndTime}, - - - fixed_start_term = #{fixedStartTerm}, - - - fixed_end_term = #{fixedEndTerm}, - - - preferential_type = #{preferentialType}, - - - percent_off = #{percentOff}, - - - price_off = #{priceOff}, - - - discount_price_limit = #{discountPriceLimit}, - - - WHERE id = #{id} - - - - UPDATE coupon_template - SET stat_fetch_Num = stat_fetch_Num + 1 - WHERE id = #{id} - AND total > stat_fetch_Num - - - diff --git a/promotion/promotion-service-impl/src/test/java/cn/iocoder/mall/promotion/biz/Application.java b/promotion/promotion-service-impl/src/test/java/cn/iocoder/mall/promotion/biz/Application.java deleted file mode 100644 index 19c4fba0f..000000000 --- a/promotion/promotion-service-impl/src/test/java/cn/iocoder/mall/promotion/biz/Application.java +++ /dev/null @@ -1,7 +0,0 @@ -package cn.iocoder.mall.promotion.biz; - -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.promotion"}) -public class Application { -} diff --git a/promotion/promotion-service-impl/src/test/java/cn/iocoder/mall/promotion/biz/dao/PromotionActivityMapperTest.java b/promotion/promotion-service-impl/src/test/java/cn/iocoder/mall/promotion/biz/dao/PromotionActivityMapperTest.java deleted file mode 100644 index 8a576e88c..000000000 --- a/promotion/promotion-service-impl/src/test/java/cn/iocoder/mall/promotion/biz/dao/PromotionActivityMapperTest.java +++ /dev/null @@ -1,94 +0,0 @@ -package cn.iocoder.mall.promotion.biz.dao; - -import cn.iocoder.common.framework.util.DateUtil; -import cn.iocoder.mall.promotion.api.enums.PreferentialTypeEnum; -import cn.iocoder.mall.promotion.api.enums.PromotionActivityStatusEnum; -import cn.iocoder.mall.promotion.api.enums.PromotionActivityTypeEnum; -import cn.iocoder.mall.promotion.api.enums.RangeTypeEnum; -import cn.iocoder.mall.promotion.biz.dataobject.PromotionActivityDO; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) -public class PromotionActivityMapperTest { - - @Autowired - private PromotionActivityMapper promotionActivityMapper; - - /** - * 插入限时折扣活动 - */ - @Test - @Ignore - public void testInsert01() { - // 创建 PromotionActivityDO 对象 - PromotionActivityDO activityDO = new PromotionActivityDO(); - activityDO.setTitle("老板跑路了"); - activityDO.setActivityType(PromotionActivityTypeEnum.TIME_LIMITED_DISCOUNT.getValue()); - activityDO.setStatus(PromotionActivityStatusEnum.RUN.getValue()); - activityDO.setStartTime(new Date()); - activityDO.setEndTime(DateUtil.addDate(new Date(), Calendar.DAY_OF_YEAR, 100)); - activityDO.setCreateTime(new Date()); - // 创建 TimeLimitedDiscount 对象 - PromotionActivityDO.TimeLimitedDiscount discount = new PromotionActivityDO.TimeLimitedDiscount(); - discount.setQuota(0); - discount.setItems(new ArrayList<>()); - PromotionActivityDO.TimeLimitedDiscount.Item item01 = new PromotionActivityDO.TimeLimitedDiscount.Item(); - item01.setSpuId(32); - item01.setPreferentialType(PreferentialTypeEnum.DISCOUNT.getValue()); - item01.setPreferentialValue(40); - discount.getItems().add(item01); - activityDO.setTimeLimitedDiscount(discount); - promotionActivityMapper.insert(activityDO); - } - - /** - * 插入满减送活动 - */ - @Test - public void testInsert02() { - // 创建 PromotionActivityDO 对象 - PromotionActivityDO activityDO = new PromotionActivityDO(); - activityDO.setTitle("老四赶海"); - activityDO.setActivityType(PromotionActivityTypeEnum.FULL_PRIVILEGE.getValue()); - activityDO.setStatus(PromotionActivityStatusEnum.RUN.getValue()); - activityDO.setStartTime(new Date()); - activityDO.setEndTime(DateUtil.addDate(new Date(), Calendar.DAY_OF_YEAR, 100)); - activityDO.setCreateTime(new Date()); - // 创建 TimeLimitedDiscount 对象 - PromotionActivityDO.FullPrivilege fullPrivilege = new PromotionActivityDO.FullPrivilege(); - fullPrivilege.setRangeType(RangeTypeEnum.ALL.getValue()); - fullPrivilege.setCycled(Boolean.FALSE); - fullPrivilege.setPrivileges(new ArrayList<>()); - PromotionActivityDO.FullPrivilege.Privilege privilege01 = new PromotionActivityDO.FullPrivilege.Privilege(); - privilege01.setMeetType(1); // TODO 芋艿,硬编码 - privilege01.setMeetValue(20); - privilege01.setPreferentialType(PreferentialTypeEnum.DISCOUNT.getValue()); - privilege01.setPreferentialValue(80); - fullPrivilege.getPrivileges().add(privilege01); - activityDO.setFullPrivilege(fullPrivilege); - promotionActivityMapper.insert(activityDO); - } - - /** - * 查询促销活动 - */ - @Test - public void testSelectById() { - PromotionActivityDO activity01 = promotionActivityMapper.selectById(1); - System.out.println(activity01); - - PromotionActivityDO activity02 = promotionActivityMapper.selectById(2); - System.out.println(activity02); - } - -} diff --git a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/PromotionApplication.java b/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/PromotionApplication.java deleted file mode 100644 index fd77f32e4..000000000 --- a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/PromotionApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.iocoder.mall.promotion.application; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.promotion"}) -public class PromotionApplication { - - public static void main(String[] args) { - SpringApplication.run(PromotionApplication.class, args); - } - -} diff --git a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java b/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java deleted file mode 100644 index 76a8601e7..000000000 --- a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponCardConvert.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.mall.promotion.application.convert; - -import cn.iocoder.mall.promotion.api.bo.CouponCardBO; -import cn.iocoder.mall.promotion.api.bo.CouponCardPageBO; -import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardPageVO; -import cn.iocoder.mall.promotion.application.vo.users.UsersCouponCardVO; -import org.mapstruct.Mapper; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface CouponCardConvert { - - CouponCardConvert INSTANCE = Mappers.getMapper(CouponCardConvert.class); - - @Mappings({}) - UsersCouponCardVO convert(CouponCardBO result); - - @Mappings({}) - UsersCouponCardPageVO convert2(CouponCardPageBO result); - -// -// @Mappings({}) -// List convertList2(List banners); - - - -} diff --git a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponTemplateConvert.java b/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponTemplateConvert.java deleted file mode 100644 index ac6ed4bcf..000000000 --- a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/CouponTemplateConvert.java +++ /dev/null @@ -1,43 +0,0 @@ -package cn.iocoder.mall.promotion.application.convert; - -import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO; -import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO; -import cn.iocoder.mall.promotion.application.vo.admins.AdminsCouponTemplatePageVO; -import cn.iocoder.mall.promotion.application.vo.admins.AdminsCouponTemplateVO; -import cn.iocoder.mall.promotion.application.vo.users.UsersCouponTemplateVO; -import org.mapstruct.Mapper; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface CouponTemplateConvert { - - Users USERS = Mappers.getMapper(Users.class); - - Admins ADMINS = Mappers.getMapper(Admins.class); - - @Mapper - interface Admins { - - @Mappings({}) - AdminsCouponTemplateVO convert(CouponTemplateBO template); - - @Mappings({}) - AdminsCouponTemplatePageVO convertPage(CouponTemplatePageBO result); - - @Mappings({}) - List convertList(List templates); - - } - - @Mapper - interface Users { - - @Mappings({}) - UsersCouponTemplateVO convert2(CouponTemplateBO template); - - } - -} diff --git a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardPageVO.java b/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardPageVO.java deleted file mode 100644 index cd12eca5d..000000000 --- a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardPageVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.mall.promotion.application.vo.users; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.List; - -@ApiModel("优惠劵分页 VO") -@Data -@Accessors(chain = true) -public class UsersCouponCardPageVO { - - @ApiModelProperty(value = "优惠劵数组") - private List list; - @ApiModelProperty(value = "优惠劵总数") - private Integer total; - -} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/CartController.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/CartController.java index ac3659822..32cfa2a7d 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/CartController.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/CartController.java @@ -3,7 +3,7 @@ package cn.iocoder.mall.shopweb.controller.order; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder; import cn.iocoder.mall.shopweb.controller.order.vo.cart.CartDetailVO; -import cn.iocoder.mall.shopweb.manager.order.cart.CartManager; +import cn.iocoder.mall.shopweb.manager.order.CartManager; import cn.iocoder.security.annotations.RequiresAuthenticate; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/OrderController.http b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/OrderController.http new file mode 100644 index 000000000..5bc462fda --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/OrderController.http @@ -0,0 +1,11 @@ +### /order/confirm-create-order-info 基于商品,确认创建订单 +GET {{shop-api-base-url}}/order/confirm-create-order-info?skuId=33&quantity=1 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{user-access-token}} + +### /order/confirm-create-order-info-from-cart 基于购物车,确认创建订单 +GET {{shop-api-base-url}}/order/confirm-create-order-info-from-cart +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{user-access-token}} + +### diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/OrderController.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/OrderController.java new file mode 100644 index 000000000..1ce43e979 --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/OrderController.java @@ -0,0 +1,49 @@ +package cn.iocoder.mall.shopweb.controller.order; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder; +import cn.iocoder.mall.shopweb.controller.order.vo.order.OrderConfirmCreateInfoRespVO; +import cn.iocoder.mall.shopweb.manager.order.OrderManager; +import cn.iocoder.security.annotations.RequiresAuthenticate; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +@Api(tags = "订单 API") +@RestController +@RequestMapping("/order") +@Validated +public class OrderController { + + @Autowired + private OrderManager orderManager; + + @GetMapping("confirm-create-order-info") + @ApiOperation("基于商品,确认创建订单") + @ApiImplicitParams({ + @ApiImplicitParam(name = "skuId", required = true, value = "商品 SKU 编号", example = "1024"), + @ApiImplicitParam(name = "quantity", required = true, value = "购买数量", example = "2"), + @ApiImplicitParam(name = "couponCardId", value = "优惠劵编号", example = "1"), + }) + @RequiresAuthenticate + public CommonResult getOrderConfirmCreateInfo(@RequestParam("skuId") Integer skuId, + @RequestParam("quantity") Integer quantity, + @RequestParam(value = "couponCardId", required = false) Integer couponCardId) { + return success(orderManager.getOrderConfirmCreateInfo(UserSecurityContextHolder.getUserId(), skuId, quantity, couponCardId)); + } + + @GetMapping("confirm-create-order-info-from-cart") + @ApiOperation("基于购物车,确认创建订单") + @ApiImplicitParam(name = "couponCardId", value = "优惠劵编号", example = "1") + @RequiresAuthenticate + public CommonResult getOrderConfirmCreateInfoFromCart(@RequestParam(value = "couponCardId", required = false) Integer couponCardId) { + return success(orderManager.getOrderConfirmCreateInfoFromCart(UserSecurityContextHolder.getUserId(), couponCardId)); + } + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/vo/cart/CartDetailVO.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/vo/cart/CartDetailVO.java index b1cad10b9..5f1546c71 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/vo/cart/CartDetailVO.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/vo/cart/CartDetailVO.java @@ -8,7 +8,7 @@ import lombok.experimental.Accessors; import java.util.List; -@ApiModel(value = "用户的购物车明细 VO") +@ApiModel(value = "用户的购物车明细 Response VO") // TODO 芋艿:swagger 文档完善 @Data @Accessors(chain = true) public class CartDetailVO { diff --git a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/response/UsersOrderConfirmCreateResponse.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/vo/order/OrderConfirmCreateInfoRespVO.java similarity index 74% rename from order/order-rest/src/main/java/cn/iocoder/mall/order/rest/response/UsersOrderConfirmCreateResponse.java rename to shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/vo/order/OrderConfirmCreateInfoRespVO.java index d16970dd0..4335c811a 100644 --- a/order/order-rest/src/main/java/cn/iocoder/mall/order/rest/response/UsersOrderConfirmCreateResponse.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/order/vo/order/OrderConfirmCreateInfoRespVO.java @@ -1,12 +1,19 @@ -package cn.iocoder.mall.order.rest.response; +package cn.iocoder.mall.shopweb.controller.order.vo.order; -import java.util.List; +import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableRespDTO; +import cn.iocoder.mall.shopweb.controller.order.vo.cart.CartDetailVO; +import cn.iocoder.mall.shopweb.controller.product.vo.attr.ProductAttrKeyValueRespVO; +import io.swagger.annotations.ApiModel; import lombok.Data; import lombok.experimental.Accessors; +import java.util.List; + +@ApiModel(value = "订单确认创建信息 Response VO") // TODO 芋艿:swagger 文档完善 @Data -@Accessors(chain = true) -public class UsersOrderConfirmCreateResponse { +@Accessors(chain = true) // TODO 芋艿:和 CartDetailVO、ProductSkuCalcPriceRespVO 有点重复,后续要优化下; +public class OrderConfirmCreateInfoRespVO { /** * 商品分组数组 @@ -16,14 +23,12 @@ public class UsersOrderConfirmCreateResponse { * 费用 */ private Fee fee; + /** * 优惠劵列表 TODO 芋艿,后续改改 */ -// private List couponCards; - /** - * 优惠劵优惠金额 - */ - private Integer couponCardDiscountTotal; + private List couponCards; + /** * 商品分组 * @@ -36,13 +41,18 @@ public class UsersOrderConfirmCreateResponse { /** * 优惠活动 */ - // TODO 芋艿,目前只会有【满减送】的情况,未来有新的促销方式,可能需要改成数组 - // TODO 芋艿,后面改成 VO -// private PromotionActivityBO activity; + private PromotionActivityRespDTO activity; // TODO 芋艿,偷懒 + /** + * 促销减少的金额 + * + * 1. 若未参与促销活动,或不满足促销条件,返回 null + * 2. 该金额,已经分摊到每个 Item 的 discountTotal ,需要注意。 + */ + private Integer activityDiscountTotal; /** * 商品数组 */ - private List items; + private List items; } @@ -66,7 +76,7 @@ public class UsersOrderConfirmCreateResponse { /** * 规格值数组 */ -// private List attrs; // TODO 后面改下 + private List attrs; // TODO 后面改下 /** * 价格,单位:分 */ @@ -82,6 +92,10 @@ public class UsersOrderConfirmCreateResponse { * 购买数量 */ private Integer buyQuantity; + /** + * 优惠活动 + */ + private PromotionActivityRespDTO activity; // TODO 芋艿,偷懒 /** * 原始单价,单位:分。 */ @@ -182,10 +196,11 @@ public class UsersOrderConfirmCreateResponse { this.postageTotal = postageTotal; this.presentTotal = presentTotal; } + } /** - * 邮费信息 + * 邮费信息 TODO 芋艿,未完成 */ @Data @Accessors(chain = true) diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSkuController.http b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSkuController.http new file mode 100644 index 000000000..32329b3ac --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSkuController.http @@ -0,0 +1,5 @@ +### /product-spu/page 计算商品 SKU 价格 +GET {{shop-api-base-url}}/product-sku/cal-price?id=33 +Content-Type: application/x-www-form-urlencoded + +### diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSkuController.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSkuController.java new file mode 100644 index 000000000..5fc6c3bc2 --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/ProductSkuController.java @@ -0,0 +1,33 @@ +package cn.iocoder.mall.shopweb.controller.product; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder; +import cn.iocoder.mall.shopweb.controller.product.vo.sku.ProductSkuCalcPriceRespVO; +import cn.iocoder.mall.shopweb.manager.product.ProductSkuManager; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = "商品 SKU API") +@RestController +@RequestMapping("/product-sku") +@Validated +public class ProductSkuController { + + @Autowired + private ProductSkuManager productSkuManager; + + @GetMapping("/cal-price") + @ApiOperation("计算商品 SKU 价格") + @ApiImplicitParam(name = "id", required = true, value = "商品 SKU 编号", example = "1024") + public CommonResult calcProductSkuPrice(@RequestParam("id") Integer id) { + return CommonResult.success(productSkuManager.calcProductSkuPrice(UserSecurityContextHolder.getUserId(), id)); + } + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/sku/ProductSkuCalcPriceRespVO.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/sku/ProductSkuCalcPriceRespVO.java new file mode 100644 index 000000000..b4dc56090 --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/product/vo/sku/ProductSkuCalcPriceRespVO.java @@ -0,0 +1,35 @@ +package cn.iocoder.mall.shopweb.controller.product.vo.sku; + +import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.experimental.Accessors; + +@ApiModel("计算商品 SKU 价格结果 VO") +@Data +@Accessors(chain = true) +// TODO 芋艿:swagger 注解 +public class ProductSkuCalcPriceRespVO { + + /** + * 原价格,单位:分。 + */ + private Integer originalPrice; + /** + * 最终价格,单位:分。 + */ + private Integer buyPrice; + /** + * 满减送促销活动 + * + * TODO 芋艿,后续改成 VO + */ + private PromotionActivityRespDTO fullPrivilege; + /** + * 限时折扣促销活动 + * + * TODO 芋艿,后续改成 VO + */ + private PromotionActivityRespDTO timeLimitedDiscount; + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/CouponCardController.http b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/CouponCardController.http new file mode 100644 index 000000000..d42640384 --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/CouponCardController.http @@ -0,0 +1,23 @@ +### /promotion/coupon-card/page 优惠劵分页(未使用) +GET {{shop-api-base-url}}/promotion/coupon-card/page?pageNo=1&pageSize=10&status=1 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{user-access-token}} + +### /promotion/coupon-card/page 优惠劵分页(已使用) +GET {{shop-api-base-url}}/promotion/coupon-card/page?pageNo=1&pageSize=10&status=2 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{user-access-token}} + +### /promotion/coupon-card/page 优惠劵分页(已过期) +GET {{shop-api-base-url}}/promotion/coupon-card/page?pageNo=1&pageSize=10&status=3 +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{user-access-token}} + +### /promotion/coupon-card/create 用户领取优惠劵(成功) +POST {{shop-api-base-url}}/promotion/coupon-card/create +Content-Type: application/x-www-form-urlencoded +Authorization: Bearer {{user-access-token}} + +couponTemplateId=1 + +### diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/CouponCardController.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/CouponCardController.java new file mode 100644 index 000000000..9ca14e00b --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/CouponCardController.java @@ -0,0 +1,43 @@ +package cn.iocoder.mall.shopweb.controller.promotion; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder; +import cn.iocoder.mall.shopweb.controller.promotion.vo.coupon.card.CouponCardPageReqVO; +import cn.iocoder.mall.shopweb.controller.promotion.vo.coupon.card.CouponCardRespVO; +import cn.iocoder.mall.shopweb.manager.promotion.CouponCardManager; +import cn.iocoder.security.annotations.RequiresAuthenticate; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +@RestController +@RequestMapping("/promotion/coupon-card") +@Api(tags = "优惠劵 API") +@Validated +public class CouponCardController { + + @Autowired + private CouponCardManager couponCardManager; + + @GetMapping("/page") + @ApiOperation("获得优惠劵分页") + @RequiresAuthenticate + public CommonResult> pageCouponCard(CouponCardPageReqVO pageVO) { + return success(couponCardManager.pageCouponCard(UserSecurityContextHolder.getUserId(),pageVO)); + } + + @PostMapping("/create") + @ApiOperation("用户领取优惠劵") + @ApiImplicitParam(name = "couponTemplateId", value = "优惠劵模板编号", required = true, example = "1024") + @RequiresAuthenticate + public CommonResult createCouponCard(@RequestParam("couponTemplateId") Integer couponTemplateId) { + return success(couponCardManager.createCouponCard(UserSecurityContextHolder.getUserId(), couponTemplateId)); + } + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/vo/coupon/card/CouponCardPageReqVO.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/vo/coupon/card/CouponCardPageReqVO.java new file mode 100644 index 000000000..a64f3d785 --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/vo/coupon/card/CouponCardPageReqVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.mall.shopweb.controller.promotion.vo.coupon.card; + +import cn.iocoder.common.framework.vo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel("优惠劵分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +public class CouponCardPageReqVO extends PageParam { + + @ApiModelProperty(value = "优惠码状态", required = true, example = "1", notes = "对应 CouponCardStatusEnum 枚举") + private Integer status; + +} diff --git a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardVO.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/vo/coupon/card/CouponCardRespVO.java similarity index 89% rename from promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardVO.java rename to shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/vo/coupon/card/CouponCardRespVO.java index 7381cdafe..f48dc4e23 100644 --- a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/vo/users/UsersCouponCardVO.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/controller/promotion/vo/coupon/card/CouponCardRespVO.java @@ -1,17 +1,16 @@ -package cn.iocoder.mall.promotion.application.vo.users; +package cn.iocoder.mall.shopweb.controller.promotion.vo.coupon.card; +import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; import java.util.Date; -/** - * 优惠劵 VO - */ +@ApiModel("优惠劵 Response VO") @Data @Accessors(chain = true) -public class UsersCouponCardVO { +public class CouponCardRespVO { // ========== 基本信息 BEGIN ========== @ApiModelProperty(value = "优惠劵编号", required = true, example = "1") @@ -47,8 +46,6 @@ public class UsersCouponCardVO { // ========== 使用情况 BEGIN ========== - // TODO 芋艿,后续要加优惠劵的使用日志,因为下单后,可能会取消。 - // ========== 使用情况 END ========== } diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/order/OrderConvert.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/order/OrderConvert.java new file mode 100644 index 000000000..1829749b6 --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/order/OrderConvert.java @@ -0,0 +1,33 @@ +package cn.iocoder.mall.shopweb.convert.order; + +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableListReqDTO; +import cn.iocoder.mall.promotion.api.rpc.price.dto.PriceProductCalcRespDTO; +import cn.iocoder.mall.shopweb.controller.order.vo.order.OrderConfirmCreateInfoRespVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@Mapper +public interface OrderConvert { + + OrderConvert INSTANCE = Mappers.getMapper(OrderConvert.class); + + OrderConfirmCreateInfoRespVO.Fee convert(PriceProductCalcRespDTO.Fee bean); + + default List convertList(List itemGroups) { + List items = new ArrayList<>(); + itemGroups.forEach(itemGroup -> items.addAll(itemGroup.getItems().stream().map( + item -> new CouponCardAvailableListReqDTO.Item() + .setSpuId(item.getSpuId()) + .setSkuId(item.getSkuId()) + .setCid(item.getCid()) + .setPrice(item.getBuyPrice()) + .setQuantity(item.getBuyQuantity())) + .collect(Collectors.toList()))); + return items; + } + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/product/ProductSkuConvert.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/product/ProductSkuConvert.java new file mode 100644 index 000000000..3f4271137 --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/product/ProductSkuConvert.java @@ -0,0 +1,20 @@ +package cn.iocoder.mall.shopweb.convert.product; + +import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO; +import cn.iocoder.mall.promotion.api.rpc.price.dto.PriceProductCalcRespDTO; +import cn.iocoder.mall.shopweb.controller.product.vo.sku.ProductSkuCalcPriceRespVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ProductSkuConvert { + + ProductSkuConvert INSTANCE = Mappers.getMapper(ProductSkuConvert.class); + + default ProductSkuCalcPriceRespVO convert(PriceProductCalcRespDTO.Item item, + PromotionActivityRespDTO fullPrivilege, PromotionActivityRespDTO timeLimitedDiscount) { + return new ProductSkuCalcPriceRespVO().setOriginalPrice(item.getOriginPrice()).setBuyPrice(item.getBuyPrice()) + .setFullPrivilege(fullPrivilege).setTimeLimitedDiscount(timeLimitedDiscount); + } + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/promotion/CouponCardConvert.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/promotion/CouponCardConvert.java new file mode 100644 index 000000000..543debce8 --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/convert/promotion/CouponCardConvert.java @@ -0,0 +1,23 @@ +package cn.iocoder.mall.shopweb.convert.promotion; + +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardPageReqDTO; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardRespDTO; +import cn.iocoder.mall.shopweb.controller.promotion.vo.coupon.card.CouponCardPageReqVO; +import cn.iocoder.mall.shopweb.controller.promotion.vo.coupon.card.CouponCardRespVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * 优惠劵 Convert + */ +@Mapper +public interface CouponCardConvert { + + CouponCardConvert INSTANCE = Mappers.getMapper(CouponCardConvert.class); + + PageResult convertPage(PageResult page); + + CouponCardPageReqDTO convert(CouponCardPageReqVO bean); + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/enums/ShopWebErrorCodeConstants.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/enums/ShopWebErrorCodeConstants.java new file mode 100644 index 000000000..418a027b4 --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/enums/ShopWebErrorCodeConstants.java @@ -0,0 +1,16 @@ +package cn.iocoder.mall.shopweb.enums; + +import cn.iocoder.common.framework.exception.ErrorCode; + +/** + * 错误码枚举类 + * + * shop web 系统,使用 1-007-000-000 段 + */ +public interface ShopWebErrorCodeConstants { + + // ========== ORDER 模块 ========== + ErrorCode ORDER_PRODUCT_SKU_NOT_EXISTS = new ErrorCode(1007000001, "商品 SKU 不存在!"); + ErrorCode ORDER_PRODUCT_SKU_QUANTITY_NOT_ENOUGH = new ErrorCode(1007000001, "商品 SKU 库存不足!"); + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/order/cart/CartManager.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/order/CartManager.java similarity index 98% rename from shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/order/cart/CartManager.java rename to shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/order/CartManager.java index 1c08dc5fd..acc56c424 100644 --- a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/order/cart/CartManager.java +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/order/CartManager.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.shopweb.manager.order.cart; +package cn.iocoder.mall.shopweb.manager.order; import cn.iocoder.common.framework.util.CollectionUtils; import cn.iocoder.common.framework.vo.CommonResult; @@ -94,7 +94,7 @@ public class CartManager { * @return 商品列表 */ public CartDetailVO getCartDetail(Integer userId) { - // 获得购物车中选中的 + // 获得购物车的商品 CommonResult> listCartItemsResult = cartRpc.listCartItems(new CartItemListReqDTO().setUserId(userId)); listCartItemsResult.checkError(); // 购物车为空时,构造空的 UsersOrderConfirmCreateVO 返回 @@ -104,7 +104,7 @@ public class CartManager { result.setFee(new CartDetailVO.Fee(0, 0, 0, 0)); return result; } - // 计算选中的商品价格 + // 计算商品价格 CommonResult calcProductPriceResult = priceRpc.calcProductPrice(new PriceProductCalcReqDTO().setUserId(userId) .setItems(listCartItemsResult.getData().stream() .map(cartItem -> new PriceProductCalcReqDTO.Item(cartItem.getSkuId(), cartItem.getQuantity(), cartItem.getSelected())) diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/order/OrderManager.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/order/OrderManager.java new file mode 100644 index 000000000..b1b853710 --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/order/OrderManager.java @@ -0,0 +1,160 @@ +package cn.iocoder.mall.shopweb.manager.order; + +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.util.CollectionUtils; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.orderservice.rpc.cart.CartRpc; +import cn.iocoder.mall.orderservice.rpc.cart.dto.CartItemListReqDTO; +import cn.iocoder.mall.orderservice.rpc.cart.dto.CartItemRespDTO; +import cn.iocoder.mall.productservice.enums.sku.ProductSkuDetailFieldEnum; +import cn.iocoder.mall.productservice.rpc.sku.ProductSkuRpc; +import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuListQueryReqDTO; +import cn.iocoder.mall.productservice.rpc.sku.dto.ProductSkuRespDTO; +import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityRpc; +import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO; +import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO; +import cn.iocoder.mall.promotion.api.rpc.coupon.CouponCardRpc; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableListReqDTO; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardAvailableRespDTO; +import cn.iocoder.mall.promotion.api.rpc.price.PriceRpc; +import cn.iocoder.mall.promotion.api.rpc.price.dto.PriceProductCalcReqDTO; +import cn.iocoder.mall.promotion.api.rpc.price.dto.PriceProductCalcRespDTO; +import cn.iocoder.mall.shopweb.controller.order.vo.order.OrderConfirmCreateInfoRespVO; +import cn.iocoder.mall.shopweb.convert.order.CartConvert; +import cn.iocoder.mall.shopweb.convert.order.OrderConvert; +import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import java.util.stream.Collectors; + +import static cn.iocoder.mall.shopweb.enums.ShopWebErrorCodeConstants.ORDER_PRODUCT_SKU_NOT_EXISTS; +import static cn.iocoder.mall.shopweb.enums.ShopWebErrorCodeConstants.ORDER_PRODUCT_SKU_QUANTITY_NOT_ENOUGH; + +/** + * Order Manager + */ +@Service +@Validated +public class OrderManager { + + @DubboReference(version = "${dubbo.consumer.PriceRpc.version}") + private PriceRpc priceRpc; + @DubboReference(version = "${dubbo.consumer.PromotionActivityRpc.version}") + private PromotionActivityRpc promotionActivityRpc; + @DubboReference(version = "${dubbo.consumer.ProductCategoryRpc.version}") + private CartRpc cartRpc; + @DubboReference(version = "${dubbo.consumer.ProductSkuRpc.version}") + private ProductSkuRpc productSkuRpc; + @DubboReference(version = "${dubbo.consumer.CouponCardRpc.version}") + private CouponCardRpc couponCardRpc; + + public OrderConfirmCreateInfoRespVO getOrderConfirmCreateInfo(Integer userId, Integer skuId, Integer quantity, Integer couponCardId) { + Map skuMap = new HashMap<>(); + skuMap.put(skuId, quantity); + return this.getOrderConfirmCreateInfo0(userId, skuMap, couponCardId); + } + + public OrderConfirmCreateInfoRespVO getOrderConfirmCreateInfoFromCart(Integer userId, Integer couponCardId) { + // 获得购物车的商品 + CommonResult> listCartItemsResult = cartRpc.listCartItems( + new CartItemListReqDTO().setUserId(userId).setSelected(true)); + listCartItemsResult.checkError(); + // 购物车为空时,构造空的 OrderConfirmCreateInfoRespVO 返回 + if (CollectionUtils.isEmpty(listCartItemsResult.getData())) { + OrderConfirmCreateInfoRespVO result = new OrderConfirmCreateInfoRespVO(); + result.setItemGroups(Collections.emptyList()); + result.setFee(new OrderConfirmCreateInfoRespVO.Fee(0, 0, 0, 0)); + return result; + } + // 计算商品价格 + Map skuMap = CollectionUtils.convertMap(listCartItemsResult.getData(), + CartItemRespDTO::getSkuId, CartItemRespDTO::getQuantity); + return this.getOrderConfirmCreateInfo0(userId, skuMap, couponCardId); + } + + private OrderConfirmCreateInfoRespVO getOrderConfirmCreateInfo0(Integer userId, Map skuMap, Integer couponCardId) { + // 校验商品都存在,并且库存足够 + this.checkProductSkus(skuMap); + // 获得商品 SKU 信息 + Map productSkuMap = this.checkProductSkus(skuMap); + // 计算商品价格 + CommonResult calcProductPriceResult = priceRpc.calcProductPrice(new PriceProductCalcReqDTO() + .setUserId(userId).setCouponCardId(couponCardId) + .setItems(skuMap.entrySet().stream().map(entry -> new PriceProductCalcReqDTO.Item(entry.getKey(), entry.getValue(), true)) + .collect(Collectors.toList()))); + calcProductPriceResult.checkError(); + // 获得促销活动信息 + Map promotionActivityMap = this.getPromotionActivityMap(calcProductPriceResult.getData()); + // 拼接结果 + OrderConfirmCreateInfoRespVO createInfoRespVO = new OrderConfirmCreateInfoRespVO(); + createInfoRespVO.setFee(OrderConvert.INSTANCE.convert(calcProductPriceResult.getData().getFee())); + createInfoRespVO.setItemGroups(new ArrayList<>(calcProductPriceResult.getData().getItemGroups().size())); + for (PriceProductCalcRespDTO.ItemGroup itemGroupDTO : calcProductPriceResult.getData().getItemGroups()) { + OrderConfirmCreateInfoRespVO.ItemGroup itemGroupVO = new OrderConfirmCreateInfoRespVO.ItemGroup(); + createInfoRespVO.getItemGroups().add(itemGroupVO); + // 活动信息 + if (itemGroupDTO.getActivityId() != null) { + itemGroupVO.setActivity(promotionActivityMap.get(itemGroupDTO.getActivityId())) + .setActivityDiscountTotal(itemGroupDTO.getActivityDiscountTotal()); + } + // 商品 SKU 信息 + itemGroupVO.setItems(new ArrayList<>()); + itemGroupDTO.getItems().forEach(item -> itemGroupVO.getItems().add(CartConvert.INSTANCE.convert(item, + productSkuMap.get(item.getSkuId()), promotionActivityMap.get(item.getActivityId())))); + } + // 查询可用优惠劵信息 + CommonResult> listAvailableCouponCardsResult = couponCardRpc.listAvailableCouponCards( + new CouponCardAvailableListReqDTO().setUserId(userId) + .setItems(OrderConvert.INSTANCE.convertList(calcProductPriceResult.getData().getItemGroups()))); + listAvailableCouponCardsResult.checkError(); + createInfoRespVO.setCouponCards(listAvailableCouponCardsResult.getData()); + return createInfoRespVO; + } + + private Map checkProductSkus(Map skuMap) { + // 获得商品 SKU 列表 + CommonResult> listProductSkusResult = productSkuRpc.listProductSkus(new ProductSkuListQueryReqDTO() + .setProductSkuIds(skuMap.keySet()) + .setFields(Arrays.asList(ProductSkuDetailFieldEnum.SPU.getField(), ProductSkuDetailFieldEnum.ATTR.getField()))); + listProductSkusResult.checkError(); + Map productSkuMap = CollectionUtils.convertMap(listProductSkusResult.getData(), ProductSkuRespDTO::getId); + // 校验商品 SKU 是否合法 + for (Map.Entry entry : skuMap.entrySet()) { + ProductSkuRespDTO productSku = productSkuMap.get(entry.getKey()); + if (productSku == null || !CommonStatusEnum.ENABLE.getValue().equals(productSku.getStatus())) { + throw ServiceExceptionUtil.exception(ORDER_PRODUCT_SKU_NOT_EXISTS); + } + if (productSku.getQuantity() < entry.getValue()) { + throw ServiceExceptionUtil.exception(ORDER_PRODUCT_SKU_QUANTITY_NOT_ENOUGH); + } + } + return productSkuMap; + } + + private Map getPromotionActivityMap(PriceProductCalcRespDTO calcRespDTO) { + // 获得所有促销活动编号 + Set activeIds = new HashSet<>(); + calcRespDTO.getItemGroups().forEach(itemGroup -> { + if (itemGroup.getActivityId() != null) { + activeIds.add(itemGroup.getActivityId()); + } + itemGroup.getItems().forEach(item -> { + if (item.getActivityId() != null) { + activeIds.add(item.getActivityId()); + } + }); + }); + if (CollectionUtils.isEmpty(activeIds)) { + return Collections.emptyMap(); + } + // 查询促销活动列表 + CommonResult> listPromotionActivitiesResult = + promotionActivityRpc.listPromotionActivities(new PromotionActivityListReqDTO().setActiveIds(activeIds)); + listPromotionActivitiesResult.checkError(); + return CollectionUtils.convertMap(listPromotionActivitiesResult.getData(), PromotionActivityRespDTO::getId); + } + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/product/ProductSkuManager.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/product/ProductSkuManager.java new file mode 100644 index 000000000..abf2fd08c --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/product/ProductSkuManager.java @@ -0,0 +1,60 @@ +package cn.iocoder.mall.shopweb.manager.product; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityRpc; +import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO; +import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO; +import cn.iocoder.mall.promotion.api.rpc.price.PriceRpc; +import cn.iocoder.mall.promotion.api.rpc.price.dto.PriceProductCalcReqDTO; +import cn.iocoder.mall.promotion.api.rpc.price.dto.PriceProductCalcRespDTO; +import cn.iocoder.mall.shopweb.controller.product.vo.sku.ProductSkuCalcPriceRespVO; +import cn.iocoder.mall.shopweb.convert.product.ProductSkuConvert; +import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.Collections; +import java.util.List; + +/** + * 商品 SKU Manager + */ +@Service +@Validated +public class ProductSkuManager { + + @DubboReference(version = "${dubbo.consumer.PriceRpc.version}") + private PriceRpc priceRpc; + @DubboReference(version = "${dubbo.consumer.PromotionActivityRpc.version}") + private PromotionActivityRpc promotionActivityRpc; + + /** + * 计算商品 SKU 价格 + * + * @param userId 用户编号 + * @param skuId 商品 SKU 编号 + * @return SKU 价格明细 + */ + public ProductSkuCalcPriceRespVO calcProductSkuPrice(Integer userId, Integer skuId) { + CommonResult calcProductPriceResult = priceRpc.calcProductPrice(new PriceProductCalcReqDTO().setUserId(userId) + .setItems(Collections.singletonList(new PriceProductCalcReqDTO.Item(skuId, 1, true)))); + calcProductPriceResult.checkError(); + // 拼接结果 + PriceProductCalcRespDTO.ItemGroup itemGroup = calcProductPriceResult.getData().getItemGroups().get(0); + // 1. 加载 满减送 促销活动 + PromotionActivityRespDTO fullPrivilege = itemGroup.getActivityId() != null ? this.getPromotionActivity(itemGroup.getActivityId()) : null; + // 2. 加载 限时折扣 促销活动 + PriceProductCalcRespDTO.Item item = itemGroup.getItems().get(0); + PromotionActivityRespDTO timeLimitedDiscount = item.getActivityId() != null ? this.getPromotionActivity(item.getActivityId()) : null; + // 3. 最终组装 + return ProductSkuConvert.INSTANCE.convert(item, fullPrivilege, timeLimitedDiscount); + } + + private PromotionActivityRespDTO getPromotionActivity(Integer activityId) { + CommonResult> listPromotionActivitiesResult = promotionActivityRpc.listPromotionActivities( + new PromotionActivityListReqDTO().setActiveIds(Collections.singleton(activityId))); + listPromotionActivitiesResult.checkError(); + return listPromotionActivitiesResult.getData().get(0); + } + +} diff --git a/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/promotion/CouponCardManager.java b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/promotion/CouponCardManager.java new file mode 100644 index 000000000..b0fff075b --- /dev/null +++ b/shop-web-app/src/main/java/cn/iocoder/mall/shopweb/manager/promotion/CouponCardManager.java @@ -0,0 +1,51 @@ +package cn.iocoder.mall.shopweb.manager.promotion; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.coupon.CouponCardRpc; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardCreateReqDTO; +import cn.iocoder.mall.promotion.api.rpc.coupon.dto.card.CouponCardRespDTO; +import cn.iocoder.mall.shopweb.controller.promotion.vo.coupon.card.CouponCardPageReqVO; +import cn.iocoder.mall.shopweb.controller.promotion.vo.coupon.card.CouponCardRespVO; +import cn.iocoder.mall.shopweb.convert.promotion.CouponCardConvert; +import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.stereotype.Service; + +/** + * 优惠劵 Manager + */ +@Service +public class CouponCardManager { + + @DubboReference(version = "${dubbo.consumer.CouponCardRpc.version}") + private CouponCardRpc couponCardRpc; + + /** + * 获得优惠劵分页 + * + * @param userId 用户编号 + * @param pageVO 优惠劵分页查询 + * @return 优惠劵分页结果 + */ + public PageResult pageCouponCard(Integer userId, CouponCardPageReqVO pageVO) { + CommonResult> pageCouponCardResult = couponCardRpc.pageCouponCard( + CouponCardConvert.INSTANCE.convert(pageVO).setUserId(userId)); + pageCouponCardResult.checkError(); + return CouponCardConvert.INSTANCE.convertPage(pageCouponCardResult.getData()); + } + + /** + * 用户领取优惠劵 + * + * @param userId 用户编号 + * @param couponTemplateId 优惠劵模板编号 + * @return 优惠劵编号 + */ + public Integer createCouponCard(Integer userId, Integer couponTemplateId) { + CommonResult createCouponCardResult = couponCardRpc.createCouponCard( + new CouponCardCreateReqDTO().setUserId(userId).setCouponTemplateId(couponTemplateId)); + createCouponCardResult.checkError(); + return createCouponCardResult.getData(); + } + +} diff --git a/shop-web-app/src/main/resources/application.yml b/shop-web-app/src/main/resources/application.yml index 29afe9fdf..adf0fdd8b 100644 --- a/shop-web-app/src/main/resources/application.yml +++ b/shop-web-app/src/main/resources/application.yml @@ -45,6 +45,10 @@ dubbo: version: 1.0.0 PromotionActivityRpc: version: 1.0.0 + CouponCardRpc: + version: 1.0.0 + CouponTemplateRpc: + version: 1.0.0 # Swagger 配置项 swagger: diff --git a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/UserPassportController.java b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/PassportController.java similarity index 86% rename from user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/UserPassportController.java rename to user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/PassportController.java index bd82bbec1..bacc0f008 100644 --- a/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/UserPassportController.java +++ b/user-web-app/src/main/java/cn/iocoder/mall/userweb/controller/passport/PassportController.java @@ -21,17 +21,17 @@ import static cn.iocoder.common.framework.vo.CommonResult.success; @Api(tags = "用户 Passport API") @RestController @RequestMapping("/passport") -public class UserPassportController { +public class PassportController { @Autowired - private PassportManager userPassportManager; + private PassportManager passportManager; @PostMapping("/login-by-sms") @ApiOperation("手机验证码登陆") @RequiresNone public CommonResult loginBySms(PassportLoginBySmsReqVO loginBySmsDTO, HttpServletRequest request) { - return success(userPassportManager.loginBySms(loginBySmsDTO, HttpUtil.getIp(request))); + return success(passportManager.loginBySms(loginBySmsDTO, HttpUtil.getIp(request))); } @PostMapping("/send-sms-code") @@ -39,7 +39,7 @@ public class UserPassportController { @RequiresNone public CommonResult sendSmsCode(UserPassportSendSmsRespVO sendSmsCodeDTO, HttpServletRequest request) { - userPassportManager.sendSmsCode(sendSmsCodeDTO, HttpUtil.getIp(request)); + passportManager.sendSmsCode(sendSmsCodeDTO, HttpUtil.getIp(request)); // 返回成功 return success(true); }