package com.talentcard.server.response; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Map; import com.talentcard.server.entity.DependentCardApply; import io.swagger.v3.oas.annotations.media.Schema; @Schema(name = "DependentCardApplyAdminResponse", description = "管理后台家属附属卡申请信息") public record DependentCardApplyAdminResponse( Long id, String applyNo, String applicationNo, Long talentId, Long talentCardId, String talentName, String talentMobile, String talentIdCardNo, Integer gender, String contactAddress, String workAddress, String talentCardNo, String cardLevel, LocalDate validStart, LocalDate validEnd, LocalDateTime issueTime, Integer familyCardLimit, Integer currentFamilyCardCount, String dependentName, String familyName, String dependentMobile, String familyMobile, String dependentIdCardNo, String idCardNo, String relation, String relationship, String proofFiles, Integer status, String statusText, LocalDateTime applyTime, Long auditBy, String auditorName, LocalDateTime auditTime, String auditRemark, LocalDateTime createdAt, LocalDateTime updatedAt ) { public static DependentCardApplyAdminResponse from(DependentCardApply apply) { return from(apply, Map.of()); } public static DependentCardApplyAdminResponse from(DependentCardApply apply, Map extra) { String applyNo = apply.getApplyNo(); String dependentName = apply.getDependentName(); String dependentMobile = apply.getDependentMobile(); String dependentIdCardNo = apply.getDependentIdCardNo(); String relation = apply.getRelation(); return new DependentCardApplyAdminResponse( apply.getId(), applyNo, applyNo, apply.getTalentId(), apply.getTalentCardId(), apply.getTalentName(), apply.getTalentMobile(), string(extra.get("talentIdCardNo")), integer(extra.get("gender")), string(extra.get("contactAddress")), string(extra.get("workAddress")), apply.getTalentCardNo(), apply.getCardLevel(), date(extra.get("validStart")), date(extra.get("validEnd")), dateTime(extra.get("issueTime")), integer(extra.get("familyCardLimit")), integer(extra.get("currentFamilyCardCount")), dependentName, dependentName, dependentMobile, dependentMobile, dependentIdCardNo, dependentIdCardNo, relation, relation, apply.getProofFiles(), apply.getStatus(), statusText(apply.getStatus()), apply.getApplyTime(), apply.getAuditBy(), string(extra.get("auditorName")), apply.getAuditTime(), apply.getAuditRemark(), apply.getCreatedAt(), apply.getUpdatedAt() ); } private static String statusText(Integer status) { if (status == null) return "未知"; return switch (status) { case DependentCardApply.STATUS_PENDING_REVIEW -> "待审核"; case DependentCardApply.STATUS_APPROVED -> "已通过"; case DependentCardApply.STATUS_REJECTED -> "已驳回"; case DependentCardApply.STATUS_CANCELLED -> "已取消"; default -> "未知"; }; } private static String string(Object value) { return value == null ? null : String.valueOf(value); } private static Integer integer(Object value) { if (value instanceof Number number) return number.intValue(); if (value == null) return null; try { return Integer.valueOf(String.valueOf(value)); } catch (NumberFormatException ex) { return null; } } private static LocalDate date(Object value) { if (value instanceof LocalDate localDate) return localDate; if (value == null) return null; return LocalDate.parse(String.valueOf(value)); } private static LocalDateTime dateTime(Object value) { if (value instanceof LocalDateTime localDateTime) return localDateTime; if (value == null) return null; return LocalDateTime.parse(String.valueOf(value).replace(' ', 'T')); } }