package com.izouma.wenlvju.web;


import com.izouma.wenlvju.ApplicationTests;
import com.izouma.wenlvju.converter.StringArrayConverter;
import com.izouma.wenlvju.domain.TrainingInstitution;
import com.izouma.wenlvju.dto.PageQuery;
import com.izouma.wenlvju.repo.TrainingInstitutionRepo;
import com.izouma.wenlvju.service.TrainingInstitutionService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

public class TrainingInstitutionControllerTest extends ApplicationTests {

    @Autowired
    private TrainingInstitutionController trainingInstitutionController;

    @Autowired
    private TrainingInstitutionService trainingInstitutionService;

    @Autowired
    private TrainingInstitutionRepo trainingInstitutionRepo;

    @Test
    public void test() throws InterruptedException {
        long count = trainingInstitutionRepo.count();

        PageQuery pageQuery = new PageQuery();
        pageQuery.setSize(1000);
        for (int i = 5; i < count / 1000; i++) {
            pageQuery.setPage(i);
            List<TrainingInstitution> content = trainingInstitutionController.all(pageQuery).getContent();
            List<TrainingInstitution> result = new ArrayList<>();
            content.forEach(t -> {
                if (t.getPhone() != null && (t.getPhone().length() < 11 || t.getPhone().contains("-"))) {
                    t.setPhone(null);
                    result.add(t);
                }

            });
            trainingInstitutionRepo.saveAll(result);
            System.out.println(i);
//            Thread.sleep(5 * 60 * 1000);
//            Thread.sleep(30 * 1000);
        }

//        System.out.println("12".split(","));
    }

    @Test
    public void test1() throws InterruptedException {
        List<String> phones = trainingInstitutionRepo.findAllBySubmitFalseAndPhoneIsNotNull();
        trainingInstitutionService.batchSend(phones);

    }


}