|
@@ -0,0 +1,92 @@
|
|
|
+package dao
|
|
|
+
|
|
|
+import (
|
|
|
+ "github.com/jinzhu/gorm"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+type SwitchBox struct {
|
|
|
+ ID int `gorm:"primary_key" json:"id"`
|
|
|
+ BoxName string `gorm:"type:varchar(64)" json:"boxName"`
|
|
|
+ BoxSN string `gorm:"type:varchar(60)" json:"boxSN"`
|
|
|
+ BrandId int `gorm:"type:int" json:"brandId"`
|
|
|
+ ModelId int `gorm:"type:int" json:"modelId"`
|
|
|
+ TransformerId int `gorm:"type:int" json:"transformerId"`
|
|
|
+ TransformerNum string `gorm:"type:varchar(60)" json:"transformerNum"`
|
|
|
+ RatedPower float32 `gorm:"type:double(8, 2) default 0.00 " json:"ratedPower"`
|
|
|
+ ProvinceName string `gorm:" type:varchar(12)" json:"provinceName"`
|
|
|
+ CityName string `gorm:"type:varchar(12)" json:"cityName"`
|
|
|
+ DistrictName string `gorm:"type:varchar(12)" json:"districtName"`
|
|
|
+ BoxLocation string `gorm:"type:varchar(100)" json:"boxLocation"`
|
|
|
+ PoleLng float64 `gorm:"type:double(17, 14) " json:"poleLng"`
|
|
|
+ PoleLat float64 `gorm:"type:double(17, 14) " json:"poleLat"`
|
|
|
+ MonitorAddress string `gorm:"type:varchar(255) " json:"monitorAddress"`
|
|
|
+ TenantId string `gorm:"type:varchar(12)" json:"tenantId"`
|
|
|
+ InstallTime time.Time `gorm:"type:date" json:"installTime"`
|
|
|
+ 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"`
|
|
|
+ Status int `gorm:"type:int" json:"status"`
|
|
|
+ Tag string `gorm:"type:varchar(255)" json:"tag"`
|
|
|
+ BoxPhotoUrl string `gorm:"type:varchar(255)" json:"boxPhotoUrl"`
|
|
|
+}
|
|
|
+
|
|
|
+func (SwitchBox) TableName() string {
|
|
|
+ return "t_dev_switch_box"
|
|
|
+}
|
|
|
+
|
|
|
+func (c SwitchBox) 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 SwitchBox) IsExistedBySN() bool {
|
|
|
+ var count = 0
|
|
|
+ _ = GDb.Model(&c).Where(" box_sn = ? and is_deleted = ?",
|
|
|
+ c.BoxSN, c.IsDeleted).Count(&count).Error
|
|
|
+ return count > 0
|
|
|
+}
|
|
|
+
|
|
|
+func (c SwitchBox) IsExistedByNameAndCode() bool {
|
|
|
+ var devices []SwitchBox
|
|
|
+ err := GDb.Model(&c).Where(" box_sn = ? and is_deleted = ?",
|
|
|
+ c.BoxSN, 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 *SwitchBox) Create() error {
|
|
|
+ return GDb.Model(&c).Save(&c).Error
|
|
|
+}
|
|
|
+
|
|
|
+func (c *SwitchBox) Update() error {
|
|
|
+ return GDb.Model(&c).Where(" id = ? ", c.ID).Update(&c).Error
|
|
|
+}
|
|
|
+
|
|
|
+func (c *SwitchBox) GetDevice() error {
|
|
|
+ err := GDb.Model(&c).Where(" id = ? ", c.ID).Scan(&c).Error
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+func (c SwitchBox) GetDevices(offset, limit int) ([]SwitchBox, error) {
|
|
|
+ var devices []SwitchBox
|
|
|
+ err := GDb.Model(&c).Where(" box_name like ? ", "%"+c.BoxName+"%").Offset(offset).Limit(limit).Find(&devices).Error
|
|
|
+ return devices, err
|
|
|
+}
|
|
|
+
|
|
|
+func (c SwitchBox) GetAllDevices() ([]SwitchBox, error) {
|
|
|
+ var devices []SwitchBox
|
|
|
+ err := GDb.Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
|
|
|
+ return devices, err
|
|
|
+}
|