Commit aa135c99 by 裴大威

feat 1001903

parent 60c1d3f2
......@@ -30,7 +30,6 @@ import com.pcloud.book.group.entity.BookGroupCipherUser;
import com.pcloud.book.group.entity.BookGroupClassify;
import com.pcloud.book.group.entity.BookGroupServe;
import com.pcloud.book.group.entity.GroupQrcode;
import com.pcloud.book.group.entity.JoinGroupCipher;
import com.pcloud.book.group.enums.QrcodeStatusEnum;
import com.pcloud.book.group.enums.TouchTypeEnum;
import com.pcloud.book.group.tools.SendWeixinRequestTools;
......@@ -809,9 +808,6 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
}
final String content = sendTextDTO.getTextContent().trim();
final String weixinGroupId = sendTextDTO.getWechatGroupId();
final String userWxId = sendTextDTO.getWechatUserId();
final String ip = sendTextDTO.getIp();
final Integer code = sendTextDTO.getCode();
String robotId = sendTextDTO.getWxId();
// 若非之前的机器人则不回复普通关键词
final Boolean groupRobot = wechatGroupConsr.isGroupRobot(robotId);
......@@ -829,18 +825,38 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
if (StringUtil.isEmpty(content) || content.length() > 20) {
return;
}
ReplyKeywordDTO replyKeywordDTO;
List<ReplyKeywordDTO> keywordDTOS = Lists.newArrayList();
final boolean equals = "群主,来个抽奖".equals(content);
if (equals) {
replyKeywordDTO = keywordDao.getByKeyword("群主,来个抽奖");
ReplyKeywordDTO replyKeywordDTO = keywordDao.getByKeyword("群主,来个抽奖");
keywordDTOS.add(replyKeywordDTO);
} else {
//获取匹配关键词
replyKeywordDTO = bookKeywordDao.getKeywordId(classifyQrcodeInfo.getClassifyId(), classifyQrcodeInfo.getBookGroupId(), content);
//获取匹配关键词 需求(1001903)by 20191023
List<ReplyKeywordDTO> replyKeywordDTO = bookKeywordDao.listAllKeywordByClassifyIdAndBookGroupId(classifyQrcodeInfo.getClassifyId(), classifyQrcodeInfo.getBookGroupId());
keywordDTOS.addAll(replyKeywordDTO);
}
if (replyKeywordDTO == null) {
if (CollectionUtils.isEmpty(keywordDTOS)) {
log.info("[关键词消息回复] replyKeywordDTO is null");
return;
}
// 去除被发送内容完整包含的关键词
List<ReplyKeywordDTO> collect = keywordDTOS.stream().filter(x -> content.contains(x.getKeywords())).collect(Collectors.toList());
// 组装发送关键词
for (ReplyKeywordDTO dto : collect) {
sendKeyword(sendTextDTO, dto, classifyQrcodeInfo);
}
}
/**
* 发送关键词
*/
private void sendKeyword(SendTextDTO sendTextDTO, ReplyKeywordDTO replyKeywordDTO, GroupClassifyQrcodeDTO classifyQrcodeInfo) {
final String content = sendTextDTO.getTextContent().trim();
final String weixinGroupId = sendTextDTO.getWechatGroupId();
final String userWxId = sendTextDTO.getWechatUserId();
final String ip = sendTextDTO.getIp();
final Integer code = sendTextDTO.getCode();
String robotId = sendTextDTO.getWxId();
log.info("[关键词回复原始数据] : sendKeywordMessage replyKeywordDTO :{}, robotId:{}, weixinGroupId:{}", replyKeywordDTO, robotId, weixinGroupId);
// 处理链接地址
final boolean isApp = ReplyTypeEnum.APP.value.equals(replyKeywordDTO.getReplyType());
......
......@@ -52,6 +52,11 @@ public interface BookKeywordDao extends BaseDao<BookKeyword> {
ReplyKeywordDTO getKeywordId(Long classifyId, Long bookGroupId, String content);
/**
* 获取分类下所有关键词
*/
List<ReplyKeywordDTO> listAllKeywordByClassifyIdAndBookGroupId(Long classifyId, Long bookGroupId);
/**
* 根据分类ids和群ids批量获取关键词
*/
List<ReplyKeywordDTO> getKeywordIds(List<Long> classifyIds, List<Long> bookGroupIds, String content);
......
......@@ -19,7 +19,6 @@ import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collector;
import java.util.stream.Collectors;
/**
......@@ -67,6 +66,14 @@ public class BookKeywordDaoImpl extends BaseDaoImpl<BookKeyword> implements Book
}
@Override
public List<ReplyKeywordDTO> listAllKeywordByClassifyIdAndBookGroupId(Long classifyId, Long bookGroupId) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("classifyId", classifyId);
paramMap.put("bookGroupId", bookGroupId);
return this.getSqlSession().selectList(this.getStatement("listAllKeywordByClassifyIdAndBookGroupId"), paramMap);
}
@Override
public List<ReplyKeywordDTO> getKeywordIds(List<Long> classifyIds, List<Long> bookGroupIds, String content) {
if (CollectionUtils.isEmpty(classifyIds) || CollectionUtils.isEmpty(bookGroupIds) || StringUtils.isEmpty(content)) {
return Lists.newArrayList();
......
......@@ -206,6 +206,31 @@
order by set_type desc, matching_rule desc, bk.id desc limit 1
</select>
<select id="listAllKeywordByClassifyIdAndBookGroupId" resultType="ReplyKeywordDTO" parameterType="map">
SELECT
k.id keywordId,
k.keywords,
k.reply_type replyType,
k.content,
k.description,
k.link_url linkUrl,
k.pic_url picUrl,
bk.is_warehouse as isWarehouse,
bk.warehouse_id as warehouseId,
k.reply_type replyType,
k.serve_id as serveId,
k.serve_type as serveType
FROM
book_keyword bk
JOIN
keyword k ON bk.keyword_id = k.id
WHERE
bk.is_delete = 0 AND k.is_delete = 0
AND classify_id in (0, ${classifyId})
AND book_group_id = #{bookGroupId}
order by set_type desc, matching_rule desc, bk.id desc
</select>
<select id="getKeywordIds" resultType="ReplyKeywordDTO" parameterType="map">
SELECT
k.id keywordId,
......
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