123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- package model
- import (
- "fmt"
- "time"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jinzhu/gorm"
- "go.uber.org/zap"
- )
- type ProjectWorkInfo struct {
- Id int64 `gorm:"column:ID;PRIMARY_KEY" json:"id"`
- Code string `gorm:"column:Code" json:"code"`
- CorpCode string `gorm:"column:CorpCode" json:"corp_code"`
- CorpName string `gorm:"column:CorpName" json:"corp_name"`
- TeamSysNo int `gorm:"column:TeamSysNo" json:"team_sys_no"`
- TeamName string `gorm:"column:TeamName" json:"team_name"`
- WorkName string `gorm:"column:WorkName" json:"work_name"`
- IsTeamLeader string `gorm:"column:IsTeamLeader" json:"is_team_leader"`
- IDCardType int `gorm:"column:IDCardType" json:"id_card_type"`
- IDCardNumber string `gorm:"column:IDCardNumber" json:"id_card_number"`
- Age int `gorm:"column:Age" json:"age"`
- Gender string `gorm:"column:Gender" json:"gender"`
- Nation string `gorm:"column:Nation" json:"nation"`
- Address string `gorm:"column:Address" json:"address"`
- HeadImage string `gorm:"column:HeadImage" json:"head_image"`
- PoliticsType int `gorm:"column:PoliticsType" json:"politics_type"`
- CultureLevelType int `gorm:"column:CultureLevelType" json:"colture_level_type"`
- GrantOrg string `gorm:"column:GrantOrg" json:"grant_org"`
- WorkType string `gorm:"column:WorkType" json:"work_type"`
- NativePlace string `gorm:"column:NativePlace" json:"native_place"`
- Mobile string `gorm:"column:Mobile" json:"mobile"`
- IssueCardPicUrl string `gorm:"column:IssueCardPicUrl" json:"issue_card_pic_url"`
- HasContract string `gorm:"column:HasContract" json:"has_contract"`
- HasBuyInsurance string `gorm:"column:HasBuyInsurance" json:"has_buy_insurance"`
- Remark string `gorm:"column:Remark" json:"remark"`
- ProjectId int64 `gorm:"column:ProjectId" json:"project_id"`
- WorkNo string `gorm:"column:WorkNo" json:"work_no"`
- 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 (ProjectWorkInfo) TableName() string {
- return "db_smart_attendance.ProjectWorkInfo"
- }
- // Insert 插入一条记录
- func (p *ProjectWorkInfo) 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 ProjectWorkInfo"),
- zap.String("fields", fields),
- zap.String("error", err.Error()))
- }
- return err
- }
- func (p *ProjectWorkInfo) 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 *ProjectWorkInfo) Delete(db *gorm.DB, filter map[string]interface{}) error {
- err := db.Table(p.TableName()).Where(filter).Delete(p).Error
- if err != nil {
- fields, _ := json.MarshalToString(filter)
- logger.Error("mysql",
- zap.String("sql", "delete from ProjectWorkInfo"),
- zap.String("fields", fields),
- zap.String("error", err.Error()))
- }
- return err
- }
- func (p *ProjectWorkInfo) 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 ProjectWorkInfo"),
- 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 ProjectWorkInfo"),
- zap.String("where", whereStr),
- zap.String("values", valuesStr),
- zap.String("error", err.Error()))
- }
- return err
- }
- func (p *ProjectWorkInfo) 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 ProjectWorkInfo"),
- 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 ProjectWorkInfo"),
- zap.String("where", whereStr),
- zap.String("error", err.Error()))
- return err
- }
- return err
- }
- type StaffIDCard struct {
- IDCardNumber string `gorm:"column:IDCardNumber" json:"id_card_number"`
- WorkNo string `gorm:"column:WorkNo" json:"work_no"`
- }
- func GetIDCardNumberByWorkNo(db *gorm.DB, projectId int64, worknos []string) ([]StaffIDCard,error) {
- sql := fmt.Sprintf("select IDCardNumber, WorkNo from db_smart_attendance.ProjectWorkInfo where ProjectId=? and WorkNo in(?)")
- array := []StaffIDCard{}
- err := db.Raw(sql, projectId, worknos).Scan(&array).Error
- if err != nil {
- return nil, err
- }
- return array, nil
- }
- func (p *ProjectWorkInfo) List(db *gorm.DB, where map[string]interface{}, or map[string]interface{}, page int32, pageSize int32) (list []ProjectWorkInfo, 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
- }
|