|
@@ -1,5 +1,8 @@
|
|
|
package com.fs.live.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
@@ -426,47 +429,54 @@ public class LiveDataServiceImpl extends ServiceImpl<LiveDataMapper, LiveData> i
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 收藏商品默认收藏直播间和店铺
|
|
|
- * 收藏店铺默认收藏直播间
|
|
|
- * 取消收藏店铺默认取消收藏商品
|
|
|
- * */
|
|
|
+ * 收藏/取消收藏店铺
|
|
|
+ */
|
|
|
@Override
|
|
|
- public String collectStore(Long storeId, Long productId, Long liveId, Long userId) {
|
|
|
- if(liveId==null&&storeId==null){
|
|
|
- return "未知的产品或店铺";
|
|
|
+ public String collectStore(Long userId, Long storeId) {
|
|
|
+ return toggleFavorite(userId, storeId, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用收藏切换方法
|
|
|
+ */
|
|
|
+ private String toggleFavorite(Long userId, Long storeId, Long productId) {
|
|
|
+ LambdaQueryWrapper<LiveUserFavorite> wrapper = Wrappers.<LiveUserFavorite>lambdaQuery()
|
|
|
+ .eq(LiveUserFavorite::getUserId, userId);
|
|
|
+
|
|
|
+ if (storeId != null) {
|
|
|
+ wrapper.eq(LiveUserFavorite::getStoreId, storeId);
|
|
|
}
|
|
|
- //判断是收藏店铺还是收藏产品
|
|
|
if (productId != null) {
|
|
|
- //查询用户是否收藏过该产品
|
|
|
- List<LiveUserFavorite> liveUserFavorites = liveUserFavoriteService.selectByIds(productId, storeId, liveId, userId);
|
|
|
- if (liveUserFavorites != null && !liveUserFavorites.isEmpty()) {
|
|
|
- liveUserFavoriteService.deleteLiveUserFavoriteByIds(productId,storeId,liveId,userId);
|
|
|
- return "取消收藏成功";
|
|
|
- }
|
|
|
- LiveUserFavorite liveUserFavorite = new LiveUserFavorite();
|
|
|
- liveUserFavorite.setProductId(productId);
|
|
|
- liveUserFavorite.setStoreId(storeId);
|
|
|
- liveUserFavorite.setLiveId(liveId);
|
|
|
- liveUserFavorite.setCreateTime(new Date());
|
|
|
- liveUserFavorite.setUserId(userId);
|
|
|
- liveUserFavoriteService.insertLiveUserFavorite(liveUserFavorite);
|
|
|
- return "收藏成功";
|
|
|
+ wrapper.eq(LiveUserFavorite::getProductId, productId);
|
|
|
}
|
|
|
- //查询用户是否收藏过该店铺
|
|
|
- List<LiveUserFavorite> liveUserFavorites = liveUserFavoriteService.selectByIds(null, storeId, liveId, userId);
|
|
|
- if (liveUserFavorites != null && !liveUserFavorites.isEmpty()) {
|
|
|
- liveUserFavoriteService.deleteLiveUserFavoriteByIds(null,storeId,liveId,userId);
|
|
|
+
|
|
|
+ long count = liveUserFavoriteService.count(wrapper);
|
|
|
+ if (count > 0) {
|
|
|
+ liveUserFavoriteService.remove(wrapper);
|
|
|
return "取消收藏成功";
|
|
|
}
|
|
|
- LiveUserFavorite liveUserFavorite = new LiveUserFavorite();
|
|
|
- liveUserFavorite.setStoreId(storeId);
|
|
|
- liveUserFavorite.setLiveId(liveId);
|
|
|
- liveUserFavorite.setCreateTime(new Date());
|
|
|
- liveUserFavorite.setUserId(userId);
|
|
|
- liveUserFavoriteService.insertLiveUserFavorite(liveUserFavorite);
|
|
|
+
|
|
|
+ LiveUserFavorite favorite = new LiveUserFavorite();
|
|
|
+ favorite.setUserId(userId);
|
|
|
+ if (storeId != null) {
|
|
|
+ favorite.setStoreId(storeId);
|
|
|
+ }
|
|
|
+ if (productId != null) {
|
|
|
+ favorite.setProductId(productId);
|
|
|
+ }
|
|
|
+
|
|
|
+ liveUserFavoriteService.insertLiveUserFavorite(favorite);
|
|
|
return "收藏成功";
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 收藏/取消收藏商品
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String collectProduct(Long userId, Long productId) {
|
|
|
+ return toggleFavorite(userId, null, productId);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, Object> getLiveViewData(Long liveId) {
|
|
|
Map<String, Object> liveViewData = new HashMap<>();
|