记得上下班打卡 | git大法好,push需谨慎

Commit 6230abef authored by 姜秀龙's avatar 姜秀龙

同一演出仅需补签一次即可领取同场次所有徽章,审核也是

parent 75c196d8
package com.liquidnet.service.adam.service.impl; package com.liquidnet.service.adam.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liquidnet.commons.lang.util.IDGenerator; import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.adam.dto.AdamCaomeiPassportUserBadgeDto; import com.liquidnet.service.adam.dto.AdamCaomeiPassportUserBadgeDto;
...@@ -30,6 +31,7 @@ import java.util.ArrayList; ...@@ -30,6 +31,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j @Slf4j
...@@ -111,13 +113,19 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi ...@@ -111,13 +113,19 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi
String idCard = real.getIdCard(); String idCard = real.getIdCard();
List<String> paidPerformanceIds = adamRdmService.getPaidPerformanceIdsByIdCard(idCard); List<String> paidPerformanceIds = adamRdmService.getPaidPerformanceIdsByIdCard(idCard);
boolean hasPaidRecord = paidPerformanceIds != null && paidPerformanceIds.contains(badge.getPerformanceId()); boolean hasPaidRecord = paidPerformanceIds != null && paidPerformanceIds.contains(badge.getPerformanceId());
String perfId = StringUtils.trimToEmpty(badge.getPerformanceId());
boolean hasPassedApply;
if (StringUtils.isNotBlank(perfId)) {
hasPassedApply = countApplyForUserPerformanceAudit(uid, perfId, 1) > 0;
} else {
Integer passedApplyCount = badgeApplyRecordMapper.selectCount( Integer passedApplyCount = badgeApplyRecordMapper.selectCount(
Wrappers.lambdaQuery(AdamCaomeiBadgeApplyRecord.class) Wrappers.lambdaQuery(AdamCaomeiBadgeApplyRecord.class)
.eq(AdamCaomeiBadgeApplyRecord::getUserId, uid) .eq(AdamCaomeiBadgeApplyRecord::getUserId, uid)
.eq(AdamCaomeiBadgeApplyRecord::getBadgeId, badgeId) .eq(AdamCaomeiBadgeApplyRecord::getBadgeId, badgeId)
.eq(AdamCaomeiBadgeApplyRecord::getAuditStatus, 1) .eq(AdamCaomeiBadgeApplyRecord::getAuditStatus, 1)
); );
boolean hasPassedApply = passedApplyCount != null && passedApplyCount > 0; hasPassedApply = passedApplyCount != null && passedApplyCount > 0;
}
if (!hasPaidRecord && !hasPassedApply) { if (!hasPaidRecord && !hasPassedApply) {
log.error("[claimBadge] 无购票记录且无通过的补签申请,无法认领, uid: {}, badgeId: {}", uid, badgeId); log.error("[claimBadge] 无购票记录且无通过的补签申请,无法认领, uid: {}, badgeId: {}", uid, badgeId);
...@@ -215,19 +223,25 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi ...@@ -215,19 +223,25 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi
return ResponseDto.failure(ErrorMapping.get("10608")); return ResponseDto.failure(ErrorMapping.get("10608"));
} }
String performanceId = StringUtils.trimToEmpty(badge.getPerformanceId());
int pendingApply;
if (StringUtils.isNotBlank(performanceId)) {
pendingApply = countApplyForUserPerformanceAudit(uid, performanceId, 0);
} else {
Integer pendingCount = badgeApplyRecordMapper.selectCount( Integer pendingCount = badgeApplyRecordMapper.selectCount(
Wrappers.lambdaQuery(AdamCaomeiBadgeApplyRecord.class) Wrappers.lambdaQuery(AdamCaomeiBadgeApplyRecord.class)
.eq(AdamCaomeiBadgeApplyRecord::getUserId, uid) .eq(AdamCaomeiBadgeApplyRecord::getUserId, uid)
.eq(AdamCaomeiBadgeApplyRecord::getBadgeId, badgeId) .eq(AdamCaomeiBadgeApplyRecord::getBadgeId, badgeId)
.eq(AdamCaomeiBadgeApplyRecord::getAuditStatus, 0) .eq(AdamCaomeiBadgeApplyRecord::getAuditStatus, 0)
); );
if (pendingCount != null && pendingCount > 0) { pendingApply = pendingCount == null ? 0 : pendingCount;
return ResponseDto.failure("您已有待审核的补签申请,请勿重复提交"); }
if (pendingApply > 0) {
return ResponseDto.failure("该场次已有待审核的补签申请,请勿重复提交");
} }
final String applyRecordId = IDGenerator.nextSnowId(); final String applyRecordId = IDGenerator.nextSnowId();
long t = System.currentTimeMillis(); long t = System.currentTimeMillis();
String performanceId = StringUtils.trimToEmpty(badge.getPerformanceId());
boolean autoPass = isPerformanceOngoing(performanceId); boolean autoPass = isPerformanceOngoing(performanceId);
if (autoPass) { if (autoPass) {
// 与 admin 审核通过保持一致:仅将申请记录标记为已通过,不自动发放徽章 // 与 admin 审核通过保持一致:仅将申请记录标记为已通过,不自动发放徽章
...@@ -256,6 +270,49 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi ...@@ -256,6 +270,49 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi
return ResponseDto.success(applyRecordId); return ResponseDto.success(applyRecordId);
} }
/**
* 同场次 type=2 徽章 ID(用于补签记录 performance_id 为空等历史数据的 OR 查询)。
*/
private Set<String> type2BadgeIdsForPerformance(String performanceId) {
if (StringUtils.isBlank(performanceId)) {
return Collections.emptySet();
}
List<AdamCaomeiBadge> list = adamCaomeiBadgeMapper.selectList(
Wrappers.lambdaQuery(AdamCaomeiBadge.class)
.eq(AdamCaomeiBadge::getType, 2)
.eq(AdamCaomeiBadge::getPerformanceId, performanceId));
if (list == null || list.isEmpty()) {
return Collections.emptySet();
}
return list.stream()
.map(AdamCaomeiBadge::getBadgeId)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toSet());
}
/**
* 用户对某场次是否存在指定审核状态的补签记录(按 performance_id 或同场徽章 ID 命中)。
*/
private int countApplyForUserPerformanceAudit(String uid, String performanceId, int auditStatus) {
if (StringUtils.isBlank(performanceId)) {
return 0;
}
Set<String> samePerfBadgeIds = type2BadgeIdsForPerformance(performanceId);
LambdaQueryWrapper<AdamCaomeiBadgeApplyRecord> qw =
Wrappers.lambdaQuery(AdamCaomeiBadgeApplyRecord.class)
.eq(AdamCaomeiBadgeApplyRecord::getUserId, uid)
.eq(AdamCaomeiBadgeApplyRecord::getAuditStatus, auditStatus);
if (samePerfBadgeIds.isEmpty()) {
qw.eq(AdamCaomeiBadgeApplyRecord::getPerformanceId, performanceId);
} else {
qw.and(w -> w.eq(AdamCaomeiBadgeApplyRecord::getPerformanceId, performanceId)
.or()
.in(AdamCaomeiBadgeApplyRecord::getBadgeId, samePerfBadgeIds));
}
Integer n = badgeApplyRecordMapper.selectCount(qw);
return n == null ? 0 : n;
}
private boolean isPerformanceOngoing(String performanceId) { private boolean isPerformanceOngoing(String performanceId) {
if (StringUtils.isBlank(performanceId)) { if (StringUtils.isBlank(performanceId)) {
return false; return false;
......
...@@ -194,7 +194,12 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse ...@@ -194,7 +194,12 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse
: new ArrayList<>(); : new ArrayList<>();
log.info("[getPassportHome] 用户已支付的演出订单数量, uid: {}, 数量: {}", uid, paidPerformanceIds.size()); log.info("[getPassportHome] 用户已支付的演出订单数量, uid: {}, 数量: {}", uid, paidPerformanceIds.size());
ApplyBadgeStatus applyBadgeStatus = loadApplyBadgeStatus(uid); // 先取上架徽章配置(供补签状态按演出聚合时做 badgeId→performanceId 兜底)
List<AdamCaomeiBadge> published = adamRdmService.getPublishedCaomeiBadges();
if (published == null) {
published = new ArrayList<>();
}
ApplyBadgeStatus applyBadgeStatus = loadApplyBadgeStatus(uid, published);
// 6. 查询用户已认领的所有徽章记录 (用于展示徽章墙) // 6. 查询用户已认领的所有徽章记录 (用于展示徽章墙)
List<AdamCaomeiPassportUserBadgeDto> rows = adamRdmService.getUserCaomeiBadgesByUid(uid); List<AdamCaomeiPassportUserBadgeDto> rows = adamRdmService.getUserCaomeiBadgesByUid(uid);
...@@ -209,11 +214,6 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse ...@@ -209,11 +214,6 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse
// 转换为 Map 方便后续匹配货架上的徽章是否已认领 // 转换为 Map 方便后续匹配货架上的徽章是否已认领
Map<String, AdamCaomeiPassportUserBadgeDto> claimedMap = toClaimedBadgeMap(rows); Map<String, AdamCaomeiPassportUserBadgeDto> claimedMap = toClaimedBadgeMap(rows);
// 7. 查询所有已上架的徽章配置,并按类型升序、排序值降序、ID降序排序
List<AdamCaomeiBadge> published = adamRdmService.getPublishedCaomeiBadges();
if (published == null) {
published = new ArrayList<>();
}
log.info("[getPassportHome] 系统已上架的徽章数量, uid: {}, 数量: {}", uid, published.size()); log.info("[getPassportHome] 系统已上架的徽章数量, uid: {}, 数量: {}", uid, published.size());
// 演出纪念徽章:批量查演出名称,供前端按演出分组展示 // 演出纪念徽章:批量查演出名称,供前端按演出分组展示
...@@ -224,8 +224,7 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse ...@@ -224,8 +224,7 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse
published, published,
claimedMap, claimedMap,
paidPerformanceIds, paidPerformanceIds,
applyBadgeStatus.passedApplyBadgeIds, applyBadgeStatus,
applyBadgeStatus.pendingApplyBadgeIds,
performanceTitleById performanceTitleById
); );
...@@ -258,7 +257,15 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse ...@@ -258,7 +257,15 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse
return card; return card;
} }
private ApplyBadgeStatus loadApplyBadgeStatus(String uid) { private ApplyBadgeStatus loadApplyBadgeStatus(String uid, List<AdamCaomeiBadge> published) {
Map<String, String> badgeIdToPerformanceId = new HashMap<>();
if (published != null) {
for (AdamCaomeiBadge b : published) {
if (b != null && StringUtils.isNotBlank(b.getBadgeId())) {
badgeIdToPerformanceId.put(b.getBadgeId(), StringUtils.trimToEmpty(b.getPerformanceId()));
}
}
}
List<AdamCaomeiBadgeApplyRecord> applyRecords = badgeApplyRecordMapper.selectList( List<AdamCaomeiBadgeApplyRecord> applyRecords = badgeApplyRecordMapper.selectList(
Wrappers.lambdaQuery(AdamCaomeiBadgeApplyRecord.class) Wrappers.lambdaQuery(AdamCaomeiBadgeApplyRecord.class)
.eq(AdamCaomeiBadgeApplyRecord::getUserId, uid) .eq(AdamCaomeiBadgeApplyRecord::getUserId, uid)
...@@ -266,17 +273,34 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse ...@@ -266,17 +273,34 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse
); );
Set<String> passedApplyBadgeIds = new HashSet<>(); Set<String> passedApplyBadgeIds = new HashSet<>();
Set<String> pendingApplyBadgeIds = new HashSet<>(); Set<String> pendingApplyBadgeIds = new HashSet<>();
Set<String> passedApplyPerformanceIds = new HashSet<>();
Set<String> pendingApplyPerformanceIds = new HashSet<>();
for (AdamCaomeiBadgeApplyRecord r : applyRecords) { for (AdamCaomeiBadgeApplyRecord r : applyRecords) {
if (r == null || StringUtils.isBlank(r.getBadgeId()) || r.getAuditStatus() == null) { if (r == null || StringUtils.isBlank(r.getBadgeId()) || r.getAuditStatus() == null) {
continue; continue;
} }
String perf = StringUtils.trimToEmpty(r.getPerformanceId());
if (StringUtils.isBlank(perf)) {
perf = StringUtils.trimToEmpty(badgeIdToPerformanceId.get(r.getBadgeId()));
}
if (r.getAuditStatus() == 1) { if (r.getAuditStatus() == 1) {
passedApplyBadgeIds.add(r.getBadgeId()); passedApplyBadgeIds.add(r.getBadgeId());
if (StringUtils.isNotBlank(perf)) {
passedApplyPerformanceIds.add(perf);
}
} else if (r.getAuditStatus() == 0) { } else if (r.getAuditStatus() == 0) {
pendingApplyBadgeIds.add(r.getBadgeId()); pendingApplyBadgeIds.add(r.getBadgeId());
if (StringUtils.isNotBlank(perf)) {
pendingApplyPerformanceIds.add(perf);
} }
} }
return new ApplyBadgeStatus(passedApplyBadgeIds, pendingApplyBadgeIds); }
return new ApplyBadgeStatus(
passedApplyBadgeIds,
pendingApplyBadgeIds,
passedApplyPerformanceIds,
pendingApplyPerformanceIds
);
} }
private static List<AdamCaomeiPassportUserClaimedBadgeVo> toClaimedBadgeVos(List<AdamCaomeiPassportUserBadgeDto> rows, private static List<AdamCaomeiPassportUserClaimedBadgeVo> toClaimedBadgeVos(List<AdamCaomeiPassportUserBadgeDto> rows,
...@@ -351,11 +375,10 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse ...@@ -351,11 +375,10 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse
private static List<AdamCaomeiPassportBadgeShelfItemVo> toShelfItems(List<AdamCaomeiBadge> published, private static List<AdamCaomeiPassportBadgeShelfItemVo> toShelfItems(List<AdamCaomeiBadge> published,
Map<String, AdamCaomeiPassportUserBadgeDto> claimedMap, Map<String, AdamCaomeiPassportUserBadgeDto> claimedMap,
List<String> paidPerformanceIds, List<String> paidPerformanceIds,
Set<String> passedApplyBadgeIds, ApplyBadgeStatus applyBadgeStatus,
Set<String> pendingApplyBadgeIds,
Map<String, String> performanceTitleById) { Map<String, String> performanceTitleById) {
return published.stream() return published.stream()
.map(b -> toShelfItem(b, claimedMap, paidPerformanceIds, passedApplyBadgeIds, pendingApplyBadgeIds, performanceTitleById)) .map(b -> toShelfItem(b, claimedMap, paidPerformanceIds, applyBadgeStatus, performanceTitleById))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
...@@ -363,16 +386,14 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse ...@@ -363,16 +386,14 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse
* @param b 徽章信息 * @param b 徽章信息
* @param claimedMap 用户已领取的徽章 * @param claimedMap 用户已领取的徽章
* @param paidPerformanceIds 当前账号实名身份证号码购买的演出IDs * @param paidPerformanceIds 当前账号实名身份证号码购买的演出IDs
* @param passedApplyBadgeIds 补签审核已通过的徽章ID集合 * @param applyBadgeStatus 补签审核状态(按徽章 + 按同场次演出聚合)
* @param pendingApplyBadgeIds 补签待审核的徽章ID集合
* @param performanceTitleById 演出 ID → 演出名称(仅 type=2 使用) * @param performanceTitleById 演出 ID → 演出名称(仅 type=2 使用)
* @return * @return
*/ */
private static AdamCaomeiPassportBadgeShelfItemVo toShelfItem(AdamCaomeiBadge b, private static AdamCaomeiPassportBadgeShelfItemVo toShelfItem(AdamCaomeiBadge b,
Map<String, AdamCaomeiPassportUserBadgeDto> claimedMap, Map<String, AdamCaomeiPassportUserBadgeDto> claimedMap,
List<String> paidPerformanceIds, List<String> paidPerformanceIds,
Set<String> passedApplyBadgeIds, ApplyBadgeStatus applyBadgeStatus,
Set<String> pendingApplyBadgeIds,
Map<String, String> performanceTitleById) { Map<String, String> performanceTitleById) {
AdamCaomeiPassportBadgeShelfItemVo v = new AdamCaomeiPassportBadgeShelfItemVo(); AdamCaomeiPassportBadgeShelfItemVo v = new AdamCaomeiPassportBadgeShelfItemVo();
v.setBadgeId(b.getBadgeId()); v.setBadgeId(b.getBadgeId());
...@@ -402,11 +423,16 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse ...@@ -402,11 +423,16 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse
// 护照纪念徽章:只要绑定了护照,就可认领(通常是绑定时漏发或后来新上架的) // 护照纪念徽章:只要绑定了护照,就可认领(通常是绑定时漏发或后来新上架的)
v.setClaimable(true); v.setClaimable(true);
} else if (type == 2) { } else if (type == 2) {
// 演出纪念徽章:有购票记录或补签审核通过即可认领 // 演出纪念徽章:有购票记录,或本场次任一补签审核通过,则本场次关联徽章均可认领
boolean canClaimByPaid = paidPerformanceIds != null && paidPerformanceIds.contains(b.getPerformanceId()); boolean canClaimByPaid = paidPerformanceIds != null && paidPerformanceIds.contains(b.getPerformanceId());
boolean canClaimByApply = passedApplyBadgeIds != null && passedApplyBadgeIds.contains(b.getBadgeId()); boolean canClaimByApplyThisBadge = applyBadgeStatus.getPassedApplyBadgeIds().contains(b.getBadgeId());
v.setClaimable(canClaimByPaid || canClaimByApply); boolean canClaimByApplyThisPerf = StringUtils.isNotBlank(perfId)
v.setApplyPending(pendingApplyBadgeIds != null && pendingApplyBadgeIds.contains(b.getBadgeId())); && applyBadgeStatus.getPassedApplyPerformanceIds().contains(perfId);
v.setClaimable(canClaimByPaid || canClaimByApplyThisBadge || canClaimByApplyThisPerf);
boolean pendingThisBadge = applyBadgeStatus.getPendingApplyBadgeIds().contains(b.getBadgeId());
boolean pendingThisPerf = StringUtils.isNotBlank(perfId)
&& applyBadgeStatus.getPendingApplyPerformanceIds().contains(perfId);
v.setApplyPending(pendingThisBadge || pendingThisPerf);
} else if (type == 3) { } else if (type == 3) {
// 特殊徽章:不可自助领取,需要提示用户 // 特殊徽章:不可自助领取,需要提示用户
v.setClaimable(false); v.setClaimable(false);
...@@ -433,10 +459,33 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse ...@@ -433,10 +459,33 @@ public class AdamCaomeiPassportUserServiceImpl implements IAdamCaomeiPassportUse
private static final class ApplyBadgeStatus { private static final class ApplyBadgeStatus {
private final Set<String> passedApplyBadgeIds; private final Set<String> passedApplyBadgeIds;
private final Set<String> pendingApplyBadgeIds; private final Set<String> pendingApplyBadgeIds;
private final Set<String> passedApplyPerformanceIds;
private final Set<String> pendingApplyPerformanceIds;
private ApplyBadgeStatus(Set<String> passedApplyBadgeIds, Set<String> pendingApplyBadgeIds) { private ApplyBadgeStatus(Set<String> passedApplyBadgeIds,
Set<String> pendingApplyBadgeIds,
Set<String> passedApplyPerformanceIds,
Set<String> pendingApplyPerformanceIds) {
this.passedApplyBadgeIds = passedApplyBadgeIds; this.passedApplyBadgeIds = passedApplyBadgeIds;
this.pendingApplyBadgeIds = pendingApplyBadgeIds; this.pendingApplyBadgeIds = pendingApplyBadgeIds;
this.passedApplyPerformanceIds = passedApplyPerformanceIds;
this.pendingApplyPerformanceIds = pendingApplyPerformanceIds;
}
Set<String> getPassedApplyBadgeIds() {
return passedApplyBadgeIds;
}
Set<String> getPendingApplyBadgeIds() {
return pendingApplyBadgeIds;
}
Set<String> getPassedApplyPerformanceIds() {
return passedApplyPerformanceIds;
}
Set<String> getPendingApplyPerformanceIds() {
return pendingApplyPerformanceIds;
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment