Prechádzať zdrojové kódy

Merge remote-tracking branch 'origin/V1' into V1

zhengqiang 5 rokov pred
rodič
commit
74ce2e4288

+ 1 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/DeviceInfoService.java

@@ -13,6 +13,7 @@ public interface DeviceInfoService {
 	int update(DeviceInfo model);
 	int delete(String id);
 	List<DeviceInfo> list();
+	DeviceInfo getByDeviceNo(String deviceNo);
 	Page<DeviceInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize,boolean count, List<Sort> sortList);
 	void updateByDeviceNo(String deviceNo, String ip);
 }

+ 5 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/DeviceInfoServiceImpl.java

@@ -61,6 +61,11 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
 		return deviceInfoDAO.list();
 	}
 
+	@Override
+	public DeviceInfo getByDeviceNo(String deviceNo){
+		return deviceInfoDAO.getByDeviceNo(deviceNo);
+	}
+
 	@Override
 	public Page<DeviceInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
         Page<DeviceInfo> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{

+ 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;
+
+
 }

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

@@ -87,7 +87,7 @@ public class LapiServiceImpl implements ILapiService {
         List<DeviceInfo> deviceList = new ArrayList<>();
         for (PersonDeviceRelation personDeviceRelation:listRelation){
             DeviceInfo deviceInfo = deviceInfoService.get(personDeviceRelation.getDeviceId());
-            if (deviceInfo!=null){
+            if (deviceInfo!=null && !deviceInfo.getDelFlag()){
                 deviceList.add(deviceInfo);
             }
         }
@@ -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 && !deviceInfo.getDelFlag()){
+                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;
+    }
 }

+ 0 - 13
lapi/src/main/java/com/jpsoft/smart/lapi/handler/PersonVerificationHandler.java

@@ -80,18 +80,5 @@ public class PersonVerificationHandler extends SimpleChannelInboundHandler<Perso
         personDeviceLogService.deviceInsertLog(deviceNo,temperature,faceImageJson,libMatInfoListJson,matchPersonInfo,date);
 
 
-
-
-        /*log.warn("faceJson"+faceJson);
-        log.warn("FaceImage"+faceImageJson);
-        log.warn("LibMatInfoList"+libMatInfoListJson);
-        log.warn("MatchPersonInfo"+matchPersonInfo);
-        long timestamp = jsonObject.getLong("Timestamp");
-
-        Date date = new Date(timestamp);
-
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
-        log.warn("考勤时间:" + sdf.format(date));*/
     }
 }

+ 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/

+ 20 - 11
web/src/main/java/com/jpsoft/smart/modules/base/controller/DeviceInfoController.java

@@ -44,19 +44,28 @@ public class DeviceInfoController {
         MessageResult<DeviceInfo> msgResult = new MessageResult<>();
 
         try {
-            deviceInfo.setId(UUID.randomUUID().toString());
-            deviceInfo.setDelFlag(false);
-            deviceInfo.setCreateBy(subject);
-            deviceInfo.setCreateTime(new Date());
-            
-            int affectCount = deviceInfoService.insert(deviceInfo);
+            DeviceInfo item = deviceInfoService.getByDeviceNo(deviceInfo.getDeviceNo());
 
-            if (affectCount > 0) {
-                msgResult.setResult(true);
-                msgResult.setData(deviceInfo);
-            } else {
+            if(item == null) {
+
+                deviceInfo.setId(UUID.randomUUID().toString());
+                deviceInfo.setDelFlag(false);
+                deviceInfo.setCreateBy(subject);
+                deviceInfo.setCreateTime(new Date());
+
+                int affectCount = deviceInfoService.insert(deviceInfo);
+
+                if (affectCount > 0) {
+                    msgResult.setResult(true);
+                    msgResult.setData(deviceInfo);
+                } else {
+                    msgResult.setResult(false);
+                    msgResult.setMessage("数据库添加失败");
+                }
+            }
+            else{
                 msgResult.setResult(false);
-                msgResult.setMessage("数据库添加失败");
+                msgResult.setMessage("设备编号已经存在,不能重复添加!");
             }
         }
         catch(Exception ex){

+ 1 - 1
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java

@@ -389,7 +389,7 @@ public class PersonDeviceRelationController {
         List<Sort> sortList = new ArrayList<>();
         sortList.add(new Sort("create_time","desc"));
 
-        searchParams.put("companyId",user.getCompanyId());
+        //searchParams.put("companyId",user.getCompanyId());
 
         Page<DeviceInfo> page = deviceInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
 

+ 32 - 0
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java

@@ -367,6 +367,37 @@ public class PersonInfoController {
             PersonInfo personInfo = personInfoService.get(id);
 
             if(personInfo.getFaceEnabled()){
+                if (personInfo==null){
+                    throw new Exception("人员信息不存在!");
+                }
+
+                //todo 同步终端
+                boolean success = true;
+                StringBuilder sb = new StringBuilder();
+                List<LapiMsgResult> msgResultList = lapiService.deletePerson(id);
+                for(int i=0;i<msgResultList.size();i++) {
+                    LapiMsgResult lapiMsgResult = msgResultList.get(i);
+
+                    if (lapiMsgResult.isSuccess()){
+                        sb.append("【" + personInfo.getName() + "】" + lapiMsgResult.getAliasName() + "解绑人脸信息成功!");
+                    }
+                    else{
+                        sb.append("【" + personInfo.getName() + "】" + lapiMsgResult.getAliasName() + "解绑人脸信息失败!" + lapiMsgResult.getMsg());
+                    }
+
+                    if (i!=msgResultList.size()-1){
+                        sb.append(",");
+                    }
+                    else{
+                        sb.append("。");
+                    }
+
+                    success &= lapiMsgResult.isSuccess();
+                }
+
+                personInfo.setFaceBound(false);
+                personInfo.setUpdateTime(new Date());
+                personInfoService.update(personInfo);
                 personInfo.setFaceEnabled(false);
             }else{
                 personInfo.setFaceEnabled(true);
@@ -858,6 +889,7 @@ public class PersonInfoController {
                 }
 
                 personInfo.setFaceBound(success);
+                personInfo.setFaceEnabled(success);
                 personInfo.setUpdateTime(new Date());
                 personInfoService.update(personInfo);
 

+ 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();
+        }
+
+    }
+
 }