project.go 18 KB

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