package com.ycwl.basic.task;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.ycwl.basic.mapper.FaceMapper;
import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.mapper.ScenicMapper;
import com.ycwl.basic.model.pc.scenic.req.ScenicReqQuery;
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
import com.ycwl.basic.service.task.TaskFaceService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
@SpringBootTest
@RunWith(SpringRunner.class)
public class FaceCleanerTest {
    @Autowired
    private FaceMapper faceMapper;
    @Autowired
    private TaskFaceService taskFaceService;
    @Autowired
    private FaceSampleMapper faceSampleMapper;
    @Autowired
    private ScenicMapper scenicMapper;

    @Test
    public void test() {
        ScenicReqQuery scenicQuery = new ScenicReqQuery();
        List<ScenicRespVO> scenicList = scenicMapper.list(scenicQuery);
        scenicList.forEach(scenic -> {
            log.info("当前景区{}，开始删除人脸样本", scenic.getName());
            taskFaceService.batchDeleteExpiredFace(scenic.getId());
        });
    }

    @Test
    public void testC() {
        List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6), Arrays.asList(7,8,9), Arrays.asList(10,11,12));
        ThreadPoolExecutor executor = new ThreadPoolExecutor(8, 16, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(16));
        list.parallelStream().forEach(integers -> {
            executor.execute(() -> {
                integers.forEach(integer -> {
                    executor.execute(() -> {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException ignored) {
                        }
                        log.info("{}", integer);
                    });
                });
            });
        });
        try {
            Thread.sleep(2000);
            executor.shutdown();
            executor.awaitTermination(1, TimeUnit.MINUTES);
        } catch (InterruptedException ignored) {

        }
    }
}