AudioServiceImpl.java
6.61 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
package com.cnlive.shenhe.serviceImpl;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.entity.ShyAudio;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.mapper.ShyAudioMapper;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
/**
* @Author: xujincheng
* @Date: 2020/6/8 10:19
*/
@Service
public class AudioServiceImpl {
@Autowired
ShyAudioMapper shyAudioMapper;
public ShyAudio getAudioMsg(String audioId) {
return shyAudioMapper.getAudioMsg(audioId);
}
public int importAudioMsg(ShyAudio ShyAudio) {
return shyAudioMapper.insertSelective(ShyAudio);
}
public int updateAudioMsg(ShyAudio ShyAudio) {
return shyAudioMapper.updateByPrimaryKeySelective(ShyAudio);
}
public ShyAudio selectByPrimaryKey(Integer id) {
ShyAudio shyAudio = shyAudioMapper.selectByPrimaryKey(id);
return shyAudio;
}
//认领
public Integer receive(String ids, Integer num, String userId, Integer spid) {
Integer n = 0;
if (CommonUtils.isNotEmpty(ids)) {
String[] cids = ids.split(",");
for (String cid : cids) {
ShyAudio shyAudio = shyAudioMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (CommonUtils.isNotNull(shyAudio) && shyAudio.getState() == CommonConst.AUDIT_INTT && shyAudio.getReceive()==CommonConst.RECEIVE_BEFORE) {
shyAudio.setReceive_user_id(userId);
shyAudio.setReceive(CommonConst.RECEIVE_AFTER);
shyAudioMapper.updateByPrimaryKeySelective(shyAudio);
n++;
}
}
} else if (CommonUtils.isNotNull(num) && num > 0) {
Example example = new Example(ShyAudio.class);
example.setOrderByClause("createTime desc");
example.and().andEqualTo("state", CommonConst.AUDIT_INTT);
example.and().andEqualTo("receive", CommonConst.RECEIVE_BEFORE);
if (CommonUtils.isNotNull(spid) && spid != 0) example.and().andEqualTo("spid", spid);
List<ShyAudio> shyCommentsList = shyAudioMapper.selectByExampleAndRowBounds(example, new RowBounds(0, num));
if (!shyCommentsList.isEmpty()) {
for (ShyAudio shyComments : shyCommentsList) {
shyComments.setReceive_user_id(userId);
shyComments.setReceive(CommonConst.RECEIVE_AFTER);
shyAudioMapper.updateByPrimaryKeySelective(shyComments);
n++;
}
}
}
return n;
}
//退领
public ResponseBean retReceive(String ids, String userId) {
String[] cids = ids.split(",");
for (String cid : cids) {
ShyAudio shyAudio = shyAudioMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (shyAudio.getState() == CommonConst.AUDIT_INTT && shyAudio.getReceive()==CommonConst.RECEIVE_AFTER && shyAudio.getReceive_user_id().equals(userId)) {
shyAudio.setReceive(CommonConst.RECEIVE_BEFORE);
shyAudio.setReceive_user_id(null);
int i = shyAudioMapper.updateByPrimaryKey(shyAudio);
if (i != 1) {
return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "退领失败,请重试");
}
} else {
return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "退领失败,您选中的内容包含已退领的或已经审核的");
}
}
return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "已退领");
}
//分页查询音频数据
public PageInfo<ShyAudio> getListContent(String video_title, String start_date, String end_date, Integer state, Integer receive, Integer page, Integer pageSize, String video_priority, String orderByClause, Integer spid, String userId, String sp_Id) {
Example example = new Example(ShyAudio.class);
Example.Criteria criteria = example.createCriteria();
Example.Criteria criteria2 = example.createCriteria();
if (CommonUtils.isNotEmpty(orderByClause)) {
example.setOrderByClause(orderByClause);
}
if (CommonUtils.isNotEmpty(start_date) && CommonUtils.isNotEmpty(end_date)) {
criteria.andGreaterThanOrEqualTo("createTime", start_date);
criteria2.andGreaterThanOrEqualTo("createTime", start_date);
criteria.andLessThanOrEqualTo("createTime", end_date);
criteria2.andLessThanOrEqualTo("createTime", end_date);
}
if (CommonUtils.isNotEmpty(video_title)) {
criteria.andLike("audioTitle", "%" + video_title + "%");
criteria2.andLike("audioTitle", "%" + video_title + "%");
}
if (CommonUtils.isNotEmpty(video_priority)) {
criteria.andEqualTo("priority", video_priority);
criteria2.andEqualTo("priority", video_priority);
}
if (CommonUtils.isNotNull(spid)) {
criteria.andEqualTo("spId", spid);
criteria2.andEqualTo("spId", spid);
} else if (CommonUtils.isNotEmpty(sp_Id)) {
criteria.andEqualTo("spId", sp_Id);
criteria2.andEqualTo("spId", sp_Id);
}
//领取状态 0-未领取 1-已领取
if (CommonUtils.isNotNull(receive)) {
criteria.andEqualTo("receive", receive);
criteria2.andEqualTo("receive", receive);
if (receive == CommonConst.RECEIVE_AFTER) {
criteria.andEqualTo("receive_user_id", userId);
criteria2.andEqualTo("receive_user_id", userId);
}
}
//审核状态 0-未审核 1-已审核 2-拒绝
if (CommonUtils.isNotNull(state) && state != 3) {
criteria.andEqualTo("state", state);
} else if (CommonUtils.isNotNull(state) && state == 3) {
criteria.andEqualTo("state", 1);
criteria2.andEqualTo("state", 2);
example.or(criteria2);
}
//默认按上传时间倒序排序
example.setOrderByClause("createTime desc");
PageHelper.startPage(page, pageSize, true);
List<ShyAudio> shyAudioList = shyAudioMapper.selectByExample(example);
PageInfo<ShyAudio> pageInfo = new PageInfo<>(shyAudioList);
return pageInfo;
}
}