소스 검색

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

zhengqiang 5 년 전
부모
커밋
53e8fc3779

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

@@ -17,7 +17,7 @@ import java.util.HashMap;
 public class LApiUtil {
     private final static int TIMEOUT = 10*1000;
 
-    public static JSONObject PostRequest(String url,HashMap map){
+    public static JSONObject postRequest(String url, HashMap map){
         String body = HttpRequest.post(url)
                 .timeout(TIMEOUT)
                 .body(new JSONObject(map).toJSONString()).execute().body();
@@ -25,7 +25,7 @@ public class LApiUtil {
         return jsonbody;
     }
 
-    public static JSONObject GetRequest(String url) throws Exception{
+    public static JSONObject getRequest(String url) throws Exception{
         String body = HttpRequest.get(url)
                 .timeout(TIMEOUT)
                 .execute().body();
@@ -34,7 +34,7 @@ public class LApiUtil {
         return jsonbody;
     }
 
-    public static JSONObject DeleteRequest(String url) {
+    public static JSONObject deleteRequest(String url) {
        String body = HttpRequest.delete(url)
                .timeout(TIMEOUT)
                .execute().body();

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

@@ -58,4 +58,11 @@ public class LApiConstant {
     public static final String UPDATALIBRARY = "/LAPI/V1.0/PeopleLibraries/BasicInfo";
 
 
+    /**
+     * 设备验证规则
+     */
+    public static final String RULE = "/LAPI/V1.0/PACS/Controller/AttributeVerification/Rule";
+
+
+
 }

+ 25 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/service/ILapiService.java

@@ -4,8 +4,11 @@ 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.LapiResult;
+import com.sun.org.apache.xpath.internal.operations.Bool;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author 墨鱼_mo
@@ -135,7 +138,29 @@ public interface ILapiService {
      */
     Boolean isSuccessAddPerson(PersonInfo personInfo, DeviceInfo deviceInfo, String faceDbId);
 
+    /**
+     * 获取设备的验证规则
+     * @param deviceInfoId
+     * @return
+     * @throws Exception
+     */
+    Map<String,Object> getDeviceRule(String deviceInfoId) throws Exception;
+
 
+    /**
+     * 设置设备的验证规则
+     * @param deviceInfoId 设备id
+     * @param needCap 安全帽验证 (0:不验证,1:验证)
+     * @param needMask 口罩验证 (0:不验证,1:验证)
+     * @param measureTemperature 测试验证 (0:不验证,1:验证)
+     * @param type 测试验证类型 (0:测额温,1:测腕温)
+     * @param minTemper 温度下限
+     * @param maxTemper 温度上限
+     * @param alarmThreshold 报警温度
+     * @return
+     * @throws Exception
+     */
+    Boolean setDeviceRule(String deviceInfoId, Integer needCap, Integer needMask, Integer measureTemperature, Integer type, BigDecimal minTemper,BigDecimal maxTemper,BigDecimal alarmThreshold) throws Exception;
 
 
 }

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

@@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.*;
 
 /**
@@ -45,7 +46,7 @@ public class LapiServiceImpl implements ILapiService {
 
     @Override
     public DeviceInfo findByIpAddressAndPort(String ipAddress, String port) throws Exception {
-        JSONObject jsonObject = LApiUtil.GetRequest(ipAddress + ":" + port + LApiConstant.DEVICEBASICINFO);
+        JSONObject jsonObject = LApiUtil.getRequest(ipAddress + ":" + port + LApiConstant.DEVICEBASICINFO);
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
         DeviceInfo deviceInfo = new DeviceInfo();
@@ -64,7 +65,7 @@ public class LapiServiceImpl implements ILapiService {
         if (deviceInfo == null) {
             throw new Exception("设备未绑定");
         }
-        JSONObject jsonObject = LApiUtil.GetRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.KEEPALIVE);
+        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.KEEPALIVE);
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         return true;
     }
@@ -120,7 +121,7 @@ public class LapiServiceImpl implements ILapiService {
                 HashMap<String, Object> map3 = new HashMap<>();
 
 
-                if (StringUtils.isNotBlank(base64Data)){
+                if (StringUtils.isNotBlank(base64Data)) {
 
                     Integer imageSize = base64Data.length();
                     //照片字节大小
@@ -133,8 +134,7 @@ public class LapiServiceImpl implements ILapiService {
                     map3.put("Data", base64Data);
                     map3.put("FaceID", personInfo.getId());
                     map3.put("Name", personInfo.getId() + ".jpg");
-                }
-                else {
+                } else {
                     map1.put("ImageNum", 0);
                     map3.put("FaceID", 0);
                     map3.put("Name", "");
@@ -152,11 +152,10 @@ public class LapiServiceImpl implements ILapiService {
                 map.put("PersonInfoList", listMap1);
 
 
-
                 //获取人员人脸库id
                 String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
 
-                JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON + faceDbId + "/People", map);
+                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) {
@@ -235,8 +234,7 @@ public class LapiServiceImpl implements ILapiService {
                 HashMap<String, Object> map3 = new HashMap<>();
 
 
-
-                if (StringUtils.isNotBlank(base64Data)){
+                if (StringUtils.isNotBlank(base64Data)) {
                     map1.put("ImageNum", 1L);
                     //照片base64长度
                     Integer imageSize = base64Data.length();
@@ -251,8 +249,7 @@ public class LapiServiceImpl implements ILapiService {
                     if (fileSize > 512 * 1024 || fileSize < 10 * 1024) {
                         throw new Exception("人员照片大小限定为10k~512k");
                     }
-                }
-                else {
+                } else {
                     map1.put("ImageNum", 0);
                     map3.put("FaceID", 0);
                     map3.put("Name", "");
@@ -271,7 +268,7 @@ public class LapiServiceImpl implements ILapiService {
                 //获取人员人脸库id
                 String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
 
-                JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON + faceDbId + "/People", map);
+                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) {
@@ -323,7 +320,7 @@ public class LapiServiceImpl implements ILapiService {
             throw new Exception("公司名称为空");
         }
         String faceDbId = "";
-        JSONObject jsonObject = LApiUtil.GetRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.GETFACEDB);
+        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.GETFACEDB);
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
         List listData = response.getJSONArray("LibList");
@@ -365,7 +362,7 @@ public class LapiServiceImpl implements ILapiService {
             throw new Exception("公司名称为空");
         }
         String faceDbId = "";
-        JSONObject jsonObject = LApiUtil.GetRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.GETFACEDB);
+        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.GETFACEDB);
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
         List listData = response.getJSONArray("LibList");
@@ -414,7 +411,7 @@ public class LapiServiceImpl implements ILapiService {
             try {
                 //获取人员人脸库id
                 String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
-                JSONObject jsonObject = LApiUtil.DeleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETEPERSON + faceDbId + "/People/" + personInfo.getId() + "?LastChange=" + new Date().getTime());
+                JSONObject jsonObject = LApiUtil.deleteRequest(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) {
@@ -462,7 +459,7 @@ public class LapiServiceImpl implements ILapiService {
             DeviceInfo deviceInfo = deviceInfoService.get(deviceId);
             try {
                 String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
-                JSONObject jsonObject = LApiUtil.DeleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETEPERSON + faceDbId + "/People/" + personInfo.getId() + "?LastChange=" + new Date().getTime());
+                JSONObject jsonObject = LApiUtil.deleteRequest(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) {
@@ -548,7 +545,7 @@ public class LapiServiceImpl implements ILapiService {
                 map.put("MemberNum", 0);
                 map.put("Name", companyInfo.getName());
                 map.put("Type", 3);
-                JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDLIBRARY, map);
+                JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDLIBRARY, map);
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
                 JSONObject response = LApiUtil.getResponse(dataJson);
                 lapiResult.setMsg("添加成功");
@@ -594,7 +591,7 @@ public class LapiServiceImpl implements ILapiService {
             map.put("MemberNum", 0);
             map.put("Name", "默认员工库");
             map.put("Type", 3);
-            JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDLIBRARY, map);
+            JSONObject jsonObject = LApiUtil.postRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDLIBRARY, map);
             JSONObject dataJson = jsonObject.getJSONObject("Response");
             JSONObject response = LApiUtil.getResponse(dataJson);
             return response.getString("ID");
@@ -621,7 +618,7 @@ public class LapiServiceImpl implements ILapiService {
 
         LapiResult lapiResult = new LapiResult();
         try {
-            JSONObject jsonObject = LApiUtil.DeleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETELIBRARY + libraryId);
+            JSONObject jsonObject = LApiUtil.deleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETELIBRARY + libraryId);
             JSONObject dataJson = jsonObject.getJSONObject("Response");
             JSONObject response = LApiUtil.getResponse(dataJson);
             lapiResult.setSuccess(true);
@@ -690,7 +687,7 @@ public class LapiServiceImpl implements ILapiService {
         if (deviceInfo == null) {
             throw new Exception("设备不存在");
         }
-        JSONObject jsonObject = LApiUtil.GetRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.UPDATALIBRARY);
+        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.UPDATALIBRARY);
         JSONObject dataJson = jsonObject.getJSONObject("Response");
         JSONObject response = LApiUtil.getResponse(dataJson);
         List<LibraryVo> list = JSONObject.parseArray(response.getString("LibList"), LibraryVo.class);
@@ -701,7 +698,7 @@ public class LapiServiceImpl implements ILapiService {
         for (LibraryVo libraryVo : list) {
             LapiResult lapiResult = new LapiResult();
             try {
-                JSONObject jsonObject1 = LApiUtil.DeleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETELIBRARY + libraryVo.getID());
+                JSONObject jsonObject1 = LApiUtil.deleteRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.DELETELIBRARY + libraryVo.getID());
                 JSONObject dataJson1 = jsonObject1.getJSONObject("Response");
                 JSONObject response1 = LApiUtil.getResponse(dataJson1);
                 lapiResult.setSuccess(true);
@@ -733,7 +730,7 @@ public class LapiServiceImpl implements ILapiService {
         list.add(map1);
         map.put("QueryInfos", list);
         try {
-            JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON + faceDbId + "/People/Info", map);
+            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");
@@ -749,5 +746,70 @@ public class LapiServiceImpl implements ILapiService {
         return false;
     }
 
+    @Override
+    public Map<String, Object> getDeviceRule(String deviceInfoId) throws Exception {
+
+        DeviceInfo deviceInfo = deviceInfoService.get(deviceInfoId);
+        if (deviceInfo == null) {
+            throw new Exception("设备不存在");
+        }
+        if (!deviceInfo.getIsOnline()) {
+            throw new Exception("设备离校,请联系管理员");
+        }
+        JSONObject jsonObject = LApiUtil.getRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.RULE);
+        JSONObject dataJson = jsonObject.getJSONObject("Response");
+        JSONObject response = LApiUtil.getResponse(dataJson);
+        return response;
+    }
+
+    @Override
+    public Boolean setDeviceRule(String deviceInfoId, Integer needCap, Integer needMask, Integer measureTemperature, Integer type, BigDecimal minTemper, BigDecimal maxTemper, BigDecimal alarmThreshold) throws Exception {
+        DeviceInfo deviceInfo = deviceInfoService.get(deviceInfoId);
+        if (deviceInfo == null) {
+            throw new Exception("设备不存在");
+        }
+        if (!deviceInfo.getIsOnline()) {
+            throw new Exception("设备离校,请联系管理员");
+        }
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("Num", 3);
+        List list = new ArrayList();
+        //安全帽数据
+        HashMap<String, Object> map1 = new HashMap<>();
+        map1.put("DoorOpenMode", 0);
+        map1.put("Mode", 1);
+        map1.put("Enabled", needCap);
+        //口罩数据
+        HashMap<String, Object> map2 = new HashMap<>();
+        map2.put("DoorOpenMode", 0);
+        map2.put("Mode", 2);
+        map2.put("Enabled", needMask);
+        //测温数据
+        HashMap<String, Object> map3 = new HashMap<>();
+        map3.put("DoorOpenMode", 0);
+        map3.put("Mode", 3);
+        map3.put("Enabled", measureTemperature);
+        list.add(map1);
+        list.add(map2);
+        list.add(map3);
+        map.put("RuleList",list);
+        if (measureTemperature == 1) {
+            HashMap<String, Object> temperatureMap = new HashMap<>();
+            temperatureMap.put("Type", type);
+            temperatureMap.put("Minimum", minTemper);
+            temperatureMap.put("Maximum", maxTemper);
+            temperatureMap.put("AlarmThreshold", alarmThreshold);
+            map.put("TemperatureRule", temperatureMap);
+        }
+
+
+        JSONObject jsonObject = LApiUtil.putRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.RULE, map);
+        JSONObject dataJson = jsonObject.getJSONObject("Response");
+        JSONObject response = LApiUtil.getResponse(dataJson);
+        return true;
+
+
+    }
+
 
 }

+ 32 - 4
web/src/test/java/com/jpsoft/smart/LApiTest.java

@@ -1,5 +1,6 @@
 package com.jpsoft.smart;
 
+import cn.hutool.json.JSONObject;
 import com.jpsoft.smart.modules.base.dao.PersonInfoDAO;
 import com.jpsoft.smart.modules.base.dao.WarningPusherDAO;
 import com.jpsoft.smart.modules.base.dto.PersonDeviceLogDTO;
@@ -12,6 +13,7 @@ import com.jpsoft.smart.modules.base.service.impl.PersonDeviceLogServiceImpl;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.common.utils.WechatMessageUtil;
 import com.jpsoft.smart.modules.lapi.service.ILapiService;
+import com.jpsoft.smart.modules.lapi.service.impl.LapiServiceImpl;
 import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
 import com.jpsoft.smart.modules.lapi.vo.LapiResult;
 import org.junit.Test;
@@ -20,10 +22,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.math.BigDecimal;
+import java.util.*;
 
 /**
  * @author 墨鱼_mo
@@ -218,5 +218,33 @@ public class LApiTest {
 
     }
 
+    @Test
+    public void testgetDeviceRule(){
+        try {
+
+            Map<String,Object> map= lapiService.getDeviceRule("32acfc7d-e7d4-4ebb-8170-035d00dc92a8");
+
+            System.out.println(map);
+        } catch (Exception e) {
+            e.printStackTrace();
+            String message = e.getMessage();
+        }
+
+    }
+
+    @Test
+    public void testSetDeviceRule(){
+        try {
+
+           Boolean success = lapiService.setDeviceRule("32acfc7d-e7d4-4ebb-8170-035d00dc92a8",0,1,1,1,new BigDecimal(30),new BigDecimal(45),new BigDecimal(37.3));
+
+            System.out.println(success);
+        } catch (Exception e) {
+            e.printStackTrace();
+            String message = e.getMessage();
+        }
+
+    }
+
 
 }