- 前端 + 后端:商品推荐列表,增加商品名。
parent
9a3b708738
commit
ab5d051f75
|
@ -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 (
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
- [ ] 会员资料【待认领】
|
||||
- TODO 需要补充
|
||||
- [ ] 营销管理
|
||||
- [ ] 广告管理
|
||||
- [x] 首页广告
|
||||
- [ ] 优惠劵
|
||||
- [ ] 优惠码【待认领】
|
||||
- [ ] 商品推荐
|
||||
|
|
18
pom.xml
18
pom.xml
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.4.RELEASE</version>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
|
@ -27,14 +27,15 @@
|
|||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<springboot.version>2.1.4.RELEASE</springboot.version>
|
||||
<springboot.version>2.1.3.RELEASE</springboot.version>
|
||||
<!-- <com.alibab.dubbo.version>2.6.5</com.alibab.dubbo.version>-->
|
||||
<dubbo.version>2.7.1</dubbo.version>
|
||||
<mysql-connector-java.version>5.1.47</mysql-connector-java.version>
|
||||
<!-- <dubbo-spring-boot-starter.version>0.2.1.RELEASE</dubbo-spring-boot-starter.version>-->
|
||||
<org.mapstruct.version>1.3.0.Final</org.mapstruct.version>
|
||||
<!-- <curator.version>2.12.0</curator.version>-->
|
||||
<curator.version>2.13.0</curator.version>
|
||||
<!-- <curator.version>4.0.1</curator.version>-->
|
||||
<!-- <zookeeper.version>3.4.14</zookeeper.version>-->
|
||||
<springfox-swagger.version>2.9.2</springfox-swagger.version>
|
||||
<mybatis-spring-boot-starter.version>2.0.0</mybatis-spring-boot-starter.version>
|
||||
<xxl-job.version>2.0.1</xxl-job.version>
|
||||
|
@ -100,12 +101,23 @@
|
|||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
<version>${curator.version}</version>
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <groupId>org.apache.zookeeper</groupId>-->
|
||||
<!-- <artifactId>zookeeper</artifactId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-recipes</artifactId>
|
||||
<version>${curator.version}</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.zookeeper</groupId>-->
|
||||
<!-- <artifactId>zookeeper</artifactId>-->
|
||||
<!-- <version>${zookeeper.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
<artifactId>user-sdk</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>system-sdk</artifactId>
|
||||
|
@ -56,20 +55,6 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.alibaba.boot</groupId>-->
|
||||
<!--<artifactId>dubbo-spring-boot-starter</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
|
@ -78,6 +63,12 @@
|
|||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>product-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -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<AdminsProductRecommendPageVO> page(@RequestParam(value = "type", required = false) Integer type,
|
||||
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
|
||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||
CommonResult<ProductRecommendPageBO> 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<ProductSpuBO> spus = productSpuService.getProductSpuList(
|
||||
result.getList().stream().map(ProductRecommendBO::getProductSpuId).collect(Collectors.toSet()));
|
||||
Map<Integer, ProductSpuBO> 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<Boolean> 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<Boolean> delete(@RequestParam("id") Integer id) {
|
||||
return productRecommendService.deleteProductRecommend(AdminSecurityContextHolder.getContext().getAdminId(), id);
|
||||
return success(productRecommendService.deleteProductRecommend(AdminSecurityContextHolder.getContext().getAdminId(), id));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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;
|
||||
|
||||
// ========== 优惠劵(码)模板 ==========
|
||||
|
|
|
@ -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<Map<Integer, Collection<UsersProductRecommendVO>>> list() {
|
||||
// 查询商品推荐列表
|
||||
List<ProductRecommendBO> productRecommends = productRecommendService.getProductRecommendList(
|
||||
null, CommonStatusEnum.ENABLE.getValue()).getData();
|
||||
null, CommonStatusEnum.ENABLE.getValue());
|
||||
// 获得商品集合
|
||||
List<ProductSpuBO> spus = productSpuService.getProductSpuList(
|
||||
productRecommends.stream().map(ProductRecommendBO::getProductSpuId).collect(Collectors.toSet()));
|
||||
|
|
|
@ -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<AdminsProductRecommendVO> convert2(CommonResult<ProductRecommendBO> result);
|
||||
|
||||
@Mappings({})
|
||||
CommonResult<AdminsProductRecommendPageVO> convert(CommonResult<ProductRecommendPageBO> result);
|
||||
AdminsProductRecommendPageVO convert(ProductRecommendPageBO result);
|
||||
|
||||
@Mappings({})
|
||||
UsersProductRecommendVO convert(ProductSpuBO productSpu);
|
||||
|
|
|
@ -27,4 +27,8 @@ public class AdminsProductRecommendVO {
|
|||
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
|
||||
private Date createTime;
|
||||
|
||||
// ========== 基本信息 =========
|
||||
@ApiModelProperty(value = "SPU 名字", required = true, example = "厮大牛逼")
|
||||
private String productSpuName;
|
||||
|
||||
}
|
||||
|
|
|
@ -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<List<ProductRecommendBO>> getProductRecommendList(Integer type, Integer status);
|
||||
List<ProductRecommendBO> getProductRecommendList(Integer type, Integer status);
|
||||
|
||||
CommonResult<ProductRecommendPageBO> getProductRecommendPage(ProductRecommendPageDTO productRecommendPageDTO);
|
||||
ProductRecommendPageBO getProductRecommendPage(ProductRecommendPageDTO productRecommendPageDTO);
|
||||
|
||||
CommonResult<ProductRecommendBO> addProductRecommend(Integer adminId, ProductRecommendAddDTO productRecommendAddDTO);
|
||||
ProductRecommendBO addProductRecommend(Integer adminId, ProductRecommendAddDTO productRecommendAddDTO);
|
||||
|
||||
CommonResult<Boolean> updateProductRecommend(Integer adminId, ProductRecommendUpdateDTO productRecommendUpdateDTO);
|
||||
Boolean updateProductRecommend(Integer adminId, ProductRecommendUpdateDTO productRecommendUpdateDTO);
|
||||
|
||||
CommonResult<Boolean> updateProductRecommendStatus(Integer adminId, Integer productRecommendId, Integer status);
|
||||
Boolean updateProductRecommendStatus(Integer adminId, Integer productRecommendId,
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
|
||||
|
||||
CommonResult<Boolean> deleteProductRecommend(Integer adminId, Integer productRecommendId);
|
||||
Boolean deleteProductRecommend(Integer adminId, Integer productRecommendId);
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 = "商品编号不能为空")
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -32,6 +32,18 @@
|
|||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-recipes</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
|
@ -40,6 +52,16 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -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<List<ProductRecommendBO>> getProductRecommendList(Integer type, Integer status) {
|
||||
public List<ProductRecommendBO> getProductRecommendList(Integer type, Integer status) {
|
||||
List<ProductRecommendDO> productRecommends = productRecommendMapper.selectListByTypeAndStatus(type, status);
|
||||
return CommonResult.success(ProductRecommendConvert.INSTANCE.convertToBO(productRecommends));
|
||||
return ProductRecommendConvert.INSTANCE.convertToBO(productRecommends);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<ProductRecommendPageBO> 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<ProductRecommendBO> 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<Boolean> 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<Boolean> 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<Boolean> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue