Commit e5877b14 by ws

Merge remote-tracking branch 'origin/back_end_dev' into back_end_dev

2 parents 3da31fba 8a9b6401
...@@ -30,9 +30,9 @@ public class WeChatSideController extends BaseController { ...@@ -30,9 +30,9 @@ public class WeChatSideController extends BaseController {
*/ */
@PreAuthorize("@ss.hasPermi('chat:side:list')") @PreAuthorize("@ss.hasPermi('chat:side:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list() { public TableDataInfo list(@RequestParam(value = "h5") String h5) {
startPage(); startPage();
List<WeChatSide> weChatSides = weChatSideService.chatSides(); List<WeChatSide> weChatSides = weChatSideService.chatSides(h5);
return getDataTable(weChatSides); return getDataTable(weChatSides);
} }
......
...@@ -216,7 +216,7 @@ public class ElasticSearch { ...@@ -216,7 +216,7 @@ public class ElasticSearch {
*/ */
public void insertBatchAsync(String idxName, List<JSONObject> list, List<Consumer<List<JSONObject>>> consumers) { public void insertBatchAsync(String idxName, List<JSONObject> list, List<Consumer<List<JSONObject>>> consumers) {
BulkRequest request = new BulkRequest(); BulkRequest request = new BulkRequest();
list.forEach(item -> request.add(new IndexRequest(idxName, "_doc").id(item.getString("msgid")) list.parallelStream().forEach(item -> request.add(new IndexRequest(idxName, "_doc").id(item.getString("msgid"))
.source(item, XContentType.JSON))); .source(item, XContentType.JSON)));
try { try {
restHighLevelClient.bulkAsync(request, RequestOptions.DEFAULT, getActionListener(list, consumers)); restHighLevelClient.bulkAsync(request, RequestOptions.DEFAULT, getActionListener(list, consumers));
......
...@@ -76,10 +76,10 @@ public class RyTask { ...@@ -76,10 +76,10 @@ public class RyTask {
"", redisCache); "", redisCache);
if (CollectionUtil.isNotEmpty(chatDataList)){ if (CollectionUtil.isNotEmpty(chatDataList)){
try { try {
List<JSONObject> elasticSearchEntities = weChatContactMappingService.saveWeChatContactMapping(chatDataList);
List<Consumer<List<JSONObject>>> consumerList = Lists.newArrayList(); List<Consumer<List<JSONObject>>> consumerList = Lists.newArrayList();
consumerList.add(weChatContactMappingService::saveWeChatContactMapping);
consumerList.add(weSensitiveService::hitSensitive); consumerList.add(weSensitiveService::hitSensitive);
elasticSearch.insertBatchAsync(WeConstans.WECOM_FINANCE_INDEX, chatDataList, consumerList); elasticSearch.insertBatchAsync(WeConstans.WECOM_FINANCE_INDEX, elasticSearchEntities, consumerList);
} catch (Exception e) { } catch (Exception e) {
log.error("消息处理异常:ex:{}", e); log.error("消息处理异常:ex:{}", e);
e.printStackTrace(); e.printStackTrace();
......
...@@ -15,10 +15,10 @@ public interface WeChatSideMapper extends BaseMapper<WeChatSide> { ...@@ -15,10 +15,10 @@ public interface WeChatSideMapper extends BaseMapper<WeChatSide> {
/** /**
* 查询侧边栏列表 * 查询侧边栏列表
* * @param h5 0 pc 1 h5
* @return {@link WeChatSide}s * @return {@link WeChatSide}s
*/ */
public List<WeChatSide> selectWeChatSides(); public List<WeChatSide> selectWeChatSides(@Param("h5") String h5);
/** /**
......
...@@ -70,7 +70,7 @@ public interface IWeChatContactMappingService extends IService<WeChatContactMapp ...@@ -70,7 +70,7 @@ public interface IWeChatContactMappingService extends IService<WeChatContactMapp
* *
* @param query * @param query
*/ */
public List<ElasticSearchEntity> saveWeChatContactMapping(List<JSONObject> query); public List<JSONObject> saveWeChatContactMapping(List<JSONObject> query);
/** /**
* 按客户查询关系映射列表 * 按客户查询关系映射列表
......
...@@ -16,7 +16,7 @@ public interface IWeChatSideService extends IService<WeChatSide> { ...@@ -16,7 +16,7 @@ public interface IWeChatSideService extends IService<WeChatSide> {
* *
* @return {@link WeChatSide}s * @return {@link WeChatSide}s
*/ */
public List<WeChatSide> chatSides(); public List<WeChatSide> chatSides(String h5);
/** /**
* 更新侧边栏信息 * 更新侧边栏信息
......
...@@ -160,11 +160,9 @@ public class WeChatContactMappingServiceImpl extends ServiceImpl<WeChatContactMa ...@@ -160,11 +160,9 @@ public class WeChatContactMappingServiceImpl extends ServiceImpl<WeChatContactMa
* @param query * @param query
*/ */
@Override @Override
public List<ElasticSearchEntity> saveWeChatContactMapping(List<JSONObject> query) { public List<JSONObject> saveWeChatContactMapping(List<JSONObject> query) {
List<ElasticSearchEntity> resultList = new ArrayList<>(); List<JSONObject> resultList = new ArrayList<>();
query.stream().filter(chatData -> StringUtils.isNotEmpty(chatData.getString("from"))).forEach(chatData -> { query.stream().filter(chatData -> StringUtils.isNotEmpty(chatData.getString("from"))).forEach(chatData -> {
ElasticSearchEntity elasticSearchEntity = new ElasticSearchEntity();
elasticSearchEntity.setId(chatData.getString("msgid"));
//发送人映射数据 //发送人映射数据
WeChatContactMapping fromWeChatContactMapping = new WeChatContactMapping(); WeChatContactMapping fromWeChatContactMapping = new WeChatContactMapping();
String fromId = chatData.getString("from"); String fromId = chatData.getString("from");
...@@ -194,8 +192,7 @@ public class WeChatContactMappingServiceImpl extends ServiceImpl<WeChatContactMa ...@@ -194,8 +192,7 @@ public class WeChatContactMappingServiceImpl extends ServiceImpl<WeChatContactMa
WeChatContactMapping reveiceWeChatContactMapping = from2ReveiceData(fromType, fromWeChatContactMapping); WeChatContactMapping reveiceWeChatContactMapping = from2ReveiceData(fromType, fromWeChatContactMapping);
insertWeChatContactMapping(fromWeChatContactMapping); insertWeChatContactMapping(fromWeChatContactMapping);
insertWeChatContactMapping(reveiceWeChatContactMapping); insertWeChatContactMapping(reveiceWeChatContactMapping);
elasticSearchEntity.setData(chatData); resultList.add(chatData);
resultList.add(elasticSearchEntity);
}); });
return resultList; return resultList;
} }
......
...@@ -21,8 +21,8 @@ public class WeChatSideServiceImpl extends ServiceImpl<WeChatSideMapper, WeChatS ...@@ -21,8 +21,8 @@ public class WeChatSideServiceImpl extends ServiceImpl<WeChatSideMapper, WeChatS
private WeChatSideMapper weChatSideMapper; private WeChatSideMapper weChatSideMapper;
@Override @Override
public List<WeChatSide> chatSides() { public List<WeChatSide> chatSides(String h5) {
return weChatSideMapper.selectWeChatSides(); return weChatSideMapper.selectWeChatSides(h5);
} }
@Override @Override
......
...@@ -22,6 +22,8 @@ import com.linkwechat.wecom.service.IWeUserService; ...@@ -22,6 +22,8 @@ import com.linkwechat.wecom.service.IWeUserService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
...@@ -30,7 +32,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -30,7 +32,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -165,6 +166,7 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService { ...@@ -165,6 +166,7 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService {
@Override @Override
public void hitSensitive(List<JSONObject> entityList) { public void hitSensitive(List<JSONObject> entityList) {
log.info("执行敏感词命中过滤,time=[{}]", System.currentTimeMillis());
//获取所有的敏感词规则 //获取所有的敏感词规则
List<WeSensitive> allSensitiveRules = weSensitiveMapper.selectWeSensitiveList(new WeSensitive()); List<WeSensitive> allSensitiveRules = weSensitiveMapper.selectWeSensitiveList(new WeSensitive());
//根据规则过滤命中 //根据规则过滤命中
...@@ -175,18 +177,14 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService { ...@@ -175,18 +177,14 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService {
List<String> users = getScopeUsers(weSensitive.getAuditUserScope()); List<String> users = getScopeUsers(weSensitive.getAuditUserScope());
jsonList.addAll(hitSensitiveInES(patternWords, users)); jsonList.addAll(hitSensitiveInES(patternWords, users));
//将命中结果插入es //将命中结果插入es
try {
addHitSensitiveList(jsonList, weSensitive); addHitSensitiveList(jsonList, weSensitive);
} catch (IOException e) {
log.warn("添加敏感词命中信息失败, jsonList={}, auditUserId={}, exception={}",
jsonList, weSensitive.getAuditUserId(), ExceptionUtils.getStackTrace(e));
}
}); });
} }
} }
@Override @Override
public PageInfo<JSONObject> getHitSensitiveList(WeSensitiveHitQuery weSensitiveHitQuery) { public PageInfo<JSONObject> getHitSensitiveList(WeSensitiveHitQuery weSensitiveHitQuery) {
elasticSearch.createIndex2(WeConstans.WECOM_SENSITIVE_HIT_INDEX, getSensitiveHitMapping());
List<String> userIds = Lists.newArrayList(); List<String> userIds = Lists.newArrayList();
if (weSensitiveHitQuery.getScopeType().equals(WeConstans.USE_SCOP_BUSINESSID_TYPE_USER)) { if (weSensitiveHitQuery.getScopeType().equals(WeConstans.USE_SCOP_BUSINESSID_TYPE_USER)) {
userIds.add(weSensitiveHitQuery.getAuditScopeId()); userIds.add(weSensitiveHitQuery.getAuditScopeId());
...@@ -218,9 +216,8 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService { ...@@ -218,9 +216,8 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService {
return elasticSearch.searchPage(WeConstans.WECOM_SENSITIVE_HIT_INDEX, builder, pageNum, pageSize, JSONObject.class); return elasticSearch.searchPage(WeConstans.WECOM_SENSITIVE_HIT_INDEX, builder, pageNum, pageSize, JSONObject.class);
} }
private void addHitSensitiveList(List<JSONObject> json, WeSensitive weSensitive) throws IOException { private void addHitSensitiveList(List<JSONObject> json, WeSensitive weSensitive) {
//创建索引 elasticSearch.createIndex2(WeConstans.WECOM_SENSITIVE_HIT_INDEX, getSensitiveHitMapping());
elasticSearch.createIndex2(WeConstans.WECOM_SENSITIVE_HIT_INDEX, elasticSearch.getFinanceMapping());
if (weSensitive.getAlertFlag().equals(1)) { if (weSensitive.getAlertFlag().equals(1)) {
//针对每一条命中信息发送消息通知给相应的审计人 TODO //针对每一条命中信息发送消息通知给相应的审计人 TODO
} }
...@@ -270,4 +267,43 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService { ...@@ -270,4 +267,43 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService {
builder.query(searchBuilder); builder.query(searchBuilder);
return elasticSearch.search(WeConstans.WECOM_FINANCE_INDEX, builder, JSONObject.class); return elasticSearch.search(WeConstans.WECOM_FINANCE_INDEX, builder, JSONObject.class);
} }
private XContentBuilder getSensitiveHitMapping() {
try {
//创建索引
XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject("msgid")
.field("type", "keyword")
.endObject()
.startObject("seq")
.field("type", "long")
.endObject()
.startObject("action")
.field("type", "keyword")
.endObject()
.startObject("from")
.field("type", "keyword")
.endObject()
.startObject("roomid")
.field("type", "keyword")
.endObject()
.startObject("msgtime")
.field("type", "long")
.endObject()
.startObject("msgtype")
.field("type", "keyword")
.endObject()
.startObject("alerted")
.field("type", "keyword")
.endObject()
.endObject()
.endObject();
return mapping;
} catch (Exception e) {
log.warn("create sensitive-hit mapping failed, exception={}", ExceptionUtils.getStackTrace(e));
}
return null;
}
} }
...@@ -31,7 +31,9 @@ ...@@ -31,7 +31,9 @@
FROM FROM
we_chat_side we_chat_side
<where> <where>
<if test="h5!=null and h5!='' and h5=='1'.toString()">
`using`=0 `using`=0
</if>
</where> </where>
</select> </select>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!