From ab5d051f7583859f63cb93d514bc7071a8aa89af Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 7 May 2019 01:58:07 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=89=8D=E7=AB=AF=20+=20=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=EF=BC=9A=E5=95=86=E5=93=81=E6=8E=A8=E8=8D=90=E5=88=97=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=95=86=E5=93=81=E5=90=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/Promotion/ProductRecommendList.js | 4 +- .../功能列表/功能列表-管理后台.md | 2 +- pom.xml | 18 +++++-- .../service/ProductSpuServiceImpl.java | 2 +- promotion/promotion-application/pom.xml | 21 +++----- .../AdminsProductRecommendController.java | 32 ++++++++--- .../users/UsersBannerController.java | 2 + .../users/UsersCouponController.java | 2 + .../UsersProductRecommendController.java | 7 ++- .../convert/ProductRecommendConvert.java | 8 +-- .../vo/admins/AdminsProductRecommendVO.java | 4 ++ .../api/ProductRecommendService.java | 18 ++++--- .../constant/ProductRecommendTypeEnum.java | 14 ++++- .../api/dto/ProductRecommendAddDTO.java | 3 ++ .../api/dto/ProductRecommendUpdateDTO.java | 3 ++ promotion/promotion-service-impl/pom.xml | 22 ++++++++ .../service/ProductRecommendServiceImpl.java | 54 +++++++------------ 17 files changed, 135 insertions(+), 81 deletions(-) diff --git a/admin-web/src/pages/Promotion/ProductRecommendList.js b/admin-web/src/pages/Promotion/ProductRecommendList.js index b4878dcf..ef673dd4 100644 --- a/admin-web/src/pages/Promotion/ProductRecommendList.js +++ b/admin-web/src/pages/Promotion/ProductRecommendList.js @@ -79,7 +79,7 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch, }, { title: '商品', - dataIndex: 'productSpuId', + dataIndex: 'productSpuName', }, { title: '排序值', @@ -103,7 +103,7 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch, }, { title: '操作', - width: 360, + width: 200, render: (text, record) => { const statusText = record.status === 1 ? '禁用' : '开启'; // TODO 芋艿,此处要改 return ( diff --git a/docs/guides/功能列表/功能列表-管理后台.md b/docs/guides/功能列表/功能列表-管理后台.md index e75d5073..22b0355e 100644 --- a/docs/guides/功能列表/功能列表-管理后台.md +++ b/docs/guides/功能列表/功能列表-管理后台.md @@ -21,7 +21,7 @@ - [ ] 会员资料【待认领】 - TODO 需要补充 - [ ] 营销管理 - - [ ] 广告管理 + - [x] 首页广告 - [ ] 优惠劵 - [ ] 优惠码【待认领】 - [ ] 商品推荐 diff --git a/pom.xml b/pom.xml index 639edc5f..3f003242 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.4.RELEASE + 2.1.3.RELEASE @@ -27,14 +27,15 @@ pom - 2.1.4.RELEASE + 2.1.3.RELEASE 2.7.1 5.1.47 1.3.0.Final - 2.13.0 + + 2.9.2 2.0.0 2.0.1 @@ -100,12 +101,23 @@ org.apache.curator curator-framework ${curator.version} + + + + + + org.apache.curator curator-recipes ${curator.version} + + + + + io.springfox diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java index fb46f965..f2638089 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java @@ -31,7 +31,7 @@ import java.util.*; import java.util.stream.Collectors; @Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示 -@org.apache.dubbo.config.annotation.Service(validation = "true") +@org.apache.dubbo.config.annotation.Service(validation = "true", version = "1.0.0") public class ProductSpuServiceImpl implements ProductSpuService { @Autowired diff --git a/promotion/promotion-application/pom.xml b/promotion/promotion-application/pom.xml index bc2afc06..95754bc5 100644 --- a/promotion/promotion-application/pom.xml +++ b/promotion/promotion-application/pom.xml @@ -39,7 +39,6 @@ user-sdk 1.0-SNAPSHOT - cn.iocoder.mall system-sdk @@ -56,20 +55,6 @@ test - - org.apache.dubbo - dubbo - - - - - - - - org.apache.curator - curator-framework - - io.springfox springfox-swagger2 @@ -78,6 +63,12 @@ io.springfox springfox-swagger-ui + + cn.iocoder.mall + product-service-api + 1.0-SNAPSHOT + compile + 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 index 3ac59088..8febe940 100644 --- 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 @@ -2,7 +2,10 @@ 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.product.api.ProductSpuService; +import cn.iocoder.mall.product.api.bo.ProductSpuBO; 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.dto.ProductRecommendAddDTO; import cn.iocoder.mall.promotion.api.dto.ProductRecommendPageDTO; @@ -10,14 +13,20 @@ 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 org.apache.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.apache.dubbo.config.annotation.Reference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static cn.iocoder.common.framework.vo.CommonResult.success; + @RestController @RequestMapping("admins/product_recommend") @Api("商品推荐模块") @@ -26,6 +35,8 @@ public class AdminsProductRecommendController { @Reference(validation = "true") @Autowired private ProductRecommendService productRecommendService; + @Reference(validation = "true", version = "*", lazy = true) + private ProductSpuService productSpuService; @GetMapping("/page") @ApiOperation(value = "商品推荐分页") @@ -37,8 +48,15 @@ public class AdminsProductRecommendController { 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); + ProductRecommendPageBO result = productRecommendService.getProductRecommendPage(new ProductRecommendPageDTO().setType(type).setPageNo(pageNo).setPageSize(pageSize)); + // 获得商品集合 + List spus = productSpuService.getProductSpuList( + result.getList().stream().map(ProductRecommendBO::getProductSpuId).collect(Collectors.toSet())); + Map spuMap = spus.stream().collect(Collectors.toMap(ProductSpuBO::getId, account -> account)); + // 拼装结果 + AdminsProductRecommendPageVO response = ProductRecommendConvert.INSTANCE.convert(result); + response.getList().forEach(recommendVO -> recommendVO.setProductSpuName(spuMap.get(recommendVO.getProductSpuId()).getName())); + return CommonResult.success(response); } @PostMapping("/add") @@ -55,7 +73,7 @@ public class AdminsProductRecommendController { @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)); + return success(ProductRecommendConvert.INSTANCE.convert(productRecommendService.addProductRecommend(AdminSecurityContextHolder.getContext().getAdminId(), bannerAddDTO))); } @PostMapping("/update") @@ -74,7 +92,7 @@ public class AdminsProductRecommendController { @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); + return success(productRecommendService.updateProductRecommend(AdminSecurityContextHolder.getContext().getAdminId(), bannerUpdateDTO)); } @PostMapping("/update_status") @@ -85,14 +103,14 @@ public class AdminsProductRecommendController { }) public CommonResult updateStatus(@RequestParam("id") Integer id, @RequestParam("status") Integer status) { - return productRecommendService.updateProductRecommendStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status); + return success(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); + return success(productRecommendService.deleteProductRecommend(AdminSecurityContextHolder.getContext().getAdminId(), id)); } } diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java index 537aa46a..d7ec8ec0 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java @@ -10,6 +10,7 @@ import cn.iocoder.mall.user.sdk.annotation.PermitAll; import org.apache.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -23,6 +24,7 @@ import java.util.List; public class UsersBannerController { @Reference(validation = "true") + @Autowired private BannerService bannerService; @GetMapping("/list") diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java index f44dcbca..9a86a0ec 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersCouponController.java @@ -18,6 +18,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @RestController @@ -26,6 +27,7 @@ import org.springframework.web.bind.annotation.*; public class UsersCouponController { @Reference(validation = "true") + @Autowired private CouponService couponService; // ========== 优惠劵(码)模板 ========== diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersProductRecommendController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersProductRecommendController.java index 0dd016e8..8cfe1c5d 100644 --- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersProductRecommendController.java +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersProductRecommendController.java @@ -14,6 +14,7 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -30,8 +31,10 @@ import java.util.stream.Collectors; public class UsersProductRecommendController { @Reference(validation = "true") + @Autowired private ProductRecommendService productRecommendService; - @Reference(validation = "true") + + @Reference(validation = "true", version = "1.0.0") private ProductSpuService productSpuService; @GetMapping("/list") @@ -40,7 +43,7 @@ public class UsersProductRecommendController { public CommonResult>> list() { // 查询商品推荐列表 List productRecommends = productRecommendService.getProductRecommendList( - null, CommonStatusEnum.ENABLE.getValue()).getData(); + null, CommonStatusEnum.ENABLE.getValue()); // 获得商品集合 List spus = productSpuService.getProductSpuList( productRecommends.stream().map(ProductRecommendBO::getProductSpuId).collect(Collectors.toSet())); 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 index 7ba9acbd..67d3bd29 100644 --- 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 @@ -1,6 +1,5 @@ package cn.iocoder.mall.promotion.application.convert; -import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.product.api.bo.ProductSpuBO; import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO; import cn.iocoder.mall.promotion.api.bo.ProductRecommendPageBO; @@ -20,10 +19,7 @@ public interface ProductRecommendConvert { AdminsProductRecommendVO convert(ProductRecommendBO bannerBO); @Mappings({}) - CommonResult convert2(CommonResult result); - - @Mappings({}) - CommonResult convert(CommonResult result); + AdminsProductRecommendPageVO convert(ProductRecommendPageBO result); @Mappings({}) UsersProductRecommendVO convert(ProductSpuBO productSpu); @@ -31,4 +27,4 @@ public interface ProductRecommendConvert { // @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/AdminsProductRecommendVO.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/admins/AdminsProductRecommendVO.java index 13e1b551..80f0007c 100644 --- 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 @@ -27,4 +27,8 @@ public class AdminsProductRecommendVO { @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") private Date createTime; + // ========== 基本信息 ========= + @ApiModelProperty(value = "SPU 名字", required = true, example = "厮大牛逼") + private String productSpuName; + } 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 index 9a87fbf1..837178ff 100644 --- 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 @@ -1,6 +1,7 @@ package cn.iocoder.mall.promotion.api; -import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.common.framework.constant.CommonStatusEnum; +import cn.iocoder.common.framework.validator.InEnum; import cn.iocoder.mall.promotion.api.bo.ProductRecommendBO; import cn.iocoder.mall.promotion.api.bo.ProductRecommendPageBO; import cn.iocoder.mall.promotion.api.dto.ProductRecommendAddDTO; @@ -11,16 +12,17 @@ import java.util.List; public interface ProductRecommendService { - CommonResult> getProductRecommendList(Integer type, Integer status); + List getProductRecommendList(Integer type, Integer status); - CommonResult getProductRecommendPage(ProductRecommendPageDTO productRecommendPageDTO); + ProductRecommendPageBO getProductRecommendPage(ProductRecommendPageDTO productRecommendPageDTO); - CommonResult addProductRecommend(Integer adminId, ProductRecommendAddDTO productRecommendAddDTO); + ProductRecommendBO addProductRecommend(Integer adminId, ProductRecommendAddDTO productRecommendAddDTO); - CommonResult updateProductRecommend(Integer adminId, ProductRecommendUpdateDTO productRecommendUpdateDTO); + Boolean updateProductRecommend(Integer adminId, ProductRecommendUpdateDTO productRecommendUpdateDTO); - CommonResult updateProductRecommendStatus(Integer adminId, Integer productRecommendId, Integer status); + Boolean updateProductRecommendStatus(Integer adminId, Integer productRecommendId, + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status); - CommonResult deleteProductRecommend(Integer adminId, Integer productRecommendId); + Boolean 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/constant/ProductRecommendTypeEnum.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/ProductRecommendTypeEnum.java index c251470b..0b50ae71 100644 --- a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/ProductRecommendTypeEnum.java +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/ProductRecommendTypeEnum.java @@ -1,15 +1,20 @@ package cn.iocoder.mall.promotion.api.constant; +import cn.iocoder.common.framework.core.IntArrayValuable; + +import java.util.Arrays; + /** * 商品推荐类型 */ -public enum ProductRecommendTypeEnum { +public enum ProductRecommendTypeEnum implements IntArrayValuable { HOT(1, "热卖推荐"), NEW(2, "新品推荐"), - ; + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductRecommendTypeEnum::getValue).toArray(); + /** * 状态值 */ @@ -40,4 +45,9 @@ public enum ProductRecommendTypeEnum { || NEW.value.equals(status); } + @Override + public int[] array() { + return ARRAYS; + } + } 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 index b1c95e63..9c2c59ac 100644 --- 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 @@ -1,5 +1,7 @@ package cn.iocoder.mall.promotion.api.dto; +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.mall.promotion.api.constant.ProductRecommendTypeEnum; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; @@ -13,6 +15,7 @@ import javax.validation.constraints.NotNull; @Accessors(chain = true) public class ProductRecommendAddDTO { + @InEnum(value = ProductRecommendTypeEnum.class, message = "修改推荐类型必须是 {value}") @NotNull(message = "推荐类型不能为空") private Integer type; @NotNull(message = "商品编号不能为空") 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 index 30590036..5e9c2dc4 100644 --- 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 @@ -1,5 +1,7 @@ package cn.iocoder.mall.promotion.api.dto; +import cn.iocoder.common.framework.validator.InEnum; +import cn.iocoder.mall.promotion.api.constant.ProductRecommendTypeEnum; import lombok.Data; import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; @@ -16,6 +18,7 @@ public class ProductRecommendUpdateDTO { @NotNull(message = "编号不能为空") private Integer id; @NotNull(message = "类型不能为空") + @InEnum(value = ProductRecommendTypeEnum.class, message = "修改推荐类型必须是 {value}") private Integer type; @NotNull(message = "商品编号不能为空") private Integer productSpuId; diff --git a/promotion/promotion-service-impl/pom.xml b/promotion/promotion-service-impl/pom.xml index 832ae55c..b995b7ec 100644 --- a/promotion/promotion-service-impl/pom.xml +++ b/promotion/promotion-service-impl/pom.xml @@ -32,6 +32,18 @@ org.apache.dubbo dubbo + + org.apache.curator + curator-framework + + + org.apache.curator + curator-recipes + + + org.apache.dubbo + dubbo-spring-boot-starter + mysql @@ -40,6 +52,16 @@ org.springframework.boot spring-boot-starter-jdbc + + + logback-classic + ch.qos.logback + + + spring-boot-starter-logging + org.springframework.boot + + 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 index 7c3a1434..d1aa2482 100644 --- 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 @@ -2,9 +2,7 @@ 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; @@ -27,20 +25,20 @@ import java.util.List; @org.apache.dubbo.config.annotation.Service(validation = "true") public class ProductRecommendServiceImpl implements ProductRecommendService { - @Reference(validation = "true") + @Reference(validation = "true", version = "1.0.0") private ProductSpuService productSpuService; @Autowired private ProductRecommendMapper productRecommendMapper; @Override - public CommonResult> getProductRecommendList(Integer type, Integer status) { + public List getProductRecommendList(Integer type, Integer status) { List productRecommends = productRecommendMapper.selectListByTypeAndStatus(type, status); - return CommonResult.success(ProductRecommendConvert.INSTANCE.convertToBO(productRecommends)); + return ProductRecommendConvert.INSTANCE.convertToBO(productRecommends); } @Override - public CommonResult getProductRecommendPage(ProductRecommendPageDTO productRecommendPageDTO) { + public ProductRecommendPageBO getProductRecommendPage(ProductRecommendPageDTO productRecommendPageDTO) { ProductRecommendPageBO productRecommendPageBO = new ProductRecommendPageBO(); // 查询分页数据 int offset = (productRecommendPageDTO.getPageNo() - 1) * productRecommendPageDTO.getPageSize(); @@ -48,86 +46,74 @@ public class ProductRecommendServiceImpl implements ProductRecommendService { offset, productRecommendPageDTO.getPageSize()))); // 查询分页总数 productRecommendPageBO.setTotal(productRecommendMapper.selectCountByType(productRecommendPageDTO.getType())); - return CommonResult.success(productRecommendPageBO); + return 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 有点搓 - } + public ProductRecommendBO addProductRecommend(Integer adminId, ProductRecommendAddDTO productRecommendAddDTO) { // 校验商品不存在 if (productSpuService.getProductSpuDetail(productRecommendAddDTO.getProductSpuId()) == null) { - return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode()); } // 校验商品是否已经推荐 if (productRecommendMapper.selectByProductSpuIdAndType(productRecommendAddDTO.getProductSpuId(), productRecommendAddDTO.getType()) != null) { - return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_EXISTS.getCode()); + 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 CommonResult.success(ProductRecommendConvert.INSTANCE.convertToBO(productRecommend)); + return 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 有点搓 - } + public Boolean updateProductRecommend(Integer adminId, ProductRecommendUpdateDTO productRecommendUpdateDTO) { // 校验更新的商品推荐存在 if (productRecommendMapper.selectById(productRecommendUpdateDTO.getId()) == null) { - return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); } // 校验商品不存在 if (productSpuService.getProductSpuDetail(productRecommendUpdateDTO.getProductSpuId()) == null) { - return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS.getCode()); + 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())) { - return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_EXISTS.getCode()); } // 更新到数据库 ProductRecommendDO updateProductRecommend = ProductRecommendConvert.INSTANCE.convert(productRecommendUpdateDTO); productRecommendMapper.update(updateProductRecommend); // 返回成功 - return CommonResult.success(true); + return 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 有点搓 - } + public Boolean updateProductRecommendStatus(Integer adminId, Integer productRecommendId, Integer status) { // 校验更新的商品推荐存在 if (productRecommendMapper.selectById(productRecommendId) == null) { - return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); } // 更新到数据库 ProductRecommendDO updateProductRecommend = new ProductRecommendDO().setId(productRecommendId).setStatus(status); productRecommendMapper.update(updateProductRecommend); // 返回成功 - return CommonResult.success(true); + return true; } @Override - public CommonResult deleteProductRecommend(Integer adminId, Integer productRecommendId) { + public Boolean deleteProductRecommend(Integer adminId, Integer productRecommendId) { // 校验更新的商品推荐存在 if (productRecommendMapper.selectById(productRecommendId) == null) { - return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_RECOMMEND_NOT_EXISTS.getCode()); + 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 CommonResult.success(true); + return true; } }