invoice_info_dao.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package dao
  2. import (
  3. "gorm.io/gorm"
  4. "youngee_b_api/app/entity"
  5. )
  6. type InvoiceInfoDao struct{}
  7. func (d InvoiceInfoDao) Select(invoiceId int64) (*entity.InvoiceInfo, error) {
  8. var invoiceInfo entity.InvoiceInfo
  9. err := Db.Debug().Model(&entity.InvoiceInfo{}).Where("invoice_id = ?", invoiceId).Find(&invoiceInfo).Error
  10. if err != nil {
  11. if err == gorm.ErrRecordNotFound {
  12. return &invoiceInfo, nil
  13. }
  14. return nil, err
  15. }
  16. return &invoiceInfo, nil
  17. }
  18. func (d InvoiceInfoDao) Delete(invoiceInfo entity.InvoiceInfo) error {
  19. err := Db.Where(invoiceInfo).Delete(&entity.InvoiceInfo{}).Error
  20. if err != nil {
  21. return err
  22. }
  23. return nil
  24. }
  25. func (d InvoiceInfoDao) SelectDefault(enterpriseId string, invoiceType int64) (*entity.InvoiceInfo, error) {
  26. var invoiceInfo entity.InvoiceInfo
  27. err := Db.Debug().Model(&entity.InvoiceInfo{}).Where("enterprise_id = ? AND invoice_type = ?", enterpriseId, invoiceType).Find(&invoiceInfo).Error
  28. if err != nil {
  29. if err == gorm.ErrRecordNotFound {
  30. return &invoiceInfo, nil
  31. }
  32. return nil, err
  33. }
  34. return &invoiceInfo, nil
  35. }
  36. func (d InvoiceInfoDao) Insert(invoiceInfo *entity.InvoiceInfo) error {
  37. err := Db.Debug().Model(&entity.InvoiceInfo{}).Create(invoiceInfo).Error
  38. if err != nil {
  39. return err
  40. }
  41. return nil
  42. }