update.go 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. package main
  2. import (
  3. "encoding/json"
  4. "github.com/go-xweb/log"
  5. "github.com/goinggo/mapstructure"
  6. "go.mongodb.org/mongo-driver/bson"
  7. "go.mongodb.org/mongo-driver/bson/primitive"
  8. "math"
  9. mu "mfw/util"
  10. "mongodb"
  11. qu "qfw/util"
  12. "reflect"
  13. "sort"
  14. "strings"
  15. "time"
  16. )
  17. /**
  18. 直接修改保存项目字段信息
  19. */
  20. func (p *ProjectTask) modifyUpdate(pid string, index, position int, tmpPro, modifyProMap map[string]interface{}) {
  21. // 1-0 备份
  22. tmpPro["reason"] = "直接在原有项目上修改字段信息"
  23. backupPro(tmpPro)
  24. delete(tmpPro, "reason")
  25. // 1-1 修改字段信息
  26. updateSet := UpdateValue(tmpPro, index, position, modifyProMap)
  27. updateSet["list"] = tmpPro["list"]
  28. // 1-2 修改mgo
  29. bol := MongoTool.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": updateSet})
  30. if bol {
  31. // 1-3 修改es
  32. by, _ := json.Marshal(map[string]interface{}{
  33. "query": map[string]interface{}{
  34. "_id": bson.M{
  35. "$gte": pid,
  36. "$lte": pid,
  37. }},
  38. "stype": "project",
  39. })
  40. qu.Debug(string(by))
  41. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  42. }
  43. // 修改内存
  44. p.modifyMem(tmpPro)
  45. }
  46. func (p *ProjectTask) mergeAndModify(pInfoId string, index, position int, tmp map[string]interface{}, tmpPro map[string]interface{}, modifyMap map[string]interface{}) {
  47. proList := []interface{}(tmpPro["list"].(primitive.A))
  48. info := ParseInfo(tmp)
  49. //项目中list大小等于1
  50. if len(proList) == 1 {
  51. log.Println("list大小等于1 合并", "------1------")
  52. // 2.1 重新合并
  53. merge := p.ReMerge(info, tmp, tmpPro)
  54. if merge {
  55. //合并到新项目中
  56. //删除老项目
  57. p.AllIdsMapLock.Lock()
  58. delete(p.AllIdsMap, pInfoId)
  59. p.AllIdsMapLock.Unlock()
  60. delOldPro(pInfoId)
  61. // 2.2 备份
  62. tmpPro["reason"] = "删除原有项目,修改合并到新的项目中"
  63. backupPro(tmpPro)
  64. } else {
  65. //没有合并到新项目中
  66. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  67. // 修改内存
  68. p.modifyMem(tmpPro)
  69. }
  70. }else if index == 0 {
  71. // 招标公告信息在原有项目中位于第1个
  72. merge := p.ReMerge(info, tmp, tmpPro)
  73. if merge {
  74. // 合并到新项目中
  75. // 该条招标公告信息重新参与合并,该项目的其它招标公告信息逐条参与合并
  76. tmpPro["reason"] = "修改list中第一个条招标公告信息"
  77. backupPro(tmpPro)
  78. delete(tmpPro, "reason")
  79. proList = deleteSlice1(proList, proList[0])
  80. p.AllIdsMapLock.Lock()
  81. Id := p.AllIdsMap[pInfoId]
  82. p.AllIdsMapLock.Unlock()
  83. proMem := Id.P
  84. flag := true // 标记是否需要删除原有项目信息
  85. for _, v := range proList{
  86. v1 := v.(map[string]interface{})
  87. temp := MongoTool.FindById(ExtractColl, qu.ObjToString(v1["infoid"]))
  88. if len(temp) == 0 {
  89. temp = MongoTool.FindById(ExtractColl1, qu.ObjToString(v1["infoid"]))
  90. if len(temp) == 0 {
  91. qu.Debug("extract not find id...", v1["infoid"])
  92. continue
  93. }
  94. }
  95. tempInfo := ParseInfo(temp)
  96. if flag {
  97. merge := p.ReMerge(tempInfo, temp, tmpPro)
  98. if !merge {
  99. flag = false
  100. break
  101. }
  102. }
  103. }
  104. if flag {
  105. delOldPro(pInfoId)
  106. }else {
  107. //合并到原有项目中, 不用继续重新合并, 原有项目内部合并即可
  108. p.innerMerge(proList, tmpPro)
  109. bol := MongoTool.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
  110. if bol {
  111. by, _ := json.Marshal(map[string]interface{}{
  112. "query": map[string]interface{}{
  113. "_id": bson.M{
  114. "$gte": pInfoId,
  115. "$lte": pInfoId,
  116. }},
  117. "stype": "project",
  118. })
  119. qu.Debug(string(by))
  120. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  121. }
  122. // 修改内存
  123. p.AllIdsMapLock.Lock()
  124. if v, ok := p.AllIdsMap[pInfoId]; ok {
  125. v.P = proMem
  126. }
  127. p.AllIdsMapLock.Unlock()
  128. }
  129. }else {
  130. //没有合并到新项目中,更新list字段,有条件更新项目外围字段
  131. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  132. // 修改内存
  133. p.modifyMem(tmpPro)
  134. }
  135. }else if index == 1 {
  136. // 招标公告信息在原有项目中处于中间某一条
  137. merge := p.ReMerge(info, tmp, tmpPro)
  138. if merge {
  139. tmpPro["reason"] = "修改list中位于中间某一条招标公告信息"
  140. backupPro(tmpPro)
  141. delete(tmpPro, "reason")
  142. p.innerMerge1(proList, qu.ObjToString(tmp["infoid"]), tmpPro)
  143. bol := MongoTool.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
  144. if bol {
  145. by, _ := json.Marshal(map[string]interface{}{
  146. "query": map[string]interface{}{
  147. "_id": bson.M{
  148. "$gte": pInfoId,
  149. "$lte": pInfoId,
  150. }},
  151. "stype": "project",
  152. })
  153. qu.Debug(string(by))
  154. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  155. }
  156. }else {
  157. // 未合并到新项目中
  158. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  159. // 修改内存
  160. p.modifyMem(tmpPro)
  161. }
  162. }else if index == 2 {
  163. // 招标公告信息在原有项目中位于最后一条
  164. merge := p.ReMerge(info, tmp, tmpPro)
  165. if merge {
  166. // 合并到新项目中
  167. tmpPro["reason"] = "修改list中最后一条招标公告信息"
  168. backupPro(tmpPro)
  169. w := len(proList) - 1
  170. proList = deleteSlice1(proList, proList[w])
  171. p.innerMerge(proList, tmpPro)
  172. bol := MongoTool.UpdateById(ProjectColl, pInfoId, map[string]interface{}{"$set": tmpPro})
  173. if bol {
  174. by, _ := json.Marshal(map[string]interface{}{
  175. "query": map[string]interface{}{
  176. "_id": bson.M{
  177. "$gte": pInfoId,
  178. "$lte": pInfoId,
  179. }},
  180. "stype": "project",
  181. })
  182. qu.Debug(string(by))
  183. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  184. }
  185. }else {
  186. // 未合并到新项目中
  187. p.modifyUpdate(pInfoId, index, position, tmpPro, modifyMap)
  188. // 修改内存
  189. p.modifyMem(tmpPro)
  190. }
  191. }
  192. }
  193. // 删除
  194. func (p *ProjectTask) delJudge(infoid, pid string) {
  195. tmpPro := MongoTool.FindById(ProjectColl, pid)
  196. ids := []interface{}(tmpPro["ids"].(primitive.A))
  197. proList := []interface{}(tmpPro["list"].(primitive.A))
  198. if len(ids) == 1 {
  199. tmpPro["reason"] = "删除项目信息"
  200. backupPro(tmpPro)
  201. c := MongoTool.Delete(ProjectColl, pid)
  202. if c > 0 {
  203. client := Es.GetEsConn()
  204. defer Es.DestoryEsConn(client)
  205. Es.DelById(Itype, Index, pid)
  206. }
  207. return
  208. }
  209. var index = -1 //0:第一个,1:中间,2:最后一个
  210. for i, v := range ids {
  211. if qu.ObjToString(v) == infoid {
  212. if i == 0 {
  213. index = 0
  214. }else if i == len(ids) - 1 {
  215. index = 2
  216. }else {
  217. index = 1
  218. }
  219. }
  220. }
  221. if index == 0 {
  222. tmpPro["reason"] = "删除list中第一个条招标公告信息"
  223. backupPro(tmpPro)
  224. delete(tmpPro, "reason")
  225. proList = deleteSlice1(proList, proList[0])
  226. var pro *ProjectInfo
  227. flag := true // 标记是否需要删除原有项目信息
  228. for _, v := range proList{
  229. v1 := v.(map[string]interface{})
  230. temp := MongoTool.FindById(ExtractColl, qu.ObjToString(v1["infoid"]))
  231. if len(temp) == 0 {
  232. temp = MongoTool.FindById(ExtractColl1, qu.ObjToString(v1["infoid"]))
  233. if len(temp) == 0 {
  234. qu.Debug("extract not find id...", v1["infoid"])
  235. continue
  236. }
  237. }
  238. tempInfo := ParseInfo(temp)
  239. if flag {
  240. merge := p.ReMerge(tempInfo, temp, tmpPro)
  241. if !merge {
  242. flag = false
  243. break
  244. }
  245. }
  246. }
  247. if flag {
  248. delOldPro(pid)
  249. }else {
  250. tmpPro, pro = p.innerMerge(proList, tmpPro)
  251. bol := MongoTool.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
  252. if bol {
  253. by, _ := json.Marshal(map[string]interface{}{
  254. "query": map[string]interface{}{
  255. "_id": bson.M{
  256. "$gte": pid,
  257. "$lte": pid,
  258. }},
  259. "stype": "project",
  260. })
  261. qu.Debug(string(by))
  262. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  263. }
  264. // 修改内存
  265. p.AllIdsMapLock.Lock()
  266. if v, ok := p.AllIdsMap[pid]; ok {
  267. v.P = pro
  268. }
  269. p.AllIdsMapLock.Unlock()
  270. }
  271. }else if index == 1 {
  272. tmpPro["reason"] = "删除list中间某一条招标公告信息"
  273. backupPro(tmpPro)
  274. delete(tmpPro, "reason")
  275. var pro *ProjectInfo
  276. tmpPro, pro = p.innerMerge1(proList, infoid, tmpPro)
  277. bol := MongoTool.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
  278. if bol {
  279. by, _ := json.Marshal(map[string]interface{}{
  280. "query": map[string]interface{}{
  281. "_id": bson.M{
  282. "$gte": pid,
  283. "$lte": pid,
  284. }},
  285. "stype": "project",
  286. })
  287. qu.Debug(string(by))
  288. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  289. }
  290. // 内存
  291. p.AllIdsMapLock.Lock()
  292. if v, ok := p.AllIdsMap[pid]; ok {
  293. v.P = pro
  294. }
  295. p.AllIdsMapLock.Unlock()
  296. }else if index == 2 {
  297. tmpPro["reason"] = "删除list中最后一条招标公告信息"
  298. backupPro(tmpPro)
  299. delete(tmpPro, "reason")
  300. w := len(proList) - 1
  301. proList = deleteSlice1(proList, proList[w])
  302. var pro *ProjectInfo
  303. tmpPro, pro = p.innerMerge(proList, tmpPro)
  304. bol := MongoTool.UpdateById(ProjectColl, pid, map[string]interface{}{"$set": tmpPro})
  305. if bol {
  306. by, _ := json.Marshal(map[string]interface{}{
  307. "query": map[string]interface{}{
  308. "_id": bson.M{
  309. "$gte": pid,
  310. "$lte": pid,
  311. }},
  312. "stype": "project",
  313. })
  314. qu.Debug(string(by))
  315. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  316. }
  317. // 内存
  318. p.AllIdsMapLock.Lock()
  319. if v, ok := p.AllIdsMap[pid]; ok {
  320. v.P = pro
  321. }
  322. p.AllIdsMapLock.Unlock()
  323. }
  324. }
  325. // 合并
  326. func (p *ProjectTask) ReMerge(info *Info, tmp map[string]interface{}, tmpPro map[string]interface{}) bool {
  327. bpn, bpc, bptc, bpb, pids, _, IDArr := p.getCompareIds(info.ProjectName, info.ProjectCode, info.PTC, info.Buyer)
  328. defer p.wg.Done()
  329. for _, m := range pids {
  330. defer m.Lock.Unlock()
  331. }
  332. for _, id := range IDArr {
  333. defer id.Lock.Unlock()
  334. }
  335. bFindProject := false
  336. findPid := ""
  337. comRes1 := []*ProjectInfo{}
  338. comRes2 := []*ProjectInfo{}
  339. comRes3 := []*ProjectInfo{}
  340. for _, v := range IDArr {
  341. comStr := ""
  342. compareProject := v.P
  343. compareProject.score = 0
  344. diffTime := int64(math.Abs(float64(info.Publishtime - compareProject.LastTime)))
  345. if diffTime <= p.validTime {
  346. if CheckContain(compareProject.Agency, info.Agency) == 3 {
  347. continue
  348. }
  349. if ComparePlace(compareProject, info) {
  350. continue
  351. }
  352. info.PNBH = 0
  353. info.PCBH = 0
  354. info.PTCBH = 0
  355. compareStr, score := comparePNC(info, compareProject)
  356. resVal, pjVal := Select(compareStr, info, compareProject)
  357. if resVal > 0 {
  358. compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount, score2 := p.compareBCTABB(info, compareProject, diffTime, score)
  359. comStr = compareStr + compareBuyer + compareCity + compareTime + compareAgency + compareBudget + compareBidmount
  360. compareProject.comStr = comStr
  361. compareProject.pjVal = pjVal
  362. compareProject.resVal = resVal
  363. eqV := compareResult(resVal, pjVal, score2, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount)
  364. if eqV == 1 {
  365. comRes1 = append(comRes1, compareProject)
  366. } else if eqV == 2 {
  367. comRes2 = append(comRes2, compareProject)
  368. } else if eqV == 3 {
  369. comRes3 = append(comRes3, compareProject)
  370. }
  371. }
  372. }
  373. }
  374. //--------------------------------对比完成-----------------------
  375. for kv, resN := range [][]*ProjectInfo{comRes1, comRes2, comRes3} {
  376. if len(resN) > 0 {
  377. if len(resN) > 1 {
  378. sort.Slice(resN, func(i, j int) bool {
  379. return resN[i].score > resN[j].score
  380. })
  381. }
  382. ex := 0
  383. resArr := []*ProjectInfo{}
  384. for i, res := range resN {
  385. choose, e := p.CompareStatus(resN[i], info)
  386. if !choose {
  387. ex = e
  388. resArr = append(resArr, res)
  389. }
  390. }
  391. if len(resArr) > 0 {
  392. bFindProject = true
  393. findPid = resArr[0].Id.Hex()
  394. if findPid == mongodb.BsonIdToSId(tmpPro["_id"]) {
  395. return false
  396. }
  397. p.updateProFiled(tmp, info, resArr[0], kv+1, resArr[0].comStr, ex)
  398. for k2, bv := range []int{bpn, bpc, bptc, bpb} {
  399. if bv > -1 {
  400. pids[bv].Arr = append(pids[bv].Arr, findPid)
  401. if k2 == 0 {
  402. if resArr[0].ProjectName == "" {
  403. resArr[0].ProjectName = info.ProjectName
  404. } else {
  405. if resArr[0].MPN == nil {
  406. resArr[0].MPN = []string{info.ProjectName}
  407. } else {
  408. resArr[0].MPN = append(resArr[0].MPN, info.ProjectName)
  409. }
  410. }
  411. } else if k2 < 3 {
  412. if resArr[0].ProjectCode == "" {
  413. resArr[0].ProjectCode = qu.If(k2 == 1, info.ProjectCode, info.PTC).(string)
  414. } else {
  415. if resArr[0].MPC == nil {
  416. resArr[0].MPC = []string{qu.If(k2 == 1, info.ProjectCode, info.PTC).(string)}
  417. } else {
  418. resArr[0].MPC = append(resArr[0].MPC, qu.If(k2 == 1, info.ProjectCode, info.PTC).(string))
  419. }
  420. }
  421. } else {
  422. if resArr[0].Buyer == "" {
  423. resArr[0].Buyer = info.Buyer
  424. }
  425. }
  426. }
  427. }
  428. } else {
  429. bFindProject = false
  430. findPid = ""
  431. }
  432. break
  433. }
  434. }
  435. if !bFindProject {
  436. id, p1 := p.NewProject(tmp, info)
  437. p.AllIdsMapLock.Lock()
  438. p.AllIdsMap[id] = &ID{Id: id, P: p1}
  439. p.AllIdsMapLock.Unlock()
  440. for _, m := range pids {
  441. m.Arr = append(m.Arr, id)
  442. }
  443. return false
  444. }
  445. return true
  446. }
  447. //内部合并
  448. func (p *ProjectTask) innerMerge(infoList []interface{}, tmpPro map[string]interface{}) (map[string]interface{}, *ProjectInfo) {
  449. newP := make(map[string]interface{})
  450. newP["_id"] = tmpPro["_id"]
  451. var p1 *ProjectInfo
  452. for k, m := range infoList{
  453. m1 := m.(map[string]interface{})
  454. temp := MongoTool.FindById(ExtractColl, qu.ObjToString(m1["infoid"]))
  455. if len(temp) == 0 {
  456. temp = MongoTool.FindById(ExtractColl1, qu.ObjToString(m1["infoid"]))
  457. if len(temp) == 0 {
  458. qu.Debug("extract not find id...", m1["infoid"])
  459. continue
  460. }
  461. }
  462. tempInfo := ParseInfo(temp)
  463. if k == 0 {
  464. p1 = p.newPro(temp, newP, tempInfo)
  465. }else {
  466. p.updateOldProField(p1, tempInfo, newP, temp, m1)
  467. }
  468. }
  469. return newP, p1
  470. }
  471. func (p *ProjectTask) innerMerge1(infoList []interface{}, infoid string, tmpPro map[string]interface{}) (map[string]interface{}, *ProjectInfo) {
  472. newP := make(map[string]interface{})
  473. newP["_id"] = tmpPro["_id"]
  474. var p1 *ProjectInfo
  475. for k, m := range infoList{
  476. m1 := m.(map[string]interface{})
  477. if m1["infoid"] == infoid {
  478. continue
  479. }
  480. temp := MongoTool.FindById(ExtractColl, qu.ObjToString(m1["infoid"]))
  481. if len(temp) == 0 {
  482. temp = MongoTool.FindById(ExtractColl1, qu.ObjToString(m1["infoid"]))
  483. if len(temp) == 0 {
  484. qu.Debug("extract not find id...", m1["infoid"])
  485. continue
  486. }
  487. }
  488. tempInfo := ParseInfo(temp)
  489. if k == 0 {
  490. p1 = p.newPro(temp, newP, tempInfo)
  491. }else {
  492. p.updateOldProField(p1, tempInfo, newP, temp, m1)
  493. }
  494. }
  495. return newP, p1
  496. }
  497. // 更新招标公告到新的项目中
  498. func (p *ProjectTask) updateProFiled(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectInfo, weight int, comStr string, ex int) {
  499. set := map[string]interface{}{}
  500. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  501. if len(pInfo.Ids) > 30 {
  502. //异常标记
  503. set["listtag"] = 1
  504. }
  505. if thisinfo.Publishtime > pInfo.LastTime {
  506. pInfo.LastTime = thisinfo.Publishtime
  507. set["lasttime"] = thisinfo.Publishtime
  508. }
  509. if thisinfo.TopType == "招标" {
  510. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && pInfo.Zbtime <= 0 {
  511. set["zbtime"] = tmp["publishtime"]
  512. }
  513. } else if thisinfo.TopType == "结果" {
  514. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  515. if pInfo.Jgtime > 0 {
  516. jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  517. //公告状态和项目状态同样都是中标或者成交,
  518. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  519. if jg1 > p.jgTime {
  520. set["jgtime"] = tmp["publishtime"]
  521. pInfo.Jgtime = thisinfo.Publishtime
  522. }
  523. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  524. //公告状态和项目状态同样是流标或者废标
  525. if jg1 > p.jgTime {
  526. set["jgtime"] = tmp["publishtime"]
  527. pInfo.Jgtime = thisinfo.Publishtime
  528. }
  529. }
  530. } else {
  531. set["jgtime"] = tmp["publishtime"]
  532. pInfo.Jgtime = thisinfo.Publishtime
  533. }
  534. }
  535. } else if thisinfo.SubType == "合同" {
  536. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  537. //中标、成交不更新jgtime
  538. } else {
  539. set["jgtime"] = tmp["publishtime"]
  540. pInfo.Jgtime = thisinfo.Publishtime
  541. }
  542. }
  543. if thisinfo.Bidopentime > pInfo.Bidopentime {
  544. pInfo.Bidopentime = thisinfo.Bidopentime
  545. set["bidopentime"] = pInfo.Bidopentime
  546. }
  547. // bidtype、bidstatus
  548. pInfo.Bidtype, pInfo.Bidstatus = GetBidTypeAndBidStatus(thisinfo)
  549. set["bidtype"] = pInfo.Bidtype
  550. set["bidstatus"] = pInfo.Bidstatus
  551. //异常标记
  552. if ex > 0 {
  553. set["exception"] = ex
  554. }
  555. //相同城市的公告才会合并到一起(全国列外)
  556. if thisinfo.Area != "全国" {
  557. pInfo.Area = thisinfo.Area
  558. set["area"] = thisinfo.Area
  559. pInfo.City = thisinfo.City
  560. set["city"] = thisinfo.City
  561. if thisinfo.District != "" {
  562. pInfo.District = thisinfo.District
  563. set["district"] = thisinfo.District
  564. }
  565. }
  566. // 项目名称
  567. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  568. pInfo.ProjectName = thisinfo.ProjectName
  569. set["projectname"] = thisinfo.ProjectName
  570. }
  571. // 项目编号
  572. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  573. pInfo.ProjectCode = thisinfo.ProjectCode
  574. set["projectcode"] = thisinfo.ProjectCode
  575. }
  576. // 采购单位
  577. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  578. pInfo.Buyer = thisinfo.Buyer
  579. set["buyer"] = thisinfo.Buyer
  580. pInfo.Buyerclass = thisinfo.Buyerclass
  581. set["buyerclass"] = thisinfo.Buyerclass
  582. }
  583. if pInfo.Buyer == "" {
  584. set["buyerclass"] = ""
  585. }
  586. // 采购单位联系人
  587. if thisinfo.Buyerperson != "" {
  588. pInfo.Buyerperson = thisinfo.Buyerperson
  589. set["buyerperson"] = pInfo.Buyerperson
  590. } else {
  591. pInfo.Buyerperson = ""
  592. set["buyerperson"] = ""
  593. }
  594. // 采购单位電話
  595. if thisinfo.Buyertel != "" {
  596. pInfo.Buyertel = thisinfo.Buyertel
  597. set["buyertel"] = pInfo.Buyertel
  598. } else {
  599. pInfo.Buyertel = ""
  600. set["buyertel"] = ""
  601. }
  602. if thisinfo.ContractCode != "" {
  603. set["contractcode"] = pInfo.ContractCode + "," + thisinfo.ContractCode
  604. }
  605. // 代理机构 相同的代理机构才会合并到一个项目 2020.11.9
  606. //if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  607. // pInfo.Agency = thisinfo.Agency
  608. // set["agency"] = thisinfo.Agency
  609. //}
  610. if len(thisinfo.Topscopeclass) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  611. sort.Strings(pInfo.Topscopeclass)
  612. for _, k := range thisinfo.Topscopeclass {
  613. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  614. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  615. sort.Strings(pInfo.Topscopeclass)
  616. }
  617. }
  618. set["topscopeclass"] = pInfo.Topscopeclass
  619. }
  620. // 项目评审专家
  621. if len(thisinfo.ReviewExperts) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  622. set["review_experts"] = thisinfo.ReviewExperts
  623. pInfo.ReviewExperts = thisinfo.ReviewExperts
  624. }
  625. if thisinfo.Purchasing != "" && thisinfo.Publishtime > pInfo.LastTime {
  626. if pInfo.Purchasing == "" {
  627. pInfo.Purchasing = thisinfo.Purchasing
  628. set["purchasing"] = thisinfo.Purchasing
  629. } else {
  630. list := strings.Split(pInfo.Purchasing, ",")
  631. for _, k := range list {
  632. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  633. list = append(list, k)
  634. sort.Strings(list)
  635. }
  636. }
  637. set["purchasing"] = strings.Join(list, ",")
  638. }
  639. }
  640. //中标候选人
  641. if len(thisinfo.WinnerOrder) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  642. var list = []string{}
  643. for _, v := range thisinfo.WinnerOrder {
  644. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  645. list = append(list, qu.ObjToString(v["entname"]))
  646. }
  647. }
  648. set["winnerorder"] = list
  649. pInfo.Winnerorder = list
  650. }
  651. if len(thisinfo.Subscopeclass) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  652. sort.Strings(pInfo.Subscopeclass)
  653. for _, k := range thisinfo.Subscopeclass {
  654. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  655. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  656. sort.Strings(pInfo.Subscopeclass)
  657. }
  658. }
  659. set["subscopeclass"] = pInfo.Subscopeclass
  660. set["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  661. }
  662. if len(thisinfo.Winners) > 0 && thisinfo.Publishtime > pInfo.LastTime {
  663. if len(pInfo.Winners) <= 0 {
  664. set["winner"] = qu.ObjToString(tmp["winner"])
  665. }
  666. sort.Strings(pInfo.Winners)
  667. for _, k := range thisinfo.Winners {
  668. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  669. if BinarySearch(pInfo.Winners, k) != -1 {
  670. deleteSlice(pInfo.Winners, k, "")
  671. sort.Strings(pInfo.Winners)
  672. }
  673. } else {
  674. if BinarySearch(pInfo.Winners, k) == -1 {
  675. pInfo.Winners = append(pInfo.Winners, k)
  676. sort.Strings(pInfo.Winners)
  677. }
  678. }
  679. }
  680. set["s_winner"] = strings.Join(pInfo.Winners, ",")
  681. }
  682. if thisinfo.HasPackage { //多包处理
  683. set["multipackage"] = 1
  684. pkg := PackageFormat(thisinfo, pInfo)
  685. pInfo.Package = pkg
  686. set["package"] = pInfo.Package
  687. }
  688. //处理多包后,计算预算金额、中标金额
  689. CountAmount(pInfo, thisinfo, tmp)
  690. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  691. set["budget"] = pInfo.Budget
  692. set["budgettag"] = 0
  693. }
  694. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  695. set["bidamount"] = pInfo.Bidamount
  696. set["bidamounttag"] = 0
  697. }
  698. if pInfo.Bidamount >= pInfo.Budget {
  699. set["sortprice"] = pInfo.Bidamount
  700. } else if pInfo.Budget >= pInfo.Bidamount {
  701. set["sortprice"] = pInfo.Budget
  702. }
  703. infofield := InfoField{
  704. Budget: thisinfo.Budget,
  705. Bidamount: thisinfo.Bidamount,
  706. ContractCode: thisinfo.ContractCode,
  707. ProjectName: thisinfo.ProjectName,
  708. ProjectCode: thisinfo.ProjectCode,
  709. Bidstatus: pInfo.Bidstatus,
  710. }
  711. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  712. copyMap[thisinfo.Id] = infofield
  713. tmpMap := make(map[string]interface{})
  714. for k, v := range copyMap {
  715. tmpMap[k] = StructToMap(v)
  716. }
  717. tmpMap[thisinfo.Id] = StructToMap(infofield)
  718. pInfo.InfoFiled = copyMap
  719. set["infofield"] = tmpMap
  720. set["mpn"] = pInfo.MPN
  721. set["mpc"] = pInfo.MPC
  722. set["updatetime"] = p.pici
  723. update := map[string]interface{}{}
  724. if len(set) > 0 {
  725. update["$set"] = set
  726. }
  727. push := p.PushListInfo(tmp, thisinfo.Id)
  728. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  729. push["compareStr"] = comStr
  730. push["resVal"] = pInfo.resVal
  731. push["pjVal"] = pInfo.pjVal
  732. update["$push"] = map[string]interface{}{
  733. "list": push,
  734. "ids": thisinfo.Id,
  735. }
  736. bol := MongoTool.UpdateById(ProjectColl, pInfo.Id.Hex(), update)
  737. if bol {
  738. by, _ := json.Marshal(map[string]interface{}{
  739. "query": map[string]interface{}{
  740. "_id": bson.M{
  741. "$gte": pInfo.Id.Hex(),
  742. "$lte": pInfo.Id.Hex(),
  743. }},
  744. "stype": "project",
  745. })
  746. qu.Debug(string(by))
  747. _ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
  748. }
  749. }
  750. // 内部合并时,原有项目id基础上新建项目
  751. func (p *ProjectTask) newPro(tmp, tmpPro map[string]interface{}, thisinfo *Info) *ProjectInfo {
  752. for _, f := range FIELDS {
  753. if tmp[f] != nil && tmp[f] != "" {
  754. tmpPro[f] = tmp[f]
  755. }
  756. }
  757. bidopentime := qu.Int64All(tmp["bidopentime"])
  758. if bidopentime > 0 {
  759. tmpPro["bidopentime"] = bidopentime
  760. }
  761. //异常标记
  762. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  763. tmpPro["exception"] = 1
  764. }
  765. //projecthref保存
  766. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  767. if jsonData != nil && qu.ObjToString(jsonData["projecthref"]) != "" {
  768. tmpPro["projecthref"] = jsonData["projecthref"]
  769. }
  770. }
  771. //合同编号
  772. if thisinfo.ContractCode != "" {
  773. tmpPro["contractcode"] = thisinfo.ContractCode
  774. }
  775. bs, bt := GetBidTypeAndBidStatus(thisinfo)
  776. tmpPro["bidtype"] = bs
  777. tmpPro["bidstatus"] = bt
  778. pkg := PackageFormat(thisinfo, nil)
  779. p1 := p.NewCachePinfo(tmpPro["_id"].(primitive.ObjectID), thisinfo, bs, bt, pkg)
  780. now := time.Now().Unix()
  781. tmpPro["createtime"] = now
  782. tmpPro["sourceinfoid"] = thisinfo.Id
  783. tmpPro["sourceinfourl"] = tmp["href"]
  784. tmpPro["firsttime"] = tmp["publishtime"]
  785. tmpPro["lasttime"] = tmp["publishtime"]
  786. tmpPro["pici"] = tmp["comeintime"]
  787. tmpPro["ids"] = []string{thisinfo.Id}
  788. if thisinfo.TopType == "招标" {
  789. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  790. tmpPro["zbtime"] = tmp["publishtime"]
  791. p1.Zbtime = qu.Int64All(tmp["publishtime"])
  792. }
  793. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  794. tmpPro["jgtime"] = tmp["publishtime"]
  795. p1.Jgtime = thisinfo.Publishtime
  796. }
  797. if len(thisinfo.Subscopeclass) > 0 {
  798. tmpPro["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  799. }
  800. if len(thisinfo.Winners) > 0 {
  801. tmpPro["s_winner"] = strings.Join(thisinfo.Winners, ",")
  802. p1.Winners = thisinfo.Winners
  803. }
  804. if thisinfo.HasPackage {
  805. tmpPro["multipackage"] = 1
  806. tmpPro["package"] = pkg
  807. } else {
  808. tmpPro["multipackage"] = 0
  809. }
  810. //项目评审专家
  811. if len(thisinfo.ReviewExperts) > 0 {
  812. tmpPro["review_experts"] = thisinfo.ReviewExperts
  813. p1.ReviewExperts = thisinfo.ReviewExperts
  814. }
  815. //标的物
  816. if thisinfo.Purchasing != "" {
  817. tmpPro["purchasing"] = thisinfo.Purchasing
  818. p1.Purchasing = thisinfo.Purchasing
  819. }
  820. //中标候选人
  821. if len(thisinfo.WinnerOrder) > 0 {
  822. var list = []string{}
  823. for _, v := range thisinfo.WinnerOrder {
  824. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  825. list = append(list, qu.ObjToString(v["entname"]))
  826. }
  827. }
  828. tmpPro["winnerorder"] = list
  829. p1.Winnerorder = list
  830. }
  831. p1.InfoFiled = make(map[string]InfoField)
  832. infofield := InfoField{
  833. Budget: thisinfo.Budget,
  834. Bidamount: thisinfo.Bidamount,
  835. ContractCode: thisinfo.ContractCode,
  836. ProjectName: thisinfo.ProjectName,
  837. ProjectCode: thisinfo.ProjectCode,
  838. Bidstatus: bs,
  839. }
  840. p1.InfoFiled[thisinfo.Id] = infofield
  841. res := StructToMap(infofield)
  842. tmpPro["infofield"] = map[string]interface{}{
  843. thisinfo.Id: res,
  844. }
  845. if tmp["budget"] != nil && tmp["budget"] != "" {
  846. tmpPro["budget"] = thisinfo.Budget
  847. p1.Budgettag = 0
  848. tmpPro["budgettag"] = 0
  849. } else {
  850. p1.Budgettag = 1
  851. tmpPro["budgettag"] = 1
  852. }
  853. if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  854. tmpPro["bidamount"] = thisinfo.Bidamount
  855. p1.Bidamounttag = 0
  856. tmpPro["bidamounttag"] = 0
  857. } else {
  858. p1.Bidamounttag = 1
  859. tmpPro["bidamounttag"] = 1
  860. }
  861. if p1.Bidamount > 0 {
  862. tmpPro["sortprice"] = p1.Bidamount
  863. } else if p1.Budget > 0 {
  864. tmpPro["sortprice"] = p1.Budget
  865. }
  866. push := p.PushListInfo(tmp, thisinfo.Id)
  867. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  868. tmpPro["list"] = []map[string]interface{}{
  869. push,
  870. }
  871. return &p1
  872. }
  873. // 合并字段到老项目中
  874. func (p *ProjectTask) updateOldProField(pInfo *ProjectInfo, thisinfo *Info, tmpPro, tmp, m1 map[string]interface{}) {
  875. if len(pInfo.Ids) > 30 {
  876. //异常标记
  877. tmpPro["listtag"] = 1
  878. }
  879. if thisinfo.Publishtime > pInfo.LastTime {
  880. pInfo.LastTime = thisinfo.Publishtime
  881. tmpPro["lasttime"] = thisinfo.Publishtime
  882. }
  883. if thisinfo.TopType == "招标" {
  884. if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" && pInfo.Zbtime <= 0 {
  885. tmpPro["zbtime"] = tmp["publishtime"]
  886. }
  887. } else if thisinfo.TopType == "结果" {
  888. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  889. if pInfo.Jgtime > 0 {
  890. jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  891. //公告状态和项目状态同样都是中标或者成交,
  892. if (thisinfo.SubType == "中标" || thisinfo.SubType == "成交") && (pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交") {
  893. if jg1 > p.jgTime {
  894. tmpPro["jgtime"] = tmp["publishtime"]
  895. pInfo.Jgtime = thisinfo.Publishtime
  896. }
  897. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (pInfo.Bidstatus == "流标" || pInfo.Bidstatus == "废标") {
  898. //公告状态和项目状态同样是流标或者废标
  899. if jg1 > p.jgTime {
  900. tmpPro["jgtime"] = tmp["publishtime"]
  901. pInfo.Jgtime = thisinfo.Publishtime
  902. }
  903. }
  904. } else {
  905. tmpPro["jgtime"] = tmp["publishtime"]
  906. pInfo.Jgtime = thisinfo.Publishtime
  907. }
  908. }
  909. } else if thisinfo.SubType == "合同" {
  910. if pInfo.Bidstatus == "中标" || pInfo.Bidstatus == "成交" || pInfo.Bidstatus == "" {
  911. //中标、成交不更新jgtime
  912. } else {
  913. tmpPro["jgtime"] = tmp["publishtime"]
  914. pInfo.Jgtime = thisinfo.Publishtime
  915. }
  916. }
  917. if thisinfo.Bidopentime > pInfo.Bidopentime {
  918. pInfo.Bidopentime = thisinfo.Bidopentime
  919. tmpPro["bidopentime"] = pInfo.Bidopentime
  920. }
  921. // bidtype、bidstatus
  922. pInfo.Bidtype, pInfo.Bidstatus = GetBidTypeAndBidStatus(thisinfo)
  923. tmpPro["bidtype"] = pInfo.Bidtype
  924. tmpPro["bidstatus"] = pInfo.Bidstatus
  925. //相同城市的公告才会合并到一起(全国列外)
  926. if thisinfo.Area != "全国" {
  927. pInfo.Area = thisinfo.Area
  928. tmpPro["area"] = thisinfo.Area
  929. pInfo.City = thisinfo.City
  930. tmpPro["city"] = thisinfo.City
  931. if thisinfo.District != "" {
  932. pInfo.District = thisinfo.District
  933. tmpPro["district"] = thisinfo.District
  934. }
  935. }
  936. // 项目名称
  937. if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  938. pInfo.ProjectName = thisinfo.ProjectName
  939. tmpPro["projectname"] = thisinfo.ProjectName
  940. }
  941. // 项目编号
  942. if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  943. pInfo.ProjectCode = thisinfo.ProjectCode
  944. tmpPro["projectcode"] = thisinfo.ProjectCode
  945. }
  946. // 采购单位
  947. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  948. pInfo.Buyer = thisinfo.Buyer
  949. tmpPro["buyer"] = thisinfo.Buyer
  950. pInfo.Buyerclass = thisinfo.Buyerclass
  951. tmpPro["buyerclass"] = thisinfo.Buyerclass
  952. }
  953. if pInfo.Buyer == "" {
  954. tmpPro["buyerclass"] = ""
  955. }
  956. // 采购单位联系人
  957. if thisinfo.Buyerperson != "" {
  958. pInfo.Buyerperson = thisinfo.Buyerperson
  959. tmpPro["buyerperson"] = pInfo.Buyerperson
  960. } else {
  961. pInfo.Buyerperson = ""
  962. tmpPro["buyerperson"] = ""
  963. }
  964. // 采购单位電話
  965. if thisinfo.Buyertel != "" {
  966. pInfo.Buyertel = thisinfo.Buyertel
  967. tmpPro["buyertel"] = pInfo.Buyertel
  968. } else {
  969. pInfo.Buyertel = ""
  970. tmpPro["buyertel"] = ""
  971. }
  972. if thisinfo.ContractCode != "" {
  973. tmpPro["contractcode"] = pInfo.ContractCode + "," + thisinfo.ContractCode
  974. }
  975. // 代理机构 相同的代理机构才会合并到一个项目 2020.11.9
  976. //if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  977. // pInfo.Agency = thisinfo.Agency
  978. // set["agency"] = thisinfo.Agency
  979. //}
  980. if len(thisinfo.Topscopeclass) > 0 {
  981. sort.Strings(pInfo.Topscopeclass)
  982. for _, k := range thisinfo.Topscopeclass {
  983. if BinarySearch(pInfo.Topscopeclass, k) == -1 {
  984. pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
  985. sort.Strings(pInfo.Topscopeclass)
  986. }
  987. }
  988. tmpPro["topscopeclass"] = pInfo.Topscopeclass
  989. }
  990. // 项目评审专家
  991. if len(thisinfo.ReviewExperts) > 0 {
  992. tmpPro["review_experts"] = thisinfo.ReviewExperts
  993. pInfo.ReviewExperts = thisinfo.ReviewExperts
  994. }
  995. if thisinfo.Purchasing != "" {
  996. if pInfo.Purchasing == "" {
  997. pInfo.Purchasing = thisinfo.Purchasing
  998. tmpPro["purchasing"] = thisinfo.Purchasing
  999. } else {
  1000. list := strings.Split(pInfo.Purchasing, ",")
  1001. for _, k := range list {
  1002. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  1003. list = append(list, k)
  1004. sort.Strings(list)
  1005. }
  1006. }
  1007. tmpPro["purchasing"] = strings.Join(list, ",")
  1008. }
  1009. }
  1010. //中标候选人
  1011. if len(thisinfo.WinnerOrder) > 0 {
  1012. var list = []string{}
  1013. for _, v := range thisinfo.WinnerOrder {
  1014. if BinarySearch(list, qu.ObjToString(v["entname"])) == -1 {
  1015. list = append(list, qu.ObjToString(v["entname"]))
  1016. }
  1017. }
  1018. tmpPro["winnerorder"] = list
  1019. pInfo.Winnerorder = list
  1020. }
  1021. if len(thisinfo.Subscopeclass) > 0 {
  1022. sort.Strings(pInfo.Subscopeclass)
  1023. for _, k := range thisinfo.Subscopeclass {
  1024. if BinarySearch(pInfo.Subscopeclass, k) == -1 {
  1025. pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
  1026. sort.Strings(pInfo.Subscopeclass)
  1027. }
  1028. }
  1029. tmpPro["subscopeclass"] = pInfo.Subscopeclass
  1030. tmpPro["s_subscopeclass"] = strings.Join(pInfo.Subscopeclass, ",")
  1031. }
  1032. if len(thisinfo.Winners) > 0 {
  1033. if len(pInfo.Winners) <= 0 {
  1034. tmpPro["winner"] = qu.ObjToString(tmp["winner"])
  1035. }
  1036. sort.Strings(pInfo.Winners)
  1037. for _, k := range thisinfo.Winners {
  1038. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  1039. if BinarySearch(pInfo.Winners, k) != -1 {
  1040. deleteSlice(pInfo.Winners, k, "")
  1041. sort.Strings(pInfo.Winners)
  1042. }
  1043. } else {
  1044. if BinarySearch(pInfo.Winners, k) == -1 {
  1045. pInfo.Winners = append(pInfo.Winners, k)
  1046. sort.Strings(pInfo.Winners)
  1047. }
  1048. }
  1049. }
  1050. tmpPro["s_winner"] = strings.Join(pInfo.Winners, ",")
  1051. }
  1052. if thisinfo.HasPackage { //多包处理
  1053. tmpPro["multipackage"] = 1
  1054. pkg := PackageFormat(thisinfo, pInfo)
  1055. pInfo.Package = pkg
  1056. tmpPro["package"] = pInfo.Package
  1057. }
  1058. //处理多包后,计算预算金额、中标金额
  1059. CountAmount(pInfo, thisinfo, tmp)
  1060. if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
  1061. tmpPro["budget"] = pInfo.Budget
  1062. tmpPro["budgettag"] = 0
  1063. }
  1064. if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
  1065. tmpPro["bidamount"] = pInfo.Bidamount
  1066. tmpPro["bidamounttag"] = 0
  1067. }
  1068. if pInfo.Bidamount >= pInfo.Budget {
  1069. tmpPro["sortprice"] = pInfo.Bidamount
  1070. } else if pInfo.Budget >= pInfo.Bidamount {
  1071. tmpPro["sortprice"] = pInfo.Budget
  1072. }
  1073. infofield := InfoField{
  1074. Budget: thisinfo.Budget,
  1075. Bidamount: thisinfo.Bidamount,
  1076. ContractCode: thisinfo.ContractCode,
  1077. ProjectName: thisinfo.ProjectName,
  1078. ProjectCode: thisinfo.ProjectCode,
  1079. Bidstatus: pInfo.Bidstatus,
  1080. }
  1081. copyMap := Copy(pInfo.InfoFiled).(map[string]InfoField)
  1082. copyMap[thisinfo.Id] = infofield
  1083. tmpMap := make(map[string]interface{})
  1084. for k, v := range copyMap {
  1085. tmpMap[k] = StructToMap(v)
  1086. }
  1087. tmpMap[thisinfo.Id] = StructToMap(infofield)
  1088. pInfo.InfoFiled = copyMap
  1089. tmpPro["infofield"] = tmpMap
  1090. tmpPro["mpn"] = pInfo.MPN
  1091. tmpPro["mpc"] = pInfo.MPC
  1092. tmpPro["updatetime"] = p.pici
  1093. push := p.PushListInfo(tmp, thisinfo.Id)
  1094. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1095. push["compareStr"] = m1["compareStr"]
  1096. push["resVal"] = m1["resVal"]
  1097. push["pjVal"] = m1["pjVal"]
  1098. list := tmpPro["list"].([]map[string]interface{})
  1099. tmpPro["list"] = append(list, push)
  1100. tmpPro["ids"] = append(tmpPro["ids"].([]string), thisinfo.Id)
  1101. }
  1102. func deleteSlice1(arr []interface{}, v interface{}) []interface{} {
  1103. for k, v1 := range arr {
  1104. if reflect.DeepEqual(v1, v) {
  1105. return append(arr[:k], arr[k+1:]...)
  1106. }
  1107. }
  1108. return arr
  1109. }
  1110. // 修改字段值
  1111. func UpdateValue(proMap map[string]interface{}, index, position int, modifyMap map[string]interface{}) map[string]interface{} {
  1112. updataSet := make(map[string]interface{})
  1113. infoList := []interface{}(proMap["list"].(primitive.A))
  1114. tempMap := infoList[position].(map[string]interface{})
  1115. for k := range modifyMap {
  1116. //项目中lsit大小等于1 或者 修改的招标公告处于项目的list中最后一个
  1117. if len(infoList) == 1 || index == 2 {
  1118. if k == "budget" || k == "bidamount" {
  1119. if proMap["sortprice"] == proMap[k] {
  1120. updataSet["sortprice"] = modifyMap[k]
  1121. }
  1122. updataSet[k] = modifyMap[k]
  1123. proMap[k] = modifyMap[k]
  1124. tempMap[k] = modifyMap[k]
  1125. }else {
  1126. updataSet[k] = modifyMap[k]
  1127. proMap[k] = modifyMap[k]
  1128. tempMap[k] = modifyMap[k]
  1129. }
  1130. } else {
  1131. tempMap[k] = modifyMap[k]
  1132. if k == "budget" || k == "bidamount" {
  1133. if proMap["sortprice"] == proMap[k] {
  1134. proMap["sortprice"] = modifyMap[k]
  1135. }
  1136. updataSet[k] = modifyMap[k]
  1137. proMap[k] = modifyMap[k]
  1138. }
  1139. // 有条件更新项目外围字段值(非空)
  1140. if proMap[k] == nil || qu.ObjToString(k) == "" {
  1141. updataSet[k] = modifyMap[k]
  1142. proMap[k] = modifyMap[k]
  1143. }
  1144. }
  1145. }
  1146. return updataSet
  1147. }
  1148. //备份(快照)
  1149. func backupPro(tmp map[string]interface{}) {
  1150. tmp1 := make(map[string]interface{})
  1151. for k, v := range tmp{
  1152. tmp1[k] = v
  1153. }
  1154. if Sysconfig["backupFlag"].(bool) {
  1155. tmp1["sourceprojectid"] = mongodb.BsonIdToSId(tmp1["_id"])
  1156. delete(tmp1, "_id")
  1157. MongoTool.Save(BackupColl, tmp1)
  1158. }
  1159. }
  1160. // 删除原有项目数据
  1161. func delOldPro(pid string) {
  1162. t := MongoTool.Delete(ProjectColl, pid)
  1163. if t >=0 {
  1164. client := Es.GetEsConn()
  1165. defer Es.DestoryEsConn(client)
  1166. Es.DelById(Index, Itype, pid)
  1167. }
  1168. }
  1169. // 修改内存中的数据
  1170. func (p *ProjectTask) modifyMem(tmpPro map[string]interface{}) {
  1171. pid := qu.ObjToString(tmpPro["_id"])
  1172. var pro ProjectInfo
  1173. err := mapstructure.Decode(tmpPro, &pro)
  1174. if err != nil {
  1175. qu.Debug(err)
  1176. }
  1177. pro.Id = StringTOBsonId(pid)
  1178. tmpMap := make(map[string]InfoField)
  1179. infoMap := tmpPro["infofield"].(map[string]interface{})
  1180. for _, v := range infoMap {
  1181. var field InfoField
  1182. b, _ := json.Marshal(v)
  1183. _ = json.Unmarshal(b, &field)
  1184. tmpMap[pid] = field
  1185. }
  1186. pro.InfoFiled = tmpMap
  1187. p.AllIdsMapLock.Lock()
  1188. if v, ok := p.AllIdsMap[pid]; ok {
  1189. v.P = &pro
  1190. }
  1191. p.AllIdsMapLock.Unlock()
  1192. p.printMemPro(pid)
  1193. }
  1194. // 打印内存中的项目信息
  1195. func (p *ProjectTask) printMemPro(pid string) {
  1196. p.AllIdsMapLock.Lock()
  1197. if v, ok := p.AllIdsMap[pid]; ok {
  1198. qu.Debug("mem pro ----------", *v.P)
  1199. }
  1200. p.AllIdsMapLock.Unlock()
  1201. }