This commit is contained in:
2025-10-17 17:59:54 +08:00
parent b92dfd0d58
commit adc9db7f78
17 changed files with 713 additions and 30 deletions

View File

@@ -0,0 +1,66 @@
package qcxg
import (
"context"
"encoding/json"
"errors"
"tyapi-server/internal/domains/api/dto"
"tyapi-server/internal/domains/api/services/processors"
"tyapi-server/internal/infrastructure/external/zhicha"
)
// ProcessQCXG9P1CRequest QCXG9P1C API处理方法
func ProcessQCXG9P1CRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
var paramsDto dto.QCXG9P1CReq
if err := json.Unmarshal(params, &paramsDto); err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
return nil, errors.Join(processors.ErrInvalidParam, err)
}
encryptedIDCard, err := deps.ZhichaService.Encrypt(paramsDto.IDCard)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
reqData := map[string]interface{}{
"data": map[string]interface{}{
"idCardNum": encryptedIDCard,
"authorized": paramsDto.Authorized,
},
}
if paramsDto.Name != "" {
encryptedName, err := deps.ZhichaService.Encrypt(paramsDto.Name)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
reqData["data"].(map[string]interface{})["name"] = encryptedName
}
// 如果传了 vehicleType则添加到请求数据中
if paramsDto.VehicleType != "" {
reqData["data"].(map[string]interface{})["vehicleType"] = paramsDto.VehicleType
}
if paramsDto.UserType != "" {
reqData["data"].(map[string]interface{})["userType"] = paramsDto.UserType
}
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI051", reqData)
if err != nil {
if errors.Is(err, zhicha.ErrDatasource) {
return nil, errors.Join(processors.ErrDatasource, err)
} else {
return nil, errors.Join(processors.ErrSystem, err)
}
}
// 将响应数据转换为 JSON 字节
respBytes, err := json.Marshal(respData)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
return respBytes, nil
}