123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- // Copyright 2019 githup.com. All rights reserved.
- // Use of this source code is governed by githup.com.
- package model
- import (
- "github.com/jinzhu/gorm"
- "time"
- )
- type TProviderDevice struct {
- Id int64 `gorm:"column:id" json:"id" form:"id"`
- ProviderId int64 `gorm:"column:provider_id" json:"provider_id" form:"provider_id"`
- DeviceCode int32 `gorm:"column:device_code" json:"device_code" form:"device_code"`
- Status int32 `gorm:"column:status" json:"status" form:"status"`
- CreatedAt time.Time
- UpdatedAt time.Time
- Feedback string
- }
- func (TProviderDevice) TableName() string {
- return "t_provider_device"
- }
- func (p *TProviderDevice) Insert(db *gorm.DB) error {
- return db.Create(p).Error
- }
- func (p *TProviderDevice) 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 *TProviderDevice) 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()).Table(p.TableName()).Where(cond, val...).Updates(values).Error
- }
- func (p *TProviderDevice) FindSort(db *gorm.DB, where map[string]interface{}, sort string) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- return err
- }
- ps := []TProviderDevice{}
- 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 *TProviderDevice) Save(db *gorm.DB) error {
- return db.Save(p).Error
- }
- func (p *TProviderDevice) List(db *gorm.DB, where map[string]interface{}) (list []TProviderDevice, 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...).Find(&list)
- return list, result.Error
- }
- result := db.Table(p.TableName()).Find(&list)
- return list, result.Error
- }
- func (p *TProviderDevice) All(db *gorm.DB) (list []TProviderDevice, err error) {
- result := db.Table(p.TableName()).Find(&list)
- return list, result.Error
- }
- func (p *TProviderDevice) 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 *TProviderDevice) 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
- }
|