package com.xjrsoft.module.personnel.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.xjrsoft.XjrSoftApplication; import com.xjrsoft.common.enums.DeleteMark; import com.xjrsoft.common.utils.UploadUtil; import com.xjrsoft.module.personnel.entity.StundentFaceProcess; import com.xjrsoft.module.personnel.service.IStundentFaceProcessService; import com.xjrsoft.module.student.service.IStudentManagerService; import org.apache.commons.io.FileUtils; 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.mock.web.MockMultipartFile; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; import static org.junit.jupiter.api.Assertions.*; /** * @author dzx * @date 2024/5/22 */ @RunWith(SpringRunner.class) @SpringBootTest(classes = XjrSoftApplication.class) class StundentFaceProcessControllerTest { @Autowired private IStundentFaceProcessService stundentFaceProcessService; @Autowired private IStudentManagerService studentManagerService; @Test void test() throws Exception { String filePath = "C:\\Users\\14263\\Downloads\\2023级全部学籍照.zip"; File file = new File(filePath); ZipFile zipFile = new ZipFile(file, Charset.forName("GBK")); List faceList = stundentFaceProcessService.list( new QueryWrapper().lambda() .eq(StundentFaceProcess::getDeleteMark, DeleteMark.NODELETE.getCode()) ); Set idNumberSet = new HashSet<>(); for (StundentFaceProcess faceProcess : faceList) { if(faceProcess.getHikvisionResult() != null && faceProcess.getHikvisionResult().contains("{\"code\":\"0\",\"msg\":\"success\",")){ idNumberSet.add(faceProcess.getIdentityCard()); } } Set notIntSet = new HashSet<>(); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()){ ZipEntry entry = entries.nextElement(); String filename = entry.getName(); String[] split = filename.split("\\."); String idNumber = split[0].substring(split[0].length() - 18); if(!idNumberSet.contains(idNumber)){ notIntSet.add(filename); System.out.println(filename); } } for (String fileName : notIntSet) { String newFilePath = "C:\\Users\\14263\\Downloads\\2023级全部学籍照\\" + fileName; File sourceFile = new File(newFilePath); File destinationDir = new File("C:\\Users\\14263\\Downloads\\2023级全部学籍照2"); FileUtils.moveFileToDirectory(sourceFile, destinationDir, true); } } }