update.go 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920
  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. infofield := InfoField{
  734. Budget: thisinfo.Budget,
  735. Bidamount: thisinfo.Bidamount,
  736. ContractCode: thisinfo.ContractCode,
  737. ProjectName: thisinfo.ProjectName,
  738. ProjectCode: thisinfo.ProjectCode,
  739. Bidstatus: pInfo.Bidstatus,
  740. }
  741. copyMap := util.DeepCopy(project.InfoFiled).(map[string]InfoField)
  742. copyMap[thisinfo.Id] = infofield
  743. tmpMap := make(map[string]interface{})
  744. for k, v := range copyMap {
  745. tmpMap[k] = StructToMap(v)
  746. }
  747. tmpMap[thisinfo.Id] = StructToMap(infofield)
  748. project.InfoFiled = copyMap
  749. set["infofield"] = tmpMap
  750. set["mpn"] = pInfo.MPN
  751. set["mpc"] = pInfo.MPC
  752. set["updatetime"] = p.pici
  753. redis.PutCKV("project", project.Id.Hex(), set)
  754. update := map[string]interface{}{}
  755. if len(set) > 0 {
  756. update["$set"] = set
  757. }
  758. push := p.PushListInfo(tmp, thisinfo.Id)
  759. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  760. push["compareStr"] = comStr
  761. push["resVal"] = pInfo.resVal
  762. push["pjVal"] = pInfo.pjVal
  763. update["$push"] = map[string]interface{}{
  764. "list": push,
  765. "ids": thisinfo.Id,
  766. }
  767. bol := MgoP.UpdateById(ProjectColl, pInfo.Id.Hex(), update)
  768. if bol {
  769. by, _ := json.Marshal(map[string]interface{}{
  770. "query": map[string]interface{}{
  771. "_id": bson.M{
  772. "$gte": pInfo.Id.Hex(),
  773. "$lte": pInfo.Id.Hex(),
  774. }},
  775. "stype": "project",
  776. })
  777. log.Info(string(by))
  778. _ = udpclient.WriteUdp(by, udp.OP_TYPE_DATA, toaddr[1])
  779. }
  780. }
  781. // 内部合并时,原有项目id基础上新建项目
  782. func (p *ProjectTask) newPro(tmp, tmpPro map[string]interface{}, thisinfo *Info) *ProjectCache {
  783. for _, f := range FIELDS {
  784. if tmp[f] != nil && tmp[f] != "" {
  785. tmpPro[f] = tmp[f]
  786. }
  787. }
  788. bidopentime := util.Int64All(tmp["bidopentime"])
  789. if bidopentime > 0 {
  790. tmpPro["bidopentime"] = bidopentime
  791. }
  792. //异常标记
  793. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  794. tmpPro["exception"] = 1
  795. }
  796. //projecthref保存
  797. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  798. if jsonData != nil && util.ObjToString(jsonData["projecthref"]) != "" {
  799. tmpPro["projecthref"] = jsonData["projecthref"]
  800. }
  801. }
  802. //合同编号
  803. if thisinfo.ContractCode != "" {
  804. tmpPro["contractcode"] = thisinfo.ContractCode
  805. }
  806. bs, bt := p.GetBidTypeAndBidStatus(thisinfo)
  807. tmpPro["bidtype"] = bs
  808. tmpPro["bidstatus"] = bt
  809. pkg := PackageFormat(thisinfo, nil)
  810. p1 := p.NewCachePinfo(tmpPro["_id"].(primitive.ObjectID), thisinfo, bs, bt)
  811. now := time.Now().Unix()
  812. tmpPro["createtime"] = now
  813. tmpPro["sourceinfoid"] = thisinfo.Id
  814. tmpPro["sourceinfourl"] = tmp["href"]
  815. tmpPro["firsttime"] = tmp["publishtime"]
  816. tmpPro["lasttime"] = tmp["publishtime"]
  817. tmpPro["pici"] = tmp["comeintime"]
  818. tmpPro["ids"] = []string{thisinfo.Id}
  819. if thisinfo.TopType == "招标" {
  820. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  821. tmpPro["zbtime"] = tmp["publishtime"]
  822. }
  823. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  824. tmpPro["jgtime"] = tmp["publishtime"]
  825. }
  826. if len(thisinfo.Subscopeclass) > 0 {
  827. tmpPro["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  828. }
  829. if len(thisinfo.Winners) > 0 {
  830. tmpPro["s_winner"] = strings.Join(thisinfo.Winners, ",")
  831. }
  832. if thisinfo.HasPackage {
  833. tmpPro["multipackage"] = 1
  834. tmpPro["package"] = pkg
  835. } else {
  836. tmpPro["multipackage"] = 0
  837. }
  838. //项目评审专家
  839. if len(thisinfo.ReviewExperts) > 0 {
  840. tmpPro["review_experts"] = thisinfo.ReviewExperts
  841. }
  842. //标的物
  843. if thisinfo.Purchasing != "" {
  844. tmpPro["purchasing"] = thisinfo.Purchasing
  845. }
  846. //中标候选人
  847. if len(thisinfo.WinnerOrder) > 0 {
  848. var list = []string{}
  849. for _, v := range thisinfo.WinnerOrder {
  850. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  851. list = append(list, util.ObjToString(v["entname"]))
  852. }
  853. }
  854. tmpPro["winnerorder"] = list
  855. }
  856. infofield := InfoField{
  857. Budget: thisinfo.Budget,
  858. Bidamount: thisinfo.Bidamount,
  859. ContractCode: thisinfo.ContractCode,
  860. ProjectName: thisinfo.ProjectName,
  861. ProjectCode: thisinfo.ProjectCode,
  862. Bidstatus: bs,
  863. }
  864. res := StructToMap(infofield)
  865. tmpPro["infofield"] = map[string]interface{}{
  866. thisinfo.Id: res,
  867. }
  868. if tmp["budget"] != nil && tmp["budget"] != "" {
  869. tmpPro["budget"] = thisinfo.Budget
  870. tmpPro["budgettag"] = 0
  871. } else {
  872. tmpPro["budgettag"] = 1
  873. }
  874. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  875. tmpPro["bidamount"] = thisinfo.Bidamount
  876. tmpPro["bidamounttag"] = 0
  877. } else {
  878. tmpPro["bidamounttag"] = 1
  879. }
  880. if p1.Bidamount > 0 {
  881. tmpPro["sortprice"] = p1.Bidamount
  882. } else if p1.Budget > 0 {
  883. tmpPro["sortprice"] = p1.Budget
  884. }
  885. push := p.PushListInfo(tmp, thisinfo.Id)
  886. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  887. tmpPro["list"] = []map[string]interface{}{
  888. push,
  889. }
  890. return &p1
  891. }
  892. // 合并字段到老项目中
  893. func (p *ProjectTask) updateOldProField(pInfo *ProjectCache, thisinfo *Info, tmpPro, tmp, m1 map[string]interface{}) {
  894. pdata := redis.Get("project", pInfo.Id.Hex())
  895. projectMap := pdata.(map[string]interface{})
  896. bys, _ := json.Marshal(projectMap)
  897. var project *Project
  898. err := json.Unmarshal(bys, &project)
  899. if err != nil {
  900. log.Error("project Unmarshal err," + err.Error())
  901. return
  902. }
  903. if len(pInfo.Ids) > 30 {
  904. //异常标记
  905. tmpPro["listtag"] = 1
  906. }
  907. if thisinfo.Publishtime > pInfo.LastTime {
  908. pInfo.LastTime = thisinfo.Publishtime
  909. project.LastTime = thisinfo.Publishtime
  910. tmpPro["lasttime"] = thisinfo.Publishtime
  911. }
  912. if thisinfo.TopType == "招标" {
  913. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && project.Zbtime <= 0 {
  914. tmpPro["zbtime"] = tmp["publishtime"]
  915. }
  916. } else if thisinfo.TopType == "结果" {
  917. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  918. if project.Jgtime > 0 {
  919. jg1 := int64(math.Abs(float64(project.Jgtime - thisinfo.Publishtime)))
  920. //公告状态和项目状态同样都是中标或者成交,
  921. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  922. if jg1 > p.jgTime {
  923. tmpPro["jgtime"] = tmp["publishtime"]
  924. project.Jgtime = thisinfo.Publishtime
  925. }
  926. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  927. //公告状态和项目状态同样是流标或者废标
  928. if jg1 > p.jgTime {
  929. tmpPro["jgtime"] = tmp["publishtime"]
  930. project.Jgtime = thisinfo.Publishtime
  931. }
  932. }
  933. } else {
  934. tmpPro["jgtime"] = tmp["publishtime"]
  935. project.Jgtime = thisinfo.Publishtime
  936. }
  937. }
  938. } else if thisinfo.SubType == "合同" {
  939. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  940. //中标、成交不更新jgtime
  941. } else {
  942. tmpPro["jgtime"] = tmp["publishtime"]
  943. project.Jgtime = thisinfo.Publishtime
  944. }
  945. }
  946. if thisinfo.BidOpenTime > project.BidOpenTime {
  947. project.BidOpenTime = thisinfo.BidOpenTime
  948. tmpPro["bidopentime"] = thisinfo.BidOpenTime
  949. }
  950. if thisinfo.BidEndTime > 0 {
  951. project.BidEndTime = thisinfo.BidEndTime
  952. tmpPro["bidendtime"] = thisinfo.BidEndTime
  953. }
  954. // bidtype、bidstatus
  955. pInfo.Bidtype, pInfo.Bidstatus = p.GetBidTypeAndBidStatus(thisinfo)
  956. project.Bidtype, project.Bidstatus = p.GetBidTypeAndBidStatus(thisinfo)
  957. tmpPro["bidtype"] = pInfo.Bidtype
  958. tmpPro["bidstatus"] = pInfo.Bidstatus
  959. //相同城市的公告才会合并到一起(全国列外)
  960. if thisinfo.Area != "全国" {
  961. pInfo.Area = thisinfo.Area
  962. project.Area = thisinfo.Area
  963. tmpPro["area"] = thisinfo.Area
  964. pInfo.City = thisinfo.City
  965. project.City = thisinfo.City
  966. tmpPro["city"] = thisinfo.City
  967. if thisinfo.District != "" {
  968. pInfo.District = thisinfo.District
  969. project.District = thisinfo.District
  970. tmpPro["district"] = thisinfo.District
  971. }
  972. }
  973. // 项目名称
  974. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  975. pInfo.ProjectName = thisinfo.ProjectName
  976. project.ProjectName = thisinfo.ProjectName
  977. tmpPro["projectname"] = thisinfo.ProjectName
  978. }
  979. // 项目编号
  980. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  981. pInfo.ProjectCode = thisinfo.ProjectCode
  982. project.ProjectCode = thisinfo.ProjectCode
  983. tmpPro["projectcode"] = thisinfo.ProjectCode
  984. }
  985. // 采购单位
  986. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  987. pInfo.Buyer = thisinfo.Buyer
  988. tmpPro["buyer"] = thisinfo.Buyer
  989. project.Buyerclass = thisinfo.Buyerclass
  990. tmpPro["buyerclass"] = thisinfo.Buyerclass
  991. }
  992. if pInfo.Buyer == "" {
  993. project.Buyerclass = ""
  994. tmpPro["buyerclass"] = ""
  995. }
  996. // 采购单位联系人
  997. if thisinfo.Buyerperson != "" {
  998. project.Buyerperson = thisinfo.Buyerperson
  999. tmpPro["buyerperson"] = thisinfo.Buyerperson
  1000. } else {
  1001. project.Buyerperson = ""
  1002. tmpPro["buyerperson"] = ""
  1003. }
  1004. // 采购单位電話
  1005. if thisinfo.Buyertel != "" {
  1006. project.Buyertel = thisinfo.Buyertel
  1007. tmpPro["buyertel"] = thisinfo.Buyertel
  1008. } else {
  1009. project.Buyertel = ""
  1010. tmpPro["buyertel"] = ""
  1011. }
  1012. if thisinfo.ContractCode != "" {
  1013. tmpPro["contractcode"] = project.ContractCode + "," + thisinfo.ContractCode
  1014. }
  1015. // 代理机构 相同的代理机构才会合并到一个项目 2020.11.9
  1016. //if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  1017. // pInfo.Agency = thisinfo.Agency
  1018. // set["agency"] = thisinfo.Agency
  1019. //}
  1020. if len(thisinfo.Topscopeclass) > 0 {
  1021. sort.Strings(project.Topscopeclass)
  1022. for _, k := range thisinfo.Topscopeclass {
  1023. if BinarySearch(project.Topscopeclass, k) == -1 {
  1024. project.Topscopeclass = append(project.Topscopeclass, k)
  1025. sort.Strings(project.Topscopeclass)
  1026. }
  1027. }
  1028. tmpPro["topscopeclass"] = project.Topscopeclass
  1029. }
  1030. // 项目评审专家
  1031. if len(thisinfo.ReviewExperts) > 0 {
  1032. tmpPro["review_experts"] = thisinfo.ReviewExperts
  1033. project.ReviewExperts = thisinfo.ReviewExperts
  1034. }
  1035. if thisinfo.Purchasing != "" {
  1036. if project.Purchasing == "" {
  1037. project.Purchasing = thisinfo.Purchasing
  1038. tmpPro["purchasing"] = thisinfo.Purchasing
  1039. } else {
  1040. list := strings.Split(project.Purchasing, ",")
  1041. for _, k := range list {
  1042. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  1043. list = append(list, k)
  1044. sort.Strings(list)
  1045. }
  1046. }
  1047. tmpPro["purchasing"] = strings.Join(list, ",")
  1048. }
  1049. }
  1050. //中标候选人
  1051. if len(thisinfo.WinnerOrder) > 0 {
  1052. var list = []string{}
  1053. for _, v := range thisinfo.WinnerOrder {
  1054. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  1055. list = append(list, util.ObjToString(v["entname"]))
  1056. }
  1057. }
  1058. tmpPro["winnerorder"] = list
  1059. project.Winnerorder = list
  1060. }
  1061. if len(thisinfo.Subscopeclass) > 0 {
  1062. sort.Strings(project.Subscopeclass)
  1063. for _, k := range thisinfo.Subscopeclass {
  1064. if BinarySearch(project.Subscopeclass, k) == -1 {
  1065. project.Subscopeclass = append(project.Subscopeclass, k)
  1066. sort.Strings(project.Subscopeclass)
  1067. }
  1068. }
  1069. tmpPro["subscopeclass"] = project.Subscopeclass
  1070. tmpPro["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
  1071. }
  1072. if len(thisinfo.Winners) > 0 {
  1073. if len(project.Winners) <= 0 {
  1074. tmpPro["winner"] = util.ObjToString(tmp["winner"])
  1075. }
  1076. winners := strings.Split(project.Winners, ",")
  1077. for _, k := range thisinfo.Winners {
  1078. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  1079. if BinarySearch(winners, k) != -1 {
  1080. deleteSlice(winners, k, "")
  1081. }
  1082. } else {
  1083. if BinarySearch(winners, k) == -1 {
  1084. winners = append(winners, k)
  1085. }
  1086. }
  1087. }
  1088. tmpPro["s_winner"] = strings.Join(winners, ",")
  1089. }
  1090. if thisinfo.HasPackage { //多包处理
  1091. tmpPro["multipackage"] = 1
  1092. pkg := PackageFormat(thisinfo, project)
  1093. project.Package = pkg
  1094. tmpPro["package"] = project.Package
  1095. }
  1096. //处理多包后,计算预算金额、中标金额
  1097. CountAmount(project, thisinfo, tmp)
  1098. if project.Budget >= 0 && project.Budgettag != 1 {
  1099. pInfo.Budget = project.Budget
  1100. tmpPro["budget"] = pInfo.Budget
  1101. tmpPro["budgettag"] = 0
  1102. }
  1103. if project.Bidamount >= 0 && project.Bidamounttag != 1 {
  1104. pInfo.Bidamount = project.Bidamount
  1105. tmpPro["bidamount"] = pInfo.Bidamount
  1106. tmpPro["bidamounttag"] = 0
  1107. }
  1108. if pInfo.Bidamount >= pInfo.Budget {
  1109. tmpPro["sortprice"] = pInfo.Bidamount
  1110. } else if pInfo.Budget >= pInfo.Bidamount {
  1111. tmpPro["sortprice"] = pInfo.Budget
  1112. }
  1113. infofield := InfoField{
  1114. Budget: thisinfo.Budget,
  1115. Bidamount: thisinfo.Bidamount,
  1116. ContractCode: thisinfo.ContractCode,
  1117. ProjectName: thisinfo.ProjectName,
  1118. ProjectCode: thisinfo.ProjectCode,
  1119. Bidstatus: pInfo.Bidstatus,
  1120. }
  1121. copyMap := util.DeepCopy(project.InfoFiled).(map[string]InfoField)
  1122. copyMap[thisinfo.Id] = infofield
  1123. tmpMap := make(map[string]interface{})
  1124. for k, v := range copyMap {
  1125. tmpMap[k] = StructToMap(v)
  1126. }
  1127. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1128. project.InfoFiled = copyMap
  1129. tmpPro["infofield"] = tmpMap
  1130. tmpPro["mpn"] = pInfo.MPN
  1131. tmpPro["mpc"] = pInfo.MPC
  1132. tmpPro["updatetime"] = p.pici
  1133. push := p.PushListInfo(tmp, thisinfo.Id)
  1134. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1135. push["compareStr"] = m1["compareStr"]
  1136. push["resVal"] = m1["resVal"]
  1137. push["pjVal"] = m1["pjVal"]
  1138. list := tmpPro["list"].([]map[string]interface{})
  1139. tmpPro["list"] = append(list, push)
  1140. tmpPro["ids"] = append(tmpPro["ids"].([]string), thisinfo.Id)
  1141. }
  1142. func deleteSlice1(arr []interface{}, v interface{}) []interface{} {
  1143. for k, v1 := range arr {
  1144. if reflect.DeepEqual(v1, v) {
  1145. return append(arr[:k], arr[k+1:]...)
  1146. }
  1147. }
  1148. return arr
  1149. }
  1150. // 修改字段值
  1151. func UpdateValue(proMap map[string]interface{}, index, position int, modifyMap map[string]interface{}) map[string]interface{} {
  1152. updataSet := make(map[string]interface{})
  1153. infoList := proMap["list"].([]interface{})
  1154. tempMap := infoList[position].(map[string]interface{})
  1155. for k := range modifyMap {
  1156. //项目中lsit大小等于1 或者 修改的招标公告处于项目的list中最后一个
  1157. if len(infoList) == 1 || index == 2 {
  1158. if k == "budget" || k == "bidamount" {
  1159. if proMap["sortprice"] == proMap[k] {
  1160. updataSet["sortprice"] = modifyMap[k]
  1161. }
  1162. updataSet[k] = modifyMap[k]
  1163. proMap[k] = modifyMap[k]
  1164. tempMap[k] = modifyMap[k]
  1165. } else {
  1166. updataSet[k] = modifyMap[k]
  1167. proMap[k] = modifyMap[k]
  1168. tempMap[k] = modifyMap[k]
  1169. }
  1170. } else {
  1171. tempMap[k] = modifyMap[k]
  1172. if k == "budget" || k == "bidamount" {
  1173. if proMap["sortprice"] == proMap[k] {
  1174. proMap["sortprice"] = modifyMap[k]
  1175. }
  1176. updataSet[k] = modifyMap[k]
  1177. proMap[k] = modifyMap[k]
  1178. }
  1179. // 有条件更新项目外围字段值(非空)
  1180. if proMap[k] == nil || util.ObjToString(k) == "" {
  1181. updataSet[k] = modifyMap[k]
  1182. proMap[k] = modifyMap[k]
  1183. }
  1184. }
  1185. }
  1186. return updataSet
  1187. }
  1188. // 备份(快照)
  1189. func backupPro(tmp map[string]interface{}) {
  1190. tmp1 := make(map[string]interface{})
  1191. for k, v := range tmp {
  1192. tmp1[k] = v
  1193. }
  1194. if config.Conf.Serve.BackupFlag {
  1195. tmp1["sourceprojectid"] = mongodb.BsonIdToSId(tmp1["_id"])
  1196. delete(tmp1, "_id")
  1197. MgoP.Save(BackupColl, tmp1)
  1198. }
  1199. }
  1200. // 删除原有项目数据
  1201. func delOldPro(pid string) {
  1202. t := MgoP.Delete(ProjectColl, map[string]interface{}{"_id": mongodb.StringTOBsonId(pid)})
  1203. if t >= 0 {
  1204. Es.DelById(config.Conf.DB.Es.Index, pid)
  1205. }
  1206. }
  1207. // 修改内存中的数据
  1208. func (p *ProjectTask) modifyMem(tmpPro map[string]interface{}) {
  1209. pid := util.ObjToString(tmpPro["_id"])
  1210. var pro ProjectCache
  1211. err := mapstructure.Decode(tmpPro, &pro)
  1212. if err != nil {
  1213. log.Info(err.Error())
  1214. }
  1215. pro.Id = mongodb.StringTOBsonId(pid)
  1216. tmpMap := make(map[string]InfoField)
  1217. infoMap := tmpPro["infofield"].(map[string]interface{})
  1218. for _, v := range infoMap {
  1219. var field InfoField
  1220. b, _ := json.Marshal(v)
  1221. _ = json.Unmarshal(b, &field)
  1222. tmpMap[pid] = field
  1223. }
  1224. p.AllIdsMapLock.Lock()
  1225. if v, ok := p.AllIdsMap[pid]; ok {
  1226. v.P = &pro
  1227. }
  1228. p.AllIdsMapLock.Unlock()
  1229. p.printMemPro(pid)
  1230. }
  1231. // 打印内存中的项目信息
  1232. func (p *ProjectTask) printMemPro(pid string) {
  1233. p.AllIdsMapLock.Lock()
  1234. if v, ok := p.AllIdsMap[pid]; ok {
  1235. log.Info("mem pro ----------", zap.Any("pro", *v.P))
  1236. }
  1237. p.AllIdsMapLock.Unlock()
  1238. }
  1239. // @Description id不变,内容变化 重新进行项目合并
  1240. // @Author J 2022/8/10 14:51
  1241. func (p *ProjectTask) taskinfo(id string) {
  1242. tmpPro, _ := MgoP.FindOneByField(ProjectColl, map[string]interface{}{"ids": id}, nil)
  1243. if tmpPro == nil || len(*tmpPro) == 0 {
  1244. log.Info(fmt.Sprintf("taskinfo bidding id=%s 未查询到项目数据", id))
  1245. return
  1246. }
  1247. pid := mongodb.BsonIdToSId((*tmpPro)["_id"])
  1248. ids := util.ObjArrToStringArr((*tmpPro)["ids"].([]interface{}))
  1249. list := (*tmpPro)["list"].([]interface{})
  1250. var newP map[string]interface{}
  1251. var p1 *ProjectCache
  1252. for i, s := range ids {
  1253. temp, _ := MgoB.FindById(BiddingColl, s, nil)
  1254. if temp == nil || len(*temp) == 0 {
  1255. temp, _ = MgoB.FindById("bidding_back", s, nil)
  1256. if temp == nil || len(*temp) == 0 {
  1257. log.Info("extract not find id..." + s)
  1258. return
  1259. }
  1260. }
  1261. push := p.PushListInfo(*temp, id)
  1262. if s == id {
  1263. list[i] = push
  1264. }
  1265. info := ParseInfo(*temp)
  1266. if i == 0 {
  1267. newP, p1 = p.createPro(*temp, info, pid)
  1268. } else {
  1269. p.updatePro(newP, *temp, p1, info)
  1270. }
  1271. }
  1272. newP["ids"] = ids
  1273. newP["pici"] = p.pici
  1274. p.AllIdsMapLock.Lock()
  1275. _, ok := p.AllIdsMap[pid]
  1276. if ok {
  1277. redis.PutCKV("project", pid, newP)
  1278. p.AllIdsMap[id] = &ID{Id: id, P: p1}
  1279. }
  1280. p.AllIdsMapLock.Unlock()
  1281. newP["list"] = list
  1282. if len(newP) > 0 {
  1283. updateInfo := []map[string]interface{}{
  1284. {
  1285. "_id": mongodb.StringTOBsonId(pid),
  1286. },
  1287. {"$set": newP},
  1288. }
  1289. p.updatePool <- updateInfo
  1290. }
  1291. }
  1292. // @Description 创建项目
  1293. // @Author J 2022/8/11 09:17
  1294. func (p *ProjectTask) createPro(tmp map[string]interface{}, thisinfo *Info, pid string) (map[string]interface{}, *ProjectCache) {
  1295. set := map[string]interface{}{}
  1296. set["_id"] = mongodb.StringTOBsonId(pid)
  1297. for _, f := range FIELDS {
  1298. if tmp[f] != nil && tmp[f] != "" {
  1299. set[f] = tmp[f]
  1300. }
  1301. }
  1302. bidopentime := util.Int64All(tmp["bidopentime"])
  1303. if bidopentime > 0 {
  1304. set["bidopentime"] = bidopentime
  1305. }
  1306. //异常标记
  1307. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  1308. set["exception"] = 1
  1309. }
  1310. //projecthref保存
  1311. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  1312. if jsonData != nil && util.ObjToString(jsonData["projecthref"]) != "" {
  1313. set["projecthref"] = jsonData["projecthref"]
  1314. }
  1315. }
  1316. //合同编号
  1317. if thisinfo.ContractCode != "" {
  1318. set["contractcode"] = thisinfo.ContractCode
  1319. }
  1320. bt := util.ObjToString(tmp["toptype"])
  1321. bs := util.ObjToString(tmp["subtype"])
  1322. p.mapBidLock.Lock()
  1323. if thisinfo.Infoformat == 2 || thisinfo.SubType == "拟建" {
  1324. set["bidstatus"] = "拟建"
  1325. bt = "拟建"
  1326. } else {
  1327. if bidtype[bs] != "" {
  1328. set["bidtype"] = bidtype[bs]
  1329. } else {
  1330. set["bidtype"] = "招标"
  1331. }
  1332. if bt == "招标" {
  1333. set["projectscope"] = util.ObjToString(tmp["projectscope"])
  1334. set["bidstatus"] = bt
  1335. } else {
  1336. if bidstatus[bs] != "" {
  1337. set["bidstatus"] = thisinfo.SubType
  1338. bt = thisinfo.SubType
  1339. } else if bs == "" {
  1340. set["bidstatus"] = ""
  1341. bt = ""
  1342. } else {
  1343. set["bidstatus"] = "其它"
  1344. bt = "其它"
  1345. }
  1346. }
  1347. }
  1348. p.mapBidLock.Unlock()
  1349. pkg := PackageFormat(thisinfo, nil)
  1350. p1 := p.NewCachePinfo(mongodb.StringTOBsonId(pid), thisinfo, bs, bt)
  1351. now := time.Now().Unix()
  1352. set["createtime"] = now
  1353. set["sourceinfoid"] = thisinfo.Id
  1354. set["sourceinfourl"] = tmp["href"]
  1355. set["firsttime"] = tmp["publishtime"]
  1356. set["lasttime"] = tmp["publishtime"]
  1357. //增量用系统时间,全量(历史)入库时间
  1358. if p.currentType == "pl" {
  1359. set["pici"] = tmp["comeintime"]
  1360. } else {
  1361. set["pici"] = p.pici
  1362. }
  1363. set["ids"] = []string{thisinfo.Id}
  1364. if thisinfo.TopType == "招标" {
  1365. //if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  1366. set["zbtime"] = tmp["publishtime"]
  1367. //}
  1368. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  1369. set["jgtime"] = tmp["publishtime"]
  1370. }
  1371. if len(thisinfo.Subscopeclass) > 0 {
  1372. set["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  1373. }
  1374. if len(thisinfo.Winners) > 0 {
  1375. set["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1376. }
  1377. if thisinfo.HasPackage {
  1378. set["multipackage"] = 1
  1379. set["package"] = pkg
  1380. } else {
  1381. set["multipackage"] = 0
  1382. }
  1383. //项目评审专家
  1384. if len(thisinfo.ReviewExperts) > 0 {
  1385. set["review_experts"] = thisinfo.ReviewExperts
  1386. }
  1387. //标的物
  1388. if thisinfo.Purchasing != "" {
  1389. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  1390. p := strings.Join(util.ObjArrToStringArr(list), ",")
  1391. set["purchasing"] = p
  1392. }
  1393. //中标候选人
  1394. if len(thisinfo.WinnerOrder) > 0 {
  1395. var list = []string{}
  1396. for _, v := range thisinfo.WinnerOrder {
  1397. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  1398. list = append(list, util.ObjToString(v["entname"]))
  1399. }
  1400. }
  1401. set["winnerorder"] = list
  1402. }
  1403. //项目规模
  1404. if len(thisinfo.ProjectScale) > 0 {
  1405. set["project_scale"] = thisinfo.ProjectScale
  1406. }
  1407. //工期时长
  1408. if thisinfo.ProjectDuration > 0 {
  1409. set["project_duration"] = thisinfo.ProjectDuration
  1410. }
  1411. // 工期单位
  1412. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  1413. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  1414. }
  1415. //开工日期
  1416. if thisinfo.ProjectStartDate > 0 {
  1417. set["project_startdate"] = thisinfo.ProjectStartDate
  1418. }
  1419. //竣工日期
  1420. if thisinfo.ProjectCompleteDate > 0 {
  1421. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1422. }
  1423. //付款方式
  1424. if len(thisinfo.Payway) > 0 {
  1425. set["payway"] = thisinfo.Payway
  1426. }
  1427. // 履约保证金
  1428. if tmp["contract_guarantee"] != nil {
  1429. set["contract_guarantee"] = thisinfo.ContractGuarantee
  1430. }
  1431. // 投标保证金
  1432. if tmp["bid_guarantee"] != nil {
  1433. set["bid_guarantee"] = thisinfo.BidGuarantee
  1434. }
  1435. // 资质条件
  1436. if len(thisinfo.Qualifies) > 0 {
  1437. var str []string
  1438. for _, v := range thisinfo.Qualifies {
  1439. if len(util.ObjToString(v["key"])) > 0 {
  1440. if BinarySearch(str, util.ObjToString(v["key"])) == -1 {
  1441. str = append(str, util.ObjToString(v["key"]))
  1442. }
  1443. }
  1444. }
  1445. if len(str) > 0 {
  1446. set["qualifies"] = strings.Join(str, ",")
  1447. }
  1448. }
  1449. if len(thisinfo.EntIdList) > 0 {
  1450. set["entidlist"] = thisinfo.EntIdList
  1451. }
  1452. // first_cooperation
  1453. if p1.Buyer != "" && len(thisinfo.Winners) > 0 {
  1454. FirstCooperation(set, p1.Buyer, thisinfo.Winners, thisinfo.EntIdList)
  1455. }
  1456. infofield := InfoField{
  1457. Budget: thisinfo.Budget,
  1458. Bidamount: thisinfo.Bidamount,
  1459. ContractCode: thisinfo.ContractCode,
  1460. ProjectName: thisinfo.ProjectName,
  1461. ProjectCode: thisinfo.ProjectCode,
  1462. Bidstatus: bs,
  1463. }
  1464. res := StructToMap(infofield)
  1465. set["infofield"] = map[string]interface{}{
  1466. thisinfo.Id: res,
  1467. }
  1468. if tmp["budget"] != nil && tmp["budget"] != "" {
  1469. set["budget"] = thisinfo.Budget
  1470. set["budgettag"] = 0
  1471. } else {
  1472. set["budgettag"] = 1
  1473. }
  1474. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  1475. set["bidamount"] = thisinfo.Bidamount
  1476. set["bidamounttag"] = 0
  1477. } else {
  1478. set["bidamounttag"] = 1
  1479. }
  1480. if p1.Bidamount > 0 {
  1481. set["sortprice"] = p1.Bidamount
  1482. } else {
  1483. if p1.Budget > 0 {
  1484. set["sortprice"] = p1.Budget
  1485. }
  1486. }
  1487. return set, &p1
  1488. }
  1489. // @Description id不变,内容覆盖 修改项目
  1490. // @Author J 2022/8/10 17:00
  1491. func (p *ProjectTask) updatePro(set, tmp map[string]interface{}, pInfo *ProjectCache, thisinfo *Info) {
  1492. bys, _ := json.Marshal(set)
  1493. var project *Project
  1494. err := json.Unmarshal(bys, &project)
  1495. if err != nil {
  1496. log.Info("project Unmarshal err," + err.Error())
  1497. return
  1498. }
  1499. //zbtime、lasttime、jgtime
  1500. pInfo.LastTime = thisinfo.Publishtime
  1501. set["lasttime"] = thisinfo.Publishtime
  1502. if thisinfo.TopType == "招标" {
  1503. if project.Zbtime <= 0 {
  1504. project.Zbtime = thisinfo.Publishtime
  1505. set["zbtime"] = tmp["publishtime"]
  1506. }
  1507. if project.Jgtime > 0 {
  1508. project.Jgtime = int64(0)
  1509. set["jgtime"] = int64(0)
  1510. }
  1511. } else if thisinfo.TopType == "结果" {
  1512. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  1513. if project.Jgtime > 0 {
  1514. //jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  1515. //公告状态和项目状态同样都是中标或者成交,
  1516. if thisinfo.SubType == "成交" && project.Bidstatus == "中标" {
  1517. if p.jgTime < thisinfo.Publishtime {
  1518. project.Jgtime = thisinfo.Publishtime
  1519. set["jgtime"] = tmp["publishtime"]
  1520. }
  1521. //公告状态和项目状态同样是流标或者废标
  1522. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (project.Bidstatus == "流标" || project.Bidstatus == "废标") {
  1523. if p.jgTime < thisinfo.Publishtime {
  1524. project.Jgtime = thisinfo.Publishtime
  1525. set["jgtime"] = tmp["publishtime"]
  1526. }
  1527. }
  1528. } else {
  1529. project.Jgtime = thisinfo.Publishtime
  1530. set["jgtime"] = tmp["publishtime"]
  1531. }
  1532. }
  1533. } else if thisinfo.SubType == "合同" {
  1534. if project.Bidstatus == "中标" || project.Bidstatus == "成交" || project.Bidstatus == "" {
  1535. //中标、成交不更新jgtime
  1536. } else {
  1537. project.Jgtime = thisinfo.Publishtime
  1538. set["jgtime"] = tmp["publishtime"]
  1539. }
  1540. }
  1541. if thisinfo.BidOpenTime > project.BidOpenTime {
  1542. project.BidOpenTime = thisinfo.BidOpenTime
  1543. set["bidopentime"] = project.BidOpenTime
  1544. }
  1545. if thisinfo.BidEndTime > 0 {
  1546. project.BidEndTime = thisinfo.BidEndTime
  1547. set["bidendtime"] = project.BidEndTime
  1548. }
  1549. bt := util.ObjToString(tmp["toptype"])
  1550. bs := util.ObjToString(tmp["subtype"])
  1551. p.mapBidLock.Lock()
  1552. if bt == "招标" {
  1553. //招标状态,更新projectscope
  1554. if tmp["projectscope"] != nil {
  1555. set["projectscope"] = util.ObjToString(tmp["projectscope"])
  1556. }
  1557. set["bidstatus"] = bt
  1558. project.Bidstatus = bt
  1559. if bidtype[bs] != "" {
  1560. set["bidtype"] = bidtype[bs]
  1561. project.Bidtype = bidtype[bs]
  1562. } else {
  1563. set["bidtype"] = "招标"
  1564. project.Bidtype = "招标"
  1565. }
  1566. } else {
  1567. if bidstatus[bs] != "" {
  1568. set["bidstatus"] = thisinfo.SubType
  1569. project.Bidstatus = thisinfo.SubType
  1570. } else if thisinfo.Infoformat == 2 {
  1571. set["bidstatus"] = "拟建"
  1572. project.Bidstatus = "拟建"
  1573. } else if bs == "" && bt == "结果" {
  1574. if project.Bidstatus == "招标" {
  1575. set["bidstatus"] = ""
  1576. project.Bidstatus = ""
  1577. }
  1578. } else {
  1579. set["bidstatus"] = "其它"
  1580. project.Bidstatus = "其它"
  1581. }
  1582. }
  1583. p.mapBidLock.Unlock()
  1584. //相同城市的公告才会合并到一起(全国列外)
  1585. if thisinfo.Area != "全国" {
  1586. pInfo.Area = thisinfo.Area
  1587. project.Area = thisinfo.Area
  1588. set["area"] = thisinfo.Area
  1589. if thisinfo.City != "" {
  1590. pInfo.City = thisinfo.City
  1591. project.City = thisinfo.City
  1592. set["city"] = thisinfo.City
  1593. }
  1594. if thisinfo.District != "" {
  1595. pInfo.District = thisinfo.District
  1596. project.District = thisinfo.District
  1597. set["district"] = thisinfo.District
  1598. }
  1599. }
  1600. //项目名称
  1601. //if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  1602. if pInfo.ProjectName == "" && thisinfo.ProjectName != "" {
  1603. pInfo.ProjectName = thisinfo.ProjectName
  1604. project.ProjectName = thisinfo.ProjectName
  1605. set["projectname"] = thisinfo.ProjectName
  1606. }
  1607. //7--项目编号
  1608. //if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  1609. if pInfo.ProjectCode == "" && thisinfo.ProjectCode != "" {
  1610. pInfo.ProjectCode = thisinfo.ProjectCode
  1611. project.ProjectCode = thisinfo.ProjectCode
  1612. set["projectcode"] = thisinfo.ProjectCode
  1613. }
  1614. //7--采购单位
  1615. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  1616. pInfo.Buyer = thisinfo.Buyer
  1617. project.Buyer = thisinfo.Buyer
  1618. set["buyer"] = thisinfo.Buyer
  1619. project.Buyerclass = thisinfo.Buyerclass
  1620. set["buyerclass"] = thisinfo.Buyerclass
  1621. }
  1622. if pInfo.Buyer == "" {
  1623. project.Buyerclass = ""
  1624. set["buyerclass"] = ""
  1625. }
  1626. //采购单位联系人
  1627. if thisinfo.Buyerperson != "" {
  1628. project.Buyerperson = thisinfo.Buyerperson
  1629. set["buyerperson"] = thisinfo.Buyerperson
  1630. } else {
  1631. project.Buyerperson = ""
  1632. set["buyerperson"] = ""
  1633. }
  1634. //采购单位電話
  1635. if thisinfo.Buyertel != "" {
  1636. project.Buyertel = thisinfo.Buyertel
  1637. set["buyertel"] = project.Buyertel
  1638. } else {
  1639. project.Buyertel = ""
  1640. set["buyertel"] = ""
  1641. }
  1642. if thisinfo.ContractCode != "" {
  1643. if project.ContractCode == "" {
  1644. set["contractcode"] = thisinfo.ContractCode
  1645. } else {
  1646. list := strings.Split(project.ContractCode, ",")
  1647. if BinarySearch(list, thisinfo.ContractCode) == -1 {
  1648. list = append(list, thisinfo.ContractCode)
  1649. sort.Strings(list)
  1650. }
  1651. set["contractcode"] = strings.Join(list, ",")
  1652. }
  1653. }
  1654. //8--代理机构
  1655. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  1656. pInfo.Agency = thisinfo.Agency
  1657. project.Agency = thisinfo.Agency
  1658. set["agency"] = thisinfo.Agency
  1659. }
  1660. if len(thisinfo.Topscopeclass) > 0 {
  1661. sort.Strings(project.Topscopeclass)
  1662. for _, k := range thisinfo.Topscopeclass {
  1663. if BinarySearch(project.Topscopeclass, k) == -1 {
  1664. project.Topscopeclass = append(project.Topscopeclass, k)
  1665. sort.Strings(project.Topscopeclass)
  1666. }
  1667. }
  1668. set["topscopeclass"] = project.Topscopeclass
  1669. }
  1670. //项目评审专家
  1671. if len(thisinfo.ReviewExperts) > 0 {
  1672. set["review_experts"] = thisinfo.ReviewExperts
  1673. project.ReviewExperts = thisinfo.ReviewExperts
  1674. }
  1675. if thisinfo.Purchasing != "" {
  1676. if project.Purchasing == "" {
  1677. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  1678. p := strings.Join(util.ObjArrToStringArr(list), ",")
  1679. project.Purchasing = p
  1680. set["purchasing"] = p
  1681. } else {
  1682. list := strings.Split(project.Purchasing, ",")
  1683. list = util.ObjArrToStringArr(Duplicate(list))
  1684. for _, k := range list {
  1685. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  1686. list = append(list, k)
  1687. sort.Strings(list)
  1688. }
  1689. }
  1690. set["purchasing"] = strings.Join(list, ",")
  1691. }
  1692. }
  1693. //中标候选人
  1694. if len(thisinfo.WinnerOrder) > 0 {
  1695. var list = []string{}
  1696. for _, v := range thisinfo.WinnerOrder {
  1697. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  1698. list = append(list, util.ObjToString(v["entname"]))
  1699. }
  1700. }
  1701. set["winnerorder"] = list
  1702. project.Winnerorder = list
  1703. }
  1704. if len(thisinfo.Subscopeclass) > 0 {
  1705. sort.Strings(project.Subscopeclass)
  1706. for _, k := range thisinfo.Subscopeclass {
  1707. if BinarySearch(project.Subscopeclass, k) == -1 {
  1708. project.Subscopeclass = append(project.Subscopeclass, k)
  1709. sort.Strings(project.Subscopeclass)
  1710. }
  1711. }
  1712. set["subscopeclass"] = project.Subscopeclass
  1713. set["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
  1714. }
  1715. if len(thisinfo.Winners) > 0 {
  1716. if len(project.Winners) <= 0 {
  1717. set["winner"] = util.ObjToString(tmp["winner"])
  1718. }
  1719. winners := strings.Split(project.Winners, ",")
  1720. for _, k := range thisinfo.Winners {
  1721. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  1722. if BinarySearch(winners, k) != -1 {
  1723. deleteSlice(winners, k, "")
  1724. }
  1725. } else {
  1726. if BinarySearch(winners, k) == -1 {
  1727. winners = append(winners, k)
  1728. }
  1729. }
  1730. }
  1731. set["s_winner"] = strings.Join(util.ObjArrToStringArr(Duplicate(winners)), ",")
  1732. }
  1733. if len(thisinfo.EntIdList) > 0 {
  1734. for _, v := range thisinfo.EntIdList {
  1735. if BinarySearch(project.EntIdList, v) == -1 {
  1736. project.EntIdList = append(project.EntIdList, v)
  1737. }
  1738. }
  1739. set["entidlist"] = project.EntIdList
  1740. }
  1741. // first_cooperation
  1742. if pInfo.Buyer != "" && len(strings.Split(project.Winners, ",")) > 0 {
  1743. FirstCooperation(set, pInfo.Buyer, strings.Split(project.Winners, ","), project.EntIdList)
  1744. }
  1745. //项目规模
  1746. if len(thisinfo.ProjectScale) > 0 {
  1747. project.ProjectScale = thisinfo.ProjectScale
  1748. set["project_scale"] = thisinfo.ProjectScale
  1749. }
  1750. //工期时长
  1751. if thisinfo.ProjectDuration > 0 {
  1752. project.ProjectDuration = thisinfo.ProjectDuration
  1753. set["project_duration"] = thisinfo.ProjectDuration
  1754. }
  1755. // 工期单位
  1756. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  1757. project.ProjectTimeunit = thisinfo.ProjectTimeUnit
  1758. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  1759. }
  1760. //开工日期
  1761. if thisinfo.ProjectStartDate > 0 {
  1762. if project.ProjectStartDate > 0 {
  1763. if project.ProjectStartDate < thisinfo.ProjectStartDate {
  1764. project.ProjectStartDate = thisinfo.ProjectStartDate
  1765. set["project_startdate"] = thisinfo.ProjectStartDate
  1766. }
  1767. } else {
  1768. project.ProjectStartDate = thisinfo.ProjectStartDate
  1769. set["project_startdate"] = thisinfo.ProjectStartDate
  1770. }
  1771. }
  1772. //竣工日期
  1773. if thisinfo.ProjectCompleteDate > 0 {
  1774. if project.ProjctCompleteDate > 0 {
  1775. if project.ProjctCompleteDate < thisinfo.ProjectCompleteDate {
  1776. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1777. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1778. }
  1779. } else {
  1780. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1781. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1782. }
  1783. }
  1784. // 付款方式
  1785. if len(thisinfo.Payway) > 0 {
  1786. project.Payway = thisinfo.Payway
  1787. set["payway"] = thisinfo.Payway
  1788. }
  1789. // 履约保证金
  1790. if tmp["contract_guarantee"] != nil {
  1791. project.ContractGuarantee = thisinfo.ContractGuarantee
  1792. set["contract_guarantee"] = thisinfo.ContractGuarantee
  1793. }
  1794. // 投标保证金
  1795. if tmp["bid_guarantee"] != nil {
  1796. project.BidGuarantee = thisinfo.BidGuarantee
  1797. set["bid_guarantee"] = thisinfo.BidGuarantee
  1798. }
  1799. // 资质条件
  1800. if len(thisinfo.Qualifies) > 0 {
  1801. var str []string
  1802. if len(project.Qualifies) > 0 {
  1803. str = append(str, strings.Split(project.Qualifies, ",")...)
  1804. }
  1805. for _, v := range thisinfo.Qualifies {
  1806. if len(util.ObjToString(v["key"])) > 0 {
  1807. if BinarySearch(str, util.ObjToString(v["key"])) == -1 {
  1808. str = append(str, util.ObjToString(v["key"]))
  1809. }
  1810. }
  1811. }
  1812. if len(str) > 0 {
  1813. project.Qualifies = strings.Join(str, ",")
  1814. set["qualifies"] = strings.Join(str, ",")
  1815. }
  1816. }
  1817. if thisinfo.HasPackage { //多包处理
  1818. set["multipackage"] = 1
  1819. pkg := PackageFormat(thisinfo, project)
  1820. project.Package = pkg
  1821. set["package"] = project.Package
  1822. }
  1823. //处理多包后,计算预算金额、中标金额
  1824. CountAmount(project, thisinfo, tmp)
  1825. if project.Budget >= 0 && project.Budgettag != 1 {
  1826. pInfo.Budget = project.Budget
  1827. set["budget"] = project.Budget
  1828. set["budgettag"] = 0
  1829. }
  1830. if project.Bidamount >= 0 && project.Bidamounttag != 1 {
  1831. pInfo.Bidamount = project.Bidamount
  1832. set["bidamount"] = pInfo.Bidamount
  1833. set["bidamounttag"] = 0
  1834. }
  1835. if pInfo.Bidamount > 0 {
  1836. set["sortprice"] = pInfo.Bidamount
  1837. } else {
  1838. if pInfo.Budget > 0 {
  1839. set["sortprice"] = pInfo.Budget
  1840. }
  1841. }
  1842. infofield := InfoField{
  1843. Budget: thisinfo.Budget,
  1844. Bidamount: thisinfo.Bidamount,
  1845. ContractCode: thisinfo.ContractCode,
  1846. ProjectName: thisinfo.ProjectName,
  1847. ProjectCode: thisinfo.ProjectCode,
  1848. Bidstatus: bs,
  1849. }
  1850. tmpMap := set["infofield"].(map[string]interface{})
  1851. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1852. set["infofield"] = tmpMap
  1853. copyMap := util.DeepCopy(project.InfoFiled).(map[string]InfoField)
  1854. copyMap[thisinfo.Id] = infofield
  1855. project.InfoFiled = copyMap
  1856. set["mpn"] = pInfo.MPN
  1857. set["mpc"] = pInfo.MPC
  1858. }