diff --git a/workflow/service/flow/flow_execution_service.go b/workflow/service/flow/flow_execution_service.go index cc410cf..00ce36f 100644 --- a/workflow/service/flow/flow_execution_service.go +++ b/workflow/service/flow/flow_execution_service.go @@ -124,10 +124,11 @@ func (s *flowExecutionService) List(ctx context.Context, req *flowDto.ListFlowEx } } - // 1. 先按日期归集所有数据,暂不编号 + // 1. 按日期归集,严格使用 Y-m-d 格式 dateMap := make(map[string][]flowDto.OutputItem) for _, execution := range validList { - createDate := execution.CreatedAt.Format("2006-01-02") + // 按要求使用 Y-m-d + createDate := execution.CreatedAt.Format("Y-m-d") execID := execution.Id outputParams := execution.OutputParams @@ -158,52 +159,65 @@ func (s *flowExecutionService) List(ctx context.Context, req *flowDto.ListFlowEx dateMap[createDate] = append(dateMap[createDate], tempItems...) } - // ========== 改动开始 ========== - // 第一步:先全量遍历统计每个类型总数量(用于倒序编号) + // ========== 修复编号乱序核心逻辑 ========== + // 1. 取出所有日期并 倒序排序(和前端展示顺序一致) + var sortedDates []string + for d := range dateMap { + sortedDates = append(sortedDates, d) + } + // 日期字符串倒序 + sort.Slice(sortedDates, func(i, j int) bool { + return sortedDates[i] > sortedDates[j] + }) + + // 2. 按【前端展示顺序】拼接所有条目,用于统计总数量 + var allItems []flowDto.OutputItem + for _, d := range sortedDates { + allItems = append(allItems, dateMap[d]...) + } + + // 3. 统计各类型总数 type totalCnt struct { total int idx int } typeTotal := make(map[string]*totalCnt) - // 先统计各类型总数 - for _, items := range dateMap { - for _, item := range items { - val := item.Content - suffix := "内容" - ext := GetFileTypeByPath(val) + for _, item := range allItems { + val := item.Content + suffix := "内容" + ext := GetFileTypeByPath(val) - switch ext { - case "image": - suffix = "图片" - case "video": - suffix = "视频" - case "audio": - suffix = "音频" - case "text": - suffix = "文案" - case "html": - suffix = "HTML" - } - if _, ok := typeTotal[suffix]; !ok { - typeTotal[suffix] = &totalCnt{} - } - typeTotal[suffix].total++ + switch ext { + case "image": + suffix = "图片" + case "video": + suffix = "视频" + case "audio": + suffix = "音频" + case "text": + suffix = "文案" + case "html": + suffix = "HTML" } + if _, ok := typeTotal[suffix]; !ok { + typeTotal[suffix] = &totalCnt{} + } + typeTotal[suffix].total++ } - // 初始化当前索引 = 总数量(从最大值开始倒序) + // 初始序号 = 总数,从最大值开始倒序 for _, v := range typeTotal { v.idx = v.total } - // ========== 改动结束 ========== + // ====================================== var tree []flowDto.DateNode - - // 先组装节点再统一排序 - for date, items := range dateMap { + // 按有序日期遍历生成最终数据 + for _, date := range sortedDates { + items := dateMap[date] if len(items) == 0 { continue } - // 逐个打标签,使用倒序序号 + // 逐个生成倒序标签 for idx := range items { item := &items[idx] val := item.Content @@ -223,7 +237,6 @@ func (s *flowExecutionService) List(ctx context.Context, req *flowDto.ListFlowEx suffix = "HTML" } - // 倒序取值,取完自减 cnt := typeTotal[suffix] item.Type = ext item.Label = fmt.Sprintf("%s_%d", suffix, cnt.idx) @@ -236,11 +249,6 @@ func (s *flowExecutionService) List(ctx context.Context, req *flowDto.ListFlowEx }) } - // 日期倒序展示 - sort.Slice(tree, func(i, j int) bool { - return tree[i].CreateDate > tree[j].CreateDate - }) - imgPrefix, err := utils.GetFileAddressPrefix(ctx) return &flowDto.ListFlowExecutionTreeRes{ Tree: tree,