company.go 3.2 KB
package domain

import (
	"fmt"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant"
	"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)
	}

	company.UpdatedAt = time.Now()
	return nil
}

func (company *Company) CloneSample() *Company {
	return &Company{
		CompanyId:   company.CompanyId,
		Status:      company.Status,
		CompanyInfo: company.CompanyInfo,
	}
}

func (company *Company) ToCompanyVisible() *CompanyVisible {
	return &CompanyVisible{
		CompanyId:   company.CompanyId,
		CompanyInfo: *company.CompanyInfo,
		Status:      company.Status,
		SystemName:  company.CompanyConfig.SystemName,
	}
}

/*****   2.缓存模块  *****/

func (company *Company) CacheKeyFunc() string {
	if constant.DISABLE_REPOSITORY_CACHE {
		return ""
	}
	if company.CompanyId == 0 {
		return ""
	}
	return fmt.Sprintf("%v:cache:company:id:%v", constant.CACHE_PREFIX, company.CompanyId)
}

type CompanyVisible struct {
	// 企业id
	CompanyId int64 `json:"companyId"`
	// 企业基本信息
	CompanyInfo
	Status int `json:"status"`
	// 系统名称
	SystemName string `json:"systemName,omitempty"`
}