|
|
@@ -7,14 +7,15 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.cyksj.common.constant.TaskTypeEnum;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.config.WeChatConfig;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
+import com.cyksj.mapper.UserTransferLogMapper;
|
|
|
+import com.cyksj.mapper.WxSyncLogMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
|
|
|
import com.cyksj.mapper.market.task.TaskTypeMapper;
|
|
|
import com.cyksj.model.dto.GzhOAuth2UserInfo;
|
|
|
import com.cyksj.model.dto.UserWhoami;
|
|
|
-import com.cyksj.model.entity.TaskType;
|
|
|
-import com.cyksj.model.entity.User;
|
|
|
-import com.cyksj.model.entity.UserDistributeShared;
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.service.market.task.TaskService;
|
|
|
import com.cyksj.service.user.UserService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
@@ -44,26 +45,58 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
|
|
|
private final TaskTypeMapper taskTypeMapper;
|
|
|
|
|
|
+ private final WeChatConfig weChatConfig;
|
|
|
+
|
|
|
+ private final UserTransferLogMapper userTransferLogMapper;
|
|
|
+
|
|
|
+ private final WxSyncLogMapper wxSyncLogMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public User saveAuth(GzhOAuth2UserInfo info, Long sharedId) {
|
|
|
final String unionid = info.getUnionid();
|
|
|
if (StrUtil.isEmpty(unionid)) {
|
|
|
throw BusinessRuntimeException.getInstance("授权操作异常,请刷新页面");
|
|
|
}
|
|
|
- // 查询用户是否存在
|
|
|
- User user = Optional.ofNullable(
|
|
|
- this.getOne(new LambdaQueryWrapper<User>().eq(User::getUnionid,info.getUnionid())))
|
|
|
- .orElseGet(() -> Optional.ofNullable(this.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenId,info.getOpenid())))
|
|
|
- .orElseGet(()-> new User()
|
|
|
- .setUnionid(unionid)));
|
|
|
-
|
|
|
+ User user;
|
|
|
+ //迁移公众号之后同步授权后信息
|
|
|
+ //是否是迁移用户
|
|
|
+ WxSyncLog wxSyncLog = wxSyncLogMapper.selectOne(Wrappers.lambdaQuery(WxSyncLog.class)
|
|
|
+ .eq(WxSyncLog::getToAppid, weChatConfig.getAppid())
|
|
|
+ .eq(WxSyncLog::getNewOpenid, info.getOpenid()).last("limit 1"));
|
|
|
+ if (wxSyncLog != null) {
|
|
|
+ user = this.getOne(Wrappers.lambdaQuery(User.class)
|
|
|
+ .eq(User::getOpenId, wxSyncLog.getOriOpenid()).last("limit 1"));
|
|
|
+ if (user != null) {
|
|
|
+ user.setOpenId(wxSyncLog.getNewOpenid());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 查询用户是否存在
|
|
|
+ user = Optional.ofNullable(
|
|
|
+ this.getOne(new LambdaQueryWrapper<User>().eq(User::getUnionid, info.getUnionid())))
|
|
|
+ .orElseGet(() -> this.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, info.getOpenid())));
|
|
|
+ }
|
|
|
+ user = Optional.ofNullable(user).orElseGet(() -> new User()
|
|
|
+ .setUnionid(unionid));
|
|
|
user.setNickname(info.getNickname())
|
|
|
.setSex(info.getSex())
|
|
|
.setCountry(info.getCountry())
|
|
|
.setProvince(info.getProvince())
|
|
|
.setCity(info.getCity())
|
|
|
.setHeadimgurl(info.getHeadimgurl());
|
|
|
-
|
|
|
+ if (!user.getUnionid().equals(unionid)) {
|
|
|
+ UserTransferLog log = new UserTransferLog();
|
|
|
+ if (wxSyncLog != null) {
|
|
|
+ log.setType("公众号迁移");
|
|
|
+ } else {
|
|
|
+ log.setType("绑定开发者账号");
|
|
|
+ }
|
|
|
+ log.setOldAppId(weChatConfig.getOldAppid());
|
|
|
+ log.setNewAppId(weChatConfig.getAppid());
|
|
|
+ log.setUserId(user.getId());
|
|
|
+ log.setOldUnionid(user.getUnionid());
|
|
|
+ log.setNewUnionid(info.getUnionid());
|
|
|
+ userTransferLogMapper.insert(log);
|
|
|
+ }
|
|
|
user.setUnionid(unionid);
|
|
|
user.setOpenId(info.getOpenid());
|
|
|
UserDistributeShared userDistributeShared = null;
|