|
|
@ -0,0 +1,51 @@ |
|
|
|
package api |
|
|
|
|
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"errors" |
|
|
|
"github.com/gogf/gf/v2/database/gdb" |
|
|
|
"github.com/gogf/gf/v2/errors/gerror" |
|
|
|
v1 "xgit.pub/module/cms/app/api/api/v1" |
|
|
|
"xgit.pub/module/cms/app/dao" |
|
|
|
"xgit.pub/module/cms/app/model/entity" |
|
|
|
"xgit.pub/module/cms/app/service" |
|
|
|
) |
|
|
|
|
|
|
|
type sApi struct { |
|
|
|
} |
|
|
|
|
|
|
|
func init() { |
|
|
|
Api := New() |
|
|
|
service.RegisterApi(Api) |
|
|
|
} |
|
|
|
|
|
|
|
func New() *sApi { |
|
|
|
return &sApi{} |
|
|
|
} |
|
|
|
|
|
|
|
// Create 创建
|
|
|
|
func (s *sApi) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) { |
|
|
|
err = dao.Video.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error { |
|
|
|
if req.CollectId < 1 { |
|
|
|
return errors.New("请输入采集站点信息") |
|
|
|
} |
|
|
|
collectName := service.Collect().GetCollectNameById(ctx, req.CollectId) |
|
|
|
if collectName == "" { |
|
|
|
err = gerror.New("采集站点信息不存在") |
|
|
|
return err |
|
|
|
} |
|
|
|
video, _ := s.GetBySourceUrl(ctx, req.SourceUrl) |
|
|
|
if video != nil && video.Id > 0 { |
|
|
|
_, err = dao.Video.Ctx(ctx).Data(req).Where(dao.Video.Columns().Id, video.Id).Update() |
|
|
|
} else { |
|
|
|
_, err = dao.Video.Ctx(ctx).InsertAndGetId(req) |
|
|
|
} |
|
|
|
return err |
|
|
|
}) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func (s *sApi) GetBySourceUrl(ctx context.Context, SourceUrl string) (res *entity.Video, err error) { |
|
|
|
err = dao.Video.Ctx(ctx).Where("source_url", SourceUrl).Scan(&res) |
|
|
|
return |
|
|
|
} |