120 lines
3.8 KiB
Go
120 lines
3.8 KiB
Go
package logic
|
|
|
|
import (
|
|
"service/api/consts"
|
|
textaudittaskproto "service/api/proto/textaudittask/proto"
|
|
"service/app/mix/dao"
|
|
"service/bizcommon/util"
|
|
"service/dbstruct"
|
|
"service/library/logger"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
goproto "google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type TextAuditTask struct {
|
|
store *dao.Store
|
|
}
|
|
|
|
func NewTextAuditTask(store *dao.Store) (a *TextAuditTask) {
|
|
a = &TextAuditTask{
|
|
store: store,
|
|
}
|
|
return
|
|
}
|
|
|
|
func (p *TextAuditTask) OpCreate(ctx *gin.Context, req *textaudittaskproto.OpCreateReq) error {
|
|
req.TextAuditTask.Id = goproto.String(primitive.NewObjectID().Hex())
|
|
req.TextAuditTask.Ct = goproto.Int64(time.Now().Unix())
|
|
req.TextAuditTask.Ut = goproto.Int64(time.Now().Unix())
|
|
req.TextAuditTask.DelFlag = goproto.Int64(consts.Exist)
|
|
err := p.store.CreateTextAuditTask(ctx, req.TextAuditTask)
|
|
if err != nil {
|
|
logger.Error("CreateTextAuditTask fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *TextAuditTask) OpUpdate(ctx *gin.Context, req *textaudittaskproto.OpUpdateReq) error {
|
|
err := p.store.UpdateTextAuditTask(ctx, req.TextAuditTask)
|
|
if err != nil {
|
|
logger.Error("UpdateTextAuditTask fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *TextAuditTask) OpDelete(ctx *gin.Context, id string) error {
|
|
err := p.store.DeleteTextAuditTask(ctx, id)
|
|
if err != nil {
|
|
logger.Error("DeleteTextAuditTask fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *TextAuditTask) OpList(ctx *gin.Context, req *textaudittaskproto.OpListReq) ([]*dbstruct.TextAuditTask, error) {
|
|
list, err := p.store.GetTextAuditTaskList(ctx, req)
|
|
if err != nil {
|
|
logger.Error("GetTextAuditTaskList fail, err: %v", err)
|
|
return make([]*dbstruct.TextAuditTask, 0), err
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
func (p *TextAuditTask) OpListByCollectionInfos(ctx *gin.Context, databases []string, tableNames []string, status int64, offset, limit int) ([]*dbstruct.TextAuditTask, error) {
|
|
list, err := p.store.GetTextAuditTaskListByCollectionInfos(ctx, databases, tableNames, status, offset, limit)
|
|
if err != nil {
|
|
logger.Error("GetTextAuditTaskListByCollectionInfos fail, err: %v", err)
|
|
return make([]*dbstruct.TextAuditTask, 0), err
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
func (p *TextAuditTask) OpUpdateByBatchId(ctx *gin.Context, batchId string, textaudittask *dbstruct.TextAuditTask) error {
|
|
err := p.store.UpdateTextAuditTaskByBatchId(ctx, batchId, textaudittask)
|
|
if err != nil {
|
|
logger.Error("UpdateTextAuditTaskByBatchId fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *TextAuditTask) OpUpdateByIds(ctx *gin.Context, req *textaudittaskproto.OpUpdateByIdsReq) error {
|
|
err := p.store.UpdateTextAuditTaskByIds(ctx, req.TextAuditTask, req.Ids)
|
|
if err != nil {
|
|
logger.Error("UpdateTextAuditTaskByIds fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 处理批次号早于参数提供的批次号的审核任务,全部置为已失效
|
|
func (p *TextAuditTask) OpHandleOverdue(ctx *gin.Context, task *dbstruct.TextAuditTask, batchId string, statuses []int64) error {
|
|
result, err := p.store.UpdateOverdueTextAuditTasksStatus(ctx, task, batchId, statuses)
|
|
if err != nil {
|
|
logger.Error("UpdateOverdueTextAuditTasksStatus fail, err: %v", err)
|
|
return err
|
|
}
|
|
if result.ModifiedCount > 0 {
|
|
logger.Info("Set %v tasks overdued", result.ModifiedCount)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *TextAuditTask) OpGetTextAuditTaskMapByIds(ctx *gin.Context, ids []string) (map[string]*dbstruct.TextAuditTask, error) {
|
|
list, err := p.store.GetTextAuditTaskListByIds(ctx, ids)
|
|
if err != nil {
|
|
logger.Error("GetTextAuditTaskListByIds fail, err: %v", err)
|
|
return make(map[string]*dbstruct.TextAuditTask, 0), err
|
|
}
|
|
_map := make(map[string]*dbstruct.TextAuditTask)
|
|
for _, task := range list {
|
|
_map[util.DerefString(task.Id)] = task
|
|
}
|
|
return _map, nil
|
|
}
|