VodDictServiceImpl.java
5.88 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
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
package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.common.configure.VODConfig;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.content.GetContendVodsDTO;
import com.subsidy.dto.vod.AddVodDictDTO;
import com.subsidy.dto.vod.ChangeOrdersDTO;
import com.subsidy.dto.vod.VodDictPageDTO;
import com.subsidy.mapper.ContentVodMappingMapper;
import com.subsidy.mapper.CourseDictMapper;
import com.subsidy.mapper.VodDictMapper;
import com.subsidy.model.ContentVodMappingDO;
import com.subsidy.model.CourseDictDO;
import com.subsidy.model.VodDictDO;
import com.subsidy.service.VodDictService;
import com.subsidy.util.Signature;
import com.subsidy.util.VodUtil;
import com.subsidy.vo.vod.GetContendVodsVO;
import com.subsidy.vo.vod.QueryVodPageVO;
import com.subsidy.vo.vod.SignatureVO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
/**
* <p>
* 视频表 服务实现类
* </p>
*
* @author DengMin
* @since 2021-10-11
*/
@Service
public class VodDictServiceImpl extends ServiceImpl<VodDictMapper, VodDictDO> implements VodDictService {
@Autowired
private VODConfig vodConfig;
@Value("${spring.profiles.active}")
private String env;
@Autowired
private ContentVodMappingMapper contentVodMappingMapper;
@Autowired
private CourseDictMapper courseDictMapper;
@Override
public SignatureVO signature() {
SignatureVO signatureVO = new SignatureVO();
Signature signature = new Signature();
signature.setSecretId(vodConfig.getSecretId());
signature.setSecretKey(vodConfig.getSecretKey());
signature.setCurrentTime(System.currentTimeMillis());
signature.setRandom(new Random().nextInt(Integer.MAX_VALUE));
signature.setSignValidDuration(3600 * 24 * 2);
signature.setClassId(vodConfig.getClassId());
String sign = "";
try {
sign = signature.getUploadSignature();
signatureVO.setSign(sign);
} catch (Exception ex) {
ex.printStackTrace();
}
return signatureVO;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteVod(VodDictDO vodDictDO) {
VodDictDO vod = this.baseMapper.selectById(vodDictDO.getId());
if(null == vod) {
throw new HttpException(18000);
}
if(vodDictDO.getVodCode() != null) {
VodUtil.deleteMedia(vodConfig, vodDictDO.getVodCode());
}
this.baseMapper.deleteById(vodDictDO.getId());
}
@Override
public void addVod(VodDictDO vodDictDO) {
int orderNo = 1;//排序
List<VodDictDO> vodDictDOS = this.baseMapper.selectList(new QueryWrapper<VodDictDO>()
.lambda()
.eq(VodDictDO::getLabelId, vodDictDO.getLabelId())
.orderByDesc(VodDictDO::getOrderNo));
if (CollectionUtils.isNotEmpty(vodDictDOS)){
VodDictDO vod = vodDictDOS.get(0);
if (null != vod){
orderNo = vod.getOrderNo() + 1;
}
}
vodDictDO.setOrderNo(orderNo);
this.baseMapper.insert(vodDictDO);
//测试环境就不转码了
if (env.equals("prod")){
VodUtil.processMedia(vodConfig, vodDictDO.getVodCode());
}
}
@Override
public void addCompanyVod(AddVodDictDTO addVodDictDTO) {
int orderNo = 1;//排序
List<VodDictDO> vodDictDOS = this.baseMapper.getCompanyVod(addVodDictDTO.getContentId());
if (CollectionUtils.isNotEmpty(vodDictDOS)){
VodDictDO vod = vodDictDOS.get(0);
if (null != vod){
orderNo = vod.getOrderNo() + 1;
}
}
addVodDictDTO.setOrderNo(orderNo);
this.baseMapper.insert(addVodDictDTO);
if(addVodDictDTO.getContentId() != null) {
ContentVodMappingDO contentVodMappingDO = new ContentVodMappingDO();
contentVodMappingDO.setVodId(addVodDictDTO.getId());
contentVodMappingDO.setContentId(addVodDictDTO.getContentId());
contentVodMappingMapper.insert(contentVodMappingDO);
}
//测试环境就不转码了
if (env.equals("prod")){
VodUtil.processMedia(vodConfig, addVodDictDTO.getVodCode());
}
}
@Override
public void updateVod(VodDictDO vodDictDO) {
this.baseMapper.updateById(vodDictDO);
}
@Override
public void changeOrders(ChangeOrdersDTO changeOrdersDTO){
int i = 1 ;
List<Long> longs = changeOrdersDTO.getVodIds();
for (Long lg : longs){
this.baseMapper.updateVodOrderNo(lg,i++);
}
}
@Override
public IPage queryVodPage(VodDictPageDTO vodDictPageDTO) {
Page page = new Page(vodDictPageDTO.getPageNum(), vodDictPageDTO.getPageSize());
IPage<QueryVodPageVO> iPage = this.baseMapper.queryVodPage(page, vodDictPageDTO.getLabelId(), vodDictPageDTO.getVodName());
for (QueryVodPageVO queryVodPageVO : iPage.getRecords()) {
List<CourseDictDO> list = courseDictMapper.getListByVodId(queryVodPageVO.getId());
List<String> courseNames = list.stream().map(CourseDictDO::getCourseName).collect(Collectors.toList());
queryVodPageVO.setCourseNames(courseNames);
}
return iPage;
}
}