Commit dac43b46 by leejoker

修改查询接口,添加冗余字段

1 parent b2ce6511
...@@ -95,6 +95,8 @@ public class ChatMsgCheckListener implements MessageListener { ...@@ -95,6 +95,8 @@ public class ChatMsgCheckListener implements MessageListener {
wrapper.eq(WeChatContactMsg::getMsgId, msgId); wrapper.eq(WeChatContactMsg::getMsgId, msgId);
WeChatContactMsg ccm = weChatContactMsgService.getOne(wrapper); WeChatContactMsg ccm = weChatContactMsgService.getOne(wrapper);
wccsm.setWeChatContactId(ccm.getId()); wccsm.setWeChatContactId(ccm.getId());
wccsm.setFrom(ccm.getFromId());
wccsm.setMsgTime(ccm.getMsgTime());
int result = weChatContactSensitiveMsgMapper.insert(wccsm); int result = weChatContactSensitiveMsgMapper.insert(wccsm);
if (result > 0) { if (result > 0) {
sendMessage(wccsm, weSensitive); sendMessage(wccsm, weSensitive);
......
package com.linkwechat.wecom.domain; package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.linkwechat.common.annotation.Excel; import com.linkwechat.common.annotation.Excel;
...@@ -12,6 +13,7 @@ import lombok.NoArgsConstructor; ...@@ -12,6 +13,7 @@ import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
/** /**
* @author leejoker <1056650571@qq.com> * @author leejoker <1056650571@qq.com>
...@@ -51,4 +53,13 @@ public class WeChatContactSensitiveMsg extends BaseEntity implements Serializabl ...@@ -51,4 +53,13 @@ public class WeChatContactSensitiveMsg extends BaseEntity implements Serializabl
@Excel(name = "匹配的内容") @Excel(name = "匹配的内容")
@ApiModelProperty("匹配的内容") @ApiModelProperty("匹配的内容")
private String content; private String content;
@Excel(name = "发送用户id")
@ApiModelProperty("发送用户id")
@TableField(value = "from_id")
private String from;
@Excel(name = "发送时间")
@ApiModelProperty("发送时间")
private Date msgTime;
} }
package com.linkwechat.wecom.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author leejoker <1056650571@qq.com>
* @version 1.0
* @date 2021/8/14 9:32
*/
@ApiModel
@Data
public class WeChatContactSensitiveMsgVO {
@ApiModelProperty("发送人")
private String from;
@ApiModelProperty("发送内容")
private String content;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private Date msgtime;
@ApiModelProperty("通知发送状态")
private String status;
@ApiModelProperty("匹配的关键词")
private String patternWords;
}
package com.linkwechat.wecom.service; package com.linkwechat.wecom.service;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.linkwechat.wecom.domain.WeChatContactSensitiveMsg;
import com.linkwechat.wecom.domain.WeSensitive; import com.linkwechat.wecom.domain.WeSensitive;
import com.linkwechat.wecom.domain.WeSensitiveAuditScope; import com.linkwechat.wecom.domain.WeSensitiveAuditScope;
import com.linkwechat.wecom.domain.query.WeSensitiveHitQuery; import com.linkwechat.wecom.domain.query.WeSensitiveHitQuery;
import com.linkwechat.wecom.domain.vo.WeChatContactSensitiveMsgVO;
import java.util.List; import java.util.List;
...@@ -64,7 +62,7 @@ public interface IWeSensitiveService { ...@@ -64,7 +62,7 @@ public interface IWeSensitiveService {
*/ */
public int destroyWeSensitiveByIds(Long[] ids); public int destroyWeSensitiveByIds(Long[] ids);
public PageInfo<JSONObject> getHitSensitiveList(WeSensitiveHitQuery weSensitiveHitQuery); public List<WeChatContactSensitiveMsgVO> getHitSensitiveList(WeSensitiveHitQuery weSensitiveHitQuery);
List<String> getScopeUsers(List<WeSensitiveAuditScope> auditUserScope); List<String> getScopeUsers(List<WeSensitiveAuditScope> auditUserScope);
} }
package com.linkwechat.wecom.service.impl; package com.linkwechat.wecom.service.impl;
import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.linkwechat.common.constant.WeConstans; import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.elasticsearch.ElasticSearch; import com.linkwechat.common.core.elasticsearch.ElasticSearch;
import com.linkwechat.common.core.page.PageDomain;
import com.linkwechat.common.core.page.TableSupport;
import com.linkwechat.common.utils.DateUtils; import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.SecurityUtils; import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeMessagePushClient; import com.linkwechat.wecom.client.WeMessagePushClient;
import com.linkwechat.wecom.domain.WeChatContactSensitiveMsg;
import com.linkwechat.wecom.domain.WeSensitive; import com.linkwechat.wecom.domain.WeSensitive;
import com.linkwechat.wecom.domain.WeSensitiveAuditScope; import com.linkwechat.wecom.domain.WeSensitiveAuditScope;
import com.linkwechat.wecom.domain.WeUser; import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.domain.query.WeSensitiveHitQuery; 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.mapper.WeSensitiveMapper;
import com.linkwechat.wecom.service.IWeCorpAccountService; import com.linkwechat.wecom.service.IWeCorpAccountService;
import com.linkwechat.wecom.service.IWeSensitiveAuditScopeService; import com.linkwechat.wecom.service.IWeSensitiveAuditScopeService;
...@@ -25,10 +25,6 @@ import org.apache.commons.collections4.CollectionUtils; ...@@ -25,10 +25,6 @@ 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.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -65,6 +61,9 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService { ...@@ -65,6 +61,9 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService {
@Autowired @Autowired
private IWeCorpAccountService weCorpAccountService; private IWeCorpAccountService weCorpAccountService;
@Autowired
private WeChatContactSensitiveMsgMapper weChatContactSensitiveMsgMapper;
@Value("${wecome.chatKey}") @Value("${wecome.chatKey}")
private String chartKey; private String chartKey;
...@@ -175,8 +174,7 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService { ...@@ -175,8 +174,7 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService {
} }
@Override @Override
public PageInfo<JSONObject> getHitSensitiveList(WeSensitiveHitQuery weSensitiveHitQuery) { public List<WeChatContactSensitiveMsgVO> 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());
...@@ -185,51 +183,30 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService { ...@@ -185,51 +183,30 @@ public class WeSensitiveServiceImpl implements IWeSensitiveService {
.stream().filter(Objects::nonNull).map(WeUser::getUserId).collect(Collectors.toList()); .stream().filter(Objects::nonNull).map(WeUser::getUserId).collect(Collectors.toList());
userIds.addAll(userIdList); userIds.addAll(userIdList);
} }
PageDomain pageDomain = TableSupport.buildPageRequest(); LambdaQueryWrapper<WeChatContactSensitiveMsg> wrapper = new LambdaQueryWrapper<>();
Integer pageNum = pageDomain.getPageNum() == null ? 1 : pageDomain.getPageNum(); wrapper.in(WeChatContactSensitiveMsg::getFrom, userIds);
Integer pageSize = pageDomain.getPageSize() == null ? 10 : pageDomain.getPageSize();
SearchSourceBuilder builder = new SearchSourceBuilder();
int from = (pageNum - 1) * pageSize;
builder.size(pageSize);
builder.from(from);
builder.sort("msgtime", SortOrder.DESC);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
BoolQueryBuilder userBuilder = QueryBuilders.boolQuery();
userIds.forEach(user -> {
userBuilder.should(QueryBuilders.termQuery("from.keyword", user));
});
userBuilder.minimumShouldMatch(1);
boolQueryBuilder.must(userBuilder);
if (StringUtils.isNotBlank(weSensitiveHitQuery.getKeyword())) { if (StringUtils.isNotBlank(weSensitiveHitQuery.getKeyword())) {
BoolQueryBuilder keywordBuilder = QueryBuilders.boolQuery().should(QueryBuilders.matchPhraseQuery("content", weSensitiveHitQuery.getKeyword())); wrapper.like(WeChatContactSensitiveMsg::getPatternWords, weSensitiveHitQuery.getKeyword());
boolQueryBuilder.must(keywordBuilder);
} }
builder.query(boolQueryBuilder); wrapper.orderByDesc(WeChatContactSensitiveMsg::getMsgTime);
PageInfo<JSONObject> pageInfo = elasticSearch.searchPage(WeConstans.WECOM_SENSITIVE_HIT_INDEX, builder, pageNum, pageSize, JSONObject.class); List<WeChatContactSensitiveMsg> msgList = weChatContactSensitiveMsgMapper.selectList(wrapper);
return hitPageInfoHandler(pageInfo); return hitPageInfoHandler(msgList);
} }
private PageInfo<JSONObject> hitPageInfoHandler(PageInfo<JSONObject> pageInfo) { private List<WeChatContactSensitiveMsgVO> hitPageInfoHandler(List<WeChatContactSensitiveMsg> msgList) {
List<JSONObject> jsonList = pageInfo.getList(); List<WeChatContactSensitiveMsgVO> voList = Lists.newArrayList();
if (CollectionUtils.isNotEmpty(jsonList)) { if (CollectionUtils.isNotEmpty(msgList)) {
List<JSONObject> newList = jsonList.stream().map(j -> { msgList.forEach(msg -> {
JSONObject json = new JSONObject(); WeChatContactSensitiveMsgVO vo = new WeChatContactSensitiveMsgVO();
String userId = j.getString("from"); vo.setContent(msg.getContent());
WeUser user = new WeUser(); vo.setFrom(msg.getFrom());
user.setUserId(userId); vo.setMsgtime(msg.getMsgTime());
List<WeUser> uList = weUserService.getList(user); vo.setStatus(msg.getSendStatus().toString());
if (CollectionUtils.isNotEmpty(uList)) { vo.setPatternWords(msg.getPatternWords());
json.put("from", uList.get(0).getName()); voList.add(vo);
json.put("content", j.getString("content")); });
json.put("msgtime", j.getString("msgtime"));
json.put("status", j.getString("status"));
json.put("patternWords", j.getString("pattern_words"));
}
return json;
}).collect(Collectors.toList());
pageInfo.setList(newList);
} }
return pageInfo; return voList;
} }
public List<String> getScopeUsers(List<WeSensitiveAuditScope> scopeList) { public List<String> getScopeUsers(List<WeSensitiveAuditScope> scopeList) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!