handleproject.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. package main
  2. import (
  3. "fmt"
  4. "qfw/util"
  5. "regexp"
  6. "strings"
  7. )
  8. var pnreg = regexp.MustCompile("^(及编号[::])|(项目|采购|招标|中标|成交|结果|[_]|公告)$")
  9. var numreg = regexp.MustCompile("^[0-9]$")
  10. /**
  11. 0 项目名称不是多包结构,直接按项目名称查找
  12. 1 项目名称多包,截去多包查找,再按不截取的查找
  13. 2 非招标项目名称含单个子包,截取多包查找,再搂
  14. **/
  15. func handleprojectname(pn, buyer, toptype string) (string, int) {
  16. for i := 0; i < 4; i++ {
  17. opn := pn
  18. pn = pnreg.ReplaceAllString(opn, "")
  19. if opn == pn {
  20. break
  21. }
  22. }
  23. //return pn
  24. if len([]rune(pn)) > lenprojectname || strings.Index(pn, buyer) > -1 || AreaGet.CheckSensitiveWord(pn) {
  25. return pn, 0
  26. } else {
  27. return buyer + pn, 0
  28. }
  29. }
  30. //对字段的优先级处理
  31. type ExtractLevel struct {
  32. Strarr []string
  33. }
  34. func InitEL(v string) (e *ExtractLevel) {
  35. if v == "" {
  36. v = "0999999999"
  37. //第1位一下标为0,不用
  38. }
  39. Strarr := strings.Split(v, "")
  40. e = &ExtractLevel{Strarr}
  41. return
  42. }
  43. func (e *ExtractLevel) PutVal(field, val string) {
  44. e.Strarr[extractpos[field]] = val
  45. }
  46. func (e *ExtractLevel) GetVal() string {
  47. return strings.Join(e.Strarr, "")
  48. }
  49. //字段优先级处理
  50. func (e *ExtractLevel) fieldpriority(info, project, set *map[string]interface{}) {
  51. defer util.Catch()
  52. for _k, v := range extractpos {
  53. breplace := false
  54. var _infov interface{}
  55. _infopos := fmt.Sprintf("%d", (*info)[_k+"_w"])
  56. if !numreg.MatchString(_infopos) {
  57. _infopos = "9"
  58. }
  59. if project == nil {
  60. breplace = true
  61. _infov = (*info)[_k]
  62. } else {
  63. ty := cextractpos[_k]
  64. switch ty {
  65. case 's':
  66. _v := util.ObjToString((*project)[_k])
  67. _tv := util.ObjToString((*info)[_k])
  68. _infov = _tv
  69. if _v == "" && _tv != "" {
  70. breplace = true
  71. } else if _tv != "" { //对比
  72. if e.Strarr[v] > _infopos {
  73. breplace = true
  74. }
  75. }
  76. case 'l':
  77. _v := util.Float64All((*project)[_k])
  78. _tv := util.Float64All((*info)[_k])
  79. _infov = _tv
  80. if _v == 0 && _tv > 0 {
  81. breplace = true
  82. } else if _tv > 0 {
  83. if e.Strarr[v] > _infopos {
  84. breplace = true
  85. }
  86. }
  87. }
  88. }
  89. if breplace {
  90. (*set)[_k] = _infov
  91. e.PutVal(_k, _infopos)
  92. }
  93. }
  94. otherfieldpriority(info, project, set)
  95. }
  96. //抽取字段
  97. var cextractpos = map[string]rune{
  98. "projectname": 's',
  99. "projectcode": 's',
  100. "buyer": 's',
  101. "winner": 's',
  102. "budget": 'l',
  103. "bidamount": 'l',
  104. "bidstatus": 's',
  105. "agency": 's',
  106. "projectscope": 's',
  107. }
  108. var extractpos = map[string]int{
  109. "projectname": 0,
  110. "projectcode": 1,
  111. "buyer": 2,
  112. "winner": 3,
  113. "budget": 4,
  114. "bidamount": 5,
  115. "bidstatus": 6,
  116. "agency": 7,
  117. "projectscope": 8,
  118. }
  119. //合并字段
  120. //"area","city","topscopeclass","subscopeclass","bidtype","zbtime","jgtime","buyerclass"
  121. var bidtype = map[string]string{
  122. "招标": "招标",
  123. "邀标": "邀标",
  124. "询价": "询价",
  125. "竞谈": "竞谈",
  126. "单一": "单一",
  127. "竞价": "竞价",
  128. }
  129. func otherfieldpriority(info, project, set *map[string]interface{}) {
  130. area2 := util.ObjToString((*info)["area"])
  131. infoformat := util.IntAll((*info)["infoformat"])
  132. toptype := util.ObjToString((*info)["toptype"])
  133. topscopeclass := util.ObjToString((*info)["topscopeclass"])
  134. subscopeclass := util.ObjToString((*info)["subscopeclass"])
  135. bt := bidtype[util.ObjToString((*info)["subtype"])]
  136. if project == nil {
  137. if area2 == "" || area2 == "全国" {
  138. area2 = "A"
  139. }
  140. (*set)["area"] = area2
  141. (*set)["city"] = util.ObjToString((*info)["city"])
  142. (*set)["topscopeclass"] = topscopeclass
  143. (*set)["subscopeclass"] = subscopeclass
  144. if bt == "" {
  145. bt = "招标"
  146. }
  147. (*set)["bidtype"] = bt
  148. if infoformat == 2 {
  149. (*set)["njtime"] = (*info)["publishtime"]
  150. } else {
  151. if toptype == "招标" {
  152. (*set)["zbtime"] = (*info)["publishtime"]
  153. } else if toptype == "结果" {
  154. (*set)["jgtime"] = (*info)["publishtime"]
  155. }
  156. }
  157. if (*set)["zbtime"] == nil {
  158. (*set)["zbtime"] = (*info)["publishtime"]
  159. }
  160. } else {
  161. area := util.ObjToString((*project)["area"])
  162. if area == "A" && (area2 != "" && area2 != "A" && area2 != "全国") {
  163. (*set)["area"] = area2
  164. }
  165. publishtime := util.Int64All((*info)["publishtime"])
  166. if infoformat == 2 {
  167. //拟建信息,先不判断
  168. if publishtime > 0 {
  169. (*set)["njtime"] = publishtime
  170. }
  171. } else {
  172. //招标信息
  173. if toptype == "招标" {
  174. zbtime := util.Int64All((*project)["zbtime"])
  175. if publishtime > 0 && publishtime < zbtime {
  176. (*set)["zbtime"] = publishtime
  177. }
  178. } else if toptype == "结果" {
  179. jgtime := util.Int64All((*project)["jgtime"])
  180. if publishtime > 0 && publishtime > jgtime {
  181. (*set)["jgtime"] = publishtime
  182. }
  183. }
  184. }
  185. if subscopeclass != "" {
  186. (*set)["topscopeclass"] = topscopeclass
  187. (*set)["subscopeclass"] = subscopeclass
  188. }
  189. if bt != "" && bt != "招标" {
  190. (*set)["bidtype"] = bt
  191. }
  192. }
  193. }