update.go 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  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 > 0 {
  698. set["sortprice"] = pInfo.Bidamount
  699. } else {
  700. if pInfo.Budget > 0 {
  701. set["sortprice"] = pInfo.Budget
  702. }
  703. }
  704. infofield := InfoField{
  705. Budget: thisinfo.Budget,
  706. Bidamount: thisinfo.Bidamount,
  707. ContractCode: thisinfo.ContractCode,
  708. ProjectName: thisinfo.ProjectName,
  709. ProjectCode: thisinfo.ProjectCode,
  710. Bidstatus: pInfo.Bidstatus,
  711. }
  712. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  713. copyMap[thisinfo.Id] = infofield
  714. tmpMap := make(map[string]interface{})
  715. for k, v := range copyMap {
  716. tmpMap[k] = StructToMap(v)
  717. }
  718. tmpMap[thisinfo.Id] = StructToMap(infofield)
  719. pInfo.InfoFiled = copyMap
  720. set["infofield"] = tmpMap
  721. set["mpn"] = pInfo.MPN
  722. set["mpc"] = pInfo.MPC
  723. set["updatetime"] = p.pici
  724. update := map[string]interface{}{}
  725. if len(set) > 0 {
  726. update["$set"] = set
  727. }
  728. push := p.PushListInfo(tmp, thisinfo.Id)
  729. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  730. push["compareStr"] = comStr
  731. push["resVal"] = pInfo.resVal
  732. push["pjVal"] = pInfo.pjVal
  733. update["$push"] = map[string]interface{}{
  734. "list": push,
  735. "ids": thisinfo.Id,
  736. }
  737. bol := MongoTool.UpdateById(ProjectColl, pInfo.Id.Hex(), update)
  738. if bol {
  739. by, _ := json.Marshal(map[string]interface{}{
  740. "query": map[string]interface{}{
  741. "_id": bson.M{
  742. "$gte": pInfo.Id.Hex(),
  743. "$lte": pInfo.Id.Hex(),
  744. }},
  745. "stype": "project",
  746. })
  747. qu.Debug(string(by))
  748. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  749. }
  750. }
  751. // 内部合并时,原有项目id基础上新建项目
  752. func (p *ProjectTask) newPro(tmp, tmpPro map[string]interface{}, thisinfo *Info) *ProjectInfo {
  753. for _, f := range FIELDS {
  754. if tmp[f] != nil && tmp[f] != "" {
  755. tmpPro[f] = tmp[f]
  756. }
  757. }
  758. bidopentime := qu.Int64All(tmp["bidopentime"])
  759. if bidopentime > 0 {
  760. tmpPro["bidopentime"] = bidopentime
  761. }
  762. //异常标记
  763. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  764. tmpPro["exception"] = 1
  765. }
  766. //projecthref保存
  767. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  768. if jsonData != nil && qu.ObjToString(jsonData["projecthref"]) != "" {
  769. tmpPro["projecthref"] = jsonData["projecthref"]
  770. }
  771. }
  772. //合同编号
  773. if thisinfo.ContractCode != "" {
  774. tmpPro["contractcode"] = thisinfo.ContractCode
  775. }
  776. bs, bt := p.GetBidTypeAndBidStatus(thisinfo)
  777. tmpPro["bidtype"] = bs
  778. tmpPro["bidstatus"] = bt
  779. pkg := PackageFormat(thisinfo, nil)
  780. p1 := p.NewCachePinfo(tmpPro["_id"].(primitive.ObjectID), thisinfo, bs, bt, pkg)
  781. now := time.Now().Unix()
  782. tmpPro["createtime"] = now
  783. tmpPro["sourceinfoid"] = thisinfo.Id
  784. tmpPro["sourceinfourl"] = tmp["href"]
  785. tmpPro["firsttime"] = tmp["publishtime"]
  786. tmpPro["lasttime"] = tmp["publishtime"]
  787. tmpPro["pici"] = tmp["comeintime"]
  788. tmpPro["ids"] = []string{thisinfo.Id}
  789. if thisinfo.TopType == "招标" {
  790. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  791. tmpPro["zbtime"] = tmp["publishtime"]
  792. p1.Zbtime = qu.Int64All(tmp["publishtime"])
  793. }
  794. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  795. tmpPro["jgtime"] = tmp["publishtime"]
  796. p1.Jgtime = thisinfo.Publishtime
  797. }
  798. if len(thisinfo.Subscopeclass) > 0 {
  799. tmpPro["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  800. }
  801. if len(thisinfo.Winners) > 0 {
  802. tmpPro["s_winner"] = strings.Join(thisinfo.Winners, ",")
  803. p1.Winners = thisinfo.Winners
  804. }
  805. if thisinfo.HasPackage {
  806. tmpPro["multipackage"] = 1
  807. tmpPro["package"] = pkg
  808. } else {
  809. tmpPro["multipackage"] = 0
  810. }
  811. //项目评审专家
  812. if len(thisinfo.ReviewExperts) > 0 {
  813. tmpPro["review_experts"] = thisinfo.ReviewExperts
  814. p1.ReviewExperts = thisinfo.ReviewExperts
  815. }
  816. //标的物
  817. if thisinfo.Purchasing != "" {
  818. tmpPro["purchasing"] = thisinfo.Purchasing
  819. p1.Purchasing = thisinfo.Purchasing
  820. }
  821. //中标候选人
  822. if len(thisinfo.WinnerOrder) > 0 {
  823. var list = []string{}
  824. for _, v := range thisinfo.WinnerOrder {
  825. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  826. list = append(list, qu.ObjToString(v["entname"]))
  827. }
  828. }
  829. tmpPro["winnerorder"] = list
  830. p1.Winnerorder = list
  831. }
  832. p1.InfoFiled = make(map[string]InfoField)
  833. infofield := InfoField{
  834. Budget: thisinfo.Budget,
  835. Bidamount: thisinfo.Bidamount,
  836. ContractCode: thisinfo.ContractCode,
  837. ProjectName: thisinfo.ProjectName,
  838. ProjectCode: thisinfo.ProjectCode,
  839. Bidstatus: bs,
  840. }
  841. p1.InfoFiled[thisinfo.Id] = infofield
  842. res := StructToMap(infofield)
  843. tmpPro["infofield"] = map[string]interface{}{
  844. thisinfo.Id: res,
  845. }
  846. if tmp["budget"] != nil && tmp["budget"] != "" {
  847. tmpPro["budget"] = thisinfo.Budget
  848. p1.Budgettag = 0
  849. tmpPro["budgettag"] = 0
  850. } else {
  851. p1.Budgettag = 1
  852. tmpPro["budgettag"] = 1
  853. }
  854. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  855. tmpPro["bidamount"] = thisinfo.Bidamount
  856. p1.Bidamounttag = 0
  857. tmpPro["bidamounttag"] = 0
  858. } else {
  859. p1.Bidamounttag = 1
  860. tmpPro["bidamounttag"] = 1
  861. }
  862. if p1.Bidamount > 0 {
  863. tmpPro["sortprice"] = p1.Bidamount
  864. } else if p1.Budget > 0 {
  865. tmpPro["sortprice"] = p1.Budget
  866. }
  867. push := p.PushListInfo(tmp, thisinfo.Id)
  868. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  869. tmpPro["list"] = []map[string]interface{}{
  870. push,
  871. }
  872. return &p1
  873. }
  874. // 合并字段到老项目中
  875. func (p *ProjectTask) updateOldProField(pInfo *ProjectInfo, thisinfo *Info, tmpPro, tmp, m1 map[string]interface{}) {
  876. if len(pInfo.Ids) > 30 {
  877. //异常标记
  878. tmpPro["listtag"] = 1
  879. }
  880. if thisinfo.Publishtime > pInfo.LastTime {
  881. pInfo.LastTime = thisinfo.Publishtime
  882. tmpPro["lasttime"] = thisinfo.Publishtime
  883. }
  884. if thisinfo.TopType == "招标" {
  885. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && pInfo.Zbtime <= 0 {
  886. tmpPro["zbtime"] = tmp["publishtime"]
  887. }
  888. } else if thisinfo.TopType == "结果" {
  889. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  890. if pInfo.Jgtime > 0 {
  891. jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  892. //公告状态和项目状态同样都是中标或者成交,
  893. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  894. if jg1 > p.jgTime {
  895. tmpPro["jgtime"] = tmp["publishtime"]
  896. pInfo.Jgtime = thisinfo.Publishtime
  897. }
  898. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  899. //公告状态和项目状态同样是流标或者废标
  900. if jg1 > p.jgTime {
  901. tmpPro["jgtime"] = tmp["publishtime"]
  902. pInfo.Jgtime = thisinfo.Publishtime
  903. }
  904. }
  905. } else {
  906. tmpPro["jgtime"] = tmp["publishtime"]
  907. pInfo.Jgtime = thisinfo.Publishtime
  908. }
  909. }
  910. } else if thisinfo.SubType == "合同" {
  911. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  912. //中标、成交不更新jgtime
  913. } else {
  914. tmpPro["jgtime"] = tmp["publishtime"]
  915. pInfo.Jgtime = thisinfo.Publishtime
  916. }
  917. }
  918. if thisinfo.Bidopentime > pInfo.Bidopentime {
  919. pInfo.Bidopentime = thisinfo.Bidopentime
  920. tmpPro["bidopentime"] = pInfo.Bidopentime
  921. }
  922. // bidtype、bidstatus
  923. pInfo.Bidtype, pInfo.Bidstatus = p.GetBidTypeAndBidStatus(thisinfo)
  924. tmpPro["bidtype"] = pInfo.Bidtype
  925. tmpPro["bidstatus"] = pInfo.Bidstatus
  926. //相同城市的公告才会合并到一起(全国列外)
  927. if thisinfo.Area != "全国" {
  928. pInfo.Area = thisinfo.Area
  929. tmpPro["area"] = thisinfo.Area
  930. pInfo.City = thisinfo.City
  931. tmpPro["city"] = thisinfo.City
  932. if thisinfo.District != "" {
  933. pInfo.District = thisinfo.District
  934. tmpPro["district"] = thisinfo.District
  935. }
  936. }
  937. // 项目名称
  938. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  939. pInfo.ProjectName = thisinfo.ProjectName
  940. tmpPro["projectname"] = thisinfo.ProjectName
  941. }
  942. // 项目编号
  943. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  944. pInfo.ProjectCode = thisinfo.ProjectCode
  945. tmpPro["projectcode"] = thisinfo.ProjectCode
  946. }
  947. // 采购单位
  948. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  949. pInfo.Buyer = thisinfo.Buyer
  950. tmpPro["buyer"] = thisinfo.Buyer
  951. pInfo.Buyerclass = thisinfo.Buyerclass
  952. tmpPro["buyerclass"] = thisinfo.Buyerclass
  953. }
  954. if pInfo.Buyer == "" {
  955. tmpPro["buyerclass"] = ""
  956. }
  957. // 采购单位联系人
  958. if thisinfo.Buyerperson != "" {
  959. pInfo.Buyerperson = thisinfo.Buyerperson
  960. tmpPro["buyerperson"] = pInfo.Buyerperson
  961. } else {
  962. pInfo.Buyerperson = ""
  963. tmpPro["buyerperson"] = ""
  964. }
  965. // 采购单位電話
  966. if thisinfo.Buyertel != "" {
  967. pInfo.Buyertel = thisinfo.Buyertel
  968. tmpPro["buyertel"] = pInfo.Buyertel
  969. } else {
  970. pInfo.Buyertel = ""
  971. tmpPro["buyertel"] = ""
  972. }
  973. if thisinfo.ContractCode != "" {
  974. tmpPro["contractcode"] = pInfo.ContractCode + "," + thisinfo.ContractCode
  975. }
  976. // 代理机构 相同的代理机构才会合并到一个项目 2020.11.9
  977. //if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  978. // pInfo.Agency = thisinfo.Agency
  979. // set["agency"] = thisinfo.Agency
  980. //}
  981. if len(thisinfo.Topscopeclass) > 0 {
  982. sort.Strings(pInfo.Topscopeclass)
  983. for _, k := range thisinfo.Topscopeclass {
  984. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  985. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  986. sort.Strings(pInfo.Topscopeclass)
  987. }
  988. }
  989. tmpPro["topscopeclass"] = pInfo.Topscopeclass
  990. }
  991. // 项目评审专家
  992. if len(thisinfo.ReviewExperts) > 0 {
  993. tmpPro["review_experts"] = thisinfo.ReviewExperts
  994. pInfo.ReviewExperts = thisinfo.ReviewExperts
  995. }
  996. if thisinfo.Purchasing != "" {
  997. if pInfo.Purchasing == "" {
  998. pInfo.Purchasing = thisinfo.Purchasing
  999. tmpPro["purchasing"] = thisinfo.Purchasing
  1000. } else {
  1001. list := strings.Split(pInfo.Purchasing, ",")
  1002. for _, k := range list {
  1003. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  1004. list = append(list, k)
  1005. sort.Strings(list)
  1006. }
  1007. }
  1008. tmpPro["purchasing"] = strings.Join(list, ",")
  1009. }
  1010. }
  1011. //中标候选人
  1012. if len(thisinfo.WinnerOrder) > 0 {
  1013. var list = []string{}
  1014. for _, v := range thisinfo.WinnerOrder {
  1015. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  1016. list = append(list, qu.ObjToString(v["entname"]))
  1017. }
  1018. }
  1019. tmpPro["winnerorder"] = list
  1020. pInfo.Winnerorder = list
  1021. }
  1022. if len(thisinfo.Subscopeclass) > 0 {
  1023. sort.Strings(pInfo.Subscopeclass)
  1024. for _, k := range thisinfo.Subscopeclass {
  1025. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  1026. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  1027. sort.Strings(pInfo.Subscopeclass)
  1028. }
  1029. }
  1030. tmpPro["subscopeclass"] = pInfo.Subscopeclass
  1031. tmpPro["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  1032. }
  1033. if len(thisinfo.Winners) > 0 {
  1034. if len(pInfo.Winners) <= 0 {
  1035. tmpPro["winner"] = qu.ObjToString(tmp["winner"])
  1036. }
  1037. sort.Strings(pInfo.Winners)
  1038. for _, k := range thisinfo.Winners {
  1039. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  1040. if BinarySearch(pInfo.Winners, k) != -1 {
  1041. deleteSlice(pInfo.Winners, k, "")
  1042. sort.Strings(pInfo.Winners)
  1043. }
  1044. } else {
  1045. if BinarySearch(pInfo.Winners, k) == -1 {
  1046. pInfo.Winners = append(pInfo.Winners, k)
  1047. sort.Strings(pInfo.Winners)
  1048. }
  1049. }
  1050. }
  1051. tmpPro["s_winner"] = strings.Join(pInfo.Winners, ",")
  1052. }
  1053. if thisinfo.HasPackage { //多包处理
  1054. tmpPro["multipackage"] = 1
  1055. pkg := PackageFormat(thisinfo, pInfo)
  1056. pInfo.Package = pkg
  1057. tmpPro["package"] = pInfo.Package
  1058. }
  1059. //处理多包后,计算预算金额、中标金额
  1060. CountAmount(pInfo, thisinfo, tmp)
  1061. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  1062. tmpPro["budget"] = pInfo.Budget
  1063. tmpPro["budgettag"] = 0
  1064. }
  1065. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  1066. tmpPro["bidamount"] = pInfo.Bidamount
  1067. tmpPro["bidamounttag"] = 0
  1068. }
  1069. if pInfo.Bidamount >= pInfo.Budget {
  1070. tmpPro["sortprice"] = pInfo.Bidamount
  1071. } else if pInfo.Budget >= pInfo.Bidamount {
  1072. tmpPro["sortprice"] = pInfo.Budget
  1073. }
  1074. infofield := InfoField{
  1075. Budget: thisinfo.Budget,
  1076. Bidamount: thisinfo.Bidamount,
  1077. ContractCode: thisinfo.ContractCode,
  1078. ProjectName: thisinfo.ProjectName,
  1079. ProjectCode: thisinfo.ProjectCode,
  1080. Bidstatus: pInfo.Bidstatus,
  1081. }
  1082. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  1083. copyMap[thisinfo.Id] = infofield
  1084. tmpMap := make(map[string]interface{})
  1085. for k, v := range copyMap {
  1086. tmpMap[k] = StructToMap(v)
  1087. }
  1088. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1089. pInfo.InfoFiled = copyMap
  1090. tmpPro["infofield"] = tmpMap
  1091. tmpPro["mpn"] = pInfo.MPN
  1092. tmpPro["mpc"] = pInfo.MPC
  1093. tmpPro["updatetime"] = p.pici
  1094. push := p.PushListInfo(tmp, thisinfo.Id)
  1095. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1096. push["compareStr"] = m1["compareStr"]
  1097. push["resVal"] = m1["resVal"]
  1098. push["pjVal"] = m1["pjVal"]
  1099. list := tmpPro["list"].([]map[string]interface{})
  1100. tmpPro["list"] = append(list, push)
  1101. tmpPro["ids"] = append(tmpPro["ids"].([]string), thisinfo.Id)
  1102. }
  1103. func deleteSlice1(arr []interface{}, v interface{}) []interface{} {
  1104. for k, v1 := range arr {
  1105. if reflect.DeepEqual(v1, v) {
  1106. return append(arr[:k], arr[k+1:]...)
  1107. }
  1108. }
  1109. return arr
  1110. }
  1111. // 修改字段值
  1112. func UpdateValue(proMap map[string]interface{}, index, position int, modifyMap map[string]interface{}) map[string]interface{} {
  1113. updataSet := make(map[string]interface{})
  1114. infoList := []interface{}(proMap["list"].(primitive.A))
  1115. tempMap := infoList[position].(map[string]interface{})
  1116. for k := range modifyMap {
  1117. //项目中lsit大小等于1 或者 修改的招标公告处于项目的list中最后一个
  1118. if len(infoList) == 1 || index == 2 {
  1119. if k == "budget" || k == "bidamount" {
  1120. if proMap["sortprice"] == proMap[k] {
  1121. updataSet["sortprice"] = modifyMap[k]
  1122. }
  1123. updataSet[k] = modifyMap[k]
  1124. proMap[k] = modifyMap[k]
  1125. tempMap[k] = modifyMap[k]
  1126. } else {
  1127. updataSet[k] = modifyMap[k]
  1128. proMap[k] = modifyMap[k]
  1129. tempMap[k] = modifyMap[k]
  1130. }
  1131. } else {
  1132. tempMap[k] = modifyMap[k]
  1133. if k == "budget" || k == "bidamount" {
  1134. if proMap["sortprice"] == proMap[k] {
  1135. proMap["sortprice"] = modifyMap[k]
  1136. }
  1137. updataSet[k] = modifyMap[k]
  1138. proMap[k] = modifyMap[k]
  1139. }
  1140. // 有条件更新项目外围字段值(非空)
  1141. if proMap[k] == nil || qu.ObjToString(k) == "" {
  1142. updataSet[k] = modifyMap[k]
  1143. proMap[k] = modifyMap[k]
  1144. }
  1145. }
  1146. }
  1147. return updataSet
  1148. }
  1149. //备份(快照)
  1150. func backupPro(tmp map[string]interface{}) {
  1151. tmp1 := make(map[string]interface{})
  1152. for k, v := range tmp {
  1153. tmp1[k] = v
  1154. }
  1155. if Sysconfig["backupFlag"].(bool) {
  1156. tmp1["sourceprojectid"] = BsonIdToSId(tmp1["_id"])
  1157. delete(tmp1, "_id")
  1158. MongoTool.Save(BackupColl, tmp1)
  1159. }
  1160. }
  1161. // 删除原有项目数据
  1162. func delOldPro(pid string) {
  1163. t := MongoTool.Delete(ProjectColl, pid)
  1164. if t >= 0 {
  1165. client := Es.GetEsConn()
  1166. defer Es.DestoryEsConn(client)
  1167. Es.DelById(Index, Itype, pid)
  1168. }
  1169. }
  1170. // 修改内存中的数据
  1171. func (p *ProjectTask) modifyMem(tmpPro map[string]interface{}) {
  1172. pid := qu.ObjToString(tmpPro["_id"])
  1173. var pro ProjectInfo
  1174. err := mapstructure.Decode(tmpPro, &pro)
  1175. if err != nil {
  1176. qu.Debug(err)
  1177. }
  1178. pro.Id = StringTOBsonId(pid)
  1179. tmpMap := make(map[string]InfoField)
  1180. infoMap := tmpPro["infofield"].(map[string]interface{})
  1181. for _, v := range infoMap {
  1182. var field InfoField
  1183. b, _ := json.Marshal(v)
  1184. _ = json.Unmarshal(b, &field)
  1185. tmpMap[pid] = field
  1186. }
  1187. pro.InfoFiled = tmpMap
  1188. p.AllIdsMapLock.Lock()
  1189. if v, ok := p.AllIdsMap[pid]; ok {
  1190. v.P = &pro
  1191. }
  1192. p.AllIdsMapLock.Unlock()
  1193. p.printMemPro(pid)
  1194. }
  1195. // 打印内存中的项目信息
  1196. func (p *ProjectTask) printMemPro(pid string) {
  1197. p.AllIdsMapLock.Lock()
  1198. if v, ok := p.AllIdsMap[pid]; ok {
  1199. qu.Debug("mem pro ----------", *v.P)
  1200. }
  1201. p.AllIdsMapLock.Unlock()
  1202. }