employee.go 2.2 KB
package domain

import "time"

// 员工
type Employee struct {
	// 员工ID
	EmployeeId int64 `json:"employeeId"`
	// 公司ID
	CompanyId int64 `json:"companyId"`
	// 员工信息
	EmployeeInfo *EmployeeInfo `json:"employeeInfo"`
	// 当前素币
	SuMoney float64 `json:"suMoney"`
	// 员工状态(启用或者禁用)
	Status int `json:"status"`
	// 员工权限集合
	Permissions []int `json:"permissions"`
	// 创建时间
	CreateTime time.Time `json:"createTime"`
}

type EmployeeRepository interface {
	Save(employee *Employee) (*Employee, error)
	Remove(employee *Employee) (*Employee, error)
	FindOne(queryOptions map[string]interface{}) (*Employee, error)
	Find(queryOptions map[string]interface{}) (int64, []*Employee, error)
	FindByIds(queryOptions map[string]interface{}) (int64, []*Employee, error)
	FindAll(queryOptions map[string]interface{}) (int64, []*Employee, error)
}

func (employee *Employee) Identify() interface{} {
	if employee.EmployeeId == 0 {
		return nil
	}
	return employee.EmployeeId
}

func (employee *Employee) Update(data map[string]interface{}) error {
	if employeeName, ok := data["employeeName"]; ok && employeeName != "" {
		employee.EmployeeInfo.EmployeeName = employeeName.(string)
	}
	if employeeAccount, ok := data["employeeAccount"]; ok && employeeAccount != "" {
		employee.EmployeeInfo.EmployeeAccount = employeeAccount.(string)
	}
	if employeeAvatarUrl, ok := data["employeeAvatarUrl"]; ok && employeeAvatarUrl != "" {
		employee.EmployeeInfo.EmployeeAvatarUrl = employeeAvatarUrl.(string)
	}
	if isPrincipal, ok := data["isPrincipal"]; ok {
		employee.EmployeeInfo.IsPrincipal = isPrincipal.(bool)
	}
	if status, ok := data["status"]; ok && status != 0 {
		employee.Status = status.(int)
	}
	if permissions, ok := data["permissions"]; ok {
		employee.Permissions = permissions.([]int)
	}
	if createTime, ok := data["createTime"]; ok && !createTime.(time.Time).IsZero() {
		employee.CreateTime = createTime.(time.Time)
	}
	return nil
}

func (employee *Employee) TransferSuMoney(suMoney float64) error {
	employee.SuMoney = employee.SuMoney + suMoney
	return nil
}

func (employee *Employee) TransitionSuMoney(suMoney float64) error {
	employee.SuMoney = employee.SuMoney + suMoney
	return nil
}