优化-自动将Code-Create注册的新用户添加到AiDA
This commit is contained in:
@@ -1392,7 +1392,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
|
||||
private static final String QUERY_MAXIMUM_USERID = "SELECT MAX(ID) AS max_id FROM pmr_users;";
|
||||
|
||||
private static final String QUERY_NEW_USER_EMAIL = "SELECT user_email FROM pmr_users " +
|
||||
private static final String QUERY_NEW_USER_EMAIL = "SELECT user_email, user_nicename FROM pmr_users " +
|
||||
"WHERE ID > ? ";
|
||||
|
||||
@Value("${redis.key.maximumUserId}")
|
||||
@@ -1404,7 +1404,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void registerUserToVisitor(){
|
||||
ArrayList<String> newUserEmails = new ArrayList<>();
|
||||
ArrayList<Map<String, String>> newUsersInfo = new ArrayList<>();
|
||||
ArrayList<String> allEmail = new ArrayList<>();
|
||||
long maxUserId = CommonConstant.MAXIMUM_USER_ID;
|
||||
try (Connection connection = dataSource.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(QUERY_MAXIMUM_USERID)) {
|
||||
@@ -1420,9 +1421,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
// 填充参数 - 历史最大用户ID
|
||||
newUserEmail.setLong(1, maxUserIdHistory);
|
||||
try (ResultSet queryEmailResultSet = newUserEmail.executeQuery()) {
|
||||
if (queryEmailResultSet.next()) {
|
||||
while (queryEmailResultSet.next()) {
|
||||
String email = queryEmailResultSet.getString("user_email");
|
||||
newUserEmails.add(email);
|
||||
String username = queryEmailResultSet.getString("user_nicename");
|
||||
HashMap<String, String> info = new HashMap<>();
|
||||
info.put("email", email);
|
||||
info.put("username", username);
|
||||
newUsersInfo.add(info);
|
||||
allEmail.add(email);
|
||||
} /*else {
|
||||
log.error("未知错误。code-create的用户表中没有付费用户的信息");
|
||||
throw new BusinessException("user info missing");
|
||||
@@ -1437,22 +1443,32 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
// return null;
|
||||
}
|
||||
|
||||
if (!newUserEmails.isEmpty()){
|
||||
if (!newUsersInfo.isEmpty()){
|
||||
// 查询这些邮箱在aida上是否有账号
|
||||
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("user_email", newUserEmails).select("user_email");
|
||||
queryWrapper.in("user_email", allEmail).select("user_email");
|
||||
|
||||
// 重复的邮箱
|
||||
List<String> collect = baseMapper.selectList(queryWrapper).stream().map(Account::getUserEmail).collect(Collectors.toList());
|
||||
if (!collect.isEmpty()){
|
||||
// 移除Code-Create新增用户中在AiDA已有账号的邮箱
|
||||
newUserEmails.removeAll(collect);
|
||||
// 移除Code-Create新增用户中在AiDA已有账号的邮箱,allEmail中剩余邮箱均为新用户邮箱
|
||||
allEmail.removeAll(collect);
|
||||
if (!allEmail.isEmpty()){
|
||||
for (Map<String,String> userInfo : newUsersInfo){
|
||||
String email = userInfo.get("email");
|
||||
if (!allEmail.contains(email)) {
|
||||
newUsersInfo.remove(userInfo); // 移除不在 allEmail 中的用户
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 将新增用户添加到AiDA,身份为游客
|
||||
if (!newUserEmails.isEmpty()){
|
||||
newUserEmails.forEach(email -> {
|
||||
if (!newUsersInfo.isEmpty()){
|
||||
newUsersInfo.forEach(userInfo -> {
|
||||
Account account = new Account();
|
||||
account.setUserEmail(email);
|
||||
account.setUserName(email);
|
||||
account.setUserEmail(userInfo.get("email"));
|
||||
account.setUserName(userInfo.get("username"));
|
||||
account.setUserPassword("Third-000000");
|
||||
account.setLanguage(Language.ENGLISH.name());
|
||||
account.setValidStartTime(Instant.now().toEpochMilli());
|
||||
@@ -1463,7 +1479,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
|
||||
account.setSystemUser(0);
|
||||
baseMapper.insert(account);
|
||||
// 邮件通知用户
|
||||
SendEmailUtil.notificationForRegisterUser(email);
|
||||
SendEmailUtil.notificationForRegisterUser(userInfo.get("email"));
|
||||
});
|
||||
}
|
||||
// 记录当前最大的用户id
|
||||
|
||||
Reference in New Issue
Block a user