火箭修复
This commit is contained in:
parent
89a26758bc
commit
2e35bbedc0
@ -7,7 +7,6 @@ import com.red.circle.console.app.dto.clienobject.RocketConfigCO;
|
||||
import com.red.circle.console.app.dto.clienobject.RocketStatisticsCO;
|
||||
import com.red.circle.console.app.dto.cmd.RocketConfigQueryCmd;
|
||||
import com.red.circle.console.app.dto.cmd.RocketConfigUpdateCmd;
|
||||
import com.red.circle.console.app.service.RocketConfigService;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -27,7 +26,6 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class RocketConfigRestController {
|
||||
|
||||
private final RocketConfigService rocketConfigService;
|
||||
private final RocketConfigUpdateExe rocketConfigUpdateExe;
|
||||
private final RocketStatisticsQueryExe rocketStatisticsQueryExe;
|
||||
private final RocketConfigQueryExe rocketConfigQueryExe;
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
package com.red.circle.console.app.service;
|
||||
|
||||
import com.red.circle.console.app.dto.clienobject.RocketConfigCO;
|
||||
import com.red.circle.console.app.dto.clienobject.RocketStatisticsCO;
|
||||
import com.red.circle.console.app.dto.cmd.RocketConfigQueryCmd;
|
||||
import com.red.circle.console.app.dto.cmd.RocketConfigUpdateCmd;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 火箭配置管理服务
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-01-15
|
||||
*/
|
||||
public interface RocketConfigService {
|
||||
|
||||
/**
|
||||
* 查询所有配置
|
||||
*/
|
||||
List<RocketConfigCO> queryAll(RocketConfigQueryCmd cmd);
|
||||
|
||||
/**
|
||||
* 根据ID查询配置
|
||||
*/
|
||||
RocketConfigCO queryById(Long id);
|
||||
|
||||
/**
|
||||
* 更新配置
|
||||
*/
|
||||
void update(RocketConfigUpdateCmd cmd);
|
||||
|
||||
/**
|
||||
* 启用/禁用配置
|
||||
*/
|
||||
void updateStatus(Long id, Integer status);
|
||||
|
||||
/**
|
||||
* 查询火箭数据统计
|
||||
*/
|
||||
RocketStatisticsCO queryStatistics();
|
||||
}
|
||||
@ -41,7 +41,7 @@ public class RocketRestController {
|
||||
/**
|
||||
* 手动触发发射 (测试用)
|
||||
*/
|
||||
@PostMapping("/manual-launch")
|
||||
// @PostMapping("/manual-launch")
|
||||
public void manualLaunch(@RequestParam Long roomId) {
|
||||
rocketService.manualLaunch(roomId);
|
||||
}
|
||||
|
||||
@ -31,7 +31,6 @@ public class RocketLaunchCmdExe {
|
||||
private final RocketHistoryGateway rocketHistoryGateway;
|
||||
private final DistributedLockUtil distributedLockUtil;
|
||||
private final RocketImPushManager rocketImPushManager;
|
||||
private final RocketConvertor rocketConvertor;
|
||||
|
||||
/**
|
||||
* 执行火箭发射
|
||||
@ -93,7 +92,7 @@ public class RocketLaunchCmdExe {
|
||||
|
||||
// 8. 推送发射动画消息
|
||||
try {
|
||||
RocketStatusCO statusCO = rocketConvertor.toStatusCO(rocketStatus);
|
||||
RocketStatusCO statusCO = RocketConvertor.toStatusCO(rocketStatus);
|
||||
rocketImPushManager.pushRocketLaunch(roomId, statusCO);
|
||||
} catch (Exception e) {
|
||||
log.error("推送火箭发射消息失败: roomId={}", roomId, e);
|
||||
|
||||
@ -51,8 +51,8 @@ public class RocketStatusQryExe {
|
||||
RocketStatusCO statusCO = convertToStatusCO(rocketStatus);
|
||||
|
||||
// 3. 填充当前用户相关信息
|
||||
if (cmd.getCurrentUserId() != null) {
|
||||
fillUserInfo(statusCO, rocketStatus, cmd.getCurrentUserId());
|
||||
if (cmd.getReqUserId() != null) {
|
||||
// fillUserInfo(statusCO, rocketStatus, cmd.getReqUserId());
|
||||
}
|
||||
|
||||
return statusCO;
|
||||
|
||||
@ -0,0 +1,111 @@
|
||||
package com.red.circle.other.app.convertor;
|
||||
|
||||
import com.red.circle.other.app.dto.clientobject.RocketContributorCO;
|
||||
import com.red.circle.other.app.dto.clientobject.RocketStatusCO;
|
||||
import com.red.circle.other.domain.rocket.RocketContributor;
|
||||
import com.red.circle.other.domain.rocket.RocketStatus;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 火箭对象转换器
|
||||
*
|
||||
* @author system
|
||||
* @date 2025-01-15
|
||||
*/
|
||||
public class RocketConvertor {
|
||||
|
||||
/**
|
||||
* Domain转StatusCO
|
||||
*/
|
||||
public static RocketStatusCO toStatusCO(RocketStatus rocketStatus) {
|
||||
if (rocketStatus == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RocketStatusCO co = new RocketStatusCO();
|
||||
co.setRoomId(rocketStatus.getRoomId());
|
||||
co.setDate(rocketStatus.getDate());
|
||||
co.setLevel(rocketStatus.getLevel().getLevel());
|
||||
co.setLevelName(rocketStatus.getLevel().getName());
|
||||
co.setCurrentEnergy(rocketStatus.getCurrentEnergy());
|
||||
co.setMaxEnergy(rocketStatus.getMaxEnergy());
|
||||
|
||||
// 计算能量百分比
|
||||
if (rocketStatus.getMaxEnergy() != null && rocketStatus.getMaxEnergy() > 0) {
|
||||
BigDecimal percent = BigDecimal.valueOf(rocketStatus.getCurrentEnergy())
|
||||
.divide(BigDecimal.valueOf(rocketStatus.getMaxEnergy()), 4, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100));
|
||||
co.setEnergyPercent(percent);
|
||||
} else {
|
||||
co.setEnergyPercent(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
co.setStatus(rocketStatus.getStatus().name());
|
||||
co.setStatusDesc(rocketStatus.getStatus().getDesc());
|
||||
|
||||
// 转换贡献者列表
|
||||
if (rocketStatus.getContributors() != null) {
|
||||
List<RocketContributorCO> contributorCOs = rocketStatus.getContributors().stream()
|
||||
.map(RocketConvertor::toContributorCO)
|
||||
.collect(Collectors.toList());
|
||||
co.setTopContributors(contributorCOs);
|
||||
} else {
|
||||
co.setTopContributors(new ArrayList<>());
|
||||
}
|
||||
|
||||
co.setTotalContributors(rocketStatus.getContributors() != null
|
||||
? rocketStatus.getContributors().size() : 0);
|
||||
co.setLaunchTime(rocketStatus.getLaunchTime());
|
||||
co.setClaimExpireTime(rocketStatus.getClaimExpireTime());
|
||||
co.setClaimCount(rocketStatus.getClaimCount());
|
||||
|
||||
// 判断是否可领取
|
||||
co.setCanClaim(rocketStatus.canClaim());
|
||||
|
||||
return co;
|
||||
}
|
||||
|
||||
/**
|
||||
* Domain转ContributorCO
|
||||
*/
|
||||
public static RocketContributorCO toContributorCO(RocketContributor contributor) {
|
||||
if (contributor == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RocketContributorCO co = new RocketContributorCO();
|
||||
co.setUserId(contributor.getUserId());
|
||||
co.setUserName(contributor.getUserName());
|
||||
co.setUserAvatar(contributor.getUserAvatar());
|
||||
co.setEnergy(contributor.getEnergy());
|
||||
co.setContributionRate(contributor.getContributionRate());
|
||||
co.setGiftCount(contributor.getGiftCount());
|
||||
// co.setRank(contributor.getEnergy());
|
||||
|
||||
return co;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换贡献者列表(带排名)
|
||||
*/
|
||||
public static List<RocketContributorCO> toContributorCOList(List<RocketContributor> contributors) {
|
||||
if (contributors == null || contributors.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<RocketContributorCO> coList = new ArrayList<>();
|
||||
for (int i = 0; i < contributors.size(); i++) {
|
||||
RocketContributor contributor = contributors.get(i);
|
||||
RocketContributorCO co = toContributorCO(contributor);
|
||||
co.setRank(i + 1); // 设置排名
|
||||
coList.add(co);
|
||||
}
|
||||
|
||||
return coList;
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,9 @@
|
||||
package com.red.circle.other.app.dto.cmd;
|
||||
|
||||
import com.red.circle.common.business.dto.cmd.AppExtCommand;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 火箭状态查询命令
|
||||
@ -9,8 +11,9 @@ import lombok.Data;
|
||||
* @author system
|
||||
* @date 2025-01-15
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class RocketStatusQueryCmd {
|
||||
public class RocketStatusQueryCmd extends AppExtCommand {
|
||||
|
||||
/**
|
||||
* 房间ID
|
||||
@ -18,8 +21,4 @@ public class RocketStatusQueryCmd {
|
||||
@NotNull(message = "房间ID不能为空")
|
||||
private Long roomId;
|
||||
|
||||
/**
|
||||
* 当前用户ID (可选,用于判断是否可领取)
|
||||
*/
|
||||
private Long currentUserId;
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package com.red.circle.other.infra.database.rds.dao;
|
||||
package com.red.circle.other.infra.database.rds.dao.rocket;
|
||||
|
||||
import com.red.circle.other.infra.database.rds.entity.RocketConfigEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@ -12,8 +11,7 @@ import java.util.List;
|
||||
* @author system
|
||||
* @date 2025-01-15
|
||||
*/
|
||||
@Mapper
|
||||
public interface RocketConfigMapper {
|
||||
public interface RocketConfigDAO {
|
||||
|
||||
/**
|
||||
* 根据等级查询
|
||||
@ -1,7 +1,6 @@
|
||||
package com.red.circle.other.infra.database.rds.dao;
|
||||
package com.red.circle.other.infra.database.rds.dao.rocket;
|
||||
|
||||
import com.red.circle.other.infra.database.rds.entity.RocketRewardClaimLogEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@ -12,8 +11,7 @@ import java.util.List;
|
||||
* @author system
|
||||
* @date 2025-01-15
|
||||
*/
|
||||
@Mapper
|
||||
public interface RocketRewardClaimLogMapper {
|
||||
public interface RocketRewardClaimLogDAO {
|
||||
|
||||
/**
|
||||
* 插入
|
||||
@ -3,7 +3,7 @@ package com.red.circle.other.infra.gateway;
|
||||
import com.red.circle.other.domain.gateway.RocketConfigGateway;
|
||||
import com.red.circle.other.domain.rocket.RocketConfig;
|
||||
import com.red.circle.other.infra.convertor.RocketConfigConvertor;
|
||||
import com.red.circle.other.infra.database.rds.dao.RocketConfigMapper;
|
||||
import com.red.circle.other.infra.database.rds.dao.rocket.RocketConfigDAO;
|
||||
import com.red.circle.other.infra.database.rds.entity.RocketConfigEntity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -23,18 +23,18 @@ import java.util.stream.Collectors;
|
||||
@RequiredArgsConstructor
|
||||
public class RocketConfigGatewayImpl implements RocketConfigGateway {
|
||||
|
||||
private final RocketConfigMapper rocketConfigMapper;
|
||||
private final RocketConfigDAO rocketConfigDAO;
|
||||
private final RocketConfigConvertor rocketConfigConvertor;
|
||||
|
||||
@Override
|
||||
public RocketConfig findByLevel(Integer level) {
|
||||
RocketConfigEntity entity = rocketConfigMapper.selectByLevel(level);
|
||||
RocketConfigEntity entity = rocketConfigDAO.selectByLevel(level);
|
||||
return rocketConfigConvertor.toRocketConfig(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RocketConfig> findAll() {
|
||||
List<RocketConfigEntity> entities = rocketConfigMapper.selectAll();
|
||||
List<RocketConfigEntity> entities = rocketConfigDAO.selectAll();
|
||||
return entities.stream()
|
||||
.map(rocketConfigConvertor::toRocketConfig)
|
||||
.collect(Collectors.toList());
|
||||
@ -42,7 +42,7 @@ public class RocketConfigGatewayImpl implements RocketConfigGateway {
|
||||
|
||||
@Override
|
||||
public List<RocketConfig> findAllEnabled() {
|
||||
List<RocketConfigEntity> entities = rocketConfigMapper.selectAllEnabled();
|
||||
List<RocketConfigEntity> entities = rocketConfigDAO.selectAllEnabled();
|
||||
return entities.stream()
|
||||
.map(rocketConfigConvertor::toRocketConfig)
|
||||
.collect(Collectors.toList());
|
||||
@ -51,13 +51,13 @@ public class RocketConfigGatewayImpl implements RocketConfigGateway {
|
||||
@Override
|
||||
public void save(RocketConfig config) {
|
||||
RocketConfigEntity entity = rocketConfigConvertor.toEntity(config);
|
||||
rocketConfigMapper.insert(entity);
|
||||
rocketConfigDAO.insert(entity);
|
||||
config.setId(entity.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(RocketConfig config) {
|
||||
RocketConfigEntity entity = rocketConfigConvertor.toEntity(config);
|
||||
rocketConfigMapper.update(entity);
|
||||
rocketConfigDAO.update(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ package com.red.circle.other.infra.gateway;
|
||||
import com.red.circle.other.domain.gateway.RocketRewardLogGateway;
|
||||
import com.red.circle.other.domain.rocket.RocketRewardLog;
|
||||
import com.red.circle.other.infra.convertor.RocketRewardLogConvertor;
|
||||
import com.red.circle.other.infra.database.rds.dao.RocketRewardClaimLogMapper;
|
||||
import com.red.circle.other.infra.database.rds.dao.rocket.RocketRewardClaimLogDAO;
|
||||
import com.red.circle.other.infra.database.rds.entity.RocketRewardClaimLogEntity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -23,26 +23,26 @@ import java.util.stream.Collectors;
|
||||
@RequiredArgsConstructor
|
||||
public class RocketRewardLogGatewayImpl implements RocketRewardLogGateway {
|
||||
|
||||
private final RocketRewardClaimLogMapper rocketRewardClaimLogMapper;
|
||||
private final RocketRewardClaimLogDAO rocketRewardClaimLogDAO;
|
||||
private final RocketRewardLogConvertor rocketRewardLogConvertor;
|
||||
|
||||
@Override
|
||||
public void save(RocketRewardLog log) {
|
||||
RocketRewardClaimLogEntity entity = rocketRewardLogConvertor.toEntity(log);
|
||||
rocketRewardClaimLogMapper.insert(entity);
|
||||
rocketRewardClaimLogDAO.insert(entity);
|
||||
log.setId(entity.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByRocketAndUser(String rocketHistoryId, Long userId) {
|
||||
int count = rocketRewardClaimLogMapper.countByRocketAndUser(rocketHistoryId, userId);
|
||||
int count = rocketRewardClaimLogDAO.countByRocketAndUser(rocketHistoryId, userId);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RocketRewardLog> findByRocketHistoryId(String rocketHistoryId) {
|
||||
List<RocketRewardClaimLogEntity> entities =
|
||||
rocketRewardClaimLogMapper.selectByRocketHistoryId(rocketHistoryId);
|
||||
rocketRewardClaimLogDAO.selectByRocketHistoryId(rocketHistoryId);
|
||||
return entities.stream()
|
||||
.map(rocketRewardLogConvertor::toDomain)
|
||||
.collect(Collectors.toList());
|
||||
@ -51,7 +51,7 @@ public class RocketRewardLogGatewayImpl implements RocketRewardLogGateway {
|
||||
@Override
|
||||
public List<RocketRewardLog> findByRoomIdAndUserId(Long roomId, Long userId) {
|
||||
List<RocketRewardClaimLogEntity> entities =
|
||||
rocketRewardClaimLogMapper.selectByRoomIdAndUserId(roomId, userId);
|
||||
rocketRewardClaimLogDAO.selectByRoomIdAndUserId(roomId, userId);
|
||||
return entities.stream()
|
||||
.map(rocketRewardLogConvertor::toDomain)
|
||||
.collect(Collectors.toList());
|
||||
@ -59,6 +59,6 @@ public class RocketRewardLogGatewayImpl implements RocketRewardLogGateway {
|
||||
|
||||
@Override
|
||||
public int countByRocketHistoryId(String rocketHistoryId) {
|
||||
return rocketRewardClaimLogMapper.countByRocketHistoryId(rocketHistoryId);
|
||||
return rocketRewardClaimLogDAO.countByRocketHistoryId(rocketHistoryId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.red.circle.other.infra.database.rds.dao.RocketConfigMapper">
|
||||
<mapper namespace="com.red.circle.other.infra.database.rds.dao.rocket.RocketConfigDAO">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.red.circle.other.infra.database.rds.entity.RocketConfigEntity">
|
||||
<id column="id" property="id"/>
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.red.circle.other.infra.database.rds.dao.RocketRewardClaimLogMapper">
|
||||
<mapper namespace="com.red.circle.other.infra.database.rds.dao.rocket.RocketRewardClaimLogDAO">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.red.circle.other.infra.database.rds.entity.RocketRewardClaimLogEntity">
|
||||
<id column="id" property="id"/>
|
||||
@ -1,5 +1,6 @@
|
||||
package com.red.circle.other.app.inner.endpoint.rocket;
|
||||
|
||||
import com.red.circle.framework.core.response.CommonErrorCode;
|
||||
import com.red.circle.framework.dto.ResultResponse;
|
||||
import com.red.circle.other.app.inner.convertor.RocketInnerConvertor;
|
||||
import com.red.circle.other.domain.gateway.RocketConfigGateway;
|
||||
@ -54,7 +55,7 @@ public class RocketConfigEndpoint implements RocketConfigClientApi {
|
||||
// 通过等级查询(id就是等级)
|
||||
RocketConfig config = rocketConfigGateway.findByLevel(id.intValue());
|
||||
if (config == null) {
|
||||
return ResultResponse.failure("配置不存在");
|
||||
return ResultResponse.failure(CommonErrorCode.CONFIGURATION_ERROR);
|
||||
}
|
||||
return ResultResponse.success(rocketInnerConvertor.toDTO(config));
|
||||
}
|
||||
@ -63,7 +64,7 @@ public class RocketConfigEndpoint implements RocketConfigClientApi {
|
||||
public ResultResponse<RocketConfigDTO> queryByLevel(Integer level) {
|
||||
RocketConfig config = rocketConfigGateway.findByLevel(level);
|
||||
if (config == null) {
|
||||
return ResultResponse.failure("配置不存在");
|
||||
return ResultResponse.failure(CommonErrorCode.CONFIGURATION_ERROR);
|
||||
}
|
||||
return ResultResponse.success(rocketInnerConvertor.toDTO(config));
|
||||
}
|
||||
@ -79,7 +80,7 @@ public class RocketConfigEndpoint implements RocketConfigClientApi {
|
||||
public ResultResponse<Void> updateStatus(Long id, Integer status) {
|
||||
RocketConfig config = rocketConfigGateway.findByLevel(id.intValue());
|
||||
if (config == null) {
|
||||
return ResultResponse.failure("配置不存在");
|
||||
return ResultResponse.failure(CommonErrorCode.CONFIGURATION_ERROR);
|
||||
}
|
||||
config.setStatus(status);
|
||||
rocketConfigGateway.update(config);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user