增加部署日志
This commit is contained in:
parent
990889858c
commit
c23c93b753
@ -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, " +
|
||||
"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")
|
||||
@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', '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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user