// 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" ) func ParasOds18(content string) (ret []map[string]string, err error) { data := gjson.Parse(content) requestParams := data.Get("request_params").String() requestParamsArray := gjson.Parse(requestParams).Array() if len(requestParamsArray) < 1 { return nil, fmt.Errorf("数据异常,没有数据") } requestParam := requestParamsArray[0] responseParams := data.Get("response_params").String() code := gjson.Get(responseParams, "code").String() if code != "0" { return nil, fmt.Errorf("数据异常,没有数据") } result := gjson.Get(responseParams, "result").String() engineNo := gjson.Get(result, "engine_number").String() vin := requestParam.Get("vin").String() if vin == "" || engineNo == "" { return nil, fmt.Errorf("数据异常") } dataMap := make(map[string]string) dataMap["vin"] = vin dataMap["engine_no"] = engineNo ret = append(ret, dataMap) return ret, nil } // ZCRK vin 查发动机号(141-003) func HandleOnlineOds18(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) { dataMapList, err = ParasOds18(msg.Content) if err != nil { // 解析不出来数据直接返回 return nil, nil } if len(dataMapList) == 0 { return nil, nil } // 入本地库 ods18 := &model.Ods18{} ods18.Vin = dataMapList[0]["vin"] ods18.Content = msg.Content err = ods18.Insert(clinit.DB()) if err != nil { if !strings.Contains(err.Error(), "Duplicate") { return nil, err } else { where := map[string]interface{}{"vin": ods18.Vin} oldOds18 := &model.Ods18{} err = oldOds18.Query(clinit.DB(), where) if err == nil { oldDataMapList, _ := ParasOds18(oldOds18.Content) if checkDataMapListEqual(oldDataMapList, dataMapList) { return nil, nil } } ods18.UpdateWhere(clinit.DB(), where) } } return dataMapList, nil }