12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package dao
- import "time"
- type TimeCondition struct {
- ID int `gorm:"primary key" json:"id"` //编号
- LightId int `gorm:"type:int;default 0" json:"lightId"` //照明策略id
- StartTime string `gorm:"type:varchar(60)" json:"startTime"` //开始时间
- EndTime string `gorm:"type:varchar(60)" json:"endTime"` //结束时间
- Luminance int `gorm:"type:int " json:"luminance"` //开灯亮度
- Remark string `gorm:"type:varchar(255)" json:"remark"` //备注
- CreateTime time.Time `gorm:"type:datetime" json:"createTime"` //新增时间
- CreateUser int `gorm:"type:int" json:"createUser"` //新增记录操作用户ID
- UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"` //修改时间
- UpdateUser int `gorm:"type:int" json:"updateUser"` //修改用户
- IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
- Sunshine int `gorm:"type:int;default 1" json:"sunshine"` //日出日落 设置 2=开启,1=不开启
- }
- func (TimeCondition) TableName() string {
- return "strategy_time_condition"
- }
- func (c *TimeCondition) Get() error {
- return Db.Model(&c).Where("id = ? and is_deleted = 0", c.ID).Find(&c).Error
- }
- func (c *TimeCondition) BatchGet(ids []int) ([]TimeCondition, error) {
- var conditions []TimeCondition
- err := Db.Model(&c).Where("id in ? and is_deleted = 0", ids).Find(&conditions).Error
- return conditions, err
- }
- func (c *TimeCondition) GetByLightId() ([]TimeCondition, error) {
- var conditions []TimeCondition
- err := Db.Model(&c).Where("light_id = ? and is_deleted = 0", c.LightId).Find(&conditions).Error
- return conditions, err
- }
- func (c *TimeCondition) GetAll() ([]TimeCondition, error) {
- var conditions []TimeCondition
- err := Db.Model(&c).Find(&conditions).Error
- return conditions, err
- }
- func (c *TimeCondition) Save() error {
- return Db.Model(&c).Save(&c).Error
- }
- func (c *TimeCondition) Update() error {
- return Db.Model(&c).Updates(&c).Error
- }
|