123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- // 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"
- )
- func ConvertPlateType(s string) (plateColor string, exist bool) {
- plateTypeMap := map[string]string{
- "1": "01",
- "0": "02",
- "5": "51",
- "4": "52",
- }
- if v, ok := plateTypeMap[s]; ok {
- return v, true
- }
- return
- }
- // ZCRK 姓名车牌号核查(河南)(141-001)
- func ParasOds12(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]
- responseParams := data.Get("response_params").String()
- code := gjson.Get(responseParams, "code").String()
- if code != "0" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- result := gjson.Get(responseParams, "result").String()
- consistent := gjson.Get(result, "consistent").Bool()
- if !consistent {
- return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
- }
- plateNo := requestParam.Get("plateNo").String()
- plateType := requestParam.Get("plateType").String()
- if plateType == "" {
- plateColor := requestParam.Get("plateColor").String()
- if plateColor != "" {
- plateType, _ = ConvertPlateType(plateColor)
- }
- }
- owner := requestParam.Get("name").String()
- 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 HandleOnlineOds12(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds12(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods12 := &model.Ods12{}
- ods12.PlateNo = dataMapList[0]["plate_no"]
- ods12.PlateType = dataMapList[0]["plate_type"]
- ods12.Owner = dataMapList[0]["owner"]
- ods12.Content = msg.Content
- err = ods12.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"plate_no": ods12.PlateNo, "plate_type": ods12.PlateType, "owner": ods12.Owner}
- oldOds12 := &model.Ods12{}
- err = oldOds12.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds12(oldOds12.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods12.UpdateWhere(clinit.DB(), where)
- }
- }
- /*for _, dataMap := range dataMapList {
- dwsMsg := dutils.NewDwsMessage(msg)
- dwsMsg.Content = utils.MarshalJsonString(dataMap)
- ret = append(ret, dwsMsg)
- }*/
- return dataMapList, nil
- }
|