123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package model
- import (
- "github.com/jinzhu/gorm"
- "time"
- )
- type TowerDeviceInfo struct {
- ID int64 `gorm:"column:ID;PRIMARY_KEY" json:"ID"`
- Code string `gorm:"column:Code" json:"code"`
- Name string `gorm:"column:Name" json:"name"`
- DeviceId string `gorm:"column:DeviceId" json:"deviceid"`
- DeviceModel string `gorm:"column:DeviceModel" json:"devicemodel"`
- DeviceName string `gorm:"column:DeviceName" json:"devicename"`
- Manufacturer string `gorm:"column:Manufacturer" json:"manufacturer"`
- Batch string `gorm:"column:Batch" json:"batch"`
- SN string `gorm:"column:SN" json:"sn"`
- DeviceState int64 `gorm:"column:DeviceState" json:"devicestate"`
- Unit string `gorm:"column:Unit" json:"unit"`
- Person string `gorm:"column:Person" json:"person"`
- Phone string `gorm:"column:phone" json:"phone"`
- Remark string `gorm:"column:remark" json:"remark"`
- Longitude string `gorm:"column:Longitude" json:"longitude"`
- Latitude string `gorm:"column:Latitude" json:"latitude"`
- VerifyTime time.Time `gorm:"column:VerifyTime"`
- VerifyStatus int `gorm:"column:VerifyStatus"`
- Key string `gorm:"column:Key"`
- ProjectId int64 `gorm:"column:ProjectId"`
- ProviderId int64 `gorm:"column:ProviderId"`
- CreatedAt time.Time `gorm:"column:CreatedAt"`
- ChannelId int64 `gorm:"column:ChannelId"`
- }
- func (TowerDeviceInfo) TableName() string {
- return "db_smart_v2.TowerDeviceInfo"
- }
- func (p *TowerDeviceInfo) Insert(db *gorm.DB) error {
- return db.Table(p.TableName()).Create(p).Error
- }
- func (p *TowerDeviceInfo) Del(db *gorm.DB, where map[string]interface{}) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- return err
- }
- return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
- }
- func (p *TowerDeviceInfo) Find(db *gorm.DB, where map[string]interface{}) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- return err
- }
- return db.Table(p.TableName()).Where(cond, val...).First(p).Error
- }
- func (p *TowerDeviceInfo) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- return err
- }
- return db.Table(p.TableName()).Where(cond, val...).Updates(values).Error
- }
- func (p *TowerDeviceInfo) FindSort(db *gorm.DB, where map[string]interface{}, sort string) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- return err
- }
- ps := []TowerDeviceInfo{}
- err = db.Table(p.TableName()).Where(cond, val...).Order(sort).Limit(1).Find(&ps).Error
- if err != nil {
- return err
- }
- if len(ps) > 0 {
- *p = ps[0]
- }
- return nil
- }
- func (p *TowerDeviceInfo) Save(db *gorm.DB) error {
- return db.Save(p).Error
- }
- func (p *TowerDeviceInfo) Count(db *gorm.DB, where map[string]interface{}) (int64, error) {
- if len(where) > 0 {
- cond, val, err := whereBuild(where)
- if err != nil {
- return 0, err
- }
- ret := int64(0)
- err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
- return ret, err
- }
- ret := int64(0)
- err := db.Table(p.TableName()).Count(&ret).Error
- return ret, err
- }
- func (p *TowerDeviceInfo) All(db *gorm.DB) (list []TowerDeviceInfo, err error) {
- result := db.Table(p.TableName()).Find(&list)
- return list, result.Error
- }
|