|
|
@@ -1,6 +1,8 @@
|
|
|
package com.xjrsoft.module.hikvision.util;
|
|
|
|
|
|
+import com.google.gson.JsonArray;
|
|
|
import com.google.gson.JsonObject;
|
|
|
+import com.google.gson.JsonParser;
|
|
|
import com.xjrsoft.module.personnel.entity.TeacherFaceProcess;
|
|
|
import com.xjrsoft.module.teacher.mapper.FaceImportMapper;
|
|
|
|
|
|
@@ -18,29 +20,84 @@ public class FaceImportUtil {
|
|
|
private static ApiUtil apiUtil = new ApiUtil();
|
|
|
|
|
|
public static String ImportTeacherFace(String personId, String fileUrl) {
|
|
|
+ JsonParser parser = new JsonParser();
|
|
|
+
|
|
|
+ String apiUrl = "/api/resource/v1/person/condition/personInfo";
|
|
|
+ JsonObject paramsJson = new JsonObject();
|
|
|
+ paramsJson.addProperty("paramName", "personId");
|
|
|
+ JsonArray array = new JsonArray();
|
|
|
+ array.add(personId);
|
|
|
+ paramsJson.add("paramValue", array);
|
|
|
+ String personInfoRes = apiUtil.doPost(apiUrl, paramsJson.toString(), null);
|
|
|
+ JsonObject personInfoData = parser.parse(personInfoRes).getAsJsonObject();
|
|
|
+ String faceId = null;
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String response = null;
|
|
|
+ String base64String = ImageToBase64(fileUrl);
|
|
|
JsonObject paramJson = new JsonObject();
|
|
|
- paramJson.addProperty("personId", personId);
|
|
|
- paramJson.addProperty("faceData", ImageToBase64(fileUrl));
|
|
|
+ if(faceId == null){
|
|
|
+ paramJson.addProperty("personId", personId);
|
|
|
+ paramJson.addProperty("faceData", base64String);
|
|
|
|
|
|
- Map<String, String> querys = new HashMap<>();
|
|
|
- querys.put("tagId", "frs");
|
|
|
+ Map<String, String> querys = new HashMap<>();
|
|
|
+ querys.put("tagId", "frs");
|
|
|
|
|
|
- String apiPath = "/api/resource/v1/face/single/add";
|
|
|
- String response = apiUtil.doPost(apiPath, String.valueOf(paramJson), querys);
|
|
|
+ String apiPath = "/api/resource/v1/face/single/add";
|
|
|
+ response = apiUtil.doPost(apiPath, String.valueOf(paramJson), querys);
|
|
|
+ }else{
|
|
|
+ String apiPath = "/api/resource/v1/face/single/update";
|
|
|
+ paramJson.addProperty("faceId", faceId);
|
|
|
+ paramJson.addProperty("faceData", base64String);
|
|
|
+ response = apiUtil.doPost(apiPath, paramJson.toString(), null);
|
|
|
+ }
|
|
|
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
public static String ImportStudentFace(String personId, String fileUrl) {
|
|
|
+
|
|
|
+ JsonParser parser = new JsonParser();
|
|
|
+
|
|
|
+ String apiUrl = "/api/resource/v1/person/condition/personInfo";
|
|
|
+ JsonObject paramsJson = new JsonObject();
|
|
|
+ paramsJson.addProperty("paramName", "personId");
|
|
|
+ JsonArray array = new JsonArray();
|
|
|
+ array.add(personId);
|
|
|
+ paramsJson.add("paramValue", array);
|
|
|
+ String personInfoRes = apiUtil.doPost(apiUrl, paramsJson.toString(), null);
|
|
|
+ JsonObject personInfoData = parser.parse(personInfoRes).getAsJsonObject();
|
|
|
+ String faceId = null;
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String response = null;
|
|
|
+ String base64String = ImageToBase64(fileUrl);
|
|
|
JsonObject paramJson = new JsonObject();
|
|
|
- paramJson.addProperty("personId", personId);
|
|
|
- paramJson.addProperty("faceData", ImageToBase64(fileUrl));
|
|
|
+ if(faceId == null){
|
|
|
+ paramJson.addProperty("personId", personId);
|
|
|
+ paramJson.addProperty("faceData", base64String);
|
|
|
|
|
|
- Map<String, String> querys = new HashMap<>();
|
|
|
- querys.put("tagId", "frs");
|
|
|
+ Map<String, String> querys = new HashMap<>();
|
|
|
+ querys.put("tagId", "frs");
|
|
|
|
|
|
- String apiPath = "/api/resource/v1/face/single/add";
|
|
|
- String response = apiUtil.doPost(apiPath, String.valueOf(paramJson), querys);
|
|
|
+ String apiPath = "/api/resource/v1/face/single/add";
|
|
|
+ response = apiUtil.doPost(apiPath, String.valueOf(paramJson), querys);
|
|
|
+ }else{
|
|
|
+ String apiPath = "/api/resource/v1/face/single/update";
|
|
|
+ paramJson.addProperty("faceId", faceId);
|
|
|
+ paramJson.addProperty("faceData", base64String);
|
|
|
+ response = apiUtil.doPost(apiPath, paramJson.toString(), null);
|
|
|
+ }
|
|
|
|
|
|
return response;
|
|
|
}
|