StundentFaceProcessControllerTest.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package com.xjrsoft.module.personnel.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.xjrsoft.XjrSoftApplication;
  4. import com.xjrsoft.common.enums.DeleteMark;
  5. import com.xjrsoft.common.utils.UploadUtil;
  6. import com.xjrsoft.module.personnel.entity.StundentFaceProcess;
  7. import com.xjrsoft.module.personnel.service.IStundentFaceProcessService;
  8. import com.xjrsoft.module.student.service.IStudentManagerService;
  9. import org.apache.commons.io.FileUtils;
  10. import org.junit.jupiter.api.Test;
  11. import org.junit.runner.RunWith;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.boot.test.context.SpringBootTest;
  14. import org.springframework.mock.web.MockMultipartFile;
  15. import org.springframework.test.context.junit4.SpringRunner;
  16. import org.springframework.web.multipart.MultipartFile;
  17. import java.io.File;
  18. import java.io.FileInputStream;
  19. import java.io.FileNotFoundException;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import java.nio.charset.Charset;
  23. import java.util.Enumeration;
  24. import java.util.HashMap;
  25. import java.util.HashSet;
  26. import java.util.List;
  27. import java.util.Map;
  28. import java.util.Set;
  29. import java.util.zip.ZipEntry;
  30. import java.util.zip.ZipFile;
  31. import java.util.zip.ZipInputStream;
  32. import static org.junit.jupiter.api.Assertions.*;
  33. /**
  34. * @author dzx
  35. * @date 2024/5/22
  36. */
  37. @RunWith(SpringRunner.class)
  38. @SpringBootTest(classes = XjrSoftApplication.class)
  39. class StundentFaceProcessControllerTest {
  40. @Autowired
  41. private IStundentFaceProcessService stundentFaceProcessService;
  42. @Autowired
  43. private IStudentManagerService studentManagerService;
  44. @Test
  45. void test() throws Exception {
  46. String filePath = "C:\\Users\\14263\\Downloads\\2023级全部学籍照.zip";
  47. File file = new File(filePath);
  48. ZipFile zipFile = new ZipFile(file, Charset.forName("GBK"));
  49. List<StundentFaceProcess> faceList = stundentFaceProcessService.list(
  50. new QueryWrapper<StundentFaceProcess>().lambda()
  51. .eq(StundentFaceProcess::getDeleteMark, DeleteMark.NODELETE.getCode())
  52. );
  53. Set<String> idNumberSet = new HashSet<>();
  54. for (StundentFaceProcess faceProcess : faceList) {
  55. if(faceProcess.getHikvisionResult() != null && faceProcess.getHikvisionResult().contains("{\"code\":\"0\",\"msg\":\"success\",")){
  56. idNumberSet.add(faceProcess.getIdentityCard());
  57. }
  58. }
  59. Set<String> notIntSet = new HashSet<>();
  60. Enumeration<? extends ZipEntry> entries = zipFile.entries();
  61. while (entries.hasMoreElements()){
  62. ZipEntry entry = entries.nextElement();
  63. String filename = entry.getName();
  64. String[] split = filename.split("\\.");
  65. String idNumber = split[0].substring(split[0].length() - 18);
  66. if(!idNumberSet.contains(idNumber)){
  67. notIntSet.add(filename);
  68. System.out.println(filename);
  69. }
  70. }
  71. for (String fileName : notIntSet) {
  72. String newFilePath = "C:\\Users\\14263\\Downloads\\2023级全部学籍照\\" + fileName;
  73. File sourceFile = new File(newFilePath);
  74. File destinationDir = new File("C:\\Users\\14263\\Downloads\\2023级全部学籍照2");
  75. FileUtils.moveFileToDirectory(sourceFile, destinationDir, true);
  76. }
  77. }
  78. }