licailing 5 лет назад
Родитель
Сommit
79f302a26e
1 измененных файлов с 127 добавлено и 0 удалено
  1. 127 0
      src/test/java/com/izouma/wenlvju/repo/RepoTest.java

+ 127 - 0
src/test/java/com/izouma/wenlvju/repo/RepoTest.java

@@ -0,0 +1,127 @@
+package com.izouma.wenlvju.repo;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.izouma.wenlvju.ApplicationTests;
+import com.izouma.wenlvju.domain.Collaborate;
+import com.izouma.wenlvju.domain.Organization;
+import com.izouma.wenlvju.domain.Rate;
+import com.izouma.wenlvju.service.storage.StorageService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RepoTest extends ApplicationTests {
+    @Autowired
+    private CollaborateRepo  collaborateRepo;
+    @Autowired
+    private StorageService   storageService;
+    @Autowired
+    private OrganizationRepo organizationRepo;
+    @Autowired
+    private RateRepo         rateRepo;
+
+    @Test
+    public void test() {
+
+//        List<Collaborate> users = collaborateRepo.findAll();
+//        users.forEach(user -> {
+//            List<String> strs = new ArrayList<>();
+//            user.getConsent().forEach(con -> {
+//                String path = con.substring(con.lastIndexOf("/", con.lastIndexOf("/") - 1) + 1);
+//                String url = storageService.uploadFromUrl(con, path);
+//                strs.add(url);
+//            });
+//            user.setConsent(strs);
+//            collaborateRepo.save(user);
+//        });
+
+//        List<Organization> users = organizationRepo.findAll();
+//        users.forEach(user -> {
+//            String con = user.getBusinessLicense();
+//            if (StrUtil.isNotBlank(con)) {
+//
+//
+//                String path = con.substring(con.lastIndexOf("/", con.lastIndexOf("/") - 1) + 1);
+//                String url = storageService.uploadFromUrl(con, path);
+//
+//                user.setBusinessLicense(url);
+//                organizationRepo.save(user);
+//            }
+//        });
+
+
+        List<Rate> users = rateRepo.findAll();
+        users.forEach(user -> {
+            List<String> strs = new ArrayList<>();
+            List<String> strs1 = new ArrayList<>();
+            List<String> strs2 = new ArrayList<>();
+            List<String> strs3= new ArrayList<>();
+            List<String> strs4 = new ArrayList<>();
+            List<String> strs5 = new ArrayList<>();
+            List<String> strs6 = new ArrayList<>();
+            List<String> strs7 = new ArrayList<>();
+            user.getBusiness().forEach(con -> {
+                String path = con.substring(con.lastIndexOf("/", con.lastIndexOf("/") - 1) + 1);
+                String url = storageService.uploadFromUrl(con, path);
+                strs.add(url);
+            });
+            user.setBusiness(strs);
+
+            user.getCredits().forEach(con -> {
+                String path = con.substring(con.lastIndexOf("/", con.lastIndexOf("/") - 1) + 1);
+                String url = storageService.uploadFromUrl(con, path);
+                strs1.add(url);
+            });
+            user.setCredits(strs1);
+
+            user.getFire().forEach(con -> {
+                String path = con.substring(con.lastIndexOf("/", con.lastIndexOf("/") - 1) + 1);
+                String url = storageService.uploadFromUrl(con, path);
+                strs2.add(url);
+            });
+            user.setFire(strs2);
+
+            user.getHygiene().forEach(con -> {
+                String path = con.substring(con.lastIndexOf("/", con.lastIndexOf("/") - 1) + 1);
+                String url = storageService.uploadFromUrl(con, path);
+                strs3.add(url);
+            });
+            user.setHygiene(strs3);
+
+            user.getPrivacyPolicy().forEach(con -> {
+                String path = con.substring(con.lastIndexOf("/", con.lastIndexOf("/") - 1) + 1);
+                String url = storageService.uploadFromUrl(con, path);
+                strs4.add(url);
+            });
+            user.setPrivacyPolicy(strs4);
+
+            user.getProperty().forEach(con -> {
+                String path = con.substring(con.lastIndexOf("/", con.lastIndexOf("/") - 1) + 1);
+                String url = storageService.uploadFromUrl(con, path);
+                strs5.add(url);
+            });
+            user.setProperty(strs5);
+
+            user.getFinance().forEach(con -> {
+                String path = con.substring(con.lastIndexOf("/", con.lastIndexOf("/") - 1) + 1);
+                String url = storageService.uploadFromUrl(con, path);
+                strs6.add(url);
+            });
+            user.setFinance(strs6);
+
+            if (CollUtil.isNotEmpty(user.getIntroductionAnnex())){
+                user.getIntroductionAnnex().forEach(con -> {
+                    String path = con.substring(con.lastIndexOf("/", con.lastIndexOf("/") - 1) + 1);
+                    String url = storageService.uploadFromUrl(con, path);
+                    strs7.add(url);
+                });
+                user.setIntroductionAnnex(strs7);
+            }
+
+            rateRepo.save(user);
+        });
+    }
+}