|
|
@@ -1,35 +1,18 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
-import com.github.kevinsawicki.http.HttpRequest;
|
|
|
-import com.huifu.adapay.core.exception.BaseAdaPayException;
|
|
|
import com.izouma.nineth.ApplicationTests;
|
|
|
import com.izouma.nineth.config.Constants;
|
|
|
-import com.izouma.nineth.domain.IdentityAuth;
|
|
|
import com.izouma.nineth.domain.User;
|
|
|
-import com.izouma.nineth.dto.BankValidate;
|
|
|
-import com.izouma.nineth.dto.PageQuery;
|
|
|
-import com.izouma.nineth.dto.UserBankCard;
|
|
|
import com.izouma.nineth.dto.UserRegister;
|
|
|
-import com.izouma.nineth.enums.AuthStatus;
|
|
|
-import com.izouma.nineth.enums.AuthorityName;
|
|
|
-import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.IdentityAuthRepo;
|
|
|
import com.izouma.nineth.repo.UserBankCardRepo;
|
|
|
import com.izouma.nineth.repo.UserRepo;
|
|
|
-import com.izouma.nineth.security.Authority;
|
|
|
import com.izouma.nineth.service.storage.StorageService;
|
|
|
-import com.izouma.nineth.utils.BankUtils;
|
|
|
-import org.apache.commons.lang3.RandomStringUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.junit.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
public class UserServiceTest extends ApplicationTests {
|
|
|
|
|
|
@@ -58,143 +41,24 @@ public class UserServiceTest extends ApplicationTests {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void sss9() throws IOException {
|
|
|
- for (User user : userRepo.findAll()) {
|
|
|
- if (user.getAvatar().startsWith("https://cdn")) {
|
|
|
- HttpRequest request = HttpRequest.get(user.getAvatar());
|
|
|
- File file = File.createTempFile("gw1", "1sadga");
|
|
|
- request.receive(file);
|
|
|
- user.setAvatar(storageService.uploadFromInputStream(new FileInputStream(file), "image/" + RandomStringUtils.randomAlphabetic(12) + ".jpg"));
|
|
|
- userRepo.save(user);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void a() {
|
|
|
- for (String s : ("13816681152\n" +
|
|
|
- "15564456867\n" +
|
|
|
- "13363659367\n" +
|
|
|
- "18963550881\n" +
|
|
|
- "13931604318\n" +
|
|
|
- "13705395943\n" +
|
|
|
- "13162078752\n" +
|
|
|
- "13589360751\n")
|
|
|
- .split("\n")) {
|
|
|
- String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
|
|
|
+ public void register() throws IOException {
|
|
|
+ try {
|
|
|
User user = userService.create(UserRegister.builder()
|
|
|
- .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
|
|
|
- .username(name)
|
|
|
- .nickname(name)
|
|
|
- .password("123456")
|
|
|
+ .username("1111fff1g1rertuiohejldknhgurphoj")
|
|
|
+ .nickname("1111fff1g1rertuiohejldknhgurphoj")
|
|
|
.avatar(Constants.DEFAULT_AVATAR)
|
|
|
- .phone(s)
|
|
|
+ .phone("15077886171")
|
|
|
.build());
|
|
|
+ System.out.println(user.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (Pattern.matches(".*SQL.*constraint.*phone.*", e.getMessage())) {
|
|
|
+ System.out.println("手机号已注册");
|
|
|
+ }
|
|
|
+ if (Pattern.matches(".*SQL.*constraint.*username.*", e.getMessage())) {
|
|
|
+ System.out.println("用户名已存在");
|
|
|
+ }
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- public void batchRegister() {
|
|
|
- userService.batchRegister("13226246698\n" +
|
|
|
- "13793310531\n" +
|
|
|
- "13358006613\n" +
|
|
|
- "18898406893\n" +
|
|
|
- "17615876370\n" +
|
|
|
- "13267002685\n" +
|
|
|
- "15888548080\n" +
|
|
|
- "13678662069\n" +
|
|
|
- "15659009359\n" +
|
|
|
- "13011776866\n" +
|
|
|
- "18810668532\n" +
|
|
|
- "13543322894\n" +
|
|
|
- "13589360750\n" +
|
|
|
- "18582589484\n" +
|
|
|
- "15194185209\n" +
|
|
|
- "15063692500\n" +
|
|
|
- "13605489618\n" +
|
|
|
- "18069783568\n" +
|
|
|
- "15801815684\n" +
|
|
|
- "13285413859\n" +
|
|
|
- "13688419164\n" +
|
|
|
- "15979115671\n" +
|
|
|
- "13799940755\n" +
|
|
|
- "18301015323", "123456");
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void test() {
|
|
|
- PageQuery pageQuery = new PageQuery();
|
|
|
- Map<String, Object> query = pageQuery.getQuery();
|
|
|
- query.put("inviteCode", "JL21FF");
|
|
|
- pageQuery.setSize(5000);
|
|
|
- List<User> phone = userService.all(pageQuery)
|
|
|
- .getContent();
|
|
|
- phone.forEach(user -> System.out.println(user.getPhone() + ":" + user.getCreatedAt()));
|
|
|
- // 2022-01-14T15:53:58 504 第一次查询
|
|
|
- phone.forEach(user -> System.out.print(user.getPhone() + " "));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void switchAccount() {
|
|
|
- userService.checkSettleAccount();
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void phoneRegister() {
|
|
|
- userService.phoneRegister("18100004444", "1234", "123456", null, 9972L, 206925L);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void addBankCard() throws BaseAdaPayException {
|
|
|
- Long userId = 134613L;
|
|
|
- String bankNo = "6222024301070380165";
|
|
|
- String phone = "15077886171";
|
|
|
- User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
- IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(userId, AuthStatus.SUCCESS)
|
|
|
- .orElseThrow(new BusinessException("用户未认证"));
|
|
|
- if (identityAuth.isOrg()) {
|
|
|
- //throw new BusinessException("企业认证用户请绑定对公账户");
|
|
|
- }
|
|
|
- if (!StringUtils.isBlank(user.getSettleAccountId())) {
|
|
|
- throw new BusinessException("此账号已绑定");
|
|
|
- }
|
|
|
- BankValidate bankValidate = BankUtils.validate(bankNo);
|
|
|
- if (!bankValidate.isValidated()) {
|
|
|
- throw new BusinessException("暂不支持此卡");
|
|
|
- }
|
|
|
-
|
|
|
- adapayMerchantService.createMemberForAll(userId.toString(), user.getPhone(), identityAuth.getRealName(), identityAuth.getIdNo());
|
|
|
- user.setMemberId(user.getId().toString());
|
|
|
- userRepo.save(user);
|
|
|
-
|
|
|
- String accountId = adapayMerchantService.createSettleAccountForAll
|
|
|
- (user.getMemberId(), identityAuth.getRealName(),
|
|
|
- identityAuth.getIdNo(), phone, bankNo);
|
|
|
- user.setSettleAccountId(accountId);
|
|
|
- userRepo.save(user);
|
|
|
-
|
|
|
- userBankCardRepo.save(UserBankCard.builder()
|
|
|
- .bank(bankValidate.getBank())
|
|
|
- .bankName(bankValidate.getBankName())
|
|
|
- .bankNo(bankNo)
|
|
|
- .cardType(bankValidate.getCardType())
|
|
|
- .cardTypeDesc(bankValidate.getCardTypeDesc())
|
|
|
- .userId(userId)
|
|
|
- .phone(phone)
|
|
|
- .realName(identityAuth.getRealName())
|
|
|
- .idNo(identityAuth.getIdNo())
|
|
|
- .build());
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void test1() {
|
|
|
- List<User> users = userRepo.findAll();
|
|
|
- users.forEach(user -> {
|
|
|
- if (user.getVipPoint() > 1) {
|
|
|
- user.setVipPoint(1);
|
|
|
- } else {
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
}
|