UserService.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. package com.izouma.nineth.service;
  2. import cn.binarywang.wx.miniapp.api.WxMaService;
  3. import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
  4. import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
  5. import com.huifu.adapay.core.exception.BaseAdaPayException;
  6. import com.izouma.nineth.config.Constants;
  7. import com.izouma.nineth.domain.Follow;
  8. import com.izouma.nineth.domain.IdentityAuth;
  9. import com.izouma.nineth.domain.Invite;
  10. import com.izouma.nineth.domain.User;
  11. import com.izouma.nineth.dto.*;
  12. import com.izouma.nineth.enums.AuthStatus;
  13. import com.izouma.nineth.enums.AuthorityName;
  14. import com.izouma.nineth.event.AccountCreatedEvent;
  15. import com.izouma.nineth.exception.BusinessException;
  16. import com.izouma.nineth.repo.*;
  17. import com.izouma.nineth.security.Authority;
  18. import com.izouma.nineth.security.JwtTokenUtil;
  19. import com.izouma.nineth.security.JwtUserFactory;
  20. import com.izouma.nineth.service.sms.SmsService;
  21. import com.izouma.nineth.service.storage.StorageService;
  22. import com.izouma.nineth.utils.BankUtils;
  23. import com.izouma.nineth.utils.JpaUtils;
  24. import com.izouma.nineth.utils.ObjUtils;
  25. import com.izouma.nineth.utils.SecurityUtils;
  26. import lombok.AllArgsConstructor;
  27. import lombok.extern.slf4j.Slf4j;
  28. import me.chanjar.weixin.common.error.WxErrorException;
  29. import me.chanjar.weixin.mp.api.WxMpService;
  30. import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
  31. import me.chanjar.weixin.mp.bean.result.WxMpUser;
  32. import org.apache.commons.lang3.RandomStringUtils;
  33. import org.apache.commons.lang3.StringUtils;
  34. import org.springframework.beans.BeanUtils;
  35. import org.springframework.cache.annotation.CacheEvict;
  36. import org.springframework.context.ApplicationContext;
  37. import org.springframework.context.event.EventListener;
  38. import org.springframework.data.domain.Page;
  39. import org.springframework.data.domain.PageImpl;
  40. import org.springframework.data.jpa.domain.Specification;
  41. import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
  42. import org.springframework.stereotype.Service;
  43. import javax.persistence.criteria.Predicate;
  44. import java.text.SimpleDateFormat;
  45. import java.util.*;
  46. import java.util.regex.Pattern;
  47. import java.util.stream.Collectors;
  48. @Service
  49. @Slf4j
  50. @AllArgsConstructor
  51. public class UserService {
  52. private UserRepo userRepo;
  53. private WxMaService wxMaService;
  54. private WxMpService wxMpService;
  55. private SmsService smsService;
  56. private StorageService storageService;
  57. private JwtTokenUtil jwtTokenUtil;
  58. private CaptchaService captchaService;
  59. private FollowService followService;
  60. private FollowRepo followRepo;
  61. private IdentityAuthRepo identityAuthRepo;
  62. private SysConfigService sysConfigService;
  63. private CollectionService collectionService;
  64. private AdapayService adapayService;
  65. private UserBankCardRepo userBankCardRepo;
  66. private InviteRepo inviteRepo;
  67. private NFTService nftService;
  68. private CacheService cacheService;
  69. private ApplicationContext context;
  70. public User update(User user) {
  71. User orig = userRepo.findById(user.getId()).orElseThrow(new BusinessException("无记录"));
  72. ObjUtils.merge(orig, user);
  73. orig = save(orig);
  74. userRepo.updateAssetMinter(orig.getId());
  75. userRepo.updateAssetOwner(orig.getId());
  76. userRepo.updateCollectionMinter(orig.getId());
  77. userRepo.updateCollectionOwner(orig.getId());
  78. userRepo.updateOrderMinter(orig.getId());
  79. userRepo.updateHistoryFromUser(orig.getId());
  80. userRepo.updateHistoryToUser(orig.getId());
  81. cacheService.clearCollection();
  82. return orig;
  83. }
  84. public User save(User user) {
  85. cacheService.clearUserInfo(user.getId());
  86. cacheService.clearUser(user.getUsername());
  87. return userRepo.save(user);
  88. }
  89. public Page<User> all(PageQuery pageQuery) {
  90. Specification<User> specification = JpaUtils.toSpecification(pageQuery, User.class);
  91. specification = specification.and((Specification<User>) (root, criteriaQuery, criteriaBuilder) -> {
  92. List<Predicate> and = new ArrayList<>();
  93. and.add(criteriaBuilder.equal(root.get("del"), false));
  94. if (!pageQuery.getQuery().containsKey("admin")) {
  95. and.add(criteriaBuilder.equal(root.get("admin"), false));
  96. }
  97. if (pageQuery.getQuery().containsKey("hasRole")) {
  98. String roleName = (String) pageQuery.getQuery().get("hasRole");
  99. and.add(criteriaBuilder.isMember(Authority.get(AuthorityName.valueOf(roleName)), root.get("authorities")));
  100. }
  101. return criteriaBuilder.and(and.toArray(new Predicate[0]));
  102. });
  103. return userRepo.findAll(specification, JpaUtils.toPageRequest(pageQuery));
  104. }
  105. public User create(UserRegister userRegister) {
  106. if (StringUtils.isNoneEmpty(userRegister.getPhone()) && userRepo.findByPhoneAndDelFalse(userRegister.getPhone())
  107. .orElse(null) != null) {
  108. throw new BusinessException("该手机号已注册");
  109. }
  110. User user = new User();
  111. BeanUtils.copyProperties(userRegister, user);
  112. user.setShareRatio(sysConfigService.getBigDecimal("share_ratio"));
  113. user.setAuthStatus(AuthStatus.NOT_AUTH);
  114. if (StringUtils.isNotBlank(userRegister.getPassword())) {
  115. user.setPassword(new BCryptPasswordEncoder().encode(userRegister.getPassword()));
  116. }
  117. user = userRepo.saveAndFlush(user);
  118. nftService.createAccount(user.getId());
  119. return user;
  120. }
  121. @EventListener
  122. public void accountCreated(AccountCreatedEvent event) {
  123. }
  124. public User phoneRegister(String phone, String code, String password, String inviteCode) {
  125. String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
  126. Invite invite = null;
  127. if (StringUtils.isNotBlank(inviteCode)) {
  128. invite = inviteRepo.findFirstByCode(inviteCode).orElse(null);
  129. }
  130. smsService.verify(phone, code);
  131. User user = create(UserRegister.builder()
  132. .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
  133. .username(name)
  134. .nickname(name)
  135. .password(password)
  136. .avatar(Constants.DEFAULT_AVATAR)
  137. .phone(phone)
  138. .invitorPhone(Optional.ofNullable(invite).map(Invite::getPhone).orElse(null))
  139. .invitorName(Optional.ofNullable(invite).map(Invite::getName).orElse(null))
  140. .inviteCode(Optional.ofNullable(invite).map(Invite::getCode).orElse(null))
  141. .build());
  142. if (invite != null) {
  143. inviteRepo.increaseNum(invite.getId());
  144. }
  145. return user;
  146. }
  147. public void del(Long id) {
  148. User user = userRepo.findById(id).orElseThrow(new BusinessException("用户不存在"));
  149. user.setDel(true);
  150. if (StringUtils.isNoneEmpty(user.getOpenId())) {
  151. user.setOpenId(user.getOpenId() + "###" + RandomStringUtils.randomAlphabetic(8));
  152. }
  153. if (StringUtils.isNoneEmpty(user.getPhone())) {
  154. user.setPhone(user.getPhone() + "###" + RandomStringUtils.randomAlphabetic(8));
  155. }
  156. userRepo.save(user);
  157. //删除实名认证
  158. identityAuthRepo.softDeleteByUserId(id);
  159. }
  160. public User loginByPhone(String phone, String code) {
  161. User user = userRepo.findByPhoneAndDelFalse(phone).orElseThrow(new BusinessException("该手机未注册"));
  162. smsService.verify(phone, code);
  163. if (user == null) {
  164. String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
  165. user = create(UserRegister.builder()
  166. .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
  167. .username(name)
  168. .nickname(name)
  169. .avatar(Constants.DEFAULT_AVATAR)
  170. .phone(phone)
  171. .build());
  172. }
  173. return user;
  174. }
  175. public User loginByPhonePwd(String phone, String password) {
  176. if (StringUtils.isEmpty(phone)) {
  177. throw new BusinessException("手机号错误");
  178. }
  179. User user = userRepo.findByPhoneAndDelFalse(phone).orElseThrow(new BusinessException("账号或密码错误"));
  180. if (StringUtils.isEmpty(user.getPassword())) {
  181. throw new BusinessException("账号或密码错误");
  182. }
  183. if (StringUtils.isNoneEmpty(user.getPassword()) &&
  184. !new BCryptPasswordEncoder().matches(password, user.getPassword())) {
  185. throw new BusinessException("账号或密码错误");
  186. }
  187. return user;
  188. }
  189. public User loginMp(String code) throws WxErrorException {
  190. WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code);
  191. WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(accessToken, null);
  192. User user = userRepo.findByOpenIdAndDelFalse(wxMpUser.getOpenId()).orElse(null);
  193. if (user == null) {
  194. String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
  195. user = User.builder()
  196. .username(name)
  197. .nickname(name)
  198. .avatar(wxMpUser.getHeadImgUrl())
  199. .sex(wxMpUser.getSexDesc())
  200. .country(wxMpUser.getCountry())
  201. .province(wxMpUser.getProvince())
  202. .city(wxMpUser.getCity())
  203. .openId(wxMpUser.getOpenId())
  204. .language(wxMpUser.getLanguage())
  205. .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
  206. .authStatus(AuthStatus.NOT_AUTH)
  207. .build();
  208. userRepo.save(user);
  209. }
  210. return user;
  211. }
  212. public String code2openId(String code) throws WxErrorException {
  213. WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code);
  214. return wxMpService.oauth2getUserInfo(accessToken, null).getOpenId();
  215. }
  216. public User loginMa(String code) {
  217. try {
  218. WxMaJscode2SessionResult result = wxMaService.jsCode2SessionInfo(code);
  219. String openId = result.getOpenid();
  220. String sessionKey = result.getSessionKey();
  221. User userInfo = userRepo.findByOpenIdAndDelFalse(openId).orElse(null);
  222. ;
  223. if (userInfo != null) {
  224. return userInfo;
  225. }
  226. String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
  227. userInfo = User.builder()
  228. .username(name)
  229. .nickname(name)
  230. .openId(openId)
  231. .avatar(Constants.DEFAULT_AVATAR)
  232. .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
  233. .authStatus(AuthStatus.NOT_AUTH)
  234. .build();
  235. userInfo = userRepo.save(userInfo);
  236. return userInfo;
  237. } catch (WxErrorException e) {
  238. e.printStackTrace();
  239. }
  240. throw new BusinessException("登录失败");
  241. }
  242. public User getMaUserInfo(String sessionKey, String rawData, String signature,
  243. String encryptedData, String iv) {
  244. // 用户信息校验
  245. if (!wxMaService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
  246. throw new BusinessException("获取用户信息失败");
  247. }
  248. // 解密用户信息
  249. WxMaUserInfo wxUserInfo = wxMaService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
  250. User user = userRepo.findByOpenIdAndDelFalse(wxUserInfo.getOpenId()).orElse(null);
  251. String avatarUrl = Constants.DEFAULT_AVATAR;
  252. try {
  253. String path = "image/avatar/" +
  254. new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) +
  255. RandomStringUtils.randomAlphabetic(8) +
  256. ".jpg";
  257. avatarUrl = storageService.uploadFromUrl(wxUserInfo.getAvatarUrl(), path);
  258. } catch (Exception e) {
  259. log.error("获取头像失败", e);
  260. }
  261. if (user == null) {
  262. user = User.builder()
  263. .username(UUID.randomUUID().toString())
  264. .nickname(wxUserInfo.getNickName())
  265. .openId(wxUserInfo.getOpenId())
  266. .avatar(avatarUrl)
  267. .sex(wxUserInfo.getGender())
  268. .country(wxUserInfo.getCountry())
  269. .province(wxUserInfo.getProvince())
  270. .city(wxUserInfo.getCity())
  271. .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
  272. .build();
  273. user = userRepo.save(user);
  274. } else {
  275. user.setAvatar(avatarUrl);
  276. user.setNickname(wxUserInfo.getNickName());
  277. user.setSex(wxUserInfo.getGender());
  278. user.setCountry(wxUserInfo.getCountry());
  279. user.setProvince(wxUserInfo.getProvince());
  280. user.setCity(wxUserInfo.getCity());
  281. user = userRepo.save(user);
  282. }
  283. return user;
  284. }
  285. public String setPassword(Long userId, String password) {
  286. User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
  287. user.setPassword(new BCryptPasswordEncoder().encode(password));
  288. user = userRepo.save(user);
  289. return jwtTokenUtil.generateToken(JwtUserFactory.create(user));
  290. }
  291. public String setPassword(Long userId, String code, String password) {
  292. User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
  293. smsService.verify(user.getPhone(), code);
  294. return setPassword(userId, password);
  295. }
  296. public String forgotPassword(String phone, String password, String code) {
  297. User user = userRepo.findByPhoneAndDelFalse(phone).orElseThrow(new BusinessException("手机号未注册"));
  298. smsService.verify(user.getPhone(), code);
  299. return setPassword(user.getId(), password);
  300. }
  301. public void bindPhone(Long userId, String phone) {
  302. User user = userRepo.findByIdAndDelFalse(userId).orElseThrow(new BusinessException("用户不存在"));
  303. if (StringUtils.isNoneEmpty(user.getPhone())) {
  304. throw new BusinessException("该账号已绑定手机");
  305. }
  306. userRepo.findByPhoneAndDelFalse(phone).ifPresent(user1 -> {
  307. if (!user1.getId().equals(userId)) {
  308. throw new BusinessException("该手机号已绑定其他账号");
  309. }
  310. });
  311. user.setPhone(phone);
  312. userRepo.save(user);
  313. }
  314. public UserDTO toDTO(User user) {
  315. return toDTO(user, true);
  316. }
  317. public UserDTO toDTO(User user, boolean join) {
  318. UserDTO userDTO = new UserDTO();
  319. BeanUtils.copyProperties(user, userDTO);
  320. if (user.getAuthorities() != null) {
  321. userDTO.setAuthorities(new HashSet<>(user.getAuthorities()));
  322. }
  323. if (join) {
  324. if (SecurityUtils.getAuthenticatedUser() != null) {
  325. userDTO.setFollow(followService.isFollow(SecurityUtils.getAuthenticatedUser().getId(), user.getId()));
  326. }
  327. }
  328. return userDTO;
  329. }
  330. public List<UserDTO> toDTO(List<User> users) {
  331. List<Follow> follows = new ArrayList<>();
  332. if (SecurityUtils.getAuthenticatedUser() != null) {
  333. follows.addAll(followRepo.findByUserId(SecurityUtils.getAuthenticatedUser().getId()));
  334. }
  335. return users.stream().parallel().map(user -> {
  336. UserDTO dto = toDTO(user, false);
  337. if (!follows.isEmpty()) {
  338. dto.setFollow(follows.stream().anyMatch(f -> f.getFollowUserId().equals(user.getId())));
  339. }
  340. return dto;
  341. }).collect(Collectors.toList());
  342. }
  343. public Page<UserDTO> toDTO(Page<User> users) {
  344. List<UserDTO> userDTOS = toDTO(users.getContent());
  345. return new PageImpl<>(userDTOS, users.getPageable(), users.getTotalElements());
  346. }
  347. @CacheEvict(value = "user", allEntries = true)
  348. public void setTradeCode(Long userId, String token, String tradeCode) {
  349. String phone = smsService.verifyToken(token);
  350. User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
  351. if (!StringUtils.equals(phone, user.getPhone())) {
  352. throw new BusinessException("验证码无效");
  353. }
  354. user.setTradeCode(new BCryptPasswordEncoder().encode(tradeCode));
  355. userRepo.save(user);
  356. }
  357. public void verifyTradeCode(Long userId, String tradeCode) {
  358. User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
  359. if (!new BCryptPasswordEncoder().matches(tradeCode, user.getTradeCode())) {
  360. throw new BusinessException("校验失败");
  361. }
  362. }
  363. public Map<String, Object> searchByPhone(String phone) {
  364. if (AuthStatus.SUCCESS != SecurityUtils.getAuthenticatedUser().getAuthStatus()) {
  365. throw new BusinessException("实名认证后才能赠送");
  366. }
  367. User user = userRepo.findByPhoneAndDelFalse(phone).orElseThrow(new BusinessException("用户不存在或未认证"));
  368. if (AuthStatus.SUCCESS != user.getAuthStatus()) {
  369. throw new BusinessException("用户不存在或未认证");
  370. }
  371. String realName = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(
  372. user.getId(), AuthStatus.SUCCESS)
  373. .map(IdentityAuth::getRealName).orElse("").replaceAll(".*(?=.)", "**");
  374. Map<String, Object> map = new HashMap<>();
  375. map.put("id", user.getId());
  376. map.put("avatar", user.getAvatar());
  377. map.put("phone", user.getPhone().replaceAll("(?<=.{3}).*(?=.{4})", "**"));
  378. map.put("realName", realName);
  379. return map;
  380. }
  381. public Map<String, Object> searchByPhoneAdmin(String phoneStr) {
  382. List<String> phone = Arrays.stream(phoneStr.replaceAll("\n", " ")
  383. .replaceAll("\r\n", " ")
  384. .split(" "))
  385. .map(String::trim)
  386. .filter(s -> !StringUtils.isEmpty(s))
  387. .collect(Collectors.toList());
  388. List<User> users = userRepo.findByPhoneInAndDelFalse(phone);
  389. Map<String, Object> map = new HashMap<>();
  390. map.put("users", users);
  391. List<String> notFound = phone.stream().filter(p -> users.stream().noneMatch(u -> p.equals(u.getPhone())))
  392. .collect(Collectors.toList());
  393. map.put("notFound", notFound);
  394. return map;
  395. }
  396. public void addBankCard(Long userId, String bankNo, String phone, String code) throws BaseAdaPayException {
  397. User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
  398. IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(userId, AuthStatus.SUCCESS)
  399. .orElseThrow(new BusinessException("用户未认证"));
  400. if (identityAuth.isOrg()) {
  401. //throw new BusinessException("企业认证用户请绑定对公账户");
  402. }
  403. if (!StringUtils.isBlank(user.getSettleAccountId())) {
  404. throw new BusinessException("此账号已绑定");
  405. }
  406. BankValidate bankValidate = BankUtils.validate(bankNo);
  407. if (!bankValidate.isValidated()) {
  408. throw new BusinessException("暂不支持此卡");
  409. }
  410. if (StringUtils.isEmpty(user.getMemberId())) {
  411. user.setMemberId(adapayService.createMember(userId, user.getPhone(), identityAuth.getRealName(),
  412. identityAuth.getIdNo()));
  413. userRepo.saveAndFlush(user);
  414. }
  415. smsService.verify(phone, code);
  416. String accountId = adapayService.createSettleAccount(user.getMemberId(), identityAuth.getRealName(),
  417. identityAuth.getIdNo(), phone, bankNo);
  418. user.setSettleAccountId(accountId);
  419. userRepo.save(user);
  420. userBankCardRepo.save(UserBankCard.builder()
  421. .bank(bankValidate.getBank())
  422. .bankName(bankValidate.getBankName())
  423. .bankNo(bankNo)
  424. .cardType(bankValidate.getCardType())
  425. .cardTypeDesc(bankValidate.getCardTypeDesc())
  426. .userId(userId)
  427. .build());
  428. }
  429. public void removeBankCard(Long userId) throws BaseAdaPayException {
  430. User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
  431. if (StringUtils.isNotBlank(user.getSettleAccountId()) && StringUtils.isNotBlank(user.getMemberId())) {
  432. adapayService.delSettleAccount(user.getMemberId(), user.getSettleAccountId());
  433. user.setSettleAccountId(null);
  434. userRepo.save(user);
  435. userBankCardRepo.deleteByUserId(userId);
  436. } else {
  437. throw new BusinessException("未绑定");
  438. }
  439. }
  440. public void removeAuth(Long userId) {
  441. User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
  442. if (user.getAuthStatus() == AuthStatus.SUCCESS) {
  443. user.setAuthStatus(AuthStatus.NOT_AUTH);
  444. userRepo.save(user);
  445. identityAuthRepo.deleteAll(identityAuthRepo.findByUserIdAndDelFalse(userId));
  446. }
  447. }
  448. public Map<String, Object> batchRegister(String phones, String defaultPassword) {
  449. List<String> exist = new ArrayList<>();
  450. List<String> err = new ArrayList<>();
  451. List<String> success = new ArrayList<>();
  452. Arrays.stream(phones.replaceAll(",", " ")
  453. .replaceAll(",", " ")
  454. .replaceAll("\n", " ")
  455. .replaceAll("\r\n", " ")
  456. .split(" ")).forEach(phone -> {
  457. if (userRepo.findByPhoneAndDelFalse(phone).isPresent()) {
  458. exist.add(phone);
  459. } else {
  460. if (!Pattern.matches("^1[3-9]\\d{9}$", phone)) {
  461. err.add(phone);
  462. } else {
  463. try {
  464. String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
  465. User user = create(UserRegister.builder()
  466. .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
  467. .username(name)
  468. .nickname(name)
  469. .password(defaultPassword)
  470. .avatar(Constants.DEFAULT_AVATAR)
  471. .phone(phone)
  472. .build());
  473. success.add(phone);
  474. } catch (Exception e) {
  475. log.error("注册失败", e);
  476. err.add(phone);
  477. }
  478. }
  479. }
  480. });
  481. Map<String, Object> map = new HashMap<>();
  482. map.put("exist", exist);
  483. map.put("error", err);
  484. map.put("success", success);
  485. return map;
  486. }
  487. }