merge_comparepncb.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package main
  2. import (
  3. "strings"
  4. )
  5. func comparePNCB(info *Info, compareProject *ProjectInfo) (compareStr string, score int) {
  6. if info.ProjectName != "" {
  7. pns := []string{}
  8. if compareProject.ProjectName != "" {
  9. pns = append(pns, compareProject.ProjectName)
  10. }
  11. if len(compareProject.MPN) > 0 {
  12. pns = append(pns, compareProject.MPN...)
  13. }
  14. ifind := 0
  15. for _, v := range pns {
  16. if info.ProjectName == v {
  17. ifind = 1
  18. break
  19. } else {
  20. //if strings.Contains(info.ProjectName, v) || strings.Contains(v, info.ProjectName) ||
  21. retv := CheckContain(info.ProjectName, v, info.Buyer)
  22. if retv == 1 {
  23. ifind = 1
  24. break
  25. } else if retv == 2 {
  26. ifind = 2
  27. } else if ifind == 0 {
  28. ifind = 3
  29. }
  30. }
  31. }
  32. switch ifind {
  33. case 0:
  34. compareStr = "D"
  35. case 1:
  36. compareStr = "A"
  37. score += 4
  38. if len([]rune(info.ProjectName)) > 18 {
  39. score += 2
  40. }
  41. case 2:
  42. compareStr = "B"
  43. score += 2
  44. if len([]rune(info.ProjectName)) > 18 {
  45. score += 1
  46. }
  47. case 3:
  48. compareStr = "C"
  49. }
  50. } else {
  51. compareStr = "D"
  52. }
  53. /*
  54. 项目编号 - -()() 要注意
  55. init_text = ["号","(重)","(第二次)","(重)"]
  56. all_clean_mark = ["[","(","【","(","〖","]",")","】",")","〗","-","〔","〕","《","[","]","{","}","{","—"," ","-","﹝","﹞","–"]
  57. */
  58. for _, pc := range []string{info.ProjectCode, info.PTC} {
  59. if pc != "" {
  60. pcs := []string{}
  61. if compareProject.ProjectCode != "" {
  62. pcs = append(pcs, compareProject.ProjectCode)
  63. }
  64. if len(compareProject.MPC) > 0 {
  65. pcs = append(pcs, compareProject.MPC...)
  66. }
  67. ifind := 0
  68. for _, v := range pcs {
  69. if pc == v {
  70. ifind = 1
  71. break
  72. } else {
  73. // math.Abs(float64(len([]rune(pc))-len([]rune(v)))) < 6
  74. //if !_numreg1.MatchString(pc) && !_zimureg1.MatchString(pc) && !_numreg1.MatchString(v) && !_zimureg1.MatchString(v)
  75. if strings.Contains(pc, v) || strings.Contains(v, pc) {
  76. t1 := pc
  77. t2 := v
  78. if len(v) > len(pc) {
  79. t1 = v
  80. t2 = pc
  81. }
  82. t3 := strings.Replace(t1, t2, "", -1)
  83. t3 = _datereg.ReplaceAllString(t3, "")
  84. if t3 == "" {
  85. ifind = 1
  86. break
  87. } else {
  88. ifind = 2
  89. }
  90. } else if ifind == 0 {
  91. ifind = 3
  92. }
  93. }
  94. }
  95. switch ifind {
  96. case 0:
  97. compareStr += "D"
  98. case 1:
  99. compareStr += "A"
  100. score += 4
  101. if len([]rune(pc)) > 18 {
  102. score += 2
  103. }
  104. case 2:
  105. compareStr += "B"
  106. score += 2
  107. if len([]rune(pc)) > 18 {
  108. score += 1
  109. }
  110. case 3:
  111. compareStr += "C"
  112. }
  113. } else {
  114. compareStr += "D"
  115. }
  116. }
  117. return
  118. }
  119. func CheckContain(b1, b2, infoBuyer string) (res int) {
  120. b1 = replaceStr.ReplaceAllString(b1, "")
  121. b2 = replaceStr.ReplaceAllString(b2, "")
  122. b1 = strings.Replace(b1, infoBuyer, "", 1)
  123. b2 = strings.Replace(b2, infoBuyer, "", 1)
  124. if b1 == b2 {
  125. res = 1 //相等
  126. return
  127. }
  128. bs1 := []rune(b1)
  129. bs2 := []rune(b2)
  130. tmp := ""
  131. for i := 0; i < len(bs1); i++ {
  132. for j := 0; j < len(bs2); j++ {
  133. if bs1[i] == bs2[j] {
  134. tmp += string(bs1[i])
  135. } else if tmp != "" {
  136. b1 = strings.Replace(b1, tmp, "", -1)
  137. b2 = strings.Replace(b2, tmp, "", -1)
  138. tmp = ""
  139. }
  140. }
  141. }
  142. if tmp != "" {
  143. b1 = strings.Replace(b1, tmp, "", -1)
  144. b2 = strings.Replace(b2, tmp, "", -1)
  145. }
  146. if b1 == b2 {
  147. res = 1 //相等
  148. } else if b1 == "" || b2 == "" {
  149. res = 2 //包含
  150. } else {
  151. res = 3 //不相等
  152. }
  153. return
  154. }