Merge branch 'master' of gitee.com:zhijiantianya/onemall
This commit is contained in:
commit
ef622fbf95
|
@ -32,6 +32,7 @@
|
|||
6. 会员资料 @nengjie
|
||||
7. 拼团购买 @大太阳
|
||||
8. 部门管理 @Tprotect曦
|
||||
9. 商品收藏 @笑笑生
|
||||
|
||||
# 演示
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
- [x] 商品列表(基于分类)
|
||||
- [ ] 商品列表(基于促销活动)
|
||||
- [x] 商品详情
|
||||
- [ ] 商品收藏【待认领】
|
||||
- [ ] 商品收藏 @笑笑生
|
||||
- 订单相关
|
||||
- [x] 下单(直接购买)
|
||||
- [x] 下单(购物车购买)
|
||||
|
|
|
@ -128,4 +128,23 @@ CREATE TABLE `users` (
|
|||
UNIQUE KEY `idx_uid` (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=108 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for user_spu_collections
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `user_spu_collections`;
|
||||
CREATE TABLE `user_spu_collections` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id自增长',
|
||||
`user_id` int(11) NOT NULL COMMENT '用户id',
|
||||
`nickname` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名称',
|
||||
`spu_id` int(11) NOT NULL COMMENT '商品id',
|
||||
`spu_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '商品名字',
|
||||
`spu_image` varchar(250) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图片名字',
|
||||
`create_time` datetime(0) NOT NULL COMMENT '创建时间',
|
||||
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
|
||||
`deleted` smallint(2) NOT NULL COMMENT '删除状态',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用户_商品_收藏记录表' ROW_FORMAT = Dynamic;
|
||||
|
||||
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package cn.iocoder.mall.product.application.controller.users;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.product.api.ProductSpuCollectionService;
|
||||
import cn.iocoder.mall.user.sdk.annotation.RequiresLogin;
|
||||
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 商品收藏接口
|
||||
* @author xiaofeng
|
||||
* @date 2019/07/01 23:21
|
||||
* @version 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("users/spu")
|
||||
@Api("商品收藏")
|
||||
public class UsersProductSpuCollectionController {
|
||||
|
||||
@Reference(validation = "true", version = "${dubbo.provider.ProductSpuCollectionService.version}")
|
||||
private ProductSpuCollectionService productSpuCollectionService;
|
||||
|
||||
@PostMapping("/collection/{spuId}/{hasCollectionType}")
|
||||
@ApiOperation("商品收藏")
|
||||
// @RequiresLogin
|
||||
public CommonResult<Boolean> productSpuCollection(@PathVariable("spuId") Integer spuId,
|
||||
@PathVariable("hasCollectionType") Integer hasCollectionType) {
|
||||
// final Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||
|
||||
return success(productSpuCollectionService.productSpuCollection(spuId, hasCollectionType,140));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cn.iocoder.mall.product.api;
|
||||
|
||||
/**
|
||||
* 商品收藏
|
||||
* @author xiaofeng
|
||||
* @date 2019/07/01 23:13
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface ProductSpuCollectionService {
|
||||
|
||||
/**
|
||||
* 商品收藏
|
||||
* @param spuId
|
||||
* @param hasCollectionType 1 商品收藏 2 取消收藏
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
boolean productSpuCollection(Integer spuId,Integer hasCollectionType,Integer userId);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package cn.iocoder.mall.product.api.message;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 商品收藏或取消收藏时发送消息
|
||||
* @author xiaofeng
|
||||
* @date 2019/07/01 22:33
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ProductSpuCollectionMessage {
|
||||
|
||||
public static final String TOPIC = "ProductSpuCollection";
|
||||
|
||||
/**
|
||||
* SPU 编号
|
||||
*/
|
||||
private Integer spuId;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Integer userId;
|
||||
|
||||
// ========== 基本信息 =========
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
private String spuName;
|
||||
|
||||
|
||||
/**
|
||||
* 商品图片
|
||||
*/
|
||||
private String spuImage;
|
||||
|
||||
/**
|
||||
* 1 收藏 2 取消
|
||||
*/
|
||||
private Integer hasCollectionType;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package cn.iocoder.mall.product.service;
|
||||
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.mall.product.api.ProductSpuCollectionService;
|
||||
import cn.iocoder.mall.product.api.constant.ProductErrorCodeEnum;
|
||||
import cn.iocoder.mall.product.api.message.ProductSpuCollectionMessage;
|
||||
import cn.iocoder.mall.product.dao.ProductSpuMapper;
|
||||
import cn.iocoder.mall.product.dataobject.ProductSpuDO;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* ProductSpuCollectionServiceImpl
|
||||
* @author xiaofeng
|
||||
* @date 2019/07/01 23:14
|
||||
* @version 1.0
|
||||
*/
|
||||
@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示
|
||||
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.ProductSpuCollectionService.version}")
|
||||
public class ProductSpuCollectionServiceImpl implements ProductSpuCollectionService {
|
||||
|
||||
@Autowired
|
||||
private ProductSpuMapper productSpuMapper;
|
||||
|
||||
@Resource
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean productSpuCollection(Integer spuId, Integer hasCollectionType, Integer userId) {
|
||||
ProductSpuDO productSpuDO = this.productSpuMapper.selectById(spuId);
|
||||
// 校验 Spu 是否存在
|
||||
if (productSpuDO == null) {
|
||||
throw ServiceExceptionUtil.exception(ProductErrorCodeEnum.PRODUCT_SPU_NOT_EXISTS.getCode());
|
||||
}
|
||||
this.sendProductSpuCollectionMessage(productSpuDO, hasCollectionType, userId);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送商品收藏或取消消息
|
||||
* @param productSpuDO
|
||||
* @param hasCollectionType
|
||||
*/
|
||||
private void sendProductSpuCollectionMessage(final ProductSpuDO productSpuDO, final Integer hasCollectionType,
|
||||
final Integer userId) {
|
||||
ProductSpuCollectionMessage productSpuCollectionMessage = new ProductSpuCollectionMessage()
|
||||
.setSpuId(productSpuDO.getId()).setSpuName(productSpuDO.getName())
|
||||
.setSpuImage(productSpuDO.getPicUrls()).setHasCollectionType(hasCollectionType)
|
||||
.setUserId(userId);
|
||||
rocketMQTemplate.convertAndSend(ProductSpuCollectionMessage.TOPIC, productSpuCollectionMessage);
|
||||
}
|
||||
}
|
|
@ -35,6 +35,8 @@ dubbo:
|
|||
version: 1.0.0
|
||||
OAuth2Service:
|
||||
version: 1.0.0
|
||||
ProductSpuCollectionService:
|
||||
version: 1.0.0
|
||||
|
||||
# rocketmq
|
||||
rocketmq:
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package cn.iocoder.mall.user.api;
|
||||
|
||||
import cn.iocoder.mall.user.api.bo.UserProductSpuCollectionsBO;
|
||||
import cn.iocoder.mall.user.api.dto.UserProductSpuCollectionsAddDTO;
|
||||
import cn.iocoder.mall.user.api.dto.UserProductSpuCollectionsUpdateDTO;
|
||||
|
||||
/**
|
||||
* UserProductSpuCollectionsService
|
||||
* @author xiaofeng
|
||||
* @date 2019/07/01 20:27
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface UserProductSpuCollectionsService {
|
||||
|
||||
/**
|
||||
* 添加商品收藏
|
||||
* @return
|
||||
*/
|
||||
int addUserSkuCollections(UserProductSpuCollectionsAddDTO userProductSpuCollectionsAddDTO);
|
||||
|
||||
/**
|
||||
* 获取用户商品收藏
|
||||
* @param userId 用户ID
|
||||
* @param spuId 商品ID
|
||||
* @return
|
||||
*/
|
||||
UserProductSpuCollectionsBO getUserSpuCollectionsByUserIdAndSpuId(Integer userId, Integer spuId);
|
||||
|
||||
/**
|
||||
* 取消商品收藏
|
||||
* @param userProductSpuCollectionsUpdateDTO
|
||||
* @return
|
||||
*/
|
||||
int updateUserProductSpuCollections(UserProductSpuCollectionsUpdateDTO userProductSpuCollectionsUpdateDTO);
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package cn.iocoder.mall.user.api.bo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户_商品_收藏记录表
|
||||
* @author xiaofeng
|
||||
* @date 2019-07-01 20:23:30
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserProductSpuCollectionsBO implements Serializable {
|
||||
|
||||
/**
|
||||
* id自增长
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Integer userId;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Integer spuId;
|
||||
|
||||
/**
|
||||
* 商品名字
|
||||
*/
|
||||
private String spuName;
|
||||
|
||||
/**
|
||||
* 图片名字
|
||||
*/
|
||||
private String spuImage;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 删除状态
|
||||
*/
|
||||
private Integer deleted;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package cn.iocoder.mall.user.api.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 添加商品收藏参数
|
||||
* @author xiaofeng
|
||||
* @date 2019/07/01 20:38
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserProductSpuCollectionsAddDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* id自增长
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Integer userId;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Integer spuId;
|
||||
|
||||
/**
|
||||
* 商品名字
|
||||
*/
|
||||
private String spuName;
|
||||
|
||||
/**
|
||||
* 图片名字
|
||||
*/
|
||||
private String spuImage;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 删除状态
|
||||
*/
|
||||
private Integer deleted;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package cn.iocoder.mall.user.api.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 更新商品收藏参数
|
||||
* @author xiaofeng
|
||||
* @date 2019/07/01 20:38
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserProductSpuCollectionsUpdateDTO implements Serializable {
|
||||
|
||||
/**
|
||||
* id自增长
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 删除状态
|
||||
*/
|
||||
private Integer deleted;
|
||||
|
||||
|
||||
}
|
|
@ -17,6 +17,12 @@
|
|||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>product-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- DB 相关 -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
|
@ -67,6 +73,12 @@
|
|||
<artifactId>curator-framework</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MQ 相关 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.rocketmq</groupId>
|
||||
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
package cn.iocoder.mall.user.biz.convert;
|
||||
|
||||
import cn.iocoder.mall.product.api.message.ProductSpuCollectionMessage;
|
||||
import cn.iocoder.mall.user.api.bo.UserProductSpuCollectionsBO;
|
||||
import cn.iocoder.mall.user.api.dto.UserProductSpuCollectionsAddDTO;
|
||||
import cn.iocoder.mall.user.api.dto.UserProductSpuCollectionsUpdateDTO;
|
||||
import cn.iocoder.mall.user.biz.dataobject.UserProductSpuCollectionsDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户_商品_收藏记录表
|
||||
*
|
||||
* @author xiaofeng
|
||||
* @date 2019-07-01 20:23:30
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserProductSpuCollectionsConvert {
|
||||
|
||||
UserProductSpuCollectionsConvert INSTANCE = Mappers.getMapper(UserProductSpuCollectionsConvert.class);
|
||||
|
||||
/**
|
||||
* DTO convert DO
|
||||
* @param userSkuCollectionsAddDTO
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
UserProductSpuCollectionsDO convert(UserProductSpuCollectionsAddDTO userSkuCollectionsAddDTO);
|
||||
|
||||
/**
|
||||
* update DTO convert DO
|
||||
* @param userProductSpuCollectionsUpdateDTO
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
UserProductSpuCollectionsDO convert(UserProductSpuCollectionsUpdateDTO userProductSpuCollectionsUpdateDTO);
|
||||
|
||||
/**
|
||||
* DO Convert BO
|
||||
* @param userSkuCollectionsDO
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
UserProductSpuCollectionsBO convert(UserProductSpuCollectionsDO userSkuCollectionsDO);
|
||||
|
||||
/**
|
||||
* DO List convert BO LIST
|
||||
* @param userSkuCollectionsDOS
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
List<UserProductSpuCollectionsBO> convert(List<UserProductSpuCollectionsDO> userSkuCollectionsDOS);
|
||||
|
||||
/**
|
||||
* 消处数据转换
|
||||
* @param productSpuCollectionMessage
|
||||
* @return
|
||||
*/
|
||||
@Mappings({})
|
||||
UserProductSpuCollectionsAddDTO convert(ProductSpuCollectionMessage productSpuCollectionMessage);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package cn.iocoder.mall.user.biz.dao;
|
||||
|
||||
import cn.iocoder.mall.user.biz.dataobject.UserProductSpuCollectionsDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 用户_商品_收藏记录表
|
||||
*
|
||||
* @author xiaofeng
|
||||
* @date 2019-07-01 20:23:30
|
||||
*/
|
||||
public interface UserProductSpuCollectionsMapper extends BaseMapper<UserProductSpuCollectionsDO> {
|
||||
|
||||
/**
|
||||
* 根据用户id 和 spuId 查找用户商品收藏
|
||||
* @param userId
|
||||
* @param spuId
|
||||
* @return
|
||||
*/
|
||||
default UserProductSpuCollectionsDO getUserSpuCollectionsByUserIdAndSpuId(final Integer userId,
|
||||
final Integer spuId) {
|
||||
QueryWrapper<UserProductSpuCollectionsDO> query = new QueryWrapper<UserProductSpuCollectionsDO>()
|
||||
.eq("user_id", userId).eq("spu_id", spuId);
|
||||
return selectOne(query);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package cn.iocoder.mall.user.biz.dataobject;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 用户_商品_收藏记录表
|
||||
*
|
||||
* @author xiaofeng
|
||||
* @date 2019-07-01 20:23:30
|
||||
*/
|
||||
@TableName("user_spu_collections")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserProductSpuCollectionsDO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id自增长
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Integer userId;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Integer spuId;
|
||||
|
||||
/**
|
||||
* 商品名字
|
||||
*/
|
||||
private String spuName;
|
||||
|
||||
/**
|
||||
* 图片名字
|
||||
*/
|
||||
private String spuImage;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 删除状态
|
||||
*/
|
||||
private Integer deleted;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package cn.iocoder.mall.user.biz.mq;
|
||||
|
||||
import cn.iocoder.common.framework.constant.DeletedStatusEnum;
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.mall.product.api.message.ProductSpuCollectionMessage;
|
||||
import cn.iocoder.mall.user.api.UserProductSpuCollectionsService;
|
||||
import cn.iocoder.mall.user.api.UserService;
|
||||
import cn.iocoder.mall.user.api.bo.UserBO;
|
||||
import cn.iocoder.mall.user.api.bo.UserProductSpuCollectionsBO;
|
||||
import cn.iocoder.mall.user.api.constant.UserErrorCodeEnum;
|
||||
import cn.iocoder.mall.user.api.dto.UserProductSpuCollectionsAddDTO;
|
||||
import cn.iocoder.mall.user.api.dto.UserProductSpuCollectionsUpdateDTO;
|
||||
import cn.iocoder.mall.user.biz.convert.UserProductSpuCollectionsConvert;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
||||
import org.apache.rocketmq.spring.core.RocketMQListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 商品收藏 消费者
|
||||
* @author xiaofeng
|
||||
* @date 2019/07/02 19:57
|
||||
* @version 1.0
|
||||
*/
|
||||
@Service
|
||||
@RocketMQMessageListener(topic = ProductSpuCollectionMessage.TOPIC, consumerGroup = "product-spu-consumer-group-"
|
||||
+ ProductSpuCollectionMessage.TOPIC)
|
||||
public class UserProductSpuCollectionsConsumer implements RocketMQListener<ProductSpuCollectionMessage> {
|
||||
|
||||
@Autowired
|
||||
private UserProductSpuCollectionsService userProductSpuCollectionsService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
public void onMessage(ProductSpuCollectionMessage productSpuCollectionMessage) {
|
||||
UserBO userBO = userService.getUser(productSpuCollectionMessage.getUserId());
|
||||
if (userBO == null) {
|
||||
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_NOT_EXISTS.getCode());
|
||||
}
|
||||
// 收藏
|
||||
if (productSpuCollectionMessage.getHasCollectionType().equals(1)) {
|
||||
this.saveUserProductSpuCollections(productSpuCollectionMessage, userBO.getNickname());
|
||||
} else if (productSpuCollectionMessage.getHasCollectionType().equals(2)) {
|
||||
// 取消收藏
|
||||
this.deleteUserProductSpuCollections(productSpuCollectionMessage.getUserId(),
|
||||
productSpuCollectionMessage.getSpuId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存商品收藏
|
||||
* @param productSpuCollectionMessage
|
||||
* @param nickname
|
||||
* @return
|
||||
*/
|
||||
private int saveUserProductSpuCollections(final ProductSpuCollectionMessage productSpuCollectionMessage,
|
||||
final String nickname) {
|
||||
int result = 0;
|
||||
UserProductSpuCollectionsBO userProductSpuCollectionsBO = this.userProductSpuCollectionsService
|
||||
.getUserSpuCollectionsByUserIdAndSpuId(productSpuCollectionMessage.getUserId(),
|
||||
productSpuCollectionMessage.getSpuId());
|
||||
if (userProductSpuCollectionsBO == null) {
|
||||
UserProductSpuCollectionsAddDTO userProductSpuCollectionsAddDTO = UserProductSpuCollectionsConvert.INSTANCE
|
||||
.convert(productSpuCollectionMessage);
|
||||
userProductSpuCollectionsAddDTO.setNickname(StringUtils.isEmpty(nickname) ? "" : nickname);
|
||||
userProductSpuCollectionsAddDTO.setCreateTime(new Date());
|
||||
userProductSpuCollectionsAddDTO.setDeleted(DeletedStatusEnum.DELETED_NO.getValue());
|
||||
result = userProductSpuCollectionsService.addUserSkuCollections(userProductSpuCollectionsAddDTO);
|
||||
} else {
|
||||
// 存在重新收藏
|
||||
if (userProductSpuCollectionsBO.getDeleted().equals(DeletedStatusEnum.DELETED_YES.getValue())) {
|
||||
UserProductSpuCollectionsUpdateDTO userProductSpuCollectionsUpdateDTO = this
|
||||
.setUserProductSpuCollectionsUpdateDTO(userProductSpuCollectionsBO.getId(),
|
||||
DeletedStatusEnum.DELETED_NO);
|
||||
result = this.userProductSpuCollectionsService
|
||||
.updateUserProductSpuCollections(userProductSpuCollectionsUpdateDTO);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消收藏
|
||||
* @param userId
|
||||
* @param spuId
|
||||
* @return
|
||||
*/
|
||||
private int deleteUserProductSpuCollections(final Integer userId, final Integer spuId) {
|
||||
UserProductSpuCollectionsBO userProductSpuCollectionsBO = this.userProductSpuCollectionsService
|
||||
.getUserSpuCollectionsByUserIdAndSpuId(userId, spuId);
|
||||
int result = 0;
|
||||
if (userProductSpuCollectionsBO != null) {
|
||||
// 未取消收藏的数据
|
||||
if (userProductSpuCollectionsBO.getDeleted().equals(DeletedStatusEnum.DELETED_NO.getValue())) {
|
||||
UserProductSpuCollectionsUpdateDTO userProductSpuCollectionsUpdateDTO = this
|
||||
.setUserProductSpuCollectionsUpdateDTO(userProductSpuCollectionsBO.getId(),
|
||||
DeletedStatusEnum.DELETED_YES);
|
||||
result = this.userProductSpuCollectionsService
|
||||
.updateUserProductSpuCollections(userProductSpuCollectionsUpdateDTO);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置更新值
|
||||
* @param id
|
||||
* @param deletedStatusEnum
|
||||
* @return
|
||||
*/
|
||||
private UserProductSpuCollectionsUpdateDTO setUserProductSpuCollectionsUpdateDTO(final Integer id,
|
||||
final DeletedStatusEnum deletedStatusEnum) {
|
||||
return new UserProductSpuCollectionsUpdateDTO().setId(id).setUpdateTime(new Date())
|
||||
.setDeleted(deletedStatusEnum.getValue());
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package cn.iocoder.mall.user.biz.service;
|
||||
|
||||
import cn.iocoder.mall.user.api.UserProductSpuCollectionsService;
|
||||
import cn.iocoder.mall.user.api.bo.UserProductSpuCollectionsBO;
|
||||
import cn.iocoder.mall.user.api.dto.UserProductSpuCollectionsAddDTO;
|
||||
import cn.iocoder.mall.user.api.dto.UserProductSpuCollectionsUpdateDTO;
|
||||
import cn.iocoder.mall.user.biz.convert.UserProductSpuCollectionsConvert;
|
||||
import cn.iocoder.mall.user.biz.dao.UserProductSpuCollectionsMapper;
|
||||
import cn.iocoder.mall.user.biz.dataobject.UserProductSpuCollectionsDO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* UserSkuCollectionsServiceImpl
|
||||
* @author xiaofeng
|
||||
* @date 2019/07/01 21:02
|
||||
* @version 1.0
|
||||
*/
|
||||
@Service
|
||||
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.UserProductSpuCollectionsService.version}")
|
||||
public class UserProductSpuCollectionsServiceImpl implements UserProductSpuCollectionsService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserProductSpuCollectionsMapper userProductSpuCollectionsMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public int addUserSkuCollections(UserProductSpuCollectionsAddDTO userProductSpuCollectionsAddDTO) {
|
||||
return userProductSpuCollectionsMapper
|
||||
.insert(UserProductSpuCollectionsConvert.INSTANCE.convert(userProductSpuCollectionsAddDTO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProductSpuCollectionsBO getUserSpuCollectionsByUserIdAndSpuId(Integer userId, Integer spuId) {
|
||||
UserProductSpuCollectionsDO userProductSpuCollectionsDO = userProductSpuCollectionsMapper
|
||||
.getUserSpuCollectionsByUserIdAndSpuId(userId, spuId);
|
||||
return UserProductSpuCollectionsConvert.INSTANCE.convert(userProductSpuCollectionsDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateUserProductSpuCollections(UserProductSpuCollectionsUpdateDTO userProductSpuCollectionsUpdateDTO) {
|
||||
return userProductSpuCollectionsMapper
|
||||
.updateById(UserProductSpuCollectionsConvert.INSTANCE.convert(userProductSpuCollectionsUpdateDTO));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -39,6 +39,14 @@ dubbo:
|
|||
version: 1.0.0
|
||||
UserService:
|
||||
version: 1.0.0
|
||||
UserProductSpuCollectionsService:
|
||||
version: 1.0.0
|
||||
consumer:
|
||||
OAuth2Service:
|
||||
version: 1.0.0
|
||||
|
||||
# rocketmq
|
||||
rocketmq:
|
||||
name-server: 127.0.0.1:9876
|
||||
producer:
|
||||
group: user-producer-spu-collection-group
|
||||
|
|
Loading…
Reference in New Issue