feat: sync badge resource config

This commit is contained in:
hy001 2026-05-15 20:41:24 +08:00
parent 3bbaa78528
commit 112bf13c95

View File

@ -1,39 +1,44 @@
package com.red.circle.other.app.inner.service.material.props.impl; package com.red.circle.other.app.inner.service.material.props.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.red.circle.component.redis.service.RedisService; import com.alibaba.fastjson.JSONObject;
import com.red.circle.framework.dto.PageResult; import com.red.circle.component.redis.service.RedisService;
import com.red.circle.other.app.inner.convertor.material.PropsResourcesInnerConvertor; import com.red.circle.framework.dto.PageResult;
import com.red.circle.other.app.inner.service.material.props.PropsBackpackClientService; import com.red.circle.other.app.inner.convertor.material.PropsResourcesInnerConvertor;
import com.red.circle.other.app.inner.service.material.props.PropsSourceClientService; import com.red.circle.other.app.inner.service.material.props.PropsSourceClientService;
import com.red.circle.other.infra.common.props.PropsResourcesCommon; import com.red.circle.other.infra.common.props.PropsResourcesCommon;
import com.red.circle.other.infra.database.cache.key.AdminFreeKeys; import com.red.circle.other.infra.database.cache.key.AdminFreeKeys;
import com.red.circle.other.infra.database.cache.key.GameListKeys; import com.red.circle.other.infra.database.rds.entity.badge.BadgeConfig;
import com.red.circle.other.infra.database.rds.entity.family.FamilyLevelConfig; import com.red.circle.other.infra.database.rds.entity.badge.BadgePictureConfig;
import com.red.circle.other.infra.database.rds.entity.props.PropsRedPacketSkin; import com.red.circle.other.infra.database.rds.entity.family.FamilyLevelConfig;
import com.red.circle.other.infra.database.rds.entity.props.PropsSourceRecord; import com.red.circle.other.infra.database.rds.entity.props.PropsRedPacketSkin;
import com.red.circle.other.infra.database.rds.service.family.FamilyLevelConfigService; import com.red.circle.other.infra.database.rds.entity.props.PropsSourceRecord;
import com.red.circle.other.infra.database.rds.service.props.PropsRedPacketSkinService; import com.red.circle.other.infra.database.rds.service.badge.BadgeConfigService;
import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService; import com.red.circle.other.infra.database.rds.service.badge.BadgePictureConfigService;
import com.red.circle.other.infra.utils.RedisUtils; import com.red.circle.other.infra.database.rds.service.family.FamilyLevelConfigService;
import com.red.circle.other.inner.enums.material.ConsolePropsTypeEnum; import com.red.circle.other.infra.database.rds.service.props.PropsRedPacketSkinService;
import com.red.circle.other.inner.enums.material.PropsTypeEnum; import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService;
import com.red.circle.other.inner.model.cmd.material.PropsResourcesMergeCmd; import com.red.circle.other.infra.utils.RedisUtils;
import com.red.circle.other.inner.model.cmd.material.PropsSourceRecordQryCmd; import com.red.circle.other.inner.enums.material.ConsolePropsTypeEnum;
import com.red.circle.other.inner.model.dto.material.PropsRedPacketSkinDTO; import com.red.circle.other.inner.enums.material.PropsTypeEnum;
import com.red.circle.other.inner.model.dto.material.PropsResourcesDTO; import com.red.circle.other.inner.enums.sys.SysBadgeConfigTypeEnum;
import com.red.circle.other.inner.model.dto.material.PropsResourcesMergeDTO; import com.red.circle.other.inner.model.cmd.material.PropsResourcesMergeCmd;
import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.other.inner.model.cmd.material.PropsSourceRecordQryCmd;
import com.red.circle.tool.core.text.StringUtils; import com.red.circle.other.inner.model.dto.material.PropsRedPacketSkinDTO;
import java.util.List; import com.red.circle.other.inner.model.dto.material.PropsResourcesDTO;
import java.util.Map; import com.red.circle.other.inner.model.dto.material.PropsResourcesMergeDTO;
import java.util.Objects; import com.red.circle.tool.core.collection.CollectionUtils;
import java.util.Set; import com.red.circle.tool.core.text.StringUtils;
import java.util.stream.Collectors; import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/** /**
* 道具资源. * 道具资源.
@ -42,16 +47,21 @@ import org.springframework.stereotype.Service;
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class PropsSourceClientServiceImpl implements PropsSourceClientService { public class PropsSourceClientServiceImpl implements PropsSourceClientService {
private final PropsResourcesCommon propsResourcesCommon; private static final String BADGE_TYPE = PropsTypeEnum.BADGE.name();
private final FamilyLevelConfigService familyLevelConfigService; private static final String DEFAULT_BADGE_SOURCE_TYPE = SysBadgeConfigTypeEnum.ACTIVITY.getName();
private final PropsSourceRecordService propsSourceRecordService;
private final PropsRedPacketSkinService propsRedPacketSkinService; private final PropsResourcesCommon propsResourcesCommon;
private final RedisService redisService; private final FamilyLevelConfigService familyLevelConfigService;
@Autowired private final PropsSourceRecordService propsSourceRecordService;
@Qualifier("propsResourcesInnerConvertorImplNew") private final PropsRedPacketSkinService propsRedPacketSkinService;
private PropsResourcesInnerConvertor propsResourcesInnerConvertor; private final BadgeConfigService badgeConfigService;
private final BadgePictureConfigService badgePictureConfigService;
private final RedisService redisService;
@Autowired
@Qualifier("propsResourcesInnerConvertorImplNew")
private PropsResourcesInnerConvertor propsResourcesInnerConvertor;
@Override @Override
public PropsResourcesDTO getById(Long id) { public PropsResourcesDTO getById(Long id) {
@ -95,10 +105,18 @@ public class PropsSourceClientServiceImpl implements PropsSourceClientService {
return props; return props;
} }
@Override @Override
public void offShelfPropsResources(Long id, Boolean offShelf) { @Transactional(rollbackFor = Exception.class)
propsSourceRecordService.offShelf(id, offShelf); public void offShelfPropsResources(Long id, Boolean offShelf) {
} PropsSourceRecord sourceRecord = propsSourceRecordService.getById(id);
propsSourceRecordService.offShelf(id, offShelf);
if (Objects.nonNull(sourceRecord) && Objects.equals(BADGE_TYPE, sourceRecord.getType())) {
badgeConfigService.update()
.set(BadgeConfig::getDel, Boolean.TRUE.equals(offShelf))
.eq(BadgeConfig::getId, id)
.execute();
}
}
@Override @Override
public PageResult<PropsResourcesDTO> pagePropsResourcesOps(PropsSourceRecordQryCmd qryCmd) { public PageResult<PropsResourcesDTO> pagePropsResourcesOps(PropsSourceRecordQryCmd qryCmd) {
@ -118,13 +136,18 @@ public class PropsSourceClientServiceImpl implements PropsSourceClientService {
); );
} }
@Override @Override
public void addOrUpdatePropsResources(PropsResourcesDTO dto) { @Transactional(rollbackFor = Exception.class)
PropsSourceRecord propsSourceRecord = propsResourcesInnerConvertor.toPropsSourceRecord(dto); public void addOrUpdatePropsResources(PropsResourcesDTO dto) {
if (Objects.isNull(dto.getId())) { PropsSourceRecord propsSourceRecord = propsResourcesInnerConvertor.toPropsSourceRecord(dto);
propsSourceRecordService.save(propsSourceRecord); PropsSourceRecord beforeUpdate = Objects.nonNull(dto.getId())
if (Objects.equals(PropsTypeEnum.RED_PACKET.name(), propsSourceRecord.getType())) { ? propsSourceRecordService.getById(dto.getId())
propsRedPacketSkinService.save(new PropsRedPacketSkin().setId(propsSourceRecord.getId()) : null;
if (Objects.isNull(dto.getId())) {
propsSourceRecordService.save(propsSourceRecord);
syncBadgeConfig(dto, propsSourceRecord);
if (Objects.equals(PropsTypeEnum.RED_PACKET.name(), propsSourceRecord.getType())) {
propsRedPacketSkinService.save(new PropsRedPacketSkin().setId(propsSourceRecord.getId())
.setImNotOpenedUrl(dto.getImNotOpenedUrl()) .setImNotOpenedUrl(dto.getImNotOpenedUrl())
.setImOpenedUrl(dto.getImOpenedUrl()) .setImOpenedUrl(dto.getImOpenedUrl())
.setImSendCoverUrl(dto.getImSendCoverUrl()) .setImSendCoverUrl(dto.getImSendCoverUrl())
@ -133,12 +156,20 @@ public class PropsSourceClientServiceImpl implements PropsSourceClientService {
.setRoomOpenedUrl(dto.getRoomOpenedUrl()) .setRoomOpenedUrl(dto.getRoomOpenedUrl())
.setImOpenedUrlTwo(dto.getImOpenedUrlTwo()) .setImOpenedUrlTwo(dto.getImOpenedUrlTwo())
.setSysOrigin(dto.getSysOrigin())); .setSysOrigin(dto.getSysOrigin()));
} }
return; return;
} }
propsSourceRecordService.updateSelectiveById(propsSourceRecord); propsSourceRecordService.updateSelectiveById(propsSourceRecord);
if (Objects.nonNull(beforeUpdate) && Objects.equals(BADGE_TYPE, beforeUpdate.getType())
if (Objects.equals(PropsTypeEnum.RED_PACKET.name(), propsSourceRecord.getType())) { && !Objects.equals(BADGE_TYPE, propsSourceRecord.getType())) {
badgeConfigService.update()
.set(BadgeConfig::getDel, Boolean.TRUE)
.eq(BadgeConfig::getId, propsSourceRecord.getId())
.execute();
}
syncBadgeConfig(dto, propsSourceRecord);
if (Objects.equals(PropsTypeEnum.RED_PACKET.name(), propsSourceRecord.getType())) {
propsRedPacketSkinService.updateSelectiveById( propsRedPacketSkinService.updateSelectiveById(
new PropsRedPacketSkin().setId(propsSourceRecord.getId()) new PropsRedPacketSkin().setId(propsSourceRecord.getId())
@ -150,8 +181,79 @@ public class PropsSourceClientServiceImpl implements PropsSourceClientService {
.setRoomOpenedUrl(dto.getRoomOpenedUrl()) .setRoomOpenedUrl(dto.getRoomOpenedUrl())
.setImOpenedUrlTwo(dto.getImOpenedUrlTwo()) .setImOpenedUrlTwo(dto.getImOpenedUrlTwo())
.setSysOrigin(dto.getSysOrigin())); .setSysOrigin(dto.getSysOrigin()));
} }
} }
private void syncBadgeConfig(PropsResourcesDTO dto, PropsSourceRecord propsSourceRecord) {
if (!Objects.equals(BADGE_TYPE, propsSourceRecord.getType())) {
return;
}
Long badgeId = propsSourceRecord.getId();
if (Objects.isNull(badgeId)) {
return;
}
JSONObject expand = parseExpand(dto.getExpand());
String badgeSourceType = normalizeBadgeSourceType(expand.getString("badgeType"));
Integer badgeLevel = expand.getInteger("badgeLevel");
Long milestone = expand.getLong("milestone");
String badgeKey = StringUtils.isNotBlank(expand.getString("badgeKey"))
? expand.getString("badgeKey")
: propsSourceRecord.getCode();
BadgeConfig badgeConfig = new BadgeConfig()
.setId(badgeId)
.setType(badgeSourceType)
.setBadgeLevel(Objects.nonNull(badgeLevel) ? badgeLevel : 0)
.setMilestone(milestone)
.setBadgeName(propsSourceRecord.getName())
.setBadgeKey(badgeKey)
.setDel(Boolean.TRUE.equals(propsSourceRecord.getDel()));
if (Objects.isNull(badgeConfigService.getById(badgeId))) {
badgeConfigService.save(badgeConfig);
} else {
badgeConfigService.updateSelectiveById(badgeConfig);
}
BadgePictureConfig pictureConfig = badgePictureConfigService
.getByConfigIdBySysOrigin(badgeId, propsSourceRecord.getSysOrigin());
String notSelectUrl = expand.getString("notSelectUrl");
if (Objects.isNull(pictureConfig)) {
badgePictureConfigService.save(new BadgePictureConfig()
.setBadgeConfigId(badgeId)
.setSysOrigin(propsSourceRecord.getSysOrigin())
.setSelectUrl(propsSourceRecord.getCover())
.setNotSelectUrl(notSelectUrl)
.setAnimationUrl(propsSourceRecord.getSourceUrl()));
return;
}
pictureConfig.setSelectUrl(propsSourceRecord.getCover());
pictureConfig.setNotSelectUrl(notSelectUrl);
pictureConfig.setAnimationUrl(propsSourceRecord.getSourceUrl());
badgePictureConfigService.updateSelectiveById(pictureConfig);
}
private JSONObject parseExpand(String expand) {
if (StringUtils.isBlank(expand)) {
return new JSONObject();
}
try {
return JSON.parseObject(expand);
} catch (Exception ex) {
return new JSONObject();
}
}
private String normalizeBadgeSourceType(String badgeType) {
if (StringUtils.isBlank(badgeType)) {
return DEFAULT_BADGE_SOURCE_TYPE;
}
for (SysBadgeConfigTypeEnum value : SysBadgeConfigTypeEnum.values()) {
if (Objects.equals(value.getName(), badgeType)) {
return badgeType;
}
}
return DEFAULT_BADGE_SOURCE_TYPE;
}
@Override @Override
public PropsRedPacketSkinDTO getPropsRedPacketSkin(Long id) { public PropsRedPacketSkinDTO getPropsRedPacketSkin(Long id) {