|
|
@@ -1,12 +1,23 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
import com.izouma.nineth.ApplicationTests;
|
|
|
+import com.izouma.nineth.domain.IdentityAuth;
|
|
|
+import com.izouma.nineth.domain.User;
|
|
|
+import com.izouma.nineth.enums.AuthStatus;
|
|
|
+import com.izouma.nineth.repo.IdentityAuthRepo;
|
|
|
+import com.izouma.nineth.repo.UserRepo;
|
|
|
import org.junit.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
public class IdentityAuthServiceTest extends ApplicationTests {
|
|
|
@Autowired
|
|
|
private IdentityAuthService identityAuthService;
|
|
|
+ @Autowired
|
|
|
+ private IdentityAuthRepo identityAuthRepo;
|
|
|
+ @Autowired
|
|
|
+ private UserRepo userRepo;
|
|
|
|
|
|
@Test
|
|
|
public void validate() {
|
|
|
@@ -14,4 +25,40 @@ public class IdentityAuthServiceTest extends ApplicationTests {
|
|
|
identityAuthService.validate("熊竹", "15077886171", "321002199408304614");
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void asdfa() {
|
|
|
+ User user = userRepo.findById(8157L).get();
|
|
|
+ List<IdentityAuth> list = identityAuthRepo.findByUserId(8157L);
|
|
|
+ if (list.size() > 1) {
|
|
|
+ IdentityAuth auth = list.stream()
|
|
|
+ .filter(i -> i.getStatus() == AuthStatus.SUCCESS)
|
|
|
+ .findAny().orElse(null);
|
|
|
+ if (auth != null) {
|
|
|
+ userRepo.setAuthStatus(user.getId(), auth.getStatus(), auth.getId());
|
|
|
+ identityAuthRepo.deleteDuplicated(user.getId(), auth.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ auth = list.stream()
|
|
|
+ .filter(i -> i.getStatus() == AuthStatus.PENDING)
|
|
|
+ .findAny().orElse(null);
|
|
|
+ if (auth != null) {
|
|
|
+ userRepo.setAuthStatus(user.getId(), auth.getStatus(), auth.getId());
|
|
|
+ identityAuthRepo.deleteDuplicated(user.getId(), auth.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ auth = list.stream()
|
|
|
+ .filter(i -> i.getStatus() == AuthStatus.FAIL)
|
|
|
+ .findAny().orElse(null);
|
|
|
+ if (auth != null) {
|
|
|
+ userRepo.setAuthStatus(user.getId(), auth.getStatus(), auth.getId());
|
|
|
+ identityAuthRepo.deleteDuplicated(user.getId(), auth.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (list.size() == 1) {
|
|
|
+ userRepo.setAuthStatus(user.getId(), list.get(0).getStatus(), list.get(0).getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|