diff --git a/workflow/service/flow/flow_execution_service.go b/workflow/service/flow/flow_execution_service.go index 9909d45..ba40297 100644 --- a/workflow/service/flow/flow_execution_service.go +++ b/workflow/service/flow/flow_execution_service.go @@ -116,29 +116,21 @@ func (s *flowExecutionService) List(ctx context.Context, req *flowDto.ListFlowEx return nil, err } - // ========== 只统计【有数据】的执行记录,空的直接跳过 ========== - executionNumber := make(map[int64]int) // executionId -> 倒序编号(最新=1) + // 过滤出有有效输出的执行记录 var validList []*entity.FlowExecution for _, execution := range list { - if g.IsEmpty(execution.OutputParams) { - continue + if !g.IsEmpty(execution.OutputParams) { + validList = append(validList, execution) } - validList = append(validList, execution) - } - totalValid := len(validList) - for idx, execution := range validList { - executionNumber[execution.Id] = totalValid - idx } - // ========== 分组:日期 -> 合并所有 OutputItem ========== + // 1. 先按日期归集所有数据,暂不编号 dateMap := make(map[string][]flowDto.OutputItem) - for _, execution := range validList { - createDate := execution.CreatedAt.Format("Y-m-d") - execID := execution.Id // 拿到执行ID + createDate := execution.CreatedAt.Format("2006-01-02") + execID := execution.Id outputParams := execution.OutputParams - // 解析 outputParams var tempItems []flowDto.OutputItem for _, paramMap := range outputParams { for tsKey, value := range paramMap { @@ -156,20 +148,32 @@ func (s *flowExecutionService) List(ctx context.Context, req *flowDto.ListFlowEx continue } - // 时间戳正序 + // 单条执行内按时间戳正序 sort.Slice(tempItems, func(i, j int) bool { t1, _ := strconv.ParseInt(tempItems[i].Timestamp, 10, 64) t2, _ := strconv.ParseInt(tempItems[j].Timestamp, 10, 64) return t1 < t2 }) - // 标号:相同类型递增,不同重置 - suffixCount := make(map[string]int) - for idx := range tempItems { - item := &tempItems[idx] + dateMap[createDate] = append(dateMap[createDate], tempItems...) + } + + // 2. 全局计数器:跨所有日期、所有数据连续编号 + globalCount := make(map[string]int) + var tree []flowDto.DateNode + + // 先组装节点再统一排序 + for date, items := range dateMap { + if len(items) == 0 { + continue + } + // 逐个打标签,全局累加 + for idx := range items { + item := &items[idx] val := item.Content suffix := "内容" ext := GetFileTypeByPath(val) + switch ext { case "image": suffix = "图片" @@ -182,28 +186,19 @@ func (s *flowExecutionService) List(ctx context.Context, req *flowDto.ListFlowEx case "html": suffix = "HTML" } - suffixCount[suffix]++ + + globalCount[suffix]++ item.Type = ext - item.Label = fmt.Sprintf("%s_%d", suffix, suffixCount[suffix]) + item.Label = fmt.Sprintf("%s_%d", suffix, globalCount[suffix]) } - // 直接追加到对应日期下(不再包一层 FlowNode) - dateMap[createDate] = append(dateMap[createDate], tempItems...) - } - - // ========== 构建树并排序 ========== - var tree []flowDto.DateNode - for date, items := range dateMap { - if len(items) == 0 { - continue - } tree = append(tree, flowDto.DateNode{ CreateDate: date, Items: items, }) } - // 日期倒序 + // 日期倒序展示 sort.Slice(tree, func(i, j int) bool { return tree[i].CreateDate > tree[j].CreateDate })