Parcourir la source

人员上传照片逻辑修改

M墨鱼—_mo il y a 5 ans
Parent
commit
d030886d3a

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

@@ -84,11 +84,12 @@ public class PersonDeviceLogServiceImpl implements PersonDeviceLogService {
             log.error("保存图片路径错误" + e.getMessage());
         }
 
+        Integer personId = LApiUtil.getPersonCode(libMatInfoListJson, matchPersonInfo);
 
         PersonDeviceLog personDeviceLog = new PersonDeviceLog();
         personDeviceLog.setId(UUID.randomUUID().toString());
         personDeviceLog.setDeviceNo(deviceNo);
-        personDeviceLog.setPersonId(LApiUtil.getPersonCode(libMatInfoListJson, matchPersonInfo));
+        personDeviceLog.setPersonId(personId);
 
         personDeviceLog.setTemperature(temperature);
         if (StringUtils.isNotBlank(libMatInfoListJson.getStr("MatchStatus"))) {
@@ -109,7 +110,7 @@ public class PersonDeviceLogServiceImpl implements PersonDeviceLogService {
         //人员识别成功,温度超过限定时发送模板消息给监管者
         new Thread(()->{
             try {
-                if (personDeviceLog.getPersonId() != 0) {
+                if (personId != 0) {
                     sendTemperatureAlarmsyncTask(personDeviceLog);
                 }
             }

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

@@ -95,48 +95,58 @@ public class LapiServiceImpl implements ILapiService {
 
         List<LapiResult> lapiResultList = new ArrayList<>();
         for (DeviceInfo deviceInfo : deviceList) {
-            HashMap<String, Object> map = new HashMap<>();
-            map.put("Num", 1L);
-            HashMap<String, Object> map1 = new HashMap<>();
-            map1.put("PersonID", personInfo.getId());
-            map1.put("LastChange", new Date().getTime());
-            map1.put("PersonCode", personInfo.getId().toString());
-            map1.put("PersonName", personInfo.getName() + "_" + personInfo.getId().toString());
-            map1.put("Remarks", companyInfo.getName());
-
-            //TimeTemplateNum 首字符必须大写
-            map1.put("TimeTemplateNum", 0L);
-
-            map1.put("IdentificationNum", 1L);
-            HashMap<String, Object> map2 = new HashMap<>();
-            List listMap2 = new ArrayList();
-            listMap2.add(map2);
-            map2.put("Type", 0L);
-            map2.put("Number", personInfo.getIdCard());
-            map1.put("IdentificationList", listMap2);
-            map1.put("ImageNum", 1L);
-
-            HashMap<String, Object> map3 = new HashMap<>();
-            map3.put("FaceID", personInfo.getId());
-            map3.put("Name", personInfo.getId() + ".jpg");
-
-            //照片base64长度
-            Integer imageSize = base64Data.length();
-            map3.put("Size", imageSize);
-            map3.put("Data", base64Data);
-            List listMap3 = new ArrayList();
-            listMap3.add(map3);
-            map1.put("ImageList", listMap3);
-            List listMap1 = new ArrayList();
-            listMap1.add(map1);
-            map.put("PersonInfoList", listMap1);
-
             try {
-                //照片字节大小
-                Integer fileSize = imageSize - (imageSize/8)*2;
-                if (fileSize > 512 * 1024 || fileSize < 10 * 1024) {
-                    throw new Exception("人员照片大小限定为10k~512k");
+                HashMap<String, Object> map = new HashMap<>();
+                map.put("Num", 1L);
+                HashMap<String, Object> map1 = new HashMap<>();
+                map1.put("PersonID", personInfo.getId());
+                map1.put("LastChange", new Date().getTime());
+                map1.put("PersonCode", personInfo.getId().toString());
+                map1.put("PersonName", personInfo.getName() + "_" + personInfo.getId().toString());
+                map1.put("Remarks", companyInfo.getName());
+
+                //TimeTemplateNum 首字符必须大写
+                map1.put("TimeTemplateNum", 0L);
+
+                map1.put("IdentificationNum", 1L);
+                HashMap<String, Object> map2 = new HashMap<>();
+                List listMap2 = new ArrayList();
+                listMap2.add(map2);
+                map2.put("Type", 0L);
+                map2.put("Number", personInfo.getIdCard());
+                map1.put("IdentificationList", listMap2);
+                map1.put("ImageNum", 1L);
+
+                HashMap<String, Object> map3 = new HashMap<>();
+                map3.put("FaceID", personInfo.getId());
+                map3.put("Name", personInfo.getId() + ".jpg");
+
+                if (StringUtils.isNotBlank(base64Data)){
+                    Integer imageSize = base64Data.length();
+                    //照片字节大小
+                    Integer fileSize = imageSize - (imageSize / 8) * 2;
+                    if (fileSize > 512 * 1024 || fileSize < 10 * 1024) {
+                        throw new Exception("人员照片大小限定为10k~512k");
+                    }
+                    map3.put("Size", imageSize);
+                    map3.put("Data", base64Data);
+                }
+                else {
+                    map3.put("Size", "");
+                    map3.put("Data", "");
                 }
+
+                //照片base64长度
+
+                List listMap3 = new ArrayList();
+                listMap3.add(map3);
+                map1.put("ImageList", listMap3);
+                List listMap1 = new ArrayList();
+                listMap1.add(map1);
+                map.put("PersonInfoList", listMap1);
+
+
+
                 //获取人员人脸库id
                 String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
 
@@ -144,18 +154,18 @@ public class LapiServiceImpl implements ILapiService {
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
                 JSONObject response = LApiUtil.getResponse(dataJson);
                 if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
-                    Boolean success = isSuccessAddPerson(personInfo,deviceInfo,faceDbId);
-                    HashMap<String,Object> dataMap = new HashMap<>();
-                    dataMap.put("deviceId",deviceInfo.getId());
-                    dataMap.put("deviceAliasName",deviceInfo.getAliasName());
-                    dataMap.put("personName",personInfo.getName());
+                    Boolean success = isSuccessAddPerson(personInfo, deviceInfo, faceDbId);
+                    HashMap<String, Object> dataMap = new HashMap<>();
+                    dataMap.put("deviceId", deviceInfo.getId());
+                    dataMap.put("deviceAliasName", deviceInfo.getAliasName());
+                    dataMap.put("personName", personInfo.getName());
                     LapiResult lapiResult = new LapiResult();
-                    if (success){
+                    if (success) {
                         lapiResult.setMsg("绑定成功");
                         lapiResult.setSuccess(true);
                         lapiResult.setData(dataMap);
                         lapiResultList.add(lapiResult);
-                    }else {
+                    } else {
                         lapiResult.setMsg("绑定失败");
                         lapiResult.setSuccess(false);
                         lapiResult.setData(dataMap);
@@ -165,13 +175,13 @@ public class LapiServiceImpl implements ILapiService {
                 }
             } catch (Exception e) {
                 log.error(e.getMessage());
-                HashMap<String,Object> dataMap = new HashMap<>();
-                dataMap.put("deviceId",deviceInfo.getId());
-                dataMap.put("deviceAliasName",deviceInfo.getAliasName());
-                dataMap.put("personName",personInfo.getName());
+                HashMap<String, Object> dataMap = new HashMap<>();
+                dataMap.put("deviceId", deviceInfo.getId());
+                dataMap.put("deviceAliasName", deviceInfo.getAliasName());
+                dataMap.put("personName", personInfo.getName());
                 LapiResult lapiResult = new LapiResult();
                 lapiResult.setSuccess(false);
-                lapiResult.setMsg(e.getMessage().contains("timed out")?"设备连接超时":e.getMessage());
+                lapiResult.setMsg(e.getMessage().contains("timed out") ? "设备连接超时" : e.getMessage());
                 lapiResult.setData(dataMap);
                 lapiResultList.add(lapiResult);
             }
@@ -182,7 +192,7 @@ public class LapiServiceImpl implements ILapiService {
 
     @Override
     public List<LapiResult> addPersonForDeviceIds(Long id, String deviceIds) throws Exception {
-        if (StringUtils.isBlank(deviceIds)){
+        if (StringUtils.isBlank(deviceIds)) {
             throw new Exception("设备为空");
         }
         PersonInfo personInfo = personInfoService.get(id);
@@ -192,97 +202,96 @@ public class LapiServiceImpl implements ILapiService {
         List<String> deviceIdList = Arrays.asList(deviceIds.split(","));
         List<LapiResult> lapiResultList = new ArrayList<>();
 
-            for (String deviceId : deviceIdList) {
-                DeviceInfo deviceInfo = deviceInfoService.get(deviceId);
-                try {
-                    HashMap<String, Object> map = new HashMap<>();
-                    map.put("Num", 1L);
-                    HashMap<String, Object> map1 = new HashMap<>();
-                    map1.put("PersonID", personInfo.getId());
-                    map1.put("LastChange", new Date().getTime());
-                    map1.put("PersonCode", personInfo.getId().toString());
-                    map1.put("PersonName", personInfo.getName() + "_" + personInfo.getId().toString());
-                    map1.put("Remarks", companyInfo.getName());
-
-                    //TimeTemplateNum 首字符必须大写
-                    map1.put("TimeTemplateNum", 0L);
-
-                    map1.put("IdentificationNum", 1L);
-                    HashMap<String, Object> map2 = new HashMap<>();
-                    List listMap2 = new ArrayList();
-                    listMap2.add(map2);
-                    map2.put("Type", 0L);
-                    map2.put("Number", personInfo.getIdCard());
-                    map1.put("IdentificationList", listMap2);
-                    map1.put("ImageNum", 1L);
-
-                    HashMap<String, Object> map3 = new HashMap<>();
-                    map3.put("FaceID", personInfo.getId());
-                    map3.put("Name", personInfo.getId() + ".jpg");
-
-                    //照片base64长度
-                    Integer imageSize = base64Data.length();
-                    map3.put("Size", imageSize);
-                    map3.put("Data", base64Data);
-                    List listMap3 = new ArrayList();
-                    listMap3.add(map3);
-                    map1.put("ImageList", listMap3);
-                    List listMap1 = new ArrayList();
-                    listMap1.add(map1);
-                    map.put("PersonInfoList", listMap1);
-
-                    //照片字节大小
-                    Integer fileSize = imageSize - (imageSize/8)*2;
+        for (String deviceId : deviceIdList) {
+            DeviceInfo deviceInfo = deviceInfoService.get(deviceId);
+            try {
+                HashMap<String, Object> map = new HashMap<>();
+                map.put("Num", 1L);
+                HashMap<String, Object> map1 = new HashMap<>();
+                map1.put("PersonID", personInfo.getId());
+                map1.put("LastChange", new Date().getTime());
+                map1.put("PersonCode", personInfo.getId().toString());
+                map1.put("PersonName", personInfo.getName() + "_" + personInfo.getId().toString());
+                map1.put("Remarks", companyInfo.getName());
+
+                //TimeTemplateNum 首字符必须大写
+                map1.put("TimeTemplateNum", 0L);
+
+                map1.put("IdentificationNum", 1L);
+                HashMap<String, Object> map2 = new HashMap<>();
+                List listMap2 = new ArrayList();
+                listMap2.add(map2);
+                map2.put("Type", 0L);
+                map2.put("Number", personInfo.getIdCard());
+                map1.put("IdentificationList", listMap2);
+                map1.put("ImageNum", 1L);
+
+                HashMap<String, Object> map3 = new HashMap<>();
+                map3.put("FaceID", personInfo.getId());
+                map3.put("Name", personInfo.getId() + ".jpg");
+
+                //照片base64长度
+                Integer imageSize = base64Data.length();
+                map3.put("Size", imageSize);
+                map3.put("Data", base64Data);
+                List listMap3 = new ArrayList();
+                listMap3.add(map3);
+                map1.put("ImageList", listMap3);
+                List listMap1 = new ArrayList();
+                listMap1.add(map1);
+                map.put("PersonInfoList", listMap1);
 
-                    if (fileSize > 512 * 1024 || fileSize < 10 * 1024) {
-                        throw new Exception("人员照片大小限定为10k~512k");
-                    }
-                    //获取人员人脸库id
-                    String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
-
-                    JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON + faceDbId + "/People", map);
-                    JSONObject dataJson = jsonObject.getJSONObject("Response");
-                    JSONObject response = LApiUtil.getResponse(dataJson);
-                    if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
-                        Boolean success = isSuccessAddPerson(personInfo,deviceInfo,faceDbId);
-                        HashMap<String,Object> dataMap = new HashMap<>();
-                        dataMap.put("deviceId",deviceInfo.getId());
-                        dataMap.put("deviceAliasName",deviceInfo.getAliasName());
-                        dataMap.put("personName",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);
-                        }
+                //照片字节大小
+                Integer fileSize = imageSize - (imageSize / 8) * 2;
 
+                if (fileSize > 512 * 1024 || fileSize < 10 * 1024) {
+                    throw new Exception("人员照片大小限定为10k~512k");
+                }
+                //获取人员人脸库id
+                String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
 
+                JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON + faceDbId + "/People", map);
+                JSONObject dataJson = jsonObject.getJSONObject("Response");
+                JSONObject response = LApiUtil.getResponse(dataJson);
+                if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
+                    Boolean success = isSuccessAddPerson(personInfo, deviceInfo, faceDbId);
+                    HashMap<String, Object> dataMap = new HashMap<>();
+                    dataMap.put("deviceId", deviceInfo.getId());
+                    dataMap.put("deviceAliasName", deviceInfo.getAliasName());
+                    dataMap.put("personName", 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){
-                    log.error(e.getMessage());
-                    HashMap<String,Object> dataMap = new HashMap<>();
-                    dataMap.put("deviceId",deviceInfo.getId());
-                    dataMap.put("deviceAliasName",deviceInfo.getAliasName());
-                    dataMap.put("personName",personInfo.getName());
-                    LapiResult lapiResult = new LapiResult();
-                    lapiResult.setSuccess(false);
-                    lapiResult.setMsg(e.getMessage().contains("timed out")?"设备连接超时":e.getMessage());
-                    lapiResult.setData(dataMap);
-                    lapiResultList.add(lapiResult);
                 }
 
 
+            } catch (Exception e) {
+                log.error(e.getMessage());
+                HashMap<String, Object> dataMap = new HashMap<>();
+                dataMap.put("deviceId", deviceInfo.getId());
+                dataMap.put("deviceAliasName", deviceInfo.getAliasName());
+                dataMap.put("personName", personInfo.getName());
+                LapiResult lapiResult = new LapiResult();
+                lapiResult.setSuccess(false);
+                lapiResult.setMsg(e.getMessage().contains("timed out") ? "设备连接超时" : e.getMessage());
+                lapiResult.setData(dataMap);
+                lapiResultList.add(lapiResult);
             }
 
 
+        }
+
 
         return lapiResultList;
     }
@@ -322,8 +331,7 @@ public class LapiServiceImpl implements ILapiService {
 
 
             }
-        }
-        else {
+        } else {
             faceDbId = getDefaultLib(deviceInfo.getId());
         }
 
@@ -691,11 +699,11 @@ public class LapiServiceImpl implements ILapiService {
     }
 
     @Override
-    public Boolean isSuccessAddPerson(PersonInfo personInfo,DeviceInfo deviceInfo,String faceDbId) {
+    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);
+        map.put("Limit", 3);
+        map.put("Offset", 0);
         List list = new ArrayList();
         HashMap map1 = new HashMap();
         map1.put("QryType", 27);
@@ -703,15 +711,15 @@ public class LapiServiceImpl implements ILapiService {
         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);
+        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){
+            if (num > 0) {
                 return true;
             }
-        }catch (Exception e){
+        } catch (Exception e) {
 
             return false;
         }