businessTacticsDao.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package dao
  2. import (
  3. "gorm.io/gorm"
  4. "iot_manager_service/app/warn/model"
  5. "iot_manager_service/util/common"
  6. "time"
  7. )
  8. type BusinessTactics struct {
  9. AlarmType int `comment:"告警类型-数据字典" json:"alarmType,omitempty"`
  10. DeviceType int `comment:"设备告警类型" json:"deviceType,omitempty"`
  11. BusinessName string `comment:"业务告警名称" json:"businessName,omitempty"`
  12. MaxValue float64 `comment:"上限值" json:"maxValue,omitempty"`
  13. MinValue float64 `comment:"下限值" json:"minValue,omitempty"`
  14. Duration int `comment:"持续时间" json:"duration,omitempty"`
  15. IsEnable int `comment:"1-启用,2-禁用;默认启用" json:"isEnable,omitempty"`
  16. TenantId string `gorm:"type:varchar(12)" comment:"租户ID" json:"tenantId,omitempty"`
  17. ID uint `gorm:"primarykey" json:"id"`
  18. CreatedAt time.Time
  19. UpdatedAt time.Time
  20. DeletedAt gorm.DeletedAt `gorm:"index"`
  21. RelevanceLampNum int `gorm:"_" json:"relevanceLampNum"` //关联灯杆数
  22. AlarmTypeName string `gorm:"_" json:"alarmTypeName,omitempty"`
  23. DeviceTypeName string `gorm:"_" json:"deviceTypeName,omitempty"`
  24. }
  25. func (BusinessTactics) TableName() string {
  26. return "warn_business_tactics"
  27. }
  28. func (t BusinessTactics) Gets(filter model.RequestBusinessTacticFilter) ([]BusinessTactics, int64, error) {
  29. var list []BusinessTactics
  30. db := Db.Debug().Model(&t).Where(&BusinessTactics{TenantId: t.TenantId})
  31. db = db.Scopes(common.Paginate(filter.Current, filter.Size))
  32. // filter
  33. if filter.BusinessName != "" {
  34. db = db.Where("business_name like ?", "%"+filter.BusinessName+"%")
  35. }
  36. if filter.ArmClassify != 0 {
  37. db = db.Where("alarm_type = ?", filter.ArmClassify)
  38. }
  39. err := db.Find(&list).Error
  40. var count int64
  41. db.Count(&count)
  42. return list, count, err
  43. }
  44. func (t BusinessTactics) Create() error {
  45. err := Db.Debug().Create(&t).Error
  46. return err
  47. }
  48. func (t BusinessTactics) Update(id int) error {
  49. err := Db.Debug().Where("id=?", id).Updates(&t).Error
  50. return err
  51. }
  52. func (t BusinessTactics) Delete(id int) error {
  53. err := Db.Debug().Model(&t).Delete(&t, id).Error
  54. return err
  55. }