123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- // 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
- }
|