update_project.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package main
  2. import (
  3. qu "qfw/util"
  4. "sort"
  5. "strings"
  6. )
  7. func UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectInfo, weight int, comStr string, resVal, pjVal int) {
  8. //log.Println(thisinfo.ProjectName, pInfo.ProjectName, comStr)
  9. // updateid := pInfo.Id
  10. // if BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
  11. // return //updateid
  12. // }
  13. set := map[string]interface{}{}
  14. //res, bres := MongoTool.FindById(ProjectColl, pInfo.Id.Hex(), `{"list":0}`)
  15. EqInfoUpdate(thisinfo, pInfo)
  16. //if bres && res != nil && *res != nil {
  17. set["topscopeclass"] = pInfo.Topscopeclass
  18. set["subscopeclass"] = pInfo.Subscopeclass
  19. s_subscopeclass := strings.Join(pInfo.Subscopeclass, ",")
  20. if len(s_subscopeclass) > 0 {
  21. s_subscopeclass = "," + s_subscopeclass + ","
  22. }
  23. set["s_subscopeclass"] = s_subscopeclass
  24. s_winner := strings.Join(pInfo.Winners, ",")
  25. if len(s_winner) > 0 {
  26. s_winner = "," + s_winner + ","
  27. }
  28. set["s_winner"] = s_winner
  29. if pInfo.Buyerperson != "" && pInfo.Buyertel != "" {
  30. set["buyerperson"] = pInfo.Buyerperson
  31. set["buyertel"] = pInfo.Buyertel
  32. }
  33. if pInfo.Buyerclass != "" {
  34. set["buyerclass"] = pInfo.Buyerclass
  35. }
  36. if pInfo.District != "" {
  37. set["district"] = pInfo.District
  38. }
  39. if pInfo.Bidopentime > 0 {
  40. set["bidopentime"] = pInfo.Bidopentime
  41. }
  42. if len(pInfo.Winnerorder) > 0 {
  43. set["winnerorder"] = pInfo.Winnerorder
  44. }
  45. if thisinfo.HasPackage {
  46. set["multipackage"] = 1
  47. } else {
  48. set["multipackage"] = 0
  49. }
  50. if pInfo.ProjectName != "" {
  51. set["projectname"] = pInfo.ProjectName
  52. }
  53. if pInfo.ProjectCode != "" {
  54. set["projectcode"] = pInfo.ProjectCode
  55. }
  56. if pInfo.Buyer != "" {
  57. set["buyer"] = pInfo.Buyer
  58. }
  59. //预算、中标价
  60. if qu.Float64All(tmp["bidamount"]) > 0 && pInfo.Bidamount == 0 {
  61. set["bidamount"] = tmp["bidamount"]
  62. }
  63. if qu.Float64All(tmp["budget"]) > 0 && pInfo.Budget == 0 {
  64. set["budget"] = tmp["budget"]
  65. }
  66. set["mpn"] = pInfo.MPN
  67. set["mpc"] = pInfo.MPC
  68. set["area"] = pInfo.Area
  69. set["city"] = pInfo.City
  70. //e := InitEL(util.ObjToString((*res)["extractpos"]))
  71. if thisinfo.dealtype == 1 {
  72. var sonpackage map[string]interface{}
  73. for _, obj := range tmp["package"].(map[string]interface{}) {
  74. sonpackage, _ = obj.(map[string]interface{})
  75. }
  76. for _, v2 := range []string{"budget", "budget_w", "winner", "winner_w", "bidstatus", "bidstatus_w"} {
  77. if sonpackage[v2] != nil {
  78. tmp[v2] = sonpackage[v2]
  79. }
  80. }
  81. }
  82. //e.fieldpriority(&tmp, res, &set)
  83. //set["extractpos"] = e.GetVal()
  84. // if thisinfo.HasPackage { //多包处理
  85. // p1, _ := (*res)["package"].(map[string]interface{})
  86. // p2, _ := tmp["package"].(map[string]interface{})
  87. // if p2 != nil {
  88. // if p1 != nil {
  89. // for pk2, pv2 := range p2 {
  90. // if p1[pk2] != nil { //合并
  91. // item1, _ := p1[pk2].(map[string]interface{})
  92. // item2, _ := pv2.(map[string]interface{})
  93. // if item1 != nil && item2 != nil { //原始项
  94. // for ik1, iv1 := range item2 {
  95. // if item1[ik1] == nil {
  96. // item1[ik1] = iv1
  97. // }
  98. // }
  99. // }
  100. // } else {
  101. // p1[pk2] = pv2
  102. // }
  103. // }
  104. // } else {
  105. // p1 = p2
  106. // }
  107. // }
  108. // set["package"] = p1
  109. // }
  110. //中标候选人合并
  111. update := map[string]interface{}{}
  112. if len(set) > 0 {
  113. update["$set"] = set
  114. }
  115. //保留原数据吧
  116. push := NewPushInfo(tmp)
  117. push["compareStr"] = comStr
  118. push["resVal"] = resVal
  119. push["pjVal"] = pjVal
  120. update["$push"] = map[string]interface{}{
  121. "list": push,
  122. }
  123. if len(update) > 0 {
  124. updateInfo := []map[string]interface{}{
  125. map[string]interface{}{
  126. "_id": pInfo.Id,
  127. },
  128. update,
  129. }
  130. //批量更新,这块可能需要再做判重处理
  131. updatePool <- updateInfo
  132. // MongoTool.Update(ProjectColl, map[string]interface{}{
  133. // "_id": qu.StringTOBsonId(pInfo.Id.Hex()),
  134. // }, &update, false, false)
  135. }
  136. //}
  137. //再往redis中放 index
  138. //往队列中增加时间 -------------->start
  139. }
  140. func EqInfoUpdate(thisinfo *Info, pInfo *ProjectInfo) {
  141. if thisinfo.Publishtime > pInfo.LastTime {
  142. pInfo.LastTime = thisinfo.Publishtime
  143. }
  144. if pInfo.FirstTime == 0 || (thisinfo.Publishtime < pInfo.FirstTime && thisinfo.Publishtime > 0) {
  145. pInfo.FirstTime = thisinfo.Publishtime
  146. }
  147. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  148. //增加发布时间结束----------------->end
  149. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  150. pInfo.Buyer = thisinfo.Buyer
  151. }
  152. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  153. pInfo.Agency = thisinfo.Agency
  154. }
  155. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  156. pInfo.ProjectCode = thisinfo.ProjectCode
  157. }
  158. if pInfo.Area == "全国" && thisinfo.Area != "全国" {
  159. pInfo.Area = thisinfo.Area
  160. pInfo.City = thisinfo.City
  161. }
  162. if thisinfo.District != "" {
  163. pInfo.District = thisinfo.District
  164. }
  165. if thisinfo.Buyerperson != "" && thisinfo.Buyertel != "" {
  166. pInfo.Buyerperson = thisinfo.Buyerperson
  167. pInfo.Buyertel = thisinfo.Buyertel
  168. }
  169. if thisinfo.Buyerclass != "" {
  170. pInfo.Buyerclass = thisinfo.Buyerclass
  171. }
  172. if thisinfo.Bidopentime > 0 {
  173. pInfo.Bidopentime = thisinfo.Bidopentime
  174. }
  175. if thisinfo.Bidamount > 0 && pInfo.Bidamount < 1 {
  176. pInfo.Bidamount = thisinfo.Bidamount
  177. }
  178. if thisinfo.Budget > 0 && pInfo.Budget < 1 {
  179. pInfo.Budget = thisinfo.Budget
  180. }
  181. if len(thisinfo.Topscopeclass) > 0 {
  182. sort.Strings(pInfo.Topscopeclass)
  183. for _, k := range thisinfo.Topscopeclass {
  184. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  185. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  186. sort.Strings(pInfo.Topscopeclass)
  187. }
  188. }
  189. }
  190. if len(thisinfo.Subscopeclass) > 0 {
  191. sort.Strings(pInfo.Subscopeclass)
  192. for _, k := range thisinfo.Subscopeclass {
  193. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  194. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  195. sort.Strings(pInfo.Subscopeclass)
  196. }
  197. }
  198. }
  199. //winner
  200. if len(thisinfo.Winners) > 0 {
  201. sort.Strings(pInfo.Winners)
  202. for _, k := range thisinfo.Winners {
  203. if BinarySearch(pInfo.Winners, k) == -1 {
  204. pInfo.Winners = append(pInfo.Winners, k)
  205. sort.Strings(pInfo.Winners)
  206. }
  207. }
  208. }
  209. //winnerorder
  210. // if len(thisinfo.Winnerorder) > 0 {
  211. // sort.Strings(pInfo.Winnerorder)
  212. // for _, k := range thisinfo.Winnerorder {
  213. // //if BinarySearch(pInfo.Winnerorder, k) == -1 {
  214. // pInfo.Winnerorder = append(pInfo.Winnerorder, k)
  215. // sort.Strings(pInfo.Winnerorder)
  216. // //}
  217. // }
  218. // }
  219. }