|
@@ -306,62 +306,70 @@ public class HikiotTool {
|
|
|
* @Date 15:09 2025/8/15
|
|
* @Date 15:09 2025/8/15
|
|
|
**/
|
|
**/
|
|
|
public static String deleteExpiredVisitors(String deviceSerial) {
|
|
public static String deleteExpiredVisitors(String deviceSerial) {
|
|
|
- try {
|
|
|
|
|
- // 1. 查询访客信息
|
|
|
|
|
- String userInfoResponse = queryUserInfo(deviceSerial);
|
|
|
|
|
- JsonObject responseJson = JsonParser.parseString(userInfoResponse).getAsJsonObject();
|
|
|
|
|
|
|
+ // 1. 查询访客信息
|
|
|
|
|
+ String userInfoResponse = queryUserInfo(deviceSerial);
|
|
|
|
|
+ JsonObject responseJson = JsonParser.parseString(userInfoResponse).getAsJsonObject();
|
|
|
|
|
|
|
|
- if (responseJson.get("code").getAsInt() != 0) {
|
|
|
|
|
- throw new JeecgBootException("查询用户信息失败: " + responseJson.get("msg").getAsString());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ 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");
|
|
|
|
|
|
|
|
- // 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");
|
|
|
|
|
|
|
|
- for (JsonElement element : dataArray) {
|
|
|
|
|
- JsonObject user = element.getAsJsonObject();
|
|
|
|
|
- JsonObject valid = user.getAsJsonObject("Valid");
|
|
|
|
|
|
|
+ // 解析时间字段
|
|
|
|
|
+ String endTimeStr = valid.get("endTime").getAsString();
|
|
|
|
|
|
|
|
- // 解析时间字段
|
|
|
|
|
- String endTimeStr = valid.get("endTime").getAsString();
|
|
|
|
|
|
|
+ // 增加对空字符串的检查
|
|
|
|
|
+ if (endTimeStr == null || endTimeStr.isEmpty()) {
|
|
|
|
|
+ // 如果 endTime 为空,可以考虑将其视为已过期或跳过处理
|
|
|
|
|
+ expiredEmployees.add(user.get("employeeNo").getAsString());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
LocalDateTime endTime = LocalDateTime.parse(endTimeStr, DateTimeFormatter.ISO_DATE_TIME);
|
|
LocalDateTime endTime = LocalDateTime.parse(endTimeStr, DateTimeFormatter.ISO_DATE_TIME);
|
|
|
|
|
|
|
|
// 判断是否过期
|
|
// 判断是否过期
|
|
|
if (endTime.isBefore(now)) {
|
|
if (endTime.isBefore(now)) {
|
|
|
expiredEmployees.add(user.get("employeeNo").getAsString());
|
|
expiredEmployees.add(user.get("employeeNo").getAsString());
|
|
|
}
|
|
}
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 如果解析失败,可以记录日志或按业务需求处理
|
|
|
|
|
+ throw new JeecgBootException("时间解析失败: " + endTimeStr, e);
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 3. 构造删除请求体
|
|
|
|
|
- if (expiredEmployees.isEmpty()) {
|
|
|
|
|
- return "无过期访客需要删除";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- JsonObject requestJson = new JsonObject();
|
|
|
|
|
- requestJson.addProperty("deviceSerial", deviceSerial); // deviceSerial在顶层
|
|
|
|
|
|
|
+ // 3. 构造删除请求体
|
|
|
|
|
+ if (expiredEmployees.isEmpty()) {
|
|
|
|
|
+ return "无过期访客需要删除";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 创建payload对象
|
|
|
|
|
- JsonObject payload = new JsonObject();
|
|
|
|
|
- JsonArray userInfoArray = new JsonArray();
|
|
|
|
|
|
|
+ JsonObject requestJson = new JsonObject();
|
|
|
|
|
+ requestJson.addProperty("deviceSerial", deviceSerial); // deviceSerial在顶层
|
|
|
|
|
|
|
|
- // 添加userInfo数组
|
|
|
|
|
- for (String employeeNo : expiredEmployees) {
|
|
|
|
|
- JsonObject userInfoItem = new JsonObject();
|
|
|
|
|
- userInfoItem.addProperty("employeeNo", employeeNo);
|
|
|
|
|
- userInfoArray.add(userInfoItem);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 创建payload对象
|
|
|
|
|
+ JsonObject payload = new JsonObject();
|
|
|
|
|
+ JsonArray userInfoArray = new JsonArray();
|
|
|
|
|
|
|
|
- payload.add("userInfo", userInfoArray);
|
|
|
|
|
- requestJson.add("payload", payload); // payload作为顶层字段
|
|
|
|
|
|
|
+ // 添加userInfo数组
|
|
|
|
|
+ for (String employeeNo : expiredEmployees) {
|
|
|
|
|
+ JsonObject userInfoItem = new JsonObject();
|
|
|
|
|
+ userInfoItem.addProperty("employeeNo", employeeNo);
|
|
|
|
|
+ userInfoArray.add(userInfoItem);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 4. 发送删除请求
|
|
|
|
|
- return sendPostRequest(BATCH_DELETE_USER_URL, requestJson.toString(), setHeaders());
|
|
|
|
|
|
|
+ payload.add("userInfo", userInfoArray);
|
|
|
|
|
+ requestJson.add("payload", payload); // payload作为顶层字段
|
|
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- throw new JeecgBootException("删除过期访客失败", e);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 4. 发送删除请求
|
|
|
|
|
+ return sendPostRequest(BATCH_DELETE_USER_URL, requestJson.toString(), setHeaders());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -559,25 +567,6 @@ public class HikiotTool {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException, InterruptedException {
|
|
public static void main(String[] args) throws IOException, InterruptedException {
|
|
|
-// addUserPlanTemplate("FX0889961");
|
|
|
|
|
-// deleteExpiredVisitors("FX0889961");
|
|
|
|
|
-// queryUserInfo("FX0889961");
|
|
|
|
|
- addUserWeekPlan("FX0889961");
|
|
|
|
|
- addUser(new Date(),"FX0889961","Sheep","1999",null);
|
|
|
|
|
- addFace("FX0889961","1999","https://national-motion.oss-cn-beijing.aliyuncs.com/opt/upFiles/tmp_81fc8aa195d37dac70fd57221d82845e_1756361097600.jpg");
|
|
|
|
|
-// 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();
|
|
|
|
|
-// addFace();
|
|
|
|
|
-// addUserWeekPlan();
|
|
|
|
|
-// JsonObject root = JsonParser.parseString(HikiotTool.getAppAccessToken()).getAsJsonObject();
|
|
|
|
|
-// JsonObject data;
|
|
|
|
|
-// if (root.get("code").getAsInt() == 0) {
|
|
|
|
|
-// data = root.getAsJsonObject("data");
|
|
|
|
|
-// sendGetRequest(GET_USER_ACCESS_TOKEN_URL + AUTH_CODE + "FX0889961", data.get("appAccessToken").getAsString());
|
|
|
|
|
-// } else {
|
|
|
|
|
-// throw new JeecgBootException("海康API 请求失败: " + root.get("msg").getAsString());
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ deleteExpiredVisitors("FY2389353");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|