|
@@ -0,0 +1,97 @@
|
|
|
+package dao
|
|
|
+
|
|
|
+import (
|
|
|
+ "github.com/jinzhu/gorm"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+type InfoBoard struct {
|
|
|
+ ID int `gorm:"primary_key" json:"id"`
|
|
|
+ InfoName string `gorm:"type:varchar(60)" json:"infoName"`
|
|
|
+ SN string `gorm:"type:varchar(60)" json:"sn"`
|
|
|
+ LampPoleId int `gorm:"type:int" json:"LampPoleId"`
|
|
|
+ LampPoleName string `gorm:"type: varchar(64)" json:"lampPoleName"`
|
|
|
+ LampPoleSN string `gorm:"type: varchar(64)" json:"lampPoleSN"`
|
|
|
+ LampPoleLocation string `gorm:"type:varchar(255)" json:"lampPoleLocation"`
|
|
|
+ PoleLng float64 `gorm:"type:double(17, 14) " json:"poleLng"`
|
|
|
+ PoleLat float64 `gorm:"type:double(17, 14) " json:"poleLat"`
|
|
|
+ GatewayId string `gorm:"type:varchar(32)" json:"gatewayId"`
|
|
|
+ GroupId int `gorm:"type:int" json:"groupId"`
|
|
|
+ Resolution int `gorm:"type:int" json:"resolution"`
|
|
|
+ BrandID int `gorm:"type:int" json:"brandID"`
|
|
|
+ ModelID int `gorm:"type:int" json:"modelID"`
|
|
|
+ InfoSize int `gorm:"type:int" json:"infoSize"`
|
|
|
+ RatedPower float32 `gorm:"type:float(8, 2); default 0.00" json:"ratedPower"`
|
|
|
+ IPAddress string `gorm:"type:varchar(64)" json:"ipAddress"`
|
|
|
+ BootStartTime string `gorm:"type:time" json:"bootStartTime"`
|
|
|
+ BootEndTime string `gorm:"type:time" json:"bootEndTime"`
|
|
|
+ NeverCloseDown int `gorm:"type:int" json:"neverCloseDown"`
|
|
|
+ InstallTime time.Time `gorm:"type:date" json:"installTime"`
|
|
|
+ TenantId string `gorm:"type:varchar(12)" json:"tenantId"`
|
|
|
+ CreateTime time.Time `gorm:"type:datetime" json:"createTime"`
|
|
|
+ CreateUser string `gorm:"type:varchar(60)" json:"createUser"`
|
|
|
+ UpdateTime time.Time `gorm:"type:datetime" json:"updateTime"`
|
|
|
+ UpdateUser string `gorm:"type:varchar(60)" json:"updateUser"`
|
|
|
+ IsDeleted int `gorm:"type:int;default 0" json:"isDeleted"`
|
|
|
+ Tag string `gorm:"type:varchar(255)" json:"tag"`
|
|
|
+ ExteriorUid int `gorm:"type:bigint" json:"exteriorUid"`
|
|
|
+ IsEnable int `gorm:"type: int; default 2 " json:"isEnable"`
|
|
|
+}
|
|
|
+
|
|
|
+func (InfoBoard) TableName() string {
|
|
|
+ return "t_dev_info_board"
|
|
|
+}
|
|
|
+
|
|
|
+func (c InfoBoard) Delete() error {
|
|
|
+ return GDb.Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime,
|
|
|
+ "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
|
|
|
+}
|
|
|
+
|
|
|
+func (c InfoBoard) IsExistedBySN() bool {
|
|
|
+ var count = 0
|
|
|
+ _ = GDb.Model(&c).Where(" sn = ? and is_deleted = ?",
|
|
|
+ c.SN, c.IsDeleted).Count(&count).Error
|
|
|
+ return count > 0
|
|
|
+}
|
|
|
+
|
|
|
+func (c InfoBoard) IsExistedByNameAndCode() bool {
|
|
|
+ var devices []InfoBoard
|
|
|
+ err := GDb.Model(&c).Where(" sn = ? and is_deleted = ?",
|
|
|
+ c.SN, c.IsDeleted).Find(&devices).Error
|
|
|
+
|
|
|
+ if gorm.IsRecordNotFoundError(err) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ for _, d := range devices {
|
|
|
+ if d.ID != c.ID {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+func (c *InfoBoard) Create() error {
|
|
|
+ return GDb.Model(&c).Save(&c).Error
|
|
|
+}
|
|
|
+
|
|
|
+func (c *InfoBoard) Update() error {
|
|
|
+ return GDb.Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
|
|
|
+}
|
|
|
+
|
|
|
+func (c *InfoBoard) GetDevice() error {
|
|
|
+ err := GDb.Model(&c).Where(" id = ? ", c.ID).Scan(&c).Error
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+func (c InfoBoard) GetDevices(offset, limit int) ([]InfoBoard, error) {
|
|
|
+ var devices []InfoBoard
|
|
|
+ err := GDb.Model(&c).Where(" info_name like ? ", "%"+c.InfoName+"%").Offset(offset).Limit(limit).Find(&devices).Error
|
|
|
+ return devices, err
|
|
|
+}
|
|
|
+
|
|
|
+func (c InfoBoard) GetAllDevices() ([]*InfoBoard, error) {
|
|
|
+ var devices []*InfoBoard
|
|
|
+ err := GDb.Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
|
|
|
+ return devices, err
|
|
|
+}
|