更新处理器

This commit is contained in:
2026-06-10 20:32:24 +08:00
parent a29265f901
commit 45ae6cf36e
293 changed files with 2028 additions and 23462 deletions

View File

@@ -2,13 +2,12 @@ package services
import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
"hyapi-server/internal/config"
"hyapi-server/internal/domains/api/dto"
"hyapi-server/internal/domains/api/services/processors"
"hyapi-server/internal/domains/api/services/processors/qygl"
"hyapi-server/internal/domains/certification/entities"
"hyapi-server/internal/domains/certification/entities/value_objects"
"hyapi-server/internal/domains/certification/repositories"
@@ -71,85 +70,72 @@ func (s *EnterpriseInfoSubmitRecordService) Save(ctx context.Context, enterprise
return s.repositories.Create(ctx, enterpriseInfoSubmitRecord)
}
// ValidateWithWestdex 调用QYGL5CMP处理器验证企业信息
// ValidateWithWestdex 通过天眼查企业基本信息核对企业名称、统一社会信用代码与法人姓名(原 QYGL23T7 产品已下线)。
func (s *EnterpriseInfoSubmitRecordService) ValidateWithWestdex(ctx context.Context, info *value_objects.EnterpriseInfo) error {
if info == nil {
return errors.New("企业信息不能为空")
}
// 先做本地校验
if err := info.Validate(); err != nil {
return err
}
// 开发环境下跳过外部验证
// if s.appConfig.IsDevelopment() {
// s.logger.Info("开发环境:跳过企业信息外部验证",
// zap.String("company_name", info.CompanyName),
// zap.String("legal_person", info.LegalPersonName))
// return nil
// }
// 构建QYGL5CMP请求参数
reqDto := dto.QYGL5CMPReq{
EntName: info.CompanyName,
LegalPerson: info.LegalPersonName,
EntCode: info.UnifiedSocialCode,
IDCard: info.LegalPersonID,
MobileNo: info.LegalPersonPhone,
if s.tianYanChaService == nil {
return errors.New("企业信息验证服务未配置")
}
// 序列化请求参数
paramsBytes, err := json.Marshal(reqDto)
resp, err := s.tianYanChaService.CallAPI(ctx, "baseinfo", map[string]string{
"keyword": info.UnifiedSocialCode,
})
if err != nil {
return fmt.Errorf("序列化请求参数失败: %w", err)
}
// 创建处理器依赖
deps := &processors.ProcessorDependencies{
WestDexService: s.westdexService,
TianYanChaService: s.tianYanChaService,
AlicloudService: s.alicloudService,
YushanService: s.yushanService,
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)
if errors.Is(err, tianyancha.ErrNotFound) {
return fmt.Errorf("企业信息不一致")
}
if errors.Is(err, tianyancha.ErrDatasource) {
return fmt.Errorf("数据源异常: %w", errors.Join(processors.ErrDatasource, err))
}
return fmt.Errorf("企业信息验证失败: %w", err)
}
// 解析响应结果
var response map[string]interface{}
if err := json.Unmarshal(responseBytes, &response); err != nil {
return fmt.Errorf("解析响应结果失败: %w", err)
if resp == nil || !resp.Success {
return fmt.Errorf("企业信息验证失败")
}
// 检查验证状态
status, ok := response["status"].(float64)
data, ok := resp.Data.(map[string]interface{})
if !ok {
return fmt.Errorf("响应格式错误")
}
// 根据状态码判断验证结果
switch int(status) {
case 0:
// 验证通过
s.logger.Info("企业信息验证通过",
zap.String("company_name", info.CompanyName),
zap.String("legal_person", info.LegalPersonName))
return nil
case 1:
// 企业信息不一致
return fmt.Errorf("企业信息不一致")
case 2:
// 身份证信息不一致
return fmt.Errorf("身份证信息不一致")
default:
return fmt.Errorf("未知的验证状态: %d", int(status))
entName := strings.TrimSpace(fmt.Sprint(data["name"]))
entCode := strings.TrimSpace(fmt.Sprint(data["creditCode"]))
if entCode == "" {
entCode = strings.TrimSpace(fmt.Sprint(data["regNumber"]))
}
legalPerson := strings.TrimSpace(fmt.Sprint(data["legalPersonName"]))
if !enterpriseNamesMatch(entName, info.CompanyName) || !strings.EqualFold(entCode, strings.TrimSpace(info.UnifiedSocialCode)) {
return fmt.Errorf("企业信息不一致")
}
if legalPerson != "" && !namesMatch(legalPerson, info.LegalPersonName) {
return fmt.Errorf("身份证信息不一致")
}
s.logger.Info("企业信息验证通过",
zap.String("company_name", info.CompanyName),
zap.String("legal_person", info.LegalPersonName))
return nil
}
func enterpriseNamesMatch(a, b string) bool {
a = normalizeEnterpriseName(a)
b = normalizeEnterpriseName(b)
return a == b || strings.Contains(a, b) || strings.Contains(b, a)
}
func namesMatch(a, b string) bool {
return strings.TrimSpace(a) == strings.TrimSpace(b)
}
func normalizeEnterpriseName(s string) string {
s = strings.TrimSpace(s)
s = strings.ReplaceAll(s, "", "(")
s = strings.ReplaceAll(s, "", ")")
return s
}