1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- // 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"
- "fmt"
- "github.com/tidwall/gjson"
- "strings"
- )
- // SPY 二要素验证(新能源)(128-008)
- func ParasOds10(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- requestParams := data.Get("request_params").String()
- responseParams := data.Get("response_params").String()
- plateNo := gjson.Get(requestParams, "cp").String()
- owner := gjson.Get(requestParams, "name").String()
- code := gjson.Get(responseParams, "respCode").String()
- if code != "0" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- if plateNo == "" || owner == "" {
- return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
- }
- dataMap := make(map[string]string)
- dataMap["plate_no"] = plateNo
- dataMap["owner"] = owner
- respData := gjson.Get(responseParams, "data").String()
- isMatch := gjson.Get(respData, "isMatch").Bool()
- if isMatch {
- ret = append(ret, dataMap)
- return ret, nil
- } else {
- return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
- }
- /*if isMatch {
- dataMap["is_expire"] = consts.NORMALDATA
- }else{
- dataMap["is_expire"] = consts.EXPIREDATA
- }
- ret = append(ret, dataMap)
- return ret, nil*/
- }
- func HandleOnlineOds10(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds10(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods10 := &model.Ods10{}
- ods10.PlateNo = dataMapList[0]["plate_no"]
- ods10.Owner = dataMapList[0]["owner"]
- ods10.Content = msg.Content
- err = ods10.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"plate_no": ods10.PlateNo, "owner": ods10.Owner}
- oldOds10 := &model.Ods10{}
- err = oldOds10.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds10(oldOds10.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods10.UpdateWhere(clinit.DB(), where)
- }
- }
- /*for _, dataMap := range dataMapList {
- dwsMsg := dutils.NewDwsMessage(msg)
- dwsMsg.Content = utils.MarshalJsonString(dataMap)
- ret = append(ret, dwsMsg)
- }*/
- return dataMapList, nil
- }
|