From ab07698444f013b099901a7bb1112f990a833ccc Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Fri, 17 Dec 2021 15:23:58 +0800 Subject: [PATCH] 20211216 --- src/main/java/cc/mrbird/febs/video/mapper/VideoCommentLikeMapper.java | 10 ++ src/main/java/cc/mrbird/febs/video/dto/ApiVideoLikeDto.java | 21 +++++ src/main/resources/mapper/modules/VideoCollectionMapper.xml | 10 ++ src/main/java/cc/mrbird/febs/video/mapper/VideoCommentInfoMapper.java | 7 + src/main/resources/mapper/modules/VideoCommentLikeMapper.xml | 12 +++ src/main/java/cc/mrbird/febs/video/dto/ApiVideoCollectionDto.java | 17 ++++ src/main/java/cc/mrbird/febs/video/service/impl/VideoMasterInfoServiceImpl.java | 86 +++++++++++++++++++++ src/main/java/cc/mrbird/febs/video/controller/ApiVideoController.java | 16 +++ src/main/java/cc/mrbird/febs/video/mapper/VideoCollectionMapper.java | 2 src/main/java/cc/mrbird/febs/video/service/IVideoMasterInfoService.java | 7 + 10 files changed, 187 insertions(+), 1 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/video/controller/ApiVideoController.java b/src/main/java/cc/mrbird/febs/video/controller/ApiVideoController.java index 40f634a..8ecda48 100644 --- a/src/main/java/cc/mrbird/febs/video/controller/ApiVideoController.java +++ b/src/main/java/cc/mrbird/febs/video/controller/ApiVideoController.java @@ -1,6 +1,8 @@ package cc.mrbird.febs.video.controller; import cc.mrbird.febs.common.entity.FebsResponse; +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.service.IVideoMasterInfoService; import cc.mrbird.febs.video.vo.VideoInfoVo; @@ -30,7 +32,7 @@ @ApiResponses({ @ApiResponse(code = 200, message = "success", response = VideoListVo.class) }) - @PostMapping(value = "/list") + @PostMapping(value = "/videoCollectionlist") public FebsResponse videoInPage(@RequestBody VideoListDto videoListDto) { return new FebsResponse().success().data(this.videoMasterInfoService.findVideoList(videoListDto)); } @@ -43,4 +45,16 @@ public FebsResponse videoInfo(@PathVariable("videoId") Long videoId, @RequestParam(value = "itemId", required = false) Long itemId) { return new FebsResponse().success().data(this.videoMasterInfoService.findVideoInfo(videoId, itemId)); } + + @ApiOperation(value = "收藏", notes = "收藏") + @PostMapping(value = "/videoCollection") + public FebsResponse videoCollection(@RequestBody ApiVideoCollectionDto apiVideoCollectionDto) { + return videoMasterInfoService.videoCollection(apiVideoCollectionDto); + } + + @ApiOperation(value = "点赞", notes = "点赞") + @PostMapping(value = "/videoLike") + public FebsResponse videoLike(@RequestBody ApiVideoLikeDto apiVideoLikeDto) { + return videoMasterInfoService.videoLike(apiVideoLikeDto); + } } diff --git a/src/main/java/cc/mrbird/febs/video/dto/ApiVideoCollectionDto.java b/src/main/java/cc/mrbird/febs/video/dto/ApiVideoCollectionDto.java new file mode 100644 index 0000000..d9823b8 --- /dev/null +++ b/src/main/java/cc/mrbird/febs/video/dto/ApiVideoCollectionDto.java @@ -0,0 +1,17 @@ +package cc.mrbird.febs.video.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +@ApiModel(value = "ApiVideoCollectionDto", description = "接收参数类") +public class ApiVideoCollectionDto { + + @NotBlank(message = "视频ID不能为空") + @ApiModelProperty(value = "视频ID", example = "10") + private Long videoId; + +} diff --git a/src/main/java/cc/mrbird/febs/video/dto/ApiVideoLikeDto.java b/src/main/java/cc/mrbird/febs/video/dto/ApiVideoLikeDto.java new file mode 100644 index 0000000..fb8f36e --- /dev/null +++ b/src/main/java/cc/mrbird/febs/video/dto/ApiVideoLikeDto.java @@ -0,0 +1,21 @@ +package cc.mrbird.febs.video.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +@ApiModel(value = "ApiVideoLikeDto", description = "接收参数类") +public class ApiVideoLikeDto { + + @NotBlank(message = "类型不能为空") + @ApiModelProperty(value = "类型;1/视频 2/评论", example = "1") + private Integer type; + + @NotBlank(message = "关联id不能为空") + @ApiModelProperty(value = "关联id", example = "10") + private Long relateId; + +} diff --git a/src/main/java/cc/mrbird/febs/video/mapper/VideoCollectionMapper.java b/src/main/java/cc/mrbird/febs/video/mapper/VideoCollectionMapper.java index c0a822b..f60bf2c 100644 --- a/src/main/java/cc/mrbird/febs/video/mapper/VideoCollectionMapper.java +++ b/src/main/java/cc/mrbird/febs/video/mapper/VideoCollectionMapper.java @@ -14,4 +14,6 @@ IPage<ApiMyVideoCollectionVo> selectApiVideoCollectionInPage(IPage<ApiMyVideoCollectionVo> page, @Param("record")ApiMyVideoCollectionDto apiMyVideoCollectionDto); IPage<ApiMyVideoHistoryVo> selectApiMyVideoHistoryInPage(IPage<ApiMyVideoHistoryVo> page, @Param("record")ApiMyVideoHistoryDto apiMyVideoHistoryDto); + + VideoCollectionEntity selectVideoCollectionByVideoIdAndMemberId(@Param("videoId")Long videoId, @Param("memberId")Long id); } diff --git a/src/main/java/cc/mrbird/febs/video/mapper/VideoCommentInfoMapper.java b/src/main/java/cc/mrbird/febs/video/mapper/VideoCommentInfoMapper.java new file mode 100644 index 0000000..520b7ac --- /dev/null +++ b/src/main/java/cc/mrbird/febs/video/mapper/VideoCommentInfoMapper.java @@ -0,0 +1,7 @@ +package cc.mrbird.febs.video.mapper; + +import cc.mrbird.febs.video.entity.VideoCommentInfoEntity; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +public interface VideoCommentInfoMapper extends BaseMapper<VideoCommentInfoEntity> { +} diff --git a/src/main/java/cc/mrbird/febs/video/mapper/VideoCommentLikeMapper.java b/src/main/java/cc/mrbird/febs/video/mapper/VideoCommentLikeMapper.java new file mode 100644 index 0000000..30058bf --- /dev/null +++ b/src/main/java/cc/mrbird/febs/video/mapper/VideoCommentLikeMapper.java @@ -0,0 +1,10 @@ +package cc.mrbird.febs.video.mapper; + +import cc.mrbird.febs.video.entity.VideoCommentLikeEntity; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +public interface VideoCommentLikeMapper extends BaseMapper<VideoCommentLikeEntity> { + + VideoCommentLikeEntity selectCommentLikeByMemberIdAndRelateId(Long id, Long relateId); + +} diff --git a/src/main/java/cc/mrbird/febs/video/service/IVideoMasterInfoService.java b/src/main/java/cc/mrbird/febs/video/service/IVideoMasterInfoService.java index 8e9ae42..30d4f03 100644 --- a/src/main/java/cc/mrbird/febs/video/service/IVideoMasterInfoService.java +++ b/src/main/java/cc/mrbird/febs/video/service/IVideoMasterInfoService.java @@ -1,6 +1,9 @@ package cc.mrbird.febs.video.service; +import cc.mrbird.febs.common.entity.FebsResponse; import cc.mrbird.febs.common.entity.QueryRequest; +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.VideoMasterInfoEntity; import cc.mrbird.febs.video.vo.VideoInfoVo; @@ -25,5 +28,9 @@ List<VideoListVo> findVideoList(VideoListDto videoListDto); VideoInfoVo findVideoInfo(Long videoId, Long itemId); + + FebsResponse videoCollection(ApiVideoCollectionDto apiVideoCollectionDto); + + FebsResponse videoLike(ApiVideoLikeDto apiVideoLikeDto); } diff --git a/src/main/java/cc/mrbird/febs/video/service/impl/VideoMasterInfoServiceImpl.java b/src/main/java/cc/mrbird/febs/video/service/impl/VideoMasterInfoServiceImpl.java index bf845cd..d8a1fd6 100644 --- a/src/main/java/cc/mrbird/febs/video/service/impl/VideoMasterInfoServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/video/service/impl/VideoMasterInfoServiceImpl.java @@ -1,11 +1,14 @@ 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.*; @@ -15,6 +18,7 @@ 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; @@ -38,6 +42,9 @@ 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 @@ -197,4 +204,83 @@ 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("已点赞"); + } + + } } diff --git a/src/main/resources/mapper/modules/VideoCollectionMapper.xml b/src/main/resources/mapper/modules/VideoCollectionMapper.xml index fd60577..10b00a2 100644 --- a/src/main/resources/mapper/modules/VideoCollectionMapper.xml +++ b/src/main/resources/mapper/modules/VideoCollectionMapper.xml @@ -39,4 +39,14 @@ order by a.created_time desc </select> + + + <select id="selectVideoCollectionByVideoIdAndMemberId" resultType="cc.mrbird.febs.video.entity.VideoCollectionEntity"> + select + a.* + from video_collection a + where a.member_id = #{memberId} + and a.video_id = #{videoId} + </select> + </mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/modules/VideoCommentLikeMapper.xml b/src/main/resources/mapper/modules/VideoCommentLikeMapper.xml new file mode 100644 index 0000000..6227c5f --- /dev/null +++ b/src/main/resources/mapper/modules/VideoCommentLikeMapper.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="cc.mrbird.febs.video.mapper.VideoCommentLikeMapper"> + + + + <select id="selectCommentLikeByMemberIdAndRelateId" resultType="cc.mrbird.febs.video.entity.VideoCommentLikeEntity"> + select * from video_comment_like where member_id = #{memberId} and relate_id = #{relateId} + </select> + + +</mapper> \ No newline at end of file -- Gitblit v1.9.1