cloudroam
4 天以前 47efb98ace2e67443fd4064cbfd22b059808a095
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
package com.mzl.flower.service.film.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.BatchDTO;
import com.mzl.flower.dto.request.film.FilmWorksDTO;
import com.mzl.flower.dto.request.film.FilmWorksQueryDTO;
import com.mzl.flower.dto.request.system.UserInfoDTO;
import com.mzl.flower.dto.response.customer.CustomerDTO;
import com.mzl.flower.dto.response.film.FilmWorksVO;
import com.mzl.flower.dto.response.system.MenuTreeDTO;
import com.mzl.flower.entity.film.FilmWorks;
import com.mzl.flower.entity.system.Role;
import com.mzl.flower.mapper.customer.CustomerMapper;
import com.mzl.flower.mapper.film.FilmWorksMapper;
import com.mzl.flower.service.film.FilmWorksService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mzl.flower.service.system.RoleService;
import com.mzl.flower.utils.DateUtils;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
 
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 * 影视作品信息表 服务实现类
 * </p>
 *
 * @author generator@Fang
 * @since 2025-05-19
 */
@Service
@Transactional
@RequiredArgsConstructor
public class FilmWorksServiceImpl extends ServiceImpl<FilmWorksMapper, FilmWorks> implements FilmWorksService {
 
    private final FilmWorksMapper filmWorksMapper;
    private final CustomerMapper customerMapper;
    private final RoleService roleService;
 
    @Override
    public void saveFilmWorks(FilmWorksDTO filmWorksDTO) {
        //获取当前人员角色,判断是不是编辑角色
        List<String> roleIds = new ArrayList<>();
        List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId());
        for (Role role : roleList) {
            roleIds.add(role.getId());
        }
        if (!roleIds.contains("8f9ef89f6b2d4d8e9ea1fc8d2f25ce69")) {
            throw new ValidationException("非编辑角色不能新增");
        }
        //  转换
        FilmWorks filmWorks = new FilmWorks();
        BeanUtils.copyProperties(filmWorksDTO, filmWorks);
        filmWorks.create();
        filmWorks.setStatus(Constants.COMMON_PUBLISH_STATUS.pending_review.name());
        filmWorksMapper.insert(filmWorks);
    }
 
    @Override
    public void updateFilmWorks(FilmWorksDTO filmWorksDTO) {
        FilmWorks filmWorks = new FilmWorks();
        //系统生成的内容无需管理
        if ("sys".equals(filmWorksDTO.getType())) {
            filmWorks = filmWorksMapper.selectById(filmWorksDTO.getId());
            filmWorks.setFilmContent(filmWorksDTO.getFilmContent());
            //生成之后变成待审核
            if(StringUtils.isNotBlank(filmWorks.getFilmContent())){
                filmWorks.setStatus(Constants.COMMON_PUBLISH_STATUS.pending_review.name());
            }else{
                filmWorks.setStatus(Constants.COMMON_PUBLISH_STATUS.create_failed.name());
            }
 
        } else {
            List<String> roleIds = new ArrayList<>();
            List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId());
            for (Role role : roleList) {
                roleIds.add(role.getId());
            }
            if (!roleIds.contains("8f9ef89f6b2d4d8e9ea1fc8d2f25ce69")) {
                throw new ValidationException("非编辑角色不能修改");
            }
            filmWorks = filmWorksMapper.selectById(filmWorksDTO.getId());
            //判断影视作品状态
            if(Constants.COMMON_PUBLISH_STATUS.published.name().equals(filmWorks.getStatus()) ){
                throw new ValidationException("发布作品不能编辑");
            }
 
            if(Constants.COMMON_PUBLISH_STATUS.approved.name().equals(filmWorks.getStatus()) ){
                throw new ValidationException("审核作品不能编辑");
            }
            BeanUtils.copyProperties(filmWorksDTO, filmWorks);
            filmWorks.update(SecurityUtils.getUserId());
            filmWorks.setStatus(Constants.COMMON_PUBLISH_STATUS.pending_review.name());
        }
        filmWorksMapper.updateById(filmWorks);
    }
 
    @Override
    public void deleteFilmWorks(String id) {
        FilmWorks filmWork = filmWorksMapper.selectById(id);
        if(filmWork==null){
            throw new ValidationException("找不到id为"+id+"的影视作品");
        }
        filmWorksMapper.deleteById(id);
    }
 
    @Override
    public Page<FilmWorksVO> queryPage(FilmWorksQueryDTO dto, Page page) {
        if(StringUtils.isNotBlank(dto.getCreateDateBeginStr())){
            dto.setCreateDateBegin(DateUtils.dateToLocalDateTime(dto.getCreateDateBeginStr(),true));
        }
        if(StringUtils.isNotBlank(dto.getCreateDateEndStr())){
            dto.setCreateDateEnd(DateUtils.dateToLocalDateTime(dto.getCreateDateEndStr(),false));
        }
        if (!StringUtils.isEmpty(dto.getCategory()) && Constants.FILM_CATEGORY.all.getDesc().equals(dto.getCategory())) {
            //当时全部的时时候值设置为空,表示查询全部
            dto.setCategory(null);
        }
 
        //todo 这里的用户ID可能为空,用户存在不登录的情况下访问,传null
        try {
            dto.setUserId(SecurityUtils.getUserId());
        } catch (Exception e) {
            dto.setUserId(null);
        }
        List<FilmWorksVO> list =  filmWorksMapper.queryPage(dto,page);
        page.setRecords(list);
 
 
        return page;
    }
 
    @Override
    public List<FilmWorksVO> getFilmWorksAll() {
        return filmWorksMapper.getFilmWorksAll();
    }
 
    @Override
    public List<FilmWorksVO> pendingCreate() {
        return filmWorksMapper.pendingCreate();
    }
 
    @Override
    public void changeStatus(Long id) {
        //获取当前人员角色,判断是不是审核角色
        List<String> roleIds = new ArrayList<>();
        List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId());
        for (Role role : roleList) {
            roleIds.add(role.getId());
        }
        if (!roleIds.contains("77462b362bad4c88a7a5c64cbdd25d91")) {
            throw new ValidationException("非运营角色不能发布");
        }
        FilmWorks filmWork = filmWorksMapper.selectById(id);
        if (filmWork == null) {
            throw new ValidationException("找不到id为" + id + "的公告");
        }
        if (Constants.COMMON_PUBLISH_STATUS.approved.name().equals(filmWork.getStatus()) || Constants.COMMON_PUBLISH_STATUS.published.name().equals(filmWork.getStatus()) || Constants.COMMON_PUBLISH_STATUS.unpublished.name().equals(filmWork.getStatus())) {
            if (Constants.COMMON_PUBLISH_STATUS.published.name().equals(filmWork.getStatus())) {
                filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.unpublished.name());
            } else {
                filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.published.name());
                filmWork.setPublishDate(LocalDate.now());
            }
            filmWorksMapper.updateById(filmWork);
        }else{
            throw new ValidationException("非审核通过或者发布状态,不能操作");
        }
    }
 
 
    @Override
    public void changeTopState(Long id) {
        //获取当前人员角色,判断是不是审核角色
        List<String> roleIds = new ArrayList<>();
        List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId());
        for (Role role : roleList) {
            roleIds.add(role.getId());
        }
        if (!roleIds.contains("77462b362bad4c88a7a5c64cbdd25d91")) {
            throw new ValidationException("非运营角色不能置顶");
        }
        FilmWorks filmWork = filmWorksMapper.selectById(id);
        if (filmWork == null) {
            throw new ValidationException("找不到id为" + id + "的公告");
        }
        if (Constants.COMMON_PUBLISH_STATUS.unpublished.name().equals(filmWork.getStatus())) {
            throw new ValidationException("未发布作品不能置顶,请先发布");
        }
 
        FilmWorks filmWorkTop = filmWorksMapper.getTopStickyWeight();
        if (!ObjectUtils.isEmpty(filmWorkTop)) {
            filmWork.setStickyWeight(filmWorkTop.getStickyWeight() + 100);
        } else {
            filmWork.setStickyWeight(100);
        }
        filmWorksMapper.updateById(filmWork);
    }
 
 
    @Override
    public void changeDownState(Long id) {
        //获取当前人员角色,判断是不是审核角色
        List<String> roleIds = new ArrayList<>();
        List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId());
        for (Role role : roleList) {
            roleIds.add(role.getId());
        }
        if (!roleIds.contains("77462b362bad4c88a7a5c64cbdd25d91")) {
            throw new ValidationException("非运营角色不能清除权重");
        }
        FilmWorks filmWork = filmWorksMapper.selectById(id);
        if (filmWork == null) {
            throw new ValidationException("找不到id为" + id + "的公告");
        }
        if (Constants.COMMON_PUBLISH_STATUS.unpublished.name().equals(filmWork.getStatus())) {
            throw new ValidationException("未发布作品无需清除权重");
        }
        filmWork.setStickyWeight(0);
        filmWorksMapper.updateById(filmWork);
    }
 
    @Override
    public void batchDelete(BatchDTO dto) {
        filmWorksMapper.deleteBatchIds(dto.getIds());
    }
 
    @Override
    public void batchPublish(BatchDTO dto) {
        //获取当前人员角色,判断是不是审核角色
        List<String> roleIds = new ArrayList<>();
        List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId());
        for (Role role : roleList) {
            roleIds.add(role.getId());
        }
        if (!roleIds.contains("77462b362bad4c88a7a5c64cbdd25d91")) {
            throw new ValidationException("非运营角色不能发布");
        }
 
        List<FilmWorks> list = filmWorksMapper.selectList(new LambdaQueryWrapper<FilmWorks>().in(FilmWorks::getId, dto.getIds()));
        for (FilmWorks filmWork : list) {
            filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.published.name());
            filmWork.setPublishDate(LocalDate.now());
            filmWorksMapper.updateById(filmWork);
        }
    }
 
    @Override
    public FilmWorksVO detail(Long id) {
        // userId 可以是空,因为用户可以登录
 
        String userId = SecurityUtils.getUserId();
        FilmWorksVO filmWorksVO = filmWorksMapper.selectInfoById(id,userId);
        if(filmWorksVO==null){
            return null;
        }
        CustomerDTO currentCustomer = customerMapper.getCurrentCustomer(filmWorksVO.getCreateBy());
        filmWorksVO.setNickname(currentCustomer.getNickName());
        filmWorksVO.setAvatar(currentCustomer.getCover());
        return filmWorksVO;
    }
 
    @Override
    public void batchApproved(BatchDTO dto) {
        //获取当前人员角色,判断是不是审核角色
        List<String> roleIds = new ArrayList<>();
        List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId());
        for (Role role : roleList) {
            roleIds.add(role.getId());
        }
        if (!roleIds.contains("86a36a0b789c4d0e840f7b807c09459b")) {
            throw new ValidationException("非审核角色不能审批");
        }
        List<FilmWorks> list = filmWorksMapper.selectList(new LambdaQueryWrapper<FilmWorks>().in(FilmWorks::getId, dto.getIds()));
        //判断所有的状态都是待审核
        if (!list.stream().allMatch(filmWork -> Constants.COMMON_PUBLISH_STATUS.pending_review.name().equals(filmWork.getStatus()) || Constants.COMMON_PUBLISH_STATUS.rejected.name().equals(filmWork.getStatus()))) {
            throw new ValidationException("只有待审核或者审核拒绝的才能批量审核");
        }
        for (FilmWorks filmWork : list) {
            filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.approved.name());
            filmWork.setAuditDate(LocalDate.now());
            filmWorksMapper.updateById(filmWork);
        }
    }
 
    @Override
    public void batchRejected(BatchDTO dto) {
        //获取当前人员角色,判断是不是审核角色
        List<String> roleIds = new ArrayList<>();
        List<Role> roleList = roleService.getUserRoleList(SecurityUtils.getUserId());
        for (Role role : roleList) {
            roleIds.add(role.getId());
        }
        if (!roleIds.contains("86a36a0b789c4d0e840f7b807c09459b")) {
            throw new ValidationException("非审核角色不能审批");
        }
        List<FilmWorks> list = filmWorksMapper.selectList(new LambdaQueryWrapper<FilmWorks>().in(FilmWorks::getId, dto.getIds()));
        //判断所有的状态都是待审核或者审核通过
        if (!list.stream().allMatch(filmWork -> Constants.COMMON_PUBLISH_STATUS.pending_review.name().equals(filmWork.getStatus()) || Constants.COMMON_PUBLISH_STATUS.approved.name().equals(filmWork.getStatus()))) {
            throw new ValidationException("只有待审核或者审核通过的状态才能批量审核");
        }
        for (FilmWorks filmWork : list) {
            filmWork.setStatus(Constants.COMMON_PUBLISH_STATUS.rejected.name());
            filmWork.setAuditDate(LocalDate.now());
            filmWorksMapper.updateById(filmWork);
        }
    }
}