From e7f8993fa56bf5832c202a06649bf14b57596582 Mon Sep 17 00:00:00 2001 From: sxy <3187870250@qq.com> Date: Tue, 12 Aug 2025 10:24:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=97=B6=E9=97=B4=E5=92=8Cuu?= =?UTF-8?q?id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/import/artist.go | 22 +++++++--- pkg/service/import/confirm.go | 16 +++++-- pkg/service/import/publish.go | 83 ++++++++++++++++++++++++++++++++--- 3 files changed, 107 insertions(+), 14 deletions(-) diff --git a/pkg/service/import/artist.go b/pkg/service/import/artist.go index 3dac408..20f4d06 100644 --- a/pkg/service/import/artist.go +++ b/pkg/service/import/artist.go @@ -9,14 +9,26 @@ type ArtistAccount struct { Account map[apiCast.PlatformIDENUM]string `json:"account"` } type ArtistMedia struct { - Id string `json:"id"` - Name string `json:"name"` - Title string `json:"title"` - Img string `json:"img"` - Video string `json:"video"` + Id string `json:"id"` + Name string `json:"name"` + Title string `json:"title"` + Img string `json:"img"` + Video string `json:"video"` + Youtube string `json:"youtube"` + Instagram string `json:"instagram"` + TikTok string `json:"tiktok"` } type FailedRecord struct { Name string `json:"name"` Msg string `json:"msg"` } +type ArtistVideoDetail struct { + Id string `json:"id"` + ArtistName string `json:"artistName"` + Title string `json:"title"` + WorkUuid string `json:"workUuid"` + Youtube string `json:"youtube"` + Instagram string `json:"instagram"` + TikTok string `json:"tiktok"` +} diff --git a/pkg/service/import/confirm.go b/pkg/service/import/confirm.go index c39057d..af95509 100644 --- a/pkg/service/import/confirm.go +++ b/pkg/service/import/confirm.go @@ -52,8 +52,12 @@ func WorkConfirm(c *gin.Context) { // 确认作品并扣除余量 VideoConsumptionNumber: 1, }) if err != nil { - service.Error(c, err) - return + failedRecords = append(failedRecords, FailedRecord{ + Name: v.ArtistName, + Msg: fmt.Sprintf("扣除余额失败: %s", err.Error()), + }) + log.Printf(fmt.Sprintf("扣除余额失败: %s", err.Error())) + continue } _, err = service.CastProvider.UpdateStatus(c, &apiCast.UpdateStatusReq{ WorkAction: apiCast.WorkActionENUM_CONFIRM, @@ -62,8 +66,12 @@ func WorkConfirm(c *gin.Context) { // 确认作品并扣除余量 ConfirmStatus: 1, }) if err != nil { - service.Error(c, err) - return + failedRecords = append(failedRecords, FailedRecord{ + Name: v.ArtistName, + Msg: fmt.Sprintf("更新状态失败: %s", err.Error()), + }) + log.Printf(fmt.Sprintf("更新状态失败: %s", err.Error())) + continue } } service.Success(c, failedRecords) diff --git a/pkg/service/import/publish.go b/pkg/service/import/publish.go index f86a9e3..14ae87f 100644 --- a/pkg/service/import/publish.go +++ b/pkg/service/import/publish.go @@ -85,6 +85,8 @@ func ImportPublish(c *gin.Context) { } // 5.发布视频 var failedRecords []FailedRecord + var artistResp []ArtistVideoDetail + for _, artist := range artists { var infoResp *accountFiee.UserInfoResponse var err error @@ -158,7 +160,7 @@ func ImportPublish(c *gin.Context) { platformIDs = append(platformIDs, apiCast.PlatformIDENUM(info.PlatformID)) } newCtx := cast.NewCtxWithUserInfo(c) - _, err = service.CastProvider.UpdateWorkVideo(newCtx, &apiCast.UpdateWorkVideoReq{ + resp, err := service.CastProvider.UpdateWorkVideo(newCtx, &apiCast.UpdateWorkVideoReq{ Title: artist.Title, Content: artist.Title, VideoUrl: artist.Video, @@ -205,10 +207,28 @@ func ImportPublish(c *gin.Context) { log.Printf(fmt.Sprintf("发布"+artist.Name+"视频"+artist.Title+"失败: %s", err.Error())) continue } + artistResp = append(artistResp, ArtistVideoDetail{ + Id: artist.Id, + ArtistName: artist.Name, + Title: artist.Title, + WorkUuid: resp.WorkUuid, + Youtube: artist.Youtube, + Instagram: artist.Instagram, + TikTok: artist.TikTok, + }) + + } + excelUrl, err := exportRecordsToExcel(artistResp) + if err != nil { + service.Error(c, err) + return } // 6. 返回结果 - service.Success(c, failedRecords) + service.Success(c, map[string]interface{}{ + "excelUrl": excelUrl, + "failedRecords": failedRecords, + }) } func readArtistVideoInfo(excelPath, unzipPath string) ([]ArtistMedia, error) { @@ -244,10 +264,25 @@ func readArtistVideoInfo(excelPath, unzipPath string) ([]ArtistMedia, error) { if title != "" { title = strings.TrimSpace(title) } + youtube, _ := f.GetCellValue(sheetName, fmt.Sprintf("D%d", i+1)) + if youtube != "" { + youtube = strings.TrimSpace(youtube) + } + instagram, _ := f.GetCellValue(sheetName, fmt.Sprintf("E%d", i+1)) + if instagram != "" { + instagram = strings.TrimSpace(instagram) + } + tiktok, _ := f.GetCellValue(sheetName, fmt.Sprintf("F%d", i+1)) + if tiktok != "" { + tiktok = strings.TrimSpace(tiktok) + } artists = append(artists, ArtistMedia{ - Id: id, - Name: artistName, - Title: title, + Id: id, + Name: artistName, + Title: title, + Youtube: youtube, + Instagram: instagram, + TikTok: tiktok, }) } artists, err = matchArtistMedia(artists, unzipPath) @@ -353,3 +388,41 @@ func UploadToAnotherService(ctx context.Context, fileData []byte, path string) e } return nil } +func exportRecordsToExcel(artistInfos []ArtistVideoDetail) (string, error) { + f := excelize.NewFile() + sheet := "Sheet1" + f.NewSheet(sheet) + + // 写表头 + headers := []string{"序号", "画家名", "标题", "uuid", "youtube", "instagram", "tiktok"} + + for col, h := range headers { + _ = f.SetCellValue(sheet, string(rune('A'+col))+"1", h) + } + + // 写数据 + for i, artistInfo := range artistInfos { + row := i + 2 + _ = f.SetCellValue(sheet, "A"+strconv.Itoa(row), artistInfo.Id) + _ = f.SetCellValue(sheet, "B"+strconv.Itoa(row), artistInfo.ArtistName) + _ = f.SetCellValue(sheet, "C"+strconv.Itoa(row), artistInfo.Title) + _ = f.SetCellValue(sheet, "D"+strconv.Itoa(row), artistInfo.WorkUuid) + _ = f.SetCellValue(sheet, "E"+strconv.Itoa(row), artistInfo.Youtube) + _ = f.SetCellValue(sheet, "F"+strconv.Itoa(row), artistInfo.Instagram) + _ = f.SetCellValue(sheet, "G"+strconv.Itoa(row), artistInfo.TikTok) + } + // 保存文件 + filename := "画家视频详情记录.xlsx" + fileDir := "./runtime/import/" // 自定义目录 + _ = os.MkdirAll(fileDir, os.ModePerm) + filePath := filepath.Join(fileDir, filename) + if err := f.SaveAs(filePath); err != nil { + return "", err + } + excelUrl, err := upload.PutBos(filePath, "excel", true) + if err != nil { + return "", err + + } + return excelUrl, nil +}