123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- // Copyright 2019 autocareai.com. All rights reserved.
- // Use of this source code is governed by autocareai.com.
- package analysis
- import (
- "fmt"
- "gadm-ods/apis"
- "gadm-ods/common.in/clinit"
- "gadm-ods/model"
- "gadm-ods/utils"
- "github.com/tidwall/gjson"
- "strings"
- )
- // cdbd 二要素
- func ParasOds2(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- //rawCode := data.Get("raw_code").String()
- requestParams := data.Get("request_params").String()
- responseParams := data.Get("response_params").String()
- if requestParams == "" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- idCard := gjson.Get(requestParams,"id_card").String()
- plateNum := gjson.Get(requestParams,"plate_num").String()
- plateNo := "川"+plateNum
- dataMap := make(map[string]string)
- dataMap["plate_no"] = plateNo
- dataMap["id_card"] = idCard
- code := gjson.Get(responseParams, "code").Int()
- if code == 200 {
- result := gjson.Get(responseParams, "result").String()
- rdata, err := utils.SM4ECBBase64Decrypt(result)
- if err != nil {
- fmt.Println("SM4ECBBase64Decrypt error:", err)
- return nil, fmt.Errorf("数据异常,解密失败")
- }
- isMatch := gjson.Get(rdata,"match_result").String()
- if isMatch == "1"{
- dataMap["state"] = gjson.Get(rdata,"car_detail.car_state").String()
- //dataMap[""] = gjson.Get(rdata,"car_detail.reg_date").String()
- dataMap["brand_name"] = gjson.Get(rdata,"car_detail.model_name").String()
- dataMap["model_no"] = gjson.Get(rdata,"car_detail.model_type").String()
- dataMap["vehicle_type"] = gjson.Get(rdata,"car_detail.vehicle_type").String()
- dataMap["vin"] = gjson.Get(rdata,"car_detail.vin").String()
- dataMap["initial_registration_date"] = gjson.Get(rdata,"car_detail.initial_reg_date").String()
- }else{
- return nil, fmt.Errorf("数据异常,不匹配")
- }
- } else{
- return nil, fmt.Errorf("数据异常,无记录")
- }
- ret = append(ret, dataMap)
- return ret, nil
- }
- func HandleOnlineOds2(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds2(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods2 := &model.Ods2{}
- ods2.PlateNo = dataMapList[0]["plate_no"]
- ods2.IdCard = dataMapList[0]["id_card"]
- ods2.Content = msg.Content
- err = ods2.Save(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"plate_no": ods2.PlateNo,"id_card":ods2.IdCard}
- oldOds2 := &model.Ods2{}
- err = oldOds2.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds2(oldOds2.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods2.UpdateWhere(clinit.DB(), where)
- }
- }
- /*for _, dataMap := range dataMapList {
- dwsMsg := dutils.NewDwsMessage(msg)
- dwsMsg.Content = utils.MarshalJsonString(dataMap)
- ret = append(ret, dwsMsg)
- }*/
- return dataMapList, nil
- }
|