Commit fc4a271f by 阮思源

Merge branch 'feat-1002019' into 'master'

发送入群邀请链接之前先拿到群里最新的消息,如果不是48小时之内,就主动发一条消息

See merge request rays/pcloud-book!233
parents d2edadf1 887355ee
...@@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
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;
...@@ -438,4 +439,15 @@ public class WechatGroupConsr { ...@@ -438,4 +439,15 @@ public class WechatGroupConsr {
} }
return groupRobotDTO; return groupRobotDTO;
} }
@ParamLog("根据群id集合查最后发言时间")
public Map<String, Date> getChatLastTimeByGroup(List<String> groupId) {
Map<String, Date> map = new HashMap<>();
try {
map = ResponseHandleUtil.parseMapResponse(messageService.getChatLastTimeByGroup(groupId), String.class, Date.class);
} catch (Exception e) {
log.error("根据群id集合查最后发言时间.[getChatLastTimeByGroup]:" + e.getMessage(), e);
}
return map;
}
} }
...@@ -14,6 +14,7 @@ import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr; ...@@ -14,6 +14,7 @@ import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
import com.pcloud.book.group.biz.BookGroupBiz; import com.pcloud.book.group.biz.BookGroupBiz;
import com.pcloud.book.group.biz.BookGroupClassifyBiz; import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import com.pcloud.book.group.biz.GroupQrcodeBiz; import com.pcloud.book.group.biz.GroupQrcodeBiz;
import com.pcloud.book.group.biz.WeixinQrcodeBiz;
import com.pcloud.book.group.dao.AppTouchRecordDao; import com.pcloud.book.group.dao.AppTouchRecordDao;
import com.pcloud.book.group.dao.BookGroupCipherUserDao; import com.pcloud.book.group.dao.BookGroupCipherUserDao;
import com.pcloud.book.group.dao.BookGroupClassifyDao; import com.pcloud.book.group.dao.BookGroupClassifyDao;
...@@ -21,6 +22,7 @@ import com.pcloud.book.group.dao.BookGroupDao; ...@@ -21,6 +22,7 @@ import com.pcloud.book.group.dao.BookGroupDao;
import com.pcloud.book.group.dao.GroupQrcodeDao; import com.pcloud.book.group.dao.GroupQrcodeDao;
import com.pcloud.book.group.dao.JoinGroupCipherDao; import com.pcloud.book.group.dao.JoinGroupCipherDao;
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.GroupClassifyQrcodeDTO; import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO;
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;
...@@ -55,6 +57,7 @@ import com.pcloud.book.keywords.vo.QrWeixinParam; ...@@ -55,6 +57,7 @@ import com.pcloud.book.keywords.vo.QrWeixinParam;
import com.pcloud.book.keywords.vo.SetKeywordVO; import com.pcloud.book.keywords.vo.SetKeywordVO;
import com.pcloud.book.keywords.vo.SetRankVO; import com.pcloud.book.keywords.vo.SetRankVO;
import com.pcloud.book.keywords.vo.UpdateKeywordVO; import com.pcloud.book.keywords.vo.UpdateKeywordVO;
import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.channelcenter.base.constants.ChannelEnum; import com.pcloud.channelcenter.base.constants.ChannelEnum;
import com.pcloud.channelcenter.qrcode.service.QrcodeSceneService; import com.pcloud.channelcenter.qrcode.service.QrcodeSceneService;
import com.pcloud.channelcenter.qrcode.vo.MessageBookVO; import com.pcloud.channelcenter.qrcode.vo.MessageBookVO;
...@@ -91,12 +94,14 @@ import org.springframework.util.CollectionUtils; ...@@ -91,12 +94,14 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; 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.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -149,6 +154,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -149,6 +154,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
private LiveCons liveCons; private LiveCons liveCons;
@Autowired @Autowired
private BookGroupCipherUserDao bookGroupCipherUserDao; private BookGroupCipherUserDao bookGroupCipherUserDao;
@Autowired
private WeixinQrcodeBiz weixinQrcodeBiz;
/** /**
* 字符串切割长度 * 字符串切割长度
*/ */
...@@ -623,15 +630,61 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -623,15 +630,61 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
if (null == groupQrcode4ClassifyVO) { if (null == groupQrcode4ClassifyVO) {
throw new BookBizException(BookBizException.ID_NOT_EXIST, "群不存在"); throw new BookBizException(BookBizException.ID_NOT_EXIST, "群不存在");
} }
String wxGroupId = groupQrcode4ClassifyVO.getWeixinGroupId(); sendAndCheckInviteGroup(sendTextDTO,groupQrcode4ClassifyVO.getWeixinGroupId());
//发送邀请入群 }
@ParamLog("判断冒泡和发送冒泡和发入群链接")
private void sendAndCheckInviteGroup(SendTextDTO sendTextDTO, String wxGroupId) {
if (checkLastAcTimeSendMsg(wxGroupId)) {
//需要冒泡,冒泡之后隔3秒发
ThreadPoolUtils.SEND_MAOPAO_THREAD_POOL.execute(() -> {
sendMaoPao(sendTextDTO, wxGroupId);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
log.error("需要冒泡,冒泡之后隔3秒发出错!sendTextDTO=" + sendTextDTO.toString() + "wxGroupId=" + wxGroupId);
}
sendInviteToGroup(sendTextDTO, wxGroupId);
});
} else {
//如果不需要冒泡,就直接发
sendInviteToGroup(sendTextDTO, wxGroupId);
}
}
@ParamLog("发送入群邀请链接之前先拿到群里最新的消息,如果不是48小时之内,就主动发一条消息")
private Boolean checkLastAcTimeSendMsg(String wxGroupId) {
Boolean flag = false;
List<String> wechatGroupIds = new ArrayList<>();
wechatGroupIds.add(wxGroupId);
Map<String, Date> map = wechatGroupConsr.getChatLastTimeByGroup(wechatGroupIds);
Date lastTime = map.get(wxGroupId);
if (lastTime == null || (new Date().getTime() - lastTime.getTime()) > 48 * 60 * 60 * 1000) {
flag = true;
}
return flag;
}
@ParamLog("发送冒泡消息")
private void sendMaoPao(SendTextDTO sendTextDTO, String wxGroupId){
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent("我来冒个泡");
sendTextMessageVO.setAltId(sendTextDTO.getWxId());
sendTextMessageVO.setWxGroupId(wxGroupId);
sendTextMessageVO.setIp(findIp(wxGroupId));
WxGroupSDK.sendTextMessage(sendTextMessageVO);
log.info("发送入群邀请链接之前发冒泡消息:"+sendTextMessageVO.toString());
}
@ParamLog("发送进群链接")
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());
sendGroupInviteVO.setWxGroupId(wxGroupId); sendGroupInviteVO.setWxGroupId(wxGroupId);
sendGroupInviteVO.setIp(sendTextDTO.getIp()); sendGroupInviteVO.setIp(sendTextDTO.getIp());
WxGroupSDK.sendGroupInvite(sendGroupInviteVO); WxGroupSDK.sendGroupInvite(sendGroupInviteVO);
log.info("[同意加好友发送欢迎语] 发送进群链接 sendGroupInviteVO:{}", sendGroupInviteVO); log.info("发送进群链接 sendGroupInviteVO:{}", sendGroupInviteVO);
} }
@ParamLog("根据关键词判断关键词是否为1V1社群群名称") @ParamLog("根据关键词判断关键词是否为1V1社群群名称")
...@@ -651,14 +704,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -651,14 +704,7 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
if (null == groupQrcode4ClassifyVO) { if (null == groupQrcode4ClassifyVO) {
throw new BookBizException(BookBizException.ID_NOT_EXIST, "群不存在"); throw new BookBizException(BookBizException.ID_NOT_EXIST, "群不存在");
} }
//发送邀请入群 sendAndCheckInviteGroup(sendTextDTO,groupQrcode4ClassifyVO.getWeixinGroupId());
SendGroupInviteVO sendGroupInviteVO = new SendGroupInviteVO();
sendGroupInviteVO.setAltId(sendTextDTO.getWxId());
sendGroupInviteVO.setWxId(sendTextDTO.getWechatUserId());
sendGroupInviteVO.setWxGroupId(groupQrcode4ClassifyVO.getWeixinGroupId());
sendGroupInviteVO.setIp(sendTextDTO.getIp());
WxGroupSDK.sendGroupInvite(sendGroupInviteVO);
log.info("邀请入群" + sendGroupInviteVO.toString());
} }
} }
} }
...@@ -1156,4 +1202,10 @@ public class BookKeywordBizImpl implements BookKeywordBiz { ...@@ -1156,4 +1202,10 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
return replyKeywordDTO; return replyKeywordDTO;
} }
@ParamLog("获取ip")
private String findIp(String wechatGroupId) {
Map<String, BookWxQrcodeDTO> groupVersion = weixinQrcodeBiz.getGroupVersion(Collections.singletonList(wechatGroupId));
String ip = Optional.ofNullable(groupVersion.get(wechatGroupId)).orElse(new BookWxQrcodeDTO()).getWechatGroupIp();
return ip;
}
} }
...@@ -27,4 +27,10 @@ public class ThreadPoolUtils { ...@@ -27,4 +27,10 @@ public class ThreadPoolUtils {
public static final ExecutorService OTHER_THREAD_POOL = new ThreadPoolExecutor(8, 8, 0L, TimeUnit.SECONDS, public static final ExecutorService OTHER_THREAD_POOL = new ThreadPoolExecutor(8, 8, 0L, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("other-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy()); new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("other-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy());
/**
* 入群邀请链接发送之前发送冒泡消息线程池
*/
public static final ExecutorService SEND_MAOPAO_THREAD_POOL = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("other-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy());
} }
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