feat:ai生成图文
This commit is contained in:
parent
eb33d725eb
commit
6b63afbdff
@ -26,33 +26,31 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type excelData struct {
|
type excelData struct {
|
||||||
ArtistName string //艺人 必须字段
|
ArtistName string //艺人 必须字段
|
||||||
SubNum string //用户编号 必须字段
|
SubNum string //用户编号 必须字段
|
||||||
TikTok string
|
TikTok string
|
||||||
Instagram string
|
Instagram string
|
||||||
Youtube string
|
Youtube string
|
||||||
Desc string //艺人简介
|
Desc string //艺人简介
|
||||||
TitleRequire string //标题要求 必须字段
|
TitleRequire string //标题要求 必须字段
|
||||||
ContentRequire string //内容要求 必须字段
|
ContentRequire string //内容要求 必须字段
|
||||||
PhotoRequire string //图片要求 必须字段
|
PhotoRequire string //图片要求 必须字段
|
||||||
PhotoUrl string //画作地址
|
PhotoUrl string //画作地址
|
||||||
PhotoNum int //图片数量 必须字段
|
PhotoNum int //图片数量 必须字段
|
||||||
LineNum int
|
LineNum int
|
||||||
|
MediaAccountUuids []string
|
||||||
|
MediaAccountNames []string
|
||||||
}
|
}
|
||||||
type publishImageReq struct {
|
type publishImageReq struct {
|
||||||
ArtistName string //艺人
|
ArtistName string //艺人
|
||||||
SubNum string //用户编号
|
SubNum string //用户编号
|
||||||
Title string //标题
|
Title string //标题
|
||||||
Content string //内容
|
Content string //内容
|
||||||
GeneratePhotoUrl []string //生成图片地址
|
TikTok string
|
||||||
}
|
Instagram string
|
||||||
|
GeneratePhotoUrl []string //生成图片地址
|
||||||
// 记录处理结果
|
MediaAccountUuids []string
|
||||||
type ProcessResult struct {
|
MediaAccountNames []string
|
||||||
ExcelData excelData
|
|
||||||
Success bool
|
|
||||||
ErrorMessage string
|
|
||||||
TaskID string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getErrorMessage(err error) string {
|
func getErrorMessage(err error) string {
|
||||||
@ -166,27 +164,44 @@ func readExcel(excelPath string) ([]excelData, error) {
|
|||||||
var result []excelData
|
var result []excelData
|
||||||
for i := 1; i < len(rows); i++ { // 从第2行开始(跳过表头)
|
for i := 1; i < len(rows); i++ { // 从第2行开始(跳过表头)
|
||||||
row := rows[i]
|
row := rows[i]
|
||||||
if len(row) == 0 || strings.TrimSpace(row[0]) == "" {
|
if len(row) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
artistName := getCellValue(f, sheetName, i, 0)
|
artistName := getCellValue(f, sheetName, i, 0)
|
||||||
|
if artistName == "" {
|
||||||
|
return nil, fmt.Errorf("第%d行应该有艺人名称", i+1)
|
||||||
|
}
|
||||||
subNum := getCellValue(f, sheetName, i, 1)
|
subNum := getCellValue(f, sheetName, i, 1)
|
||||||
|
if subNum == "" {
|
||||||
|
return nil, fmt.Errorf("第%d行应该有编号", i+1)
|
||||||
|
}
|
||||||
tikTok := getCellValue(f, sheetName, i, 2)
|
tikTok := getCellValue(f, sheetName, i, 2)
|
||||||
|
if tikTok == "" {
|
||||||
|
return nil, fmt.Errorf("第%d行应该有tiktok账号昵称", i+1)
|
||||||
|
}
|
||||||
instagram := getCellValue(f, sheetName, i, 3)
|
instagram := getCellValue(f, sheetName, i, 3)
|
||||||
youtube := getCellValue(f, sheetName, i, 4)
|
if instagram == "" {
|
||||||
desc := getCellValue(f, sheetName, i, 5)
|
return nil, fmt.Errorf("第%d行应该有ins账号昵称", i+1)
|
||||||
titleRequire := getCellValue(f, sheetName, i, 6)
|
}
|
||||||
contentRequire := getCellValue(f, sheetName, i, 7)
|
desc := getCellValue(f, sheetName, i, 4)
|
||||||
photoRequire := getCellValue(f, sheetName, i, 8)
|
titleRequire := getCellValue(f, sheetName, i, 5)
|
||||||
photoUrl := getCellValue(f, sheetName, i, 9)
|
if titleRequire == "" {
|
||||||
|
return nil, fmt.Errorf("第%d行应该有标题要求", i+1)
|
||||||
|
}
|
||||||
|
contentRequire := getCellValue(f, sheetName, i, 6)
|
||||||
|
if contentRequire == "" {
|
||||||
|
return nil, fmt.Errorf("第%d行应该有内容要求", i+1)
|
||||||
|
}
|
||||||
|
photoRequire := getCellValue(f, sheetName, i, 7)
|
||||||
|
photoUrl := getCellValue(f, sheetName, i, 8)
|
||||||
|
photoNumStr := getCellValue(f, sheetName, i, 9)
|
||||||
var num int
|
var num int
|
||||||
if photoUrl == "" { //如果没有关联画作,数量必须有,需求必须有
|
if photoUrl == "" { //如果没有关联画作,数量必须有,需求必须有
|
||||||
//需求必须有
|
//需求必须有
|
||||||
if photoRequire == "" {
|
if photoRequire == "" {
|
||||||
return nil, fmt.Errorf("第%d行应该有图片需求", i+1)
|
return nil, fmt.Errorf("第%d行应该有图片需求", i+1)
|
||||||
}
|
}
|
||||||
photoNumStr := getCellValue(f, sheetName, i, 10)
|
|
||||||
//转换成功
|
//转换成功
|
||||||
photoNum, err := strconv.Atoi(strings.TrimSpace(photoNumStr))
|
photoNum, err := strconv.Atoi(strings.TrimSpace(photoNumStr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -204,11 +219,11 @@ func readExcel(excelPath string) ([]excelData, error) {
|
|||||||
SubNum: subNum,
|
SubNum: subNum,
|
||||||
TikTok: tikTok,
|
TikTok: tikTok,
|
||||||
Instagram: instagram,
|
Instagram: instagram,
|
||||||
Youtube: youtube,
|
|
||||||
Desc: desc,
|
Desc: desc,
|
||||||
TitleRequire: titleRequire,
|
TitleRequire: titleRequire,
|
||||||
ContentRequire: contentRequire,
|
ContentRequire: contentRequire,
|
||||||
PhotoUrl: photoRequire,
|
PhotoRequire: photoRequire,
|
||||||
|
PhotoUrl: photoUrl,
|
||||||
PhotoNum: num,
|
PhotoNum: num,
|
||||||
LineNum: i, //行数
|
LineNum: i, //行数
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,13 @@
|
|||||||
package imports
|
package imports
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"fonchain-fiee/api/accountFiee"
|
||||||
|
apiCast "fonchain-fiee/api/cast"
|
||||||
"fonchain-fiee/pkg/config"
|
"fonchain-fiee/pkg/config"
|
||||||
|
"fonchain-fiee/pkg/service"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -108,6 +112,77 @@ func (p *BatchProcessor) GetStatus() int {
|
|||||||
|
|
||||||
// 提交任务
|
// 提交任务
|
||||||
func (p *BatchProcessor) submitSingleTask(req excelData, num int) error {
|
func (p *BatchProcessor) submitSingleTask(req excelData, num int) error {
|
||||||
|
//var infoResp *accountFiee.UserInfoResponse
|
||||||
|
list, err := service.AccountFieeProvider.UserList(context.Background(), &accountFiee.UserListRequest{
|
||||||
|
Name: req.ArtistName,
|
||||||
|
SubNum: req.SubNum,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("获取用户信息失败: %s", err.Error())
|
||||||
|
}
|
||||||
|
if len(list.UserList) == 0 {
|
||||||
|
return fmt.Errorf("未找到用户信息: %s", req.ArtistName)
|
||||||
|
}
|
||||||
|
if len(list.UserList) > 0 {
|
||||||
|
_, err = service.AccountFieeProvider.Info(context.Background(), &accountFiee.InfoRequest{
|
||||||
|
ID: list.UserList[0].Id,
|
||||||
|
Domain: "app",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("获取用户信息失败: %s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
accountListTikTok, err := service.CastProvider.MediaUserList(context.Background(), &apiCast.MediaUserListReq{
|
||||||
|
ArtistVal: req.ArtistName,
|
||||||
|
PlatformID: 1,
|
||||||
|
Page: 1,
|
||||||
|
PageSize: 10,
|
||||||
|
ArtistUuid: strconv.FormatUint(list.UserList[0].Id, 10),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("tiktok自媒体账号数量获取失败: %s,账号数量:%d", err.Error(), len(accountListTikTok.Data))
|
||||||
|
}
|
||||||
|
if accountListTikTok == nil || len(accountListTikTok.Data) == 0 {
|
||||||
|
return fmt.Errorf("tiktok自媒体账号数量为0")
|
||||||
|
}
|
||||||
|
tiktokFound := false
|
||||||
|
for _, user := range accountListTikTok.Data {
|
||||||
|
if user.PlatformUserName == req.TikTok {
|
||||||
|
req.MediaAccountNames = append(req.MediaAccountNames, user.PlatformUserName)
|
||||||
|
req.MediaAccountUuids = append(req.MediaAccountUuids, user.MediaAccountUuid)
|
||||||
|
tiktokFound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !tiktokFound {
|
||||||
|
return fmt.Errorf("未找到匹配的TikTok账号: %s", req.TikTok)
|
||||||
|
}
|
||||||
|
accountListIns, err := service.CastProvider.MediaUserList(context.Background(), &apiCast.MediaUserListReq{
|
||||||
|
ArtistVal: req.ArtistName,
|
||||||
|
PlatformID: 3,
|
||||||
|
Page: 1,
|
||||||
|
PageSize: 10,
|
||||||
|
ArtistUuid: strconv.FormatUint(list.UserList[0].Id, 10),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ins自媒体账号数量获取失败: %s,账号数量:%d", err.Error(), len(accountListIns.Data))
|
||||||
|
}
|
||||||
|
if accountListIns == nil || len(accountListIns.Data) == 0 {
|
||||||
|
return fmt.Errorf("ins自媒体账号数量为0")
|
||||||
|
}
|
||||||
|
insFound := false
|
||||||
|
for _, user := range accountListIns.Data {
|
||||||
|
if user.PlatformUserName == req.Instagram {
|
||||||
|
req.MediaAccountNames = append(req.MediaAccountNames, user.PlatformUserName)
|
||||||
|
req.MediaAccountUuids = append(req.MediaAccountUuids, user.MediaAccountUuid)
|
||||||
|
insFound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !insFound {
|
||||||
|
return fmt.Errorf("未找到匹配的Instagram账号: %s", req.Instagram)
|
||||||
|
}
|
||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
defer p.mu.Unlock()
|
defer p.mu.Unlock()
|
||||||
//title, content, err := p.generateTitleAndContent(req)
|
//title, content, err := p.generateTitleAndContent(req)
|
||||||
@ -396,6 +471,8 @@ func (p *BatchProcessor) UpdateTaskStatuses(taskId string) (err error) {
|
|||||||
Title: p.tasks[taskId].Title,
|
Title: p.tasks[taskId].Title,
|
||||||
Content: p.tasks[taskId].Content,
|
Content: p.tasks[taskId].Content,
|
||||||
GeneratePhotoUrl: []string{p.tasks[taskId].Data.PhotoUrl},
|
GeneratePhotoUrl: []string{p.tasks[taskId].Data.PhotoUrl},
|
||||||
|
TikTok: p.tasks[taskId].Data.TikTok,
|
||||||
|
Instagram: p.tasks[taskId].Data.Instagram,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
p.tasks[taskId].Status = TaskFailed
|
p.tasks[taskId].Status = TaskFailed
|
||||||
p.inProgress[taskId] = true
|
p.inProgress[taskId] = true
|
||||||
@ -455,6 +532,8 @@ func (p *BatchProcessor) UpdateTaskStatuses(taskId string) (err error) {
|
|||||||
SubNum: p.tasks[getTaskDetailRes.Output.TaskID].Data.SubNum,
|
SubNum: p.tasks[getTaskDetailRes.Output.TaskID].Data.SubNum,
|
||||||
Title: p.tasks[getTaskDetailRes.Output.TaskID].Title,
|
Title: p.tasks[getTaskDetailRes.Output.TaskID].Title,
|
||||||
Content: p.tasks[getTaskDetailRes.Output.TaskID].Content,
|
Content: p.tasks[getTaskDetailRes.Output.TaskID].Content,
|
||||||
|
TikTok: p.tasks[taskId].Data.TikTok,
|
||||||
|
Instagram: p.tasks[taskId].Data.Instagram,
|
||||||
GeneratePhotoUrl: uploadedURLs,
|
GeneratePhotoUrl: uploadedURLs,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
localTask.Status = TaskFailed
|
localTask.Status = TaskFailed
|
||||||
|
|||||||
@ -32,35 +32,38 @@ func publishImage(req publishImageReq) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------获取自媒体账号
|
//-----------------------------------------------------获取自媒体账号
|
||||||
accountList, err := service.CastProvider.MediaUserList(context.Background(), &apiCast.MediaUserListReq{
|
//accountList, err := service.CastProvider.MediaUserList(context.Background(), &apiCast.MediaUserListReq{
|
||||||
ArtistUuid: strconv.FormatUint(list.UserList[0].Id, 10),
|
// ArtistUuid: strconv.FormatUint(list.UserList[0].Id, 10),
|
||||||
ArtistVal: req.ArtistName,
|
// ArtistVal: req.ArtistName,
|
||||||
Page: 1,
|
// Page: 1,
|
||||||
PageSize: 10,
|
// PageSize: 10,
|
||||||
})
|
//})
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
return fmt.Errorf("自媒体账号数量获取失败: %s,账号数量:%d", err.Error(), len(accountList.Data))
|
// return fmt.Errorf("自媒体账号数量获取失败: %s,账号数量:%d", err.Error(), len(accountList.Data))
|
||||||
}
|
//}
|
||||||
if accountList == nil || len(accountList.Data) == 0 {
|
//if accountList == nil || len(accountList.Data) == 0 {
|
||||||
return fmt.Errorf("自媒体账号数量为0")
|
// return fmt.Errorf("自媒体账号数量为0")
|
||||||
}
|
//}
|
||||||
var mediaAccountUuids []string
|
//var mediaAccountUuids []string
|
||||||
var mediaAccountNames []string
|
//var mediaAccountNames []string
|
||||||
platformIDs := []apiCast.PlatformIDENUM{}
|
//platformIDs 1 tiktok 2youtube 3ins
|
||||||
for _, info := range accountList.Data {
|
//platformIDs := []apiCast.PlatformIDENUM{}
|
||||||
mediaAccountUuids = append(mediaAccountUuids, info.MediaAccountUuid)
|
//for _, info := range accountList.Data {
|
||||||
mediaAccountNames = append(mediaAccountNames, info.PlatformUserName)
|
// if info.ArtistName == req.TikTok || info.ArtistName == req.Instagram {
|
||||||
platformIDs = append(platformIDs, apiCast.PlatformIDENUM(info.PlatformID))
|
// mediaAccountUuids = append(mediaAccountUuids, info.MediaAccountUuid)
|
||||||
}
|
// mediaAccountNames = append(mediaAccountNames, info.PlatformUserName)
|
||||||
|
// platformIDs = append(platformIDs, apiCast.PlatformIDENUM(info.PlatformID))
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
//---------------------------------------------------发布
|
//---------------------------------------------------发布
|
||||||
_, err = service.CastProvider.UpdateWorkImage(context.Background(), &apiCast.UpdateWorkImageReq{
|
_, err = service.CastProvider.UpdateWorkImage(context.Background(), &apiCast.UpdateWorkImageReq{
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Content: req.Content,
|
Content: req.Content,
|
||||||
Images: req.GeneratePhotoUrl,
|
Images: req.GeneratePhotoUrl,
|
||||||
MediaAccountUuids: mediaAccountUuids,
|
MediaAccountUuids: req.MediaAccountUuids,
|
||||||
MediaAccountNames: mediaAccountNames,
|
MediaAccountNames: req.MediaAccountNames,
|
||||||
PlatformIDs: platformIDs,
|
PlatformIDs: []apiCast.PlatformIDENUM{1, 3},
|
||||||
PublishConfig1: &apiCast.PublishConfig{
|
PublishConfig1: &apiCast.PublishConfig{
|
||||||
CanComment: 1,
|
CanComment: 1,
|
||||||
CanJoin: 1,
|
CanJoin: 1,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user