add qygl23t7

This commit is contained in:
2025-07-30 00:51:22 +08:00
parent 83530c0f9b
commit 723c418a1b
38 changed files with 999 additions and 785 deletions

View File

@@ -24,8 +24,6 @@ type EnterpriseInfo struct {
LegalPersonID string `gorm:"type:varchar(50);not null" json:"legal_person_id" comment:"法定代表人身份证号"`
LegalPersonPhone string `gorm:"type:varchar(50);not null" json:"legal_person_phone" comment:"法定代表人手机号"`
EnterpriseAddress string `json:"enterprise_address" gorm:"type:varchar(200);not null" comment:"企业地址"`
EnterpriseEmail string `json:"enterprise_email" gorm:"type:varchar(100);not null" comment:"企业邮箱"`
// 时间戳字段
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at" comment:"创建时间"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at" comment:"更新时间"`
@@ -54,7 +52,7 @@ func (e *EnterpriseInfo) BeforeCreate(tx *gorm.DB) error {
// ================ 工厂方法 ================
// NewEnterpriseInfo 创建新的企业信息
func NewEnterpriseInfo(userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone,enterpriseAddress, enterpriseEmail string) (*EnterpriseInfo, error) {
func NewEnterpriseInfo(userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone,enterpriseAddress string) (*EnterpriseInfo, error) {
if userID == "" {
return nil, fmt.Errorf("用户ID不能为空")
}
@@ -76,9 +74,6 @@ func NewEnterpriseInfo(userID, companyName, unifiedSocialCode, legalPersonName,
if enterpriseAddress == "" {
return nil, fmt.Errorf("企业地址不能为空")
}
if enterpriseEmail == "" {
return nil, fmt.Errorf("企业邮箱不能为空")
}
enterpriseInfo := &EnterpriseInfo{
ID: uuid.New().String(),
@@ -89,7 +84,6 @@ func NewEnterpriseInfo(userID, companyName, unifiedSocialCode, legalPersonName,
LegalPersonID: legalPersonID,
LegalPersonPhone: legalPersonPhone,
EnterpriseAddress: enterpriseAddress,
EnterpriseEmail: enterpriseEmail,
domainEvents: make([]interface{}, 0),
}
@@ -108,7 +102,7 @@ func NewEnterpriseInfo(userID, companyName, unifiedSocialCode, legalPersonName,
// ================ 聚合根核心方法 ================
// UpdateEnterpriseInfo 更新企业信息
func (e *EnterpriseInfo) UpdateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail string) error {
func (e *EnterpriseInfo) UpdateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress string) error {
// 验证输入参数
if companyName == "" {
return fmt.Errorf("企业名称不能为空")
@@ -128,9 +122,6 @@ func (e *EnterpriseInfo) UpdateEnterpriseInfo(companyName, unifiedSocialCode, le
if enterpriseAddress == "" {
return fmt.Errorf("企业地址不能为空")
}
if enterpriseEmail == "" {
return fmt.Errorf("企业邮箱不能为空")
}
// 记录原始值用于事件
oldCompanyName := e.CompanyName
@@ -143,7 +134,6 @@ func (e *EnterpriseInfo) UpdateEnterpriseInfo(companyName, unifiedSocialCode, le
e.LegalPersonID = legalPersonID
e.LegalPersonPhone = legalPersonPhone
e.EnterpriseAddress = enterpriseAddress
e.EnterpriseEmail = enterpriseEmail
// 添加领域事件
e.addDomainEvent(&EnterpriseInfoUpdatedEvent{
@@ -198,10 +188,6 @@ func (e *EnterpriseInfo) validateBasicFields() error {
if e.LegalPersonPhone == "" {
return fmt.Errorf("法定代表人手机号不能为空")
}
if e.EnterpriseEmail == "" {
return fmt.Errorf("企业邮箱不能为空")
}
// 统一社会信用代码格式验证
if !e.isValidUnifiedSocialCode(e.UnifiedSocialCode) {
return fmt.Errorf("统一社会信用代码格式无效")
@@ -217,11 +203,6 @@ func (e *EnterpriseInfo) validateBasicFields() error {
return fmt.Errorf("法定代表人手机号格式无效")
}
// 邮箱格式验证 (简单示例,实际应更严格)
if !e.isValidEmail(e.EnterpriseEmail) {
return fmt.Errorf("企业邮箱格式无效")
}
return nil
}
@@ -237,11 +218,6 @@ func (e *EnterpriseInfo) validateBusinessLogic() error {
return fmt.Errorf("法定代表人姓名长度不能超过100个字符")
}
// 企业邮箱格式验证 (简单示例,实际应更严格)
if !e.isValidEmail(e.EnterpriseEmail) {
return fmt.Errorf("企业邮箱格式无效")
}
return nil
}
@@ -255,8 +231,7 @@ func (e *EnterpriseInfo) IsComplete() bool {
e.UnifiedSocialCode != "" &&
e.LegalPersonName != "" &&
e.LegalPersonID != "" &&
e.LegalPersonPhone != "" &&
e.EnterpriseEmail != ""
e.LegalPersonPhone != ""
}
// GetCertificationProgress 获取认证进度

View File

@@ -102,14 +102,14 @@ func (u *User) CompleteCertification() error {
// ================ 企业信息管理方法 ================
// CreateEnterpriseInfo 创建企业信息
func (u *User) CreateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail string) error {
func (u *User) CreateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress string) error {
// 检查是否已有企业信息
if u.EnterpriseInfo != nil {
return fmt.Errorf("用户已有企业信息")
}
// 创建企业信息实体
enterpriseInfo, err := NewEnterpriseInfo(u.ID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail)
enterpriseInfo, err := NewEnterpriseInfo(u.ID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress)
if err != nil {
return fmt.Errorf("创建企业信息失败: %w", err)
}
@@ -130,7 +130,7 @@ func (u *User) CreateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonN
}
// UpdateEnterpriseInfo 更新企业信息
func (u *User) UpdateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail string) error {
func (u *User) UpdateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress string) error {
// 检查是否有企业信息
if u.EnterpriseInfo == nil {
return fmt.Errorf("用户暂无企业信息")
@@ -141,7 +141,7 @@ func (u *User) UpdateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonN
oldUnifiedSocialCode := u.EnterpriseInfo.UnifiedSocialCode
// 更新企业信息
err := u.EnterpriseInfo.UpdateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail)
err := u.EnterpriseInfo.UpdateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress)
if err != nil {
return err
}

View File

@@ -36,14 +36,14 @@ type UserAggregateService interface {
GetUserStats(ctx context.Context) (*repositories.UserStats, error)
// 企业信息管理
CreateEnterpriseInfo(ctx context.Context, userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail string) error
UpdateEnterpriseInfo(ctx context.Context, userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail string) error
CreateEnterpriseInfo(ctx context.Context, userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress string) error
UpdateEnterpriseInfo(ctx context.Context, userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress string) error
GetUserWithEnterpriseInfo(ctx context.Context, userID string) (*entities.User, error)
ValidateEnterpriseInfo(ctx context.Context, userID string) error
CheckUnifiedSocialCodeExists(ctx context.Context, unifiedSocialCode string, excludeUserID string) (bool, error)
// 认证域专用:写入/覆盖企业信息
CreateOrUpdateEnterpriseInfo(ctx context.Context, userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail string) error
CreateOrUpdateEnterpriseInfo(ctx context.Context, userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress string) error
CompleteCertification(ctx context.Context, userID string) error
}
@@ -122,7 +122,7 @@ func (s *UserAggregateServiceImpl) LoadUser(ctx context.Context, userID string)
// 验证业务规则
if err := s.ValidateBusinessRules(ctx, &user); err != nil {
s.logger.Warn("用户业务规则验证失败",
s.logger.Warn("用户业务规则验证失败",
zap.String("user_id", userID),
zap.Error(err),
)
@@ -186,7 +186,7 @@ func (s *UserAggregateServiceImpl) LoadUserByPhone(ctx context.Context, phone st
// 验证业务规则
if err := s.ValidateBusinessRules(ctx, user); err != nil {
s.logger.Warn("用户业务规则验证失败",
s.logger.Warn("用户业务规则验证失败",
zap.String("phone", phone),
zap.Error(err),
)
@@ -303,7 +303,7 @@ func (s *UserAggregateServiceImpl) UpdateLoginStats(ctx context.Context, userID
// ================ 企业信息管理 ================
// CreateEnterpriseInfo 创建企业信息
func (s *UserAggregateServiceImpl) CreateEnterpriseInfo(ctx context.Context, userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail string) error {
func (s *UserAggregateServiceImpl) CreateEnterpriseInfo(ctx context.Context, userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress string) error {
s.logger.Debug("创建企业信息", zap.String("user_id", userID))
// 1. 加载用户聚合根
@@ -327,7 +327,7 @@ func (s *UserAggregateServiceImpl) CreateEnterpriseInfo(ctx context.Context, use
}
// 4. 使用聚合根方法创建企业信息
err = user.CreateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail)
err = user.CreateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress)
if err != nil {
return fmt.Errorf("创建企业信息失败: %w", err)
}
@@ -349,7 +349,7 @@ func (s *UserAggregateServiceImpl) CreateEnterpriseInfo(ctx context.Context, use
}
// UpdateEnterpriseInfo 更新企业信息
func (s *UserAggregateServiceImpl) UpdateEnterpriseInfo(ctx context.Context, userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail string) error {
func (s *UserAggregateServiceImpl) UpdateEnterpriseInfo(ctx context.Context, userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress string) error {
s.logger.Debug("更新企业信息", zap.String("user_id", userID))
// 1. 加载用户聚合根
@@ -373,7 +373,7 @@ func (s *UserAggregateServiceImpl) UpdateEnterpriseInfo(ctx context.Context, use
}
// 4. 使用聚合根方法更新企业信息
err = user.UpdateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail)
err = user.UpdateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress)
if err != nil {
return fmt.Errorf("更新企业信息失败: %w", err)
}
@@ -394,7 +394,6 @@ func (s *UserAggregateServiceImpl) UpdateEnterpriseInfo(ctx context.Context, use
return nil
}
// GetUserWithEnterpriseInfo 获取用户信息(包含企业信息)
func (s *UserAggregateServiceImpl) GetUserWithEnterpriseInfo(ctx context.Context, userID string) (*entities.User, error) {
s.logger.Debug("获取用户信息(包含企业信息)", zap.String("user_id", userID))
@@ -407,7 +406,7 @@ func (s *UserAggregateServiceImpl) GetUserWithEnterpriseInfo(ctx context.Context
// 验证业务规则
if err := s.ValidateBusinessRules(ctx, &user); err != nil {
s.logger.Warn("用户业务规则验证失败",
s.logger.Warn("用户业务规则验证失败",
zap.String("user_id", userID),
zap.Error(err),
)
@@ -437,7 +436,7 @@ func (s *UserAggregateServiceImpl) ValidateEnterpriseInfo(ctx context.Context, u
// CheckUnifiedSocialCodeExists 检查统一社会信用代码是否存在
func (s *UserAggregateServiceImpl) CheckUnifiedSocialCodeExists(ctx context.Context, unifiedSocialCode string, excludeUserID string) (bool, error) {
s.logger.Debug("检查统一社会信用代码是否存在",
s.logger.Debug("检查统一社会信用代码是否存在",
zap.String("unified_social_code", unifiedSocialCode),
zap.String("exclude_user_id", excludeUserID),
)
@@ -455,12 +454,12 @@ func (s *UserAggregateServiceImpl) CheckUnifiedSocialCodeExists(ctx context.Cont
}
if exists {
s.logger.Info("统一社会信用代码已存在",
s.logger.Info("统一社会信用代码已存在",
zap.String("unified_social_code", unifiedSocialCode),
zap.String("exclude_user_id", excludeUserID),
)
} else {
s.logger.Debug("统一社会信用代码不存在",
s.logger.Debug("统一社会信用代码不存在",
zap.String("unified_social_code", unifiedSocialCode),
)
}
@@ -471,20 +470,20 @@ func (s *UserAggregateServiceImpl) CheckUnifiedSocialCodeExists(ctx context.Cont
// CreateOrUpdateEnterpriseInfo 认证域专用:写入/覆盖企业信息
func (s *UserAggregateServiceImpl) CreateOrUpdateEnterpriseInfo(
ctx context.Context,
userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail string,
userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress string,
) error {
user, err := s.LoadUser(ctx, userID)
if err != nil {
return fmt.Errorf("用户不存在: %w", err)
}
if user.EnterpriseInfo == nil {
enterpriseInfo, err := entities.NewEnterpriseInfo(userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail)
enterpriseInfo, err := entities.NewEnterpriseInfo(userID, companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress)
if err != nil {
return err
}
user.EnterpriseInfo = enterpriseInfo
} else {
err := user.EnterpriseInfo.UpdateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress, enterpriseEmail)
err := user.EnterpriseInfo.UpdateEnterpriseInfo(companyName, unifiedSocialCode, legalPersonName, legalPersonID, legalPersonPhone, enterpriseAddress)
if err != nil {
return err
}
@@ -504,7 +503,7 @@ func (s *UserAggregateServiceImpl) CompleteCertification(ctx context.Context, us
// ListUsers 获取用户列表
func (s *UserAggregateServiceImpl) ListUsers(ctx context.Context, query *queries.ListUsersQuery) ([]*entities.User, int64, error) {
s.logger.Debug("获取用户列表",
s.logger.Debug("获取用户列表",
zap.Int("page", query.Page),
zap.Int("page_size", query.PageSize),
)
@@ -516,7 +515,7 @@ func (s *UserAggregateServiceImpl) ListUsers(ctx context.Context, query *queries
return nil, 0, fmt.Errorf("查询用户列表失败: %w", err)
}
s.logger.Info("用户列表查询成功",
s.logger.Info("用户列表查询成功",
zap.Int("count", len(users)),
zap.Int64("total", total),
)
@@ -535,7 +534,7 @@ func (s *UserAggregateServiceImpl) GetUserStats(ctx context.Context) (*repositor
return nil, fmt.Errorf("查询用户统计信息失败: %w", err)
}
s.logger.Info("用户统计信息查询成功",
s.logger.Info("用户统计信息查询成功",
zap.Int64("total_users", stats.TotalUsers),
zap.Int64("active_users", stats.ActiveUsers),
zap.Int64("certified_users", stats.CertifiedUsers),
@@ -556,7 +555,7 @@ func (s *UserAggregateServiceImpl) publishDomainEvents(ctx context.Context, user
for _, event := range events {
// 这里需要将领域事件转换为标准事件格式
// 暂时跳过,后续可以完善事件转换逻辑
s.logger.Debug("发布领域事件",
s.logger.Debug("发布领域事件",
zap.String("user_id", user.ID),
zap.Any("event", event),
)
@@ -566,4 +565,4 @@ func (s *UserAggregateServiceImpl) publishDomainEvents(ctx context.Context, user
user.ClearDomainEvents()
return nil
}
}