projectindex.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package main
  2. import (
  3. "math"
  4. "strconv"
  5. util "utils"
  6. "utils/mongodb"
  7. )
  8. func projectTask(data []byte, project, mapInfo map[string]interface{}) {
  9. defer util.Catch()
  10. q, _ := mapInfo["query"].(map[string]interface{})
  11. if q == nil {
  12. q = map[string]interface{}{
  13. "_id": map[string]interface{}{
  14. "$gt": mongodb.StringTOBsonId(mapInfo["gtid"].(string)),
  15. "$lte": mongodb.StringTOBsonId(mapInfo["lteid"].(string)),
  16. },
  17. }
  18. } else {
  19. if q["pici"] == nil {
  20. idMap, _ := q["_id"].(map[string]interface{})
  21. if idMap != nil {
  22. tmpQ := map[string]interface{}{}
  23. for c, id := range idMap {
  24. if idStr, ok := id.(string); ok && id != "" {
  25. tmpQ[c] = mongodb.StringTOBsonId(idStr)
  26. }
  27. }
  28. q["_id"] = tmpQ
  29. }
  30. }
  31. }
  32. conn := projectMgo.GetMgoConn()
  33. defer projectMgo.DestoryMongoConn(conn)
  34. c, _ := project["collect"].(string)
  35. count, _ := conn.DB(projectMgo.DbName).C(c).Find(&q).Count()
  36. util.Debug(c, "查询语句:", q, "同步总数:", count, "elastic库:", q["pici"])
  37. query := conn.DB(projectMgo.DbName).C(c).Find(q).Iter()
  38. n := 0
  39. for tmp := make(map[string]interface{}); query.Next(tmp); n++ {
  40. if n%20000 == 0 {
  41. util.Debug("current---------", n)
  42. }
  43. pp := map[string]map[string]interface{}{}
  44. if packages, ok := tmp["package"].(map[string]interface{}); ok {
  45. for _, pks := range packages {
  46. if pk, ok := pks.([]interface{}); ok {
  47. for _, v := range pk {
  48. if p, ok := v.(map[string]interface{}); ok {
  49. winner := util.ObjToString(p["winner"])
  50. bidamount := util.Float64All((p["bidamount"]))
  51. if len(winner) > 4 && bidamount > 0 {
  52. p := map[string]interface{}{
  53. "winner": winner,
  54. "bidamount": bidamount,
  55. }
  56. pp[winner] = p
  57. }
  58. }
  59. }
  60. }
  61. }
  62. } else {
  63. winner := util.ObjToString(tmp["winner"])
  64. bidamount := util.Float64All(tmp["bidamount"])
  65. if len(winner) > 4 && bidamount > 0 {
  66. p := map[string]interface{}{
  67. "winner": winner,
  68. "bidamount": bidamount,
  69. }
  70. pp[winner] = p
  71. }
  72. }
  73. pk1 := []map[string]interface{}{}
  74. for _, v := range pp {
  75. pk1 = append(pk1, v)
  76. }
  77. if len(pk1) > 0 {
  78. tmp["package1"] = pk1
  79. }
  80. budget := util.Float64All(tmp["budget"])
  81. bidamount := util.Float64All(tmp["bidamount"])
  82. if float64(budget) > 0 && float64(bidamount) > 0 {
  83. rate := float64(1) - float64(bidamount)/float64(budget)
  84. f, _ := strconv.ParseFloat(strconv.FormatFloat(rate, 'f', 4, 64), 64)
  85. //不在0~0.6之间,不生成费率;只生成预算,中标金额舍弃,索引增加折扣率异常标识
  86. if f < 0 || f > 0.6 {
  87. delete(tmp, "bidamount")
  88. tmp["prate_flag"] = 1
  89. } else {
  90. tmp["project_rate"] = f
  91. }
  92. }
  93. if topscopeclass, ok := tmp["topscopeclass"].([]interface{}); ok {
  94. tc := []string{}
  95. m2 := map[string]bool{}
  96. for _, v := range topscopeclass {
  97. str := util.ObjToString(v)
  98. str = reg_letter.ReplaceAllString(str, "") // 去除字母
  99. if !m2[str] {
  100. m2[str] = true
  101. tc = append(tc, str)
  102. }
  103. }
  104. tmp["topscopeclass"] = tc
  105. }
  106. //不生索引字段
  107. delete(tmp, "package")
  108. delete(tmp, "infofield")
  109. bidopentime := util.Int64All(tmp["bidopentime"]) //开标日期
  110. fzb_publishtime := int64(0) //记录第一个招标信息的publishtime
  111. bidcycle_flag := false //判断是否已计算出标书表编制周期
  112. list := tmp["list"].([]interface{})
  113. for _, m := range list {
  114. tmpM := m.(map[string]interface{})
  115. //删除purchasing,review_experts
  116. delete(tmpM, "purchasing")
  117. delete(tmpM, "review_experts")
  118. if bidamount, ok := tmpM["bidamount"].(string); ok && len(bidamount) > 0 { //bidamount为string类型,转成float
  119. tmpB := util.Float64All(tmpM["bidamount"])
  120. tmpM["bidamount"] = tmpB
  121. }
  122. //projectscope截断
  123. listProjectscopeRune := []rune(util.ObjToString(tmpM["projectscope"]))
  124. if len(listProjectscopeRune) > 1000 {
  125. tmpM["projectscope"] = string(listProjectscopeRune[:1000])
  126. }
  127. //计算bidcycle标书表编制周期字段
  128. if !bidcycle_flag && bidopentime > 0 { //bidopentime>0证明list中有bidopentime,无则不用计算bidcycle
  129. if toptype := util.ObjToString(tmpM["toptype"]); toptype == "招标" {
  130. zb_bidopentime := util.Int64All(tmpM["bidopentime"])
  131. zb_publishtime := util.Int64All(tmpM["publishtime"])
  132. if zb_publishtime > 0 {
  133. if zb_bidopentime > 0 {
  134. if tmpTime := zb_bidopentime - zb_publishtime; tmpTime > 0 {
  135. f_day := float64(tmpTime) / float64(86400)
  136. day := math.Ceil(f_day)
  137. tmp["bidcycle"] = int(day)
  138. bidcycle_flag = true
  139. }
  140. }
  141. if fzb_publishtime == 0 { //仅赋值第一个招标信息的publishtime
  142. fzb_publishtime = zb_publishtime
  143. }
  144. }
  145. }
  146. }
  147. }
  148. //计算bidcycle标书表编制周期字段
  149. //list中招标信息中未能计算出bidcycle,用第一个招标信息的fzb_publishtime和外围bidopentime计算
  150. if !bidcycle_flag && bidopentime > 0 && fzb_publishtime > 0 {
  151. if tmpTime := bidopentime - fzb_publishtime; tmpTime > 0 {
  152. f_day := float64(tmpTime) / float64(86400)
  153. day := math.Ceil(f_day)
  154. tmp["bidcycle"] = int(day)
  155. }
  156. }
  157. //projectscope截断
  158. projectscopeRune := []rune(util.ObjToString(tmp["projectscope"]))
  159. if len(projectscopeRune) > 1000 {
  160. tmp["projectscope"] = string(projectscopeRune[:1000])
  161. }
  162. // if s_budget := fmt.Sprint(tmp["budget"]); s_budget == "" || s_budget == "<nil>" || s_budget == "null" {
  163. // tmp["budget"] = nil
  164. // }
  165. // if s_bidamount := fmt.Sprint(tmp["bidamount"]); s_bidamount == "" || s_bidamount == "<nil>" || s_bidamount == "null" {
  166. // tmp["bidamount"] = nil
  167. // }
  168. //go IS.Add("project")
  169. if tmp["bidamount"] != nil && util.Float64All(tmp["bidamount"]) > 1000000000 {
  170. delete(tmp, "bidamount")
  171. }
  172. if tmp["budget"] != nil && util.Float64All(tmp["budget"]) > 1000000000 {
  173. delete(tmp, "budget")
  174. }
  175. tmp["s_projectname"] = tmp["projectname"]
  176. saveProjectEsPool <- tmp
  177. tmp = make(map[string]interface{})
  178. }
  179. util.Debug(mapInfo, "create project index...over", n)
  180. }