update.go 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908
  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. newP["pici"] = p.pici
  1266. p.AllIdsMapLock.Lock()
  1267. _, ok := p.AllIdsMap[pid]
  1268. if ok {
  1269. redis.PutCKV("project", pid, newP)
  1270. p.AllIdsMap[id] = &ID{Id: id, P: p1}
  1271. }
  1272. p.AllIdsMapLock.Unlock()
  1273. newP["list"] = list
  1274. if len(newP) > 0 {
  1275. updateInfo := []map[string]interface{}{
  1276. {
  1277. "_id": mongodb.StringTOBsonId(pid),
  1278. },
  1279. {"$set": newP},
  1280. }
  1281. p.updatePool <- updateInfo
  1282. }
  1283. }
  1284. // @Description 创建项目
  1285. // @Author J 2022/8/11 09:17
  1286. func (p *ProjectTask) createPro(tmp map[string]interface{}, thisinfo *Info, pid string) (map[string]interface{}, *ProjectCache) {
  1287. set := map[string]interface{}{}
  1288. set["_id"] = mongodb.StringTOBsonId(pid)
  1289. for _, f := range FIELDS {
  1290. if tmp[f] != nil && tmp[f] != "" {
  1291. set[f] = tmp[f]
  1292. }
  1293. }
  1294. bidopentime := qu.Int64All(tmp["bidopentime"])
  1295. if bidopentime > 0 {
  1296. set["bidopentime"] = bidopentime
  1297. }
  1298. //异常标记
  1299. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  1300. set["exception"] = 1
  1301. }
  1302. //projecthref保存
  1303. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  1304. if jsonData != nil && qu.ObjToString(jsonData["projecthref"]) != "" {
  1305. set["projecthref"] = jsonData["projecthref"]
  1306. }
  1307. }
  1308. //合同编号
  1309. if thisinfo.ContractCode != "" {
  1310. set["contractcode"] = thisinfo.ContractCode
  1311. }
  1312. bt := qu.ObjToString(tmp["toptype"])
  1313. bs := qu.ObjToString(tmp["subtype"])
  1314. p.mapBidLock.Lock()
  1315. if thisinfo.Infoformat == 2 || thisinfo.SubType == "拟建" {
  1316. set["bidstatus"] = "拟建"
  1317. bt = "拟建"
  1318. } else {
  1319. if bidtype[bs] != "" {
  1320. set["bidtype"] = bidtype[bs]
  1321. } else {
  1322. set["bidtype"] = "招标"
  1323. }
  1324. if bt == "招标" {
  1325. set["projectscope"] = qu.ObjToString(tmp["projectscope"])
  1326. set["bidstatus"] = bt
  1327. } else {
  1328. if bidstatus[bs] != "" {
  1329. set["bidstatus"] = thisinfo.SubType
  1330. bt = thisinfo.SubType
  1331. } else if bs == "" {
  1332. set["bidstatus"] = ""
  1333. bt = ""
  1334. } else {
  1335. set["bidstatus"] = "其它"
  1336. bt = "其它"
  1337. }
  1338. }
  1339. }
  1340. p.mapBidLock.Unlock()
  1341. pkg := PackageFormat(thisinfo, nil)
  1342. p1 := p.NewCachePinfo(mongodb.StringTOBsonId(pid), thisinfo, bs, bt)
  1343. now := time.Now().Unix()
  1344. set["createtime"] = now
  1345. set["sourceinfoid"] = thisinfo.Id
  1346. set["sourceinfourl"] = tmp["href"]
  1347. set["firsttime"] = tmp["publishtime"]
  1348. set["lasttime"] = tmp["publishtime"]
  1349. //增量用系统时间,全量(历史)入库时间
  1350. if p.currentType == "pl" {
  1351. set["pici"] = tmp["comeintime"]
  1352. } else {
  1353. set["pici"] = p.pici
  1354. }
  1355. set["ids"] = []string{thisinfo.Id}
  1356. if thisinfo.TopType == "招标" {
  1357. //if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  1358. set["zbtime"] = tmp["publishtime"]
  1359. //}
  1360. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  1361. set["jgtime"] = tmp["publishtime"]
  1362. }
  1363. if len(thisinfo.Subscopeclass) > 0 {
  1364. set["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  1365. }
  1366. if len(thisinfo.Winners) > 0 {
  1367. set["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1368. }
  1369. if thisinfo.HasPackage {
  1370. set["multipackage"] = 1
  1371. set["package"] = pkg
  1372. } else {
  1373. set["multipackage"] = 0
  1374. }
  1375. //项目评审专家
  1376. if len(thisinfo.ReviewExperts) > 0 {
  1377. set["review_experts"] = thisinfo.ReviewExperts
  1378. }
  1379. //标的物
  1380. if thisinfo.Purchasing != "" {
  1381. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  1382. p := strings.Join(qu.ObjArrToStringArr(list), ",")
  1383. set["purchasing"] = p
  1384. }
  1385. //中标候选人
  1386. if len(thisinfo.WinnerOrder) > 0 {
  1387. var list = []string{}
  1388. for _, v := range thisinfo.WinnerOrder {
  1389. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  1390. list = append(list, qu.ObjToString(v["entname"]))
  1391. }
  1392. }
  1393. set["winnerorder"] = list
  1394. }
  1395. //项目规模
  1396. if len(thisinfo.ProjectScale) > 0 {
  1397. set["project_scale"] = thisinfo.ProjectScale
  1398. }
  1399. //工期时长
  1400. if thisinfo.ProjectDuration > 0 {
  1401. set["project_duration"] = thisinfo.ProjectDuration
  1402. }
  1403. // 工期单位
  1404. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  1405. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  1406. }
  1407. //开工日期
  1408. if thisinfo.ProjectStartDate > 0 {
  1409. set["project_startdate"] = thisinfo.ProjectStartDate
  1410. }
  1411. //竣工日期
  1412. if thisinfo.ProjectCompleteDate > 0 {
  1413. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1414. }
  1415. //付款方式
  1416. if len(thisinfo.Payway) > 0 {
  1417. set["payway"] = thisinfo.Payway
  1418. }
  1419. // 履约保证金
  1420. if tmp["contract_guarantee"] != nil {
  1421. set["contract_guarantee"] = thisinfo.ContractGuarantee
  1422. }
  1423. // 投标保证金
  1424. if tmp["bid_guarantee"] != nil {
  1425. set["bid_guarantee"] = thisinfo.BidGuarantee
  1426. }
  1427. // 资质条件
  1428. if len(thisinfo.Qualifies) > 0 {
  1429. var str []string
  1430. for _, v := range thisinfo.Qualifies {
  1431. if len(qu.ObjToString(v["key"])) > 0 {
  1432. if BinarySearch(str, qu.ObjToString(v["key"])) == -1 {
  1433. str = append(str, qu.ObjToString(v["key"]))
  1434. }
  1435. }
  1436. }
  1437. if len(str) > 0 {
  1438. set["qualifies"] = strings.Join(str, ",")
  1439. }
  1440. }
  1441. if len(thisinfo.EntIdList) > 0 {
  1442. set["entidlist"] = thisinfo.EntIdList
  1443. }
  1444. // first_cooperation
  1445. if p1.Buyer != "" && len(thisinfo.Winners) > 0 {
  1446. FirstCooperation(set, p1.Buyer, thisinfo.Winners, thisinfo.EntIdList)
  1447. }
  1448. infofield := InfoField{
  1449. Budget: thisinfo.Budget,
  1450. Bidamount: thisinfo.Bidamount,
  1451. ContractCode: thisinfo.ContractCode,
  1452. ProjectName: thisinfo.ProjectName,
  1453. ProjectCode: thisinfo.ProjectCode,
  1454. Bidstatus: bs,
  1455. }
  1456. res := StructToMap(infofield)
  1457. set["infofield"] = map[string]interface{}{
  1458. thisinfo.Id: res,
  1459. }
  1460. if tmp["budget"] != nil && tmp["budget"] != "" {
  1461. set["budget"] = thisinfo.Budget
  1462. set["budgettag"] = 0
  1463. } else {
  1464. set["budgettag"] = 1
  1465. }
  1466. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  1467. set["bidamount"] = thisinfo.Bidamount
  1468. set["bidamounttag"] = 0
  1469. } else {
  1470. set["bidamounttag"] = 1
  1471. }
  1472. if p1.Bidamount > 0 {
  1473. set["sortprice"] = p1.Bidamount
  1474. } else {
  1475. if p1.Budget > 0 {
  1476. set["sortprice"] = p1.Budget
  1477. }
  1478. }
  1479. return set, &p1
  1480. }
  1481. // @Description id不变,内容覆盖 修改项目
  1482. // @Author J 2022/8/10 17:00
  1483. func (p *ProjectTask) updatePro(set, tmp map[string]interface{}, pInfo *ProjectCache, thisinfo *Info) {
  1484. bys, _ := json.Marshal(set)
  1485. var project *Project
  1486. err := json.Unmarshal(bys, &project)
  1487. if err != nil {
  1488. qu.Debug("project Unmarshal err,", err)
  1489. return
  1490. }
  1491. //zbtime、lasttime、jgtime
  1492. pInfo.LastTime = thisinfo.Publishtime
  1493. set["lasttime"] = thisinfo.Publishtime
  1494. if thisinfo.TopType == "招标" {
  1495. if project.Zbtime <= 0 {
  1496. project.Zbtime = thisinfo.Publishtime
  1497. set["zbtime"] = tmp["publishtime"]
  1498. }
  1499. if project.Jgtime > 0 {
  1500. project.Jgtime = int64(0)
  1501. set["jgtime"] = int64(0)
  1502. }
  1503. } else if thisinfo.TopType == "结果" {
  1504. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  1505. if project.Jgtime > 0 {
  1506. //jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  1507. //公告状态和项目状态同样都是中标或者成交,
  1508. if thisinfo.SubType == "成交" && project.Bidstatus == "中标" {
  1509. if p.jgTime < thisinfo.Publishtime {
  1510. project.Jgtime = thisinfo.Publishtime
  1511. set["jgtime"] = tmp["publishtime"]
  1512. }
  1513. //公告状态和项目状态同样是流标或者废标
  1514. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (project.Bidstatus == "流标" || project.Bidstatus == "废标") {
  1515. if p.jgTime < thisinfo.Publishtime {
  1516. project.Jgtime = thisinfo.Publishtime
  1517. set["jgtime"] = tmp["publishtime"]
  1518. }
  1519. }
  1520. } else {
  1521. project.Jgtime = thisinfo.Publishtime
  1522. set["jgtime"] = tmp["publishtime"]
  1523. }
  1524. }
  1525. } else if thisinfo.SubType == "合同" {
  1526. if project.Bidstatus == "中标" || project.Bidstatus == "成交" || project.Bidstatus == "" {
  1527. //中标、成交不更新jgtime
  1528. } else {
  1529. project.Jgtime = thisinfo.Publishtime
  1530. set["jgtime"] = tmp["publishtime"]
  1531. }
  1532. }
  1533. if thisinfo.Bidopentime > project.Bidopentime {
  1534. project.Bidopentime = thisinfo.Bidopentime
  1535. set["bidopentime"] = project.Bidopentime
  1536. }
  1537. bt := qu.ObjToString(tmp["toptype"])
  1538. bs := qu.ObjToString(tmp["subtype"])
  1539. p.mapBidLock.Lock()
  1540. if bt == "招标" {
  1541. //招标状态,更新projectscope
  1542. if tmp["projectscope"] != nil {
  1543. set["projectscope"] = qu.ObjToString(tmp["projectscope"])
  1544. }
  1545. set["bidstatus"] = bt
  1546. project.Bidstatus = bt
  1547. if bidtype[bs] != "" {
  1548. set["bidtype"] = bidtype[bs]
  1549. project.Bidtype = bidtype[bs]
  1550. } else {
  1551. set["bidtype"] = "招标"
  1552. project.Bidtype = "招标"
  1553. }
  1554. } else {
  1555. if bidstatus[bs] != "" {
  1556. set["bidstatus"] = thisinfo.SubType
  1557. project.Bidstatus = thisinfo.SubType
  1558. } else if thisinfo.Infoformat == 2 {
  1559. set["bidstatus"] = "拟建"
  1560. project.Bidstatus = "拟建"
  1561. } else if bs == "" && bt == "结果" {
  1562. if project.Bidstatus == "招标" {
  1563. set["bidstatus"] = ""
  1564. project.Bidstatus = ""
  1565. }
  1566. } else {
  1567. set["bidstatus"] = "其它"
  1568. project.Bidstatus = "其它"
  1569. }
  1570. }
  1571. p.mapBidLock.Unlock()
  1572. //相同城市的公告才会合并到一起(全国列外)
  1573. if thisinfo.Area != "全国" {
  1574. pInfo.Area = thisinfo.Area
  1575. project.Area = thisinfo.Area
  1576. set["area"] = thisinfo.Area
  1577. if thisinfo.City != "" {
  1578. pInfo.City = thisinfo.City
  1579. project.City = thisinfo.City
  1580. set["city"] = thisinfo.City
  1581. }
  1582. if thisinfo.District != "" {
  1583. pInfo.District = thisinfo.District
  1584. project.District = thisinfo.District
  1585. set["district"] = thisinfo.District
  1586. }
  1587. }
  1588. //项目名称
  1589. //if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  1590. if pInfo.ProjectName == "" && thisinfo.ProjectName != "" {
  1591. pInfo.ProjectName = thisinfo.ProjectName
  1592. project.ProjectName = thisinfo.ProjectName
  1593. set["projectname"] = thisinfo.ProjectName
  1594. }
  1595. //7--项目编号
  1596. //if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  1597. if pInfo.ProjectCode == "" && thisinfo.ProjectCode != "" {
  1598. pInfo.ProjectCode = thisinfo.ProjectCode
  1599. project.ProjectCode = thisinfo.ProjectCode
  1600. set["projectcode"] = thisinfo.ProjectCode
  1601. }
  1602. //7--采购单位
  1603. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  1604. pInfo.Buyer = thisinfo.Buyer
  1605. project.Buyer = thisinfo.Buyer
  1606. set["buyer"] = thisinfo.Buyer
  1607. project.Buyerclass = thisinfo.Buyerclass
  1608. set["buyerclass"] = thisinfo.Buyerclass
  1609. }
  1610. if pInfo.Buyer == "" {
  1611. project.Buyerclass = ""
  1612. set["buyerclass"] = ""
  1613. }
  1614. //采购单位联系人
  1615. if thisinfo.Buyerperson != "" {
  1616. project.Buyerperson = thisinfo.Buyerperson
  1617. set["buyerperson"] = thisinfo.Buyerperson
  1618. } else {
  1619. project.Buyerperson = ""
  1620. set["buyerperson"] = ""
  1621. }
  1622. //采购单位電話
  1623. if thisinfo.Buyertel != "" {
  1624. project.Buyertel = thisinfo.Buyertel
  1625. set["buyertel"] = project.Buyertel
  1626. } else {
  1627. project.Buyertel = ""
  1628. set["buyertel"] = ""
  1629. }
  1630. if thisinfo.ContractCode != "" {
  1631. if project.ContractCode == "" {
  1632. set["contractcode"] = thisinfo.ContractCode
  1633. } else {
  1634. list := strings.Split(project.ContractCode, ",")
  1635. if BinarySearch(list, thisinfo.ContractCode) == -1 {
  1636. list = append(list, thisinfo.ContractCode)
  1637. sort.Strings(list)
  1638. }
  1639. set["contractcode"] = strings.Join(list, ",")
  1640. }
  1641. }
  1642. //8--代理机构
  1643. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  1644. pInfo.Agency = thisinfo.Agency
  1645. project.Agency = thisinfo.Agency
  1646. set["agency"] = thisinfo.Agency
  1647. }
  1648. if len(thisinfo.Topscopeclass) > 0 {
  1649. sort.Strings(project.Topscopeclass)
  1650. for _, k := range thisinfo.Topscopeclass {
  1651. if BinarySearch(project.Topscopeclass, k) == -1 {
  1652. project.Topscopeclass = append(project.Topscopeclass, k)
  1653. sort.Strings(project.Topscopeclass)
  1654. }
  1655. }
  1656. set["topscopeclass"] = project.Topscopeclass
  1657. }
  1658. //项目评审专家
  1659. if len(thisinfo.ReviewExperts) > 0 {
  1660. set["review_experts"] = thisinfo.ReviewExperts
  1661. project.ReviewExperts = thisinfo.ReviewExperts
  1662. }
  1663. if thisinfo.Purchasing != "" {
  1664. if project.Purchasing == "" {
  1665. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  1666. p := strings.Join(qu.ObjArrToStringArr(list), ",")
  1667. project.Purchasing = p
  1668. set["purchasing"] = p
  1669. } else {
  1670. list := strings.Split(project.Purchasing, ",")
  1671. list = qu.ObjArrToStringArr(Duplicate(list))
  1672. for _, k := range list {
  1673. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  1674. list = append(list, k)
  1675. sort.Strings(list)
  1676. }
  1677. }
  1678. set["purchasing"] = strings.Join(list, ",")
  1679. }
  1680. }
  1681. //中标候选人
  1682. if len(thisinfo.WinnerOrder) > 0 {
  1683. var list = []string{}
  1684. for _, v := range thisinfo.WinnerOrder {
  1685. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  1686. list = append(list, qu.ObjToString(v["entname"]))
  1687. }
  1688. }
  1689. set["winnerorder"] = list
  1690. project.Winnerorder = list
  1691. }
  1692. if len(thisinfo.Subscopeclass) > 0 {
  1693. sort.Strings(project.Subscopeclass)
  1694. for _, k := range thisinfo.Subscopeclass {
  1695. if BinarySearch(project.Subscopeclass, k) == -1 {
  1696. project.Subscopeclass = append(project.Subscopeclass, k)
  1697. sort.Strings(project.Subscopeclass)
  1698. }
  1699. }
  1700. set["subscopeclass"] = project.Subscopeclass
  1701. set["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
  1702. }
  1703. if len(thisinfo.Winners) > 0 {
  1704. if len(project.Winners) <= 0 {
  1705. set["winner"] = qu.ObjToString(tmp["winner"])
  1706. }
  1707. winners := strings.Split(project.Winners, ",")
  1708. for _, k := range thisinfo.Winners {
  1709. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  1710. if BinarySearch(winners, k) != -1 {
  1711. deleteSlice(winners, k, "")
  1712. }
  1713. } else {
  1714. if BinarySearch(winners, k) == -1 {
  1715. winners = append(winners, k)
  1716. }
  1717. }
  1718. }
  1719. set["s_winner"] = strings.Join(qu.ObjArrToStringArr(Duplicate(winners)), ",")
  1720. }
  1721. if len(thisinfo.EntIdList) > 0 {
  1722. for _, v := range thisinfo.EntIdList {
  1723. if BinarySearch(project.EntIdList, v) == -1 {
  1724. project.EntIdList = append(project.EntIdList, v)
  1725. }
  1726. }
  1727. set["entidlist"] = project.EntIdList
  1728. }
  1729. // first_cooperation
  1730. if pInfo.Buyer != "" && len(strings.Split(project.Winners, ",")) > 0 {
  1731. FirstCooperation(set, pInfo.Buyer, strings.Split(project.Winners, ","), project.EntIdList)
  1732. }
  1733. //项目规模
  1734. if len(thisinfo.ProjectScale) > 0 {
  1735. project.ProjectScale = thisinfo.ProjectScale
  1736. set["project_scale"] = thisinfo.ProjectScale
  1737. }
  1738. //工期时长
  1739. if thisinfo.ProjectDuration > 0 {
  1740. project.ProjectDuration = thisinfo.ProjectDuration
  1741. set["project_duration"] = thisinfo.ProjectDuration
  1742. }
  1743. // 工期单位
  1744. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  1745. project.ProjectTimeunit = thisinfo.ProjectTimeUnit
  1746. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  1747. }
  1748. //开工日期
  1749. if thisinfo.ProjectStartDate > 0 {
  1750. if project.ProjectStartDate > 0 {
  1751. if project.ProjectStartDate < thisinfo.ProjectStartDate {
  1752. project.ProjectStartDate = thisinfo.ProjectStartDate
  1753. set["project_startdate"] = thisinfo.ProjectStartDate
  1754. }
  1755. } else {
  1756. project.ProjectStartDate = thisinfo.ProjectStartDate
  1757. set["project_startdate"] = thisinfo.ProjectStartDate
  1758. }
  1759. }
  1760. //竣工日期
  1761. if thisinfo.ProjectCompleteDate > 0 {
  1762. if project.ProjctCompleteDate > 0 {
  1763. if project.ProjctCompleteDate < thisinfo.ProjectCompleteDate {
  1764. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1765. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1766. }
  1767. } else {
  1768. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1769. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1770. }
  1771. }
  1772. // 付款方式
  1773. if len(thisinfo.Payway) > 0 {
  1774. project.Payway = thisinfo.Payway
  1775. set["payway"] = thisinfo.Payway
  1776. }
  1777. // 履约保证金
  1778. if tmp["contract_guarantee"] != nil {
  1779. project.ContractGuarantee = thisinfo.ContractGuarantee
  1780. set["contract_guarantee"] = thisinfo.ContractGuarantee
  1781. }
  1782. // 投标保证金
  1783. if tmp["bid_guarantee"] != nil {
  1784. project.BidGuarantee = thisinfo.BidGuarantee
  1785. set["bid_guarantee"] = thisinfo.BidGuarantee
  1786. }
  1787. // 资质条件
  1788. if len(thisinfo.Qualifies) > 0 {
  1789. var str []string
  1790. if len(project.Qualifies) > 0 {
  1791. str = append(str, strings.Split(project.Qualifies, ",")...)
  1792. }
  1793. for _, v := range thisinfo.Qualifies {
  1794. if len(qu.ObjToString(v["key"])) > 0 {
  1795. if BinarySearch(str, qu.ObjToString(v["key"])) == -1 {
  1796. str = append(str, qu.ObjToString(v["key"]))
  1797. }
  1798. }
  1799. }
  1800. if len(str) > 0 {
  1801. project.Qualifies = strings.Join(str, ",")
  1802. set["qualifies"] = strings.Join(str, ",")
  1803. }
  1804. }
  1805. if thisinfo.HasPackage { //多包处理
  1806. set["multipackage"] = 1
  1807. pkg := PackageFormat(thisinfo, project)
  1808. project.Package = pkg
  1809. set["package"] = project.Package
  1810. }
  1811. //处理多包后,计算预算金额、中标金额
  1812. CountAmount(project, thisinfo, tmp)
  1813. if project.Budget >= 0 && project.Budgettag != 1 {
  1814. pInfo.Budget = project.Budget
  1815. set["budget"] = project.Budget
  1816. set["budgettag"] = 0
  1817. }
  1818. if project.Bidamount >= 0 && project.Bidamounttag != 1 {
  1819. pInfo.Bidamount = project.Bidamount
  1820. set["bidamount"] = pInfo.Bidamount
  1821. set["bidamounttag"] = 0
  1822. }
  1823. if pInfo.Bidamount > 0 {
  1824. set["sortprice"] = pInfo.Bidamount
  1825. } else {
  1826. if pInfo.Budget > 0 {
  1827. set["sortprice"] = pInfo.Budget
  1828. }
  1829. }
  1830. infofield := InfoField{
  1831. Budget: thisinfo.Budget,
  1832. Bidamount: thisinfo.Bidamount,
  1833. ContractCode: thisinfo.ContractCode,
  1834. ProjectName: thisinfo.ProjectName,
  1835. ProjectCode: thisinfo.ProjectCode,
  1836. Bidstatus: bs,
  1837. }
  1838. tmpMap := set["infofield"].(map[string]interface{})
  1839. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1840. set["infofield"] = tmpMap
  1841. copyMap := Copy(project.InfoFiled).(map[string]InfoField)
  1842. copyMap[thisinfo.Id] = infofield
  1843. project.InfoFiled = copyMap
  1844. set["mpn"] = pInfo.MPN
  1845. set["mpc"] = pInfo.MPC
  1846. }