123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- // 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"
- "strings"
- )
- func dumpOds13() {
- }
- // ZJC 所有人验证(142-001)
- func ParasOds13(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("carno").String()
- plateType := requestParam.Get("plateType").String()
- owner := requestParam.Get("name").String()
- if plateNo == "" || owner == "" {
- return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
- }
- responseParams := data.Get("response_params").String()
- errorCode := gjson.Get(responseParams, "err_code").String()
- if errorCode != "200" {
- return nil, fmt.Errorf("数据异常,没有数据", errorCode)
- }
- respData := gjson.Get(responseParams, "data").String()
- if respData == "" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- detail := gjson.Get(respData, "vehicle_drivers_permit_detailed").String()
- detailCode := gjson.Get(detail, "code").String()
- if detailCode != "9100" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- dataMap := make(map[string]string)
- dataMap["plate_no"] = plateNo
- dataMap["plate_type"] = plateType
- detailData := gjson.Get(detail, "data")
- ownerVerifyResult := detailData.Get("owerState").String()
- dataMap["owner"] = owner
- if ownerVerifyResult == "1" {
- dataMap["is_expire"] = consts.NORMALDATA
- } else {
- dataMap["is_expire"] = consts.EXPIREDATA
- }
- dataMap["brand_name"] = detailData.Get("brandName").String()
- dataMap["use_property"] = detailData.Get("useType").String()
- dataMap["vehicle_body_color"] = detailData.Get("bodyColor").String()
- dataMap["engine_no"] = detailData.Get("engineNumber").String()
- dataMap["vin"] = detailData.Get("frameVIN").String()
- dataMap["compulsory_scrap_to"] = detailData.Get("retirementDate").String()
- dataMap["engine_type"] = detailData.Get("engineType").String()
- dataMap["initial_registration_date"] = detailData.Get("firstIssueDate").String()
- dataMap["inspection_result_effective_to"] = detailData.Get("validityDayEnd").String()
- dataMap["fuel_type"] = detailData.Get("fuelType").String()
- dataMap["state"] = detailData.Get("vehicleStatus").String()
- dataMap["vehicle_type"] = detailData.Get("vehicleType").String()
- dataMap["approved_number"] = detailData.Get("passengers").String()
- dataMap["displacement"] = detailData.Get("displacement").String()
- dataMap["release_date"] = detailData.Get("productionDate").String()
- dataMap["rated_power"] = detailData.Get("maxJourney").String()
- dataMap["axle_number"] = detailData.Get("shaft").String()
- dataMap["wheel_base"] = detailData.Get("wheelBase").String()
- dataMap["front_wheel_distance"] = detailData.Get("frontTread").String()
- dataMap["back_wheel_distance"] = detailData.Get("rearTread").String()
- dataMap["gross_mass"] = detailData.Get("crossWeight").String()
- dataMap["unladen_mass"] = detailData.Get("curbWeight").String()
- dataMap["approved_load"] = detailData.Get("loadWeight").String()
- ret = append(ret, dataMap)
- return ret, nil
- }
- func HandleOnlineOds13(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds13(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods13 := &model.Ods13{}
- ods13.PlateNo = dataMapList[0]["plate_no"]
- ods13.PlateType = dataMapList[0]["plate_type"]
- ods13.Owner = dataMapList[0]["owner"]
- ods13.Content = msg.Content
- err = ods13.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"plate_no": ods13.PlateNo, "plate_type": ods13.PlateType, "owner": ods13.Owner}
- oldOds13 := &model.Ods13{}
- err = oldOds13.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds13(oldOds13.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods13.UpdateWhere(clinit.DB(), where)
- }
- }
- for _, dataMap := range dataMapList {
- if dataMap["is_expire"] == consts.EXPIREDATA {
- delete(dataMap, "owner")
- }
- }
- return dataMapList, nil
- }
|