WeSensitiveServiceImpl.java
8.34 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
package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.elasticsearch.ElasticSearch;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeMessagePushClient;
import com.linkwechat.wecom.domain.WeChatContactSensitiveMsg;
import com.linkwechat.wecom.domain.WeSensitive;
import com.linkwechat.wecom.domain.WeSensitiveAuditScope;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.domain.query.WeSensitiveHitQuery;
import com.linkwechat.wecom.domain.vo.WeChatContactSensitiveMsgVO;
import com.linkwechat.wecom.mapper.WeChatContactSensitiveMsgMapper;
import com.linkwechat.wecom.mapper.WeSensitiveMapper;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import com.linkwechat.wecom.service.IWeSensitiveAuditScopeService;
import com.linkwechat.wecom.service.IWeSensitiveService;
import com.linkwechat.wecom.service.IWeUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.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.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 敏感词设置Service业务层处理
*
* @author ruoyi
* @date 2020-12-29
*/
@Service
@Slf4j
public class WeSensitiveServiceImpl implements IWeSensitiveService {
@Autowired
private WeSensitiveMapper weSensitiveMapper;
@Autowired
private IWeSensitiveAuditScopeService sensitiveAuditScopeService;
@Autowired
private ElasticSearch elasticSearch;
@Autowired
private IWeUserService weUserService;
@Autowired
private WeMessagePushClient weMessagePushClient;
@Autowired
private IWeCorpAccountService weCorpAccountService;
@Autowired
private WeChatContactSensitiveMsgMapper weChatContactSensitiveMsgMapper;
/**
* 查询敏感词设置
*
* @param id 敏感词设置ID
* @return 敏感词设置
*/
@Override
public WeSensitive selectWeSensitiveById(Long id) {
return weSensitiveMapper.selectWeSensitiveById(id);
}
/**
* 查询敏感词设置列表
*
* @param weSensitive 敏感词设置
* @return 敏感词设置
*/
@Override
public List<WeSensitive> selectWeSensitiveList(WeSensitive weSensitive) {
return weSensitiveMapper.selectWeSensitiveList(weSensitive);
}
/**
* 新增敏感词设置
*
* @param weSensitive 敏感词设置
* @return 结果
*/
@Override
@Transactional
public int insertWeSensitive(WeSensitive weSensitive) {
weSensitive.setCreateBy(SecurityUtils.getUsername());
weSensitive.setCreateTime(DateUtils.getNowDate());
int insertResult = weSensitiveMapper.insertWeSensitive(weSensitive);
if (insertResult > 0) {
if (CollectionUtils.isNotEmpty(weSensitive.getAuditUserScope())) {
if (weSensitive.getId() != null) {
weSensitive.getAuditUserScope().forEach(scope -> {
scope.setSensitiveId(weSensitive.getId());
});
sensitiveAuditScopeService.insertWeSensitiveAuditScopeList(weSensitive.getAuditUserScope());
}
}
}
return insertResult;
}
/**
* 修改敏感词设置
*
* @param weSensitive 敏感词设置
* @return 结果
*/
@Override
@Transactional
public int updateWeSensitive(WeSensitive weSensitive) {
weSensitive.setUpdateBy(SecurityUtils.getUsername());
weSensitive.setUpdateTime(DateUtils.getNowDate());
int updateResult = weSensitiveMapper.updateWeSensitive(weSensitive);
if (updateResult > 0 && weSensitive.getAuditUserScope() != null) {
//删除原有关联信息
sensitiveAuditScopeService.deleteAuditScopeBySensitiveId(weSensitive.getId());
if (CollectionUtils.isNotEmpty(weSensitive.getAuditUserScope())) {
weSensitive.getAuditUserScope().forEach(scope -> {
scope.setSensitiveId(weSensitive.getId());
});
sensitiveAuditScopeService.insertWeSensitiveAuditScopeList(weSensitive.getAuditUserScope());
}
}
return updateResult;
}
/**
* 批量删除敏感词设置
*
* @param ids 需要删除的敏感词设置ID
* @return 结果
*/
@Override
public int deleteWeSensitiveByIds(Long[] ids) {
List<WeSensitive> sensitiveList = weSensitiveMapper.selectWeSensitiveByIds(ids);
sensitiveList.forEach(sensitive -> {
sensitive.setDelFlag(1);
sensitive.setUpdateBy(SecurityUtils.getUsername());
sensitive.setUpdateTime(DateUtils.getNowDate());
});
return weSensitiveMapper.batchUpdateWeSensitive(sensitiveList);
}
/**
* 批量删除敏感词配置数据
*
* @param ids 敏感词设置ID
* @return 结果
*/
@Override
@Transactional
public int destroyWeSensitiveByIds(Long[] ids) {
int deleteResult = weSensitiveMapper.deleteWeSensitiveByIds(ids);
if (deleteResult > 0) {
//删除关联数据
sensitiveAuditScopeService.deleteAuditScopeBySensitiveIds(ids);
}
return deleteResult;
}
@Override
public List<WeChatContactSensitiveMsgVO> getHitSensitiveList(WeSensitiveHitQuery weSensitiveHitQuery) {
List<String> userIds = Lists.newArrayList();
if (ObjectUtil.equal(WeConstans.USE_SCOP_BUSINESSID_TYPE_USER,weSensitiveHitQuery.getScopeType())) {
userIds.add(weSensitiveHitQuery.getAuditScopeId());
} else {
List<String> userIdList = weUserService.getList(WeUser.builder().department(weSensitiveHitQuery.getAuditScopeId()).build())
.stream().filter(Objects::nonNull).map(WeUser::getUserId).collect(Collectors.toList());
userIds.addAll(userIdList);
}
LambdaQueryWrapper<WeChatContactSensitiveMsg> wrapper = new LambdaQueryWrapper<>();
if(CollectionUtil.isNotEmpty(userIds)){
wrapper.in(WeChatContactSensitiveMsg::getFromId, userIds);
}
if (StringUtils.isNotBlank(weSensitiveHitQuery.getKeyword())) {
wrapper.like(WeChatContactSensitiveMsg::getPatternWords, weSensitiveHitQuery.getKeyword());
}
wrapper.orderByDesc(WeChatContactSensitiveMsg::getMsgTime);
List<WeChatContactSensitiveMsg> msgList = weChatContactSensitiveMsgMapper.selectList(wrapper);
return hitPageInfoHandler(msgList);
}
private List<WeChatContactSensitiveMsgVO> hitPageInfoHandler(List<WeChatContactSensitiveMsg> msgList) {
List<WeChatContactSensitiveMsgVO> voList = Lists.newArrayList();
if (CollectionUtils.isNotEmpty(msgList)) {
msgList.forEach(msg -> {
WeChatContactSensitiveMsgVO vo = new WeChatContactSensitiveMsgVO();
vo.setContent(msg.getContent());
vo.setFromId(msg.getFromId());
vo.setMsgtime(msg.getMsgTime());
vo.setStatus(msg.getSendStatus().toString());
vo.setPatternWords(msg.getPatternWords());
voList.add(vo);
});
}
return voList;
}
public List<String> getScopeUsers(List<WeSensitiveAuditScope> scopeList) {
List<String> users = Lists.newArrayList();
scopeList.forEach(scope -> {
if (scope.getScopeType().equals(WeConstans.USE_SCOP_BUSINESSID_TYPE_USER)) {
users.add(scope.getAuditScopeId());
} else {
List<String> userIdList = weUserService.getList(WeUser.builder().department(scope.getAuditScopeId()).build())
.stream().filter(Objects::nonNull).map(WeUser::getUserId).collect(Collectors.toList());
users.addAll(userIdList);
}
});
return users;
}
}