// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. package utils import ( "strconv" "strings" "time" ) const LastCompulsoryScrapTo = "2099-12-31 00:00:00" func compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate string, years int) string { initialDate := "" if initialRegistrationDate != "" { initialDate = initialRegistrationDate } else { initialDate = insuranceFirstDate } if initialDate == ""{ return "" } compulsoryScrapToTime, _ := time.Parse(DayLayout, initialDate[:DataLen]) compulsoryScrapTo := compulsoryScrapToTime.AddDate(years, 0, 0).String()[:DataLen] + " 00:00:00" return compulsoryScrapTo } func getMapValueString(key string,reqMap map[string]interface{}) (string,bool){ if v1, ok := reqMap[key]; ok { switch v1.(type) { case string: return v1.(string),true } }else{ return "",false } return "",true } func getMapValueInt(key string,reqMap map[string]interface{}) int { if v1, ok := reqMap[key]; ok { switch v1.(type) { case string: v ,_ := strconv.Atoi(v1.(string)) return v case int: return v1.(int) case int16: return int(v1.(int16)) case int32: return int(v1.(int32)) case int64: return int(v1.(int64)) case float64: return int(v1.(float64)) case float32: return int(v1.(float32)) } } return 0 } // 车辆报废日期计算 func CalcCompulsoryScrapTo(reqMap map[string]interface{}) { compulsoryScrapTo,isExist := getMapValueString("compulsory_scrap_to",reqMap) if !isExist{ return } vehicleType,_ := getMapValueString("vehicle_type",reqMap) initialRegistrationDate,_ := getMapValueString("initial_registration_date",reqMap) insuranceFirstDate,_ := getMapValueString("insurance_first_date",reqMap) useProperty,_ := getMapValueString("use_property",reqMap) approvedNumber := getMapValueInt("approved_number",reqMap) if compulsoryScrapTo != "" && compulsoryScrapTo != LastCompulsoryScrapTo { return } if vehicleType != "" && (initialRegistrationDate != "" || insuranceFirstDate != "") { switch { case vehicleType >= "H41" && vehicleType <= "H46": compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 8) case vehicleType >= "H11" && vehicleType <= "H39": compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 15) case vehicleType >= "Q11" && vehicleType <= "Q32": compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 15) case vehicleType == "T11" || vehicleType == "X99": compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 15) } if useProperty != "" { if strings.HasPrefix(vehicleType, "K") { switch { case strings.Contains("DGT", useProperty): if approvedNumber != 0 { if approvedNumber >= 20 { compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 12) } else { compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 8) } } case strings.Contains("BCFGHKN", useProperty): compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 15) case strings.Contains("A", useProperty): if approvedNumber != 0 { if approvedNumber > 9 { compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 20) } } case strings.Contains("E", useProperty): compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 20) } } } } if compulsoryScrapTo == ""{ compulsoryScrapTo = LastCompulsoryScrapTo } reqMap["compulsory_scrap_to"] = compulsoryScrapTo }