update.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. package main
  2. import (
  3. "encoding/json"
  4. "github.com/go-xweb/log"
  5. "github.com/goinggo/mapstructure"
  6. "go.mongodb.org/mongo-driver/bson"
  7. "go.mongodb.org/mongo-driver/bson/primitive"
  8. "math"
  9. mu "mfw/util"
  10. "mongodb"
  11. qu "qfw/util"
  12. "reflect"
  13. "sort"
  14. "strings"
  15. "time"
  16. )
  17. /**
  18. 直接修改保存项目字段信息
  19. */
  20. func (p *ProjectTask) modifyUpdate(pid string, index, position int, tmpPro, modifyProMap map[string]interface{}) {
  21. // 1-0 备份
  22. tmpPro["reason"] = "直接在原有项目上修改字段信息"
  23. backupPro(tmpPro)
  24. delete(tmpPro, "reason")
  25. // 1-1 修改字段信息
  26. updateSet := UpdateValue(tmpPro, index, position, modifyProMap)
  27. updateSet["list"] = tmpPro["list"]
  28. // 1-2 修改mgo
  29. bol := MongoTool.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": updateSet})
  30. if bol {
  31. // 1-3 修改es
  32. by, _ := json.Marshal(map[string]interface{}{
  33. "query": map[string]interface{}{
  34. "_id": bson.M{
  35. "$gte": pid,
  36. "$lte": pid,
  37. }},
  38. "stype": "project",
  39. })
  40. qu.Debug(string(by))
  41. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  42. }
  43. // 修改内存
  44. var pro ProjectInfo
  45. err := mapstructure.Decode(tmpPro, &pro)
  46. if err != nil {
  47. qu.Debug(err)
  48. }
  49. p.AllIdsMapLock.Lock()
  50. if v, ok := p.AllIdsMap[pid]; ok {
  51. v.P = &pro
  52. }
  53. p.AllIdsMapLock.Unlock()
  54. p.printMemPro(pid)
  55. }
  56. func (p *ProjectTask) mergeAndModify(pInfoId string, index, position int, tmp map[string]interface{}, tmpPro map[string]interface{}, modifyMap map[string]interface{}) {
  57. proList := []interface{}(tmpPro["list"].(primitive.A))
  58. info := ParseInfo(tmp)
  59. //项目中list大小等于1
  60. if len(proList) == 1 {
  61. log.Println("list大小等于1 合并", "------1------")
  62. // 2.1 重新合并
  63. merge := p.ReMerge(info, tmp, tmpPro)
  64. if merge {
  65. //合并到新项目中
  66. //删除老项目
  67. p.AllIdsMapLock.Lock()
  68. delete(p.AllIdsMap, pInfoId)
  69. p.AllIdsMapLock.Unlock()
  70. delOldPro(pInfoId)
  71. // 2.2 备份
  72. tmpPro["reason"] = "删除原有项目,修改合并到新的项目中"
  73. backupPro(tmpPro)
  74. } else {
  75. //没有合并到新项目中
  76. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  77. // 修改内存
  78. var pro ProjectInfo
  79. err := mapstructure.Decode(tmpPro, &pro)
  80. if err != nil {
  81. qu.Debug(err)
  82. }
  83. p.AllIdsMapLock.Lock()
  84. if v, ok := p.AllIdsMap[pInfoId]; ok {
  85. v.P = &pro
  86. }
  87. p.AllIdsMapLock.Unlock()
  88. }
  89. }else if index == 0 {
  90. // 招标公告信息在原有项目中位于第1个
  91. merge := p.ReMerge(info, tmp, tmpPro)
  92. if merge {
  93. // 合并到新项目中
  94. // 该条招标公告信息重新参与合并,该项目的其它招标公告信息逐条参与合并
  95. tmpPro["reason"] = "修改list中第一个条招标公告信息"
  96. backupPro(tmpPro)
  97. delete(tmpPro, "reason")
  98. proList = deleteSlice1(proList, proList[0])
  99. p.AllIdsMapLock.Lock()
  100. Id := p.AllIdsMap[pInfoId]
  101. p.AllIdsMapLock.Unlock()
  102. proMem := Id.P
  103. flag := true // 标记是否需要删除原有项目信息
  104. for _, v := range proList{
  105. v1 := v.(map[string]interface{})
  106. temp := MongoTool.FindById(ExtractColl, qu.ObjToString(v1["infoid"]))
  107. tempInfo := ParseInfo(temp)
  108. if flag {
  109. merge := p.ReMerge(tempInfo, temp, tmpPro)
  110. if !merge {
  111. flag = false
  112. break
  113. }
  114. }
  115. }
  116. if flag {
  117. delOldPro(pInfoId)
  118. }else {
  119. //合并到原有项目中, 不用继续重新合并, 原有项目内部合并即可
  120. p.innerMerge(proList, tmpPro)
  121. bol := MongoTool.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
  122. if bol {
  123. by, _ := json.Marshal(map[string]interface{}{
  124. "query": map[string]interface{}{
  125. "_id": bson.M{
  126. "$gte": pInfoId,
  127. "$lte": pInfoId,
  128. }},
  129. "stype": "project",
  130. })
  131. qu.Debug(string(by))
  132. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  133. }
  134. // 修改内存
  135. p.AllIdsMapLock.Lock()
  136. if v, ok := p.AllIdsMap[pInfoId]; ok {
  137. v.P = proMem
  138. }
  139. p.AllIdsMapLock.Unlock()
  140. }
  141. }else {
  142. //没有合并到新项目中,更新list字段,有条件更新项目外围字段
  143. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  144. // 修改内存
  145. var pro ProjectInfo
  146. err := mapstructure.Decode(tmpPro, &pro)
  147. if err != nil {
  148. qu.Debug(err)
  149. }
  150. p.AllIdsMapLock.Lock()
  151. if v, ok := p.AllIdsMap[pInfoId]; ok {
  152. v.P = &pro
  153. }
  154. p.AllIdsMapLock.Unlock()
  155. }
  156. }else if index == 1 {
  157. // 招标公告信息在原有项目中处于中间某一条
  158. merge := p.ReMerge(info, tmp, tmpPro)
  159. if merge {
  160. tmpPro["reason"] = "修改list中位于中间某一条招标公告信息"
  161. backupPro(tmpPro)
  162. delete(tmpPro, "reason")
  163. p.innerMerge1(proList, qu.ObjToString(tmp["infoid"]), tmpPro)
  164. bol := MongoTool.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
  165. if bol {
  166. by, _ := json.Marshal(map[string]interface{}{
  167. "query": map[string]interface{}{
  168. "_id": bson.M{
  169. "$gte": pInfoId,
  170. "$lte": pInfoId,
  171. }},
  172. "stype": "project",
  173. })
  174. qu.Debug(string(by))
  175. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  176. }
  177. }else {
  178. // 未合并到新项目中
  179. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  180. // 修改内存
  181. var pro ProjectInfo
  182. err := mapstructure.Decode(tmpPro, &pro)
  183. if err != nil {
  184. qu.Debug(err)
  185. }
  186. p.AllIdsMapLock.Lock()
  187. if v, ok := p.AllIdsMap[pInfoId]; ok {
  188. v.P = &pro
  189. }
  190. p.AllIdsMapLock.Unlock()
  191. }
  192. }else if index == 2 {
  193. // 招标公告信息在原有项目中位于最后一条
  194. merge := p.ReMerge(info, tmp, tmpPro)
  195. if merge {
  196. // 合并到新项目中
  197. tmpPro["reason"] = "修改list中最后一条招标公告信息"
  198. backupPro(tmpPro)
  199. w := len(proList) - 1
  200. proList = deleteSlice1(proList, proList[w])
  201. p.innerMerge(proList, tmpPro)
  202. bol := MongoTool.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
  203. if bol {
  204. by, _ := json.Marshal(map[string]interface{}{
  205. "query": map[string]interface{}{
  206. "_id": bson.M{
  207. "$gte": pInfoId,
  208. "$lte": pInfoId,
  209. }},
  210. "stype": "project",
  211. })
  212. qu.Debug(string(by))
  213. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  214. }
  215. }else {
  216. // 未合并到新项目中
  217. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  218. // 修改内存
  219. var pro ProjectInfo
  220. err := mapstructure.Decode(tmpPro, &pro)
  221. if err != nil {
  222. qu.Debug(err)
  223. }
  224. p.AllIdsMapLock.Lock()
  225. if v, ok := p.AllIdsMap[pInfoId]; ok {
  226. v.P = &pro
  227. }
  228. p.AllIdsMapLock.Unlock()
  229. }
  230. }
  231. }
  232. // 删除
  233. func (p *ProjectTask) delJudge(infoid, pid string) {
  234. tmpPro := MongoTool.FindById(ProjectColl, pid)
  235. ids := []interface{}(tmpPro["ids"].(primitive.A))
  236. proList := []interface{}(tmpPro["list"].(primitive.A))
  237. if len(ids) == 1 {
  238. tmpPro["reason"] = "删除项目信息"
  239. backupPro(tmpPro)
  240. c := MongoTool.Delete(ProjectColl, pid)
  241. if c > 0 {
  242. //client := Es.GetEsConn()
  243. //defer Es.DestoryEsConn(client)
  244. //Es.DelById(Itype, Index, pid)
  245. }
  246. return
  247. }
  248. var index = -1 //0:第一个,1:中间,2:最后一个
  249. for i, v := range ids {
  250. if qu.ObjToString(v) == infoid {
  251. if i == 0 {
  252. index = 0
  253. }else if i == len(ids) - 1 {
  254. index = 2
  255. }else {
  256. index = 1
  257. }
  258. }
  259. }
  260. if index == 0 {
  261. tmpPro["reason"] = "删除list中第一个条招标公告信息"
  262. backupPro(tmpPro)
  263. delete(tmpPro, "reason")
  264. proList = deleteSlice1(proList, proList[0])
  265. var pro *ProjectInfo
  266. flag := true // 标记是否需要删除原有项目信息
  267. for _, v := range proList{
  268. v1 := v.(map[string]interface{})
  269. temp := MongoTool.FindById(ExtractColl, qu.ObjToString(v1["infoid"]))
  270. tempInfo := ParseInfo(temp)
  271. if flag {
  272. merge := p.ReMerge(tempInfo, temp, tmpPro)
  273. if !merge {
  274. flag = false
  275. break
  276. }
  277. }
  278. }
  279. if flag {
  280. delOldPro(pid)
  281. }else {
  282. tmpPro, pro = p.innerMerge(proList, tmpPro)
  283. bol := MongoTool.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
  284. if bol {
  285. by, _ := json.Marshal(map[string]interface{}{
  286. "query": map[string]interface{}{
  287. "_id": bson.M{
  288. "$gte": pid,
  289. "$lte": pid,
  290. }},
  291. "stype": "project",
  292. })
  293. qu.Debug(string(by))
  294. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  295. }
  296. // 修改内存
  297. p.AllIdsMapLock.Lock()
  298. if v, ok := p.AllIdsMap[pid]; ok {
  299. v.P = pro
  300. }
  301. p.AllIdsMapLock.Unlock()
  302. }
  303. }else if index == 1 {
  304. tmpPro["reason"] = "删除list中间某一条招标公告信息"
  305. backupPro(tmpPro)
  306. delete(tmpPro, "reason")
  307. var pro *ProjectInfo
  308. tmpPro, pro = p.innerMerge1(proList, infoid, tmpPro)
  309. bol := MongoTool.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
  310. if bol {
  311. by, _ := json.Marshal(map[string]interface{}{
  312. "query": map[string]interface{}{
  313. "_id": bson.M{
  314. "$gte": pid,
  315. "$lte": pid,
  316. }},
  317. "stype": "project",
  318. })
  319. qu.Debug(string(by))
  320. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  321. }
  322. // 内存
  323. p.AllIdsMapLock.Lock()
  324. if v, ok := p.AllIdsMap[pid]; ok {
  325. v.P = pro
  326. }
  327. p.AllIdsMapLock.Unlock()
  328. }else if index == 2 {
  329. tmpPro["reason"] = "删除list中最后一条招标公告信息"
  330. backupPro(tmpPro)
  331. delete(tmpPro, "reason")
  332. w := len(proList) - 1
  333. proList = deleteSlice1(proList, proList[w])
  334. var pro *ProjectInfo
  335. tmpPro, pro = p.innerMerge(proList, tmpPro)
  336. bol := MongoTool.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
  337. if bol {
  338. by, _ := json.Marshal(map[string]interface{}{
  339. "query": map[string]interface{}{
  340. "_id": bson.M{
  341. "$gte": pid,
  342. "$lte": pid,
  343. }},
  344. "stype": "project",
  345. })
  346. qu.Debug(string(by))
  347. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  348. }
  349. // 内存
  350. p.AllIdsMapLock.Lock()
  351. if v, ok := p.AllIdsMap[pid]; ok {
  352. v.P = pro
  353. }
  354. p.AllIdsMapLock.Unlock()
  355. }
  356. }
  357. // 合并
  358. func (p *ProjectTask) ReMerge(info *Info, tmp map[string]interface{}, tmpPro map[string]interface{}) bool {
  359. bpn, bpc, bptc, bpb, pids, _, IDArr := p.getCompareIds(info.ProjectName, info.ProjectCode, info.PTC, info.Buyer)
  360. defer p.wg.Done()
  361. for _, m := range pids {
  362. defer m.Lock.Unlock()
  363. }
  364. for _, id := range IDArr {
  365. defer id.Lock.Unlock()
  366. }
  367. bFindProject := false
  368. findPid := ""
  369. comRes1 := []*ProjectInfo{}
  370. comRes2 := []*ProjectInfo{}
  371. comRes3 := []*ProjectInfo{}
  372. for _, v := range IDArr {
  373. comStr := ""
  374. compareProject := v.P
  375. compareProject.score = 0
  376. diffTime := int64(math.Abs(float64(info.Publishtime - compareProject.LastTime)))
  377. if diffTime <= p.validTime {
  378. if CheckContain(compareProject.Agency, info.Agency) == 3 {
  379. continue
  380. }
  381. if ComparePlace(compareProject, info) {
  382. continue
  383. }
  384. info.PNBH = 0
  385. info.PCBH = 0
  386. info.PTCBH = 0
  387. compareStr, score := comparePNC(info, compareProject)
  388. resVal, pjVal := Select(compareStr, info, compareProject)
  389. if resVal > 0 {
  390. compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount, score2 := p.compareBCTABB(info, compareProject, diffTime, score)
  391. comStr = compareStr + compareBuyer + compareCity + compareTime + compareAgency + compareBudget + compareBidmount
  392. compareProject.comStr = comStr
  393. compareProject.pjVal = pjVal
  394. compareProject.resVal = resVal
  395. eqV := compareResult(resVal, pjVal, score2, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount)
  396. if eqV == 1 {
  397. comRes1 = append(comRes1, compareProject)
  398. } else if eqV == 2 {
  399. comRes2 = append(comRes2, compareProject)
  400. } else if eqV == 3 {
  401. comRes3 = append(comRes3, compareProject)
  402. }
  403. }
  404. }
  405. }
  406. //--------------------------------对比完成-----------------------
  407. for kv, resN := range [][]*ProjectInfo{comRes1, comRes2, comRes3} {
  408. if len(resN) > 0 {
  409. if len(resN) > 1 {
  410. sort.Slice(resN, func(i, j int) bool {
  411. return resN[i].score > resN[j].score
  412. })
  413. }
  414. ex := 0
  415. resArr := []*ProjectInfo{}
  416. for i, res := range resN {
  417. choose, e := p.CompareStatus(resN[i], info)
  418. if !choose {
  419. ex = e
  420. resArr = append(resArr, res)
  421. }
  422. }
  423. if len(resArr) > 0 {
  424. bFindProject = true
  425. findPid = resArr[0].Id.Hex()
  426. if findPid == mongodb.BsonIdToSId(tmpPro["_id"]) {
  427. return false
  428. }
  429. p.updateProFiled(tmp, info, resArr[0], kv+1, resArr[0].comStr, ex)
  430. for k2, bv := range []int{bpn, bpc, bptc, bpb} {
  431. if bv > -1 {
  432. pids[bv].Arr = append(pids[bv].Arr, findPid)
  433. if k2 == 0 {
  434. if resArr[0].ProjectName == "" {
  435. resArr[0].ProjectName = info.ProjectName
  436. } else {
  437. if resArr[0].MPN == nil {
  438. resArr[0].MPN = []string{info.ProjectName}
  439. } else {
  440. resArr[0].MPN = append(resArr[0].MPN, info.ProjectName)
  441. }
  442. }
  443. } else if k2 < 3 {
  444. if resArr[0].ProjectCode == "" {
  445. resArr[0].ProjectCode = qu.If(k2 == 1, info.ProjectCode, info.PTC).(string)
  446. } else {
  447. if resArr[0].MPC == nil {
  448. resArr[0].MPC = []string{qu.If(k2 == 1, info.ProjectCode, info.PTC).(string)}
  449. } else {
  450. resArr[0].MPC = append(resArr[0].MPC, qu.If(k2 == 1, info.ProjectCode, info.PTC).(string))
  451. }
  452. }
  453. } else {
  454. if resArr[0].Buyer == "" {
  455. resArr[0].Buyer = info.Buyer
  456. }
  457. }
  458. }
  459. }
  460. } else {
  461. bFindProject = false
  462. findPid = ""
  463. }
  464. break
  465. }
  466. }
  467. if !bFindProject {
  468. id, p1 := p.NewProject(tmp, info)
  469. p.AllIdsMapLock.Lock()
  470. p.AllIdsMap[id] = &ID{Id: id, P: p1}
  471. p.AllIdsMapLock.Unlock()
  472. for _, m := range pids {
  473. m.Arr = append(m.Arr, id)
  474. }
  475. return false
  476. }
  477. return true
  478. }
  479. //内部合并
  480. func (p *ProjectTask) innerMerge(infoList []interface{}, tmpPro map[string]interface{}) (map[string]interface{}, *ProjectInfo) {
  481. newP := make(map[string]interface{})
  482. newP["_id"] = tmpPro["_id"]
  483. var p1 *ProjectInfo
  484. for k, m := range infoList{
  485. m1 := m.(map[string]interface{})
  486. temp := MongoTool.FindById(ExtractColl, qu.ObjToString(m1["infoid"]))
  487. tempInfo := ParseInfo(temp)
  488. if k == 0 {
  489. p1 = p.newPro(temp, newP, tempInfo)
  490. }else {
  491. p.updateOldProField(p1, tempInfo, newP, temp, m1)
  492. }
  493. }
  494. return newP, p1
  495. }
  496. func (p *ProjectTask) innerMerge1(infoList []interface{}, infoid string, tmpPro map[string]interface{}) (map[string]interface{}, *ProjectInfo) {
  497. newP := make(map[string]interface{})
  498. newP["_id"] = tmpPro["_id"]
  499. var p1 *ProjectInfo
  500. for k, m := range infoList{
  501. m1 := m.(map[string]interface{})
  502. if m1["infoid"] == infoid {
  503. continue
  504. }
  505. temp := MongoTool.FindById(ExtractColl, qu.ObjToString(m1["infoid"]))
  506. tempInfo := ParseInfo(temp)
  507. if k == 0 {
  508. p1 = p.newPro(temp, newP, tempInfo)
  509. }else {
  510. p.updateOldProField(p1, tempInfo, newP, temp, m1)
  511. }
  512. }
  513. return newP, p1
  514. }
  515. // 更新招标公告到新的项目中
  516. func (p *ProjectTask) updateProFiled(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectInfo, weight int, comStr string, ex int) {
  517. set := map[string]interface{}{}
  518. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  519. if len(pInfo.Ids) > 30 {
  520. //异常标记
  521. set["listtag"] = 1
  522. }
  523. if thisinfo.Publishtime > pInfo.LastTime {
  524. pInfo.LastTime = thisinfo.Publishtime
  525. set["lasttime"] = thisinfo.Publishtime
  526. }
  527. if thisinfo.TopType == "招标" {
  528. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && pInfo.Zbtime <= 0 {
  529. set["zbtime"] = tmp["publishtime"]
  530. }
  531. } else if thisinfo.TopType == "结果" {
  532. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  533. if pInfo.Jgtime > 0 {
  534. jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  535. //公告状态和项目状态同样都是中标或者成交,
  536. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  537. if jg1 > p.jgTime {
  538. set["jgtime"] = tmp["publishtime"]
  539. pInfo.Jgtime = thisinfo.Publishtime
  540. }
  541. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  542. //公告状态和项目状态同样是流标或者废标
  543. if jg1 > p.jgTime {
  544. set["jgtime"] = tmp["publishtime"]
  545. pInfo.Jgtime = thisinfo.Publishtime
  546. }
  547. }
  548. } else {
  549. set["jgtime"] = tmp["publishtime"]
  550. pInfo.Jgtime = thisinfo.Publishtime
  551. }
  552. }
  553. } else if thisinfo.SubType == "合同" {
  554. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  555. //中标、成交不更新jgtime
  556. } else {
  557. set["jgtime"] = tmp["publishtime"]
  558. pInfo.Jgtime = thisinfo.Publishtime
  559. }
  560. }
  561. if thisinfo.Bidopentime > pInfo.Bidopentime {
  562. pInfo.Bidopentime = thisinfo.Bidopentime
  563. set["bidopentime"] = pInfo.Bidopentime
  564. }
  565. // bidtype、bidstatus
  566. pInfo.Bidtype, pInfo.Bidstatus = GetBidTypeAndBidStatus(thisinfo)
  567. set["bidtype"] = pInfo.Bidtype
  568. set["bidstatus"] = pInfo.Bidstatus
  569. //异常标记
  570. if ex > 0 {
  571. set["exception"] = ex
  572. }
  573. //相同城市的公告才会合并到一起(全国列外)
  574. if thisinfo.Area != "全国" {
  575. pInfo.Area = thisinfo.Area
  576. set["area"] = thisinfo.Area
  577. pInfo.City = thisinfo.City
  578. set["city"] = thisinfo.City
  579. if thisinfo.District != "" {
  580. pInfo.District = thisinfo.District
  581. set["district"] = thisinfo.District
  582. }
  583. }
  584. // 项目名称
  585. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  586. pInfo.ProjectName = thisinfo.ProjectName
  587. set["projectname"] = thisinfo.ProjectName
  588. }
  589. // 项目编号
  590. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  591. pInfo.ProjectCode = thisinfo.ProjectCode
  592. set["projectcode"] = thisinfo.ProjectCode
  593. }
  594. // 采购单位
  595. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  596. pInfo.Buyer = thisinfo.Buyer
  597. set["buyer"] = thisinfo.Buyer
  598. pInfo.Buyerclass = thisinfo.Buyerclass
  599. set["buyerclass"] = thisinfo.Buyerclass
  600. }
  601. if pInfo.Buyer == "" {
  602. set["buyerclass"] = ""
  603. }
  604. // 采购单位联系人
  605. if thisinfo.Buyerperson != "" {
  606. pInfo.Buyerperson = thisinfo.Buyerperson
  607. set["buyerperson"] = pInfo.Buyerperson
  608. } else {
  609. pInfo.Buyerperson = ""
  610. set["buyerperson"] = ""
  611. }
  612. // 采购单位電話
  613. if thisinfo.Buyertel != "" {
  614. pInfo.Buyertel = thisinfo.Buyertel
  615. set["buyertel"] = pInfo.Buyertel
  616. } else {
  617. pInfo.Buyertel = ""
  618. set["buyertel"] = ""
  619. }
  620. if thisinfo.ContractCode != "" {
  621. set["contractcode"] = pInfo.ContractCode + "," + thisinfo.ContractCode
  622. }
  623. // 代理机构 相同的代理机构才会合并到一个项目 2020.11.9
  624. //if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  625. // pInfo.Agency = thisinfo.Agency
  626. // set["agency"] = thisinfo.Agency
  627. //}
  628. if len(thisinfo.Topscopeclass) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  629. sort.Strings(pInfo.Topscopeclass)
  630. for _, k := range thisinfo.Topscopeclass {
  631. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  632. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  633. sort.Strings(pInfo.Topscopeclass)
  634. }
  635. }
  636. set["topscopeclass"] = pInfo.Topscopeclass
  637. }
  638. // 项目评审专家
  639. if len(thisinfo.ReviewExperts) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  640. set["review_experts"] = thisinfo.ReviewExperts
  641. pInfo.ReviewExperts = thisinfo.ReviewExperts
  642. }
  643. if thisinfo.Purchasing != "" && thisinfo.Publishtime > pInfo.LastTime {
  644. if pInfo.Purchasing == "" {
  645. pInfo.Purchasing = thisinfo.Purchasing
  646. set["purchasing"] = thisinfo.Purchasing
  647. } else {
  648. list := strings.Split(pInfo.Purchasing, ",")
  649. for _, k := range list {
  650. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  651. list = append(list, k)
  652. sort.Strings(list)
  653. }
  654. }
  655. set["purchasing"] = strings.Join(list, ",")
  656. }
  657. }
  658. //中标候选人
  659. if len(thisinfo.WinnerOrder) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  660. var list = []string{}
  661. for _, v := range thisinfo.WinnerOrder {
  662. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  663. list = append(list, qu.ObjToString(v["entname"]))
  664. }
  665. }
  666. set["winnerorder"] = list
  667. pInfo.Winnerorder = list
  668. }
  669. if len(thisinfo.Subscopeclass) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  670. sort.Strings(pInfo.Subscopeclass)
  671. for _, k := range thisinfo.Subscopeclass {
  672. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  673. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  674. sort.Strings(pInfo.Subscopeclass)
  675. }
  676. }
  677. set["subscopeclass"] = pInfo.Subscopeclass
  678. set["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  679. }
  680. if len(thisinfo.Winners) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  681. if len(pInfo.Winners) <= 0 {
  682. set["winner"] = qu.ObjToString(tmp["winner"])
  683. }
  684. sort.Strings(pInfo.Winners)
  685. for _, k := range thisinfo.Winners {
  686. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  687. if BinarySearch(pInfo.Winners, k) != -1 {
  688. deleteSlice(pInfo.Winners, k, "")
  689. sort.Strings(pInfo.Winners)
  690. }
  691. } else {
  692. if BinarySearch(pInfo.Winners, k) == -1 {
  693. pInfo.Winners = append(pInfo.Winners, k)
  694. sort.Strings(pInfo.Winners)
  695. }
  696. }
  697. }
  698. set["s_winner"] = strings.Join(pInfo.Winners, ",")
  699. }
  700. if thisinfo.HasPackage { //多包处理
  701. set["multipackage"] = 1
  702. pkg := PackageFormat(thisinfo, pInfo)
  703. pInfo.Package = pkg
  704. set["package"] = pInfo.Package
  705. }
  706. //处理多包后,计算预算金额、中标金额
  707. CountAmount(pInfo, thisinfo, tmp)
  708. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  709. set["budget"] = pInfo.Budget
  710. set["budgettag"] = 0
  711. }
  712. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  713. set["bidamount"] = pInfo.Bidamount
  714. set["bidamounttag"] = 0
  715. }
  716. if pInfo.Bidamount >= pInfo.Budget {
  717. set["sortprice"] = pInfo.Bidamount
  718. } else if pInfo.Budget >= pInfo.Bidamount {
  719. set["sortprice"] = pInfo.Budget
  720. }
  721. infofield := InfoField{
  722. Budget: thisinfo.Budget,
  723. Bidamount: thisinfo.Bidamount,
  724. ContractCode: thisinfo.ContractCode,
  725. ProjectName: thisinfo.ProjectName,
  726. ProjectCode: thisinfo.ProjectCode,
  727. Bidstatus: pInfo.Bidstatus,
  728. }
  729. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  730. copyMap[thisinfo.Id] = infofield
  731. tmpMap := make(map[string]interface{})
  732. for k, v := range copyMap {
  733. tmpMap[k] = StructToMap(v)
  734. }
  735. tmpMap[thisinfo.Id] = StructToMap(infofield)
  736. pInfo.InfoFiled = copyMap
  737. set["infofield"] = tmpMap
  738. set["mpn"] = pInfo.MPN
  739. set["mpc"] = pInfo.MPC
  740. set["updatetime"] = p.pici
  741. update := map[string]interface{}{}
  742. if len(set) > 0 {
  743. update["$set"] = set
  744. }
  745. push := p.PushListInfo(tmp, thisinfo.Id)
  746. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  747. push["compareStr"] = comStr
  748. push["resVal"] = pInfo.resVal
  749. push["pjVal"] = pInfo.pjVal
  750. update["$push"] = map[string]interface{}{
  751. "list": push,
  752. "ids": thisinfo.Id,
  753. }
  754. bol := MongoTool.UpdateById(ProjectColl, pInfo.Id.Hex(), update)
  755. if bol {
  756. by, _ := json.Marshal(map[string]interface{}{
  757. "query": map[string]interface{}{
  758. "_id": bson.M{
  759. "$gte": pInfo.Id.Hex(),
  760. "$lte": pInfo.Id.Hex(),
  761. }},
  762. "stype": "project",
  763. })
  764. qu.Debug(string(by))
  765. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  766. }
  767. }
  768. // 内部合并时,原有项目id基础上新建项目
  769. func (p *ProjectTask) newPro(tmp, tmpPro map[string]interface{}, thisinfo *Info) *ProjectInfo {
  770. for _, f := range FIELDS {
  771. if tmp[f] != nil && tmp[f] != "" {
  772. tmpPro[f] = tmp[f]
  773. }
  774. }
  775. bidopentime := qu.Int64All(tmp["bidopentime"])
  776. if bidopentime > 0 {
  777. tmpPro["bidopentime"] = bidopentime
  778. }
  779. //异常标记
  780. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  781. tmpPro["exception"] = 1
  782. }
  783. //projecthref保存
  784. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  785. if jsonData != nil && qu.ObjToString(jsonData["projecthref"]) != "" {
  786. tmpPro["projecthref"] = jsonData["projecthref"]
  787. }
  788. }
  789. //合同编号
  790. if thisinfo.ContractCode != "" {
  791. tmpPro["contractcode"] = thisinfo.ContractCode
  792. }
  793. bs, bt := GetBidTypeAndBidStatus(thisinfo)
  794. tmpPro["bidtype"] = bs
  795. tmpPro["bidstatus"] = bt
  796. pkg := PackageFormat(thisinfo, nil)
  797. p1 := p.NewCachePinfo(tmpPro["_id"].(primitive.ObjectID), thisinfo, bs, bt, pkg)
  798. now := time.Now().Unix()
  799. tmpPro["createtime"] = now
  800. tmpPro["sourceinfoid"] = thisinfo.Id
  801. tmpPro["sourceinfourl"] = tmp["href"]
  802. tmpPro["firsttime"] = tmp["publishtime"]
  803. tmpPro["lasttime"] = tmp["publishtime"]
  804. tmpPro["pici"] = tmp["comeintime"]
  805. tmpPro["ids"] = []string{thisinfo.Id}
  806. if thisinfo.TopType == "招标" {
  807. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  808. tmpPro["zbtime"] = tmp["publishtime"]
  809. p1.Zbtime = qu.Int64All(tmp["publishtime"])
  810. }
  811. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  812. tmpPro["jgtime"] = tmp["publishtime"]
  813. p1.Jgtime = thisinfo.Publishtime
  814. }
  815. if len(thisinfo.Subscopeclass) > 0 {
  816. tmpPro["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  817. }
  818. if len(thisinfo.Winners) > 0 {
  819. tmpPro["s_winner"] = strings.Join(thisinfo.Winners, ",")
  820. p1.Winners = thisinfo.Winners
  821. }
  822. if thisinfo.HasPackage {
  823. tmpPro["multipackage"] = 1
  824. tmpPro["package"] = pkg
  825. } else {
  826. tmpPro["multipackage"] = 0
  827. }
  828. //项目评审专家
  829. if len(thisinfo.ReviewExperts) > 0 {
  830. tmpPro["review_experts"] = thisinfo.ReviewExperts
  831. p1.ReviewExperts = thisinfo.ReviewExperts
  832. }
  833. //标的物
  834. if thisinfo.Purchasing != "" {
  835. tmpPro["purchasing"] = thisinfo.Purchasing
  836. p1.Purchasing = thisinfo.Purchasing
  837. }
  838. //中标候选人
  839. if len(thisinfo.WinnerOrder) > 0 {
  840. var list = []string{}
  841. for _, v := range thisinfo.WinnerOrder {
  842. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  843. list = append(list, qu.ObjToString(v["entname"]))
  844. }
  845. }
  846. tmpPro["winnerorder"] = list
  847. p1.Winnerorder = list
  848. }
  849. p1.InfoFiled = make(map[string]InfoField)
  850. infofield := InfoField{
  851. Budget: thisinfo.Budget,
  852. Bidamount: thisinfo.Bidamount,
  853. ContractCode: thisinfo.ContractCode,
  854. ProjectName: thisinfo.ProjectName,
  855. ProjectCode: thisinfo.ProjectCode,
  856. Bidstatus: bs,
  857. }
  858. p1.InfoFiled[thisinfo.Id] = infofield
  859. res := StructToMap(infofield)
  860. tmpPro["infofield"] = map[string]interface{}{
  861. thisinfo.Id: res,
  862. }
  863. if tmp["budget"] != nil && tmp["budget"] != "" {
  864. tmpPro["budget"] = thisinfo.Budget
  865. p1.Budgettag = 0
  866. tmpPro["budgettag"] = 0
  867. } else {
  868. p1.Budgettag = 1
  869. tmpPro["budgettag"] = 1
  870. }
  871. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  872. tmpPro["bidamount"] = thisinfo.Bidamount
  873. p1.Bidamounttag = 0
  874. tmpPro["bidamounttag"] = 0
  875. } else {
  876. p1.Bidamounttag = 1
  877. tmpPro["bidamounttag"] = 1
  878. }
  879. if p1.Bidamount > 0 {
  880. tmpPro["sortprice"] = p1.Bidamount
  881. } else if p1.Budget > 0 {
  882. tmpPro["sortprice"] = p1.Budget
  883. }
  884. push := p.PushListInfo(tmp, thisinfo.Id)
  885. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  886. tmpPro["list"] = []map[string]interface{}{
  887. push,
  888. }
  889. return &p1
  890. }
  891. // 合并字段到老项目中
  892. func (p *ProjectTask) updateOldProField(pInfo *ProjectInfo, thisinfo *Info, tmpPro, tmp, m1 map[string]interface{}) {
  893. if len(pInfo.Ids) > 30 {
  894. //异常标记
  895. tmpPro["listtag"] = 1
  896. }
  897. if thisinfo.Publishtime > pInfo.LastTime {
  898. pInfo.LastTime = thisinfo.Publishtime
  899. tmpPro["lasttime"] = thisinfo.Publishtime
  900. }
  901. if thisinfo.TopType == "招标" {
  902. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && pInfo.Zbtime <= 0 {
  903. tmpPro["zbtime"] = tmp["publishtime"]
  904. }
  905. } else if thisinfo.TopType == "结果" {
  906. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  907. if pInfo.Jgtime > 0 {
  908. jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  909. //公告状态和项目状态同样都是中标或者成交,
  910. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  911. if jg1 > p.jgTime {
  912. tmpPro["jgtime"] = tmp["publishtime"]
  913. pInfo.Jgtime = thisinfo.Publishtime
  914. }
  915. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  916. //公告状态和项目状态同样是流标或者废标
  917. if jg1 > p.jgTime {
  918. tmpPro["jgtime"] = tmp["publishtime"]
  919. pInfo.Jgtime = thisinfo.Publishtime
  920. }
  921. }
  922. } else {
  923. tmpPro["jgtime"] = tmp["publishtime"]
  924. pInfo.Jgtime = thisinfo.Publishtime
  925. }
  926. }
  927. } else if thisinfo.SubType == "合同" {
  928. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  929. //中标、成交不更新jgtime
  930. } else {
  931. tmpPro["jgtime"] = tmp["publishtime"]
  932. pInfo.Jgtime = thisinfo.Publishtime
  933. }
  934. }
  935. if thisinfo.Bidopentime > pInfo.Bidopentime {
  936. pInfo.Bidopentime = thisinfo.Bidopentime
  937. tmpPro["bidopentime"] = pInfo.Bidopentime
  938. }
  939. // bidtype、bidstatus
  940. pInfo.Bidtype, pInfo.Bidstatus = GetBidTypeAndBidStatus(thisinfo)
  941. tmpPro["bidtype"] = pInfo.Bidtype
  942. tmpPro["bidstatus"] = pInfo.Bidstatus
  943. //相同城市的公告才会合并到一起(全国列外)
  944. if thisinfo.Area != "全国" {
  945. pInfo.Area = thisinfo.Area
  946. tmpPro["area"] = thisinfo.Area
  947. pInfo.City = thisinfo.City
  948. tmpPro["city"] = thisinfo.City
  949. if thisinfo.District != "" {
  950. pInfo.District = thisinfo.District
  951. tmpPro["district"] = thisinfo.District
  952. }
  953. }
  954. // 项目名称
  955. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  956. pInfo.ProjectName = thisinfo.ProjectName
  957. tmpPro["projectname"] = thisinfo.ProjectName
  958. }
  959. // 项目编号
  960. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  961. pInfo.ProjectCode = thisinfo.ProjectCode
  962. tmpPro["projectcode"] = thisinfo.ProjectCode
  963. }
  964. // 采购单位
  965. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  966. pInfo.Buyer = thisinfo.Buyer
  967. tmpPro["buyer"] = thisinfo.Buyer
  968. pInfo.Buyerclass = thisinfo.Buyerclass
  969. tmpPro["buyerclass"] = thisinfo.Buyerclass
  970. }
  971. if pInfo.Buyer == "" {
  972. tmpPro["buyerclass"] = ""
  973. }
  974. // 采购单位联系人
  975. if thisinfo.Buyerperson != "" {
  976. pInfo.Buyerperson = thisinfo.Buyerperson
  977. tmpPro["buyerperson"] = pInfo.Buyerperson
  978. } else {
  979. pInfo.Buyerperson = ""
  980. tmpPro["buyerperson"] = ""
  981. }
  982. // 采购单位電話
  983. if thisinfo.Buyertel != "" {
  984. pInfo.Buyertel = thisinfo.Buyertel
  985. tmpPro["buyertel"] = pInfo.Buyertel
  986. } else {
  987. pInfo.Buyertel = ""
  988. tmpPro["buyertel"] = ""
  989. }
  990. if thisinfo.ContractCode != "" {
  991. tmpPro["contractcode"] = pInfo.ContractCode + "," + thisinfo.ContractCode
  992. }
  993. // 代理机构 相同的代理机构才会合并到一个项目 2020.11.9
  994. //if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  995. // pInfo.Agency = thisinfo.Agency
  996. // set["agency"] = thisinfo.Agency
  997. //}
  998. if len(thisinfo.Topscopeclass) > 0 {
  999. sort.Strings(pInfo.Topscopeclass)
  1000. for _, k := range thisinfo.Topscopeclass {
  1001. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  1002. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  1003. sort.Strings(pInfo.Topscopeclass)
  1004. }
  1005. }
  1006. tmpPro["topscopeclass"] = pInfo.Topscopeclass
  1007. }
  1008. // 项目评审专家
  1009. if len(thisinfo.ReviewExperts) > 0 {
  1010. tmpPro["review_experts"] = thisinfo.ReviewExperts
  1011. pInfo.ReviewExperts = thisinfo.ReviewExperts
  1012. }
  1013. if thisinfo.Purchasing != "" {
  1014. if pInfo.Purchasing == "" {
  1015. pInfo.Purchasing = thisinfo.Purchasing
  1016. tmpPro["purchasing"] = thisinfo.Purchasing
  1017. } else {
  1018. list := strings.Split(pInfo.Purchasing, ",")
  1019. for _, k := range list {
  1020. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  1021. list = append(list, k)
  1022. sort.Strings(list)
  1023. }
  1024. }
  1025. tmpPro["purchasing"] = strings.Join(list, ",")
  1026. }
  1027. }
  1028. //中标候选人
  1029. if len(thisinfo.WinnerOrder) > 0 {
  1030. var list = []string{}
  1031. for _, v := range thisinfo.WinnerOrder {
  1032. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  1033. list = append(list, qu.ObjToString(v["entname"]))
  1034. }
  1035. }
  1036. tmpPro["winnerorder"] = list
  1037. pInfo.Winnerorder = list
  1038. }
  1039. if len(thisinfo.Subscopeclass) > 0 {
  1040. sort.Strings(pInfo.Subscopeclass)
  1041. for _, k := range thisinfo.Subscopeclass {
  1042. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  1043. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  1044. sort.Strings(pInfo.Subscopeclass)
  1045. }
  1046. }
  1047. tmpPro["subscopeclass"] = pInfo.Subscopeclass
  1048. tmpPro["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  1049. }
  1050. if len(thisinfo.Winners) > 0 {
  1051. if len(pInfo.Winners) <= 0 {
  1052. tmpPro["winner"] = qu.ObjToString(tmp["winner"])
  1053. }
  1054. sort.Strings(pInfo.Winners)
  1055. for _, k := range thisinfo.Winners {
  1056. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  1057. if BinarySearch(pInfo.Winners, k) != -1 {
  1058. deleteSlice(pInfo.Winners, k, "")
  1059. sort.Strings(pInfo.Winners)
  1060. }
  1061. } else {
  1062. if BinarySearch(pInfo.Winners, k) == -1 {
  1063. pInfo.Winners = append(pInfo.Winners, k)
  1064. sort.Strings(pInfo.Winners)
  1065. }
  1066. }
  1067. }
  1068. tmpPro["s_winner"] = strings.Join(pInfo.Winners, ",")
  1069. }
  1070. if thisinfo.HasPackage { //多包处理
  1071. tmpPro["multipackage"] = 1
  1072. pkg := PackageFormat(thisinfo, pInfo)
  1073. pInfo.Package = pkg
  1074. tmpPro["package"] = pInfo.Package
  1075. }
  1076. //处理多包后,计算预算金额、中标金额
  1077. CountAmount(pInfo, thisinfo, tmp)
  1078. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  1079. tmpPro["budget"] = pInfo.Budget
  1080. tmpPro["budgettag"] = 0
  1081. }
  1082. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  1083. tmpPro["bidamount"] = pInfo.Bidamount
  1084. tmpPro["bidamounttag"] = 0
  1085. }
  1086. if pInfo.Bidamount >= pInfo.Budget {
  1087. tmpPro["sortprice"] = pInfo.Bidamount
  1088. } else if pInfo.Budget >= pInfo.Bidamount {
  1089. tmpPro["sortprice"] = pInfo.Budget
  1090. }
  1091. infofield := InfoField{
  1092. Budget: thisinfo.Budget,
  1093. Bidamount: thisinfo.Bidamount,
  1094. ContractCode: thisinfo.ContractCode,
  1095. ProjectName: thisinfo.ProjectName,
  1096. ProjectCode: thisinfo.ProjectCode,
  1097. Bidstatus: pInfo.Bidstatus,
  1098. }
  1099. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  1100. copyMap[thisinfo.Id] = infofield
  1101. tmpMap := make(map[string]interface{})
  1102. for k, v := range copyMap {
  1103. tmpMap[k] = StructToMap(v)
  1104. }
  1105. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1106. pInfo.InfoFiled = copyMap
  1107. tmpPro["infofield"] = tmpMap
  1108. tmpPro["mpn"] = pInfo.MPN
  1109. tmpPro["mpc"] = pInfo.MPC
  1110. tmpPro["updatetime"] = p.pici
  1111. push := p.PushListInfo(tmp, thisinfo.Id)
  1112. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1113. push["compareStr"] = m1["compareStr"]
  1114. push["resVal"] = m1["resVal"]
  1115. push["pjVal"] = m1["pjVal"]
  1116. list := tmpPro["list"].([]map[string]interface{})
  1117. tmpPro["list"] = append(list, push)
  1118. tmpPro["ids"] = append(tmpPro["ids"].([]string), thisinfo.Id)
  1119. }
  1120. func deleteSlice1(arr []interface{}, v interface{}) []interface{} {
  1121. for k, v1 := range arr {
  1122. if reflect.DeepEqual(v1, v) {
  1123. return append(arr[:k], arr[k+1:]...)
  1124. }
  1125. }
  1126. return arr
  1127. }
  1128. // 修改字段值
  1129. func UpdateValue(proMap map[string]interface{}, index, position int, modifyMap map[string]interface{}) map[string]interface{} {
  1130. updataSet := make(map[string]interface{})
  1131. infoList := []interface{}(proMap["list"].(primitive.A))
  1132. tempMap := infoList[position].(map[string]interface{})
  1133. for k := range modifyMap {
  1134. //项目中lsit大小等于1 或者 修改的招标公告处于项目的list中最后一个
  1135. if len(infoList) == 1 || index == 2 {
  1136. if k == "budget" || k == "bidamount" {
  1137. if proMap["sortprice"] == proMap[k] {
  1138. updataSet["sortprice"] = modifyMap[k]
  1139. }
  1140. updataSet[k] = modifyMap[k]
  1141. proMap[k] = modifyMap[k]
  1142. tempMap[k] = modifyMap[k]
  1143. }else {
  1144. updataSet[k] = modifyMap[k]
  1145. proMap[k] = modifyMap[k]
  1146. tempMap[k] = modifyMap[k]
  1147. }
  1148. } else {
  1149. tempMap[k] = modifyMap[k]
  1150. if k == "budget" || k == "bidamount" {
  1151. if proMap["sortprice"] == proMap[k] {
  1152. proMap["sortprice"] = modifyMap[k]
  1153. }
  1154. updataSet[k] = modifyMap[k]
  1155. proMap[k] = modifyMap[k]
  1156. }
  1157. // 有条件更新项目外围字段值(非空)
  1158. if proMap[k] == nil || qu.ObjToString(k) == "" {
  1159. updataSet[k] = modifyMap[k]
  1160. proMap[k] = modifyMap[k]
  1161. }
  1162. }
  1163. }
  1164. return updataSet
  1165. }
  1166. //备份(快照)
  1167. func backupPro(tmp map[string]interface{}) {
  1168. tmp1 := make(map[string]interface{})
  1169. for k, v := range tmp{
  1170. tmp1[k] = v
  1171. }
  1172. if Sysconfig["backupFlag"].(bool) {
  1173. tmp1["sourceprojectid"] = mongodb.BsonIdToSId(tmp1["_id"])
  1174. delete(tmp1, "_id")
  1175. MongoTool.Save(BackupColl, tmp1)
  1176. }
  1177. }
  1178. // 删除原有项目数据
  1179. func delOldPro(pid string) {
  1180. t := MongoTool.Delete(ProjectColl, pid)
  1181. if t >=0 {
  1182. client := Es.GetEsConn()
  1183. defer Es.DestoryEsConn(client)
  1184. Es.DelById(Index, Itype, pid)
  1185. }
  1186. }
  1187. // 打印内存中的项目信息
  1188. func (p *ProjectTask) printMemPro(pid string) {
  1189. p.AllIdsMapLock.Lock()
  1190. if v, ok := p.AllIdsMap[pid]; ok {
  1191. qu.Debug("mem pro ----------", *v.P)
  1192. }
  1193. p.AllIdsMapLock.Unlock()
  1194. }