Browse Source

人员上传设备成功与否逻辑修改

M墨鱼—_mo 5 years ago
parent
commit
40fc5ed5b7

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/DeviceInfoDAO.java

@@ -20,4 +20,6 @@ public interface DeviceInfoDAO {
 	List<DeviceInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
 	List<DeviceInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
 
 
 	DeviceInfo findByDeviceNo(String deviceNo);
 	DeviceInfo findByDeviceNo(String deviceNo);
+
+	List<DeviceInfo> listOnline();
 }
 }

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

@@ -19,4 +19,5 @@ public interface DeviceInfoService {
 	Page<DeviceInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize,boolean count, List<Sort> sortList);
 	Page<DeviceInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize,boolean count, List<Sort> sortList);
 	void updateByDeviceNo(String deviceNo, String ip);
 	void updateByDeviceNo(String deviceNo, String ip);
 
 
+	List<DeviceInfo> listOnline();
 }
 }

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

@@ -111,4 +111,9 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
 		}
 		}
 
 
 	}
 	}
+
+	@Override
+	public List<DeviceInfo> listOnline() {
+		return deviceInfoDAO.listOnline();
+	}
 }
 }

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

@@ -1,6 +1,7 @@
 package com.jpsoft.smart.modules.lapi.service;
 package com.jpsoft.smart.modules.lapi.service;
 
 
 import com.jpsoft.smart.modules.base.entity.DeviceInfo;
 import com.jpsoft.smart.modules.base.entity.DeviceInfo;
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
 import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
 import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
 import com.jpsoft.smart.modules.lapi.vo.LapiResult;
 import com.jpsoft.smart.modules.lapi.vo.LapiResult;
 
 
@@ -45,7 +46,7 @@ public interface ILapiService {
      * @return
      * @return
      * @throws Exception
      * @throws Exception
      */
      */
-     List<LapiMsgResult> addPersonForDeviceIds(Long id ,String deviceIds) throws Exception;
+     List<LapiResult> addPersonForDeviceIds(Long id ,String deviceIds) throws Exception;
 
 
     /**
     /**
      * 根据公司名称获取人脸库
      * 根据公司名称获取人脸库
@@ -127,6 +128,12 @@ public interface ILapiService {
     List<LapiResult> deleteDeviceAllCompanyLib(String deviceInfoId) throws Exception;
     List<LapiResult> deleteDeviceAllCompanyLib(String deviceInfoId) throws Exception;
 
 
 
 
+    /**
+     * 人员是否成功写入设备
+     * @param
+     * @return
+     */
+    Boolean isSuccessAddPerson(PersonInfo personInfo, DeviceInfo deviceInfo, String faceDbId);
 
 
 
 
 
 

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

@@ -144,15 +144,24 @@ public class LapiServiceImpl implements ILapiService {
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
                 JSONObject response = LApiUtil.getResponse(dataJson);
                 JSONObject response = LApiUtil.getResponse(dataJson);
                 if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
                 if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
+                    Boolean success = isSuccessAddPerson(personInfo,deviceInfo,faceDbId);
                     HashMap<String,Object> dataMap = new HashMap<>();
                     HashMap<String,Object> dataMap = new HashMap<>();
                     dataMap.put("deviceId",deviceInfo.getId());
                     dataMap.put("deviceId",deviceInfo.getId());
                     dataMap.put("deviceAliasName",deviceInfo.getAliasName());
                     dataMap.put("deviceAliasName",deviceInfo.getAliasName());
                     dataMap.put("persoName",personInfo.getName());
                     dataMap.put("persoName",personInfo.getName());
                     LapiResult lapiResult = new LapiResult();
                     LapiResult lapiResult = new LapiResult();
-                    lapiResult.setMsg("绑定成功");
-                    lapiResult.setSuccess(true);
-                    lapiResult.setData(dataMap);
-                    lapiResultList.add(lapiResult);
+                    if (success){
+                        lapiResult.setMsg("绑定成功");
+                        lapiResult.setSuccess(true);
+                        lapiResult.setData(dataMap);
+                        lapiResultList.add(lapiResult);
+                    }else {
+                        lapiResult.setMsg("绑定失败");
+                        lapiResult.setSuccess(false);
+                        lapiResult.setData(dataMap);
+                        lapiResultList.add(lapiResult);
+                    }
+
                 }
                 }
             } catch (Exception e) {
             } catch (Exception e) {
                 log.error(e.getMessage());
                 log.error(e.getMessage());
@@ -162,7 +171,7 @@ public class LapiServiceImpl implements ILapiService {
                 dataMap.put("persoName",personInfo.getName());
                 dataMap.put("persoName",personInfo.getName());
                 LapiResult lapiResult = new LapiResult();
                 LapiResult lapiResult = new LapiResult();
                 lapiResult.setSuccess(false);
                 lapiResult.setSuccess(false);
-                lapiResult.setMsg(e.getMessage());
+                lapiResult.setMsg(e.getMessage().contains("time out")?"设备连接超时":e.getMessage());
                 lapiResult.setData(dataMap);
                 lapiResult.setData(dataMap);
                 lapiResultList.add(lapiResult);
                 lapiResultList.add(lapiResult);
             }
             }
@@ -172,7 +181,7 @@ public class LapiServiceImpl implements ILapiService {
     }
     }
 
 
     @Override
     @Override
-    public List<LapiMsgResult> addPersonForDeviceIds(Long id, String deviceIds) throws Exception {
+    public List<LapiResult> addPersonForDeviceIds(Long id, String deviceIds) throws Exception {
         if (StringUtils.isBlank(deviceIds)){
         if (StringUtils.isBlank(deviceIds)){
             throw new Exception("设备为空");
             throw new Exception("设备为空");
         }
         }
@@ -181,7 +190,7 @@ public class LapiServiceImpl implements ILapiService {
         String base64Data = OSSUtil.downloadToBase64(personInfo.getFaceImageUrl());
         String base64Data = OSSUtil.downloadToBase64(personInfo.getFaceImageUrl());
 
 
         List<String> deviceIdList = Arrays.asList(deviceIds.split(","));
         List<String> deviceIdList = Arrays.asList(deviceIds.split(","));
-        List<LapiMsgResult> lapiMsgResults = new ArrayList<>();
+        List<LapiResult> lapiResultList = new ArrayList<>();
 
 
             for (String deviceId : deviceIdList) {
             for (String deviceId : deviceIdList) {
                 DeviceInfo deviceInfo = deviceInfoService.get(deviceId);
                 DeviceInfo deviceInfo = deviceInfoService.get(deviceId);
@@ -235,22 +244,39 @@ public class LapiServiceImpl implements ILapiService {
                     JSONObject dataJson = jsonObject.getJSONObject("Response");
                     JSONObject dataJson = jsonObject.getJSONObject("Response");
                     JSONObject response = LApiUtil.getResponse(dataJson);
                     JSONObject response = LApiUtil.getResponse(dataJson);
                     if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
                     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);
+                        Boolean success = isSuccessAddPerson(personInfo,deviceInfo,faceDbId);
+                        HashMap<String,Object> dataMap = new HashMap<>();
+                        dataMap.put("deviceId",deviceInfo.getId());
+                        dataMap.put("deviceAliasName",deviceInfo.getAliasName());
+                        dataMap.put("persoName",personInfo.getName());
+                        LapiResult lapiResult = new LapiResult();
+                        if (success){
+                            lapiResult.setMsg("绑定成功");
+                            lapiResult.setSuccess(true);
+                            lapiResult.setData(dataMap);
+                            lapiResultList.add(lapiResult);
+                        }else {
+                            lapiResult.setMsg("绑定失败");
+                            lapiResult.setSuccess(false);
+                            lapiResult.setData(dataMap);
+                            lapiResultList.add(lapiResult);
+                        }
+
+
                     }
                     }
 
 
 
 
                 }catch (Exception e){
                 }catch (Exception e){
-                    log.error(e.getMessage(),e);
-                    LapiMsgResult lapiMsgResult = new LapiMsgResult();
-                    lapiMsgResult.setAliasName(deviceInfo.getAliasName());
-                    lapiMsgResult.setMsg(e.getMessage());
-                    lapiMsgResult.setPersonName("");
-                    lapiMsgResult.setSuccess(false);
-                    lapiMsgResults.add(lapiMsgResult);
+                    log.error(e.getMessage());
+                    HashMap<String,Object> dataMap = new HashMap<>();
+                    dataMap.put("deviceId",deviceInfo.getId());
+                    dataMap.put("deviceAliasName",deviceInfo.getAliasName());
+                    dataMap.put("persoName",personInfo.getName());
+                    LapiResult lapiResult = new LapiResult();
+                    lapiResult.setSuccess(false);
+                    lapiResult.setMsg(e.getMessage().contains("time out")?"设备连接超时":e.getMessage());
+                    lapiResult.setData(dataMap);
+                    lapiResultList.add(lapiResult);
                 }
                 }
 
 
 
 
@@ -258,7 +284,7 @@ public class LapiServiceImpl implements ILapiService {
 
 
 
 
 
 
-        return lapiMsgResults;
+        return lapiResultList;
     }
     }
 
 
     @Override
     @Override
@@ -664,5 +690,35 @@ public class LapiServiceImpl implements ILapiService {
         return lapiResultList;
         return lapiResultList;
     }
     }
 
 
+    @Override
+    public Boolean isSuccessAddPerson(PersonInfo personInfo,DeviceInfo deviceInfo,String faceDbId) {
+        HashMap map = new HashMap();
+        map.put("Num", 1);
+        map.put("Limit",3);
+        map.put("Offset",0);
+        List list = new ArrayList();
+        HashMap map1 = new HashMap();
+        map1.put("QryType", 27);
+        map1.put("QryCondition", 0);
+        map1.put("QryData", personInfo.getId().toString());
+        list.add(map1);
+        map.put("QueryInfos", list);
+        try{
+            JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON +faceDbId +"/People/Info", map);
+            JSONObject dataJson = jsonObject.getJSONObject("Response");
+            JSONObject response = LApiUtil.getResponse(dataJson);
+            Integer num = response.getInteger("Total");
+            if (num >0){
+                return true;
+            }
+        }catch (Exception e){
+
+            return false;
+        }
+
+
+        return false;
+    }
+
 
 
 }
 }

+ 3 - 0
common/src/main/resources/mapper/base/DeviceInfo.xml

@@ -145,6 +145,9 @@ id_, header_,device_no,alias_name,address_,is_online,company_id,unlock_password,
 	<select id="list" resultMap="DeviceInfoMap">
 	<select id="list" resultMap="DeviceInfoMap">
 		select * from base_device_info where del_flag=false
 		select * from base_device_info where del_flag=false
 	</select>
 	</select>
+	<select id="listOnline" resultMap="DeviceInfoMap">
+		select * from base_device_info where is_online=true and del_flag=false
+	</select>
 	<select id="findByDeviceIdList"  resultMap="DeviceInfoMap">
 	<select id="findByDeviceIdList"  resultMap="DeviceInfoMap">
 		select * from base_device_info where del_flag=false and id_ in
 		select * from base_device_info where del_flag=false and id_ in
 		<foreach item="item" collection="list"  open="(" separator="," close=")">
 		<foreach item="item" collection="list"  open="(" separator="," close=")">

+ 29 - 5
lapi/src/main/java/com/jpsoft/smart/lapi/handler/PersonVerificationHandler.java

@@ -11,7 +11,11 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
+import sun.misc.BASE64Encoder;
 
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Date;
@@ -97,12 +101,32 @@ public class PersonVerificationHandler extends SimpleChannelInboundHandler<Perso
 
 
 
 
 
 
+    }
 
 
-
-
-
-
-
+    public static void main(String[] args) {
+        String imgStr = "";
+        try {
+
+            File file = new File("C:\\Users\\Administrator\\Desktop\\异常照片\\3.jpg");
+            FileInputStream fis = new FileInputStream(file);
+            byte[] buffer = new byte[(int) file.length()];
+            int offset = 0;
+            int numRead = 0;
+            while (offset < buffer.length && (numRead = fis.read(buffer, offset, buffer.length - offset)) >= 0) {
+                offset += numRead;
+            }
+
+            if (offset != buffer.length) {
+                throw new IOException("Could not completely read file "
+                        + file.getName());
+            }
+            fis.close();
+            BASE64Encoder encoder = new BASE64Encoder();
+            imgStr = encoder.encode(buffer);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        System.out.print(imgStr.length());
 
 
     }
     }
 }
 }

+ 23 - 26
web/src/main/java/com/jpsoft/smart/schduled/HeartbeatDetectionTask.java

@@ -28,42 +28,39 @@ public class HeartbeatDetectionTask {
     private ILapiService lapiService;
     private ILapiService lapiService;
 
 
     //每2分钟执行一次
     //每2分钟执行一次
-    @Scheduled(cron="0 0/1 * * * ?")
+    @Scheduled(cron = "0 0/2 * * * ?")
     public void run() {
     public void run() {
 
 
-        List<DeviceInfo> deviceInfoList = deviceInfoService.list();
-
-        for (DeviceInfo deviceInfo : deviceInfoList){
-            if (deviceInfo.getIsOnline() && deviceInfo.getHeartbeatUpdateTime() != null){
-                Long heartbeatUpdateTime = deviceInfo.getHeartbeatUpdateTime().getTime();
-                if (new Date().getTime() - heartbeatUpdateTime >2*60*1000){
-                    deviceInfo.setIsOnline(false);
-                    try{
-                        Boolean isKeepAlive = lapiService.keepAlive(deviceInfo.getId());
-                        if (isKeepAlive){
-                            deviceInfo.setAbnormalReason("设备可正常访问,但无心跳返回,请查看设备服务器配置");
-                        }else {
+        log.warn("设备在线定时任务启动");
+        List<DeviceInfo> deviceInfoList = deviceInfoService.listOnline();
+
+        if (deviceInfoList.size() > 0) {
+
+            for (DeviceInfo deviceInfo : deviceInfoList) {
+                if (deviceInfo.getHeartbeatUpdateTime() != null) {
+                    Long heartbeatUpdateTime = deviceInfo.getHeartbeatUpdateTime().getTime();
+                    if (new Date().getTime() - heartbeatUpdateTime > 2 * 60 * 1000) {
+                        deviceInfo.setIsOnline(false);
+                        try {
+                            Boolean isKeepAlive = lapiService.keepAlive(deviceInfo.getId());
+                            if (isKeepAlive) {
+                                deviceInfo.setAbnormalReason("设备可正常访问,但无心跳返回,请查看设备服务器配置");
+                            } else {
+                                deviceInfo.setAbnormalReason("设备离线");
+                            }
+                            deviceInfoService.update(deviceInfo);
+                        } catch (Exception e) {
                             deviceInfo.setAbnormalReason("设备离线");
                             deviceInfo.setAbnormalReason("设备离线");
+                            deviceInfoService.update(deviceInfo);
                         }
                         }
-                        deviceInfoService.update(deviceInfo);
-                    }catch (Exception e){
-                        deviceInfo.setAbnormalReason("设备离线");
-                        deviceInfoService.update(deviceInfo);
-                    }
 
 
+                    }
                 }
                 }
             }
             }
-        }
-
 
 
         }
         }
 
 
-    public static void main(String[] args) {
-
-    /*    String base64Data = OSSUtil.downloadToBase64("C:\\Users\\Administrator\\Desktop\\异常照片\\3.jpg");*/
-
-
-    //    System.out.println(base64Data.length());
     }
     }
 
 
+
 }
 }

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

@@ -184,5 +184,17 @@ public class LApiTest {
 
 
     }
     }
 
 
+    @Test
+    public void testIsSuccessAddPerson(){
+        try {
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            String message = e.getMessage();
+        }
+
+    }
+
 
 
 }
 }