common.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package analysis
  4. import "strconv"
  5. func checkDataMapListEqual(oldDataMapList, newDataMapList []map[string]string) bool {
  6. if len(oldDataMapList) == len(newDataMapList) {
  7. for index, v := range newDataMapList {
  8. for key, value := range v {
  9. if value1, ok := oldDataMapList[index][key]; ok {
  10. if value != value1 {
  11. return false
  12. }
  13. } else {
  14. return false
  15. }
  16. }
  17. }
  18. } else {
  19. return false
  20. }
  21. return true
  22. }
  23. func calcPlateType(longStr, approvedNumberStr, grossMassStr string) string {
  24. if longStr == "" && approvedNumberStr == "" && grossMassStr == "" {
  25. return ""
  26. }
  27. long, _ := strconv.Atoi(longStr)
  28. approvedNumber, _ := strconv.Atoi(approvedNumberStr)
  29. grossMass, _ := strconv.Atoi(grossMassStr)
  30. if (long != 0) && (approvedNumber != 0 || grossMass != 0) {
  31. if (long < 6000 && approvedNumber > 9) || long >= 6000 || approvedNumber >= 20 || grossMass >= 4500 {
  32. return "01"
  33. } else {
  34. return "02"
  35. }
  36. }
  37. return ""
  38. }
  39. func checkLastMapIsLastDate(lastMap, newMap map[string]string) bool {
  40. if lastMap["last_compulsory_insurance_date"] == newMap["last_compulsory_insurance_date"] {
  41. if lastMap["insurance_first_date"] < newMap["insurance_first_date"] {
  42. return false
  43. }
  44. } else if lastMap["last_compulsory_insurance_date"] < newMap["last_compulsory_insurance_date"] {
  45. return false
  46. }
  47. return true
  48. }
  49. func sortByDate(dataMapList []map[string]string) (newDataMapList []map[string]string) {
  50. // TODO 准确判断出过期的数据
  51. var lastMap map[string]string
  52. var lastOtherMap map[string]string
  53. for _, v := range dataMapList {
  54. plateType := ""
  55. longStr := ""
  56. approvedNumberStr := ""
  57. grossMassStr := ""
  58. if value, ok := v["plate_type"]; ok {
  59. plateType = value
  60. }
  61. if value, ok := v["long"]; ok {
  62. longStr = value
  63. }
  64. if value, ok := v["approved_number"]; ok {
  65. approvedNumberStr = value
  66. }
  67. if value, ok := v["gross_mass"]; ok {
  68. grossMassStr = value
  69. }
  70. if plateType == "" {
  71. plateType := calcPlateType(longStr, approvedNumberStr, grossMassStr)
  72. v["plate_type"] = plateType
  73. }
  74. if lastMap == nil {
  75. lastMap = v
  76. } else {
  77. // 号牌种类相同
  78. if lastMap["plate_type"] == v["plate_type"] {
  79. if checkLastMapIsLastDate(lastMap, v) {
  80. delete(v, "plate_type")
  81. newDataMapList = append(newDataMapList, v)
  82. } else {
  83. delete(lastMap, "plate_type")
  84. newDataMapList = append(newDataMapList, lastMap)
  85. lastMap = v
  86. }
  87. } else {
  88. // 号牌种类不同
  89. if lastOtherMap == nil {
  90. lastOtherMap = v
  91. } else {
  92. if checkLastMapIsLastDate(lastOtherMap, v) {
  93. delete(v, "plate_type")
  94. newDataMapList = append(newDataMapList, v)
  95. } else {
  96. delete(lastOtherMap, "plate_type")
  97. newDataMapList = append(newDataMapList, lastOtherMap)
  98. lastOtherMap = v
  99. }
  100. }
  101. }
  102. }
  103. }
  104. if lastMap != nil {
  105. delete(lastMap, "plate_type")
  106. newDataMapList = append(newDataMapList, lastMap)
  107. }
  108. if lastOtherMap != nil {
  109. delete(lastOtherMap, "plate_type")
  110. newDataMapList = append(newDataMapList, lastOtherMap)
  111. }
  112. return newDataMapList
  113. }