ContentVodMappingServiceImpl.java
5.36 KB
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
package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.content.GetContendVodsDTO;
import com.subsidy.dto.contentVod.AddContentVodDTO;
import com.subsidy.dto.contentVod.ContentVodDTO;
import com.subsidy.dto.vod.ChangeOrdersDTO;
import com.subsidy.mapper.VodDictMapper;
import com.subsidy.model.ContentVodMappingDO;
import com.subsidy.mapper.ContentVodMappingMapper;
import com.subsidy.service.ContentVodMappingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.vo.vod.GetContendVodsVO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
* 目录视频关系表 服务实现类
* </p>
*
* @author DengMin
* @since 2022-07-19
*/
@Service
public class ContentVodMappingServiceImpl extends ServiceImpl<ContentVodMappingMapper, ContentVodMappingDO> implements ContentVodMappingService {
@Autowired
private VodDictMapper vodDictMapper;
@Override
public List<GetContendVodsVO> getContendVods(GetContendVodsDTO getContendVodsDTO) {
return vodDictMapper.getContendVods( getContendVodsDTO.getVodName(), getContendVodsDTO.getContentId());
}
@Override
public void changeContentVodOrders(ChangeOrdersDTO changeOrdersDTO){
if(CollectionUtils.isNotEmpty(changeOrdersDTO.getVodIds())) {
for (int i = 0; i < changeOrdersDTO.getVodIds().size(); i++) {
ContentVodMappingDO contentVodMappingDO = this.baseMapper.selectOne(new QueryWrapper<ContentVodMappingDO>().lambda()
.eq(ContentVodMappingDO::getContentId, changeOrdersDTO.getContentId())
.eq(ContentVodMappingDO::getVodId, changeOrdersDTO.getVodIds().get(i)));
ContentVodMappingDO contentVodMapping = new ContentVodMappingDO();
contentVodMapping.setId(contentVodMappingDO.getId());
contentVodMapping.setOrderNo(i+1);
this.baseMapper.updateById(contentVodMapping);
}
}
}
@Override
public void deleteContentVod(ContentVodDTO contentVodDTO) {
ContentVodMappingDO contentVodMappingDO = this.baseMapper.selectOne(new QueryWrapper<ContentVodMappingDO>()
.lambda()
.eq(ContentVodMappingDO::getContentId, contentVodDTO.getContentId())
.eq(ContentVodMappingDO::getVodId, contentVodDTO.getVodId()));
if(contentVodMappingDO == null) {
throw new HttpException(18001);
}
this.baseMapper.deleteById(contentVodMappingDO.getId());
}
@Override
public void addContentVod(AddContentVodDTO addContentVod) {
if(CollectionUtils.isNotEmpty(addContentVod.getVodIds())) {
List<ContentVodMappingDO> list = this.baseMapper.selectList(new QueryWrapper<ContentVodMappingDO>()
.lambda()
.eq(ContentVodMappingDO::getContentId, addContentVod.getContentId()));
if(CollectionUtils.isNotEmpty(list)) {
this.baseMapper.deleteBatchIds(list.stream().map(ContentVodMappingDO::getId).collect(Collectors.toList()));
}
List<ContentVodMappingDO> contentVodMappingList = this.baseMapper.selectList(new QueryWrapper<ContentVodMappingDO>()
.lambda()
.eq(ContentVodMappingDO::getContentId, addContentVod.getContentId())
.orderByDesc(ContentVodMappingDO::getOrderNo));
int orderNo = 0;
if(CollectionUtils.isNotEmpty(contentVodMappingList)) {
orderNo = contentVodMappingList.get(0).getOrderNo();
}
for (ContentVodDTO contentVodDTO : addContentVod.getVodIds()) {
ContentVodMappingDO cvm = this.baseMapper.selectOne(new QueryWrapper<ContentVodMappingDO>().lambda()
.eq(ContentVodMappingDO::getVodId, contentVodDTO.getVodId())
.eq(ContentVodMappingDO::getContentId, addContentVod.getContentId()));
if(cvm == null) {
ContentVodMappingDO contentVodMappingDO = new ContentVodMappingDO();
contentVodMappingDO.setContentId(addContentVod.getContentId());
contentVodMappingDO.setVodId(contentVodDTO.getVodId());
contentVodMappingDO.setVodAliasName(contentVodDTO.getVodAliasName());
contentVodMappingDO.setOrderNo(++ orderNo);
this.baseMapper.insert(contentVodMappingDO);
}
}
}
}
@Override
public void updateContentVod(ContentVodDTO contentVodDTO) {
ContentVodMappingDO contentVodMappingDO = this.baseMapper.selectOne(new QueryWrapper<ContentVodMappingDO>()
.lambda()
.eq(ContentVodMappingDO::getVodId, contentVodDTO.getVodId())
.eq(ContentVodMappingDO::getContentId, contentVodDTO.getContentId()));
if(contentVodMappingDO != null) {
ContentVodMappingDO cvm = new ContentVodMappingDO();
cvm.setId(contentVodMappingDO.getId());
cvm.setVodAliasName(contentVodDTO.getVodAliasName());
this.baseMapper.updateById(cvm);
}
}
}