12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- // 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/consts"
- "adm-ods/model"
- "fmt"
- "github.com/tidwall/gjson"
- "go.uber.org/zap"
- "strings"
- )
- // CXY 违章查询
- func ParasOds1(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- rawCode := data.Get("raw_code").String()
- dataMap := make(map[string]string)
- if rawCode == "0" || rawCode == "-6" {
- arrayStr := data.Get("request_params").String()
- array := gjson.Parse(arrayStr).Array()
- if len(array) < 2 {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- requestParams := array[1]
- dataMap["plate_no"] = requestParams.Get("carnumber").String()
- dataMap["plate_type"] = requestParams.Get("cartype").String()
- dataMap["vin"] = requestParams.Get("carcode").String()
- dataMap["engine_no"] = requestParams.Get("cardrivenumber").String()
- if rawCode == "0" {
- dataMap["is_expire"] = consts.NORMALDATA
- } else {
- dataMap["is_expire"] = consts.EXPIREDATA
- }
- return append(ret, dataMap), nil
- }
- l.Error("func",
- zap.String("call", "ParasOds2"),
- zap.String("args", content),
- zap.String("error", "数据异常,无法解析"))
- return nil, fmt.Errorf("数据异常")
- }
- func HandleOnlineOds1(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds1(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 如本地库
- ods1 := &model.Ods1{}
- ods1.Vin = dataMapList[0]["vin"]
- ods1.PlateType = dataMapList[0]["plate_type"]
- ods1.PlateNo = dataMapList[0]["plate_no"]
- ods1.EngineNo = dataMapList[0]["engine_no"]
- ods1.Content = msg.Content
- err = ods1.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- // 如果存在判断是否字段相等
- where := map[string]interface{}{"vin": ods1.Vin, "plate_no": ods1.PlateNo, "plate_type": ods1.PlateType, "engine_no": ods1.EngineNo}
- oldOds1 := &model.Ods1{}
- err = oldOds1.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds1(oldOds1.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods1.UpdateWhere(clinit.DB(), where)
- }
- }
- // 构建消息
- /*for _, dataMap := range dataMapList {
- dwsMsg := dutils.NewDwsMessage(msg)
- dwsMsg.Content = utils.MarshalJsonString(dataMap)
- ret = append(ret, dwsMsg)
- }*/
- return dataMapList, nil
- }
|