LiveApplyServiceImpl.java
12.7 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
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
package com.cnlive.shenhe.serviceImpl;
import com.alibaba.fastjson.JSON;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.dto.LiveApplyDTO;
import com.cnlive.shenhe.entity.ShyLiveapply;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.mapper.ShyLiveMapper;
import com.cnlive.shenhe.mapper.ShyLiveapplyMapper;
import com.cnlive.shenhe.mapper.ShyUsersMapper;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.List;
/**
* @Auther: liwei
* @Date: 2018/11/30 14:23
* @Description:
*/
@Service
public class LiveApplyServiceImpl {
private static Logger logger = LoggerFactory.getLogger(LiveApplyServiceImpl.class);
@Autowired
ShyLiveMapper shyLiveMapper;
@Autowired
ShyLiveapplyMapper shyLiveApplyMapper;
@Autowired
ShyUsersMapper shyUsersMapper;
@Autowired
SitesServiceImpl sitesService;
//==============
public boolean impotLiveApply(ShyLiveapply shyLiveApply) {
int result = shyLiveApplyMapper.insertSelective(shyLiveApply);
if (result == 0) {
return false;
}
return true;
}
//==============
public ShyLiveapply selectByPrimaryKey(Integer id) {
ShyLiveapply shyLiveApply = shyLiveApplyMapper.selectByPrimaryKey(id);
return shyLiveApply;
}
//=============
public List<ShyLiveapply> findshyLiveApply(ShyLiveapply shyLiveApply) {
List<ShyLiveapply> shyLiveApplylist = shyLiveApplyMapper.selectByRowBounds(shyLiveApply, new RowBounds(0, 100));
return shyLiveApplylist;
}
public ShyLiveapply queryshyLiveApply(String activity_id) {
ShyLiveapply shyLiveApply =new ShyLiveapply();
shyLiveApply.setActivity_id(activity_id);
List<ShyLiveapply> shyLiveApplylist = shyLiveApplyMapper.select(shyLiveApply);
return shyLiveApplylist.get(0);
}
//==============
public boolean updateshyLiveApply(ShyLiveapply shyLiveApply) {
int i = shyLiveApplyMapper.updateByPrimaryKey(shyLiveApply);
if (i == 0) {
return false;
}
return true;
}
//==============
public int updateLiveApply(Integer id, String auditor_id,String updater, Integer status, String msg) {
ShyLiveapply shyLiveapply = shyLiveApplyMapper.selectByPrimaryKey(id);
shyLiveapply.setAuditor(auditor_id);
shyLiveapply.setShenhe_state(status);
shyLiveapply.setReceive(CommonConst.RECEIVE_AFTER);
shyLiveapply.setShenhe_msg(msg);
shyLiveapply.setUpdater(updater);
shyLiveapply.setUpdated_at(CommonUtils.getCurrentTime());
return shyLiveApplyMapper.updateByPrimaryKey(shyLiveapply);
}
//===============
public PageInfo<ShyLiveapply> getListLiveApply(LiveApplyDTO liveApplyDTO) {
logger.info("接参数列表为,LiveApplyDTO:{}", JSON.toJSONString(liveApplyDTO));
Example example = new Example(ShyLiveapply.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(liveApplyDTO.getOrderByClause())) {
example.setOrderByClause(liveApplyDTO.getOrderByClause());
}else{
example.setOrderByClause("created_at desc");
}
if (CommonUtils.isNotEmpty(liveApplyDTO.getStart_date())) {
Timestamp startdate = null;
try {
startdate = CommonUtils.parseDate(liveApplyDTO.getStart_date(), "yyyy-MM-dd");
} catch (ParseException e) {
e.printStackTrace();
}
criteria.andGreaterThanOrEqualTo("pre_start_time", startdate);
}
if ( CommonUtils.isNotEmpty(liveApplyDTO.getEnd_date())) {
Timestamp enddate = null;
try {
enddate = CommonUtils.parseDate(liveApplyDTO.getEnd_date(), "yyyy-MM-dd");
} catch (ParseException e) {
e.printStackTrace();
}
criteria.andLessThanOrEqualTo("pre_end_time", enddate);
}
if (CommonUtils.isNotEmpty(liveApplyDTO.getTheme())) {
criteria.andLike("theme", "%" + liveApplyDTO.getTheme() + "%");
}
if (CommonUtils.isNotNull(liveApplyDTO.getBusiness_model())) {
criteria.andLike("organization", "%" + liveApplyDTO.getBusiness_model() + "%");
}
if (CommonUtils.isNotNull(liveApplyDTO.getSpid())) {
criteria.andEqualTo("sp_id", liveApplyDTO.getSpid());
}
if (CommonUtils.isNotNull(liveApplyDTO.getShenhe_state())&& liveApplyDTO.getShenhe_state() != 3) {
criteria.andEqualTo("shenhe_state", liveApplyDTO.getShenhe_state());
}else if(CommonUtils.isNotNull(liveApplyDTO.getShenhe_state())&& liveApplyDTO.getShenhe_state() == 3){
criteria.andNotEqualTo("shenhe_state", 0);
}
if (CommonUtils.isNotNull(liveApplyDTO.getReceive())) {
criteria.andEqualTo("receive", liveApplyDTO.getReceive());
if(liveApplyDTO.getReceive()!=0 && CommonUtils.isNotEmpty(liveApplyDTO.getUserId())){
criteria.andEqualTo("auditor", liveApplyDTO.getUserId());
}
}
PageHelper.startPage(liveApplyDTO.getPage(), liveApplyDTO.getPageSize(), true);
List<ShyLiveapply> shyLiveApplyList = shyLiveApplyMapper.selectByExample(example);
PageInfo<ShyLiveapply> pageInfo = new PageInfo<>(shyLiveApplyList);
return pageInfo;
}
//======================
public ShyLiveapply getDetailsLive(Integer id) {
ShyLiveapply shyLiveapply = shyLiveApplyMapper.selectByPrimaryKey(id);
if (!shyLiveapply.getShenhe_state().equals(CommonConst.RECEIVE_BEFORE)) {
String updater = CommonUtils.isEmpty(shyLiveapply.getUpdater()) || "null".equals(shyLiveapply.getUpdater())? "自动通过":shyLiveapply.getUpdater();
String auditor_id = shyLiveapply.getAuditor();
if (CommonUtils.isNotEmpty(auditor_id)) {
ShyUsers user = new ShyUsers();
user.setUser_id(auditor_id);
user = shyUsersMapper.selectOne(user);
String email = CommonUtils.isEmpty(user.getEmail()) || "null".equals(user.getEmail())? "" : user.getEmail();
String userName = CommonUtils.isEmpty(user.getUsername()) ? email: user.getUsername();
updater = userName;
}
shyLiveapply.setUpdater(updater);
}
return shyLiveapply;
}
//====================
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) {
ShyLiveapply shyLiveapply = shyLiveApplyMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (CommonUtils.isNotNull(shyLiveapply) && shyLiveapply.getShenhe_state() == CommonConst.RECEIVE_BEFORE ) {
shyLiveapply.setAuditor(userId);;
shyLiveapply.setShenhe_state(CommonConst.AUDIT_INTT);
shyLiveapply.setReceive(CommonConst.RECEIVE_AFTER);
shyLiveApplyMapper.updateByPrimaryKeySelective(shyLiveapply);
n++;
}
}
} else if (CommonUtils.isNotNull(num) && num > 0) {
Example example = new Example(ShyLiveapply.class);
example.setOrderByClause("pre_start_time asc");
example.and().andEqualTo("shenhe_state", CommonConst.AUDIT_INTT);
example.and().andEqualTo("receive", CommonConst.RECEIVE_BEFORE);
if (CommonUtils.isNotNull(spid) && spid != 0) {
example.and().andEqualTo("spid", spid);
}
List<ShyLiveapply> shyLiveapplyList = shyLiveApplyMapper.selectByExampleAndRowBounds(example, new RowBounds(0, num));
if (!shyLiveapplyList.isEmpty()) {
for (ShyLiveapply shyLiveapply : shyLiveapplyList) {
shyLiveapply.setAuditor(userId);
shyLiveapply.setShenhe_state(CommonConst.AUDIT_INTT);
shyLiveapply.setReceive(CommonConst.RECEIVE_AFTER);
shyLiveApplyMapper.updateByPrimaryKeySelective(shyLiveapply);
n++;
}
}
}
return n;
}
//================
public ResponseBean retReceive(String ids, String userId) {
String[] cids = ids.split(",");
for (String cid : cids) {
ShyLiveapply shyLiveapply = shyLiveApplyMapper.selectByPrimaryKey(Integer.parseInt(cid));
if (shyLiveapply.getShenhe_state().equals(CommonConst.AUDIT_INTT) && shyLiveapply.getReceive().equals(CommonConst.RECEIVE_AFTER) && shyLiveapply.getAuditor().equals(userId)) {
shyLiveapply.setShenhe_state(CommonConst.AUDIT_INTT);
shyLiveapply.setReceive(CommonConst.RECEIVE_BEFORE);
shyLiveapply.setAuditor(null);
int i = shyLiveApplyMapper.updateByPrimaryKey(shyLiveapply);
if (i != 1) {
return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "退领失败,请重试");
}
} else {
return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "退领失败,您选中的内容包含已退领的或已经审核的");
}
}
return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "已退领");
}
/**
* 根据条件导出数据excel
* @return
*/
public List<ShyLiveapply> findByCondition(LiveApplyDTO liveApplyDTO) {
Example example = new Example(ShyLiveapply.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(liveApplyDTO.getOrderByClause())) {
example.setOrderByClause(liveApplyDTO.getOrderByClause());
}else{
example.setOrderByClause("pre_start_time");
}
if (CommonUtils.isNotEmpty(liveApplyDTO.getStart_date())) {
Timestamp startdate = null;
try {
startdate = CommonUtils.parseDate(liveApplyDTO.getStart_date(), "yyyy-MM-dd");
} catch (ParseException e) {
e.printStackTrace();
}
criteria.andGreaterThanOrEqualTo("pre_start_time", startdate);
}
if ( CommonUtils.isNotEmpty(liveApplyDTO.getEnd_date())) {
Timestamp enddate = null;
try {
enddate = CommonUtils.parseDate(liveApplyDTO.getEnd_date(), "yyyy-MM-dd");
} catch (ParseException e) {
e.printStackTrace();
}
criteria.andLessThanOrEqualTo("pre_end_time", enddate);
}
if (CommonUtils.isNotEmpty(liveApplyDTO.getTheme())) {
criteria.andLike("theme", "%" + liveApplyDTO.getTheme() + "%");
}
if (CommonUtils.isNotNull(liveApplyDTO.getBusiness_model())) {
criteria.andEqualTo("business_model", liveApplyDTO.getBusiness_model());
}
if (CommonUtils.isNotNull(liveApplyDTO.getSpid())) {
criteria.andEqualTo("sp_id", liveApplyDTO.getSpid());
}
if (CommonUtils.isNotNull(liveApplyDTO.getShenhe_state())&& liveApplyDTO.getShenhe_state() != 3) {
criteria.andEqualTo("shenhe_state", liveApplyDTO.getShenhe_state());
}else if(CommonUtils.isNotNull(liveApplyDTO.getShenhe_state())&& liveApplyDTO.getShenhe_state() == 3){
criteria.andNotEqualTo("shenhe_state", 0);
}
if (CommonUtils.isNotNull(liveApplyDTO.getReceive())) {
criteria.andEqualTo("receive", liveApplyDTO.getReceive());
if(liveApplyDTO.getReceive()!=0 && CommonUtils.isNotEmpty(liveApplyDTO.getUserId())){
criteria.andEqualTo("auditor", liveApplyDTO.getUserId());
}
}
List<ShyLiveapply> shyLiveApplyList = shyLiveApplyMapper.selectByExample(example);
return shyLiveApplyList;
}
/**
* 获得审核类型
* @param shyLiveApply
*/
public void getShenheType(ShyLiveapply shyLiveApply){
//获取直播频道免审sp
List<Integer> sites = sitesService.getBusinessList(CommonConst.BUSINESS_LIVEAPPLY);
//初始化一个审核状态
Integer shenheType=3;//审核类型,1:免审,2:机审,3:人工审
//如果当前sp是免审sp
if(sites.contains(shyLiveApply.getSp_id())){
shenheType=1;//免审
}
shyLiveApply.setShenhe_type(shenheType);
}
}