Commit 0ab91627 by 裴大威

feat add ip

parent c8025a4b
......@@ -6,6 +6,7 @@ import com.pcloud.book.book.dto.BookFreezeDto;
import com.pcloud.book.book.entity.BookFreeze;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
......@@ -27,6 +28,9 @@ public class BookFreezeDaoImpl extends BaseDaoImpl<BookFreeze> implements BookFr
@Override
public Map<Long, BookFreezeDto> getFreezeStatus(List<Long> bookIds) {
if(CollectionUtils.isEmpty(bookIds)) {
return Maps.newHashMap();
}
return this.getSqlSession().selectMap(this.getStatement("getFreezeStatus"), bookIds, "bookId");
}
......
......@@ -20,6 +20,7 @@ import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.ResponseHandleUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -312,4 +313,15 @@ public class QrcodeSceneConsr {
return null;
}
@ParamLog("根据二维码id获取bookId")
public Long getBookId4SceneId(Long sceneId) throws BizException {
if (null == sceneId) return null;
try {
return ResponseHandleUtil.parseResponse(qrcodeSceneService.getBookId4SceneId(sceneId), Long.class);
} catch (BizException e) {
LOGGER.error("【二维码-渠道】 根据二维码id获取bookId,<ERROR>.[getBookId4SceneId]:" + e.getMessage(), e);
}
return null;
}
}
......@@ -75,7 +75,7 @@ public interface GroupQrcodeBiz {
* @Desr:新增一个用户
* @Date:2019/4/28 14:45
*/
void addOneUser(String wechatGroupId, Integer memberCount, String nickName, String robotId);
void addOneUser(String wechatGroupId, Integer memberCount, String nickName, String robotId, String ip);
/**
* @Author:lili
......
......@@ -121,12 +121,17 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
@Autowired
private LearningReportTouchRecordDao learningReportTouchRecordDao;
@Override
@ParamLog("新增分类")
@Transactional(rollbackFor = Exception.class)
public void addClassify(AddClassifyVO addClassifyVO, Long partyId) {
checkClassifyIsExist(addClassifyVO.getClassify(), null, addClassifyVO.getBookGroupId());
Integer classifyCount = getClassifyCount(addClassifyVO.getBookGroupId());
final Map<Long, BookGroupStatisticDTO> statistic = bookGroupClassifyBiz.getBookGroupStatistic(Collections.singletonList(addClassifyVO.getBookGroupId()));
Integer classifyCount = 0;
if (!CollectionUtils.isEmpty(statistic) && null != statistic.get(addClassifyVO.getBookGroupId())) {
classifyCount = statistic.get(addClassifyVO.getBookGroupId()).getClassifyCount();
}
if (classifyCount >= 10) {
throw new BookBizException(BookBizException.ERROR, "分类数量超出限制");
}
......@@ -385,10 +390,14 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
@ParamLog("获取分类与群数量")
public ClassifyAndGroupCountVO getClassifyAndGroupCount(Long bookGroupId) {
ClassifyAndGroupCountVO classifyAndGroupCountVO = new ClassifyAndGroupCountVO();
//获取分类数量
Integer classifyCount = bookGroupClassifyDao.getClassifyCount(bookGroupId);
Integer groupCount = bookGroupClassifyDao.getGroupCount(bookGroupId);
classifyAndGroupCountVO.setClassifyCount(classifyCount);
//获取分类数量
final Map<Long, BookGroupStatisticDTO> statistic = bookGroupClassifyBiz.getBookGroupStatistic(Collections.singletonList(bookGroupId));
if (CollectionUtils.isEmpty(statistic) || null == statistic.get(bookGroupId)) {
classifyAndGroupCountVO.setClassifyCount(0);
} else {
classifyAndGroupCountVO.setClassifyCount(statistic.get(bookGroupId).getClassifyCount());
}
classifyAndGroupCountVO.setGroupCount(groupCount);
return classifyAndGroupCountVO;
}
......@@ -397,9 +406,13 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
@ParamLog("获取分类数与用户总数")
public ClassifyAndUserCountVO getClassifyAndUserCount(Long bookGroupId) {
ClassifyAndUserCountVO classifyAndUserCountVO = new ClassifyAndUserCountVO();
Integer classifyCount = bookGroupClassifyDao.getClassifyCount(bookGroupId);
final Map<Long, BookGroupStatisticDTO> statistic = bookGroupClassifyBiz.getBookGroupStatistic(Collections.singletonList(bookGroupId));
if (CollectionUtils.isEmpty(statistic) || null == statistic.get(bookGroupId)) {
classifyAndUserCountVO.setClassifyCount(0);
} else {
classifyAndUserCountVO.setClassifyCount(statistic.get(bookGroupId).getClassifyCount());
}
Integer userCount = bookGroupClassifyDao.getUserNumberCount(bookGroupId);
classifyAndUserCountVO.setClassifyCount(classifyCount);
classifyAndUserCountVO.setUserCount(userCount);
return classifyAndUserCountVO;
}
......@@ -436,7 +449,9 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
@ParamLog(value = "设置是否购买", isBefore = false)
private void setIsBuy(List<ListClassify4WechatVO> listClassify4Wechats, Long wechatUserId) {
if (ListUtils.isEmpty(listClassify4Wechats)) return;
if (ListUtils.isEmpty(listClassify4Wechats)) {
return;
}
List<Long> classifyIds = new ArrayList<>();
for (ListClassify4WechatVO listClassify4WechatVO : listClassify4Wechats) {
classifyIds.add(listClassify4WechatVO.getClassifyId());
......@@ -461,7 +476,7 @@ public class BookGroupClassifyBizImpl implements BookGroupClassifyBiz {
if (classify == null) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "社群码不存在,请刷新后重试");
}
if (new BigDecimal(0).compareTo(classify.getPrice()) == -1) {
if (new BigDecimal(0).compareTo(classify.getPrice()) < 0) {
//校验用户是否购买
Boolean isBuy = bookClassifyBuyRecordDao.checkUserBuy(wechatUserId, classifyId);
if (!isBuy) {
......
......@@ -14,6 +14,8 @@ import com.pcloud.book.group.biz.GroupAnnouncementBiz;
import com.pcloud.book.group.biz.GroupQrcodeBiz;
import com.pcloud.book.group.biz.WeixinQrcodeBiz;
import com.pcloud.book.group.dao.GroupQrcodeDao;
import com.pcloud.book.group.dto.AutoUpdateGroupNumDTO;
import com.pcloud.book.group.dto.BookWxQrcodeDTO;
import com.pcloud.book.group.dto.ChangeGroupNameDTO;
import com.pcloud.book.group.dto.GroupAndUserNumberDTO;
import com.pcloud.book.group.dto.GroupNameAndMaxSeqDTO;
......@@ -57,11 +59,13 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
......@@ -99,7 +103,6 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
@Autowired
private LabelConsr labelConsr;
private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(5);
@Override
@ParamLog("updateGroupQrcode")
......@@ -175,7 +178,9 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
for (ClassifyQrcodeVO classifyQrcodeVO : classifyQrcodeVOS) {
qrcodeIds.add(classifyQrcodeVO.getWeixinQrcodeId());
}
if (ListUtils.isEmpty(qrcodeIds)) return;
if (ListUtils.isEmpty(qrcodeIds)) {
return;
}
Map<Long, KeywordUserCountDTO> keywordMap = bookKeywordRecordDao.listKeywordUseCount(qrcodeIds);
for (ClassifyQrcodeVO classifyQrcodeVO : classifyQrcodeVOS) {
if (keywordMap == null || keywordMap.get(classifyQrcodeVO.getWeixinQrcodeId()) == null) {
......@@ -221,7 +226,7 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
@Override
@ParamLog("新增一个用户")
public void addOneUser(String weixinGroupId, Integer memberCount, String nickName, String robotId) {
public void addOneUser(String weixinGroupId, Integer memberCount, String nickName, String robotId, String ip) {
// 收发一体
String robotIdByGroupId = robotId;
if(StringUtil.isBlank(robotId)) {
......@@ -229,7 +234,7 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
robotIdByGroupId = wechatGroupConsr.getRobotIdByGroupId(weixinGroupId);
}
if(robotIdByGroupId != null){
Integer peopleCounts = WxGroupSDK.getPeopleCounts(weixinGroupId, robotIdByGroupId);
Integer peopleCounts = WxGroupSDK.getPeopleCounts(weixinGroupId, robotIdByGroupId, ip);
if (peopleCounts != null) {
memberCount = peopleCounts;
}
......@@ -268,13 +273,16 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
} else {
return;
}
LOGGER.info("【发送欢迎语消息】,topic发送开始");
PushAddUserMessageDTO pushAddUserMessageDTO = new PushAddUserMessageDTO();
pushAddUserMessageDTO.setWeixinGroupId(weixinGroupId);
pushAddUserMessageDTO.setTime(System.currentTimeMillis());
pushAddUserMessageDTO.setNickName(nickName);
pushAddUserMessageDTO.setMemberCount(memberCount);
pushAddUserMessageDTO.setRobotId(robotIdByGroupId);
pushAddUserMessageDTO.setIp(ip);
bookMQProducer.pushAddUserMessageTopic(pushAddUserMessageDTO);
LOGGER.info("【发送欢迎语消息】,topic发送结束");
}
......@@ -294,7 +302,8 @@ public class GroupQrcodeBizImpl implements GroupQrcodeBiz {
if (StringUtil.isEmpty(weixinGroupId) || StringUtil.isEmpty(wxUserId)) {
return;
}
Integer peopleCounts = WxGroupSDK.getPeopleCounts(weixinGroupId,wxUserId);
final Map<String, BookWxQrcodeDTO> groupVersion = weixinQrcodeBiz.getGroupVersion(Collections.singletonList(weixinGroupId));
Integer peopleCounts = WxGroupSDK.getPeopleCounts(weixinGroupId, wxUserId, Optional.ofNullable(groupVersion.get(weixinGroupId)).orElse(new BookWxQrcodeDTO()).getWechatGroupIp());
if (peopleCounts != null) {
//更新用户数
groupQrcodeDao.updateUserNumber(weixinGroupId, peopleCounts);
......
......@@ -20,6 +20,7 @@ import com.pcloud.book.group.tools.QrcodeTools;
import com.pcloud.book.group.tools.SendWeixinRequestTools;
import com.pcloud.book.group.vo.QrStatisticsVO;
import com.pcloud.book.group.vo.WeixinQrcodeVO;
import com.pcloud.book.util.common.ThreadPoolUtils;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.core.biz.MessageBiz;
import com.pcloud.common.core.dto.SendEmailDto;
......@@ -43,9 +44,11 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
......@@ -69,8 +72,9 @@ public class WeixinQrcodeBizImpl implements WeixinQrcodeBiz {
private PromotionConsr promotionConsr;
@Autowired
private WechatGroupConsr wechatGroupConsr;
@Autowired
private WeixinQrcodeBiz weixinQrcodeBiz;
private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(5);
@Override
public Long countWechatGroup(){
......@@ -88,12 +92,14 @@ public class WeixinQrcodeBizImpl implements WeixinQrcodeBiz {
//更新二维码
Integer number = weixinQrcodeDao.setIsUseById(qrcodeVO.getId());
if (number > 0) {
EXECUTOR_SERVICE.execute(()->{
ThreadPoolUtils.OTHER_THREAD_POOL.execute(()->{
wechatGroupConsr.addGroupManagers(qrcodeVO.getWeixinGroupId(), qrcodeVO.getRobotWxId());
});
//获取当前群人数
try {
Integer peopleCounts = WxGroupSDK.getPeopleCounts(qrcodeVO.getWeixinGroupId(), qrcodeVO.getRobotWxId());
final String weixinGroupId = qrcodeVO.getWeixinGroupId();
final Map<String, BookWxQrcodeDTO> groupVersion = weixinQrcodeBiz.getGroupVersion(Collections.singletonList(weixinGroupId));
Integer peopleCounts = WxGroupSDK.getPeopleCounts(weixinGroupId, qrcodeVO.getRobotWxId(), Optional.ofNullable(groupVersion.get(weixinGroupId)).orElse(new BookWxQrcodeDTO()).getWechatGroupIp());
qrcodeVO.setUserNumber(peopleCounts);
} catch (Exception e) {
qrcodeVO.setUserNumber(0);
......
......@@ -20,4 +20,6 @@ public class PushAddUserMessageDTO implements Serializable {
private String robotId;
private String ip;
}
......@@ -2,7 +2,10 @@ package com.pcloud.book.group.facade.impl;
import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.group.biz.GroupQrcodeBiz;
import com.pcloud.book.group.biz.WeixinQrcodeBiz;
import com.pcloud.book.group.dto.BookWxQrcodeDTO;
import com.pcloud.book.group.facade.GroupQrcodeFacade;
import com.pcloud.book.group.service.WeixinQrcodeService;
import com.pcloud.book.group.vo.ClassifyQrcodeVO;
import com.pcloud.book.group.vo.GroupQrcodeBaseInfoVO;
import com.pcloud.book.group.vo.GroupQrcodeBookVO;
......@@ -26,6 +29,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import io.swagger.annotations.ApiOperation;
/**
......@@ -38,6 +46,8 @@ public class GroupQrcodeFacadeImpl implements GroupQrcodeFacade {
@Autowired
private GroupQrcodeBiz groupQrcodeBiz;
@Autowired
private WeixinQrcodeBiz weixinQrcodeBiz;
@GetMapping("listAllGroupQrcode")
public ResponseDto<PageBeanNew> listAllGroupQrcode(@RequestHeader("token") String token,
......@@ -95,7 +105,8 @@ public class GroupQrcodeFacadeImpl implements GroupQrcodeFacade {
@GetMapping("addUser")
ResponseDto<?> addUser(@RequestParam("weixinGroupId") String weixinGroupId, @RequestParam("userNumber") Integer userNumber)
throws BizException{
groupQrcodeBiz.addOneUser(weixinGroupId, userNumber, null, null);
final Map<String, BookWxQrcodeDTO> groupVersion = weixinQrcodeBiz.getGroupVersion(Collections.singletonList(weixinGroupId));
groupQrcodeBiz.addOneUser(weixinGroupId, userNumber, null, null, Optional.ofNullable(groupVersion.get(weixinGroupId)).orElse(new BookWxQrcodeDTO()).getWechatGroupIp());
return new ResponseDto<>();
}
......
......@@ -128,7 +128,7 @@ public class SendWeixinRequestTools {
}
@ParamLog("修改微信群名称")
public static void sendGuideMessage(List<ReplyMessageVO> replyMessages, String robotId, String weixinGroupId) {
public static void sendGuideMessage(List<ReplyMessageVO> replyMessages, String robotId, String weixinGroupId, String ip) {
//JedisClusterUtils.del("BOOK:WEIXINGROUP:GUIDEUSER" + weixinGroupId);
if (ListUtils.isEmpty(replyMessages)) {
return;
......@@ -144,29 +144,31 @@ public class SendWeixinRequestTools {
if (ReplyTypeEnum.TEXT.value.equals(sendMessageDTO.getReplyType())) {
sendMessageDTO.setContent(nickNameStr + " " + sendMessageDTO.getContent());
} else {
sendAtMessage(nickNameStr, robotId, weixinGroupId);
sendAtMessage(nickNameStr, robotId, weixinGroupId, ip);
}
}
}
sendMessage(sendMessageDTO, robotId, weixinGroupId);
sendMessage(sendMessageDTO, robotId, weixinGroupId, ip);
i++;
}
}
@ParamLog("推送消息")
private static void sendMessage(SendMessageDTO sendMessageDTO, String robotId, String weixinGroupId) {
private static void sendMessage(SendMessageDTO sendMessageDTO, String robotId, String weixinGroupId, String ip) {
if (ReplyTypeEnum.TEXT.value.equals(sendMessageDTO.getReplyType())) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent(sendMessageDTO.getContent());
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setIp(ip);
WxGroupSDK.sendTextMessage(sendTextMessageVO);
} else if (ReplyTypeEnum.IMAGE.value.equals(sendMessageDTO.getReplyType())) {
SendPicMessageVO sendPicMessageVO = new SendPicMessageVO();
sendPicMessageVO.setGroupId(weixinGroupId);
sendPicMessageVO.setAltId(robotId);
sendPicMessageVO.setPicUrl(sendMessageDTO.getPicUrl());
sendPicMessageVO.setIp(ip);
WxGroupSDK.sendPicMessage(sendPicMessageVO);
} else if (ReplyTypeEnum.APP.value.equals(sendMessageDTO.getReplyType()) || ReplyTypeEnum.LINK.value.equals(sendMessageDTO.getReplyType())) {
SendArticleMessageVO sendArticleMessageVO = new SendArticleMessageVO();
......@@ -176,16 +178,18 @@ public class SendWeixinRequestTools {
sendArticleMessageVO.setGroupId(weixinGroupId);
sendArticleMessageVO.setPicUrl(sendMessageDTO.getPicUrl());
sendArticleMessageVO.setTitle(sendMessageDTO.getContent());
sendArticleMessageVO.setIp(ip);
WxGroupSDK.sendArticleMessage(sendArticleMessageVO);
}
}
private static void sendAtMessage(String nickNameStr,String robotId,String weixinGroupId){
private static void sendAtMessage(String nickNameStr,String robotId,String weixinGroupId, String ip){
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent(nickNameStr);
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setIp(ip);
WxGroupSDK.sendTextMessage(sendTextMessageVO);
}
......@@ -205,7 +209,7 @@ public class SendWeixinRequestTools {
@ParamLog("推送公众号消息")
public static void sendAccountMessage(String weixinGroupId, String recommendLanguage, String robotId,
AccountSettingDto accountSettingDto) {
AccountSettingDto accountSettingDto, String ip) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
if (StringUtil.isEmpty(recommendLanguage)) {
recommendLanguage = "关注本书公众号,获取更多资源。";
......@@ -213,19 +217,21 @@ public class SendWeixinRequestTools {
sendTextMessageVO.setContent(recommendLanguage);
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setIp(ip);
WxGroupSDK.sendTextMessage(sendTextMessageVO);
SendPicMessageVO sendPicMessageVO = new SendPicMessageVO();
sendPicMessageVO.setGroupId(weixinGroupId);
sendPicMessageVO.setAltId(robotId);
sendPicMessageVO.setPicUrl(accountSettingDto.getQrcodeUrl());
sendPicMessageVO.setIp(ip);
WxGroupSDK.sendPicMessage(sendPicMessageVO);
}
@ParamLog("推送关键词回复消息")
public static void sendKeywordMessage(ReplyKeywordDTO replyKeywordDTO, String robotId, String weixinGroupId) {
public static void sendKeywordMessage(ReplyKeywordDTO replyKeywordDTO, String robotId, String weixinGroupId, String ip) {
SendMessageDTO sendMessageDTO = new SendMessageDTO();
BeanUtils.copyProperties(replyKeywordDTO, sendMessageDTO);
sendMessage(sendMessageDTO, robotId, weixinGroupId);
sendMessage(sendMessageDTO, robotId, weixinGroupId, ip);
}
@ParamLog("补充域名")
......@@ -263,14 +269,16 @@ public class SendWeixinRequestTools {
}
@ParamLog("欢迎语中推送关键词信息")
public static void sendKeywordsInfo(List<KeywordDTO> keywords, String robotId, String weixinGroupId) {
if (ListUtils.isEmpty(keywords)) return;
public static void sendKeywordsInfo(List<KeywordDTO> keywords, String robotId, String weixinGroupId, String ip){
if (ListUtils.isEmpty(keywords)) {
return;
}
String content = "";
for (int i = 0; i < keywords.size(); i++) {
KeywordDTO keywordDTO = keywords.get(i);
String keyword = "关键词【" + keywordDTO.getKeywords() + "】\n" + " "+keywordDTO.getGuide();
if (content.length() + keyword.length() > 300) {
sendTextMessage(content, robotId, weixinGroupId);
sendTextMessage(content, robotId, weixinGroupId, ip);
content = keyword;
}else{
content = content + keyword;
......@@ -279,14 +287,15 @@ public class SendWeixinRequestTools {
content = content + "\n";
}
}
sendTextMessage(content, robotId, weixinGroupId);
sendTextMessage(content, robotId, weixinGroupId, ip);
}
public static void sendTextMessage(String content, String robotId, String weixinGroupId){
public static void sendTextMessage(String content, String robotId, String weixinGroupId, String ip){
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setContent(content);
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setIp(ip);
WxGroupSDK.sendTextMessage(sendTextMessageVO);
}
......@@ -298,7 +307,7 @@ public class SendWeixinRequestTools {
// WxGroupSDK.sendTextMessage(sendTextMessageVO);
}
public static void sendDefaultMessage(String groupName, String robotId, String weixinGroupId, Boolean isHaveKeywords) {
public static void sendDefaultMessage(String groupName, String robotId, String weixinGroupId, Boolean isHaveKeywords, String ip) {
String content = getNickNameStr(weixinGroupId);
if (StringUtil.isEmpty(groupName)) {
content += " 欢迎加入本群!";
......@@ -308,7 +317,7 @@ public class SendWeixinRequestTools {
if(isHaveKeywords){
content = content + "本群目的为学习交流和学习辅导,线上资源和工具为图书的增值服务,可根据实际情况配合图书一起使用。凭以下关键词领取任务或资源:";
}
sendTextMessage(content, robotId, weixinGroupId);
sendTextMessage(content, robotId, weixinGroupId, ip);
}
private static String getNickNameStr(String weixinGroupId) {
......@@ -337,11 +346,14 @@ public class SendWeixinRequestTools {
}
@ParamLog("欢迎语中推送关键词信息")
public static void sendClockKeywordsInfo(List<BookClockKeywordDTO> keywords, String robotId, String weixinGroupId) {
public static void sendClockKeywordsInfo(List<BookClockKeywordDTO> keywords, String robotId, String weixinGroupId, String ip) {
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
if (ListUtils.isEmpty(keywords)) return;
sendTextMessageVO.setIp(ip);
if (ListUtils.isEmpty(keywords)) {
return;
}
String content = "";
for (int i = 0; i < keywords.size(); i++) {
BookClockKeywordDTO bookClockKeywordDTO = keywords.get(i);
......
......@@ -70,7 +70,7 @@ public interface BookKeywordBiz {
* @Desr: 回复关键词消息
* @Date:2019/5/5 16:28
*/
void sendKeywordMessage(String content, String weixinGroupId, String userWxId, String robotId);
void sendKeywordMessage(String content, String weixinGroupId, String userWxId, String robotId, String ip);
/**
* 关键词统计
......
......@@ -272,22 +272,22 @@ public class BookGuideBizImpl implements BookGuideBiz {
//获取群名称
GroupQrcodeBaseInfoVO groupInfo = groupQrcodeBiz.getBaseById(classifyQrcodeInfo.getGroupQrcodeId());
//推送消息
SendWeixinRequestTools.sendDefaultMessage(groupInfo == null ? "" : groupInfo.getGroupName(), robotId, weixinGroupId, isHaveKeywords);
SendWeixinRequestTools.sendDefaultMessage(groupInfo == null ? "" : groupInfo.getGroupName(), robotId, weixinGroupId, isHaveKeywords, pushAddUserMessageDTO.getIp());
} else {
//处理链接
handleUrl(replyMessages, wechatInfo, classifyQrcodeInfo);
//推送消息
SendWeixinRequestTools.sendGuideMessage(replyMessages, robotId, weixinGroupId);
SendWeixinRequestTools.sendGuideMessage(replyMessages, robotId, weixinGroupId, pushAddUserMessageDTO.getIp());
//新增欢迎语应用触发记录
addGuideAppTouchRecord(replyMessages,weixinGroupId,classifyQrcodeInfo.getBookGroupId(),classifyQrcodeInfo.getClassifyId());
}
//获取关键词信息(改成10个了)
SendWeixinRequestTools.sendKeywordsInfo(keywords, robotId, weixinGroupId);
SendWeixinRequestTools.sendKeywordsInfo(keywords, robotId, weixinGroupId, pushAddUserMessageDTO.getIp());
//如果设置了群学习报告,加一个群学习报告的关键词
pushLearningReport(classifyQrcodeInfo,robotId, weixinGroupId);
pushLearningReport(classifyQrcodeInfo,robotId, weixinGroupId, pushAddUserMessageDTO.getIp());
if (bookGuide != null && bookGuide.getIsRecommend() != null && bookGuide.getIsRecommend() == 1) {
//推送公众号消息
SendWeixinRequestTools.sendAccountMessage(weixinGroupId, bookGuide.getRecommendLanguage(), robotId, wechatInfo);
SendWeixinRequestTools.sendAccountMessage(weixinGroupId, bookGuide.getRecommendLanguage(), robotId, wechatInfo, pushAddUserMessageDTO.getIp());
}
//校验该群是否与微信群打卡有关
List<Long> bookClockInfoIdList = bookClockCheck.checkGroupIsClock(classifyQrcodeInfo);
......@@ -305,10 +305,10 @@ public class BookGuideBizImpl implements BookGuideBiz {
bookClockKeywordDTOList.addAll(bookClockKeywordDTOS);
if(i%2 == 0){
log.info("欢迎语中推送关键词信息,bookClockKeywordDTOList="+bookClockKeywordDTOList);
SendWeixinRequestTools.sendClockKeywordsInfo(bookClockKeywordDTOList, robotId, weixinGroupId);
SendWeixinRequestTools.sendClockKeywordsInfo(bookClockKeywordDTOList, robotId, weixinGroupId, pushAddUserMessageDTO.getIp());
bookClockKeywordDTOList.clear();
}else if(i == bookClockInfoIdList.size()){
SendWeixinRequestTools.sendClockKeywordsInfo(bookClockKeywordDTOList, robotId, weixinGroupId);
SendWeixinRequestTools.sendClockKeywordsInfo(bookClockKeywordDTOList, robotId, weixinGroupId, pushAddUserMessageDTO.getIp());
bookClockKeywordDTOList.clear();
}
......@@ -317,9 +317,9 @@ public class BookGuideBizImpl implements BookGuideBiz {
}
@ParamLog("推关学习报告键词消息")
private void pushLearningReport(GroupClassifyQrcodeDTO classifyQrcodeInfo, String robotId, String weixinGroupId) {
private void pushLearningReport(GroupClassifyQrcodeDTO classifyQrcodeInfo, String robotId, String weixinGroupId, String ip) {
if (classifyQrcodeInfo.getHasOpenLearningReport() != null && classifyQrcodeInfo.getHasOpenLearningReport()) {
SendWeixinRequestTools.sendTextMessage("关键词【学习报告】\n 获取个人专属学习报告,与群成员PK元气值", robotId, weixinGroupId);
SendWeixinRequestTools.sendTextMessage("关键词【学习报告】\n 获取个人专属学习报告,与群成员PK元气值", robotId, weixinGroupId, ip);
}
}
......
......@@ -411,15 +411,13 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
@Override
@ParamLog("关键词消息回复")
public void sendKeywordMessage(String content, String weixinGroupId, String userWxId, String robotId) {
public void sendKeywordMessage(String content, String weixinGroupId, String userWxId, String robotId, String ip) {
//简单过滤非关键词的词
if (StringUtil.isEmpty(content) || content.length() > 20) {
return;
}
//通过群id获取对应基本信息
final long l = System.currentTimeMillis();
GroupClassifyQrcodeDTO classifyQrcodeInfo = bookGroupClassifyBiz.getClassifyQrcodeInfo(weixinGroupId);
log.info("[接收用户发送文本消息] bookGroupClassifyBiz.getClassifyQrcodeInfo耗时:{}ms ", System.currentTimeMillis() - l);
if (classifyQrcodeInfo == null) {
log.info("[关键词消息回复] classifyQrcodeInfo is null");
return;
......@@ -427,14 +425,10 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
ReplyKeywordDTO replyKeywordDTO ;
final boolean equals = "群主,来个抽奖".equals(content);
if (equals){
final long l1 = System.currentTimeMillis();
replyKeywordDTO = keywordDao.getByKeyword("群主,来个抽奖");
log.info("[接收用户发送文本消息] keywordDao.getByKeyword耗时:{}ms ", System.currentTimeMillis() - l1);
} else {
//获取匹配关键词
final long l1 = System.currentTimeMillis();
replyKeywordDTO = bookKeywordDao.getKeywordId(classifyQrcodeInfo.getClassifyId(), classifyQrcodeInfo.getBookGroupId(), content);
log.info("[接收用户发送文本消息] keywordDao.getByKeyword耗时:{}ms ", System.currentTimeMillis() - l1);
}
if (replyKeywordDTO == null) {
log.info("[关键词消息回复] replyKeywordDTO is null");
......@@ -448,16 +442,14 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
replyKeywordDTO.setLinkUrl(linkUrl);
}
String redisContent = JedisClusterUtils.getJson("BOOK:KEYWORD:" + weixinGroupId + "-" + replyKeywordDTO.getKeywordId(), String.class);
// 同一群10秒内不回复同一关键词
if (redisContent != null) {
final long l1 = System.currentTimeMillis();
insertBookKeywordRecord(classifyQrcodeInfo, replyKeywordDTO.getKeywordId(), userWxId, weixinGroupId, false);
log.info("[关键词消息回复] redisContent:{} insertBookKeywordRecord return", redisContent);
return;
} else {
final long l1 = System.currentTimeMillis();
JedisClusterUtils.setJson("BOOK:KEYWORD:" + weixinGroupId + "-" + replyKeywordDTO.getKeywordId(), replyKeywordDTO.getKeywordId(), 10);
insertBookKeywordRecord(classifyQrcodeInfo, replyKeywordDTO.getKeywordId(), userWxId, weixinGroupId, true);
log.info("[接收用户发送文本消息] redisContent == null insertBookKeywordRecord耗时:{}ms ", System.currentTimeMillis() - l1);
}
//获取推送消息机器人
// 20190704改为收发一体
......@@ -465,16 +457,11 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
log.info("[关键词消息回复] robotId is null content:{}, robotId:{},weixinGroupId:{}", content, robotId, weixinGroupId);
robotId = wechatGroupConsr.getRobotIdByGroupId(weixinGroupId);
}
final long l2 = System.currentTimeMillis();
log.info("[关键词回复发送数据] : sendKeywordMessage replyKeywordDTO :{}, robotId:{}, weixinGroupId:{}", replyKeywordDTO, robotId, weixinGroupId);
SendWeixinRequestTools.sendKeywordMessage(replyKeywordDTO, robotId, weixinGroupId);
log.info("[接收用户发送文本消息] SendWeixinRequestTools.sendKeywordMessage耗时:{}ms ", System.currentTimeMillis() - l2);
SendWeixinRequestTools.sendKeywordMessage(replyKeywordDTO, robotId, weixinGroupId, ip);
//新增关键词触发记录
final long l3 = System.currentTimeMillis();
addKeywordAppTouchRecord(replyKeywordDTO, weixinGroupId, classifyQrcodeInfo.getClassifyId(), classifyQrcodeInfo.getBookGroupId());
log.info("[接收用户发送文本消息] addKeywordAppTouchRecord耗时:{}ms ", System.currentTimeMillis() - l3);
//第一推送关键词消息埋点
final long l4 = System.currentTimeMillis();
String keywordsKey = "BOOK:FIRSTKEYWORD:" + DateUtils.getShortDateStr() + "-" + weixinGroupId;
Boolean isSend = JedisClusterUtils.getJson(keywordsKey, Boolean.class);
if (isSend != null && isSend) {
......@@ -487,7 +474,6 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
robotReplyDTO.setWxGroupId(weixinGroupId);
robotReplyDTO.setWxUserId(userWxId);
wechatGroupConsr.addFirstRobotReplyRecord(robotReplyDTO);
log.info("[接收用户发送文本消息] addKeywordAppTouchRecord耗时:{}ms ", System.currentTimeMillis() - l4);
}
/**
......
......@@ -31,7 +31,7 @@ public class AddWxGroupListener {
try {
if (addWXGroupDTO == null || addWXGroupDTO.getWechatGroupId() == null || addWXGroupDTO.getMemberCount() == null)
return;
groupQrcodeBiz.addOneUser(addWXGroupDTO.getWechatGroupId(), addWXGroupDTO.getMemberCount(),addWXGroupDTO.getNickName(), addWXGroupDTO.getWxId());
groupQrcodeBiz.addOneUser(addWXGroupDTO.getWechatGroupId(), addWXGroupDTO.getMemberCount(),addWXGroupDTO.getNickName(), addWXGroupDTO.getWxId(), addWXGroupDTO.getIp());
} catch (Exception e) {
LOGGER.error("接收微信用户进群消息失败" + e.getMessage(), e);
}
......
package com.pcloud.book.mq.topic;
import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
import com.pcloud.book.group.biz.WeixinQrcodeBiz;
import com.pcloud.book.group.dao.GroupQrcodeDao;
import com.pcloud.book.group.dto.BookWxQrcodeDTO;
import com.pcloud.book.group.entity.GroupQrcode;
import com.pcloud.book.mq.config.MQTopicConumer;
import com.pcloud.common.core.aspect.ParamLog;
......@@ -17,6 +19,10 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
@Component
@RabbitListener(queues = MQTopicConumer.UPDATE_WXGROUP_NAME)
public class UpdateWXGroupNameListener {
......@@ -27,6 +33,8 @@ public class UpdateWXGroupNameListener {
private GroupQrcodeDao groupQrcodeDao;
@Autowired
private WechatGroupConsr wechatGroupConsr;
@Autowired
private WeixinQrcodeBiz weixinQrcodeBiz;
@ParamLog("接收修改群名称topic")
@RabbitHandler
......@@ -53,6 +61,7 @@ public class UpdateWXGroupNameListener {
changeNameVO.setWxGroupId(wechatGroupId);
String altId = groupNameDTO.getWxId();
changeNameVO.setAltId(altId);
changeNameVO.setIp(groupNameDTO.getIp());
LOGGER.info("修改群名称" + changeNameVO.toString());
WxGroupSDK.changeGroupName(changeNameVO);
SendTextMessageVO sendTextMessageVO = new SendTextMessageVO();
......@@ -60,10 +69,18 @@ public class UpdateWXGroupNameListener {
sendTextMessageVO.setAltId(altId);
sendTextMessageVO.setGroupId(wechatGroupId);
LOGGER.info("发送警告文本消息"+sendTextMessageVO.toString());
sendTextMessageVO.setIp(findIp(wechatGroupId));
WxGroupSDK.sendTextMessage(sendTextMessageVO);
}
} catch (Exception e) {
LOGGER.error("接收修改群名称失败" + e.getMessage(), e);
}
}
@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;
}
}
......@@ -107,6 +107,7 @@ public class WXGroupLearningReportListener {
sendTextMessageVO.setGroupId(wechatGroupId);
sendTextMessageVO.setAltId(alt);
sendTextMessageVO.setContent("个人专属学习报告,及群成员元气排行榜。点击获取" + resultUrl);
sendTextMessageVO.setIp(findIp(wechatGroupId));
LOGGER.info("发送文字消息开始"+sendTextMessageVO.toString());
WxGroupSDK.sendTextMessage(sendTextMessageVO);
LOGGER.info("发送文字消息结束"+sendTextMessageVO.toString());
......@@ -114,6 +115,7 @@ public class WXGroupLearningReportListener {
sendPicMessageVO.setPicUrl(imageUrl);
sendPicMessageVO.setGroupId(wechatGroupId);
sendPicMessageVO.setAltId(alt);
sendPicMessageVO.setIp(findIp(wechatGroupId));
LOGGER.info("发送分享图消息开始"+sendTextMessageVO.toString());
WxGroupSDK.sendPicMessage(sendPicMessageVO);
LOGGER.info("发送分享图消息开始"+sendTextMessageVO.toString());
......@@ -122,6 +124,13 @@ public class WXGroupLearningReportListener {
}
}
@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;
}
@ParamLog("获取图片")
private String getPic(List<LearningScoreDTO> learningScoreDTOS, String qrcodeUrl) {
String list="";
......
......@@ -10,11 +10,13 @@ import com.pcloud.book.consumer.wechatgroup.WechatGroupConsr;
import com.pcloud.book.es.biz.ESNewsBiz;
import com.pcloud.book.es.entity.ESNews;
import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import com.pcloud.book.group.biz.WeixinQrcodeBiz;
import com.pcloud.book.group.dao.AppTouchRecordDao;
import com.pcloud.book.group.dao.BookGroupClassifyDao;
import com.pcloud.book.group.dao.BookGroupDao;
import com.pcloud.book.group.dao.GroupQrcodeDao;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.dto.BookWxQrcodeDTO;
import com.pcloud.book.group.dto.ClassifyDTO;
import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO;
import com.pcloud.book.group.entity.AppTouchRecord;
......@@ -106,6 +108,8 @@ public class PushBizImpl implements PushBiz {
private PushPlanDao pushPlanDao;
@Autowired
private BookGroupDao bookGroupDao;
@Autowired
private WeixinQrcodeBiz weixinQrcodeBiz;
private static final String PUSH_SCHEDULE_PRE="BOOK_GROUP_PUSH_";
......@@ -320,6 +324,7 @@ public class PushBizImpl implements PushBiz {
sendTextMessageVO.setAltId(altId);
sendTextMessageVO.setContent(pushItem.getTextContent());
sendTextMessageVO.setPushGroupRecordId(pushGroupRecordId);
sendTextMessageVO.setIp(findIp(groupId));
WxGroupSDK.sendTextMessage(sendTextMessageVO);
}
if (ItemTypeEnum.LINK.value.equals(itemType)) {
......@@ -337,6 +342,7 @@ public class PushBizImpl implements PushBiz {
sendArticleMessageVO.setPicUrl(pushItem.getLinkImageUrl());
sendArticleMessageVO.setTitle(pushItem.getLinkTitle());
sendArticleMessageVO.setPushGroupRecordId(pushGroupRecordId);
sendArticleMessageVO.setIp(findIp(groupId));
WxGroupSDK.sendArticleMessage(sendArticleMessageVO);
}
if (ItemTypeEnum.APP.value.equals(itemType)) {
......@@ -361,6 +367,7 @@ public class PushBizImpl implements PushBiz {
sendArticleMessageVO.setPicUrl(appDto.getSquareImg());
sendArticleMessageVO.setTitle(appDto.getTitle());
sendArticleMessageVO.setPushGroupRecordId(pushGroupRecordId);
sendArticleMessageVO.setIp(findIp(groupId));
WxGroupSDK.sendArticleMessage(sendArticleMessageVO);
//新增群发应用作品触发记录
addPushAppTouchRecord(pushItem, groupId, classifyDTO.getId(), classifyDTO.getBookGroupId());
......@@ -382,6 +389,7 @@ public class PushBizImpl implements PushBiz {
sendArticleMessageVO.setPicUrl(productDto.getCoverImg());
sendArticleMessageVO.setTitle(productDto.getProductName());
sendArticleMessageVO.setPushGroupRecordId(pushGroupRecordId);
sendArticleMessageVO.setIp(findIp(groupId));
WxGroupSDK.sendArticleMessage(sendArticleMessageVO);
//新增群发应用作品触发记录
addPushAppTouchRecord(pushItem, groupId, classifyDTO.getId(), classifyDTO.getBookGroupId());
......@@ -394,6 +402,7 @@ public class PushBizImpl implements PushBiz {
sendPicMessageVO.setGroupId(groupId);
sendPicMessageVO.setPicUrl(pushItem.getImageUrl());
sendPicMessageVO.setPushGroupRecordId(pushGroupRecordId);
sendPicMessageVO.setIp(findIp(groupId));
WxGroupSDK.sendPicMessage(sendPicMessageVO);
}
}
......@@ -914,6 +923,7 @@ public class PushBizImpl implements PushBiz {
sendTextMessageVO.setContent(content);
sendTextMessageVO.setAltId(robotId);
sendTextMessageVO.setGroupId(weixinGroupId);
sendTextMessageVO.setIp(findIp(weixinGroupId));
WxGroupSDK.sendTextMessage(sendTextMessageVO);
LOGGER.info("发送早晚报" + sendTextMessageVO.toString());
}
......@@ -1605,4 +1615,11 @@ public class PushBizImpl implements PushBiz {
pushGroup.setPushId(push.getId());
}
}
@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;
}
}
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