| | |
| | | package cc.mrbird.febs.video.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.AppContants; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.video.conversion.VideoConversion; |
| | | import cc.mrbird.febs.video.conversion.VideoMemberConversion; |
| | | import cc.mrbird.febs.video.dto.ApiVideoCollectionDto; |
| | | import cc.mrbird.febs.video.dto.ApiVideoLikeDto; |
| | | import cc.mrbird.febs.video.dto.VideoListDto; |
| | | import cc.mrbird.febs.video.entity.*; |
| | | import cc.mrbird.febs.video.mapper.*; |
| | |
| | | import cc.mrbird.febs.video.vo.VideoListVo; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.core.*; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | private final VideoMasterItemsMapper videoMasterItemsMapper; |
| | | private final VideoMasterSourceMapper videoMasterSourceMapper; |
| | | private final VideoMasterDataMapper videoMasterDataMapper; |
| | | private final VideoCollectionMapper videoCollectionMapper; |
| | | private final VideoCommentInfoMapper videoCommentInfoMapper; |
| | | private final VideoCommentLikeMapper videoCommentLikeMapper; |
| | | private final VideoMemberMapper videoMemberMapper; |
| | | |
| | | @Override |
| | |
| | | videoInfoVo.setTimeLength(currentItem.getTimeLength()); |
| | | return videoInfoVo; |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse videoCollection(ApiVideoCollectionDto apiVideoCollectionDto) { |
| | | Long id = LoginUserUtil.getLoginUser().getId(); |
| | | Long videoId = apiVideoCollectionDto.getVideoId(); |
| | | VideoMasterInfoEntity videoMasterInfoEntity = this.baseMapper.selectById(videoId); |
| | | if(videoMasterInfoEntity == null){ |
| | | throw new FebsException("视频不存在"); |
| | | } |
| | | VideoCollectionEntity videoCollection = videoCollectionMapper.selectVideoCollectionByVideoIdAndMemberId(videoId, id); |
| | | if(videoCollection != null){ |
| | | videoCollectionMapper.deleteById(videoCollection.getId()); |
| | | |
| | | //收藏数-1 |
| | | VideoMasterDataEntity videoMasterDataEntity = videoMasterDataMapper.selectDataByMasterId(videoId); |
| | | int collectCnt = videoMasterDataEntity.getCollectCnt(); |
| | | videoMasterDataEntity.setCollectCnt((collectCnt - 1) <= 0 ? 0:(collectCnt - 1)); |
| | | videoMasterDataMapper.updateById(videoMasterDataEntity); |
| | | return new FebsResponse().success().message("已取消收藏"); |
| | | }else{ |
| | | VideoCollectionEntity videoCollectionEntity = new VideoCollectionEntity(); |
| | | videoCollectionEntity.setMemberId(id); |
| | | videoCollectionEntity.setVideoId(videoId); |
| | | videoCollectionMapper.insert(videoCollectionEntity); |
| | | //收藏数+1 |
| | | VideoMasterDataEntity videoMasterDataEntity = videoMasterDataMapper.selectDataByMasterId(videoId); |
| | | int collectCnt = videoMasterDataEntity.getCollectCnt(); |
| | | videoMasterDataEntity.setCollectCnt((collectCnt + 1) <= 0 ? 0:(collectCnt + 1)); |
| | | videoMasterDataMapper.updateById(videoMasterDataEntity); |
| | | return new FebsResponse().success().message("已收藏"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse videoLike(ApiVideoLikeDto apiVideoLikeDto) { |
| | | Long id = LoginUserUtil.getLoginUser().getId(); |
| | | Integer type = apiVideoLikeDto.getType(); |
| | | Long relateId = apiVideoLikeDto.getRelateId(); |
| | | VideoCommentLikeEntity videoCommentLikeEntity = videoCommentLikeMapper.selectCommentLikeByMemberIdAndRelateId(id,relateId); |
| | | if(videoCommentLikeEntity != null){ |
| | | if(1 == type){ |
| | | //视频 |
| | | VideoMasterInfoEntity videoMasterInfoEntity = this.baseMapper.selectById(relateId); |
| | | if(videoMasterInfoEntity == null){ |
| | | throw new FebsException("视频不存在"); |
| | | } |
| | | videoCommentLikeMapper.deleteById(videoCommentLikeEntity.getId()); |
| | | //点赞数-1 |
| | | VideoMasterDataEntity videoMasterDataEntity = videoMasterDataMapper.selectDataByMasterId(relateId); |
| | | int starCnt = videoMasterDataEntity.getStarCnt(); |
| | | videoMasterDataEntity.setCollectCnt((starCnt - 1) <= 0 ? 0:(starCnt - 1)); |
| | | videoMasterDataMapper.updateById(videoMasterDataEntity); |
| | | return new FebsResponse().success().message("已取消点赞"); |
| | | }else if(2 == type){ |
| | | //评论 |
| | | VideoCommentInfoEntity videoCommentInfoEntity = videoCommentInfoMapper.selectById(relateId); |
| | | if(videoCommentInfoEntity == null){ |
| | | throw new FebsException("评论不存在"); |
| | | } |
| | | videoCommentLikeMapper.deleteById(videoCommentLikeEntity.getId()); |
| | | return new FebsResponse().success().message("已取消点赞"); |
| | | }else{ |
| | | throw new FebsException("网络繁忙"); |
| | | } |
| | | }else{ |
| | | VideoCommentLikeEntity videoCommentLike = new VideoCommentLikeEntity(); |
| | | videoCommentLike.setType(type); |
| | | videoCommentLike.setRelateId(relateId); |
| | | videoCommentLike.setMemberId(id); |
| | | videoCommentLikeMapper.insert(videoCommentLike); |
| | | //点赞数+1 |
| | | VideoMasterDataEntity videoMasterDataEntity = videoMasterDataMapper.selectDataByMasterId(relateId); |
| | | int starCnt = videoMasterDataEntity.getStarCnt(); |
| | | videoMasterDataEntity.setCollectCnt((starCnt + 1) <= 0 ? 0:(starCnt + 1)); |
| | | videoMasterDataMapper.updateById(videoMasterDataEntity); |
| | | return new FebsResponse().success().message("已点赞"); |
| | | } |
| | | |
| | | } |
| | | } |