- 前端 + 后端:商品推荐列表,增加商品名。

This commit is contained in:
YunaiV
2019-05-07 01:58:07 +08:00
parent 9a3b708738
commit ab5d051f75
17 changed files with 135 additions and 81 deletions

View File

@@ -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;
}
}