feat: sync badge resource config
This commit is contained in:
parent
3bbaa78528
commit
112bf13c95
@ -1,23 +1,27 @@
|
|||||||
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.alibaba.fastjson.JSONObject;
|
||||||
import com.red.circle.component.redis.service.RedisService;
|
import com.red.circle.component.redis.service.RedisService;
|
||||||
import com.red.circle.framework.dto.PageResult;
|
import com.red.circle.framework.dto.PageResult;
|
||||||
import com.red.circle.other.app.inner.convertor.material.PropsResourcesInnerConvertor;
|
import com.red.circle.other.app.inner.convertor.material.PropsResourcesInnerConvertor;
|
||||||
import com.red.circle.other.app.inner.service.material.props.PropsBackpackClientService;
|
|
||||||
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.badge.BadgePictureConfig;
|
||||||
import com.red.circle.other.infra.database.rds.entity.family.FamilyLevelConfig;
|
import com.red.circle.other.infra.database.rds.entity.family.FamilyLevelConfig;
|
||||||
import com.red.circle.other.infra.database.rds.entity.props.PropsRedPacketSkin;
|
import com.red.circle.other.infra.database.rds.entity.props.PropsRedPacketSkin;
|
||||||
import com.red.circle.other.infra.database.rds.entity.props.PropsSourceRecord;
|
import com.red.circle.other.infra.database.rds.entity.props.PropsSourceRecord;
|
||||||
|
import com.red.circle.other.infra.database.rds.service.badge.BadgeConfigService;
|
||||||
|
import com.red.circle.other.infra.database.rds.service.badge.BadgePictureConfigService;
|
||||||
import com.red.circle.other.infra.database.rds.service.family.FamilyLevelConfigService;
|
import com.red.circle.other.infra.database.rds.service.family.FamilyLevelConfigService;
|
||||||
import com.red.circle.other.infra.database.rds.service.props.PropsRedPacketSkinService;
|
import com.red.circle.other.infra.database.rds.service.props.PropsRedPacketSkinService;
|
||||||
import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService;
|
import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService;
|
||||||
import com.red.circle.other.infra.utils.RedisUtils;
|
import com.red.circle.other.infra.utils.RedisUtils;
|
||||||
import com.red.circle.other.inner.enums.material.ConsolePropsTypeEnum;
|
import com.red.circle.other.inner.enums.material.ConsolePropsTypeEnum;
|
||||||
import com.red.circle.other.inner.enums.material.PropsTypeEnum;
|
import com.red.circle.other.inner.enums.material.PropsTypeEnum;
|
||||||
|
import com.red.circle.other.inner.enums.sys.SysBadgeConfigTypeEnum;
|
||||||
import com.red.circle.other.inner.model.cmd.material.PropsResourcesMergeCmd;
|
import com.red.circle.other.inner.model.cmd.material.PropsResourcesMergeCmd;
|
||||||
import com.red.circle.other.inner.model.cmd.material.PropsSourceRecordQryCmd;
|
import com.red.circle.other.inner.model.cmd.material.PropsSourceRecordQryCmd;
|
||||||
import com.red.circle.other.inner.model.dto.material.PropsRedPacketSkinDTO;
|
import com.red.circle.other.inner.model.dto.material.PropsRedPacketSkinDTO;
|
||||||
@ -34,6 +38,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 道具资源.
|
* 道具资源.
|
||||||
@ -44,14 +49,19 @@ import org.springframework.stereotype.Service;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class PropsSourceClientServiceImpl implements PropsSourceClientService {
|
public class PropsSourceClientServiceImpl implements PropsSourceClientService {
|
||||||
|
|
||||||
|
private static final String BADGE_TYPE = PropsTypeEnum.BADGE.name();
|
||||||
|
private static final String DEFAULT_BADGE_SOURCE_TYPE = SysBadgeConfigTypeEnum.ACTIVITY.getName();
|
||||||
|
|
||||||
private final PropsResourcesCommon propsResourcesCommon;
|
private final PropsResourcesCommon propsResourcesCommon;
|
||||||
private final FamilyLevelConfigService familyLevelConfigService;
|
private final FamilyLevelConfigService familyLevelConfigService;
|
||||||
private final PropsSourceRecordService propsSourceRecordService;
|
private final PropsSourceRecordService propsSourceRecordService;
|
||||||
private final PropsRedPacketSkinService propsRedPacketSkinService;
|
private final PropsRedPacketSkinService propsRedPacketSkinService;
|
||||||
|
private final BadgeConfigService badgeConfigService;
|
||||||
|
private final BadgePictureConfigService badgePictureConfigService;
|
||||||
private final RedisService redisService;
|
private final RedisService redisService;
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("propsResourcesInnerConvertorImplNew")
|
@Qualifier("propsResourcesInnerConvertorImplNew")
|
||||||
private PropsResourcesInnerConvertor propsResourcesInnerConvertor;
|
private PropsResourcesInnerConvertor propsResourcesInnerConvertor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PropsResourcesDTO getById(Long id) {
|
public PropsResourcesDTO getById(Long id) {
|
||||||
@ -96,8 +106,16 @@ public class PropsSourceClientServiceImpl implements PropsSourceClientService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void offShelfPropsResources(Long id, Boolean offShelf) {
|
public void offShelfPropsResources(Long id, Boolean offShelf) {
|
||||||
|
PropsSourceRecord sourceRecord = propsSourceRecordService.getById(id);
|
||||||
propsSourceRecordService.offShelf(id, offShelf);
|
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
|
||||||
@ -119,10 +137,15 @@ public class PropsSourceClientServiceImpl implements PropsSourceClientService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void addOrUpdatePropsResources(PropsResourcesDTO dto) {
|
public void addOrUpdatePropsResources(PropsResourcesDTO dto) {
|
||||||
PropsSourceRecord propsSourceRecord = propsResourcesInnerConvertor.toPropsSourceRecord(dto);
|
PropsSourceRecord propsSourceRecord = propsResourcesInnerConvertor.toPropsSourceRecord(dto);
|
||||||
|
PropsSourceRecord beforeUpdate = Objects.nonNull(dto.getId())
|
||||||
|
? propsSourceRecordService.getById(dto.getId())
|
||||||
|
: null;
|
||||||
if (Objects.isNull(dto.getId())) {
|
if (Objects.isNull(dto.getId())) {
|
||||||
propsSourceRecordService.save(propsSourceRecord);
|
propsSourceRecordService.save(propsSourceRecord);
|
||||||
|
syncBadgeConfig(dto, propsSourceRecord);
|
||||||
if (Objects.equals(PropsTypeEnum.RED_PACKET.name(), propsSourceRecord.getType())) {
|
if (Objects.equals(PropsTypeEnum.RED_PACKET.name(), propsSourceRecord.getType())) {
|
||||||
propsRedPacketSkinService.save(new PropsRedPacketSkin().setId(propsSourceRecord.getId())
|
propsRedPacketSkinService.save(new PropsRedPacketSkin().setId(propsSourceRecord.getId())
|
||||||
.setImNotOpenedUrl(dto.getImNotOpenedUrl())
|
.setImNotOpenedUrl(dto.getImNotOpenedUrl())
|
||||||
@ -137,6 +160,14 @@ public class PropsSourceClientServiceImpl implements PropsSourceClientService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
propsSourceRecordService.updateSelectiveById(propsSourceRecord);
|
propsSourceRecordService.updateSelectiveById(propsSourceRecord);
|
||||||
|
if (Objects.nonNull(beforeUpdate) && Objects.equals(BADGE_TYPE, beforeUpdate.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())) {
|
if (Objects.equals(PropsTypeEnum.RED_PACKET.name(), propsSourceRecord.getType())) {
|
||||||
|
|
||||||
@ -153,6 +184,77 @@ public class PropsSourceClientServiceImpl implements PropsSourceClientService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user