优化导出 提示
This commit is contained in:
parent
65ce2132e7
commit
71517967c8
@ -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,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user