merge.go 20 KB

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