update.go 35 KB

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