project.go 20 KB

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