Commit 02d91d38 by 阮思源

Merge branch 'feat-1002467' into 'master'

【ID1002467】平台端新增非关键词用户输入内容替代码

See merge request rays/pcloud-book!485
parents f0e611da 5b0ba313
...@@ -50,7 +50,7 @@ public interface PersonalStageBiz { ...@@ -50,7 +50,7 @@ public interface PersonalStageBiz {
PersonalStageUser nextStageAddStageUserAndWakeupDelay(String robotId, String userWxId, String ip, Long personalStageId); PersonalStageUser nextStageAddStageUserAndWakeupDelay(String robotId, String userWxId, String ip, Long personalStageId);
void sendNotKeywordReply(String robotId, String userWxId, String ip, Long personalStageId, Long personalStageUserId); void sendNotKeywordReply(String robotId, String userWxId, String ip, Long personalStageId, Long personalStageUserId, String userSendContent);
void sendNotKeywordFusingReply(String robotId, String userWxId, String ip, Long personalStageId,Long personalStageUserId); void sendNotKeywordFusingReply(String robotId, String userWxId, String ip, Long personalStageId,Long personalStageUserId);
......
...@@ -116,6 +116,8 @@ public class PersonalStageBizImpl implements PersonalStageBiz { ...@@ -116,6 +116,8 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
//需求定制单路由 https://wechat666.raysgo.com/personalCenter/questionNaire?paperId=679 //需求定制单路由 https://wechat666.raysgo.com/personalCenter/questionNaire?paperId=679
private final static String PERSONAL_STAGE_PAPER = "/personalCenter/questionNaire?paperId="; private final static String PERSONAL_STAGE_PAPER = "/personalCenter/questionNaire?paperId=";
private final static String USER_SEND_CONTENT="${USER_SEND_CONTENT}";
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ParamLog("新增阶段") @ParamLog("新增阶段")
@Override @Override
...@@ -328,7 +330,7 @@ public class PersonalStageBizImpl implements PersonalStageBiz { ...@@ -328,7 +330,7 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
last.setNotKeywordSendCount(notKeywordSendCount+1); last.setNotKeywordSendCount(notKeywordSendCount+1);
last.setState(PersonalStageUserStateEnum.NORMAL.value); last.setState(PersonalStageUserStateEnum.NORMAL.value);
personalStageUserDao.update(last); personalStageUserDao.update(last);
sendNotKeywordReply(robotId,userWxId,ip,personalStage.getId(), last.getId()); sendNotKeywordReply(robotId,userWxId,ip,personalStage.getId(), last.getId(), content);
} }
} }
} }
...@@ -337,7 +339,7 @@ public class PersonalStageBizImpl implements PersonalStageBiz { ...@@ -337,7 +339,7 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
if (!iskeyword&&!hasRecord){ if (!iskeyword&&!hasRecord){
//走正常非关键词回复并且新增记录 //走正常非关键词回复并且新增记录
LOGGER.info("走正常非关键词回复并且新增记录"); LOGGER.info("走正常非关键词回复并且新增记录");
sendNotKeywordReply(robotId,userWxId,ip,personalStage.getId(), last.getId()); sendNotKeywordReply(robotId,userWxId,ip,personalStage.getId(), last.getId(), content);
PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(robotId); PcloudRobot pcloudRobot = pcloudRobotDao.getByWxId(robotId);
Long robotClassifyId=pcloudRobot.getRobotType().longValue(); Long robotClassifyId=pcloudRobot.getRobotType().longValue();
PersonalStage firstStage = personalStageDao.getFirstStage(robotClassifyId); PersonalStage firstStage = personalStageDao.getFirstStage(robotClassifyId);
...@@ -520,7 +522,7 @@ public class PersonalStageBizImpl implements PersonalStageBiz { ...@@ -520,7 +522,7 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
@ParamLog("非关键词回复") @ParamLog("非关键词回复")
@Override @Override
public void sendNotKeywordReply(String robotId, String userWxId, String ip, Long personalStageId, Long personalStageUserId) { public void sendNotKeywordReply(String robotId, String userWxId, String ip, Long personalStageId, Long personalStageUserId, String userSendContent) {
List<Long> ids = personalStageReplyDao.getIdsByRelevance(StageReplyRelevEnum.STAGE_NOT_KEYWORD.value, personalStageId); List<Long> ids = personalStageReplyDao.getIdsByRelevance(StageReplyRelevEnum.STAGE_NOT_KEYWORD.value, personalStageId);
if (ListUtils.isEmpty(ids)){ if (ListUtils.isEmpty(ids)){
return; return;
...@@ -532,11 +534,64 @@ public class PersonalStageBizImpl implements PersonalStageBiz { ...@@ -532,11 +534,64 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
if (ListUtils.isEmpty(items)){ if (ListUtils.isEmpty(items)){
return; return;
} }
//替换用户输入内容
items=replaceUserSendContent(items,ids, userSendContent,robotId,userWxId,ip);
if (ListUtils.isEmpty(items)){
return;
}
//替换需求定制单链接 //替换需求定制单链接
this.replacePaperUrl(items, robotId, userWxId, personalStageReply.getPaperId()); this.replacePaperUrl(items, robotId, userWxId, personalStageReply.getPaperId());
sendReplyItems(items,robotId,userWxId,ip,personalStageUserId); sendReplyItems(items,robotId,userWxId,ip,personalStageUserId);
} }
@ParamLog("替换用户输入内容")
private List<PersonalStageReplyItem> replaceUserSendContent(List<PersonalStageReplyItem> items, List<Long> ids, String userSendContent, String robotId, String userWxId, String ip) {
//如果用户没有输入文本
if (StringUtil.isEmpty(userSendContent)){
List<PersonalStageReplyItem> itemNew=new ArrayList<>();
//找一个不带占位符的
List<PersonalStageReplyItem> replyItems = personalStageReplyItemDao.getListByReplyIds(ids);
Map<Long,List<PersonalStageReplyItem>> map=replyItems.stream().collect(Collectors.groupingBy(PersonalStageReplyItem::getPersonalStageReplyId));
List<Long> idsNew=new ArrayList<>();
for (Long id:ids){
List<PersonalStageReplyItem> ins=map.get(id);
if (!ListUtils.isEmpty(ins)){
Boolean flag=true;
for (PersonalStageReplyItem replyItem:ins){
if (!StringUtil.isEmpty(replyItem.getContent())&&replyItem.getContent().contains(USER_SEND_CONTENT)){
flag=false;
}
}
if (flag){
idsNew.add(id);
}
}
}
if (ListUtils.isEmpty(idsNew)){
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent("哎哟 ~小主,你给我的不是书名啊。输入一本正在读或者感兴趣的书名,小睿就可以给你秀一下我的独家绝技哦");
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setWxGroupId(userWxId);
sendTextMessageVO.setIp(ip);
sendTextMessageVO.setCode(SendMessageTypeEnum.SELF.getCode());
WxGroupSDK.sendTextMessage(sendTextMessageVO);
}else {
Random random = new Random();
Long replyId=idsNew.get(random.nextInt(idsNew.size()));
itemNew = personalStageReplyItemDao.getListByReplyIds(Arrays.asList(replyId));
}
return itemNew;
}else {
for (PersonalStageReplyItem item:items){
Integer type=item.getReplyType();
if (ReplyTypeEnum.TEXT.value.equals(type)&&item.getContent().contains(USER_SEND_CONTENT)) {
item.setContent(item.getContent().replace(USER_SEND_CONTENT,userSendContent));
}
}
}
return items;
}
@ParamLog("尝试插入单号") @ParamLog("尝试插入单号")
private void tryInsertNumber(Long personalStageUserId) { private void tryInsertNumber(Long personalStageUserId) {
String requireNumber = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss").concat(String.valueOf((int)((Math.random()*9+1)*100000))); String requireNumber = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss").concat(String.valueOf((int)((Math.random()*9+1)*100000)));
......
...@@ -34,4 +34,6 @@ public interface PersonalStageJumpKeywordDao extends BaseDao<PersonalStageJumpKe ...@@ -34,4 +34,6 @@ public interface PersonalStageJumpKeywordDao extends BaseDao<PersonalStageJumpKe
* @return * @return
*/ */
PersonalStageJumpKeywordDto getByKeyword(Long personalStageId, String content, Integer jumpType); PersonalStageJumpKeywordDto getByKeyword(Long personalStageId, String content, Integer jumpType);
String getFirstKeywordByPersonalStageId(Long personalStageId);
} }
\ No newline at end of file
...@@ -38,4 +38,11 @@ public class PersonalStageJumpKeywordDaoImpl extends BaseDaoImpl<PersonalStageJu ...@@ -38,4 +38,11 @@ public class PersonalStageJumpKeywordDaoImpl extends BaseDaoImpl<PersonalStageJu
paramMap.put("jumpType", jumpType); paramMap.put("jumpType", jumpType);
return super.getSessionTemplate().selectOne(getStatement("getByKeyword"), paramMap); return super.getSessionTemplate().selectOne(getStatement("getByKeyword"), paramMap);
} }
@Override
public String getFirstKeywordByPersonalStageId(Long personalStageId) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("personalStageId", personalStageId);
return super.getSessionTemplate().selectOne(getStatement("getFirstKeywordByPersonalStageId"), paramMap);
}
} }
...@@ -96,4 +96,11 @@ ...@@ -96,4 +96,11 @@
</foreach> </foreach>
limit 1 limit 1
</select> </select>
<select id="getFirstKeywordByPersonalStageId" parameterType="map" resultType="string">
select keyword from personal_stage_jump_keyword where
personal_stage_id=#{personalStageId}
order by id asc
limit 1
</select>
</mapper> </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