移除商品推荐的逻辑
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.controller;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.*;
|
||||
import cn.iocoder.mall.promotionservice.manager.recommend.ProductRecommendManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* Title:
|
||||
* Description:
|
||||
*
|
||||
* @author zhuyang
|
||||
* @version 1.0 2021/10/9
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/promotion/prod/recommend")
|
||||
public class ProductRecommendController {
|
||||
|
||||
@Autowired
|
||||
private ProductRecommendManager productRecommendManager;
|
||||
|
||||
|
||||
@PostMapping("createProductRecommend")
|
||||
public CommonResult<Integer> createProductRecommend(@RequestBody ProductRecommendCreateReqDTO createDTO) {
|
||||
return success(productRecommendManager.createProductRecommend(createDTO));
|
||||
}
|
||||
|
||||
@PostMapping("updateProductRecommend")
|
||||
public CommonResult<Boolean> updateProductRecommend(@RequestBody ProductRecommendUpdateReqDTO updateDTO) {
|
||||
productRecommendManager.updateProductRecommend(updateDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("deleteProductRecommend")
|
||||
public CommonResult<Boolean> deleteProductRecommend(@RequestParam("productRecommendId") Integer productRecommendId) {
|
||||
productRecommendManager.deleteProductRecommend(productRecommendId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("listProductRecommends")
|
||||
public CommonResult<List<ProductRecommendRespDTO>> listProductRecommends(@RequestBody ProductRecommendListReqDTO listReqDTO) {
|
||||
return success(productRecommendManager.listProductRecommends(listReqDTO));
|
||||
}
|
||||
|
||||
@PostMapping("pageProductRecommend")
|
||||
public CommonResult<PageResult<ProductRecommendRespDTO>> pageProductRecommend(@RequestBody ProductRecommendPageReqDTO pageDTO) {
|
||||
return success(productRecommendManager.pageProductRecommend(pageDTO));
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.controller;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityPageReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
|
||||
import cn.iocoder.mall.promotionservice.manager.activity.PromotionActivityManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* Title:
|
||||
* Description:
|
||||
*
|
||||
* @author zhuyang
|
||||
* @version 1.0 2021/10/9
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/promotion/activity")
|
||||
public class PromotionActivityController {
|
||||
@Autowired
|
||||
private PromotionActivityManager promotionActivityManager;
|
||||
|
||||
@PostMapping("pagePromotionActivity")
|
||||
public CommonResult<PageResult<PromotionActivityRespDTO>> pagePromotionActivity(@RequestBody PromotionActivityPageReqDTO pageReqDTO) {
|
||||
return success(promotionActivityManager.pagePromotionActivity(pageReqDTO));
|
||||
}
|
||||
@PostMapping("listPromotionActivities")
|
||||
public CommonResult<List<PromotionActivityRespDTO>> listPromotionActivities(@RequestBody PromotionActivityListReqDTO listReqDTO) {
|
||||
return success(promotionActivityManager.listPromotionActivities(listReqDTO));
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.convert.activity;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
|
||||
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity.PromotionActivityDO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PromotionActivityConvert {
|
||||
|
||||
PromotionActivityConvert INSTANCE = Mappers.getMapper(PromotionActivityConvert.class);
|
||||
|
||||
List<PromotionActivityRespDTO> convertList(List<PromotionActivityDO> list);
|
||||
|
||||
@Mapping(source = "records", target = "list")
|
||||
PageResult<PromotionActivityRespDTO> convertPage(IPage<PromotionActivityDO> page);
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.convert.recommend;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendCreateReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendRespDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendUpdateReqDTO;
|
||||
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.recommend.ProductRecommendDO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductRecommendConvert {
|
||||
|
||||
ProductRecommendConvert INSTANCE = Mappers.getMapper(ProductRecommendConvert.class);
|
||||
|
||||
List<ProductRecommendRespDTO> convertList(List<ProductRecommendDO> list);
|
||||
|
||||
@Mapping(source = "records", target = "list")
|
||||
PageResult<ProductRecommendRespDTO> convertPage(IPage<ProductRecommendDO> page);
|
||||
|
||||
ProductRecommendDO convert(ProductRecommendCreateReqDTO bean);
|
||||
|
||||
ProductRecommendDO convert(ProductRecommendUpdateReqDTO bean);
|
||||
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.activity;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityStatusEnum;
|
||||
import cn.iocoder.mall.promotion.api.enums.activity.PromotionActivityTypeEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 促销活动 DO
|
||||
*/
|
||||
@TableName(value = "promotion_activity", autoResultMap = true)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class PromotionActivityDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 活动编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 活动标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 活动类型
|
||||
*
|
||||
* 参见 {@link PromotionActivityTypeEnum} 枚举
|
||||
*/
|
||||
private Integer activityType;
|
||||
// /**
|
||||
// * 促销类型
|
||||
// * // TODO 芋艿 https://jos.jd.com/api/complexTemplate.htm?webPamer=promotion_v_o&groupName=%E4%BF%83%E9%94%80API&id=54&restName=jingdong.seller.promotion.list&isMulti=false 促销类型,可选值:单品促销(1),赠品促销(4),套装促销(6),总价促销(10)
|
||||
// */
|
||||
// private Integer promotionType;
|
||||
/**
|
||||
* 活动状态
|
||||
*
|
||||
* 参见 {@link PromotionActivityStatusEnum} 枚举
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private Date startTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private Date endTime;
|
||||
/**
|
||||
* 失效时间
|
||||
*/
|
||||
private Date invalidTime;
|
||||
/**
|
||||
* 删除时间
|
||||
*/
|
||||
private Date deleteTime;
|
||||
/**
|
||||
* 限制折扣字符串,使用 JSON 序列化成字符串存储
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
private TimeLimitedDiscount timeLimitedDiscount;
|
||||
/**
|
||||
* 满减送字符串,使用 JSON 序列化成字符串存储
|
||||
*/
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||
private FullPrivilege fullPrivilege;
|
||||
|
||||
/**
|
||||
* 限制折扣
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class TimeLimitedDiscount {
|
||||
|
||||
/**
|
||||
* 商品折扣
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Item {
|
||||
|
||||
/**
|
||||
* 商品 SPU 编号
|
||||
*/
|
||||
private Integer spuId;
|
||||
/**
|
||||
* 优惠类型
|
||||
*/
|
||||
private Integer preferentialType;
|
||||
/**
|
||||
* 优惠值
|
||||
*/
|
||||
private Integer preferentialValue;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 每人每种限购多少
|
||||
*
|
||||
* 当 quota = 0 时,表示不限购
|
||||
*/
|
||||
private Integer quota;
|
||||
/**
|
||||
* 商品折扣数组
|
||||
*/
|
||||
private List<Item> items;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 满减送
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class FullPrivilege {
|
||||
|
||||
/**
|
||||
* 优惠
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Privilege {
|
||||
|
||||
/**
|
||||
* 满足类型
|
||||
*
|
||||
* 1 - 金额
|
||||
* 2 - 件数
|
||||
*/
|
||||
private Integer meetType;
|
||||
/**
|
||||
* 满足值
|
||||
*/
|
||||
private Integer meetValue;
|
||||
/**
|
||||
* 优惠类型
|
||||
*/
|
||||
private Integer preferentialType;
|
||||
/**
|
||||
* 优惠值
|
||||
*/
|
||||
private Integer preferentialValue;
|
||||
// /**
|
||||
// * 是否包邮
|
||||
// */
|
||||
// private Boolean isPostage;
|
||||
// /**
|
||||
// * 积分
|
||||
// */
|
||||
// private Integer score;
|
||||
// /**
|
||||
// * 优惠劵(码)分组编号
|
||||
// */
|
||||
// private Integer couponTemplateId;
|
||||
// /**
|
||||
// * 优惠劵(码)数量
|
||||
// */
|
||||
// private Integer couponNum;
|
||||
// /**
|
||||
// * 赠品编号
|
||||
// */
|
||||
// private Integer presentId;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 可用范围的类型
|
||||
*
|
||||
* 参见 {@link cn.iocoder.mall.promotion.api.enums.RangeTypeEnum} 枚举
|
||||
* 暂时只用 “所有可用” + “PRODUCT_INCLUDE_PRT”
|
||||
*/
|
||||
private Integer rangeType;
|
||||
/**
|
||||
* 指定可用商品列表
|
||||
*/
|
||||
private List<Integer> rangeValues;
|
||||
/**
|
||||
* 是否循环
|
||||
*/
|
||||
private Boolean cycled;
|
||||
/**
|
||||
* 优惠数组
|
||||
*/
|
||||
private List<Privilege> privileges;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.dal.mysql.dataobject.recommend;
|
||||
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
|
||||
import cn.iocoder.mall.promotion.api.enums.recommend.ProductRecommendTypeEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品推荐 DO
|
||||
*/
|
||||
@TableName("product_recommend")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductRecommendDO extends DeletableDO {
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 类型
|
||||
*
|
||||
* {@link ProductRecommendTypeEnum}
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 商品 Spu 编号
|
||||
*/
|
||||
private Integer productSpuId;
|
||||
// TODO 芋艿,商品 spu 名
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* {@link cn.iocoder.common.framework.enums.CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String memo;
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.dal.mysql.mapper.recommend;
|
||||
|
||||
import cn.iocoder.mall.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendListReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.ProductRecommendPageReqDTO;
|
||||
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.recommend.ProductRecommendDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ProductRecommendMapper extends BaseMapper<ProductRecommendDO> {
|
||||
|
||||
default ProductRecommendDO selectByProductSpuIdAndType(Integer productSpuId, Integer type) {
|
||||
return selectOne(new QueryWrapper<ProductRecommendDO>().eq("product_spu_id", productSpuId)
|
||||
.eq("type", type));
|
||||
}
|
||||
|
||||
default IPage<ProductRecommendDO> selectPage(ProductRecommendPageReqDTO pageReqDTO) {
|
||||
return selectPage(new Page<>(pageReqDTO.getPageNo(), pageReqDTO.getPageSize()),
|
||||
new QueryWrapperX<ProductRecommendDO>().eqIfPresent("type", pageReqDTO.getType()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.manager.activity;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityListReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityPageReqDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.activity.dto.PromotionActivityRespDTO;
|
||||
import cn.iocoder.mall.promotionservice.service.activity.PromotionActivityService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 促销活动 Manager
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class PromotionActivityManager {
|
||||
|
||||
@Autowired
|
||||
private PromotionActivityService promotionActivityService;
|
||||
|
||||
public List<PromotionActivityRespDTO> listPromotionActivities(PromotionActivityListReqDTO listReqDTO) {
|
||||
return promotionActivityService.listPromotionActivities(listReqDTO);
|
||||
}
|
||||
|
||||
public PageResult<PromotionActivityRespDTO> pagePromotionActivity(PromotionActivityPageReqDTO pageReqDTO) {
|
||||
return promotionActivityService.pagePromotionActivity(pageReqDTO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.manager.recommend;
|
||||
|
||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.ProductSpuFeign;
|
||||
import cn.iocoder.mall.productservice.rpc.spu.dto.ProductSpuRespDTO;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.*;
|
||||
import cn.iocoder.mall.promotionservice.service.recommend.ProductRecommendService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants.PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 商品推荐 Manager
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ProductRecommendManager {
|
||||
|
||||
@Autowired
|
||||
private ProductSpuFeign productSpuFeign;
|
||||
|
||||
@Autowired
|
||||
private ProductRecommendService productRecommendService;
|
||||
|
||||
public List<ProductRecommendRespDTO> listProductRecommends(ProductRecommendListReqDTO listReqDTO) {
|
||||
return productRecommendService.listProductRecommends(listReqDTO);
|
||||
}
|
||||
|
||||
public PageResult<ProductRecommendRespDTO> pageProductRecommend(ProductRecommendPageReqDTO pageReqDTO) {
|
||||
return productRecommendService.pageProductRecommend(pageReqDTO);
|
||||
}
|
||||
|
||||
public Integer createProductRecommend(ProductRecommendCreateReqDTO createReqDTO) {
|
||||
// 校验商品不存在
|
||||
checkProductSpu(createReqDTO.getProductSpuId());
|
||||
// 创建商品推荐
|
||||
return productRecommendService.createProductRecommend(createReqDTO);
|
||||
}
|
||||
|
||||
public void updateProductRecommend(ProductRecommendUpdateReqDTO updateReqDTO) {
|
||||
// 校验商品不存在
|
||||
checkProductSpu(updateReqDTO.getProductSpuId());
|
||||
// 更新商品推荐
|
||||
productRecommendService.updateProductRecommend(updateReqDTO);
|
||||
}
|
||||
|
||||
public void deleteProductRecommend(Integer productRecommendId) {
|
||||
productRecommendService.deleteProductRecommend(productRecommendId);
|
||||
}
|
||||
|
||||
private void checkProductSpu(Integer productSpuId) {
|
||||
CommonResult<ProductSpuRespDTO> getProductSpuResult = productSpuFeign.getProductSpu(productSpuId);
|
||||
getProductSpuResult.checkError();
|
||||
if (getProductSpuResult.getData() == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_PRODUCT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package cn.iocoder.mall.promotionservice.service.recommend;
|
||||
|
||||
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.promotion.api.rpc.recommend.dto.*;
|
||||
import cn.iocoder.mall.promotionservice.convert.recommend.ProductRecommendConvert;
|
||||
import cn.iocoder.mall.promotionservice.dal.mysql.dataobject.recommend.ProductRecommendDO;
|
||||
import cn.iocoder.mall.promotionservice.dal.mysql.mapper.recommend.ProductRecommendMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants.PRODUCT_RECOMMEND_EXISTS;
|
||||
import static cn.iocoder.mall.promotion.api.enums.PromotionErrorCodeConstants.PRODUCT_RECOMMEND_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 商品推荐 Service
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ProductRecommendService {
|
||||
|
||||
@Autowired
|
||||
private ProductRecommendMapper productRecommendMapper;
|
||||
|
||||
/**
|
||||
* 获得商品推荐列表
|
||||
*
|
||||
* @param listReqDTO 列表查询 DTO
|
||||
* @return 商品推荐列表
|
||||
*/
|
||||
public List<ProductRecommendRespDTO> listProductRecommends(ProductRecommendListReqDTO listReqDTO) {
|
||||
List<ProductRecommendDO> productRecommends = productRecommendMapper.selectList(listReqDTO);
|
||||
return ProductRecommendConvert.INSTANCE.convertList(productRecommends);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得商品推荐分页
|
||||
*
|
||||
* @param pageReqDTO 分页查询 DTO
|
||||
* @return 商品推荐分页
|
||||
*/
|
||||
public PageResult<ProductRecommendRespDTO> pageProductRecommend(ProductRecommendPageReqDTO pageReqDTO) {
|
||||
IPage<ProductRecommendDO> productRecommendPage = productRecommendMapper.selectPage(pageReqDTO);
|
||||
return ProductRecommendConvert.INSTANCE.convertPage(productRecommendPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品推荐
|
||||
*
|
||||
* @param createReqDTO 商品推荐信息
|
||||
* @return 商品推荐编号
|
||||
*/
|
||||
public Integer createProductRecommend(ProductRecommendCreateReqDTO createReqDTO) {
|
||||
// 校验商品是否已经推荐
|
||||
if (productRecommendMapper.selectByProductSpuIdAndType(createReqDTO.getProductSpuId(), createReqDTO.getType()) != null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_EXISTS);
|
||||
}
|
||||
// 保存到数据库
|
||||
ProductRecommendDO productRecommend = ProductRecommendConvert.INSTANCE.convert(createReqDTO);
|
||||
productRecommendMapper.insert(productRecommend);
|
||||
// 返回成功
|
||||
return productRecommend.getId();
|
||||
}
|
||||
|
||||
public void updateProductRecommend(ProductRecommendUpdateReqDTO updateReqDTO) {
|
||||
// 校验更新的商品推荐存在
|
||||
if (productRecommendMapper.selectById(updateReqDTO.getId()) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_NOT_EXISTS);
|
||||
}
|
||||
// 校验商品是否已经推荐
|
||||
ProductRecommendDO existProductRecommend = productRecommendMapper.selectByProductSpuIdAndType(updateReqDTO.getProductSpuId(), updateReqDTO.getType());
|
||||
if (existProductRecommend != null && !existProductRecommend.getId().equals(updateReqDTO.getId())) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_EXISTS.getCode());
|
||||
}
|
||||
// 更新到数据库
|
||||
ProductRecommendDO updateProductRecommend = ProductRecommendConvert.INSTANCE.convert(updateReqDTO);
|
||||
productRecommendMapper.updateById(updateProductRecommend);
|
||||
}
|
||||
|
||||
public void deleteProductRecommend(Integer productRecommendId) {
|
||||
// 校验更新的商品推荐存在
|
||||
if (productRecommendMapper.selectById(productRecommendId) == null) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCT_RECOMMEND_NOT_EXISTS);
|
||||
}
|
||||
// 更新到数据库
|
||||
productRecommendMapper.deleteById(productRecommendId);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user