Commit 3eae4013 by 阮思源

【ID1002070】合并微信聊天用户和RAYS用户

parent 7f4b8a5b
......@@ -638,4 +638,9 @@ public interface BookGroupBiz {
* 根据类型获取社群书id集合
*/
List<Long> getBookGroupIdsByJoinGroupType(Integer joinGroupType);
/**
* 获取随机码
*/
String getRandomCode(Long wechatUserId);
}
......@@ -46,6 +46,7 @@ import com.pcloud.book.group.dao.PushBookGroupUpdateDao;
import com.pcloud.book.group.dao.TempletRelevanceDao;
import com.pcloud.book.group.dao.WeixinQrcodeDao;
import com.pcloud.book.group.dao.WeixinQrcodeGenerationDao;
import com.pcloud.book.group.dao.WxUserWechatRelevanceDao;
import com.pcloud.book.group.dto.AgentStatisticsInfoDTO;
import com.pcloud.book.group.dto.AltAndCountDTO;
import com.pcloud.book.group.dto.AltIdAndNameDTO;
......@@ -86,6 +87,7 @@ import com.pcloud.book.group.entity.JoinGroupCipher;
import com.pcloud.book.group.entity.PushBookGroupUpdate;
import com.pcloud.book.group.entity.TempletRelevance;
import com.pcloud.book.group.entity.WeixinQrcodeGeneration;
import com.pcloud.book.group.entity.WxUserWechatRelevance;
import com.pcloud.book.group.enums.CipherTypeEnum;
import com.pcloud.book.group.enums.JoinGroupTypeEnum;
import com.pcloud.book.group.enums.LargeTempletEnum;
......@@ -304,6 +306,8 @@ public class BookGroupBizImpl implements BookGroupBiz {
private BrowseRecordConsr browseRecordConsr;
@Autowired
private ExportConsr exportConsr;
@Autowired
private WxUserWechatRelevanceDao wxUserWechatRelevanceDao;
private static final ThreadPoolExecutor PLATFORM_STATISTICS_EXPORT_THREAD = new ThreadPoolExecutor(2, 2,
0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
......@@ -3610,4 +3614,43 @@ public class BookGroupBizImpl implements BookGroupBiz {
List<Long> bookGroupIds = bookGroupDao.getIdsByJoinGroupType(joinGroupType);
return bookGroupIds;
}
@ParamLog("获取随机码")
@Override
public String getRandomCode(Long wechatUserId) {
if (wechatUserId == null) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "微信id为空!");
}
//先查询数据库
WxUserWechatRelevance wxUserWechatRelevance = wxUserWechatRelevanceDao.getByWechatUserId(wechatUserId);
if (wxUserWechatRelevance != null) {
return wxUserWechatRelevance.getRandomCode();
}
//之前没有就新增
WxUserWechatRelevance wechatRelevanceNew = new WxUserWechatRelevance();
wechatRelevanceNew.setWechatUserId(wechatUserId);
String randomCode = createRandomCode();
//校验库里面有没有
WxUserWechatRelevance toCheck = wxUserWechatRelevanceDao.getByRandomCode(randomCode);
if (toCheck != null) {
//重新获取
randomCode = createRandomCode();
}
wechatRelevanceNew.setRandomCode(randomCode);
//新增
wxUserWechatRelevanceDao.insert(wechatRelevanceNew);
return randomCode;
}
@ParamLog("生成随机码")
private String createRandomCode(){
//生成暗号规则:abcdefg,7位字符串
Random random = new Random();
String s = "";
for (int i = 0; i < 7; i++) {
int result = 97 + random.nextInt(26);
s = s + String.valueOf((char) result);
}
return s;
}
}
package com.pcloud.book.group.dao;
import com.pcloud.book.group.entity.WxUserWechatRelevance;
import com.pcloud.common.core.dao.BaseDao;
public interface WxUserWechatRelevanceDao extends BaseDao<WxUserWechatRelevance> {
void updateWxIdByRandomCode(String randomCode, String wxId);
WxUserWechatRelevance getByWechatUserId(Long wechatUserId);
WxUserWechatRelevance getByRandomCode(String randomCode);
}
package com.pcloud.book.group.dao.impl;
import com.pcloud.book.group.dao.WxUserWechatRelevanceDao;
import com.pcloud.book.group.entity.WxUserWechatRelevance;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @Description
* @Author ruansiyuan
* @Date 2019/12/16 15:46
**/
@Component("wxUserWechatRelevanceDao")
public class WxUserWechatRelevanceDaoImpl extends BaseDaoImpl<WxUserWechatRelevance> implements WxUserWechatRelevanceDao {
@Override
public void updateWxIdByRandomCode(String randomCode, String wxId) {
Map<String, Object> map = new HashMap<>();
map.put("randomCode", randomCode);
map.put("wxId", wxId);
this.getSqlSession().update(this.getStatement("updateWxIdByRandomCode"), map);
}
@Override
public WxUserWechatRelevance getByWechatUserId(Long wechatUserId) {
return this.getSqlSession().selectOne(this.getStatement("getByWechatUserId"), wechatUserId);
}
@Override
public WxUserWechatRelevance getByRandomCode(String randomCode) {
return this.getSqlSession().selectOne(this.getStatement("getByRandomCode"), randomCode);
}
}
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/12/16 15:34
**/
@ApiModel("系统微信用户和社群书微信用户关联")
public class WxUserWechatRelevance extends BaseEntity {
@ApiModelProperty("微信id")
private Long wechatUserId;
@ApiModelProperty("微信唯一标识")
private String wxId;
@ApiModelProperty("随机码")
private String randomCode;
public Long getWechatUserId() {
return wechatUserId;
}
public void setWechatUserId(Long wechatUserId) {
this.wechatUserId = wechatUserId;
}
public String getWxId() {
return wxId;
}
public void setWxId(String wxId) {
this.wxId = wxId;
}
public String getRandomCode() {
return randomCode;
}
public void setRandomCode(String randomCode) {
this.randomCode = randomCode;
}
@Override
public String toString() {
return "WxUserWechatRelevance{" +
"wechatUserId=" + wechatUserId +
", wxId='" + wxId + '\'' +
", randomCode='" + randomCode + '\'' +
"} " + super.toString();
}
}
......@@ -587,4 +587,10 @@ public interface BookGroupFacade {
@PostMapping("listUser4SelfPush")
public ResponseDto<PageBeanNew<UserBookInfoVO>> listUser4SelfPush(
@RequestHeader("token") String token, @RequestBody @ApiParam UserSelectParamDTO userSelectParamDTO) throws PermissionException;
@ApiOperation("获取随机码")
@GetMapping("getRandomCode")
ResponseDto<?> getRandomCode(
@CookieValue("userInfo")String userInfo
) throws PermissionException;
}
......@@ -915,4 +915,14 @@ public class BookGroupFacadeImpl implements BookGroupFacade {
PageBeanNew<UserBookInfoVO> pageBeanNew = bookGroupBiz.listUser4SelfPush(userSelectParamDTO);
return new ResponseDto<>(pageBeanNew);
}
@ApiOperation("获取随机码")
@GetMapping("getRandomCode")
@Override
public ResponseDto<?> getRandomCode(
@CookieValue("userInfo")String userInfo
) throws PermissionException {
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
return new ResponseDto<>(bookGroupBiz.getRandomCode(wechatUserId));
}
}
......@@ -22,6 +22,7 @@ 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.dao.JoinGroupCipherDao;
import com.pcloud.book.group.dao.WxUserWechatRelevanceDao;
import com.pcloud.book.group.dto.BookGroupDTO;
import com.pcloud.book.group.dto.BookWxQrcodeDTO;
import com.pcloud.book.group.dto.GroupClassifyQrcodeDTO;
......@@ -163,6 +164,8 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
private WeixinQrcodeBiz weixinQrcodeBiz;
@Autowired
private BookGroupAppBiz bookGroupAppBiz;
@Autowired
private WxUserWechatRelevanceDao wxUserWechatRelevanceDao;
/**
* 字符串切割长度
*/
......@@ -500,10 +503,16 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
@ParamLog("获取的关键词是否为社群书的暗号")
private void dealBookGroupCipher(SendTextDTO sendTextDTO) {
BookGroup bookGroup = bookGroupDao.getByBookGroupCipher(sendTextDTO.getTextContent());
String cipher = sendTextDTO.getTextContent();
//判断是否为加了随机码的暗号
if (cipher.length() > 7) {
cipher = cipher.substring(0, 7);
}
BookGroup bookGroup = bookGroupDao.getByBookGroupCipher(cipher);
if (bookGroup != null) {
try {
addBookGroupCipherUser(sendTextDTO, bookGroup.getId());
addBookGroupCipherUser(sendTextDTO, cipher, bookGroup.getId());
updateWxUserWechatRelevance(sendTextDTO);
dealByBookGroup(sendTextDTO, bookGroup.getId(), false);
} catch (Exception e) {
log.error("拉群出错" + e.getMessage());
......@@ -511,10 +520,20 @@ public class BookKeywordBizImpl implements BookKeywordBiz {
}
}
@ParamLog("更新系统微信用户和社群书微信用户关联表")
private void updateWxUserWechatRelevance(SendTextDTO sendTextDTO) {
if (sendTextDTO.getTextContent().length() != 15) {
return;
}
String randomCode = sendTextDTO.getTextContent().substring(8);
//更新
wxUserWechatRelevanceDao.updateWxIdByRandomCode(randomCode, sendTextDTO.getWechatUserId());
}
@ParamLog("增加暗号对应书记录")
private void addBookGroupCipherUser(SendTextDTO sendTextDTO, Long bookGroupId) {
private void addBookGroupCipherUser(SendTextDTO sendTextDTO, String cipher, Long bookGroupId) {
BookGroupCipherUser bookGroupCipherUser = new BookGroupCipherUser();
bookGroupCipherUser.setBookGroupCipher(sendTextDTO.getTextContent());
bookGroupCipherUser.setBookGroupCipher(cipher);
bookGroupCipherUser.setBookGroupId(bookGroupId);
bookGroupCipherUser.setWxUserId(sendTextDTO.getWechatUserId());
bookGroupCipherUser.setAltId(sendTextDTO.getWxId());
......
<?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.WxUserWechatRelevanceDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.WxUserWechatRelevance">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="wechat_user_id" property="wechatUserId" jdbcType="BIGINT"/>
<result column="wx_id" property="wxId" jdbcType="VARCHAR"/>
<result column="random_code" property="randomCode" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, wechat_user_id, wx_id, random_code, create_time
</sql>
<insert id="insert" parameterType="com.pcloud.book.group.entity.WxUserWechatRelevance" useGeneratedKeys="true"
keyProperty="id">
insert into wx_user_wechat_relevance
<trim prefix="(" suffix=")" suffixOverrides=",">
wechat_user_id,
wx_id,
random_code,
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{wechatUserId,jdbcType=BIGINT},
#{wxId,jdbcType=VARCHAR},
#{randomCode,jdbcType=VARCHAR},
NOW()
</trim>
</insert>
<!--更新wxId-->
<update id="updateWxIdByRandomCode" parameterType="map">
update wx_user_wechat_relevance
set wx_id=#{wxId}
where random_code=#{randomCode}
</update>
<!--根据微信id获取-->
<select id="getByWechatUserId" parameterType="long" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from wx_user_wechat_relevance
where wechat_user_id=#{wechatUserId}
limit 1
</select>
<!--根据随机码获取-->
<select id="getByRandomCode" parameterType="string" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from wx_user_wechat_relevance
where random_code=#{randomCode}
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