75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package callback
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/analysis/internal/dao"
|
|
"lone-services/services/analysis/internal/model"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func SaveTask(ts dao.TaskTimeStamp, userId int64, path *dao.HandleZipResource, coverPath string) error {
|
|
m := model.ImageAnalysisModel{}.Init()
|
|
var task dao.ImageAnalysis
|
|
w := modelbase.Params{Eq: map[string]string{"task_id": ts.TaskId}}
|
|
if err := m.GetOne(w, &task); err != nil {
|
|
return err
|
|
}
|
|
|
|
now := utils.Now()
|
|
if task.Id < utils.NumberOne {
|
|
return m.Create(&dao.ImageAnalysis{
|
|
TaskId: ts.TaskId,
|
|
UserId: userId,
|
|
FolderPath: path.TargetDir,
|
|
Status: dao.AnalysisStatusPending,
|
|
UploadCount: 1,
|
|
Cover: coverPath,
|
|
CreatedAt: now,
|
|
UpdatedAt: now,
|
|
})
|
|
}
|
|
|
|
updateData := map[string]interface{}{
|
|
"upload_count": gorm.Expr("upload_count + ?", 1),
|
|
"folder_path": path.TargetDir,
|
|
"updated_at": now,
|
|
}
|
|
if coverPath != utils.StringEmpty {
|
|
updateData["cover"] = coverPath
|
|
}
|
|
_, err := m.Edit(w, updateData)
|
|
return err
|
|
}
|
|
|
|
func SaveSubTask(ts dao.TaskTimeStamp, path *dao.HandleZipResource) error {
|
|
now := utils.Now()
|
|
return model.ImageAnalysisSubModel{}.Init().Create(&dao.ImageAnalysisSub{
|
|
TaskId: ts.TaskId,
|
|
SubTaskId: ts.SubTaskId,
|
|
Status: dao.AnalysisStatusProcessing,
|
|
FilePath: path.FilePath,
|
|
ImageDir: path.FinalDir,
|
|
UploadStartTs: ts.UploadStartTs,
|
|
UploadEndTs: ts.UploadEndTs,
|
|
ProcessStartTs: ts.ProcessStartTs,
|
|
CreatedAt: now,
|
|
UpdatedAt: now,
|
|
})
|
|
}
|
|
|
|
func MarkTaskProcessing(taskId string) error {
|
|
_, err := model.ImageAnalysisModel{}.Init().Edit(modelbase.Params{
|
|
Eq: map[string]string{
|
|
"task_id": taskId,
|
|
"status": strconv.Itoa(int(dao.AnalysisStatusPending)),
|
|
},
|
|
}, map[string]interface{}{
|
|
"status": dao.AnalysisStatusProcessing,
|
|
})
|
|
return err
|
|
}
|