123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package model
- import (
- "github.com/jinzhu/gorm"
- "time"
- )
- type SlagcarDevice struct {
- ID int64 `gorm:"column:ID;PRIMARY_KEY" json:"id"`
- Code string `gorm:"column:Code" json:"code"`
- Name string `gorm:"column:name" json:"name"`
- DeviceNum string `gorm:"column:deviceNum" json:"devicenum"`
- 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"`
- SIM string `gorm:"column:SIM" json:"sim"`
- State int64 `gorm:"column:state" json:"state"`
- Unit string `gorm:"column:unit" json:"unit"`
- Person string `gorm:"column:contactName" json:"person"`
- Phone string `gorm:"column:contactPerson" 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"`
- }
- func (SlagcarDevice) TableName() string {
- return "db_smart_v2.SlagcarDevice"
- }
- func (p *SlagcarDevice) Insert(db *gorm.DB) error {
- return db.Table(p.TableName()).Create(p).Error
- }
- func (p *SlagcarDevice) 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 *SlagcarDevice) 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 *SlagcarDevice) 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 *SlagcarDevice) Save(db *gorm.DB) error {
- return db.Save(p).Error
- }
- func (p *SlagcarDevice) 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 *SlagcarDevice) List(db *gorm.DB, where map[string]interface{}, page int) (list []SlagcarDevice, err error) {
- if len(where) > 0 {
- cond, val, err := whereBuild(where)
- if err != nil {
- return list, err
- }
- result := db.Table(p.TableName()).Where(cond, val...).Limit(10).Offset(page).Find(&list)
- return list, result.Error
- }
- result := db.Table(p.TableName()).Limit(10).Offset(page).Find(&list)
- return list, result.Error
- }
|