project.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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. }
  344. // else if info.Budget == 0 && cp.Budget == 0 {
  345. // compareBudget = "B"
  346. // }
  347. compareBidmount = "C"
  348. if info.Bidamount > 0 && (info.Bidamount == cp.Bidamount || (cp.Budget > 0 && cp.Budget > info.Bidamount && (cp.Budget-info.Bidamount) < 0.1*cp.Budget)) {
  349. compareBidmount = "A"
  350. score += 1
  351. score2 += 1
  352. }
  353. // else if info.Bidamount == 0 && cp.Bidamount == 0 {
  354. // compareBidmount = "B"
  355. // }
  356. cp.score = score
  357. return
  358. }
  359. var FIELDS = []string{
  360. "area",
  361. "city",
  362. "district",
  363. "projectname",
  364. "projectcode",
  365. "buyer",
  366. "buyerclass",
  367. "buyerperson",
  368. "buyertel",
  369. "winner",
  370. "budget",
  371. "bidamount",
  372. //"bidstatus",
  373. "agency",
  374. "projectscope",
  375. "bidopentime",
  376. "topscopeclass",
  377. "subscopeclass",
  378. "winnerorder",
  379. "package",
  380. }
  381. var bidtype = map[string]string{
  382. "招标": "招标",
  383. "邀标": "邀标",
  384. "询价": "询价",
  385. "竞谈": "竞谈",
  386. "单一": "单一",
  387. "竞价": "竞价",
  388. }
  389. var bidstatus = map[string]string{
  390. "中标": "中标",
  391. "成交": "成交",
  392. "废标": "废标",
  393. "流标": "流标",
  394. }
  395. //招标时间zbtime、中标时间jgtime、项目状态bidstatus、招标类型bidtype、最后发布时间lasttime、首次发布时间firsttime
  396. func (p *ProjectTask) NewProject(tmp map[string]interface{}, thisinfo *Info) (string, *ProjectInfo) {
  397. pId := bson.NewObjectId()
  398. p1 := p.NewCachePinfo(pId, thisinfo)
  399. set := map[string]interface{}{}
  400. set["_id"] = pId
  401. for _, f := range FIELDS {
  402. if tmp[f] != nil {
  403. set[f] = tmp[f]
  404. }
  405. }
  406. if thisinfo.ProjectName != "" {
  407. set["s_projectname"] = tmp["projectname"] //兼容老版本
  408. }
  409. now := time.Now().Unix()
  410. set["createtime"] = now
  411. set["sourceinfoid"] = thisinfo.Id
  412. set["sourceinfourl"] = tmp["href"]
  413. set["firsttime"] = tmp["publishtime"]
  414. set["lasttime"] = tmp["publishtime"]
  415. set["pici"] = p.pici
  416. set["ids"] = []string{thisinfo.Id}
  417. if thisinfo.TopType == "招标" {
  418. set["zbtime"] = tmp["publishtime"]
  419. } else if thisinfo.TopType == "结果" {
  420. set["jgtime"] = tmp["publishtime"]
  421. }
  422. //招标类型
  423. bt := bidtype[thisinfo.SubType]
  424. if bt == "" {
  425. bt = "招标"
  426. }
  427. set["bidtype"] = bt
  428. bs, _ := tmp["bidstatus"].(string)
  429. if bidstatus[bs] != "" {
  430. set["bidstatus"] = bs
  431. }
  432. if set["bidstatus"] == nil && thisinfo.TopType == "结果" {
  433. set["bidstatus"] = thisinfo.SubType
  434. }
  435. if len(thisinfo.Subscopeclass) > 0 {
  436. s_subscopeclass := strings.Join(thisinfo.Subscopeclass, ",")
  437. set["s_subscopeclass"] = s_subscopeclass
  438. }
  439. if len(thisinfo.Winners) > 0 {
  440. set["s_winner"] = strings.Join(thisinfo.Winners, ",")
  441. p1.Winners = thisinfo.Winners
  442. }
  443. push := p.PushListInfo(tmp)
  444. set["list"] = []bson.M{
  445. push,
  446. }
  447. p.savePool <- set
  448. // []map[string]interface{}{
  449. // map[string]interface{}{
  450. // "_id": pId,
  451. // },
  452. // map[string]interface{}{
  453. // "$set": ,
  454. // },
  455. // }
  456. return pId.Hex(), &p1
  457. }
  458. var INFOFIELDS = []string{
  459. "projectname",
  460. "projectcode",
  461. "title",
  462. "href",
  463. "publishtime",
  464. "comeintime",
  465. "bidopentime",
  466. "toptype",
  467. "subtype",
  468. "buyer",
  469. "buyerclass",
  470. "agency",
  471. "winner",
  472. "budget",
  473. "bidamount",
  474. "topscopeclass",
  475. "subscopclass",
  476. "infoformat",
  477. "buyerperson",
  478. "buyertel",
  479. }
  480. //项目中list的信息
  481. func (p *ProjectTask) PushListInfo(tmp map[string]interface{}) bson.M {
  482. res := bson.M{
  483. "infoid": qu.BsonIdToSId(tmp["_id"]),
  484. }
  485. for _, k := range INFOFIELDS {
  486. if tmp[k] != nil {
  487. res[k] = tmp[k]
  488. }
  489. }
  490. return res
  491. }
  492. //生成存放在内存中的对象
  493. func (p *ProjectTask) NewCachePinfo(id bson.ObjectId, thisinfo *Info) ProjectInfo {
  494. p1 := ProjectInfo{
  495. Id: id,
  496. Ids: []string{thisinfo.Id},
  497. ProjectName: thisinfo.ProjectName,
  498. ProjectCode: thisinfo.ProjectCode,
  499. Buyer: thisinfo.Buyer,
  500. Buyerclass: thisinfo.Buyerclass,
  501. Buyerperson: thisinfo.Buyerperson,
  502. Buyertel: thisinfo.Buyertel,
  503. Topscopeclass: thisinfo.Topscopeclass,
  504. Subscopeclass: thisinfo.Subscopeclass,
  505. Agency: thisinfo.Agency,
  506. Area: thisinfo.Area,
  507. City: thisinfo.City,
  508. District: thisinfo.District,
  509. MPN: []string{},
  510. MPC: []string{},
  511. HasPackage: thisinfo.HasPackage,
  512. FirstTime: thisinfo.Publishtime,
  513. LastTime: thisinfo.Publishtime,
  514. Budget: thisinfo.Budget,
  515. Bidamount: thisinfo.Bidamount,
  516. }
  517. if thisinfo.LenPTC > 5 {
  518. p1.MPC = append(p1.MPC, thisinfo.PTC)
  519. }
  520. return p1
  521. }
  522. //更新项目
  523. func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectInfo, weight int, comStr string) {
  524. if p.currentType != "ql" {
  525. if BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
  526. log.Println("repeat", thisinfo.Id)
  527. return
  528. }
  529. }
  530. set := map[string]interface{}{}
  531. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  532. //1--firsttime
  533. if thisinfo.Publishtime < pInfo.FirstTime && thisinfo.Publishtime > 0 {
  534. pInfo.FirstTime = thisinfo.Publishtime
  535. set["firsttime"] = thisinfo.Publishtime
  536. if thisinfo.TopType == "招标" {
  537. set["zbtime"] = tmp["publishtime"]
  538. }
  539. }
  540. //2--lasttime
  541. if thisinfo.Publishtime > pInfo.LastTime {
  542. pInfo.LastTime = thisinfo.Publishtime
  543. set["lasttime"] = thisinfo.Publishtime
  544. bt := bidtype[thisinfo.SubType]
  545. if bt != "" {
  546. set["bidtype"] = bt
  547. }
  548. if thisinfo.TopType == "结果" {
  549. set["bidstatus"] = thisinfo.SubType
  550. set["jgtime"] = tmp["publishtime"]
  551. }
  552. }
  553. //3\4\5--省、市、县
  554. if thisinfo.Area != "全国" {
  555. //xt := true
  556. if pInfo.Area == "全国" {
  557. pInfo.Area = thisinfo.Area
  558. set["area"] = thisinfo.Area
  559. } else if pInfo.Area != thisinfo.Area {
  560. //xt = false
  561. }
  562. if pInfo.City == "" && thisinfo.City != "" {
  563. pInfo.City = thisinfo.City
  564. set["city"] = thisinfo.City
  565. } else if pInfo.City != thisinfo.City {
  566. //xt = false
  567. }
  568. if thisinfo.District != "" && pInfo.District == "" {
  569. pInfo.District = thisinfo.District
  570. set["district"] = thisinfo.District
  571. }
  572. //省市县有不相同的
  573. // if !xt {
  574. // log.Println(pInfo.Area, pInfo.City, thisinfo.Area, thisinfo.District)
  575. // }
  576. }
  577. //6--项目名称
  578. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  579. pInfo.ProjectName = thisinfo.ProjectName
  580. set["projectname"] = thisinfo.ProjectName
  581. }
  582. //7--项目编号
  583. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  584. pInfo.ProjectCode = thisinfo.ProjectCode
  585. set["projectcode"] = thisinfo.ProjectCode
  586. }
  587. //7--采购单位
  588. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  589. pInfo.Buyer = thisinfo.Buyer
  590. set["buyer"] = thisinfo.Buyer
  591. }
  592. //8--代理机构
  593. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  594. pInfo.Agency = thisinfo.Agency
  595. set["agency"] = thisinfo.Agency
  596. }
  597. //9--采购单位联系人
  598. if thisinfo.Buyerperson != "" && strings.Index(pInfo.Buyerperson, thisinfo.Buyerperson) < 0 {
  599. pInfo.Buyerperson = thisinfo.Buyerperson
  600. set["buyerperson"] = pInfo.Buyerperson
  601. }
  602. //10--采购单位電話
  603. if thisinfo.Buyertel != "" && strings.Index(pInfo.Buyertel, thisinfo.Buyertel) < 0 {
  604. pInfo.Buyertel = thisinfo.Buyertel
  605. set["buyertel"] = pInfo.Buyertel
  606. }
  607. if thisinfo.Buyerclass != "" && pInfo.Buyerclass == "" {
  608. pInfo.Buyerclass = thisinfo.Buyerclass
  609. set["buyerclass"] = pInfo.Buyerclass
  610. }
  611. if thisinfo.Bidopentime > pInfo.Bidopentime {
  612. pInfo.Bidopentime = thisinfo.Bidopentime
  613. set["bidopentime"] = pInfo.Bidopentime
  614. }
  615. if thisinfo.Bidamount > 0 && pInfo.Bidamount < 1 {
  616. pInfo.Bidamount = thisinfo.Bidamount
  617. set["bidamount"] = pInfo.Bidamount
  618. }
  619. if thisinfo.Budget > 0 && pInfo.Budget < 1 { //多包的会有问题,没有进行合计。
  620. pInfo.Budget = thisinfo.Budget
  621. set["budget"] = pInfo.Budget
  622. }
  623. if len(thisinfo.Topscopeclass) > 0 {
  624. sort.Strings(pInfo.Topscopeclass)
  625. for _, k := range thisinfo.Topscopeclass {
  626. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  627. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  628. sort.Strings(pInfo.Topscopeclass)
  629. }
  630. }
  631. set["topscopeclass"] = pInfo.Topscopeclass
  632. }
  633. if len(thisinfo.Subscopeclass) > 0 {
  634. sort.Strings(pInfo.Subscopeclass)
  635. for _, k := range thisinfo.Subscopeclass {
  636. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  637. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  638. sort.Strings(pInfo.Subscopeclass)
  639. }
  640. }
  641. set["subscopeclass"] = pInfo.Subscopeclass
  642. set["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  643. }
  644. //winner
  645. if len(thisinfo.Winners) > 0 {
  646. sort.Strings(pInfo.Winners)
  647. for _, k := range thisinfo.Winners {
  648. if BinarySearch(pInfo.Winners, k) == -1 {
  649. pInfo.Winners = append(pInfo.Winners, k)
  650. sort.Strings(pInfo.Winners)
  651. }
  652. }
  653. set["winners"] = pInfo.Winners
  654. set["s_winner"] = strings.Join(pInfo.Winners, ",")
  655. }
  656. set["mpn"] = pInfo.MPN
  657. set["mpc"] = pInfo.MPC
  658. set["pici"] = p.pici
  659. if thisinfo.HasPackage {
  660. set["multipackage"] = 1
  661. } else {
  662. set["multipackage"] = 0
  663. }
  664. update := map[string]interface{}{}
  665. if len(set) > 0 {
  666. update["$set"] = set
  667. }
  668. //保留原数据吧
  669. push := p.PushListInfo(tmp)
  670. push["compareStr"] = comStr
  671. push["resVal"] = pInfo.resVal
  672. push["pjVal"] = pInfo.pjVal
  673. update["$push"] = map[string]interface{}{
  674. "list": push,
  675. "ids": thisinfo.Id,
  676. }
  677. if len(update) > 0 {
  678. updateInfo := []map[string]interface{}{
  679. map[string]interface{}{
  680. "_id": pInfo.Id,
  681. },
  682. update,
  683. }
  684. p.updatePool <- updateInfo
  685. }
  686. }