123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- // 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 TProjectJob struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- Type int64 `gorm:"column:type" json:"type" form:"type"`
- Origin string `gorm:"column:origin" json:"origin" form:"origin"`
- Content string `gorm:"column:content" json:"content" form:"content"`
- CreatedAt time.Time `gorm:"column:created_at" json:"created_at" form:"created_at"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" form:"updated_at"`
- ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
- Feedback string `json:"feedback"`
- Reason string `json:"reason"`
- ProviderId int64 `json:"provider_id"`
- DeviceId int64 `json:"device_id"`
- }
- func (TProjectJob) TableName() string {
- return "t_project_job"
- }
- func (p *TProjectJob) Insert(db *gorm.DB) error {
- return db.Create(p).Error
- }
- func (p *TProjectJob) 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 *TProjectJob) 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 *TProjectJob) 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 *TProjectJob) FindSort(db *gorm.DB, where map[string]interface{}, sort string) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- return err
- }
- ps := []TProjectJob{}
- 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 *TProjectJob) Save(db *gorm.DB) error {
- return db.Save(p).Error
- }
- func (p *TProjectJob) 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 *TProjectJob) List(db *gorm.DB, where map[string]interface{}, page int) (list []TProjectJob, 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 *TProjectJob) All(db *gorm.DB) (list []TDevice, err error) {
- result := db.Table(p.TableName()).Find(&list)
- return list, result.Error
- }
|