From 28407987700ab62540ff61c12098ab50f31ca546 Mon Sep 17 00:00:00 2001
From: shinnosuke <tantao@1hoper.com>
Date: 星期四, 13 八月 2026 16:15:23 +0800
Subject: [PATCH] fix(family-card): 修正管理页面并支持解绑

---
 talent-card-server/src/main/java/com/talentcard/server/service/DependentCardApplyAdminService.java |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/talent-card-server/src/main/java/com/talentcard/server/service/DependentCardApplyAdminService.java b/talent-card-server/src/main/java/com/talentcard/server/service/DependentCardApplyAdminService.java
index f4feb26..05d5cdb 100644
--- a/talent-card-server/src/main/java/com/talentcard/server/service/DependentCardApplyAdminService.java
+++ b/talent-card-server/src/main/java/com/talentcard/server/service/DependentCardApplyAdminService.java
@@ -50,10 +50,16 @@
 			Integer status,
 			LocalDate applyStart,
 			LocalDate applyEnd,
+			boolean management,
 			int page,
 			int size
 	) {
 		validateStatusFilter(status);
+		if (management && status != null
+				&& status != DependentCardApply.STATUS_APPROVED
+				&& status != DependentCardApply.STATUS_CANCELLED) {
+			throw new BusinessException(ErrorCode.BAD_REQUEST, "家属卡管理状态只能为正常或已解绑");
+		}
 		if (applyStart != null && applyEnd != null && applyStart.isAfter(applyEnd)) {
 			throw new BusinessException(ErrorCode.BAD_REQUEST, "申请开始时间不能晚于结束时间");
 		}
@@ -62,6 +68,8 @@
 		LambdaQueryWrapper<DependentCardApply> query = Wrappers.<DependentCardApply>lambdaQuery()
 				.eq(talentCardId != null, DependentCardApply::getTalentCardId, talentCardId)
 				.eq(status != null, DependentCardApply::getStatus, status)
+				.in(management && status == null, DependentCardApply::getStatus,
+						DependentCardApply.STATUS_APPROVED, DependentCardApply.STATUS_CANCELLED)
 				.eq(cardLevel != null && !cardLevel.isBlank(), DependentCardApply::getCardLevel, trimToNull(cardLevel))
 				.and(familyKeyword != null && !familyKeyword.isBlank(), wrapper -> wrapper
 						.like(DependentCardApply::getDependentName, familyKeyword.trim())
@@ -165,6 +173,40 @@
 		return DependentCardApplyAdminResponse.from(updatedApply, applicationExtra(updatedApply));
 	}
 
+	@Transactional
+	public DependentCardApplyAdminResponse unbind(Long id, Long operatorId) {
+		DependentCardApply apply = mapper.selectByIdForUpdate(id);
+		if (apply == null) {
+			throw new BusinessException(ErrorCode.NOT_FOUND, "家属卡不存在");
+		}
+		if (!Integer.valueOf(DependentCardApply.STATUS_APPROVED).equals(apply.getStatus())) {
+			throw new BusinessException(ErrorCode.CONFLICT, "仅正常状态的家属卡可以解除绑定");
+		}
+		int updated = mapper.update(
+				null,
+				Wrappers.<DependentCardApply>lambdaUpdate()
+						.eq(DependentCardApply::getId, id)
+						.eq(DependentCardApply::getStatus, DependentCardApply.STATUS_APPROVED)
+						.set(DependentCardApply::getStatus, DependentCardApply.STATUS_CANCELLED)
+		);
+		if (updated != 1) {
+			throw new BusinessException(ErrorCode.CONFLICT, "家属卡状态已变化,请刷新后重试");
+		}
+		if (statusLogMapper.insert(new DependentCardApplyStatusLog(
+				apply.getId(),
+				apply.getApplyNo(),
+				DependentCardApply.STATUS_APPROVED,
+				DependentCardApply.STATUS_CANCELLED,
+				"ADMIN",
+				operatorId,
+				"管理后台解除绑定"
+		)) != 1) {
+			throw new BusinessException(ErrorCode.INTERNAL_ERROR, "解绑状态记录保存失败");
+		}
+		DependentCardApply updatedApply = mapper.selectById(id);
+		return DependentCardApplyAdminResponse.from(updatedApply, applicationExtra(updatedApply));
+	}
+
 	private Map<String, Object> applicationExtra(DependentCardApply apply) {
 		if (apply == null || apply.getTalentCardId() == null) {
 			return Map.of();

--
Gitblit v1.7.1