Commit f7f6a941 by 裴大威

增加配置延时时间

parent 913d77fa
...@@ -71,6 +71,7 @@ import java.util.Date; ...@@ -71,6 +71,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -164,13 +165,14 @@ public class BookGuideBizImpl implements BookGuideBiz { ...@@ -164,13 +165,14 @@ public class BookGuideBizImpl implements BookGuideBiz {
sendFriendGuide(bookGroupId, agreeAddUserDTO); sendFriendGuide(bookGroupId, agreeAddUserDTO);
// TODO 引导语发送后 查询等待时间 // TODO 引导语发送后 查询等待时间
int time = 60;
// 向缓存中写入相关信息 延迟推送时间 // 向缓存中写入相关信息 延迟推送时间
if (envStr.toUpperCase().equals("TEST") && agreeAddUserDTO.getRobotWxId().equals("wxid_zus32xb5ukjn22") if (envStr.toUpperCase().equals("TEST") && agreeAddUserDTO.getRobotWxId().equals("wxid_zus32xb5ukjn22")
|| envStr.toUpperCase().equals("UAT") && agreeAddUserDTO.getRobotWxId().equals("wxid_p7gywuxkk89112") || envStr.toUpperCase().equals("UAT") && agreeAddUserDTO.getRobotWxId().equals("wxid_p7gywuxkk89112")
|| envStr.toUpperCase().equals("PRO") && agreeAddUserDTO.getRobotWxId().equals("wxid_x8i897ryabo722")) { || envStr.toUpperCase().equals("PRO") && agreeAddUserDTO.getRobotWxId().equals("wxid_x8i897ryabo722")) {
List<SelfRobotKeyword> selfRobotKeywords = selfRobotKeywordDao.getListByBookGroupId(bookGroupId); List<SelfRobotKeyword> selfRobotKeywords = selfRobotKeywordDao.getListByBookGroupId(bookGroupId);
BookGuideDelayDto delayDto = new BookGuideDelayDto(agreeAddUserDTO.getUserWxId(), DateUtils.addSecond(new Date(), time), selfRobotKeywords.get(0).getKeyword(), agreeAddUserDTO.getIp()); List<SelfRobotKeyword> hasGuideKeywords=selfRobotKeywords.stream().filter(s->s.getGuide()!=null&&s.getDelayTime()!=null).collect(Collectors.toList());
int time = hasGuideKeywords.get(0).getDelayTime();
BookGuideDelayDto delayDto = new BookGuideDelayDto(agreeAddUserDTO.getUserWxId(), DateUtils.addSecond(new Date(), time), hasGuideKeywords.get(0).getKeyword(), agreeAddUserDTO.getIp());
log.info("[向缓存中写入相关信息 延迟推送时间]:{}",JSONObject.toJSONString(delayDto)); log.info("[向缓存中写入相关信息 延迟推送时间]:{}",JSONObject.toJSONString(delayDto));
// 加好友 清除历史 // 加好友 清除历史
JedisClusterUtils.hdel(agreeAddUserDTO.getRobotWxId()+"_DELAY_PUSH", agreeAddUserDTO.getUserWxId()); JedisClusterUtils.hdel(agreeAddUserDTO.getRobotWxId()+"_DELAY_PUSH", agreeAddUserDTO.getUserWxId());
......
...@@ -524,83 +524,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -524,83 +524,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
if (bookGroupCipherUser == null || StringUtil.isEmpty(bookGroupCipherUser.getShortBookName())) { if (bookGroupCipherUser == null || StringUtil.isEmpty(bookGroupCipherUser.getShortBookName())) {
return; return;
} }
// 处理 YES NO
if ((envStr.toUpperCase().equals("TEST") && sendTextDTO.getWxId().equals("wxid_zus32xb5ukjn22") && new Long(1621L).equals(bookGroupCipherUser.getBookGroupId()))
|| (envStr.toUpperCase().equals("UAT") && sendTextDTO.getWxId().equals("wxid_51ff9f099l9a22") && new Long(449L).equals(bookGroupCipherUser.getBookGroupId()))
|| (envStr.toUpperCase().equals("PRO") && sendTextDTO.getWxId().equals("wxid_x8i897ryabo722") && new Long(23735L).equals(bookGroupCipherUser.getBookGroupId()))) {
// 从缓存中获取当前关键词
String curJson = JedisClusterUtils.hget(sendTextDTO.getWxId()+"_DELAY_PUSH", sendTextDTO.getWechatUserId());
if (!StringUtil.isEmpty(curJson)) {
BookGuideDelayDto bookGuideDelayDto = JSONObject.parseObject(curJson, BookGuideDelayDto.class);
// 获取下一个关键词
SelfRobotKeyword selfRobotKeyword = selfRobotKeywordDao.getNextKeyWord(bookGroupCipherUser.getBookGroupId(), bookGuideDelayDto.getKeyword());
if (sendTextDTO.getTextContent().contains("不")) {
// 用户否定回复 发送引导语
SendTextMessageVO vo = new SendTextMessageVO();
vo.setContent(selfRobotKeyword.getGuide());
vo.setCode(SendMessageTypeEnum.SELF.getCode());
vo.setWxId(sendTextDTO.getWechatUserId());
vo.setAltId(sendTextDTO.getWxId());
vo.setWxGroupId(sendTextDTO.getWechatUserId());
vo.setIp(sendTextDTO.getIp());
WxGroupSDK.sendTextMessage(vo);
log.info("[回复内容包含否定内容] SendTextMessageVO:{}",vo);
if ("学前".equals(selfRobotKeyword.getKeyword())
&& envStr.toUpperCase().equals("PRO") && sendTextDTO.getWxId().equals("wxid_x8i897ryabo722")) {
SendGroupInviteVO sendGroupInviteVO = new SendGroupInviteVO();
sendGroupInviteVO.setAltId(sendTextDTO.getWxId());
sendGroupInviteVO.setWxId(sendTextDTO.getWechatUserId());
sendGroupInviteVO.setWxGroupId("23084048866@chatroom");
sendGroupInviteVO.setIp(sendTextDTO.getIp());
WxGroupSDK.sendGroupInvite(sendGroupInviteVO);
log.info("临时发送入群连接 sendGroupInviteVO:{}", sendGroupInviteVO);
}
if ("教辅书单".equals(selfRobotKeyword.getKeyword())){
List<SelfRobotKeywordReply> replyList = selfRobotKeywordReplyDao.getListByKeywordId(selfRobotKeyword.getId());
if (!ListUtils.isEmpty(replyList)) {
for (SelfRobotKeywordReply keywordReply : replyList) {
if (ReplyTypeEnum.RESOURCE.value.equals(keywordReply.getType())) {
SendFileVO sendFileVO = new SendFileVO();
Map<Long, ResourceDTO> map = resourceConsr.mapByIds(Arrays.asList(keywordReply.getResourceId()));
ResourceDTO resourceDTO = map.get(keywordReply.getResourceId());
if (resourceDTO != null) {
sendFileVO.setFileUrl(resourceDTO.getFileUrl());
sendFileVO.setFileName(resourceDTO.getResourceName());
}
sendFileVO.setIp(sendTextDTO.getIp());
sendFileVO.setAltId(sendTextDTO.getWxId());
sendFileVO.setWxId(sendTextDTO.getWechatUserId());
WxGroupSDK.sendFile(sendFileVO);
}
}
}
}
int time = 60;
if ("背景音乐".equals(bookGuideDelayDto.getKeyword())){
time = 600;
}
// 更新缓存中的关键词
BookGuideDelayDto delayDto = BookGuideDelayDto.builder().userWxId(sendTextDTO.getWechatUserId())
.expireTime(DateUtils.addSecond(new Date(), time))
.keyword(selfRobotKeyword.getKeyword())
.ip(sendTextDTO.getIp()).build();
JedisClusterUtils.hset(sendTextDTO.getWxId() + "_DELAY_PUSH", sendTextDTO.getWechatUserId(), JSONObject.toJSONString(delayDto));
} else {
content = bookGuideDelayDto.getKeyword();
}
}
}
SelfRobotKeyword selfRobotKeyword = selfRobotKeywordDao.getByBookGroupIdAndKeyword(bookGroupCipherUser.getBookGroupId(), content); SelfRobotKeyword selfRobotKeyword = selfRobotKeywordDao.getByBookGroupIdAndKeyword(bookGroupCipherUser.getBookGroupId(), content);
if (selfRobotKeyword != null) { if (selfRobotKeyword != null) {
// 用户回复了关键词 删除缓存中的数据 结束主动推送流程
if(JedisClusterUtils.hexists(sendTextDTO.getWxId()+"_DELAY_PUSH",sendTextDTO.getWechatUserId())){
JedisClusterUtils.hdel(sendTextDTO.getWxId()+"_DELAY_PUSH",sendTextDTO.getWechatUserId());
}
sendSelfKeyword(selfRobotKeyword, sendTextDTO); sendSelfKeyword(selfRobotKeyword, sendTextDTO);
//临时,后面要删 //临时,后面要删
String robotId = sendTextDTO.getWxId(); String robotId = sendTextDTO.getWxId();
......
...@@ -353,9 +353,6 @@ public class SelfRobotKeywordBizImpl implements SelfRobotKeywordBiz { ...@@ -353,9 +353,6 @@ public class SelfRobotKeywordBizImpl implements SelfRobotKeywordBiz {
if (ListUtils.isEmpty(selfRobotKeyword.getKeywordReplyList())) { if (ListUtils.isEmpty(selfRobotKeyword.getKeywordReplyList())) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "回复不能为空!"); throw new BookBizException(BookBizException.PARAM_IS_ERROR, "回复不能为空!");
} }
/* if (StringUtil.isEmpty(selfRobotKeyword.getGuide())) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "引导语不能为空!");
}*/
if (StringUtil.isEmpty(selfRobotKeyword.getKeyword())) { if (StringUtil.isEmpty(selfRobotKeyword.getKeyword())) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "关键词不能为空!"); throw new BookBizException(BookBizException.PARAM_IS_ERROR, "关键词不能为空!");
} }
......
...@@ -30,6 +30,9 @@ public class SelfRobotKeyword extends BaseEntity { ...@@ -30,6 +30,9 @@ public class SelfRobotKeyword extends BaseEntity {
@ApiModelProperty("排序值") @ApiModelProperty("排序值")
private Integer seqNum; private Integer seqNum;
@ApiModelProperty("延时时间")
private Integer delayTime;
@ApiModelProperty("创建人") @ApiModelProperty("创建人")
private Long createUser; private Long createUser;
......
...@@ -100,23 +100,19 @@ public class KeyWordDelayRunner implements ApplicationRunner { ...@@ -100,23 +100,19 @@ public class KeyWordDelayRunner implements ApplicationRunner {
try { try {
BookGuideDelayDto bookGuideDelayDto = JSONObject.parseObject(friends.get(userId), BookGuideDelayDto.class); BookGuideDelayDto bookGuideDelayDto = JSONObject.parseObject(friends.get(userId), BookGuideDelayDto.class);
if (bookGuideDelayDto.getExpireTime().before(new Date())) { if (bookGuideDelayDto.getExpireTime().before(new Date())) {
// 用户超时未答复 主动推送关键词 // 查询当前关键词
SelfRobotKeyword selfRobotKeyword = selfRobotKeywordDao.getNextKeyWord(finalBookGroupId, bookGuideDelayDto.getKeyword()); SelfRobotKeyword currentKeyword=selfRobotKeywordDao.getByBookGroupIdAndKeyword(finalBookGroupId,bookGuideDelayDto.getKeyword());
if (selfRobotKeyword==null){ // 发送当前关键词引导语
JedisClusterUtils.hdel(finalWxid+"_DELAY_PUSH",userId);
continue;
}
// log.info("finalBookGroupId:{} bookGuideDelayDto:{}", finalBookGroupId, friends.get(userId));
// 用户否定回复 发送引导语
SendTextMessageVO vo = new SendTextMessageVO(); SendTextMessageVO vo = new SendTextMessageVO();
vo.setContent(selfRobotKeyword.getGuide()); vo.setContent(currentKeyword.getGuide());
vo.setCode(SendMessageTypeEnum.SELF.getCode()); vo.setCode(SendMessageTypeEnum.SELF.getCode());
vo.setWxId(bookGuideDelayDto.getUserWxId()); vo.setWxId(bookGuideDelayDto.getUserWxId());
vo.setAltId(finalWxid); vo.setAltId(finalWxid);
vo.setWxGroupId(bookGuideDelayDto.getUserWxId()); vo.setWxGroupId(bookGuideDelayDto.getUserWxId());
vo.setIp(bookGuideDelayDto.getIp()); vo.setIp(bookGuideDelayDto.getIp());
WxGroupSDK.sendTextMessage(vo); WxGroupSDK.sendTextMessage(vo);
if ("学前".equals(selfRobotKeyword.getKeyword()) log.info("[发送当前关键词]:{}", JSONObject.toJSONString(vo));
if ("学前".equals(currentKeyword.getKeyword())
&& envStr.toUpperCase().equals("PRO") && finalWxid.equals("wxid_x8i897ryabo722")) { && envStr.toUpperCase().equals("PRO") && finalWxid.equals("wxid_x8i897ryabo722")) {
SendGroupInviteVO sendGroupInviteVO = new SendGroupInviteVO(); SendGroupInviteVO sendGroupInviteVO = new SendGroupInviteVO();
sendGroupInviteVO.setAltId(finalWxid); sendGroupInviteVO.setAltId(finalWxid);
...@@ -126,8 +122,8 @@ public class KeyWordDelayRunner implements ApplicationRunner { ...@@ -126,8 +122,8 @@ public class KeyWordDelayRunner implements ApplicationRunner {
WxGroupSDK.sendGroupInvite(sendGroupInviteVO); WxGroupSDK.sendGroupInvite(sendGroupInviteVO);
log.info("临时发送入群连接 sendGroupInviteVO:{}", sendGroupInviteVO); log.info("临时发送入群连接 sendGroupInviteVO:{}", sendGroupInviteVO);
} }
if ("教辅书单".equals(selfRobotKeyword.getKeyword())) { if ("教辅书单".equals(currentKeyword.getKeyword())) {
List<SelfRobotKeywordReply> replyList = selfRobotKeywordReplyDao.getListByKeywordId(selfRobotKeyword.getId()); List<SelfRobotKeywordReply> replyList = selfRobotKeywordReplyDao.getListByKeywordId(currentKeyword.getId());
if (!ListUtils.isEmpty(replyList)) { if (!ListUtils.isEmpty(replyList)) {
for (SelfRobotKeywordReply keywordReply : replyList) { for (SelfRobotKeywordReply keywordReply : replyList) {
if (ReplyTypeEnum.RESOURCE.value.equals(keywordReply.getType())) { if (ReplyTypeEnum.RESOURCE.value.equals(keywordReply.getType())) {
...@@ -147,15 +143,16 @@ public class KeyWordDelayRunner implements ApplicationRunner { ...@@ -147,15 +143,16 @@ public class KeyWordDelayRunner implements ApplicationRunner {
} }
} }
SelfRobotKeyword nextKeyWord = selfRobotKeywordDao.getNextKeyWord(finalBookGroupId, bookGuideDelayDto.getKeyword());
int time = 60; if (nextKeyWord==null){
if ("背景音乐".equals(selfRobotKeyword.getKeyword())){ JedisClusterUtils.hdel(finalWxid+"_DELAY_PUSH",userId);
time = 600; continue;
} }
int time = nextKeyWord.getDelayTime();
// 更新缓存中的关键词 // 更新缓存中的关键词
BookGuideDelayDto delayDto = BookGuideDelayDto.builder().userWxId(bookGuideDelayDto.getUserWxId()) BookGuideDelayDto delayDto = BookGuideDelayDto.builder().userWxId(bookGuideDelayDto.getUserWxId())
.expireTime(DateUtils.addSecond(new Date(), time)) .expireTime(DateUtils.addSecond(new Date(), time))
.keyword(selfRobotKeyword.getKeyword()) .keyword(nextKeyWord.getKeyword())
.ip(bookGuideDelayDto.getIp()).build(); .ip(bookGuideDelayDto.getIp()).build();
JedisClusterUtils.hset(finalWxid + "_DELAY_PUSH", bookGuideDelayDto.getUserWxId(), JSONObject.toJSONString(delayDto)); JedisClusterUtils.hset(finalWxid + "_DELAY_PUSH", bookGuideDelayDto.getUserWxId(), JSONObject.toJSONString(delayDto));
......
...@@ -7,13 +7,14 @@ ...@@ -7,13 +7,14 @@
<result column="guide" property="guide" jdbcType="VARCHAR"/> <result column="guide" property="guide" jdbcType="VARCHAR"/>
<result column="keyword" property="keyword" jdbcType="VARCHAR"/> <result column="keyword" property="keyword" jdbcType="VARCHAR"/>
<result column="seq_num" property="seqNum" jdbcType="INTEGER"/> <result column="seq_num" property="seqNum" jdbcType="INTEGER"/>
<result column="delay_time" property="delayTime" jdbcType="INTEGER"/>
<result column="create_user" property="createUser" jdbcType="BIGINT"/> <result column="create_user" property="createUser" jdbcType="BIGINT"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/> <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, book_group_id, guide, keyword, seq_num, create_user, create_time id, book_group_id, guide, keyword, seq_num, delay_time, create_user, create_time
</sql> </sql>
<insert id="insert" parameterType="com.pcloud.book.keywords.entity.SelfRobotKeyword" useGeneratedKeys="true" <insert id="insert" parameterType="com.pcloud.book.keywords.entity.SelfRobotKeyword" useGeneratedKeys="true"
...@@ -24,6 +25,7 @@ ...@@ -24,6 +25,7 @@
guide, guide,
keyword, keyword,
seq_num, seq_num,
delay_time,
create_user, create_user,
create_time create_time
</trim> </trim>
...@@ -32,6 +34,7 @@ ...@@ -32,6 +34,7 @@
#{guide,jdbcType=VARCHAR}, #{guide,jdbcType=VARCHAR},
#{keyword,jdbcType=VARCHAR}, #{keyword,jdbcType=VARCHAR},
#{seqNum,jdbcType=INTEGER}, #{seqNum,jdbcType=INTEGER},
#{delayTime,jdbcType=INTEGER},
#{createUser,jdbcType=BIGINT}, #{createUser,jdbcType=BIGINT},
NOW() NOW()
</trim> </trim>
...@@ -44,6 +47,7 @@ ...@@ -44,6 +47,7 @@
guide, guide,
keyword, keyword,
seq_num, seq_num,
delay_time,
create_user, create_user,
create_time create_time
) values ) values
...@@ -53,6 +57,7 @@ ...@@ -53,6 +57,7 @@
#{item.guide,jdbcType=VARCHAR}, #{item.guide,jdbcType=VARCHAR},
#{item.keyword,jdbcType=VARCHAR}, #{item.keyword,jdbcType=VARCHAR},
#{item.seqNum,jdbcType=INTEGER}, #{item.seqNum,jdbcType=INTEGER},
#{item.delayTime,jdbcType=INTEGER},
#{item.createUser,jdbcType=BIGINT}, #{item.createUser,jdbcType=BIGINT},
NOW() NOW()
) )
...@@ -65,7 +70,8 @@ ...@@ -65,7 +70,8 @@
book_group_id = #{bookGroupId,jdbcType=BIGINT}, book_group_id = #{bookGroupId,jdbcType=BIGINT},
guide = #{guide,jdbcType=VARCHAR}, guide = #{guide,jdbcType=VARCHAR},
keyword = #{keyword,jdbcType=VARCHAR}, keyword = #{keyword,jdbcType=VARCHAR},
seq_num = #{seqNum,jdbcType=INTEGER} seq_num = #{seqNum,jdbcType=INTEGER},
delay_time = #{delayTime,jdbcType=INTEGER}
</set> </set>
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
...@@ -97,6 +103,8 @@ ...@@ -97,6 +103,8 @@
SELECT * FROM self_robot_keyword SELECT * FROM self_robot_keyword
WHERE book_group_id=#{bookGroupId} WHERE book_group_id=#{bookGroupId}
AND seq_num > (SELECT seq_num FROM self_robot_keyword WHERE keyword = #{keyword} AND book_group_id=#{bookGroupId} LIMIT 1) AND seq_num > (SELECT seq_num FROM self_robot_keyword WHERE keyword = #{keyword} AND book_group_id=#{bookGroupId} LIMIT 1)
and delay_time is not null
and guide is not null
ORDER BY seq_num ORDER BY seq_num
LIMIT 1 LIMIT 1
</select> </select>
......
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