Commit 9559320d by 阮思源

修改1v1入群逻辑

parent 383a8c30
......@@ -1255,6 +1255,9 @@ public class BookGroupBizImpl implements BookGroupBiz {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "没有该社群码");
}
ownAltQrcodeInfoDTO.setCustomerServiceName(bookGroupDTO.getCustomerServiceName());
//这里的暗号从社群书获取
ownAltQrcodeInfoDTO.setCipher(bookGroupDTO.getBookGroupCipher());
ownAltQrcodeInfoDTO.setAddFriendGuide(bookGroupDTO.getAddFriendGuide());
Long bookId = bookGroupDTO.getBookId();
Map<String, Object> paramMap = Maps.newHashMap();
paramMap.put("bookId", bookId);
......@@ -1276,29 +1279,6 @@ public class BookGroupBizImpl implements BookGroupBiz {
ownAltQrcodeInfoDTO.setAltNickName(selfRobotDTO.getNickName());
ownAltQrcodeInfoDTO.setAltQrcodeUrl(selfRobotDTO.getQrcodeUrl());
ownAltQrcodeInfoDTO.setAltHeadUrl(selfRobotDTO.getHeadPic());
//获取之前是否有没有使用的暗号
JoinGroupCipher joinGroupCipher = joinGroupCipherDao.getByCondition(wechatUserId, bookGroupId, CipherTypeEnum.BOOK_GROUP_CIPHER.code);
String cipher;
if (joinGroupCipher != null) {
cipher = joinGroupCipher.getCipher();
} else {
//新增暗号
cipher = UUIDUitl.generateShort();
//查重,如果有重复,再次生成
JoinGroupCipher joinGroupCipherHas = joinGroupCipherDao.getByCipher(cipher);
if (joinGroupCipherHas != null) {
cipher = UUIDUitl.generateShort();
}
cipher = "RAYS_" + cipher;
JoinGroupCipher joinGroupCipherNew = new JoinGroupCipher();
joinGroupCipherNew.setCipher(cipher);
joinGroupCipherNew.setWechatUserId(wechatUserId);
joinGroupCipherNew.setBookGroupId(bookGroupId);
joinGroupCipherNew.setAltId(selfRobotDTO.getWxId());
joinGroupCipherNew.setType(CipherTypeEnum.BOOK_GROUP_CIPHER.code);
joinGroupCipherDao.insert(joinGroupCipherNew);
}
ownAltQrcodeInfoDTO.setCipher(cipher);
return ownAltQrcodeInfoDTO;
}
......
package com.pcloud.book.group.dao;
import com.pcloud.book.group.entity.BookGroupCipherUser;
import com.pcloud.common.core.dao.BaseDao;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/9/24 15:18
**/
public interface BookGroupCipherUserDao extends BaseDao<BookGroupCipherUser> {
Long getBookGroupIdByWxUserId(String wxUserId);
}
......@@ -263,5 +263,5 @@ public interface BookGroupClassifyDao extends BaseDao<BookGroupClassify> {
List<ListClassifyVO> getClassifyIngoreDelete(Long bookGroupId);
List<BookGroupClassify> getListByBookGroupIds(List<Long> bookGroupIds);
List<BookGroupClassify> getListByBookGroupId(Long bookGroupId);
}
......@@ -162,4 +162,11 @@ public interface BookGroupDao extends BaseDao<BookGroup> {
* @return
*/
public Integer getBookGroupFriendsCountByAdviser(Long adviserId);
/**
* 根据社群码暗号获取社群码
* @param bookGroupCipher
* @return
*/
BookGroup getByBookGroupCipher(String bookGroupCipher);
}
package com.pcloud.book.group.dao.impl;
import com.pcloud.book.group.dao.BookGroupCipherUserDao;
import com.pcloud.book.group.entity.BookGroupCipherUser;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/9/24 15:19
**/
@Component("bookGroupCipherUserDao")
public class BookGroupCipherUserDaoImpl extends BaseDaoImpl<BookGroupCipherUser> implements BookGroupCipherUserDao {
@Override
public Long getBookGroupIdByWxUserId(String wxUserId) {
return this.getSqlSession().selectOne(this.getStatement("getBookGroupIdByWxUserId"), wxUserId);
}
}
......@@ -250,7 +250,7 @@ public class BookGroupClassifyDaoImpl extends BaseDaoImpl<BookGroupClassify> imp
}
@Override
public List<BookGroupClassify> getListByBookGroupIds(List<Long> bookGroupIds) {
return this.getSqlSession().selectList(this.getStatement("getListByBookGroupIds"), bookGroupIds);
public List<BookGroupClassify> getListByBookGroupId(Long bookGroupId) {
return this.getSqlSession().selectList(this.getStatement("getListByBookGroupIds"), bookGroupId);
}
}
......@@ -168,4 +168,9 @@ public class BookGroupDaoImpl extends BaseDaoImpl<BookGroup> implements BookGrou
public Integer getBookGroupFriendsCountByAdviser(Long adviserId) {
return this.getSqlSession().selectOne(getStatement("getBookGroupFriendsCountByAdviser"), adviserId);
}
@Override
public BookGroup getByBookGroupCipher(String bookGroupCipher) {
return this.getSqlSession().selectOne(getStatement("getByBookGroupCipher"), bookGroupCipher);
}
}
......@@ -31,6 +31,9 @@ public class OwnAltQrcodeInfoDTO implements Serializable {
@ApiModelProperty("客服称谓")
private String customerServiceName;
@ApiModelProperty("加好友宣传语")
private String addFriendGuide;
public String getAltId() {
return altId;
}
......@@ -79,6 +82,14 @@ public class OwnAltQrcodeInfoDTO implements Serializable {
this.customerServiceName = customerServiceName;
}
public String getAddFriendGuide() {
return addFriendGuide;
}
public void setAddFriendGuide(String addFriendGuide) {
this.addFriendGuide = addFriendGuide;
}
@Override
public String toString() {
return "OwnAltQrcodeInfoDTO{" +
......@@ -88,6 +99,7 @@ public class OwnAltQrcodeInfoDTO implements Serializable {
", altQrcodeUrl='" + altQrcodeUrl + '\'' +
", cipher='" + cipher + '\'' +
", customerServiceName='" + customerServiceName + '\'' +
", addFriendGuide='" + addFriendGuide + '\'' +
'}';
}
}
package com.pcloud.book.group.entity;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/9/24 15:16
**/
@ApiModel("社群书暗号关联用户")
public class BookGroupCipherUser extends BaseEntity {
private static final long serialVersionUID = 1763812276337850708L;
@ApiModelProperty("社群码id")
private Long bookGroupId;
@ApiModelProperty("社群码暗号")
private String bookGroupCipher;
@ApiModelProperty("用户微信id")
private String wxUserId;
public Long getBookGroupId() {
return bookGroupId;
}
public void setBookGroupId(Long bookGroupId) {
this.bookGroupId = bookGroupId;
}
public String getBookGroupCipher() {
return bookGroupCipher;
}
public void setBookGroupCipher(String bookGroupCipher) {
this.bookGroupCipher = bookGroupCipher;
}
public String getWxUserId() {
return wxUserId;
}
public void setWxUserId(String wxUserId) {
this.wxUserId = wxUserId;
}
@Override
public String toString() {
return "BookGroupCipherUser{" +
"bookGroupId=" + bookGroupId +
", bookGroupCipher='" + bookGroupCipher + '\'' +
", wxUserId='" + wxUserId + '\'' +
"} " + super.toString();
}
}
......@@ -36,6 +36,9 @@ public class GroupQrcode4ClassifyVO implements Serializable {
@ApiModelProperty("分类名称")
private String classify;
@ApiModelProperty("微信群名称")
private String weixinGroupId;
public String getClassify() {
return classify;
}
......@@ -92,6 +95,14 @@ public class GroupQrcode4ClassifyVO implements Serializable {
this.spareQr = spareQr;
}
public String getWeixinGroupId() {
return weixinGroupId;
}
public void setWeixinGroupId(String weixinGroupId) {
this.weixinGroupId = weixinGroupId;
}
@Override
public String toString() {
return "GroupQrcode4ClassifyVO{" +
......@@ -102,6 +113,7 @@ public class GroupQrcode4ClassifyVO implements Serializable {
", groupQrcodeId=" + groupQrcodeId +
", spareQr='" + spareQr + '\'' +
", classify='" + classify + '\'' +
", weixinGroupId='" + weixinGroupId + '\'' +
'}';
}
}
......@@ -26,7 +26,6 @@ import com.pcloud.book.group.enums.CipherTypeEnum;
import com.pcloud.book.group.enums.TouchTypeEnum;
import com.pcloud.book.group.tools.SendWeixinRequestTools;
import com.pcloud.book.group.vo.GroupQrcodeBaseInfoVO;
import com.pcloud.book.group.vo.ListClassifyVO;
import com.pcloud.book.keywords.biz.BookGuideBiz;
import com.pcloud.book.keywords.biz.BookKeywordBiz;
import com.pcloud.book.keywords.dao.BookGuideDao;
......@@ -107,10 +106,6 @@ public class BookGuideBizImpl implements BookGuideBiz {
private KeywordDao keywordDao;
@Autowired
private WeixinClockGroupClassifyDao weixinClockGroupClassifyDao;
/**
* 字符串切割长度
*/
private static final Integer LE = 1000;
@ParamLog("同意加好友发送欢迎语")
@Override
......@@ -127,12 +122,6 @@ public class BookGuideBizImpl implements BookGuideBiz {
log.info("[同意加好友发送欢迎语] 暗号为空 agreeAddUserDTO:{}", agreeAddUserDTO);
return;
}
// 判断是否是书的暗号,如果是,就走书的暗号流程
JoinGroupCipher joinGroupCipher = joinGroupCipherDao.getByCipher(cipher);
if (joinGroupCipher != null && CipherTypeEnum.BOOK_GROUP_CIPHER.code.equals(joinGroupCipher.getType())) {
dealByBookGroup(joinGroupCipher,agreeAddUserDTO);
return;
}
final JoinGroupCipherDTO dto = joinGroupCipherDao.getDTOByCipher(cipher);
//获取群
GroupQrcodeBaseInfoVO wxGroup = bookGroupClassifyBiz.getWxGroupIdByClassifyIdAndWechatId(dto.getClassifyId(), dto.getWechatUserId());
......@@ -209,117 +198,6 @@ public class BookGuideBizImpl implements BookGuideBiz {
}
}
@ParamLog("按照书处理暗号回复")
private void dealByBookGroup(JoinGroupCipher joinGroupCipher, AgreeAddUserDTO agreeAddUserDTO) {
Long bookGroupId = joinGroupCipher.getBookGroupId();
BookGroupDTO bookGroupDTO = bookGroupDao.getBookBaseInfoById(bookGroupId);
String text = "";
Boolean isInviteGroup = bookGroupDTO.getIsInviteGroup();
String addFriendGuide = bookGroupDTO.getAddFriendGuide();
if (!StringUtil.isEmpty(addFriendGuide)) {
text = text + addFriendGuide + "\n";
}
//获取配套关键词
List<KeywordDTO> keywordDTOS = bookKeywordBiz.getListByBookGroupId(bookGroupId);
if (!ListUtils.isEmpty(keywordDTOS)) {
text = text + "回复括号内关键词领取本书配套资源学习资料:\n";
for (KeywordDTO keywordDTO : keywordDTOS) {
if (!StringUtil.isEmpty(keywordDTO.getKeywords())) {
text = text + "【" + keywordDTO.getKeywords() + "】";
}
}
text = text + "\n";
}
//邀请进群
if (isInviteGroup != null && isInviteGroup) {
//获取社群码下的分类
List<ListClassifyVO> listClassifyVOS = bookGroupClassifyBiz.listAllClassify(bookGroupId);
if (!ListUtils.isEmpty(listClassifyVOS)) {
if (listClassifyVOS.size() == 1) {
ListClassifyVO listClassifyVO = listClassifyVOS.get(0);
//如果只有一个分类
text = text + "本书还配有交流群“" + listClassifyVO.getClassify() + "”," + listClassifyVO.getClassifyIntroduce() + ",点击下方邀请链接,即可进群";
//发送欢迎语
if (text.length() > LE) {
sendTextBatch(agreeAddUserDTO, text, LE);
} else {
sendText(agreeAddUserDTO, text);
}
dealGroupInvite(agreeAddUserDTO, listClassifyVO.getId(), joinGroupCipher.getWechatUserId());
} else {
text = text + "本书还配有以下交流群,选择你想加入的微信群,回复群名称,我会拉你入群!\n";
for (ListClassifyVO listClassifyVO : listClassifyVOS) {
text = text + listClassifyVO.getClassify() + ":" + listClassifyVO.getClassifyIntroduce() + "\n";
}
//发送欢迎语
if (text.length() > LE) {
sendTextBatch(agreeAddUserDTO, text, LE);
} else {
sendText(agreeAddUserDTO, text);
}
}
}
return;
}
//发送欢迎语
if (text.length() > LE) {
sendTextBatch(agreeAddUserDTO, text, LE);
} else {
sendText(agreeAddUserDTO, text);
}
}
@ParamLog("发送收到暗号后的本书介绍")
private void sendText(AgreeAddUserDTO agreeAddUserDTO, String content) {
SendTextMessageVO vo = new SendTextMessageVO();
vo.setContent(content);
vo.setCode(SendMessageTypeEnum.SELF.getCode());
vo.setWxId(agreeAddUserDTO.getRobotWxId());
vo.setAltId(agreeAddUserDTO.getRobotWxId());
vo.setWxGroupId(agreeAddUserDTO.getUserWxId());
vo.setIp(agreeAddUserDTO.getIp());
WxGroupSDK.sendTextMessage(vo);
log.info("发送收到暗号后的本书介绍 : {}", vo);
}
@ParamLog("发送收到暗号后的本书介绍")
private void sendTextBatch(AgreeAddUserDTO agreeAddUserDTO, String content, Integer le) {
List<String> contents = new ArrayList<>();
String s = content;
while (s.length() > le) {
contents.add(s.substring(0, le));
s = s.substring(le, s.length());
}
contents.add(s);
for (String sin : contents) {
sendText(agreeAddUserDTO, sin);
}
}
@ParamLog("分类群发送邀请入群链接")
private void dealGroupInvite(AgreeAddUserDTO agreeAddUserDTO, Long classifyId, Long wechatUserId) {
//获取群
final GroupQrcodeBaseInfoVO wxGroup = bookGroupClassifyBiz.getWxGroupIdByClassifyIdAndWechatId(classifyId, wechatUserId);
if (null == wxGroup) {
log.error("[同意加好友发送欢迎语] : bookGroupClassifyBiz.getWxGroupIdByClassifyIdAndWechatId dto:{}");
throw new BookBizException(BookBizException.ID_NOT_EXIST, "群不存在");
}
String wxGroupId = wxGroup.getWeixinGroupId();
//发送邀请入群
SendGroupInviteVO sendGroupInviteVO = new SendGroupInviteVO();
sendGroupInviteVO.setAltId(agreeAddUserDTO.getRobotWxId());
sendGroupInviteVO.setWxId(agreeAddUserDTO.getUserWxId());
sendGroupInviteVO.setWxGroupId(wxGroupId);
sendGroupInviteVO.setIp(agreeAddUserDTO.getIp());
WxGroupSDK.sendGroupInvite(sendGroupInviteVO);
log.info("[同意加好友发送欢迎语] 发送进群链接 sendGroupInviteVO:{}", sendGroupInviteVO);
}
@ParamLog("进群之后更新群qrCodeId")
private void updateQrcodeForCipher(String wxGroupId, String cipher, String userWxId){
log.info("根据群id查询群信息wxGroupId", wxGroupId);
......
......@@ -16,6 +16,7 @@ import com.pcloud.book.group.biz.BookGroupBiz;
import com.pcloud.book.group.biz.BookGroupClassifyBiz;
import com.pcloud.book.group.biz.GroupQrcodeBiz;
import com.pcloud.book.group.dao.AppTouchRecordDao;
import com.pcloud.book.group.dao.BookGroupCipherUserDao;
import com.pcloud.book.group.dao.BookGroupClassifyDao;
import com.pcloud.book.group.dao.BookGroupDao;
import com.pcloud.book.group.dao.GroupQrcodeDao;
......@@ -24,15 +25,20 @@ import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO;
import com.pcloud.book.group.dto.JoinGroupCipherDTO;
import com.pcloud.book.group.entity.AppTouchRecord;
import com.pcloud.book.group.entity.BookGroup;
import com.pcloud.book.group.entity.BookGroupCipherUser;
import com.pcloud.book.group.entity.BookGroupClassify;
import com.pcloud.book.group.entity.BookGroupServe;
import com.pcloud.book.group.entity.GroupQrcode;
import com.pcloud.book.group.entity.JoinGroupCipher;
import com.pcloud.book.group.enums.CipherTypeEnum;
import com.pcloud.book.group.enums.QrcodeStatusEnum;
import com.pcloud.book.group.enums.TouchTypeEnum;
import com.pcloud.book.group.tools.SendWeixinRequestTools;
import com.pcloud.book.group.vo.ClassifyNameVO;
import com.pcloud.book.group.vo.ClassifyVO;
import com.pcloud.book.group.vo.GroupQrcode4ClassifyVO;
import com.pcloud.book.group.vo.GroupQrcodeBaseInfoVO;
import com.pcloud.book.group.vo.ListClassifyVO;
import com.pcloud.book.keywords.biz.BookKeywordBiz;
import com.pcloud.book.keywords.dao.BookKeywordDao;
import com.pcloud.book.keywords.dao.BookKeywordRecordDao;
......@@ -77,6 +83,7 @@ import com.pcloud.wechatgroup.message.dto.SendTextDTO;
import com.sdk.wxgroup.ChangeNameVO;
import com.sdk.wxgroup.SendGroupInviteVO;
import com.sdk.wxgroup.SendMessageTypeEnum;
import com.sdk.wxgroup.SendTextMessageVO;
import com.sdk.wxgroup.WxGroupSDK;
import org.apache.commons.collections.MapUtils;
......@@ -145,6 +152,12 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
private JoinGroupCipherDao joinGroupCipherDao;
@Autowired
private LiveCons liveCons;
@Autowired
private BookGroupCipherUserDao bookGroupCipherUserDao;
/**
* 字符串切割长度
*/
private static final Integer LE = 1000;
@Override
@ParamLog("新增关键词")
......@@ -468,15 +481,9 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
return;
}
if (SendMessageTypeEnum.SELF.getCode().equals(sendTextDTO.getCode())) {
//根据机器人id和wxId和类型获取暗号信息
List<JoinGroupCipher> joinGroupCiphers = joinGroupCipherDao.getListByAltIdAndWxIdAndType(robotId, userWxId, CipherTypeEnum.BOOK_GROUP_CIPHER.code);
if (!ListUtils.isEmpty(joinGroupCiphers)) {
try {
inviteToGroupByKeyword(sendTextDTO, joinGroupCiphers);
} catch (Exception e) {
log.error("拉群出错" + e.getMessage());
}
}
dealBookGroupCipher(sendTextDTO);
//判断是否为某个群分类名称
inviteToGroupByKeyword(sendTextDTO);
}
//个人机器人接收消息的时候,weixinGroupId就是userWxId,也就是用户的id,robotId是接收的机器人的id
......@@ -602,39 +609,175 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
}
}
@ParamLog("根据关键词判断关键词是否为1V1社群群名称")
private void inviteToGroupByKeyword(SendTextDTO sendTextDTO, List<JoinGroupCipher> joinGroupCiphers) {
List<Long> bookGroupIds = new ArrayList<>();
Map<Long, JoinGroupCipher> map = new HashMap<>();
for (JoinGroupCipher joinGroupCipher : joinGroupCiphers) {
if (joinGroupCipher.getBookGroupId() != null) {
map.put(joinGroupCipher.getBookGroupId(), joinGroupCipher);
bookGroupIds.add(joinGroupCipher.getBookGroupId());
@ParamLog("获取的关键词是否为社群书的暗号")
private void dealBookGroupCipher(SendTextDTO sendTextDTO) {
BookGroup bookGroup = bookGroupDao.getByBookGroupCipher(sendTextDTO.getTextContent());
if (bookGroup != null) {
try {
dealByBookGroup(sendTextDTO, bookGroup.getId());
} catch (Exception e) {
log.error("拉群出错" + e.getMessage());
}
}
if (!ListUtils.isEmpty(bookGroupIds)) {
List<BookGroupClassify> bookGroupClassifyList = bookGroupClassifyDao.getListByBookGroupIds(bookGroupIds);
if (!ListUtils.isEmpty(bookGroupClassifyList)) {
for (BookGroupClassify bookGroupClassify : bookGroupClassifyList) {
if (bookGroupClassify.getClassify().equals(sendTextDTO.getTextContent())) {
//分配群
JoinGroupCipher jgc = map.get(bookGroupClassify.getBookGroupId());
if (jgc == null) {
continue;
}
GroupQrcodeBaseInfoVO wxGroup = bookGroupClassifyBiz.getWxGroupIdByClassifyIdAndWechatId(bookGroupClassify.getId(), jgc.getWechatUserId());
if (null == wxGroup) {
throw new BookBizException(BookBizException.ID_NOT_EXIST, "群不存在" + bookGroupClassify.toString() + jgc.toString());
}
//发送邀请入群
SendGroupInviteVO sendGroupInviteVO = new SendGroupInviteVO();
sendGroupInviteVO.setAltId(sendTextDTO.getWxId());
sendGroupInviteVO.setWxId(sendTextDTO.getWechatUserId());
sendGroupInviteVO.setWxGroupId(wxGroup.getWeixinGroupId());
sendGroupInviteVO.setIp(sendTextDTO.getIp());
WxGroupSDK.sendGroupInvite(sendGroupInviteVO);
log.info("[同意加好友发送欢迎语] 发送进群链接 sendGroupInviteVO:{}", sendGroupInviteVO);
}
@ParamLog("按照书处理暗号回复")
private void dealByBookGroup(SendTextDTO sendTextDTO, Long bookGroupId) {
BookGroupCipherUser bookGroupCipherUser=new BookGroupCipherUser();
bookGroupCipherUser.setBookGroupCipher(sendTextDTO.getTextContent());
bookGroupCipherUser.setBookGroupId(bookGroupId);
bookGroupCipherUser.setWxUserId(sendTextDTO.getWechatUserId());
//新增暗号对应记录
bookGroupCipherUserDao.insert(bookGroupCipherUser);
BookGroupDTO bookGroupDTO = bookGroupDao.getBookBaseInfoById(bookGroupId);
String text = "";
Boolean isInviteGroup = bookGroupDTO.getIsInviteGroup();
// 获取配置的资源服务
List<BookGroupServe> bookGroupServeList = bookGroupBiz.getBookGroupServeList(bookGroupId);
if (!ListUtils.isEmpty(bookGroupServeList)) {
String bookName = bookGroupDTO.getBookName();
if (!StringUtil.isEmpty(bookName)) {
text = text + "《" + bookName + "》" + "配有以下资源服务,戳链接立即获取:" + "\n";
}
int i = 1;
for (BookGroupServe bookGroupServe : bookGroupServeList) {
text = text + i + "." + bookGroupServe.getServeName() + bookGroupServe.getShortUrl() + "\n";
i = i + 1;
}
}
//获取配套关键词
List<KeywordDTO> keywordDTOS = getListByBookGroupId(bookGroupId);
if (!ListUtils.isEmpty(keywordDTOS)) {
text = text + "回复括号内关键词领取本书配套资源学习资料:\n";
for (KeywordDTO keywordDTO : keywordDTOS) {
if (!StringUtil.isEmpty(keywordDTO.getKeywords())) {
text = text + "【" + keywordDTO.getKeywords() + "】";
}
}
text = text + "\n";
}
//邀请进群
if (isInviteGroup != null && isInviteGroup) {
//获取社群码下的分类
List<ListClassifyVO> listClassifyVOS = bookGroupClassifyBiz.listAllClassify(bookGroupId);
if (!ListUtils.isEmpty(listClassifyVOS)) {
if (listClassifyVOS.size() == 1) {
ListClassifyVO listClassifyVO = listClassifyVOS.get(0);
//如果只有一个分类
text = text + "本书还配有交流群“" + listClassifyVO.getClassify() + "”," + listClassifyVO.getClassifyIntroduce() + ",点击下方邀请链接,即可进群";
//发送欢迎语
if (text.length() > LE) {
sendTextBatch(sendTextDTO, text, LE);
} else {
sendText(sendTextDTO, text);
}
dealGroupInvite(sendTextDTO, listClassifyVO.getId(), listClassifyVO.getChangeNumber());
} else {
text = text + "本书还配有以下交流群,选择你想加入的微信群,回复群名称,我会拉你入群!\n";
for (ListClassifyVO listClassifyVO : listClassifyVOS) {
text = text + listClassifyVO.getClassify() + ":" + listClassifyVO.getClassifyIntroduce() + "\n";
}
//发送欢迎语
if (text.length() > LE) {
sendTextBatch(sendTextDTO, text, LE);
} else {
sendText(sendTextDTO, text);
}
}
}
return;
}
//发送欢迎语
if (text.length() > LE) {
sendTextBatch(sendTextDTO, text, LE);
} else {
sendText(sendTextDTO, text);
}
}
@ParamLog("发送收到暗号后的本书介绍")
private void sendText(SendTextDTO sendTextDTO, String content) {
String userWxId = sendTextDTO.getWechatUserId();
String ip = sendTextDTO.getIp();
Integer code = sendTextDTO.getCode();
String robotId = sendTextDTO.getWxId();
SendTextMessageVO vo = new SendTextMessageVO();
vo.setContent(content);
vo.setCode(code);
vo.setWxId(robotId);
vo.setAltId(robotId);
vo.setWxGroupId(userWxId);
vo.setIp(ip);
WxGroupSDK.sendTextMessage(vo);
log.info("发送收到暗号后的本书介绍 : {}", vo);
}
@ParamLog("发送收到暗号后的本书介绍")
private void sendTextBatch(SendTextDTO sendTextDTO, String content, Integer le) {
List<String> contents = new ArrayList<>();
String s = content;
while (s.length() > le) {
contents.add(s.substring(0, le));
s = s.substring(le, s.length());
}
contents.add(s);
for (String sin : contents) {
sendText(sendTextDTO, sin);
}
}
@ParamLog("分类群发送邀请入群链接")
private void dealGroupInvite(SendTextDTO sendTextDTO, Long classifyId, Integer changeNumber) {
//获取分类基本信息
ClassifyVO classify = bookGroupClassifyDao.getClassify(classifyId);
if (classify == null) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "分类不存在");
}
//获取群
GroupQrcode4ClassifyVO groupQrcode4ClassifyVO = bookGroupClassifyDao.getClassifyQrcode(classifyId, changeNumber);
if (null == groupQrcode4ClassifyVO) {
throw new BookBizException(BookBizException.ID_NOT_EXIST, "群不存在");
}
String wxGroupId = groupQrcode4ClassifyVO.getWeixinGroupId();
//发送邀请入群
SendGroupInviteVO sendGroupInviteVO = new SendGroupInviteVO();
sendGroupInviteVO.setAltId(sendTextDTO.getWxId());
sendGroupInviteVO.setWxId(sendTextDTO.getWechatUserId());
sendGroupInviteVO.setWxGroupId(wxGroupId);
sendGroupInviteVO.setIp(sendTextDTO.getIp());
WxGroupSDK.sendGroupInvite(sendGroupInviteVO);
log.info("[同意加好友发送欢迎语] 发送进群链接 sendGroupInviteVO:{}", sendGroupInviteVO);
}
@ParamLog("根据关键词判断关键词是否为1V1社群群名称")
private void inviteToGroupByKeyword(SendTextDTO sendTextDTO) {
String userWxId = sendTextDTO.getWechatUserId();
//获取这个人最近一次触发的关联社群码
Long bookGroupId = bookGroupCipherUserDao.getBookGroupIdByWxUserId(userWxId);
if (bookGroupId == null) {
return;
}
List<BookGroupClassify> bookGroupClassifyList = bookGroupClassifyDao.getListByBookGroupId(bookGroupId);
if (!ListUtils.isEmpty(bookGroupClassifyList)) {
for (BookGroupClassify bookGroupClassify : bookGroupClassifyList) {
if (bookGroupClassify.getClassify().equals(sendTextDTO.getTextContent())) {
//获取群
GroupQrcode4ClassifyVO groupQrcode4ClassifyVO = bookGroupClassifyDao.getClassifyQrcode(bookGroupClassify.getId(), bookGroupClassify.getChangeNumber());
if (null == groupQrcode4ClassifyVO) {
throw new BookBizException(BookBizException.ID_NOT_EXIST, "群不存在");
}
//发送邀请入群
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());
}
}
}
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd" >
<mapper namespace="com.pcloud.book.group.dao.impl.BookGroupCipherUserDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.BookGroupCipherUser">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="book_group_id" property="bookGroupId" jdbcType="BIGINT"/>
<result column="book_group_cipher" property="bookGroupCipher" jdbcType="VARCHAR"/>
<result column="wx_user_id" property="wxUserId" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, book_group_id, book_group_cipher, wx_user_id, create_time
</sql>
<insert id="insert" parameterType="com.pcloud.book.group.entity.BookGroupCipherUser" useGeneratedKeys="true"
keyProperty="id">
insert into book_group_cipher_user
<trim prefix="(" suffix=")" suffixOverrides=",">
book_group_id,
book_group_cipher,
wx_user_id,
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{bookGroupId,jdbcType=BIGINT},
#{bookGroupCipher,jdbcType=VARCHAR},
#{wxUserId,jdbcType=VARCHAR},
NOW()
</trim>
</insert>
<!--根据用户查询社群码id-->
<select id="getBookGroupIdByWxUserId" parameterType="String" resultType="long">
select book_group_id t where t.wx_user_id=#{wxUserId} order by create_time desc limit 1
</select>
</mapper>
\ No newline at end of file
......@@ -402,10 +402,11 @@
classify_id classifyId,
id groupQrcodeId,
qrcode_url qrcodeUrl,
weixin_group_id weixinGroupId,
group_name groupName
FROM
book_group_qrcode
WHERE user_number <![CDATA[ < ]]> #{changeNumber} AND classify_id = #{classifyId} AND use_state = 1 AND is_delete = 0 limit 1
WHERE user_number <![CDATA[ < ]]> #{changeNumber} AND classify_id = #{classifyId} AND use_state = 1 AND is_delete = 0 order by user_number asc limit 1
</select>
<select id="listGroupClassifyByAdviser" resultType="com.pcloud.book.group.vo.BookGroupClassifyVO" parameterType="map">
......@@ -976,16 +977,14 @@
</select>
<!--根据社群码id集合获取-->
<select id="getListByBookGroupIds" parameterType="list" resultMap="BaseResultMap">
<select id="getListByBookGroupId" parameterType="list" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM
book_group_classify t
WHERE
t.book_group_id IN
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
t.book_group_id =#{bookGroupId}
AND t.is_delete = 0
order by create_time asc
</select>
</mapper>
\ No newline at end of file
......@@ -426,4 +426,13 @@
AND G.is_delete = 0
AND c.has_used = 1
</select>
<!--根据社群码暗号获取-->
<select id="getByBookGroupCipher" parameterType="String" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from book_group
where book_group_cipher=#{bookGroupCipher}
and is_delete=0
limit 1
</select>
</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