Commit 68c95a83 by danmo

会话存档扫描修改

1 parent 41765e42
......@@ -99,7 +99,7 @@ public class ElasticSearch {
// request.settings() 手工指定Setting
CreateIndexResponse res = restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);
if (!res.isAcknowledged()) {
throw new RuntimeException("初始化失败");
log.info("初始化失败");
}
} catch (Exception e) {
e.printStackTrace();
......@@ -169,7 +169,7 @@ public class ElasticSearch {
*/
public void insertOrUpdateOne(String idxName, ElasticSearchEntity entity) {
IndexRequest request = new IndexRequest(idxName, "_doc");
log.error("Data : id={},entity={}", entity.getId(), JSON.toJSONString(entity.getData()));
log.info("Data : id={},entity={}", entity.getId(), JSON.toJSONString(entity.getData()));
request.id(entity.getId());
request.source(entity.getData(), XContentType.JSON);
// request.source(JSON.toJSONString(entity.getData()), XContentType.JSON);
......
......@@ -4,7 +4,8 @@ import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.core.domain.elastic.ElasticSearchEntity;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.uuid.IdUtils;
......@@ -17,6 +18,7 @@ import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author sxw
......@@ -62,8 +64,8 @@ public class FinanceUtils {
* @param proxy 代理
* @param passwd 密码
*/
public static List<ElasticSearchEntity> getChatData(long seq, String proxy, String passwd) {
List<ElasticSearchEntity> resList = new ArrayList<>();
public static List<JSONObject> getChatData(long seq, String proxy, String passwd, RedisCache redisCache) {
List<JSONObject> resList = new ArrayList<>();
long slice = Finance.NewSlice();
int ret = Finance.GetChatData(sdk, seq, LIMIT, proxy, passwd, timeout, slice);
if (ret != 0) {
......@@ -73,20 +75,18 @@ public class FinanceUtils {
String content = Finance.GetContentFromSlice(slice);
JSONArray chatdataArr = JSONObject.parseObject(content).getJSONArray("chatdata");
log.info("开始执行数据解析:------------");
AtomicLong LocalSEQ = new AtomicLong();
if (CollectionUtil.isNotEmpty(chatdataArr)) {
chatdataArr.stream().map(data -> (JSONObject) data).forEach(data -> {
try {
ElasticSearchEntity elasticSearchEntity = new ElasticSearchEntity();
long LocalSEQ = data.getLong("seq");
LocalSEQ.set(data.getLong("seq"));
JSONObject jsonObject = decryptChatRecord(sdk, data.getString("encrypt_random_key"),
data.getString("encrypt_chat_msg"), privateKey);
if (jsonObject ==null){
return;
}
jsonObject.put("seq", LocalSEQ);
elasticSearchEntity.setData(jsonObject);
elasticSearchEntity.setId(jsonObject.getString("msgid"));
resList.add(elasticSearchEntity);
jsonObject.put("seq", LocalSEQ.get());
resList.add(jsonObject);
} catch (Exception e) {
e.printStackTrace();
}
......@@ -94,6 +94,7 @@ public class FinanceUtils {
log.info("数据解析完成:------------");
}
Finance.FreeSlice(slice);
redisCache.setCacheObject(WeConstans.CONTACT_SEQ_KEY,LocalSEQ.get());
return resList;
}
......
......@@ -67,18 +67,16 @@ public class RyTask {
log.info(">>>>>>>seq:{}",index.get());
FinanceUtils.initSDK(corpId, secret);
List<ElasticSearchEntity> chatDataList = FinanceUtils.getChatData(index.get(),
List<JSONObject> chatDataList = FinanceUtils.getChatData(index.get(),
"",
"");
"", redisCache);
if (CollectionUtil.isNotEmpty(chatDataList)){
try {
elasticSearch.insertBatch(WeConstans.WECOM_FINANCE_INDEX, chatDataList);
weChatContactMappingService.saveWeChatContactMapping(chatDataList);
List<ElasticSearchEntity> elasticSearchEntities = weChatContactMappingService.saveWeChatContactMapping(chatDataList);
elasticSearch.insertBatch(WeConstans.WECOM_FINANCE_INDEX, elasticSearchEntities);
} catch (Exception e) {
log.error("消息处理异常:ex:{}", e);
e.printStackTrace();
}finally {
setRedisCacheSeqValue(index);
}
}
}
......@@ -90,7 +88,7 @@ public class RyTask {
searchSourceBuilder.size(1);
List<JSONObject> searchResultList = elasticSearch.search(WeConstans.WECOM_FINANCE_INDEX, searchSourceBuilder, JSONObject.class);
searchResultList.stream().findFirst().ifPresent(result ->{
index.set(result.getLong(WeConstans.CONTACT_SEQ_KEY) + 1);
index.set(result.getLong(WeConstans.CONTACT_SEQ_KEY));
});
redisCache.setCacheObject(WeConstans.CONTACT_SEQ_KEY,index);
}
......
package com.linkwechat.wecom.service;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.github.pagehelper.PageInfo;
import com.linkwechat.common.core.domain.elastic.ElasticSearchEntity;
......@@ -69,7 +70,7 @@ public interface IWeChatContactMappingService extends IService<WeChatContactMapp
*
* @param query
*/
public void saveWeChatContactMapping(List<ElasticSearchEntity> query);
public List<ElasticSearchEntity> saveWeChatContactMapping(List<JSONObject> query);
/**
* 按客户查询关系映射列表
......
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
......@@ -18,6 +19,7 @@ import com.linkwechat.wecom.client.WeUserClient;
import com.linkwechat.wecom.domain.WeChatContactMapping;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.domain.dto.WeUserDto;
import com.linkwechat.wecom.domain.dto.customer.CustomerGroupDetail;
import com.linkwechat.wecom.domain.dto.msgaudit.GroupChatVo;
import com.linkwechat.wecom.mapper.WeChatContactMappingMapper;
......@@ -160,33 +162,62 @@ public class WeChatContactMappingServiceImpl extends ServiceImpl<WeChatContactMa
* @param query
*/
@Override
public void saveWeChatContactMapping(List<ElasticSearchEntity> query) {
query.stream().forEach(elasticSearchEntity -> {
public List<ElasticSearchEntity> saveWeChatContactMapping(List<JSONObject> query) {
List<ElasticSearchEntity> resultList = new ArrayList<>();
query.stream().filter(chatData -> StringUtils.isNotEmpty(chatData.getString("from"))).forEach(chatData -> {
ElasticSearchEntity elasticSearchEntity = new ElasticSearchEntity();
elasticSearchEntity.setId(chatData.getString("msgid"));
//发送人映射数据
WeChatContactMapping fromWeChatContactMapping = new WeChatContactMapping();
JSONObject chatData = JSONObject.parseObject(JSONObject.toJSONString(elasticSearchEntity.getData()));
String fromId = chatData.getString("from");
//发送人类型
int fromType = StringUtils.weCustomTypeJudgment(fromId);
fromWeChatContactMapping.setFromId(fromId);
getUserOrCustomerInfo(chatData, fromId, fromType, "fromInfo");
JSONArray tolist = chatData.getJSONArray("tolist");
if (CollectionUtil.isNotEmpty(tolist)) {
//如果是单聊,tolist唯一,只有一个接收人,并判断接收人的类型
if (StringUtils.isEmpty(chatData.getString("roomid"))) {
String idStr = String.valueOf(tolist.get(0));
//接收人类型
int reveiceType = StringUtils.weCustomTypeJudgment(idStr);
fromWeChatContactMapping.setReceiveId(idStr);
//获取接收人信息
getUserOrCustomerInfo(chatData, idStr, reveiceType, "toListInfo");
fromWeChatContactMapping.setIsCustom(reveiceType);
} else {
fromWeChatContactMapping.setRoomId(chatData.getString("roomid"));
CustomerGroupDetail customerGroupDetail = weCustomerGroupClient
.groupChatDetail(new CustomerGroupDetail().new Params(chatData.getString("roomid")));
GroupChatVo groupChatVo = new GroupChatVo();
BeanUtil.copyProperties(customerGroupDetail.getGroup_chat().get(0), groupChatVo);
chatData.put("roomInfo",JSONObject.parse(JSONObject.toJSONString(groupChatVo)));
}
}
//接收人映射数据
WeChatContactMapping reveiceWeChatContactMapping = from2ReveiceData(fromType, fromWeChatContactMapping);
insertWeChatContactMapping(fromWeChatContactMapping);
insertWeChatContactMapping(reveiceWeChatContactMapping);
elasticSearchEntity.setData(chatData);
resultList.add(elasticSearchEntity);
});
return resultList;
}
private void getUserOrCustomerInfo(JSONObject chatData, String fromId, int fromType, String key) {
//获取发送人信息
if (WeConstans.ID_TYPE_USER.equals(fromType)) {
//成员信息
WeUser weUser = weUserMapper.selectOne(new LambdaQueryWrapper<WeUser>().eq(WeUser::getUserId, fromId));
chatData.put(key, JSONObject.parse(JSONObject.toJSONString(weUser)));
} else if (WeConstans.ID_TYPE_EX.equals(fromType)) {
//获取外部联系人信息
WeCustomer weCustomer = weCustomerMapper.selectWeCustomerById(fromId);
chatData.put(key,JSONObject.parse(JSONObject.toJSONString(weCustomer)));
} else if (WeConstans.ID_TYPE_MACHINE.equals(fromType)) {
//拉去机器人信息暂不处理
}
}
@Override
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!