scores.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // scores
  2. package main
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "log"
  7. "qfw/util"
  8. "qfw/util/redis"
  9. "strings"
  10. )
  11. //有效值三选一、三选二
  12. var ThreeToTow, ThreeToOne map[string]bool
  13. func init() {
  14. ThreeToTow = map[string]bool{}
  15. ThreeToOne = map[string]bool{
  16. "AAA": true,
  17. "AAB": true,
  18. }
  19. tows := [][][]string{
  20. [][]string{
  21. []string{"A", "B"},
  22. []string{"A", "B"},
  23. []string{"A", "B"},
  24. },
  25. [][]string{
  26. []string{"A", "B"},
  27. []string{"D", "E"},
  28. []string{"A", "B"},
  29. },
  30. [][]string{
  31. []string{"A", "B"},
  32. []string{"A", "B"},
  33. []string{"D", "E"},
  34. },
  35. [][]string{
  36. []string{"D", "E"},
  37. []string{"A", "B"},
  38. []string{"A", "B"},
  39. },
  40. }
  41. for _, tow := range tows {
  42. for _, v1 := range tow[0] {
  43. for _, v2 := range tow[1] {
  44. for _, v3 := range tow[2] {
  45. key := fmt.Sprintf("%s%s%s", v1, v2, v3)
  46. ThreeToTow[key] = true
  47. }
  48. }
  49. }
  50. }
  51. }
  52. //三选一打分
  53. func (com *CompareInfo) ComputeOne(thisinfo *Info, ids []string) []*CompareOne {
  54. defer util.Catch()
  55. res := redis.Mget(REDISIDS, ids)
  56. scores := []*CompareOne{}
  57. if len(res) > 0 { //找到项目名称、项目编号或采购单位相同时
  58. for _, b1 := range res { //遍历对象数组
  59. if b1 != nil {
  60. var info ProjectInfo
  61. err := json.Unmarshal(b1.([]byte), &info)
  62. if err != nil {
  63. log.Println(err)
  64. }
  65. cone := &CompareOne{
  66. Parent: com,
  67. Pinfo: &info,
  68. }
  69. if com.Field == "pn" { //比较字段项目名称
  70. if len(info.ProjectName) > 0 {
  71. if thisinfo.ProjectName == info.ProjectName { //A
  72. cone.Score += 2
  73. cone.ProjectNameType = "A"
  74. } else if strings.Index(info.ProjectName, thisinfo.ProjectName) > -1 || strings.Index(thisinfo.ProjectName, info.ProjectName) > -1 { //B
  75. cone.Score += 1
  76. cone.ProjectNameType = "B"
  77. } else { //C
  78. cone.Score -= 2
  79. cone.ProjectNameType = "C"
  80. }
  81. } else { //D不计分
  82. cone.ProjectNameType = "D"
  83. }
  84. }
  85. if com.Field == "pc" { //比较字段项目编号
  86. if len(info.ProjectCode) > 0 {
  87. if thisinfo.ProjectCode == info.ProjectCode { //A
  88. cone.Score += 2
  89. cone.ProjectCodeType = "A"
  90. } else if strings.Index(info.ProjectCode, thisinfo.ProjectCode) > -1 || strings.Index(thisinfo.ProjectCode, info.ProjectCode) > -1 { //B
  91. cone.Score += 1
  92. cone.ProjectCodeType = "B"
  93. } else { //C
  94. cone.Score -= 2
  95. cone.ProjectCodeType = "C"
  96. }
  97. } else { //D不计分
  98. cone.ProjectCodeType = "D"
  99. }
  100. }
  101. if thisinfo.Area != "A" && thisinfo.Area != "全国" && info.Area != "A" && info.Area != "全国" {
  102. if thisinfo.Area == info.Area && thisinfo.District == info.District {
  103. cone.Score += 2
  104. cone.AreaType = "A"
  105. } else {
  106. cone.Score -= 1
  107. cone.AreaType = "C"
  108. }
  109. } else {
  110. cone.Score += 1
  111. cone.AreaType = "B"
  112. }
  113. if len([]rune(info.Agency)) > 0 {
  114. if thisinfo.Agency == info.Agency { //A
  115. cone.Score += 2
  116. cone.AgencyType = "A"
  117. } else if strings.Index(info.Agency, thisinfo.Agency) > -1 || strings.Index(thisinfo.Agency, info.Agency) > -1 { //B
  118. cone.Score += 1
  119. cone.AgencyType = "B"
  120. } else {
  121. if len(thisinfo.Agency) < 1 { //E
  122. cone.Score -= 1
  123. cone.AgencyType = "E"
  124. } else { //C
  125. cone.Score -= 2
  126. cone.AgencyType = "C"
  127. }
  128. }
  129. } else { //D不计分
  130. cone.AgencyType = "D"
  131. }
  132. scores = append(scores, cone)
  133. }
  134. }
  135. }
  136. return scores
  137. }
  138. //三选二打分
  139. func (com *CompareInfo) ComputeTow(thisinfo *Info, ids []string, hasbyer bool) []*CompareOne {
  140. defer util.Catch()
  141. res := redis.Mget(REDISIDS, ids)
  142. scores := []*CompareOne{}
  143. if len(res) > 0 { //找到项目名称、项目编号或采购单位相同时
  144. for _, b1 := range res { //遍历对象数组
  145. if b1 != nil {
  146. var info ProjectInfo
  147. err := json.Unmarshal(b1.([]byte), &info)
  148. if err != nil {
  149. log.Println(err)
  150. }
  151. cone := &CompareOne{
  152. Parent: com,
  153. Pinfo: &info,
  154. }
  155. cone.BuyerType, cone.Score = fieldPCBScore(thisinfo.Buyer, info.Buyer, cone.BuyerType, cone.Score)
  156. if hasbyer {
  157. cone.ProjectNameType, cone.Score = fieldPCBScore(thisinfo.ProjectName, info.ProjectName, cone.ProjectNameType, cone.Score)
  158. cone.ProjectCodeType, cone.Score = fieldPCBScore(thisinfo.ProjectCode, info.ProjectCode, cone.ProjectCodeType, cone.Score)
  159. } else { //无采购单位,打分考虑长度
  160. if len([]rune(thisinfo.ProjectName)) > 5 {
  161. cone.ProjectNameType, cone.Score = fieldPCBScore(thisinfo.ProjectName, info.ProjectName, cone.ProjectNameType, cone.Score)
  162. } else {
  163. cone.ProjectNameType = "D"
  164. }
  165. if len(thisinfo.ProjectCode) > 6 {
  166. cone.ProjectCodeType, cone.Score = fieldPCBScore(thisinfo.ProjectCode, info.ProjectCode, cone.ProjectCodeType, cone.Score)
  167. } else {
  168. cone.ProjectCodeType = "D"
  169. }
  170. }
  171. //省市打分
  172. if thisinfo.Area != "A" && thisinfo.Area != "全国" && info.Area != "A" && info.Area != "全国" {
  173. if thisinfo.Area == info.Area && thisinfo.City == info.City {
  174. cone.Score += 2
  175. } else {
  176. cone.Score -= 1
  177. }
  178. } else {
  179. cone.Score += 1
  180. }
  181. //代理机构打分
  182. if len([]rune(info.Agency)) > 0 {
  183. if thisinfo.Agency == info.Agency { //A
  184. cone.Score += 2
  185. } else if strings.Index(info.Agency, thisinfo.Agency) > -1 || strings.Index(thisinfo.Agency, info.Agency) > -1 { //B
  186. cone.Score += 1
  187. } else {
  188. if len(thisinfo.Agency) < 1 { //E
  189. cone.Score -= 1
  190. } else { //C
  191. cone.Score -= 2
  192. }
  193. }
  194. } else { //D不计分
  195. //
  196. }
  197. scores = append(scores, cone)
  198. }
  199. }
  200. }
  201. return scores
  202. }
  203. //项目名称、项目编号、采购单位打分
  204. func fieldPCBScore(this, info, ctype string, score int) (string, int) {
  205. if len(info) > 0 {
  206. if this == info { //A
  207. score += 5
  208. ctype = "A"
  209. } else if strings.Index(info, this) > -1 || strings.Index(this, info) > -1 { //B
  210. score += 2
  211. ctype = "B"
  212. } else {
  213. if len(this) < 1 { //E
  214. score -= 1
  215. ctype = "E"
  216. } else { //C
  217. score -= 2
  218. ctype = "C"
  219. }
  220. }
  221. } else { //D不计分
  222. ctype = "D"
  223. }
  224. return ctype, score
  225. }