12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package dao
- import (
- "time"
- )
- //LampPoleGroup 灯杆分组
- type LampPoleGroup struct {
- ID int `gorm:"type:int;primary_key"` //编号
- PoleGroupName string `gorm:"type:varchar(64)"` //分组名称
- TenantId string `gorm:"type:varchar(12)"` //租户ID
- CreateTime time.Time `gorm:"type:datetime"` //新增时间
- CreateUser string `gorm:"type:varchar(60)"` //新增记录操作用户ID
- UpdateTime time.Time `gorm:"type:datetime"` //修改时间
- UpdateUser string `gorm:"type:varchar(60)"` //修改用户
- IsDeleted int `gorm:"type:int;default 0"` //是否删除 0=未删除,1=删除
- Tag string `gorm:"type:varchar(255)"` //标签,(备用,逗号区分)
- Remark string `gorm:"type:varchar(255)"` //备注
- }
- func (LampPoleGroup) TableName() string {
- return "t_dev_lamp_pole_group"
- }
- func (c LampPoleGroup) Delete() error {
- return GDb.Model(&c).Updates(map[string]interface{}{"state": 0}).Error
- }
- func (c LampPoleGroup) IsExistedByCode() (bool, error) {
- var count = 0
- err := GDb.Model(&c).Where(" id = ? ", c.ID).Count(&count).Error
- return count > 0, err
- }
- func (c LampPoleGroup) GetDeviceID() (int, error) {
- err := GDb.Model(&c).Where(" pole_group_name = ? and tenant_id = ? and is_deleted = ?", c.PoleGroupName, c.TenantId, c.IsDeleted).First(&c).Error
- return c.ID, err
- }
- func (c LampPoleGroup) Create() error {
- return GDb.Create(&c).Error
- }
- func (c LampPoleGroup) Update() error {
- return GDb.Model(&c).Updates(map[string]interface{}{"pole_group_name": c.PoleGroupName,
- "tenant_id": c.TenantId, "update_time": time.Now(), "update_user": "TODO", "is_deleted": 0}).Error
- }
- func (c LampPoleGroup) GetDevice() error {
- err := GDb.Model(&c).Where(" id = ? ", c.ID).Scan(&c).Error
- return err
- }
- func (c LampPoleGroup) GetDevices(offset, limit int) ([]LampPoleGroup, error) {
- var devices []LampPoleGroup
- err := GDb.Model(&c).Where(" id like '%?%'", c.PoleGroupName).Offset(offset).Limit(limit).Scan(&devices).Error
- return devices, err
- }
|