优化导出 提示

This commit is contained in:
daiyb 2026-03-02 09:52:30 +08:00
parent 65ce2132e7
commit 71517967c8

View File

@ -2,6 +2,7 @@ package cast
import (
"context"
"errors"
"fmt"
"strings"
"time"
@ -36,6 +37,7 @@ func PublishLogList(ctx *gin.Context) {
func PublishLogListExport(ctx *gin.Context) {
var req cast.ListPublishLogReq
if err := ctx.ShouldBind(&req); err != nil {
service.Error(ctx, errors.New("绑定参数失败"))
return
}
@ -45,6 +47,7 @@ func PublishLogListExport(ctx *gin.Context) {
lockKey := "PublishLogListExport" + fmt.Sprint(loginInfo.ID)
replay := cache.RedisClient.SetNX(lockKey, time.Now().Unix(), time.Minute*30)
if !replay.Val() {
service.Error(ctx, errors.New("已有导出任务在进行中,请稍后再试"))
return
}
defer cache.RedisClient.Del(lockKey)
@ -69,6 +72,7 @@ func PublishLogListExport(ctx *gin.Context) {
resp, err := service.CastProvider.ListPublishLog(newCtx, &req)
if err != nil {
zap.L().Error("获取发布记录失败", zap.Error(err), zap.Int32("page", page))
service.Error(ctx, errors.New("获取发布记录失败"))
return
}
@ -94,6 +98,7 @@ func PublishLogListExport(ctx *gin.Context) {
zap.L().Info("数据获取完成开始生成Excel", zap.Int("总数据量", len(allData)))
if len(allData) == 0 {
service.Error(ctx, errors.New("没有数据可导出"))
return
}
@ -115,5 +120,7 @@ func PublishLogListExport(ctx *gin.Context) {
exportUrl := fmt.Sprintf("%s://%s/api/fiee/static/%s", scheme, ctx.Request.Host, strings.Replace(filePath, "./runtime/", "", 1))
zap.L().Info("Excel导出成功", zap.String("文件名", fileName), zap.Int("记录数", len(allData)))
service.Success(ctx, gin.H{"url": exportUrl})
service.Success(ctx, map[string]interface{}{
"url": exportUrl,
})
}