123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package analysis
- import (
- "adm-ods/apis"
- "adm-ods/common.in/clinit"
- "adm-ods/consts"
- "adm-ods/model"
- "fmt"
- "github.com/tidwall/gjson"
- "strings"
- )
- // spy 过户车记录查询128-010
- func ParasOds7(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()
- if vin == "" {
- return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
- }
- code := gjson.Get(responseParams, "respCode").String()
- if code != "0" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- lastTransTime := int64(0)
- lastPlate := ""
- respData := gjson.Get(responseParams, "data").Array()
- for _, v := range respData {
- dataMap := make(map[string]string)
- //record.TransferNumber = v.Get("transTime").Int()
- //record.TransferAge = v.Get("carYear").String()
- //record.NewPlateNo = v.Get("newCp").String()
- transTime := v.Get("transTime").Int()
- dataMap["vin"] = vin
- dataMap["plate_no"] = v.Get("oldCp").String()
- if transTime > lastTransTime {
- lastPlate = v.Get("newCp").String()
- lastTransTime = transTime
- }
- insuranceDate := v.Get("changeMonth").String()
- if len(insuranceDate) >= 6 {
- insuranceDate = insuranceDate[0:4] + "-" + insuranceDate[4:]
- }
- dataMap["insurance_date"] = insuranceDate
- dataMap["is_expire"] = consts.EXPIREDATA
- //record.TransferDate = v.Get("changeMonth").String()
- //record.TransferAgeMonth = v.Get("carMonth").String()
- ret = append(ret, dataMap)
- }
- if lastPlate != "" {
- dataMap := make(map[string]string)
- dataMap["vin"] = vin
- dataMap["plate_no"] = lastPlate
- dataMap["is_expire"] = consts.NORMALDATA
- ret = append(ret, dataMap)
- }
- return ret, nil
- }
- func HandleOnlineOds7(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds7(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods7 := &model.Ods7{}
- ods7.Vin = dataMapList[0]["vin"]
- ods7.Content = msg.Content
- err = ods7.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"vin": ods7.Vin}
- oldOds7 := &model.Ods7{}
- err = oldOds7.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds7(oldOds7.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods7.UpdateWhere(clinit.DB(), where)
- }
- }
- /*for _, dataMap := range dataMapList {
- dwsMsg := dutils.NewDwsMessage(msg)
- dwsMsg.Content = utils.MarshalJsonString(dataMap)
- ret = append(ret, dwsMsg)
- }*/
- return dataMapList, nil
- }
|