thisinfo.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // thisinfo
  2. package main
  3. import (
  4. "crypto/sha1"
  5. "encoding/json"
  6. "fmt"
  7. "io"
  8. du "jy/util"
  9. "qfw/util"
  10. "strings"
  11. "gopkg.in/mgo.v2/bson"
  12. )
  13. //抽取信息映射实体类
  14. type Info struct {
  15. Id string `json:"_id"`
  16. Href string `json:"href"`
  17. Publishtime int64 `json:"publishtime"`
  18. Title string `json:"title"`
  19. TopType string `json:"toptype"`
  20. SubType string `json:"subtype"`
  21. ProjectName string `json:"projectname"`
  22. ProjectCode string `json:"projectcode"`
  23. Buyer string `json:"buyer"`
  24. Buyerperson string `json:"buyerperson"`
  25. Buyertel string `json:"buyertel"`
  26. Agency string `json:"agency"`
  27. Area string `json:"area"`
  28. City string `json:"city"`
  29. HasPackage bool `json:"haspackage"`
  30. Package map[string]interface{} `json:"package"`
  31. PNum string `json:"pnum"`
  32. Topscopeclass []string `json:"topscopeclass"`
  33. Subscopeclass []string `json:"subscopeclass"`
  34. Winners []string
  35. dealtype int
  36. Buyerclass string `json:"buyerclass"`
  37. Bidopentime int64 `json:"bidopentime"`
  38. District string `json:"district"`
  39. Winnerorder []string
  40. NewPNKey string
  41. PNKey string
  42. PCKey string
  43. PBKey string
  44. AllRelatePNKeyMap map[string]*Key
  45. AllRelatePCKeyMap map[string]*Key
  46. }
  47. //pcb三选值
  48. type PCBV struct {
  49. Val int //1一项有效值,2二项有效值,3三项有效值
  50. Pname bool //有项目名称
  51. Pcode bool //有项目编号
  52. Buyer bool //有采购单位
  53. Area bool //区域
  54. City bool //市
  55. Agency bool //代理机构
  56. PnameLen int //值长度
  57. PcodeLen int //值长度
  58. BuyerLen int //值长度
  59. }
  60. func PreThisInfo(tmp map[string]interface{} /*新信息*/) *Info {
  61. bys, _ := json.Marshal(tmp)
  62. var thisinfo *Info
  63. json.Unmarshal(bys, &thisinfo)
  64. if thisinfo == nil {
  65. return nil
  66. }
  67. if len(thisinfo.Topscopeclass) == 0 {
  68. thisinfo.Topscopeclass = []string{}
  69. }
  70. if len(thisinfo.Subscopeclass) == 0 {
  71. thisinfo.Subscopeclass = []string{}
  72. }
  73. //去重
  74. thisinfo.Subscopeclass = RemoveDup(thisinfo.Subscopeclass)
  75. if len(thisinfo.Package) > 0 { //信息是否分包
  76. thisinfo.HasPackage = true
  77. } else if thisinfo.TopType == "结果" && TitleReg.MatchString(thisinfo.Title) {
  78. //当信息类型是结果时,并且标题中包含分包字样,找到包号,用以后面比较打分
  79. res := TitleReg.FindAllStringSubmatch(thisinfo.Title, -1)
  80. pnum := du.PackageNumberConvert(res[0][0])
  81. //du.Debug(pnum, res)
  82. thisinfo.PNum = pnum
  83. }
  84. if thisinfo.SubType == "变更" || strings.Index(thisinfo.Title, "变更公告") > -1 || strings.Index(thisinfo.Title, "更正公告") > -1 {
  85. //当信息类型是变更或标题中含变更时
  86. if thisinfo.TopType == "招标" {
  87. //招标的变更公告过,不作处理
  88. //du.Debug(thisinfo.Id, thisinfo.Href, thisinfo.ProjectName, thisinfo.ProjectCode)
  89. return nil
  90. } else if thisinfo.TopType == "结果" {
  91. thisinfo.SubType = "变更"
  92. }
  93. }
  94. //计算中标人
  95. winner, _ := tmp["winner"].(string)
  96. m1 := map[string]bool{}
  97. winners := []string{}
  98. if winner != "" {
  99. m1[winner] = true
  100. winners = append(winners, winner)
  101. }
  102. if thisinfo.HasPackage {
  103. packageM, _ := tmp["package"].(bson.M)
  104. for _, p := range packageM {
  105. pm, _ := p.(map[string]interface{})
  106. pw, _ := pm["winner"].(string)
  107. if pw != "" {
  108. m1[pw] = true
  109. winners = append(winners, pw)
  110. }
  111. }
  112. }
  113. thisinfo.Winners = winners
  114. m1 = nil
  115. //中标候选人
  116. winnerorder := []string{}
  117. if winorders, ok := tmp["winnerorder"].([]interface{}); ok {
  118. for _, wins := range winorders {
  119. if win, ok := wins.(map[string]interface{}); ok {
  120. entname := util.ObjToString(win["entname"])
  121. if entname != "" && len([]rune(entname)) > 6 {
  122. winnerorder = append(winnerorder, entname)
  123. }
  124. }
  125. }
  126. }
  127. thisinfo.Winnerorder = winnerorder
  128. new_pn, _ := handleprojectname(thisinfo.ProjectName, thisinfo.Buyer, thisinfo.TopType) //作为判断依据
  129. thisinfo.NewPNKey = new_pn
  130. thisinfo.PNKey = "pn_" + new_pn
  131. thisinfo.PCKey = "pc_" + thisinfo.ProjectCode
  132. thisinfo.PBKey = "pb_" + thisinfo.Buyer
  133. return thisinfo
  134. }
  135. //获取hascode
  136. func GetHas1(key string) string {
  137. t := sha1.New()
  138. io.WriteString(t, key)
  139. return fmt.Sprintf("%x", t.Sum(nil))
  140. }