1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- // Copyright 204 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 ParasOds4(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()
- plateNo := requestParam.Get("vinOrPlateNumber").String()
- if plateNo == ""{
- return nil, fmt.Errorf("数据异常")
- }
- dataMap := make(map[string]string)
- dataMap["plate_no"] = plateNo
- code := gjson.Get(responseParams, "code").String()
- if code != "0"{
- return nil , fmt.Errorf("数据异常,code不为0")
- }
- rdata := gjson.Get(responseParams, "data").String()
- dataMap["engine_type"] = gjson.Get(rdata, "fdjxh").String()
- dataMap["engine_no"] = gjson.Get(rdata, "fdjh").String()
- dataMap["model_no"] = gjson.Get(rdata, "clxh").String()
- dataMap["vin"] = gjson.Get(rdata, "vin").String()
- dataMap["initial_registration_date"] = gjson.Get(rdata, "registerDate").String()
- dataMap["brand_name"] = gjson.Get(rdata, "brand").String()
- ret = append(ret, dataMap)
- return ret, nil
- }
- // ZR 车牌查车五项或者vin
- func HandleOnlineOds4(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds4(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods4 := &model.Ods4{}
- ods4.PlateNo = dataMapList[0]["plate_no"]
- //ods4.PlateType = dataMapList[0]["plate_type"]
- //ods4.Owner = dataMapList[0]["owner"]
- ods4.Content = msg.Content
- err = ods4.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"plate_no": ods4.PlateNo}
- oldOds4 := &model.Ods4{}
- err = oldOds4.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds4(oldOds4.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods4.UpdateWhere(clinit.DB(), where)
- }
- }
- return dataMapList, nil
- }
|