diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/repository/IDeployRecordRepository.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/repository/IDeployRecordRepository.java index c5d10b30..70472467 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/repository/IDeployRecordRepository.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/repository/IDeployRecordRepository.java @@ -50,16 +50,28 @@ public interface IDeployRecordRepository extends IBaseRepository 30) " + + " THEN 1 ELSE 0 END) as failedCount, " + + " SUM(CASE WHEN dr.status = 'RUNNING' " + + " OR (dr.status = 'CREATED' AND TIMESTAMPDIFF(MINUTE, dr.create_time, NOW()) <= 30) " + + " THEN 1 ELSE 0 END) as runningCount, " + + " MAX(dr.start_time) as lastDeployTime " + + "FROM deploy_record dr " + + "WHERE dr.team_application_id IN (:teamApplicationIds) AND dr.deleted = false " + + "GROUP BY dr.team_application_id", + nativeQuery = true) List findDeployStatisticsByTeamApplicationIds( @Param("teamApplicationIds") List teamApplicationIds); diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/DeployServiceImpl.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/DeployServiceImpl.java index 0493eb24..dab7c040 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/DeployServiceImpl.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/DeployServiceImpl.java @@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -209,7 +210,15 @@ public class DeployServiceImpl implements IDeployService { Long successCount = ((Number) row[2]).longValue(); Long failedCount = ((Number) row[3]).longValue(); Long runningCount = ((Number) row[4]).longValue(); - LocalDateTime lastDeployTime = (LocalDateTime) row[5]; + // 处理原生SQL返回的Timestamp类型 + LocalDateTime lastDeployTime = null; + if (row[5] != null) { + if (row[5] instanceof Timestamp) { + lastDeployTime = ((Timestamp) row[5]).toLocalDateTime(); + } else if (row[5] instanceof LocalDateTime) { + lastDeployTime = (LocalDateTime) row[5]; + } + } DeployStatisticsDTO stats = new DeployStatisticsDTO(); stats.setTotalCount(totalCount);