dzx 9 місяців тому
батько
коміт
db3726a757

+ 12 - 6
src/main/java/com/xjrsoft/module/hikvision/util/FaceImportUtil.java

@@ -4,8 +4,6 @@ import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import com.xjrsoft.common.utils.ImageUtil;
-import com.xjrsoft.module.personnel.entity.TeacherFaceProcess;
-import com.xjrsoft.module.teacher.mapper.FaceImportMapper;
 
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
@@ -35,8 +33,12 @@ public class FaceImportUtil {
         if("0".equals(personInfoData.get("code").getAsString()) && "success".equals(personInfoData.get("msg").getAsString())){
             JsonObject dataJson = personInfoData.get("data").getAsJsonObject();
             if(dataJson.get("total").getAsInt() > 0){
-                faceId = dataJson.get("list").getAsJsonArray().get(0)
-                        .getAsJsonObject().get("personPhoto").getAsJsonObject().get("personPhotoIndexCode").getAsString();
+                JsonArray personPhoto = dataJson.get("list").getAsJsonArray().get(0)
+                        .getAsJsonObject().get("personPhoto").getAsJsonArray();
+                if(personPhoto.size() > 0){
+                    faceId = personPhoto.get(0).getAsJsonObject().get("personPhotoIndexCode").getAsString();
+                }
+
             }
         }
         String response = null;
@@ -77,8 +79,12 @@ public class FaceImportUtil {
         if("0".equals(personInfoData.get("code").getAsString()) && "success".equals(personInfoData.get("msg").getAsString())){
             JsonObject dataJson = personInfoData.get("data").getAsJsonObject();
             if(dataJson.get("total").getAsInt() > 0){
-                faceId = dataJson.get("list").getAsJsonArray().get(0)
-                        .getAsJsonObject().get("personPhoto").getAsJsonObject().get("personPhotoIndexCode").getAsString();
+                JsonArray personPhoto = dataJson.get("list").getAsJsonArray().get(0)
+                        .getAsJsonObject().get("personPhoto").getAsJsonArray();
+                if(personPhoto.size() > 0){
+                    faceId = personPhoto.get(0).getAsJsonObject().get("personPhotoIndexCode").getAsString();
+                }
+
             }
         }
         String response = null;

+ 2 - 0
src/main/java/com/xjrsoft/module/job/AttenDanceWarnNoticeTask.java

@@ -102,6 +102,8 @@ public class AttenDanceWarnNoticeTask {
                 paramJson.put("const12", "出校");
             }
 
+
+
             weChatSendMessageDto.setContent(paramJson);
             weChatService.sendTemplateMessage(weChatSendMessageDto);
         }

+ 1 - 1
src/main/java/com/xjrsoft/module/job/InsertOutInRecordTask.java

@@ -25,7 +25,7 @@ public class InsertOutInRecordTask {
 
     OutInRecordUtil out_in_recordUtil = new OutInRecordUtil();
 
-    @Scheduled(cron = "*/15 * * * * ?")
+    @Scheduled(cron = "*/60 * * * * ?")
     public void RefreshConnectionPool() {
         String active = SpringUtil.getActiveProfile();
         if(!"prod".equals(active)){

+ 86 - 0
src/test/java/com/xjrsoft/module/hikvision/util/FaceImportUtilTest.java

@@ -0,0 +1,86 @@
+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\",")
+        );
+
+
+        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);
+        }
+    }
+
+}

+ 24 - 0
src/test/java/com/xjrsoft/module/personnel/controller/StundentFaceProcessControllerTest.java

@@ -3,6 +3,7 @@ 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.ImageUtil;
 import com.xjrsoft.common.utils.UploadUtil;
 import com.xjrsoft.module.personnel.entity.StundentFaceProcess;
 import com.xjrsoft.module.personnel.service.IStundentFaceProcessService;
@@ -19,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.Charset;
@@ -87,4 +89,26 @@ class StundentFaceProcessControllerTest {
 
     }
 
+    @Test
+    void imgTest() throws IOException {
+        String newFilePath = "C:\\Users\\14263\\Downloads\\2023级剩余学籍找\\20240607-194930.jpg";
+        File sourceFile = new File(newFilePath);
+        FileInputStream fileInputStream = new FileInputStream(sourceFile);
+
+        byte[] imageBytes = new byte[(int) sourceFile.length()];
+        fileInputStream.read(imageBytes);
+
+        fileInputStream.close();
+
+        imageBytes = ImageUtil.compressUnderSize(imageBytes, 204800);
+
+        File file = new File("C:\\Users\\14263\\Downloads\\2023级剩余学籍找\\20240607-194930-压缩.jpg");
+        try (FileOutputStream fos = new FileOutputStream(file)) {
+            fos.write(imageBytes);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
 }