f
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// FadadaCorpAuthRecord 法大大企业授权相关数据(与 certifications 分离,便于签署链路复用)
|
||||
// open_corp_id:企业对本应用授权后,法大大分配的企业标识
|
||||
type FadadaCorpAuthRecord struct {
|
||||
ID string `json:"id" gorm:"primaryKey;type:varchar(36)"`
|
||||
UserID string `json:"user_id" gorm:"type:varchar(36);not null;index;comment:用户ID"`
|
||||
CertificationID string `json:"certification_id" gorm:"type:varchar(36);index;comment:关联认证记录ID"`
|
||||
|
||||
AppID string `json:"app_id" gorm:"type:varchar(32);index;comment:法大大应用AppId"`
|
||||
CompanyName string `json:"company_name" gorm:"type:varchar(200);comment:企业名称"`
|
||||
UnifiedSocialCode string `json:"unified_social_code" gorm:"column:unified_social_code;type:varchar(50);index;comment:统一社会信用代码(corpIdentNo)"`
|
||||
ClientCorpID string `json:"client_corp_id" gorm:"column:client_corp_id;type:varchar(64);index;comment:应用内企业标识(clientCorpId)"`
|
||||
OpenCorpID string `json:"open_corp_id" gorm:"column:open_corp_id;type:varchar(64);index;comment:法大大企业openCorpId"`
|
||||
|
||||
BindingStatus string `json:"binding_status" gorm:"type:varchar(32);comment:授权绑定状态 unauthorized/authorized"`
|
||||
IdentStatus string `json:"ident_status" gorm:"type:varchar(32);comment:实名状态 unidentified/identified"`
|
||||
AvailableStatus string `json:"available_status" gorm:"type:varchar(32);comment:启用状态 disable/enable"`
|
||||
AuthScopes string `json:"auth_scopes" gorm:"type:text;comment:授权范围JSON数组字符串"`
|
||||
Source string `json:"source" gorm:"type:varchar(64);comment:数据来源"`
|
||||
|
||||
CreatedAt time.Time `json:"created_at" gorm:"not null"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"not null"`
|
||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
||||
}
|
||||
|
||||
func (FadadaCorpAuthRecord) TableName() string {
|
||||
return "fadada_corp_auth_records"
|
||||
}
|
||||
|
||||
func NewFadadaCorpAuthRecord(userID, certificationID, appID, companyName, uscc, clientCorpID string) *FadadaCorpAuthRecord {
|
||||
now := time.Now()
|
||||
return &FadadaCorpAuthRecord{
|
||||
ID: uuid.New().String(),
|
||||
UserID: strings.TrimSpace(userID),
|
||||
CertificationID: strings.TrimSpace(certificationID),
|
||||
AppID: strings.TrimSpace(appID),
|
||||
CompanyName: strings.TrimSpace(companyName),
|
||||
UnifiedSocialCode: strings.TrimSpace(uscc),
|
||||
ClientCorpID: strings.TrimSpace(clientCorpID),
|
||||
Source: "init",
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *FadadaCorpAuthRecord) ApplyAuthStatus(
|
||||
openCorpID, clientCorpID, bindingStatus, identStatus, availableStatus string,
|
||||
authScopes []string,
|
||||
source string,
|
||||
) {
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
if v := strings.TrimSpace(openCorpID); v != "" {
|
||||
r.OpenCorpID = v
|
||||
}
|
||||
if v := strings.TrimSpace(clientCorpID); v != "" {
|
||||
r.ClientCorpID = v
|
||||
}
|
||||
if v := strings.TrimSpace(bindingStatus); v != "" {
|
||||
r.BindingStatus = v
|
||||
}
|
||||
if v := strings.TrimSpace(identStatus); v != "" {
|
||||
r.IdentStatus = v
|
||||
}
|
||||
if v := strings.TrimSpace(availableStatus); v != "" {
|
||||
r.AvailableStatus = v
|
||||
}
|
||||
if len(authScopes) > 0 {
|
||||
r.AuthScopes = strings.Join(authScopes, ",")
|
||||
}
|
||||
if v := strings.TrimSpace(source); v != "" {
|
||||
r.Source = v
|
||||
}
|
||||
r.UpdatedAt = time.Now()
|
||||
}
|
||||
|
||||
func (r *FadadaCorpAuthRecord) IsAuthorized() bool {
|
||||
return r != nil && strings.EqualFold(strings.TrimSpace(r.BindingStatus), "authorized") && strings.TrimSpace(r.OpenCorpID) != ""
|
||||
}
|
||||
Reference in New Issue
Block a user