VodDictServiceImpl.java
3.44 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
package com.zhongzhi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongzhi.common.configure.VODConfig;
import com.zhongzhi.common.utils.Signature;
import com.zhongzhi.common.utils.VodUtil;
import com.zhongzhi.dto.course.ChangeOrdersDTO;
import com.zhongzhi.dto.course.VodsDTO;
import com.zhongzhi.model.CourseDictDO;
import com.zhongzhi.model.VodDictDO;
import com.zhongzhi.dao.VodDictDAO;
import com.zhongzhi.service.VodDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongzhi.vo.course.SignatureVO;
import com.zhongzhi.vo.course.VodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Random;
/**
* <p>
* 服务实现类
* </p>
*
* @author DengMin
* @since 2022-11-14
*/
@Service
public class VodDictServiceImpl extends ServiceImpl<VodDictDAO, VodDictDO> implements VodDictService {
@Autowired
private VODConfig vodConfig;
@Value("${spring.profiles.active}")
private String env;
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();
// throw new MyException(ResultEnum.UNKNOWN_ERROR);
}
return signatureVO;
}
public void deleteVod(VodDictDO vodDictDO) {
this.baseMapper.deleteById(vodDictDO.getId());
}
public void addVod(VodDictDO vodDictDO) {
//查看这个课程当前最大的no
List<VodDictDO> vodDictDOS = this.baseMapper.selectList(new QueryWrapper<VodDictDO>()
.lambda()
.eq(VodDictDO::getCourseId, vodDictDO.getCourseId())
.orderByDesc(VodDictDO::getOrderNo));
int orderNo = 1;
if (vodDictDOS.size() > 0) {
orderNo += vodDictDOS.get(0).getOrderNo();
}
vodDictDO.setOrderNo(orderNo);
this.baseMapper.insert(vodDictDO);
//测试环境就不转码了
if (env.equals("prod")){
VodUtil.processMedia(vodConfig, vodDictDO.getVodCode());
}
}
public void updateVod(VodDictDO vodDictDO) {
this.baseMapper.updateById(vodDictDO);
}
public void changeOrders(ChangeOrdersDTO changeOrdersDTO) {
List<Long> ids = changeOrdersDTO.getIds();
int i = 1;
for (Long id : ids) {
VodDictDO vodDictDO = this.baseMapper.selectById(id);
vodDictDO.setOrderNo(i);
this.baseMapper.updateById(vodDictDO);
i++;
}
}
public List<VodsVO> vods(VodsDTO vodsDTO) {
return this.baseMapper.vods(vodsDTO.getCourseId(), vodsDTO.getVodName(),vodsDTO.getYearId());
}
public List<VodsVO> fourVods(CourseDictDO courseDictDO) {
return this.baseMapper.fourVods(courseDictDO);
}
}