update.go 37 KB

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