123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- // 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 DeviceDelJob struct {
- ID int64 `gorm:"column:ID" json:"id" form:"id"`
- CreatedAt time.Time `gorm:"column:CreatedAt" json:"created_at" form:"created_at"`
- Status int64 `gorm:"column:Status" json:"status" form:"status"`
- UpdatedAt time.Time `gorm:"column:UpdatedAt" json:"updated_at" form:"updated_at"`
- ProjectId int64 `gorm:"column:ProjectId" json:"project_id" form:"project_id"`
- Feedback string `gorm:"column:Feedback"`
- Reason string `gorm:"column:Reason"`
- ProviderId int64 `gorm:"column:ProviderId"`
- DeviceId int64 `gorm:"column:DeviceId"`
- DeviceCode uint32 `gorm:"column:DeviceCode"`
- Sn string `gorm:"column:SN"`
- DeviceName string `gorm:"column:DeviceName"`
- }
- func (DeviceDelJob) TableName() string {
- return "DeviceDelJob"
- }
- func (p *DeviceDelJob) Insert(db *gorm.DB) error {
- return db.Table(p.TableName()).Create(p).Error
- }
- func (p *DeviceDelJob) 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 *DeviceDelJob) 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 *DeviceDelJob) 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 *DeviceDelJob) Save(db *gorm.DB) error {
- return db.Table(p.TableName()).Save(p).Error
- }
- func (p *DeviceDelJob) 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 *DeviceDelJob) List(db *gorm.DB, where map[string]interface{}, page int) (list []DeviceDelJob, 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(PageSize).Offset(page).Find(&list)
- return list, result.Error
- }
- result := db.Table(p.TableName()).Limit(10).Offset(page).Find(&list)
- return list, result.Error
- }
- func (p *DeviceDelJob) All(db *gorm.DB) (list []DeviceDelJob, err error) {
- result := db.Table(p.TableName()).Find(&list)
- return list, result.Error
- }
|