Merge branch 'wwq' into dev
This commit is contained in:
commit
9d35de6b11
@ -111,8 +111,18 @@ func ImageContentImport(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
processor.SetStatus(StatusProcessing)
|
||||
processor = GetBatchProcessorRead()
|
||||
|
||||
qps := 10
|
||||
interval := time.Second / time.Duration(qps)
|
||||
|
||||
for i, v := range readExcelResult {
|
||||
if err := GetBatchProcessorRead().submitSingleTask(v, i); err != nil {
|
||||
// 在每次请求前等待
|
||||
if i > 0 {
|
||||
time.Sleep(interval)
|
||||
}
|
||||
|
||||
if err := processor.submitSingleTask(v, i); err != nil {
|
||||
task := &ImageTask{
|
||||
Data: v,
|
||||
TaskID: strconv.Itoa(i),
|
||||
@ -156,22 +166,33 @@ func readExcel(excelPath string) ([]excelData, error) {
|
||||
var result []excelData
|
||||
for i := 1; i < len(rows); i++ { // 从第2行开始(跳过表头)
|
||||
row := rows[i]
|
||||
|
||||
// 跳过空行
|
||||
if len(row) == 0 || strings.TrimSpace(row[0]) == "" {
|
||||
continue
|
||||
}
|
||||
var num int
|
||||
|
||||
artistName := getCellValue(f, sheetName, i, 0)
|
||||
subNum := getCellValue(f, sheetName, i, 1)
|
||||
tikTok := getCellValue(f, sheetName, i, 2)
|
||||
instagram := getCellValue(f, sheetName, i, 3)
|
||||
youtube := getCellValue(f, sheetName, i, 4)
|
||||
desc := getCellValue(f, sheetName, i, 5)
|
||||
titleRequire := getCellValue(f, sheetName, i, 6)
|
||||
contentRequire := getCellValue(f, sheetName, i, 7)
|
||||
photoRequire := getCellValue(f, sheetName, i, 8)
|
||||
photoUrl := getCellValue(f, sheetName, i, 9)
|
||||
if photoUrl == "" { //如果没有关联画作,数量有用
|
||||
var num int
|
||||
if photoUrl == "" { //如果没有关联画作,数量必须有,需求必须有
|
||||
//需求必须有
|
||||
if photoRequire == "" {
|
||||
return nil, fmt.Errorf("第%d行应该有图片需求", i+1)
|
||||
}
|
||||
photoNumStr := getCellValue(f, sheetName, i, 10)
|
||||
//转换成功
|
||||
photoNum, err := strconv.Atoi(strings.TrimSpace(photoNumStr))
|
||||
if err != nil {
|
||||
// 提供详细的错误信息
|
||||
return nil, fmt.Errorf("第%d行图片数量格式错误: '%s',必须是整数", i+1, photoNumStr)
|
||||
}
|
||||
|
||||
// 验证图片数量范围
|
||||
// 数量大于
|
||||
if photoNum <= 0 {
|
||||
return nil, fmt.Errorf("第%d行图片数量必须大于0,当前值: %d", i+1, photoNum)
|
||||
}
|
||||
@ -179,18 +200,17 @@ func readExcel(excelPath string) ([]excelData, error) {
|
||||
}
|
||||
|
||||
data := excelData{
|
||||
ArtistName: getCellValue(f, sheetName, i, 0),
|
||||
SubNum: getCellValue(f, sheetName, i, 1),
|
||||
TikTok: getCellValue(f, sheetName, i, 2),
|
||||
Instagram: getCellValue(f, sheetName, i, 3),
|
||||
Youtube: getCellValue(f, sheetName, i, 4),
|
||||
Desc: getCellValue(f, sheetName, i, 5),
|
||||
TitleRequire: getCellValue(f, sheetName, i, 6),
|
||||
ContentRequire: getCellValue(f, sheetName, i, 7),
|
||||
PhotoRequire: getCellValue(f, sheetName, i, 8),
|
||||
PhotoUrl: photoUrl,
|
||||
ArtistName: artistName,
|
||||
SubNum: subNum,
|
||||
TikTok: tikTok,
|
||||
Instagram: instagram,
|
||||
Youtube: youtube,
|
||||
Desc: desc,
|
||||
TitleRequire: titleRequire,
|
||||
ContentRequire: contentRequire,
|
||||
PhotoUrl: photoRequire,
|
||||
PhotoNum: num,
|
||||
LineNum: i,
|
||||
LineNum: i, //行数
|
||||
}
|
||||
|
||||
result = append(result, data)
|
||||
|
||||
@ -384,7 +384,8 @@ func (p *BatchProcessor) UpdateTaskStatuses(taskId string) (err error) {
|
||||
p.tasks[taskId].Status = TaskFailed
|
||||
p.inProgress[taskId] = true
|
||||
p.tasks[taskId].EndTime = time.Now()
|
||||
return fmt.Errorf("生成标题和内容失败: %v", err)
|
||||
p.tasks[taskId].Error = fmt.Errorf("生成标题和内容失败: %v", err)
|
||||
return err
|
||||
}
|
||||
p.tasks[taskId].Title = title
|
||||
p.tasks[taskId].Content = content
|
||||
@ -396,10 +397,10 @@ func (p *BatchProcessor) UpdateTaskStatuses(taskId string) (err error) {
|
||||
Content: p.tasks[taskId].Content,
|
||||
GeneratePhotoUrl: []string{p.tasks[taskId].Data.PhotoUrl},
|
||||
}); err != nil {
|
||||
p.tasks[taskId].Error = err
|
||||
p.tasks[taskId].Status = TaskFailed
|
||||
p.inProgress[taskId] = true
|
||||
p.tasks[taskId].EndTime = time.Now()
|
||||
p.tasks[taskId].Error = fmt.Errorf("发布内容失败: %v", err)
|
||||
}
|
||||
p.tasks[taskId].Status = TaskSuccessful
|
||||
p.inProgress[taskId] = true
|
||||
@ -554,15 +555,18 @@ func downloadAndUploadToBucket(imageURL string) (string, error) {
|
||||
|
||||
// 上传到桶
|
||||
BOSClient, err := objstorage.NewOSS(
|
||||
os.Getenv(config.ConfigData.Oss.AccessKeyId),
|
||||
os.Getenv(config.ConfigData.Oss.AccessKeySecret),
|
||||
os.Getenv(config.ConfigData.Oss.Endpoint),
|
||||
//os.Getenv(config.ConfigData.Oss.AccessKeyId),
|
||||
//os.Getenv(config.ConfigData.Oss.AccessKeySecret),
|
||||
//os.Getenv(config.ConfigData.Oss.Endpoint),
|
||||
config.ConfigData.Oss.AccessKeyId,
|
||||
config.ConfigData.Oss.AccessKeySecret,
|
||||
config.ConfigData.Oss.Endpoint,
|
||||
)
|
||||
_, err = BOSClient.PutObjectFromBytes(os.Getenv(config.ConfigData.Oss.BucketName), fileName, fileBytes)
|
||||
_, err = BOSClient.PutObjectFromBytes(config.ConfigData.Oss.BucketName, fileName, fileBytes)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("上传文件失败: %v", err)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s", os.Getenv(config.ConfigData.Oss.CdnHost), fileName)
|
||||
url := fmt.Sprintf("%s/%s", config.ConfigData.Oss.CdnHost, fileName)
|
||||
|
||||
return url, nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user