project.go 19 KB

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