cloudroam
4 天以前 46715d892da947c31f07796fdc79dbbef06677b3
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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.*;
 
/**
 * <p>
 * FilmHotCity热门城市表 服务实现类
 * </p>
 *
 * @author generator@Fang
 * @since 2025-05-20
 */
@Service
@Transactional
@RequiredArgsConstructor
public class FilmHotCityServiceImpl extends ServiceImpl<FilmHotCityMapper, FilmHotCity> 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<FilmHotCityVO> queryPage(FilmHotCityQueryDTO dto, Page page) {
 
        List<FilmHotCityVO> 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());
    }
 
 
}