|
@@ -1,6 +1,8 @@
|
|
|
package org.jeecg.modules.hikiot;
|
|
|
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import com.google.gson.JsonArray;
|
|
|
+import com.google.gson.JsonElement;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.google.gson.JsonParser;
|
|
|
import org.jeecg.common.exception.JeecgBootException;
|
|
@@ -18,6 +20,7 @@ import java.nio.charset.StandardCharsets;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
|
|
|
import static com.alibaba.dashscope.utils.JsonUtils.gson;
|
|
@@ -293,8 +296,63 @@ public class HikiotTool {
|
|
|
* @Description 删除已过期的访客
|
|
|
* @Date 15:09 2025/8/15
|
|
|
**/
|
|
|
- public static String deleteExpiredVisitors(String deviceSerial){
|
|
|
- return sendPostRequest(QUERY_USER_INFO_URL, gson.toJson(queryUserInfo(deviceSerial)),setHeaders());
|
|
|
+ public static String deleteExpiredVisitors(String deviceSerial) {
|
|
|
+ try {
|
|
|
+ // 1. 查询访客信息
|
|
|
+ String userInfoResponse = queryUserInfo(deviceSerial);
|
|
|
+ JsonObject responseJson = JsonParser.parseString(userInfoResponse).getAsJsonObject();
|
|
|
+
|
|
|
+ if (responseJson.get("code").getAsInt() != 0) {
|
|
|
+ throw new JeecgBootException("查询用户信息失败: " + responseJson.get("msg").getAsString());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 解析并筛选过期访客
|
|
|
+ List<String> expiredEmployees = new ArrayList<>();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ JsonArray dataArray = responseJson.getAsJsonArray("data");
|
|
|
+
|
|
|
+ for (JsonElement element : dataArray) {
|
|
|
+ JsonObject user = element.getAsJsonObject();
|
|
|
+ JsonObject valid = user.getAsJsonObject("Valid");
|
|
|
+
|
|
|
+ // 解析时间字段
|
|
|
+ String endTimeStr = valid.get("endTime").getAsString();
|
|
|
+ LocalDateTime endTime = LocalDateTime.parse(endTimeStr, DateTimeFormatter.ISO_DATE_TIME);
|
|
|
+
|
|
|
+ // 判断是否过期
|
|
|
+ if (endTime.isBefore(now)) {
|
|
|
+ expiredEmployees.add(user.get("employeeNo").getAsString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 构造删除请求体
|
|
|
+ if (expiredEmployees.isEmpty()) {
|
|
|
+ return "无过期访客需要删除";
|
|
|
+ }
|
|
|
+
|
|
|
+ JsonObject requestJson = new JsonObject();
|
|
|
+ requestJson.addProperty("deviceSerial", deviceSerial); // deviceSerial在顶层
|
|
|
+
|
|
|
+ // 创建payload对象
|
|
|
+ JsonObject payload = new JsonObject();
|
|
|
+ JsonArray userInfoArray = new JsonArray();
|
|
|
+
|
|
|
+ // 添加userInfo数组
|
|
|
+ for (String employeeNo : expiredEmployees) {
|
|
|
+ JsonObject userInfoItem = new JsonObject();
|
|
|
+ userInfoItem.addProperty("employeeNo", employeeNo);
|
|
|
+ userInfoArray.add(userInfoItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ payload.add("userInfo", userInfoArray);
|
|
|
+ requestJson.add("payload", payload); // payload作为顶层字段
|
|
|
+
|
|
|
+ // 4. 发送删除请求
|
|
|
+ return sendPostRequest(BATCH_DELETE_USER_URL, requestJson.toString(), setHeaders());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new JeecgBootException("删除过期访客失败", e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -486,8 +544,8 @@ public class HikiotTool {
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) throws IOException, InterruptedException {
|
|
|
- queryUserInfo("FX0889961");
|
|
|
-// addUser(new Date(),"FX0889961","Sheep","1001");
|
|
|
+ deleteExpiredVisitors("FX0889961");
|
|
|
+// addUser(new Date(),"FX0889961","Sheep123","10011");
|
|
|
// addFace("FX0889961","1001","https://national-motion.oss-cn-beijing.aliyuncs.com/opt/upFiles/tmp_81fc8aa195d37dac70fd57221d82845e_1756361097600.jpg");
|
|
|
// addUser();
|
|
|
// addUserPlanTemplate();
|