From bb8e44a26840d5b6ad9a39d55ce7478cd54dcf81 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 10 Jun 2023 00:17:22 +0800 Subject: [PATCH 1/9] =?UTF-8?q?mall=20+=20product=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=AF=84=E8=AE=BA=20mock=20=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/comment/AppCommentController.java | 78 ++++++++++++++++++- .../app/comment/vo/AppCommentBaseVO.java | 6 +- .../app/comment/vo/AppCommentRespVO.java | 10 --- .../dataobject/comment/ProductCommentDO.java | 2 +- 4 files changed, 80 insertions(+), 16 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java index 7d05161e7..3c9359412 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.product.controller.app.comment; +import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; @@ -7,16 +8,20 @@ import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentCreateReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; +import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.Map; +import java.time.LocalDateTime; +import java.util.*; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @@ -34,6 +39,66 @@ public class AppCommentController { @Resource private MemberUserApi memberUserApi; + @GetMapping("/list") + @Operation(summary = "获得最近的 n 条商品评价") + @Parameters({ + @Parameter(name = "spuId", description = "商品 SPU 编号", required = true, example = "1024"), + @Parameter(name = "count", description = "数量", required = true, example = "10") + }) + public CommonResult> getCommentList(@RequestParam("spuId") Long spuId, + @RequestParam(value = "count", defaultValue = "10") Integer count) { + + List list = new ArrayList<>(); + + AppProductPropertyValueDetailRespVO item1 = new AppProductPropertyValueDetailRespVO(); + item1.setPropertyId(1L); + item1.setPropertyName("颜色"); + item1.setValueId(1024L); + item1.setValueName("红色"); + list.add(item1); + + AppProductPropertyValueDetailRespVO item2 = new AppProductPropertyValueDetailRespVO(); + item2.setPropertyId(2L); + item2.setPropertyName("尺寸"); + item2.setValueId(2048L); + item2.setValueName("大号"); + list.add(item2); + + AppProductPropertyValueDetailRespVO item3 = new AppProductPropertyValueDetailRespVO(); + item3.setPropertyId(3L); + item3.setPropertyName("重量"); + item3.setValueId(3072L); + item3.setValueName("500克"); + list.add(item3); + + // TODO 生成 mock 的数据 + AppCommentRespVO appCommentRespVO = new AppCommentRespVO(); + appCommentRespVO.setUserId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setUserNickname("用户" + new Random().nextInt(100)); + appCommentRespVO.setUserAvatar("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); + appCommentRespVO.setId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setAnonymous(new Random().nextBoolean()); + appCommentRespVO.setOrderId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setOrderItemId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setReplyStatus(new Random().nextBoolean()); + appCommentRespVO.setReplyUserId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setReplyContent("回复内容" + new Random().nextInt(100)); + appCommentRespVO.setReplyTime(LocalDateTime.now().minusDays(new Random().nextInt(30))); + appCommentRespVO.setCreateTime(LocalDateTime.now().minusDays(new Random().nextInt(30))); + appCommentRespVO.setFinalScore(new Random().nextInt(5) + 1); + appCommentRespVO.setSpuId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setSpuName("商品" + new Random().nextInt(100)); + appCommentRespVO.setSkuId((long) (new Random().nextInt(100000) + 10000)); + appCommentRespVO.setSkuProperties(list); + appCommentRespVO.setScores(new Random().nextInt(5) + 1); + appCommentRespVO.setDescriptionScores(new Random().nextInt(5) + 1); + appCommentRespVO.setBenefitScores(new Random().nextInt(5) + 1); + appCommentRespVO.setContent("评论内容" + new Random().nextInt(100)); + appCommentRespVO.setPicUrls(Arrays.asList("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg")); + + return success(Arrays.asList(appCommentRespVO)); + } + @GetMapping("/page") @Operation(summary = "获得商品评价分页") public CommonResult> getCommentPage(@Valid AppCommentPageReqVO pageVO) { @@ -41,10 +106,15 @@ public class AppCommentController { } // TODO @puhui999:方法名改成 getCommentStatistics?然后搞个对应的 vo?想了下,这样更优雅 - @GetMapping("/get-count") + @GetMapping("/statistics") @Operation(summary = "获得商品的评价统计") // TODO @puhui999:@RequestParam 哈,针对 spuId - public CommonResult> getCommentPage(@Valid Long spuId) { - return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE)); + public CommonResult> getCommentStatistics(@Valid Long spuId) { + // TODO 生成 mock 的数据 + if (true) { + return success(MapUtil.builder("allCount", 10L).put("goodPercent", "10.33").build()); + } + return null; +// return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE)); } @PostMapping(value = "/create") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentBaseVO.java index 2cbefad01..12910f25e 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentBaseVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.product.controller.app.comment.vo; +import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -7,7 +8,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.List; -// TODO @puhui999:把 Product 前缀给补下哈 +// TODO @puhui999:C 端可以不要 base 哈。 @Data public class AppCommentBaseVO { @@ -23,6 +24,9 @@ public class AppCommentBaseVO { @NotNull(message = "商品SKU编号不能为空") private Long skuId; + @Schema(description = "商品 SKU 属性", required = true) + private List skuProperties; // TODO puhui999:这个需要从数据库查询哈 + @Schema(description = "评分星级 1-5分", required = true) @NotNull(message = "评分星级 1-5分不能为空") private Integer scores; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java index 77c419b96..69456030b 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java @@ -6,7 +6,6 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import java.time.LocalDateTime; -import java.util.List; @Schema(description = "用户APP - 商品评价 Response VO") @Data @@ -49,15 +48,6 @@ public class AppCommentRespVO extends AppCommentBaseVO { @Schema(description = "商家回复时间") private LocalDateTime replyTime; - @Schema(description = "追加评价内容") - private String additionalContent; - - @Schema(description = "追评评价图片地址数组,以逗号分隔最多上传9张") - private List additionalPicUrls; - - @Schema(description = "追加评价时间") - private LocalDateTime additionalTime; - @Schema(description = "创建时间", required = true) private LocalDateTime createTime; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java index cf7b47051..5082b2da9 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java @@ -35,7 +35,7 @@ public class ProductCommentDO extends BaseDO { private Long id; /** - * 评价人 用户编号 + * 评价人的用户编号 * * 关联 MemberUserDO 的 id 编号 */ From 9e894e04306bdd37ef0de348a3818d6b01ea231d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 10 Jun 2023 09:57:37 +0800 Subject: [PATCH 2/9] =?UTF-8?q?mall=20+=20promotion=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BC=98=E6=83=A0=E5=8A=B5=E7=9A=84=20mock=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProductCommentServiceImplTest.java | 27 ------ .../app/coupon/AppCouponController.java | 28 +++++++ .../coupon/AppCouponTemplateController.java | 84 +++++++++++++++++++ .../coupon/vo/coupon/AppCouponTakeReqVO.java | 16 ++++ .../template/AppCouponTemplatePageReqVO.java | 19 +++++ .../vo/template/AppCouponTemplateRespVO.java | 68 +++++++++++++++ 6 files changed, 215 insertions(+), 27 deletions(-) create mode 100755 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java create mode 100755 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponTakeReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplatePageReqVO.java create mode 100755 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplateRespVO.java diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java index 6754f3ba0..520555141 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java @@ -4,12 +4,10 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.RandomUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; @@ -93,12 +91,10 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { o.setSkuId(generateId()); o.setDescriptionScores(ProductCommentScoresEnum.FOUR.getScores()); o.setBenefitScores(ProductCommentScoresEnum.FOUR.getScores()); - o.setDeliveryScores(ProductCommentScoresEnum.FOUR.getScores()); o.setContent("真好吃"); o.setReplyUserId(generateId()); o.setReplyContent("确实"); o.setReplyTime(LocalDateTime.now()); - o.setAdditionalTime(LocalDateTime.now()); o.setCreateTime(LocalDateTime.now()); o.setUpdateTime(LocalDateTime.now()); }); @@ -196,27 +192,4 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { assertEquals("测试", productCommentDO.getReplyContent()); } - @Test - public void testCreateComment_success() { - // mock 测试 - ProductCommentDO productComment = randomPojo(ProductCommentDO.class, o -> { - o.setAdditionalContent(""); - }); - - productCommentService.createComment(productComment, Boolean.TRUE); - - MemberUserRespDTO user = new MemberUserRespDTO(); - user.setId(productComment.getUserId()); - - AppCommentAdditionalReqVO createReqVO = new AppCommentAdditionalReqVO(); - createReqVO.setId(productComment.getId()); - createReqVO.setAdditionalContent("追加"); - createReqVO.setAdditionalPicUrls(productComment.getAdditionalPicUrls()); - - productCommentService.additionalComment(user, createReqVO); - ProductCommentDO exist = productCommentMapper.selectById(productComment.getId()); - - assertEquals("追加", exist.getAdditionalContent()); - } - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java new file mode 100755 index 000000000..a0804079b --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.promotion.controller.app.coupon; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplatePageReqVO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "用户 App - 优惠劵") +@RestController +@RequestMapping("/promotion/coupon") +@Validated +public class AppCouponController { + + // TODO 芋艿:待实现 + @PostMapping("/take") + @Operation(description = "领取优惠劵") + public CommonResult takeCoupon(@RequestBody AppCouponTemplatePageReqVO pageReqVO) { + return success(1L); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java new file mode 100755 index 000000000..f08bd0d74 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java @@ -0,0 +1,84 @@ +package cn.iocoder.yudao.module.promotion.controller.app.coupon; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplatePageReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplateRespVO; +import cn.iocoder.yudao.module.promotion.service.coupon.CouponTemplateService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.tags.Tag; +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; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "用户 App - 优惠劵模板") +@RestController +@RequestMapping("/promotion/coupon-template") +@Validated +public class AppCouponTemplateController { + + @Resource + private CouponTemplateService couponTemplateService; + + // TODO 芋艿:待实现 + @GetMapping("/list") + @Operation(description = "获得优惠劵模版列表") // 目前主要给商品详情使用 + @Parameters({ + @Parameter(name = "spuId", description = "商品 SPU 编号", required = true), + @Parameter(name = "useType", description = "使用类型"), + @Parameter(name = "count", description = "数量", required = true) + }) + public CommonResult> getCouponTemplateList(@RequestParam("spuId") Long spuId, + @RequestParam(value = "useType", required = false) Integer useType) { + List list = new ArrayList<>(); + Random random = new Random(); + for (int i = 0; i < 10; i++) { + AppCouponTemplateRespVO vo = new AppCouponTemplateRespVO(); + vo.setId(i + 1L); + vo.setName("优惠劵" + (i + 1)); + vo.setTakeLimitCount(random.nextInt(10) + 1); + vo.setUsePrice(random.nextInt(100) * 100); + vo.setValidityType(random.nextInt(2) + 1); + if (vo.getValidityType() == 1) { + vo.setValidStartTime(LocalDateTime.now().plusDays(random.nextInt(10))); + vo.setValidEndTime(LocalDateTime.now().plusDays(random.nextInt(20) + 10)); + } else { + vo.setFixedStartTerm(random.nextInt(10)); + vo.setFixedEndTerm(random.nextInt(10) + vo.getFixedStartTerm() + 1); + } + vo.setDiscountType(random.nextInt(2) + 1); + if (vo.getDiscountType() == 1) { + vo.setDiscountPercent(null); + vo.setDiscountPrice(random.nextInt(50) * 100); + vo.setDiscountLimitPrice(null); + } else { + vo.setDiscountPercent(random.nextInt(90) + 10); + vo.setDiscountPrice(null); + vo.setDiscountLimitPrice(random.nextInt(200) * 100); + } + vo.setTakeStatus(random.nextBoolean()); + list.add(vo); + } + return success(list); + } + + // TODO 芋艿:待实现 + @GetMapping("/page") + @Operation(description = "获得优惠劵模版分页") + public CommonResult> getCouponTemplatePage(AppCouponTemplatePageReqVO pageReqVO) { + return null; + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponTakeReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponTakeReqVO.java new file mode 100644 index 000000000..0f71fe2bf --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponTakeReqVO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Schema(description = "用户 App - 优惠劵领取 Request VO") +@Data +public class AppCouponTakeReqVO { + + @Schema(description = "优惠劵模板编号", example = "1") + @NotNull(message = "优惠劵模板编号不能为空") + private Long templateId; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplatePageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplatePageReqVO.java new file mode 100644 index 000000000..6eda32167 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplatePageReqVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@Schema(description = "用户 App - 优惠劵模板分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AppCouponTemplatePageReqVO extends PageParam { + + @Schema(description = "使用类型", example = "1") + // TODO 芋艿:这里要限制下枚举的使用 + private Integer useType; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplateRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplateRespVO.java new file mode 100755 index 000000000..5e8aa86ef --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplateRespVO.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.Min; +import java.time.LocalDateTime; + +@Schema(description = "用户 App - 优惠劵模板 Response VO") +@Data +public class AppCouponTemplateRespVO { + + @Schema(description = "优惠劵模板编号", required = true, example = "1") + private Long id; + + @Schema(description = "优惠劵名", required = true, example = "春节送送送") + private String name; + + @Schema(description = "每人限领个数", required = true, example = "66") // -1 - 则表示不限制 + private Integer takeLimitCount; + + @Schema(description = "是否设置满多少金额可用", required = true, example = "100") // 单位:分;0 - 不限制 + private Integer usePrice; + + // TODO 芋艿:这两要改的 +// @Schema(description = "商品范围", required = true, example = "1") +// @InEnum(PromotionProductScopeEnum.class) +// private Integer productScope; +// +// @Schema(description = "商品 SPU 编号的数组", example = "1,3") +// private List productSpuIds; + + @Schema(description = "生效日期类型", required = true, example = "1") + private Integer validityType; + + @Schema(description = "固定日期 - 生效开始时间") + private LocalDateTime validStartTime; + + @Schema(description = "固定日期 - 生效结束时间") + private LocalDateTime validEndTime; + + @Schema(description = "领取日期 - 开始天数") + @Min(value = 0L, message = "开始天数必须大于 0") + private Integer fixedStartTerm; + + @Schema(description = "领取日期 - 结束天数") + @Min(value = 1L, message = "开始天数必须大于 1") + private Integer fixedEndTerm; + + @Schema(description = "优惠类型", required = true, example = "1") + private Integer discountType; + + @Schema(description = "折扣百分比", example = "80") // 例如说,80% 为 80 + private Integer discountPercent; + + @Schema(description = "优惠金额", example = "10") + @Min(value = 0, message = "优惠金额需要大于等于 0") + private Integer discountPrice; + + @Schema(description = "折扣上限", example = "100") // 单位:分,仅在 discountType 为 PERCENT 使用 + private Integer discountLimitPrice; + + // ========== 用户相关字段 ========== + + @Schema(description = "是否已领取", required = true, example = "true") + private Boolean takeStatus; + +} From 4f5ac0edbbf925a2aaa865dcad3b357207488038 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 10 Jun 2023 17:51:15 +0800 Subject: [PATCH 3/9] =?UTF-8?q?mall=20+=20promotion=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=90=A5=E9=94=80=E6=B4=BB=E5=8A=A8=E7=9A=84=20mock?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/query/LambdaQueryWrapperX.java | 1 - .../app/spu/AppProductSpuController.java | 21 ++++-- .../app/spu/vo/AppProductSpuDetailRespVO.java | 5 ++ .../app/spu/vo/AppProductSpuPageReqVO.java | 3 +- ...spVO.java => AppProductSpuPageRespVO.java} | 9 ++- .../convert/spu/ProductSpuConvert.java | 31 ++++----- .../dal/mysql/spu/ProductSpuMapper.java | 36 +++++++--- .../service/spu/ProductSpuService.java | 9 +++ .../service/spu/ProductSpuServiceImpl.java | 5 ++ .../enums/common/PromotionTypeEnum.java | 12 ++-- .../app/AppMarketTestController.java | 24 ------- .../app/activity/AppActivityController.java | 65 +++++++++++++++++++ .../app/activity/vo/AppActivityRespVO.java | 27 ++++++++ .../trade/enums/order/TradeOrderTypeEnum.java | 6 +- 14 files changed, 186 insertions(+), 68 deletions(-) rename yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/{AppProductSpuPageItemRespVO.java => AppProductSpuPageRespVO.java} (81%) delete mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/AppMarketTestController.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/vo/AppActivityRespVO.java diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java index 342fa4611..4fe20bd4b 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.framework.mybatis.core.query; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java index 693e8e911..5d79ba7d1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java @@ -3,17 +3,17 @@ package cn.iocoder.yudao.module.product.controller.app.spu; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO; -import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageItemRespVO; +import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageRespVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; -import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -40,12 +40,23 @@ public class AppProductSpuController { private ProductSpuService productSpuService; @Resource private ProductSkuService productSkuService; - @Resource - private ProductPropertyValueService productPropertyValueService; + + @GetMapping("/list") + @Operation(summary = "获得商品 SPU 列表") + @Parameters({ + @Parameter(name = "recommendType", description = "推荐类型", required = true), // 参见 AppProductSpuPageReqVO.RECOMMEND_TYPE_XXX 常量 + @Parameter(name = "count", description = "数量", required = true) + }) + public CommonResult> getSpuList( + @RequestParam("recommendType") String recommendType, + @RequestParam(value = "count", defaultValue = "10") Integer count) { + List list = productSpuService.getSpuList(recommendType, count); + return success(ProductSpuConvert.INSTANCE.convertListForGetSpuList(list)); + } @GetMapping("/page") @Operation(summary = "获得商品 SPU 分页") - public CommonResult> getSpuPage(@Valid AppProductSpuPageReqVO pageVO) { + public CommonResult> getSpuPage(@Valid AppProductSpuPageReqVO pageVO) { PageResult pageResult = productSpuService.getSpuPage(pageVO); return success(ProductSpuConvert.INSTANCE.convertPageForGetSpuPage(pageResult)); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java index a543f0af2..60f1c6c57 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuDetailRespVO.java @@ -39,6 +39,11 @@ public class AppProductSpuDetailRespVO { @Schema(description = "单位名", required = true, example = "个") private String unitName; + // ========== 营销相关字段 ========= + + @Schema(description = "活动排序数组", required = true, example = "1024") + private List activityOrders; + // ========== SKU 相关字段 ========= @Schema(description = "规格类型", required = true, example = "true") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageReqVO.java index 5050561d6..653ca5215 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageReqVO.java @@ -20,6 +20,7 @@ public class AppProductSpuPageReqVO extends PageParam { public static final String SORT_FIELD_SALES_COUNT = "salesCount"; public static final String RECOMMEND_TYPE_HOT = "hot"; + public static final String RECOMMEND_TYPE_GOOD = "good"; @Schema(description = "分类编号", example = "1") private Long categoryId; @@ -33,7 +34,7 @@ public class AppProductSpuPageReqVO extends PageParam { @Schema(description = "排序方式", example = "true") private Boolean sortAsc; - @Schema(description = "推荐类型", example = "hot") // 参见 AppProductSpuPageReqVO.RECOMMEND_TYPE_XXX 常亮 + @Schema(description = "推荐类型", example = "hot") // 参见 AppProductSpuPageReqVO.RECOMMEND_TYPE_XXX 常量 private String recommendType; @AssertTrue(message = "排序字段不合法") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageItemRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageRespVO.java similarity index 81% rename from yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageItemRespVO.java rename to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageRespVO.java index 68812b754..85658b0e7 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageItemRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/vo/AppProductSpuPageRespVO.java @@ -5,9 +5,9 @@ import lombok.Data; import java.util.List; -@Schema(description = "用户 App - 商品 SPU 分页项 Response VO") +@Schema(description = "用户 App - 商品 SPU Response VO") @Data -public class AppProductSpuPageItemRespVO { +public class AppProductSpuPageRespVO { @Schema(description = "商品 SPU 编号", required = true, example = "1") private Long id; @@ -35,6 +35,11 @@ public class AppProductSpuPageItemRespVO { @Schema(description = "库存", required = true, example = "666") private Integer stock; + // ========== 营销相关字段 ========= + + @Schema(description = "活动排序数组", required = true, example = "1024") + private List activityOrders; + // ========== 统计相关字段 ========= @Schema(description = "商品销量", required = true, example = "1024") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java index 80902660c..f525f3134 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java @@ -1,14 +1,12 @@ package cn.iocoder.yudao.module.product.convert.spu; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO; -import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageItemRespVO; +import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageRespVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; @@ -80,14 +78,15 @@ public interface ProductSpuConvert { // ========== 用户 App 相关 ========== - default PageResult convertPageForGetSpuPage(PageResult page) { - // 累加虚拟销量 - page.getList().forEach(spu -> spu.setSalesCount(spu.getSalesCount() + spu.getVirtualSalesCount())); - // 然后进行转换 - return convertPageForGetSpuPage0(page); - } + PageResult convertPageForGetSpuPage(PageResult page); - PageResult convertPageForGetSpuPage0(PageResult page); + default List convertListForGetSpuList(List list) { + // 处理虚拟销量 + list.forEach(spu -> spu.setSalesCount(spu.getSalesCount() + spu.getVirtualSalesCount())); + return convertListForGetSpuList0(list); + } + @Named("convertListForGetSpuList0") + List convertListForGetSpuList0(List list); default AppProductSpuDetailRespVO convertForGetSpuDetail(ProductSpuDO spu, List skus) { // 处理 SPU @@ -109,15 +108,9 @@ public interface ProductSpuConvert { List convertListForGetSpuDetail(List skus); default ProductSpuDetailRespVO convertForSpuDetailRespVO(ProductSpuDO spu, List skus) { - ProductSpuDetailRespVO productSpuDetailRespVO = convert03(spu); - // skus 为空直接返回 - if (CollUtil.isEmpty(skus)) { - return productSpuDetailRespVO; - } - List skuVOs = ProductSkuConvert.INSTANCE.convertList(skus); - // fix: 因为现在已改为 sku 属性列表 属性 已包含 属性名字 属性值名字 所以不需要再额外处理,属性更新时更新 sku 中的属性相关冗余即可 - productSpuDetailRespVO.setSkus(skuVOs); - return productSpuDetailRespVO; + ProductSpuDetailRespVO detailRespVO = convert03(spu); + detailRespVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skus)); + return detailRespVO; } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java index 27a393ee6..9c237fa9f 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuExportReqVO; import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; @@ -66,7 +67,10 @@ public interface ProductSpuMapper extends BaseMapperX { // 推荐类型的过滤条件 if (ObjUtil.equal(pageReqVO.getRecommendType(), AppProductSpuPageReqVO.RECOMMEND_TYPE_HOT)) { query.eq(ProductSpuDO::getRecommendHot, true); + } else if (ObjUtil.equal(pageReqVO.getRecommendType(), AppProductSpuPageReqVO.RECOMMEND_TYPE_GOOD)) { + query.eq(ProductSpuDO::getRecommendGood, true); } + // 排序逻辑 if (Objects.equals(pageReqVO.getSortField(), AppProductSpuPageReqVO.SORT_FIELD_SALES_COUNT)) { query.last(String.format(" ORDER BY (sales_count + virtual_sales_count) %s, sort DESC, id DESC", @@ -80,6 +84,21 @@ public interface ProductSpuMapper extends BaseMapperX { return selectPage(pageReqVO, query); } + default List selectListByRecommendType(String recommendType, Integer count) { + QueryWrapperX query = new QueryWrapperX<>(); + // 上架状态 且有库存 + query.eq("status", ProductSpuStatusEnum.ENABLE.getStatus()).gt("stock", 0); + // 推荐类型的过滤条件 + if (ObjUtil.equal(recommendType, AppProductSpuPageReqVO.RECOMMEND_TYPE_HOT)) { + query.eq("recommend_hot", true); + } else if (ObjUtil.equal(recommendType, AppProductSpuPageReqVO.RECOMMEND_TYPE_GOOD)) { + query.eq("recommend_good", true); + } + // 设置最大长度 + query.limitN(count); + return selectList(query); + } + /** * 更新商品 SPU 库存 * @@ -111,33 +130,34 @@ public interface ProductSpuMapper extends BaseMapperX { } /** - * 验证选项卡类型构建条件 + * 添加后台 Tab 选项的查询条件 * * @param tabType 标签类型 - * @param queryWrapper 查询条件 + * @param query 查询条件 */ - static void appendTabQuery(Integer tabType, LambdaQueryWrapperX queryWrapper) { + static void appendTabQuery(Integer tabType, LambdaQueryWrapperX query) { // 出售中商品 if (ObjectUtil.equals(ProductSpuPageReqVO.FOR_SALE, tabType)) { - queryWrapper.eqIfPresent(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus()); + query.eqIfPresent(ProductSpuDO::getStatus, ProductSpuStatusEnum.ENABLE.getStatus()); } // 仓储中商品 if (ObjectUtil.equals(ProductSpuPageReqVO.IN_WAREHOUSE, tabType)) { - queryWrapper.eqIfPresent(ProductSpuDO::getStatus, ProductSpuStatusEnum.DISABLE.getStatus()); + query.eqIfPresent(ProductSpuDO::getStatus, ProductSpuStatusEnum.DISABLE.getStatus()); } // 已售空商品 if (ObjectUtil.equals(ProductSpuPageReqVO.SOLD_OUT, tabType)) { - queryWrapper.eqIfPresent(ProductSpuDO::getStock, 0); + query.eqIfPresent(ProductSpuDO::getStock, 0); } // 警戒库存 if (ObjectUtil.equals(ProductSpuPageReqVO.ALERT_STOCK, tabType)) { - queryWrapper.le(ProductSpuDO::getStock, ProductConstants.ALERT_STOCK) + query.le(ProductSpuDO::getStock, ProductConstants.ALERT_STOCK) // 如果库存触发警戒库存且状态为回收站的话则不在警戒库存列表展示 .notIn(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus()); } // 回收站 if (ObjectUtil.equals(ProductSpuPageReqVO.RECYCLE_BIN, tabType)) { - queryWrapper.eqIfPresent(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus()); + query.eqIfPresent(ProductSpuDO::getStatus, ProductSpuStatusEnum.RECYCLE.getStatus()); } } + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java index 102b5e1fa..f381e6de6 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java @@ -98,6 +98,15 @@ public interface ProductSpuService { */ PageResult getSpuPage(AppProductSpuPageReqVO pageReqVO); + /** + * 获得商品 SPU 列表,提供给用户 App 使用 + * + * @param recommendType 推荐类型 + * @param count 数量 + * @return 商品 SPU 列表 + */ + List getSpuList(String recommendType, Integer count); + /** * 更新商品 SPU 库存(增量) * diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index 297259509..3ada0be78 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -201,6 +201,11 @@ public class ProductSpuServiceImpl implements ProductSpuService { return productSpuMapper.selectPage(pageReqVO, categoryIds); } + @Override + public List getSpuList(String recommendType, Integer count) { + return productSpuMapper.selectListByRecommendType(recommendType, count); + } + @Override @Transactional(rollbackFor = Exception.class) public void updateSpuStock(Map stockIncrCounts) { diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java index ee87306bf..874651ea3 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java @@ -15,11 +15,15 @@ import java.util.Arrays; @AllArgsConstructor public enum PromotionTypeEnum implements IntArrayValuable { - DISCOUNT_ACTIVITY(1, "限时折扣"), - REWARD_ACTIVITY(2, "满减送"), + SECKILL_ACTIVITY(1, "秒杀活动"), + BARGAIN_ACTIVITY(2, "拼团活动"), + COMBINATION_ACTIVITY(3, "砍价活动"), - MEMBER(3, "会员折扣"), // TODO 芋艿:待实现 StrUtil.format("会员折扣:省 {} 元", formatPrice(orderItem.getPayPrice() - memberPrice) - COUPON(4, "优惠劵") + DISCOUNT_ACTIVITY(4, "限时折扣"), + REWARD_ACTIVITY(5, "满减送"), + + MEMBER(6, "会员折扣"), + COUPON(7, "优惠劵") ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionTypeEnum::getType).toArray(); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/AppMarketTestController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/AppMarketTestController.java deleted file mode 100644 index cafddecf5..000000000 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/AppMarketTestController.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.promotion.controller.app; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -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.RestController; - -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; - -@Tag(name = "用户 App - 营销") -@RestController -@RequestMapping("/market/test") -@Validated -public class AppMarketTestController { - - @GetMapping("/get") - @Operation(summary = "获取 market 信息") - public CommonResult get() { - return success("true"); - } -} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java new file mode 100644 index 000000000..a616bfeda --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.promotion.controller.app.activity; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.promotion.controller.app.activity.vo.AppActivityRespVO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +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; + +import java.time.LocalDateTime; +import java.util.*; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "用户 APP - 营销活动") // 用于提供跨多个活动的 HTTP 接口 +@RestController +@RequestMapping("/promotion/activity") +@Validated +public class AppActivityController { + + @GetMapping("/list-by-spu-id") + @Operation(summary = "获得单个商品,近期参与的每个活动") // 每种活动,只返回一个 + @Parameter(name = "spuId", description = "商品编号", required = true) + public CommonResult> getActivityListBySpuId(@RequestParam("spuId") Long spuId) { + // TODO 芋艿,实现 + List randomList = new ArrayList<>(); + Random random = new Random(); + for (int i = 0; i < 3; i++) { // 生成5个随机对象 + AppActivityRespVO vo = new AppActivityRespVO(); + vo.setId(random.nextLong()); // 随机生成一个长整型 ID + vo.setType(i + 1); // 随机生成一个介于0到2之间的整数,对应枚举类型的三种类型之一 + vo.setName(String.format("活动%d", random.nextInt(100))); // 随机生成一个类似于“活动XX”的活动名称,XX为0到99之间的随机整数 + vo.setStartTime(LocalDateTime.now()); // 随机生成一个在过去的一年内的开始时间(以毫秒为单位) + vo.setEndTime(LocalDateTime.now()); // 随机生成一个在未来的一年内的结束时间(以毫秒为单位) + randomList.add(vo); + } + return success(randomList); + } + + @GetMapping("/list-by-spu-ids") + @Operation(summary = "获得多个商品,近期参与的每个活动") // 每种活动,只返回一个;key 为 SPU 编号 + @Parameter(name = "spuIds", description = "商品编号数组", required = true) + public CommonResult>> getActivityListBySpuIds(@RequestParam("spuIds") List spuIds) { + // TODO 芋艿,实现 + List randomList = new ArrayList<>(); + Random random = new Random(); + for (int i = 0; i < 5; i++) { // 生成5个随机对象 + AppActivityRespVO vo = new AppActivityRespVO(); + vo.setId(random.nextLong()); // 随机生成一个长整型 ID + vo.setType(random.nextInt(3)); // 随机生成一个介于0到2之间的整数,对应枚举类型的三种类型之一 + vo.setName(String.format("活动%d", random.nextInt(100))); // 随机生成一个类似于“活动XX”的活动名称,XX为0到99之间的随机整数 + vo.setStartTime(LocalDateTime.now()); // 随机生成一个在过去的一年内的开始时间(以毫秒为单位) + vo.setEndTime(LocalDateTime.now()); // 随机生成一个在未来的一年内的结束时间(以毫秒为单位) + randomList.add(vo); + } + Map> map = new HashMap<>(); + map.put(109L, randomList); + return success(map); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/vo/AppActivityRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/vo/AppActivityRespVO.java new file mode 100644 index 000000000..064cc21a2 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/vo/AppActivityRespVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.promotion.controller.app.activity.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "用户 App - 营销活动 Response VO") +@Data +public class AppActivityRespVO { + + @Schema(description = "活动编号", required = true, example = "1024") + private Long id; + + @Schema(description = "活动类型", required = true, example = "1") // 对应 PromotionTypeEnum 枚举 + private Integer type; + + @Schema(description = "活动名称", required = true, example = "618 大促") + private String name; + + @Schema(description = "活动开始时间", required = true) + private LocalDateTime startTime; + + @Schema(description = "活动结束时间", required = true) + private LocalDateTime endTime; + +} diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderTypeEnum.java index 34e47a12e..27596197f 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderTypeEnum.java @@ -17,10 +17,8 @@ public enum TradeOrderTypeEnum implements IntArrayValuable { NORMAL(0, "普通订单"), SECKILL(1, "秒杀订单"), - // TODO 芋艿:如下三个字段,名字需要改下,等后面表设计完成后。 - KANJIA(2, "砍价订单"), - PINTUAN(3, "拼团订单"), - YUSHOU(4, "预售订单"), + BARGAIN(2, "砍价订单"), + COMBINATION(3, "拼团订单"), ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(TradeOrderTypeEnum::getType).toArray(); From 5ffc1ac9f34d32c13ddb26711dd21797e286e9ad Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 11 Jun 2023 00:22:45 +0800 Subject: [PATCH 4/9] =?UTF-8?q?mall=20+=20promotion=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=A7=92=E6=9D=80=E6=B4=BB=E5=8A=A8=E7=9A=84=20mock?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/coupon/AppCouponController.java | 2 +- .../coupon/AppCouponTemplateController.java | 4 +- .../seckill/AppSeckillActivityController.java | 67 +++++++++++++++++++ .../vo/AppSeckillActivitiDetailRespVO.java | 51 ++++++++++++++ .../seckillactivity/SeckillActivityDO.java | 2 +- .../seckillactivity/SeckillProductDO.java | 6 +- .../app/order/AppTradeOrderController.java | 2 +- 7 files changed, 127 insertions(+), 7 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java index a0804079b..481ced4b4 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java @@ -20,7 +20,7 @@ public class AppCouponController { // TODO 芋艿:待实现 @PostMapping("/take") - @Operation(description = "领取优惠劵") + @Operation(summary = "领取优惠劵") public CommonResult takeCoupon(@RequestBody AppCouponTemplatePageReqVO pageReqVO) { return success(1L); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java index f08bd0d74..8c6521803 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java @@ -34,7 +34,7 @@ public class AppCouponTemplateController { // TODO 芋艿:待实现 @GetMapping("/list") - @Operation(description = "获得优惠劵模版列表") // 目前主要给商品详情使用 + @Operation(summary = "获得优惠劵模版列表") // 目前主要给商品详情使用 @Parameters({ @Parameter(name = "spuId", description = "商品 SPU 编号", required = true), @Parameter(name = "useType", description = "使用类型"), @@ -76,7 +76,7 @@ public class AppCouponTemplateController { // TODO 芋艿:待实现 @GetMapping("/page") - @Operation(description = "获得优惠劵模版分页") + @Operation(summary = "获得优惠劵模版分页") public CommonResult> getCouponTemplatePage(AppCouponTemplatePageReqVO pageReqVO) { return null; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java new file mode 100644 index 000000000..22d4f76bd --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java @@ -0,0 +1,67 @@ +package cn.iocoder.yudao.module.promotion.controller.app.seckill; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.AppSeckillActivitiDetailRespVO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +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; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "用户 App - 秒杀活动") +@RestController +@RequestMapping("/promotion/seckill-activity") +@Validated +public class AppSeckillActivityController { + + @GetMapping("/get-detail") + @Operation(summary = "获得秒杀活动明细") + @Parameter(name = "id", description = "活动编号", required = true, example = "1024") + public CommonResult getSeckillActivity(@RequestParam("id") Long id) { + // TODO 芋艿:如果禁用的时候,需要抛出异常; + AppSeckillActivitiDetailRespVO obj = new AppSeckillActivitiDetailRespVO(); + // 设置其属性的值 + obj.setId(id); + obj.setName("晚九点限时秒杀"); + obj.setStatus(1); + obj.setStartTime(LocalDateTime.of(2023, 6, 10, 0, 0, 0)); + obj.setEndTime(LocalDateTime.of(2023, 6, 10, 23, 59, 0)); + obj.setSpuId(633L); + // 创建一个Product对象的列表 + List productList = new ArrayList<>(); + // 创建三个新的Product对象并设置其属性的值 + AppSeckillActivitiDetailRespVO.Product product1 = new AppSeckillActivitiDetailRespVO.Product(); + product1.setSkuId(4096L); + product1.setSeckillPrice(100); + product1.setQuota(50); + // 将第一个Product对象添加到列表中 + productList.add(product1); + // 创建第二个Product对象并设置其属性的值 + AppSeckillActivitiDetailRespVO.Product product2 = new AppSeckillActivitiDetailRespVO.Product(); + product2.setSkuId(4097L); + product2.setSeckillPrice(200); + product2.setQuota(100); + // 将第二个Product对象添加到列表中 + productList.add(product2); + // 创建第三个Product对象并设置其属性的值 + AppSeckillActivitiDetailRespVO.Product product3 = new AppSeckillActivitiDetailRespVO.Product(); + product3.setSkuId(4098L); + product3.setSeckillPrice(300); + product3.setQuota(150); + // 将第三个Product对象添加到列表中 + productList.add(product3); + // 将Product列表设置为对象的属性值 + obj.setProducts(productList); + return success(obj); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java new file mode 100644 index 000000000..62cdf9b4f --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java @@ -0,0 +1,51 @@ +package cn.iocoder.yudao.module.promotion.controller.app.seckill.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.List; + +@Schema(description = "用户 App - 秒杀活动 Response VO") +@Data +public class AppSeckillActivitiDetailRespVO { + + @Schema(description = "秒杀活动编号", required = true, example = "1024") + private Long id; + + @Schema(description = "秒杀活动名称", required = true, example = "晚九点限时秒杀") + private String name; + + @Schema(description = "活动状态", required = true, example = "1") + private Integer status; + + // TODO @芋艿:开始时间、结束时间,要和场次结合起来;就是要算到当前场次,是几点哈; + + @Schema(description = "活动开始时间", required = true) + private LocalDateTime startTime; + + @Schema(description = "活动结束时间", required = true) + private LocalDateTime endTime; + + @Schema(description = "商品 SPU 编号", required = true, example = "2048") + private Long spuId; + + @Schema(description = "商品 SPU 名字", required = true) + private List products; + + @Schema(description = "商品信息") + @Data + public static class Product { + + @Schema(description = "商品 SKU 编号", required = true, example = "4096") + private Long skuId; + + @Schema(description = "秒杀金额,单位:分", required = true, example = "100") + private Integer seckillPrice; + + @Schema(description = "秒杀限量库存", required = true, example = "50") + private Integer quota; + + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java index 1d3b6da27..2a0dcd70b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillActivityDO.java @@ -37,7 +37,7 @@ public class SeckillActivityDO extends BaseDO { private String name; /** * 活动状态 - *

+ * * 枚举 {@link PromotionActivityStatusEnum 对应的类} */ private Integer status; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java index 3783d6dda..2adc0acfd 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/seckillactivity/SeckillProductDO.java @@ -53,6 +53,7 @@ public class SeckillProductDO extends BaseDO { */ private Integer seckillPrice; + // TODO @芋艿:改成 quota 限量库存;每次购买时,需要减小; /** * 秒杀库存 */ @@ -61,5 +62,6 @@ public class SeckillProductDO extends BaseDO { /** * 每人限购 */ - private Integer limitBuyCount; -} \ No newline at end of file + private Integer limitCount; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index e3008fdd6..49bc63986 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -64,7 +64,7 @@ public class AppTradeOrderController { } @PostMapping("/update-paid") - @Operation(description = "更新订单为已支付") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob + @Operation(summary = "更新订单为已支付") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob public CommonResult updateOrderPaid(@RequestBody PayOrderNotifyReqDTO notifyReqDTO) { tradeOrderService.updateOrderPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()), notifyReqDTO.getPayOrderId()); From 45e5578cb44392e8e59c2da4296034365e25148c Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Sun, 11 Jun 2023 10:22:33 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=BF=AB=E9=80=92=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E3=80=81=20=E9=80=9A=E8=BF=87=E5=BF=AB=E9=80=92=E9=B8=9F?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/config/YudaoWebAutoConfiguration.java | 12 ++ .../trade/enums/ErrorCodeConstants.java | 3 +- .../config/TradeExpressQueryProperties.java | 65 +++++++++ .../delivery/core/ExpressQueryClient.java | 21 +++ .../delivery/core/ExpressQueryProvider.java | 20 +++ .../core/ExpressQueryProviderEnum.java | 28 ++++ .../core/ExpressQueryProviderFactory.java | 14 ++ .../core/convert/ExpressQueryConvert.java | 20 +++ .../delivery/core/dto/ExpressQueryReqDTO.java | 30 ++++ .../core/dto/ExpressQueryRespDTO.java | 22 +++ .../kdniao/KdNiaoExpressQueryReqDTO.java | 32 +++++ .../kdniao/KdNiaoExpressQueryRespDTO.java | 75 ++++++++++ .../core/impl/ExpressQueryClientImpl.java | 53 +++++++ .../impl/ExpressQueryProviderFactoryImpl.java | 45 ++++++ .../core/impl/Kd100ExpressQueryProvider.java | 30 ++++ .../core/impl/KdNiaoExpressQueryProvider.java | 129 ++++++++++++++++++ .../impl/KdNiaoExpressQueryProviderTest.java | 52 +++++++ .../application-trade-delivery-query.yaml | 15 ++ 18 files changed, 665 insertions(+), 1 deletion(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderEnum.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryReqDTO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryRespDTO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryRespDTO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java index b20565eca..110eb80bb 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java @@ -10,11 +10,14 @@ import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.util.AntPathMatcher; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; @@ -107,6 +110,15 @@ public class YudaoWebAutoConfiguration implements WebMvcConfigurer { return createFilterBean(new DemoFilter(), WebFilterOrderEnum.DEMO_FILTER); } + /** + * 创建 RestTemplate 实例 + * @param restTemplateBuilder {@link RestTemplateAutoConfiguration#restTemplateBuilder} + */ + @Bean + public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder){ + return restTemplateBuilder.build(); + } + public static FilterRegistrationBean createFilterBean(T filter, Integer order) { FilterRegistrationBean bean = new FilterRegistrationBean<>(filter); bean.setOrder(order); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 43a9d62e6..4d74a3695 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -53,7 +53,8 @@ public interface ErrorCodeConstants { ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011003003, "已经存在该运费模板名"); ErrorCode DELIVERY_EXPRESS_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003004, "计算快递运费时,收件人地址编号为空"); ErrorCode PRODUCT_EXPRESS_TEMPLATE_NOT_FOUND = new ErrorCode(1011003005, "找不到到商品对应的运费模板"); - ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011003006, "自提门店不存在"); + ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011003006, "快递接口查询失败"); + ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011003007, "自提门店不存在"); // ========== Price 相关 1011004000 ============ ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1011004000, "支付价格计算异常,原因:价格小于等于 0"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java new file mode 100644 index 000000000..c0705b74b --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.config; + +import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderEnum; +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; + +/** + * 交易快递查询的配置项 + * + * @author jason + */ +@Component +@ConfigurationProperties(prefix = "yudao.trade.express.query") +@Data +@Validated +public class TradeExpressQueryProperties { + + /** + * 快递查询服务商, 如果未配置,默认使用快递鸟 + */ + private ExpressQueryProviderEnum expressQueryProvider; + /** + * 快递鸟配置 + */ + @Valid + private KdNiaoConfig kdNiao; + /** + * 快递 100 配置 + */ + @Valid + private Kd100Config kd100; + + /** + * 快递鸟配置项目 + */ + @Data + public static class KdNiaoConfig { + + /** + * 快递鸟用户 ID + */ + @NotEmpty(message = "快递鸟用户 ID 配置项不能为空") + private String businessId; + + /** + * 快递鸟 API Key + */ + @NotEmpty(message = "快递鸟 Api Key 配置项不能为空") + private String apiKey; + } + + /** + * 快递100 配置项 TODO + */ + public static class Kd100Config { + + } + + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java new file mode 100644 index 000000000..d43429d72 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core; + +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; + +import java.util.List; + +/** + * 快递查询客户端 + * + * @author jason + */ +public interface ExpressQueryClient { + + /** + * 快递实时查询 + * + * @param reqDTO 查询请求参数 + */ + List realTimeQuery(ExpressQueryReqDTO reqDTO); +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java new file mode 100644 index 000000000..6fb0a4179 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core; + +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; + +import java.util.List; + +/** + * 快递查询服务商 + * + * @author jason + */ +public interface ExpressQueryProvider { + /** + * 快递实时查询 + * + * @param reqDTO 查询请求参数 + */ + List realTimeQueryExpress(ExpressQueryReqDTO reqDTO); +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderEnum.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderEnum.java new file mode 100644 index 000000000..094848ba6 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderEnum.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core; + +import lombok.Getter; + +/** + * 快递查询服务商枚举 + * + * @author jason + */ +@Getter +public enum ExpressQueryProviderEnum { + KD_NIAO("kd-niao", "快递鸟"), + KD_100("kd-100", "快递100"); + /** + * 快递服务商唯一编码 + */ + private final String code; + + /** + * 快递服务商名称 + */ + private final String name; + + ExpressQueryProviderEnum(String code, String name) { + this.code = code; + this.name = name; + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java new file mode 100644 index 000000000..87504faa3 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core; + +/** + * 快递服务商工厂, 用于创建和缓存快递服务商服务 + * @author jason + */ +public interface ExpressQueryProviderFactory { + + /** + * 通过枚举获取快递查询服务商, 如果不存在。就创建一个对应的快递查询服务商 + * @param queryProviderEnum 快递服务商枚举 + */ + ExpressQueryProvider getOrCreateExpressQueryProvider(ExpressQueryProviderEnum queryProviderEnum); +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java new file mode 100644 index 000000000..834c6170e --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.convert; + +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryRespDTO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface ExpressQueryConvert { + + ExpressQueryConvert INSTANCE = Mappers.getMapper(ExpressQueryConvert.class); + + List convertList(List expressTrackList); + + KdNiaoExpressQueryReqDTO convert(ExpressQueryReqDTO dto); +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryReqDTO.java new file mode 100644 index 000000000..7315aea07 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryReqDTO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.dto; + +import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; +import lombok.Data; + +/** + * 快递查询 Req DTO + * + * @author jason + */ +@Data +public class ExpressQueryReqDTO { + + /** + * 快递公司编码 + * + * 对应 {@link DeliveryExpressDO#getCode()} } + */ + private String expressCompanyCode; + + /** + * 发货快递单号 + */ + private String logisticsNo; + + /** + * 收、寄件人的电话号码 + */ + private String phone; +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryRespDTO.java new file mode 100644 index 000000000..feb06ea96 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryRespDTO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.dto; + +import lombok.Data; + +/** + * 快递查询 Resp DTO + * + * @author jason + */ +@Data +public class ExpressQueryRespDTO { + + /** + * 发生时间 + */ + private String time; + + /** + * 快递状态 + */ + private String state; +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java new file mode 100644 index 000000000..3f0faae49 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * 快递鸟快递查询 Req DTO + * + * @author jason + */ +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class KdNiaoExpressQueryReqDTO { + /** + * 快递公司编码 + */ + @JsonProperty("ShipperCode") + private String expressCompanyCode; + + /** + * 快递单号 + */ + @JsonProperty("LogisticCode") + private String logisticsNo; + + /** + * 订单编号 + */ + @JsonProperty("OrderCode") + private String orderNo; +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryRespDTO.java new file mode 100644 index 000000000..3e8883bbd --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryRespDTO.java @@ -0,0 +1,75 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +/** + * 快递鸟快递查询 Resp DTO 参见 快递鸟接口文档 + * + * @author jason + */ +@Data +public class KdNiaoExpressQueryRespDTO { + + /** + * 快递公司编码 + */ + @JsonProperty("ShipperCode") + private String expressCompanyCode; + + /** + * 快递单号 + */ + @JsonProperty("LogisticCode") + private String logisticsNo; + + /** + * 订单编号 + */ + @JsonProperty("OrderCode") + private String orderNo; + + @JsonProperty("EBusinessID") + private String businessId; + @JsonProperty("State") + private String state; + /** + * 成功与否 + */ + @JsonProperty("Success") + private Boolean success; + /** + * 失败原因 + */ + @JsonProperty("Reason") + private String reason; + + @JsonProperty("Traces") + private List tracks; + + @Data + public static class ExpressTrack { + /** + * 轨迹发生时间 + */ + @JsonProperty("AcceptTime") + private String time; + /** + * 轨迹描述 + */ + @JsonProperty("AcceptStation") + private String state; + } + +// { +// "EBusinessID": "1237100", +// "Traces": [], +// "State": "0", +// "ShipperCode": "STO", +// "LogisticCode": "638650888018", +// "Success": true, +// "Reason": "暂无轨迹信息" +// } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java new file mode 100644 index 000000000..cbf29cd4e --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java @@ -0,0 +1,53 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; + +import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProvider; +import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderEnum; +import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderFactory; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.List; + +import static cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderEnum.KD_NIAO; + +/** + * 快递查询客户端实现 + * + * @author jason + */ +@Component +@Slf4j +public class ExpressQueryClientImpl implements ExpressQueryClient { + @Resource + private ExpressQueryProviderFactory expressQueryProviderFactory; + @Resource + private TradeExpressQueryProperties tradeExpressQueryProperties; + + private ExpressQueryProvider expressQueryProvider; + @PostConstruct + private void init(){ + ExpressQueryProviderEnum queryProvider = tradeExpressQueryProperties.getExpressQueryProvider(); + if (queryProvider == null) { + // 如果未设置,默认使用快递鸟 + queryProvider = KD_NIAO; + } + expressQueryProvider = expressQueryProviderFactory.getOrCreateExpressQueryProvider(queryProvider); + if (expressQueryProvider == null) { + // 记录错误日志 + log.error("获取创建快递查询服务商{}失败,请检查相关配置", queryProvider); + } + Assert.notNull(expressQueryProvider, "快递查询服务商不能为空"); + + } + @Override + public List realTimeQuery(ExpressQueryReqDTO reqDTO) { + return expressQueryProvider.realTimeQueryExpress(reqDTO); + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java new file mode 100644 index 000000000..3060cb21c --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java @@ -0,0 +1,45 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; + +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProvider; +import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderEnum; +import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import javax.annotation.Resource; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author jason + */ +@Component +public class ExpressQueryProviderFactoryImpl implements ExpressQueryProviderFactory { + + private final Map providerMap = new ConcurrentHashMap<>(8); + @Resource + private TradeExpressQueryProperties tradeExpressQueryProperties; + @Resource + private RestTemplate restTemplate; + + @Override + public ExpressQueryProvider getOrCreateExpressQueryProvider(ExpressQueryProviderEnum queryProviderEnum) { + return providerMap.computeIfAbsent(queryProviderEnum, + provider -> createExpressQueryProvider(provider, tradeExpressQueryProperties)); + } + + private ExpressQueryProvider createExpressQueryProvider(ExpressQueryProviderEnum queryProviderEnum, + TradeExpressQueryProperties tradeExpressQueryProperties) { + ExpressQueryProvider result = null; + switch (queryProviderEnum) { + case KD_NIAO: + result = new KdNiaoExpressQueryProvider(restTemplate, tradeExpressQueryProperties.getKdNiao()); + break; + case KD_100: + result = new Kd100ExpressQueryProvider(restTemplate, tradeExpressQueryProperties.getKd100()); + break; + } + return result; + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java new file mode 100644 index 000000000..12a2fe653 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; + +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProvider; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; +import org.springframework.web.client.RestTemplate; + +import java.util.List; + +/** + * 快递 100 服务商 TODO + * @author jason + */ +public class Kd100ExpressQueryProvider implements ExpressQueryProvider { + + private final RestTemplate restTemplate; + + private final TradeExpressQueryProperties.Kd100Config config; + + public Kd100ExpressQueryProvider(RestTemplate restTemplate, TradeExpressQueryProperties.Kd100Config config) { + this.restTemplate = restTemplate; + this.config = config; + } + + @Override + public List realTimeQueryExpress(ExpressQueryReqDTO reqDTO) { + return null; + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java new file mode 100644 index 000000000..00a2f8b24 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java @@ -0,0 +1,129 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; + +import cn.hutool.core.codec.Base64; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.net.URLEncodeUtil; +import cn.hutool.crypto.digest.DigestUtil; +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProvider; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryRespDTO; +import com.fasterxml.jackson.core.type.TypeReference; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.*; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import java.util.Collections; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_FAILED; +import static cn.iocoder.yudao.module.trade.framework.delivery.core.convert.ExpressQueryConvert.INSTANCE; + +/** + * 快递鸟服务商 + * + * @author jason + */ +@Slf4j +public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { + private static final String REAL_TIME_QUERY_URL = "https://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx"; + /** + * 快递鸟即时查询免费版 RequestType + */ + private static final String REAL_TIME_FREE_REQ_TYPE = "1002"; + private final RestTemplate restTemplate; + private final TradeExpressQueryProperties.KdNiaoConfig config; + + public KdNiaoExpressQueryProvider(RestTemplate restTemplate, TradeExpressQueryProperties.KdNiaoConfig config) { + this.restTemplate = restTemplate; + this.config = config; + } + + /** + * 快递鸟即时查询免费版本 参见 快递鸟接口文档 + * @param reqDTO 查询请求参数 + */ + @Override + public List realTimeQueryExpress(ExpressQueryReqDTO reqDTO) { + KdNiaoExpressQueryReqDTO kdNiaoReqData = INSTANCE.convert(reqDTO); + // 快递公司编码需要转成大写 + kdNiaoReqData.setExpressCompanyCode(reqDTO.getExpressCompanyCode().toUpperCase()); + KdNiaoExpressQueryRespDTO respDTO = sendKdNiaoApiRequest(REAL_TIME_QUERY_URL, REAL_TIME_FREE_REQ_TYPE, + kdNiaoReqData, KdNiaoExpressQueryRespDTO.class); + log.debug("快递鸟即时查询接口返回 {}", respDTO); + if (respDTO.getSuccess() && CollUtil.isNotEmpty(respDTO.getTracks())) { + return INSTANCE.convertList(respDTO.getTracks()); + }else{ + return Collections.emptyList(); + } + } + + private Resp sendKdNiaoApiRequest(String url, String requestType, Req req, + Class respClass){ + return sendKdNiaoApiRequest(url, requestType, req, respClass, null); + } + private Resp sendKdNiaoApiRequest(String url, String requestType, Req req, + TypeReference typeRefResp){ + return sendKdNiaoApiRequest(url, requestType, req, null, typeRefResp); + } + + /** + * 快递鸟 通用的 API 请求 + * @param url 请求 url + * @param requestType 对应的请求指令 (快递鸟的RequestType) + * @param req 对应请求的请求参数 + * @param respClass 对应请求的响应 class + * @param typeRefResp 对应请求的响应 TypeReference + * @param 每个请求的请求结构 Req DTO + * @param 每个请求的响应结构 Resp DTO + */ + private Resp sendKdNiaoApiRequest(String url, String requestType, Req req, + Class respClass, TypeReference typeRefResp){ + // 请求头 + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + // 请求体 + String reqData = JsonUtils.toJsonString(req); + String dataSign = generateDataSign(reqData, config.getApiKey()); + log.trace("得到快递鸟接口 RequestType : {} 的 签名: {}", requestType, dataSign); + MultiValueMap requestBody = new LinkedMultiValueMap<>(); + requestBody.add("RequestData", reqData); + requestBody.add("DataType", "2"); + requestBody.add("EBusinessID", config.getBusinessId()); + requestBody.add("DataSign", dataSign); + requestBody.add("RequestType", requestType); + log.debug("快递鸟接口 RequestType : {}, 的请求参数 {}", requestType, requestBody); + HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); + // 发送请求 + ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); + log.debug("快递鸟接口 RequestType : {}, 的响应结果 {}", requestType, responseEntity); + // 处理响应 + if (responseEntity.getStatusCode().is2xxSuccessful()) { + String response = responseEntity.getBody(); + if (respClass != null && typeRefResp == null) { + return JsonUtils.parseObject(response, respClass); + } else { + return JsonUtils.parseObject(response, typeRefResp); + } + } else { + throw exception(EXPRESS_API_QUERY_FAILED); + } + } + + /** + * 快递鸟生成请求签名 参见 签名说明 + * @param reqData 请求实体 + * @param apiKey api Key + */ + private String generateDataSign(String reqData, String apiKey) { + String plainText = String.format("%s%s", reqData, apiKey); + log.trace("签名前的数据 {}", plainText); + return URLEncodeUtil.encode(Base64.encode(DigestUtil.md5Hex(plainText))); + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java new file mode 100644 index 000000000..f64550c77 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java @@ -0,0 +1,52 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; + +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; + +import javax.annotation.Resource; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * @author jason + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = KdNiaoExpressQueryProviderTest.Application.class) +@ActiveProfiles("trade-delivery-query") // 设置使用 trade-delivery-query 配置文件 +public class KdNiaoExpressQueryProviderTest { + @Resource + private RestTemplateBuilder builder; + @Resource + private TradeExpressQueryProperties expressQueryProperties; + + private KdNiaoExpressQueryProvider kdNiaoExpressQueryProvider; + + @BeforeEach + public void init(){ + kdNiaoExpressQueryProvider = new KdNiaoExpressQueryProvider(builder.build(),expressQueryProperties.getKdNiao()); + } + @Test + void queryExpress() { + ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO(); + reqDTO.setExpressCompanyCode("yto"); + reqDTO.setLogisticsNo("YT1764381060802"); + List expressQueryRespDTOS = kdNiaoExpressQueryProvider.realTimeQueryExpress(reqDTO); + assertNotNull(expressQueryRespDTOS); + } + + @Import({ + RestTemplateAutoConfiguration.class + }) + @EnableConfigurationProperties(TradeExpressQueryProperties.class) + public static class Application { + } +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml new file mode 100644 index 000000000..9922b84b9 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml @@ -0,0 +1,15 @@ +spring: + main: + lazy-initialization: true # 开启懒加载,加快速度 + banner-mode: off # 单元测试,禁用 Banner + +--- #################### 数据库相关配置 #################### + +yudao: + trade: + express: + query: + express-query-provider: kd_niao + kd-niao: + api-key: 8e22d97d-6a3d-442e-b243-2190c9f0cfdd + business-id: 1801700 \ No newline at end of file From 644d976a7855e06b7e947b75a2711e2a664445fa Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Sun, 11 Jun 2023 18:15:33 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E5=BF=AB=E9=80=92100=20=E5=BF=AB=E9=80=92?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/util/json/JsonUtils.java | 2 + .../trade/enums/ErrorCodeConstants.java | 5 +- .../config/TradeExpressQueryProperties.java | 14 +++- .../core/convert/ExpressQueryConvert.java | 6 ++ .../kd100/Kd100ExpressQueryReqDTO.java | 47 +++++++++++ .../kd100/Kd100ExpressQueryRespDTO.java | 59 ++++++++++++++ .../core/impl/Kd100ExpressQueryProvider.java | 81 ++++++++++++++++++- .../core/impl/KdNiaoExpressQueryProvider.java | 34 +++----- .../impl/Kd100ExpressQueryProviderTest.java | 56 +++++++++++++ .../impl/KdNiaoExpressQueryProviderTest.java | 20 ++--- .../application-trade-delivery-query.yaml | 9 ++- 11 files changed, 293 insertions(+), 40 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProviderTest.java diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/JsonUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/JsonUtils.java index 86d220638..7a2b1abce 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/JsonUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/JsonUtils.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -29,6 +30,7 @@ public class JsonUtils { static { objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.registerModules(new JavaTimeModule()); // 解决 LocalDateTime 的序列化 } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 4d74a3695..341a02c2b 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -53,8 +53,9 @@ public interface ErrorCodeConstants { ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011003003, "已经存在该运费模板名"); ErrorCode DELIVERY_EXPRESS_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003004, "计算快递运费时,收件人地址编号为空"); ErrorCode PRODUCT_EXPRESS_TEMPLATE_NOT_FOUND = new ErrorCode(1011003005, "找不到到商品对应的运费模板"); - ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011003006, "快递接口查询失败"); - ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011003007, "自提门店不存在"); + ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011003006, "快递查询接口异常"); + ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011003007, "快递查询返回失败, 原因:{}"); + ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011003008, "自提门店不存在"); // ========== Price 相关 1011004000 ============ ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1011004000, "支付价格计算异常,原因:价格小于等于 0"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java index c0705b74b..567e34085 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java @@ -55,10 +55,20 @@ public class TradeExpressQueryProperties { } /** - * 快递100 配置项 TODO + * 快递100 配置项 */ + @Data public static class Kd100Config { - + /** + * 快递 100 授权码 + */ + @NotEmpty(message = "快递 100 授权码配置项不能为空") + private String customer; + /** + * 快递 100 授权 key + */ + @NotEmpty(message = "快递 100 授权 Key 配置项不能为空") + private String key; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java index 834c6170e..d22f61ae5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.convert; import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100.Kd100ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100.Kd100ExpressQueryRespDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryRespDTO; import org.mapstruct.Mapper; @@ -16,5 +18,9 @@ public interface ExpressQueryConvert { List convertList(List expressTrackList); + List convertList2(List expressTrackList); + KdNiaoExpressQueryReqDTO convert(ExpressQueryReqDTO dto); + + Kd100ExpressQueryReqDTO convert2(ExpressQueryReqDTO dto); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java new file mode 100644 index 000000000..e2d55db34 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * 快递 100 快递查询 Req DTO + * + * @author jason + */ +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Kd100ExpressQueryReqDTO { + + /** + * 快递公司编码 + */ + @JsonProperty("com") + private String expressCompanyCode; + + /** + * 快递单号 + */ + @JsonProperty("num") + private String logisticsNo; + + /** + * 收、寄件人的电话号码 + */ + private String phone; + + /** + * 出发地城市 + */ + private String from; + + /** + * 目的地城市,到达目的地后会加大监控频率 + */ + private String to; + + /** + * 返回结果排序:desc降序(默认),asc 升序 + */ + private String order; +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java new file mode 100644 index 000000000..49be06234 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java @@ -0,0 +1,59 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +/** + * 快递 100 实时快递查询 Resp DTO 参见 快递 100 文档 + * + * @author jason + */ +@Data +public class Kd100ExpressQueryRespDTO { + + /** + * 快递公司编码 + */ + @JsonProperty("com") + private String expressCompanyCode; + + /** + * 快递单号 + */ + @JsonProperty("nu") + private String logisticsNo; + + /** + * 快递单当前状态 + */ + private String state; + + /** + * 查询结果, 失败返回 "false" + */ + private String result; + + /** + * 查询结果失败时的错误信息 + */ + private String message; + + @JsonProperty("data") + private List tracks; + + @Data + public static class ExpressTrack { + /** + * 轨迹发生时间 + */ + @JsonProperty("time") + private String time; + /** + * 轨迹描述 + */ + @JsonProperty("context") + private String state; + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java index 12a2fe653..07a51d0c9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java @@ -1,19 +1,39 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.HexUtil; +import cn.hutool.crypto.digest.DigestUtil; +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; import cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProvider; import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100.Kd100ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100.Kd100ExpressQueryRespDTO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.*; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; +import java.util.Collections; import java.util.List; +import java.util.Objects; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_FAILED; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_ERROR; +import static cn.iocoder.yudao.module.trade.framework.delivery.core.convert.ExpressQueryConvert.INSTANCE; /** - * 快递 100 服务商 TODO + * 快递 100 服务商 + * * @author jason */ +@Slf4j public class Kd100ExpressQueryProvider implements ExpressQueryProvider { + private static final String REAL_TIME_QUERY_URL = "https://poll.kuaidi100.com/poll/query.do"; private final RestTemplate restTemplate; private final TradeExpressQueryProperties.Kd100Config config; @@ -25,6 +45,63 @@ public class Kd100ExpressQueryProvider implements ExpressQueryProvider { @Override public List realTimeQueryExpress(ExpressQueryReqDTO reqDTO) { - return null; + Kd100ExpressQueryReqDTO kd100ReqParam = INSTANCE.convert2(reqDTO); + // 快递公司编码需要转成小写 + kd100ReqParam.setExpressCompanyCode(kd100ReqParam.getExpressCompanyCode().toLowerCase()); + Kd100ExpressQueryRespDTO respDTO = sendExpressQueryReq(REAL_TIME_QUERY_URL, kd100ReqParam, + Kd100ExpressQueryRespDTO.class); + log.debug("快递 100 接口 查询接口返回 {}", respDTO); + if (Objects.equals("false", respDTO.getResult())) { + log.error("快递 100 接口 返回失败 {} ", respDTO.getMessage()); + throw exception(EXPRESS_API_QUERY_FAILED, respDTO.getMessage()); + } else { + if (CollUtil.isNotEmpty(respDTO.getTracks())) { + return INSTANCE.convertList2(respDTO.getTracks()); + } else { + return Collections.emptyList(); + } + } + } + + /** + * 发送快递 100 实时快递查询请求,可以作为通用快递 100 通用请求接口。 目前没有其它场景需要使用。暂时放这里 + * @param url 请求 url + * @param req 对应请求的请求参数 + * @param respClass 对应请求的响应 class + * @param 每个请求的请求结构 Req DTO + * @param 每个请求的响应结构 Resp DTO + */ + private Resp sendExpressQueryReq(String url, Req req, Class respClass) { + // 请求头 + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + // 生成签名 + String param = JsonUtils.toJsonString(req); + String sign = generateReqSign(param, config.getKey(), config.getCustomer()); + log.debug("快递 100 快递 接口生成签名的: {}", sign); + // 请求体 + MultiValueMap requestBody = new LinkedMultiValueMap<>(); + requestBody.add("customer", config.getCustomer()); + requestBody.add("sign", sign); + requestBody.add("param", param); + log.debug("快递 100 接口的请求参数: {}", requestBody); + + HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); + // 发送请求 + ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); + log.debug("快递 100 接口响应结果 {}", responseEntity); + // 处理响应 + if (responseEntity.getStatusCode().is2xxSuccessful()) { + String response = responseEntity.getBody(); + return JsonUtils.parseObject(response, respClass); + } else { + throw exception(EXPRESS_API_QUERY_ERROR); + } + } + + private String generateReqSign(String param, String key, String customer) { + String plainText = String.format("%s%s%s", param, key, customer); + log.debug("快递 100 接口待签名的数据 {}", plainText); + return HexUtil.encodeHexStr(DigestUtil.md5(plainText), false); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java index 00a2f8b24..b911892cd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java @@ -11,7 +11,6 @@ import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReq import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryRespDTO; -import com.fasterxml.jackson.core.type.TypeReference; import lombok.extern.slf4j.Slf4j; import org.springframework.http.*; import org.springframework.util.LinkedMultiValueMap; @@ -23,6 +22,7 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_FAILED; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_ERROR; import static cn.iocoder.yudao.module.trade.framework.delivery.core.convert.ExpressQueryConvert.INSTANCE; /** @@ -57,34 +57,28 @@ public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { KdNiaoExpressQueryRespDTO respDTO = sendKdNiaoApiRequest(REAL_TIME_QUERY_URL, REAL_TIME_FREE_REQ_TYPE, kdNiaoReqData, KdNiaoExpressQueryRespDTO.class); log.debug("快递鸟即时查询接口返回 {}", respDTO); - if (respDTO.getSuccess() && CollUtil.isNotEmpty(respDTO.getTracks())) { - return INSTANCE.convertList(respDTO.getTracks()); + if(!respDTO.getSuccess()){ + throw exception(EXPRESS_API_QUERY_FAILED, respDTO.getReason()); }else{ - return Collections.emptyList(); + if (CollUtil.isNotEmpty(respDTO.getTracks())) { + return INSTANCE.convertList(respDTO.getTracks()); + }else{ + return Collections.emptyList(); + } } } - private Resp sendKdNiaoApiRequest(String url, String requestType, Req req, - Class respClass){ - return sendKdNiaoApiRequest(url, requestType, req, respClass, null); - } - private Resp sendKdNiaoApiRequest(String url, String requestType, Req req, - TypeReference typeRefResp){ - return sendKdNiaoApiRequest(url, requestType, req, null, typeRefResp); - } - /** - * 快递鸟 通用的 API 请求 + * 快递鸟 通用的 API 请求, 暂时没有其他应用场景, 暂时放这里 * @param url 请求 url * @param requestType 对应的请求指令 (快递鸟的RequestType) * @param req 对应请求的请求参数 * @param respClass 对应请求的响应 class - * @param typeRefResp 对应请求的响应 TypeReference * @param 每个请求的请求结构 Req DTO * @param 每个请求的响应结构 Resp DTO */ private Resp sendKdNiaoApiRequest(String url, String requestType, Req req, - Class respClass, TypeReference typeRefResp){ + Class respClass){ // 请求头 HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); @@ -106,13 +100,9 @@ public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { // 处理响应 if (responseEntity.getStatusCode().is2xxSuccessful()) { String response = responseEntity.getBody(); - if (respClass != null && typeRefResp == null) { - return JsonUtils.parseObject(response, respClass); - } else { - return JsonUtils.parseObject(response, typeRefResp); - } + return JsonUtils.parseObject(response, respClass); } else { - throw exception(EXPRESS_API_QUERY_FAILED); + throw exception(EXPRESS_API_QUERY_ERROR); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProviderTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProviderTest.java new file mode 100644 index 000000000..0d82f745b --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProviderTest.java @@ -0,0 +1,56 @@ +package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; + +import cn.iocoder.yudao.framework.common.exception.ServiceException; +import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; +import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; + +import javax.annotation.Resource; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * @author jason + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = Kd100ExpressQueryProviderTest.Application.class) +@ActiveProfiles("trade-delivery-query") // 设置使用 trade-delivery-query 配置文件 +public class Kd100ExpressQueryProviderTest { + @Resource + private RestTemplateBuilder builder; + @Resource + private TradeExpressQueryProperties expressQueryProperties; + + private Kd100ExpressQueryProvider kd100ExpressQueryProvider; + + @BeforeEach + public void init(){ + kd100ExpressQueryProvider = new Kd100ExpressQueryProvider(builder.build(),expressQueryProperties.getKd100()); + } + @Test + @Disabled("需要 授权 key. 暂时忽略") + void testRealTimeQueryExpressFailed() { + ServiceException t = assertThrows(ServiceException.class, () -> { + ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO(); + reqDTO.setExpressCompanyCode("yto"); + reqDTO.setLogisticsNo("YT9383342193097"); + kd100ExpressQueryProvider.realTimeQueryExpress(reqDTO); + }); + assertEquals(1011003007, t.getCode()); + } + + @Import({ + RestTemplateAutoConfiguration.class + }) + @EnableConfigurationProperties(TradeExpressQueryProperties.class) + public static class Application { + } +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java index f64550c77..cdde6c683 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java @@ -1,9 +1,10 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.impl; +import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressQueryProperties; import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -13,9 +14,8 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.ActiveProfiles; import javax.annotation.Resource; -import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author jason @@ -35,12 +35,14 @@ public class KdNiaoExpressQueryProviderTest { kdNiaoExpressQueryProvider = new KdNiaoExpressQueryProvider(builder.build(),expressQueryProperties.getKdNiao()); } @Test - void queryExpress() { - ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO(); - reqDTO.setExpressCompanyCode("yto"); - reqDTO.setLogisticsNo("YT1764381060802"); - List expressQueryRespDTOS = kdNiaoExpressQueryProvider.realTimeQueryExpress(reqDTO); - assertNotNull(expressQueryRespDTOS); + @Disabled("需要 授权 key. 暂时忽略") + void testRealTimeQueryExpressFailed() { + assertThrows(ServiceException.class,() ->{ + ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO(); + reqDTO.setExpressCompanyCode("yy"); + reqDTO.setLogisticsNo("YT9383342193097"); + kdNiaoExpressQueryProvider.realTimeQueryExpress(reqDTO); + }); } @Import({ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml index 9922b84b9..e01cb1652 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/application-trade-delivery-query.yaml @@ -3,7 +3,7 @@ spring: lazy-initialization: true # 开启懒加载,加快速度 banner-mode: off # 单元测试,禁用 Banner ---- #################### 数据库相关配置 #################### +--- #################### 交易快递查询相关配置 #################### yudao: trade: @@ -11,5 +11,8 @@ yudao: query: express-query-provider: kd_niao kd-niao: - api-key: 8e22d97d-6a3d-442e-b243-2190c9f0cfdd - business-id: 1801700 \ No newline at end of file + api-key: xxx + business-id: xxxxxxxx + kd100: + customer: xxxx + key: xxxxx From b6c7a940be7e62b1f7054fc018dc48684b41b9aa Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 11 Jun 2023 23:19:04 +0800 Subject: [PATCH 7/9] =?UTF-8?q?mall=20+=20promotion=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=A7=92=E6=9D=80=E6=B4=BB=E5=8A=A8=E7=9A=84=20mock?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seckill/vo/activity/SeckillActivityBaseVO.java | 2 +- .../app/seckill/AppSeckillActivityController.java | 13 ++++++++----- .../seckill/vo/AppSeckillActivitiDetailRespVO.java | 3 +++ .../seckillactivity/SeckillActivityConvert.java | 4 ++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityBaseVO.java index 1fa803f71..63f68da1c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckill/vo/activity/SeckillActivityBaseVO.java @@ -58,7 +58,7 @@ public class SeckillActivityBaseVO { @Schema(description = "每人限购", example = "10") // 如果为 0 则不限购 @Min(value = 0, message = "每人限购需要大于等于 0") - private Integer limitBuyCount; + private Integer limitCount; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java index 22d4f76bd..4e37a361e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java @@ -33,30 +33,33 @@ public class AppSeckillActivityController { obj.setId(id); obj.setName("晚九点限时秒杀"); obj.setStatus(1); - obj.setStartTime(LocalDateTime.of(2023, 6, 10, 0, 0, 0)); - obj.setEndTime(LocalDateTime.of(2023, 6, 10, 23, 59, 0)); + obj.setStartTime(LocalDateTime.of(2023, 6, 11, 0, 0, 0)); + obj.setEndTime(LocalDateTime.of(2023, 6, 11, 23, 59, 0)); obj.setSpuId(633L); // 创建一个Product对象的列表 List productList = new ArrayList<>(); // 创建三个新的Product对象并设置其属性的值 AppSeckillActivitiDetailRespVO.Product product1 = new AppSeckillActivitiDetailRespVO.Product(); - product1.setSkuId(4096L); + product1.setSkuId(1L); product1.setSeckillPrice(100); product1.setQuota(50); + product1.setLimitCount(3); // 将第一个Product对象添加到列表中 productList.add(product1); // 创建第二个Product对象并设置其属性的值 AppSeckillActivitiDetailRespVO.Product product2 = new AppSeckillActivitiDetailRespVO.Product(); - product2.setSkuId(4097L); + product2.setSkuId(2L); product2.setSeckillPrice(200); product2.setQuota(100); + product2.setLimitCount(4); // 将第二个Product对象添加到列表中 productList.add(product2); // 创建第三个Product对象并设置其属性的值 AppSeckillActivitiDetailRespVO.Product product3 = new AppSeckillActivitiDetailRespVO.Product(); - product3.setSkuId(4098L); + product3.setSkuId(3L); product3.setSeckillPrice(300); product3.setQuota(150); + product3.setLimitCount(5); // 将第三个Product对象添加到列表中 productList.add(product3); // 将Product列表设置为对象的属性值 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java index 62cdf9b4f..0f1408928 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/AppSeckillActivitiDetailRespVO.java @@ -46,6 +46,9 @@ public class AppSeckillActivitiDetailRespVO { @Schema(description = "秒杀限量库存", required = true, example = "50") private Integer quota; + @Schema(description = "limitCount", required = true, example = "10") + private Integer limitCount; + } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index 1a00fdeb6..0294c248b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -56,7 +56,7 @@ public interface SeckillActivityConvert { && ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId()) && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice()) && ObjectUtil.equals(productDO.getStock(), productVO.getStock()) - && ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount()); + && ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount()); } /** @@ -71,7 +71,7 @@ public interface SeckillActivityConvert { && ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId()) && ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice()) && ObjectUtil.equals(productDO.getStock(), productVO.getStock()) - && ObjectUtil.equals(productDO.getLimitBuyCount(), productVO.getLimitBuyCount()); + && ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount()); } From e1a8e45ac781bb2948adbabd86dc801ef2595e07 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 11 Jun 2023 23:40:38 +0800 Subject: [PATCH 8/9] =?UTF-8?q?mall=20+=20trade=EF=BC=9A=E5=BF=AB=E9=80=92?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/ErrorCodeConstants.java | 4 ++-- .../DeliveryExpressTemplateService.java | 3 ++- .../DeliveryExpressTemplateServiceImpl.java | 3 +-- .../bo/SpuDeliveryExpressTemplateRespBO.java | 2 ++ .../price/bo/TradePriceCalculateRespBO.java | 21 ++++++++++--------- .../TradeDeliveryPriceCalculator.java | 6 ++++-- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 341a02c2b..46ee636a5 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -51,8 +51,8 @@ public interface ErrorCodeConstants { ErrorCode EXPRESS_CODE_DUPLICATE = new ErrorCode(1011003001, "已经存在该编码的快递公司"); ErrorCode EXPRESS_TEMPLATE_NOT_EXISTS = new ErrorCode(1011003002, "运费模板不存在"); ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011003003, "已经存在该运费模板名"); - ErrorCode DELIVERY_EXPRESS_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003004, "计算快递运费时,收件人地址编号为空"); - ErrorCode PRODUCT_EXPRESS_TEMPLATE_NOT_FOUND = new ErrorCode(1011003005, "找不到到商品对应的运费模板"); + ErrorCode DELIVERY_EXPRESS_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003004, "计算快递运费时,收件人地址编号为空"); // TODO @jaosn:这个错误码,放到 Price 这块 + ErrorCode PRODUCT_EXPRESS_TEMPLATE_NOT_FOUND = new ErrorCode(1011003005, "找不到到商品对应的运费模板"); // TODO @jaosn:这个错误码,放到 Price 这块 ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011003006, "快递查询接口异常"); ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011003007, "快递查询返回失败, 原因:{}"); ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011003008, "自提门店不存在"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java index e037dbc29..3c438df12 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateService.java @@ -75,7 +75,7 @@ public interface DeliveryExpressTemplateService { /** * 校验快递运费模板 - *

+ * * 如果校验不通过,抛出 {@link cn.iocoder.yudao.framework.common.exception.ServiceException} 异常 * * @param templateId 模板编号 @@ -83,6 +83,7 @@ public interface DeliveryExpressTemplateService { */ DeliveryExpressTemplateDO validateDeliveryExpressTemplate(Long templateId); + // TODO @jason:可以把 spuIds 改成传递 ids 么?价格计算那,在 TradePriceCalculateRespBO 冗余好 templateId 字段。目的是,减少重复的查询 /** * 基于指定的 SPU 编号数组和收件人地址区域编号. 获取匹配运费模板 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java index 7aa591388..c7ddc9da6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/DeliveryExpressTemplateServiceImpl.java @@ -242,10 +242,9 @@ public class DeliveryExpressTemplateServiceImpl implements DeliveryExpressTempla if (spu == null) { return; } + // TODO @jason:避免循环查询;最好类似 expressTemplateMapper.selectBatchIds(spuMap.keySet()); 批量查询,内存组合; SpuDeliveryExpressTemplateRespBO bo = new SpuDeliveryExpressTemplateRespBO() .setChargeMode(item.getChargeMode()) - // TODO @jason:是不是只要查询到一个,就不用查询下一个了;TemplateCharge 和 TemplateFree - // @芋艿 包邮的优先级> 费用的优先级 所以两个都要查询 .setTemplateCharge(findMatchExpressTemplateCharge(item.getId(), areaId)) .setTemplateFree(findMatchExpressTemplateFree(item.getId(), areaId)); result.put(spu.getId(), bo); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/SpuDeliveryExpressTemplateRespBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/SpuDeliveryExpressTemplateRespBO.java index 5fd11f030..82a0274de 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/SpuDeliveryExpressTemplateRespBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/delivery/bo/SpuDeliveryExpressTemplateRespBO.java @@ -18,6 +18,8 @@ public class SpuDeliveryExpressTemplateRespBO { */ private Integer chargeMode; + // TODO @jaosn:可以把 DeliveryExpressTemplateChargeBO 和 DeliveryExpressTemplateFreeBO 搞成内嵌的类。这样简洁一点 + /** * 运费模板快递运费设置 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java index 5a6a762a9..8231621bb 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java @@ -164,16 +164,7 @@ public class TradePriceCalculateRespBO { */ private Integer payPrice; - /** - * 商品重量,单位:kg 千克 - */ - private Double weight; - /** - * 商品体积,单位:m^3 平米 - */ - private Double volume; - - // ========== 商品信息 ========== + // ========== 商品 SPU 信息 ========== /** * 商品名 */ @@ -189,6 +180,16 @@ public class TradePriceCalculateRespBO { */ private Long categoryId; + // ========== 商品 SKU 信息 ========== + /** + * 商品重量,单位:kg 千克 + */ + private Double weight; + /** + * 商品体积,单位:m^3 平米 + */ + private Double volume; + /** * 商品属性数组 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java index 222acab9e..9f8e6afa7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java @@ -62,7 +62,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { deliveryExpressTemplateService.getExpressTemplateMapBySpuIdsAndArea(spuIds, address.getAreaId()); // 3. 计算配送费用 if (CollUtil.isEmpty(spuExpressTemplateMap)) { - log.error("找不到商品 SPU ID {}, area Id {} ,对应的运费模板", spuIds, address.getAreaId()); + log.error("[calculate][找不到商品 spuId{} areaId{} 对应的运费模板]", spuIds, address.getAreaId()); throw exception(PRODUCT_EXPRESS_TEMPLATE_NOT_FOUND); } calculateDeliveryPrice(selectedItem, spuExpressTemplateMap, result); @@ -170,7 +170,8 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { */ private void divideDeliveryPrice(int deliveryPrice, List orderItems) { // TODO @jason:分摊的话,是不是要按照比例呀?重量、价格、数量等等, - // 按比例是不是有点复杂。后面看看是否需要 + // 按比例是不是有点复杂。后面看看是否需要; + // TODO 可以看看别的项目怎么搞的哈。 int dividePrice = deliveryPrice / orderItems.size(); for (OrderItem item : orderItems) { // 更新快递运费 @@ -207,6 +208,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { // freeCount 是不是应该是 double ?? // TODO @jason:要不配置的时候,把它的单位和商品对齐?到底是 kg、还是斤 // TODO @芋艿 目前 包邮 件数/重量/体积 都用的是这个字段 + // TODO @jason:那要不快递模版也改成 kg?这样是不是就不用 double ? if (totalWeight >= templateFree.getFreeCount() && totalPrice >= templateFree.getFreePrice()) { return true; From dcb1660880064f8357955761fb03011e4a976d4c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 12 Jun 2023 00:20:20 +0800 Subject: [PATCH 9/9] =?UTF-8?q?mall=20+=20trade=EF=BC=9Acode=20review=20?= =?UTF-8?q?=E5=BF=AB=E9=80=92=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/config/YudaoWebAutoConfiguration.java | 18 +++++------ .../config/TradeExpressQueryProperties.java | 15 ++++++--- .../delivery/core/ExpressQueryClient.java | 3 ++ .../delivery/core/ExpressQueryProvider.java | 2 ++ .../core/ExpressQueryProviderEnum.java | 5 +++ .../core/ExpressQueryProviderFactory.java | 9 ++++-- .../core/convert/ExpressQueryConvert.java | 1 + .../delivery/core/dto/ExpressQueryReqDTO.java | 4 ++- .../core/dto/ExpressQueryRespDTO.java | 4 ++- .../kd100/Kd100ExpressQueryReqDTO.java | 8 +++-- .../kd100/Kd100ExpressQueryRespDTO.java | 8 ++--- .../kdniao/KdNiaoExpressQueryReqDTO.java | 5 +-- .../core/impl/ExpressQueryClientImpl.java | 22 ++++++++++--- .../impl/ExpressQueryProviderFactoryImpl.java | 3 ++ .../core/impl/Kd100ExpressQueryProvider.java | 32 ++++++++++++------- .../core/impl/KdNiaoExpressQueryProvider.java | 18 +++++++---- .../impl/KdNiaoExpressQueryProviderTest.java | 5 +-- 17 files changed, 111 insertions(+), 51 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java index 110eb80bb..e47619df3 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java @@ -110,19 +110,19 @@ public class YudaoWebAutoConfiguration implements WebMvcConfigurer { return createFilterBean(new DemoFilter(), WebFilterOrderEnum.DEMO_FILTER); } - /** - * 创建 RestTemplate 实例 - * @param restTemplateBuilder {@link RestTemplateAutoConfiguration#restTemplateBuilder} - */ - @Bean - public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder){ - return restTemplateBuilder.build(); - } - public static FilterRegistrationBean createFilterBean(T filter, Integer order) { FilterRegistrationBean bean = new FilterRegistrationBean<>(filter); bean.setOrder(order); return bean; } + /** + * 创建 RestTemplate 实例 + * + * @param restTemplateBuilder {@link RestTemplateAutoConfiguration#restTemplateBuilder} + */ + @Bean + public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) { + return restTemplateBuilder.build(); + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java index 567e34085..be0f93414 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressQueryProperties.java @@ -9,6 +9,8 @@ import org.springframework.validation.annotation.Validated; import javax.validation.Valid; import javax.validation.constraints.NotEmpty; +// TODO @jason:TradeExpressProperties;更通用哈 +// TODO @芋艿:未来要不要放数据库中?考虑 saas 多租户时,不同租户使用不同的配置? /** * 交易快递查询的配置项 * @@ -21,9 +23,13 @@ import javax.validation.constraints.NotEmpty; public class TradeExpressQueryProperties { /** - * 快递查询服务商, 如果未配置,默认使用快递鸟 + * 快递查询服务商 + * + * 如果未配置,默认使用快递鸟 */ - private ExpressQueryProviderEnum expressQueryProvider; + // TODO @jason:可以把 expressQueryProvider 改成 client 变量,更简洁一点; + private ExpressQueryProviderEnum expressQueryProvider; // TODO @jaosn:默认值可以通过属性直接赋值哈; + // TODO @jason:需要考虑下,用户只配置了其中一个; /** * 快递鸟配置 */ @@ -46,12 +52,12 @@ public class TradeExpressQueryProperties { */ @NotEmpty(message = "快递鸟用户 ID 配置项不能为空") private String businessId; - /** * 快递鸟 API Key */ @NotEmpty(message = "快递鸟 Api Key 配置项不能为空") private String apiKey; + } /** @@ -59,6 +65,7 @@ public class TradeExpressQueryProperties { */ @Data public static class Kd100Config { + /** * 快递 100 授权码 */ @@ -69,7 +76,7 @@ public class TradeExpressQueryProperties { */ @NotEmpty(message = "快递 100 授权 Key 配置项不能为空") private String key; + } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java index d43429d72..1494bb2e5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryClient.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRes import java.util.List; +// TODO @jason:可以改成 ExpressClient,未来可能还对接别的接口噢 /** * 快递查询客户端 * @@ -17,5 +18,7 @@ public interface ExpressQueryClient { * * @param reqDTO 查询请求参数 */ + // TODO @jason:可以改成 getExpressTrackList。返回字段可以参考 https://doc.youzanyun.com/detail/API/0/5 响应的 data List realTimeQuery(ExpressQueryReqDTO reqDTO); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java index 6fb0a4179..e741e1426 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProvider.java @@ -11,10 +11,12 @@ import java.util.List; * @author jason */ public interface ExpressQueryProvider { + /** * 快递实时查询 * * @param reqDTO 查询请求参数 */ List realTimeQueryExpress(ExpressQueryReqDTO reqDTO); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderEnum.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderEnum.java index 094848ba6..48dab7eec 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderEnum.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderEnum.java @@ -8,9 +8,12 @@ import lombok.Getter; * @author jason */ @Getter + public enum ExpressQueryProviderEnum { + KD_NIAO("kd-niao", "快递鸟"), KD_100("kd-100", "快递100"); + /** * 快递服务商唯一编码 */ @@ -21,8 +24,10 @@ public enum ExpressQueryProviderEnum { */ private final String name; + // TODO @jaosn:@AllArgsConstructor 可以替代哈 ExpressQueryProviderEnum(String code, String name) { this.code = code; this.name = name; } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java index 87504faa3..bad2c6a5d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/ExpressQueryProviderFactory.java @@ -1,14 +1,19 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core; /** - * 快递服务商工厂, 用于创建和缓存快递服务商服务 + * 快递服务商工厂,用于创建和缓存快递服务商服务 + * * @author jason */ public interface ExpressQueryProviderFactory { /** - * 通过枚举获取快递查询服务商, 如果不存在。就创建一个对应的快递查询服务商 + * 通过枚举获取快递查询服务商 + * + * 如果不存在,就创建一个对应的快递查询服务商 + * * @param queryProviderEnum 快递服务商枚举 */ ExpressQueryProvider getOrCreateExpressQueryProvider(ExpressQueryProviderEnum queryProviderEnum); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java index d22f61ae5..615f84b4e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/convert/ExpressQueryConvert.java @@ -23,4 +23,5 @@ public interface ExpressQueryConvert { KdNiaoExpressQueryReqDTO convert(ExpressQueryReqDTO dto); Kd100ExpressQueryReqDTO convert2(ExpressQueryReqDTO dto); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryReqDTO.java index 7315aea07..ffa72c532 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryReqDTO.java @@ -14,8 +14,9 @@ public class ExpressQueryReqDTO { /** * 快递公司编码 * - * 对应 {@link DeliveryExpressDO#getCode()} } + * 对应 {@link DeliveryExpressDO#getCode()} */ + // TODO @jaosn:要不改成 expressCode;项目里使用这个哈 private String expressCompanyCode; /** @@ -27,4 +28,5 @@ public class ExpressQueryReqDTO { * 收、寄件人的电话号码 */ private String phone; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryRespDTO.java index feb06ea96..0bdb386c4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryRespDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/ExpressQueryRespDTO.java @@ -10,13 +10,15 @@ import lombok.Data; @Data public class ExpressQueryRespDTO { + // TODO @jason:LocalDateTime /** * 发生时间 */ private String time; - + // TODO @jason:其它字段可能要补充下 /** * 快递状态 */ private String state; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java index e2d55db34..d1b72426f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java @@ -13,6 +13,7 @@ import lombok.Data; @JsonInclude(JsonInclude.Include.NON_NULL) public class Kd100ExpressQueryReqDTO { + // TODO @jaosn:要不改成 expressCode;项目里使用这个哈 /** * 快递公司编码 */ @@ -29,19 +30,20 @@ public class Kd100ExpressQueryReqDTO { * 收、寄件人的电话号码 */ private String phone; - /** * 出发地城市 */ private String from; - /** * 目的地城市,到达目的地后会加大监控频率 */ private String to; /** - * 返回结果排序:desc降序(默认),asc 升序 + * 返回结果排序 + * + * desc 降序(默认), asc 升序 */ private String order; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java index 49be06234..f7e5bdf04 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java @@ -18,23 +18,22 @@ public class Kd100ExpressQueryRespDTO { */ @JsonProperty("com") private String expressCompanyCode; - /** * 快递单号 */ @JsonProperty("nu") private String logisticsNo; - /** * 快递单当前状态 */ private String state; /** - * 查询结果, 失败返回 "false" + * 查询结果 + * + * 失败返回 "false" */ private String result; - /** * 查询结果失败时的错误信息 */ @@ -56,4 +55,5 @@ public class Kd100ExpressQueryRespDTO { @JsonProperty("context") private String state; } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java index 3f0faae49..21b1abc58 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java @@ -12,21 +12,22 @@ import lombok.Data; @Data @JsonInclude(JsonInclude.Include.NON_NULL) public class KdNiaoExpressQueryReqDTO { + + // TODO @jaosn:要不改成 expressCode;项目里使用这个哈 /** * 快递公司编码 */ @JsonProperty("ShipperCode") private String expressCompanyCode; - /** * 快递单号 */ @JsonProperty("LogisticCode") private String logisticsNo; - /** * 订单编号 */ @JsonProperty("OrderCode") private String orderNo; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java index cbf29cd4e..59dfc77c1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryClientImpl.java @@ -17,6 +17,15 @@ import java.util.List; import static cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQueryProviderEnum.KD_NIAO; +// TODO @jason:可以把整体包结构调整下;参考 sms client 的方式; +// + config +// + core +// client +// + dto +// + impl:里面可以放 kdniaoclient、kd100client +// ExpressClient +// ExpressClientFactory: 通过它直接获取默认和创建默认的 Client +// enums /** * 快递查询客户端实现 * @@ -24,30 +33,33 @@ import static cn.iocoder.yudao.module.trade.framework.delivery.core.ExpressQuery */ @Component @Slf4j -public class ExpressQueryClientImpl implements ExpressQueryClient { +public class ExpressQueryClientImpl implements ExpressQueryClient { + @Resource private ExpressQueryProviderFactory expressQueryProviderFactory; @Resource private TradeExpressQueryProperties tradeExpressQueryProperties; private ExpressQueryProvider expressQueryProvider; + @PostConstruct - private void init(){ + private void init() { + // 如果未设置,默认使用快递鸟 ExpressQueryProviderEnum queryProvider = tradeExpressQueryProperties.getExpressQueryProvider(); if (queryProvider == null) { - // 如果未设置,默认使用快递鸟 queryProvider = KD_NIAO; } + // 创建客户端 expressQueryProvider = expressQueryProviderFactory.getOrCreateExpressQueryProvider(queryProvider); if (expressQueryProvider == null) { - // 记录错误日志 log.error("获取创建快递查询服务商{}失败,请检查相关配置", queryProvider); } Assert.notNull(expressQueryProvider, "快递查询服务商不能为空"); - } + @Override public List realTimeQuery(ExpressQueryReqDTO reqDTO) { return expressQueryProvider.realTimeQueryExpress(reqDTO); } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java index 3060cb21c..b6ce8d68a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/ExpressQueryProviderFactoryImpl.java @@ -12,12 +12,14 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** + * // TODO @jason:注释不全 * @author jason */ @Component public class ExpressQueryProviderFactoryImpl implements ExpressQueryProviderFactory { private final Map providerMap = new ConcurrentHashMap<>(8); + @Resource private TradeExpressQueryProperties tradeExpressQueryProperties; @Resource @@ -31,6 +33,7 @@ public class ExpressQueryProviderFactoryImpl implements ExpressQueryProviderFact private ExpressQueryProvider createExpressQueryProvider(ExpressQueryProviderEnum queryProviderEnum, TradeExpressQueryProperties tradeExpressQueryProperties) { + // TODO @jason:是不是直接 return 就好啦,更简洁一点 ExpressQueryProvider result = null; switch (queryProviderEnum) { case KD_NIAO: diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java index 07a51d0c9..4227cebc8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProvider.java @@ -21,10 +21,11 @@ import java.util.List; import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_FAILED; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_ERROR; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_API_QUERY_FAILED; import static cn.iocoder.yudao.module.trade.framework.delivery.core.convert.ExpressQueryConvert.INSTANCE; +// TODO @jason:可以参考 KdNiaoExpressQueryProvider 建议改改哈 /** * 快递 100 服务商 * @@ -34,8 +35,8 @@ import static cn.iocoder.yudao.module.trade.framework.delivery.core.convert.Expr public class Kd100ExpressQueryProvider implements ExpressQueryProvider { private static final String REAL_TIME_QUERY_URL = "https://poll.kuaidi100.com/poll/query.do"; - private final RestTemplate restTemplate; + private final RestTemplate restTemplate; private final TradeExpressQueryProperties.Kd100Config config; public Kd100ExpressQueryProvider(RestTemplate restTemplate, TradeExpressQueryProperties.Kd100Config config) { @@ -45,16 +46,19 @@ public class Kd100ExpressQueryProvider implements ExpressQueryProvider { @Override public List realTimeQueryExpress(ExpressQueryReqDTO reqDTO) { + // 发起查询 Kd100ExpressQueryReqDTO kd100ReqParam = INSTANCE.convert2(reqDTO); - // 快递公司编码需要转成小写 - kd100ReqParam.setExpressCompanyCode(kd100ReqParam.getExpressCompanyCode().toLowerCase()); + kd100ReqParam.setExpressCompanyCode(kd100ReqParam.getExpressCompanyCode().toLowerCase()); // 快递公司编码需要转成小写 Kd100ExpressQueryRespDTO respDTO = sendExpressQueryReq(REAL_TIME_QUERY_URL, kd100ReqParam, Kd100ExpressQueryRespDTO.class); - log.debug("快递 100 接口 查询接口返回 {}", respDTO); + log.debug("[realTimeQueryExpress][快递 100 接口 查询接口返回 {}]", respDTO); + // 处理结果 if (Objects.equals("false", respDTO.getResult())) { - log.error("快递 100 接口 返回失败 {} ", respDTO.getMessage()); + log.error("[realTimeQueryExpress][快递 100 接口 返回失败 {}]", respDTO.getMessage()); throw exception(EXPRESS_API_QUERY_FAILED, respDTO.getMessage()); + // TODO @json:else 可以不用写哈; } else { + // TODO @jason:convertList2 如果空,应该返回 list 了; if (CollUtil.isNotEmpty(respDTO.getTracks())) { return INSTANCE.convertList2(respDTO.getTracks()); } else { @@ -65,12 +69,14 @@ public class Kd100ExpressQueryProvider implements ExpressQueryProvider { /** * 发送快递 100 实时快递查询请求,可以作为通用快递 100 通用请求接口。 目前没有其它场景需要使用。暂时放这里 + * * @param url 请求 url * @param req 对应请求的请求参数 * @param respClass 对应请求的响应 class * @param 每个请求的请求结构 Req DTO * @param 每个请求的响应结构 Resp DTO */ + // TODO @jason:可以改成 request,发起请求哈; private Resp sendExpressQueryReq(String url, Req req, Class respClass) { // 请求头 HttpHeaders headers = new HttpHeaders(); @@ -78,19 +84,20 @@ public class Kd100ExpressQueryProvider implements ExpressQueryProvider { // 生成签名 String param = JsonUtils.toJsonString(req); String sign = generateReqSign(param, config.getKey(), config.getCustomer()); - log.debug("快递 100 快递 接口生成签名的: {}", sign); // 请求体 MultiValueMap requestBody = new LinkedMultiValueMap<>(); requestBody.add("customer", config.getCustomer()); requestBody.add("sign", sign); requestBody.add("param", param); - log.debug("快递 100 接口的请求参数: {}", requestBody); - - HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); + log.debug("[sendExpressQueryReq][快递 100 接口的请求参数: {}]", requestBody); // 发送请求 + HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); + // TODO @jason:可以使用 restTemplate 的 post 方法哇? ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); - log.debug("快递 100 接口响应结果 {}", responseEntity); + log.debug("[sendExpressQueryReq][快递 100 接口响应结果 {}]", responseEntity); + // 处理响应 + // TODO @jason:if return 原则;if (!responseEntity.getStatusCode().is2xxSuccessful()) 抛出异常;接着处理成功的 if (responseEntity.getStatusCode().is2xxSuccessful()) { String response = responseEntity.getBody(); return JsonUtils.parseObject(response, respClass); @@ -101,7 +108,8 @@ public class Kd100ExpressQueryProvider implements ExpressQueryProvider { private String generateReqSign(String param, String key, String customer) { String plainText = String.format("%s%s%s", param, key, customer); - log.debug("快递 100 接口待签名的数据 {}", plainText); + // TODO @jason:DigestUtil.md5Hex(plainText); return HexUtil.encodeHexStr(DigestUtil.md5(plainText), false); } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java index b911892cd..4ca5f6142 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProvider.java @@ -32,21 +32,27 @@ import static cn.iocoder.yudao.module.trade.framework.delivery.core.convert.Expr */ @Slf4j public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { + private static final String REAL_TIME_QUERY_URL = "https://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx"; + /** * 快递鸟即时查询免费版 RequestType */ private static final String REAL_TIME_FREE_REQ_TYPE = "1002"; + private final RestTemplate restTemplate; private final TradeExpressQueryProperties.KdNiaoConfig config; + // TODO @jason:可以改成 lombok 哈 public KdNiaoExpressQueryProvider(RestTemplate restTemplate, TradeExpressQueryProperties.KdNiaoConfig config) { this.restTemplate = restTemplate; this.config = config; } /** - * 快递鸟即时查询免费版本 参见 快递鸟接口文档 + * 快递鸟即时查询免费版本 + * + * @see 快递鸟接口文档 * @param reqDTO 查询请求参数 */ @Override @@ -56,7 +62,7 @@ public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { kdNiaoReqData.setExpressCompanyCode(reqDTO.getExpressCompanyCode().toUpperCase()); KdNiaoExpressQueryRespDTO respDTO = sendKdNiaoApiRequest(REAL_TIME_QUERY_URL, REAL_TIME_FREE_REQ_TYPE, kdNiaoReqData, KdNiaoExpressQueryRespDTO.class); - log.debug("快递鸟即时查询接口返回 {}", respDTO); + log.debug("[realTimeQueryExpress][快递鸟即时查询接口返回 {}]", respDTO); if(!respDTO.getSuccess()){ throw exception(EXPRESS_API_QUERY_FAILED, respDTO.getReason()); }else{ @@ -85,16 +91,16 @@ public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { // 请求体 String reqData = JsonUtils.toJsonString(req); String dataSign = generateDataSign(reqData, config.getApiKey()); - log.trace("得到快递鸟接口 RequestType : {} 的 签名: {}", requestType, dataSign); MultiValueMap requestBody = new LinkedMultiValueMap<>(); requestBody.add("RequestData", reqData); requestBody.add("DataType", "2"); requestBody.add("EBusinessID", config.getBusinessId()); requestBody.add("DataSign", dataSign); requestBody.add("RequestType", requestType); - log.debug("快递鸟接口 RequestType : {}, 的请求参数 {}", requestType, requestBody); - HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); + log.debug("[sendKdNiaoApiRequest][快递鸟接口 RequestType : {}, 的请求参数 {}]", requestType, requestBody); + // 发送请求 + HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); log.debug("快递鸟接口 RequestType : {}, 的响应结果 {}", requestType, responseEntity); // 处理响应 @@ -113,7 +119,7 @@ public class KdNiaoExpressQueryProvider implements ExpressQueryProvider { */ private String generateDataSign(String reqData, String apiKey) { String plainText = String.format("%s%s", reqData, apiKey); - log.trace("签名前的数据 {}", plainText); return URLEncodeUtil.encode(Base64.encode(DigestUtil.md5Hex(plainText))); } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java index cdde6c683..8f6615678 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java @@ -17,11 +17,12 @@ import javax.annotation.Resource; import static org.junit.jupiter.api.Assertions.assertThrows; +// TODO @芋艿:单测最后 review /** * @author jason */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = KdNiaoExpressQueryProviderTest.Application.class) -@ActiveProfiles("trade-delivery-query") // 设置使用 trade-delivery-query 配置文件 +@ActiveProfiles("trade-delivery-query") // 设置使用 trade-delivery-query 配置文件 TODO @jason:可以直接写到 application-unit-test.yaml 配置文件里 public class KdNiaoExpressQueryProviderTest { @Resource private RestTemplateBuilder builder; @@ -51,4 +52,4 @@ public class KdNiaoExpressQueryProviderTest { @EnableConfigurationProperties(TradeExpressQueryProperties.class) public static class Application { } -} \ No newline at end of file +}