123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- // 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 TStaff struct {
- Id int64 `gorm:"column:id"`
- ProjectId int64 `gorm:"column:project_id"`
- WorkNo string `gorm:"column:work_no"`
- Name string `gorm:"column:name"`
- IdCert string `gorm:"column:id_cert"`
- Gender int64 `gorm:"column:gender"`
- StaffType int64 `gorm:"column:staff_type"`
- Birthday string `gorm:"column:birthday"`
- Address string `gorm:"column:address"`
- IdIssue string `gorm:"column:id_issue"`
- IdPeriod string `gorm:"column:id_period"`
- IdPhoto string `gorm:"column:id_photo"`
- Photo string `gorm:"column:photo"`
- InfPhoto string `gorm:"column:inf_photo"`
- Sn string `gorm:"column:sn"`
- Status int64 `gorm:"column:status"`
- Phone string `gorm:"column:phone"`
- WorkType string `gorm:"column:work_type"`
- LaborCompany string `gorm:"column:labor_company"`
- Group string `gorm:"column:group"`
- IsDelete int64 `gorm:"column:is_delete"`
- CreatedAt time.Time `gorm:"column:created_at"`
- UpdatedAt time.Time `gorm:"column:updated_at"`
- }
- func (TStaff) TableName() string {
- return "db_smart_staff.t_staff"
- }
- func (p *TStaff) Insert(db *gorm.DB) error {
- return db.Create(p).Error
- }
- func (p *TStaff) 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 *TStaff) 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 *TStaff) 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 *TStaff) Save(db *gorm.DB) error {
- return db.Save(p).Error
- }
- func (p *TStaff) 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 *TStaff) List(db *gorm.DB, where map[string]interface{}, page int) (list []TStaff, 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 *TStaff) All(db *gorm.DB) (list []TStaff, err error) {
- result := db.Table(p.TableName()).Find(&list)
- return list, result.Error
- }
|