基础架构
This commit is contained in:
108
internal/domains/user/entities/enterprise_info.go
Normal file
108
internal/domains/user/entities/enterprise_info.go
Normal file
@@ -0,0 +1,108 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// EnterpriseInfo 企业信息实体
|
||||
// 存储用户在认证过程中验证后的企业信息,认证完成后不可修改
|
||||
// 与用户是一对一关系,每个用户最多对应一个企业信息
|
||||
type EnterpriseInfo struct {
|
||||
// 基础标识
|
||||
ID string `gorm:"primaryKey;type:varchar(36)" json:"id" comment:"企业信息唯一标识"`
|
||||
UserID string `gorm:"type:varchar(36);not null;uniqueIndex" json:"user_id" comment:"关联用户ID"`
|
||||
|
||||
// 企业四要素 - 企业认证的核心信息
|
||||
CompanyName string `gorm:"type:varchar(255);not null" json:"company_name" comment:"企业名称"`
|
||||
UnifiedSocialCode string `gorm:"type:varchar(50);not null;index" json:"unified_social_code" comment:"统一社会信用代码"`
|
||||
LegalPersonName string `gorm:"type:varchar(100);not null" json:"legal_person_name" comment:"法定代表人姓名"`
|
||||
LegalPersonID string `gorm:"type:varchar(50);not null" json:"legal_person_id" comment:"法定代表人身份证号"`
|
||||
|
||||
// 认证状态 - 各环节的验证结果
|
||||
IsOCRVerified bool `gorm:"default:false" json:"is_ocr_verified" comment:"OCR验证是否通过"`
|
||||
IsFaceVerified bool `gorm:"default:false" json:"is_face_verified" comment:"人脸识别是否通过"`
|
||||
IsCertified bool `gorm:"default:false" json:"is_certified" comment:"是否已完成认证"`
|
||||
VerificationData string `gorm:"type:text" json:"verification_data,omitempty" comment:"验证数据(JSON格式)"`
|
||||
|
||||
// OCR识别结果 - 从营业执照中自动识别的信息
|
||||
OCRRawData string `gorm:"type:text" json:"ocr_raw_data,omitempty" comment:"OCR原始返回数据(JSON格式)"`
|
||||
OCRConfidence float64 `gorm:"type:decimal(5,2)" json:"ocr_confidence,omitempty" comment:"OCR识别置信度(0-1)"`
|
||||
|
||||
// 认证完成时间
|
||||
CertifiedAt *time.Time `json:"certified_at,omitempty" comment:"认证完成时间"`
|
||||
|
||||
// 时间戳字段
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at" comment:"创建时间"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at" comment:"更新时间"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-" comment:"软删除时间"`
|
||||
|
||||
// 关联关系
|
||||
User *User `gorm:"foreignKey:UserID" json:"user,omitempty" comment:"关联的用户信息"`
|
||||
}
|
||||
|
||||
// TableName 指定数据库表名
|
||||
func (EnterpriseInfo) TableName() string {
|
||||
return "enterprise_infos"
|
||||
}
|
||||
|
||||
// IsComplete 检查企业四要素是否完整
|
||||
// 验证企业名称、统一社会信用代码、法定代表人姓名、身份证号是否都已填写
|
||||
func (e *EnterpriseInfo) IsComplete() bool {
|
||||
return e.CompanyName != "" &&
|
||||
e.UnifiedSocialCode != "" &&
|
||||
e.LegalPersonName != "" &&
|
||||
e.LegalPersonID != ""
|
||||
}
|
||||
|
||||
// Validate 验证企业信息是否有效
|
||||
// 这里可以添加企业信息的业务验证逻辑
|
||||
// 比如统一社会信用代码格式验证、身份证号格式验证等
|
||||
func (e *EnterpriseInfo) Validate() error {
|
||||
if !e.IsComplete() {
|
||||
return fmt.Errorf("企业信息不完整")
|
||||
}
|
||||
// 这里可以添加企业信息的业务验证逻辑
|
||||
// 比如统一社会信用代码格式验证、身份证号格式验证等
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsFullyVerified 检查是否已完成所有验证
|
||||
func (e *EnterpriseInfo) IsFullyVerified() bool {
|
||||
return e.IsOCRVerified && e.IsFaceVerified && e.IsCertified
|
||||
}
|
||||
|
||||
// UpdateOCRVerification 更新OCR验证状态
|
||||
func (e *EnterpriseInfo) UpdateOCRVerification(isVerified bool, rawData string, confidence float64) {
|
||||
e.IsOCRVerified = isVerified
|
||||
e.OCRRawData = rawData
|
||||
e.OCRConfidence = confidence
|
||||
}
|
||||
|
||||
// UpdateFaceVerification 更新人脸识别验证状态
|
||||
func (e *EnterpriseInfo) UpdateFaceVerification(isVerified bool) {
|
||||
e.IsFaceVerified = isVerified
|
||||
}
|
||||
|
||||
// CompleteCertification 完成认证
|
||||
func (e *EnterpriseInfo) CompleteCertification() {
|
||||
e.IsCertified = true
|
||||
now := time.Now()
|
||||
e.CertifiedAt = &now
|
||||
}
|
||||
|
||||
// IsReadOnly 检查企业信息是否只读(认证完成后不可修改)
|
||||
func (e *EnterpriseInfo) IsReadOnly() bool {
|
||||
return e.IsCertified
|
||||
}
|
||||
|
||||
// BeforeCreate GORM钩子:创建前自动生成UUID
|
||||
func (e *EnterpriseInfo) BeforeCreate(tx *gorm.DB) error {
|
||||
if e.ID == "" {
|
||||
e.ID = uuid.New().String()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user