123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- // 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"
- "go.uber.org/zap"
- "strings"
- )
- // ZQY 两日期查询119-005
- func ParasOds4(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- //rawCode := data.Get("raw_code").String()
- requestParams := data.Get("request_params").String()
- responseParams := data.Get("response_params").String()
- requestArray := gjson.Parse(requestParams).Array()
- if len(requestArray) < 1 {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- code := requestArray[0].Get("code").String()
- if code == "" {
- return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
- }
- state := gjson.Get(responseParams, "ok").String()
- if state != "1" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- responseArray := gjson.Get(responseParams, "ds").Array()
- for _, v := range responseArray {
- dataMap := make(map[string]string)
- dataMap["code"] = code
- if dutils.IsPlate(code) {
- dataMap["plate_no"] = code
- } else {
- dataMap["vin"] = code
- }
- if dataMap["vin"] == "" {
- dataMap["vin"] = v.Get("vin").String()
- }
- //dataMap["vin"] = v.Get("vin").String()
- dataMap["insurance_first_date"] = v.Get("register_date").String()
- dataMap["last_compulsory_insurance_date"] = v.Get("year_date").String()
- ret = append(ret, dataMap)
- }
- dataMapLen := len(ret)
- // TODO 排序
- if dataMapLen == 0 {
- l.Error("func",
- zap.String("call", "ParasOds3"),
- zap.String("args", content),
- zap.String("error", "数据异常,无法解析"))
- return nil, fmt.Errorf("数据异常")
- } else {
- if dataMapLen > 1 {
- return sortByDate(ret), nil
- }
- return ret, nil
- }
- }
- func HandleOnlineOds4(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds4(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods4 := &model.Ods4{}
- ods4.Code = dataMapList[0]["code"]
- ods4.Content = msg.Content
- err = ods4.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- // 如果存在判断是否字段相等
- where := map[string]interface{}{"code": ods4.Code}
- oldOds4 := &model.Ods4{}
- err = oldOds4.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds4(oldOds4.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods4.UpdateWhere(clinit.DB(), where)
- }
- }
- for _, dataMap := range dataMapList {
- delete(dataMap, "code")
- //dwsMsg := dutils.NewDwsMessage(msg)
- //dwsMsg.Content = utils.MarshalJsonString(dataMap)
- //ret = append(ret, dwsMsg)
- }
- return dataMapList, nil
- }
|