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