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

Commit dee9040e authored by wangyifan's avatar wangyifan

Merge branch 'dev-caomeihuzhao-V1.1' into test-ecs

parents bbbf90da 633e0966
-- ============================================================
-- 草莓护照 / 徽章 v1.1 数据库变更
-- 说明:新增徽章类型「签证页」(type=4),仅更新字段注释,无结构变更
-- 适用:已在 v1.0 建表的环境(adam_caomei_badge)
-- 日期:2026-05-13
-- ============================================================
-- 1. 徽章类型:补充 4-签证页
ALTER TABLE `adam_caomei_badge`
MODIFY COLUMN `type` tinyint(4) NOT NULL COMMENT '徽章类型: 1-护照纪念徽章, 2-演出纪念徽章, 3-特殊徽章, 4-签证页';
-- 2. 关联演出:签证页同样需绑定音乐节/演出
ALTER TABLE `adam_caomei_badge`
MODIFY COLUMN `performance_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '关联演出ID (演出纪念徽章、签证页必填,其他类型为空)';
...@@ -26,10 +26,10 @@ public class AdamCaomeiBadgeParam { ...@@ -26,10 +26,10 @@ public class AdamCaomeiBadgeParam {
@ApiModelProperty(value = "徽章图标 (Emoji字符或图片URL)") @ApiModelProperty(value = "徽章图标 (Emoji字符或图片URL)")
private String icon; private String icon;
@ApiModelProperty(value = "徽章类型: 1-护照纪念徽章, 2-演出纪念徽章, 3-特殊徽章") @ApiModelProperty(value = "徽章类型: 1-护照纪念徽章, 2-演出纪念徽章, 3-特殊徽章, 4-签证页")
private Integer type; private Integer type;
@ApiModelProperty(value = "关联演出ID (仅演出纪念徽章必填,其他类型为空)") @ApiModelProperty(value = "关联演出ID (演出纪念徽章、签证页必填,其他类型为空)")
private String performanceId; private String performanceId;
@ApiModelProperty(value = "上架状态: 0-下架(默认), 1-已发布") @ApiModelProperty(value = "上架状态: 0-下架(默认), 1-已发布")
......
...@@ -14,7 +14,7 @@ public class AdamCaomeiBadgeSearchParam { ...@@ -14,7 +14,7 @@ public class AdamCaomeiBadgeSearchParam {
@ApiModelProperty(value = "徽章名称") @ApiModelProperty(value = "徽章名称")
private String name; private String name;
@ApiModelProperty(value = "徽章类型: 1-护照纪念徽章, 2-演出纪念徽章, 3-特殊徽章") @ApiModelProperty(value = "徽章类型: 1-护照纪念徽章, 2-演出纪念徽章, 3-特殊徽章, 4-签证页")
private Integer type; private Integer type;
@ApiModelProperty(value = "上架状态: 0-下架(默认), 1-已发布") @ApiModelProperty(value = "上架状态: 0-下架(默认), 1-已发布")
......
...@@ -28,7 +28,7 @@ public class AdamCaomeiBadgeVo { ...@@ -28,7 +28,7 @@ public class AdamCaomeiBadgeVo {
@ApiModelProperty(value = "徽章图标 (Emoji字符或图片URL)") @ApiModelProperty(value = "徽章图标 (Emoji字符或图片URL)")
private String icon; private String icon;
@ApiModelProperty(value = "徽章类型: 1-护照纪念徽章, 2-演出纪念徽章, 3-特殊徽章") @ApiModelProperty(value = "徽章类型: 1-护照纪念徽章, 2-演出纪念徽章, 3-特殊徽章, 4-签证页")
private Integer type; private Integer type;
@ApiModelProperty(value = "关联演出ID") @ApiModelProperty(value = "关联演出ID")
......
...@@ -27,10 +27,10 @@ public class AdamCaomeiPassportBadgeShelfItemVo { ...@@ -27,10 +27,10 @@ public class AdamCaomeiPassportBadgeShelfItemVo {
@ApiModelProperty("分享文案") @ApiModelProperty("分享文案")
private String shareText; private String shareText;
@ApiModelProperty("类型 1护照 2演出 3特殊") @ApiModelProperty("类型 1护照 2演出 3特殊(不含 4 签证页,签证页见 home.visaBadges)")
private Integer type; private Integer type;
@ApiModelProperty("关联演出ID(演出纪念徽章)") @ApiModelProperty("关联演出ID(演出纪念徽章、签证页)")
private String performanceId; private String performanceId;
@ApiModelProperty("关联演出名称(type=2 时用于按演出分组展示;无数据时可能为演出ID)") @ApiModelProperty("关联演出名称(type=2 时用于按演出分组展示;无数据时可能为演出ID)")
......
...@@ -13,9 +13,12 @@ public class AdamCaomeiPassportHomeVo { ...@@ -13,9 +13,12 @@ public class AdamCaomeiPassportHomeVo {
@ApiModelProperty("个人信息卡片") @ApiModelProperty("个人信息卡片")
private AdamCaomeiPassportUserCardVo userCard; private AdamCaomeiPassportUserCardVo userCard;
@ApiModelProperty("已认领徽章(全部获得记录,用于网格墙)") @ApiModelProperty("已认领徽章(用于网格墙;不含 type=4 签证页)")
private List<AdamCaomeiPassportUserClaimedBadgeVo> claimedBadges; private List<AdamCaomeiPassportUserClaimedBadgeVo> claimedBadges;
@ApiModelProperty("全部上架徽章(扁平列表;演出类含 performanceName,前端可按类型或按演出分组展示)") @ApiModelProperty("签证页卡片(type=4;home 内静默发放后返回,含 performanceName)")
private List<AdamCaomeiPassportUserClaimedBadgeVo> visaBadges;
@ApiModelProperty("全部上架徽章货架(不含 type=4 签证页;演出类含 performanceName)")
private List<AdamCaomeiPassportBadgeShelfItemVo> allBadges; private List<AdamCaomeiPassportBadgeShelfItemVo> allBadges;
} }
...@@ -9,7 +9,7 @@ import lombok.Data; ...@@ -9,7 +9,7 @@ import lombok.Data;
import java.util.Date; import java.util.Date;
@Data @Data
@ApiModel("草莓护照-已认领徽章(墙)") @ApiModel("草莓护照-用户已获徽章(徽章墙、签证页卡片等共用)")
public class AdamCaomeiPassportUserClaimedBadgeVo { public class AdamCaomeiPassportUserClaimedBadgeVo {
@ApiModelProperty("徽章ID") @ApiModelProperty("徽章ID")
...@@ -27,10 +27,13 @@ public class AdamCaomeiPassportUserClaimedBadgeVo { ...@@ -27,10 +27,13 @@ public class AdamCaomeiPassportUserClaimedBadgeVo {
@ApiModelProperty("分享文案") @ApiModelProperty("分享文案")
private String shareText; private String shareText;
@ApiModelProperty("类型 1护照类型徽章 2演出类型徽章 3特殊徽章") @ApiModelProperty("类型 1护照类型徽章 2演出类型徽章 3特殊徽章 4签证页")
private Integer type; private Integer type;
@ApiModelProperty("关联演出名称(仅 type=2 有值)") @ApiModelProperty("关联音乐节/演出ID(type=2、type=4 有值)")
private String performanceId;
@ApiModelProperty("关联音乐节/演出名称(type=2、type=4 有值)")
private String performanceName; private String performanceName;
@ApiModelProperty("获得时间") @ApiModelProperty("获得时间")
......
...@@ -17,7 +17,8 @@ public interface IAdamCaomeiPassportUserService { ...@@ -17,7 +17,8 @@ public interface IAdamCaomeiPassportUserService {
ResponseDto<List<AdamCaomeiPassportUserClaimedBadgeVo>> bindPassport(String passportNo); ResponseDto<List<AdamCaomeiPassportUserClaimedBadgeVo>> bindPassport(String passportNo);
/** /**
* 护照首页:个人信息、实名状态、已认领墙、按类型分组的全部上架徽章 * 护照首页:个人信息、实名状态、已认领墙、签证页(type=4)、上架徽章货架;
* 末尾自动发放满足条件的 type=4 签证页,并在 {@link AdamCaomeiPassportHomeVo#getVisaBadges()} 返回。
*/ */
ResponseDto<AdamCaomeiPassportHomeVo> getPassportHome(); ResponseDto<AdamCaomeiPassportHomeVo> getPassportHome();
......
...@@ -94,11 +94,11 @@ public class AdamCaomeiBadgeController extends BaseController { ...@@ -94,11 +94,11 @@ public class AdamCaomeiBadgeController extends BaseController {
badge.setCreatedAt(new Date()); badge.setCreatedAt(new Date());
badge.setUpdatedAt(new Date()); badge.setUpdatedAt(new Date());
// 演出类型校验 // 演出纪念徽章、签证页须关联音乐节
if (badge.getType() != null && badge.getType() == 2) { if (badgeRequiresPerformance(badge.getType())) {
String pid = StringUtils.trimToEmpty(badge.getPerformanceId()); String pid = StringUtils.trimToEmpty(badge.getPerformanceId());
if (StringUtils.isBlank(pid)) { if (StringUtils.isBlank(pid)) {
return error("演出纪念徽章必须关联演出"); return error(badgePerformanceRequiredMessage(badge.getType()));
} }
badge.setPerformanceId(pid); badge.setPerformanceId(pid);
if (!adamCaomeiBadgeAdminService.kylinPerformanceExists(pid)) { if (!adamCaomeiBadgeAdminService.kylinPerformanceExists(pid)) {
...@@ -184,10 +184,10 @@ public class AdamCaomeiBadgeController extends BaseController { ...@@ -184,10 +184,10 @@ public class AdamCaomeiBadgeController extends BaseController {
badge.setUpdatedAt(new java.util.Date()); badge.setUpdatedAt(new java.util.Date());
// 徽章类型与「已发布不可改」一致:编辑时不允许变更类型 // 徽章类型与「已发布不可改」一致:编辑时不允许变更类型
badge.setType(oldBadge.getType()); badge.setType(oldBadge.getType());
if (badge.getType() != null && badge.getType() == 2) { if (badgeRequiresPerformance(badge.getType())) {
String pid = StringUtils.trimToEmpty(badge.getPerformanceId()); String pid = StringUtils.trimToEmpty(badge.getPerformanceId());
if (StringUtils.isBlank(pid)) { if (StringUtils.isBlank(pid)) {
return error("演出纪念徽章必须关联演出"); return error(badgePerformanceRequiredMessage(badge.getType()));
} }
badge.setPerformanceId(pid); badge.setPerformanceId(pid);
if (!adamCaomeiBadgeAdminService.kylinPerformanceExists(pid)) { if (!adamCaomeiBadgeAdminService.kylinPerformanceExists(pid)) {
...@@ -217,6 +217,17 @@ public class AdamCaomeiBadgeController extends BaseController { ...@@ -217,6 +217,17 @@ public class AdamCaomeiBadgeController extends BaseController {
return toAjax(adamCaomeiBadgeAdminService.updateById(updateBadge)); return toAjax(adamCaomeiBadgeAdminService.updateById(updateBadge));
} }
private static boolean badgeRequiresPerformance(Integer type) {
return type != null && (type == 2 || type == 4);
}
private static String badgePerformanceRequiredMessage(Integer type) {
if (type != null && type == 4) {
return "签证页必须关联音乐节";
}
return "演出纪念徽章必须关联演出";
}
/** /**
* @return 校验通过返回 null,否则返回错误 AjaxResult * @return 校验通过返回 null,否则返回错误 AjaxResult
*/ */
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
<option value="">请选择</option> <option value="">请选择</option>
<option value="1">护照纪念徽章</option> <option value="1">护照纪念徽章</option>
<option value="2">演出纪念徽章</option> <option value="2">演出纪念徽章</option>
<option value="4">签证页</option>
<!-- <option value="3">特殊徽章</option> --> <!-- <option value="3">特殊徽章</option> -->
</select> </select>
</div> </div>
...@@ -59,7 +60,7 @@ ...@@ -59,7 +60,7 @@
<label class="col-sm-3 control-label is-required">关联演出:</label> <label class="col-sm-3 control-label is-required">关联演出:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input name="performanceId" id="performanceId" class="form-control" type="text" placeholder="请输入演出ID"> <input name="performanceId" id="performanceId" class="form-control" type="text" placeholder="请输入演出ID">
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 演出纪念徽章必填</span> <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 演出纪念徽章、签证页必填</span>
</div> </div>
</div> </div>
</form> </form>
...@@ -71,7 +72,7 @@ ...@@ -71,7 +72,7 @@
var platformUrl = /*[[${platformUrl}]]*/ ''; var platformUrl = /*[[${platformUrl}]]*/ '';
function typeChange(val) { function typeChange(val) {
if (val == 2) { if (val == 2 || val == 4) {
$("#ticketTimesDiv").show(); $("#ticketTimesDiv").show();
$("#performanceId").prop("required", true); $("#performanceId").prop("required", true);
} else { } else {
......
...@@ -32,10 +32,11 @@ ...@@ -32,10 +32,11 @@
<div class="col-sm-8"> <div class="col-sm-8">
<div class="form-control-static" th:if="*{type == 1}">护照纪念徽章</div> <div class="form-control-static" th:if="*{type == 1}">护照纪念徽章</div>
<div class="form-control-static" th:if="*{type == 2}">演出纪念徽章</div> <div class="form-control-static" th:if="*{type == 2}">演出纪念徽章</div>
<div class="form-control-static" th:if="*{type == 3}">特殊徽章</div> <div class="form-control-static" th:if="*{type == 4}">签证页</div>
<!-- <div class="form-control-static" th:if="*{type == 3}">特殊徽章</div>-->
</div> </div>
</div> </div>
<div class="form-group" th:style="${badge.type == 2 ? 'display:block;' : 'display:none;'}"> <div class="form-group" th:style="${badge.type == 2 or badge.type == 4 ? 'display:block;' : 'display:none;'}">
<label class="col-sm-3 control-label">关联演出:</label> <label class="col-sm-3 control-label">关联演出:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<div class="form-control-static" th:text="*{performanceId}"></div> <div class="form-control-static" th:text="*{performanceId}"></div>
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
<select class="form-control m-b" disabled> <select class="form-control m-b" disabled>
<option th:selected="${badge.type == 1}" value="1">护照纪念徽章</option> <option th:selected="${badge.type == 1}" value="1">护照纪念徽章</option>
<option th:selected="${badge.type == 2}" value="2">演出纪念徽章</option> <option th:selected="${badge.type == 2}" value="2">演出纪念徽章</option>
<option th:selected="${badge.type == 4}" value="4">签证页</option>
</select> </select>
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 徽章类型保存后不可修改</span> <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 徽章类型保存后不可修改</span>
</div> </div>
...@@ -63,11 +64,11 @@ ...@@ -63,11 +64,11 @@
<textarea name="shareText" th:field="*{shareText}" class="form-control" rows="3" maxlength="255" placeholder="请输入徽章分享文案"></textarea> <textarea name="shareText" th:field="*{shareText}" class="form-control" rows="3" maxlength="255" placeholder="请输入徽章分享文案"></textarea>
</div> </div>
</div> </div>
<div class="form-group" id="ticketTimesDiv" th:style="${badge.type == 2 ? 'display:block;' : 'display:none;'}"> <div class="form-group" id="ticketTimesDiv" th:style="${badge.type == 2 or badge.type == 4 ? 'display:block;' : 'display:none;'}">
<label class="col-sm-3 control-label is-required">关联演出:</label> <label class="col-sm-3 control-label is-required">关联演出:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input name="performanceId" id="performanceId" th:field="*{performanceId}" class="form-control" type="text" placeholder="请输入演出ID" th:required="${badge.type == 2}"> <input name="performanceId" id="performanceId" th:field="*{performanceId}" class="form-control" type="text" placeholder="请输入演出ID" th:required="${badge.type == 2 or badge.type == 4}">
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 演出纪念徽章必填</span> <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 演出纪念徽章、签证页必填</span>
</div> </div>
</div> </div>
</form> </form>
...@@ -79,7 +80,7 @@ ...@@ -79,7 +80,7 @@
var platformUrl = /*[[${platformUrl}]]*/ ''; var platformUrl = /*[[${platformUrl}]]*/ '';
function typeChange(val) { function typeChange(val) {
if (val == 2 || val == '2') { if (val == 2 || val == '2' || val == 4 || val == '4') {
$("#ticketTimesDiv").show(); $("#ticketTimesDiv").show();
$("#performanceId").prop("required", true); $("#performanceId").prop("required", true);
} else { } else {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<option value="">所有</option> <option value="">所有</option>
<option value="1">护照纪念徽章</option> <option value="1">护照纪念徽章</option>
<option value="2">演出纪念徽章</option> <option value="2">演出纪念徽章</option>
<option value="4">签证页</option>
<!-- <option value="3">特殊徽章</option> --> <!-- <option value="3">特殊徽章</option> -->
</select> </select>
</li> </li>
...@@ -106,6 +107,7 @@ ...@@ -106,6 +107,7 @@
if (value == 1) return '<span class="badge badge-info">护照纪念</span>'; if (value == 1) return '<span class="badge badge-info">护照纪念</span>';
if (value == 2) return '<span class="badge badge-primary">演出纪念</span>'; if (value == 2) return '<span class="badge badge-primary">演出纪念</span>';
if (value == 3) return '<span class="badge badge-warning">特殊徽章</span>'; if (value == 3) return '<span class="badge badge-warning">特殊徽章</span>';
if (value == 4) return '<span class="badge badge-success">签证页</span>';
return value; return value;
} }
}, },
......
package com.liquidnet.service.adam.dto;
import lombok.Data;
@Data
public class AdamCaomeiPerformanceIdTitleDto {
private String performanceId;
private String title;
}
...@@ -44,12 +44,12 @@ public class AdamCaomeiBadge implements Serializable { ...@@ -44,12 +44,12 @@ public class AdamCaomeiBadge implements Serializable {
private String icon; private String icon;
/** /**
* 徽章类型: 1-护照纪念徽章, 2-演出纪念徽章, 3-特殊徽章 * 徽章类型: 1-护照纪念徽章, 2-演出纪念徽章, 3-特殊徽章, 4-签证页
*/ */
private Integer type; private Integer type;
/** /**
* 关联演出ID (仅演出纪念徽章必填,其他类型为空) * 关联演出ID (演出纪念徽章、签证页必填,其他类型为空)
*/ */
private String performanceId; private String performanceId;
......
...@@ -3,6 +3,7 @@ package com.liquidnet.service.adam.mapper; ...@@ -3,6 +3,7 @@ package com.liquidnet.service.adam.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liquidnet.service.adam.dto.AdamCaomeiBadgeClaimCountDto; import com.liquidnet.service.adam.dto.AdamCaomeiBadgeClaimCountDto;
import com.liquidnet.service.adam.dto.AdamCaomeiBadgeClaimUserDto; import com.liquidnet.service.adam.dto.AdamCaomeiBadgeClaimUserDto;
import com.liquidnet.service.adam.dto.AdamCaomeiPerformanceIdTitleDto;
import com.liquidnet.service.adam.entity.AdamCaomeiBadge; import com.liquidnet.service.adam.entity.AdamCaomeiBadge;
import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
...@@ -107,4 +108,16 @@ public interface AdamCaomeiBadgeMapper extends BaseMapper<AdamCaomeiBadge> { ...@@ -107,4 +108,16 @@ public interface AdamCaomeiBadgeMapper extends BaseMapper<AdamCaomeiBadge> {
@Select("select title from kylin_performances where performances_id = #{performanceId}") @Select("select title from kylin_performances where performances_id = #{performanceId}")
String selectKylinPerformanceTitleById(@Param("performanceId") String performanceId); String selectKylinPerformanceTitleById(@Param("performanceId") String performanceId);
@Select({
"<script>",
"select performances_id as performanceId, title",
"from kylin_performances",
"where performances_id in",
"<foreach collection='performanceIds' item='performanceId' open='(' separator=',' close=')'>",
"#{performanceId}",
"</foreach>",
"</script>"
})
List<AdamCaomeiPerformanceIdTitleDto> selectKylinPerformanceTitlesByIds(@Param("performanceIds") List<String> performanceIds);
} }
...@@ -36,7 +36,7 @@ public class AdamCaomeiPassportUserController { ...@@ -36,7 +36,7 @@ public class AdamCaomeiPassportUserController {
} }
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation("护照首页聚合数据") @ApiOperation("护照首页聚合数据(含签证页 type=4 字段 visaBadges,访问时自动静默发放)")
@GetMapping("home") @GetMapping("home")
public ResponseDto<AdamCaomeiPassportHomeVo> home() { public ResponseDto<AdamCaomeiPassportHomeVo> home() {
return adamCaomeiPassportUserService.getPassportHome(); return adamCaomeiPassportUserService.getPassportHome();
......
...@@ -12,6 +12,7 @@ import com.liquidnet.commons.lang.util.JsonUtils; ...@@ -12,6 +12,7 @@ import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.SensitizeUtil; import com.liquidnet.commons.lang.util.SensitizeUtil;
import com.liquidnet.service.adam.constant.AdamRedisConst; import com.liquidnet.service.adam.constant.AdamRedisConst;
import com.liquidnet.service.adam.dto.AdamCaomeiPassportUserBadgeDto; import com.liquidnet.service.adam.dto.AdamCaomeiPassportUserBadgeDto;
import com.liquidnet.service.adam.dto.AdamCaomeiPerformanceIdTitleDto;
import com.liquidnet.service.adam.dto.AdamUserInfoDto; import com.liquidnet.service.adam.dto.AdamUserInfoDto;
import com.liquidnet.service.adam.dto.vo.*; import com.liquidnet.service.adam.dto.vo.*;
import com.liquidnet.service.adam.entity.AdamCaomeiBadge; import com.liquidnet.service.adam.entity.AdamCaomeiBadge;
...@@ -807,21 +808,62 @@ public class AdamRdmService { ...@@ -807,21 +808,62 @@ public class AdamRdmService {
* 读取不到时返回 null。 * 读取不到时返回 null。
*/ */
public String getPerformanceTitleById(String performanceId) { public String getPerformanceTitleById(String performanceId) {
if (StringUtils.isEmpty(performanceId)) {
return null;
}
String id = performanceId.trim();
Map<String, String> map = getPerformanceTitleMapByIds(Collections.singletonList(id));
return map.get(id);
}
/**
* 批量解析演出 ID → 标题:先走 Kylin Redis,缓存未命中的 ID 合并为一次 DB IN 查询。
*/
public Map<String, String> getPerformanceTitleMapByIds(Collection<String> performanceIds) {
if (CollectionUtils.isEmpty(performanceIds)) {
return Collections.emptyMap();
}
List<String> ids = performanceIds.stream()
.filter(id -> !StringUtils.isEmpty(id))
.map(String::trim)
.distinct()
.collect(Collectors.toList());
if (ids.isEmpty()) {
return Collections.emptyMap();
}
Map<String, String> result = new HashMap<>(ids.size() * 2);
List<String> missingFromCache = new ArrayList<>();
for (String id : ids) {
try { try {
KylinPerformanceVo vo = getKylinPerformanceVoById(performanceId); KylinPerformanceVo vo = getKylinPerformanceVoById(id);
if (vo != null) { if (vo != null) {
return vo.getTitle(); String title = vo.getTitle();
}
// 从数据库查询
String title = adamCaomeiBadgeMapper.selectKylinPerformanceTitleById(performanceId);
if (!StringUtils.isEmpty(title)) { if (!StringUtils.isEmpty(title)) {
return title; result.put(id, title);
}
} else {
missingFromCache.add(id);
} }
return null;
} catch (Exception e) { } catch (Exception e) {
log.warn("[getPerformanceTitleById] 读取演出缓存失败, performanceId: {}", performanceId, e); log.warn("[getPerformanceTitleMapByIds] 读取演出缓存失败, performanceId: {}", id, e);
return null; missingFromCache.add(id);
}
}
if (!missingFromCache.isEmpty()) {
List<AdamCaomeiPerformanceIdTitleDto> rows =
adamCaomeiBadgeMapper.selectKylinPerformanceTitlesByIds(missingFromCache);
if (!CollectionUtils.isEmpty(rows)) {
for (AdamCaomeiPerformanceIdTitleDto row : rows) {
if (row == null || StringUtils.isEmpty(row.getPerformanceId()) || StringUtils.isEmpty(row.getTitle())) {
continue;
}
result.put(row.getPerformanceId().trim(), row.getTitle());
}
}
} }
return result;
} }
/** /**
......
package com.liquidnet.service.adam.service.caomei;
import java.util.Collections;
import java.util.Set;
/**
* 用户补签审核状态快照(按「徽章 ID」与「场次 performanceId」两个维度聚合)。
* <p>
* 由 {@link CaomeiBadgeEligibilityService#loadApplyBadgeStatus} 从 DB 补签表加载,
* 供护照首页货架({@code claimable} / {@code applyPending})与演出徽章认领前置判断共用,
* 避免 home 展示与 POST claim 规则不一致。
*/
public final class CaomeiBadgeApplyStatus {
/** 审核已通过(auditStatus=1)的补签申请对应的 badgeId */
private final Set<String> passedApplyBadgeIds;
/** 待审核(auditStatus=0)的补签申请对应的 badgeId */
private final Set<String> pendingApplyBadgeIds;
/** 审核已通过补签所关联的场次 ID(含从 badge 配置兜底解析的 performanceId) */
private final Set<String> passedApplyPerformanceIds;
/** 待审核补签所关联的场次 ID */
private final Set<String> pendingApplyPerformanceIds;
/**
* @param passedApplyBadgeIds 已通过补签的徽章 ID 集合,可为 null(视为空集)
* @param pendingApplyBadgeIds 待审核补签的徽章 ID 集合,可为 null
* @param passedApplyPerformanceIds 已通过补签的场次 ID 集合,可为 null
* @param pendingApplyPerformanceIds 待审核补签的场次 ID 集合,可为 null
*/
public CaomeiBadgeApplyStatus(Set<String> passedApplyBadgeIds,
Set<String> pendingApplyBadgeIds,
Set<String> passedApplyPerformanceIds,
Set<String> pendingApplyPerformanceIds) {
this.passedApplyBadgeIds = passedApplyBadgeIds == null ? Collections.emptySet() : passedApplyBadgeIds;
this.pendingApplyBadgeIds = pendingApplyBadgeIds == null ? Collections.emptySet() : pendingApplyBadgeIds;
this.passedApplyPerformanceIds = passedApplyPerformanceIds == null ? Collections.emptySet() : passedApplyPerformanceIds;
this.pendingApplyPerformanceIds = pendingApplyPerformanceIds == null ? Collections.emptySet() : pendingApplyPerformanceIds;
}
public Set<String> getPassedApplyBadgeIds() {
return passedApplyBadgeIds;
}
public Set<String> getPendingApplyBadgeIds() {
return pendingApplyBadgeIds;
}
public Set<String> getPassedApplyPerformanceIds() {
return passedApplyPerformanceIds;
}
public Set<String> getPendingApplyPerformanceIds() {
return pendingApplyPerformanceIds;
}
}
package com.liquidnet.service.adam.service.caomei;
import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.service.adam.dto.AdamCaomeiPassportUserBadgeDto;
import com.liquidnet.service.adam.entity.AdamCaomeiBadge;
import com.liquidnet.service.adam.service.AdamRdmService;
import com.liquidnet.service.adam.util.QueueUtils;
import com.liquidnet.service.base.SqlMapping;
import com.liquidnet.service.base.constant.MQConst;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 草莓徽章「发放」统一入口:写入用户徽章 Redis({@code INFO_CAOMEI_BADGE_USER + uid}),
* 并通过 MQ 异步 INSERT {@code adam_caomei_user_badge}。
* <p>
* 调用方:绑护照发 type=1、用户 claim、home 静默发 type=4 签证页。
* <p>
* {@code source} 与库表一致:1-绑定护照,2-购票自动,3-补签通过,4-现场管理员(本服务未使用 4)。
*/
@Slf4j
@Service
public class CaomeiBadgeGrantService {
@Autowired
private AdamRdmService adamRdmService;
@Autowired
private QueueUtils queueUtils;
/**
* 将运营配置的徽章实体转为用户已获列表中的缓存 DTO(尚未写 Redis)。
*
* @param badge 上架徽章配置(含 badgeId、名称、type、performanceId 等)
* @param source 获得途径,见类说明
* @param claimedAt 获得时间,null 时使用当前时间
*/
public AdamCaomeiPassportUserBadgeDto toUserBadgeDto(AdamCaomeiBadge badge, int source, Date claimedAt) {
AdamCaomeiPassportUserBadgeDto dto = new AdamCaomeiPassportUserBadgeDto();
dto.setBadgeId(badge.getBadgeId());
dto.setBadgeName(StringUtils.defaultString(badge.getName()));
dto.setSubTitle(StringUtils.defaultString(badge.getSubTitle()));
dto.setIcon(StringUtils.defaultString(badge.getIcon()));
dto.setShareText(StringUtils.defaultString(badge.getShareText()));
dto.setType(badge.getType());
dto.setPerformanceId(StringUtils.trimToEmpty(badge.getPerformanceId()));
dto.setClaimedAt(claimedAt != null ? claimedAt : DateUtil.now());
dto.setSource(source);
return dto;
}
/**
* 批量发放:对比用户当前已拥有 badgeId,仅对「尚未拥有」的徽章追加缓存并落库。
* <p>
* 适用于:绑护照一次性发多个 type=1、home 末尾静默发多个 type=4。
*
* @param uid 当前用户 ID
* @param badges 待发放的配置列表(通常来自 published 缓存筛选)
* @param source 获得途径
* @param grantAt 统一获得时间(批量场景 bind/签证 使用同一时间戳),null 则取当前时间
* @return 本次实际写入 Redis 的 DTO;空列表表示全部已拥有、未发生发放
*/
public List<AdamCaomeiPassportUserBadgeDto> grantBadgesIfAbsent(String uid,
List<AdamCaomeiBadge> badges,
int source,
Date grantAt) {
if (StringUtils.isBlank(uid) || CollectionUtils.isEmpty(badges)) {
return new ArrayList<>();
}
Date at = grantAt != null ? grantAt : DateUtil.now();
List<AdamCaomeiPassportUserBadgeDto> cacheList = copyUserBadgeCache(uid);
Set<String> existedBadgeIds = cacheList.stream()
.map(AdamCaomeiPassportUserBadgeDto::getBadgeId)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toSet());
List<AdamCaomeiPassportUserBadgeDto> appendVos = badges.stream()
.filter(b -> b != null && StringUtils.isNotBlank(b.getBadgeId()))
.filter(b -> !existedBadgeIds.contains(b.getBadgeId()))
.map(b -> toUserBadgeDto(b, source, at))
.collect(Collectors.toList());
if (appendVos.isEmpty()) {
return appendVos;
}
adamRdmService.addUserCaomeiBadgeDtosByUid(uid, cacheList, appendVos);
sendUserBadgeInsertMq(uid, appendVos, source, at);
return appendVos;
}
/**
* 单条发放:用于 POST claim 循环内逐枚写入。
* <p>
* 调用方须已做「未领取」校验;本方法不再查重。
*
* @param uid 用户 ID
* @param badge 单枚上架徽章配置
* @param source 获得途径(type=2 时由 Eligibility 解析为 2 或 3)
* @param mutableCacheList 当前请求内持有的用户徽章列表副本,发放后会 append 并写回 Redis
*/
public void grantOne(String uid,
AdamCaomeiBadge badge,
int source,
List<AdamCaomeiPassportUserBadgeDto> mutableCacheList) {
if (badge == null || StringUtils.isBlank(badge.getBadgeId())) {
return;
}
Date now = new Date();
AdamCaomeiPassportUserBadgeDto dto = toUserBadgeDto(badge, source, now);
adamRdmService.addUserCaomeiBadgeDtoByUid(uid, mutableCacheList, dto);
queueUtils.sendMsgByRedis(
MQConst.AdamQueue.SQL_UCENTER.getKey(),
SqlMapping.get("adam_caomei_user_badge.add", uid, badge.getBadgeId(), source, now)
);
}
/** 读取用户徽章 Redis,返回可修改副本(miss 时可能为空列表) */
private List<AdamCaomeiPassportUserBadgeDto> copyUserBadgeCache(String uid) {
List<AdamCaomeiPassportUserBadgeDto> cache = adamRdmService.getUserCaomeiBadgesByUid(uid);
if (cache == null) {
return new ArrayList<>();
}
return new ArrayList<>(cache);
}
/** 批量 MQ:仅对 appendVos 中的 badgeId 发送 INSERT,与 Redis 追加范围一致 */
private void sendUserBadgeInsertMq(String uid,
List<AdamCaomeiPassportUserBadgeDto> appendVos,
int source,
Date grantAt) {
LinkedList<Object[]> paramsList = new LinkedList<>();
for (AdamCaomeiPassportUserBadgeDto dto : appendVos) {
if (dto == null || StringUtils.isBlank(dto.getBadgeId())) {
continue;
}
paramsList.add(new Object[]{uid, dto.getBadgeId(), source, grantAt});
}
if (paramsList.isEmpty()) {
return;
}
queueUtils.sendMsgByRedis(
MQConst.AdamQueue.SQL_UCENTER.getKey(),
SqlMapping.get("adam_caomei_user_badge.add", paramsList)
);
}
}
...@@ -7,7 +7,6 @@ import com.liquidnet.service.adam.dto.AdamCaomeiPassportUserBadgeDto; ...@@ -7,7 +7,6 @@ import com.liquidnet.service.adam.dto.AdamCaomeiPassportUserBadgeDto;
import com.liquidnet.service.adam.dto.param.AdamCaomeiBadgeApplyParam; import com.liquidnet.service.adam.dto.param.AdamCaomeiBadgeApplyParam;
import com.liquidnet.service.adam.dto.AdamCaomeiBadgeApplyRecordUserDto; import com.liquidnet.service.adam.dto.AdamCaomeiBadgeApplyRecordUserDto;
import com.liquidnet.service.adam.dto.vo.AdamCaomeiBadgeApplyRecordUserVo; import com.liquidnet.service.adam.dto.vo.AdamCaomeiBadgeApplyRecordUserVo;
import com.liquidnet.service.adam.dto.vo.AdamRealInfoVo;
import com.liquidnet.service.adam.entity.AdamCaomeiBadgeApplyRecord; import com.liquidnet.service.adam.entity.AdamCaomeiBadgeApplyRecord;
import com.liquidnet.service.adam.entity.AdamCaomeiBadge; import com.liquidnet.service.adam.entity.AdamCaomeiBadge;
import com.liquidnet.service.adam.entity.AdamCaomeiPassport; import com.liquidnet.service.adam.entity.AdamCaomeiPassport;
...@@ -16,6 +15,8 @@ import com.liquidnet.service.adam.mapper.AdamCaomeiBadgeMapper; ...@@ -16,6 +15,8 @@ import com.liquidnet.service.adam.mapper.AdamCaomeiBadgeMapper;
import com.liquidnet.service.adam.mapper.AdamCaomeiPassportMapper; import com.liquidnet.service.adam.mapper.AdamCaomeiPassportMapper;
import com.liquidnet.service.adam.service.AdamRdmService; import com.liquidnet.service.adam.service.AdamRdmService;
import com.liquidnet.service.adam.service.IAdamCaomeiBadgeUserService; import com.liquidnet.service.adam.service.IAdamCaomeiBadgeUserService;
import com.liquidnet.service.adam.service.caomei.CaomeiBadgeEligibilityService;
import com.liquidnet.service.adam.service.caomei.CaomeiBadgeGrantService;
import com.liquidnet.service.adam.util.QueueUtils; import com.liquidnet.service.adam.util.QueueUtils;
import com.liquidnet.service.base.ErrorMapping; import com.liquidnet.service.base.ErrorMapping;
import com.liquidnet.service.base.ResponseDto; import com.liquidnet.service.base.ResponseDto;
...@@ -29,12 +30,10 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -29,12 +30,10 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.HashSet;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j @Slf4j
...@@ -50,6 +49,10 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi ...@@ -50,6 +49,10 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi
@Autowired @Autowired
private AdamRdmService adamRdmService; private AdamRdmService adamRdmService;
@Autowired @Autowired
private CaomeiBadgeGrantService caomeiBadgeGrantService;
@Autowired
private CaomeiBadgeEligibilityService caomeiBadgeEligibilityService;
@Autowired
private QueueUtils queueUtils; private QueueUtils queueUtils;
@Override @Override
...@@ -133,56 +136,13 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi ...@@ -133,56 +136,13 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi
} }
} }
Set<String> paidPerformanceSet = Collections.emptySet(); CaomeiBadgeEligibilityService.Type2ClaimContext type2Ctx = null;
Set<String> passedApplyBadgeIds = Collections.emptySet();
Set<String> passedApplyPerformanceIds = Collections.emptySet();
Map<String, Set<String>> perfAllBadgeIds = Collections.emptyMap();
if (hasType2) { if (hasType2) {
AdamRealInfoVo real = adamRdmService.getRealInfoVoByUidPlain(uid); type2Ctx = caomeiBadgeEligibilityService.buildType2ClaimContext(uid, orderedBadges);
if (real == null || real.getState() == null || real.getState() != 1 || StringUtils.isBlank(real.getIdCard())) { if (!type2Ctx.isRealNameOk()) {
log.error("[claimBadges] 认领演出徽章需先实名, uid: {}, badgeIds: {}", uid, requestBadgeIds); log.error("[claimBadges] 认领演出徽章需先实名, uid: {}, badgeIds: {}", uid, requestBadgeIds);
return ResponseDto.failure(ErrorMapping.get("10610")); return ResponseDto.failure(ErrorMapping.get("10610"));
} }
List<String> paidPerformanceIds = adamRdmService.getPaidPerformanceIdsByIdCard(real.getIdCard());
paidPerformanceSet = paidPerformanceIds == null ? Collections.emptySet() : new HashSet<>(paidPerformanceIds);
List<AdamCaomeiBadgeApplyRecord> passedApplyRecords = badgeApplyRecordMapper.selectList(
Wrappers.lambdaQuery(AdamCaomeiBadgeApplyRecord.class)
.eq(AdamCaomeiBadgeApplyRecord::getUserId, uid)
.eq(AdamCaomeiBadgeApplyRecord::getAuditStatus, 1)
);
passedApplyBadgeIds = new HashSet<>();
passedApplyPerformanceIds = new HashSet<>();
if (passedApplyRecords != null) {
for (AdamCaomeiBadgeApplyRecord r : passedApplyRecords) {
if (r == null) {
continue;
}
if (StringUtils.isNotBlank(r.getBadgeId())) {
passedApplyBadgeIds.add(r.getBadgeId());
}
if (StringUtils.isNotBlank(r.getPerformanceId())) {
passedApplyPerformanceIds.add(r.getPerformanceId());
}
}
}
Set<String> targetPerfIds = orderedBadges.stream()
.filter(b -> b.getType() != null && b.getType() == 2)
.map(AdamCaomeiBadge::getPerformanceId)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toSet());
if (!targetPerfIds.isEmpty()) {
List<AdamCaomeiBadge> perfBadges = adamCaomeiBadgeMapper.selectList(
Wrappers.lambdaQuery(AdamCaomeiBadge.class)
.eq(AdamCaomeiBadge::getType, 2)
.in(AdamCaomeiBadge::getPerformanceId, targetPerfIds)
);
perfAllBadgeIds = perfBadges.stream()
.filter(b -> StringUtils.isNotBlank(b.getPerformanceId()) && StringUtils.isNotBlank(b.getBadgeId()))
.collect(Collectors.groupingBy(AdamCaomeiBadge::getPerformanceId,
Collectors.mapping(AdamCaomeiBadge::getBadgeId, Collectors.toSet())));
}
} }
List<String> claimedBadgeIds = new ArrayList<>(); List<String> claimedBadgeIds = new ArrayList<>();
...@@ -190,25 +150,14 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi ...@@ -190,25 +150,14 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi
int type = badge.getType() == null ? 0 : badge.getType(); int type = badge.getType() == null ? 0 : badge.getType();
int source = 1; int source = 1;
if (type == 2) { if (type == 2) {
String perfId = StringUtils.trimToEmpty(badge.getPerformanceId()); if (!caomeiBadgeEligibilityService.canClaimPerformanceBadge(badge, type2Ctx)) {
boolean hasPaidRecord = StringUtils.isNotBlank(perfId) && paidPerformanceSet.contains(perfId);
boolean hasPassedApply = false;
if (StringUtils.isNotBlank(perfId)) {
if (passedApplyPerformanceIds.contains(perfId)) {
hasPassedApply = true;
} else {
Set<String> badgeIdSet = perfAllBadgeIds.getOrDefault(perfId, Collections.emptySet());
hasPassedApply = badgeIdSet.stream().anyMatch(passedApplyBadgeIds::contains);
}
}
if (!hasPaidRecord && !hasPassedApply) {
log.error("[claimBadges] 无购票记录且无通过补签,无法认领, uid: {}, badgeId: {}", uid, badge.getBadgeId()); log.error("[claimBadges] 无购票记录且无通过补签,无法认领, uid: {}, badgeId: {}", uid, badge.getBadgeId());
return ResponseDto.failure(ErrorMapping.get("10611")); return ResponseDto.failure(ErrorMapping.get("10611"));
} }
source = hasPaidRecord ? 2 : 3; source = caomeiBadgeEligibilityService.resolveClaimSourceForType2(badge, type2Ctx);
} }
grantUserBadgeRedisThenMq(uid, badge, source, badgeVos); caomeiBadgeGrantService.grantOne(uid, badge, source, badgeVos);
claimedBadgeIds.add(badge.getBadgeId()); claimedBadgeIds.add(badge.getBadgeId());
} }
...@@ -216,33 +165,6 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi ...@@ -216,33 +165,6 @@ public class AdamCaomeiBadgeUserServiceImpl implements IAdamCaomeiBadgeUserServi
return ResponseDto.success(claimedBadgeIds); return ResponseDto.success(claimedBadgeIds);
} }
/**
* Redis 追加用户徽章展示 DTO,再发 MQ 异步执行 sqlmap 中的 INSERT。
*/
private void grantUserBadgeRedisThenMq(String uid, AdamCaomeiBadge badge, int source,
List<AdamCaomeiPassportUserBadgeDto> badgeVos) {
Date now = new Date();
AdamCaomeiPassportUserBadgeDto dto = new AdamCaomeiPassportUserBadgeDto();
dto.setBadgeId(badge.getBadgeId());
dto.setBadgeName(StringUtils.defaultString(badge.getName()));
dto.setIcon(StringUtils.defaultString(badge.getIcon()));
dto.setShareText(StringUtils.defaultString(badge.getShareText()));
dto.setType(badge.getType());
dto.setClaimedAt(now);
dto.setSource(source);
dto.setSubTitle(badge.getSubTitle());
dto.setPerformanceId(StringUtils.defaultString(badge.getPerformanceId()));
adamRdmService.addUserCaomeiBadgeDtoByUid(uid, badgeVos, dto);
long t = System.currentTimeMillis();
queueUtils.sendMsgByRedis(
MQConst.AdamQueue.SQL_UCENTER.getKey(),
SqlMapping.get("adam_caomei_user_badge.add", uid, badge.getBadgeId(), source, now)
);
log.debug("[claimBadge] MQ耗时:{}ms, uid: {}, badgeId: {}", System.currentTimeMillis() - t, uid, badge.getBadgeId());
}
@Override @Override
public ResponseDto<List<AdamCaomeiBadgeApplyRecordUserVo>> getApplyRecords(String uid) { public ResponseDto<List<AdamCaomeiBadgeApplyRecordUserVo>> getApplyRecords(String uid) {
if (StringUtils.isBlank(uid)) { if (StringUtils.isBlank(uid)) {
......
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