TopicServiceImpl.java
7.35 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
package com.cnlive.shenhe.service.serviceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.dto.TopicDTO;
import com.cnlive.shenhe.entity.ShyTopic;
import com.cnlive.shenhe.mapper.ShyTopicMapper;
import com.cnlive.shenhe.service.SitesService;
import com.cnlive.shenhe.service.TopicService;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.cnlive.shenhe.utils.TransitServiceUtils;
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.util.List;
/**
* @Auther: liwei
* @Date: 2019/5/20 17:30
* @Description:
*/
@Service
public class TopicServiceImpl implements TopicService {
private static Logger logger = LoggerFactory.getLogger(TopicServiceImpl.class);
@Autowired
ShyTopicMapper shyTopicMapper;
@Autowired
TransitServiceUtils transitServiceUtils;
@Autowired
SitesService sitesService;
/**
* 获取话题实体对象
*
* @param shyTopic
* @return
*/
@Override
public ShyTopic getShyTopic(ShyTopic shyTopic) {
List<ShyTopic> shyTopicList = shyTopicMapper.select(shyTopic);
if (CommonUtils.isNotNull(shyTopicList) && shyTopicList.size() > 0) {
return shyTopicList.get(0);
}
return new ShyTopic();
}
/**
* 根据条件获取话题列表集合
*
* @param shyTopic
* @return
*/
@Override
public List<ShyTopic> findShyTopic(ShyTopic shyTopic) {
return shyTopicMapper.selectByRowBounds(shyTopic, new RowBounds(0, 100));
}
/**
* 修改话题 返回布尔类型
*
* @param shyTopic
* @return
*/
@Override
public boolean updateShyTopic(ShyTopic shyTopic) {
int result = shyTopicMapper.updateByPrimaryKey(shyTopic);
return result != 0;
}
/**
* 导入话题 返回布尔类型
*
* @param shyTopic
* @return
*/
@Override
public boolean impotShyTopic(ShyTopic shyTopic) {
int result = shyTopicMapper.insertSelective(shyTopic);
return result != 0;
}
/**
* 分页、条件查询列表
*
* @param topicDTO
* @return
*/
@Override
public PageInfo<ShyTopic> getPage(TopicDTO topicDTO) {
logger.info("接受参数列表为,TopicDTO:{}", JSON.toJSONString(topicDTO));
Example example = new Example(ShyTopic.class);
Example.Criteria criteria = example.createCriteria();
if (CommonUtils.isNotEmpty(topicDTO.getOrderByClause())) {
example.setOrderByClause(topicDTO.getOrderByClause());
} else {
example.setOrderByClause("create_date desc");
}
if (CommonUtils.isNotEmpty(topicDTO.getStart_date())) {
criteria.andGreaterThanOrEqualTo("create_date", topicDTO.getStart_date());
}
if (CommonUtils.isNotEmpty(topicDTO.getEnd_date())) {
criteria.andLessThanOrEqualTo("create_date", topicDTO.getEnd_date());
}
if (CommonUtils.isNotEmpty(topicDTO.getTopic_name())) {
criteria.andLike("title", "%" + topicDTO.getTopic_name() + "%");
}
if (CommonUtils.isNotEmpty(topicDTO.getUpdater())) {
criteria.andEqualTo("updater", topicDTO.getUpdater());
}
if (CommonUtils.isNotEmpty(topicDTO.getTopic_tag())) {
criteria.andEqualTo("topic_tag", topicDTO.getTopic_tag());
}
if (CommonUtils.isNotNull(topicDTO.getSpid())) {
criteria.andEqualTo("sp_id", topicDTO.getSpid());
}
if (CommonUtils.isNotEmpty(topicDTO.getTopic_id())) {
criteria.andEqualTo("topic_id", topicDTO.getTopic_id());
}
if (CommonUtils.isNotNull(topicDTO.getReceive()) && topicDTO.getReceive().equals(CommonConst.RECEIVE_AFTER)) {
criteria.andEqualTo("auditor_id", topicDTO.getUserId());
}
//不是 我的已审 进来的,只查一种状态
if (CommonUtils.isNotNull(topicDTO.getShenhe_status()) && topicDTO.getShenhe_status() != 3) {
criteria.andEqualTo("shenhe_status", topicDTO.getShenhe_status());
//是 我的已审,查通过和拒绝的两种状态
} else if (CommonUtils.isNotNull(topicDTO.getShenhe_status()) && topicDTO.getShenhe_status() == 3) {
criteria.andBetween("shenhe_status", CommonConst.AUDIT_SUCCESS, CommonConst.AUDIT_REFUSE);
}
PageHelper.startPage(topicDTO.getPage(), topicDTO.getPageSize(), true);
List<ShyTopic> topicList = shyTopicMapper.selectByExample(example);
PageInfo<ShyTopic> pageInfo = new PageInfo<>(topicList);
return pageInfo;
}
/**
* 话题回调
*
* @param id
* @param msg
* @param state
* @param userId
* @param updater
* @return
*/
@Override
public boolean callback(String id, String msg, Integer state, String userId, String updater) {
boolean success;
ShyTopic topic = shyTopicMapper.selectByPrimaryKey(Integer.parseInt(id));
JSONObject params = new JSONObject();
params.put("topic_id", topic.getTopic_id());
params.put("status", state + 1);
params.put("msg", msg);
success = transitServiceUtils.send("cms", "updateTopicStatus", true, params);
if (!success) {
logger.error("话题审核回调失败,话题表id:{}", topic.getId());
return success;
}
// 设置话题状态为审核后的状态
topic.setShenhe_status(state);
// 设置审核消息
topic.setShenhe_msg(msg);
if (CommonUtils.isNotEmpty(userId)) {
topic.setAuditor_id(userId);
// 设置审核类型为人工
topic.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
} else {
//设置更新人
topic.setUpdater(updater);
}
topic.setUpdate_date(CommonUtils.getCurrentTime());
int i = shyTopicMapper.updateByPrimaryKeySelective(topic);
if (i != 1) {
success = false;
}
return success;
}
/**
* 根据主键id查询话题对象
*
* @param id
* @return
*/
@Override
public ShyTopic selectByPrimaryKey(Integer id) {
return shyTopicMapper.selectByPrimaryKey(id);
}
/**
* 根据主键修改话题对象
*
* @param topic
* @return
*/
@Override
public int updateByPrimaryKeySelective(ShyTopic topic) {
return shyTopicMapper.updateByPrimaryKeySelective(topic);
}
/**
* 获得审核类型
*
* @param spId
*/
@Override
public Integer getShenheType(Integer spId) {
//获取图文免审sp
List<Integer> sites = sitesService.getBusinessList(CommonConst.BUSINESS_TOPIC);
//初始化一个审核状态
//审核类型,1:免审,2:机审,3:人工审
Integer shenheType = CommonConst.AUDIT_TYPE_USER;
//如果当前sp是免审sp
if (sites.contains(spId)) {
//免审
shenheType = CommonConst.AUDIT_TYPE_FREE;
}
return shenheType;
}
}