123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package vehicle
- import (
- "context"
- "fmt"
- "gd_vehicle/consts"
- "gd_vehicle/errors"
- "gd_vehicle/impl/thirdparty_impl"
- "gd_vehicle/utils"
- dutils "gd_vehicle/utils"
- "strings"
- "gd_vehicle/apis"
- )
- /*
- func IsReuse(reuse *bool, LReq *[]apis.ThirdpartLogWrite) {
- if len(*LReq) > 0 {
- for _, v := range *LReq {
- if v.ProviderCode == "" {
- *reuse = false
- return
- }
- }
- *reuse = true
- } else {
- *reuse = true
- }
- }*/
- type FuncInterface struct {
- Func func(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) error
- NeedVehicleInfo bool
- NeedFormat bool
- }
- var interfaces = map[string]FuncInterface{
- "1001": {A001,true,true }, // 车牌查车辆信息
- "1002": {A002,true,true }, // vin查车辆信息
- "1003": {A003,false,false }, // vin查车型
- "2001": {V001,false,false }, // 二要素验证
- "2002": {V002,true,true }, // 二要素验证,返回车档
- "2003": {V003,false ,true}, // 二要素验证,不一致不返回车档
- "2004": {V004,false ,false}, // 三要素验证
- "2005": {V005,true ,true}, // 三要素验证返回车档
- "2006": {V006,false ,true}, // 三要素验证,不一致不返回车档
- "3001": {IS001,true ,true}, // 保险日期查询
- //"4001": {X001,false ,false}, // 学位证信息
- }
- /*
- func getApiCodeMap(reqCode string) string {
- retCode := ""
- err := orm.NewOrm().Raw("select dest from db_gd_management.t_gd_api_code_map where source = ?", reqCode).QueryRow(&retCode)
- if err == nil {
- return retCode
- }
- return retCode
- }*/
- func newResponse(respConf []apis.ManagementBaseApiParam) map[string]interface{}{
- retMap := make(map[string]interface{})
- for _,v := range respConf{
- //if v.Selected{
- key := v.Name
- if v.Type == "int"{
- retMap[key] = 0
- }else if v.Type == "float"{
- retMap[key] = 0
- }else if v.Type == "bool"{
- retMap[key] = false
- }else if v.Type == "string"{
- retMap[key] = ""
- }else if v.Type == "struct"{
- retMap[key] = make(map[string]interface{})
- }else if strings.Contains(v.Type,"list"){
- retMap[key] = make([]interface{},0)
- }
- //}
- }
- return retMap
- }
- func Query(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) (err error) {
- defer func() {
- //IsReuse(&reply.IsReuse, &reply.LReq)
- if r := recover(); r != nil {
- if e, ok := r.(error); ok {
- err = e
- } else {
- err = fmt.Errorf("%+v", r)
- }
- }
- }()
- if len(req.Code) < 4 {
- return errors.CheckApiNotExist
- }else {
- req.Code = req.Code[0:4]
- }
- merchantProviderLimitInfoList, err := utils.GetProviderInfo(req.MerchantApiInfo.MerchantChildApiId, req.BaseApiId)
- if err != nil {
- return errors.ServiceError
- }
- req.ProviderMap, req.ProviderGroup = utils.GenProviderInfoMapNew(merchantProviderLimitInfoList)
- err = errors.NoRecord
- if v, ok := interfaces[strings.ToUpper(req.Code)]; ok {
- req.NeedVehicleInfo = v.NeedVehicleInfo
- reply.Data = newResponse(req.ResponseParamConf)
- err = v.Func(ctx, req, reply)
- if err == nil {
- if v.NeedFormat {
- // 调用F01格式化
- tReq := &apis.ThirdpartRequest{
- Ctx: ctx,
- Params: reply.Data.(map[string]interface{}),
- ProviderApiCode: dutils.ADMF01,
- ProviderMap: req.ProviderMap,
- RangeNo: consts.RANGEONE,
- Req: req,
- Reply: reply,
- }
- respData := make(map[string]interface{})
- err := thirdparty_impl.CallThirdparty(tReq,respData)
- if err == nil {
- reply.Data = respData
- }
- }
- return nil
- }else {
- return err
- }
- }else{
- return errors.CheckApiNotExist
- }
- return errors.NoRecord
- }
|