company.go 1.9 KB
package domain

import (
	"fmt"
	"time"
)

// 公司的状态 1正常 2禁用
const (
	companyStatusUsable   int8 = 1
	companyStatusUnusable int8 = 2
)

//是否开启机会模块,是否有效【1:有效】【2:无效】
const (
	CompanyEnableYes int8 = 1
	CompanyEnableNo  int8 = 2
)

// 公司信息
type Company struct {
	// 唯一标识
	Id int64 `json:"id"`
	// 名称
	Name string `json:"name"`
	// 手机号码
	Phone string `json:"phone"`
	// 公司logo
	Logo string `json:"logo"`
	// 备注
	Remarks string `json:"remarks"`
	// 总后台的公司id
	AdminCompanyId int `json:"adminCompanyId"`
	// 状态 1正常 2禁用
	Status int8 `json:"status"`
	//是否开启机会模块,是否有效【1:有效】【2:无效】
	Enable int8 `json:"enable"`
	// 创建时间
	CreateAt time.Time `json:"createAt"`
	// 更新时间
	UpdateAt time.Time `json:"updateAt"`
	// 删除时间
	DeleteAt time.Time `json:"deleteAt"`
}

func (c Company) StatusIsOk() bool {
	return c.Status == companyStatusUsable
}

func (c Company) EnableIsOk() bool {
	return c.Enable == CompanyEnableYes
}

func (c *Company) Update(m map[string]interface{}) error {
	if v, ok := m["Name"]; ok {
		c.Name = fmt.Sprint(v)
	}
	if v, ok := m["Phone"]; ok {
		c.Phone = fmt.Sprint(v)
	}
	if v, ok := m["Logo"]; ok {
		c.Logo = fmt.Sprint(v)
	}
	if v, ok := m["Remarks"]; ok {
		c.Remarks = fmt.Sprint(v)
	}
	if v, ok := m["AdminCompanyId"]; ok {
		c.AdminCompanyId = v.(int)
	}
	if v, ok := m["Remarks"]; ok {
		c.Remarks = fmt.Sprint(v)
	}
	if v, ok := m["Status"]; ok {
		c.Status = v.(int8)
	}
	if v, ok := m["Enable"]; ok {
		c.Enable = v.(int8)
	}
	return nil
}

type CompanyFindOneOptions struct {
	Id             int64
	AdminCompanyId int64
}

type CompanyFindOptions struct {
}

type CompanyRepository interface {
	Add(*Company) error
	Edit(*Company) error
	FindOne(queryOptions CompanyFindOneOptions) (Company, error)
	Find(queryOptions CompanyFindOptions) (int64, []Company, error)
}