// Copyright 2019 autocareai.com. All rights reserved. // Use of this source code is governed by autocareai.com. package analysis import ( "gadm-ods/apis" "gadm-ods/common.in/clinit" "gadm-ods/model" "fmt" "github.com/tidwall/gjson" "strings" ) // SPY 过户车查询(VIN)(128-007) func ParasOds9(content string) (ret []map[string]string, err error) { data := gjson.Parse(content) requestParams := data.Get("request_params").String() responseParams := data.Get("response_params").String() vin := gjson.Get(requestParams, "vin").String() code := gjson.Get(responseParams, "respCode").String() if code != "0" { return nil, fmt.Errorf("数据异常,没有数据") } if vin == "" { return nil, fmt.Errorf("数据异常,车牌姓名不匹配") } dataMap := make(map[string]string) dataMap["vin"] = vin respData := gjson.Get(responseParams, "data").String() dataMap["engine_no"] = gjson.Get(respData, "fdjh").String() if vin == "" { dataMap["vin"] = gjson.Get(respData, "vin").String() } //dataMap["insurance_first_date"] = gjson.Get(respData, "registerDate").String() dataMap["insurance_first_date"] = gjson.Get(respData, "registerDate").String() ret = append(ret, dataMap) return ret, nil } func HandleOnlineOds9(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) { dataMapList, err = ParasOds9(msg.Content) if err != nil { // 解析不出来数据直接返回 return nil, nil } if len(dataMapList) == 0 { return nil, nil } // 入本地库 ods9 := &model.Ods9{} ods9.Vin = dataMapList[0]["vin"] ods9.Content = msg.Content err = ods9.Insert(clinit.DB()) if err != nil { if !strings.Contains(err.Error(), "Duplicate") { return nil, err } else { where := map[string]interface{}{"vin": ods9.Vin} oldOds9 := &model.Ods9{} err = oldOds9.Query(clinit.DB(), where) if err == nil { oldDataMapList, _ := ParasOds9(oldOds9.Content) if checkDataMapListEqual(oldDataMapList, dataMapList) { return nil, nil } } ods9.UpdateWhere(clinit.DB(), where) } } /*for _, dataMap := range dataMapList { dwsMsg := dutils.NewDwsMessage(msg) dwsMsg.Content = utils.MarshalJsonString(dataMap) ret = append(ret, dwsMsg) }*/ return dataMapList, nil }