修改导出文件并删除
This commit is contained in:
parent
6f0187209a
commit
7ad44130a2
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
@ -162,7 +163,7 @@ func ExportRegister(c *gin.Context) {
|
||||
}
|
||||
columns := []string{"画家姓名", "性别", "手机号", "身份证号", "通讯地址", "身份证照片", "本人近照", "作品名称", "报名时间", "更新时间"}
|
||||
exportFileName := fmt.Sprintf("%s迁想妙得.xlsx", time.Now().Format("20060102"))
|
||||
filePath := fmt.Sprintf("../runtime/%s", exportFileName)
|
||||
filePath := fmt.Sprintf("./runtime/%s", exportFileName)
|
||||
data := make([]interface{}, 0)
|
||||
for _, v := range resp.Data {
|
||||
var temp []string
|
||||
@ -194,6 +195,13 @@ func ExportRegister(c *gin.Context) {
|
||||
response.ResponseQuickMsg(c, msg.Fail, err.Error(), nil)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if err := os.Remove(filePath); err != nil {
|
||||
logger.Errorf("删除临时文件失败: %v", err)
|
||||
} else {
|
||||
logger.Info("临时文件已清理:", filePath)
|
||||
}
|
||||
}()
|
||||
var httpType string
|
||||
if config.Data.System.IsHttps {
|
||||
httpType = model.HttpsType
|
||||
|
@ -4,17 +4,19 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/dubbogo/gost/log/logger"
|
||||
"github.com/exhibition-main/internal/msg"
|
||||
"github.com/tealeg/xlsx"
|
||||
"go.uber.org/zap"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dubbogo/gost/log/logger"
|
||||
"github.com/exhibition-main/internal/msg"
|
||||
"github.com/tealeg/xlsx"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// PostForm 发送post请求
|
||||
@ -78,6 +80,10 @@ func ToExcelByType(titleList []string, dataList []interface{}, dataType string,
|
||||
var buffer bytes.Buffer
|
||||
_ = file.Write(&buffer)
|
||||
if filePath != "" {
|
||||
dir := filepath.Dir(filePath)
|
||||
if err = CreateDirPath(dir); err != nil {
|
||||
return
|
||||
}
|
||||
if err = file.Save(filePath); err != nil {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user