company.go 2.1 KB
package domain

import "time"

// 公司信息
type Company struct {
	// 公司Id
	CompanyId int64 `json:"companyId"`
	// 公司信息
	CompanyInfo *CompanyInfo `json:"companyInfo"`
	// 创建时间
	CreateAt time.Time `json:"createAt"`
	// 更新时间
	UpdateAt time.Time `json:"updateAt"`
	// 删除时间
	DeleteAt time.Time `json:"deleteAt"`
}

type CompanyRepository interface {
	Save(company *Company) (*Company, error)
	Remove(company *Company) (*Company, error)
	FindOne(queryOptions map[string]interface{}) (*Company, error)
	Find(queryOptions map[string]interface{}) (int64, []*Company, error)
}

func (company *Company) Identify() interface{} {
	if company.CompanyId == 0 {
		return nil
	}
	return company.CompanyId
}

func (company *Company) Update(data map[string]interface{}) error {
	if companyId, ok := data["companyId"]; ok {
		company.CompanyId = companyId.(int64)
	}
	if name, ok := data["name"]; ok {
		company.CompanyInfo.Name = name.(string)
	}
	if abbreviation, ok := data["abbreviation"]; ok {
		company.CompanyInfo.Abbreviation = abbreviation.(string)
	}
	if logo, ok := data["logo"]; ok {
		company.CompanyInfo.Logo = logo.(string)
	}
	if phone, ok := data["phone"]; ok {
		company.CompanyInfo.Phone = phone.(string)
	}
	if status, ok := data["status"]; ok {
		company.CompanyInfo.Status = status.(int64)
	}
	if remarks, ok := data["remarks"]; ok {
		company.CompanyInfo.Remarks = remarks.(string)
	}
	if enable, ok := data["enable"]; ok {
		company.CompanyInfo.Enable = enable.(int64)
	}
	if userAccount, ok := data["userAccount"]; ok {
		company.CompanyInfo.Admin.UserAccount = userAccount.(string)
	}
	if userName, ok := data["userName"]; ok {
		company.CompanyInfo.Admin.UserName = userName.(string)
	}

	if createAt, ok := data["createAt"]; ok {
		company.CreateAt = createAt.(time.Time)
	}
	if updateAt, ok := data["updateAt"]; ok {
		company.UpdateAt = updateAt.(time.Time)
	}
	if deleteAt, ok := data["deleteAt"]; ok {
		company.DeleteAt = deleteAt.(time.Time)
	}

	return nil
}

// 更改公司管理员信息
func (company *Company) SetCompanyAdmin(admin *CompanyAdmin) error {
	company.CompanyInfo.Admin = admin
	return nil
}