licailing 4 жил өмнө
parent
commit
54d2512919

+ 36 - 0
src/main/java/com/izouma/wenlvju/service/ExamRoomService.java

@@ -92,6 +92,28 @@ public class ExamRoomService {
         }
     }
 
+    /*
+   添加设备
+    */
+    public void addDevice1(String deviceSerial, String validateCode) {
+        String accessToken = ezvizTokenService.getToken();
+        String uri = "https://open.ys7.com/api/lapp/device/add";
+        String send = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&validateCode=" + validateCode;
+        log.info("萤石添加设备--->" + send);
+
+        String body = HttpRequest.post(uri).send(send).body();
+        log.info("萤石添加设备返回--->" + body);
+
+        JSONObject json = JSONObject.parseObject(body);
+        if (!"200".equals(json.getString("code")) && !"20017".equals(json.getString("code"))) {
+            throw new BusinessException(json.getString("msg"));
+        }
+        // 解密设备
+        this.encryptOff1(deviceSerial, validateCode, accessToken);
+
+    }
+
+
     /*
     删除设备
      */
@@ -171,6 +193,20 @@ public class ExamRoomService {
         }
     }
 
+    public void encryptOff1(String deviceSerial, String validateCode, String accessToken) {
+        String uri = "https://open.ys7.com/api/lapp/device/encrypt/off";
+        String send = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&validateCode=" + validateCode;
+        log.info("萤石关闭设备加密--->" + send);
+
+        String body = HttpRequest.post(uri).send(send).body();
+        log.info("萤石关闭设备加密返回--->" + body);
+
+        JSONObject json = JSONObject.parseObject(body);
+        if (!"200".equals(json.getString("code")) && !"60016".equals(json.getString("code"))) {
+            throw new BusinessException(json.getString("msg"));
+        }
+    }
+
     /*
     展示今天备案中的所有考场信息
      */

+ 2 - 2
src/main/java/com/izouma/wenlvju/web/ExamRoomController.java

@@ -38,14 +38,14 @@ public class ExamRoomController extends BaseController {
             ExamRoom orig = examRoomRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
             if (StrUtil.isNotBlank(deviceSerial) && StrUtil.isNotBlank(validateCode) && !deviceSerial.equals(orig.getDeviceSerial())) {
                 // 添加设备
-                examRoomService.addDevice(deviceSerial, validateCode);
+                examRoomService.addDevice1(deviceSerial, validateCode);
             }
             ObjUtils.merge(orig, record);
             return examRoomRepo.save(orig);
         }
         if (StrUtil.isNotBlank(deviceSerial) && StrUtil.isNotBlank(validateCode)) {
             // 添加设备
-            examRoomService.addDevice(deviceSerial, validateCode);
+            examRoomService.addDevice1(deviceSerial, validateCode);
         }
         return examRoomRepo.save(record);
     }