x003.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package dybd
  2. import (
  3. "gd_service/apis"
  4. "gd_service/common.in/config"
  5. "gd_service/common.in/utils"
  6. "gd_service/consts"
  7. "gd_service/errors"
  8. "gd_service/thirdparty"
  9. dutils "gd_service/utils"
  10. "go.uber.org/zap"
  11. "github.com/tidwall/gjson"
  12. )
  13. func GetDybdX003Data(rdata string,) []map[string]string{
  14. arr := gjson.Parse(rdata).Array()
  15. ret := []map[string]string{}
  16. for _, v := range arr {
  17. respMap := make(map[string]string)
  18. respMap["is_double_first_class_university"] = v.Get("isDoubleFirstClassUniversity").String() // 是否为双一流学校
  19. respMap["is_two_one_one_university"] = v.Get("isTwoOneOneUniversity").String() // 是否为211学校
  20. respMap["end_date"] = v.Get("endDate").String() // 毕业日期
  21. respMap["type_name"] = v.Get("typeName").String() // 研究类型
  22. respMap["edu_code"] = v.Get("eduCode").String() // 学校代码
  23. respMap["qualification_code"] = v.Get( "qualificationCode").String() // 教育类别代码
  24. respMap["major_category"] = v.Get( "majorCategory").String() // 专业名称
  25. respMap["edu_name"] = v.Get( "eduName").String() // 学校名
  26. respMap["qualification_name"] = v.Get( "qualificationName").String() // 教育类别
  27. respMap["type_code"] = v.Get( "typeCode").String() // 研究类型代码
  28. respMap["secondary_category"] = v.Get( "secondaryCategory").String() // 二级学科名称
  29. respMap["begin_date"] = v.Get( "beginDate").String() // 注册日期
  30. respMap["major_code"] = v.Get( "majorCode").String() // 专业代码
  31. respMap["is_nine_eight_five_university"] = v.Get( "isNineEightFiveUniversity").String() // 是否为985学校
  32. ret = append(ret,respMap)
  33. }
  34. return ret
  35. }
  36. func getDybdX003Key(req *apis.ThirdpartRequest) string {
  37. key := consts.DybdX003Pre + req.Params[consts.DyBdX003P1] + req.Params[consts.DyBdX003P2]
  38. return key
  39. }
  40. func paramDybdX003Data(ret string) (reply string, err error) {
  41. code := gjson.Get(ret, "code").Int()
  42. if code == 200 {
  43. result := gjson.Get(ret, "data").String()
  44. arr := gjson.Parse(result).Array()
  45. if len(arr) <= 0 {
  46. return result, errors.NoRecord
  47. } else {
  48. if arr[0].Get( "eduName").String() == "" {
  49. return result, errors.NoRecord
  50. }
  51. // 学校名
  52. return result, nil
  53. }
  54. } else if code == 300{
  55. return "" ,errors.UserTokenExpire
  56. }else {
  57. return "", errors.VendorError
  58. }
  59. }
  60. func DybdX003Local(req *apis.ThirdpartRequest) (reply string, err error) {
  61. reply, err = dutils.GetDataByRedis(getDybdX003Key(req), int64(req.Req.ReuseTime), paramDybdX003Data)
  62. return reply, err
  63. }
  64. func DybdX003(req *apis.ThirdpartRequest) (reply string, err error) {
  65. redisKey := "dybd:xlalltoken:"
  66. token,err := getDybdToken(req.TryAgain,req.ProviderInfo.Timeout,config.Conf.ThirdPart.DybdXlAllAppkey,redisKey)
  67. if err != nil{
  68. l.Error("thridPart",
  69. zap.String("call", "getDybdToken"),
  70. zap.String("args",utils.MarshalJsonString(req.Params)),
  71. zap.String("error", err.Error()))
  72. req.LReq.ResponseParams = err.Error()
  73. dutils.SetAccessLogReqCodeMsgState(req.LReq, 1101, "gd_1101", err.Error(), false)
  74. return "",errors.VendorError
  75. }
  76. ret, err := thirdparty.DyBdClientPost(req.ProviderInfo.ThirdpartHost+"/"+req.ProviderInfo.ThirdpartApiRouter, req.Params, req.ProviderInfo.Timeout,token)
  77. if err != nil {
  78. l.Error("func",
  79. zap.String("call", "DyBdClientPost"),
  80. zap.String("args", utils.MarshalJsonString(req)),
  81. zap.String("error", err.Error()))
  82. req.LReq.ResponseParams = err.Error()
  83. dutils.SetAccessLogReqCodeMsgState(req.LReq, 1101, "gd_1101", "三方错误,请求失败", false)
  84. return "", errors.VendorError
  85. } else {
  86. req.LReq.ResponseParams = string(ret)
  87. reply, err = paramDybdX003Data(string(ret))
  88. code := gjson.GetBytes(ret, "code").String()
  89. message := gjson.GetBytes(ret, "message").String()
  90. if err == nil {
  91. dutils.SetAccessLogReqCodeMsgState(req.LReq, 0, code, message, true)
  92. dutils.StoreDataToRedis(getDybdX003Key(req), string(ret))
  93. } else if err == errors.NoRecord {
  94. dutils.SetAccessLogReqCodeMsgState(req.LReq, 1100, "gd_1100", message, false)
  95. dutils.StoreDataToRedis(getDybdX003Key(req), string(ret))
  96. } else if err == errors.UserTokenExpire{
  97. if !req.TryAgain {
  98. req.TryAgain = true
  99. return DybdX003(req)
  100. }
  101. dutils.SetAccessLogReqCodeMsgState(req.LReq, 1101, code, message, false)
  102. }else {
  103. l.Error("func",
  104. zap.String("call", "DyBdClientPost"),
  105. zap.String("args", utils.MarshalJsonString(req.Params)),
  106. zap.String("error", err.Error()))
  107. dutils.SetAccessLogReqCodeMsgState(req.LReq,1101,code, message, false)
  108. }
  109. return reply, err
  110. }
  111. }