diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/BannerController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/BannerController.java new file mode 100644 index 000000000..714dcbc72 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/BannerController.java @@ -0,0 +1,65 @@ +package cn.iocoder.mall.managementweb.controller.promotion.brand; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerCreateReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerPageReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerRespVO; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerUpdateReqVO; +import cn.iocoder.mall.managementweb.manager.promotion.brand.BannerManager; +import cn.iocoder.security.annotations.RequiresPermissions; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +/** + * Banner Controller + */ +@RestController +@RequestMapping("/promotion/banner") +@Api(tags = "Banner API") +@Validated +public class BannerController { + + @Autowired + private BannerManager bannerManager; + + @PostMapping("/create") + @ApiOperation("创建 Banner") + @RequiresPermissions("promotion:banner:create") + public CommonResult createBanner(@Valid BannerCreateReqVO createVO) { + return success(bannerManager.createBanner(createVO)); + } + + @PostMapping("/update") + @ApiOperation("更新 Banner") + @RequiresPermissions("promotion:banner:update") + public CommonResult updateBanner(@Valid BannerUpdateReqVO updateVO) { + bannerManager.updateBanner(updateVO); + return success(true); + } + + @PostMapping("/delete") + @ApiOperation("删除 Banner") + @ApiImplicitParam(name = "bannerId", value = " Banner 编号", required = true) + @RequiresPermissions("promotion:banner:delete") + public CommonResult deleteBanner(@RequestParam("bannerId") Integer bannerId) { + bannerManager.deleteBanner(bannerId); + return success(true); + } + + @GetMapping("/page") + @ApiOperation("获得 Banner 分页") + @RequiresPermissions("promotion:banner:page") + public CommonResult> pageBanner(BannerPageReqVO pageVO) { + return success(bannerManager.pageBanner(pageVO)); + } + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerCreateReqVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerCreateReqVO.java new file mode 100644 index 000000000..99a4e0c45 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerCreateReqVO.java @@ -0,0 +1,43 @@ +package cn.iocoder.mall.managementweb.controller.promotion.brand.vo; + +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.hibernate.validator.constraints.Length; +import org.hibernate.validator.constraints.URL; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@ApiModel("Banner 创建 Request VO") +@Data +public class BannerCreateReqVO { + + @ApiModelProperty(value = "标题", required = true, example = "活动 A") + @NotEmpty(message = "标题不能为空") + @Length(min = 2, max = 32, message = "标题长度为 2-32 位") + private String title; + @ApiModelProperty(value = "跳转链接", required = true, example = "http://www.baidu.com") + @NotEmpty(message = "跳转链接不能为空") + @URL(message = "跳转链接格式不正确") + @Length(max = 255, message = "跳转链接最大长度为 255 位") + private String url; + @ApiModelProperty(value = "跳转链接", required = true, example = "http://www.iocoder.cn/01.jpg") + @NotEmpty(message = "跳转链接不能为空") + @URL(message = "图片链接格式不正确") + @Length(max = 255, message = "图片链接最大长度为 255 位") + private String picUrl; + @ApiModelProperty(value = "排序", required = true, example = "10") + @NotNull(message = "排序不能为空") + private Integer sort; + @ApiModelProperty(value = "状态", required = true, example = "1") + @NotNull(message = "状态不能为空") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + @ApiModelProperty(value = "备注", example = "这个活动很牛逼") + @Length(max = 255, message = "备注最大长度为 255 位") + private String memo; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerPageReqVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerPageReqVO.java new file mode 100644 index 000000000..ea78dd3e6 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerPageReqVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.mall.managementweb.controller.promotion.brand.vo; + +import cn.iocoder.common.framework.vo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel("Banner 分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +public class BannerPageReqVO extends PageParam { + + @ApiModelProperty(value = "标题", required = true, example = "活动 A") + private String title; + +} diff --git a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsBannerVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerRespVO.java similarity index 85% rename from promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsBannerVO.java rename to management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerRespVO.java index d73900c29..536289705 100644 --- a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsBannerVO.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.promotion.application.vo.admins; +package cn.iocoder.mall.managementweb.controller.promotion.brand.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -10,7 +10,7 @@ import java.util.Date; @ApiModel("Banner VO") @Data @Accessors(chain = true) -public class AdminsBannerVO { +public class BannerRespVO { @ApiModelProperty(value = "Banner 编号", required = true, example = "1") private Integer id; @@ -24,7 +24,7 @@ public class AdminsBannerVO { private Integer sort; @ApiModelProperty(value = "状态", required = true, example = "1") private Integer status; - @ApiModelProperty(value = "备注", required = true, example = "这个活动很牛逼") + @ApiModelProperty(value = "备注", example = "这个活动很牛逼") private String memo; @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") private Date createTime; diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerUpdateBO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerUpdateReqVO.java similarity index 50% rename from promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerUpdateBO.java rename to management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerUpdateReqVO.java index e48d5262b..fa8d3a8c9 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerUpdateBO.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/brand/vo/BannerUpdateReqVO.java @@ -1,36 +1,42 @@ -package cn.iocoder.mall.promotionservice.service.banner.bo; +package cn.iocoder.mall.managementweb.controller.promotion.brand.vo; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.URL; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -import java.io.Serializable; -/** - * Banner 更新 DTO - */ +@ApiModel("Banner 更新 Request VO") @Data -@Accessors(chain = true) -public class BannerUpdateBO implements Serializable { +public class BannerUpdateReqVO { + @ApiModelProperty(value = "Banner 编号", required = true, example = "1") @NotNull(message = "编号不能为空") private Integer id; + @ApiModelProperty(value = "标题", required = true, example = "活动 A") @NotEmpty(message = "标题不能为空") @Length(min = 2, max = 32, message = "标题长度为 2-32 位") private String title; + @ApiModelProperty(value = "跳转链接", required = true, example = "http://www.baidu.com") @NotEmpty(message = "跳转链接不能为空") @URL(message = "跳转链接格式不正确") @Length(max = 255, message = "跳转链接最大长度为 255 位") private String url; - @NotEmpty(message = "图片链接不能为空") + @ApiModelProperty(value = "跳转链接", required = true, example = "http://www.iocoder.cn/01.jpg") + @NotEmpty(message = "跳转链接不能为空") @URL(message = "图片链接格式不正确") @Length(max = 255, message = "图片链接最大长度为 255 位") private String picUrl; + @ApiModelProperty(value = "排序", required = true, example = "10") @NotNull(message = "排序不能为空") private Integer sort; + @ApiModelProperty(value = "状态", required = true, example = "1") + @NotNull(message = "状态不能为空") + private Integer status; + @ApiModelProperty(value = "备注", example = "这个活动很牛逼") @Length(max = 255, message = "备注最大长度为 255 位") private String memo; diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/ProductRecommendController.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/ProductRecommendController.java new file mode 100644 index 000000000..8505ba65d --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/ProductRecommendController.java @@ -0,0 +1,60 @@ +package cn.iocoder.mall.managementweb.controller.promotion.recommend; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendCreateReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendDetailVO; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendPageReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendUpdateReqVO; +import cn.iocoder.mall.managementweb.manager.promotion.recommend.ProductRecommendManager; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +/** + * 商品推荐 Controller + */ +@RestController +@RequestMapping("/promotion/product-recommend") +@Api(tags = "商品推荐") +@Validated +public class ProductRecommendController { + + @Autowired + private ProductRecommendManager productRecommendManager; + + @PostMapping("/create") + @ApiOperation("创建商品推荐") + public CommonResult createProductRecommend(@Valid ProductRecommendCreateReqVO createVO) { + return success(productRecommendManager.createProductRecommend(createVO)); + } + + @PostMapping("/update") + @ApiOperation("更新商品推荐") + public CommonResult updateProductRecommend(@Valid ProductRecommendUpdateReqVO updateVO) { + productRecommendManager.updateProductRecommend(updateVO); + return success(true); + } + + @PostMapping("/delete") + @ApiOperation("删除商品推荐") + @ApiImplicitParam(name = "productRecommendId", value = "商品推荐编号", required = true) + public CommonResult deleteProductRecommend(@RequestParam("productRecommendId") Integer productRecommendId) { + productRecommendManager.deleteProductRecommend(productRecommendId); + return success(true); + } + + @GetMapping("/page") + @ApiOperation("获得商品推荐分页") + public CommonResult> pageProductRecommend(ProductRecommendPageReqVO pageVO) { + return success(productRecommendManager.pageProductRecommend(pageVO)); + } + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendCreateReqVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendCreateReqVO.java new file mode 100644 index 000000000..83ff2d8c2 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendCreateReqVO.java @@ -0,0 +1,33 @@ +package cn.iocoder.mall.managementweb.controller.promotion.recommend.vo; + +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@ApiModel("商品推荐创建 Request VO") +@Data +public class ProductRecommendCreateReqVO { + + @ApiModelProperty(value = "类型", example = "1", required = true, notes = "参见 ProductRecommendTypeEnum 枚举") + @NotNull(message = "类型不能为空") + @InEnum(value = ProductRecommendTypeEnum.class, message = "推荐类型必须是 {value}") + private Integer type; + @ApiModelProperty(value = "商品 Spu 编号", required = true, example = "1") + @NotNull(message = "商品 Spu 编号不能为空") + private Integer productSpuId; + @ApiModelProperty(value = "排序", required = true, example = "1") + @NotNull(message = "排序不能为空") + private Integer sort; + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举") + @NotNull(message = "状态不能为空") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + @ApiModelProperty(value = "备注", example = "我是备注") + private String memo; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendDetailVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendDetailVO.java new file mode 100644 index 000000000..d79ce6609 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendDetailVO.java @@ -0,0 +1,43 @@ +package cn.iocoder.mall.managementweb.controller.promotion.recommend.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; + +@ApiModel("商品推荐明细 VO") +@Data +@Accessors(chain = true) +public class ProductRecommendDetailVO { + + @ApiModelProperty(value = "编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "推荐类型", required = true, example = "1", notes = "参见 ProductRecommendTypeEnum 枚举") + private Integer type; + @ApiModelProperty(value = "商品编号", required = true, example = "1") + private Integer productSpuId; + @ApiModelProperty(value = "排序", required = true, example = "10") + private Integer sort; + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举") + private Integer status; + @ApiModelProperty(value = "备注", required = true, example = "这个活动很牛逼") + private String memo; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") + private Date createTime; + /** + * 商品信息 + */ + private Spu spu; + + @ApiModel("商品信息") + @Data + public static class Spu { + + @ApiModelProperty(value = "SPU 名字", required = true, example = "厮大牛逼") + private String name; + + } + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendPageReqVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendPageReqVO.java new file mode 100644 index 000000000..f6873b847 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendPageReqVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.mall.managementweb.controller.promotion.recommend.vo; + +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.common.framework.vo.PageParam; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel("商品推荐分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +public class ProductRecommendPageReqVO extends PageParam { + + @ApiModelProperty(value = "类型", example = "1", notes = "参见 ProductRecommendTypeEnum 枚举") + @InEnum(value = ProductRecommendTypeEnum.class, message = "推荐类型必须是 {value}") + private Integer type; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendUpdateReqVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendUpdateReqVO.java new file mode 100644 index 000000000..b547afa0a --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/promotion/recommend/vo/ProductRecommendUpdateReqVO.java @@ -0,0 +1,36 @@ +package cn.iocoder.mall.managementweb.controller.promotion.recommend.vo; + +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@ApiModel("商品推荐更新 Request VO") +@Data +public class ProductRecommendUpdateReqVO { + + @ApiModelProperty(value = "编号", required = true, example = "1") + @NotNull(message = "编号不能为空") + private Integer id; + @ApiModelProperty(value = "类型", example = "1", required = true, notes = "参见 ProductRecommendTypeEnum 枚举") + @NotNull(message = "类型不能为空") + @InEnum(value = ProductRecommendTypeEnum.class, message = "推荐类型必须是 {value}") + private Integer type; + @ApiModelProperty(value = "商品 Spu 编号", required = true, example = "1") + @NotNull(message = "商品 Spu 编号不能为空") + private Integer productSpuId; + @ApiModelProperty(value = "排序", required = true, example = "1") + @NotNull(message = "排序不能为空") + private Integer sort; + @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举") + @NotNull(message = "状态不能为空") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + @ApiModelProperty(value = "备注", example = "我是备注") + private String memo; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/BannerConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/BannerConvert.java new file mode 100644 index 000000000..e4e7aa871 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/BannerConvert.java @@ -0,0 +1,28 @@ +package cn.iocoder.mall.managementweb.convert.promotion; + +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerCreateReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerPageReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerRespVO; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerUpdateReqVO; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerCreateReqDTO; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerPageReqDTO; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerRespDTO; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerUpdateReqDTO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface BannerConvert { + + BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class); + + BannerCreateReqDTO convert(BannerCreateReqVO bean); + + BannerUpdateReqDTO convert(BannerUpdateReqVO bean); + + BannerPageReqDTO convert(BannerPageReqVO bean); + + PageResult convertPage(PageResult page); + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/coupon/CouponTemplateConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/CouponTemplateConvert.java similarity index 95% rename from management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/coupon/CouponTemplateConvert.java rename to management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/CouponTemplateConvert.java index b39223ae0..eaed998fe 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/coupon/CouponTemplateConvert.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/CouponTemplateConvert.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.managementweb.convert.promotion.coupon; +package cn.iocoder.mall.managementweb.convert.promotion; import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardCreateReqVO; diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/ProductRecommendConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/ProductRecommendConvert.java new file mode 100644 index 000000000..7044ff0b3 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/ProductRecommendConvert.java @@ -0,0 +1,31 @@ +package cn.iocoder.mall.managementweb.convert.promotion; + +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendCreateReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendDetailVO; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendPageReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendUpdateReqVO; +import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendCreateReqDTO; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendPageReqDTO; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendRespDTO; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendUpdateReqDTO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ProductRecommendConvert { + + ProductRecommendConvert INSTANCE = Mappers.getMapper(ProductRecommendConvert.class); + + ProductRecommendCreateReqDTO convert(ProductRecommendCreateReqVO bean); + + ProductRecommendUpdateReqDTO convert(ProductRecommendUpdateReqVO bean); + + ProductRecommendPageReqDTO convert(ProductRecommendPageReqVO bean); + + PageResult convertPage(PageResult page); + + ProductRecommendDetailVO.Spu convert(ProductSpuRespDTO bean); + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/activity/PromotionActivityConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/PromotionActivityConvert.java similarity index 87% rename from management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/activity/PromotionActivityConvert.java rename to management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/PromotionActivityConvert.java index ca01430d4..708ed4566 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/activity/PromotionActivityConvert.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/promotion/PromotionActivityConvert.java @@ -1,4 +1,4 @@ -package cn.iocoder.mall.managementweb.convert.promotion.activity; +package cn.iocoder.mall.managementweb.convert.promotion; import cn.iocoder.mall.managementweb.controller.promotion.activity.vo.PromotionActivityPageReqVO; import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityPageReqDTO; diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/activity/PromotionActivityManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/activity/PromotionActivityManager.java index 16146381b..91b090455 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/activity/PromotionActivityManager.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/activity/PromotionActivityManager.java @@ -3,7 +3,7 @@ package cn.iocoder.mall.managementweb.manager.promotion.activity; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.managementweb.controller.promotion.activity.vo.PromotionActivityPageReqVO; -import cn.iocoder.mall.managementweb.convert.promotion.activity.PromotionActivityConvert; +import cn.iocoder.mall.managementweb.convert.promotion.PromotionActivityConvert; import cn.iocoder.mall.promotion.api.rpc.activity.PromotionActivityRpc; import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO; import org.apache.dubbo.config.annotation.DubboReference; diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/brand/BannerManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/brand/BannerManager.java new file mode 100644 index 000000000..17ed69daf --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/brand/BannerManager.java @@ -0,0 +1,68 @@ +package cn.iocoder.mall.managementweb.manager.promotion.brand; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerCreateReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerPageReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerRespVO; +import cn.iocoder.mall.managementweb.controller.promotion.brand.vo.BannerUpdateReqVO; +import cn.iocoder.mall.managementweb.convert.promotion.BannerConvert; +import cn.iocoder.mall.promotion.api.rpc.banner.BannerRpc; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerRespDTO; +import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.stereotype.Service; + +/** +* Banner Manager +*/ +@Service +public class BannerManager { + + @DubboReference(version = "${dubbo.consumer.BannerRpc.version}") + private BannerRpc bannerRpc; + + /** + * 创建 Banner + * + * @param createVO 创建 Banner VO + * @return Banner + */ + public Integer createBanner(BannerCreateReqVO createVO) { + CommonResult createBannerResult = bannerRpc.createBanner(BannerConvert.INSTANCE.convert(createVO)); + createBannerResult.checkError(); + return createBannerResult.getData(); + } + + /** + * 更新 Banner + * + * @param updateVO 更新 Banner VO + */ + public void updateBanner(BannerUpdateReqVO updateVO) { + CommonResult updateBannerResult = bannerRpc.updateBanner(BannerConvert.INSTANCE.convert(updateVO)); + updateBannerResult.checkError(); + } + + /** + * 删除 Banner + * + * @param bannerId Banner 编号 + */ + public void deleteBanner(Integer bannerId) { + CommonResult deleteBannerResult = bannerRpc.deleteBanner(bannerId); + deleteBannerResult.checkError(); + } + + /** + * 获得 Banner 分页 + * + * @param pageVO Banner 分页查询 + * @return Banner 分页结果 + */ + public PageResult pageBanner(BannerPageReqVO pageVO) { + CommonResult> pageBannerResult = bannerRpc.pageBanner(BannerConvert.INSTANCE.convert(pageVO)); + pageBannerResult.checkError(); + return BannerConvert.INSTANCE.convertPage(pageBannerResult.getData()); + } + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/coupon/CouponTemplateManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/coupon/CouponTemplateManager.java index 99742ef39..bedc7c4b3 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/coupon/CouponTemplateManager.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/coupon/CouponTemplateManager.java @@ -6,7 +6,7 @@ import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.Cou import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateCardUpdateReqVO; import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplatePageReqVO; import cn.iocoder.mall.managementweb.controller.promotion.coupon.vo.template.CouponTemplateRespVO; -import cn.iocoder.mall.managementweb.convert.promotion.coupon.CouponTemplateConvert; +import cn.iocoder.mall.managementweb.convert.promotion.CouponTemplateConvert; import cn.iocoder.mall.promotion.api.rpc.coupon.CouponTemplateRpc; import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponCardTemplateUpdateStatusReqDTO; import cn.iocoder.mall.promotion.api.rpc.coupon.dto.template.CouponTemplateRespDTO; diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/recommend/ProductRecommendManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/recommend/ProductRecommendManager.java new file mode 100644 index 000000000..0a3c686b6 --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/promotion/recommend/ProductRecommendManager.java @@ -0,0 +1,91 @@ +package cn.iocoder.mall.managementweb.manager.promotion.recommend; + +import cn.iocoder.common.framework.util.CollectionUtils; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendCreateReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendDetailVO; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendPageReqVO; +import cn.iocoder.mall.managementweb.controller.promotion.recommend.vo.ProductRecommendUpdateReqVO; +import cn.iocoder.mall.managementweb.convert.promotion.ProductRecommendConvert; +import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc; +import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO; +import cn.iocoder.mall.promotion.api.rpc.recommend.ProductRecommendRpc; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendRespDTO; +import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.List; +import java.util.Map; + +/** + * 商品推荐 Manager + */ +@Service +@Validated +public class ProductRecommendManager { + + @DubboReference(version = "${dubbo.consumer.ProductRecommendRpc.version}") + private ProductRecommendRpc productRecommendRpc; + @DubboReference(version = "${dubbo.consumer.ProductSpuRpc.version}") + private ProductSpuRpc productSpuRpc; + + /** + * 创建商品推荐 + * + * @param createVO 创建商品推荐 VO + * @return 商品推荐 + */ + public Integer createProductRecommend(ProductRecommendCreateReqVO createVO) { + CommonResult createProductRecommendResult = productRecommendRpc.createProductRecommend( + ProductRecommendConvert.INSTANCE.convert(createVO)); + createProductRecommendResult.checkError(); + return createProductRecommendResult.getData(); + } + + /** + * 更新商品推荐 + * + * @param updateVO 更新商品推荐 VO + */ + public void updateProductRecommend(ProductRecommendUpdateReqVO updateVO) { + CommonResult updateProductRecommendResult = productRecommendRpc.updateProductRecommend( + ProductRecommendConvert.INSTANCE.convert(updateVO)); + updateProductRecommendResult.checkError(); + } + + /** + * 删除商品推荐 + * + * @param productRecommendId 商品推荐编号 + */ + public void deleteProductRecommend(Integer productRecommendId) { + CommonResult deleteProductRecommendResult = productRecommendRpc.deleteProductRecommend(productRecommendId); + deleteProductRecommendResult.checkError(); + } + + /** + * 获得商品推荐分页 + * + * @param pageVO 商品推荐分页查询 + * @return 商品推荐分页结果 + */ + public PageResult pageProductRecommend(ProductRecommendPageReqVO pageVO) { + CommonResult> pageProductRecommendResult = productRecommendRpc.pageProductRecommend(ProductRecommendConvert.INSTANCE.convert(pageVO)); + pageProductRecommendResult.checkError(); + // 拼接结果 + PageResult pageResult = ProductRecommendConvert.INSTANCE.convertPage(pageProductRecommendResult.getData()); + if (!CollectionUtils.isEmpty(pageResult.getList())) { + // 获取商品信息,并进行拼接 + CommonResult> listProductSpusResult = productSpuRpc.listProductSpus( + CollectionUtils.convertSet(pageResult.getList(), ProductRecommendDetailVO::getProductSpuId)); + listProductSpusResult.checkError(); + Map productSpuMap = CollectionUtils.convertMap(listProductSpusResult.getData(), ProductSpuRespDTO::getId); + pageResult.getList().forEach(detailVO -> + detailVO.setSpu(ProductRecommendConvert.INSTANCE.convert(productSpuMap.get(detailVO.getProductSpuId())))); + } + return pageResult; + } + +} diff --git a/management-web-app/src/main/resources/application.yml b/management-web-app/src/main/resources/application.yml index 01402aa28..64c577898 100644 --- a/management-web-app/src/main/resources/application.yml +++ b/management-web-app/src/main/resources/application.yml @@ -61,6 +61,10 @@ dubbo: version: 1.0.0 PromotionActivityRpc: version: 1.0.0 + BannerRpc: + version: 1.0.0 + ProductRecommendRpc: + version: 1.0.0 # Swagger 配置项 swagger: diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/BannerRpc.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/BannerRpc.java index 62521cae1..9d3efab6e 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/BannerRpc.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/BannerRpc.java @@ -1,28 +1,52 @@ package cn.iocoder.mall.promotion.api.rpc.banner; -import cn.iocoder.common.framework.enums.CommonStatusEnum; -import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerRespDTO; -import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerPageRespDTO; -import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerAddReqDTO; -import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerPageDTO; -import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerUpdateReqDTO; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.*; import java.util.List; +/** + * Banner Rpc 接口 + */ public interface BannerRpc { - List getBannerListByStatus(Integer status); + /** + * 创建 Banner + * + * @param createDTO 创建 Banner DTO + * @return Banner 编号 + */ + CommonResult createBanner(BannerCreateReqDTO createDTO); - BannerPageRespDTO getBannerPage(BannerPageDTO bannerPageDTO); + /** + * 更新 Banner + * + * @param updateDTO 更新 Banner DTO + */ + CommonResult updateBanner(BannerUpdateReqDTO updateDTO); - BannerRespDTO addBanner(Integer adminId, BannerAddReqDTO bannerAddDTO); + /** + * 删除 Banner + * + * @param bannerId Banner 编号 + */ + CommonResult deleteBanner(Integer bannerId); - Boolean updateBanner(Integer adminId, BannerUpdateReqDTO bannerUpdateDTO); + /** + * 获得 Banner 列表 + * + * @param listDTO Banner 列表查询 DTO + * @return Banner 列表 + */ + CommonResult> listBanners(BannerListReqDTO listDTO); - Boolean updateBannerStatus(Integer adminId, Integer bannerId, - @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status); - - Boolean deleteBanner(Integer adminId, Integer bannerId); + /** + * 获得 Banner 分页 + * + * @param pageDTO Banner 分页查询 + * @return Banner 分页结果 + */ + CommonResult> pageBanner(BannerPageReqDTO pageDTO); } diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerAddReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerCreateReqDTO.java similarity index 66% rename from promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerAddReqDTO.java rename to promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerCreateReqDTO.java index a243d274e..1713a5075 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerAddReqDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerCreateReqDTO.java @@ -1,5 +1,7 @@ package cn.iocoder.mall.promotion.api.rpc.banner.dto; +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; @@ -10,25 +12,46 @@ import javax.validation.constraints.NotNull; import java.io.Serializable; /** - * Banner 添加 DTO + * Banner 创建 Request DTO */ @Data @Accessors(chain = true) -public class BannerAddReqDTO implements Serializable { +public class BannerCreateReqDTO implements Serializable { + /** + * 标题 + */ @NotEmpty(message = "标题不能为空") @Length(min = 2, max = 32, message = "标题长度为 2-32 位") private String title; + /** + * 跳转链接 + */ @NotEmpty(message = "跳转链接不能为空") @URL(message = "跳转链接格式不正确") @Length(max = 255, message = "跳转链接最大长度为 255 位") private String url; + /** + * 图片链接 + */ @NotEmpty(message = "图片链接不能为空") @URL(message = "图片链接格式不正确") @Length(max = 255, message = "图片链接最大长度为 255 位") private String picUrl; + /** + * 排序 + */ @NotNull(message = "排序不能为空") private Integer sort; + /** + * 状态 + */ + @NotNull(message = "状态不能为空") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + /** + * 备注 + */ @Length(max = 255, message = "备注最大长度为 255 位") private String memo; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerListReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerListReqDTO.java new file mode 100644 index 000000000..c0e54f821 --- /dev/null +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerListReqDTO.java @@ -0,0 +1,26 @@ +package cn.iocoder.mall.promotion.api.rpc.banner.dto; + +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.common.framework.vo.PageParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; + +/** + * Banner 列表 Request DTO + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +public class BannerListReqDTO extends PageParam { + + /** + * 状态 + */ + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + +} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerPageDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerPageDTO.java deleted file mode 100644 index a58a55722..000000000 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerPageDTO.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.mall.promotion.api.rpc.banner.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * Banner 分页 DTO - */ -@Data -@Accessors(chain = true) -public class BannerPageDTO implements Serializable { - - /** - * 标题,模糊匹配 - */ - private String title; - - @NotNull(message = "页码不能为空") - private Integer pageNo; - @NotNull(message = "每页条数不能为空") - private Integer pageSize; - -} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerPageReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerPageReqDTO.java new file mode 100644 index 000000000..c9543556f --- /dev/null +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerPageReqDTO.java @@ -0,0 +1,21 @@ +package cn.iocoder.mall.promotion.api.rpc.banner.dto; + +import cn.iocoder.common.framework.vo.PageParam; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * Banner 分页 Request DTO + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +public class BannerPageReqDTO extends PageParam { + + /** + * 标题,模糊匹配 + */ + private String title; + +} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerPageRespDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerPageRespDTO.java deleted file mode 100644 index 111d19d8e..000000000 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerPageRespDTO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.mall.promotion.api.rpc.banner.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.List; - -/** - * Banner 分页 BO - */ -@Data -@Accessors(chain = true) -public class BannerPageRespDTO implements Serializable { - - /** - * Banner 数组 - */ - private List list; - /** - * 总量 - */ - private Integer total; - -} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerRespDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerRespDTO.java index e0f3058a0..1a204c23b 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerRespDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerRespDTO.java @@ -7,7 +7,7 @@ import java.io.Serializable; import java.util.Date; /** - * Banner BO + * Banner Response DTO */ @Data @Accessors(chain = true) diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerUpdateReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerUpdateReqDTO.java index e7d3f3ec1..2b006a7e7 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerUpdateReqDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/banner/dto/BannerUpdateReqDTO.java @@ -1,5 +1,7 @@ package cn.iocoder.mall.promotion.api.rpc.banner.dto; +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; @@ -10,27 +12,51 @@ import javax.validation.constraints.NotNull; import java.io.Serializable; /** - * Banner 更新 DTO + * Banner 更新 Request DTO */ @Data @Accessors(chain = true) public class BannerUpdateReqDTO implements Serializable { + /** + * 编号 + */ @NotNull(message = "编号不能为空") private Integer id; + /** + * 标题 + */ @NotEmpty(message = "标题不能为空") @Length(min = 2, max = 32, message = "标题长度为 2-32 位") private String title; + /** + * 跳转链接 + */ @NotEmpty(message = "跳转链接不能为空") @URL(message = "跳转链接格式不正确") @Length(max = 255, message = "跳转链接最大长度为 255 位") private String url; + /** + * 图片链接 + */ @NotEmpty(message = "图片链接不能为空") @URL(message = "图片链接格式不正确") @Length(max = 255, message = "图片链接最大长度为 255 位") private String picUrl; + /** + * 排序 + */ @NotNull(message = "排序不能为空") private Integer sort; + /** + * 状态 + */ + @NotNull(message = "状态不能为空") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + /** + * 备注 + */ @Length(max = 255, message = "备注最大长度为 255 位") private String memo; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/ProductRecommendRpc.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/ProductRecommendRpc.java index 982f20c40..7afbbe4d9 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/ProductRecommendRpc.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/ProductRecommendRpc.java @@ -1,24 +1,52 @@ -package cn.iocoder.mall.promotion.api.rpc.recommend.dto; +package cn.iocoder.mall.promotion.api.rpc.recommend; -import cn.iocoder.common.framework.enums.CommonStatusEnum; -import cn.iocoder.common.framework.exception.ServiceException; -import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.*; import java.util.List; +/** + * 商品推荐 Rpc 接口 + */ public interface ProductRecommendRpc { - List getProductRecommendList(Integer type, Integer status); + /** + * 创建商品推荐 + * + * @param createDTO 创建商品推荐 DTO + * @return 商品推荐编号 + */ + CommonResult createProductRecommend(ProductRecommendCreateReqDTO createDTO); - ProductRecommendPageRespDTO getProductRecommendPage(ProductRecommendPageReqDTO productRecommendPageDTO); + /** + * 更新商品推荐 + * + * @param updateDTO 更新商品推荐 DTO + */ + CommonResult updateProductRecommend(ProductRecommendUpdateReqDTO updateDTO); - ProductRecommendRespDTO addProductRecommend(Integer adminId, ProductRecommendAddReqDTO productRecommendAddDTO) throws ServiceException; + /** + * 删除商品推荐 + * + * @param productRecommendId 商品推荐编号 + */ + CommonResult deleteProductRecommend(Integer productRecommendId); - Boolean updateProductRecommend(Integer adminId, ProductRecommendUpdateReqDTO productRecommendUpdateDTO) throws ServiceException; + /** + * 获得商品推荐列表 + * + * @param listReqDTO 商品推荐列表查询 DTO + * @return 商品推荐列表 + */ + CommonResult> listProductRecommends(ProductRecommendListReqDTO listReqDTO); - Boolean updateProductRecommendStatus(Integer adminId, Integer productRecommendId, - @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status) throws ServiceException; - - Boolean deleteProductRecommend(Integer adminId, Integer productRecommendId); + /** + * 获得商品推荐分页 + * + * @param pageDTO 商品推荐分页查询 + * @return 商品推荐分页结果 + */ + CommonResult> pageProductRecommend(ProductRecommendPageReqDTO pageDTO); } diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendAddReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendCreateReqDTO.java similarity index 63% rename from promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendAddReqDTO.java rename to promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendCreateReqDTO.java index 89d03b7a4..44473b03c 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendAddReqDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendCreateReqDTO.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.promotion.api.rpc.recommend.dto; +import cn.iocoder.common.framework.enums.CommonStatusEnum; import cn.iocoder.common.framework.validator.InEnum; import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; import lombok.Data; @@ -10,19 +11,37 @@ import javax.validation.constraints.NotNull; import java.io.Serializable; /** - * 商品推荐添加 DTO + * 商品推荐创建 Request DTO */ @Data @Accessors(chain = true) -public class ProductRecommendAddReqDTO implements Serializable { +public class ProductRecommendCreateReqDTO implements Serializable { + /** + * 推荐类型 + */ @InEnum(value = ProductRecommendTypeEnum.class, message = "修改推荐类型必须是 {value}") @NotNull(message = "推荐类型不能为空") private Integer type; + /** + * 商品编号 + */ @NotNull(message = "商品编号不能为空") private Integer productSpuId; + /** + * 排序 + */ @NotNull(message = "排序不能为空") private Integer sort; + /** + * 状态 + */ + @NotNull(message = "状态不能为空") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + /** + * 备注 + */ @Length(max = 255, message = "备注最大长度为 255 位") private String memo; diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendListReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendListReqDTO.java new file mode 100644 index 000000000..fcd5ba606 --- /dev/null +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendListReqDTO.java @@ -0,0 +1,29 @@ +package cn.iocoder.mall.promotion.api.rpc.recommend.dto; + +import cn.iocoder.common.framework.enums.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 商品推荐列表 Req DTO + */ +@Data +@Accessors(chain = true) +public class ProductRecommendListReqDTO implements Serializable { + + /** + * 类型 + */ + @InEnum(value = ProductRecommendTypeEnum.class, message = "推荐类型必须是 {value}") + private Integer type; + /** + * 状态 + */ + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + +} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendPageReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendPageReqDTO.java index f6e6359c1..dd58085da 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendPageReqDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendPageReqDTO.java @@ -1,26 +1,24 @@ package cn.iocoder.mall.promotion.api.rpc.recommend.dto; +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.common.framework.vo.PageParam; +import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; -import javax.validation.constraints.NotNull; -import java.io.Serializable; - /** - * 商品推荐分页 DTO + * 商品推荐分页 Request DTO */ @Data +@EqualsAndHashCode(callSuper = true) @Accessors(chain = true) -public class ProductRecommendPageReqDTO implements Serializable { +public class ProductRecommendPageReqDTO extends PageParam { /** * 推荐类型 */ + @InEnum(value = ProductRecommendTypeEnum.class, message = "推荐类型必须是 {value}") private Integer type; - @NotNull(message = "页码不能为空") - private Integer pageNo; - @NotNull(message = "每页条数不能为空") - private Integer pageSize; - } diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendPageRespDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendPageRespDTO.java deleted file mode 100644 index 07e512c28..000000000 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendPageRespDTO.java +++ /dev/null @@ -1,25 +0,0 @@ -package cn.iocoder.mall.promotion.api.rpc.recommend.dto; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.List; - -/** - * 商品推荐分页 BO - */ -@Data -@Accessors(chain = true) -public class ProductRecommendPageRespDTO implements Serializable { - - /** - * ProductRecommend 数组 - */ - private List list; - /** - * 总量 - */ - private Integer total; - -} diff --git a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendUpdateReqDTO.java b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendUpdateReqDTO.java index 8f5a1c439..fbc3906ce 100644 --- a/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendUpdateReqDTO.java +++ b/promotion-service-project/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/rpc/recommend/dto/ProductRecommendUpdateReqDTO.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.promotion.api.rpc.recommend.dto; +import cn.iocoder.common.framework.enums.CommonStatusEnum; import cn.iocoder.common.framework.validator.InEnum; import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; import lombok.Data; @@ -10,21 +11,42 @@ import javax.validation.constraints.NotNull; import java.io.Serializable; /** - * 商品推荐更新 DTO + * 商品推荐更新 Request DTO */ @Data @Accessors(chain = true) public class ProductRecommendUpdateReqDTO implements Serializable { + /** + * 编号 + */ @NotNull(message = "编号不能为空") private Integer id; - @NotNull(message = "类型不能为空") + /** + * 推荐类型 + */ @InEnum(value = ProductRecommendTypeEnum.class, message = "修改推荐类型必须是 {value}") + @NotNull(message = "推荐类型不能为空") private Integer type; + /** + * 商品编号 + */ @NotNull(message = "商品编号不能为空") private Integer productSpuId; + /** + * 排序 + */ @NotNull(message = "排序不能为空") private Integer sort; + /** + * 状态 + */ + @NotNull(message = "状态不能为空") + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") + private Integer status; + /** + * 备注 + */ @Length(max = 255, message = "备注最大长度为 255 位") private String memo; diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/banner/BannerConvert.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/banner/BannerConvert.java index 48c89ce45..e57643a2a 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/banner/BannerConvert.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/banner/BannerConvert.java @@ -1,11 +1,13 @@ package cn.iocoder.mall.promotionservice.convert.banner; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerCreateReqDTO; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerRespDTO; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerUpdateReqDTO; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.banner.BannerDO; -import cn.iocoder.mall.promotionservice.service.banner.bo.BannerAddBO; -import cn.iocoder.mall.promotionservice.service.banner.bo.BannerBO; -import cn.iocoder.mall.promotionservice.service.banner.bo.BannerUpdateBO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; -import org.mapstruct.Mappings; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; import java.util.List; @@ -15,16 +17,13 @@ public interface BannerConvert { BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class); - @Mappings({}) - BannerBO convertToBO(BannerDO banner); + BannerDO convert(BannerCreateReqDTO bean); - @Mappings({}) - List convertToBO(List bannerList); + BannerDO convert(BannerUpdateReqDTO bean); - @Mappings({}) - BannerDO convert(BannerAddBO bannerAddDTO); + @Mapping(source = "records", target = "list") + PageResult convertPage(IPage page); - @Mappings({}) - BannerDO convert(BannerUpdateBO bannerUpdateDTO); + List convertList(List list); -} \ No newline at end of file +} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/recommend/ProductRecommendConvert.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/recommend/ProductRecommendConvert.java index 8cacb5188..60cf3f727 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/recommend/ProductRecommendConvert.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/convert/recommend/ProductRecommendConvert.java @@ -1,12 +1,13 @@ package cn.iocoder.mall.promotionservice.convert.recommend; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendCreateReqDTO; import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendRespDTO; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendUpdateReqDTO; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.recommend.ProductRecommendDO; -import cn.iocoder.mall.promotionservice.service.recommend.bo.ProductRecommendAddBO; -import cn.iocoder.mall.promotionservice.service.recommend.bo.ProductRecommendBO; -import cn.iocoder.mall.promotionservice.service.recommend.bo.ProductRecommendUpdateBO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; -import org.mapstruct.Mappings; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; import java.util.List; @@ -16,19 +17,13 @@ public interface ProductRecommendConvert { ProductRecommendConvert INSTANCE = Mappers.getMapper(ProductRecommendConvert.class); - @Mappings({}) - ProductRecommendBO convertToBO(ProductRecommendDO recommend); + List convertList(List list); - @Mappings({}) - List convertToBO(List recommendList); + @Mapping(source = "records", target = "list") + PageResult convertPage(IPage page); - @Mappings({}) - List convertToDTO(List recommendList); + ProductRecommendDO convert(ProductRecommendCreateReqDTO bean); - @Mappings({}) - ProductRecommendDO convert(ProductRecommendAddBO recommendAddDTO); - - @Mappings({}) - ProductRecommendDO convert(ProductRecommendUpdateBO recommendUpdateDTO); + ProductRecommendDO convert(ProductRecommendUpdateReqDTO bean); } diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/banner/BannerDO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/banner/BannerDO.java index ea8836961..58da17412 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/banner/BannerDO.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/banner/BannerDO.java @@ -1,13 +1,17 @@ package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.banner; import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; /** * Banner 广告页 */ +@TableName("banner") @Data +@EqualsAndHashCode(callSuper = true) @Accessors(chain = true) public class BannerDO extends DeletableDO { diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/recommend/ProductRecommendDO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/recommend/ProductRecommendDO.java index ad7a701b0..f801439f8 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/recommend/ProductRecommendDO.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/dataobject/recommend/ProductRecommendDO.java @@ -3,12 +3,14 @@ package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.recommend; import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO; import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.experimental.Accessors; /** * 商品推荐 DO */ +@TableName("product_recommend") @Data @Accessors(chain = true) public class ProductRecommendDO extends DeletableDO { diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/banner/BannerMapper.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/banner/BannerMapper.java index 62e53a2d3..95e1e0465 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/banner/BannerMapper.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/banner/BannerMapper.java @@ -1,26 +1,26 @@ package cn.iocoder.mall.promotionservice.dal.mysql.mapper.banner; +import cn.iocoder.mall.mybatis.core.query.QueryWrapperX; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerListReqDTO; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerPageReqDTO; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.banner.BannerDO; -import org.apache.ibatis.annotations.Param; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.stereotype.Repository; import java.util.List; @Repository -public interface BannerMapper { +public interface BannerMapper extends BaseMapper { - BannerDO selectById(@Param("id") Integer id); + default List selectList(BannerListReqDTO listReqDTO) { + return selectList(new QueryWrapperX().eqIfPresent("status", listReqDTO.getStatus())); + } - List selectListByStatus(@Param("status") Integer status); + default IPage selectPage(BannerPageReqDTO pageReqDTO) { + return selectPage(new Page<>(pageReqDTO.getPageNo(), pageReqDTO.getPageSize()), + new QueryWrapperX().likeIfPresent("title", pageReqDTO.getTitle())); + } - List selectListByTitleLike(@Param("title") String title, - @Param("offset") Integer offset, - @Param("limit") Integer limit); - - Integer selectCountByTitleLike(@Param("title") String title); - - void insert(BannerDO bannerDO); - - int update(BannerDO bannerDO); - -} \ No newline at end of file +} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/recommend/ProductRecommendMapper.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/recommend/ProductRecommendMapper.java index b676c40df..46850b680 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/recommend/ProductRecommendMapper.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/dal/mysql/mapper/recommend/ProductRecommendMapper.java @@ -1,30 +1,33 @@ package cn.iocoder.mall.promotionservice.dal.mysql.mapper.recommend; +import cn.iocoder.mall.mybatis.core.query.QueryWrapperX; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendListReqDTO; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendPageReqDTO; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.recommend.ProductRecommendDO; -import org.apache.ibatis.annotations.Param; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.stereotype.Repository; import java.util.List; @Repository -public interface ProductRecommendMapper { +public interface ProductRecommendMapper extends BaseMapper { - ProductRecommendDO selectById(@Param("id") Integer id); + default ProductRecommendDO selectByProductSpuIdAndType(Integer productSpuId, Integer type) { + return selectOne(new QueryWrapper().eq("product_spu_id", productSpuId) + .eq("type", type)); + } - ProductRecommendDO selectByProductSpuIdAndType(@Param("productSpuId") Integer productSpuId, - @Param("type") Integer type); + default List selectList(ProductRecommendListReqDTO listReqDTO) { + return selectList(new QueryWrapperX().eqIfPresent("type", listReqDTO.getType()) + .eqIfPresent("status", listReqDTO.getStatus())); + } - List selectListByTypeAndStatus(@Param("type") Integer type, - @Param("status") Integer status); + default IPage selectPage(ProductRecommendPageReqDTO pageReqDTO) { + return selectPage(new Page<>(pageReqDTO.getPageNo(), pageReqDTO.getPageSize()), + new QueryWrapperX().eqIfPresent("type", pageReqDTO.getType())); + } - List selectPageByType(@Param("type") Integer type, - @Param("offset") Integer offset, - @Param("limit") Integer limit); - - Integer selectCountByType(@Param("type") Integer type); - - void insert(ProductRecommendDO bannerDO); - - int update(ProductRecommendDO bannerDO); - -} \ No newline at end of file +} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/banner/BannerManager.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/banner/BannerManager.java new file mode 100644 index 000000000..7f9669233 --- /dev/null +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/banner/BannerManager.java @@ -0,0 +1,42 @@ +package cn.iocoder.mall.promotionservice.manager.banner; + +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.*; +import cn.iocoder.mall.promotionservice.service.banner.BannerService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.validation.Valid; +import java.util.List; + +/** + * Banner Manager + */ +@Service +@Valid +public class BannerManager { + + @Autowired + private BannerService bannerService; + + public Integer createBanner(BannerCreateReqDTO createDTO) { + return bannerService.createBanner(createDTO); + } + + public void updateBanner(BannerUpdateReqDTO updateDTO) { + bannerService.updateBanner(updateDTO); + } + + public void deleteBanner(Integer bannerId) { + bannerService.deleteBanner(bannerId); + } + + public List listBanners(BannerListReqDTO listDTO) { + return bannerService.listBanners(listDTO); + } + + public PageResult pageBanner(BannerPageReqDTO pageDTO) { + return bannerService.pageBanner(pageDTO); + } + +} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/recommend/ProductRecommendManager.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/recommend/ProductRecommendManager.java new file mode 100644 index 000000000..9ca04e34b --- /dev/null +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/manager/recommend/ProductRecommendManager.java @@ -0,0 +1,66 @@ +package cn.iocoder.mall.promotionservice.manager.recommend; + +import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc; +import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.*; +import cn.iocoder.mall.promotionservice.service.recommend.ProductRecommendService; +import org.apache.dubbo.config.annotation.DubboReference; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import java.util.List; + +import static cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS; + +/** + * 商品推荐 Manager + */ +@Service +@Validated +public class ProductRecommendManager { + + @DubboReference(validation = "true", version = "${dubbo.consumer.ProductSpuRpc.version}") + private ProductSpuRpc productSpuRpc; + + @Autowired + private ProductRecommendService productRecommendService; + + public List listProductRecommends(ProductRecommendListReqDTO listReqDTO) { + return productRecommendService.listProductRecommends(listReqDTO); + } + + public PageResult pageProductRecommend(ProductRecommendPageReqDTO pageReqDTO) { + return productRecommendService.pageProductRecommend(pageReqDTO); + } + + public Integer createProductRecommend(ProductRecommendCreateReqDTO createReqDTO) { + // 校验商品不存在 + checkProductSpu(createReqDTO.getProductSpuId()); + // 创建商品推荐 + return productRecommendService.createProductRecommend(createReqDTO); + } + + public void updateProductRecommend(ProductRecommendUpdateReqDTO updateReqDTO) { + // 校验商品不存在 + checkProductSpu(updateReqDTO.getProductSpuId()); + // 更新商品推荐 + productRecommendService.updateProductRecommend(updateReqDTO); + } + + public void deleteProductRecommend(Integer productRecommendId) { + productRecommendService.deleteProductRecommend(productRecommendId); + } + + private void checkProductSpu(Integer productSpuId) { + CommonResult getProductSpuResult = productSpuRpc.getProductSpu(productSpuId); + getProductSpuResult.checkError(); + if (getProductSpuResult.getData() == null) { + throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS); + } + } + +} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/rpc/banner/BannerRpcImpl.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/rpc/banner/BannerRpcImpl.java new file mode 100644 index 000000000..50523e60f --- /dev/null +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/rpc/banner/BannerRpcImpl.java @@ -0,0 +1,48 @@ +package cn.iocoder.mall.promotionservice.rpc.banner; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.banner.BannerRpc; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.*; +import cn.iocoder.mall.promotionservice.manager.banner.BannerManager; +import org.apache.dubbo.config.annotation.DubboService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +@DubboService +public class BannerRpcImpl implements BannerRpc { + + @Autowired + private BannerManager bannerManager; + + @Override + public CommonResult createBanner(BannerCreateReqDTO createDTO) { + return success(bannerManager.createBanner(createDTO)); + } + + @Override + public CommonResult updateBanner(BannerUpdateReqDTO updateDTO) { + bannerManager.updateBanner(updateDTO); + return success(true); + } + + @Override + public CommonResult deleteBanner(Integer bannerId) { + bannerManager.deleteBanner(bannerId); + return success(true); + } + + @Override + public CommonResult> listBanners(BannerListReqDTO listDTO) { + return success(bannerManager.listBanners(listDTO)); + } + + @Override + public CommonResult> pageBanner(BannerPageReqDTO pageDTO) { + return success(bannerManager.pageBanner(pageDTO)); + } + +} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/rpc/recommend/ProductRecommendRpcImpl.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/rpc/recommend/ProductRecommendRpcImpl.java new file mode 100644 index 000000000..140f20b34 --- /dev/null +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/rpc/recommend/ProductRecommendRpcImpl.java @@ -0,0 +1,48 @@ +package cn.iocoder.mall.promotionservice.rpc.recommend; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.recommend.ProductRecommendRpc; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.*; +import cn.iocoder.mall.promotionservice.manager.recommend.ProductRecommendManager; +import org.apache.dubbo.config.annotation.DubboService; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + +@DubboService +public class ProductRecommendRpcImpl implements ProductRecommendRpc { + + @Autowired + private ProductRecommendManager productRecommendManager; + + @Override + public CommonResult createProductRecommend(ProductRecommendCreateReqDTO createDTO) { + return success(productRecommendManager.createProductRecommend(createDTO)); + } + + @Override + public CommonResult updateProductRecommend(ProductRecommendUpdateReqDTO updateDTO) { + productRecommendManager.updateProductRecommend(updateDTO); + return success(true); + } + + @Override + public CommonResult deleteProductRecommend(Integer productRecommendId) { + productRecommendManager.deleteProductRecommend(productRecommendId); + return success(true); + } + + @Override + public CommonResult> listProductRecommends(ProductRecommendListReqDTO listReqDTO) { + return success(productRecommendManager.listProductRecommends(listReqDTO)); + } + + @Override + public CommonResult> pageProductRecommend(ProductRecommendPageReqDTO pageDTO) { + return success(productRecommendManager.pageProductRecommend(pageDTO)); + } + +} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/BannerService.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/BannerService.java index 74934dc38..cec3bac3d 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/BannerService.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/BannerService.java @@ -1,22 +1,20 @@ package cn.iocoder.mall.promotionservice.service.banner; -import cn.iocoder.common.framework.enums.CommonStatusEnum; import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil; -import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum; -import cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants; -import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerPageDTO; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.banner.dto.*; import cn.iocoder.mall.promotionservice.convert.banner.BannerConvert; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.banner.BannerDO; import cn.iocoder.mall.promotionservice.dal.mysql.mapper.banner.BannerMapper; -import cn.iocoder.mall.promotionservice.service.banner.bo.BannerAddBO; -import cn.iocoder.mall.promotionservice.service.banner.bo.BannerBO; -import cn.iocoder.mall.promotionservice.service.banner.bo.BannerPageBO; -import cn.iocoder.mall.promotionservice.service.banner.bo.BannerUpdateBO; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import java.util.*; +import javax.validation.Valid; +import java.util.List; + +import static cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants.BANNER_NOT_EXISTS; @Service @@ -26,66 +24,69 @@ public class BannerService { @Autowired private BannerMapper bannerMapper; - public List getBannerListByStatus(Integer status) { - List banners = bannerMapper.selectListByStatus(status); - return BannerConvert.INSTANCE.convertToBO(banners); + /** + * 获得 Banner 列表 + * + * @param listReqDTO Banner 列表查询 + * @return Banner 列表 + */ + public List listBanners(BannerListReqDTO listReqDTO) { + List banners = bannerMapper.selectList(listReqDTO); + return BannerConvert.INSTANCE.convertList(banners); } - public BannerPageBO getBannerPage(BannerPageDTO bannerPageDTO) { - BannerPageBO bannerPageBO = new BannerPageBO(); - // 查询分页数据 - int offset = (bannerPageDTO.getPageNo() - 1) * bannerPageDTO.getPageSize(); - bannerPageBO.setList(BannerConvert.INSTANCE.convertToBO(bannerMapper.selectListByTitleLike(bannerPageDTO.getTitle(), - offset, bannerPageDTO.getPageSize()))); - // 查询分页总数 - bannerPageBO.setTotal(bannerMapper.selectCountByTitleLike(bannerPageDTO.getTitle())); - return bannerPageBO; + /** + * 获得 Banner 分页 + * + * @param bannerPageDTO Banner 分页查询 + * @return Banner 分页结果 + */ + public PageResult pageBanner(BannerPageReqDTO bannerPageDTO) { + IPage bannerPage = bannerMapper.selectPage(bannerPageDTO); + return BannerConvert.INSTANCE.convertPage(bannerPage); } - public BannerBO addBanner(Integer adminId, BannerAddBO bannerAddDTO) { - // 保存到数据库 - BannerDO banner = BannerConvert.INSTANCE.convert(bannerAddDTO).setStatus(CommonStatusEnum.ENABLE.getValue()); - banner.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()).setCreateTime(new Date()); - bannerMapper.insert(banner); - // 返回成功 - return BannerConvert.INSTANCE.convertToBO(banner); + /** + * 创建 Banner + * + * @param createReqDTO 创建 Banner 信息 + * @return banner + */ + public Integer createBanner(@Valid BannerCreateReqDTO createReqDTO) { + // 插入到数据库 + BannerDO bannerDO = BannerConvert.INSTANCE.convert(createReqDTO); + bannerMapper.insert(bannerDO); + // 返回 + return bannerDO.getId(); } - public Boolean updateBanner(Integer adminId, BannerUpdateBO bannerUpdateDTO) { - // 校验 Banner 存在 - if (bannerMapper.selectById(bannerUpdateDTO.getId()) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.BANNER_NOT_EXISTS.getCode()); + /** + * 更新 Banner + * + * @param updateReqDTO 更新 Banner 信息 + */ + public void updateBanner(@Valid BannerUpdateReqDTO updateReqDTO) { + // 校验更新的 Banner 是否存在 + if (bannerMapper.selectById(updateReqDTO.getId()) == null) { + throw ServiceExceptionUtil.exception(BANNER_NOT_EXISTS); } // 更新到数据库 - BannerDO updateBanner = BannerConvert.INSTANCE.convert(bannerUpdateDTO); - bannerMapper.update(updateBanner); - // 返回成功 - return true; + BannerDO updateObject = BannerConvert.INSTANCE.convert(updateReqDTO); + bannerMapper.updateById(updateObject); } - public Boolean updateBannerStatus(Integer adminId, Integer bannerId, Integer status) { + /** + * 删除 Banner + * + * @param bannerId Banner 编号 + */ + public void deleteBanner(Integer bannerId) { // 校验 Banner 存在 if (bannerMapper.selectById(bannerId) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.BANNER_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(BANNER_NOT_EXISTS); } // 更新到数据库 - BannerDO updateBanner = new BannerDO().setId(bannerId).setStatus(status); - bannerMapper.update(updateBanner); - // 返回成功 - return true; - } - - public Boolean deleteBanner(Integer adminId, Integer bannerId) { - // 校验 Banner 存在 - if (bannerMapper.selectById(bannerId) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.BANNER_NOT_EXISTS.getCode()); - } - // 更新到数据库 - BannerDO updateBanner = new BannerDO().setId(bannerId); - updateBanner.setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); - bannerMapper.update(updateBanner); - // 返回成功 - return true; + bannerMapper.deleteById(bannerId); } } diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerAddBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerAddBO.java deleted file mode 100644 index c796ee88a..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerAddBO.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.mall.promotionservice.service.banner.bo; - -import lombok.Data; -import lombok.experimental.Accessors; -import org.hibernate.validator.constraints.Length; -import org.hibernate.validator.constraints.URL; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * Banner 添加 DTO - */ -@Data -@Accessors(chain = true) -public class BannerAddBO implements Serializable { - - @NotEmpty(message = "标题不能为空") - @Length(min = 2, max = 32, message = "标题长度为 2-32 位") - private String title; - @NotEmpty(message = "跳转链接不能为空") - @URL(message = "跳转链接格式不正确") - @Length(max = 255, message = "跳转链接最大长度为 255 位") - private String url; - @NotEmpty(message = "图片链接不能为空") - @URL(message = "图片链接格式不正确") - @Length(max = 255, message = "图片链接最大长度为 255 位") - private String picUrl; - @NotNull(message = "排序不能为空") - private Integer sort; - @Length(max = 255, message = "备注最大长度为 255 位") - private String memo; - -} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerBO.java deleted file mode 100644 index 68ae2062b..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerBO.java +++ /dev/null @@ -1,49 +0,0 @@ -package cn.iocoder.mall.promotionservice.service.banner.bo; - -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.Date; - -/** - * Banner BO - */ -@Data -@Accessors(chain = true) -public class BannerBO implements Serializable { - - /** - * 编号 - */ - private Integer id; - /** - * 标题 - */ - private String title; - /** - * 跳转链接 - */ - private String url; - /** - * 图片链接 - */ - private String picUrl; - /** - * 排序 - */ - private Integer sort; - /** - * 状态 - */ - private Integer status; - /** - * 备注 - */ - private String memo; - /** - * 创建时间 - */ - private Date createTime; - -} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerPageBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerPageBO.java deleted file mode 100644 index 7db1b479b..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/banner/bo/BannerPageBO.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.mall.promotionservice.service.banner.bo; - -import cn.iocoder.mall.promotion.api.rpc.banner.dto.BannerRespDTO; -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; -import java.io.Serializable; -import java.util.List; - -/** - * Banner 分页 DTO - */ -@Data -@Accessors(chain = true) -public class BannerPageBO implements Serializable { - - /** - * Banner 数组 - */ - private List list; - /** - * 总量 - */ - private Integer total; -} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/ProductRecommendService.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/ProductRecommendService.java index 42f49ad93..defeda9e9 100644 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/ProductRecommendService.java +++ b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/ProductRecommendService.java @@ -1,113 +1,93 @@ package cn.iocoder.mall.promotionservice.service.recommend; -import cn.iocoder.common.framework.enums.CommonStatusEnum; import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil; -import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum; -import cn.iocoder.mall.productservice.rpc.spu.ProductSpuRpc; -import cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants; -import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendPageReqDTO; -import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendPageRespDTO; +import cn.iocoder.common.framework.vo.PageResult; +import cn.iocoder.mall.promotion.api.rpc.recommend.dto.*; import cn.iocoder.mall.promotionservice.convert.recommend.ProductRecommendConvert; import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.recommend.ProductRecommendDO; import cn.iocoder.mall.promotionservice.dal.mysql.mapper.recommend.ProductRecommendMapper; -import cn.iocoder.mall.promotionservice.service.recommend.bo.ProductRecommendAddBO; -import cn.iocoder.mall.promotionservice.service.recommend.bo.ProductRecommendBO; -import cn.iocoder.mall.promotionservice.service.recommend.bo.ProductRecommendUpdateBO; -import org.apache.dubbo.config.annotation.DubboReference; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import java.util.Date; import java.util.List; +import static cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants.PRODUCT_RECOMMEND_EXISTS; +import static cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants.PRODUCT_RECOMMEND_NOT_EXISTS; + +/** + * 商品推荐 Service + */ @Service @Validated public class ProductRecommendService { - @DubboReference(validation = "true", version = "${dubbo.consumer.ProductSpuRpc.version}") - private ProductSpuRpc productSpuRpc; - @Autowired private ProductRecommendMapper productRecommendMapper; - public List getProductRecommendList(Integer type, Integer status) { - List productRecommends = productRecommendMapper.selectListByTypeAndStatus(type, status); - return ProductRecommendConvert.INSTANCE.convertToBO(productRecommends); + /** + * 获得商品推荐列表 + * + * @param listReqDTO 列表查询 DTO + * @return 商品推荐列表 + */ + public List listProductRecommends(ProductRecommendListReqDTO listReqDTO) { + List productRecommends = productRecommendMapper.selectList(listReqDTO); + return ProductRecommendConvert.INSTANCE.convertList(productRecommends); } - public ProductRecommendPageRespDTO getProductRecommendPage(ProductRecommendPageReqDTO productRecommendPageDTO) { - ProductRecommendPageRespDTO productRecommendPageBO = new ProductRecommendPageRespDTO(); - // 查询分页数据 - int offset = (productRecommendPageDTO.getPageNo() - 1) * productRecommendPageDTO.getPageSize(); - productRecommendPageBO.setList(ProductRecommendConvert.INSTANCE.convertToDTO(productRecommendMapper.selectPageByType(productRecommendPageDTO.getType(), - offset, productRecommendPageDTO.getPageSize()))); - // 查询分页总数 - productRecommendPageBO.setTotal(productRecommendMapper.selectCountByType(productRecommendPageDTO.getType())); - return productRecommendPageBO; + /** + * 获得商品推荐分页 + * + * @param pageReqDTO 分页查询 DTO + * @return 商品推荐分页 + */ + public PageResult pageProductRecommend(ProductRecommendPageReqDTO pageReqDTO) { + IPage productRecommendPage = productRecommendMapper.selectPage(pageReqDTO); + return ProductRecommendConvert.INSTANCE.convertPage(productRecommendPage); } - public ProductRecommendBO addProductRecommend(Integer adminId, ProductRecommendAddBO productRecommendAddDTO) { - // 校验商品不存在 - if (productSpuRpc.getProductSpu(productRecommendAddDTO.getProductSpuId()) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode()); - } + /** + * 创建商品推荐 + * + * @param createReqDTO 商品推荐信息 + * @return 商品推荐编号 + */ + public Integer createProductRecommend(ProductRecommendCreateReqDTO createReqDTO) { // 校验商品是否已经推荐 - if (productRecommendMapper.selectByProductSpuIdAndType(productRecommendAddDTO.getProductSpuId(), productRecommendAddDTO.getType()) != null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.PRODUCT_RECOMMEND_EXISTS.getCode()); + if (productRecommendMapper.selectByProductSpuIdAndType(createReqDTO.getProductSpuId(), createReqDTO.getType()) != null) { + throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_EXISTS); } // 保存到数据库 - ProductRecommendDO productRecommend = ProductRecommendConvert.INSTANCE.convert(productRecommendAddDTO).setStatus(CommonStatusEnum.ENABLE.getValue()); - productRecommend.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()).setCreateTime(new Date()); + ProductRecommendDO productRecommend = ProductRecommendConvert.INSTANCE.convert(createReqDTO); productRecommendMapper.insert(productRecommend); // 返回成功 - return ProductRecommendConvert.INSTANCE.convertToBO(productRecommend); + return productRecommend.getId(); } - public Boolean updateProductRecommend(Integer adminId, ProductRecommendUpdateBO productRecommendUpdateDTO) { + public void updateProductRecommend(ProductRecommendUpdateReqDTO updateReqDTO) { // 校验更新的商品推荐存在 - if (productRecommendMapper.selectById(productRecommendUpdateDTO.getId()) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); - } - // 校验商品不存在 - if (productSpuRpc.getProductSpu(productRecommendUpdateDTO.getProductSpuId()) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode()); + if (productRecommendMapper.selectById(updateReqDTO.getId()) == null) { + throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_NOT_EXISTS); } // 校验商品是否已经推荐 - ProductRecommendDO existProductRecommend = productRecommendMapper.selectByProductSpuIdAndType(productRecommendUpdateDTO.getProductSpuId(), productRecommendUpdateDTO.getType()); - if (existProductRecommend != null && !existProductRecommend.getId().equals(productRecommendUpdateDTO.getId())) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.PRODUCT_RECOMMEND_EXISTS.getCode()); + ProductRecommendDO existProductRecommend = productRecommendMapper.selectByProductSpuIdAndType(updateReqDTO.getProductSpuId(), updateReqDTO.getType()); + if (existProductRecommend != null && !existProductRecommend.getId().equals(updateReqDTO.getId())) { + throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_EXISTS.getCode()); } // 更新到数据库 - ProductRecommendDO updateProductRecommend = ProductRecommendConvert.INSTANCE.convert(productRecommendUpdateDTO); - productRecommendMapper.update(updateProductRecommend); - // 返回成功 - return true; + ProductRecommendDO updateProductRecommend = ProductRecommendConvert.INSTANCE.convert(updateReqDTO); + productRecommendMapper.updateById(updateProductRecommend); } - public Boolean updateProductRecommendStatus(Integer adminId, Integer productRecommendId, Integer status) { + public void deleteProductRecommend(Integer productRecommendId) { // 校验更新的商品推荐存在 if (productRecommendMapper.selectById(productRecommendId) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_NOT_EXISTS); } // 更新到数据库 - ProductRecommendDO updateProductRecommend = new ProductRecommendDO().setId(productRecommendId).setStatus(status); - productRecommendMapper.update(updateProductRecommend); - // 返回成功 - return true; - } - - public Boolean deleteProductRecommend(Integer adminId, Integer productRecommendId) { - // 校验更新的商品推荐存在 - if (productRecommendMapper.selectById(productRecommendId) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeConstants.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); - } - // 更新到数据库 - ProductRecommendDO updateProductRecommend = new ProductRecommendDO().setId(productRecommendId); - updateProductRecommend.setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); - productRecommendMapper.update(updateProductRecommend); - // 返回成功 - return true; + productRecommendMapper.deleteById(productRecommendId); } } diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendAddBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendAddBO.java deleted file mode 100644 index 011e965fa..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendAddBO.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.mall.promotionservice.service.recommend.bo; - -import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; -import lombok.Data; -import lombok.experimental.Accessors; -import org.hibernate.validator.constraints.Length; - -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * 商品推荐添加 DTO - */ -@Data -@Accessors(chain = true) -public class ProductRecommendAddBO implements Serializable { - - @InEnum(value = ProductRecommendTypeEnum.class, message = "修改推荐类型必须是 {value}") - @NotNull(message = "推荐类型不能为空") - private Integer type; - @NotNull(message = "商品编号不能为空") - private Integer productSpuId; - @NotNull(message = "排序不能为空") - private Integer sort; - @Length(max = 255, message = "备注最大长度为 255 位") - private String memo; - -} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendBO.java deleted file mode 100644 index 99b67ae6d..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendBO.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.mall.promotionservice.service.recommend.bo; - -import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.io.Serializable; -import java.util.Date; - -/** - * 商品推荐 BO - */ -@Data -@Accessors(chain = true) -public class ProductRecommendBO implements Serializable { - - /** - * 编号 - */ - private Integer id; - /** - * 类型 - * - * {@link ProductRecommendTypeEnum} - */ - private Integer type; - /** - * 商品 Spu 编号 - */ - private Integer productSpuId; - /** - * 排序 - */ - private Integer sort; - /** - * 状态 - * - * {@link cn.iocoder.common.framework.enums.CommonStatusEnum} - */ - private Integer status; - /** - * 备注 - */ - private String memo; - /** - * 创建时间 - */ - private Date createTime; - -} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendPageBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendPageBO.java deleted file mode 100644 index 93b98db7f..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendPageBO.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.mall.promotionservice.service.recommend.bo; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * 商品推荐分页 DTO - */ -@Data -@Accessors(chain = true) -public class ProductRecommendPageBO implements Serializable { - - /** - * 推荐类型 - */ - private Integer type; - - @NotNull(message = "页码不能为空") - private Integer pageNo; - @NotNull(message = "每页条数不能为空") - private Integer pageSize; - -} diff --git a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendUpdateBO.java b/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendUpdateBO.java deleted file mode 100644 index 572a6daba..000000000 --- a/promotion-service-project/promotion-service-app/src/main/java/cn/iocoder/mall/promotionservice/service/recommend/bo/ProductRecommendUpdateBO.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.mall.promotionservice.service.recommend.bo; - -import cn.iocoder.common.framework.validator.InEnum; -import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum; -import lombok.Data; -import lombok.experimental.Accessors; -import org.hibernate.validator.constraints.Length; - -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -/** - * 商品推荐更新 DTO - */ -@Data -@Accessors(chain = true) -public class ProductRecommendUpdateBO implements Serializable { - - @NotNull(message = "编号不能为空") - private Integer id; - @NotNull(message = "类型不能为空") - @InEnum(value = ProductRecommendTypeEnum.class, message = "修改推荐类型必须是 {value}") - private Integer type; - @NotNull(message = "商品编号不能为空") - private Integer productSpuId; - @NotNull(message = "排序不能为空") - private Integer sort; - @Length(max = 255, message = "备注最大长度为 255 位") - private String memo; - -} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/BannerConvert.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/BannerConvert.java deleted file mode 100644 index 39d7888b2..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/BannerConvert.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.mall.promotion.biz.convert; - -import cn.iocoder.mall.promotion.api.bo.BannerBO; -import cn.iocoder.mall.promotion.api.dto.BannerAddDTO; -import cn.iocoder.mall.promotion.api.dto.BannerUpdateDTO; -import cn.iocoder.mall.promotion.biz.dataobject.BannerDO; -import org.mapstruct.Mapper; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface BannerConvert { - - BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class); - - @Mappings({}) - BannerBO convertToBO(BannerDO banner); - - @Mappings({}) - List convertToBO(List bannerList); - - @Mappings({}) - BannerDO convert(BannerAddDTO bannerAddDTO); - - @Mappings({}) - BannerDO convert(BannerUpdateDTO bannerUpdateDTO); - -} \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/ProductRecommendConvert.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/ProductRecommendConvert.java deleted file mode 100644 index e48e85a66..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/ProductRecommendConvert.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.mall.promotion.biz.convert; - -import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO; -import cn.iocoder.mall.promotion.api.dto.ProductRecommendAddDTO; -import cn.iocoder.mall.promotion.api.dto.ProductRecommendUpdateDTO; -import cn.iocoder.mall.promotion.biz.dataobject.ProductRecommendDO; -import org.mapstruct.Mapper; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface ProductRecommendConvert { - - ProductRecommendConvert INSTANCE = Mappers.getMapper(ProductRecommendConvert.class); - - @Mappings({}) - ProductRecommendBO convertToBO(ProductRecommendDO recommend); - - @Mappings({}) - List convertToBO(List recommendList); - - @Mappings({}) - ProductRecommendDO convert(ProductRecommendAddDTO recommendAddDTO); - - @Mappings({}) - ProductRecommendDO convert(ProductRecommendUpdateDTO recommendUpdateDTO); - -} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/BannerMapper.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/BannerMapper.java deleted file mode 100644 index fa4a513a0..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/BannerMapper.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.mall.promotion.biz.dao; - -import cn.iocoder.mall.promotion.biz.dataobject.BannerDO; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface BannerMapper { - - BannerDO selectById(@Param("id") Integer id); - - List selectListByStatus(@Param("status") Integer status); - - List selectListByTitleLike(@Param("title") String title, - @Param("offset") Integer offset, - @Param("limit") Integer limit); - - Integer selectCountByTitleLike(@Param("title") String title); - - void insert(BannerDO bannerDO); - - int update(BannerDO bannerDO); - -} \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/ProductRecommendMapper.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/ProductRecommendMapper.java deleted file mode 100644 index f8a66228c..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/ProductRecommendMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.mall.promotion.biz.dao; - -import cn.iocoder.mall.promotion.biz.dataobject.ProductRecommendDO; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface ProductRecommendMapper { - - ProductRecommendDO selectById(@Param("id") Integer id); - - ProductRecommendDO selectByProductSpuIdAndType(@Param("productSpuId") Integer productSpuId, - @Param("type") Integer type); - - List selectListByTypeAndStatus(@Param("type") Integer type, - @Param("status") Integer status); - - List selectPageByType(@Param("type") Integer type, - @Param("offset") Integer offset, - @Param("limit") Integer limit); - - Integer selectCountByType(@Param("type") Integer type); - - void insert(ProductRecommendDO bannerDO); - - int update(ProductRecommendDO bannerDO); - -} \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/BannerServiceImpl.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/BannerServiceImpl.java deleted file mode 100644 index 3092d7e67..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/BannerServiceImpl.java +++ /dev/null @@ -1,97 +0,0 @@ -package cn.iocoder.mall.promotion.biz.service; - -import cn.iocoder.common.framework.enums.CommonStatusEnum; -import cn.iocoder.common.framework.util.ServiceExceptionUtil; -import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum; -import cn.iocoder.mall.promotion.api.BannerService; -import cn.iocoder.mall.promotion.api.bo.BannerBO; -import cn.iocoder.mall.promotion.api.bo.BannerPageBO; -import cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeEnum; -import cn.iocoder.mall.promotion.api.dto.BannerAddDTO; -import cn.iocoder.mall.promotion.api.dto.BannerPageDTO; -import cn.iocoder.mall.promotion.api.dto.BannerUpdateDTO; -import cn.iocoder.mall.promotion.biz.convert.BannerConvert; -import cn.iocoder.mall.promotion.biz.dao.BannerMapper; -import cn.iocoder.mall.promotion.biz.dataobject.BannerDO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Date; -import java.util.List; - -@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示 -@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.BannerService.version}") -public class BannerServiceImpl implements BannerService { - - @Autowired - private BannerMapper bannerMapper; - - @Override - public List getBannerListByStatus(Integer status) { - List banners = bannerMapper.selectListByStatus(status); - return BannerConvert.INSTANCE.convertToBO(banners); - } - - @Override - public BannerPageBO getBannerPage(BannerPageDTO bannerPageDTO) { - BannerPageBO bannerPageBO = new BannerPageBO(); - // 查询分页数据 - int offset = (bannerPageDTO.getPageNo() - 1) * bannerPageDTO.getPageSize(); - bannerPageBO.setList(BannerConvert.INSTANCE.convertToBO(bannerMapper.selectListByTitleLike(bannerPageDTO.getTitle(), - offset, bannerPageDTO.getPageSize()))); - // 查询分页总数 - bannerPageBO.setTotal(bannerMapper.selectCountByTitleLike(bannerPageDTO.getTitle())); - return bannerPageBO; - } - - @Override - public BannerBO addBanner(Integer adminId, BannerAddDTO bannerAddDTO) { - // 保存到数据库 - BannerDO banner = BannerConvert.INSTANCE.convert(bannerAddDTO).setStatus(CommonStatusEnum.ENABLE.getValue()); - banner.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()).setCreateTime(new Date()); - bannerMapper.insert(banner); - // 返回成功 - return BannerConvert.INSTANCE.convertToBO(banner); - } - - @Override - public Boolean updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO) { - // 校验 Banner 存在 - if (bannerMapper.selectById(bannerUpdateDTO.getId()) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode()); - } - // 更新到数据库 - BannerDO updateBanner = BannerConvert.INSTANCE.convert(bannerUpdateDTO); - bannerMapper.update(updateBanner); - // 返回成功 - return true; - } - - @Override - public Boolean updateBannerStatus(Integer adminId, Integer bannerId, Integer status) { - // 校验 Banner 存在 - if (bannerMapper.selectById(bannerId) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode()); - } - // 更新到数据库 - BannerDO updateBanner = new BannerDO().setId(bannerId).setStatus(status); - bannerMapper.update(updateBanner); - // 返回成功 - return true; - } - - @Override - public Boolean deleteBanner(Integer adminId, Integer bannerId) { - // 校验 Banner 存在 - if (bannerMapper.selectById(bannerId) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode()); - } - // 更新到数据库 - BannerDO updateBanner = new BannerDO().setId(bannerId); - updateBanner.setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); - bannerMapper.update(updateBanner); - // 返回成功 - return true; - } - -} diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/ProductRecommendServiceImpl.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/ProductRecommendServiceImpl.java deleted file mode 100644 index d79592218..000000000 --- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/ProductRecommendServiceImpl.java +++ /dev/null @@ -1,119 +0,0 @@ -package cn.iocoder.mall.promotion.biz.service; - -import cn.iocoder.common.framework.enums.CommonStatusEnum; -import cn.iocoder.common.framework.util.ServiceExceptionUtil; -import cn.iocoder.mall.mybatis.core.enums.DeletedStatusEnum; -import cn.iocoder.mall.product.rpc.api.ProductSpuRpc; -import cn.iocoder.mall.promotion.api.ProductRecommendService; -import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO; -import cn.iocoder.mall.promotion.api.bo.ProductRecommendPageBO; -import cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeEnum; -import cn.iocoder.mall.promotion.api.dto.ProductRecommendAddDTO; -import cn.iocoder.mall.promotion.api.dto.ProductRecommendPageDTO; -import cn.iocoder.mall.promotion.api.dto.ProductRecommendUpdateDTO; -import cn.iocoder.mall.promotion.biz.convert.ProductRecommendConvert; -import cn.iocoder.mall.promotion.biz.dao.ProductRecommendMapper; -import cn.iocoder.mall.promotion.biz.dataobject.ProductRecommendDO; -import org.apache.dubbo.config.annotation.Reference; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Date; -import java.util.List; - -@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示 -@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.ProductRecommendService.version}") -public class ProductRecommendServiceImpl implements ProductRecommendService { - - @Reference(validation = "true", version = "${dubbo.consumer.ProductSpuService.version}") - private ProductSpuRpc productSpuRpc; - - @Autowired - private ProductRecommendMapper productRecommendMapper; - - @Override - public List getProductRecommendList(Integer type, Integer status) { - List productRecommends = productRecommendMapper.selectListByTypeAndStatus(type, status); - return ProductRecommendConvert.INSTANCE.convertToBO(productRecommends); - } - - @Override - public ProductRecommendPageBO getProductRecommendPage(ProductRecommendPageDTO productRecommendPageDTO) { - ProductRecommendPageBO productRecommendPageBO = new ProductRecommendPageBO(); - // 查询分页数据 - int offset = (productRecommendPageDTO.getPageNo() - 1) * productRecommendPageDTO.getPageSize(); - productRecommendPageBO.setList(ProductRecommendConvert.INSTANCE.convertToBO(productRecommendMapper.selectPageByType(productRecommendPageDTO.getType(), - offset, productRecommendPageDTO.getPageSize()))); - // 查询分页总数 - productRecommendPageBO.setTotal(productRecommendMapper.selectCountByType(productRecommendPageDTO.getType())); - return productRecommendPageBO; - } - - @Override - public ProductRecommendBO addProductRecommend(Integer adminId, ProductRecommendAddDTO productRecommendAddDTO) { - // 校验商品不存在 - if (productSpuRpc.getProductSpuDetail(productRecommendAddDTO.getProductSpuId()) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode()); - } - // 校验商品是否已经推荐 - if (productRecommendMapper.selectByProductSpuIdAndType(productRecommendAddDTO.getProductSpuId(), productRecommendAddDTO.getType()) != null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_EXISTS.getCode()); - } - // 保存到数据库 - ProductRecommendDO productRecommend = ProductRecommendConvert.INSTANCE.convert(productRecommendAddDTO).setStatus(CommonStatusEnum.ENABLE.getValue()); - productRecommend.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()).setCreateTime(new Date()); - productRecommendMapper.insert(productRecommend); - // 返回成功 - return ProductRecommendConvert.INSTANCE.convertToBO(productRecommend); - } - - @Override - public Boolean updateProductRecommend(Integer adminId, ProductRecommendUpdateDTO productRecommendUpdateDTO) { - // 校验更新的商品推荐存在 - if (productRecommendMapper.selectById(productRecommendUpdateDTO.getId()) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); - } - // 校验商品不存在 - if (productSpuRpc.getProductSpuDetail(productRecommendUpdateDTO.getProductSpuId()) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode()); - } - // 校验商品是否已经推荐 - ProductRecommendDO existProductRecommend = productRecommendMapper.selectByProductSpuIdAndType(productRecommendUpdateDTO.getProductSpuId(), productRecommendUpdateDTO.getType()); - if (existProductRecommend != null && !existProductRecommend.getId().equals(productRecommendUpdateDTO.getId())) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_EXISTS.getCode()); - } - // 更新到数据库 - ProductRecommendDO updateProductRecommend = ProductRecommendConvert.INSTANCE.convert(productRecommendUpdateDTO); - productRecommendMapper.update(updateProductRecommend); - // 返回成功 - return true; - } - - @Override - public Boolean updateProductRecommendStatus(Integer adminId, Integer productRecommendId, Integer status) { - // 校验更新的商品推荐存在 - if (productRecommendMapper.selectById(productRecommendId) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); - } - // 更新到数据库 - ProductRecommendDO updateProductRecommend = new ProductRecommendDO().setId(productRecommendId).setStatus(status); - productRecommendMapper.update(updateProductRecommend); - // 返回成功 - return true; - } - - @Override - public Boolean deleteProductRecommend(Integer adminId, Integer productRecommendId) { - // 校验更新的商品推荐存在 - if (productRecommendMapper.selectById(productRecommendId) == null) { - throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); - } - // 更新到数据库 - ProductRecommendDO updateProductRecommend = new ProductRecommendDO().setId(productRecommendId); - updateProductRecommend.setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); - productRecommendMapper.update(updateProductRecommend); - // 返回成功 - return true; - } - -} diff --git a/promotion/promotion-service-impl/src/main/resources/mapper/BannerMapper.xml b/promotion/promotion-service-impl/src/main/resources/mapper/BannerMapper.xml deleted file mode 100644 index 0eb135dc0..000000000 --- a/promotion/promotion-service-impl/src/main/resources/mapper/BannerMapper.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - id, title, url, pic_url, sort, - status, memo, create_time - - - - - - - - - - - - - - - - - - - - - - - - - - - - - INSERT INTO banner ( - title, url, pic_url, sort, status, - memo, create_time, deleted - ) VALUES ( - #{title}, #{url}, #{picUrl}, #{sort}, #{status}, - #{memo}, #{createTime}, #{deleted} - ) - - - - UPDATE banner - - - title = #{title}, - - - url = #{url}, - - - pic_url = #{picUrl} , - - - sort = #{sort}, - - - status = #{status}, - - - memo = #{memo}, - - - deleted = #{deleted} - - - WHERE id = #{id} - - - \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/resources/mapper/ProductRecommendMapper.xml b/promotion/promotion-service-impl/src/main/resources/mapper/ProductRecommendMapper.xml deleted file mode 100644 index 7632b2579..000000000 --- a/promotion/promotion-service-impl/src/main/resources/mapper/ProductRecommendMapper.xml +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - id, type, product_spu_id, sort, - status, memo, create_time - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - INSERT INTO product_recommend ( - type, product_spu_id, sort, status, memo, - create_time, deleted - ) VALUES ( - #{type}, #{productSpuId}, #{sort}, #{status}, #{memo}, - #{createTime}, #{deleted} - ) - - - - UPDATE product_recommend - - - type = #{type}, - - - product_spu_id = #{productSpuId}, - - - sort = #{sort}, - - - status = #{status}, - - - memo = #{memo}, - - - deleted = #{deleted} - - - WHERE id = #{id} - - - \ No newline at end of file diff --git a/promotion/promotion-start/pom.xml b/promotion/promotion-start/pom.xml deleted file mode 100644 index 3d5c5cce8..000000000 --- a/promotion/promotion-start/pom.xml +++ /dev/null @@ -1,132 +0,0 @@ - - - - promotion - cn.iocoder.mall - 1.0-SNAPSHOT - - 4.0.0 - - promotion-start - - - - - cn.iocoder.mall - common-framework - 1.0-SNAPSHOT - - - cn.iocoder.mall - mall-spring-boot - 1.0-SNAPSHOT - - - cn.iocoder.mall - product-service-api - 1.0-SNAPSHOT - - - cn.iocoder.mall - promotion-service-api - 1.0-SNAPSHOT - - - cn.iocoder.mall - promotion-service-impl - 1.0-SNAPSHOT - - - cn.iocoder.mall - user-service-api - 1.0-SNAPSHOT - - - cn.iocoder.mall - user-sdk - 1.0-SNAPSHOT - - - cn.iocoder.mall - system-sdk - 1.0-SNAPSHOT - - - cn.iocoder.mall - mall-spring-boot-starter-mybatis - - - - - org.springframework.boot - spring-boot-starter-web - - - - - io.springfox - springfox-swagger2 - - - com.github.xiaoymin - swagger-bootstrap-ui - - - - - com.alibaba.cloud - spring-cloud-starter-alibaba-sentinel - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - io.micrometer - micrometer-registry-prometheus - - - - - org.springframework.boot - spring-boot-starter-test - test - - - cn.iocoder.mall - mall-spring-boot-starter-security - 1.0-SNAPSHOT - compile - - - cn.iocoder.mall - mall-spring-boot-starter-security - 1.0-SNAPSHOT - compile - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - diff --git a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java b/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java deleted file mode 100644 index 7b20fc96c..000000000 --- a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java +++ /dev/null @@ -1,101 +0,0 @@ -package cn.iocoder.mall.promotion.application.controller.admins; - -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.promotion.api.BannerService; -import cn.iocoder.mall.promotion.api.bo.BannerPageBO; -import cn.iocoder.mall.promotion.api.dto.BannerAddDTO; -import cn.iocoder.mall.promotion.api.dto.BannerPageDTO; -import cn.iocoder.mall.promotion.api.dto.BannerUpdateDTO; -import cn.iocoder.mall.promotion.application.convert.BannerConvert; -import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerPageVO; -import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerVO; -import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; -import org.apache.dubbo.config.annotation.Reference; -import org.springframework.web.bind.annotation.*; - -import static cn.iocoder.common.framework.vo.CommonResult.success; - -@RestController -@RequestMapping("admins/banner") -@Api("Banner 模块") -public class AdminsBannerController { - - @Reference(validation = "true", version = "${dubbo.provider.BannerService.version}") - private BannerService bannerService; - - @GetMapping("/page") - @ApiOperation(value = "Banner 分页") - @ApiImplicitParams({ - @ApiImplicitParam(name = "title", value = "标题,模糊匹配", example = "活动 A"), - @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), - @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), - }) - public CommonResult page(@RequestParam(value = "title", required = false) String title, - @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, - @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { - BannerPageBO result = bannerService.getBannerPage(new BannerPageDTO().setTitle(title).setPageNo(pageNo).setPageSize(pageSize)); - return success(BannerConvert.ADMINS.convert3(result)); - } - - @PostMapping("/add") - @ApiOperation(value = "创建 Banner") - @ApiImplicitParams({ - @ApiImplicitParam(name = "title", value = "标题", required = true, example = "活动A"), - @ApiImplicitParam(name = "url", value = "跳转链接", required = true, example = "http://www.iocoder.cn"), - @ApiImplicitParam(name = "picUrl", value = "图片链接", required = true, example = "http://www.iocoder.cn/01.jpg"), - @ApiImplicitParam(name = "sort", value = "排序", required = true, example = "10"), - @ApiImplicitParam(name = "memo", value = "备注", required = true, example = "活动很牛逼"), - }) - public CommonResult add(@RequestParam("title") String title, - @RequestParam("url") String url, - @RequestParam("picUrl") String picUrl, - @RequestParam("sort") Integer sort, - @RequestParam(value = "memo", required = false) String memo) { - BannerAddDTO bannerAddDTO = new BannerAddDTO().setTitle(title).setUrl(url).setPicUrl(picUrl) - .setSort(sort).setMemo(memo); - return success(BannerConvert.ADMINS.convert(bannerService.addBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerAddDTO))); - } - - @PostMapping("/update") - @ApiOperation(value = "更新 Banner") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1"), - @ApiImplicitParam(name = "url", value = "跳转链接", required = true, example = "http://www.iocoder.cn"), - @ApiImplicitParam(name = "picUrl", value = "图片链接", required = true, example = "http://www.iocoder.cn/01.jpg"), - @ApiImplicitParam(name = "sort", value = "排序", required = true, example = "10"), - @ApiImplicitParam(name = "memo", value = "备注", required = true, example = "活动很牛逼"), - }) - public CommonResult update(@RequestParam("id") Integer id, - @RequestParam("title") String title, - @RequestParam("url") String url, - @RequestParam("picUrl") String picUrl, - @RequestParam("sort") Integer sort, - @RequestParam(value = "memo", required = false) String memo) { - BannerUpdateDTO bannerUpdateDTO = new BannerUpdateDTO().setId(id).setTitle(title).setUrl(url).setPicUrl(picUrl) - .setSort(sort).setMemo(memo); - return success(bannerService.updateBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerUpdateDTO)); - } - - @PostMapping("/update_status") - @ApiOperation(value = "更新 Banner 状态") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1"), - @ApiImplicitParam(name = "status", value = "状态。1 - 开启;2 - 禁用", required = true, example = "1"), - }) - public CommonResult updateStatus(@RequestParam("id") Integer id, - @RequestParam("status") Integer status) { - return success(bannerService.updateBannerStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status)); - } - - @PostMapping("/delete") - @ApiOperation(value = "删除 Banner") - @ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1") - public CommonResult delete(@RequestParam("id") Integer id) { - return success(bannerService.deleteBanner(AdminSecurityContextHolder.getContext().getAdminId(), id)); - } - -} diff --git a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java b/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java index 8670c7b81..ca6ae48fe 100644 --- a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java +++ b/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java @@ -93,17 +93,6 @@ public class AdminsProductRecommendController { return success(productRecommendService.updateProductRecommend(AdminSecurityContextHolder.getContext().getAdminId(), bannerUpdateDTO)); } - @PostMapping("/update_status") - @ApiOperation(value = "更新商品推荐状态") - @ApiImplicitParams({ - @ApiImplicitParam(name = "id", value = "商品推荐编号", required = true, example = "1"), - @ApiImplicitParam(name = "status", value = "状态。1 - 开启;2 - 禁用", required = true, example = "1"), - }) - public CommonResult updateStatus(@RequestParam("id") Integer id, - @RequestParam("status") Integer status) { - return success(productRecommendService.updateProductRecommendStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status)); - } - @PostMapping("/delete") @ApiOperation(value = "删除商品推荐") @ApiImplicitParam(name = "id", value = "商品推荐编号", required = true, example = "1") diff --git a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java b/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java deleted file mode 100644 index 5b7e2825e..000000000 --- a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.mall.promotion.application.convert; - -import cn.iocoder.mall.promotion.api.bo.BannerBO; -import cn.iocoder.mall.promotion.api.bo.BannerPageBO; -import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerPageVO; -import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerVO; -import cn.iocoder.mall.promotion.application.vo.users.UsersBannerVO; -import org.mapstruct.Mapper; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -public interface BannerConvert { - - Users USERS = Mappers.getMapper(Users.class); - - Admins ADMINS = Mappers.getMapper(Admins.class); - - @Mapper - interface Admins { - - @Mappings({}) - AdminsBannerVO convert(BannerBO bannerBO); - - @Mappings({}) - AdminsBannerPageVO convert3(BannerPageBO bannerPageBO); - - } - - @Mapper - interface Users { - - @Mappings({}) - List convertList(List banners); - - } - -} diff --git a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/ProductRecommendConvert.java b/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/ProductRecommendConvert.java deleted file mode 100644 index 67d3bd293..000000000 --- a/promotion/promotion-start/src/main/java/cn/iocoder/mall/promotion/application/convert/ProductRecommendConvert.java +++ /dev/null @@ -1,30 +0,0 @@ -package cn.iocoder.mall.promotion.application.convert; - -import cn.iocoder.mall.product.api.bo.ProductSpuBO; -import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO; -import cn.iocoder.mall.promotion.api.bo.ProductRecommendPageBO; -import cn.iocoder.mall.promotion.application.vo.admins.AdminsProductRecommendPageVO; -import cn.iocoder.mall.promotion.application.vo.admins.AdminsProductRecommendVO; -import cn.iocoder.mall.promotion.application.vo.users.UsersProductRecommendVO; -import org.mapstruct.Mapper; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface ProductRecommendConvert { - - ProductRecommendConvert INSTANCE = Mappers.getMapper(ProductRecommendConvert.class); - - @Mappings({}) - AdminsProductRecommendVO convert(ProductRecommendBO bannerBO); - - @Mappings({}) - AdminsProductRecommendPageVO convert(ProductRecommendPageBO result); - - @Mappings({}) - UsersProductRecommendVO convert(ProductSpuBO productSpu); - - // @Mappings({}) - // List convertList(List banners); - -}