123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package utils
- import (
- "adm-data/errors"
- "strings"
- "fmt"
- "time"
- )
- const (
- //营运载客汽车5年以内每年检验1次;超过5年的,每6个月检验1次
- rule1 = iota
- //载货汽车和大型、中型非营运载客汽车10年以内每年检验1次;超过10年的,每6个月检验1次
- rule2
- //小型、微型非营运载客汽车6年以内每2年检验1次;超过6年的,每年检验1次;超过15年的,每6个月检验1次
- rule3
- //摩托车4年以内每2年检验1次;超过4年的,每年检验1次
- rule4
- //拖拉机和其他机动车每年检验1次
- rule5
- //校车每半年检验1次
- rule6
- //非营运轿车、非营运小型和微型载客汽车6年免检 6年以内每2年免上线检验1次,超过6年的,每年检验1次;超过15年的,每6个月检验1次
- rule7
- )
- /*
- rule1:营运载客汽车5年以内每年检验1次;超过5年的,每6个月检验1次
- rule2:载货汽车和大型、中型非营运载客汽车10年以内每年检验1次;超过10年的,每6个月检验1次
- rule3:小型、微型非营运载客汽车6年以内每2年检验1次;超过6年的,每年检验1次;超过15年的,每6个月检验1次
- rule4:摩托车4年以内每2年检验1次;超过4年的,每年检验1次
- rule5:拖拉机和其他机动车每年检验1次
- rule6:校车每半年检验1次
- rule7:非营运轿车、非营运小型和微型载客汽车6年免检 6年以内每2年免上线检验1次,超过6年的,每年检验1次;超过15年的,每6个月检验1次
- */
- type AnnualExamDetail struct {
- Desc string `json:"desc"` //车龄+几年年检+ 1次
- NumYear int64 `json:"num"` //第几年
- }
- type ItemTime struct {
- Date string `json:"date"` //时间
- Day int64 `json:"day"` //还剩多少天
- }
- type GetAnnualInspectionTimeInfo struct {
- TimeRemain string `json:"time_remain" description:"年检到期剩余时间"`
- TimeDate string `json:"time_date" description:"年检到期时间"`
- Rule string `json:"rule" description:"年检规则"`
- TimeYear string `json:"time_year" description:"第几年"`
- CanBeUncheck bool `json:"can_be_uncheck" description:"是否可免检年审"`
- CanBeInspection bool `json:"can_be_inspection" description:"是否到达年审时间"`
- }
- //获取月份的天数
- func DayCount(year int, month int) (days int) {
- if month != 2 {
- if month == 4 || month == 6 || month == 9 || month == 11 {
- days = 30
- } else {
- days = 31
- }
- } else {
- if ((year%4) == 0 && (year%100) != 0) || (year%400) == 0 {
- days = 29
- } else {
- days = 28
- }
- }
- return days
- }
- //计算 start 到 end 还有多少天
- func DeltaTimeByDay(start time.Time, end time.Time) int64 {
- sub := start.Truncate(24 * time.Hour).Sub(end.Truncate(24 * time.Hour))
- return int64(sub.Hours() / 24)
- }
- //营运载客汽车
- func CalcAnnualExamTimeOperation(nowTime time.Time, cdrqTime time.Time, examTime int64, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- var item ItemTime
- var detail AnnualExamDetail
- // 年检时间
- annualExamString := ""
- var annualExamYear int64 = 0
- annualExamDesc := ""
- if examTime != 0 {
- tempTime := time.Unix(examTime/1000, 0)
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), tempTime.Month(), DayCount(int(tempTime.Year()), int(tempTime.Month())))
- } else {
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), cdrqTime.Month(), DayCount(int(cdrqTime.Year()), int(cdrqTime.Month())))
- }
- annualExamTime, err := time.Parse("2006-01-02", annualExamString)
- if err != nil {
- return item, detail, errors.TimeCalcFailed
- }
- for i := 0; i < 5; i++ {
- annualExamYear += 1
- annualExamTime = annualExamTime.AddDate(1, 0, 0)
- annualExamDesc = "5年车龄1年年检1次"
- if annualExamTime.After(nowTime) {
- if isExpire {
- annualExamTime = annualExamTime.AddDate(-1, 0, 0)
- }
- goto CALCANNUALEXAMTIME
- }
- }
- for i := 0; i < 30; i++ {
- if i%2 == 0 {
- annualExamYear += 1
- }
- annualExamTime = annualExamTime.AddDate(0, 6, 0)
- annualExamDesc = "5年以上车龄每6个月年检1次"
- if annualExamTime.After(nowTime) {
- if isExpire {
- annualExamTime = annualExamTime.AddDate(0, -6, 0)
- }
- goto CALCANNUALEXAMTIME
- }
- }
- CALCANNUALEXAMTIME:
- item.Date = annualExamTime.Format("2006-01-02 15:04:05")
- item.Day = DeltaTimeByDay(annualExamTime, nowTime)
- detail.NumYear = annualExamYear
- detail.Desc = annualExamDesc
- return item, detail, nil
- }
- //载货汽车和大型、中型非营运载客汽车10年以内每年检验1次;超过10年的每6个月检验1次
- func CalcAnnualExamTimeBigVehicle(nowTime time.Time, cdrqTime time.Time, examTime int64, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- var item ItemTime
- var detail AnnualExamDetail
- // 年检时间
- annualExamString := ""
- var annualExamYear int64 = 0
- annualExamDesc := ""
- if examTime != 0 {
- tempTime := time.Unix(examTime/1000, 0)
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), tempTime.Month(), DayCount(int(tempTime.Year()), int(tempTime.Month())))
- } else {
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), cdrqTime.Month(), DayCount(int(cdrqTime.Year()), int(cdrqTime.Month())))
- }
- annualExamTime, err := time.Parse("2006-01-02", annualExamString)
- if err != nil {
- return item, detail, errors.TimeCalcFailed
- }
- for i := 0; i < 10; i++ {
- annualExamYear += 1
- annualExamTime = annualExamTime.AddDate(1, 0, 0)
- annualExamDesc = "10年车龄1年年检1次"
- if annualExamTime.After(nowTime) {
- if isExpire {
- annualExamTime = annualExamTime.AddDate(-1, 0, 0)
- }
- goto CALCANNUALEXAMTIME
- }
- }
- for i := 0; i < 30; i++ {
- if i%2 == 0 {
- annualExamYear += 1
- }
- annualExamTime = annualExamTime.AddDate(0, 6, 0)
- annualExamDesc = "10年以上车龄每6个月年检1次"
- if annualExamTime.After(nowTime) {
- if isExpire {
- annualExamTime = annualExamTime.AddDate(0, -6, 0)
- }
- goto CALCANNUALEXAMTIME
- }
- }
- CALCANNUALEXAMTIME:
- item.Date = annualExamTime.Format("2006-01-02 15:04:05")
- item.Day = DeltaTimeByDay(annualExamTime, nowTime)
- detail.NumYear = annualExamYear
- detail.Desc = annualExamDesc
- return item, detail, nil
- }
- //摩托车
- func CalcAnnualExamTimeMotor(nowTime time.Time, cdrqTime time.Time, examTime int64, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- var item ItemTime
- var detail AnnualExamDetail
- // 年检时间
- annualExamString := ""
- var annualExamYear int64 = 0
- annualExamDesc := ""
- if examTime != 0 {
- tempTime := time.Unix(examTime/1000, 0)
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), tempTime.Month(), DayCount(int(tempTime.Year()), int(tempTime.Month())))
- } else {
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), cdrqTime.Month(), DayCount(int(cdrqTime.Year()), int(cdrqTime.Month())))
- }
- annualExamTime, err := time.Parse("2006-01-02", annualExamString)
- if err != nil {
- return item, detail, errors.TimeCalcFailed
- }
- for i := 0; i < 2; i++ {
- annualExamYear += 2
- annualExamTime = annualExamTime.AddDate(2, 0, 0)
- annualExamDesc = "4年车龄2年年检1次"
- if annualExamTime.After(nowTime) {
- if isExpire {
- annualExamTime = annualExamTime.AddDate(-2, 0, 0)
- }
- goto CALCANNUALEXAMTIME
- }
- }
- for i := 0; i < 30; i++ {
- annualExamYear += 1
- annualExamTime = annualExamTime.AddDate(1, 0, 0)
- annualExamDesc = "4年以上车龄1年年检1次"
- if annualExamTime.After(nowTime) {
- if isExpire {
- annualExamTime = annualExamTime.AddDate(-1, 0, 0)
- }
- goto CALCANNUALEXAMTIME
- }
- }
- CALCANNUALEXAMTIME:
- item.Date = annualExamTime.Format("2006-01-02 15:04:05")
- item.Day = DeltaTimeByDay(annualExamTime, nowTime)
- detail.NumYear = annualExamYear
- detail.Desc = annualExamDesc
- return item, detail, nil
- }
- func CalcAnnualExamTimeRule1(nowTime time.Time, cdrqTime time.Time, examTime int64, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- return CalcAnnualExamTimeOperation(nowTime, cdrqTime, examTime, isExpire)
- }
- func CalcAnnualExamTimeRule2(nowTime time.Time, cdrqTime time.Time, examTime int64, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- return CalcAnnualExamTimeBigVehicle(nowTime, cdrqTime, examTime, isExpire)
- }
- func CalcAnnualExamTimeRule3(nowTime time.Time, cdrqTime time.Time, examTime int64, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- return CalcAnnualExamTime(nowTime, cdrqTime, examTime, isExpire)
- }
- func CalcAnnualExamTimeRule4(nowTime time.Time, cdrqTime time.Time, examTime int64, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- return CalcAnnualExamTimeMotor(nowTime, cdrqTime, examTime, isExpire)
- }
- func CalcAnnualExamTimeRule5(nowTime time.Time, cdrqTime time.Time, examTime int64, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- var item ItemTime
- var detail AnnualExamDetail
- // 年检时间
- annualExamString := ""
- var annualExamYear int64 = 0
- annualExamDesc := ""
- if examTime != 0 {
- tempTime := time.Unix(examTime/1000, 0)
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), tempTime.Month(), DayCount(int(tempTime.Year()), int(tempTime.Month())))
- } else {
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), cdrqTime.Month(), DayCount(int(cdrqTime.Year()), int(cdrqTime.Month())))
- }
- annualExamTime, err := time.Parse("2006-01-02", annualExamString)
- if err != nil {
- return item, detail, errors.TimeCalcFailed
- }
- for i := 0; i < 30; i++ {
- annualExamYear += 1
- annualExamTime = annualExamTime.AddDate(1, 0, 0)
- annualExamDesc = "每年年检1次"
- if annualExamTime.After(nowTime) {
- if isExpire {
- annualExamTime = annualExamTime.AddDate(-1, 0, 0)
- }
- goto CALCANNUALEXAMTIME
- }
- }
- CALCANNUALEXAMTIME:
- item.Date = annualExamTime.Format("2006-01-02 15:04:05")
- item.Day = DeltaTimeByDay(annualExamTime, nowTime)
- detail.NumYear = annualExamYear
- detail.Desc = annualExamDesc
- return item, detail, nil
- }
- func CalcAnnualExamTimeRule6(nowTime time.Time, cdrqTime time.Time, examTime int64, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- var item ItemTime
- var detail AnnualExamDetail
- // 年检时间
- annualExamString := ""
- var annualExamYear int64 = 0
- annualExamDesc := ""
- if examTime != 0 {
- tempTime := time.Unix(examTime/1000, 0)
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), tempTime.Month(), DayCount(int(tempTime.Year()), int(tempTime.Month())))
- } else {
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), cdrqTime.Month(), DayCount(int(cdrqTime.Year()), int(cdrqTime.Month())))
- }
- annualExamTime, err := time.Parse("2006-01-02", annualExamString)
- if err != nil {
- return item, detail, errors.TimeCalcFailed
- }
- for i := 0; i < 30; i++ {
- if i%2 == 0 {
- annualExamYear += 1
- }
- annualExamTime = annualExamTime.AddDate(0, 6, 0)
- annualExamDesc = "每6个月年检1次"
- if annualExamTime.After(nowTime) {
- if isExpire {
- annualExamTime = annualExamTime.AddDate(0, -6, 0)
- }
- goto CALCANNUALEXAMTIME
- }
- }
- CALCANNUALEXAMTIME:
- item.Date = annualExamTime.Format("2006-01-02 15:04:05")
- item.Day = DeltaTimeByDay(annualExamTime, nowTime)
- detail.NumYear = annualExamYear
- detail.Desc = annualExamDesc
- return item, detail, nil
- }
- func CalcAnnualExamTime(nowTime time.Time, cdrqTime time.Time, examTime int64, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- var item ItemTime
- var detail AnnualExamDetail
- // 年检时间
- annualExamString := ""
- var annualExamYear int64 = 0
- annualExamDesc := ""
- if examTime != 0 {
- tempTime := time.Unix(examTime/1000, 0)
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), tempTime.Month(), DayCount(int(tempTime.Year()), int(tempTime.Month())))
- } else {
- annualExamString = fmt.Sprintf("%d-%0.2d-%0.2d", cdrqTime.Year(), cdrqTime.Month(), DayCount(int(cdrqTime.Year()), int(cdrqTime.Month())))
- }
- annualExamTime, err := time.Parse("2006-01-02", annualExamString)
- if err != nil {
- return item, detail, errors.TimeCalcFailed
- }
- for i := 0; i < 5; i++ {
- annualExamYear += 2
- annualExamTime = annualExamTime.AddDate(2, 0, 0)
- annualExamDesc = "10年车龄2年年检1次"
- if annualExamTime.After(nowTime) {
- if isExpire {
- annualExamTime = annualExamTime.AddDate(-2, 0, 0)
- }
- goto CALCANNUALEXAMTIME
- }
- }
- for i := 0; i < 5; i++ {
- annualExamYear += 1
- annualExamTime = annualExamTime.AddDate(1, 0, 0)
- annualExamDesc = "10年以上车龄1年年检1次"
- if annualExamTime.After(nowTime) {
- if isExpire {
- annualExamTime = annualExamTime.AddDate(-1, 0, 0)
- }
- goto CALCANNUALEXAMTIME
- }
- }
- for i := 0; i < 30; i++ {
- if i%2 == 0 {
- annualExamYear += 1
- }
- annualExamTime = annualExamTime.AddDate(0, 6, 0)
- annualExamDesc = "15年以上车龄每6个月年检1次"
- if annualExamTime.After(nowTime) {
- if isExpire {
- annualExamTime = annualExamTime.AddDate(0, -6, 0)
- }
- goto CALCANNUALEXAMTIME
- }
- }
- CALCANNUALEXAMTIME:
- item.Date = annualExamTime.Format("2006-01-02 15:04:05")
- item.Day = DeltaTimeByDay(annualExamTime, nowTime)
- detail.NumYear = annualExamYear
- detail.Desc = annualExamDesc
- return item, detail, nil
- }
- func CalcAnnualExamTimeRule7(nowTime time.Time, cdrqTime time.Time, examTime int64, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- return CalcAnnualExamTime(nowTime, cdrqTime, examTime, isExpire)
- }
- func calcAnnualExamTimeByRule(nowTime time.Time, cdrqTime time.Time, rule int, isExpire bool) (ItemTime, AnnualExamDetail, error) {
- if rule == rule1 {
- return CalcAnnualExamTimeRule1(nowTime, cdrqTime, 0, isExpire)
- }
- if rule == rule2 {
- return CalcAnnualExamTimeRule2(nowTime, cdrqTime, 0, isExpire)
- }
- if rule == rule3 {
- return CalcAnnualExamTimeRule3(nowTime, cdrqTime, 0, isExpire)
- }
- if rule == rule4 {
- return CalcAnnualExamTimeRule4(nowTime, cdrqTime, 0, isExpire)
- }
- if rule == rule5 {
- return CalcAnnualExamTimeRule5(nowTime, cdrqTime, 0, isExpire)
- }
- if rule == rule6 {
- return CalcAnnualExamTimeRule6(nowTime, cdrqTime, 0, isExpire)
- }
- return CalcAnnualExamTimeRule7(nowTime, cdrqTime, 0, isExpire)
- }
- var OperationProperty = map[string]string{"B": "", "C": "", "D": "", "E": "", "F": "", "G": "", "R": "", "T": ""}
- var UnoperationProperty = map[string]string{"A": "", "H": "", "I": "", "J": "", "K": "", "L": "", "M": "", "N": "", "U": ""}
- func isOperation(usePropery string) bool {
- if usePropery == "" {
- return false
- }
- bytes := []byte(usePropery)
- for _, v := range bytes {
- s := fmt.Sprintf("%c", v)
- if _, ok := OperationProperty[s]; ok == false {
- return false
- }
- }
- return true
- }
- func isUnoperation(usePropery string) bool {
- if usePropery == "" {
- return false
- }
- bytes := []byte(usePropery)
- for _, v := range bytes {
- s := fmt.Sprintf("%c", v)
- if _, ok := UnoperationProperty[s]; ok == false {
- return false
- }
- }
- return true
- }
- func isRule1(useProperty string, vehicleType string, seat int, reg time.Time) bool {
- if isOperation(useProperty) == false {
- return false
- }
- if vehicleType == "K10" ||
- vehicleType == "K11" ||
- vehicleType == "K12" ||
- vehicleType == "K13" ||
- vehicleType == "K14" ||
- vehicleType == "K15" ||
- vehicleType == "K16" ||
- vehicleType == "K17" ||
- vehicleType == "K20" ||
- vehicleType == "K21" ||
- vehicleType == "K22" ||
- vehicleType == "K23" ||
- vehicleType == "K24" ||
- vehicleType == "K25" ||
- vehicleType == "K26" ||
- vehicleType == "K27" ||
- vehicleType == "K30" ||
- vehicleType == "K31" ||
- vehicleType == "K32" ||
- vehicleType == "K33" ||
- vehicleType == "K34" ||
- vehicleType == "K39" ||
- vehicleType == "K40" ||
- vehicleType == "K41" ||
- vehicleType == "K42" ||
- vehicleType == "K43" {
- return true
- }
- return false
- }
- func isRule2(useProperty string, vehicleType string, seat int, reg time.Time) bool {
- if strings.Contains(vehicleType, "G") ||
- strings.Contains(vehicleType, "Q") ||
- strings.Contains(vehicleType, "B") ||
- strings.Contains(vehicleType, "H") {
- return true
- }
- if isUnoperation(useProperty) == false {
- return false
- }
- if vehicleType == "K10" ||
- vehicleType == "K11" ||
- vehicleType == "K12" ||
- vehicleType == "K13" ||
- vehicleType == "K14" ||
- vehicleType == "K15" ||
- vehicleType == "K16" ||
- vehicleType == "K17" ||
- vehicleType == "K20" ||
- vehicleType == "K21" ||
- vehicleType == "K22" ||
- vehicleType == "K23" ||
- vehicleType == "K24" ||
- vehicleType == "K25" ||
- vehicleType == "K26" ||
- vehicleType == "K27" {
- return true
- }
- return false
- }
- func isRule3(useProperty string, vehicleType string, seat int, reg time.Time) bool {
- if isUnoperation(useProperty) == false {
- return false
- }
- if vehicleType == "K30" ||
- vehicleType == "K31" ||
- vehicleType == "K32" ||
- vehicleType == "K33" ||
- vehicleType == "K34" ||
- vehicleType == "K40" ||
- vehicleType == "K41" ||
- vehicleType == "K42" ||
- vehicleType == "K43" ||
- vehicleType == "K39" ||
- vehicleType == "K49" {
- return true
- }
- return false
- }
- func isRule4(useProperty string, vehicleType string, seat int, reg time.Time) bool {
- if strings.Contains(vehicleType, "M") {
- return true
- }
- return false
- }
- func isRule5(useProperty string, vehicleType string, seat int, reg time.Time) bool {
- if strings.Contains(vehicleType, "T") ||
- strings.Contains(vehicleType, "J") ||
- strings.Contains(vehicleType, "X") ||
- strings.Contains(vehicleType, "Z") {
- return true
- }
- return false
- }
- func isRule6(useProperty string, vehicleType string, seat int, reg time.Time) bool {
- if useProperty == "O" ||
- useProperty == "P" ||
- useProperty == "Q" ||
- useProperty == "S" {
- return true
- }
- if vehicleType == "K18" ||
- vehicleType == "K28" ||
- vehicleType == "K38" {
- return true
- }
- return false
- }
- func isRule7(useProperty string, vehicleType string, seat int, reg time.Time, casualty bool) bool {
- if useProperty != "A" {
- return false
- }
- if seat >= 10 || seat <= 0 {
- return false
- }
- if casualty == true {
- return false
- }
- if reg.Year() < 2010 {
- return false
- }
- if reg.Year() == 2010 && reg.Month() < 9 {
- return false
- }
- if vehicleType == "K16" ||
- vehicleType == "K26" ||
- vehicleType == "K30" ||
- vehicleType == "K31" ||
- vehicleType == "K32" ||
- vehicleType == "K33" ||
- vehicleType == "K34" ||
- vehicleType == "K40" ||
- vehicleType == "K41" ||
- vehicleType == "K42" ||
- vehicleType == "K43" {
- return true
- }
- return false
- }
- func getRule(useProperty string, vehicleType string, seat int, reg time.Time, casualty bool) int {
- if isRule7(useProperty, vehicleType, seat, reg, casualty) {
- return rule7
- }
- if isRule1(useProperty, vehicleType, seat, reg) {
- return rule1
- }
- if isRule2(useProperty, vehicleType, seat, reg) {
- return rule2
- }
- if isRule3(useProperty, vehicleType, seat, reg) {
- return rule3
- }
- if isRule4(useProperty, vehicleType, seat, reg) {
- return rule4
- }
- if isRule5(useProperty, vehicleType, seat, reg) {
- return rule5
- }
- if isRule6(useProperty, vehicleType, seat, reg) {
- return rule6
- }
- return -1
- }
- func getAnnualInsepctionTimeInfoNew(vehicleType,initialRegistrationDate string,approvedNumber int,useProperty string,casualty,isExpire bool) (annualInfo GetAnnualInspectionTimeInfo ,err error) {
- vehicleType = strings.ToUpper(vehicleType)
- useProperty = strings.ToUpper(useProperty)
- timeLayout := "2006-01-02"
- nowTime := time.Now()
- loc, _ := time.LoadLocation("Local")
- array := strings.Split(initialRegistrationDate, " ")
- if len(array) > 0 {
- initialRegistrationDate = array[0]
- }
- cdrqTime, err := time.ParseInLocation(timeLayout, initialRegistrationDate, loc)
- if err != nil {
- return annualInfo,err
- }
- rule := getRule(useProperty, vehicleType, approvedNumber, cdrqTime, casualty)
- if rule < 0 {
- return annualInfo,errors.AnnualRuleError
- }
- iterm, detail, err := calcAnnualExamTimeByRule(nowTime, cdrqTime, rule, isExpire)
- if err != nil {
- return annualInfo,err
- }
- array = strings.Split(iterm.Date, " ")
- annualInfo.TimeDate = fmt.Sprintf("%s到期", array[0])
- annualInfo.TimeRemain = fmt.Sprintf("剩%d天", iterm.Day)
- annualInfo.TimeYear = fmt.Sprintf("第%d年", detail.NumYear)
- annualInfo.Rule = detail.Desc
- if rule == rule7 {
- //可免检
- if strings.Contains(detail.Desc, "10年车龄2年年检1次") && !casualty {
- annualInfo.CanBeUncheck = true
- }
- }
- if iterm.Day < 90 {
- //距年审90天内可年审
- annualInfo.CanBeInspection = true
- }
- return annualInfo,nil
- }
- // 年检时间计算
- func calcAnnualExamTimeNew(reqMap map[string]interface{}, isExpire bool) {
- 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 initialRegistrationDate != "" ||
- insuranceFirstDate != "" {
- VehicleType := "K33"
- if vehicleType != "" {
- VehicleType = vehicleType
- }
- InitialRegistrationDate := ""
- if initialRegistrationDate == "" {
- InitialRegistrationDate = insuranceFirstDate
- } else {
- InitialRegistrationDate = initialRegistrationDate
- }
- if len(InitialRegistrationDate) > DataLen {
- InitialRegistrationDate = InitialRegistrationDate[:DataLen]
- }
- annualInfo,err := getAnnualInsepctionTimeInfoNew(VehicleType,InitialRegistrationDate,approvedNumber,useProperty,false,isExpire)
- if err == nil {
- reqMap["inspection_result_effective_to"] = annualInfo.TimeDate[:DataLen] + " 00:00:00"
- }
- /*vReq := gd_service.ServiceGetAnnualInspectionTimeNewReq{VehicleType: VehicleType, RegDate: InitialRegistrationDate, SeatNumber: vehicle.ApprovedNumber, UseProperty: vehicle.UseProperty, Casualty: false, IsExpire: isExpire}
- vReply, err := rpc_apis.Service.ServiceGetAnnualInspectionTimeNew(context.Background(), &vReq)
- if err != nil || vReply.ErrCode != 0 {
- } else {
- vehicle.InspectionResultEffectiveTo = vReply.Info.TimeDate[:dutils.DataLen] + " 00:00:00"
- }*/
- }
- }
- func CalcAnnualExamExpireTime(reqMap map[string]interface{}){
- inspectionResultEffectiveTo,isExist := getMapValueString("inspection_result_effective_to",reqMap)
- if !isExist{
- return
- }
- state ,_:= getMapValueString("state",reqMap)
- if inspectionResultEffectiveTo != "" {
- lastTime, _ := time.Parse(DaySecLayout, inspectionResultEffectiveTo)
- if strings.Contains(state, "E") ||
- strings.Contains(state, "K") ||
- strings.Contains(state, "P") ||
- strings.Contains(state, "Q") {
- if lastTime.After(time.Now()) {
- calcAnnualExamTimeNew(reqMap, true)
- }
- } else if lastTime.Before(time.Now()) {
- calcAnnualExamTimeNew(reqMap, false)
- }
- } else {
- if strings.Contains(state, "E") ||
- strings.Contains(state, "K") ||
- strings.Contains(state, "P") ||
- strings.Contains(state, "Q") {
- calcAnnualExamTimeNew(reqMap, true)
- } else {
- calcAnnualExamTimeNew(reqMap, false)
- }
- }
- }
|