// 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"` } 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 }