Compare commits

...

2 Commits

Author SHA1 Message Date
daiyb
6ff1789848 Merge branch 'feature-publishLog-daiyb' into dev 2026-03-02 09:52:38 +08:00
daiyb
71517967c8 优化导出 提示 2026-03-02 09:52:30 +08:00

View File

@ -2,6 +2,7 @@ package cast
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
"time" "time"
@ -36,6 +37,7 @@ func PublishLogList(ctx *gin.Context) {
func PublishLogListExport(ctx *gin.Context) { func PublishLogListExport(ctx *gin.Context) {
var req cast.ListPublishLogReq var req cast.ListPublishLogReq
if err := ctx.ShouldBind(&req); err != nil { if err := ctx.ShouldBind(&req); err != nil {
service.Error(ctx, errors.New("绑定参数失败"))
return return
} }
@ -45,6 +47,7 @@ func PublishLogListExport(ctx *gin.Context) {
lockKey := "PublishLogListExport" + fmt.Sprint(loginInfo.ID) lockKey := "PublishLogListExport" + fmt.Sprint(loginInfo.ID)
replay := cache.RedisClient.SetNX(lockKey, time.Now().Unix(), time.Minute*30) replay := cache.RedisClient.SetNX(lockKey, time.Now().Unix(), time.Minute*30)
if !replay.Val() { if !replay.Val() {
service.Error(ctx, errors.New("已有导出任务在进行中,请稍后再试"))
return return
} }
defer cache.RedisClient.Del(lockKey) defer cache.RedisClient.Del(lockKey)
@ -69,6 +72,7 @@ func PublishLogListExport(ctx *gin.Context) {
resp, err := service.CastProvider.ListPublishLog(newCtx, &req) resp, err := service.CastProvider.ListPublishLog(newCtx, &req)
if err != nil { if err != nil {
zap.L().Error("获取发布记录失败", zap.Error(err), zap.Int32("page", page)) zap.L().Error("获取发布记录失败", zap.Error(err), zap.Int32("page", page))
service.Error(ctx, errors.New("获取发布记录失败"))
return return
} }
@ -94,6 +98,7 @@ func PublishLogListExport(ctx *gin.Context) {
zap.L().Info("数据获取完成开始生成Excel", zap.Int("总数据量", len(allData))) zap.L().Info("数据获取完成开始生成Excel", zap.Int("总数据量", len(allData)))
if len(allData) == 0 { if len(allData) == 0 {
service.Error(ctx, errors.New("没有数据可导出"))
return 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)) 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))) 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,
})
} }