mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-17 23:46:12 +08:00
添加账号注销功能
This commit is contained in:
@@ -22,7 +22,6 @@ import plus.bookshelf.Service.Service.ThirdPartyUserService;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@Service
|
||||
public class ThirdPartyUserServiceImpl implements ThirdPartyUserService {
|
||||
|
@@ -10,10 +10,14 @@ import plus.bookshelf.Common.SessionManager.RedisSessionManager;
|
||||
import plus.bookshelf.Controller.VO.UserVO;
|
||||
import plus.bookshelf.Dao.DO.ThirdPartyUserDO;
|
||||
import plus.bookshelf.Dao.DO.UserDO;
|
||||
import plus.bookshelf.Dao.Mapper.ThirdPartyUserAuthDOMapper;
|
||||
import plus.bookshelf.Dao.Mapper.ThirdPartyUserDOMapper;
|
||||
import plus.bookshelf.Dao.Mapper.UserDOMapper;
|
||||
import plus.bookshelf.Service.Model.UserModel;
|
||||
import plus.bookshelf.Service.Service.UserService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@@ -22,6 +26,12 @@ public class UserServiceImpl implements UserService {
|
||||
@Autowired
|
||||
UserDOMapper userDOMapper;
|
||||
|
||||
@Autowired
|
||||
ThirdPartyUserDOMapper thirdPartyUserDOMapper;
|
||||
|
||||
@Autowired
|
||||
ThirdPartyUserAuthDOMapper thirdPartyUserAuthDOMapper;
|
||||
|
||||
@Override
|
||||
public UserModel userLogin(String username, String encryptPwd) {
|
||||
UserDO userDO = userDOMapper.selectByUsernameAndEncryptpwd(username, encryptPwd);
|
||||
@@ -79,6 +89,44 @@ public class UserServiceImpl implements UserService {
|
||||
return userDOMapper.insertSelective(userDO) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean cancelAccount(UserModel userModel) throws BusinessException {
|
||||
|
||||
// 用户Id
|
||||
Integer userId = userModel.getId();
|
||||
|
||||
ThirdPartyUserDO[] userBindThirdParties = thirdPartyUserDOMapper.getUserBindThirdParties(userModel.getId());
|
||||
|
||||
List<Integer> thirdPartyIds = new ArrayList<>();
|
||||
for (ThirdPartyUserDO thirdPartyUserDO : userBindThirdParties) {
|
||||
Integer thirdPartyUserId = thirdPartyUserDO.getId();
|
||||
// 删除第三方账号与用户的关联
|
||||
// 首先在 Auth 表中删除
|
||||
int affectRows = thirdPartyUserAuthDOMapper.deleteByUserIdAndThirdPartyUserId(userId, thirdPartyUserId);
|
||||
if (affectRows == 0) {
|
||||
// 删除失败
|
||||
return false;
|
||||
}
|
||||
// 第三方账号与用户关联删除成功,删除第三方账号信息
|
||||
int affectRows2 = thirdPartyUserDOMapper.deleteByPrimaryKey(thirdPartyUserId);
|
||||
if (affectRows2 == 0) {
|
||||
// 删除失败
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 删除用户信息
|
||||
int affectRows3 = userDOMapper.deleteByPrimaryKey(userModel.getId());
|
||||
if (affectRows3 == 0) {
|
||||
// 删除失败
|
||||
return false;
|
||||
}
|
||||
|
||||
// 注销成功
|
||||
return true;
|
||||
}
|
||||
|
||||
private UserModel convertFromDataObject(UserDO userDO) {
|
||||
if (userDO == null) {
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user