lightConditionDao.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package dao
  2. import "time"
  3. type LightCondition struct {
  4. ID int `gorm:"primary key" json:"id"` //编号
  5. LightId int `gorm:"type:int" json:"lightId"` //照明策略id
  6. ScopeStart int `gorm:"type:int" json:"scopeStart"` //光照度范围开始值
  7. ScopeEnd int `gorm:"type:int" json:"scopeEnd"` //光照度范围结束值
  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. }
  16. func (LightCondition) TableName() string {
  17. return "strategy_light_condition"
  18. }
  19. func (c *LightCondition) Get() error {
  20. return Db.Model(&c).Where("id = ?", c.ID).Find(&c).Error
  21. }
  22. func (c *LightCondition) BatchGet(ids []int) ([]LightCondition, error) {
  23. var conditions []LightCondition
  24. err := Db.Model(&c).Where("id in ?", ids).Find(&conditions).Error
  25. return conditions, err
  26. }
  27. func (c *LightCondition) Save(conditions []LightCondition, lightId int) error {
  28. for i, _ := range conditions {
  29. conditions[i].LightId = lightId
  30. }
  31. return Db.Model(&c).Save(&conditions).Error
  32. }