package dybd import ( "gd_service/apis" "gd_service/common.in/config" "gd_service/consts" "gd_service/errors" "gd_service/thirdparty" dutils "gd_service/utils" "time" "github.com/astaxie/beego/orm" "gd_service/common.in/utils" "go.uber.org/zap" "github.com/tidwall/gjson" ) func GetDybdX002Data(rdata string, respMap map[string]string) { arr := gjson.Parse(rdata).Array() for _, v := range arr { respMap["name"] = v.Get("xm").String() //respMap[""] = gjson.Get(rdata,"car_detail.reg_date").String() respMap["level"] = v.Get("cc").String() // 层次 专科,本科 respMap["major"] = v.Get("zymc").String() //专业名称 respMap["university"] = v.Get("yxmc").String() //毕业学校名称 respMap["end_year"] = v.Get( "byrq").String() //毕业日期 respMap["start_year"] = v.Get( "rxrq").String() //入学日期 respMap["form"] = v.Get( "xxxs").String() //学习形式 普通全日制 } } func getDybdX002Key(req *apis.ThirdpartRequest) string { key := consts.DybdX002Pre + req.Params[consts.DyBdX002P1] + req.Params[consts.DyBdX002P2] return key } func paramDybdX002Data(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 { return result, nil } } else if code == 401{ return "" ,errors.UserTokenExpire }else { return "", errors.VendorError } } func DybdX002Local(req *apis.ThirdpartRequest) (reply string, err error) { reply, err = dutils.GetDataByRedis(getDybdX002Key(req), int64(req.Req.ReuseTime), paramDybdX002Data) return reply, err } func StoreX002DataToMysql(rData map[string]string,resData string) { x002Data := apis.DybdX002Data{} name := rData[consts.DyBdX002P2] educationId := rData[consts.DyBdX002P1] o := orm.NewOrm() err := o.Raw("select * from t_gd_dybd_x002_data where education_id = ? and name=?",educationId,name).QueryRow(&x002Data) if err == nil{ return } x002Data.Name = name x002Data.EducationId = educationId x002Data.Data = resData x002Data.Timestamp = time.Now().Unix() o.Insert(&x002Data) } func DybdX002(req *apis.ThirdpartRequest) (reply string, err error) { //req.LReq.Search = req.Params[consts.DyBdX002P1] //owner := req.Params["owner"] /*req.Params["qqfyyId"] = "test" req.Params["qqfyymc"] = "test" req.Params["qqrId"] = "test" req.Params["qqr"] = "test"*/ redisKey := "dybd:xltoken:" token,err := getDybdToken(req.TryAgain,req.ProviderInfo.Timeout,config.Conf.ThirdPart.DybdXlAppkey,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 = paramDybdX002Data(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(getDybdX002Key(req), string(ret)) //go StoreX002DataToMysql(req.Params,reply) } else if err == errors.NoRecord { dutils.SetAccessLogReqCodeMsgState(req.LReq, 1100, "gd_1100", message, false) dutils.StoreDataToRedis(getDybdX002Key(req), string(ret)) } else if err == errors.UserTokenExpire{ if !req.TryAgain { req.TryAgain = true return DybdX002(req) } err = errors.VendorError 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 } }