|
@@ -5,16 +5,20 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.util.Codec;
|
|
import com.cyksj.common.util.Codec;
|
|
|
|
|
+import com.cyksj.config.WeChatConfig;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
import com.cyksj.mapper.WxAppMapper;
|
|
import com.cyksj.mapper.WxAppMapper;
|
|
|
|
|
+import com.cyksj.mapper.WxSyncLogMapper;
|
|
|
import com.cyksj.mapper.gzh.UserGzhRelationMapper;
|
|
import com.cyksj.mapper.gzh.UserGzhRelationMapper;
|
|
|
import com.cyksj.model.dto.GzhUnionidUserinfo;
|
|
import com.cyksj.model.dto.GzhUnionidUserinfo;
|
|
|
import com.cyksj.model.dto.MsgEvent;
|
|
import com.cyksj.model.dto.MsgEvent;
|
|
|
import com.cyksj.model.entity.User;
|
|
import com.cyksj.model.entity.User;
|
|
|
import com.cyksj.model.entity.UserGzhRelation;
|
|
import com.cyksj.model.entity.UserGzhRelation;
|
|
|
import com.cyksj.model.entity.WxApp;
|
|
import com.cyksj.model.entity.WxApp;
|
|
|
|
|
+import com.cyksj.model.entity.WxSyncLog;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.distribute.DistributeService;
|
|
import com.cyksj.service.distribute.DistributeService;
|
|
|
|
|
+import com.cyksj.service.user.UserService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -45,6 +49,12 @@ public class EventMsgService implements GzhMsgService {
|
|
|
|
|
|
|
|
private final DistributeService distributeService;
|
|
private final DistributeService distributeService;
|
|
|
|
|
|
|
|
|
|
+ private final UserService userService;
|
|
|
|
|
+
|
|
|
|
|
+ private final WeChatConfig weChatConfig;
|
|
|
|
|
+
|
|
|
|
|
+ private final WxSyncLogMapper wxSyncLogMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public String handleNotify(MsgEvent msgEvent) {
|
|
public String handleNotify(MsgEvent msgEvent) {
|
|
|
try {
|
|
try {
|
|
@@ -84,12 +94,15 @@ public class EventMsgService implements GzhMsgService {
|
|
|
if (StrUtil.isEmpty(openId)) {
|
|
if (StrUtil.isEmpty(openId)) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- //该用户是否存在于用户表里面
|
|
|
|
|
- User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
|
|
|
|
|
- .eq(User::getOpenId, openId)
|
|
|
|
|
- .select(User::getId)
|
|
|
|
|
- .last("limit 1"));
|
|
|
|
|
|
|
+ //迁移公众号之后同步授权后信息
|
|
|
|
|
+ //是否是迁移用户
|
|
|
|
|
+ WxSyncLog wxSyncLog = wxSyncLogMapper.selectOne(Wrappers.lambdaQuery(WxSyncLog.class)
|
|
|
|
|
+ .eq(WxSyncLog::getToAppid, weChatConfig.getAppid())
|
|
|
|
|
+ .eq(WxSyncLog::getNewOpenid, openId).last("limit 1"));
|
|
|
GzhUnionidUserinfo info = weChatService.getUserInfo2(weChatService.getAccessToken(), openId);
|
|
GzhUnionidUserinfo info = weChatService.getUserInfo2(weChatService.getAccessToken(), openId);
|
|
|
|
|
+
|
|
|
|
|
+ User user = userService.getSyncUser(info.getOpenid(), info.getUnionid(), wxSyncLog);
|
|
|
|
|
+
|
|
|
if (user == null) {
|
|
if (user == null) {
|
|
|
user = new User();
|
|
user = new User();
|
|
|
user.setNickname(String.format("%s%s", Constant.DEFAULT_NAME, Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.MD5).setStringData(RandomUtil.randomString(10)).toHexString().substring(0, 6)))
|
|
user.setNickname(String.format("%s%s", Constant.DEFAULT_NAME, Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.MD5).setStringData(RandomUtil.randomString(10)).toHexString().substring(0, 6)))
|