|
@@ -44,6 +44,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -394,7 +395,7 @@ public class UserService {
|
|
|
|
|
|
|
|
public Map<String, Object> searchByPhoneAdmin(String phoneStr) {
|
|
public Map<String, Object> searchByPhoneAdmin(String phoneStr) {
|
|
|
List<String> phone = Arrays.stream(phoneStr.replaceAll("\n", " ")
|
|
List<String> phone = Arrays.stream(phoneStr.replaceAll("\n", " ")
|
|
|
- .replaceAll("\r\n", "")
|
|
|
|
|
|
|
+ .replaceAll("\r\n", " ")
|
|
|
.split(" "))
|
|
.split(" "))
|
|
|
.map(String::trim)
|
|
.map(String::trim)
|
|
|
.filter(s -> !StringUtils.isEmpty(s))
|
|
.filter(s -> !StringUtils.isEmpty(s))
|
|
@@ -454,4 +455,45 @@ public class UserService {
|
|
|
throw new BusinessException("未绑定");
|
|
throw new BusinessException("未绑定");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public Map<String, Object> batchRegister(String phones, String defaultPassword) {
|
|
|
|
|
+ List<String> exist = new ArrayList<>();
|
|
|
|
|
+ List<String> err = new ArrayList<>();
|
|
|
|
|
+ List<String> success = new ArrayList<>();
|
|
|
|
|
+ Arrays.stream(phones.replaceAll(",", " ")
|
|
|
|
|
+ .replaceAll(",", " ")
|
|
|
|
|
+ .replaceAll("\n", " ")
|
|
|
|
|
+ .replaceAll("\r\n", " ")
|
|
|
|
|
+ .split(" ")).forEach(phone -> {
|
|
|
|
|
+
|
|
|
|
|
+ if (userRepo.findByPhoneAndDelFalse(phone).isPresent()) {
|
|
|
|
|
+ exist.add(phone);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (!Pattern.matches("^1[3-9]\\d{9}]$", phone)) {
|
|
|
|
|
+ err.add(phone);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
|
|
|
|
|
+ User user = create(UserRegister.builder()
|
|
|
|
|
+ .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
|
|
|
|
|
+ .username(name)
|
|
|
|
|
+ .nickname(name)
|
|
|
|
|
+ .password(defaultPassword)
|
|
|
|
|
+ .avatar(Constants.DEFAULT_AVATAR)
|
|
|
|
|
+ .phone(phone)
|
|
|
|
|
+ .build());
|
|
|
|
|
+ success.add(phone);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("注册失败", e);
|
|
|
|
|
+ err.add(phone);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("exist", exist);
|
|
|
|
|
+ map.put("error", err);
|
|
|
|
|
+ map.put("success", success);
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|