company.go 2.3 KB
package domain

import "time"

// 公司状态状态  1:已注册 2:待认证 3:已认证
const (
	CompanyRegistered = iota + 1
	CompanyUnauthenticated
	CompanyAuthenticated
)

// 企业信息 (base)
type Company struct {
	// 企业id
	CompanyId int64 `json:"companyId"`
	// 企业配置信息
	CompanyConfig *CompanyConfig `json:"companyConfig"`
	// 企业基本信息
	CompanyInfo *CompanyInfo `json:"companyInfo"`
	// 公司状态 1:已注册 2:待认证 3:已认证
	Status int `json:"status"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt"`
}

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 systemName, ok := data["systemName"]; ok {
		company.CompanyConfig.SystemName = systemName.(string)
	}
	if theme, ok := data["theme"]; ok {
		company.CompanyConfig.Theme = theme.(string)
	}
	if companyName, ok := data["companyName"]; ok {
		company.CompanyInfo.CompanyName = companyName.(string)
	}
	if scale, ok := data["scale"]; ok {
		company.CompanyInfo.Scale = scale.(string)
	}
	if logo, ok := data["logo"]; ok {
		company.CompanyInfo.Logo = logo.(string)
	}
	if address, ok := data["address"]; ok {
		company.CompanyInfo.Address = address.(string)
	}
	if industryCategory, ok := data["industryCategory"]; ok {
		company.CompanyInfo.IndustryCategory = industryCategory.(string)
	}
	if contacts, ok := data["contacts"]; ok {
		company.CompanyInfo.Contacts = contacts.(string)
	}
	if registTime, ok := data["registTime"]; ok {
		company.CompanyInfo.RegisteredTime = registTime.(time.Time)
	}
	if registStatus, ok := data["registStatus"]; ok {
		company.CompanyInfo.status = registStatus.(int)
	}
	if status, ok := data["status"]; ok {
		company.Status = status.(int)
	}
	if createdAt, ok := data["createdAt"]; ok {
		company.CreatedAt = createdAt.(time.Time)
	}
	if updatedAt, ok := data["updatedAt"]; ok {
		company.UpdatedAt = updatedAt.(time.Time)
	}
	return nil
}