Commit 92fd39fa by leejoker

fix bug

1 parent a3ae04db
...@@ -39,6 +39,7 @@ import java.util.Collection; ...@@ -39,6 +39,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer;
/** /**
* @author danmo * @author danmo
...@@ -230,6 +231,17 @@ public class ElasticSearch { ...@@ -230,6 +231,17 @@ public class ElasticSearch {
} }
} }
public void insertBatchAsync(String idxName, List<JSONObject> list, Consumer<List<JSONObject>> consumer) {
BulkRequest request = new BulkRequest();
list.parallelStream().forEach(item -> request.add(new IndexRequest(idxName, "_doc").id(item.getString("msgid"))
.source(item, XContentType.JSON)));
try {
restHighLevelClient.bulkAsync(request, RequestOptions.DEFAULT, getActionListener(consumer, list));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void updateBatch(String idxName, List<ElasticSearchEntity> list) { public void updateBatch(String idxName, List<ElasticSearchEntity> list) {
BulkRequest request = new BulkRequest(); BulkRequest request = new BulkRequest();
list.forEach(item -> request.add(new UpdateRequest(idxName, item.getId()).upsert(item.getData(), XContentType.JSON))); list.forEach(item -> request.add(new UpdateRequest(idxName, item.getId()).upsert(item.getData(), XContentType.JSON)));
...@@ -377,6 +389,20 @@ public class ElasticSearch { ...@@ -377,6 +389,20 @@ public class ElasticSearch {
} }
} }
public ActionListener getActionListener(Consumer consumer, List<JSONObject> list) {
return new ActionListener() {
@Override
public void onResponse(Object o) {
consumer.accept(list);
}
@Override
public void onFailure(Exception e) {
log.warn("work with es failed, exception={}", ExceptionUtils.getStackTrace(e));
}
};
}
public ActionListener getActionListener(BiConsumer consumer, List<ElasticSearchEntity> list, Object param) { public ActionListener getActionListener(BiConsumer consumer, List<ElasticSearchEntity> list, Object param) {
return new ActionListener() { return new ActionListener() {
@Override @Override
......
...@@ -3,7 +3,6 @@ package com.linkwechat.quartz.task; ...@@ -3,7 +3,6 @@ package com.linkwechat.quartz.task;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
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.redis.RedisCache; import com.linkwechat.common.core.redis.RedisCache;
...@@ -27,7 +26,6 @@ import java.util.List; ...@@ -27,7 +26,6 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
/** /**
* 定时任务调度测试 * 定时任务调度测试
...@@ -92,9 +90,7 @@ public class RyTask { ...@@ -92,9 +90,7 @@ public class RyTask {
List<JSONObject> elasticSearchEntities = weChatContactMappingService.saveWeChatContactMapping(chatDataList); List<JSONObject> elasticSearchEntities = weChatContactMappingService.saveWeChatContactMapping(chatDataList);
//获取敏感行为命中信息 //获取敏感行为命中信息
weSensitiveActHitService.hitWeSensitiveAct(chatDataList); weSensitiveActHitService.hitWeSensitiveAct(chatDataList);
List<Consumer<List<JSONObject>>> consumerList = Lists.newArrayList(); elasticSearch.insertBatchAsync(WeConstans.WECOM_FINANCE_INDEX, elasticSearchEntities, weSensitiveService::hitSensitive);
consumerList.add(weSensitiveService::hitSensitive);
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();
...@@ -161,7 +157,7 @@ public class RyTask { ...@@ -161,7 +157,7 @@ public class RyTask {
semaphore.acquire(); semaphore.acquire();
if (s.getMessageInfo() != null && s.getMessageId() != null || (s.getMessageInfo().getPushType().equals(WeConstans.SEND_MESSAGE_CUSTOMER) if (s.getMessageInfo() != null && s.getMessageId() != null || (s.getMessageInfo().getPushType().equals(WeConstans.SEND_MESSAGE_CUSTOMER)
&& CollectionUtils.isNotEmpty(s.getCustomersInfo())) ||(s.getMessageInfo().getPushType().equals(WeConstans.SEND_MESSAGE_GROUP) && CollectionUtils.isNotEmpty(s.getCustomersInfo())) || (s.getMessageInfo().getPushType().equals(WeConstans.SEND_MESSAGE_GROUP)
&& CollectionUtils.isNotEmpty(s.getGroupsInfo()))) { && CollectionUtils.isNotEmpty(s.getGroupsInfo()))) {
weCustomerMessageService.sendMessgae(s.getMessageInfo(), s.getMessageId(), s.getCustomersInfo(), s.getGroupsInfo()); weCustomerMessageService.sendMessgae(s.getMessageInfo(), s.getMessageId(), s.getCustomersInfo(), s.getGroupsInfo());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!