Explorar el Código

update format

jaryhe hace 1 año
padre
commit
ec5ee34253
Se han modificado 3 ficheros con 511 adiciones y 0 borrados
  1. 391 0
      impl/v1/query/F01.go
  2. 21 0
      impl/v1/query/U01.go
  3. 99 0
      utils/standard.go

+ 391 - 0
impl/v1/query/F01.go

@@ -3,9 +3,11 @@ package query
 import (
 	"context"
 	"encoding/json"
+	"fmt"
 	"gd_adm_data/apis"
 	"gd_adm_data/errors"
 	"gd_adm_data/utils"
+	"strconv"
 	"strings"
 	"time"
 
@@ -67,6 +69,395 @@ func calcLatestInsuredate(reqMap map[string]interface{}) {
 	reqMap["latest_nsurance_date_start"] = latestInsuranceDateStart
 }
 
+func FormatNormal(in string) string {
+	in = strings.TrimSpace(in)
+	in = strings.TrimLeft(in, "-")
+	in = strings.TrimLeft(in, ".")
+	in = strings.TrimLeft(in, "/")
+	in = strings.TrimLeft(in, "&")
+	in = strings.TrimLeft(in, ",")
+	in = strings.Replace(in, `"`, "", -1)
+	if strings.Contains(in, "月") {
+		return ""
+	}
+	switch in {
+	case "―":
+		return ""
+		/*case "99999":
+			return ""
+		case "999999":
+			return ""
+		case "9999999":
+			return ""
+		case "99999999":
+			return ""*/
+	case "00976867":
+		return ""
+	case "02":
+		return "2"
+	case "04":
+		return "4"
+	case "06":
+		return "6"
+	case "07":
+		return "7"
+	case "08":
+		return "8"
+	case "09":
+		return "9"
+	case "未":
+		return ""
+	case "无":
+		return ""
+	case "未知":
+		return ""
+	case "N/A":
+		return ""
+	case "*ANQ":
+		return "ANQ"
+	case "/AYJ":
+		return "AYJ"
+	case "----":
+		return ""
+	case "---":
+		return ""
+	case "######":
+		return ""
+	case "***":
+		return ""
+	case "****":
+		return ""
+	case "**/":
+		return ""
+	case "....":
+		return ""
+	case ".00":
+		return ""
+	case "0.1*":
+		return ""
+	case "00":
+		return ""
+	case "000":
+		return ""
+	case "0000":
+		return ""
+	case "00000":
+		return ""
+	case "000000":
+		return ""
+	case "0000000":
+		return ""
+	case "+":
+		return ""
+	case "+G4E":
+		return "G4E"
+	case "0.0":
+		return ""
+	case "0":
+		return ""
+	case "-1":
+		return ""
+	case "?":
+		return ""
+	case "-":
+		return ""
+	case "--":
+		return ""
+	case ".":
+		return ""
+	case "..":
+		return ""
+	case "...":
+		return ""
+	case "/":
+		return ""
+	case "#":
+		return ""
+	case "##":
+		return ""
+	case "*":
+		return ""
+	case "**":
+		return ""
+	case "__":
+		return ""
+	case "null":
+		return ""
+	case "/8":
+		return "8"
+	case "#NAME?":
+		return ""
+	case "1.4/44KW 5G":
+		return ""
+	case "1.6":
+		return ""
+	case "1.6AT":
+		return ""
+	case "1.8":
+		return ""
+	case "1.8AT":
+		return ""
+	case "1.8T":
+		return ""
+	case "1.8TAT":
+		return ""
+	case "100":
+		return ""
+	case "100-2.2E":
+		return ""
+	case "100-2.6E":
+		return ""
+	case "1598CC":
+		return ""
+	case "1984CC":
+		return ""
+	case "1984CC小轿车":
+		return ""
+	case "1997CC":
+		return ""
+	}
+	in = strings.Replace(in, ` `, "", -1)
+
+	return in
+}
+
+// 发动机型号
+func FormatEngineType(in string) string {
+	if in == "" {
+		return in
+	}
+	in = strings.TrimSpace(in)
+	in = strings.Replace(in, `,`, "", -1)
+	in = strings.Replace(in, `+`, "", -1)
+	in = strings.Replace(in, `*`, "", -1)
+	//in = strings.Replace(in,`.`,"",-1)
+	//in = strings.TrimLeft(in,"-")
+	//in = strings.TrimLeft(in,"-")
+	//in = strings.TrimLeft(in,"/")
+
+	return FormatNormal(in)
+}
+
+// 轴荷
+func FormatAxleWeight(in string) string {
+	if in == "" {
+		return ""
+	}
+	in = strings.Replace(in, `"`, "", -1)
+	in = strings.Replace(in, `-/`, "", -1)
+	return FormatNormal(in)
+}
+
+//轮胎数
+func FormatTyreNum(tyreNum string) string {
+	if tyreNum == "" {
+		return ""
+	}
+	if strings.Contains(tyreNum, "AM") || strings.Contains(tyreNum, "月") || strings.Contains(tyreNum, "R") {
+		return ""
+	}
+
+	tyreNum = strings.Replace(tyreNum, "]", "", -1)
+
+	return FormatNormal(tyreNum)
+}
+
+// 轴数
+func FormatAxleNumber(axleNumber string) string {
+	if axleNumber == "" {
+		return axleNumber
+	}
+
+	switch axleNumber {
+	case "2月4日":
+		return "2线4轴"
+	case "2轴":
+		return "2"
+	case "3轴":
+		return "3"
+	case "4轴":
+		return "4"
+	case "5轴":
+		return "5"
+	case "三线六轴":
+		return "3线6轴"
+	case "三轴":
+		return "3"
+	case "两线四轴":
+		return "2线4轴"
+	case "二线四轴":
+		return "2线4轴"
+	case "-":
+		return ""
+	case "-1":
+		return ""
+	}
+
+	axleNumber = strings.Replace(axleNumber, `"`, "", -1)
+	axleNumber = strings.Replace(axleNumber, `,`, "", -1)
+
+	return axleNumber
+}
+
+// 轮胎规格
+func FormatTyreSize(tyreSize string) string {
+	if tyreSize == "" {
+		return ""
+	}
+
+	tyreSize = strings.Replace(tyreSize, `"`, "", -1)
+	tyreSize = strings.Replace(tyreSize, `第1轴:`, "第1轴", -1)
+	tyreSize = strings.Replace(tyreSize, `第2轴:`, "第2轴", -1)
+	tyreSize = strings.Replace(tyreSize, `;第2轴`, "第2轴", -1)
+	tyreSize = strings.Replace(tyreSize, `第一轴`, "第1轴", -1)
+	tyreSize = strings.Replace(tyreSize, `第二轴`, "第2轴", -1)
+	tyreSize = strings.Replace(tyreSize, `前`, "第1轴", -1)
+	tyreSize = strings.Replace(tyreSize, `后`, "第2轴", -1)
+	tyreSize = strings.Replace(tyreSize, ` `, "", -1)
+	return tyreSize
+}
+func FormatOilWear(oilWear string) string {
+	if oilWear == "" {
+		return ""
+	}
+	// 截断
+	oilWear = strings.Split(oilWear, "L")[0]
+	oilWear = strings.Split(oilWear, "(")[0]
+	oilWear = strings.Split(oilWear, "&")[0]
+	oilWear = strings.Split(oilWear, "R")[0]
+	oilWear = strings.Split(oilWear, "(")[0]
+
+	// 去掉空格
+	oilWear = strings.Replace(oilWear, "小于等于", "", -1)
+	oilWear = strings.Replace(oilWear, " ", "", -1)
+
+	if oilWear == "" {
+		return ""
+	}
+
+	num, err := strconv.ParseFloat(oilWear, 10)
+	if err != nil {
+		return ""
+	}
+
+	if num == 0 {
+		return ""
+	}
+
+	if num > 200 {
+		return ""
+	}
+
+	return fmt.Sprintf("%.2f", num)
+}
+func FormatRatedPower(in string) string {
+	num, err := strconv.ParseFloat(in, 10)
+	if err != nil {
+		return in
+	}
+
+	if num == 0 {
+		return ""
+	}
+
+	return fmt.Sprintf("%.1f", num)
+}
+func FormatLongWideHigh(in string) string {
+	if in == "" {
+		return in
+	}
+	inList := strings.Split(in, ",")
+	for _, v := range inList {
+		if v == "0" {
+			continue
+		} else {
+			return v
+		}
+	}
+	return in
+}
+func FormatField(reqMap map[string]interface{}, key string) {
+	if v, ok := reqMap[key]; ok {
+		if _, ok = v.(string); ok && v.(string) != "" {
+			switch key {
+			case "engine_type":
+				reqMap[key] = FormatEngineType(v.(string))
+			case "axle_weight":
+				reqMap[key] = FormatAxleWeight(v.(string))
+			case "tyre_number":
+				reqMap[key] = FormatTyreNum(v.(string))
+			case "axle_number":
+				reqMap[key] = FormatAxleNumber(v.(string))
+			case "tyre_size":
+				reqMap[key] = FormatTyreSize(v.(string))
+			case "oil_wear":
+				reqMap[key] = FormatOilWear(v.(string))
+			case "rated_power":
+				reqMap[key] = FormatRatedPower(v.(string))
+			case "traction_mass":
+				tmp := FormatNormal(v.(string))
+				reqMap[key] = FormatLongWideHigh(tmp)
+			case "front_wheel_distance":
+				tmp := FormatNormal(v.(string))
+				reqMap[key] = FormatLongWideHigh(tmp)
+			case "back_wheel_distance":
+				tmp := FormatNormal(v.(string))
+				reqMap[key] = FormatLongWideHigh(tmp)
+			case "gross_mass":
+				tmp := FormatNormal(v.(string))
+				reqMap[key] = FormatLongWideHigh(tmp)
+			case "unladen_mass":
+				tmp := FormatNormal(v.(string))
+				reqMap[key] = FormatLongWideHigh(tmp)
+			case "approved_load":
+				tmp := FormatNormal(v.(string))
+				reqMap[key] = FormatLongWideHigh(tmp)
+			case "wheel_base":
+				wheelBase := FormatNormal(v.(string))
+				reqMap[key] = FormatLongWideHigh(wheelBase)
+			case "long":
+				reqMap[key] = FormatLongWideHigh(v.(string))
+			case "wide":
+				reqMap[key] = FormatLongWideHigh(v.(string))
+			case "high":
+				reqMap[key] = FormatLongWideHigh(v.(string))
+			case "approved_number":
+				reqMap[key] = FormatNormal(v.(string))
+			case "displacement":
+				reqMap[key] = FormatNormal(v.(string))
+			case "displacement_l":
+				reqMap[key] = FormatNormal(v.(string))
+			case "engine_no":
+				reqMap[key] = FormatNormal(v.(string))
+			}
+		}
+	}
+}
+
+func DisplacementTol(displacementml string) string {
+	tmp, err := strconv.Atoi(displacementml)
+	if err != nil {
+		return displacementml
+	}
+
+	if tmp == 0 {
+		return displacementml
+	}
+
+	left := tmp % 100
+
+	if left >= 50 {
+		tmp = tmp / 100
+		tmp = tmp * 100
+		tmp = tmp + 100
+	} else {
+		tmp = tmp / 100
+		tmp = tmp * 100
+	}
+	r := float64(tmp) / float64(1000)
+	return fmt.Sprintf("%.1f", r)
+}
+
 // 格式化数据
 func F01(ctx context.Context, params string) (reply *apis.QueryResponse, err error) {
 	reply = &apis.QueryResponse{}

+ 21 - 0
impl/v1/query/U01.go

@@ -640,6 +640,27 @@ func formatData(reqMap map[string]interface{}) {
 	// 格式化品牌
 	formatBrand(reqMap)
 
+	FormatField(reqMap, "engine_type")
+	FormatField(reqMap, "axle_weight")
+	FormatField(reqMap, "tyre_number")
+	FormatField(reqMap, "axle_number")
+	FormatField(reqMap, "tyre_size")
+	FormatField(reqMap, "oil_wear")
+	FormatField(reqMap, "rated_power")
+	FormatField(reqMap, "traction_mass")
+	FormatField(reqMap, "front_wheel_distance")
+	FormatField(reqMap, "back_wheel_distance")
+	FormatField(reqMap, "gross_mass")
+	FormatField(reqMap, "unladen_mass")
+	FormatField(reqMap, "approved_load")
+	FormatField(reqMap, "wheel_base")
+	FormatField(reqMap, "long")
+	FormatField(reqMap, "wide")
+	FormatField(reqMap, "high")
+	FormatField(reqMap, "approved_number")
+	FormatField(reqMap, "displacement")
+	FormatField(reqMap, "displacement_l")
+	FormatField(reqMap, "engine_no")
 	// 计算强制报废日期
 	utils.CalcCompulsoryScrapTo(reqMap)
 	// 计算年检到期时间

+ 99 - 0
utils/standard.go

@@ -307,6 +307,76 @@ func calcEmissionStandard(s string) string {
 
 func EmissionStandard(s string) string {
 	reload()
+
+	switch s {
+	case "":
+		return ""
+	case "见其它":
+		return ""
+	case "美国加洲排放认证证书":
+		return ""
+	case "N/A":
+		return ""
+	case "-":
+		return ""
+	case "--":
+		return ""
+	case "0":
+		return ""
+	case "未知":
+		return ""
+	case "不适用":
+		return ""
+	case "/":
+		return ""
+	case "无":
+		return ""
+	case "#N/A":
+		return ""
+	case "﹣":
+		return ""
+	case "—":
+		return ""
+	case "梅赛德斯-奔驰(中国)汽车销售有限公司":
+		return ""
+	case "汽油":
+		return ""
+	case "WAUGFEF50KA084988":
+		return ""
+	case "WAUGFEF50KA086174":
+		return ""
+	case "CNCA-02C-024:2008":
+		return ""
+	case "DWS135B1315111100":
+		return ""
+	case "EV":
+		return "EV"
+	case "98/69/EC":
+		return "欧四"
+	case "1":
+		return ""
+	case "EUROⅡ":
+		return "欧二"
+	case "欧洲1":
+		return "欧一"
+	case "欧5":
+		return "欧五"
+	case "欧IV":
+		return "欧四"
+	case "欧V":
+		return "欧五"
+	case "欧六":
+		return "欧六"
+	case " 欧IV":
+		return "欧四"
+	case "欧洲III号":
+		return "欧三"
+	}
+
+	if v, ok := std.emissionStandard[s]; ok {
+		return "国" + v
+	}
+
 	s = strings.Replace(s, " ", "", -1)
 	a := strings.Split(s, "国")
 	if len(a) == 1 {
@@ -343,6 +413,35 @@ func EmissionStandard(s string) string {
 		}
 	}
 
+	if strings.Contains(s, "ⅠⅠⅠ") || strings.Contains(s, "III") || strings.Contains(s, "Ⅲ") || strings.Contains(s, "国3") {
+		return "国三"
+	} else if strings.Contains(s, "ⅠⅤ") || strings.Contains(s, "Ⅳ") || strings.Contains(s, "IV") ||
+		strings.Contains(s, "ⅠV") || strings.Contains(s, "国4") {
+		return "国四"
+	} else if strings.Contains(s, "ⅤⅠ") || strings.Contains(s, "VI") || strings.Contains(s, "VⅠ") ||
+		strings.Contains(s, "Ⅵ") || strings.Contains(s, "国6") {
+		return "国六"
+	} else if strings.Contains(s, "ⅠⅠ") || strings.Contains(s, "II") || strings.Contains(s, "国2") || strings.Contains(s, "Ⅱ") {
+		return "国二" // 欧标2  欧洲2 欧洲1  欧2
+	} else if strings.Contains(s, "Ⅰ") || strings.Contains(s, "I") || strings.Contains(s, "国1") {
+		return "国一"
+	} else if strings.Contains(s, "Ⅴ") || strings.Contains(s, "V") || strings.Contains(s, "V") || strings.Contains(s, "国5") {
+		return "国五"
+	} else if strings.Contains(s, "GB18352.6-2016") {
+		return "国六"
+	} else if strings.Contains(s, "8352.2-2001") || strings.Contains(s, "18352.2-2001") || strings.Contains(s, "GB-18352.2-2001") || strings.Contains(s, "GB18352.2-2001") {
+		return "国二"
+	} else if strings.Contains(s, "GB14762-2008") || strings.Contains(s, "GB14622-2016") || strings.Contains(s, "GB17691-2005") {
+		return "国四"
+	} else if strings.Contains(s, "GB18352.5-20013") || strings.Contains(s, "GB18352.5-2013") ||
+		strings.Contains(s, "GB18352.52013") || strings.Contains(s, "GB18352.5-2014") || strings.Contains(s, "GB18352.5-2015") {
+		return "国五"
+	} else if strings.Contains(s, "GB18352.6-2016") {
+		return "国六"
+	} else if strings.Contains(s, "18352.3-2005") || strings.Contains(s, "GB3847-2005") {
+		return "国三"
+	}
+
 	if v, ok := std.emissionStandard[condition]; ok {
 		return "国" + v
 	}