Commit f8edf969 by 桂前礼

feat:[1004024] 微信群被封处理-转企业微信个人号流程

parent 6c2dc8e4
package com.pcloud.book.group.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
/**
* TODO
*
* @author guiq
* @version 1.0
* @since 2020/12/9
*/
@Getter
@Setter
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ReplyMsgDTO {
@ApiModelProperty("1 文本 | 2 图片 | 3 链接")
private Integer msgType;
private String keyWord;
private String content;
private String imgUrl;
private String desc;
private String title;
private String url;
}
package com.pcloud.book.group.service;
import com.pcloud.book.group.dto.ReplyMsgDTO;
import com.pcloud.common.dto.ResponseDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient(value = "pcloud-service-book", qualifier = "wxWorkKeyWordServiceCloud", path = "book/v1.0/wxWorkKeyWordService")
@Api(description = "关键词内部接口")
public interface WxWorkKeyWordService {
@ApiOperation("根据群分类ID获取关键词回复")
@GetMapping("/getKeyWordsByClassify")
ResponseEntity<ResponseDto<List<ReplyMsgDTO>>> getKeyWordsByClassify(@RequestParam("classifyId") Long classifyId);
}
...@@ -717,11 +717,13 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz { ...@@ -717,11 +717,13 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
@Override @Override
@ParamLog("客户端根据群分类获取二维码") @ParamLog("客户端根据群分类获取二维码")
public GroupQrcode4ClassifyVO getGroupQrcode4ClassifyWechat(Long classifyId, Long wechatUserId) { public GroupQrcode4ClassifyVO getGroupQrcode4ClassifyWechat(Long classifyId, Long wechatUserId) {
//获取分类基本信息 //获取分类基本信息
ClassifyVO classify = bookGroupClassifyDao.getClassify(classifyId); ClassifyVO classify = bookGroupClassifyDao.getClassify(classifyId);
if (classify == null) { if (classify == null) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "社群码不存在,请刷新后重试"); throw new BookBizException(BookBizException.PARAM_IS_NULL, "社群码不存在,请刷新后重试");
} }
if (new BigDecimal(0).compareTo(classify.getPrice()) < 0) { if (new BigDecimal(0).compareTo(classify.getPrice()) < 0) {
//校验用户是否正版授权 //校验用户是否正版授权
Boolean isAuth = bookAuthUserBiz.checkIsHaveAuth(classify.getBookId(), classify.getChannelId(), classify.getCreateUser(), wechatUserId, 1); Boolean isAuth = bookAuthUserBiz.checkIsHaveAuth(classify.getBookId(), classify.getChannelId(), classify.getCreateUser(), wechatUserId, 1);
...@@ -734,6 +736,14 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz { ...@@ -734,6 +736,14 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
} }
} }
// 临时替换为企业微信加好友流程
if (JedisClusterUtils.exists("WECHAT_GROUP_BAN_PROCESS")) {
GroupQrcode4ClassifyVO vo = new GroupQrcode4ClassifyVO();
vo.setQrcodeUrl(JedisClusterUtils.get("WECHAT_GROUP_BAN_PROCESS"));
vo.setGroupName(classify.getClassify());
return vo;
}
//获取用户是否分配过二维码 //获取用户是否分配过二维码
GroupQrcode4ClassifyVO groupQrcode4ClassifyVO = bookQrcodeUserDao.getUserQrcode(classifyId, wechatUserId); GroupQrcode4ClassifyVO groupQrcode4ClassifyVO = bookQrcodeUserDao.getUserQrcode(classifyId, wechatUserId);
if (groupQrcode4ClassifyVO == null) { if (groupQrcode4ClassifyVO == null) {
......
package com.pcloud.book.group.service.impl;
import com.pcloud.book.group.dto.ReplyMsgDTO;
import com.pcloud.book.group.service.WxWorkKeyWordService;
import com.pcloud.book.keywords.biz.BookKeywordBiz;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.utils.ResponseHandleUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* TODO
*
* @author guiq
* @version 1.0
* @since 2020/12/9
*/
@RestController
@RequestMapping("/wxWorkKeyWordService")
public class WxWorkKeyWordServiceImpl implements WxWorkKeyWordService {
@Autowired
private BookKeywordBiz bookKeywordBiz;
@Override
@GetMapping("/getKeyWordsByClassify")
public ResponseEntity<ResponseDto<List<ReplyMsgDTO>>> getKeyWordsByClassify(@RequestParam("classifyId") Long classifyId) {
return ResponseHandleUtil.toResponse(bookKeywordBiz.getKeyWordsByClassify(classifyId));
}
}
package com.pcloud.book.keywords.biz; package com.pcloud.book.keywords.biz;
import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO; import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO;
import com.pcloud.book.group.dto.ReplyMsgDTO;
import com.pcloud.book.keywords.dto.KeywordDTO; import com.pcloud.book.keywords.dto.KeywordDTO;
import com.pcloud.book.keywords.dto.KeywordStatisticsDTO; import com.pcloud.book.keywords.dto.KeywordStatisticsDTO;
import com.pcloud.book.keywords.dto.ReplyKeywordDTO; import com.pcloud.book.keywords.dto.ReplyKeywordDTO;
...@@ -160,4 +161,6 @@ public interface BookKeywordBiz { ...@@ -160,4 +161,6 @@ public interface BookKeywordBiz {
* 自动唤醒处理 * 自动唤醒处理
*/ */
void robotWakeUp(String userWxId, String ip, Integer code, String robotId); void robotWakeUp(String userWxId, String ip, Integer code, String robotId);
List<ReplyMsgDTO> getKeyWordsByClassify(Long classifyId);
} }
package com.pcloud.book.keywords.biz.impl; package com.pcloud.book.keywords.biz.impl;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
...@@ -33,7 +34,9 @@ import com.pcloud.book.group.dao.GroupQrcodeDao; ...@@ -33,7 +34,9 @@ import com.pcloud.book.group.dao.GroupQrcodeDao;
import com.pcloud.book.group.dao.WxUserWechatRelevanceDao; import com.pcloud.book.group.dao.WxUserWechatRelevanceDao;
import com.pcloud.book.group.dto.BookGroupDTO; import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.dto.BookWxQrcodeDTO; import com.pcloud.book.group.dto.BookWxQrcodeDTO;
import com.pcloud.book.group.dto.ClassifyDTO;
import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO; import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO;
import com.pcloud.book.group.dto.ReplyMsgDTO;
import com.pcloud.book.group.entity.AppTouchRecord; import com.pcloud.book.group.entity.AppTouchRecord;
import com.pcloud.book.group.entity.BookGroup; import com.pcloud.book.group.entity.BookGroup;
import com.pcloud.book.group.entity.BookGroupCipherUser; import com.pcloud.book.group.entity.BookGroupCipherUser;
...@@ -90,7 +93,6 @@ import com.pcloud.book.pcloudkeyword.enums.RelevanceTypeEnum; ...@@ -90,7 +93,6 @@ import com.pcloud.book.pcloudkeyword.enums.RelevanceTypeEnum;
import com.pcloud.book.pcloudkeyword.set.PcloudRobotSet; import com.pcloud.book.pcloudkeyword.set.PcloudRobotSet;
import com.pcloud.book.personalstage.biz.PersonalStageBiz; import com.pcloud.book.personalstage.biz.PersonalStageBiz;
import com.pcloud.book.personalstage.biz.PersonalStageJumpBiz; import com.pcloud.book.personalstage.biz.PersonalStageJumpBiz;
import com.pcloud.book.personalstage.enums.JumpTypeEnum;
import com.pcloud.book.reading.biz.ReadingActivityBiz; import com.pcloud.book.reading.biz.ReadingActivityBiz;
import com.pcloud.book.skill.dto.AppOrProductReplyDTO; import com.pcloud.book.skill.dto.AppOrProductReplyDTO;
import com.pcloud.book.util.common.ThreadPoolUtils; import com.pcloud.book.util.common.ThreadPoolUtils;
...@@ -593,24 +595,24 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -593,24 +595,24 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
} }
//判断是否是平台端配置的小号,如果是,走平台端 //判断是否是平台端配置的小号,如果是,走平台端
PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(sendTextDTO.getWxId()); PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(sendTextDTO.getWxId());
if (pcloudRobot!=null){ if (pcloudRobot != null) {
//如果是全局退订关键词 //如果是全局退订关键词
if(sendTextDTO.getTextContent().equals(pcloudRobotBiz.getTdKeyword())) { if (sendTextDTO.getTextContent().equals(pcloudRobotBiz.getTdKeyword())) {
pcloudRobotBiz.handlePcloudTdReply(sendTextDTO); pcloudRobotBiz.handlePcloudTdReply(sendTextDTO);
return; return;
} }
// 读者发送书名 // 读者发送书名
if (!StringUtil.isEmpty(sendTextDTO.getTextContent()) if (!StringUtil.isEmpty(sendTextDTO.getTextContent())
&&sendTextDTO.getTextContent().length()>1 && sendTextDTO.getTextContent().length() > 1
&&sendTextDTO.getTextContent().startsWith("#")){ && sendTextDTO.getTextContent().startsWith("#")) {
sendSearchBook(sendTextDTO); sendSearchBook(sendTextDTO);
return; return;
} }
if (personalStageBiz.isPersonalStageUser(sendTextDTO.getWxId())){ if (personalStageBiz.isPersonalStageUser(sendTextDTO.getWxId())) {
personalStageBiz.userSendPersonalStage(sendTextDTO.getWechatUserId(), sendTextDTO.getIp(), sendTextDTO.getCode(), sendTextDTO.getWxId(), sendTextDTO.getTextContent()); personalStageBiz.userSendPersonalStage(sendTextDTO.getWechatUserId(), sendTextDTO.getIp(), sendTextDTO.getCode(), sendTextDTO.getWxId(), sendTextDTO.getTextContent());
return; return;
} }
sendPcloudKeyword(sendTextDTO,pcloudRobot); sendPcloudKeyword(sendTextDTO, pcloudRobot);
return; return;
} }
if (SendMessageTypeEnum.SELF.getCode().equals(sendTextDTO.getCode())) { if (SendMessageTypeEnum.SELF.getCode().equals(sendTextDTO.getCode())) {
...@@ -626,17 +628,17 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -626,17 +628,17 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
@ParamLog("发送搜索书籍") @ParamLog("发送搜索书籍")
private void sendSearchBook(SendTextDTO sendTextDTO) { private void sendSearchBook(SendTextDTO sendTextDTO) {
String bookName=sendTextDTO.getTextContent().substring(1); String bookName = sendTextDTO.getTextContent().substring(1);
BookDto bookDto=bookDao.getAdviserBookByName(bookName); BookDto bookDto = bookDao.getAdviserBookByName(bookName);
String userWxId = sendTextDTO.getWechatUserId(); String userWxId = sendTextDTO.getWechatUserId();
String ip = sendTextDTO.getIp(); String ip = sendTextDTO.getIp();
Integer code = sendTextDTO.getCode(); Integer code = sendTextDTO.getCode();
String robotId = sendTextDTO.getWxId(); String robotId = sendTextDTO.getWxId();
String uuid= UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
RobotProcessTypeEnum robotProcessType=RobotProcessTypeEnum.USER_BOOK_SEARCH; RobotProcessTypeEnum robotProcessType = RobotProcessTypeEnum.USER_BOOK_SEARCH;
int counts=1; int counts = 1;
int index=0; int index = 0;
if (bookDto==null){ if (bookDto == null) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO(); SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent("如果这里没有你需要的,小睿深表歉意,小睿还在不断丰富阅读内容,提升阅读体验,一旦发现好东西就会快马加鞭分享给你的!"); sendTextMessageVO.setContent("如果这里没有你需要的,小睿深表歉意,小睿还在不断丰富阅读内容,提升阅读体验,一旦发现好东西就会快马加鞭分享给你的!");
sendTextMessageVO.setAltId(robotId); sendTextMessageVO.setAltId(robotId);
...@@ -648,36 +650,36 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -648,36 +650,36 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
sendTextMessageVO.setIndex(index); sendTextMessageVO.setIndex(index);
sendTextMessageVO.setCounts(counts); sendTextMessageVO.setCounts(counts);
wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO)); wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO));
String h5link = wechatGroupLinkPrefix +"/dialog/search?wxId=" + userWxId +"&robotWxId=" + robotId; String h5link = wechatGroupLinkPrefix + "/dialog/search?wxId=" + userWxId + "&robotWxId=" + robotId;
String linkUrl = UrlUtils.getShortUrl4Own(h5link); String linkUrl = UrlUtils.getShortUrl4Own(h5link);
linkUrl = "★" + linkUrl + "★"; linkUrl = "★" + linkUrl + "★";
sendTextMessageVO.setContent("详情点击进入:"+linkUrl); sendTextMessageVO.setContent("详情点击进入:" + linkUrl);
wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO)); wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO));
}else { } else {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO(); SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setAltId(robotId); sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setWxGroupId(userWxId); sendTextMessageVO.setWxGroupId(userWxId);
sendTextMessageVO.setIp(ip); sendTextMessageVO.setIp(ip);
sendTextMessageVO.setCode(code); sendTextMessageVO.setCode(code);
String h5link = wechatGroupLinkPrefix +"/dialog/resource?bookId="+bookDto.getBookId()+"&adviserId="+bookDto.getAdviserId()+"&channelId="+bookDto.getChannelId()+"&wxId=" + userWxId +"&robotWxId=" + robotId; String h5link = wechatGroupLinkPrefix + "/dialog/resource?bookId=" + bookDto.getBookId() + "&adviserId=" + bookDto.getAdviserId() + "&channelId=" + bookDto.getChannelId() + "&wxId=" + userWxId + "&robotWxId=" + robotId;
String linkUrl = UrlUtils.getShortUrl4Own(h5link); String linkUrl = UrlUtils.getShortUrl4Own(h5link);
linkUrl = "★" + linkUrl + "★"; linkUrl = "★" + linkUrl + "★";
sendTextMessageVO.setContent("详情点击进入:"+linkUrl); sendTextMessageVO.setContent("详情点击进入:" + linkUrl);
sendTextMessageVO.setMessageGroupId(uuid); sendTextMessageVO.setMessageGroupId(uuid);
sendTextMessageVO.setRobotProcessType(robotProcessType); sendTextMessageVO.setRobotProcessType(robotProcessType);
sendTextMessageVO.setIndex(index); sendTextMessageVO.setIndex(index);
sendTextMessageVO.setCounts(counts); sendTextMessageVO.setCounts(counts);
wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO)); wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO));
//插入触发记录 //插入触发记录
SearchRecord searchRecord=new SearchRecord(); SearchRecord searchRecord = new SearchRecord();
searchRecord.setContent(bookName); searchRecord.setContent(bookName);
searchRecord.setBookId(bookDto.getBookId()); searchRecord.setBookId(bookDto.getBookId());
searchRecord.setWxId(userWxId); searchRecord.setWxId(userWxId);
Long agentId=adviserConsr.getAgentIdByAdviser(bookDto.getAdviserId()); Long agentId = adviserConsr.getAgentIdByAdviser(bookDto.getAdviserId());
searchRecord.setAgentId(agentId); searchRecord.setAgentId(agentId);
if (searchRecord.getContent().length()>50){ if (searchRecord.getContent().length() > 50) {
log.error("长度大于50"+bookName); log.error("长度大于50" + bookName);
}else { } else {
searchRecordDao.insert(searchRecord); searchRecordDao.insert(searchRecord);
searchBiz.createSearchRecordDis(searchRecord); searchBiz.createSearchRecordDis(searchRecord);
} }
...@@ -688,7 +690,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -688,7 +690,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
private boolean replySelfKeywordTemplate(SendTextDTO sendTextDTO) { private boolean replySelfKeywordTemplate(SendTextDTO sendTextDTO) {
try { try {
String content = sendTextDTO.getTextContent(); String content = sendTextDTO.getTextContent();
String redisKey = "replySelfKeywordTemplate:"+sendTextDTO.getWxId()+":"+sendTextDTO.getWechatUserId(); String redisKey = "replySelfKeywordTemplate:" + sendTextDTO.getWxId() + ":" + sendTextDTO.getWechatUserId();
List<SelfRobotKeywordReplyTemplate> replyTemplateList = selfRobotKeywordReplyTemplateDao.getList(); List<SelfRobotKeywordReplyTemplate> replyTemplateList = selfRobotKeywordReplyTemplateDao.getList();
// 解析出《》的书名 // 解析出《》的书名
Pattern pattern = Pattern.compile("《(.*?)》"); Pattern pattern = Pattern.compile("《(.*?)》");
...@@ -698,19 +700,21 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -698,19 +700,21 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
// 解析出版社 出版社: // 解析出版社 出版社:
int index = content.indexOf("出版社:"); int index = content.indexOf("出版社:");
// 再匹配不到,直接返回,并走接下来的逻辑 // 再匹配不到,直接返回,并走接下来的逻辑
if(index == -1) { if (index == -1) {
index = content.indexOf("出版社:"); index = content.indexOf("出版社:");
if(index == -1) if (index == -1)
return true; return true;
} }
String agentName = content.substring(index + 4); String agentName = content.substring(index + 4);
// 如果出版社名称为空,则直接return走非关键逻辑 // 如果出版社名称为空,则直接return走非关键逻辑
if(StringUtil.isEmpty(agentName)){ return true; } if (StringUtil.isEmpty(agentName)) {
return true;
}
// 从redis取出书名 // 从redis取出书名
String bookName = JedisClusterUtils.get(redisKey); String bookName = JedisClusterUtils.get(redisKey);
// 删掉书名 // 删掉书名
JedisClusterUtils.del(redisKey); JedisClusterUtils.del(redisKey);
if(StringUtil.isNotNull(bookName)){ if (StringUtil.isNotNull(bookName)) {
// 将书的信息录入 // 将书的信息录入
SelfRobotBookRecord selfRobotBookRecord = new SelfRobotBookRecord(); SelfRobotBookRecord selfRobotBookRecord = new SelfRobotBookRecord();
selfRobotBookRecord.setWxUserId(sendTextDTO.getWechatUserId()); selfRobotBookRecord.setWxUserId(sendTextDTO.getWechatUserId());
...@@ -728,18 +732,18 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -728,18 +732,18 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
String bookName = matcher.group(1).trim(); String bookName = matcher.group(1).trim();
// 根据书名查询到 bookIds // 根据书名查询到 bookIds
List<Long> bookIds = bookDao.getBookIdsByBookName(bookName); List<Long> bookIds = bookDao.getBookIdsByBookName(bookName);
if(ListUtils.isEmpty(bookIds)){ if (ListUtils.isEmpty(bookIds)) {
// 将书名写入redis暂存 // 将书名写入redis暂存
JedisClusterUtils.set(redisKey, bookName); JedisClusterUtils.set(redisKey, bookName);
// 如果bookIds没有值,则回复模板状态3 // 如果bookIds没有值,则回复模板状态3
// 呃,小睿刚才仔细的找了下,发现书刊的配套资源我这边还没有呢,要不等小睿看完整理好后再给你吧 // 呃,小睿刚才仔细的找了下,发现书刊的配套资源我这边还没有呢,要不等小睿看完整理好后再给你吧
Optional<SelfRobotKeywordReplyTemplate> replyTemplate = replyTemplateList.stream().filter(x -> x.getStatus().equals(3)).findFirst(); Optional<SelfRobotKeywordReplyTemplate> replyTemplate = replyTemplateList.stream().filter(x -> x.getStatus().equals(3)).findFirst();
sendText(sendTextDTO, replyTemplate.get().getReplyContentTemplate().replace("${bookName}",bookName)); sendText(sendTextDTO, replyTemplate.get().getReplyContentTemplate().replace("${bookName}", bookName));
return false; return false;
} else { } else {
// 根据bookIds查询资源数; // 根据bookIds查询资源数;
Integer totalCount = channelConsr.getMessageCountByBookIds(bookIds); Integer totalCount = channelConsr.getMessageCountByBookIds(bookIds);
if(totalCount > 0){ if (totalCount > 0) {
// 信息录入 // 信息录入
SelfRobotBookRecord selfRobotBookRecord = new SelfRobotBookRecord(); SelfRobotBookRecord selfRobotBookRecord = new SelfRobotBookRecord();
selfRobotBookRecord.setWxUserId(sendTextDTO.getWechatUserId()); selfRobotBookRecord.setWxUserId(sendTextDTO.getWechatUserId());
...@@ -748,13 +752,13 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -748,13 +752,13 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
selfRobotBookRecord.setStatus(3); selfRobotBookRecord.setStatus(3);
selfRobotBookRecordDao.insert(selfRobotBookRecord); selfRobotBookRecordDao.insert(selfRobotBookRecord);
// 如果有书有资源,则转换链接,并推送链接给用户 // 如果有书有资源,则转换链接,并推送链接给用户
Map<String,String> paramMap = new HashMap<>(); Map<String, String> paramMap = new HashMap<>();
paramMap.put("wxId",sendTextDTO.getWechatUserId()); paramMap.put("wxId", sendTextDTO.getWechatUserId());
paramMap.put("robotWxId",sendTextDTO.getWxId()); paramMap.put("robotWxId", sendTextDTO.getWxId());
paramMap.put("bookName",URLEncoder.encode(bookName)); paramMap.put("bookName", URLEncoder.encode(bookName));
Optional<SelfRobotKeywordReplyTemplate> replyTemplate = replyTemplateList.stream().filter(x -> x.getStatus().equals(4)).findFirst(); Optional<SelfRobotKeywordReplyTemplate> replyTemplate = replyTemplateList.stream().filter(x -> x.getStatus().equals(4)).findFirst();
sendText(sendTextDTO,appendUrlParams(replyTemplate.get().getReplyContentTemplate(),paramMap)); sendText(sendTextDTO, appendUrlParams(replyTemplate.get().getReplyContentTemplate(), paramMap));
} else{ } else {
// 信息录入 // 信息录入
SelfRobotBookRecord selfRobotBookRecord = new SelfRobotBookRecord(); SelfRobotBookRecord selfRobotBookRecord = new SelfRobotBookRecord();
selfRobotBookRecord.setWxUserId(sendTextDTO.getWechatUserId()); selfRobotBookRecord.setWxUserId(sendTextDTO.getWechatUserId());
...@@ -764,7 +768,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -764,7 +768,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
selfRobotBookRecordDao.insert(selfRobotBookRecord); selfRobotBookRecordDao.insert(selfRobotBookRecord);
// 如果有书但没有资源,则回复模板状态1 // 如果有书但没有资源,则回复模板状态1
Optional<SelfRobotKeywordReplyTemplate> replyTemplate = replyTemplateList.stream().filter(x -> x.getStatus().equals(1)).findFirst(); Optional<SelfRobotKeywordReplyTemplate> replyTemplate = replyTemplateList.stream().filter(x -> x.getStatus().equals(1)).findFirst();
sendText(sendTextDTO, replyTemplate.get().getReplyContentTemplate().replace("${bookName}",bookName)); sendText(sendTextDTO, replyTemplate.get().getReplyContentTemplate().replace("${bookName}", bookName));
} }
return false; return false;
} }
...@@ -775,36 +779,36 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -775,36 +779,36 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
} }
@ParamLog("发送平台端小号的") @ParamLog("发送平台端小号的")
private void sendPcloudKeyword(SendTextDTO sendTextDTO,PcloudRobot pcloudRobot) { private void sendPcloudKeyword(SendTextDTO sendTextDTO, PcloudRobot pcloudRobot) {
String userWxId = sendTextDTO.getWechatUserId(); String userWxId = sendTextDTO.getWechatUserId();
String ip = sendTextDTO.getIp(); String ip = sendTextDTO.getIp();
Integer code = sendTextDTO.getCode(); Integer code = sendTextDTO.getCode();
String robotId = sendTextDTO.getWxId(); String robotId = sendTextDTO.getWxId();
Long robotClassifyId=pcloudRobot.getRobotType().longValue(); Long robotClassifyId = pcloudRobot.getRobotType().longValue();
//判断人工客服服务状态 //判断人工客服服务状态
Integer serviceState = wechatGroupConsr.getServiceStateByRobotUser(robotId, userWxId); Integer serviceState = wechatGroupConsr.getServiceStateByRobotUser(robotId, userWxId);
if (serviceState == 1){ if (serviceState == 1) {
log.info("人工客服服务中,userWxId="+userWxId+"+robotId+"+robotId); log.info("人工客服服务中,userWxId=" + userWxId + "+robotId+" + robotId);
return; return;
} }
PcloudRobotClassify robotClassify = pcloudRobotClassifyDao.getById(robotClassifyId); PcloudRobotClassify robotClassify = pcloudRobotClassifyDao.getById(robotClassifyId);
if (robotClassify==null||robotClassify.getKeywordClassifyId()==null){ if (robotClassify == null || robotClassify.getKeywordClassifyId() == null) {
return; return;
} }
Long pcloudClassifyId=robotClassify.getKeywordClassifyId(); Long pcloudClassifyId = robotClassify.getKeywordClassifyId();
//查询该小号对应小号分类的关键词分类 //查询该小号对应小号分类的关键词分类
PcloudKeywordClassify pcloudKeywordClassify = pcloudKeywordClassifyDao.getById(pcloudClassifyId); PcloudKeywordClassify pcloudKeywordClassify = pcloudKeywordClassifyDao.getById(pcloudClassifyId);
if (null == pcloudKeywordClassify || !pcloudKeywordClassify.getOpen()){//分类未启用 if (null == pcloudKeywordClassify || !pcloudKeywordClassify.getOpen()) {//分类未启用
log.info("查询小号关键词分类为空或未启用sendTextDTO="+sendTextDTO.toString()+"pcloudRobot="+pcloudRobot.toString()); log.info("查询小号关键词分类为空或未启用sendTextDTO=" + sendTextDTO.toString() + "pcloudRobot=" + pcloudRobot.toString());
return; return;
} }
String content=sendTextDTO.getTextContent(); String content = sendTextDTO.getTextContent();
//根据关键词分类和关键词查询关键词 //根据关键词分类和关键词查询关键词
//精准 //精准
PcloudKeyword pcloudKeyword=pcloudKeywordDao.getByClassifyIdAndName(KeywordTypeEnum.ACCURATE.value,pcloudClassifyId,content); PcloudKeyword pcloudKeyword = pcloudKeywordDao.getByClassifyIdAndName(KeywordTypeEnum.ACCURATE.value, pcloudClassifyId, content);
if (pcloudKeyword==null){ if (pcloudKeyword == null) {
// 正向模糊 // 正向模糊
pcloudKeyword=pcloudKeywordDao.getByClassifyIdAndName(KeywordTypeEnum.LIKE.value,pcloudClassifyId,content); pcloudKeyword = pcloudKeywordDao.getByClassifyIdAndName(KeywordTypeEnum.LIKE.value, pcloudClassifyId, content);
// 反向模糊 // 反向模糊
if (Objects.isNull(pcloudKeyword)) { if (Objects.isNull(pcloudKeyword)) {
List<PcloudKeyword> pcloudKeywords = pcloudKeywordDao.listAllBlurryKeyword(pcloudClassifyId); List<PcloudKeyword> pcloudKeywords = pcloudKeywordDao.listAllBlurryKeyword(pcloudClassifyId);
...@@ -820,31 +824,31 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -820,31 +824,31 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
} }
} }
} }
if (pcloudKeyword!=null){ if (pcloudKeyword != null) {
//走关键词 //走关键词
log.info("查询平台端关键词"+pcloudKeyword.toString()+"id="+pcloudKeyword.getId()); log.info("查询平台端关键词" + pcloudKeyword.toString() + "id=" + pcloudKeyword.getId());
//3min不回复同一关键词 //3min不回复同一关键词
String key ="BOOK:PCLOUD_KEYWORD:" + userWxId + "-" +robotId + "-" + pcloudKeyword.getId(); String key = "BOOK:PCLOUD_KEYWORD:" + userWxId + "-" + robotId + "-" + pcloudKeyword.getId();
String redisContent = JedisClusterUtils.getJson(key, String.class); String redisContent = JedisClusterUtils.getJson(key, String.class);
if (!StringUtil.isEmpty(redisContent)){ if (!StringUtil.isEmpty(redisContent)) {
return; return;
}else { } else {
JedisClusterUtils.setJson(key, userWxId, 3*60); JedisClusterUtils.setJson(key, userWxId, 3 * 60);
} }
List<PcloudKeywordReply> replies = pcloudKeywordReplyDao.getByRelevance(RelevanceTypeEnum.KEYWORD.value, pcloudKeyword.getId()); List<PcloudKeywordReply> replies = pcloudKeywordReplyDao.getByRelevance(RelevanceTypeEnum.KEYWORD.value, pcloudKeyword.getId());
if (MethodEnum.RANDOM.value.equals(pcloudKeyword.getMethod())){ if (MethodEnum.RANDOM.value.equals(pcloudKeyword.getMethod())) {
int a= (int) Math.floor(Math.random()*replies.size()); int a = (int) Math.floor(Math.random() * replies.size());
replies=Arrays.asList(replies.get(a)); replies = Arrays.asList(replies.get(a));
} }
String uuid= UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
RobotProcessTypeEnum robotProcessType=RobotProcessTypeEnum.PCLOUD_KEYWORD; RobotProcessTypeEnum robotProcessType = RobotProcessTypeEnum.PCLOUD_KEYWORD;
for (PcloudKeywordReply reply:replies){ for (PcloudKeywordReply reply : replies) {
sendPcloudKeywordReply(reply, robotId, userWxId, ip, code,uuid,robotProcessType,replies.indexOf(reply),replies.size()); sendPcloudKeywordReply(reply, robotId, userWxId, ip, code, uuid, robotProcessType, replies.indexOf(reply), replies.size());
} }
//有关联技能,发送H5页面链接,取第一个技能 //有关联技能,发送H5页面链接,取第一个技能
if (!StringUtil.isEmpty(pcloudKeyword.getSkillIds())){ if (!StringUtil.isEmpty(pcloudKeyword.getSkillIds())) {
List<Long> skillIds = pcloudKeyword.getSkillList(pcloudKeyword.getSkillIds()); List<Long> skillIds = pcloudKeyword.getSkillList(pcloudKeyword.getSkillIds());
String h5link = wechatGroupLinkPrefix +"/dialog?wxId=" + userWxId +"&robotWxId=" + robotId +"&skillId="+skillIds.get(0); String h5link = wechatGroupLinkPrefix + "/dialog?wxId=" + userWxId + "&robotWxId=" + robotId + "&skillId=" + skillIds.get(0);
String linkUrl = UrlUtils.getShortUrl4Own(h5link); String linkUrl = UrlUtils.getShortUrl4Own(h5link);
linkUrl = "★" + linkUrl + "★"; linkUrl = "★" + linkUrl + "★";
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO(); SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
...@@ -859,16 +863,16 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -859,16 +863,16 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO)); wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO));
} }
}else { } else {
//非关键词响应 //非关键词响应
sendPcloudNotKeyWord(userWxId,ip,code,robotId,pcloudClassifyId, MessageTypeEnum.TEXT.value); sendPcloudNotKeyWord(userWxId, ip, code, robotId, pcloudClassifyId, MessageTypeEnum.TEXT.value);
} }
} }
@ParamLog("平台端个人号关键词回复") @ParamLog("平台端个人号关键词回复")
public void sendPcloudKeywordReply(PcloudKeywordReply reply, String robotId, String userWxId, String ip, Integer code, String uuid, RobotProcessTypeEnum robotProcessType, int index, int counts){ public void sendPcloudKeywordReply(PcloudKeywordReply reply, String robotId, String userWxId, String ip, Integer code, String uuid, RobotProcessTypeEnum robotProcessType, int index, int counts) {
Integer type = reply.getType(); Integer type = reply.getType();
if (ReplyTypeEnum.TEXT.value.equals(type)) { if (ReplyTypeEnum.TEXT.value.equals(type)) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO(); SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
...@@ -897,7 +901,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -897,7 +901,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
wechatGroupConsr.sendMessage(JSON.toJSONString(sendPicMessageVO)); wechatGroupConsr.sendMessage(JSON.toJSONString(sendPicMessageVO));
} }
if (ReplyTypeEnum.APP.value.equals(type)) { if (ReplyTypeEnum.APP.value.equals(type)) {
AppOrProductReplyDTO appOrProductReplyDTO=new AppOrProductReplyDTO(); AppOrProductReplyDTO appOrProductReplyDTO = new AppOrProductReplyDTO();
appOrProductReplyDTO.setServeType(reply.getServeType()); appOrProductReplyDTO.setServeType(reply.getServeType());
appOrProductReplyDTO.setServeId(reply.getServeId()); appOrProductReplyDTO.setServeId(reply.getServeId());
appOrProductReplyDTO.setLinkUrl(reply.getLinkUrl()); appOrProductReplyDTO.setLinkUrl(reply.getLinkUrl());
...@@ -919,11 +923,11 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -919,11 +923,11 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
sendFileVO.setFileUrl(resourceDTO.getFileUrl()); sendFileVO.setFileUrl(resourceDTO.getFileUrl());
String fileName = resourceDTO.getResourceName(); String fileName = resourceDTO.getResourceName();
String fileType = resourceDTO.getFileType(); String fileType = resourceDTO.getFileType();
log.info("fileName="+fileName+"+fileType+"+fileType); log.info("fileName=" + fileName + "+fileType+" + fileType);
if (fileName.contains(fileType)){//去掉后缀 if (fileName.contains(fileType)) {//去掉后缀
fileName = fileName.substring(0, fileName.indexOf(fileType)-1); fileName = fileName.substring(0, fileName.indexOf(fileType) - 1);
} }
log.info("fileName="+fileName); log.info("fileName=" + fileName);
sendFileVO.setFileName(fileName); sendFileVO.setFileName(fileName);
} }
sendFileVO.setIp(ip); sendFileVO.setIp(ip);
...@@ -982,23 +986,23 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -982,23 +986,23 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
@ParamLog("发送非关键词回复模板") @ParamLog("发送非关键词回复模板")
private void sendNotKeywords(SendTextDTO sendTextDTO) { private void sendNotKeywords(SendTextDTO sendTextDTO) {
NotKeywordTemplate template=notKeywordTemplateDao.getRandomTemplate(); NotKeywordTemplate template = notKeywordTemplateDao.getRandomTemplate();
if (template==null){ if (template == null) {
return; return;
} }
List<NotKeywordItem> list = notKeywordItemDao.getListByTemplateIds(Arrays.asList(template.getId())); List<NotKeywordItem> list = notKeywordItemDao.getListByTemplateIds(Arrays.asList(template.getId()));
if (ListUtils.isEmpty(list)){ if (ListUtils.isEmpty(list)) {
return; return;
} }
String userWxId = sendTextDTO.getWechatUserId(); String userWxId = sendTextDTO.getWechatUserId();
String ip = sendTextDTO.getIp(); String ip = sendTextDTO.getIp();
Integer code = sendTextDTO.getCode(); Integer code = sendTextDTO.getCode();
String robotId = sendTextDTO.getWxId(); String robotId = sendTextDTO.getWxId();
String uuid= UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
RobotProcessTypeEnum robotProcessType=RobotProcessTypeEnum.PCLOUD_NOT_KEYWORD; RobotProcessTypeEnum robotProcessType = RobotProcessTypeEnum.PCLOUD_NOT_KEYWORD;
int index=0; int index = 0;
int counts=1; int counts = 1;
for (NotKeywordItem notKeywordItem:list){ for (NotKeywordItem notKeywordItem : list) {
Integer type = notKeywordItem.getType(); Integer type = notKeywordItem.getType();
if (ReplyTypeEnum.TEXT.value.equals(type)) { if (ReplyTypeEnum.TEXT.value.equals(type)) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO(); SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
...@@ -1021,11 +1025,11 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1021,11 +1025,11 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
sendFileVO.setFileUrl(resourceDTO.getFileUrl()); sendFileVO.setFileUrl(resourceDTO.getFileUrl());
String fileName = resourceDTO.getResourceName(); String fileName = resourceDTO.getResourceName();
String fileType = resourceDTO.getFileType(); String fileType = resourceDTO.getFileType();
log.info("fileName="+fileName+"+fileType+"+fileType); log.info("fileName=" + fileName + "+fileType+" + fileType);
if (fileName.contains(fileType)){//去掉后缀 if (fileName.contains(fileType)) {//去掉后缀
fileName = fileName.substring(0, fileName.indexOf(fileType)-1); fileName = fileName.substring(0, fileName.indexOf(fileType) - 1);
} }
log.info("fileName="+fileName); log.info("fileName=" + fileName);
sendFileVO.setFileName(fileName); sendFileVO.setFileName(fileName);
} }
sendFileVO.setIp(ip); sendFileVO.setIp(ip);
...@@ -1047,21 +1051,21 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1047,21 +1051,21 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
Integer code = sendTextDTO.getCode(); Integer code = sendTextDTO.getCode();
String robotId = sendTextDTO.getWxId(); String robotId = sendTextDTO.getWxId();
List<SelfRobotKeywordReply> replyList = selfRobotKeywordReplyDao.getListByKeywordId(selfRobotKeyword.getId()); List<SelfRobotKeywordReply> replyList = selfRobotKeywordReplyDao.getListByKeywordId(selfRobotKeyword.getId());
if (ListUtils.isEmpty(replyList)){ if (ListUtils.isEmpty(replyList)) {
return; return;
} }
RobotProcessTypeEnum robotProcessType = RobotProcessTypeEnum.PCLOUD_KEYWORD; RobotProcessTypeEnum robotProcessType = RobotProcessTypeEnum.PCLOUD_KEYWORD;
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
for (SelfRobotKeywordReply keywordReply : replyList){ for (SelfRobotKeywordReply keywordReply : replyList) {
Integer type = keywordReply.getType(); Integer type = keywordReply.getType();
Integer index = replyList.indexOf(keywordReply); Integer index = replyList.indexOf(keywordReply);
Integer counts = replyList.size(); Integer counts = replyList.size();
if (ReplyTypeEnum.TEXT.value.equals(type)) { if (ReplyTypeEnum.TEXT.value.equals(type)) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO(); SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
Map<String,String> paramMap = new HashMap<>(); Map<String, String> paramMap = new HashMap<>();
paramMap.put("wxId",userWxId); paramMap.put("wxId", userWxId);
paramMap.put("robotWxId",robotId); paramMap.put("robotWxId", robotId);
sendTextMessageVO.setContent(appendUrlParams(keywordReply.getContent(),paramMap)); sendTextMessageVO.setContent(appendUrlParams(keywordReply.getContent(), paramMap));
sendTextMessageVO.setAltId(robotId); sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setWxGroupId(userWxId); sendTextMessageVO.setWxGroupId(userWxId);
sendTextMessageVO.setIp(ip); sendTextMessageVO.setIp(ip);
...@@ -1070,7 +1074,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1070,7 +1074,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
sendTextMessageVO.setRobotProcessType(robotProcessType); sendTextMessageVO.setRobotProcessType(robotProcessType);
sendTextMessageVO.setIndex(index); sendTextMessageVO.setIndex(index);
sendTextMessageVO.setCounts(counts); sendTextMessageVO.setCounts(counts);
wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO));; wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO));
;
} }
if (ReplyTypeEnum.IMAGE.value.equals(type)) { if (ReplyTypeEnum.IMAGE.value.equals(type)) {
SendPicMessageVO sendPicMessageVO = new SendPicMessageVO(); SendPicMessageVO sendPicMessageVO = new SendPicMessageVO();
...@@ -1175,11 +1180,11 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1175,11 +1180,11 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
sendFileVO.setFileUrl(resourceDTO.getFileUrl()); sendFileVO.setFileUrl(resourceDTO.getFileUrl());
String fileName = resourceDTO.getResourceName(); String fileName = resourceDTO.getResourceName();
String fileType = resourceDTO.getFileType(); String fileType = resourceDTO.getFileType();
log.info("fileName="+fileName+"+fileType+"+fileType); log.info("fileName=" + fileName + "+fileType+" + fileType);
if (fileName.contains(fileType)){//去掉后缀 if (fileName.contains(fileType)) {//去掉后缀
fileName = fileName.substring(0, fileName.indexOf(fileType)-1); fileName = fileName.substring(0, fileName.indexOf(fileType) - 1);
} }
log.info("fileName="+fileName); log.info("fileName=" + fileName);
sendFileVO.setFileName(fileName); sendFileVO.setFileName(fileName);
} }
sendFileVO.setIp(ip); sendFileVO.setIp(ip);
...@@ -1197,7 +1202,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1197,7 +1202,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
/** /**
* 关键词 补充wxid * 关键词 补充wxid
*/ */
public String appendUrlParams(String content, Map<String,String> map) { public String appendUrlParams(String content, Map<String, String> map) {
String suffix = appendParams(map); String suffix = appendParams(map);
Pattern pattern = Pattern.compile("(https?)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]"); Pattern pattern = Pattern.compile("(https?)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]");
Matcher matcher = pattern.matcher(content); Matcher matcher = pattern.matcher(content);
...@@ -1220,7 +1225,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1220,7 +1225,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
if (group.contains("?")) { if (group.contains("?")) {
content = content.replace(group, UrlUtils.getShortUrl(group + "&" + suffix)); content = content.replace(group, UrlUtils.getShortUrl(group + "&" + suffix));
}else { } else {
content = content.replace(group, UrlUtils.getShortUrl(group + "?" + suffix)); content = content.replace(group, UrlUtils.getShortUrl(group + "?" + suffix));
} }
} }
...@@ -1229,36 +1234,36 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1229,36 +1234,36 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
@ParamLog("非关键词响应") @ParamLog("非关键词响应")
@Override @Override
public void sendPcloudNotKeyWord(String userWxId, String ip, Integer code, String robotId,Long pcloudClassifyId, Integer userMessageType) { public void sendPcloudNotKeyWord(String userWxId, String ip, Integer code, String robotId, Long pcloudClassifyId, Integer userMessageType) {
//判断人工客服服务状态 //判断人工客服服务状态
Integer serviceState = wechatGroupConsr.getServiceStateByRobotUser(robotId, userWxId); Integer serviceState = wechatGroupConsr.getServiceStateByRobotUser(robotId, userWxId);
if (serviceState == 1){ if (serviceState == 1) {
log.info("人工客服服务中,userWxId="+userWxId+"+robotId+"+robotId); log.info("人工客服服务中,userWxId=" + userWxId + "+robotId+" + robotId);
return; return;
} }
//1min不重复回复 //1min不重复回复
String key ="BOOK:PCLOUD_NOT_KEYWORD:"+ userWxId +"-" + robotId +"-" + pcloudClassifyId; String key = "BOOK:PCLOUD_NOT_KEYWORD:" + userWxId + "-" + robotId + "-" + pcloudClassifyId;
String redisContent = JedisClusterUtils.getJson(key, String.class); String redisContent = JedisClusterUtils.getJson(key, String.class);
if (!StringUtil.isEmpty(redisContent)){ if (!StringUtil.isEmpty(redisContent)) {
return; return;
}else { } else {
JedisClusterUtils.setJson(key, userWxId, 60); JedisClusterUtils.setJson(key, userWxId, 60);
} }
//走非关键词 //走非关键词
List<PcloudNotKeyword> notKeywords = pcloudNotKeywordDao.getPcloudNotKeywordListByMessageType(pcloudClassifyId,userMessageType); List<PcloudNotKeyword> notKeywords = pcloudNotKeywordDao.getPcloudNotKeywordListByMessageType(pcloudClassifyId, userMessageType);
if (!ListUtils.isEmpty(notKeywords)){ if (!ListUtils.isEmpty(notKeywords)) {
for (PcloudNotKeyword pcloudNotKeyword : notKeywords){ for (PcloudNotKeyword pcloudNotKeyword : notKeywords) {
List<PcloudKeywordReply> replies = pcloudKeywordReplyDao.getByRelevance(RelevanceTypeEnum.NOT_KEYWORD.value, pcloudNotKeyword.getId()); List<PcloudKeywordReply> replies = pcloudKeywordReplyDao.getByRelevance(RelevanceTypeEnum.NOT_KEYWORD.value, pcloudNotKeyword.getId());
if (ListUtils.isEmpty(replies)){ if (ListUtils.isEmpty(replies)) {
continue; continue;
} }
if (MethodEnum.RANDOM.value.equals(pcloudNotKeyword.getMethod())){ if (MethodEnum.RANDOM.value.equals(pcloudNotKeyword.getMethod())) {
replies = Arrays.asList(replies.get(new Random().nextInt(replies.size()))); replies = Arrays.asList(replies.get(new Random().nextInt(replies.size())));
} }
String uuid= UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
RobotProcessTypeEnum robotProcessType=RobotProcessTypeEnum.PCLOUD_NOT_KEYWORD; RobotProcessTypeEnum robotProcessType = RobotProcessTypeEnum.PCLOUD_NOT_KEYWORD;
for (PcloudKeywordReply reply:replies){ for (PcloudKeywordReply reply : replies) {
sendPcloudKeywordReply(reply, robotId, userWxId, ip, code, uuid,robotProcessType,replies.indexOf(reply),replies.size()); sendPcloudKeywordReply(reply, robotId, userWxId, ip, code, uuid, robotProcessType, replies.indexOf(reply), replies.size());
} }
} }
} }
...@@ -1311,12 +1316,12 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1311,12 +1316,12 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
// if (!StringUtil.isEmpty(selfRobotKeyword.getGuide())){//改为多个引导语了1002267 // if (!StringUtil.isEmpty(selfRobotKeyword.getGuide())){//改为多个引导语了1002267
// toAddIn = selfRobotKeyword.getGuide() + ",请回复“" + selfRobotKeyword.getKeyword() + "”\n"; // toAddIn = selfRobotKeyword.getGuide() + ",请回复“" + selfRobotKeyword.getKeyword() + "”\n";
// }else { // }else {
toAddIn = "请回复“" + selfRobotKeyword.getKeyword() + "”\n"; toAddIn = "请回复“" + selfRobotKeyword.getKeyword() + "”\n";
// } // }
//最后一个 //最后一个
if (i + 1 == size) { if (i + 1 == size) {
// 拼接反馈链接 // 拼接反馈链接
String feedbackUrl = "*common/C" + channelId + "/A0/feedback/suggest?bookGroupId="+bookGroupId+"&wxId=" + sendTextDTO.getWechatUserId(); String feedbackUrl = "*common/C" + channelId + "/A0/feedback/suggest?bookGroupId=" + bookGroupId + "&wxId=" + sendTextDTO.getWechatUserId();
String url = SendWeixinRequestTools.splitUrl(accountSettingDto, feedbackUrl); String url = SendWeixinRequestTools.splitUrl(accountSettingDto, feedbackUrl);
toAddIn = toAddIn + "回复对应数字序号给我,我将助你达成所愿,提高读书效率。\n如有其他问题反馈,请点击链接:\n" toAddIn = toAddIn + "回复对应数字序号给我,我将助你达成所愿,提高读书效率。\n如有其他问题反馈,请点击链接:\n"
+ UrlUtils.getShortUrl4Own(url); + UrlUtils.getShortUrl4Own(url);
...@@ -1345,7 +1350,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1345,7 +1350,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
BookGroup bookGroup = bookGroupDao.getByBookGroupCipher(cipher); BookGroup bookGroup = bookGroupDao.getByBookGroupCipher(cipher);
if (bookGroup != null) { if (bookGroup != null) {
try { try {
addBookGroupCipherUser(sendTextDTO, cipher,null, bookGroup.getId()); addBookGroupCipherUser(sendTextDTO, cipher, null, bookGroup.getId());
updateWxUserWechatRelevance(sendTextDTO); updateWxUserWechatRelevance(sendTextDTO);
dealByBookGroup(sendTextDTO, bookGroup.getId(), false); dealByBookGroup(sendTextDTO, bookGroup.getId(), false);
} catch (Exception e) { } catch (Exception e) {
...@@ -1499,7 +1504,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1499,7 +1504,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
if (StringUtil.isEmpty(weixinGroupId)) { if (StringUtil.isEmpty(weixinGroupId)) {
throw new BookBizException(BookBizException.ID_NOT_EXIST, "群不存在classifyId=" + classifyId + ",changeNumber=" + changeNumber + ", wxId=" + sendTextDTO.getWxId()); throw new BookBizException(BookBizException.ID_NOT_EXIST, "群不存在classifyId=" + classifyId + ",changeNumber=" + changeNumber + ", wxId=" + sendTextDTO.getWxId());
} }
sendAndCheckInviteGroup(sendTextDTO,weixinGroupId); sendAndCheckInviteGroup(sendTextDTO, weixinGroupId);
} }
@ParamLog("判断冒泡和发送冒泡和发入群链接") @ParamLog("判断冒泡和发送冒泡和发入群链接")
...@@ -1535,19 +1540,19 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1535,19 +1540,19 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
} }
@ParamLog("发送冒泡消息") @ParamLog("发送冒泡消息")
private void sendMaoPao(SendTextDTO sendTextDTO, String wxGroupId){ private void sendMaoPao(SendTextDTO sendTextDTO, String wxGroupId) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO(); SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent("我来冒个泡"); sendTextMessageVO.setContent("我来冒个泡");
sendTextMessageVO.setAltId(sendTextDTO.getWxId()); sendTextMessageVO.setAltId(sendTextDTO.getWxId());
sendTextMessageVO.setWxGroupId(wxGroupId); sendTextMessageVO.setWxGroupId(wxGroupId);
sendTextMessageVO.setIp(findIp(wxGroupId)); sendTextMessageVO.setIp(findIp(wxGroupId));
// TODO sdk.message // TODO sdk.message
wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO)); wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO));
log.info("发送入群邀请链接之前发冒泡消息:"+sendTextMessageVO.toString()); log.info("发送入群邀请链接之前发冒泡消息:" + sendTextMessageVO.toString());
} }
@ParamLog("发送进群链接") @ParamLog("发送进群链接")
private void sendInviteToGroup(SendTextDTO sendTextDTO, String wxGroupId){ private void sendInviteToGroup(SendTextDTO sendTextDTO, String wxGroupId) {
SendGroupInviteVO sendGroupInviteVO = new SendGroupInviteVO(); SendGroupInviteVO sendGroupInviteVO = new SendGroupInviteVO();
sendGroupInviteVO.setAltId(sendTextDTO.getWxId()); sendGroupInviteVO.setAltId(sendTextDTO.getWxId());
sendGroupInviteVO.setWxId(sendTextDTO.getWechatUserId()); sendGroupInviteVO.setWxId(sendTextDTO.getWechatUserId());
...@@ -1630,7 +1635,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1630,7 +1635,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
} }
// 去除被发送内容完整包含的关键词 // 去除被发送内容完整包含的关键词
List<ReplyKeywordDTO> collect = keywordDTOS.stream().filter(x -> content.contains(x.getKeywords())).collect(Collectors.toList()); List<ReplyKeywordDTO> collect = keywordDTOS.stream().filter(x -> content.contains(x.getKeywords())).collect(Collectors.toList());
if (ListUtils.isEmpty(collect)){ if (ListUtils.isEmpty(collect)) {
log.info("[关键词消息回复] replyKeywordDTO is null"); log.info("[关键词消息回复] replyKeywordDTO is null");
return; return;
} }
...@@ -1672,12 +1677,12 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1672,12 +1677,12 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
//目标关键词回复+文案 //目标关键词回复+文案
combineKeyWord(replyKeyWords, classifyQrcodeInfo, accountSettingDto, sb); combineKeyWord(replyKeyWords, classifyQrcodeInfo, accountSettingDto, sb);
if (keywordsAll.size()>replyKeyWords.size()){ if (keywordsAll.size() > replyKeyWords.size()) {
sb.append("--------------------------------\n为避免晚间群消息干扰,10分钟内只响应一次关键词,请直接点击下面的链接,获取本群其他资源服务:\n\n"); sb.append("--------------------------------\n为避免晚间群消息干扰,10分钟内只响应一次关键词,请直接点击下面的链接,获取本群其他资源服务:\n\n");
//剩余关键词回复 //剩余关键词回复
for (ReplyKeywordDTO replyKeywordDTO : keywordsAll) { for (ReplyKeywordDTO replyKeywordDTO : keywordsAll) {
List<ReplyKeywordDTO> collect = replyKeyWords.stream().filter(x -> replyKeywordDTO.getKeywords().equals(x.getKeywords())).collect(Collectors.toList()); List<ReplyKeywordDTO> collect = replyKeyWords.stream().filter(x -> replyKeywordDTO.getKeywords().equals(x.getKeywords())).collect(Collectors.toList());
if (!ListUtils.isEmpty(collect)){ if (!ListUtils.isEmpty(collect)) {
continue; continue;
} }
List<ReplyKeywordDTO> addKeyWordList = new ArrayList<>(); List<ReplyKeywordDTO> addKeyWordList = new ArrayList<>();
...@@ -1719,9 +1724,9 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1719,9 +1724,9 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
} }
/** /**
*合并关键词回复 * 合并关键词回复
*/ */
private StringBuilder combineKeyWord(List<ReplyKeywordDTO> keywordsAll, GroupClassifyQrcodeDTO classifyQrcodeInfo, AccountSettingDto accountSettingDto,StringBuilder sb) { private StringBuilder combineKeyWord(List<ReplyKeywordDTO> keywordsAll, GroupClassifyQrcodeDTO classifyQrcodeInfo, AccountSettingDto accountSettingDto, StringBuilder sb) {
for (ReplyKeywordDTO keyword : keywordsAll) { for (ReplyKeywordDTO keyword : keywordsAll) {
if (ReplyTypeEnum.LINK.value.equals(keyword.getReplyType()) || ReplyTypeEnum.APP.value.equals(keyword.getReplyType())) { if (ReplyTypeEnum.LINK.value.equals(keyword.getReplyType()) || ReplyTypeEnum.APP.value.equals(keyword.getReplyType())) {
String linkUrl = SendWeixinRequestTools.splitUrlNew(accountSettingDto, keyword.getLinkUrl(), classifyQrcodeInfo.getBookGroupId(), classifyQrcodeInfo.getClassifyId(), classifyQrcodeInfo.getGroupQrcodeId()); String linkUrl = SendWeixinRequestTools.splitUrlNew(accountSettingDto, keyword.getLinkUrl(), classifyQrcodeInfo.getBookGroupId(), classifyQrcodeInfo.getClassifyId(), classifyQrcodeInfo.getGroupQrcodeId());
...@@ -2094,7 +2099,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -2094,7 +2099,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
// 个人号消息 用户发送:wechatCreateUser!=wxId,小号发送wechatCreateUser=wxId // 个人号消息 用户发送:wechatCreateUser!=wxId,小号发送wechatCreateUser=wxId
if (SendMessageTypeEnum.SELF.getCode().equals(code) && !userWxId.equals(robotId)) { if (SendMessageTypeEnum.SELF.getCode().equals(code) && !userWxId.equals(robotId)) {
// 从缓存中获取缄默信息 // 从缓存中获取缄默信息
if(JedisClusterUtils.hexists(robotId+PCLOUD_GUIDE_SUFFIX,userWxId)){ if (JedisClusterUtils.hexists(robotId + PCLOUD_GUIDE_SUFFIX, userWxId)) {
PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(robotId); PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(robotId);
if (pcloudRobot == null) { if (pcloudRobot == null) {
return; return;
...@@ -2108,7 +2113,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -2108,7 +2113,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
pcloudGuideDelayDto.setSendTime(new Date()); pcloudGuideDelayDto.setSendTime(new Date());
// duration // duration
pcloudGuideDelayDto.setDuration(duration); pcloudGuideDelayDto.setDuration(duration);
JedisClusterUtils.hset(robotId+PCLOUD_GUIDE_SUFFIX,userWxId,JSONObject.toJSONString(pcloudGuideDelayDto)); JedisClusterUtils.hset(robotId + PCLOUD_GUIDE_SUFFIX, userWxId, JSONObject.toJSONString(pcloudGuideDelayDto));
} }
} }
} }
...@@ -2131,4 +2136,62 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -2131,4 +2136,62 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
} }
} }
} }
@Override
public List<ReplyMsgDTO> getKeyWordsByClassify(Long classifyId) {
ClassifyDTO classifyDTO = bookGroupClassifyDao.getById(classifyId);
if (Objects.isNull(classifyDTO) || Objects.isNull(classifyDTO.getBookGroupId())) {
return new ArrayList<>();
}
Long bookGroupId = classifyDTO.getBookGroupId();
// 获取所有的关键词
List<ReplyKeywordDTO> replyKeywordDTOS = bookKeywordDao.listAllKeywordByClassifyIdAndBookGroupId(classifyId, bookGroupId);
if (CollUtil.isEmpty(replyKeywordDTOS)) {
return new ArrayList<>();
}
List<ReplyMsgDTO> replyMsgDTOS = new ArrayList<>();
for (ReplyKeywordDTO replyKeywordDTO : replyKeywordDTOS) {
final boolean isApp = ReplyTypeEnum.APP.value.equals(replyKeywordDTO.getReplyType());
final boolean isLink = ReplyTypeEnum.LINK.value.equals(replyKeywordDTO.getReplyType());
if (isApp || isLink) {
AccountSettingDto accountSettingDto = qrcodeSceneConsr.getWechatInfo(classifyDTO.getChannelId());
String linkUrl = SendWeixinRequestTools.splitUrlNew(accountSettingDto, replyKeywordDTO.getLinkUrl(), bookGroupId, classifyId, 0L);
String shortUrl4Own = UrlUtils.getShortUrl4Own(linkUrl);
if (replyKeywordDTO.getLinkUrl().contains("live/C")) {
// 获取直播课信息
List<CourseListDto> list4BroadcastReminder = liveCons.getList4BroadcastReminder(replyKeywordDTO.getServeId(), replyKeywordDTO.getServeType());
replyKeywordDTO.setReplyType(ReplyTypeEnum.TEXT.value);
StringBuilder sb = new StringBuilder("【");
sb.append(CollectionUtils.isEmpty(list4BroadcastReminder) ? replyKeywordDTO.getDescription() : list4BroadcastReminder.get(0).getTableTitle())
.append("】近期将开播的课程\n");
if (!CollectionUtils.isEmpty(list4BroadcastReminder)) {
int i = 1;
for (CourseListDto listDto : list4BroadcastReminder) {
sb.append("第").append(i++).append("课:").append(listDto.getTitle()).append("\n");
}
}
sb.append("查看更多课程表链接:").append(shortUrl4Own);
replyKeywordDTO.setContent(sb.toString());
}
replyKeywordDTO.setLinkUrl(linkUrl);
replyKeywordDTO.setShortLinkUrl(shortUrl4Own);
}
if (ReplyTypeEnum.TEXT.value.equals(replyKeywordDTO.getReplyType())) {
replyMsgDTOS.add(ReplyMsgDTO.builder().msgType(1).keyWord(replyKeywordDTO.getKeywords()).content(replyKeywordDTO.getContent()).build());
} else if (ReplyTypeEnum.IMAGE.value.equals(replyKeywordDTO.getReplyType())) {
replyMsgDTOS.add(ReplyMsgDTO.builder().msgType(2).keyWord(replyKeywordDTO.getKeywords()).imgUrl(replyKeywordDTO.getPicUrl()).build());
} else if (ReplyTypeEnum.APP.value.equals(replyKeywordDTO.getReplyType()) || ReplyTypeEnum.LINK.value.equals(replyKeywordDTO.getReplyType())) {
replyMsgDTOS.add(ReplyMsgDTO.builder().msgType(3).keyWord(replyKeywordDTO.getKeywords())
.desc(replyKeywordDTO.getDescription())
.url(replyKeywordDTO.getLinkUrl())
.title(replyKeywordDTO.getContent())
.imgUrl(replyKeywordDTO.getPicUrl())
.build());
}
}
return replyMsgDTOS;
}
} }
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