fix certification
This commit is contained in:
@@ -947,12 +947,16 @@ func (s *CertificationApplicationServiceImpl) AddStatusMetadata(ctx context.Cont
|
|||||||
case enums.StatusPending, enums.StatusInfoSubmitted, enums.StatusEnterpriseVerified:
|
case enums.StatusPending, enums.StatusInfoSubmitted, enums.StatusEnterpriseVerified:
|
||||||
record, err := s.enterpriseInfoSubmitRecordRepo.FindLatestByUserID(ctx, cert.UserID)
|
record, err := s.enterpriseInfoSubmitRecordRepo.FindLatestByUserID(ctx, cert.UserID)
|
||||||
if err == nil && record != nil {
|
if err == nil && record != nil {
|
||||||
metadata["company_name"] = record.CompanyName
|
enterpriseInfo := map[string]interface{}{
|
||||||
metadata["legal_person_name"] = record.LegalPersonName
|
"company_name": record.CompanyName,
|
||||||
metadata["unified_social_code"] = record.UnifiedSocialCode
|
"legal_person_name": record.LegalPersonName,
|
||||||
metadata["enterprise_address"] = record.EnterpriseAddress
|
"unified_social_code": record.UnifiedSocialCode,
|
||||||
metadata["legal_person_phone"] = record.LegalPersonPhone
|
"enterprise_address": record.EnterpriseAddress,
|
||||||
metadata["legal_person_id"] = record.LegalPersonID
|
"legal_person_phone": record.LegalPersonPhone,
|
||||||
|
"legal_person_id": record.LegalPersonID,
|
||||||
|
}
|
||||||
|
metadata["enterprise_info"] = enterpriseInfo
|
||||||
|
|
||||||
}
|
}
|
||||||
case enums.StatusCompleted:
|
case enums.StatusCompleted:
|
||||||
// 获取最终合同信息
|
// 获取最终合同信息
|
||||||
|
|||||||
@@ -2,15 +2,20 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"tyapi-server/internal/config"
|
"tyapi-server/internal/config"
|
||||||
|
"tyapi-server/internal/domains/api/dto"
|
||||||
|
"tyapi-server/internal/domains/api/services/processors"
|
||||||
|
"tyapi-server/internal/domains/api/services/processors/qygl"
|
||||||
"tyapi-server/internal/domains/certification/entities"
|
"tyapi-server/internal/domains/certification/entities"
|
||||||
"tyapi-server/internal/domains/certification/entities/value_objects"
|
"tyapi-server/internal/domains/certification/entities/value_objects"
|
||||||
"tyapi-server/internal/domains/certification/repositories"
|
"tyapi-server/internal/domains/certification/repositories"
|
||||||
|
"tyapi-server/internal/infrastructure/external/tianyancha"
|
||||||
"tyapi-server/internal/infrastructure/external/westdex"
|
"tyapi-server/internal/infrastructure/external/westdex"
|
||||||
|
"tyapi-server/internal/shared/interfaces"
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,15 +25,26 @@ import (
|
|||||||
|
|
||||||
type EnterpriseInfoSubmitRecordService struct {
|
type EnterpriseInfoSubmitRecordService struct {
|
||||||
westdexService *westdex.WestDexService
|
westdexService *westdex.WestDexService
|
||||||
|
tianYanChaService *tianyancha.TianYanChaService
|
||||||
|
validator interfaces.RequestValidator
|
||||||
repositories repositories.EnterpriseInfoSubmitRecordRepository
|
repositories repositories.EnterpriseInfoSubmitRecordRepository
|
||||||
appConfig config.AppConfig
|
appConfig config.AppConfig
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEnterpriseInfoSubmitRecordService 构造函数
|
// NewEnterpriseInfoSubmitRecordService 构造函数
|
||||||
func NewEnterpriseInfoSubmitRecordService(westdexService *westdex.WestDexService, repositories repositories.EnterpriseInfoSubmitRecordRepository, appConfig config.AppConfig, logger *zap.Logger) *EnterpriseInfoSubmitRecordService {
|
func NewEnterpriseInfoSubmitRecordService(
|
||||||
|
westdexService *westdex.WestDexService,
|
||||||
|
tianYanChaService *tianyancha.TianYanChaService,
|
||||||
|
validator interfaces.RequestValidator,
|
||||||
|
repositories repositories.EnterpriseInfoSubmitRecordRepository,
|
||||||
|
appConfig config.AppConfig,
|
||||||
|
logger *zap.Logger,
|
||||||
|
) *EnterpriseInfoSubmitRecordService {
|
||||||
return &EnterpriseInfoSubmitRecordService{
|
return &EnterpriseInfoSubmitRecordService{
|
||||||
westdexService: westdexService,
|
westdexService: westdexService,
|
||||||
|
tianYanChaService: tianYanChaService,
|
||||||
|
validator: validator,
|
||||||
repositories: repositories,
|
repositories: repositories,
|
||||||
appConfig: appConfig,
|
appConfig: appConfig,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
@@ -47,7 +63,7 @@ func (s *EnterpriseInfoSubmitRecordService) Save(ctx context.Context, enterprise
|
|||||||
return s.repositories.Create(ctx, enterpriseInfoSubmitRecord)
|
return s.repositories.Create(ctx, enterpriseInfoSubmitRecord)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateWithWestdex 调用westdexService验证企业信息
|
// ValidateWithWestdex 调用QYGL23T7处理器验证企业信息
|
||||||
func (s *EnterpriseInfoSubmitRecordService) ValidateWithWestdex(ctx context.Context, info *value_objects.EnterpriseInfo) error {
|
func (s *EnterpriseInfoSubmitRecordService) ValidateWithWestdex(ctx context.Context, info *value_objects.EnterpriseInfo) error {
|
||||||
if info == nil {
|
if info == nil {
|
||||||
return errors.New("企业信息不能为空")
|
return errors.New("企业信息不能为空")
|
||||||
@@ -58,57 +74,71 @@ func (s *EnterpriseInfoSubmitRecordService) ValidateWithWestdex(ctx context.Cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 开发环境下跳过外部验证
|
// 开发环境下跳过外部验证
|
||||||
if s.appConfig.IsDevelopment() {
|
// if s.appConfig.IsDevelopment() {
|
||||||
s.logger.Info("开发环境:跳过企业信息外部验证",
|
// s.logger.Info("开发环境:跳过企业信息外部验证",
|
||||||
|
// zap.String("company_name", info.CompanyName),
|
||||||
|
// zap.String("legal_person", info.LegalPersonName))
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 构建QYGL23T7请求参数
|
||||||
|
reqDto := dto.QYGL23T7Req{
|
||||||
|
EntName: info.CompanyName,
|
||||||
|
LegalPerson: info.LegalPersonName,
|
||||||
|
EntCode: info.UnifiedSocialCode,
|
||||||
|
IDCard: info.LegalPersonID,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 序列化请求参数
|
||||||
|
paramsBytes, err := json.Marshal(reqDto)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("序列化请求参数失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建处理器依赖
|
||||||
|
deps := &processors.ProcessorDependencies{
|
||||||
|
WestDexService: s.westdexService,
|
||||||
|
TianYanChaService: s.tianYanChaService,
|
||||||
|
Validator: s.validator,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用QYGL23T7处理器进行验证
|
||||||
|
responseBytes, err := qygl.ProcessQYGL23T7Request(ctx, paramsBytes, deps)
|
||||||
|
if err != nil {
|
||||||
|
// 检查是否是数据源错误
|
||||||
|
if errors.Is(err, processors.ErrDatasource) {
|
||||||
|
return fmt.Errorf("数据源异常: %w", err)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("企业信息验证失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析响应结果
|
||||||
|
var response map[string]interface{}
|
||||||
|
if err := json.Unmarshal(responseBytes, &response); err != nil {
|
||||||
|
return fmt.Errorf("解析响应结果失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查验证状态
|
||||||
|
status, ok := response["status"].(float64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("响应格式错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据状态码判断验证结果
|
||||||
|
switch int(status) {
|
||||||
|
case 0:
|
||||||
|
// 验证通过
|
||||||
|
s.logger.Info("企业信息验证通过",
|
||||||
zap.String("company_name", info.CompanyName),
|
zap.String("company_name", info.CompanyName),
|
||||||
zap.String("legal_person", info.LegalPersonName))
|
zap.String("legal_person", info.LegalPersonName))
|
||||||
return nil
|
return nil
|
||||||
}
|
case 1:
|
||||||
encryptedEntName, err := s.westdexService.Encrypt(info.CompanyName)
|
// 企业信息不一致
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("%s: %w", "企业四要素验证", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
encryptedLegalPerson, err := s.westdexService.Encrypt(info.LegalPersonName)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("%s: %w", "企业四要素验证", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
encryptedEntCode, err := s.westdexService.Encrypt(info.UnifiedSocialCode)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("%s: %w", "企业四要素验证", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
encryptedIDCard, err := s.westdexService.Encrypt(info.LegalPersonID)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("%s: %w", "企业四要素验证", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
reqParams := map[string]interface{}{
|
|
||||||
"data": map[string]interface{}{
|
|
||||||
"entname": encryptedEntName,
|
|
||||||
"realname": encryptedLegalPerson,
|
|
||||||
"entmark": encryptedEntCode,
|
|
||||||
"idcard": encryptedIDCard,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
var respData []byte
|
|
||||||
resp, err := s.westdexService.CallAPI("WEST00021", reqParams)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, westdex.ErrDatasource) && resp != nil {
|
|
||||||
respData = resp
|
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
respData = resp
|
|
||||||
s.logger.Info("验证企业四要素响应", zap.Any("response", respData))
|
|
||||||
resultState := gjson.GetBytes(respData, "result.state")
|
|
||||||
if !resultState.Exists() {
|
|
||||||
return fmt.Errorf("企业信息不一致")
|
return fmt.Errorf("企业信息不一致")
|
||||||
|
case 2:
|
||||||
|
// 身份证信息不一致
|
||||||
|
return fmt.Errorf("身份证信息不一致")
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("未知的验证状态: %d", int(status))
|
||||||
}
|
}
|
||||||
if resultState.Int() != 1 {
|
|
||||||
return fmt.Errorf("企业信息不一致")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user