update.go 58 KB

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