package model import ( "github.com/jinzhu/gorm" "time" ) type ProjectCorpInfo struct { ID int64 `gorm:"column:ID;primary_key"` Code string `gorm:"column:Code"` CorpName string `gorm:"column:CorpName"` CorpCode string `gorm:"column:CorpCode"` AreaCode string `gorm:"column:AreaCode"` RegisterDate time.Time `gorm:"column:RegisterDate"` CorpType uint32 `gorm:"column:CorpType"` ProjectId int64 `gorm:"column:ProjectId"` } func (ProjectCorpInfo) TableName() string { return "ProjectCorpInfo" } func (p *ProjectCorpInfo) Insert(db *gorm.DB) error { return db.Table(p.TableName()).Create(p).Error } func (p *ProjectCorpInfo) Find(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) error { cond, val, err := whereBuildAndOr(where, or) if err != nil { return err } return db.Table(p.TableName()).Where(cond, val...).First(p).Error } func (p *ProjectCorpInfo) All(db *gorm.DB, where map[string]interface{}) (list []ProjectCorpInfo, err error) { if len(where) > 0 { cond, val, err := whereBuild(where) if err != nil { return nil, 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 *ProjectCorpInfo) 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 *ProjectCorpInfo) 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 }