|
@@ -5,8 +5,14 @@ import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.spring.SpringUtils;
|
|
|
import com.fs.live.domain.LiveData;
|
|
|
+import com.fs.live.domain.LiveUserFavorite;
|
|
|
+import com.fs.live.domain.LiveUserFollow;
|
|
|
+import com.fs.live.domain.LiveUserLike;
|
|
|
import com.fs.live.mapper.LiveDataMapper;
|
|
|
import com.fs.live.service.ILiveDataService;
|
|
|
+import com.fs.live.service.ILiveUserFavoriteService;
|
|
|
+import com.fs.live.service.ILiveUserFollowService;
|
|
|
+import com.fs.live.service.ILiveUserLikeService;
|
|
|
import com.fs.live.vo.ColumnsConfigVo;
|
|
|
import com.fs.live.vo.DateRange;
|
|
|
import com.fs.live.vo.RecentLiveDataVo;
|
|
@@ -18,11 +24,14 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+import static com.fs.common.constant.LiveKeysConstant.*;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 直播数据Service业务层处理
|
|
@@ -33,12 +42,21 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class LiveDataServiceImpl extends ServiceImpl<LiveDataMapper, LiveData> implements ILiveDataService {
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
|
private LiveDataMapper liveDataMapper;
|
|
|
private final RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
|
|
|
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
private final String COLUMNS_CONFIG = "columnsConfigKey";
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ILiveUserLikeService liveUserLikeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILiveUserFollowService liveUserFollowService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILiveUserFavoriteService liveUserFavoriteService;
|
|
|
/**
|
|
|
* 查询直播数据
|
|
|
*
|
|
@@ -329,6 +347,123 @@ public class LiveDataServiceImpl extends ServiceImpl<LiveDataMapper, LiveData> i
|
|
|
redisCache.deleteObject(COLUMNS_CONFIG + userId + ":");
|
|
|
redisCache.setCacheObject(COLUMNS_CONFIG + userId + ":", columns);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String updateLikeByLiveId(Long liveId, Long userId) {
|
|
|
+ //一个用户一天只能点赞十次
|
|
|
+ String key = "live:like" + liveId + ":user:" + userId+":date:"+ DateUtils.getDate();
|
|
|
+ LiveUserLike liveUserLike;
|
|
|
+ if(!redisCache.redisTemplate.hasKey(key)) {
|
|
|
+ liveUserLike = liveUserLikeService.selectLiveUserLikeByIds(liveId, userId);
|
|
|
+ if (liveUserLike == null) {
|
|
|
+ liveUserLike = new LiveUserLike();
|
|
|
+ liveUserLike.setUserId(userId);
|
|
|
+ liveUserLike.setLiveId(liveId);
|
|
|
+ liveUserLike.setCreateTime(new Date());
|
|
|
+ liveUserLikeService.insertLiveUserLike(liveUserLike);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int count =redisCache.getCacheObject(key);
|
|
|
+ if(count>=10) {
|
|
|
+ //当前时间
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ //明天0点
|
|
|
+ LocalDateTime tomorrow = now.plusDays(1).withHour(0).withMinute(0).withSecond(0);
|
|
|
+ //间隔秒
|
|
|
+ long seconds = ChronoUnit.SECONDS.between(now, tomorrow);
|
|
|
+ redisCache.expire(key, (int)seconds, TimeUnit.SECONDS);
|
|
|
+ return "每天最多为直播间点赞10次哟";
|
|
|
+ }
|
|
|
+ //用户直播间点赞数
|
|
|
+ redisCache.increment(key,1);
|
|
|
+ //直播间总点赞数
|
|
|
+ redisCache.increment("live:like:" + liveId,1);
|
|
|
+ return "点赞成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String collect(Long liveId, Long userId) {
|
|
|
+ //查询用户是否收藏过该直播间
|
|
|
+ LiveUserFavorite liveUserFavorite = liveUserFavoriteService.selectLiveUserFavoriteByLiveIdAndUserId(liveId, userId);
|
|
|
+ if (liveUserFavorite != null) {
|
|
|
+ liveUserFavoriteService.deleteLiveUserFavoriteByLiveIdAndUserId(liveId, userId);
|
|
|
+ return "取消收藏成功";
|
|
|
+ }
|
|
|
+ liveUserFavorite = new LiveUserFavorite();
|
|
|
+ liveUserFavorite.setUserId(userId);
|
|
|
+ liveUserFavorite.setLiveId(liveId);
|
|
|
+ liveUserFavorite.setCreateTime(new Date());
|
|
|
+ liveUserFavoriteService.insertLiveUserFavorite(liveUserFavorite);
|
|
|
+ return "收藏成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String follow(Long liveId, Long userId) {
|
|
|
+ LiveUserFollow liveUserFollow = liveUserFollowService.selectLiveUserFollowByLiveIdAndUserId(liveId, userId);
|
|
|
+ if (liveUserFollow != null) {
|
|
|
+ liveUserFollowService.deleteLiveUserFollowByLiveIdAndUserId(liveId, userId);
|
|
|
+ return "取消关注成功";
|
|
|
+ }
|
|
|
+ liveUserFollow = new LiveUserFollow();
|
|
|
+ liveUserFollow.setUserId(userId);
|
|
|
+ liveUserFollow.setLiveId(liveId);
|
|
|
+ liveUserFollow.setCreateTime(new Date());
|
|
|
+ liveUserFollowService.insertLiveUserFollow(liveUserFollow);
|
|
|
+ return "关注成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 收藏商品默认收藏直播间和店铺
|
|
|
+ * 收藏店铺默认收藏直播间
|
|
|
+ * 取消收藏店铺默认取消收藏商品
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public String collectStore(Long storeId, Long productId, Long liveId, Long userId) {
|
|
|
+ if(liveId==null&&storeId==null){
|
|
|
+ return "未知的产品或店铺";
|
|
|
+ }
|
|
|
+ //判断是收藏店铺还是收藏产品
|
|
|
+ if (productId != null) {
|
|
|
+ //查询用户是否收藏过该产品
|
|
|
+ LiveUserFavorite liveUserFavorite = liveUserFavoriteService.selectByIds(productId,storeId,liveId,userId);
|
|
|
+ if (liveUserFavorite != null) {
|
|
|
+ liveUserFavoriteService.deleteLiveUserFavoriteByIds(productId,storeId,liveId,userId);
|
|
|
+ return "取消收藏成功";
|
|
|
+ }
|
|
|
+ liveUserFavorite = new LiveUserFavorite();
|
|
|
+ liveUserFavorite.setProductId(productId);
|
|
|
+ liveUserFavorite.setStoreId(storeId);
|
|
|
+ liveUserFavorite.setLiveId(liveId);
|
|
|
+ liveUserFavorite.setCreateTime(new Date());
|
|
|
+ liveUserFavoriteService.insertLiveUserFavorite(liveUserFavorite);
|
|
|
+ return "收藏成功";
|
|
|
+ }
|
|
|
+ //查询用户是否收藏过该店铺
|
|
|
+ LiveUserFavorite liveUserFavorite = liveUserFavoriteService.selectByIds(null,storeId,liveId,userId);
|
|
|
+ if (liveUserFavorite != null) {
|
|
|
+ liveUserFavoriteService.deleteLiveUserFavoriteByIds(null,storeId,liveId,userId);
|
|
|
+ return "取消收藏成功";
|
|
|
+ }
|
|
|
+ liveUserFavorite = new LiveUserFavorite();
|
|
|
+ liveUserFavorite.setStoreId(storeId);
|
|
|
+ liveUserFavorite.setLiveId(liveId);
|
|
|
+ liveUserFavorite.setCreateTime(new Date());
|
|
|
+ liveUserFavoriteService.insertLiveUserFavorite(liveUserFavorite);
|
|
|
+ return "收藏成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getLiveViewData(Long liveId) {
|
|
|
+ Map<String, Object> liveViewData = new HashMap<>();
|
|
|
+ //在线人数
|
|
|
+ liveViewData.put("online", redisCache.getCacheObject(ONLINE_USERS_KEY+liveId));
|
|
|
+ //关注数
|
|
|
+ liveViewData.put("follow", baseMapper.selectLiveDataByLiveId(liveId).getFollow_num());
|
|
|
+ //点赞数
|
|
|
+ liveViewData.put("like", redisCache.getCacheObject("live:like"+liveId));
|
|
|
+ return liveViewData;
|
|
|
+ }
|
|
|
+
|
|
|
private Map<String, String> createColumn(String dataIndex, String status, String title) {
|
|
|
Map<String, String> column = new HashMap<>();
|
|
|
column.put("dataIndex", dataIndex);
|