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.BatchDTO; import com.mzl.flower.dto.request.film.FilmHotCityDTO; import com.mzl.flower.dto.request.film.FilmHotCityQueryDTO; import com.mzl.flower.dto.response.film.FilmHotCityVO; import com.mzl.flower.entity.film.FilmHotCity; import com.mzl.flower.mapper.film.FilmHotCityMapper; import com.mzl.flower.mapper.film.FilmWorksMapper; import com.mzl.flower.service.film.FilmHotCityService; import com.mzl.flower.service.system.RoleService; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import java.util.*; /** *

* FilmHotCity热门城市表 服务实现类 *

* * @author generator@Fang * @since 2025-05-20 */ @Service @Transactional @RequiredArgsConstructor public class FilmHotCityServiceImpl extends ServiceImpl implements FilmHotCityService { private final FilmHotCityMapper filmHotCityMapper; private final RoleService roleService; private final FilmWorksMapper filmWorksMapper; @Override public void saveFilmHotCity(FilmHotCityDTO filmHotCityDTO) { // 转换 //增加保存时判断是否有城市名称 if (StringUtils.isEmpty(filmHotCityDTO.getName())) { throw new ValidationException("城市名称不能为空"); } FilmHotCity filmHotCity1 = filmHotCityMapper.selectByName(filmHotCityDTO.getName()); if (!ObjectUtils.isEmpty(filmHotCity1)) { throw new ValidationException("城市名称重复"); } FilmHotCity filmHotCity = new FilmHotCity(); BeanUtils.copyProperties(filmHotCityDTO, filmHotCity); filmHotCity.setIsEnabled(false); filmHotCity.create(); filmHotCityMapper.insert(filmHotCity); } @Override public void updateFilmHotCity(FilmHotCityDTO filmHotCityDTO) { if (StringUtils.isEmpty(filmHotCityDTO.getName())) { throw new ValidationException("城市名称不能为空"); } //增加修改时保存得城市名称是否有重复,排除当前这条 FilmHotCity filmHotCity1 = filmHotCityMapper.selectByName(filmHotCityDTO.getName()); FilmHotCity filmHotCity = filmHotCityMapper.selectById(filmHotCityDTO.getId()); if (!filmHotCity1.getId().equals(filmHotCity.getId())) { throw new ValidationException("城市名称重复"); } BeanUtils.copyProperties(filmHotCityDTO, filmHotCity, "isEnabled"); filmHotCity.update(SecurityUtils.getUserId()); filmHotCityMapper.updateById(filmHotCity); } @Override public void deleteFilmHotCity(String id) { FilmHotCity filmHotCity = filmHotCityMapper.selectById(id); if (filmHotCity == null) { throw new ValidationException("找不到id为" + id + "的城市"); } filmHotCityMapper.deleteById(id); } @Override public Page queryPage(FilmHotCityQueryDTO dto, Page page) { List list = filmHotCityMapper.queryPage(dto, page); page.setRecords(list); return page; } @Override public FilmHotCityVO detail(Long id) { FilmHotCityVO filmHotCityVO = filmHotCityMapper.selectByIdInfo(id); if (filmHotCityVO == null) { return null; } return filmHotCityVO; } @Override public void isEnable(Long id) { FilmHotCity filmHotCity = filmHotCityMapper.selectById(id); if (filmHotCity == null) { throw new ValidationException("找不到id为" + id + "的城市"); } if (filmHotCity.getIsEnabled()) { filmHotCity.setIsEnabled(false); } else { filmHotCity.setIsEnabled(true); } filmHotCity.update(SecurityUtils.getUserId()); filmHotCityMapper.updateById(filmHotCity); } @Override @Transactional public void batchDelete(BatchDTO dto) { if (CollectionUtils.isEmpty(dto.getIds())) { throw new ValidationException("删除ID列表不能为空"); } filmHotCityMapper.deleteBatchIds(dto.getIds()); } }