123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package analysis
- import "strconv"
- func checkDataMapListEqual(oldDataMapList, newDataMapList []map[string]string) bool {
- if len(oldDataMapList) == len(newDataMapList) {
- for index, v := range newDataMapList {
- for key, value := range v {
- if value1, ok := oldDataMapList[index][key]; ok {
- if value != value1 {
- return false
- }
- } else {
- return false
- }
- }
- }
- } else {
- return false
- }
- return true
- }
- func calcPlateType(longStr, approvedNumberStr, grossMassStr string) string {
- if longStr == "" && approvedNumberStr == "" && grossMassStr == "" {
- return ""
- }
- long, _ := strconv.Atoi(longStr)
- approvedNumber, _ := strconv.Atoi(approvedNumberStr)
- grossMass, _ := strconv.Atoi(grossMassStr)
- if (long != 0) && (approvedNumber != 0 || grossMass != 0) {
- if (long < 6000 && approvedNumber > 9) || long >= 6000 || approvedNumber >= 20 || grossMass >= 4500 {
- return "01"
- } else {
- return "02"
- }
- }
- return ""
- }
- func checkLastMapIsLastDate(lastMap, newMap map[string]string) bool {
- if lastMap["last_compulsory_insurance_date"] == newMap["last_compulsory_insurance_date"] {
- if lastMap["insurance_first_date"] < newMap["insurance_first_date"] {
- return false
- }
- } else if lastMap["last_compulsory_insurance_date"] < newMap["last_compulsory_insurance_date"] {
- return false
- }
- return true
- }
- func sortByDate(dataMapList []map[string]string) (newDataMapList []map[string]string) {
- // TODO 准确判断出过期的数据
- var lastMap map[string]string
- var lastOtherMap map[string]string
- for _, v := range dataMapList {
- plateType := ""
- longStr := ""
- approvedNumberStr := ""
- grossMassStr := ""
- if value, ok := v["plate_type"]; ok {
- plateType = value
- }
- if value, ok := v["long"]; ok {
- longStr = value
- }
- if value, ok := v["approved_number"]; ok {
- approvedNumberStr = value
- }
- if value, ok := v["gross_mass"]; ok {
- grossMassStr = value
- }
- if plateType == "" {
- plateType := calcPlateType(longStr, approvedNumberStr, grossMassStr)
- v["plate_type"] = plateType
- }
- if lastMap == nil {
- lastMap = v
- } else {
- // 号牌种类相同
- if lastMap["plate_type"] == v["plate_type"] {
- if checkLastMapIsLastDate(lastMap, v) {
- delete(v, "plate_type")
- newDataMapList = append(newDataMapList, v)
- } else {
- delete(lastMap, "plate_type")
- newDataMapList = append(newDataMapList, lastMap)
- lastMap = v
- }
- } else {
- // 号牌种类不同
- if lastOtherMap == nil {
- lastOtherMap = v
- } else {
- if checkLastMapIsLastDate(lastOtherMap, v) {
- delete(v, "plate_type")
- newDataMapList = append(newDataMapList, v)
- } else {
- delete(lastOtherMap, "plate_type")
- newDataMapList = append(newDataMapList, lastOtherMap)
- lastOtherMap = v
- }
- }
- }
- }
- }
- if lastMap != nil {
- delete(lastMap, "plate_type")
- newDataMapList = append(newDataMapList, lastMap)
- }
- if lastOtherMap != nil {
- delete(lastOtherMap, "plate_type")
- newDataMapList = append(newDataMapList, lastOtherMap)
- }
- return newDataMapList
- }
|