mirror of
https://gitee.com/gz-yami/mall4j.git
synced 2026-03-22 09:17:16 +08:00
注册绑定手机号接口
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yami.shop</groupId>
|
||||
<artifactId>yami-shop-common</artifactId>
|
||||
<artifactId>yami-shop-service</artifactId>
|
||||
<version>${yami.shop.version}</version>
|
||||
</dependency>
|
||||
<!--security、oauth2-->
|
||||
|
||||
@@ -12,6 +12,7 @@ package com.yami.shop.security.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yami.shop.bean.model.User;
|
||||
import com.yami.shop.security.enums.App;
|
||||
import com.yami.shop.security.model.AppConnect;
|
||||
|
||||
@@ -22,4 +23,7 @@ import com.yami.shop.security.model.AppConnect;
|
||||
public interface AppConnectService extends IService<AppConnect> {
|
||||
|
||||
AppConnect getByBizUserId(String bizUserId, App app);
|
||||
|
||||
User registerOrBindUser(User user, AppConnect appConnect, Integer appId);
|
||||
|
||||
}
|
||||
|
||||
@@ -11,10 +11,12 @@
|
||||
package com.yami.shop.security.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -22,39 +24,91 @@ import java.util.Collections;
|
||||
/**
|
||||
* 用户详细信息
|
||||
*/
|
||||
@Getter
|
||||
public class YamiUser extends User {
|
||||
@Data
|
||||
public class YamiUser implements UserDetails {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@Setter
|
||||
private String userId;
|
||||
|
||||
@Setter
|
||||
private String bizUserId;
|
||||
|
||||
@Setter
|
||||
private String pic;
|
||||
|
||||
@Setter
|
||||
private String name;
|
||||
|
||||
@Setter
|
||||
private boolean debugger;
|
||||
|
||||
@Setter
|
||||
private String password;
|
||||
|
||||
public YamiUser(String userId, String password, boolean enabled) {
|
||||
super(userId, password, enabled,true, true, true , Collections.emptyList());
|
||||
this.userId = userId;
|
||||
this.password = password;
|
||||
private Integer appType;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* 自提点Id
|
||||
*/
|
||||
private Long stationId;
|
||||
|
||||
/**
|
||||
* 店铺Id
|
||||
*/
|
||||
private Long shopId;
|
||||
/**
|
||||
* 小程序session_key
|
||||
*/
|
||||
private String sessionKey;
|
||||
|
||||
public YamiUser() {
|
||||
|
||||
}
|
||||
|
||||
public YamiUser(String userId, String bizUserId, Integer appId, boolean enabled) {
|
||||
super(appId + StrUtil.COLON + bizUserId, "", enabled,true, true, true , Collections.emptyList());
|
||||
public YamiUser(String userId, String bizUserId, Integer appType, boolean enabled) {
|
||||
this.userId = userId;
|
||||
this.bizUserId = bizUserId;
|
||||
this.appType = appType;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public YamiUser(String userId, String password, boolean enabled) {
|
||||
this.userId = userId;
|
||||
this.password = password;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return StrUtil.isBlank(userId)? bizUserId: userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
package com.yami.shop.security.service;
|
||||
|
||||
import com.yami.shop.bean.model.User;
|
||||
import com.yami.shop.security.enums.App;
|
||||
import com.yami.shop.security.exception.UsernameNotFoundExceptionBase;
|
||||
import com.yami.shop.security.model.AppConnect;
|
||||
@@ -45,4 +46,8 @@ public interface YamiUserDetailsService extends UserDetailsService {
|
||||
* @return
|
||||
*/
|
||||
YamiUser loadUserByUserMail(String userMail, String loginPassword);
|
||||
|
||||
User loadUserByMobileOrUserName(String mobileOrUserName, Integer loginType);
|
||||
|
||||
YamiUser getYamiUser(Integer appId, User user, String bizUserId);
|
||||
}
|
||||
|
||||
@@ -10,16 +10,26 @@
|
||||
|
||||
package com.yami.shop.security.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yami.shop.bean.model.User;
|
||||
import com.yami.shop.common.exception.YamiShopBindException;
|
||||
import com.yami.shop.dao.UserMapper;
|
||||
import com.yami.shop.security.dao.AppConnectMapper;
|
||||
import com.yami.shop.security.enums.App;
|
||||
import com.yami.shop.security.model.AppConnect;
|
||||
import com.yami.shop.security.service.AppConnectService;
|
||||
import com.yami.shop.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
@@ -32,6 +42,12 @@ public class AppConnectServiceImpl extends ServiceImpl<AppConnectMapper, AppConn
|
||||
@Autowired
|
||||
private AppConnectMapper appConnectMapper;
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* YamiUserServiceImpl#insertUserIfNecessary 将会清楚该缓存信息
|
||||
* @param bizUserId
|
||||
@@ -44,4 +60,46 @@ public class AppConnectServiceImpl extends ServiceImpl<AppConnectMapper, AppConn
|
||||
return appConnectMapper.getByBizUserId(bizUserId, app.value());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public User registerOrBindUser(User user, AppConnect appConnect, Integer appId) {
|
||||
if (StrUtil.isBlank(user.getUserId())) {
|
||||
if (userMapper.selectCount(new LambdaQueryWrapper<User>().eq(User::getUserMobile, user.getUserMobile())) > 0) {
|
||||
// 该电话号码已存在
|
||||
throw new YamiShopBindException("该电话号码已存在");
|
||||
}
|
||||
String userId = IdUtil.simpleUUID();
|
||||
user.setUserId(userId);
|
||||
userMapper.insert(user);
|
||||
} else {
|
||||
if (appConnect != null&& StrUtil.isBlank(user.getPic())) {
|
||||
User userParam = new User();
|
||||
userParam.setUserId(user.getUserId());
|
||||
userParam.setModifyTime(new Date());
|
||||
userParam.setPic(appConnect.getImageUrl());
|
||||
userService.updateById(userParam);
|
||||
}
|
||||
}
|
||||
if (appConnect == null) {
|
||||
// 避免重复插入数据
|
||||
if (appConnectMapper.getByBizUserId(user.getUserId(), appId) != null) {
|
||||
return user;
|
||||
}
|
||||
appConnect = new AppConnect();
|
||||
appConnect.setUserId(user.getUserId());
|
||||
appConnect.setNickName(user.getNickName());
|
||||
appConnect.setImageUrl(user.getPic());
|
||||
|
||||
// 0表示是系统的用户,不是第三方的
|
||||
appConnect.setAppId(appId);
|
||||
appConnectMapper.insert(appConnect);
|
||||
} else if (StrUtil.isBlank(appConnect.getUserId()) || Objects.isNull(appId)) {
|
||||
appConnect.setAppId(appId);
|
||||
appConnect.setUserId(user.getUserId());
|
||||
appConnect.setUserId(user.getUserId());
|
||||
appConnectMapper.updateById(appConnect);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user