Merge branch 'feat-sxy-import' into dev
This commit is contained in:
commit
db0c064828
@ -14,9 +14,21 @@ type ArtistMedia struct {
|
|||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Img string `json:"img"`
|
Img string `json:"img"`
|
||||||
Video string `json:"video"`
|
Video string `json:"video"`
|
||||||
|
Youtube string `json:"youtube"`
|
||||||
|
Instagram string `json:"instagram"`
|
||||||
|
TikTok string `json:"tiktok"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FailedRecord struct {
|
type FailedRecord struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Msg string `json:"msg"`
|
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"`
|
||||||
|
}
|
||||||
|
@ -52,8 +52,12 @@ func WorkConfirm(c *gin.Context) { // 确认作品并扣除余量
|
|||||||
VideoConsumptionNumber: 1,
|
VideoConsumptionNumber: 1,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
service.Error(c, err)
|
failedRecords = append(failedRecords, FailedRecord{
|
||||||
return
|
Name: v.ArtistName,
|
||||||
|
Msg: fmt.Sprintf("扣除余额失败: %s", err.Error()),
|
||||||
|
})
|
||||||
|
log.Printf(fmt.Sprintf("扣除余额失败: %s", err.Error()))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
_, err = service.CastProvider.UpdateStatus(c, &apiCast.UpdateStatusReq{
|
_, err = service.CastProvider.UpdateStatus(c, &apiCast.UpdateStatusReq{
|
||||||
WorkAction: apiCast.WorkActionENUM_CONFIRM,
|
WorkAction: apiCast.WorkActionENUM_CONFIRM,
|
||||||
@ -62,8 +66,12 @@ func WorkConfirm(c *gin.Context) { // 确认作品并扣除余量
|
|||||||
ConfirmStatus: 1,
|
ConfirmStatus: 1,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
service.Error(c, err)
|
failedRecords = append(failedRecords, FailedRecord{
|
||||||
return
|
Name: v.ArtistName,
|
||||||
|
Msg: fmt.Sprintf("更新状态失败: %s", err.Error()),
|
||||||
|
})
|
||||||
|
log.Printf(fmt.Sprintf("更新状态失败: %s", err.Error()))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
service.Success(c, failedRecords)
|
service.Success(c, failedRecords)
|
||||||
|
@ -85,6 +85,8 @@ func ImportPublish(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
// 5.发布视频
|
// 5.发布视频
|
||||||
var failedRecords []FailedRecord
|
var failedRecords []FailedRecord
|
||||||
|
var artistResp []ArtistVideoDetail
|
||||||
|
|
||||||
for _, artist := range artists {
|
for _, artist := range artists {
|
||||||
var infoResp *accountFiee.UserInfoResponse
|
var infoResp *accountFiee.UserInfoResponse
|
||||||
var err error
|
var err error
|
||||||
@ -158,7 +160,7 @@ func ImportPublish(c *gin.Context) {
|
|||||||
platformIDs = append(platformIDs, apiCast.PlatformIDENUM(info.PlatformID))
|
platformIDs = append(platformIDs, apiCast.PlatformIDENUM(info.PlatformID))
|
||||||
}
|
}
|
||||||
newCtx := cast.NewCtxWithUserInfo(c)
|
newCtx := cast.NewCtxWithUserInfo(c)
|
||||||
_, err = service.CastProvider.UpdateWorkVideo(newCtx, &apiCast.UpdateWorkVideoReq{
|
resp, err := service.CastProvider.UpdateWorkVideo(newCtx, &apiCast.UpdateWorkVideoReq{
|
||||||
Title: artist.Title,
|
Title: artist.Title,
|
||||||
Content: artist.Title,
|
Content: artist.Title,
|
||||||
VideoUrl: artist.Video,
|
VideoUrl: artist.Video,
|
||||||
@ -205,10 +207,28 @@ func ImportPublish(c *gin.Context) {
|
|||||||
log.Printf(fmt.Sprintf("发布"+artist.Name+"视频"+artist.Title+"失败: %s", err.Error()))
|
log.Printf(fmt.Sprintf("发布"+artist.Name+"视频"+artist.Title+"失败: %s", err.Error()))
|
||||||
continue
|
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. 返回结果
|
// 6. 返回结果
|
||||||
service.Success(c, failedRecords)
|
service.Success(c, map[string]interface{}{
|
||||||
|
"excelUrl": excelUrl,
|
||||||
|
"failedRecords": failedRecords,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func readArtistVideoInfo(excelPath, unzipPath string) ([]ArtistMedia, error) {
|
func readArtistVideoInfo(excelPath, unzipPath string) ([]ArtistMedia, error) {
|
||||||
@ -244,10 +264,25 @@ func readArtistVideoInfo(excelPath, unzipPath string) ([]ArtistMedia, error) {
|
|||||||
if title != "" {
|
if title != "" {
|
||||||
title = strings.TrimSpace(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{
|
artists = append(artists, ArtistMedia{
|
||||||
Id: id,
|
Id: id,
|
||||||
Name: artistName,
|
Name: artistName,
|
||||||
Title: title,
|
Title: title,
|
||||||
|
Youtube: youtube,
|
||||||
|
Instagram: instagram,
|
||||||
|
TikTok: tiktok,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
artists, err = matchArtistMedia(artists, unzipPath)
|
artists, err = matchArtistMedia(artists, unzipPath)
|
||||||
@ -353,3 +388,41 @@ func UploadToAnotherService(ctx context.Context, fileData []byte, path string) e
|
|||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user