123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- // 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/common.in/clinit"
- "gadm-ods/model"
- "fmt"
- "github.com/tidwall/gjson"
- "strings"
- )
- // DRV 车牌姓名验证(138-002)
- func ParasOds11(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- requestParams := data.Get("request_params").String()
- requestParamsArray := gjson.Parse(requestParams).Array()
- if len(requestParamsArray) < 1 {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- requestParam := requestParamsArray[0]
- plateNo := requestParam.Get("plateNumber").String()
- plateType := requestParam.Get("plateType").String()
- owner := requestParam.Get("name").String()
- responseParams := data.Get("response_params").String()
- respData := gjson.Get(responseParams, "data").String()
- if respData == "0" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- verifyData := gjson.Parse(respData).Get("data").String()
- msg := gjson.Parse(respData).Get("msg").String()
- if verifyData != "1" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- // 0为一致
- if msg != "0" {
- return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
- }
- if plateNo == "" || plateType == "" || owner == "" {
- return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
- }
- dataMap := make(map[string]string)
- dataMap["plate_no"] = plateNo
- dataMap["plate_type"] = plateType
- dataMap["owner"] = owner
- ret = append(ret, dataMap)
- return ret, nil
- }
- func HandleOnlineOds11(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds11(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods11 := &model.Ods11{}
- ods11.PlateNo = dataMapList[0]["plate_no"]
- ods11.PlateType = dataMapList[0]["plate_type"]
- ods11.Owner = dataMapList[0]["owner"]
- ods11.Content = msg.Content
- err = ods11.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"plate_no": ods11.PlateNo, "plate_type": ods11.PlateType, "owner": ods11.Owner}
- oldOds11 := &model.Ods11{}
- err = oldOds11.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds11(oldOds11.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods11.UpdateWhere(clinit.DB(), where)
- }
- }
- /*for _, dataMap := range dataMapList {
- dwsMsg := dutils.NewDwsMessage(msg)
- dwsMsg.Content = utils.MarshalJsonString(dataMap)
- ret = append(ret, dwsMsg)
- }*/
- return dataMapList, nil
- }
|