增加部署日志

This commit is contained in:
dengqichen 2025-11-02 22:59:13 +08:00
parent 990889858c
commit c23c93b753
2 changed files with 31 additions and 10 deletions

View File

@ -50,16 +50,28 @@ public interface IDeployRecordRepository extends IBaseRepository<DeployRecord, L
/**
* 批量查询部署统计信息按团队应用ID分组
*
* 统计规则
* - 成功SUCCESS状态
* - 失败FAILED/CANCELLED/TERMINATED/PARTIAL_SUCCESS状态或CREATED状态超过30分钟仍未更新视为启动失败
* PARTIAL_SUCCESS虽然工作流完成但存在失败节点视为部署不完整计入失败
* - 运行中RUNNING状态或CREATED状态在30分钟内视为正在启动
*/
@Query("SELECT dr.teamApplicationId, " +
@Query(value = "SELECT " +
" dr.team_application_id as teamApplicationId, " +
" COUNT(dr.id) as totalCount, " +
" SUM(CASE WHEN dr.status = 'SUCCESS' THEN 1 ELSE 0 END) as successCount, " +
"SUM(CASE WHEN dr.status IN ('FAILED', 'CANCELLED', 'TERMINATED') THEN 1 ELSE 0 END) as failedCount, " +
"SUM(CASE WHEN dr.status IN ('CREATED', 'RUNNING') THEN 1 ELSE 0 END) as runningCount, " +
"MAX(dr.startTime) as lastDeployTime " +
"FROM DeployRecord dr " +
"WHERE dr.teamApplicationId IN :teamApplicationIds AND dr.deleted = false " +
"GROUP BY dr.teamApplicationId")
" SUM(CASE WHEN dr.status IN ('FAILED', 'CANCELLED', 'TERMINATED', 'PARTIAL_SUCCESS') " +
" OR (dr.status = 'CREATED' AND TIMESTAMPDIFF(MINUTE, dr.create_time, NOW()) > 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<Object[]> findDeployStatisticsByTeamApplicationIds(
@Param("teamApplicationIds") List<Long> teamApplicationIds);

View File

@ -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);