123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724 |
- package query
- import (
- "context"
- "encoding/json"
- "fmt"
- "gd_adm_data/apis"
- "gd_adm_data/errors"
- "gd_adm_data/model"
- "gd_adm_data/utils"
- "git.getensh.com/common/gopkgsv2/database"
- "strconv"
- "strings"
- "time"
- jsoniter "github.com/json-iterator/go"
- )
- // 计算最后投保日期
- func calcLatestInsuredate(reqMap map[string]interface{}) {
- retLen := utils.MonthLen
- firstInsuranceDate := ""
- lastCompulsoryInsuranceDate := ""
- if v, ok := reqMap["first_insurance_date"]; ok {
- firstInsuranceDate = v.(string)
- }
- if v, ok := reqMap["last_compulsory_insurance_date"]; ok {
- lastCompulsoryInsuranceDate = v.(string)
- }
- if firstInsuranceDate == "" && lastCompulsoryInsuranceDate == "" {
- return
- }
- latestInsuranceDateStart := ""
- lastCompulsoryInsuranceDate = strings.TrimSpace(lastCompulsoryInsuranceDate)
- firstInsuranceDate = strings.TrimSpace(firstInsuranceDate)
- if lastCompulsoryInsuranceDate == "" {
- return
- } else if firstInsuranceDate == "" {
- latestInsuranceDateStart = lastCompulsoryInsuranceDate
- } else if len(lastCompulsoryInsuranceDate) < utils.MonthLen ||
- len(firstInsuranceDate) < utils.MonthLen {
- return
- } else if lastCompulsoryInsuranceDate[utils.MonthLen-2:utils.MonthLen] == firstInsuranceDate[utils.MonthLen-2:utils.MonthLen] {
- if len(firstInsuranceDate) == utils.DataLen {
- latestInsuranceDateStart = lastCompulsoryInsuranceDate + firstInsuranceDate[7:]
- retLen = utils.DataLen
- } else {
- latestInsuranceDateStart = lastCompulsoryInsuranceDate
- }
- } else {
- latestInsuranceDateStart = lastCompulsoryInsuranceDate
- }
- latestInsuranceDateStart = strings.TrimSpace(latestInsuranceDateStart)
- if len(latestInsuranceDateStart) > utils.DataLen {
- latestInsuranceDateStart = latestInsuranceDateStart[:utils.DataLen]
- } else if len(latestInsuranceDateStart) == utils.MonthLen {
- latestInsuranceDateStart = latestInsuranceDateStart + "-01"
- }
- latestInsuranceDateStartTime, _ := time.Parse(utils.DayLayout, latestInsuranceDateStart)
- latestInsuranceDateEnd := latestInsuranceDateStartTime.AddDate(1, 0, 0).String()[:retLen]
- reqMap["latest_insurance_date_end"] = latestInsuranceDateEnd
- reqMap["latest_nsurance_date_start"] = latestInsuranceDateStart
- }
- func FormatApprovedNumber(in string) string {
- in = FormatNormal(in)
- in = getApprovedNumberStr(in)
- return in
- }
- 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 RatedPower(in)
- //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] = FormatApprovedNumber(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 formatVehicleType(reqMap map[string]interface{}) {
- if v, ok := reqMap["vehicle_type"]; ok {
- if _, ok = v.(string); ok && v.(string) == "" {
- vehicleTypeDetail := getString("vehicle_type_detail", reqMap)
- longStr := getString("long", reqMap)
- approvedNumberStr := getString("approved_number", reqMap)
- grossMassStr := getString("gross_mass", reqMap)
- displacementStr := getString("displacement", reqMap)
- long, _ := strconv.Atoi(longStr)
- approvedNumber, _ := strconv.Atoi(approvedNumberStr)
- grossMass, _ := strconv.Atoi(grossMassStr)
- displacement, _ := strconv.Atoi(displacementStr)
- reqMap["vehicle_type"] = utils.CalcVehicleType(vehicleTypeDetail, long, approvedNumber, displacement, grossMass)
- //reqMap["vehicle_type"] = "xxxx"
- //reqMap["emission_standard"] = utils.EmissionStandard(v.(string))
- }
- }
- }
- func formatYearMonth(m map[string]interface{}, s string) {
- if v, ok := m[s]; ok {
- if _, ok = v.(string); ok && v.(string) != "" {
- if len(v.(string)) > utils.MonthLen {
- m[s] = v.(string)[0:utils.MonthLen]
- }
- }
- }
- }
- func formatDate(m map[string]interface{}, s string) {
- if v, ok := m[s]; ok {
- if _, ok = v.(string); ok && v.(string) != "" {
- m[s] = utils.FormatDate(v.(string))
- }
- }
- }
- func formatDataCode(m map[string]interface{}, s, t string, f func(string) (string, string)) {
- if v, ok := m[s]; ok {
- if _, ok = v.(string); ok && v.(string) == "" {
- if v, ok = m[t]; ok {
- if _, ok = v.(string); ok && v.(string) != "" {
- m[s], _ = f(v.(string))
- return
- }
- }
- }
- }
- if v, ok := m[t]; ok {
- if _, ok = v.(string); ok && v.(string) == "" {
- if v, ok = m[s]; ok {
- if _, ok = v.(string); ok && v.(string) != "" {
- m[t], _ = f(v.(string))
- return
- }
- }
- }
- }
- }
- func formatEmissionStandard(reqMap map[string]interface{}) {
- if v, ok := reqMap["emission_standard"]; ok {
- if _, ok = v.(string); ok && v.(string) != "" {
- reqMap["emission_standard"] = utils.EmissionStandard(v.(string))
- }
- }
- }
- func formatDisplacement(reqMap map[string]interface{}) {
- if v, ok := reqMap["displacement"]; ok {
- var (
- temp int
- )
- switch v.(type) {
- case string:
- temp, _ = strconv.Atoi(v.(string))
- case float64:
- temp = int(v.(float64))
- case int64:
- temp = int(v.(int64))
- }
- if temp > 100000 {
- temp /= 1000
- switch v.(type) {
- case string:
- reqMap["displacement"] = strconv.Itoa(temp)
- case float64:
- reqMap["displacement"] = float64(temp)
- case int64:
- reqMap["displacement"] = int64(temp)
- }
- }
- if temp > 0 {
- if l, ok := reqMap["displacement_l"]; ok {
- if _, ok = l.(string); ok && l.(string) == "" {
- reqMap["displacement_l"] = strconv.FormatFloat(float64(temp)/float64(1000), 'f', 1, 64)
- }
- }
- }
- }
- if v, ok := reqMap["displacement_l"]; ok {
- if _, ok = v.(string); ok && v.(string) != "" {
- tmp := strings.Replace(v.(string), "L", "", -1)
- tmp = strings.Replace(tmp, "T", "", -1)
- displacementL, _ := strconv.ParseFloat(tmp, 64)
- if displacementL > 100 {
- reqMap["displacement_l"] = strconv.FormatFloat(float64(displacementL)/float64(1000), 'f', 1, 64)
- }
- if l, ok := reqMap["displacement"]; ok {
- var (
- temp int
- )
- switch l.(type) {
- case string:
- temp, _ = strconv.Atoi(l.(string))
- case float64:
- temp = int(l.(float64))
- case int64:
- temp = int(l.(int64))
- }
- if temp == 0 {
- if displacementL > 100 {
- temp = int(displacementL)
- } else {
- temp = int(displacementL * float64(1000))
- }
- switch l.(type) {
- case string:
- reqMap["displacement"] = strconv.Itoa(temp)
- case float64:
- reqMap["displacement"] = float64(temp)
- case int64:
- reqMap["displacement"] = int64(temp)
- }
- }
- }
- }
- }
- }
- func formatBrand(reqMap map[string]interface{}) {
- if v, ok := reqMap["brand_name"]; ok {
- if _, ok = v.(string); ok && v.(string) != "" {
- if ads22, err := model.NewAds22Model().Get(database.DB().Where("source = ? and type = 6", v)); err == nil {
- if ads22.Standard != "" {
- //reqMap["brand_id"] = ads22.Standard
- ads2, err := model.NewDws20Model().Get(database.DB().Where("brand_id = ?", ads22.Standard))
- if err == nil {
- reqMap["brand_name"] = ads2.BrandName
- reqMap["brand_id"] = ads22.Standard
- } else {
- reqMap["brand_name"] = ads22.Standard
- }
- } else {
- if ads2, err := model.NewDws20Model().Get(database.DB().Where("brand_name = ?", v)); err == nil {
- reqMap["brand_name"] = ads2.BrandName
- if ads2.BrandId != "" {
- reqMap["brand_id"] = ads2.BrandId
- }
- }
- }
- } else {
- if ads2, err := model.NewDws20Model().Get(database.DB().Where("brand_name = ?", v)); err == nil {
- reqMap["brand_name"] = ads2.BrandName
- if ads2.BrandId != "" {
- reqMap["brand_id"] = ads2.BrandId
- }
- }
- }
- }
- }
- }
- func formatData(reqMap map[string]interface{}) {
- // 补充初等
- //supplementRegisterDate(reqMap)
- // 格式化日期
- formatDate(reqMap, "initial_registration_date")
- formatDate(reqMap, "inspection_result_effective_to")
- formatDate(reqMap, "release_date")
- formatDate(reqMap, "insurance_first_date")
- formatDate(reqMap, "compulsory_scrap_to")
- formatYearMonth(reqMap, "last_compulsory_insurance_date")
- calcLatestInsuredate(reqMap)
- // 格式化数据编码
- formatDataCode(reqMap, "use_property", "use_property_detail", utils.ParseProperty)
- fmt.Println("user property :", reqMap["use_property"], reqMap["use_property"])
- formatDataCode(reqMap, "fuel_type", "fuel_type_detail", utils.ParseFuel)
- formatDataCode(reqMap, "vehicle_type", "vehicle_type_detail", utils.VehicleType)
- formatDataCode(reqMap, "vehicle_body_color", "vehicle_body_color_detail", utils.ParseColor)
- formatDataCode(reqMap, "body_color", "body_color_detail", utils.ParseColor)
- formatVehicleType(reqMap)
- // 格式化排放标准
- formatEmissionStandard(reqMap)
- // 格式化排量
- formatDisplacement(reqMap)
- // 格式化品牌
- 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)
- // 计算年检到期时间
- utils.CalcAnnualExamExpireTime(reqMap)
- }
- // 格式化数据
- func F01(ctx context.Context, params string) (reply *apis.QueryResponse, err error) {
- reply = &apis.QueryResponse{}
- reply.Data = params
- reqMap := make(map[string]interface{})
- err = json.Unmarshal([]byte(params), &reqMap)
- if err != nil {
- return reply, errors.ParamsError
- }
- // 格式化数据
- formatData(reqMap)
- reply.Data, _ = jsoniter.MarshalToString(reqMap)
- return reply, nil
- }
|