host.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package repository
  2. import (
  3. "context"
  4. v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
  5. "github.com/go-nunu/nunu-layout-advanced/internal/model"
  6. )
  7. type HostRepository interface {
  8. GetHost(ctx context.Context, id int64) (*model.Host, error)
  9. GetHostConfig(ctx context.Context, hostId int) ([]*model.Host, error)
  10. GetProductConfigOption(ctx context.Context, id []int) ([]v1.ProductConfigOption, error)
  11. GetProductConfigOptionSub(ctx context.Context, id []int) ([]v1.ProductConfigOptionSub, error)
  12. GetDomainById(ctx context.Context, id int) (string, error)
  13. // 获取到期时间
  14. GetExpireTime(ctx context.Context, uid int64, hostId int64) (string, error)
  15. }
  16. func NewHostRepository(
  17. repository *Repository,
  18. ) HostRepository {
  19. return &hostRepository{
  20. Repository: repository,
  21. }
  22. }
  23. type hostRepository struct {
  24. *Repository
  25. }
  26. func (r *hostRepository) GetHost(ctx context.Context, id int64) (*model.Host, error) {
  27. var host model.Host
  28. return &host, nil
  29. }
  30. func (r *hostRepository) GetHostConfig(ctx context.Context, hostId int) ([]*model.Host, error) {
  31. var res []*model.Host
  32. if err := r.DB(ctx).Where("relid = ?", hostId).Find(&res).Error; err != nil {
  33. return nil, err
  34. }
  35. return res, nil
  36. }
  37. func (r *hostRepository) GetProductConfigOption(ctx context.Context, id []int) ([]v1.ProductConfigOption, error) {
  38. var res []v1.ProductConfigOption
  39. if err := r.DB(ctx).Table("shd_product_config_options").Where("id IN ?", id).Find(&res).Error; err != nil {
  40. return nil, err
  41. }
  42. return res, nil
  43. }
  44. func (r *hostRepository) GetProductConfigOptionSub(ctx context.Context, id []int) ([]v1.ProductConfigOptionSub, error) {
  45. var res []v1.ProductConfigOptionSub
  46. if err := r.DB(ctx).Table("shd_product_config_options_sub").Where("id IN ?", id).Find(&res).Error; err != nil {
  47. return nil, err
  48. }
  49. return res, nil
  50. }
  51. func (r *hostRepository) GetDomainById(ctx context.Context, id int) (string, error) {
  52. var res string
  53. if err := r.DB(ctx).Table("shd_host").
  54. Where("id = ?", id).
  55. Pluck("domain", &res).Error; err != nil {
  56. return "", err
  57. }
  58. return res, nil
  59. }
  60. // 获取到期时间
  61. func (r *hostRepository) GetExpireTime(ctx context.Context, uid int64, hostId int64) (string, error) {
  62. var nextDueDate string
  63. err := r.DB(ctx).Table("shd_host").
  64. Select("nextduedate").
  65. Where("id = ?", hostId).
  66. Where("uid = ?", uid).
  67. Scan(&nextDueDate).Error
  68. if err != nil {
  69. return "", err
  70. }
  71. return nextDueDate, nil
  72. }