package com.xjrsoft.module.hikvision.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xjrsoft.XjrSoftApplication;
import com.xjrsoft.common.utils.ImageUtil;
import com.xjrsoft.module.personnel.entity.StundentFaceProcess;
import com.xjrsoft.module.personnel.entity.TeacherFaceProcess;
import com.xjrsoft.module.personnel.service.IFaceManagementService;
import com.xjrsoft.module.personnel.service.IStundentFaceProcessService;
import com.xjrsoft.module.personnel.service.ITeacherFaceProcessService;
import com.xjrsoft.module.system.entity.File;
import com.xjrsoft.module.system.service.IFileService;
import org.junit.jupiter.api.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.List;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @author dzx
 * @date 2024/6/7
 */

@RunWith(SpringRunner.class)
@SpringBootTest(classes = XjrSoftApplication.class)
class FaceImportUtilTest {
    @Autowired
    private IStundentFaceProcessService stundentFaceProcessService;

    @Autowired
    private ITeacherFaceProcessService teacherFaceProcessService;

    @Autowired
    private IFileService fileService;
    @Test
    void test(){
        List<TeacherFaceProcess> list = teacherFaceProcessService.list(
            new QueryWrapper<TeacherFaceProcess>().lambda()
            .notLike(TeacherFaceProcess::getHikvisionResult, "{\"code\":\"0\",\"msg\":\"success\",")
                    .orderByAsc(TeacherFaceProcess::getModifyDate)
        );


        for (TeacherFaceProcess process : list) {
//            byte[] imageBytes = fileService.downloadFileByZip(process.getFacePhoto());
//            //压缩到200k
//            imageBytes = ImageUtil.compressUnderSize(imageBytes, 204800);
            File file = fileService.getOne(
                    new QueryWrapper<File>().lambda().eq(File::getFolderId, process.getFacePhoto())
            );

            String result = FaceImportUtil.ImportStudentFace(process.getUserId() + "", file.getFileUrl());

            process.setHikvisionResult(result);
            teacherFaceProcessService.updateById(process);
        }
    }


    @Test
    void test2(){
        List<StundentFaceProcess> list = stundentFaceProcessService.list(
                new QueryWrapper<StundentFaceProcess>().lambda()
                        .notLike(StundentFaceProcess::getHikvisionResult, "{\"code\":\"0\",\"msg\":\"success\",")
        );


        for (StundentFaceProcess process : list) {
//            byte[] imageBytes = fileService.downloadFileByZip(process.getFacePhoto());
//            //压缩到200k
//            imageBytes = ImageUtil.compressUnderSize(imageBytes, 204800);
            File file = fileService.getOne(
                    new QueryWrapper<File>().lambda().eq(File::getFolderId, process.getFacePhoto())
            );

            String result = FaceImportUtil.ImportStudentFace(process.getUserId() + "", file.getFileUrl());

            process.setHikvisionResult(result);
            stundentFaceProcessService.updateById(process);
        }
    }

}