Merge branch 'feature-publishLog-daiyb' into dev
This commit is contained in:
commit
6ff1789848
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user