TASK:免密登录并发优化;
This commit is contained in:
@@ -569,40 +569,76 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean addNoLoginRequired(NoLoginRequiredDTO noLoginRequiredDTO) {
|
public Boolean addNoLoginRequired(NoLoginRequiredDTO noLoginRequiredDTO) {
|
||||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
// 构建查询条件,查找已注册的账户数量
|
||||||
qw.lambda().isNotNull(Account::getBrowserIdentifiers);
|
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||||
qw.lambda().like(Account::getUserName, "PolyU-SFT-");
|
queryWrapper.lambda().isNotNull(Account::getBrowserIdentifiers);
|
||||||
List<Account> accountList = accountMapper.selectList(qw);
|
queryWrapper.lambda().like(Account::getUserName, "PolyU-SFT-");
|
||||||
if (accountList.size() >= 100) {
|
List<Account> existingAccounts = accountMapper.selectList(queryWrapper);
|
||||||
|
|
||||||
|
// 检查注册账户数量是否超过限制
|
||||||
|
if (existingAccounts.size() >= 100) {
|
||||||
throw new BusinessException("The number of registered accounts exceeds the limit");
|
throw new BusinessException("The number of registered accounts exceeds the limit");
|
||||||
}
|
}
|
||||||
qw.lambda().eq(Account::getBrowserIdentifiers, noLoginRequiredDTO.getBrowserIdentifiers());
|
|
||||||
if (!accountMapper.selectList(qw).isEmpty()) {
|
// 检查浏览器标识是否已经被注册
|
||||||
|
queryWrapper.clear();
|
||||||
|
queryWrapper.lambda().eq(Account::getBrowserIdentifiers, noLoginRequiredDTO.getBrowserIdentifiers());
|
||||||
|
if (!accountMapper.selectList(queryWrapper).isEmpty()) {
|
||||||
throw new BusinessException("This browser has already been registered");
|
throw new BusinessException("This browser has already been registered");
|
||||||
}
|
}
|
||||||
Account account = new Account();
|
|
||||||
account.setUserName("PolyU-SFT-" + String.format("%03d", accountList.size() + 1));
|
// 创建新账户
|
||||||
account.setUserPassword("Third-000000");
|
Account newAccount = new Account();
|
||||||
account.setValidStartTime(System.currentTimeMillis());
|
newAccount.setUserName("PolyU-SFT-" + String.format("%03d", existingAccounts.size() + 1));
|
||||||
account.setValidEndTime(System.currentTimeMillis() + 365L * 24 * 60 * 60 * 1000);
|
newAccount.setUserPassword("Third-000000");
|
||||||
account.setCreateDate(new Date());
|
newAccount.setValidStartTime(System.currentTimeMillis());
|
||||||
account.setIsBeginner(1);
|
newAccount.setValidEndTime(System.currentTimeMillis() + 365L * 24 * 60 * 60 * 1000);
|
||||||
account.setIsTrial(0);
|
newAccount.setCreateDate(new Date());
|
||||||
account.setBrowserIdentifiers(noLoginRequiredDTO.getBrowserIdentifiers());
|
newAccount.setIsBeginner(1);
|
||||||
account.setLanguage(Language.ENGLISH.name());
|
newAccount.setIsTrial(0);
|
||||||
accountMapper.insert(account);
|
newAccount.setBrowserIdentifiers(noLoginRequiredDTO.getBrowserIdentifiers());
|
||||||
|
newAccount.setLanguage(Language.ENGLISH.name());
|
||||||
|
|
||||||
|
// 插入新账户
|
||||||
|
accountMapper.insert(newAccount);
|
||||||
|
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean deleteNoLoginRequired(NoLoginRequiredDTO noLoginRequiredDTO) {
|
public Boolean deleteNoLoginRequired(NoLoginRequiredDTO noLoginRequiredDTO) {
|
||||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
// 删除将被注销的用户
|
||||||
qw.lambda().eq(Account::getBrowserIdentifiers, noLoginRequiredDTO.getBrowserIdentifiers());
|
QueryWrapper<Account> queryWrapperDelete = new QueryWrapper<>();
|
||||||
accountMapper.delete(qw);
|
queryWrapperDelete.lambda().eq(Account::getBrowserIdentifiers, noLoginRequiredDTO.getBrowserIdentifiers());
|
||||||
|
List<Account> accountList = accountMapper.selectList(queryWrapperDelete);
|
||||||
|
if (CollectionUtil.isNotEmpty(accountList)) {
|
||||||
|
Account accountDelete = accountList.get(0);
|
||||||
|
String userName = accountDelete.getUserName();
|
||||||
|
// 查询当前浏览器标识下的所有用户,并按照用户名编号降序排序
|
||||||
|
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.lambda().isNotNull(Account::getBrowserIdentifiers);
|
||||||
|
queryWrapper.lambda().orderByDesc(Account::getUserName);
|
||||||
|
List<Account> accounts = accountMapper.selectList(queryWrapper);
|
||||||
|
|
||||||
|
// 如果存在用户,将将被注销的用户的浏览器标识更新为用户名编号最大的用户的浏览器标识
|
||||||
|
if (!accounts.isEmpty()) {
|
||||||
|
Account userToBeUpdate = accounts.get(0);
|
||||||
|
if (!userName.equals(userToBeUpdate.getUserName())) {
|
||||||
|
accountMapper.deleteById(accountDelete);
|
||||||
|
userToBeUpdate.setUserName(userName);
|
||||||
|
accountMapper.updateById(userToBeUpdate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AccountLoginVO noLoginRequired(NoLoginRequiredDTO noLoginRequiredDTO) {
|
public AccountLoginVO noLoginRequired(NoLoginRequiredDTO noLoginRequiredDTO) {
|
||||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
QueryWrapper<Account> qw = new QueryWrapper<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user