update.go 36 KB

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