Skip to content

Commit 3343ab3

Browse files
refactor(WhitelistApiController): 简化时间戳解析逻辑
将原有的多行时间戳解析代码简化为三元表达式形式,保持功能一致但代码更简洁。 移除了不必要的try-catch块,使代码更易读。
1 parent 0f891b0 commit 3343ab3

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

src/main/java/com/xaoxiao/convenientaccess/api/WhitelistApiController.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -391,18 +391,10 @@ public void handleBatchOperation(HttpServletRequest request, HttpServletResponse
391391
}
392392

393393
// 解析时间戳(可选)
394-
LocalDateTime addedAt;
395-
if (json.has("added_at")) {
396-
try {
397-
String addedAtStr = json.get("added_at").getAsString();
398-
addedAt = LocalDateTime.parse(addedAtStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
399-
} catch (Exception e) {
400-
sendJsonResponse(response, 400, ApiResponse.badRequest("无效的时间格式,请使用ISO格式: " + e.getMessage()));
401-
return;
402-
}
403-
} else {
404-
addedAt = LocalDateTime.now();
405-
}
394+
LocalDateTime addedAt = json.has("added_at") ?
395+
LocalDateTime.parse(json.get("added_at").getAsString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME) :
396+
LocalDateTime.now();
397+
406398

407399
if (playersArray.size() == 0) {
408400
sendJsonResponse(response, 400, ApiResponse.badRequest("玩家列表不能为空"));

0 commit comments

Comments
 (0)