Ver Fonte

人脸信息删除功能添加

M墨鱼—_mo há 5 anos atrás
pai
commit
d4d09c8381

+ 18 - 3
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/PersonDeviceLogServiceImpl.java

@@ -13,6 +13,7 @@ import com.jpsoft.smart.modules.common.utils.BASE64DecodedMultipartFile;
 import com.jpsoft.smart.modules.common.utils.Base64;
 import com.jpsoft.smart.modules.common.utils.LApiUtil;
 import com.jpsoft.smart.modules.common.utils.OSSUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -35,6 +36,7 @@ import java.util.UUID;
  * @author 墨鱼_mo
  * @date 2020-3-15 14:12
  */
+@Slf4j
 @Transactional
 @Component(value="personDeviceLogService")
 public class PersonDeviceLogServiceImpl implements PersonDeviceLogService {
@@ -88,15 +90,28 @@ public class PersonDeviceLogServiceImpl implements PersonDeviceLogService {
         PersonDeviceLog personDeviceLog = new PersonDeviceLog();
         personDeviceLog.setId(UUID.randomUUID().toString());
         personDeviceLog.setDeviceNo(deviceNo);
-        if (!StringUtils.isBlank(matchPersonInfo.getStr("PersonCode"))){
+        if (!libMatInfoListJson.getStr("MatchPersonID").equals("0") && StringUtils.isNotBlank(matchPersonInfo.getStr("PersonCode"))){
             personDeviceLog.setPersonId(matchPersonInfo.getInt("PersonCode"));
-        }else {
+        }else if (!libMatInfoListJson.getStr("MatchPersonID").equals("0") && StringUtils.isBlank(matchPersonInfo.getStr("PersonCode")) && StringUtils.isNotBlank(matchPersonInfo.getStr("PersonName"))){
+            String personName = matchPersonInfo.getStr("PersonName");
+            if (personName.contains("_")){
+                log.warn(personName+"校验成功但未找到personCode");
+                Integer personId =Integer.valueOf(personName.substring(personName.indexOf("_")+1)) ;
+                personDeviceLog.setPersonId(personId);
+            }else {
+                log.warn(personName+"校验成功但姓名中无personCode后缀");
+                personDeviceLog.setPersonId(0);
+            }
+
+
+        }
+
+        else {
             personDeviceLog.setPersonId(0);
         }
 
         personDeviceLog.setTemperature(temperature);
         if (StringUtils.isNotBlank(libMatInfoListJson.getStr("MatchStatus"))){
-            System.out.println();
             personDeviceLog.setMatchStatus(libMatInfoListJson.getInt("MatchStatus"));
             personDeviceLog.setMatchMsg(LApiUtil.getMatchMsg(libMatInfoListJson.getInt("MatchStatus")));
             personDeviceLog.setMatchFaceId(libMatInfoListJson.getInt("MatchFaceID"));

+ 25 - 3
common/src/main/java/com/jpsoft/smart/modules/common/utils/LApiUtil.java

@@ -1,12 +1,21 @@
 package com.jpsoft.smart.modules.common.utils;
 
 import cn.hutool.http.HttpRequest;
-import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.aliyun.oss.common.utils.HttpUtil;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
 import org.springframework.stereotype.Component;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
 import java.util.Date;
 import java.util.HashMap;
 
@@ -36,6 +45,15 @@ public class LApiUtil {
 
 
     }
+    public static JSONObject DeletRequest(String url) {
+       String body = HttpRequest.delete(url).execute().body();
+       JSONObject jsonbody = JSONObject.parseObject(body);
+       return jsonbody;
+
+
+    }
+
+
 
 
 
@@ -125,12 +143,16 @@ public class LApiUtil {
 
 
 
+
     public static void main(String[] args) {
-        Date date = new Date(1584321770000L);
+     //   Date date = new Date(1584405803000L);
     //    Date date = new
      //   Date date = new Date();
       // long time = date.getTime();
-        System.out.println(date);
+     //   System.out.println(date);
+      //  192.168.11.13:80/V1.0/PeopleLibraries/1584409665/People/1111?LastChange=1584428390872
+        String body = HttpRequest.delete("http://192.168.11.13/LAPI/V1.0/PeopleLibraries/1584409665/People/1111?LastChange=1584424537633").execute().body();
+        System.out.println(body);
     }
 
 

+ 5 - 0
common/src/main/java/com/jpsoft/smart/modules/constant/LApiConstant.java

@@ -27,4 +27,9 @@ public class LApiConstant {
      */
     public static final String GETFACEDB = "/LAPI/V1.0/PeopleLibraries/BasicInfo";
 
+    /**
+     * 删除人脸数据
+     */
+    public static final String DELETEPERSON = "/LAPI/V1.0/PeopleLibraries/";
+
 }

+ 8 - 1
common/src/main/java/com/jpsoft/smart/modules/lapi/service/ILapiService.java

@@ -44,5 +44,12 @@ public interface ILapiService {
      */
      String getFaceDbId(DeviceInfo deviceInfo, String companyName) throws Exception;
 
-     
+    /**
+     * 删除设备人脸数据
+     * @param id
+     * @return
+     */
+    List<LapiMsgResult> deletePerson(Long id) throws Exception;
+
+
 }

+ 59 - 1
common/src/main/java/com/jpsoft/smart/modules/lapi/service/impl/LapiServiceImpl.java

@@ -102,7 +102,7 @@ public class LapiServiceImpl implements ILapiService {
             map1.put("PersonID",personInfo.getId());
             map1.put("LastChange",new Date().getTime());
             map1.put("PersonCode",personInfo.getId().toString());
-            map1.put("PersonName",personInfo.getName());
+            map1.put("PersonName",personInfo.getName()+"_"+personInfo.getId().toString());
             map1.put("Remarks",companyInfo.getName());
 
             //TimeTemplateNum 首字符必须大写
@@ -188,4 +188,62 @@ public class LapiServiceImpl implements ILapiService {
         }
         return faceDbId;
     }
+
+    @Override
+    public List<LapiMsgResult> deletePerson(Long id) throws Exception{
+
+        PersonInfo personInfo = personInfoService.get(id);
+        if (personInfo == null){
+            throw new Exception("人员不存在");
+        }
+        List<PersonDeviceRelation> listRelation = personDeviceRelationService.findByPersonId(id);
+        if (listRelation.size()<=0){
+            throw new Exception("人员未绑定设备");
+        }
+        CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());
+        List<DeviceInfo> deviceList = new ArrayList<>();
+        for (PersonDeviceRelation personDeviceRelation:listRelation){
+            DeviceInfo deviceInfo = deviceInfoService.get(personDeviceRelation.getDeviceId());
+            if (deviceInfo!=null){
+                deviceList.add(deviceInfo);
+            }
+        }
+        if (deviceList.size()<=0){
+            throw new Exception("人员与设备绑定错误");
+        }
+
+        List<LapiMsgResult> lapiMsgResults = new ArrayList<>();
+        for (DeviceInfo deviceInfo : deviceList){
+
+            try{
+                //获取人员人脸库id
+                String faceDbId = getFaceDbId(deviceInfo,companyInfo.getName());
+                JSONObject jsonObject = LApiUtil.DeletRequest(deviceInfo.getIpAddress()+":"+deviceInfo.getPort()+LApiConstant.DELETEPERSON+faceDbId+"/People/"+personInfo.getId()+"?LastChange="+new Date().getTime());
+                JSONObject dataJson = jsonObject.getJSONObject("Response");
+                JSONObject response = LApiUtil.getResponse(dataJson);
+                if (dataJson.getInteger("ResponseCode") ==0 && dataJson.getInteger("StatusCode") == 0){
+                    LapiMsgResult lapiMsgResult = new LapiMsgResult();
+                    lapiMsgResult.setPersonName(personInfo.getName());
+                    lapiMsgResult.setSuccess(true);
+                    lapiMsgResult.setAliasName(deviceInfo.getAliasName());
+                    lapiMsgResults.add(lapiMsgResult);
+                }
+
+            }catch (Exception e){
+
+                log.error(e.getMessage());
+                LapiMsgResult lapiMsgResult = new LapiMsgResult();
+                lapiMsgResult.setPersonName(personInfo.getName());
+                lapiMsgResult.setSuccess(false);
+                lapiMsgResult.setMsg(e.getMessage());
+                lapiMsgResult.setAliasName(deviceInfo.getAliasName());
+                lapiMsgResults.add(lapiMsgResult);
+
+            }
+
+
+        }
+
+        return lapiMsgResults;
+    }
 }

+ 16 - 0
lapi/src/main/resources/application-test.yml

@@ -0,0 +1,16 @@
+server:
+  port: 9988
+
+spring:
+  datasource:
+    url: jdbc:log4jdbc:mysql://127.0.0.1:3306/smart-community?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+    username: root
+    password: slgo^Root_!Q@W#E)P(O*I
+  devtools:
+    add-properties: false
+    restart:
+      enabled: true
+
+logger:
+  level: WARN
+  dir: /opt/logs/smart-community-lapi/

+ 12 - 0
web/src/test/java/com/jpsoft/smart/LApiTest.java

@@ -63,4 +63,16 @@ public class LApiTest {
 
     }
 
+    @Test
+    public void testDeletPerson(){
+        try {
+            List<LapiMsgResult> result = lapiService.deletePerson(1111L);
+            System.out.println(result);
+        } catch (Exception e) {
+            e.printStackTrace();
+            String message = e.getMessage();
+        }
+
+    }
+
 }