update.go 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916
  1. package main
  2. import (
  3. util "app.yhyue.com/data_processing/common_utils"
  4. "app.yhyue.com/data_processing/common_utils/log"
  5. "app.yhyue.com/data_processing/common_utils/mongodb"
  6. "app.yhyue.com/data_processing/common_utils/redis"
  7. "app.yhyue.com/data_processing/common_utils/udp"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/goinggo/mapstructure"
  11. "go.mongodb.org/mongo-driver/bson"
  12. "go.mongodb.org/mongo-driver/bson/primitive"
  13. "go.uber.org/zap"
  14. "math"
  15. "project/config"
  16. "reflect"
  17. "sort"
  18. "strings"
  19. "time"
  20. )
  21. /**
  22. 直接修改保存项目字段信息
  23. */
  24. func (p *ProjectTask) modifyUpdate(pid string, index, position int, tmpPro, modifyProMap map[string]interface{}) {
  25. // 1-0 备份
  26. tmpPro["reason"] = "直接在原有项目上修改字段信息"
  27. backupPro(tmpPro)
  28. delete(tmpPro, "reason")
  29. // 1-1 修改字段信息
  30. updateSet := UpdateValue(tmpPro, index, position, modifyProMap)
  31. updateSet["list"] = tmpPro["list"]
  32. // 1-2 修改mgo
  33. bol := MgoP.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": updateSet})
  34. if bol {
  35. // 1-3 修改es
  36. by, _ := json.Marshal(map[string]interface{}{
  37. "query": map[string]interface{}{
  38. "_id": bson.M{
  39. "$gte": pid,
  40. "$lte": pid,
  41. }},
  42. "stype": "project",
  43. })
  44. log.Info(string(by))
  45. _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
  46. }
  47. // 修改内存
  48. p.modifyMem(tmpPro)
  49. }
  50. func (p *ProjectTask) mergeAndModify(pInfoId string, index, position int, tmp map[string]interface{}, tmpPro map[string]interface{}, modifyMap map[string]interface{}) {
  51. proList := tmpPro["list"].([]interface{})
  52. info := ParseInfo(tmp)
  53. //项目中list大小等于1
  54. if len(proList) == 1 {
  55. log.Info("list大小等于1 合并" + "------1------")
  56. // 2.1 重新合并
  57. merge := p.ReMerge(info, tmp, tmpPro)
  58. if merge {
  59. //合并到新项目中
  60. //删除老项目
  61. p.AllIdsMapLock.Lock()
  62. delete(p.AllIdsMap, pInfoId)
  63. p.AllIdsMapLock.Unlock()
  64. delOldPro(pInfoId)
  65. // 2.2 备份
  66. tmpPro["reason"] = "删除原有项目,修改合并到新的项目中"
  67. backupPro(tmpPro)
  68. } else {
  69. //没有合并到新项目中
  70. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  71. // 修改内存
  72. p.modifyMem(tmpPro)
  73. }
  74. } else if index == 0 {
  75. // 招标公告信息在原有项目中位于第1个
  76. merge := p.ReMerge(info, tmp, tmpPro)
  77. if merge {
  78. // 合并到新项目中
  79. // 该条招标公告信息重新参与合并,该项目的其它招标公告信息逐条参与合并
  80. tmpPro["reason"] = "修改list中第一个条招标公告信息"
  81. backupPro(tmpPro)
  82. delete(tmpPro, "reason")
  83. proList = deleteSlice1(proList, proList[0])
  84. p.AllIdsMapLock.Lock()
  85. Id := p.AllIdsMap[pInfoId]
  86. p.AllIdsMapLock.Unlock()
  87. proMem := Id.P
  88. flag := true // 标记是否需要删除原有项目信息
  89. for _, v := range proList {
  90. v1 := v.(map[string]interface{})
  91. temp, _ := MgoB.FindById(BiddingColl, util.ObjToString(v1["infoid"]), nil)
  92. if len(*temp) == 0 {
  93. temp, _ = MgoB.FindById("bidding_back", util.ObjToString(v1["infoid"]), nil)
  94. if len(*temp) == 0 {
  95. log.Info("extract not find id...", zap.Any("id", v1["infoid"]))
  96. continue
  97. }
  98. }
  99. tempInfo := ParseInfo(*temp)
  100. if flag {
  101. merge := p.ReMerge(tempInfo, *temp, tmpPro)
  102. if !merge {
  103. flag = false
  104. break
  105. }
  106. }
  107. }
  108. if flag {
  109. delOldPro(pInfoId)
  110. } else {
  111. //合并到原有项目中, 不用继续重新合并, 原有项目内部合并即可
  112. p.innerMerge(proList, tmpPro)
  113. bol := MgoP.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
  114. if bol {
  115. by, _ := json.Marshal(map[string]interface{}{
  116. "query": map[string]interface{}{
  117. "_id": bson.M{
  118. "$gte": pInfoId,
  119. "$lte": pInfoId,
  120. }},
  121. "stype": "project",
  122. })
  123. log.Info(string(by))
  124. _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
  125. }
  126. // 修改内存
  127. p.AllIdsMapLock.Lock()
  128. if v, ok := p.AllIdsMap[pInfoId]; ok {
  129. v.P = proMem
  130. }
  131. p.AllIdsMapLock.Unlock()
  132. }
  133. } else {
  134. //没有合并到新项目中,更新list字段,有条件更新项目外围字段
  135. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  136. // 修改内存
  137. p.modifyMem(tmpPro)
  138. }
  139. } else if index == 1 {
  140. // 招标公告信息在原有项目中处于中间某一条
  141. merge := p.ReMerge(info, tmp, tmpPro)
  142. if merge {
  143. tmpPro["reason"] = "修改list中位于中间某一条招标公告信息"
  144. backupPro(tmpPro)
  145. delete(tmpPro, "reason")
  146. p.innerMerge1(proList, util.ObjToString(tmp["infoid"]), tmpPro)
  147. bol := MgoP.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
  148. if bol {
  149. by, _ := json.Marshal(map[string]interface{}{
  150. "query": map[string]interface{}{
  151. "_id": bson.M{
  152. "$gte": pInfoId,
  153. "$lte": pInfoId,
  154. }},
  155. "stype": "project",
  156. })
  157. log.Info(string(by))
  158. _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
  159. }
  160. } else {
  161. // 未合并到新项目中
  162. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  163. // 修改内存
  164. p.modifyMem(tmpPro)
  165. }
  166. } else if index == 2 {
  167. // 招标公告信息在原有项目中位于最后一条
  168. merge := p.ReMerge(info, tmp, tmpPro)
  169. if merge {
  170. // 合并到新项目中
  171. tmpPro["reason"] = "修改list中最后一条招标公告信息"
  172. backupPro(tmpPro)
  173. w := len(proList) - 1
  174. proList = deleteSlice1(proList, proList[w])
  175. p.innerMerge(proList, tmpPro)
  176. bol := MgoP.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
  177. if bol {
  178. by, _ := json.Marshal(map[string]interface{}{
  179. "query": map[string]interface{}{
  180. "_id": bson.M{
  181. "$gte": pInfoId,
  182. "$lte": pInfoId,
  183. }},
  184. "stype": "project",
  185. })
  186. log.Info(string(by))
  187. _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
  188. }
  189. } else {
  190. // 未合并到新项目中
  191. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  192. // 修改内存
  193. p.modifyMem(tmpPro)
  194. }
  195. }
  196. }
  197. // 删除
  198. func (p *ProjectTask) delJudge(infoid, pid string) {
  199. tmpPro, _ := MgoP.FindById(ProjectColl, pid, nil)
  200. ids := (*tmpPro)["ids"].([]interface{})
  201. proList := (*tmpPro)["list"].([]interface{})
  202. if len(ids) == 1 {
  203. (*tmpPro)["reason"] = "删除项目信息"
  204. backupPro(*tmpPro)
  205. c := MgoP.Delete(ProjectColl, map[string]interface{}{"_id": mongodb.StringTOBsonId(pid)})
  206. if c > 0 {
  207. client := Es.GetEsConn()
  208. defer Es.DestoryEsConn(client)
  209. Es.DelById(config.Conf.DB.Es.Index, pid)
  210. }
  211. return
  212. }
  213. var index = -1 //0:第一个,1:中间,2:最后一个
  214. for i, v := range ids {
  215. if util.ObjToString(v) == infoid {
  216. if i == 0 {
  217. index = 0
  218. } else if i == len(ids)-1 {
  219. index = 2
  220. } else {
  221. index = 1
  222. }
  223. }
  224. }
  225. if index == 0 {
  226. (*tmpPro)["reason"] = "删除list中第一个条招标公告信息"
  227. backupPro(*tmpPro)
  228. delete(*tmpPro, "reason")
  229. proList = deleteSlice1(proList, proList[0])
  230. var pro *ProjectCache
  231. flag := true // 标记是否需要删除原有项目信息
  232. for _, v := range proList {
  233. v1 := v.(map[string]interface{})
  234. temp, _ := MgoB.FindById(BiddingColl, util.ObjToString(v1["infoid"]), nil)
  235. if len(*temp) == 0 {
  236. temp, _ = MgoB.FindById("bidding_back", util.ObjToString(v1["infoid"]), nil)
  237. if len(*temp) == 0 {
  238. log.Info("extract not find id...", zap.Any("id", v1["infoid"]))
  239. continue
  240. }
  241. }
  242. tempInfo := ParseInfo(*temp)
  243. if flag {
  244. merge := p.ReMerge(tempInfo, *temp, *tmpPro)
  245. if !merge {
  246. flag = false
  247. break
  248. }
  249. }
  250. }
  251. if flag {
  252. delOldPro(pid)
  253. } else {
  254. *tmpPro, pro = p.innerMerge(proList, *tmpPro)
  255. bol := MgoP.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
  256. if bol {
  257. by, _ := json.Marshal(map[string]interface{}{
  258. "query": map[string]interface{}{
  259. "_id": bson.M{
  260. "$gte": pid,
  261. "$lte": pid,
  262. }},
  263. "stype": "project",
  264. })
  265. _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
  266. }
  267. // 修改内存
  268. p.AllIdsMapLock.Lock()
  269. if v, ok := p.AllIdsMap[pid]; ok {
  270. v.P = pro
  271. }
  272. p.AllIdsMapLock.Unlock()
  273. }
  274. } else if index == 1 {
  275. (*tmpPro)["reason"] = "删除list中间某一条招标公告信息"
  276. backupPro(*tmpPro)
  277. delete(*tmpPro, "reason")
  278. var pro *ProjectCache
  279. *tmpPro, pro = p.innerMerge1(proList, infoid, *tmpPro)
  280. bol := MgoP.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
  281. if bol {
  282. by, _ := json.Marshal(map[string]interface{}{
  283. "query": map[string]interface{}{
  284. "_id": bson.M{
  285. "$gte": pid,
  286. "$lte": pid,
  287. }},
  288. "stype": "project",
  289. })
  290. _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
  291. }
  292. // 内存
  293. p.AllIdsMapLock.Lock()
  294. if v, ok := p.AllIdsMap[pid]; ok {
  295. v.P = pro
  296. }
  297. p.AllIdsMapLock.Unlock()
  298. } else if index == 2 {
  299. (*tmpPro)["reason"] = "删除list中最后一条招标公告信息"
  300. backupPro(*tmpPro)
  301. delete(*tmpPro, "reason")
  302. w := len(proList) - 1
  303. proList = deleteSlice1(proList, proList[w])
  304. var pro *ProjectCache
  305. *tmpPro, pro = p.innerMerge(proList, *tmpPro)
  306. bol := MgoP.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
  307. if bol {
  308. by, _ := json.Marshal(map[string]interface{}{
  309. "query": map[string]interface{}{
  310. "_id": bson.M{
  311. "$gte": pid,
  312. "$lte": pid,
  313. }},
  314. "stype": "project",
  315. })
  316. _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
  317. }
  318. // 内存
  319. p.AllIdsMapLock.Lock()
  320. if v, ok := p.AllIdsMap[pid]; ok {
  321. v.P = pro
  322. }
  323. p.AllIdsMapLock.Unlock()
  324. }
  325. }
  326. // 合并
  327. func (p *ProjectTask) ReMerge(info *Info, tmp map[string]interface{}, tmpPro map[string]interface{}) bool {
  328. bpn, bpc, bptc, bpb, pids, _, IDArr := p.getCompareIds(info.ProjectName, info.ProjectCode, info.PTC, info.Buyer)
  329. defer p.wg.Done()
  330. for _, m := range pids {
  331. defer m.Lock.Unlock()
  332. }
  333. for _, id := range IDArr {
  334. defer id.Lock.Unlock()
  335. }
  336. bFindProject := false
  337. findPid := ""
  338. comRes1 := []*ProjectCache{}
  339. comRes2 := []*ProjectCache{}
  340. comRes3 := []*ProjectCache{}
  341. for _, v := range IDArr {
  342. comStr := ""
  343. compareProject := v.P
  344. compareProject.score = 0
  345. diffTime := int64(math.Abs(float64(info.Publishtime - compareProject.LastTime)))
  346. if diffTime <= p.validTime {
  347. if CheckContain(compareProject.Agency, info.Agency) == 3 {
  348. continue
  349. }
  350. if ComparePlace(compareProject, info) {
  351. continue
  352. }
  353. info.PNBH = 0
  354. info.PCBH = 0
  355. info.PTCBH = 0
  356. compareStr, score := comparePNC(info, compareProject)
  357. resVal, pjVal := Select(compareStr, info, compareProject)
  358. if resVal > 0 {
  359. compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount, score2 := p.compareBCTABB(info, compareProject, diffTime, score)
  360. comStr = compareStr + compareBuyer + compareCity + compareTime + compareAgency + compareBudget + compareBidmount
  361. compareProject.comStr = comStr
  362. compareProject.pjVal = pjVal
  363. compareProject.resVal = resVal
  364. eqV := compareResult(resVal, pjVal, score2, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount)
  365. if eqV == 1 {
  366. comRes1 = append(comRes1, compareProject)
  367. } else if eqV == 2 {
  368. comRes2 = append(comRes2, compareProject)
  369. } else if eqV == 3 {
  370. comRes3 = append(comRes3, compareProject)
  371. }
  372. }
  373. }
  374. }
  375. //--------------------------------对比完成-----------------------
  376. for kv, resN := range [][]*ProjectCache{comRes1, comRes2, comRes3} {
  377. if len(resN) > 0 {
  378. if len(resN) > 1 {
  379. sort.Slice(resN, func(i, j int) bool {
  380. return resN[i].score > resN[j].score
  381. })
  382. }
  383. ex := 0
  384. resArr := []*ProjectCache{}
  385. for i, res := range resN {
  386. choose, e := p.CompareStatus(resN[i], info)
  387. if !choose {
  388. ex = e
  389. resArr = append(resArr, res)
  390. }
  391. }
  392. if len(resArr) > 0 {
  393. bFindProject = true
  394. findPid = resArr[0].Id.Hex()
  395. if findPid == mongodb.BsonIdToSId(tmpPro["_id"]) {
  396. return false
  397. }
  398. p.updateProFiled(tmp, info, resArr[0], kv+1, resArr[0].comStr, ex)
  399. for k2, bv := range []int{bpn, bpc, bptc, bpb} {
  400. if bv > -1 {
  401. pids[bv].Arr = append(pids[bv].Arr, findPid)
  402. if k2 == 0 {
  403. if resArr[0].ProjectName == "" {
  404. resArr[0].ProjectName = info.ProjectName
  405. } else {
  406. if resArr[0].MPN == nil {
  407. resArr[0].MPN = []string{info.ProjectName}
  408. } else {
  409. resArr[0].MPN = append(resArr[0].MPN, info.ProjectName)
  410. }
  411. }
  412. } else if k2 < 3 {
  413. if resArr[0].ProjectCode == "" {
  414. resArr[0].ProjectCode = util.If(k2 == 1, info.ProjectCode, info.PTC).(string)
  415. } else {
  416. if resArr[0].MPC == nil {
  417. resArr[0].MPC = []string{util.If(k2 == 1, info.ProjectCode, info.PTC).(string)}
  418. } else {
  419. resArr[0].MPC = append(resArr[0].MPC, util.If(k2 == 1, info.ProjectCode, info.PTC).(string))
  420. }
  421. }
  422. } else {
  423. if resArr[0].Buyer == "" {
  424. resArr[0].Buyer = info.Buyer
  425. }
  426. }
  427. }
  428. }
  429. } else {
  430. bFindProject = false
  431. findPid = ""
  432. }
  433. break
  434. }
  435. }
  436. if !bFindProject {
  437. id, p1 := p.NewProject(tmp, info)
  438. p.AllIdsMapLock.Lock()
  439. p.AllIdsMap[id] = &ID{Id: id, P: p1}
  440. p.AllIdsMapLock.Unlock()
  441. for _, m := range pids {
  442. m.Arr = append(m.Arr, id)
  443. }
  444. return false
  445. }
  446. return true
  447. }
  448. //内部合并
  449. func (p *ProjectTask) innerMerge(infoList []interface{}, tmpPro map[string]interface{}) (map[string]interface{}, *ProjectCache) {
  450. newP := make(map[string]interface{})
  451. newP["_id"] = tmpPro["_id"]
  452. var p1 *ProjectCache
  453. for k, m := range infoList {
  454. m1 := m.(map[string]interface{})
  455. temp, _ := MgoB.FindById(BiddingColl, util.ObjToString(m1["infoid"]), nil)
  456. if len(*temp) == 0 {
  457. temp, _ = MgoB.FindById("bidding_back", util.ObjToString(m1["infoid"]), nil)
  458. if len(*temp) == 0 {
  459. continue
  460. }
  461. }
  462. tempInfo := ParseInfo(*temp)
  463. if k == 0 {
  464. p1 = p.newPro(*temp, newP, tempInfo)
  465. } else {
  466. p.updateOldProField(p1, tempInfo, newP, *temp, m1)
  467. }
  468. }
  469. return newP, p1
  470. }
  471. func (p *ProjectTask) innerMerge1(infoList []interface{}, infoid string, tmpPro map[string]interface{}) (map[string]interface{}, *ProjectCache) {
  472. newP := make(map[string]interface{})
  473. newP["_id"] = tmpPro["_id"]
  474. var p1 *ProjectCache
  475. for k, m := range infoList {
  476. m1 := m.(map[string]interface{})
  477. if m1["infoid"] == infoid {
  478. continue
  479. }
  480. temp, _ := MgoB.FindById(BiddingColl, util.ObjToString(m1["infoid"]), nil)
  481. if len(*temp) == 0 {
  482. temp, _ = MgoB.FindById("bidding_back", util.ObjToString(m1["infoid"]), nil)
  483. if len(*temp) == 0 {
  484. log.Info("extract not find id...", zap.Any("id", m1["infoid"]))
  485. continue
  486. }
  487. }
  488. tempInfo := ParseInfo(*temp)
  489. if k == 0 {
  490. p1 = p.newPro(*temp, newP, tempInfo)
  491. } else {
  492. p.updateOldProField(p1, tempInfo, newP, *temp, m1)
  493. }
  494. }
  495. return newP, p1
  496. }
  497. // 更新招标公告到新的项目中
  498. func (p *ProjectTask) updateProFiled(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectCache, weight int, comStr string, ex int) {
  499. pdata := redis.Get("project", pInfo.Id.Hex())
  500. projectMap := pdata.(map[string]interface{})
  501. bys, _ := json.Marshal(projectMap)
  502. var project *Project
  503. err := json.Unmarshal(bys, &project)
  504. if err != nil {
  505. log.Info("project Unmarshal err," + err.Error())
  506. return
  507. }
  508. set := map[string]interface{}{}
  509. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  510. project.Ids = append(project.Ids, thisinfo.Id)
  511. if len(pInfo.Ids) > 30 {
  512. //异常标记
  513. set["listtag"] = 1
  514. }
  515. if thisinfo.Publishtime > pInfo.LastTime {
  516. pInfo.LastTime = thisinfo.Publishtime
  517. project.LastTime = thisinfo.Publishtime
  518. set["lasttime"] = thisinfo.Publishtime
  519. }
  520. if thisinfo.TopType == "招标" {
  521. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && project.Zbtime <= 0 {
  522. set["zbtime"] = tmp["publishtime"]
  523. }
  524. } else if thisinfo.TopType == "结果" {
  525. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  526. if project.Jgtime > 0 {
  527. jg1 := int64(math.Abs(float64(project.Jgtime - thisinfo.Publishtime)))
  528. //公告状态和项目状态同样都是中标或者成交,
  529. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  530. if jg1 > p.jgTime {
  531. set["jgtime"] = tmp["publishtime"]
  532. project.Jgtime = thisinfo.Publishtime
  533. }
  534. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  535. //公告状态和项目状态同样是流标或者废标
  536. if jg1 > p.jgTime {
  537. set["jgtime"] = tmp["publishtime"]
  538. project.Jgtime = thisinfo.Publishtime
  539. }
  540. }
  541. } else {
  542. set["jgtime"] = tmp["publishtime"]
  543. project.Jgtime = thisinfo.Publishtime
  544. }
  545. }
  546. } else if thisinfo.SubType == "合同" {
  547. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  548. //中标、成交不更新jgtime
  549. } else {
  550. set["jgtime"] = tmp["publishtime"]
  551. project.Jgtime = thisinfo.Publishtime
  552. }
  553. }
  554. if thisinfo.BidOpenTime > project.BidOpenTime {
  555. project.BidOpenTime = thisinfo.BidOpenTime
  556. set["bidopentime"] = thisinfo.BidOpenTime
  557. }
  558. if thisinfo.BidEndTime > 0 {
  559. project.BidEndTime = thisinfo.BidEndTime
  560. set["bidendtime"] = project.BidEndTime
  561. }
  562. // bidtype、bidstatus
  563. pInfo.Bidtype, pInfo.Bidstatus = p.GetBidTypeAndBidStatus(thisinfo)
  564. project.Bidtype, project.Bidstatus = p.GetBidTypeAndBidStatus(thisinfo)
  565. set["bidtype"] = pInfo.Bidtype
  566. set["bidstatus"] = pInfo.Bidstatus
  567. //异常标记
  568. if ex > 0 {
  569. set["exception"] = ex
  570. }
  571. //相同城市的公告才会合并到一起(全国列外)
  572. if thisinfo.Area != "全国" {
  573. pInfo.Area = thisinfo.Area
  574. project.Area = thisinfo.Area
  575. set["area"] = thisinfo.Area
  576. pInfo.City = thisinfo.City
  577. project.City = thisinfo.City
  578. set["city"] = thisinfo.City
  579. if thisinfo.District != "" {
  580. pInfo.District = thisinfo.District
  581. project.District = thisinfo.District
  582. set["district"] = thisinfo.District
  583. }
  584. }
  585. // 项目名称
  586. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  587. pInfo.ProjectName = thisinfo.ProjectName
  588. project.ProjectName = thisinfo.ProjectName
  589. set["projectname"] = thisinfo.ProjectName
  590. }
  591. // 项目编号
  592. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  593. pInfo.ProjectCode = thisinfo.ProjectCode
  594. project.ProjectCode = thisinfo.ProjectCode
  595. set["projectcode"] = thisinfo.ProjectCode
  596. }
  597. // 采购单位
  598. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  599. pInfo.Buyer = thisinfo.Buyer
  600. set["buyer"] = thisinfo.Buyer
  601. project.Buyerclass = thisinfo.Buyerclass
  602. set["buyerclass"] = thisinfo.Buyerclass
  603. }
  604. if pInfo.Buyer == "" {
  605. project.Buyerclass = ""
  606. set["buyerclass"] = ""
  607. }
  608. // 采购单位联系人
  609. if thisinfo.Buyerperson != "" {
  610. project.Buyerperson = thisinfo.Buyerperson
  611. set["buyerperson"] = thisinfo.Buyerperson
  612. } else {
  613. project.Buyerperson = ""
  614. set["buyerperson"] = ""
  615. }
  616. // 采购单位電話
  617. if thisinfo.Buyertel != "" {
  618. project.Buyertel = thisinfo.Buyertel
  619. set["buyertel"] = thisinfo.Buyertel
  620. } else {
  621. project.Buyertel = ""
  622. set["buyertel"] = ""
  623. }
  624. if thisinfo.ContractCode != "" {
  625. set["contractcode"] = project.ContractCode + "," + thisinfo.ContractCode
  626. }
  627. // 代理机构 相同的代理机构才会合并到一个项目 2020.11.9
  628. //if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  629. // pInfo.Agency = thisinfo.Agency
  630. // set["agency"] = thisinfo.Agency
  631. //}
  632. if len(thisinfo.Topscopeclass) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  633. sort.Strings(project.Topscopeclass)
  634. for _, k := range thisinfo.Topscopeclass {
  635. if BinarySearch(project.Topscopeclass, k) == -1 {
  636. project.Topscopeclass = append(project.Topscopeclass, k)
  637. sort.Strings(project.Topscopeclass)
  638. }
  639. }
  640. set["topscopeclass"] = project.Topscopeclass
  641. }
  642. // 项目评审专家
  643. if len(thisinfo.ReviewExperts) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  644. set["review_experts"] = thisinfo.ReviewExperts
  645. project.ReviewExperts = thisinfo.ReviewExperts
  646. }
  647. if thisinfo.Purchasing != "" && thisinfo.Publishtime > pInfo.LastTime {
  648. if project.Purchasing == "" {
  649. project.Purchasing = thisinfo.Purchasing
  650. set["purchasing"] = thisinfo.Purchasing
  651. } else {
  652. list := strings.Split(project.Purchasing, ",")
  653. for _, k := range list {
  654. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  655. list = append(list, k)
  656. sort.Strings(list)
  657. }
  658. }
  659. set["purchasing"] = strings.Join(list, ",")
  660. }
  661. }
  662. //中标候选人
  663. if len(thisinfo.WinnerOrder) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  664. var list = []string{}
  665. for _, v := range thisinfo.WinnerOrder {
  666. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  667. list = append(list, util.ObjToString(v["entname"]))
  668. }
  669. }
  670. set["winnerorder"] = list
  671. project.Winnerorder = list
  672. }
  673. if len(thisinfo.Subscopeclass) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  674. sort.Strings(project.Subscopeclass)
  675. for _, k := range thisinfo.Subscopeclass {
  676. if BinarySearch(project.Subscopeclass, k) == -1 {
  677. project.Subscopeclass = append(project.Subscopeclass, k)
  678. sort.Strings(project.Subscopeclass)
  679. }
  680. }
  681. set["subscopeclass"] = project.Subscopeclass
  682. set["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
  683. }
  684. if len(thisinfo.Winners) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  685. winners := strings.Split(project.Winners, ",")
  686. if len(winners) <= 0 {
  687. set["winner"] = util.ObjToString(tmp["winner"])
  688. }
  689. for _, k := range thisinfo.Winners {
  690. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  691. if BinarySearch(winners, k) != -1 {
  692. deleteSlice(winners, k, "")
  693. sort.Strings(winners)
  694. }
  695. } else {
  696. if BinarySearch(winners, k) == -1 {
  697. winners = append(winners, k)
  698. sort.Strings(winners)
  699. }
  700. }
  701. }
  702. set["s_winner"] = strings.Join(winners, ",")
  703. }
  704. if thisinfo.HasPackage { //多包处理
  705. set["multipackage"] = 1
  706. pkg := PackageFormat(thisinfo, project)
  707. project.Package = pkg
  708. set["package"] = project.Package
  709. }
  710. //处理多包后,计算预算金额、中标金额
  711. CountAmount(project, thisinfo, tmp)
  712. if project.Budget >= 0 && project.Budgettag != 1 {
  713. pInfo.Budget = project.Budget
  714. set["budget"] = pInfo.Budget
  715. set["budgettag"] = 0
  716. }
  717. if pInfo.Bidamount >= 0 && project.Bidamounttag != 1 {
  718. pInfo.Bidamount = project.Bidamount
  719. set["bidamount"] = pInfo.Bidamount
  720. set["bidamounttag"] = 0
  721. }
  722. if pInfo.Bidamount > 0 {
  723. set["sortprice"] = pInfo.Bidamount
  724. } else {
  725. if pInfo.Budget > 0 {
  726. set["sortprice"] = pInfo.Budget
  727. }
  728. }
  729. infofield := InfoField{
  730. Budget: thisinfo.Budget,
  731. Bidamount: thisinfo.Bidamount,
  732. ContractCode: thisinfo.ContractCode,
  733. ProjectName: thisinfo.ProjectName,
  734. ProjectCode: thisinfo.ProjectCode,
  735. Bidstatus: pInfo.Bidstatus,
  736. }
  737. copyMap := util.DeepCopy(project.InfoFiled).(map[string]InfoField)
  738. copyMap[thisinfo.Id] = infofield
  739. tmpMap := make(map[string]interface{})
  740. for k, v := range copyMap {
  741. tmpMap[k] = StructToMap(v)
  742. }
  743. tmpMap[thisinfo.Id] = StructToMap(infofield)
  744. project.InfoFiled = copyMap
  745. set["infofield"] = tmpMap
  746. set["mpn"] = pInfo.MPN
  747. set["mpc"] = pInfo.MPC
  748. set["updatetime"] = p.pici
  749. redis.PutCKV("project", project.Id.Hex(), set)
  750. update := map[string]interface{}{}
  751. if len(set) > 0 {
  752. update["$set"] = set
  753. }
  754. push := p.PushListInfo(tmp, thisinfo.Id)
  755. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  756. push["compareStr"] = comStr
  757. push["resVal"] = pInfo.resVal
  758. push["pjVal"] = pInfo.pjVal
  759. update["$push"] = map[string]interface{}{
  760. "list": push,
  761. "ids": thisinfo.Id,
  762. }
  763. bol := MgoP.UpdateById(ProjectColl, pInfo.Id.Hex(), update)
  764. if bol {
  765. by, _ := json.Marshal(map[string]interface{}{
  766. "query": map[string]interface{}{
  767. "_id": bson.M{
  768. "$gte": pInfo.Id.Hex(),
  769. "$lte": pInfo.Id.Hex(),
  770. }},
  771. "stype": "project",
  772. })
  773. log.Info(string(by))
  774. _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
  775. }
  776. }
  777. // 内部合并时,原有项目id基础上新建项目
  778. func (p *ProjectTask) newPro(tmp, tmpPro map[string]interface{}, thisinfo *Info) *ProjectCache {
  779. for _, f := range FIELDS {
  780. if tmp[f] != nil && tmp[f] != "" {
  781. tmpPro[f] = tmp[f]
  782. }
  783. }
  784. bidopentime := util.Int64All(tmp["bidopentime"])
  785. if bidopentime > 0 {
  786. tmpPro["bidopentime"] = bidopentime
  787. }
  788. //异常标记
  789. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  790. tmpPro["exception"] = 1
  791. }
  792. //projecthref保存
  793. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  794. if jsonData != nil && util.ObjToString(jsonData["projecthref"]) != "" {
  795. tmpPro["projecthref"] = jsonData["projecthref"]
  796. }
  797. }
  798. //合同编号
  799. if thisinfo.ContractCode != "" {
  800. tmpPro["contractcode"] = thisinfo.ContractCode
  801. }
  802. bs, bt := p.GetBidTypeAndBidStatus(thisinfo)
  803. tmpPro["bidtype"] = bs
  804. tmpPro["bidstatus"] = bt
  805. pkg := PackageFormat(thisinfo, nil)
  806. p1 := p.NewCachePinfo(tmpPro["_id"].(primitive.ObjectID), thisinfo, bs, bt)
  807. now := time.Now().Unix()
  808. tmpPro["createtime"] = now
  809. tmpPro["sourceinfoid"] = thisinfo.Id
  810. tmpPro["sourceinfourl"] = tmp["href"]
  811. tmpPro["firsttime"] = tmp["publishtime"]
  812. tmpPro["lasttime"] = tmp["publishtime"]
  813. tmpPro["pici"] = tmp["comeintime"]
  814. tmpPro["ids"] = []string{thisinfo.Id}
  815. if thisinfo.TopType == "招标" {
  816. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  817. tmpPro["zbtime"] = tmp["publishtime"]
  818. }
  819. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  820. tmpPro["jgtime"] = tmp["publishtime"]
  821. }
  822. if len(thisinfo.Subscopeclass) > 0 {
  823. tmpPro["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  824. }
  825. if len(thisinfo.Winners) > 0 {
  826. tmpPro["s_winner"] = strings.Join(thisinfo.Winners, ",")
  827. }
  828. if thisinfo.HasPackage {
  829. tmpPro["multipackage"] = 1
  830. tmpPro["package"] = pkg
  831. } else {
  832. tmpPro["multipackage"] = 0
  833. }
  834. //项目评审专家
  835. if len(thisinfo.ReviewExperts) > 0 {
  836. tmpPro["review_experts"] = thisinfo.ReviewExperts
  837. }
  838. //标的物
  839. if thisinfo.Purchasing != "" {
  840. tmpPro["purchasing"] = thisinfo.Purchasing
  841. }
  842. //中标候选人
  843. if len(thisinfo.WinnerOrder) > 0 {
  844. var list = []string{}
  845. for _, v := range thisinfo.WinnerOrder {
  846. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  847. list = append(list, util.ObjToString(v["entname"]))
  848. }
  849. }
  850. tmpPro["winnerorder"] = list
  851. }
  852. infofield := InfoField{
  853. Budget: thisinfo.Budget,
  854. Bidamount: thisinfo.Bidamount,
  855. ContractCode: thisinfo.ContractCode,
  856. ProjectName: thisinfo.ProjectName,
  857. ProjectCode: thisinfo.ProjectCode,
  858. Bidstatus: bs,
  859. }
  860. res := StructToMap(infofield)
  861. tmpPro["infofield"] = map[string]interface{}{
  862. thisinfo.Id: res,
  863. }
  864. if tmp["budget"] != nil && tmp["budget"] != "" {
  865. tmpPro["budget"] = thisinfo.Budget
  866. tmpPro["budgettag"] = 0
  867. } else {
  868. tmpPro["budgettag"] = 1
  869. }
  870. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  871. tmpPro["bidamount"] = thisinfo.Bidamount
  872. tmpPro["bidamounttag"] = 0
  873. } else {
  874. tmpPro["bidamounttag"] = 1
  875. }
  876. if p1.Bidamount > 0 {
  877. tmpPro["sortprice"] = p1.Bidamount
  878. } else if p1.Budget > 0 {
  879. tmpPro["sortprice"] = p1.Budget
  880. }
  881. push := p.PushListInfo(tmp, thisinfo.Id)
  882. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  883. tmpPro["list"] = []map[string]interface{}{
  884. push,
  885. }
  886. return &p1
  887. }
  888. // 合并字段到老项目中
  889. func (p *ProjectTask) updateOldProField(pInfo *ProjectCache, thisinfo *Info, tmpPro, tmp, m1 map[string]interface{}) {
  890. pdata := redis.Get("project", pInfo.Id.Hex())
  891. projectMap := pdata.(map[string]interface{})
  892. bys, _ := json.Marshal(projectMap)
  893. var project *Project
  894. err := json.Unmarshal(bys, &project)
  895. if err != nil {
  896. log.Error("project Unmarshal err," + err.Error())
  897. return
  898. }
  899. if len(pInfo.Ids) > 30 {
  900. //异常标记
  901. tmpPro["listtag"] = 1
  902. }
  903. if thisinfo.Publishtime > pInfo.LastTime {
  904. pInfo.LastTime = thisinfo.Publishtime
  905. project.LastTime = thisinfo.Publishtime
  906. tmpPro["lasttime"] = thisinfo.Publishtime
  907. }
  908. if thisinfo.TopType == "招标" {
  909. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && project.Zbtime <= 0 {
  910. tmpPro["zbtime"] = tmp["publishtime"]
  911. }
  912. } else if thisinfo.TopType == "结果" {
  913. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  914. if project.Jgtime > 0 {
  915. jg1 := int64(math.Abs(float64(project.Jgtime - thisinfo.Publishtime)))
  916. //公告状态和项目状态同样都是中标或者成交,
  917. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  918. if jg1 > p.jgTime {
  919. tmpPro["jgtime"] = tmp["publishtime"]
  920. project.Jgtime = thisinfo.Publishtime
  921. }
  922. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  923. //公告状态和项目状态同样是流标或者废标
  924. if jg1 > p.jgTime {
  925. tmpPro["jgtime"] = tmp["publishtime"]
  926. project.Jgtime = thisinfo.Publishtime
  927. }
  928. }
  929. } else {
  930. tmpPro["jgtime"] = tmp["publishtime"]
  931. project.Jgtime = thisinfo.Publishtime
  932. }
  933. }
  934. } else if thisinfo.SubType == "合同" {
  935. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  936. //中标、成交不更新jgtime
  937. } else {
  938. tmpPro["jgtime"] = tmp["publishtime"]
  939. project.Jgtime = thisinfo.Publishtime
  940. }
  941. }
  942. if thisinfo.BidOpenTime > project.BidOpenTime {
  943. project.BidOpenTime = thisinfo.BidOpenTime
  944. tmpPro["bidopentime"] = thisinfo.BidOpenTime
  945. }
  946. if thisinfo.BidEndTime > 0 {
  947. project.BidEndTime = thisinfo.BidEndTime
  948. tmpPro["bidendtime"] = thisinfo.BidEndTime
  949. }
  950. // bidtype、bidstatus
  951. pInfo.Bidtype, pInfo.Bidstatus = p.GetBidTypeAndBidStatus(thisinfo)
  952. project.Bidtype, project.Bidstatus = p.GetBidTypeAndBidStatus(thisinfo)
  953. tmpPro["bidtype"] = pInfo.Bidtype
  954. tmpPro["bidstatus"] = pInfo.Bidstatus
  955. //相同城市的公告才会合并到一起(全国列外)
  956. if thisinfo.Area != "全国" {
  957. pInfo.Area = thisinfo.Area
  958. project.Area = thisinfo.Area
  959. tmpPro["area"] = thisinfo.Area
  960. pInfo.City = thisinfo.City
  961. project.City = thisinfo.City
  962. tmpPro["city"] = thisinfo.City
  963. if thisinfo.District != "" {
  964. pInfo.District = thisinfo.District
  965. project.District = thisinfo.District
  966. tmpPro["district"] = thisinfo.District
  967. }
  968. }
  969. // 项目名称
  970. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  971. pInfo.ProjectName = thisinfo.ProjectName
  972. project.ProjectName = thisinfo.ProjectName
  973. tmpPro["projectname"] = thisinfo.ProjectName
  974. }
  975. // 项目编号
  976. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  977. pInfo.ProjectCode = thisinfo.ProjectCode
  978. project.ProjectCode = thisinfo.ProjectCode
  979. tmpPro["projectcode"] = thisinfo.ProjectCode
  980. }
  981. // 采购单位
  982. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  983. pInfo.Buyer = thisinfo.Buyer
  984. tmpPro["buyer"] = thisinfo.Buyer
  985. project.Buyerclass = thisinfo.Buyerclass
  986. tmpPro["buyerclass"] = thisinfo.Buyerclass
  987. }
  988. if pInfo.Buyer == "" {
  989. project.Buyerclass = ""
  990. tmpPro["buyerclass"] = ""
  991. }
  992. // 采购单位联系人
  993. if thisinfo.Buyerperson != "" {
  994. project.Buyerperson = thisinfo.Buyerperson
  995. tmpPro["buyerperson"] = thisinfo.Buyerperson
  996. } else {
  997. project.Buyerperson = ""
  998. tmpPro["buyerperson"] = ""
  999. }
  1000. // 采购单位電話
  1001. if thisinfo.Buyertel != "" {
  1002. project.Buyertel = thisinfo.Buyertel
  1003. tmpPro["buyertel"] = thisinfo.Buyertel
  1004. } else {
  1005. project.Buyertel = ""
  1006. tmpPro["buyertel"] = ""
  1007. }
  1008. if thisinfo.ContractCode != "" {
  1009. tmpPro["contractcode"] = project.ContractCode + "," + thisinfo.ContractCode
  1010. }
  1011. // 代理机构 相同的代理机构才会合并到一个项目 2020.11.9
  1012. //if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  1013. // pInfo.Agency = thisinfo.Agency
  1014. // set["agency"] = thisinfo.Agency
  1015. //}
  1016. if len(thisinfo.Topscopeclass) > 0 {
  1017. sort.Strings(project.Topscopeclass)
  1018. for _, k := range thisinfo.Topscopeclass {
  1019. if BinarySearch(project.Topscopeclass, k) == -1 {
  1020. project.Topscopeclass = append(project.Topscopeclass, k)
  1021. sort.Strings(project.Topscopeclass)
  1022. }
  1023. }
  1024. tmpPro["topscopeclass"] = project.Topscopeclass
  1025. }
  1026. // 项目评审专家
  1027. if len(thisinfo.ReviewExperts) > 0 {
  1028. tmpPro["review_experts"] = thisinfo.ReviewExperts
  1029. project.ReviewExperts = thisinfo.ReviewExperts
  1030. }
  1031. if thisinfo.Purchasing != "" {
  1032. if project.Purchasing == "" {
  1033. project.Purchasing = thisinfo.Purchasing
  1034. tmpPro["purchasing"] = thisinfo.Purchasing
  1035. } else {
  1036. list := strings.Split(project.Purchasing, ",")
  1037. for _, k := range list {
  1038. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  1039. list = append(list, k)
  1040. sort.Strings(list)
  1041. }
  1042. }
  1043. tmpPro["purchasing"] = strings.Join(list, ",")
  1044. }
  1045. }
  1046. //中标候选人
  1047. if len(thisinfo.WinnerOrder) > 0 {
  1048. var list = []string{}
  1049. for _, v := range thisinfo.WinnerOrder {
  1050. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  1051. list = append(list, util.ObjToString(v["entname"]))
  1052. }
  1053. }
  1054. tmpPro["winnerorder"] = list
  1055. project.Winnerorder = list
  1056. }
  1057. if len(thisinfo.Subscopeclass) > 0 {
  1058. sort.Strings(project.Subscopeclass)
  1059. for _, k := range thisinfo.Subscopeclass {
  1060. if BinarySearch(project.Subscopeclass, k) == -1 {
  1061. project.Subscopeclass = append(project.Subscopeclass, k)
  1062. sort.Strings(project.Subscopeclass)
  1063. }
  1064. }
  1065. tmpPro["subscopeclass"] = project.Subscopeclass
  1066. tmpPro["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
  1067. }
  1068. if len(thisinfo.Winners) > 0 {
  1069. if len(project.Winners) <= 0 {
  1070. tmpPro["winner"] = util.ObjToString(tmp["winner"])
  1071. }
  1072. winners := strings.Split(project.Winners, ",")
  1073. for _, k := range thisinfo.Winners {
  1074. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  1075. if BinarySearch(winners, k) != -1 {
  1076. deleteSlice(winners, k, "")
  1077. }
  1078. } else {
  1079. if BinarySearch(winners, k) == -1 {
  1080. winners = append(winners, k)
  1081. }
  1082. }
  1083. }
  1084. tmpPro["s_winner"] = strings.Join(winners, ",")
  1085. }
  1086. if thisinfo.HasPackage { //多包处理
  1087. tmpPro["multipackage"] = 1
  1088. pkg := PackageFormat(thisinfo, project)
  1089. project.Package = pkg
  1090. tmpPro["package"] = project.Package
  1091. }
  1092. //处理多包后,计算预算金额、中标金额
  1093. CountAmount(project, thisinfo, tmp)
  1094. if project.Budget >= 0 && project.Budgettag != 1 {
  1095. pInfo.Budget = project.Budget
  1096. tmpPro["budget"] = pInfo.Budget
  1097. tmpPro["budgettag"] = 0
  1098. }
  1099. if project.Bidamount >= 0 && project.Bidamounttag != 1 {
  1100. pInfo.Bidamount = project.Bidamount
  1101. tmpPro["bidamount"] = pInfo.Bidamount
  1102. tmpPro["bidamounttag"] = 0
  1103. }
  1104. if pInfo.Bidamount >= pInfo.Budget {
  1105. tmpPro["sortprice"] = pInfo.Bidamount
  1106. } else if pInfo.Budget >= pInfo.Bidamount {
  1107. tmpPro["sortprice"] = pInfo.Budget
  1108. }
  1109. infofield := InfoField{
  1110. Budget: thisinfo.Budget,
  1111. Bidamount: thisinfo.Bidamount,
  1112. ContractCode: thisinfo.ContractCode,
  1113. ProjectName: thisinfo.ProjectName,
  1114. ProjectCode: thisinfo.ProjectCode,
  1115. Bidstatus: pInfo.Bidstatus,
  1116. }
  1117. copyMap := util.DeepCopy(project.InfoFiled).(map[string]InfoField)
  1118. copyMap[thisinfo.Id] = infofield
  1119. tmpMap := make(map[string]interface{})
  1120. for k, v := range copyMap {
  1121. tmpMap[k] = StructToMap(v)
  1122. }
  1123. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1124. project.InfoFiled = copyMap
  1125. tmpPro["infofield"] = tmpMap
  1126. tmpPro["mpn"] = pInfo.MPN
  1127. tmpPro["mpc"] = pInfo.MPC
  1128. tmpPro["updatetime"] = p.pici
  1129. push := p.PushListInfo(tmp, thisinfo.Id)
  1130. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1131. push["compareStr"] = m1["compareStr"]
  1132. push["resVal"] = m1["resVal"]
  1133. push["pjVal"] = m1["pjVal"]
  1134. list := tmpPro["list"].([]map[string]interface{})
  1135. tmpPro["list"] = append(list, push)
  1136. tmpPro["ids"] = append(tmpPro["ids"].([]string), thisinfo.Id)
  1137. }
  1138. func deleteSlice1(arr []interface{}, v interface{}) []interface{} {
  1139. for k, v1 := range arr {
  1140. if reflect.DeepEqual(v1, v) {
  1141. return append(arr[:k], arr[k+1:]...)
  1142. }
  1143. }
  1144. return arr
  1145. }
  1146. // 修改字段值
  1147. func UpdateValue(proMap map[string]interface{}, index, position int, modifyMap map[string]interface{}) map[string]interface{} {
  1148. updataSet := make(map[string]interface{})
  1149. infoList := proMap["list"].([]interface{})
  1150. tempMap := infoList[position].(map[string]interface{})
  1151. for k := range modifyMap {
  1152. //项目中lsit大小等于1 或者 修改的招标公告处于项目的list中最后一个
  1153. if len(infoList) == 1 || index == 2 {
  1154. if k == "budget" || k == "bidamount" {
  1155. if proMap["sortprice"] == proMap[k] {
  1156. updataSet["sortprice"] = modifyMap[k]
  1157. }
  1158. updataSet[k] = modifyMap[k]
  1159. proMap[k] = modifyMap[k]
  1160. tempMap[k] = modifyMap[k]
  1161. } else {
  1162. updataSet[k] = modifyMap[k]
  1163. proMap[k] = modifyMap[k]
  1164. tempMap[k] = modifyMap[k]
  1165. }
  1166. } else {
  1167. tempMap[k] = modifyMap[k]
  1168. if k == "budget" || k == "bidamount" {
  1169. if proMap["sortprice"] == proMap[k] {
  1170. proMap["sortprice"] = modifyMap[k]
  1171. }
  1172. updataSet[k] = modifyMap[k]
  1173. proMap[k] = modifyMap[k]
  1174. }
  1175. // 有条件更新项目外围字段值(非空)
  1176. if proMap[k] == nil || util.ObjToString(k) == "" {
  1177. updataSet[k] = modifyMap[k]
  1178. proMap[k] = modifyMap[k]
  1179. }
  1180. }
  1181. }
  1182. return updataSet
  1183. }
  1184. //备份(快照)
  1185. func backupPro(tmp map[string]interface{}) {
  1186. tmp1 := make(map[string]interface{})
  1187. for k, v := range tmp {
  1188. tmp1[k] = v
  1189. }
  1190. if config.Conf.Serve.BackupFlag {
  1191. tmp1["sourceprojectid"] = mongodb.BsonIdToSId(tmp1["_id"])
  1192. delete(tmp1, "_id")
  1193. MgoP.Save(BackupColl, tmp1)
  1194. }
  1195. }
  1196. // 删除原有项目数据
  1197. func delOldPro(pid string) {
  1198. t := MgoP.Delete(ProjectColl, map[string]interface{}{"_id": mongodb.StringTOBsonId(pid)})
  1199. if t >= 0 {
  1200. Es.DelById(config.Conf.DB.Es.Index, pid)
  1201. }
  1202. }
  1203. // 修改内存中的数据
  1204. func (p *ProjectTask) modifyMem(tmpPro map[string]interface{}) {
  1205. pid := util.ObjToString(tmpPro["_id"])
  1206. var pro ProjectCache
  1207. err := mapstructure.Decode(tmpPro, &pro)
  1208. if err != nil {
  1209. log.Info(err.Error())
  1210. }
  1211. pro.Id = mongodb.StringTOBsonId(pid)
  1212. tmpMap := make(map[string]InfoField)
  1213. infoMap := tmpPro["infofield"].(map[string]interface{})
  1214. for _, v := range infoMap {
  1215. var field InfoField
  1216. b, _ := json.Marshal(v)
  1217. _ = json.Unmarshal(b, &field)
  1218. tmpMap[pid] = field
  1219. }
  1220. p.AllIdsMapLock.Lock()
  1221. if v, ok := p.AllIdsMap[pid]; ok {
  1222. v.P = &pro
  1223. }
  1224. p.AllIdsMapLock.Unlock()
  1225. p.printMemPro(pid)
  1226. }
  1227. // 打印内存中的项目信息
  1228. func (p *ProjectTask) printMemPro(pid string) {
  1229. p.AllIdsMapLock.Lock()
  1230. if v, ok := p.AllIdsMap[pid]; ok {
  1231. log.Info("mem pro ----------", zap.Any("pro", *v.P))
  1232. }
  1233. p.AllIdsMapLock.Unlock()
  1234. }
  1235. // @Description id不变,内容变化 重新进行项目合并
  1236. // @Author J 2022/8/10 14:51
  1237. func (p *ProjectTask) taskinfo(id string) {
  1238. tmpPro, _ := MgoP.FindOneByField(ProjectColl, map[string]interface{}{"ids": id}, nil)
  1239. if tmpPro == nil || len(*tmpPro) == 0 {
  1240. log.Info(fmt.Sprintf("taskinfo bidding id=%s 未查询到项目数据", id))
  1241. return
  1242. }
  1243. pid := mongodb.BsonIdToSId((*tmpPro)["_id"])
  1244. ids := util.ObjArrToStringArr((*tmpPro)["ids"].([]interface{}))
  1245. list := (*tmpPro)["list"].([]interface{})
  1246. var newP map[string]interface{}
  1247. var p1 *ProjectCache
  1248. for i, s := range ids {
  1249. temp, _ := MgoB.FindById(BiddingColl, s, nil)
  1250. if temp == nil || len(*temp) == 0 {
  1251. temp, _ = MgoB.FindById("bidding_back", s, nil)
  1252. if temp == nil || len(*temp) == 0 {
  1253. log.Info("extract not find id..." + s)
  1254. return
  1255. }
  1256. }
  1257. push := p.PushListInfo(*temp, id)
  1258. if s == id {
  1259. list[i] = push
  1260. }
  1261. info := ParseInfo(*temp)
  1262. if i == 0 {
  1263. newP, p1 = p.createPro(*temp, info, pid)
  1264. } else {
  1265. p.updatePro(newP, *temp, p1, info)
  1266. }
  1267. }
  1268. newP["ids"] = ids
  1269. newP["pici"] = p.pici
  1270. p.AllIdsMapLock.Lock()
  1271. _, ok := p.AllIdsMap[pid]
  1272. if ok {
  1273. redis.PutCKV("project", pid, newP)
  1274. p.AllIdsMap[id] = &ID{Id: id, P: p1}
  1275. }
  1276. p.AllIdsMapLock.Unlock()
  1277. newP["list"] = list
  1278. if len(newP) > 0 {
  1279. updateInfo := []map[string]interface{}{
  1280. {
  1281. "_id": mongodb.StringTOBsonId(pid),
  1282. },
  1283. {"$set": newP},
  1284. }
  1285. p.updatePool <- updateInfo
  1286. }
  1287. }
  1288. // @Description 创建项目
  1289. // @Author J 2022/8/11 09:17
  1290. func (p *ProjectTask) createPro(tmp map[string]interface{}, thisinfo *Info, pid string) (map[string]interface{}, *ProjectCache) {
  1291. set := map[string]interface{}{}
  1292. set["_id"] = mongodb.StringTOBsonId(pid)
  1293. for _, f := range FIELDS {
  1294. if tmp[f] != nil && tmp[f] != "" {
  1295. set[f] = tmp[f]
  1296. }
  1297. }
  1298. bidopentime := util.Int64All(tmp["bidopentime"])
  1299. if bidopentime > 0 {
  1300. set["bidopentime"] = bidopentime
  1301. }
  1302. //异常标记
  1303. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  1304. set["exception"] = 1
  1305. }
  1306. //projecthref保存
  1307. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  1308. if jsonData != nil && util.ObjToString(jsonData["projecthref"]) != "" {
  1309. set["projecthref"] = jsonData["projecthref"]
  1310. }
  1311. }
  1312. //合同编号
  1313. if thisinfo.ContractCode != "" {
  1314. set["contractcode"] = thisinfo.ContractCode
  1315. }
  1316. bt := util.ObjToString(tmp["toptype"])
  1317. bs := util.ObjToString(tmp["subtype"])
  1318. p.mapBidLock.Lock()
  1319. if thisinfo.Infoformat == 2 || thisinfo.SubType == "拟建" {
  1320. set["bidstatus"] = "拟建"
  1321. bt = "拟建"
  1322. } else {
  1323. if bidtype[bs] != "" {
  1324. set["bidtype"] = bidtype[bs]
  1325. } else {
  1326. set["bidtype"] = "招标"
  1327. }
  1328. if bt == "招标" {
  1329. set["projectscope"] = util.ObjToString(tmp["projectscope"])
  1330. set["bidstatus"] = bt
  1331. } else {
  1332. if bidstatus[bs] != "" {
  1333. set["bidstatus"] = thisinfo.SubType
  1334. bt = thisinfo.SubType
  1335. } else if bs == "" {
  1336. set["bidstatus"] = ""
  1337. bt = ""
  1338. } else {
  1339. set["bidstatus"] = "其它"
  1340. bt = "其它"
  1341. }
  1342. }
  1343. }
  1344. p.mapBidLock.Unlock()
  1345. pkg := PackageFormat(thisinfo, nil)
  1346. p1 := p.NewCachePinfo(mongodb.StringTOBsonId(pid), thisinfo, bs, bt)
  1347. now := time.Now().Unix()
  1348. set["createtime"] = now
  1349. set["sourceinfoid"] = thisinfo.Id
  1350. set["sourceinfourl"] = tmp["href"]
  1351. set["firsttime"] = tmp["publishtime"]
  1352. set["lasttime"] = tmp["publishtime"]
  1353. //增量用系统时间,全量(历史)入库时间
  1354. if p.currentType == "pl" {
  1355. set["pici"] = tmp["comeintime"]
  1356. } else {
  1357. set["pici"] = p.pici
  1358. }
  1359. set["ids"] = []string{thisinfo.Id}
  1360. if thisinfo.TopType == "招标" {
  1361. //if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  1362. set["zbtime"] = tmp["publishtime"]
  1363. //}
  1364. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  1365. set["jgtime"] = tmp["publishtime"]
  1366. }
  1367. if len(thisinfo.Subscopeclass) > 0 {
  1368. set["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  1369. }
  1370. if len(thisinfo.Winners) > 0 {
  1371. set["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1372. }
  1373. if thisinfo.HasPackage {
  1374. set["multipackage"] = 1
  1375. set["package"] = pkg
  1376. } else {
  1377. set["multipackage"] = 0
  1378. }
  1379. //项目评审专家
  1380. if len(thisinfo.ReviewExperts) > 0 {
  1381. set["review_experts"] = thisinfo.ReviewExperts
  1382. }
  1383. //标的物
  1384. if thisinfo.Purchasing != "" {
  1385. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  1386. p := strings.Join(util.ObjArrToStringArr(list), ",")
  1387. set["purchasing"] = p
  1388. }
  1389. //中标候选人
  1390. if len(thisinfo.WinnerOrder) > 0 {
  1391. var list = []string{}
  1392. for _, v := range thisinfo.WinnerOrder {
  1393. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  1394. list = append(list, util.ObjToString(v["entname"]))
  1395. }
  1396. }
  1397. set["winnerorder"] = list
  1398. }
  1399. //项目规模
  1400. if len(thisinfo.ProjectScale) > 0 {
  1401. set["project_scale"] = thisinfo.ProjectScale
  1402. }
  1403. //工期时长
  1404. if thisinfo.ProjectDuration > 0 {
  1405. set["project_duration"] = thisinfo.ProjectDuration
  1406. }
  1407. // 工期单位
  1408. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  1409. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  1410. }
  1411. //开工日期
  1412. if thisinfo.ProjectStartDate > 0 {
  1413. set["project_startdate"] = thisinfo.ProjectStartDate
  1414. }
  1415. //竣工日期
  1416. if thisinfo.ProjectCompleteDate > 0 {
  1417. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1418. }
  1419. //付款方式
  1420. if len(thisinfo.Payway) > 0 {
  1421. set["payway"] = thisinfo.Payway
  1422. }
  1423. // 履约保证金
  1424. if tmp["contract_guarantee"] != nil {
  1425. set["contract_guarantee"] = thisinfo.ContractGuarantee
  1426. }
  1427. // 投标保证金
  1428. if tmp["bid_guarantee"] != nil {
  1429. set["bid_guarantee"] = thisinfo.BidGuarantee
  1430. }
  1431. // 资质条件
  1432. if len(thisinfo.Qualifies) > 0 {
  1433. var str []string
  1434. for _, v := range thisinfo.Qualifies {
  1435. if len(util.ObjToString(v["key"])) > 0 {
  1436. if BinarySearch(str, util.ObjToString(v["key"])) == -1 {
  1437. str = append(str, util.ObjToString(v["key"]))
  1438. }
  1439. }
  1440. }
  1441. if len(str) > 0 {
  1442. set["qualifies"] = strings.Join(str, ",")
  1443. }
  1444. }
  1445. if len(thisinfo.EntIdList) > 0 {
  1446. set["entidlist"] = thisinfo.EntIdList
  1447. }
  1448. // first_cooperation
  1449. if p1.Buyer != "" && len(thisinfo.Winners) > 0 {
  1450. FirstCooperation(set, p1.Buyer, thisinfo.Winners, thisinfo.EntIdList)
  1451. }
  1452. infofield := InfoField{
  1453. Budget: thisinfo.Budget,
  1454. Bidamount: thisinfo.Bidamount,
  1455. ContractCode: thisinfo.ContractCode,
  1456. ProjectName: thisinfo.ProjectName,
  1457. ProjectCode: thisinfo.ProjectCode,
  1458. Bidstatus: bs,
  1459. }
  1460. res := StructToMap(infofield)
  1461. set["infofield"] = map[string]interface{}{
  1462. thisinfo.Id: res,
  1463. }
  1464. if tmp["budget"] != nil && tmp["budget"] != "" {
  1465. set["budget"] = thisinfo.Budget
  1466. set["budgettag"] = 0
  1467. } else {
  1468. set["budgettag"] = 1
  1469. }
  1470. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  1471. set["bidamount"] = thisinfo.Bidamount
  1472. set["bidamounttag"] = 0
  1473. } else {
  1474. set["bidamounttag"] = 1
  1475. }
  1476. if p1.Bidamount > 0 {
  1477. set["sortprice"] = p1.Bidamount
  1478. } else {
  1479. if p1.Budget > 0 {
  1480. set["sortprice"] = p1.Budget
  1481. }
  1482. }
  1483. return set, &p1
  1484. }
  1485. // @Description id不变,内容覆盖 修改项目
  1486. // @Author J 2022/8/10 17:00
  1487. func (p *ProjectTask) updatePro(set, tmp map[string]interface{}, pInfo *ProjectCache, thisinfo *Info) {
  1488. bys, _ := json.Marshal(set)
  1489. var project *Project
  1490. err := json.Unmarshal(bys, &project)
  1491. if err != nil {
  1492. log.Info("project Unmarshal err," + err.Error())
  1493. return
  1494. }
  1495. //zbtime、lasttime、jgtime
  1496. pInfo.LastTime = thisinfo.Publishtime
  1497. set["lasttime"] = thisinfo.Publishtime
  1498. if thisinfo.TopType == "招标" {
  1499. if project.Zbtime <= 0 {
  1500. project.Zbtime = thisinfo.Publishtime
  1501. set["zbtime"] = tmp["publishtime"]
  1502. }
  1503. if project.Jgtime > 0 {
  1504. project.Jgtime = int64(0)
  1505. set["jgtime"] = int64(0)
  1506. }
  1507. } else if thisinfo.TopType == "结果" {
  1508. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  1509. if project.Jgtime > 0 {
  1510. //jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  1511. //公告状态和项目状态同样都是中标或者成交,
  1512. if thisinfo.SubType == "成交" && project.Bidstatus == "中标" {
  1513. if p.jgTime < thisinfo.Publishtime {
  1514. project.Jgtime = thisinfo.Publishtime
  1515. set["jgtime"] = tmp["publishtime"]
  1516. }
  1517. //公告状态和项目状态同样是流标或者废标
  1518. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (project.Bidstatus == "流标" || project.Bidstatus == "废标") {
  1519. if p.jgTime < thisinfo.Publishtime {
  1520. project.Jgtime = thisinfo.Publishtime
  1521. set["jgtime"] = tmp["publishtime"]
  1522. }
  1523. }
  1524. } else {
  1525. project.Jgtime = thisinfo.Publishtime
  1526. set["jgtime"] = tmp["publishtime"]
  1527. }
  1528. }
  1529. } else if thisinfo.SubType == "合同" {
  1530. if project.Bidstatus == "中标" || project.Bidstatus == "成交" || project.Bidstatus == "" {
  1531. //中标、成交不更新jgtime
  1532. } else {
  1533. project.Jgtime = thisinfo.Publishtime
  1534. set["jgtime"] = tmp["publishtime"]
  1535. }
  1536. }
  1537. if thisinfo.BidOpenTime > project.BidOpenTime {
  1538. project.BidOpenTime = thisinfo.BidOpenTime
  1539. set["bidopentime"] = project.BidOpenTime
  1540. }
  1541. if thisinfo.BidEndTime > 0 {
  1542. project.BidEndTime = thisinfo.BidEndTime
  1543. set["bidendtime"] = project.BidEndTime
  1544. }
  1545. bt := util.ObjToString(tmp["toptype"])
  1546. bs := util.ObjToString(tmp["subtype"])
  1547. p.mapBidLock.Lock()
  1548. if bt == "招标" {
  1549. //招标状态,更新projectscope
  1550. if tmp["projectscope"] != nil {
  1551. set["projectscope"] = util.ObjToString(tmp["projectscope"])
  1552. }
  1553. set["bidstatus"] = bt
  1554. project.Bidstatus = bt
  1555. if bidtype[bs] != "" {
  1556. set["bidtype"] = bidtype[bs]
  1557. project.Bidtype = bidtype[bs]
  1558. } else {
  1559. set["bidtype"] = "招标"
  1560. project.Bidtype = "招标"
  1561. }
  1562. } else {
  1563. if bidstatus[bs] != "" {
  1564. set["bidstatus"] = thisinfo.SubType
  1565. project.Bidstatus = thisinfo.SubType
  1566. } else if thisinfo.Infoformat == 2 {
  1567. set["bidstatus"] = "拟建"
  1568. project.Bidstatus = "拟建"
  1569. } else if bs == "" && bt == "结果" {
  1570. if project.Bidstatus == "招标" {
  1571. set["bidstatus"] = ""
  1572. project.Bidstatus = ""
  1573. }
  1574. } else {
  1575. set["bidstatus"] = "其它"
  1576. project.Bidstatus = "其它"
  1577. }
  1578. }
  1579. p.mapBidLock.Unlock()
  1580. //相同城市的公告才会合并到一起(全国列外)
  1581. if thisinfo.Area != "全国" {
  1582. pInfo.Area = thisinfo.Area
  1583. project.Area = thisinfo.Area
  1584. set["area"] = thisinfo.Area
  1585. if thisinfo.City != "" {
  1586. pInfo.City = thisinfo.City
  1587. project.City = thisinfo.City
  1588. set["city"] = thisinfo.City
  1589. }
  1590. if thisinfo.District != "" {
  1591. pInfo.District = thisinfo.District
  1592. project.District = thisinfo.District
  1593. set["district"] = thisinfo.District
  1594. }
  1595. }
  1596. //项目名称
  1597. //if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  1598. if pInfo.ProjectName == "" && thisinfo.ProjectName != "" {
  1599. pInfo.ProjectName = thisinfo.ProjectName
  1600. project.ProjectName = thisinfo.ProjectName
  1601. set["projectname"] = thisinfo.ProjectName
  1602. }
  1603. //7--项目编号
  1604. //if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  1605. if pInfo.ProjectCode == "" && thisinfo.ProjectCode != "" {
  1606. pInfo.ProjectCode = thisinfo.ProjectCode
  1607. project.ProjectCode = thisinfo.ProjectCode
  1608. set["projectcode"] = thisinfo.ProjectCode
  1609. }
  1610. //7--采购单位
  1611. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  1612. pInfo.Buyer = thisinfo.Buyer
  1613. project.Buyer = thisinfo.Buyer
  1614. set["buyer"] = thisinfo.Buyer
  1615. project.Buyerclass = thisinfo.Buyerclass
  1616. set["buyerclass"] = thisinfo.Buyerclass
  1617. }
  1618. if pInfo.Buyer == "" {
  1619. project.Buyerclass = ""
  1620. set["buyerclass"] = ""
  1621. }
  1622. //采购单位联系人
  1623. if thisinfo.Buyerperson != "" {
  1624. project.Buyerperson = thisinfo.Buyerperson
  1625. set["buyerperson"] = thisinfo.Buyerperson
  1626. } else {
  1627. project.Buyerperson = ""
  1628. set["buyerperson"] = ""
  1629. }
  1630. //采购单位電話
  1631. if thisinfo.Buyertel != "" {
  1632. project.Buyertel = thisinfo.Buyertel
  1633. set["buyertel"] = project.Buyertel
  1634. } else {
  1635. project.Buyertel = ""
  1636. set["buyertel"] = ""
  1637. }
  1638. if thisinfo.ContractCode != "" {
  1639. if project.ContractCode == "" {
  1640. set["contractcode"] = thisinfo.ContractCode
  1641. } else {
  1642. list := strings.Split(project.ContractCode, ",")
  1643. if BinarySearch(list, thisinfo.ContractCode) == -1 {
  1644. list = append(list, thisinfo.ContractCode)
  1645. sort.Strings(list)
  1646. }
  1647. set["contractcode"] = strings.Join(list, ",")
  1648. }
  1649. }
  1650. //8--代理机构
  1651. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  1652. pInfo.Agency = thisinfo.Agency
  1653. project.Agency = thisinfo.Agency
  1654. set["agency"] = thisinfo.Agency
  1655. }
  1656. if len(thisinfo.Topscopeclass) > 0 {
  1657. sort.Strings(project.Topscopeclass)
  1658. for _, k := range thisinfo.Topscopeclass {
  1659. if BinarySearch(project.Topscopeclass, k) == -1 {
  1660. project.Topscopeclass = append(project.Topscopeclass, k)
  1661. sort.Strings(project.Topscopeclass)
  1662. }
  1663. }
  1664. set["topscopeclass"] = project.Topscopeclass
  1665. }
  1666. //项目评审专家
  1667. if len(thisinfo.ReviewExperts) > 0 {
  1668. set["review_experts"] = thisinfo.ReviewExperts
  1669. project.ReviewExperts = thisinfo.ReviewExperts
  1670. }
  1671. if thisinfo.Purchasing != "" {
  1672. if project.Purchasing == "" {
  1673. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  1674. p := strings.Join(util.ObjArrToStringArr(list), ",")
  1675. project.Purchasing = p
  1676. set["purchasing"] = p
  1677. } else {
  1678. list := strings.Split(project.Purchasing, ",")
  1679. list = util.ObjArrToStringArr(Duplicate(list))
  1680. for _, k := range list {
  1681. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  1682. list = append(list, k)
  1683. sort.Strings(list)
  1684. }
  1685. }
  1686. set["purchasing"] = strings.Join(list, ",")
  1687. }
  1688. }
  1689. //中标候选人
  1690. if len(thisinfo.WinnerOrder) > 0 {
  1691. var list = []string{}
  1692. for _, v := range thisinfo.WinnerOrder {
  1693. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  1694. list = append(list, util.ObjToString(v["entname"]))
  1695. }
  1696. }
  1697. set["winnerorder"] = list
  1698. project.Winnerorder = list
  1699. }
  1700. if len(thisinfo.Subscopeclass) > 0 {
  1701. sort.Strings(project.Subscopeclass)
  1702. for _, k := range thisinfo.Subscopeclass {
  1703. if BinarySearch(project.Subscopeclass, k) == -1 {
  1704. project.Subscopeclass = append(project.Subscopeclass, k)
  1705. sort.Strings(project.Subscopeclass)
  1706. }
  1707. }
  1708. set["subscopeclass"] = project.Subscopeclass
  1709. set["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
  1710. }
  1711. if len(thisinfo.Winners) > 0 {
  1712. if len(project.Winners) <= 0 {
  1713. set["winner"] = util.ObjToString(tmp["winner"])
  1714. }
  1715. winners := strings.Split(project.Winners, ",")
  1716. for _, k := range thisinfo.Winners {
  1717. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  1718. if BinarySearch(winners, k) != -1 {
  1719. deleteSlice(winners, k, "")
  1720. }
  1721. } else {
  1722. if BinarySearch(winners, k) == -1 {
  1723. winners = append(winners, k)
  1724. }
  1725. }
  1726. }
  1727. set["s_winner"] = strings.Join(util.ObjArrToStringArr(Duplicate(winners)), ",")
  1728. }
  1729. if len(thisinfo.EntIdList) > 0 {
  1730. for _, v := range thisinfo.EntIdList {
  1731. if BinarySearch(project.EntIdList, v) == -1 {
  1732. project.EntIdList = append(project.EntIdList, v)
  1733. }
  1734. }
  1735. set["entidlist"] = project.EntIdList
  1736. }
  1737. // first_cooperation
  1738. if pInfo.Buyer != "" && len(strings.Split(project.Winners, ",")) > 0 {
  1739. FirstCooperation(set, pInfo.Buyer, strings.Split(project.Winners, ","), project.EntIdList)
  1740. }
  1741. //项目规模
  1742. if len(thisinfo.ProjectScale) > 0 {
  1743. project.ProjectScale = thisinfo.ProjectScale
  1744. set["project_scale"] = thisinfo.ProjectScale
  1745. }
  1746. //工期时长
  1747. if thisinfo.ProjectDuration > 0 {
  1748. project.ProjectDuration = thisinfo.ProjectDuration
  1749. set["project_duration"] = thisinfo.ProjectDuration
  1750. }
  1751. // 工期单位
  1752. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  1753. project.ProjectTimeunit = thisinfo.ProjectTimeUnit
  1754. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  1755. }
  1756. //开工日期
  1757. if thisinfo.ProjectStartDate > 0 {
  1758. if project.ProjectStartDate > 0 {
  1759. if project.ProjectStartDate < thisinfo.ProjectStartDate {
  1760. project.ProjectStartDate = thisinfo.ProjectStartDate
  1761. set["project_startdate"] = thisinfo.ProjectStartDate
  1762. }
  1763. } else {
  1764. project.ProjectStartDate = thisinfo.ProjectStartDate
  1765. set["project_startdate"] = thisinfo.ProjectStartDate
  1766. }
  1767. }
  1768. //竣工日期
  1769. if thisinfo.ProjectCompleteDate > 0 {
  1770. if project.ProjctCompleteDate > 0 {
  1771. if project.ProjctCompleteDate < thisinfo.ProjectCompleteDate {
  1772. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1773. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1774. }
  1775. } else {
  1776. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1777. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1778. }
  1779. }
  1780. // 付款方式
  1781. if len(thisinfo.Payway) > 0 {
  1782. project.Payway = thisinfo.Payway
  1783. set["payway"] = thisinfo.Payway
  1784. }
  1785. // 履约保证金
  1786. if tmp["contract_guarantee"] != nil {
  1787. project.ContractGuarantee = thisinfo.ContractGuarantee
  1788. set["contract_guarantee"] = thisinfo.ContractGuarantee
  1789. }
  1790. // 投标保证金
  1791. if tmp["bid_guarantee"] != nil {
  1792. project.BidGuarantee = thisinfo.BidGuarantee
  1793. set["bid_guarantee"] = thisinfo.BidGuarantee
  1794. }
  1795. // 资质条件
  1796. if len(thisinfo.Qualifies) > 0 {
  1797. var str []string
  1798. if len(project.Qualifies) > 0 {
  1799. str = append(str, strings.Split(project.Qualifies, ",")...)
  1800. }
  1801. for _, v := range thisinfo.Qualifies {
  1802. if len(util.ObjToString(v["key"])) > 0 {
  1803. if BinarySearch(str, util.ObjToString(v["key"])) == -1 {
  1804. str = append(str, util.ObjToString(v["key"]))
  1805. }
  1806. }
  1807. }
  1808. if len(str) > 0 {
  1809. project.Qualifies = strings.Join(str, ",")
  1810. set["qualifies"] = strings.Join(str, ",")
  1811. }
  1812. }
  1813. if thisinfo.HasPackage { //多包处理
  1814. set["multipackage"] = 1
  1815. pkg := PackageFormat(thisinfo, project)
  1816. project.Package = pkg
  1817. set["package"] = project.Package
  1818. }
  1819. //处理多包后,计算预算金额、中标金额
  1820. CountAmount(project, thisinfo, tmp)
  1821. if project.Budget >= 0 && project.Budgettag != 1 {
  1822. pInfo.Budget = project.Budget
  1823. set["budget"] = project.Budget
  1824. set["budgettag"] = 0
  1825. }
  1826. if project.Bidamount >= 0 && project.Bidamounttag != 1 {
  1827. pInfo.Bidamount = project.Bidamount
  1828. set["bidamount"] = pInfo.Bidamount
  1829. set["bidamounttag"] = 0
  1830. }
  1831. if pInfo.Bidamount > 0 {
  1832. set["sortprice"] = pInfo.Bidamount
  1833. } else {
  1834. if pInfo.Budget > 0 {
  1835. set["sortprice"] = pInfo.Budget
  1836. }
  1837. }
  1838. infofield := InfoField{
  1839. Budget: thisinfo.Budget,
  1840. Bidamount: thisinfo.Bidamount,
  1841. ContractCode: thisinfo.ContractCode,
  1842. ProjectName: thisinfo.ProjectName,
  1843. ProjectCode: thisinfo.ProjectCode,
  1844. Bidstatus: bs,
  1845. }
  1846. tmpMap := set["infofield"].(map[string]interface{})
  1847. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1848. set["infofield"] = tmpMap
  1849. copyMap := util.DeepCopy(project.InfoFiled).(map[string]InfoField)
  1850. copyMap[thisinfo.Id] = infofield
  1851. project.InfoFiled = copyMap
  1852. set["mpn"] = pInfo.MPN
  1853. set["mpc"] = pInfo.MPC
  1854. }