update.go 56 KB

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