123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- // 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/model"
- dutils "adm-ods/utils"
- "fmt"
- "github.com/tidwall/gjson"
- "strings"
- )
- // SPY 首保日期查询(128-009)
- func ParasOds8(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, "queryByCp").String()
- if cp == "" {
- return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
- }
- code := gjson.Get(responseParams, "respCode").String()
- if code != "0" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- dataMap := make(map[string]string)
- dataMap["cp"] = cp
- if dutils.IsPlate(cp) {
- dataMap["plate_no"] = cp
- } else {
- dataMap["vin"] = cp
- }
- respData := gjson.Get(responseParams, "data").String()
- dataMap["city"] = gjson.Get(respData, "city").String()
- dataMap["district"] = gjson.Get(respData, "district").String()
- dataMap["province"] = gjson.Get(respData, "province").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)
- return ret, nil
- }
- func HandleOnlineOds8(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds8(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods8 := &model.Ods8{}
- ods8.Cp = dataMapList[0]["cp"]
- ods8.Content = msg.Content
- err = ods8.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"cp": ods8.Cp}
- oldOds8 := &model.Ods8{}
- err = oldOds8.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds8(oldOds8.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods8.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
- }
|