TASK:机房免登录测试;
This commit is contained in:
@@ -32,6 +32,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -566,4 +567,59 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
return accountMapper.selectById(userInfo.getId()).getValidEndTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean addNoLoginRequired(NoLoginRequiredDTO noLoginRequiredDTO) {
|
||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
||||
qw.lambda().isNotNull(Account::getBrowserIdentifiers);
|
||||
qw.lambda().like(Account::getUserName, "PolyU-SFT-");
|
||||
List<Account> accountList = accountMapper.selectList(qw);
|
||||
if (accountList.size() >= 100) {
|
||||
throw new BusinessException("The number of registered accounts exceeds the limit");
|
||||
}
|
||||
qw.lambda().eq(Account::getBrowserIdentifiers, noLoginRequiredDTO.getBrowserIdentifiers());
|
||||
if (!accountMapper.selectList(qw).isEmpty()) {
|
||||
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.setValidStartTime(System.currentTimeMillis());
|
||||
account.setValidEndTime(System.currentTimeMillis() + 365L * 24 * 60 * 60 * 1000);
|
||||
account.setCreateDate(new Date());
|
||||
account.setIsBeginner(1);
|
||||
account.setIsTrial(0);
|
||||
account.setBrowserIdentifiers(noLoginRequiredDTO.getBrowserIdentifiers());
|
||||
accountMapper.insert(account);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteNoLoginRequired(NoLoginRequiredDTO noLoginRequiredDTO) {
|
||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(Account::getBrowserIdentifiers, noLoginRequiredDTO.getBrowserIdentifiers());
|
||||
accountMapper.delete(qw);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountLoginVO noLoginRequired(NoLoginRequiredDTO noLoginRequiredDTO) {
|
||||
QueryWrapper<Account> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(Account::getBrowserIdentifiers, noLoginRequiredDTO.getBrowserIdentifiers());
|
||||
List<Account> accountList = accountMapper.selectList(qw);
|
||||
if (CollectionUtil.isEmpty(accountList)) {
|
||||
throw new BusinessException("This browser is not registered as login free");
|
||||
}
|
||||
Account account = accountList.get(0);
|
||||
AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
|
||||
String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
//用户已登入
|
||||
response.setToken(token);
|
||||
} else {
|
||||
response.setToken(createAccountToken(account));
|
||||
}
|
||||
response.setUserId(account.getId());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user