123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- // 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/model"
- "fmt"
- "strings"
- "gadm-ods/common.in/clinit"
- "github.com/tidwall/gjson"
- )
- // spy 两日期查询128-004,128-006
- func ParasOds6(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- requestParams := data.Get("request_params").String()
- responseParams := data.Get("response_params").String()
- cp := gjson.Get(requestParams, "cp").String()
- if cp == "" {
- return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
- }
- code := gjson.Get(responseParams, "respCode").String()
- if code != "0" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- stateCode := gjson.Get(responseParams, "data.stateCode").String()
- if stateCode == "0" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- dataArray := gjson.Get(responseParams, "data").Array()
- if len(dataArray) == 0 {
- dataMap := make(map[string]string)
- dataMap["cp"] = cp
- respData := gjson.Get(responseParams, "data").String()
- dataMap["plate_no"] = gjson.Get(respData, "cp").String()
- dataMap["vin"] = gjson.Get(respData, "vin").String()
- dataMap["last_compulsory_insurance_date"] = gjson.Get(respData, "insuranceMonth").String()
- dataMap["insurance_first_date"] = gjson.Get(respData, "registerDate").String()
- dataMap["use_property_detail"] = gjson.Get(respData, "usage").String()
- ret = append(ret, dataMap)
- }else{
- for _,v := range dataArray{
- dataMap := make(map[string]string)
- dataMap["cp"] = cp
- dataMap["plate_no"] = v.Get("cp").String()
- dataMap["vin"] = v.Get("vin").String()
- dataMap["last_compulsory_insurance_date"] = v.Get("insuranceMonth").String()
- dataMap["insurance_first_date"] = v.Get("registerDate").String()
- dataMap["use_property_detail"] = v.Get("usage").String()
- dataMap["city"] = v.Get( "city").String()
- dataMap["province"] = v.Get( "province").String()
- ret = append(ret, dataMap)
- }
- }
- return ret, nil
- }
- func HandleOnlineOds6(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds6(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods6 := &model.Ods6{}
- ods6.Code = dataMapList[0]["cp"]
- if ods6.Code == "" {
- fmt.Println("主键值为空")
- return nil, nil
- }
- ods6.Content = msg.Content
- err = ods6.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"code": ods6.Code}
- oldOds6 := &model.Ods6{}
- err = oldOds6.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds6(oldOds6.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods6.UpdateWhere(clinit.DB(), where)
- }
- }
- for _, dataMap := range dataMapList {
- delete(dataMap, "cp")
- //dwsMsg := dutils.NewDwsMessage(msg)
- //dwsMsg.Content = utils.MarshalJsonString(dataMap)
- //ret = append(ret, dwsMsg)
- }
- return dataMapList, nil
- }
|