timeConditionDao.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dao
  2. import "time"
  3. type TimeCondition struct {
  4. ID int `gorm:"primary key" json:"id"` //编号
  5. LightId int `gorm:"type:int;default 0" json:"lightId"` //照明策略id
  6. StartTime string `gorm:"type:varchar(60)" json:"startTime"` //开始时间
  7. EndTime string `gorm:"type:varchar(60)" json:"endTime"` //结束时间
  8. Luminance int `gorm:"type:int " json:"luminance"` //开灯亮度
  9. Remark string `gorm:"type:varchar(255)" json:"remark"` //备注
  10. CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
  11. CreateUser int `gorm:"type:int" json:"createUser"` //新增记录操作用户ID
  12. UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
  13. UpdateUser int `gorm:"type:int" json:"updateUser"` //修改用户
  14. IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
  15. Sunshine int `gorm:"type:int;default 1" json:"sunshine"` //日出日落 设置 2=开启,1=不开启
  16. }
  17. func (TimeCondition) TableName() string {
  18. return "strategy_time_condition"
  19. }
  20. func (c *TimeCondition) Get() error {
  21. return Db.Model(&c).Where("id = ? and is_deleted = 0", c.ID).Find(&c).Error
  22. }
  23. func (c *TimeCondition) BatchGet(ids []int) ([]TimeCondition, error) {
  24. var conditions []TimeCondition
  25. err := Db.Model(&c).Where("id in ? and is_deleted = 0", ids).Find(&conditions).Error
  26. return conditions, err
  27. }
  28. func (c *TimeCondition) GetByLightId() ([]TimeCondition, error) {
  29. var conditions []TimeCondition
  30. err := Db.Model(&c).Where("light_id = ? and is_deleted = 0", c.LightId).Find(&conditions).Error
  31. return conditions, err
  32. }
  33. func (c *TimeCondition) GetAll() ([]TimeCondition, error) {
  34. var conditions []TimeCondition
  35. err := Db.Model(&c).Find(&conditions).Error
  36. return conditions, err
  37. }
  38. func (c *TimeCondition) Save() error {
  39. return Db.Model(&c).Save(&c).Error
  40. }
  41. func (c *TimeCondition) Update() error {
  42. return Db.Model(&c).Updates(&c).Error
  43. }