123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- // 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"
- "go.uber.org/zap"
- "strings"
- )
- // ZQY 车牌查车档119-001
- func ParasOds2(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("数据异常,没有数据")
- }
- plateNo := requestArray[0].Get("cph").String()
- if plateNo == "" {
- return nil, fmt.Errorf("数据异常,车牌号为空")
- }
- state := gjson.Get(responseParams, "ok").String()
- if state != "1" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- responseArray := gjson.Get(responseParams, "ds").Array()
- fmt.Println("")
- for _, v := range responseArray {
- dataMap := make(map[string]string)
- dataMap["plate_no"] = plateNo
- dataMap["vin"] = v.Get("车辆识别代码").String()
- dataMap["brand_name"] = v.Get("品牌").String()
- //dataMap["vehicle_type_detail"] = v.Get("车辆名称").String()
- dataMap["model_no"] = v.Get("车辆型号").String()
- dataMap["use_property_detail"] = v.Get("使用性质").String()
- dataMap["insurance_first_date"] = v.Get("初次登记时间").String()
- dataMap["fuel_type_detail"] = v.Get("燃料种类").String()
- dataMap["displacement"] = v.Get("排量").String()
- dataMap["engine_type"] = v.Get("发动机型号").String()
- dataMap["approved_number"] = v.Get("额定载客").String()
- dataMap["vehicle_body_color_detail"] = v.Get("车身颜色").String()
- dataMap["release_date"] = v.Get("出厂日期").String()
- dataMap["axle_number"] = v.Get("轴数").String()
- dataMap["wheel_base"] = v.Get("轴距").String()
- dataMap["front_wheel_distance"] = v.Get("前轮距").String()
- dataMap["back_wheel_distance"] = v.Get("后轮距").String()
- dataMap["gross_mass"] = v.Get("总质量").String()
- dataMap["unladen_mass"] = v.Get("整备质量").String()
- dataMap["approved_load"] = v.Get("额定载质量").String()
- dataMap["rated_power"] = v.Get("功率").String()
- //dataMap["plate_no"] = v.Get("CPH").String()
- dataMap["last_compulsory_insurance_date"] = v.Get("承保日期").String()
- dataMap["engine_no"] = v.Get("发动机号").String()
- dataMap["oil_wear"] = v.Get("油耗").String()
- dataMap["long"] = v.Get("长").String()
- dataMap["wide"] = v.Get("宽").String()
- dataMap["high"] = v.Get("高").String()
- dataMap["emission_standard"] = v.Get("排放标准").String()
- dataMap["tyre_number"] = v.Get("轮胎数").String()
- // TODO 拆分为前后轮胎规格
- dataMap["tyre_size"] = v.Get("轮胎规格").String()
- //dataMap["front_wheel_specification"] = dataMap["tyre_size"]
- //dataMap["back_wheel_specification"] = dataMap["tyre_size"]
- dataMap["axle_weight"] = v.Get("轴荷").String()
- dataMap["style_name"] = v.Get("车型").String()
- ret = append(ret, dataMap)
- }
- dataMapLen := len(ret)
- if dataMapLen == 0 {
- l.Error("func",
- zap.String("call", "ParasOds2"),
- zap.String("args", content),
- zap.String("error", "数据异常,无法解析"))
- return nil, fmt.Errorf("数据异常")
- } else {
- if dataMapLen > 1 {
- return sortByDate(ret), nil
- }
- return ret, nil
- }
- }
- func HandleOnlineOds2(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds2(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods2 := &model.Ods2{}
- ods2.PlateNo = dataMapList[0]["plate_no"]
- ods2.Content = msg.Content
- err = ods2.Save(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"plate_no": ods2.PlateNo}
- oldOds2 := &model.Ods2{}
- err = oldOds2.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds2(oldOds2.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods2.UpdateWhere(clinit.DB(), where)
- }
- }
- /*for _, dataMap := range dataMapList {
- dwsMsg := dutils.NewDwsMessage(msg)
- dwsMsg.Content = utils.MarshalJsonString(dataMap)
- ret = append(ret, dwsMsg)
- }*/
- return dataMapList, nil
- }
|