cloudroam
2025-06-11 fb514e661e644bc40dba3d2413a64ff5e86bf6be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.mzl.flower.service.film.impl;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.dto.request.film.FilmCollectsDTO;
import com.mzl.flower.dto.request.film.FilmCollectsQueryDTO;
import com.mzl.flower.dto.response.film.FilmCollectsVO;
import com.mzl.flower.entity.film.FilmCollects;
import com.mzl.flower.mapper.film.FilmCollectsMapper;
import com.mzl.flower.service.film.FilmCollectsService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
 
/**
 * <p>
 * 影视作品收藏表 服务实现类
 * </p>
 *
 * @author generator@Fang
 * @since 2025-05-29
 */
@Service
public class FilmCollectsServiceImpl extends ServiceImpl<FilmCollectsMapper, FilmCollects> implements FilmCollectsService {
 
    @Resource
     private FilmCollectsMapper filmCollectsMapper;
 
    @Override
    public void saveFilmCollects(FilmCollectsDTO filmCollectsDTO) {
        FilmCollects filmCollects = new FilmCollects();
        filmCollects.setFilmId(filmCollectsDTO.getFilmId());
        filmCollects.setStatus(true);
        if (filmCollectsMapper.insert(filmCollects) <= 0) {
            throw new ValidationException("添加评论收藏失败");
        }
    }
 
    @Override
    public Boolean updateFilmCollects(FilmCollectsDTO filmCollectsDTO) {
        // 没有,新增
        FilmCollects filmCollects  = filmCollectsMapper.getFilmCollectsByfilmIdAndCreateBy(filmCollectsDTO.getFilmId(), SecurityUtils.getUserId());
        if (filmCollects == null) {
            filmCollects = new FilmCollects();
            filmCollects.setFilmId(filmCollectsDTO.getFilmId());
            filmCollects.setStatus(true);
            filmCollects.setCreateBy(SecurityUtils.getUserId());
            if (filmCollectsMapper.insert(filmCollects) <= 0) {
                throw new ValidationException("添加评论收藏失败");
            }
        } else {
            // 状态取反
            filmCollects.setStatus(!filmCollects.getStatus());
            filmCollects.update(SecurityUtils.getUserId());
            // 校验主键是否存在
            if (filmCollects.getId() == null) {
                throw new ValidationException("主键 ID 不能为空");
            }
            int affectedRows = filmCollectsMapper.updateStatusById(
                    filmCollects.getId(),         // 确保 id 是 Long 类型
                    filmCollects.getStatus(),
                    SecurityUtils.getUserId()  // 更新人
            );
            if (affectedRows <= 0) {
                throw new ValidationException("更新评论点赞状态失败");
            }
        }
        return true;
    }
 
    @Override
    public void deleteFilmCollects(String id) {
 
    }
 
    @Override
    public Page<FilmCollectsVO> queryPage(FilmCollectsQueryDTO filmCollectsQueryDTO, Page page) {
        return null;
    }
}