Commit c42fdac5 by 阮思源

1002727读者输入不同类型书给出不同回复

parent ddacd0bf
......@@ -310,4 +310,6 @@ public interface BookGroupDao extends BaseDao<BookGroup> {
void updateGradeByDepLabel(Long depLabelId, Long graLabelId);
public Long getBookGroupId4OldData(Long raysBookId);
Long getIdByBookNameAndJoinGroupType(String bookName, Integer joinGroupType);
}
......@@ -367,4 +367,12 @@ public class BookGroupDaoImpl extends BaseDaoImpl<BookGroup> implements BookGrou
public Long getBookGroupId4OldData(Long raysBookId) {
return getSessionTemplate().selectOne(getStatement("getBookGroupId4OldData"), raysBookId);
}
@Override
public Long getIdByBookNameAndJoinGroupType(String bookName, Integer joinGroupType) {
Map<String,Object> map = new HashMap<>();
map.put("bookName", bookName);
map.put("joinGroupType", joinGroupType);
return getSessionTemplate().selectOne(getStatement("getIdByBookNameAndJoinGroupType"),map);
}
}
......@@ -45,7 +45,7 @@ public class SelfRobotSendTextListener {
LOGGER.info("接收到个人号发送文本消息,处理中:"+sendTextDTO.toString());
//TODO 处理个人号消息
if (!StringUtil.isEmpty(sendTextDTO.getTextContent()) && sendTextDTO.getTextContent().startsWith(WechatGroupConstant.SELF_ROBOT_CONTENT_KEYWORD)) {
personalStageJumpBiz.handlePersonalStageJump(sendTextDTO.getWechatGroupId(), sendTextDTO.getWxId(), sendTextDTO.getTextContent(), JumpTypeEnum.ROBOT_TRIGGER);
personalStageJumpBiz.handlePersonalStageJump(sendTextDTO.getWechatGroupId(), sendTextDTO.getWxId(), sendTextDTO.getTextContent(), JumpTypeEnum.ROBOT_TRIGGER,null,null);
}
} catch (Exception e) {
LOGGER.error("接收用户发送文本消息失败" + e.getMessage(), e);
......
......@@ -40,7 +40,7 @@ public interface PersonalStageJumpBiz {
* @return false:未能跳转到下个阶段,需要后续的其它处理;
* true:命中关键字,已经跳转到下个阶段,无需后续处理;
*/
Boolean handlePersonalStageJump(String userWxId, String robotWxId, String content, JumpTypeEnum jumpTypeEnum);
Boolean handlePersonalStageJump(String userWxId, String robotWxId, String content, JumpTypeEnum jumpTypeEnum, String bookGroupUrl,String adviserBookUrl);
/**
* 跳转到之前的阶段,清除用户填写需求单记录
......
......@@ -5,6 +5,9 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.book.constant.BookConstant;
import com.pcloud.book.book.dao.BookDao;
import com.pcloud.book.book.dto.BookDto;
import com.pcloud.book.consumer.channel.QrcodeSceneConsr;
import com.pcloud.book.consumer.content.ResourceConsr;
import com.pcloud.book.consumer.erp.ErpConsr;
import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
......@@ -14,6 +17,8 @@ import com.pcloud.book.custom.mapper.CustomPlanMapper;
import com.pcloud.book.custom.mapper.CustomPlanModuleSuggestionMapper;
import com.pcloud.book.custom.vo.AddBookNameVO;
import com.pcloud.book.custom.vo.UserBookServiceVO;
import com.pcloud.book.group.dao.BookGroupDao;
import com.pcloud.book.group.enums.JoinGroupTypeEnum;
import com.pcloud.book.keywords.enums.ReplyTypeEnum;
import com.pcloud.book.mq.delay.DelayMessageSender;
import com.pcloud.book.pcloudkeyword.dao.PcloudRobotClassifyDao;
......@@ -53,6 +58,8 @@ import com.pcloud.book.personalstage.vo.request.AddScoreRequestVO;
import com.pcloud.book.personlstage.dto.UserReplaceCodeDTO;
import com.pcloud.book.push.dao.PersonalAppletsDao;
import com.pcloud.book.push.entity.PersonalApplets;
import com.pcloud.channelcenter.wechat.dto.BookServeParamVO;
import com.pcloud.channelcenter.wechat.vo.BookServeVO;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.core.mq.DelayQueueDTO;
import com.pcloud.common.exceptions.BizException;
......@@ -147,6 +154,12 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
private CustomPlanMapper customPlanMapper;
@Autowired
private ErpConsr erpConsr;
@Autowired
private BookGroupDao bookGroupDao;
@Autowired
private BookDao bookDao;
@Autowired
private QrcodeSceneConsr qrcodeSceneConsr;
@Value("${wechat.group.link.prefix}")
......@@ -392,15 +405,6 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
PersonalStageUser last = personalStageUserDao.getLast(userWxId, robotId, null);
PersonalStage personalStage;
if (last!=null){
//如果之前有书的时候判断这个阶段的跳转方式是否踩中有0级和非0级的跳转关键词
//先判断0级
if (dealZeroBook(userWxId, robotId, content,last,JumpTypeEnum.ZERO_BOOK)){
return;
}
//再判断非0级
if (dealZeroBook(userWxId, robotId, content,last,JumpTypeEnum.NO_ZERO_BOOK)){
return;
}
hasRecord=true;
personalStage=personalStageDao.getById(last.getPersonalStageId());
}else {
......@@ -409,6 +413,10 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
Long robotClassifyId=pcloudRobot.getRobotType().longValue();
personalStage = personalStageDao.getFirstStage(robotClassifyId);
}
//优先走获取书名阶段的0级书判断跳转逻辑
if (dealBookNameStageZeroBook(userWxId, robotId, content,personalStage)){
return;
}
Boolean iskeyword;
if (StringUtil.isEmpty(content)){
iskeyword=false;
......@@ -431,7 +439,7 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
Thread.sleep(100);
}
//调关键词处理逻辑
personalStageJumpBiz.handlePersonalStageJump(userWxId,robotId,content,JumpTypeEnum.READER_TRIGGER);
personalStageJumpBiz.handlePersonalStageJump(userWxId,robotId,content,JumpTypeEnum.READER_TRIGGER,null,null);
} catch (Exception e){
LOGGER.info("缓存加锁失败,userWxId=" + userWxId +" robotId="+robotId);
} finally {
......@@ -481,34 +489,63 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
}
}
@ParamLog("处理0级书和非0级书")
private Boolean dealZeroBook(String userWxId, String robotId, String content, PersonalStageUser last,JumpTypeEnum jumpTypeEnum) {
PersonalStageJumpKeywordDto dto=personalStageJumpKeywordDao.getByKeyword(last.getPersonalStageId(),content, jumpTypeEnum.key);
if (dto==null){
@ParamLog("获取书名阶段的0级书判断跳转逻辑")
private Boolean dealBookNameStageZeroBook(String userWxId, String robotId, String content, PersonalStage personalStage) {
if (personalStage.getReplaceCodeId()!=null){
ReplaceCode replaceCode = replaceCodeDao.getById(personalStage.getReplaceCodeId());
if (replaceCode!=null&&"${bookName}".equals(replaceCode.getReplaceCode())){
Long personalStageId=personalStage.getId();
String fileId=robotId+"_"+userWxId+"_"+personalStageId;
String lastBookName = JedisClusterUtils.hget(PersonalStageConstant.LAST_NOT_KEYWORD_CONTENT_BEFORE_JUMP_STAGE_CACHE, fileId);
if (StringUtil.isEmpty(lastBookName)){
return false;
}
List<ReplaceCode> all = replaceCodeDao.getAll();
Long replaceCodeId = null;
for (ReplaceCode replaceCode:all){
if ("${bookName}".equals(replaceCode.getReplaceCode())){
replaceCodeId = replaceCode.getId();
break;
}
Integer level = erpConsr.getBookServiceLevel(lastBookName);
//判断0级书跳转且是跳转
PersonalStageJumpKeywordDto zeroBookDto=personalStageJumpKeywordDao.getByKeyword(personalStageId,content, JumpTypeEnum.ZERO_BOOK.key);
if (zeroBookDto!=null&&ServiceLevelEnum.ZERO_BOOK.value.equals(level)){
String bookGroupUrl=null;
Long bookGroupId=bookGroupDao.getIdByBookNameAndJoinGroupType(lastBookName, JoinGroupTypeEnum.GROUP_QRCODE.getCode());
if (bookGroupId!=null){
String link = wechatLinkPrefix +"/group/list?source_type=RAY&book_group_id="+bookGroupId;
bookGroupUrl = UrlUtils.getShortUrl4Own(link);
}
personalStageJumpBiz.handlePersonalStageJump(userWxId,robotId,content,JumpTypeEnum.ZERO_BOOK,bookGroupUrl,null);
return true;
}
UserReplaceCode record = userReplaceCodeDao.getLastUserReplaceByCodeId(userWxId, robotId, replaceCodeId);
if (record==null){
return false;
//判断非0级书跳转且是跳转
PersonalStageJumpKeywordDto noZeroBookDto=personalStageJumpKeywordDao.getByKeyword(personalStageId,content, JumpTypeEnum.NO_ZERO_BOOK.key);
if (noZeroBookDto!=null&&ServiceLevelEnum.NOT_ZERO_BOOK.value.equals(level)){
personalStageJumpBiz.handlePersonalStageJump(userWxId,robotId,content,JumpTypeEnum.NO_ZERO_BOOK,null,null);
return true;
}
//查询书名等级,阶段跳转
Integer level = erpConsr.getBookServiceLevel(record.getContent());
if (jumpTypeEnum.key.equals(JumpTypeEnum.ZERO_BOOK.key)&& ServiceLevelEnum.ZERO_BOOK.value.equals(level)){
personalStageJumpBiz.handlePersonalStageJump(userWxId,robotId,content,jumpTypeEnum);
//判断无等级且已收录图书跳转
PersonalStageJumpKeywordDto adviserBookDto=personalStageJumpKeywordDao.getByKeyword(personalStageId,content, JumpTypeEnum.ADVISER_BOOK.key);
if (adviserBookDto!=null){
BookDto bookDto= bookDao.getAdviserBookByName(lastBookName);
if (bookDto!=null){
String adviserBookUrl=null;
//判断这个图书有没有资源
BookServeParamVO bookServeParamVO=new BookServeParamVO();
bookServeParamVO.setAdviserId(bookDto.getAdviserId());
bookServeParamVO.setBookId(bookDto.getBookId());
bookServeParamVO.setChannelId(bookDto.getChannelId());
List<BookServeVO> bookServeVOS = qrcodeSceneConsr.listBookServeIds(bookServeParamVO);
if (!ListUtils.isEmpty(bookServeVOS)){
String link = wechatLinkPrefix +"/dialog/resource?bookId="+bookDto.getBookId()+"&adviserId="+bookDto.getAdviserId()+"&channelId="+bookDto.getChannelId()+"&wxId=" + userWxId +"&robotWxId=" + robotId;
adviserBookUrl = UrlUtils.getShortUrl4Own(link);
}
personalStageJumpBiz.handlePersonalStageJump(userWxId,robotId,content,JumpTypeEnum.ADVISER_BOOK,null,adviserBookUrl);
return true;
}
if (jumpTypeEnum.key.equals(JumpTypeEnum.NO_ZERO_BOOK.key)&& ServiceLevelEnum.NOT_ZERO_BOOK.value.equals(level)){
personalStageJumpBiz.handlePersonalStageJump(userWxId,robotId,content,jumpTypeEnum);
}
PersonalStageJumpKeywordDto noAdviserBookDto=personalStageJumpKeywordDao.getByKeyword(personalStageId,content, JumpTypeEnum.NO_ADVISER_BOOK.key);
if (noAdviserBookDto!=null){
personalStageJumpBiz.handlePersonalStageJump(userWxId,robotId,content,JumpTypeEnum.NO_ADVISER_BOOK,null,null);
return true;
}
}
}
return false;
}
......
......@@ -488,7 +488,7 @@ public class PersonalStageJumpBizImpl implements PersonalStageJumpBiz {
@Override
@ParamLog("处理用户阶段跳转逻辑")
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public Boolean handlePersonalStageJump(String userWxId, String robotWxId, String content, JumpTypeEnum jumpTypeEnum) {
public Boolean handlePersonalStageJump(String userWxId, String robotWxId, String content, JumpTypeEnum jumpTypeEnum, String bookGroupUrl,String adviserBookUrl) {
// 查询用户的当前状态信息
PersonalStageUser currentStageUser = personalStageUserDao.getLast(userWxId, robotWxId, null);
// 如果用户没有阶段状态,则不处理
......@@ -519,7 +519,7 @@ public class PersonalStageJumpBizImpl implements PersonalStageJumpBiz {
// 将用户置为下个阶段
PersonalStageUser nextPersonalStageUser = personalStageBiz.nextStageAddStageUserAndWakeupDelay(robotWxId, userWxId, ip, jumpKeywordDto.getAfterPersonalStageId());
// 发送内容衔接语
sendJumpLinkups(userWxId, robotWxId, ip, jumpKeywordDto.getPersonalStageJumpId(),nextPersonalStageUser.getId());
sendJumpLinkups(userWxId, robotWxId, ip, jumpKeywordDto.getPersonalStageJumpId(),nextPersonalStageUser.getId(),bookGroupUrl,adviserBookUrl);
// 停止发送引导语
pcloudGuideBiz.stopPcloudGuidePush(robotWxId, userWxId);
//存用户跳转之前的最后一次非关键词回复到表
......@@ -572,6 +572,14 @@ public class PersonalStageJumpBizImpl implements PersonalStageJumpBiz {
sendTextMessageVO.setIp(linkupDelayDTO.getIp());
sendTextMessageVO.setCode(SendMessageTypeEnum.SELF.getCode());
fillMessageBaseInfo(sendTextMessageVO, linkupDelayDTO);
//加跳转衔接语社群书链接
if (!StringUtil.isEmpty(linkupDelayDTO.getBookGroupUrl())){
sendTextMessageVO.setContent(sendTextMessageVO.getContent()+linkupDelayDTO.getBookGroupUrl());
}
//加跳转衔接语编辑书链接
if (!StringUtil.isEmpty(linkupDelayDTO.getAdviserBookUrl())){
sendTextMessageVO.setContent(sendTextMessageVO.getContent()+linkupDelayDTO.getAdviserBookUrl());
}
wechatGroupConsr.sendMessage(JSON.toJSONString(sendTextMessageVO));;
} else if(ReplyTypeEnum.IMAGE.value.equals( jumpLinkup.getReplyType())) {
SendPicMessageVO sendPicMessageVO = new SendPicMessageVO();
......@@ -685,7 +693,7 @@ public class PersonalStageJumpBizImpl implements PersonalStageJumpBiz {
// 将用户置为下个阶段
PersonalStageUser nextPersonalStageUser = personalStageBiz.nextStageAddStageUserAndWakeupDelay(robotWxId, userWxId, ip, paperJump.getAfterPersonalStageId());
// 发送内容衔接语
sendJumpLinkups(userWxId, robotWxId, ip, paperJump.getId(), nextPersonalStageUser.getId());
sendJumpLinkups(userWxId, robotWxId, ip, paperJump.getId(), nextPersonalStageUser.getId(), null, null);
// 停止发送引导语
pcloudGuideBiz.stopPcloudGuidePush(robotWxId, userWxId);
return true;
......@@ -793,7 +801,7 @@ public class PersonalStageJumpBizImpl implements PersonalStageJumpBiz {
// 将用户置为下个阶段
PersonalStageUser nextPersonalStageUser = personalStageBiz.nextStageAddStageUserAndWakeupDelay(robotId, wxId, ip, afterStageId);
// 发送内容衔接语
sendJumpLinkups(wxId, robotId, ip, stageJumpId, nextPersonalStageUser.getId());
sendJumpLinkups(wxId, robotId, ip, stageJumpId, nextPersonalStageUser.getId(),null,null);
// 停止发送引导语
pcloudGuideBiz.stopPcloudGuidePush(robotId, wxId);
}
......@@ -853,7 +861,7 @@ public class PersonalStageJumpBizImpl implements PersonalStageJumpBiz {
// 将用户置为下个阶段
PersonalStageUser nextPersonalStageUser = personalStageBiz.nextStageAddStageUserAndWakeupDelay(robotId, wxId, ip, afterStageId);
// 发送内容衔接语
sendJumpLinkups(wxId, robotId, ip, stageJumpId, nextPersonalStageUser.getId());
sendJumpLinkups(wxId, robotId, ip, stageJumpId, nextPersonalStageUser.getId(),null,null);
// 停止发送引导语
pcloudGuideBiz.stopPcloudGuidePush(robotId, wxId);
}
......@@ -949,7 +957,7 @@ public class PersonalStageJumpBizImpl implements PersonalStageJumpBiz {
// 将用户置为下个阶段
PersonalStageUser nextPersonalStageUser = personalStageBiz.nextStageAddStageUserAndWakeupDelay(robotId, wxId, ip, afterStageId);
// 发送内容衔接语
sendJumpLinkups(wxId, robotId, ip, stageJumpId, nextPersonalStageUser.getId());
sendJumpLinkups(wxId, robotId, ip, stageJumpId, nextPersonalStageUser.getId(),null,null);
// 停止发送引导语
pcloudGuideBiz.stopPcloudGuidePush(robotId, wxId);
}
......@@ -1026,7 +1034,7 @@ public class PersonalStageJumpBizImpl implements PersonalStageJumpBiz {
}
@ParamLog("发送内容衔接语")
private void sendJumpLinkups(String userWxId, String robotWxId, String ip, Long jumpId, Long personalStageUserId) {
private void sendJumpLinkups(String userWxId, String robotWxId, String ip, Long jumpId, Long personalStageUserId, String bookGroupUrl,String adviserBookUrl) {
List<PersonalStageJumpLinkup> linkups = personalStageJumpLinkupDao.getByJumpId(jumpId);
if(ListUtils.isEmpty(linkups)){
return;
......@@ -1047,6 +1055,10 @@ public class PersonalStageJumpBizImpl implements PersonalStageJumpBiz {
linkupDelayDTO.setMessageGroupId(messageGroupId);
linkupDelayDTO.setIndex(i);
linkupDelayDTO.setCounts(count);
if (i==0&&ReplyTypeEnum.TEXT.value.equals( jumpLinkup.getReplyType())){
linkupDelayDTO.setBookGroupUrl(bookGroupUrl);
linkupDelayDTO.setAdviserBookUrl(adviserBookUrl);
}
DelayQueueDTO delayQueueDTO = DelayQueueDTO.builder().key(userWxId).type(PersonalStageConstant.PERSONALSTAGE_DELAY_LINKUP).msg(linkupDelayDTO).timeout(jumpLinkup.getToStageStartTime()*1000).build();
delayMessageSender.send(delayQueueDTO);
LOGGER.info("增加跳转衔接语延时"+delayQueueDTO.toString());
......@@ -1054,6 +1066,16 @@ public class PersonalStageJumpBizImpl implements PersonalStageJumpBiz {
if(ReplyTypeEnum.TEXT.value.equals( jumpLinkup.getReplyType())){
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent(personalStageBiz.replaceProjectProgressUrl(jumpLinkup.getLinkupContent(),robotWxId,userWxId,personalStageUserId,ip));
if (i==0){
//加跳转衔接语社群书链接
if (!StringUtil.isEmpty(bookGroupUrl)){
sendTextMessageVO.setContent(sendTextMessageVO.getContent()+bookGroupUrl);
}
//加跳转衔接语编辑书链接
if (!StringUtil.isEmpty(adviserBookUrl)){
sendTextMessageVO.setContent(sendTextMessageVO.getContent()+adviserBookUrl);
}
}
sendTextMessageVO.setAltId(robotWxId);
sendTextMessageVO.setWxGroupId(userWxId);
sendTextMessageVO.setIp(ip);
......
......@@ -20,4 +20,8 @@ public class LinkupDelayDTO extends BaseDelayDTO {
private String ip;
@ApiModelProperty("用户阶段记录id")
private Long personalStageUserId;
@ApiModelProperty("跳转衔接语社群书链接")
private String bookGroupUrl;
@ApiModelProperty("跳转衔接语编辑书链接")
private String adviserBookUrl;
}
......@@ -10,7 +10,9 @@ public enum JumpTypeEnum {
PLAN_TRIGGER(6,"方案定制单触发"),
TIME_TRIGGER(7,"定时跳转"),
ZERO_BOOK(8,"0级书跳转"),
NO_ZERO_BOOK(9,"非0级书跳转");
NO_ZERO_BOOK(9,"非0级书跳转"),
ADVISER_BOOK(10,"无等级且已收录图书跳转"),
NO_ADVISER_BOOK(11,"无等级且未收录图书跳转");
public final Integer key;
public final String desc;
......
......@@ -947,4 +947,17 @@
SELECT book_group_id FROM book_group_old_data WHERE rays_book_id = #{raysBookId}
</select>
<select id="getIdByBookNameAndJoinGroupType" resultType="long" parameterType="map">
select
t.id
from book_group t
inner join book t1
on t.book_id=t1.book_id
where t.is_delete = 0
and t.join_group_type=#{joinGroupType}
and t1.is_delete = 0
and t1.book_name=#{bookName}
limit 1
</select>
</mapper>
\ No newline at end of file
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