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;
/**
*
* 影视作品收藏表 服务实现类
*
*
* @author generator@Fang
* @since 2025-05-29
*/
@Service
public class FilmCollectsServiceImpl extends ServiceImpl 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 queryPage(FilmCollectsQueryDTO filmCollectsQueryDTO, Page page) {
return null;
}
}