1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package utils
- import (
- "adm-data/consts"
- "encoding/json"
- "time"
- )
- func GetYearByVin10(vin10 string) int {
- nowYear := time.Now().Year()
- if v, ok := consts.YearMap[vin10]; ok {
- if v > nowYear {
- year := v - 30
- if year < 2001 {
- return 0
- }
- return year
- } else if v == nowYear {
- return nowYear
- } else {
- return getLastYear(v, nowYear)
- }
- } else {
- return nowYear
- }
- }
- func getLastYear(year, nowYear int) int {
- lastYear := year + 30
- if lastYear > nowYear {
- return year
- } else if lastYear == nowYear {
- return nowYear
- } else {
- return getLastYear(lastYear, nowYear)
- }
- }
- func MarshalJsonString(args ...interface{}) (result string) {
- if len(args) > 0 {
- if r, err := json.Marshal(args); err == nil {
- result = string(r)
- }
- }
- return
- }
|