|
|
@@ -0,0 +1,223 @@
|
|
|
+package com.fs.course.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fs.common.core.domain.AjaxResult;
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.course.domain.FsCollection;
|
|
|
+import com.fs.course.domain.FsVideoCollection;
|
|
|
+import com.fs.course.dto.VideoCollectionDTO;
|
|
|
+import com.fs.course.mapper.FsCollectionMapper;
|
|
|
+import com.fs.course.mapper.FsUserCollectionFavoriteMapper;
|
|
|
+import com.fs.course.mapper.FsVideoCollectionMapper;
|
|
|
+import com.fs.course.param.FsVideoCollectionParam;
|
|
|
+import com.fs.course.service.IFsUserCollectionFavoriteService;
|
|
|
+import com.fs.course.service.IFsUserVideoService;
|
|
|
+import com.fs.course.service.IFsVideoCollectionService;
|
|
|
+import com.fs.course.vo.FsUserVideoListUVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 合集与视频关联Service业务层处理
|
|
|
+ *
|
|
|
+ * @author fs
|
|
|
+ * @date 2025-07-24
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class FsVideoCollectionServiceImpl extends ServiceImpl<FsVideoCollectionMapper, FsVideoCollection> implements IFsVideoCollectionService {
|
|
|
+ @Autowired
|
|
|
+ private FsVideoCollectionMapper fsVideoCollectionMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsCollectionMapper fsCollectionMapper;
|
|
|
+ @Autowired
|
|
|
+ private IFsUserVideoService userVideoService;
|
|
|
+ @Autowired
|
|
|
+ private IFsUserCollectionFavoriteService fsUserCollectionFavoriteService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCollectionFavoriteMapper userCollectionFavoriteMapper;
|
|
|
+ /**
|
|
|
+ * 查询合集与视频关联
|
|
|
+ *
|
|
|
+ * @param id 合集与视频关联主键
|
|
|
+ * @return 合集与视频关联
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public FsVideoCollection selectFsVideoCollectionById(String id)
|
|
|
+ {
|
|
|
+ return baseMapper.selectFsVideoCollectionById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询合集与视频关联列表
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return 合集与视频关联
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<FsUserVideoListUVO> selectFsVideoCollectionList(FsVideoCollectionParam param)
|
|
|
+ {
|
|
|
+ List<FsUserVideoListUVO> fsUserVideoListUVOS = baseMapper.selectFsVideoCollectionList(param);
|
|
|
+ if (param != null && param.getUserId() != null) {
|
|
|
+ Long userId = param.getUserId();
|
|
|
+ fsUserVideoListUVOS = userVideoService.selectLikesAndFavorites(userId, fsUserVideoListUVOS);
|
|
|
+ }
|
|
|
+ return fsUserVideoListUVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增合集与视频关联
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AjaxResult insertFsVideoCollection(FsVideoCollectionParam fsVideoCollectionParam)
|
|
|
+ {
|
|
|
+ int i = fsVideoCollectionMapper.selectByIdAndSort(fsVideoCollectionParam.getCollectionId(), fsVideoCollectionParam.getSort());
|
|
|
+ if (i>0){
|
|
|
+ return AjaxResult.error("已存在第"+fsVideoCollectionParam.getSort()+"集,请重新排序");
|
|
|
+ }
|
|
|
+ FsCollection fsCollection = fsCollectionMapper.selectFsCollectionByCollectionId(fsVideoCollectionParam.getCollectionId().toString());
|
|
|
+ if (fsCollection==null){
|
|
|
+ return AjaxResult.error("合集不存在");
|
|
|
+ }
|
|
|
+ if (fsCollection.getTalentId()!=fsVideoCollectionParam.getTalentId()){
|
|
|
+ return AjaxResult.error("非法操作");
|
|
|
+ }
|
|
|
+ fsVideoCollectionParam.setCreateTime(DateUtils.getNowDate());
|
|
|
+ baseMapper.insertFsVideoCollection(fsVideoCollectionParam);
|
|
|
+ return AjaxResult.success();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改合集与视频关联
|
|
|
+ *
|
|
|
+ * @param fsVideoCollection 合集与视频关联
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int updateFsVideoCollection(FsVideoCollection fsVideoCollection)
|
|
|
+ {
|
|
|
+ return baseMapper.updateFsVideoCollection(fsVideoCollection);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int deleteFsVideoCollectionByCollectionId(Long collectionId) {
|
|
|
+ return fsVideoCollectionMapper.deleteFsVideoCollectionByCollectionId(collectionId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除合集与视频关联
|
|
|
+ *
|
|
|
+ * @param ids 需要删除的合集与视频关联主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteFsVideoCollectionByIds(String[] ids)
|
|
|
+ {
|
|
|
+ return baseMapper.deleteFsVideoCollectionByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除合集与视频关联信息
|
|
|
+ *
|
|
|
+ * @param id 合集与视频关联主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteFsVideoCollectionById(String id)
|
|
|
+ {
|
|
|
+ return baseMapper.deleteFsVideoCollectionById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int removeVideo(FsVideoCollection fsVideoCollection) {
|
|
|
+ return baseMapper.removeVideo(fsVideoCollection.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateVideo(FsVideoCollection fsVideoCollection) {
|
|
|
+ return baseMapper.updateFsVideoCollection(fsVideoCollection);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public AjaxResult batchInsertFsVideoCollection(List<FsVideoCollectionParam> paramList) {
|
|
|
+ if (paramList == null || paramList.isEmpty()) {
|
|
|
+ return AjaxResult.error("参数不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long collectionId = paramList.get(0).getCollectionId();
|
|
|
+ FsCollection fsCollection = fsCollectionMapper.selectFsCollectionByCollectionId(collectionId.toString());
|
|
|
+ if (fsCollection == null) {
|
|
|
+ return AjaxResult.error("合集不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ for (FsVideoCollectionParam param : paramList) {
|
|
|
+ // 检查是否属于同一个 talent
|
|
|
+ if (!fsCollection.getTalentId().equals(param.getTalentId())) {
|
|
|
+ return AjaxResult.error("非法操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查 sort 是否重复
|
|
|
+// int count = fsVideoCollectionMapper.selectByIdAndSort(param.getCollectionId(), param.getSort());
|
|
|
+// if (count > 0) {
|
|
|
+// return AjaxResult.error("已存在第" + param.getSort() + "集,请重新排序");
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量插入
|
|
|
+ fsVideoCollectionMapper.batchInsertFsVideoCollection(paramList);
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int removeVideos(List<Long> ids) {
|
|
|
+ if (ids == null || ids.isEmpty()) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return baseMapper.removeVideos(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateSort(List<FsVideoCollectionParam> sortList) {
|
|
|
+ if (sortList == null || sortList.isEmpty()) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return baseMapper.batchUpdateSort(sortList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> selectVideoIdsByCollectionId(Long collectionId) {
|
|
|
+ return fsVideoCollectionMapper.selectVideoIdsByCollectionId(collectionId);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int selectVideoCountByVideId(Long videoId) {
|
|
|
+ return fsVideoCollectionMapper.selectCountByVideoId(videoId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public VideoCollectionDTO selectCollectionByVideoId(Long videoId,Long userId) {
|
|
|
+ VideoCollectionDTO videoCollectionDTO = fsVideoCollectionMapper.selectCollectionByVideoId(videoId);
|
|
|
+ if (videoCollectionDTO != null){
|
|
|
+ int i = fsVideoCollectionMapper.selectCountByCollectionId(videoCollectionDTO.getCollectionId());
|
|
|
+ videoCollectionDTO.setCount(i);
|
|
|
+ int favoriteCount = userCollectionFavoriteMapper.checkFavorite(videoCollectionDTO.getCollectionId(), userId);
|
|
|
+ if (favoriteCount>0){
|
|
|
+ videoCollectionDTO.setIsFavorite(true);
|
|
|
+ }else {
|
|
|
+ videoCollectionDTO.setIsFavorite(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return videoCollectionDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|