diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java index 0ab93a2db..b3d4b5f70 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java @@ -8,7 +8,7 @@ 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.AdminBannerPageVO; +import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerPageVO; import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerVO; import com.alibaba.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; @@ -32,9 +32,9 @@ public class AdminsBannerController { @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) { + public CommonResult page(@RequestParam(value = "title", required = false) String title, + @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { CommonResult result = bannerService.getBannerPage(new BannerPageDTO().setTitle(title).setPageNo(pageNo).setPageSize(pageSize)); return BannerConvert.INSTANCE.convert(result); } diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java new file mode 100644 index 000000000..2f2d28021 --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java @@ -0,0 +1,96 @@ +package cn.iocoder.mall.promotion.application.controller.admins; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; +import cn.iocoder.mall.promotion.api.ProductRecommendService; +import cn.iocoder.mall.promotion.api.bo.ProductRecommendPageBO; +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.application.convert.ProductRecommendConvert; +import cn.iocoder.mall.promotion.application.vo.admins.AdminsProductRecommendPageVO; +import cn.iocoder.mall.promotion.application.vo.admins.AdminsProductRecommendVO; +import com.alibaba.dubbo.config.annotation.Reference; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("admins/product_recommend") +@Api("商品推荐模块") +public class AdminsProductRecommendController { + + @Reference(validation = "true") + private ProductRecommendService productRecommendService; + + @GetMapping("/page") + @ApiOperation(value = "商品推荐分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = "type", value = "推荐类型", example = "1"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), + }) + public CommonResult page(@RequestParam(value = "type", required = false) Integer type, + @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + CommonResult result = productRecommendService.getProductRecommendPage(new ProductRecommendPageDTO().setType(type).setPageNo(pageNo).setPageSize(pageSize)); + return ProductRecommendConvert.INSTANCE.convert(result); + } + + @PostMapping("/add") + @ApiOperation(value = "创建商品推荐") + @ApiImplicitParams({ + @ApiImplicitParam(name = "type", value = "推荐类型", required = true, example = "1"), + @ApiImplicitParam(name = "productSpuId", value = "商品编号", required = true, example = "1"), + @ApiImplicitParam(name = "sort", value = "排序", required = true, example = "10"), + @ApiImplicitParam(name = "memo", value = "备注", example = "活动很牛逼"), + }) + public CommonResult add(@RequestParam("type") Integer type, + @RequestParam("productSpuId") Integer productSpuId, + @RequestParam("sort") Integer sort, + @RequestParam(value = "memo", required = false) String memo) { + ProductRecommendAddDTO bannerAddDTO = new ProductRecommendAddDTO().setType(type).setProductSpuId(productSpuId) + .setSort(sort).setMemo(memo); + return ProductRecommendConvert.INSTANCE.convert2(productRecommendService.addProductRecommend(AdminSecurityContextHolder.getContext().getAdminId(), bannerAddDTO)); + } + + @PostMapping("/update") + @ApiOperation(value = "更新商品推荐") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "商品推荐编号", required = true, example = "1"), + @ApiImplicitParam(name = "type", value = "推荐类型", required = true, example = "1"), + @ApiImplicitParam(name = "productSpuId", value = "商品编号", required = true, example = "1"), + @ApiImplicitParam(name = "sort", value = "排序", required = true, example = "10"), + @ApiImplicitParam(name = "memo", value = "备注", example = "活动很牛逼"), + }) + public CommonResult update(@RequestParam("id") Integer id, + @RequestParam("type") Integer type, + @RequestParam("productSpuId") Integer productSpuId, + @RequestParam("sort") Integer sort, + @RequestParam(value = "memo", required = false) String memo) { + ProductRecommendUpdateDTO bannerUpdateDTO = new ProductRecommendUpdateDTO().setId(id).setType(type).setProductSpuId(productSpuId) + .setSort(sort).setMemo(memo); + return 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 productRecommendService.updateProductRecommendStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status); + } + + @PostMapping("/delete") + @ApiOperation(value = "删除商品推荐") + @ApiImplicitParam(name = "id", value = "商品推荐编号", required = true, example = "1") + public CommonResult delete(@RequestParam("id") Integer id) { + return productRecommendService.deleteProductRecommend(AdminSecurityContextHolder.getContext().getAdminId(), id); + } + +} \ No newline at end of file diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java index 7fbd35569..a7d5502fe 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java @@ -3,7 +3,7 @@ package cn.iocoder.mall.promotion.application.convert; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.promotion.api.bo.BannerBO; import cn.iocoder.mall.promotion.api.bo.BannerPageBO; -import cn.iocoder.mall.promotion.application.vo.admins.AdminBannerPageVO; +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; @@ -24,7 +24,7 @@ public interface BannerConvert { CommonResult convert2(CommonResult result); @Mappings({}) - CommonResult convert(CommonResult result); + CommonResult convert(CommonResult result); @Mappings({}) List convertList(List banners); diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/ProductRecommendConvert.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/ProductRecommendConvert.java new file mode 100644 index 000000000..2c04fec01 --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/ProductRecommendConvert.java @@ -0,0 +1,29 @@ +package cn.iocoder.mall.promotion.application.convert; + +import cn.iocoder.common.framework.vo.CommonResult; +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 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({}) + CommonResult convert2(CommonResult result); + + @Mappings({}) + CommonResult convert(CommonResult result); + +// @Mappings({}) +// List convertList(List banners); + +} \ No newline at end of file diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminBannerPageVO.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsBannerPageVO.java similarity index 79% rename from promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminBannerPageVO.java rename to promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsBannerPageVO.java index f29f0f81d..7f5595e7f 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminBannerPageVO.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsBannerPageVO.java @@ -6,7 +6,7 @@ import io.swagger.annotations.ApiModelProperty; import java.util.List; @ApiModel("Banner 分页 VO") -public class AdminBannerPageVO { +public class AdminsBannerPageVO { @ApiModelProperty(value = "Banner 数组") private List list; @@ -17,7 +17,7 @@ public class AdminBannerPageVO { return list; } - public AdminBannerPageVO setList(List list) { + public AdminsBannerPageVO setList(List list) { this.list = list; return this; } @@ -26,7 +26,7 @@ public class AdminBannerPageVO { return total; } - public AdminBannerPageVO setTotal(Integer total) { + public AdminsBannerPageVO setTotal(Integer total) { this.total = total; return this; } diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsProductRecommendPageVO.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsProductRecommendPageVO.java new file mode 100644 index 000000000..e774b8429 --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsProductRecommendPageVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.promotion.application.vo.admins; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel("商品推荐分页 VO") +public class AdminsProductRecommendPageVO { + + @ApiModelProperty(value = "商品推荐数组") + private List list; + @ApiModelProperty(value = "商品推荐总数") + private Integer total; + + public List getList() { + return list; + } + + public AdminsProductRecommendPageVO setList(List list) { + this.list = list; + return this; + } + + public Integer getTotal() { + return total; + } + + public AdminsProductRecommendPageVO setTotal(Integer total) { + this.total = total; + return this; + } + +} \ No newline at end of file diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsProductRecommendVO.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsProductRecommendVO.java new file mode 100644 index 000000000..d95a6051a --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsProductRecommendVO.java @@ -0,0 +1,88 @@ +package cn.iocoder.mall.promotion.application.vo.admins; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Date; + +@ApiModel("商品推荐 VO") +public class AdminsProductRecommendVO { + + @ApiModelProperty(value = "编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "推荐类型", required = true, example = "1") + 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") + private Integer status; + @ApiModelProperty(value = "备注", required = true, example = "这个活动很牛逼") + private String memo; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") + private Date createTime; + + public Integer getId() { + return id; + } + + public AdminsProductRecommendVO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getType() { + return type; + } + + public AdminsProductRecommendVO setType(Integer type) { + this.type = type; + return this; + } + + public Integer getProductSpuId() { + return productSpuId; + } + + public AdminsProductRecommendVO setProductSpuId(Integer productSpuId) { + this.productSpuId = productSpuId; + return this; + } + + public Integer getSort() { + return sort; + } + + public AdminsProductRecommendVO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public Integer getStatus() { + return status; + } + + public AdminsProductRecommendVO setStatus(Integer status) { + this.status = status; + return this; + } + + public String getMemo() { + return memo; + } + + public AdminsProductRecommendVO setMemo(String memo) { + this.memo = memo; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public AdminsProductRecommendVO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/ProductRecommendService.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/ProductRecommendService.java new file mode 100644 index 000000000..9a87fbf10 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/ProductRecommendService.java @@ -0,0 +1,26 @@ +package cn.iocoder.mall.promotion.api; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO; +import cn.iocoder.mall.promotion.api.bo.ProductRecommendPageBO; +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 java.util.List; + +public interface ProductRecommendService { + + CommonResult> getProductRecommendList(Integer type, Integer status); + + CommonResult getProductRecommendPage(ProductRecommendPageDTO productRecommendPageDTO); + + CommonResult addProductRecommend(Integer adminId, ProductRecommendAddDTO productRecommendAddDTO); + + CommonResult updateProductRecommend(Integer adminId, ProductRecommendUpdateDTO productRecommendUpdateDTO); + + CommonResult updateProductRecommendStatus(Integer adminId, Integer productRecommendId, Integer status); + + CommonResult deleteProductRecommend(Integer adminId, Integer productRecommendId); + +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/ProductRecommendBO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/ProductRecommendBO.java new file mode 100644 index 000000000..6abc7c560 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/ProductRecommendBO.java @@ -0,0 +1,106 @@ +package cn.iocoder.mall.promotion.api.bo; + +import java.util.Date; + +/** + * 商品推荐 BO + */ +public class ProductRecommendBO { + + /** + * 编号 + */ + private Integer id; + /** + * 类型 + * + * {@link cn.iocoder.mall.promotion.api.constant.ProductRecommendType} + */ + private Integer type; + /** + * 商品 Spu 编号 + */ + private Integer productSpuId; + /** + * 排序 + */ + private Integer sort; + /** + * 状态 + * + * {@link cn.iocoder.common.framework.constant.CommonStatusEnum} + */ + private Integer status; + /** + * 备注 + */ + private String memo; + /** + * 创建时间 + */ + private Date createTime; + + public Integer getId() { + return id; + } + + public ProductRecommendBO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getType() { + return type; + } + + public ProductRecommendBO setType(Integer type) { + this.type = type; + return this; + } + + public Integer getProductSpuId() { + return productSpuId; + } + + public ProductRecommendBO setProductSpuId(Integer productSpuId) { + this.productSpuId = productSpuId; + return this; + } + + public Integer getSort() { + return sort; + } + + public ProductRecommendBO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public Integer getStatus() { + return status; + } + + public ProductRecommendBO setStatus(Integer status) { + this.status = status; + return this; + } + + public String getMemo() { + return memo; + } + + public ProductRecommendBO setMemo(String memo) { + this.memo = memo; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public ProductRecommendBO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/ProductRecommendPageBO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/ProductRecommendPageBO.java new file mode 100644 index 000000000..30d36c5dc --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/ProductRecommendPageBO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.promotion.api.bo; + +import java.util.List; + +public class ProductRecommendPageBO { + + /** + * ProductRecommend 数组 + */ + private List list; + /** + * 总量 + */ + private Integer total; + + public List getList() { + return list; + } + + public ProductRecommendPageBO setList(List list) { + this.list = list; + return this; + } + + public Integer getTotal() { + return total; + } + + public ProductRecommendPageBO setTotal(Integer total) { + this.total = total; + return this; + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/ProductRecommendType.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/ProductRecommendType.java new file mode 100644 index 000000000..302e69e31 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/ProductRecommendType.java @@ -0,0 +1,43 @@ +package cn.iocoder.mall.promotion.api.constant; + +/** + * 商品推荐类型 + */ +public enum ProductRecommendType { + + HOT(1, "热卖推荐"), + NEW(2, "新品推荐"), + + ; + + /** + * 状态值 + */ + private final Integer value; + /** + * 状态名 + */ + private final String name; + + ProductRecommendType(Integer value, String name) { + this.value = value; + this.name = name; + } + + public Integer getValue() { + return value; + } + + public String getName() { + return name; + } + + public static boolean isValid(Integer status) { + if (status == null) { + return false; + } + return HOT.value.equals(status) + || NEW.value.equals(status); + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java index 9f98a271e..24d19f848 100644 --- a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java @@ -8,10 +8,16 @@ package cn.iocoder.mall.promotion.api.constant; public enum PromotionErrorCodeEnum { // ========== Banner 模块 ========== - BANNER_NOT_EXISTS(1002002000, "账号不存在"), + BANNER_NOT_EXISTS(1006000000, "账号不存在"), + + // ========== PRODUCT RECOMMEND 模块 ========== + PRODUCT_RECOMMEND_NOT_EXISTS(1006001000, "商品推荐不存在"), + PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS(1006001001, "商品不存在"), + PRODUCT_RECOMMEND_EXISTS(1006001002, "该商品推荐已经存在"), ; + private final int code; private final String message; diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/ProductRecommendAddDTO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/ProductRecommendAddDTO.java new file mode 100644 index 000000000..af042b409 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/ProductRecommendAddDTO.java @@ -0,0 +1,57 @@ +package cn.iocoder.mall.promotion.api.dto; + +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotNull; + +/** + * 商品推荐添加 DTO + */ +public class ProductRecommendAddDTO { + + @NotNull(message = "推荐类型不能为空") + private Integer type; + @NotNull(message = "商品编号不能为空") + private Integer productSpuId; + @NotNull(message = "排序不能为空") + private Integer sort; + @Length(max = 255, message = "备注最大长度为 255 位") + private String memo; + + public Integer getType() { + return type; + } + + public ProductRecommendAddDTO setType(Integer type) { + this.type = type; + return this; + } + + public Integer getProductSpuId() { + return productSpuId; + } + + public ProductRecommendAddDTO setProductSpuId(Integer productSpuId) { + this.productSpuId = productSpuId; + return this; + } + + public Integer getSort() { + return sort; + } + + public ProductRecommendAddDTO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public String getMemo() { + return memo; + } + + public ProductRecommendAddDTO setMemo(String memo) { + this.memo = memo; + return this; + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/ProductRecommendPageDTO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/ProductRecommendPageDTO.java new file mode 100644 index 000000000..21567327a --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/ProductRecommendPageDTO.java @@ -0,0 +1,44 @@ +package cn.iocoder.mall.promotion.api.dto; + +import javax.validation.constraints.NotNull; + +public class ProductRecommendPageDTO { + + /** + * 推荐类型 + */ + private Integer type; + + @NotNull(message = "页码不能为空") + private Integer pageNo; + @NotNull(message = "每页条数不能为空") + private Integer pageSize; + + public Integer getPageNo() { + return pageNo; + } + + public ProductRecommendPageDTO setPageNo(Integer pageNo) { + this.pageNo = pageNo; + return this; + } + + public Integer getPageSize() { + return pageSize; + } + + public ProductRecommendPageDTO setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public Integer getType() { + return type; + } + + public ProductRecommendPageDTO setType(Integer type) { + this.type = type; + return this; + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/ProductRecommendUpdateDTO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/ProductRecommendUpdateDTO.java new file mode 100644 index 000000000..779696686 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/ProductRecommendUpdateDTO.java @@ -0,0 +1,68 @@ +package cn.iocoder.mall.promotion.api.dto; + +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.NotNull; + +/** + * 商品推荐更新 DTO + */ +public class ProductRecommendUpdateDTO { + + @NotNull(message = "编号不能为空") + private Integer id; + @NotNull(message = "类型不能为空") + private Integer type; + @NotNull(message = "商品编号不能为空") + private Integer productSpuId; + @NotNull(message = "排序不能为空") + private Integer sort; + @Length(max = 255, message = "备注最大长度为 255 位") + private String memo; + + public Integer getId() { + return id; + } + + public ProductRecommendUpdateDTO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getType() { + return type; + } + + public ProductRecommendUpdateDTO setType(Integer type) { + this.type = type; + return this; + } + + public Integer getProductSpuId() { + return productSpuId; + } + + public ProductRecommendUpdateDTO setProductSpuId(Integer productSpuId) { + this.productSpuId = productSpuId; + return this; + } + + public Integer getSort() { + return sort; + } + + public ProductRecommendUpdateDTO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public String getMemo() { + return memo; + } + + public ProductRecommendUpdateDTO setMemo(String memo) { + this.memo = memo; + return this; + } + +} \ 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 new file mode 100644 index 000000000..552e6246a --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/ProductRecommendConvert.java @@ -0,0 +1,30 @@ +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 banner); + + @Mappings({}) + List convertToBO(List bannerList); + + @Mappings({}) + ProductRecommendDO convert(ProductRecommendAddDTO bannerAddDTO); + + @Mappings({}) + ProductRecommendDO convert(ProductRecommendUpdateDTO bannerUpdateDTO); + +} \ 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 new file mode 100644 index 000000000..f8a66228c --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/ProductRecommendMapper.java @@ -0,0 +1,30 @@ +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/dataobject/ProductRecommendDO.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/ProductRecommendDO.java new file mode 100644 index 000000000..4ae5f2a28 --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/ProductRecommendDO.java @@ -0,0 +1,94 @@ +package cn.iocoder.mall.promotion.biz.dataobject; + +import cn.iocoder.common.framework.dataobject.DeletableDO; + +/** + * 商品推荐 DO + */ +public class ProductRecommendDO extends DeletableDO { + + /** + * 编号 + */ + private Integer id; + /** + * 类型 + * + * {@link cn.iocoder.mall.promotion.api.constant.ProductRecommendType} + */ + private Integer type; + /** + * 商品 Spu 编号 + */ + private Integer productSpuId; + // TODO 芋艿,商品 spu 名 + /** + * 排序 + */ + private Integer sort; + /** + * 状态 + * + * {@link cn.iocoder.common.framework.constant.CommonStatusEnum} + */ + private Integer status; + /** + * 备注 + */ + private String memo; + + public Integer getId() { + return id; + } + + public ProductRecommendDO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getType() { + return type; + } + + public ProductRecommendDO setType(Integer type) { + this.type = type; + return this; + } + + public Integer getProductSpuId() { + return productSpuId; + } + + public ProductRecommendDO setProductSpuId(Integer productSpuId) { + this.productSpuId = productSpuId; + return this; + } + + public Integer getSort() { + return sort; + } + + public ProductRecommendDO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public Integer getStatus() { + return status; + } + + public ProductRecommendDO setStatus(Integer status) { + this.status = status; + return this; + } + + public String getMemo() { + return memo; + } + + public ProductRecommendDO setMemo(String memo) { + this.memo = memo; + return this; + } + +} \ 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 index 6db630fc4..b408ba87c 100644 --- 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 @@ -75,6 +75,10 @@ public class BannerServiceImpl implements BannerService { if (!CommonStatusEnum.isValid(status)) { return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "变更状态必须是开启(1)或关闭(2)"); // TODO 有点搓 } + // 校验 Banner 存在 + if (bannerMapper.selectById(bannerId) == null) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode()); + } // 更新到数据库 BannerDO updateBanner = new BannerDO().setId(bannerId).setStatus(status); bannerMapper.update(updateBanner); 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 new file mode 100644 index 000000000..7fc773ba8 --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/ProductRecommendServiceImpl.java @@ -0,0 +1,133 @@ +package cn.iocoder.mall.promotion.biz.service; + +import cn.iocoder.common.framework.constant.CommonStatusEnum; +import cn.iocoder.common.framework.constant.DeletedStatusEnum; +import cn.iocoder.common.framework.constant.SysErrorCodeEnum; +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.product.api.ProductSpuService; +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.constant.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 com.alibaba.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 报错提示 +@com.alibaba.dubbo.config.annotation.Service(validation = "true") +public class ProductRecommendServiceImpl implements ProductRecommendService { + + @Reference(validation = "true") + private ProductSpuService productSpuService; + + @Autowired + private ProductRecommendMapper productRecommendMapper; + + @Override + public CommonResult> getProductRecommendList(Integer type, Integer status) { + List productRecommends = productRecommendMapper.selectListByTypeAndStatus(type, status); + return CommonResult.success(ProductRecommendConvert.INSTANCE.convertToBO(productRecommends)); + } + + @Override + public CommonResult 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 CommonResult.success(productRecommendPageBO); + } + + @Override + public CommonResult addProductRecommend(Integer adminId, ProductRecommendAddDTO productRecommendAddDTO) { + // 校验参数 + if (!CommonStatusEnum.isValid(productRecommendAddDTO.getType())) { + return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "推荐类型必须是新品(1)或热卖(2)"); // TODO 有点搓 + } + // 校验商品不存在 + if (productSpuService.getProductSpu(productRecommendAddDTO.getProductSpuId()) == null) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode()); + } + // 校验商品是否已经推荐 + if (productRecommendMapper.selectByProductSpuIdAndType(productRecommendAddDTO.getProductSpuId(), productRecommendAddDTO.getType()) != null) { + return ServiceExceptionUtil.error(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 CommonResult.success(ProductRecommendConvert.INSTANCE.convertToBO(productRecommend)); + } + + @Override + public CommonResult updateProductRecommend(Integer adminId, ProductRecommendUpdateDTO productRecommendUpdateDTO) { + // 校验参数 + if (!CommonStatusEnum.isValid(productRecommendUpdateDTO.getType())) { + return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "推荐类型必须是新品(1)或热卖(2)"); // TODO 有点搓 + } + // 校验更新的商品推荐存在 + if (productRecommendMapper.selectById(productRecommendUpdateDTO.getId()) == null) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); + } + // 校验商品不存在 + if (productSpuService.getProductSpu(productRecommendUpdateDTO.getProductSpuId()) == null) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode()); + } + // 校验商品是否已经推荐 + ProductRecommendDO existProductRecommend = productRecommendMapper.selectByProductSpuIdAndType(productRecommendUpdateDTO.getProductSpuId(), productRecommendUpdateDTO.getType()); + if (existProductRecommend != null && !existProductRecommend.getId().equals(productRecommendUpdateDTO.getId())) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_EXISTS.getCode()); + } + // 更新到数据库 + ProductRecommendDO updateProductRecommend = ProductRecommendConvert.INSTANCE.convert(productRecommendUpdateDTO); + productRecommendMapper.update(updateProductRecommend); + // 返回成功 + return CommonResult.success(true); + } + + @Override + public CommonResult updateProductRecommendStatus(Integer adminId, Integer productRecommendId, Integer status) { + // 校验参数 + if (!CommonStatusEnum.isValid(status)) { + return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "变更状态必须是开启(1)或关闭(2)"); // TODO 有点搓 + } + // 校验更新的商品推荐存在 + if (productRecommendMapper.selectById(productRecommendId) == null) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); + } + // 更新到数据库 + ProductRecommendDO updateProductRecommend = new ProductRecommendDO().setId(productRecommendId).setStatus(status); + productRecommendMapper.update(updateProductRecommend); + // 返回成功 + return CommonResult.success(true); + } + + @Override + public CommonResult deleteProductRecommend(Integer adminId, Integer productRecommendId) { + // 校验更新的商品推荐存在 + if (productRecommendMapper.selectById(productRecommendId) == null) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); + } + // 更新到数据库 + ProductRecommendDO updateProductRecommend = new ProductRecommendDO().setId(productRecommendId); + updateProductRecommend.setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); + productRecommendMapper.update(updateProductRecommend); + // 返回成功 + return CommonResult.success(true); + } + +} \ 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 new file mode 100644 index 000000000..939e6926d --- /dev/null +++ b/promotion/promotion-service-impl/src/main/resources/mapper/ProductRecommendMapper.xml @@ -0,0 +1,125 @@ + + + + + + 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