sys_employee.go 2.7 KB
package models

import (
	"fmt"
	"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/internal/pkg/domain"
	"gorm.io/gorm"
	"gorm.io/plugin/soft_delete"
	"time"
)

type SysEmployee struct {
	Id        int64  // 唯一标识
	UserId    int64  // 用户表ID
	CompanyId int64  // 公司表ID
	Code      string `gorm:"type:varchar(128)"` // 自定义编码(成员的唯一标识、员工编号、工号等)
	//Departments   []int64                 `gorm:"type:jsonb;serializer:json"` // 归属部门列表
	//Name          string                  `gorm:"type:varchar(64)"`           // 姓名
	//Avatar        string                  `gorm:"type:varchar(1024)"`         // 头像
	//Phone         string                  `gorm:"type:varchar(64)"`           // 手机号码
	Position      string                  `gorm:"type:varchar(128)"` // 职务
	AccountStatus int                     // 账号状态 0.未激活 1.正常 2.已暂停 4.未加入 5.主动退出
	EmployeeType  string                  `gorm:"type:varchar(64)"`           // 雇员类型 正式、实习、外包、劳务、顾问
	BaseInfo      domain.EmployeeBaseInfo `gorm:"type:jsonb;serializer:json"` // 基本信息
	WorkInfo      domain.EmployeeWorkInfo `gorm:"type:jsonb;serializer:json"` // 工作信息
	CreatedAt     int64
	UpdatedAt     int64
	DeletedAt     int64
	Version       int
	IsDel         soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
}

func (m *SysEmployee) TableName() string {
	return "sys.employee"
}

func (m *SysEmployee) BeforeCreate(tx *gorm.DB) (err error) {
	m.CreatedAt = time.Now().Unix()
	m.UpdatedAt = time.Now().Unix()
	return
}

func (m *SysEmployee) BeforeUpdate(tx *gorm.DB) (err error) {
	// m.UpdatedAt = time.Now().Unix()
	return
}

func (m *SysEmployee) CacheKeyFunc() string {
	if m.Id == 0 {
		return ""
	}
	return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
}

func (m *SysEmployee) CacheKeyFuncByObject(obj interface{}) string {
	if v, ok := obj.(*SysEmployee); ok {
		return v.CacheKeyFunc()
	}
	return ""
}

func (m *SysEmployee) CachePrimaryKeyFunc() string {
	if len("") == 0 {
		return ""
	}
	return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}

func (m *SysEmployee) CachePrimaryKeyCompanyPhoneFunc() string {
	//if m.CompanyId == 0 || m.Phone == "" {
	//	return ""
	//}
	//return fmt.Sprintf("%v:cache:%v:primarykey:%v:%v", domain.ProjectName, m.TableName(), m.CompanyId, m.Phone)
	return ""
}

func (m *SysEmployee) CachePrimaryKeyCompanyUserFunc() string {
	if m.CompanyId == 0 || m.UserId == 0 {
		return ""
	}
	return fmt.Sprintf("%v:cache:%v:primarykey:%v:%v", domain.ProjectName, m.TableName(), m.CompanyId, m.UserId)
}