project.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. package main
  2. import (
  3. "fmt"
  4. "go.mongodb.org/mongo-driver/bson"
  5. "go.mongodb.org/mongo-driver/bson/primitive"
  6. "go.uber.org/zap"
  7. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  8. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  9. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  10. "math"
  11. "sort"
  12. "strings"
  13. "sync"
  14. "tieta_data/config"
  15. "time"
  16. )
  17. var (
  18. wg sync.WaitGroup
  19. )
  20. // 从对应map中获取对比的项目id
  21. func getCompareIds(pn, pc, ptc, pb string) (bpn, bpc, bptc, bpb int, res []*Key, idArr []string, IDArr []*ID) {
  22. // p.ConCurrentLock(n1, n2, n3, n4)
  23. // defer p.ConCurrentUnLock(n1, n2, n3, n4)
  24. wg.Add(1)
  25. //查找到id数组
  26. res = []*Key{}
  27. //是否查找到,并标识位置。-1代表值为空或已经存在。
  28. bpn, bpc, bptc, bpb = -1, -1, -1, -1
  29. if pn != "" {
  30. ids := mapPn[pn]
  31. if ids == nil {
  32. ids = &Key{Arr: []string{}}
  33. mapPn[pn] = ids
  34. bpn = 0
  35. }
  36. ids.Lock.Lock()
  37. res = append(res, ids)
  38. }
  39. if pc != "" {
  40. ids := mapPc[pc]
  41. if ids == nil {
  42. ids = &Key{Arr: []string{}}
  43. mapPc[pc] = ids
  44. bpc = len(res)
  45. }
  46. ids.Lock.Lock()
  47. res = append(res, ids)
  48. }
  49. if ptc != "" {
  50. ids := mapPc[ptc]
  51. if ids == nil {
  52. ids = &Key{Arr: []string{}}
  53. mapPc[ptc] = ids
  54. bptc = len(res)
  55. }
  56. ids.Lock.Lock()
  57. res = append(res, ids)
  58. }
  59. if pb != "" {
  60. ids := mapPb[pb]
  61. if ids == nil {
  62. ids = &Key{Arr: []string{}}
  63. mapPb[pb] = ids
  64. bpb = len(res)
  65. }
  66. ids.Lock.Lock()
  67. res = append(res, ids)
  68. }
  69. repeatId := map[string]bool{}
  70. idArr = []string{} //项目id
  71. IDArr = []*ID{} //项目信息
  72. for _, m := range res {
  73. for _, id := range m.Arr {
  74. if !repeatId[id] {
  75. repeatId[id] = true
  76. //_, _ = strconv.ParseInt(id[0:8], 16, 64)
  77. AllIdsMapLock.Lock()
  78. Id := AllIdsMap[id]
  79. AllIdsMapLock.Unlock()
  80. if Id != nil {
  81. Id.Lock.Lock()
  82. idArr = append(idArr, id)
  83. IDArr = append(IDArr, Id)
  84. }
  85. }
  86. }
  87. }
  88. return
  89. }
  90. func startProjectMerge(info *Info, tmp map[string]interface{}) {
  91. findLock.Lock()
  92. defer findLock.Unlock()
  93. //bpn, bpc, bptc, bpb 是否查找到,并标识位置。-1代表未查找到。
  94. //pids 是项目id数组集合
  95. //IDArr,是单个项目ID对象集合
  96. bpn, bpc, bptc, bpb, pids, _, IDArr := getCompareIds(info.ProjectName, info.ProjectCode, info.PTC, info.Buyer) //, info.LenPN, info.LenPC, info.LenPTC, len([]rune(info.Buyer)))
  97. defer wg.Done()
  98. //map--k为pn,ptn,pc,ptc,buyer值 v为Id数组和lock
  99. for _, m := range pids {
  100. defer m.Lock.Unlock()
  101. }
  102. for _, id := range IDArr {
  103. defer id.Lock.Unlock()
  104. }
  105. bFindProject := false
  106. findPid := ""
  107. //获取完id,进行计算
  108. //定义两组
  109. comRes1 := []*Project{} //优先级最高的对比结果数组
  110. comRes2 := []*Project{} //优化级其次
  111. comRes3 := []*Project{}
  112. for _, v := range IDArr {
  113. comStr := ""
  114. compareProject := v.P
  115. compareProject.score = 0
  116. //问题出地LastTime!!!!!
  117. diffTime := int64(math.Abs(float64(info.Publishtime - compareProject.LastTime)))
  118. //代理机构完全不相同,直接新建项目
  119. if CheckContain(compareProject.Agency, info.Agency) == 3 {
  120. continue
  121. }
  122. //地区(省、市、区)不同,直接新建项目
  123. if ComparePlace(compareProject, info) {
  124. continue
  125. }
  126. info.PNBH = 0
  127. info.PCBH = 0
  128. info.PTCBH = 0
  129. compareStr, score := comparePNC(info, compareProject)
  130. resVal, pjVal := Select(compareStr, info, compareProject)
  131. //---------------------------------------
  132. if resVal > 0 {
  133. compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount, score2 := compareBCTABB(info, compareProject, diffTime, score)
  134. //项目名称、项目编号、标题项目编号、采购单位、省、市、发布时间、代理机构
  135. comStr = compareStr + compareBuyer + compareCity + compareTime + compareAgency + compareBudget + compareBidmount
  136. compareProject.comStr = comStr
  137. compareProject.pjVal = pjVal
  138. compareProject.resVal = resVal
  139. //log.Println(compareProject.comStr)
  140. eqV := compareResult(resVal, pjVal, score2, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount)
  141. if eqV == 1 {
  142. comRes1 = append(comRes1, compareProject)
  143. } else if eqV == 2 {
  144. comRes2 = append(comRes2, compareProject)
  145. } else if eqV == 3 {
  146. comRes3 = append(comRes3, compareProject)
  147. }
  148. }
  149. }
  150. //--------------------------------对比完成-----------------------
  151. //更新数组、更新项目
  152. for kv, resN := range [][]*Project{comRes1, comRes2, comRes3} {
  153. if len(resN) > 0 {
  154. if len(resN) > 1 {
  155. sort.Slice(resN, func(i, j int) bool {
  156. return resN[i].score > resN[j].score
  157. })
  158. }
  159. resArr := []*Project{}
  160. for _, res := range resN {
  161. resArr = append(resArr, res)
  162. }
  163. if len(resArr) > 0 {
  164. bFindProject = true
  165. findPid = resArr[0].Id.Hex()
  166. UpdateProject(tmp, info, resArr[0], kv+1, resArr[0].comStr)
  167. for k2, bv := range []int{bpn, bpc, bptc, bpb} {
  168. if bv > -1 {
  169. pids[bv].Arr = append(pids[bv].Arr, findPid)
  170. if k2 == 0 {
  171. if resArr[0].ProjectName == "" {
  172. resArr[0].ProjectName = info.ProjectName
  173. } else {
  174. if resArr[0].MPN == nil {
  175. resArr[0].MPN = []string{info.ProjectName}
  176. } else {
  177. resArr[0].MPN = append(resArr[0].MPN, info.ProjectName)
  178. }
  179. }
  180. } else if k2 < 3 {
  181. if resArr[0].ProjectCode == "" {
  182. resArr[0].ProjectCode = util.If(k2 == 1, info.ProjectCode, info.PTC).(string)
  183. } else {
  184. if resArr[0].MPC == nil {
  185. resArr[0].MPC = []string{util.If(k2 == 1, info.ProjectCode, info.PTC).(string)}
  186. } else {
  187. resArr[0].MPC = append(resArr[0].MPC, util.If(k2 == 1, info.ProjectCode, info.PTC).(string))
  188. }
  189. }
  190. } else {
  191. if resArr[0].Buyer == "" {
  192. resArr[0].Buyer = info.Buyer
  193. }
  194. }
  195. }
  196. }
  197. } else {
  198. bFindProject = false
  199. findPid = ""
  200. }
  201. break
  202. }
  203. }
  204. if !bFindProject {
  205. id, p1 := NewProject(tmp, info)
  206. AllIdsMapLock.Lock()
  207. AllIdsMap[id] = &ID{Id: id, P: p1}
  208. AllIdsMapLock.Unlock()
  209. for _, m := range pids {
  210. m.Arr = append(m.Arr, id)
  211. }
  212. }
  213. }
  214. func compareBCTABB(info *Info, cp *Project, diffTime int64, score int) (compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string, score2 int) {
  215. compareBuyer = "D"
  216. if len([]rune(info.Buyer)) > 3 && len([]rune(cp.Buyer)) > 3 {
  217. v := CheckContain(info.Buyer, cp.Buyer)
  218. if v == 1 {
  219. compareBuyer = "A"
  220. score += 3
  221. } else {
  222. //v1 := CosineSimilar(info.Buyer, cp.Buyer)
  223. if v == 2 {
  224. compareBuyer = "B"
  225. score += 1
  226. } else {
  227. compareBuyer = "C"
  228. }
  229. }
  230. }
  231. //---------------------------------------
  232. compareCity = ""
  233. if info.Area != "全国" && info.Area != "" && info.Area == cp.Area {
  234. compareCity += "A"
  235. score += 2
  236. } else if info.Area == "全国" || cp.Area == "全国" {
  237. compareCity += "B"
  238. score += 1
  239. } else {
  240. compareCity += "C"
  241. }
  242. if compareCity != "C" {
  243. if info.City != "" && info.City == cp.City {
  244. compareCity += "A"
  245. score += 2
  246. } else {
  247. if info.Area == "全国" || cp.Area == "全国" {
  248. compareCity += "B"
  249. } else if info.City == compareCity {
  250. compareCity += "B"
  251. } else {
  252. compareCity += "C"
  253. }
  254. }
  255. } else {
  256. compareCity += "C"
  257. }
  258. score2 = 0
  259. if compareCity == "AA" {
  260. if info.District != "" && info.District == cp.District {
  261. score2 = 1
  262. }
  263. }
  264. compareTime = "D"
  265. if diffTime < 45*86400 {
  266. compareTime = "A"
  267. score += 2
  268. } else if diffTime < 90*86400 {
  269. compareTime = "B"
  270. score += 1
  271. }
  272. compareAgency = "D"
  273. if info.Agency != "" {
  274. if info.Agency == cp.Agency {
  275. compareAgency = "A"
  276. score += 2
  277. score2 += 1
  278. } else if cp.Agency != "" {
  279. if strings.Contains(info.Agency, cp.Agency) || strings.Contains(cp.Agency, info.Agency) {
  280. compareAgency = "B"
  281. score += 1
  282. score2 += 1
  283. } else {
  284. compareAgency = "C"
  285. }
  286. }
  287. }
  288. compareBudget = "C"
  289. if info.Budget > 0 && (info.Budget == cp.Budget || (cp.Bidamount > 0 && info.Budget > cp.Bidamount && (info.Budget-cp.Bidamount) < (0.15*info.Budget))) {
  290. compareBudget = "A"
  291. score += 1
  292. score2 += 1
  293. }
  294. // else if info.Budget == 0 && cp.Budget == 0 {
  295. // compareBudget = "B"
  296. // }
  297. compareBidmount = "C"
  298. if info.Bidamount > 0 && (info.Bidamount == cp.Bidamount || (cp.Budget > 0 && cp.Budget > info.Bidamount && (cp.Budget-info.Bidamount) < 0.15*cp.Budget)) {
  299. compareBidmount = "A"
  300. score += 1
  301. score2 += 1
  302. }
  303. // else if info.Bidamount == 0 && cp.Bidamount == 0 {
  304. // compareBidmount = "B"
  305. // }
  306. cp.score = score
  307. return
  308. }
  309. func compareResult(resVal, pjVal, score2 int, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string) int {
  310. eqV := 0
  311. switch resVal {
  312. case 3:
  313. if pjVal == 3 && comStr[3:] != "CCCDCCC" {
  314. eqV = 1
  315. } else if compareBuyer < "C" {
  316. if pjVal > 1 {
  317. eqV = 1
  318. } else { //if (compareCity[1:1] != "C" || compareTime != "D") && score2 > 0
  319. eqV = 2
  320. }
  321. } else if compareBuyer == "D" {
  322. if pjVal > 1 && (compareCity[1:1] != "C" || score2 > 0) {
  323. eqV = 2
  324. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  325. eqV = 3
  326. }
  327. } else {
  328. if pjVal == 3 && (score2 > 0 || compareCity[1:1] != "C") {
  329. eqV = 2
  330. } else if pjVal == 2 && compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  331. eqV = 3
  332. } else if compareCity == "AA" && compareTime == "A" && score2 > 0 {
  333. eqV = 3
  334. }
  335. }
  336. case 2:
  337. if compareBuyer < "C" {
  338. if pjVal > 1 {
  339. eqV = 2
  340. } else if compareCity[1:1] != "C" && compareTime == "A" || score2 > 0 {
  341. eqV = 3
  342. }
  343. } else if compareBuyer == "D" {
  344. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  345. eqV = 2
  346. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  347. eqV = 3
  348. }
  349. } else {
  350. if pjVal > 1 && compareTime == "A" && (score2 > 0 || compareCity[1:1] != "C") {
  351. eqV = 2
  352. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  353. eqV = 3
  354. }
  355. }
  356. case 1:
  357. if compareBuyer < "C" {
  358. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  359. eqV = 2
  360. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  361. eqV = 3
  362. }
  363. } else if compareBuyer == "D" {
  364. if pjVal > 1 && compareTime == "A" && (score2 > 0 || compareCity[1:1] != "C") {
  365. eqV = 2
  366. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  367. eqV = 3
  368. }
  369. } else {
  370. if pjVal > 1 && compareTime == "A" && score2 > 0 && (compareBudget == "A" || compareBidmount == "A") && compareCity[1:1] != "C" {
  371. eqV = 3
  372. }
  373. }
  374. }
  375. return eqV
  376. }
  377. func ComparePlace(project *Project, info *Info) bool {
  378. if info.Area == "全国" || info.Area == "" {
  379. return false
  380. }
  381. if project.Area == "全国" || project.Area == "" {
  382. return false
  383. }
  384. if info.Area == project.Area {
  385. if info.City == "" || project.City == "" {
  386. return false
  387. } else if info.City == project.City {
  388. return false
  389. }
  390. } else {
  391. return true
  392. }
  393. return true
  394. }
  395. func NewCachePinfo(id primitive.ObjectID, thisinfo *Info) Project {
  396. p1 := Project{
  397. Id: id,
  398. Ids: []string{thisinfo.Id},
  399. ProjectName: thisinfo.ProjectName,
  400. ProjectCode: thisinfo.ProjectCode,
  401. Buyer: thisinfo.Buyer,
  402. Agency: thisinfo.Agency,
  403. Area: thisinfo.Area,
  404. City: thisinfo.City,
  405. District: thisinfo.District,
  406. MPN: []string{},
  407. MPC: []string{},
  408. FirstTime: thisinfo.Publishtime,
  409. LastTime: thisinfo.Publishtime,
  410. Budget: thisinfo.Budget,
  411. Bidamount: thisinfo.Bidamount,
  412. }
  413. if thisinfo.LenPTC > 5 {
  414. p1.MPC = append(p1.MPC, thisinfo.PTC)
  415. }
  416. return p1
  417. }
  418. func NewProject(tmp map[string]interface{}, thisinfo *Info) (string, *Project) {
  419. pId := mongodb.StringTOBsonId(thisinfo.Id)
  420. set := map[string]interface{}{}
  421. set["_id"] = pId
  422. set["sourceinfoid"] = thisinfo.Id
  423. for _, f := range FIELDS {
  424. if tmp[f] != nil && tmp[f] != "" {
  425. set[f] = tmp[f]
  426. }
  427. }
  428. bidopentime := util.Int64All(tmp["bidopentime"])
  429. if bidopentime > 0 {
  430. set["bidopentime"] = bidopentime
  431. }
  432. p1 := NewCachePinfo(pId, thisinfo)
  433. now := time.Now().Unix()
  434. set["createtime"] = now
  435. set["firsttime"] = tmp["publishtime"]
  436. set["lasttime"] = tmp["publishtime"]
  437. set["ids"] = []string{thisinfo.Id}
  438. if thisinfo.TopType == "招标" {
  439. //if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  440. set["zbtime"] = tmp["publishtime"]
  441. p1.Zbtime = util.Int64All(tmp["publishtime"])
  442. set["zb_href"] = tmp["href"]
  443. set["zb_jybxhref"] = fmt.Sprintf(config.Conf.Serve.JyHref, util.CommonEncodeArticle("content", thisinfo.Id))
  444. set["zb_updatetime"] = util.Int64All(tmp["publishtime"])
  445. set["zb_infoid"] = thisinfo.Id
  446. set["bidtype"] = thisinfo.TopType
  447. //}
  448. } else if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "合同" || thisinfo.SubType == "验收" ||
  449. thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  450. set["jgtime"] = tmp["publishtime"]
  451. p1.Jgtime = thisinfo.Publishtime
  452. set["href"] = tmp["href"]
  453. set["jybxhref"] = fmt.Sprintf(config.Conf.Serve.JyHref, util.CommonEncodeArticle("content", thisinfo.Id))
  454. set["updatetime"] = util.Int64All(tmp["publishtime"])
  455. set["infoid"] = thisinfo.Id
  456. set["bidstatus"] = thisinfo.SubType
  457. }
  458. if len(thisinfo.Subscopeclass) > 0 {
  459. set["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  460. }
  461. if len(thisinfo.Winners) > 0 {
  462. set["s_winner"] = strings.Join(thisinfo.Winners, ",")
  463. p1.Winners = strings.Join(thisinfo.Winners, ",")
  464. if util.ObjToString(tmp["winnertel"]) != "" {
  465. set["winnertel"] = tmp["winnertel"]
  466. }
  467. if util.ObjToString(tmp["winnerperson"]) != "" {
  468. set["winnerperson"] = tmp["winnerperson"]
  469. }
  470. }
  471. if util.ObjToString(tmp["scenetag"]) != "" {
  472. p1.SceneTag = util.ObjToString(tmp["scenetag"])
  473. set["scenetag"] = util.ObjToString(tmp["scenetag"])
  474. }
  475. if util.ObjToString(tmp["buyertag"]) != "" {
  476. p1.BuyerTag = util.ObjToString(tmp["buyertag"])
  477. set["buyertag"] = util.ObjToString(tmp["buyertag"])
  478. }
  479. if util.ObjToString(tmp["tagname"]) != "" {
  480. p1.TagName = util.ObjToString(tmp["tagname"])
  481. set["tagname"] = util.ObjToString(tmp["tagname"])
  482. }
  483. if util.ObjToString(tmp["tagname_2"]) != "" {
  484. p1.TagName2 = util.ObjToString(tmp["tagname_2"])
  485. set["tagname_2"] = util.ObjToString(tmp["tagname_2"])
  486. }
  487. if util.ObjToString(tmp["tagname_3"]) != "" {
  488. p1.TagName3 = util.ObjToString(tmp["tagname_3"])
  489. set["tagname_3"] = util.ObjToString(tmp["tagname_3"])
  490. }
  491. if tmp["budget"] != nil {
  492. set["budget"] = thisinfo.Budget
  493. p1.Budget = thisinfo.Budget
  494. }
  495. if tmp["bidamount"] != nil {
  496. set["bidamount"] = thisinfo.Bidamount
  497. p1.Bidamount = thisinfo.Bidamount
  498. }
  499. if p1.Bidamount > 0 {
  500. set["sortprice"] = p1.Bidamount
  501. } else {
  502. if p1.Budget > 0 {
  503. set["sortprice"] = p1.Budget
  504. }
  505. }
  506. push := PushListInfo(tmp, thisinfo.Id)
  507. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  508. set["list"] = []bson.M{
  509. push,
  510. }
  511. updatePool <- []map[string]interface{}{
  512. {
  513. "_id": pId,
  514. },
  515. {
  516. "$set": set,
  517. },
  518. }
  519. return pId.Hex(), &p1
  520. }
  521. // 项目中list的信息
  522. func PushListInfo(tmp map[string]interface{}, infoid string) bson.M {
  523. res := bson.M{
  524. "infoid": infoid,
  525. }
  526. for _, k := range INFOFIELDS {
  527. if tmp[k] != nil {
  528. res[k] = tmp[k]
  529. }
  530. }
  531. return res
  532. }
  533. func UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *Project, weight int, comStr string) {
  534. if BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
  535. log.Info("repeat", zap.String("info", thisinfo.Id), zap.Any("pid", pInfo.Id))
  536. return
  537. }
  538. set := map[string]interface{}{}
  539. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  540. if thisinfo.Bidopentime > pInfo.Bidopentime {
  541. pInfo.Bidopentime = thisinfo.Bidopentime
  542. set["bidopentime"] = pInfo.Bidopentime
  543. }
  544. //相同城市的公告才会合并到一起(全国列外)
  545. if thisinfo.Area != "全国" {
  546. pInfo.Area = thisinfo.Area
  547. set["area"] = thisinfo.Area
  548. if thisinfo.City != "" {
  549. pInfo.City = thisinfo.City
  550. set["city"] = thisinfo.City
  551. }
  552. if thisinfo.District != "" {
  553. pInfo.District = thisinfo.District
  554. set["district"] = thisinfo.District
  555. }
  556. }
  557. //项目名称
  558. //if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  559. if pInfo.ProjectName == "" && thisinfo.ProjectName != "" {
  560. pInfo.ProjectName = thisinfo.ProjectName
  561. set["projectname"] = thisinfo.ProjectName
  562. }
  563. //7--项目编号
  564. //if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  565. if pInfo.ProjectCode == "" && thisinfo.ProjectCode != "" {
  566. pInfo.ProjectCode = thisinfo.ProjectCode
  567. set["projectcode"] = thisinfo.ProjectCode
  568. }
  569. //7--采购单位
  570. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  571. pInfo.Buyer = thisinfo.Buyer
  572. set["buyer"] = thisinfo.Buyer
  573. pInfo.Buyerclass = thisinfo.Buyerclass
  574. set["buyerclass"] = thisinfo.Buyerclass
  575. }
  576. if pInfo.Buyer == "" {
  577. pInfo.Buyerclass = ""
  578. set["buyerclass"] = ""
  579. }
  580. //采购单位联系人
  581. if thisinfo.Buyerperson != "" {
  582. pInfo.Buyerperson = thisinfo.Buyerperson
  583. set["buyerperson"] = thisinfo.Buyerperson
  584. }
  585. //采购单位電話
  586. if thisinfo.Buyertel != "" {
  587. pInfo.Buyertel = thisinfo.Buyertel
  588. set["buyertel"] = pInfo.Buyertel
  589. }
  590. //8--代理机构
  591. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  592. pInfo.Agency = thisinfo.Agency
  593. set["agency"] = thisinfo.Agency
  594. }
  595. if util.ObjToString(tmp["agencyperson"]) != "" {
  596. set["agencyperson"] = tmp["agencyperson"]
  597. }
  598. if util.ObjToString(tmp["agencytel"]) != "" {
  599. set["agencytel"] = tmp["agencytel"]
  600. }
  601. if len(thisinfo.Topscopeclass) > 0 {
  602. sort.Strings(pInfo.Topscopeclass)
  603. for _, k := range thisinfo.Topscopeclass {
  604. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  605. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  606. sort.Strings(pInfo.Topscopeclass)
  607. }
  608. }
  609. set["topscopeclass"] = pInfo.Topscopeclass
  610. }
  611. if len(thisinfo.Subscopeclass) > 0 {
  612. sort.Strings(pInfo.Subscopeclass)
  613. for _, k := range thisinfo.Subscopeclass {
  614. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  615. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  616. sort.Strings(pInfo.Subscopeclass)
  617. }
  618. }
  619. set["subscopeclass"] = pInfo.Subscopeclass
  620. set["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  621. }
  622. if len(thisinfo.Winners) > 0 {
  623. var winners []string
  624. if pInfo.Winners == "" {
  625. set["winner"] = util.ObjToString(tmp["winner"])
  626. for _, k := range thisinfo.Winners {
  627. if k == "" {
  628. continue
  629. }
  630. if BinarySearch(winners, k) == -1 {
  631. winners = append(winners, k)
  632. }
  633. }
  634. } else {
  635. winners = strings.Split(pInfo.Winners, ",")
  636. for _, k := range thisinfo.Winners {
  637. if k == "" {
  638. continue
  639. }
  640. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  641. if BinarySearch(winners, k) != -1 {
  642. deleteSlice(winners, k, "")
  643. }
  644. } else {
  645. if BinarySearch(winners, k) == -1 {
  646. winners = append(winners, k)
  647. }
  648. }
  649. }
  650. }
  651. set["s_winner"] = strings.Join(util.ObjArrToStringArr(Duplicate(winners)), ",")
  652. if util.ObjToString(tmp["winnertel"]) != "" {
  653. set["winnertel"] = tmp["winnertel"]
  654. }
  655. if util.ObjToString(tmp["winnerperson"]) != "" {
  656. set["winnerperson"] = tmp["winnerperson"]
  657. }
  658. }
  659. if thisinfo.TopType == "招标" {
  660. set["zb_href"] = tmp["href"]
  661. set["zb_jybxhref"] = fmt.Sprintf(config.Conf.Serve.JyHref, util.CommonEncodeArticle("content", thisinfo.Id))
  662. set["zb_infoid"] = thisinfo.Id
  663. set["zb_updatetime"] = util.Int64All(tmp["publishtime"])
  664. set["bidtype"] = thisinfo.TopType
  665. } else if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "合同" || thisinfo.SubType == "验收" ||
  666. thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  667. set["href"] = tmp["href"]
  668. set["jybxhref"] = fmt.Sprintf(config.Conf.Serve.JyHref, util.CommonEncodeArticle("content", thisinfo.Id))
  669. set["updatetime"] = util.Int64All(tmp["publishtime"])
  670. set["infoid"] = thisinfo.Id
  671. set["bidstatus"] = thisinfo.SubType
  672. }
  673. if util.ObjToString(tmp["scenetag"]) != "" && pInfo.SceneTag != "" {
  674. pInfo.SceneTag = util.ObjToString(tmp["scenetag"])
  675. set["scenetag"] = util.ObjToString(tmp["scenetag"])
  676. }
  677. if util.ObjToString(tmp["buyertag"]) != "" && pInfo.BuyerTag != "" {
  678. pInfo.BuyerTag = util.ObjToString(tmp["buyertag"])
  679. set["buyertag"] = util.ObjToString(tmp["buyertag"])
  680. }
  681. if util.ObjToString(tmp["tagname"]) != "" && pInfo.TagName != "" {
  682. pInfo.TagName = util.ObjToString(tmp["tagname"])
  683. set["tagname"] = util.ObjToString(tmp["tagname"])
  684. }
  685. if util.ObjToString(tmp["tagname_2"]) != "" && pInfo.TagName2 != "" {
  686. pInfo.TagName2 = util.ObjToString(tmp["tagname_2"])
  687. set["tagname_2"] = util.ObjToString(tmp["tagname_2"])
  688. }
  689. if util.ObjToString(tmp["tagname_3"]) != "" && pInfo.TagName3 != "" {
  690. pInfo.TagName3 = util.ObjToString(tmp["tagname_3"])
  691. set["tagname_3"] = util.ObjToString(tmp["tagname_3"])
  692. }
  693. if thisinfo.Budget > 0 {
  694. set["budget"] = thisinfo.Budget
  695. pInfo.Budget = thisinfo.Budget
  696. }
  697. if thisinfo.Bidamount > 0 {
  698. set["bidamount"] = thisinfo.Bidamount
  699. pInfo.Bidamount = thisinfo.Bidamount
  700. }
  701. if pInfo.Bidamount > 0 {
  702. set["sortprice"] = pInfo.Bidamount
  703. } else {
  704. if pInfo.Budget > 0 {
  705. set["sortprice"] = pInfo.Budget
  706. }
  707. }
  708. update := map[string]interface{}{}
  709. if len(set) > 0 {
  710. update["$set"] = set
  711. }
  712. push := PushListInfo(tmp, thisinfo.Id)
  713. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  714. push["compareStr"] = comStr
  715. push["resVal"] = pInfo.resVal
  716. push["pjVal"] = pInfo.pjVal
  717. update["$push"] = map[string]interface{}{
  718. "list": push,
  719. "ids": thisinfo.Id,
  720. }
  721. if len(update) > 0 {
  722. updateInfo := []map[string]interface{}{
  723. {
  724. "_id": pInfo.Id,
  725. },
  726. update,
  727. }
  728. updatePool <- updateInfo
  729. }
  730. }