| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package dao
- import (
- "time"
- )
- type IntelligentLightRelation struct {
- IntelligentLight
- LightStrategy
- LightControl
- LampPoleGroup
- }
- type IntelligentLight struct {
- ID int `gorm:"primary key" json:"id"` //编号
- LightID int `gorm:"type:int" json:"lightID"` //照明策略id
- RelationType int `gorm:"type:int" json:"relationType"` //关联类型1=灯控,2=灯杆分组
- Rid int `gorm:"type:int" json:"rid"` //关联外键ID 根据type类型关联至其表
- CreateTime time.Time `gorm:"type:timestamp" json:"createTime"` //新增时间
- CreateUser string `gorm:"type:varchar(60)" json:"createUser"` //新增记录操作用户ID
- UpdateTime time.Time `gorm:"type:timestamp" json:"updateTime"` //修改时间
- UpdateUser string `gorm:"type:varchar(60)" json:"updateUser"` //修改用户
- IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"` //是否删除 0=未删除,1=删除
- TenantID string `gorm:"type:varchar(12)" json:"tenantID"` //租户id
- }
- func (IntelligentLight) TableName() string {
- return "t_strategy_intelligent_light"
- }
- func (c *IntelligentLight) BatchGet(ids []int) ([]IntelligentLight, error) {
- var intelligentLights []IntelligentLight
- err := Db.Model(&c).Where("light_id in ? and is_deleted = 0", ids).Find(&intelligentLights).Error
- return intelligentLights, err
- }
- func (c *IntelligentLight) GetByRidAndType() ([]IntelligentLight, error) {
- var intelligentLights []IntelligentLight
- db := Db.Model(&c).Where("relation_type = ? and is_deleted = 0 and tenant_id = ?",
- c.RelationType, c.TenantID)
- if c.Rid > 0 {
- db = db.Where("rid = ?", c.Rid)
- }
- err := db.Find(&intelligentLights).Error
- return intelligentLights, err
- }
- func (c *IntelligentLight) GetByType() ([]IntelligentLightRelation, error) {
- var intelligentLights []IntelligentLightRelation
- sql := `SELECT lig.*,
- gro.id,
- gro.pole_group_name,
- b.light_name,
- b.light_sn,
- b.start_time,
- b.end_time,
- b.is_all_year,
- b.is_automatic_renewal
- FROM t_strategy_intelligent_light lig
- LEFT JOIN t_dev_lamp_pole_group gro ON lig.rid = gro.id
- LEFT JOIN t_strategy_light b ON b.id = lig.light_id
- WHERE lig.is_deleted = 0
- AND lig.relation_type = 2
- AND gro.is_deleted = 0
- AND lig.tenant_id = ?`
- if c.Rid > 0 {
- sql += ` lig.rid = ? ORDER BY lig.create_time desc`
- err := Db.Raw(sql, c.TenantID, c.Rid).Scan(&intelligentLights).Error
- return intelligentLights, err
- } else {
- sql += ` ORDER BY lig.create_time desc`
- err := Db.Raw(sql, c.TenantID).Scan(&intelligentLights).Error
- return intelligentLights, err
- }
- }
|