update_project.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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) {
  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 {
  61. if qu.Float64All((*res)["bidamount"]) == 0 {
  62. set["bidamount"] = tmp["bidamount"]
  63. }
  64. }
  65. if qu.Float64All(tmp["budget"]) > 0 {
  66. if qu.Float64All((*res)["budget"]) == 0 {
  67. set["budget"] = tmp["budget"]
  68. }
  69. }
  70. set["mpn"] = pInfo.MPN
  71. set["mpc"] = pInfo.MPC
  72. set["area"] = pInfo.Area
  73. set["city"] = pInfo.City
  74. //e := InitEL(util.ObjToString((*res)["extractpos"]))
  75. if thisinfo.dealtype == 1 {
  76. var sonpackage map[string]interface{}
  77. for _, obj := range tmp["package"].(map[string]interface{}) {
  78. sonpackage, _ = obj.(map[string]interface{})
  79. }
  80. for _, v2 := range []string{"budget", "budget_w", "winner", "winner_w", "bidstatus", "bidstatus_w"} {
  81. if sonpackage[v2] != nil {
  82. tmp[v2] = sonpackage[v2]
  83. }
  84. }
  85. }
  86. //e.fieldpriority(&tmp, res, &set)
  87. //set["extractpos"] = e.GetVal()
  88. if thisinfo.HasPackage { //多包处理
  89. p1, _ := (*res)["package"].(map[string]interface{})
  90. p2, _ := tmp["package"].(map[string]interface{})
  91. if p2 != nil {
  92. if p1 != nil {
  93. for pk2, pv2 := range p2 {
  94. if p1[pk2] != nil { //合并
  95. item1, _ := p1[pk2].(map[string]interface{})
  96. item2, _ := pv2.(map[string]interface{})
  97. if item1 != nil && item2 != nil { //原始项
  98. for ik1, iv1 := range item2 {
  99. if item1[ik1] == nil {
  100. item1[ik1] = iv1
  101. }
  102. }
  103. }
  104. } else {
  105. p1[pk2] = pv2
  106. }
  107. }
  108. } else {
  109. p1 = p2
  110. }
  111. }
  112. set["package"] = p1
  113. }
  114. //中标候选人合并
  115. update := map[string]interface{}{}
  116. if len(set) > 0 {
  117. update["$set"] = set
  118. }
  119. //保留原数据吧
  120. push := NewPushInfo(tmp)
  121. push["compareStr"] = comStr
  122. update["$push"] = map[string]interface{}{
  123. "list": push,
  124. }
  125. if len(update) > 0 {
  126. MongoTool.Update(ProjectColl, map[string]interface{}{
  127. "_id": qu.StringTOBsonId(pInfo.Id.Hex()),
  128. }, &update, false, false)
  129. }
  130. }
  131. //再往redis中放 index
  132. //往队列中增加时间 -------------->start
  133. }
  134. func EqInfoUpdate(thisinfo *Info, pInfo *ProjectInfo) {
  135. if thisinfo.Publishtime > pInfo.LastTime {
  136. pInfo.LastTime = thisinfo.Publishtime
  137. }
  138. if pInfo.FirstTime == 0 || (thisinfo.Publishtime < pInfo.FirstTime && thisinfo.Publishtime > 0) {
  139. pInfo.FirstTime = thisinfo.Publishtime
  140. }
  141. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  142. //增加发布时间结束----------------->end
  143. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  144. pInfo.Buyer = thisinfo.Buyer
  145. }
  146. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  147. pInfo.Agency = thisinfo.Agency
  148. }
  149. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  150. pInfo.ProjectCode = thisinfo.ProjectCode
  151. }
  152. if pInfo.Area == "全国" && thisinfo.Area != "全国" {
  153. pInfo.Area = thisinfo.Area
  154. pInfo.City = thisinfo.City
  155. }
  156. if thisinfo.Buyerperson != "" && thisinfo.Buyertel != "" && len([]rune(thisinfo.Buyertel)) > 6 {
  157. pInfo.Buyerperson = thisinfo.Buyerperson
  158. pInfo.Buyertel = thisinfo.Buyertel
  159. }
  160. if thisinfo.Buyerclass != "" {
  161. pInfo.Buyerclass = thisinfo.Buyerclass
  162. }
  163. if thisinfo.District != "" {
  164. pInfo.District = thisinfo.District
  165. }
  166. if thisinfo.Bidopentime > 0 {
  167. pInfo.Bidopentime = thisinfo.Bidopentime
  168. }
  169. if len(thisinfo.Topscopeclass) > 0 {
  170. sort.Strings(pInfo.Topscopeclass)
  171. for _, k := range thisinfo.Topscopeclass {
  172. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  173. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  174. sort.Strings(pInfo.Topscopeclass)
  175. }
  176. }
  177. }
  178. if len(thisinfo.Subscopeclass) > 0 {
  179. sort.Strings(pInfo.Subscopeclass)
  180. for _, k := range thisinfo.Subscopeclass {
  181. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  182. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  183. sort.Strings(pInfo.Subscopeclass)
  184. }
  185. }
  186. }
  187. //winner
  188. if len(thisinfo.Winners) > 0 {
  189. sort.Strings(pInfo.Winners)
  190. for _, k := range thisinfo.Winners {
  191. if BinarySearch(pInfo.Winners, k) == -1 {
  192. pInfo.Winners = append(pInfo.Winners, k)
  193. sort.Strings(pInfo.Winners)
  194. }
  195. }
  196. }
  197. //winnerorder
  198. if len(thisinfo.Winnerorder) > 0 {
  199. sort.Strings(pInfo.Winnerorder)
  200. for _, k := range thisinfo.Winnerorder {
  201. if BinarySearch(pInfo.Winnerorder, k) == -1 {
  202. pInfo.Winnerorder = append(pInfo.Winnerorder, k)
  203. sort.Strings(pInfo.Winnerorder)
  204. }
  205. }
  206. }
  207. }