123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- package dybd
- import (
- "gd_service/apis"
- "gd_service/common.in/config"
- "gd_service/common.in/utils"
- "gd_service/consts"
- "gd_service/errors"
- "gd_service/thirdparty"
- dutils "gd_service/utils"
- "go.uber.org/zap"
- "github.com/tidwall/gjson"
- )
- func GetDybdX003Data(rdata string,) []map[string]string{
- arr := gjson.Parse(rdata).Array()
- ret := []map[string]string{}
- for _, v := range arr {
- respMap := make(map[string]string)
- respMap["is_double_first_class_university"] = v.Get("isDoubleFirstClassUniversity").String() // 是否为双一流学校
- respMap["is_two_one_one_university"] = v.Get("isTwoOneOneUniversity").String() // 是否为211学校
- respMap["end_date"] = v.Get("endDate").String() // 毕业日期
- respMap["type_name"] = v.Get("typeName").String() // 研究类型
- respMap["edu_code"] = v.Get("eduCode").String() // 学校代码
- respMap["qualification_code"] = v.Get( "qualificationCode").String() // 教育类别代码
- respMap["major_category"] = v.Get( "majorCategory").String() // 专业名称
- respMap["edu_name"] = v.Get( "eduName").String() // 学校名
- respMap["qualification_name"] = v.Get( "qualificationName").String() // 教育类别
- respMap["type_code"] = v.Get( "typeCode").String() // 研究类型代码
- respMap["secondary_category"] = v.Get( "secondaryCategory").String() // 二级学科名称
- respMap["begin_date"] = v.Get( "beginDate").String() // 注册日期
- respMap["major_code"] = v.Get( "majorCode").String() // 专业代码
- respMap["is_nine_eight_five_university"] = v.Get( "isNineEightFiveUniversity").String() // 是否为985学校
- ret = append(ret,respMap)
- }
- return ret
- }
- func getDybdX003Key(req *apis.ThirdpartRequest) string {
- key := consts.DybdX003Pre + req.Params[consts.DyBdX003P1] + req.Params[consts.DyBdX003P2]
- return key
- }
- func paramDybdX003Data(ret string) (reply string, err error) {
- code := gjson.Get(ret, "code").Int()
- if code == 200 {
- result := gjson.Get(ret, "data").String()
- arr := gjson.Parse(result).Array()
- if len(arr) <= 0 {
- return result, errors.NoRecord
- } else {
- if arr[0].Get( "eduName").String() == "" {
- return result, errors.NoRecord
- }
- // 学校名
- return result, nil
- }
- } else if code == 300{
- return "" ,errors.UserTokenExpire
- }else {
- return "", errors.VendorError
- }
- }
- func DybdX003Local(req *apis.ThirdpartRequest) (reply string, err error) {
- reply, err = dutils.GetDataByRedis(getDybdX003Key(req), int64(req.Req.ReuseTime), paramDybdX003Data)
- return reply, err
- }
- func DybdX003(req *apis.ThirdpartRequest) (reply string, err error) {
- redisKey := "dybd:xlalltoken:"
- token,err := getDybdToken(req.TryAgain,req.ProviderInfo.Timeout,config.Conf.ThirdPart.DybdXlAllAppkey,redisKey)
- if err != nil{
- l.Error("thridPart",
- zap.String("call", "getDybdToken"),
- zap.String("args",utils.MarshalJsonString(req.Params)),
- zap.String("error", err.Error()))
- req.LReq.ResponseParams = err.Error()
- dutils.SetAccessLogReqCodeMsgState(req.LReq, 1101, "gd_1101", err.Error(), false)
- return "",errors.VendorError
- }
- ret, err := thirdparty.DyBdClientPost(req.ProviderInfo.ThirdpartHost+"/"+req.ProviderInfo.ThirdpartApiRouter, req.Params, req.ProviderInfo.Timeout,token)
- if err != nil {
- l.Error("func",
- zap.String("call", "DyBdClientPost"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- req.LReq.ResponseParams = err.Error()
- dutils.SetAccessLogReqCodeMsgState(req.LReq, 1101, "gd_1101", "三方错误,请求失败", false)
- return "", errors.VendorError
- } else {
- req.LReq.ResponseParams = string(ret)
- reply, err = paramDybdX003Data(string(ret))
- code := gjson.GetBytes(ret, "code").String()
- message := gjson.GetBytes(ret, "message").String()
- if err == nil {
- dutils.SetAccessLogReqCodeMsgState(req.LReq, 0, code, message, true)
- dutils.StoreDataToRedis(getDybdX003Key(req), string(ret))
- } else if err == errors.NoRecord {
- dutils.SetAccessLogReqCodeMsgState(req.LReq, 1100, "gd_1100", message, false)
- dutils.StoreDataToRedis(getDybdX003Key(req), string(ret))
- } else if err == errors.UserTokenExpire{
- if !req.TryAgain {
- req.TryAgain = true
- return DybdX003(req)
- }
- dutils.SetAccessLogReqCodeMsgState(req.LReq, 1101, code, message, false)
- }else {
- l.Error("func",
- zap.String("call", "DyBdClientPost"),
- zap.String("args", utils.MarshalJsonString(req.Params)),
- zap.String("error", err.Error()))
- dutils.SetAccessLogReqCodeMsgState(req.LReq,1101,code, message, false)
- }
- return reply, err
- }
- }
|