company.go
4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package domain
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant"
"time"
)
// 公司状态状态 1:已注册 2:已通过 3:已拒绝 4:禁用
const (
CompanyRegistered = iota + 1
CompanyAuthenticated
CompanyUnauthenticated
CompanyUnAvailable
)
// 企业信息 (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,
}
}
// 公司审核
func (company *Company) Audit(status int, remark string) error {
if company.Status != CompanyRegistered {
return fmt.Errorf("公司已审核")
}
if !(status == CompanyAuthenticated || status == CompanyUnauthenticated) {
return fmt.Errorf("审核状态有误")
}
company.Status = status
company.CompanyInfo.Remark = remark
company.Update(map[string]interface{}{})
return nil
}
// 公司启用禁用
func (company *Company) Enable(status int) error {
if company.Status == CompanyRegistered {
return fmt.Errorf("公司待审核")
}
if company.Status == status {
return nil
}
if !(status == CompanyAuthenticated || status == CompanyUnAvailable) {
return fmt.Errorf("状态有误 2:启用 4:禁用")
}
company.Status = status
company.Update(map[string]interface{}{})
return nil
}
/***** 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"`
}