|
|
@@ -1,35 +1,76 @@
|
|
|
package com.izouma.wenlvju.service;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.kevinsawicki.http.HttpRequest;
|
|
|
import com.izouma.wenlvju.domain.ExamRoom;
|
|
|
import com.izouma.wenlvju.dto.PageQuery;
|
|
|
import com.izouma.wenlvju.exception.BusinessException;
|
|
|
import com.izouma.wenlvju.repo.ExamRoomRepo;
|
|
|
+import com.izouma.wenlvju.repo.RecordExamRoomRepo;
|
|
|
import com.izouma.wenlvju.utils.JpaUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.core.env.Environment;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class ExamRoomService {
|
|
|
|
|
|
- private final ExamRoomRepo examRoomRepo;
|
|
|
- private final EzvizTokenService ezvizTokenService;
|
|
|
+ private final ExamRoomRepo examRoomRepo;
|
|
|
+ private final EzvizTokenService ezvizTokenService;
|
|
|
+ private final RecordExamRoomRepo recordExamRoomRepo;
|
|
|
|
|
|
public Page<ExamRoom> all(PageQuery pageQuery) {
|
|
|
return examRoomRepo.findAll(JpaUtils.toSpecification(pageQuery, ExamRoom.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
|
|
|
|
- public void addDevice(ExamRoom examRoom) {
|
|
|
+ /*
|
|
|
+ 查看设备列表
|
|
|
+ */
|
|
|
+ public List<String> showDevice() {
|
|
|
+ String uri = "https://open.ys7.com/api/lapp/device/list";
|
|
|
+ String accessToken = ezvizTokenService.getToken();
|
|
|
+ String send = "accessToken=" + accessToken + "&pageStart=0&pageSize=10";
|
|
|
+ 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"))) {
|
|
|
+ throw new BusinessException(json.getString("msg"));
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray data = JSONObject.parseArray(json.getString("data"));
|
|
|
+ List<String> devices = new ArrayList<>();
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ JSONObject jsonObject = data.getJSONObject(i);
|
|
|
+ String name = jsonObject.getString("deviceSerial");
|
|
|
+ devices.add(name);
|
|
|
+ }
|
|
|
+ return devices;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ 添加设备
|
|
|
+ */
|
|
|
+ public void addDevice(String deviceSerial, String validateCode) {
|
|
|
+ List<String> devices = this.showDevice();
|
|
|
+ if (devices.contains(deviceSerial)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
String uri = "https://open.ys7.com/api/lapp/device/add";
|
|
|
String accessToken = ezvizTokenService.getToken();
|
|
|
- String deviceSerial = examRoom.getDeviceSerial();
|
|
|
- String validateCode = examRoom.getValidateCode();
|
|
|
String send = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial + "&validateCode=" + validateCode;
|
|
|
log.info("萤石添加设备--->" + send);
|
|
|
|
|
|
@@ -37,16 +78,18 @@ public class ExamRoomService {
|
|
|
log.info("萤石添加设备返回--->" + body);
|
|
|
|
|
|
JSONObject json = JSONObject.parseObject(body);
|
|
|
- if (!"200".equals(json.getString("code"))){
|
|
|
+ if (!"200".equals(json.getString("code"))) {
|
|
|
throw new BusinessException(json.getString("msg"));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void delDevice(ExamRoom examRoom) {
|
|
|
+ /*
|
|
|
+ 删除设备
|
|
|
+ */
|
|
|
+ public void delDevice(String deviceSerial) {
|
|
|
String uri = "https://open.ys7.com/api/lapp/device/delete";
|
|
|
|
|
|
String accessToken = ezvizTokenService.getToken();
|
|
|
- String deviceSerial = examRoom.getDeviceSerial();
|
|
|
|
|
|
String send = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial;
|
|
|
log.info("萤石删除设备--->" + send);
|
|
|
@@ -55,8 +98,65 @@ public class ExamRoomService {
|
|
|
log.info("萤石删除设备返回--->" + body);
|
|
|
|
|
|
JSONObject json = JSONObject.parseObject(body);
|
|
|
- if (!"200".equals(json.getString("code"))){
|
|
|
+ if (!"200".equals(json.getString("code"))) {
|
|
|
throw new BusinessException(json.getString("msg"));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /*
|
|
|
+ 开启设备加密
|
|
|
+ */
|
|
|
+ public void encryptOn(String deviceSerial) {
|
|
|
+ String uri = "https://open.ys7.com/api/lapp/device/encrypt/on";
|
|
|
+
|
|
|
+ String accessToken = ezvizTokenService.getToken();
|
|
|
+
|
|
|
+ String send = "accessToken=" + accessToken + "&deviceSerial=" + deviceSerial;
|
|
|
+ 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"))) {
|
|
|
+ throw new BusinessException(json.getString("msg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ 关闭设备加密
|
|
|
+ */
|
|
|
+ public void encryptOff(String deviceSerial, String validateCode) {
|
|
|
+
|
|
|
+ String uri = "https://open.ys7.com/api/lapp/device/encrypt/off";
|
|
|
+ String accessToken = ezvizTokenService.getToken();
|
|
|
+ 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"))) {
|
|
|
+ throw new BusinessException(json.getString("msg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ 按recordId查找考场
|
|
|
+ */
|
|
|
+ public Page<ExamRoom> byRecord(Long recordId, PageQuery pageQuery) {
|
|
|
+ List<Long> ids = recordExamRoomRepo.findIdByRecordId(recordId);
|
|
|
+ if (CollUtil.isEmpty(ids)) {
|
|
|
+ return new PageImpl<>(new ArrayList<>(), JpaUtils.toPageRequest(pageQuery), 0);
|
|
|
+ }
|
|
|
+ examRoomRepo.findAll((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> and = JpaUtils.toPredicates(pageQuery, ExamRoom.class, root, criteriaQuery, criteriaBuilder);
|
|
|
+ and.add(root.get("id").in(ids));
|
|
|
+ JpaUtils.toSpecification(pageQuery, ExamRoom.class);
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|