cid适配ppgo_job
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
package dataengine
|
||||
|
||||
import (
|
||||
consts "cid/consts/dataengine"
|
||||
daoEntity "cid/model/entity/dataengine"
|
||||
"context"
|
||||
|
||||
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
|
||||
"github.com/bwmarrin/snowflake"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
@@ -51,7 +49,7 @@ func (d *MaterialVerifyLogDAO) Create(ctx context.Context, log *daoEntity.Materi
|
||||
// GetByID 根据ID获取日志
|
||||
func (d *MaterialVerifyLogDAO) GetByID(ctx context.Context, id int64) (*daoEntity.MaterialVerifyLog, error) {
|
||||
var result daoEntity.MaterialVerifyLog
|
||||
r, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
r, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.Id, id).
|
||||
One()
|
||||
if err != nil {
|
||||
@@ -69,7 +67,7 @@ func (d *MaterialVerifyLogDAO) GetByID(ctx context.Context, id int64) (*daoEntit
|
||||
// GetByTaskID 根据任务ID获取日志
|
||||
func (d *MaterialVerifyLogDAO) GetByTaskID(ctx context.Context, taskID string) (*daoEntity.MaterialVerifyLog, error) {
|
||||
var result daoEntity.MaterialVerifyLog
|
||||
r, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
r, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.TaskID, taskID).
|
||||
One()
|
||||
if err != nil {
|
||||
@@ -87,7 +85,7 @@ func (d *MaterialVerifyLogDAO) GetByTaskID(ctx context.Context, taskID string) (
|
||||
// GetByMaterialID 根据素材ID获取日志列表
|
||||
func (d *MaterialVerifyLogDAO) GetByMaterialID(ctx context.Context, materialID string) ([]daoEntity.MaterialVerifyLog, error) {
|
||||
var result []daoEntity.MaterialVerifyLog
|
||||
r, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
r, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.MaterialID, materialID).
|
||||
OrderDesc(daoEntity.MaterialVerifyLogCols.CreatedAt).
|
||||
All()
|
||||
@@ -103,7 +101,7 @@ func (d *MaterialVerifyLogDAO) GetByMaterialID(ctx context.Context, materialID s
|
||||
// GetBySource 根据来源获取日志
|
||||
func (d *MaterialVerifyLogDAO) GetBySource(ctx context.Context, sourceTable string, sourceID int64) ([]daoEntity.MaterialVerifyLog, error) {
|
||||
var result []daoEntity.MaterialVerifyLog
|
||||
r, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
r, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.SourceTable, sourceTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.SourceID, sourceID).
|
||||
OrderDesc(daoEntity.MaterialVerifyLogCols.CreatedAt).
|
||||
@@ -119,7 +117,7 @@ func (d *MaterialVerifyLogDAO) GetBySource(ctx context.Context, sourceTable stri
|
||||
|
||||
// UpdateVerifyResult 更新校验结果
|
||||
func (d *MaterialVerifyLogDAO) UpdateVerifyResult(ctx context.Context, id int64, verifyStatus string, suggestion, label, resultType int, responseResult string, checkTime int64) error {
|
||||
_, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
_, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.Id, id).
|
||||
Data(g.Map{
|
||||
daoEntity.MaterialVerifyLogCols.VerifyStatus: verifyStatus,
|
||||
@@ -138,7 +136,7 @@ func (d *MaterialVerifyLogDAO) UpdateVerifyResult(ctx context.Context, id int64,
|
||||
|
||||
// UpdateError 更新错误信息
|
||||
func (d *MaterialVerifyLogDAO) UpdateError(ctx context.Context, id int64, verifyStatus string, errorMsg string) error {
|
||||
_, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
_, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.Id, id).
|
||||
Data(g.Map{
|
||||
daoEntity.MaterialVerifyLogCols.VerifyStatus: verifyStatus,
|
||||
@@ -153,7 +151,7 @@ func (d *MaterialVerifyLogDAO) UpdateError(ctx context.Context, id int64, verify
|
||||
|
||||
// UpdateTaskID 更新任务ID
|
||||
func (d *MaterialVerifyLogDAO) UpdateTaskID(ctx context.Context, id int64, taskID string) error {
|
||||
_, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
_, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.Id, id).
|
||||
Data(g.Map{
|
||||
daoEntity.MaterialVerifyLogCols.TaskID: taskID,
|
||||
@@ -166,7 +164,7 @@ func (d *MaterialVerifyLogDAO) UpdateTaskID(ctx context.Context, id int64, taskI
|
||||
|
||||
// UpdateDuration 更新处理耗时
|
||||
func (d *MaterialVerifyLogDAO) UpdateDuration(ctx context.Context, id int64, durationMs int64) error {
|
||||
_, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
_, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.Id, id).
|
||||
Data(g.Map{
|
||||
daoEntity.MaterialVerifyLogCols.DurationMs: durationMs,
|
||||
@@ -179,7 +177,7 @@ func (d *MaterialVerifyLogDAO) UpdateDuration(ctx context.Context, id int64, dur
|
||||
|
||||
// UpdateRequestParams 更新请求参数
|
||||
func (d *MaterialVerifyLogDAO) UpdateRequestParams(ctx context.Context, id int64, requestParams string) error {
|
||||
_, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
_, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.Id, id).
|
||||
Data(g.Map{
|
||||
daoEntity.MaterialVerifyLogCols.RequestParams: requestParams,
|
||||
@@ -193,7 +191,7 @@ func (d *MaterialVerifyLogDAO) UpdateRequestParams(ctx context.Context, id int64
|
||||
// GetByCondition 根据条件分页查询
|
||||
func (d *MaterialVerifyLogDAO) GetByCondition(ctx context.Context, condition map[string]interface{}, page, pageSize int) ([]daoEntity.MaterialVerifyLog, int, error) {
|
||||
var result []daoEntity.MaterialVerifyLog
|
||||
m := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable)
|
||||
m := g.DB("cid").Model(MaterialVerifyLogTable)
|
||||
|
||||
for k, v := range condition {
|
||||
m.Where(k, v)
|
||||
@@ -219,7 +217,7 @@ func (d *MaterialVerifyLogDAO) GetByCondition(ctx context.Context, condition map
|
||||
|
||||
// CountByStatus 按状态统计
|
||||
func (d *MaterialVerifyLogDAO) CountByStatus(ctx context.Context, verifyStatus string) (int, error) {
|
||||
count, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
count, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.VerifyStatus, verifyStatus).
|
||||
Count()
|
||||
if err != nil {
|
||||
@@ -259,8 +257,8 @@ func (d *MaterialVerifyLogDAO) GetStats(ctx context.Context) (map[string]int, er
|
||||
func (d *MaterialVerifyLogDAO) GetPendingResults(ctx context.Context, limit int) ([]daoEntity.MaterialVerifyLog, error) {
|
||||
var result []daoEntity.MaterialVerifyLog
|
||||
|
||||
r, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.VerifyStatus, consts.CheckStatusPending).
|
||||
r, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.VerifyStatus, daoEntity.VerifyStatusPending).
|
||||
WhereNotNull(daoEntity.MaterialVerifyLogCols.TaskID).
|
||||
Where(daoEntity.MaterialVerifyLogCols.TaskID + " != ''").
|
||||
OrderAsc(daoEntity.MaterialVerifyLogCols.CreatedAt).
|
||||
@@ -280,7 +278,7 @@ func (d *MaterialVerifyLogDAO) GetPendingResults(ctx context.Context, limit int)
|
||||
// GetLastRejectedLogByMaterialID 根据素材ID获取最后一条失败的校验日志
|
||||
func (d *MaterialVerifyLogDAO) GetLastRejectedLogByMaterialID(ctx context.Context, materialID string, verifyStatus string) (*daoEntity.MaterialVerifyLog, error) {
|
||||
var result daoEntity.MaterialVerifyLog
|
||||
r, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
r, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.MaterialID, materialID).
|
||||
Where(daoEntity.MaterialVerifyLogCols.VerifyStatus, verifyStatus).
|
||||
OrderDesc(daoEntity.MaterialVerifyLogCols.CreatedAt).
|
||||
@@ -297,10 +295,24 @@ func (d *MaterialVerifyLogDAO) GetLastRejectedLogByMaterialID(ctx context.Contex
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// UpdateRiskDescription 更新风险描述
|
||||
func (d *MaterialVerifyLogDAO) UpdateRiskDescription(ctx context.Context, id int64, riskDescription string) error {
|
||||
_, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.Id, id).
|
||||
Data(g.Map{
|
||||
daoEntity.MaterialVerifyLogCols.RiskDescription: riskDescription,
|
||||
}).Update()
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "更新风险描述失败: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CountPendingResults 统计待查询结果的数量
|
||||
func (d *MaterialVerifyLogDAO) CountPendingResults(ctx context.Context) (int, error) {
|
||||
count, err := gfdb.DB(ctx, "cid").Model(ctx, MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.VerifyStatus, consts.CheckStatusPending).
|
||||
count, err := g.DB("cid").Model(MaterialVerifyLogTable).
|
||||
Where(daoEntity.MaterialVerifyLogCols.VerifyStatus, daoEntity.VerifyStatusPending).
|
||||
WhereNotNull(daoEntity.MaterialVerifyLogCols.TaskID).
|
||||
Where(daoEntity.MaterialVerifyLogCols.TaskID + " != ''").
|
||||
Count()
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
|
||||
"github.com/bwmarrin/snowflake"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
@@ -53,7 +52,7 @@ func (d *TencentContentCheckLogDAO) Create(ctx context.Context, log *entity.Tenc
|
||||
|
||||
// UpdateStatus 更新送检状态
|
||||
func (d *TencentContentCheckLogDAO) UpdateStatus(ctx context.Context, id int64, status string, responseData string, failReason string) error {
|
||||
_, err := gfdb.DB(ctx, "cid").Model(ctx, consts.TencentContentCheckLogTable).
|
||||
_, err := g.DB("cid").Model(consts.TencentContentCheckLogTable).
|
||||
Where("id", id).
|
||||
Data(g.Map{
|
||||
"status": status,
|
||||
@@ -65,7 +64,7 @@ func (d *TencentContentCheckLogDAO) UpdateStatus(ctx context.Context, id int64,
|
||||
|
||||
// UpdateCheckResult 更新检测结果
|
||||
func (d *TencentContentCheckLogDAO) UpdateCheckResult(ctx context.Context, id int64, suggestion, label, resultType int, checkTime int64) error {
|
||||
_, err := gfdb.DB(ctx, "cid").Model(ctx, consts.TencentContentCheckLogTable).
|
||||
_, err := g.DB("cid").Model(consts.TencentContentCheckLogTable).
|
||||
Where("id", id).
|
||||
Data(g.Map{
|
||||
"status": consts.CheckStatusCompleted,
|
||||
@@ -80,7 +79,7 @@ func (d *TencentContentCheckLogDAO) UpdateCheckResult(ctx context.Context, id in
|
||||
// GetByID 根据ID获取日志
|
||||
func (d *TencentContentCheckLogDAO) GetByID(ctx context.Context, id int64) (*entity.TencentContentCheckLog, error) {
|
||||
var result entity.TencentContentCheckLog
|
||||
r, err := gfdb.DB(ctx, "cid").Model(ctx, consts.TencentContentCheckLogTable).
|
||||
r, err := g.DB("cid").Model(consts.TencentContentCheckLogTable).
|
||||
Where("id", id).
|
||||
One()
|
||||
if err != nil {
|
||||
@@ -98,7 +97,7 @@ func (d *TencentContentCheckLogDAO) GetByID(ctx context.Context, id int64) (*ent
|
||||
// GetBySourceID 根据来源ID获取日志
|
||||
func (d *TencentContentCheckLogDAO) GetBySourceID(ctx context.Context, sourceTable string, sourceID int64) ([]entity.TencentContentCheckLog, error) {
|
||||
var result []entity.TencentContentCheckLog
|
||||
r, err := gfdb.DB(ctx, "cid").Model(ctx, consts.TencentContentCheckLogTable).
|
||||
r, err := g.DB("cid").Model(consts.TencentContentCheckLogTable).
|
||||
Where("source_table", sourceTable).
|
||||
Where("source_id", sourceID).
|
||||
OrderDesc("created_at").
|
||||
@@ -115,7 +114,7 @@ func (d *TencentContentCheckLogDAO) GetBySourceID(ctx context.Context, sourceTab
|
||||
// GetByTaskID 根据任务ID获取日志
|
||||
func (d *TencentContentCheckLogDAO) GetByTaskID(ctx context.Context, taskID string) (*entity.TencentContentCheckLog, error) {
|
||||
var result entity.TencentContentCheckLog
|
||||
r, err := gfdb.DB(ctx, "cid").Model(ctx, consts.TencentContentCheckLogTable).
|
||||
r, err := g.DB("cid").Model(consts.TencentContentCheckLogTable).
|
||||
Where("task_id", taskID).
|
||||
One()
|
||||
if err != nil {
|
||||
@@ -133,7 +132,7 @@ func (d *TencentContentCheckLogDAO) GetByTaskID(ctx context.Context, taskID stri
|
||||
// ListByStatus 根据状态获取日志列表
|
||||
func (d *TencentContentCheckLogDAO) ListByStatus(ctx context.Context, status string, page, pageSize int) ([]entity.TencentContentCheckLog, int, error) {
|
||||
var result []entity.TencentContentCheckLog
|
||||
m := gfdb.DB(ctx, "cid").Model(ctx, consts.TencentContentCheckLogTable)
|
||||
m := g.DB("cid").Model(consts.TencentContentCheckLogTable)
|
||||
|
||||
if status != "" {
|
||||
m.Where("status", status)
|
||||
@@ -159,7 +158,7 @@ func (d *TencentContentCheckLogDAO) ListByStatus(ctx context.Context, status str
|
||||
|
||||
// UpdateDuration 更新耗时
|
||||
func (d *TencentContentCheckLogDAO) UpdateDuration(ctx context.Context, id int64, duration int64) error {
|
||||
_, err := gfdb.DB(ctx, "cid").Model(ctx, consts.TencentContentCheckLogTable).
|
||||
_, err := g.DB("cid").Model(consts.TencentContentCheckLogTable).
|
||||
Where("id", id).
|
||||
Data("duration", duration).
|
||||
Update()
|
||||
@@ -168,7 +167,7 @@ func (d *TencentContentCheckLogDAO) UpdateDuration(ctx context.Context, id int64
|
||||
|
||||
// UpdateTaskID 更新任务ID
|
||||
func (d *TencentContentCheckLogDAO) UpdateTaskID(ctx context.Context, id int64, taskID string) error {
|
||||
_, err := gfdb.DB(ctx, "cid").Model(ctx, consts.TencentContentCheckLogTable).
|
||||
_, err := g.DB("cid").Model(consts.TencentContentCheckLogTable).
|
||||
Where("id", id).
|
||||
Data("task_id", taskID).
|
||||
Update()
|
||||
|
||||
@@ -121,6 +121,22 @@ func (d *TencentImageDAO) GetByCondition(ctx context.Context, condition map[stri
|
||||
return result, int(total), nil
|
||||
}
|
||||
|
||||
// ClaimPending 原子地尝试将图片从 PENDING 状态转为 SUBMITTING
|
||||
// 返回 true 表示成功抢到处理权,false 表示已被其他进程处理
|
||||
func (d *TencentImageDAO) ClaimPending(ctx context.Context, id int64) (bool, error) {
|
||||
result, err := Model(consts.TencentImageTable).
|
||||
Where(entity.TencentImageCols.Id, id).
|
||||
Where(entity.TencentImageCols.VerifyStatus, consts.CheckStatusPending).
|
||||
Data(entity.TencentImageCols.VerifyStatus, consts.CheckStatusSubmitting).
|
||||
Update()
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "原子认领图片送检失败: %v", err)
|
||||
return false, err
|
||||
}
|
||||
affected, _ := result.RowsAffected()
|
||||
return affected > 0, nil
|
||||
}
|
||||
|
||||
// UpdateStatus 更新图片校验状态
|
||||
func (d *TencentImageDAO) UpdateStatus(ctx context.Context, id int64, verifyStatus string) (int64, error) {
|
||||
result, err := Model(consts.TencentImageTable).
|
||||
|
||||
@@ -121,6 +121,22 @@ func (d *TencentVideoDAO) GetByCondition(ctx context.Context, condition map[stri
|
||||
return result, int(total), nil
|
||||
}
|
||||
|
||||
// ClaimPending 原子地尝试将视频从 PENDING 状态转为 SUBMITTING
|
||||
// 返回 true 表示成功抢到处理权,false 表示已被其他进程处理
|
||||
func (d *TencentVideoDAO) ClaimPending(ctx context.Context, id int64) (bool, error) {
|
||||
result, err := Model(consts.TencentVideoTable).
|
||||
Where(entity.TencentVideoCols.Id, id).
|
||||
Where(entity.TencentVideoCols.VerifyStatus, consts.CheckStatusPending).
|
||||
Data(entity.TencentVideoCols.VerifyStatus, consts.CheckStatusSubmitting).
|
||||
Update()
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "原子认领视频送检失败: %v", err)
|
||||
return false, err
|
||||
}
|
||||
affected, _ := result.RowsAffected()
|
||||
return affected > 0, nil
|
||||
}
|
||||
|
||||
// UpdateStatus 更新视频校验状态
|
||||
func (d *TencentVideoDAO) UpdateStatus(ctx context.Context, id int64, verifyStatus string) (int64, error) {
|
||||
result, err := Model(consts.TencentVideoTable).
|
||||
|
||||
Reference in New Issue
Block a user