Commit fc7e2e6d by 阮思源

修改下关键词回复

parent 5b8352ef
...@@ -437,12 +437,24 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -437,12 +437,24 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
} }
final Set<Long> cIds = Sets.newHashSet(); final Set<Long> cIds = Sets.newHashSet();
final Set<Long> bIds = Sets.newHashSet(); final Set<Long> bIds = Sets.newHashSet();
Map<Long, Long> classifyToBookGroupMap = new HashMap<>();
for (JoinGroupCipherDTO dto : dtos) { for (JoinGroupCipherDTO dto : dtos) {
cIds.add(dto.getClassifyId()); cIds.add(dto.getClassifyId());
bIds.add(dto.getBookGroupId()); bIds.add(dto.getBookGroupId());
classifyToBookGroupMap.put(dto.getClassifyId(),dto.getBookGroupId());
} }
final List<Long> classifyIds = Lists.newArrayList(cIds); final List<Long> classifyIds = Lists.newArrayList(cIds);
final List<ReplyKeywordDTO> replyKeywordDTOs = bookKeywordDao.getKeywordIds(classifyIds, Lists.newArrayList(bIds), content); List<ReplyKeywordDTO> replyKeywordDTOs = new ArrayList<>();
Map<Long, Long> keywordClassifyIdMap = new HashMap<>();
for (Long classifyId : classifyIds) {
//获取匹配关键词
ReplyKeywordDTO replyKeywordDTO = bookKeywordDao.getKeywordId(classifyId, classifyToBookGroupMap.get(classifyId), content);
if (replyKeywordDTO == null) {
continue;
}
keywordClassifyIdMap.put(replyKeywordDTO.getKeywordId(), classifyId);
replyKeywordDTOs.add(replyKeywordDTO);
}
final List<GroupClassifyQrcodeDTO> qrcodeDTOS = bookGroupClassifyBiz.listClassifyQrcodeInfo(classifyIds); final List<GroupClassifyQrcodeDTO> qrcodeDTOS = bookGroupClassifyBiz.listClassifyQrcodeInfo(classifyIds);
if (CollectionUtils.isEmpty(replyKeywordDTOs)) { if (CollectionUtils.isEmpty(replyKeywordDTOs)) {
log.info("[关键词消息回复] keywordIds is null"); log.info("[关键词消息回复] keywordIds is null");
...@@ -457,15 +469,19 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -457,15 +469,19 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
for (ReplyKeywordDTO replyKeywordDTO : replyKeywordDTOs) { for (ReplyKeywordDTO replyKeywordDTO : replyKeywordDTOs) {
log.info("[关键词回复原始数据] : sendKeywordMessage replyKeywordDTO :{}, robotId:{}, weixinGroupId:{}", replyKeywordDTO, robotId, weixinGroupId); log.info("[关键词回复原始数据] : sendKeywordMessage replyKeywordDTO :{}, robotId:{}, weixinGroupId:{}", replyKeywordDTO, robotId, weixinGroupId);
// 处理链接地址 // 处理链接地址
final GroupClassifyQrcodeDTO dto = classifyMap.get(replyKeywordDTO.getClassifyId()); Long classifyId = keywordClassifyIdMap.get(replyKeywordDTO.getKeywordId());
final GroupClassifyQrcodeDTO dto = classifyMap.get(classifyId);
if (ReplyTypeEnum.APP.value.equals(replyKeywordDTO.getReplyType()) || ReplyTypeEnum.LINK.value.equals(replyKeywordDTO.getReplyType())) { if (ReplyTypeEnum.APP.value.equals(replyKeywordDTO.getReplyType()) || ReplyTypeEnum.LINK.value.equals(replyKeywordDTO.getReplyType())) {
if(null == dto) { if(null == dto) {
log.info("[关键词消息回复] 分类信息为空 replyKeywordDTO:{}; classifyMap:{}", replyKeywordDTO, classifyMap); log.info("[关键词消息回复] 分类信息为空 replyKeywordDTO:{}; classifyMap:{}", replyKeywordDTO, classifyMap);
continue; continue;
} }
AccountSettingDto accountSettingDto = qrcodeSceneConsr.getWechatInfo(dto.getChannelId()); AccountSettingDto accountSettingDto = qrcodeSceneConsr.getWechatInfo(dto.getChannelId());
String linkUrl = SendWeixinRequestTools.splitUrlNew(accountSettingDto, replyKeywordDTO.getLinkUrl(), replyKeywordDTO.getBookGroupId(), replyKeywordDTO.getClassifyId(), null); String linkUrl = SendWeixinRequestTools.splitUrlNew(accountSettingDto, replyKeywordDTO.getLinkUrl(), dto.getBookGroupId(), dto.getClassifyId(), null);
replyKeywordDTO.setLinkUrl(linkUrl); replyKeywordDTO.setLinkUrl(linkUrl);
if (!StringUtil.isEmpty(linkUrl)) {
replyKeywordDTO.setShortLinkUrl(UrlUtils.getShortUrl4Own(linkUrl));
}
} }
String redisContent = JedisClusterUtils.getJson("BOOK:KEYWORD:" + weixinGroupId + "-" + replyKeywordDTO.getKeywordId(), String.class); String redisContent = JedisClusterUtils.getJson("BOOK:KEYWORD:" + weixinGroupId + "-" + replyKeywordDTO.getKeywordId(), String.class);
// 同一群10秒内不回复同一关键词 // 同一群10秒内不回复同一关键词
...@@ -486,11 +502,18 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -486,11 +502,18 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
if (replyKeywordDTOs.size() <= 1) { if (replyKeywordDTOs.size() <= 1) {
SendWeixinRequestTools.sendKeywordMessage(replyKeywordDTOs.get(0), robotId, weixinGroupId, ip, code); SendWeixinRequestTools.sendKeywordMessage(replyKeywordDTOs.get(0), robotId, weixinGroupId, ip, code);
} else { } else {
// 多条时组装成一条发送 // 多条时文字,应用,链接组装成一条发送
ReplyKeywordDTO d = new ReplyKeywordDTO(); ReplyKeywordDTO d = new ReplyKeywordDTO();
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for (ReplyKeywordDTO dto : replyKeywordDTOs) { for (ReplyKeywordDTO dto : replyKeywordDTOs) {
sb.append(dto.getContent()).append(":").append(dto.getShortLinkUrl()).append("\n"); if (ReplyTypeEnum.APP.value.equals(dto.getReplyType()) || ReplyTypeEnum.LINK.value.equals(dto.getReplyType())) {
sb.append(dto.getKeywords()).append(":").append(dto.getShortLinkUrl()).append("\n");
} else if (ReplyTypeEnum.TEXT.value.equals(dto.getReplyType())){
sb.append(dto.getKeywords()).append(":").append(dto.getContent()).append("\n");
} else if (ReplyTypeEnum.IMAGE.value.equals(dto.getReplyType())) {
SendWeixinRequestTools.sendKeywordMessage(d, robotId, weixinGroupId, ip, code);
continue;
}
} }
d.setContent(sb.toString()); d.setContent(sb.toString());
d.setReplyType(ReplyTypeEnum.TEXT.value); d.setReplyType(ReplyTypeEnum.TEXT.value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment