jaryhe 1 year ago
parent
commit
bed3c019a5
2 changed files with 61 additions and 7 deletions
  1. 11 3
      impl/v1/query/A02.go
  2. 50 4
      impl/v1/query/U01.go

+ 11 - 3
impl/v1/query/A02.go

@@ -48,19 +48,27 @@ func A02(ctx context.Context, params string) (reply *apis.QueryResponse, err err
 	}
 
 	if res.PlateType == "" {
-		res.PlateType = calcPlateType(res.Long, res.ApprovedNumber, res.GrossMass)
+		plateType, _ := calcMoto(res.VehicleTypeDetail, res.TyreNumber, res.Displacement, res.RatedPower)
+		if plateType != "" {
+			res.PlateType = plateType
+		} else {
+			res.PlateType = calcPlateType(res.Long, res.ApprovedNumber, res.GrossMass)
+		}
+
 	}
 
 	if req.PlateType != "" {
 		if res.PlateType != "" {
 			if req.PlateType == "01" || req.PlateType == "51" {
-				if res.PlateType == "02" || res.PlateType == "52" {
+				if res.PlateType != "01" && res.PlateType != "51" {
 					return reply, errors.DataNotExistError
 				}
 			} else if req.PlateType == "02" || req.PlateType == "52" {
-				if res.PlateType == "01" || res.PlateType == "51" {
+				if res.PlateType != "02" && res.PlateType != "52" {
 					return reply, errors.DataNotExistError
 				}
+			} else if req.PlateType != res.PlateType {
+				return reply, errors.DataNotExistError
 			}
 		}
 		res.PlateType = req.PlateType

+ 50 - 4
impl/v1/query/U01.go

@@ -16,6 +16,38 @@ import (
 	"git.getensh.com/common/gopkgsv2/database"
 )
 
+func calcMoto(vehicleTypeDetail, tyreNumber, displacement, ratedPower string) (plateType string, vehicleType string) {
+	// 摩托车不处理
+	if vehicleTypeDetail != "" && strings.Contains(vehicleTypeDetail, "摩托") {
+		if vehicleTypeDetail == "两轮轻便摩托车" {
+			vehicleType = "M22"
+			plateType = "08"
+		} else if vehicleTypeDetail == "两轮摩托车" {
+			vehicleType = "M21"
+			plateType = "07"
+		} else {
+			ratedPowerFloat, _ := strconv.ParseFloat(ratedPower, 64)
+			displacementFloat, _ := strconv.ParseFloat(displacement, 64)
+			if tyreNumber == "2" {
+				if ratedPowerFloat <= 4 && displacementFloat <= 50 {
+					vehicleType = "M22"
+					plateType = "08"
+				} else {
+					vehicleType = "M21"
+					plateType = "07"
+				}
+			} else {
+				if ratedPowerFloat <= 4 && displacementFloat <= 50 {
+					plateType = "08"
+				} else {
+					plateType = "07"
+				}
+			}
+		}
+	}
+	return plateType, vehicleType
+}
+
 func getString(key string, old map[string]interface{}) string {
 	if v, ok := old[key]; ok {
 		switch v.(type) {
@@ -66,10 +98,24 @@ func supplementPlateTypeByCalc(old map[string]interface{}) {
 		switch v.(type) {
 		case string:
 			if v.(string) == "" {
-				longStr := getString("long", old)
-				approvedNumberStr := getString("approved_number", old)
-				grossMassStr := getString("gross_mass", old)
-				old["plate_type"] = calcPlateType(longStr, approvedNumberStr, grossMassStr)
+				vehicleTypeDetail := getString("vehicle_type_detail", old)
+				tyreNumber := getString("tyre_number", old)
+				displacement := getString("displacement", old)
+				ratedPower := getString("rated_power", old)
+
+				plateType, vehicleType := calcMoto(vehicleTypeDetail, tyreNumber, displacement, ratedPower)
+				if plateType != "" {
+					old["plate_type"] = plateType
+					if _, ok1 := old["vehicle_type"]; ok1 {
+						old["vehicle_type"] = vehicleType
+					}
+
+				} else {
+					longStr := getString("long", old)
+					approvedNumberStr := getString("approved_number", old)
+					grossMassStr := getString("gross_mass", old)
+					old["plate_type"] = calcPlateType(longStr, approvedNumberStr, grossMassStr)
+				}
 			}
 		}
 	}