service.go 890 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package service
  2. import (
  3. "github.com/pkg/errors"
  4. "gorm.io/gorm"
  5. "kpt.notice/apiserver/config"
  6. "kpt.notice/apiserver/dao"
  7. "kpt.notice/apiserver/model"
  8. )
  9. var svc *Service
  10. type Service struct {
  11. DB *gorm.DB
  12. Con *config.Config
  13. }
  14. func New(c *config.Config) (s *Service) {
  15. dao := dao.New(c)
  16. s = &Service{
  17. DB: dao.DB,
  18. Con: c,
  19. }
  20. svc = s
  21. JobInit()
  22. return
  23. }
  24. // func (svc *Service) QueryDB(tname string, condition map[string]interface{}, result interface{}) (err error) {
  25. // if err = svc.DB.Table(tname).Where(condition).Find(result).Error; err != nil {
  26. // err = errors.Wrap(err, "service.QueryDB")
  27. // }
  28. // return
  29. // }
  30. func (svc *Service) QuerySysPastureUrl(con *model.SysPastureUrl) (result model.SysPastureUrl, err error) {
  31. if err = svc.DB.Table("sys_pasture_url").Where(con).First(&result).Error; err != nil {
  32. err = errors.Wrap(err, "service.QueryDB")
  33. }
  34. return
  35. }