employee.go 1.0 KB
package domain

// 员工
type Employee struct {
	// 员工ID
	EmployeeId int64 `json:"employeeId"`
	// 员工信息
	EmployeeInfo *EmployeeInfo `json:"employeeInfo"`
	// 当前素币
	SuMoney float64 `json:"suMoney"`
}

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)
}

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 {
		employee.EmployeeInfo.EmployeeName = employeeName.(string)
	}
	if employeeAccount, ok := data["employeeAccount"]; ok {
		employee.EmployeeInfo.EmployeeAccount = employeeAccount.(string)
	}
	return nil
}

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