fix comb298y
This commit is contained in:
parent
766a972af1
commit
937d88c9aa
@ -1,5 +1,24 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StructToMap 将结构体转换为 map[string]interface{}
|
||||||
|
func StructToMap(data interface{}) (map[string]interface{}, error) {
|
||||||
|
jsonData, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var result map[string]interface{}
|
||||||
|
if err := json.Unmarshal(jsonData, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func MapStructToAPIRequest(encryptedFields map[string]interface{}, fieldMapping map[string]string, wrapField string) map[string]interface{} {
|
func MapStructToAPIRequest(encryptedFields map[string]interface{}, fieldMapping map[string]string, wrapField string) map[string]interface{} {
|
||||||
apiRequest := make(map[string]interface{})
|
apiRequest := make(map[string]interface{})
|
||||||
|
|
||||||
|
@ -107,13 +107,6 @@ func (l *COMB298YLogic) COMB298Y(req *types.Request) (resp string, err *errs.App
|
|||||||
return "", errs.ErrParamValidation
|
return "", errs.ErrParamValidation
|
||||||
}
|
}
|
||||||
|
|
||||||
var encryptedFields map[string]interface{}
|
|
||||||
unmarshalErr := json.Unmarshal(decryptData, &encryptedFields)
|
|
||||||
if unmarshalErr != nil {
|
|
||||||
logx.Errorf("解密数据转换为map失败:%v", err)
|
|
||||||
return "", errs.ErrSystem
|
|
||||||
}
|
|
||||||
|
|
||||||
// 准备并发请求
|
// 准备并发请求
|
||||||
apiRequests := []APIRequest{
|
apiRequests := []APIRequest{
|
||||||
{SourceId: "G16BJ02", ServiceId: "YYSY09CD", Mapping: westmodel.YYSY09CDFieldMapping, Wrap: "data", Service: "west"},
|
{SourceId: "G16BJ02", ServiceId: "YYSY09CD", Mapping: westmodel.YYSY09CDFieldMapping, Wrap: "data", Service: "west"},
|
||||||
@ -133,18 +126,33 @@ func (l *COMB298YLogic) COMB298Y(req *types.Request) (resp string, err *errs.App
|
|||||||
|
|
||||||
// 为每个请求构建对应的请求参数
|
// 为每个请求构建对应的请求参数
|
||||||
for i := range apiRequests {
|
for i := range apiRequests {
|
||||||
request := encryptedFields
|
|
||||||
if apiRequests[i].Service == "west" {
|
if apiRequests[i].Service == "west" {
|
||||||
// 3、西部加密
|
// 西部服务:先加密后mapping
|
||||||
westConfig := l.svcCtx.Config.WestConfig
|
westConfig := l.svcCtx.Config.WestConfig
|
||||||
encryptedRequest, encryptStructFieldsErr := common.EncryptStructFields(request, westConfig.Key)
|
// 将结构体转换为map
|
||||||
if encryptStructFieldsErr != nil {
|
dataMap, err := common.StructToMap(data)
|
||||||
logx.Errorf("西部加密错误:%v", encryptStructFieldsErr)
|
if err != nil {
|
||||||
|
logx.Errorf("结构体转map失败:%v", err)
|
||||||
|
return "", errs.ErrSystem
|
||||||
}
|
}
|
||||||
request = encryptedRequest
|
// 加密
|
||||||
|
encryptedRequest, encryptErr := common.EncryptStructFields(dataMap, westConfig.Key)
|
||||||
|
if encryptErr != nil {
|
||||||
|
logx.Errorf("西部加密错误:%v", encryptErr)
|
||||||
|
return "", errs.ErrSystem
|
||||||
|
}
|
||||||
|
// mapping
|
||||||
|
apiRequests[i].Request = common.MapStructToAPIRequest(encryptedRequest, apiRequests[i].Mapping, apiRequests[i].Wrap)
|
||||||
|
} else {
|
||||||
|
// 羽山服务:直接mapping
|
||||||
|
dataMap, err := common.StructToMap(data)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("结构体转map失败:%v", err)
|
||||||
|
return "", errs.ErrSystem
|
||||||
|
}
|
||||||
|
apiRequests[i].Request = common.MapStructToAPIRequest(dataMap, apiRequests[i].Mapping, apiRequests[i].Wrap)
|
||||||
}
|
}
|
||||||
logx.Infof("sourceId:%s,请求参数:%v", apiRequests[i].SourceId, request)
|
logx.Infof("sourceId:%s,请求参数:%v", apiRequests[i].SourceId, apiRequests[i].Request)
|
||||||
apiRequests[i].Request = common.MapStructToAPIRequest(request, apiRequests[i].Mapping, apiRequests[i].Wrap)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建响应通道
|
// 创建响应通道
|
||||||
|
Loading…
Reference in New Issue
Block a user