new_project.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package main
  2. import (
  3. qu "qfw/util"
  4. "qfw/util/redis"
  5. "strings"
  6. "time"
  7. "gopkg.in/mgo.v2/bson"
  8. )
  9. func NewProject(tmp map[string]interface{}, thisinfo *Info) string {
  10. set := map[string]interface{}{}
  11. for _, f := range FIELDS {
  12. if tmp[f] != nil {
  13. set[f] = tmp[f]
  14. }
  15. }
  16. set["s_projectname"] = thisinfo.ProjectName
  17. set["createtime"] = time.Now().Unix()
  18. set["sourceinfoid"] = qu.BsonIdToSId(tmp["_id"])
  19. set["sourceinfourl"] = tmp["href"]
  20. set["topscopeclass"] = thisinfo.Topscopeclass
  21. set["subscopeclass"] = thisinfo.Subscopeclass
  22. if thisinfo.Buyerperson != "" {
  23. set["buyerperson"] = thisinfo.Buyerperson
  24. }
  25. if thisinfo.Buyertel != "" {
  26. set["buyertel"] = thisinfo.Buyertel
  27. }
  28. if thisinfo.Buyerclass != "" {
  29. set["buyertel"] = thisinfo.Buyerclass
  30. }
  31. if thisinfo.Bidopentime > 0 {
  32. set["bidopentime"] = thisinfo.Bidopentime
  33. }
  34. if len(thisinfo.Winnerorder) > 0 {
  35. set["winnerorder"] = thisinfo.Winnerorder
  36. }
  37. s_subscopeclass := strings.Join(thisinfo.Subscopeclass, ",")
  38. set["s_subscopeclass"] = s_subscopeclass
  39. s_winner := strings.Join(thisinfo.Winners, ",")
  40. set["s_winner"] = s_winner
  41. if tmp["package"] != nil {
  42. set["package"] = tmp["package"] //没定义优先级
  43. }
  44. push := NewPushInfo(tmp)
  45. set["list"] = []bson.M{
  46. push,
  47. }
  48. id := MongoTool.Save(ProjectColl, set)
  49. p1 := NewPinfo(id, thisinfo)
  50. redis.PutCKV(ProjectCache, id, p1)
  51. return id
  52. }
  53. func NewPushInfo(tmp map[string]interface{}) bson.M {
  54. res := bson.M{
  55. "comeintime": tmp["comeintime"],
  56. "publishtime": tmp["publishtime"],
  57. "title": tmp["title"],
  58. "toptype": tmp["toptype"],
  59. "subtype": tmp["subtype"],
  60. "infoformat": tmp["infoformat"],
  61. "infoid": qu.BsonIdToSId(tmp["_id"]),
  62. "area": tmp["area"],
  63. "city": tmp["city"],
  64. "projectname": tmp["projectname"],
  65. "projectcode": tmp["projectcode"],
  66. "buyer": tmp["buyer"],
  67. "href": tmp["href"],
  68. }
  69. for _, k := range []string{"winner", "budget", "bidamount"} {
  70. if tmp[k] != nil {
  71. res[k] = tmp[k]
  72. }
  73. }
  74. return res
  75. }
  76. //生成存放在redis数组中的对象
  77. func NewPinfo(id string, thisinfo *Info) ProjectInfo {
  78. p1 := ProjectInfo{
  79. Id: bson.ObjectIdHex(id),
  80. Ids: []string{thisinfo.Id},
  81. Topscopeclass: thisinfo.Topscopeclass,
  82. Subscopeclass: thisinfo.Subscopeclass,
  83. Winners: thisinfo.Winners,
  84. ProjectName: thisinfo.ProjectName,
  85. ProjectCode: thisinfo.ProjectCode,
  86. Buyer: thisinfo.Buyer,
  87. Agency: thisinfo.Agency,
  88. Area: thisinfo.Area,
  89. City: thisinfo.City,
  90. District: thisinfo.District,
  91. MPN: []string{},
  92. MPC: []string{},
  93. HasPackage: thisinfo.HasPackage,
  94. Package: map[string]interface{}{},
  95. Buyerclass: thisinfo.Buyerclass,
  96. Bidopentime: thisinfo.Bidopentime,
  97. Winnerorder: thisinfo.Winnerorder,
  98. FirstTime: thisinfo.Publishtime,
  99. LastTime: thisinfo.Publishtime,
  100. }
  101. if thisinfo.LenPTC > 5 {
  102. p1.MPC = append(p1.MPC, thisinfo.PTC)
  103. }
  104. for k4, _ := range thisinfo.Package {
  105. p1.Package[k4] = ""
  106. }
  107. return p1
  108. }