calc_date.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package utils
  4. import (
  5. "strconv"
  6. "strings"
  7. "time"
  8. )
  9. const LastCompulsoryScrapTo = "2099-12-31 00:00:00"
  10. func compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate string, years int) string {
  11. initialDate := ""
  12. if initialRegistrationDate != "" {
  13. initialDate = initialRegistrationDate
  14. } else {
  15. initialDate = insuranceFirstDate
  16. }
  17. if initialDate == ""{
  18. return ""
  19. }
  20. compulsoryScrapToTime, _ := time.Parse(DayLayout, initialDate[:DataLen])
  21. compulsoryScrapTo := compulsoryScrapToTime.AddDate(years, 0, 0).String()[:DataLen] + " 00:00:00"
  22. return compulsoryScrapTo
  23. }
  24. func getMapValueString(key string,reqMap map[string]interface{}) (string,bool){
  25. if v1, ok := reqMap[key]; ok {
  26. switch v1.(type) {
  27. case string:
  28. return v1.(string),true
  29. }
  30. }else{
  31. return "",false
  32. }
  33. return "",true
  34. }
  35. func getMapValueInt(key string,reqMap map[string]interface{}) int {
  36. if v1, ok := reqMap[key]; ok {
  37. switch v1.(type) {
  38. case string:
  39. v ,_ := strconv.Atoi(v1.(string))
  40. return v
  41. case int:
  42. return v1.(int)
  43. case int16:
  44. return int(v1.(int16))
  45. case int32:
  46. return int(v1.(int32))
  47. case int64:
  48. return int(v1.(int64))
  49. case float64:
  50. return int(v1.(float64))
  51. case float32:
  52. return int(v1.(float32))
  53. }
  54. }
  55. return 0
  56. }
  57. // 车辆报废日期计算
  58. func CalcCompulsoryScrapTo(reqMap map[string]interface{}) {
  59. compulsoryScrapTo,isExist := getMapValueString("compulsory_scrap_to",reqMap)
  60. if !isExist{
  61. return
  62. }
  63. vehicleType,_ := getMapValueString("vehicle_type",reqMap)
  64. initialRegistrationDate,_ := getMapValueString("initial_registration_date",reqMap)
  65. insuranceFirstDate,_ := getMapValueString("insurance_first_date",reqMap)
  66. useProperty,_ := getMapValueString("use_property",reqMap)
  67. approvedNumber := getMapValueInt("approved_number",reqMap)
  68. if compulsoryScrapTo != "" && compulsoryScrapTo != LastCompulsoryScrapTo {
  69. return
  70. }
  71. if vehicleType != "" &&
  72. (initialRegistrationDate != "" ||
  73. insuranceFirstDate != "") {
  74. switch {
  75. case vehicleType >= "H41" && vehicleType <= "H46":
  76. compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 8)
  77. case vehicleType >= "H11" && vehicleType <= "H39":
  78. compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 15)
  79. case vehicleType >= "Q11" && vehicleType <= "Q32":
  80. compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 15)
  81. case vehicleType == "T11" || vehicleType == "X99":
  82. compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 15)
  83. }
  84. if useProperty != "" {
  85. if strings.HasPrefix(vehicleType, "K") {
  86. switch {
  87. case strings.Contains("DGT", useProperty):
  88. if approvedNumber != 0 {
  89. if approvedNumber >= 20 {
  90. compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 12)
  91. } else {
  92. compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 8)
  93. }
  94. }
  95. case strings.Contains("BCFGHKN", useProperty):
  96. compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 15)
  97. case strings.Contains("A", useProperty):
  98. if approvedNumber != 0 {
  99. if approvedNumber > 9 {
  100. compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 20)
  101. }
  102. }
  103. case strings.Contains("E", useProperty):
  104. compulsoryScrapTo = compulsoryScrapToAddYear(initialRegistrationDate,insuranceFirstDate, 20)
  105. }
  106. }
  107. }
  108. }
  109. if compulsoryScrapTo == ""{
  110. compulsoryScrapTo = LastCompulsoryScrapTo
  111. }
  112. reqMap["compulsory_scrap_to"] = compulsoryScrapTo
  113. }