123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package model
- import (
- "time"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jinzhu/gorm"
- "go.uber.org/zap"
- )
- type TeamMasterInfo struct {
- ID int64 `gorm:"column:ID;primary_key"`
- Code string `gorm:"column:Code" json:"code"`
- TeamSysNo int `gorm:"column:TeamSysNo" json:"team_sys_no"`
- CorpCode string `gorm:"column:CorpCode" json:"corp_code"`
- CorpName string `gorm:"column:CorpName" json:"corp_name"`
- TeamName string `gorm:"column:TeamName" json:"team_name"`
- TeamLeaderName string `gorm:"column:TeamLeaderName" json:"team_leader_name"`
- TeamLeaderPhone string `gorm:"column:TeamLeaderPhone" json:"team_leader_phone"`
- Remark string `gorm:"column:Remark" json:"remark"`
- ProjectId int64 `gorm:"column:ProjectId" json:"project_id"`
- CreatedAt time.Time `gorm:"column:CreatedAt" json:"created_at"`
- UpdatedAt time.Time `gorm:"column:UpdatedAt" json:"updated_at"`
- Sn string `gorm:"column:Sn" json:"sn"`
- ProvincialVerifyStatus int32 `gorm:"column:ProvincialVerifyStatus" json:"provincial_verify_status"`
- ProvincialVerifyCode int32 `gorm:"column:ProvincialVerifyCode" json:"provincial_verify_code"`
- ProvincialVerifyInfo string `gorm:"column:ProvincialVerifyInfo" json:"provincial_verify_info"`
- ProvincialVerifyID string `gorm:"column:ProvincialVerifyID" json:"provincial_verify_id"`
- }
- func (TeamMasterInfo) TableName() string {
- return "db_smart_attendance.TeamMasterInfo"
- }
- // Insert 插入一条记录
- func (p *TeamMasterInfo) Insert(db *gorm.DB) error {
- err := db.Table(p.TableName()).Create(p).Error
- if err != nil {
- fields, _ := json.MarshalToString(*p)
- logger.Error("mysql",
- zap.String("sql", "insert into TeamMasterInfo"),
- zap.String("fields", fields),
- zap.String("error", err.Error()))
- }
- return err
- }
- func (p *TeamMasterInfo) Delete(db *gorm.DB, filter map[string]interface{}) error {
- cond, val, err := whereBuild(filter)
- if err != nil {
- return err
- }
- err = db.Table(p.TableName()).Where(cond, val...).Delete(p).Error
- if err != nil {
- fields, _ := json.MarshalToString(filter)
- logger.Error("mysql",
- zap.String("sql", "delete from "+p.TableName()),
- zap.String("fields", fields),
- zap.String("error", err.Error()))
- }
- return err
- }
- func (p *TeamMasterInfo) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- whereStr, _ := json.MarshalToString(where)
- valuesStr, _ := json.MarshalToString(values)
- logger.Error("mysql",
- zap.String("sql", "update TeamMasterInfo"),
- zap.String("where", whereStr),
- zap.String("values", valuesStr),
- zap.String("error", err.Error()))
- return err
- }
- err = db.Table(p.TableName()).Where(cond, val...).Updates(values).Error
- if err != nil {
- whereStr, _ := json.MarshalToString(where)
- valuesStr, _ := json.MarshalToString(values)
- logger.Error("mysql",
- zap.String("sql", "update TeamMasterInfo"),
- zap.String("where", whereStr),
- zap.String("values", valuesStr),
- zap.String("error", err.Error()))
- }
- return err
- }
- func (p *TeamMasterInfo) Find(db *gorm.DB, where map[string]interface{}) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- whereStr, _ := json.MarshalToString(where)
- logger.Error("mysql",
- zap.String("sql", "select from TeamMasterInfo"),
- zap.String("where", whereStr),
- zap.String("error", err.Error()))
- return err
- }
- err = db.Table(p.TableName()).Where(cond, val...).First(p).Error
- if err != nil {
- whereStr, _ := json.MarshalToString(where)
- logger.Error("mysql",
- zap.String("sql", "select from TeamMasterInfo"),
- zap.String("where", whereStr),
- zap.String("error", err.Error()))
- return err
- }
- return err
- }
- func (p *TeamMasterInfo) FindOr(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) error {
- cond, val, err := whereBuildAndOr(where, or)
- if err != nil {
- whereStr, _ := json.MarshalToString(where)
- logger.Error("mysql",
- zap.String("sql", "select from TeamMasterInfo"),
- zap.String("where", whereStr),
- zap.String("error", err.Error()))
- return err
- }
- err = db.Table(p.TableName()).Where(cond, val...).First(p).Error
- if err != nil {
- whereStr, _ := json.MarshalToString(where)
- logger.Error("mysql",
- zap.String("sql", "select from TeamMasterInfo"),
- zap.String("where", whereStr),
- zap.String("error", err.Error()))
- return err
- }
- return err
- }
- func (p *TeamMasterInfo) List(db *gorm.DB, where map[string]interface{}, or map[string]interface{}, page int32, pageSize int32) (list []TeamMasterInfo, err error) {
- if len(where) > 0 || len(or) > 0 {
- cond, val, err := whereBuildAndOr(where, or)
- if err != nil {
- return list, err
- }
- if pageSize < 0 {
- result := db.Table(p.TableName()).Where(cond, val...).Find(&list)
- return list, result.Error
- }
- offset := (page - 1) * pageSize
- result := db.Table(p.TableName()).Where(cond, val...).Limit(pageSize).Offset(offset).Find(&list)
- return list, result.Error
- }
- if pageSize < 0 {
- result := db.Table(p.TableName()).Find(&list)
- return list, result.Error
- }
- offset := (page - 1) * pageSize
- result := db.Table(p.TableName()).Limit(pageSize).Offset(offset).Find(&list)
- return list, result.Error
- }
|