center.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package vehicle
  4. import (
  5. "context"
  6. "fmt"
  7. "gd_vehicle/consts"
  8. "gd_vehicle/errors"
  9. "gd_vehicle/impl/thirdparty_impl"
  10. "gd_vehicle/utils"
  11. dutils "gd_vehicle/utils"
  12. "strings"
  13. "gd_vehicle/apis"
  14. )
  15. /*
  16. func IsReuse(reuse *bool, LReq *[]apis.ThirdpartLogWrite) {
  17. if len(*LReq) > 0 {
  18. for _, v := range *LReq {
  19. if v.ProviderCode == "" {
  20. *reuse = false
  21. return
  22. }
  23. }
  24. *reuse = true
  25. } else {
  26. *reuse = true
  27. }
  28. }*/
  29. type FuncInterface struct {
  30. Func func(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) error
  31. NeedVehicleInfo bool
  32. NeedFormat bool
  33. }
  34. var interfaces = map[string]FuncInterface{
  35. "1001": {A001,true,true }, // 车牌查车辆信息
  36. "1002": {A002,true,true }, // vin查车辆信息
  37. "1003": {A003,false,false }, // vin查车型
  38. "2001": {V001,false,false }, // 二要素验证
  39. "2002": {V002,true,true }, // 二要素验证,返回车档
  40. "2003": {V003,false ,true}, // 二要素验证,不一致不返回车档
  41. "2004": {V004,false ,false}, // 三要素验证
  42. "2005": {V005,true ,true}, // 三要素验证返回车档
  43. "2006": {V006,false ,true}, // 三要素验证,不一致不返回车档
  44. "3001": {IS001,true ,true}, // 保险日期查询
  45. //"4001": {X001,false ,false}, // 学位证信息
  46. }
  47. /*
  48. func getApiCodeMap(reqCode string) string {
  49. retCode := ""
  50. err := orm.NewOrm().Raw("select dest from db_gd_management.t_gd_api_code_map where source = ?", reqCode).QueryRow(&retCode)
  51. if err == nil {
  52. return retCode
  53. }
  54. return retCode
  55. }*/
  56. func newResponse(respConf []apis.ManagementBaseApiParam) map[string]interface{}{
  57. retMap := make(map[string]interface{})
  58. for _,v := range respConf{
  59. //if v.Selected{
  60. key := v.Name
  61. if v.Type == "int"{
  62. retMap[key] = 0
  63. }else if v.Type == "float"{
  64. retMap[key] = 0
  65. }else if v.Type == "bool"{
  66. retMap[key] = false
  67. }else if v.Type == "string"{
  68. retMap[key] = ""
  69. }else if v.Type == "struct"{
  70. retMap[key] = make(map[string]interface{})
  71. }else if strings.Contains(v.Type,"list"){
  72. retMap[key] = make([]interface{},0)
  73. }
  74. //}
  75. }
  76. return retMap
  77. }
  78. func Query(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) (err error) {
  79. defer func() {
  80. //IsReuse(&reply.IsReuse, &reply.LReq)
  81. if r := recover(); r != nil {
  82. if e, ok := r.(error); ok {
  83. err = e
  84. } else {
  85. err = fmt.Errorf("%+v", r)
  86. }
  87. }
  88. }()
  89. if len(req.Code) < 4 {
  90. return errors.CheckApiNotExist
  91. }else {
  92. req.Code = req.Code[0:4]
  93. }
  94. merchantProviderLimitInfoList, err := utils.GetProviderInfo(req.MerchantApiInfo.MerchantChildApiId, req.BaseApiId)
  95. if err != nil {
  96. return errors.ServiceError
  97. }
  98. req.ProviderMap, req.ProviderGroup = utils.GenProviderInfoMapNew(merchantProviderLimitInfoList)
  99. err = errors.NoRecord
  100. if v, ok := interfaces[strings.ToUpper(req.Code)]; ok {
  101. req.NeedVehicleInfo = v.NeedVehicleInfo
  102. reply.Data = newResponse(req.ResponseParamConf)
  103. err = v.Func(ctx, req, reply)
  104. if err == nil {
  105. if v.NeedFormat {
  106. // 调用F01格式化
  107. tReq := &apis.ThirdpartRequest{
  108. Ctx: ctx,
  109. Params: reply.Data.(map[string]interface{}),
  110. ProviderApiCode: dutils.ADMF01,
  111. ProviderMap: req.ProviderMap,
  112. RangeNo: consts.RANGEONE,
  113. Req: req,
  114. Reply: reply,
  115. }
  116. respData := make(map[string]interface{})
  117. err := thirdparty_impl.CallThirdparty(tReq,respData)
  118. if err == nil {
  119. reply.Data = respData
  120. }
  121. }
  122. return nil
  123. }else {
  124. return err
  125. }
  126. }else{
  127. return errors.CheckApiNotExist
  128. }
  129. return errors.NoRecord
  130. }