package internal import ( "context" "github.com/gogf/gf/util/guid" "yx-dataset-server/app/errors" "yx-dataset-server/app/model" "yx-dataset-server/app/schema" ) // NewLoginHistory 创建LoginHistory func NewLoginHistory(mLoginHistory model.ILoginHistory) *LoginHistory { return &LoginHistory{ LoginHistoryModel: mLoginHistory, } } // LoginHistory 创建LoginHistory对象 type LoginHistory struct { LoginHistoryModel model.ILoginHistory } // Query 查询数据 func (a *LoginHistory) Query(ctx context.Context, params schema.LoginHistoryQueryParam, opts ...schema.LoginHistoryQueryOptions) (*schema.LoginHistoryQueryResult, error) { return a.LoginHistoryModel.Query(ctx, params, opts...) } // Get 查询指定数据 func (a *LoginHistory) Get(ctx context.Context, recordID string, opts ...schema.LoginHistoryQueryOptions) (*schema.LoginHistory, error) { item, err := a.LoginHistoryModel.Get(ctx, recordID, opts...) if err != nil { return nil, err } else if item == nil { return nil, errors.ErrNotFound } return item, nil } func (a *LoginHistory) checkCode(ctx context.Context, code string) error { result, err := a.LoginHistoryModel.Query(ctx, schema.LoginHistoryQueryParam{ Code: code, }, schema.LoginHistoryQueryOptions{ PageParam: &schema.PaginationParam{PageSize: -1}, }) if err != nil { return err } else if result.PageResult.Total > 0 { return errors.New400Response("编号已经存在") } return nil } func (a *LoginHistory) getUpdate(ctx context.Context, recordID string) (*schema.LoginHistory, error) { return a.Get(ctx, recordID) } // Create 创建数据 func (a *LoginHistory) Create(ctx context.Context, item schema.LoginHistory) (*schema.LoginHistory, error) { item.RecordID = guid.S() err := a.LoginHistoryModel.Create(ctx, item) if err != nil { return nil, err } return a.getUpdate(ctx, item.RecordID) } // Update 更新数据 func (a *LoginHistory) Update(ctx context.Context, recordID string, item schema.LoginHistory) error { oldItem, err := a.LoginHistoryModel.Get(ctx, recordID) if err != nil { return err } else if oldItem == nil { return errors.ErrNotFound } return a.LoginHistoryModel.Update(ctx, recordID, item) } // Delete 删除数据 func (a *LoginHistory) Delete(ctx context.Context, recordID string) error { oldItem, err := a.LoginHistoryModel.Get(ctx, recordID) if err != nil { return err } else if oldItem == nil { return errors.ErrNotFound } return a.LoginHistoryModel.Delete(ctx, recordID) } // UpdateStatus 更新状态 func (a *LoginHistory) UpdateStatus(ctx context.Context, recordID string, status int) error { oldItem, err := a.LoginHistoryModel.Get(ctx, recordID) if err != nil { return err } else if oldItem == nil { return errors.ErrNotFound } return a.LoginHistoryModel.UpdateStatus(ctx, recordID, status) }