Commit 8cca8c56 by 阮思源

Merge branch 'feat-1002467-fix' into 'master'

修改,特殊字符优先

See merge request rays/pcloud-book!486
parents 02d91d38 3089b311
...@@ -546,28 +546,31 @@ public class PersonalStageBizImpl implements PersonalStageBiz { ...@@ -546,28 +546,31 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
@ParamLog("替换用户输入内容") @ParamLog("替换用户输入内容")
private List<PersonalStageReplyItem> replaceUserSendContent(List<PersonalStageReplyItem> items, List<Long> ids, String userSendContent, String robotId, String userWxId, String ip) { private List<PersonalStageReplyItem> replaceUserSendContent(List<PersonalStageReplyItem> items, List<Long> ids, String userSendContent, String robotId, String userWxId, String ip) {
//如果用户没有输入文本 List<PersonalStageReplyItem> replyItems = personalStageReplyItemDao.getListByReplyIds(ids);
if (StringUtil.isEmpty(userSendContent)){ Map<Long,List<PersonalStageReplyItem>> map=replyItems.stream().collect(Collectors.groupingBy(PersonalStageReplyItem::getPersonalStageReplyId));
List<PersonalStageReplyItem> itemNew=new ArrayList<>(); List<Long> idsNotHasSpe=new ArrayList<>();
//找一个不带占位符的 List<Long> idsHasSpe=new ArrayList<>();
List<PersonalStageReplyItem> replyItems = personalStageReplyItemDao.getListByReplyIds(ids); for (Long id:ids){
Map<Long,List<PersonalStageReplyItem>> map=replyItems.stream().collect(Collectors.groupingBy(PersonalStageReplyItem::getPersonalStageReplyId)); List<PersonalStageReplyItem> ins=map.get(id);
List<Long> idsNew=new ArrayList<>(); if (!ListUtils.isEmpty(ins)){
for (Long id:ids){ Boolean normal=true;
List<PersonalStageReplyItem> ins=map.get(id); for (PersonalStageReplyItem replyItem:ins){
if (!ListUtils.isEmpty(ins)){ if (!StringUtil.isEmpty(replyItem.getContent())&&replyItem.getContent().contains(USER_SEND_CONTENT)){
Boolean flag=true; normal=false;
for (PersonalStageReplyItem replyItem:ins){
if (!StringUtil.isEmpty(replyItem.getContent())&&replyItem.getContent().contains(USER_SEND_CONTENT)){
flag=false;
}
}
if (flag){
idsNew.add(id);
} }
} }
if (normal){
idsNotHasSpe.add(id);
}else {
idsHasSpe.add(id);
}
} }
if (ListUtils.isEmpty(idsNew)){ }
List<PersonalStageReplyItem> itemNew=new ArrayList<>();
//如果用户没有输入文本
if (StringUtil.isEmpty(userSendContent)){
//找一个不带占位符的
if (ListUtils.isEmpty(idsNotHasSpe)){
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO(); SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent("哎哟 ~小主,你给我的不是书名啊。输入一本正在读或者感兴趣的书名,小睿就可以给你秀一下我的独家绝技哦"); sendTextMessageVO.setContent("哎哟 ~小主,你给我的不是书名啊。输入一本正在读或者感兴趣的书名,小睿就可以给你秀一下我的独家绝技哦");
sendTextMessageVO.setAltId(robotId); sendTextMessageVO.setAltId(robotId);
...@@ -577,16 +580,23 @@ public class PersonalStageBizImpl implements PersonalStageBiz { ...@@ -577,16 +580,23 @@ public class PersonalStageBizImpl implements PersonalStageBiz {
WxGroupSDK.sendTextMessage(sendTextMessageVO); WxGroupSDK.sendTextMessage(sendTextMessageVO);
}else { }else {
Random random = new Random(); Random random = new Random();
Long replyId=idsNew.get(random.nextInt(idsNew.size())); Long replyId=idsNotHasSpe.get(random.nextInt(idsNotHasSpe.size()));
itemNew = personalStageReplyItemDao.getListByReplyIds(Arrays.asList(replyId)); itemNew = personalStageReplyItemDao.getListByReplyIds(Arrays.asList(replyId));
} }
return itemNew; return itemNew;
}else { }else {
for (PersonalStageReplyItem item:items){ //用户输入文本优先给带特殊符号的
Integer type=item.getReplyType(); if (!ListUtils.isEmpty(idsHasSpe)){
if (ReplyTypeEnum.TEXT.value.equals(type)&&item.getContent().contains(USER_SEND_CONTENT)) { Random random = new Random();
item.setContent(item.getContent().replace(USER_SEND_CONTENT,userSendContent)); Long replyId=idsHasSpe.get(random.nextInt(idsHasSpe.size()));
itemNew = personalStageReplyItemDao.getListByReplyIds(Arrays.asList(replyId));
for (PersonalStageReplyItem item:itemNew){
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 itemNew;
} }
} }
return items; return items;
......
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