utils.go 782 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package utils
  2. import (
  3. "encoding/json"
  4. "gd_adm_data/consts"
  5. "time"
  6. )
  7. func GetYearByVin10(vin10 string) int {
  8. nowYear := time.Now().Year()
  9. if v, ok := consts.YearMap[vin10]; ok {
  10. if v > nowYear {
  11. year := v - 30
  12. if year < 2001 {
  13. return 0
  14. }
  15. return year
  16. } else if v == nowYear {
  17. return nowYear
  18. } else {
  19. return getLastYear(v, nowYear)
  20. }
  21. } else {
  22. return nowYear
  23. }
  24. }
  25. func getLastYear(year, nowYear int) int {
  26. lastYear := year + 30
  27. if lastYear > nowYear {
  28. return year
  29. } else if lastYear == nowYear {
  30. return nowYear
  31. } else {
  32. return getLastYear(lastYear, nowYear)
  33. }
  34. }
  35. func MarshalJsonString(args ...interface{}) (result string) {
  36. if len(args) > 0 {
  37. if r, err := json.Marshal(args); err == nil {
  38. result = string(r)
  39. }
  40. }
  41. return
  42. }