103 lines
3.0 KiB
Go
103 lines
3.0 KiB
Go
package biz
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"geo/internal/config"
|
|
"geo/internal/data/impl"
|
|
"geo/internal/data/model"
|
|
"geo/tmpl/errcode"
|
|
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
type PublishBiz struct {
|
|
cfg *config.Config
|
|
publishImpl *impl.PublishImpl
|
|
userImpl *impl.UserImpl
|
|
platImpl *impl.PlatImpl
|
|
tokenImpl *impl.TokenImpl
|
|
loginRelationImpl *impl.LoginRelationImpl
|
|
}
|
|
|
|
func NewPublishBiz(
|
|
cfg *config.Config,
|
|
publishImpl *impl.PublishImpl,
|
|
userImpl *impl.UserImpl,
|
|
platImpl *impl.PlatImpl,
|
|
tokenImpl *impl.TokenImpl,
|
|
loginRelationImpl *impl.LoginRelationImpl,
|
|
|
|
) *PublishBiz {
|
|
return &PublishBiz{
|
|
cfg: cfg,
|
|
publishImpl: publishImpl,
|
|
loginRelationImpl: loginRelationImpl,
|
|
userImpl: userImpl,
|
|
platImpl: platImpl,
|
|
tokenImpl: tokenImpl,
|
|
}
|
|
}
|
|
|
|
func (b *PublishBiz) ValidateAccessToken(ctx context.Context, accessToken string) (*model.Token, error) {
|
|
cond := builder.NewCond().
|
|
And(builder.Eq{"access_token": accessToken}).
|
|
And(builder.Eq{"status": 1})
|
|
tokenInfo := &model.Token{}
|
|
err := b.tokenImpl.GetOneBySearchStruct(ctx, &cond, tokenInfo)
|
|
if err != nil || tokenInfo == nil {
|
|
return nil, errcode.Forbidden("密钥无效或已禁用")
|
|
}
|
|
return tokenInfo, nil
|
|
}
|
|
|
|
func (b *PublishBiz) BatchInsertPublish(ctx context.Context, list []*model.Publish) error {
|
|
|
|
return b.publishImpl.Add(ctx, list)
|
|
}
|
|
|
|
func (b *PublishBiz) GetPendingPublish(ctx context.Context, tokenID int) (map[string]interface{}, error) {
|
|
|
|
currentTime := time.Now()
|
|
cond := builder.NewCond().
|
|
And(builder.Eq{"p.token_id": tokenID}).
|
|
And(builder.Eq{"p.status": 1}).
|
|
And(builder.Lte{"p.publish_time": currentTime})
|
|
|
|
return b.publishImpl.GetOneWithPlat(ctx, &cond)
|
|
}
|
|
|
|
func (b *PublishBiz) GetTaskByRequestID(ctx context.Context, requestID string) (map[string]interface{}, error) {
|
|
cond := builder.NewCond().
|
|
And(builder.Eq{"p.request_id": requestID})
|
|
return b.publishImpl.GetOneWithPlat(ctx, &cond)
|
|
}
|
|
|
|
func (b *PublishBiz) UpdatePublishStatus(ctx context.Context, requestID string, status int, msg string) error {
|
|
return b.publishImpl.UpdateStatus(ctx, requestID, status, msg)
|
|
}
|
|
|
|
func (b *PublishBiz) GetPublishList(ctx context.Context, tokenID int32, page, pageSize int, filters map[string]interface{}) ([]map[string]interface{}, int64, error) {
|
|
return b.publishImpl.GetListWithUser(ctx, tokenID, page, pageSize, filters)
|
|
}
|
|
|
|
func (b *PublishBiz) GetPlatInfo(ctx context.Context, platIndex string) (*model.Plat, error) {
|
|
cond := builder.NewCond().
|
|
And(builder.Eq{"`index`": platIndex}).
|
|
And(builder.Eq{"status": 1})
|
|
plat := &model.Plat{}
|
|
err := b.platImpl.GetOneBySearchStruct(ctx, &cond, plat)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return plat, nil
|
|
}
|
|
|
|
func (b *PublishBiz) UpdateLoginStatus(ctx context.Context, userIndex, platIndex string, loginStatus int32) error {
|
|
cond := builder.NewCond().
|
|
And(builder.Eq{"user_index": userIndex}).
|
|
And(builder.Eq{"plat_index": platIndex})
|
|
return b.loginRelationImpl.UpdateByCond(ctx, &cond, &model.User{Status: loginStatus})
|
|
}
|