project.go 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538
  1. package main
  2. import (
  3. "encoding/json"
  4. "go.mongodb.org/mongo-driver/bson"
  5. "go.mongodb.org/mongo-driver/bson/primitive"
  6. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  7. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  8. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  9. "jygit.jydev.jianyu360.cn/data_processing/common_utils/redis"
  10. "math"
  11. "sort"
  12. "strings"
  13. "time"
  14. )
  15. /**
  16. 项目合并,对比,计算,合并,生成项目
  17. **/
  18. // 从对应map中获取对比的项目id
  19. func (p *ProjectTask) getCompareIds(pn, pc, ptc, pb string) (bpn, bpc, bptc, bpb int, res []*Key, idArr []string, IDArr []*ID) {
  20. // p.ConCurrentLock(n1, n2, n3, n4)
  21. // defer p.ConCurrentUnLock(n1, n2, n3, n4)
  22. p.wg.Add(1)
  23. //查找到id数组
  24. res = []*Key{}
  25. //是否查找到,并标识位置。-1代表值为空或已经存在。
  26. bpn, bpc, bptc, bpb = -1, -1, -1, -1
  27. if pn != "" {
  28. ids := p.mapPn[pn]
  29. if ids == nil {
  30. ids = &Key{Arr: []string{}}
  31. p.mapPn[pn] = ids
  32. bpn = 0
  33. }
  34. ids.Lock.Lock()
  35. res = append(res, ids)
  36. }
  37. if pc != "" {
  38. ids := p.mapPc[pc]
  39. if ids == nil {
  40. ids = &Key{Arr: []string{}}
  41. p.mapPc[pc] = ids
  42. bpc = len(res)
  43. }
  44. ids.Lock.Lock()
  45. res = append(res, ids)
  46. }
  47. if ptc != "" {
  48. ids := p.mapPc[ptc]
  49. if ids == nil {
  50. ids = &Key{Arr: []string{}}
  51. p.mapPc[ptc] = ids
  52. bptc = len(res)
  53. }
  54. ids.Lock.Lock()
  55. res = append(res, ids)
  56. }
  57. if pb != "" {
  58. ids := p.mapPb[pb]
  59. if ids == nil {
  60. ids = &Key{Arr: []string{}}
  61. p.mapPb[pb] = ids
  62. bpb = len(res)
  63. }
  64. ids.Lock.Lock()
  65. res = append(res, ids)
  66. }
  67. repeatId := map[string]bool{}
  68. idArr = []string{} //项目id
  69. IDArr = []*ID{} //项目信息
  70. for _, m := range res {
  71. for _, id := range m.Arr {
  72. if !repeatId[id] {
  73. repeatId[id] = true
  74. //_, _ = strconv.ParseInt(id[0:8], 16, 64)
  75. p.AllIdsMapLock.Lock()
  76. Id := p.AllIdsMap[id]
  77. p.AllIdsMapLock.Unlock()
  78. if Id != nil {
  79. Id.Lock.Lock()
  80. idArr = append(idArr, id)
  81. IDArr = append(IDArr, Id)
  82. }
  83. }
  84. }
  85. }
  86. return
  87. }
  88. func (p *ProjectTask) startProjectMerge(info *Info, tmp map[string]interface{}) {
  89. p.findLock.Lock()
  90. defer p.findLock.Unlock()
  91. // 3.18 isfow=0数据不参与项目合并 (1表示正常数据招标流程)
  92. code := strings.ReplaceAll(util.ObjToString(tmp["spidercode"]), " ", "")
  93. p.mapSpiderLock.Lock()
  94. defer p.mapSpiderLock.Unlock()
  95. if v, ok := p.mapSpider[code]; ok && (v == 0) {
  96. //qu.Debug("isflow=0 新建项目" + code)
  97. p.NewProject(tmp, info)
  98. return
  99. }
  100. //只有或没有采购单位的无法合并
  101. //bpn, bpc, bptc, bpb 是否查找到,并标识位置。-1代表未查找到。
  102. //pids 是项目id数组集合
  103. //IDArr,是单个项目ID对象集合
  104. bpn, bpc, bptc, bpb, pids, _, IDArr := p.getCompareIds(info.ProjectName, info.ProjectCode, info.PTC, info.Buyer) //, info.LenPN, info.LenPC, info.LenPTC, len([]rune(info.Buyer)))
  105. defer p.wg.Done()
  106. //map--k为pn,ptn,pc,ptc,buyer值 v为Id数组和lock
  107. for _, m := range pids {
  108. defer m.Lock.Unlock()
  109. }
  110. for _, id := range IDArr {
  111. defer id.Lock.Unlock()
  112. }
  113. bFindProject := false
  114. findPid := ""
  115. //获取完id,进行计算
  116. //定义两组
  117. comRes1 := []*ProjectCache{} //优先级最高的对比结果数组
  118. comRes2 := []*ProjectCache{} //优化级其次
  119. comRes3 := []*ProjectCache{}
  120. for _, v := range IDArr {
  121. comStr := ""
  122. compareProject := v.P
  123. compareProject.score = 0
  124. //问题出地LastTime!!!!!
  125. diffTime := int64(math.Abs(float64(info.Publishtime - compareProject.LastTime)))
  126. if diffTime <= p.validTime {
  127. //代理机构完全不相同,直接新建项目
  128. if CheckContain(compareProject.Agency, info.Agency) == 3 {
  129. continue
  130. }
  131. //地区(省、市、区)不同,直接新建项目
  132. if ComparePlace(compareProject, info) {
  133. continue
  134. }
  135. info.PNBH = 0
  136. info.PCBH = 0
  137. info.PTCBH = 0
  138. compareStr, score := comparePNC(info, compareProject)
  139. resVal, pjVal := Select(compareStr, info, compareProject)
  140. //---------------------------------------
  141. if resVal > 0 {
  142. compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount, score2 := p.compareBCTABB(info, compareProject, diffTime, score)
  143. //项目名称、项目编号、标题项目编号、采购单位、省、市、发布时间、代理机构
  144. comStr = compareStr + compareBuyer + compareCity + compareTime + compareAgency + compareBudget + compareBidmount
  145. compareProject.comStr = comStr
  146. compareProject.pjVal = pjVal
  147. compareProject.resVal = resVal
  148. //log.Println(compareProject.comStr)
  149. eqV := compareResult(resVal, pjVal, score2, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount)
  150. if eqV == 1 {
  151. comRes1 = append(comRes1, compareProject)
  152. } else if eqV == 2 {
  153. comRes2 = append(comRes2, compareProject)
  154. } else if eqV == 3 {
  155. comRes3 = append(comRes3, compareProject)
  156. }
  157. }
  158. }
  159. }
  160. //--------------------------------对比完成-----------------------
  161. //更新数组、更新项目
  162. for kv, resN := range [][]*ProjectCache{comRes1, comRes2, comRes3} {
  163. if len(resN) > 0 {
  164. if len(resN) > 1 {
  165. sort.Slice(resN, func(i, j int) bool {
  166. return resN[i].score > resN[j].score
  167. })
  168. }
  169. ex := 0
  170. resArr := []*ProjectCache{}
  171. for _, res := range resN {
  172. //choose, e := p.CompareStatus(resN[i], info)
  173. //if !choose {
  174. // ex = e
  175. resArr = append(resArr, res)
  176. //}
  177. }
  178. if len(resArr) > 0 {
  179. bFindProject = true
  180. findPid = resArr[0].Id.Hex()
  181. p.UpdateProject(tmp, info, resArr[0], kv+1, resArr[0].comStr, ex)
  182. for k2, bv := range []int{bpn, bpc, bptc, bpb} {
  183. if bv > -1 {
  184. pids[bv].Arr = append(pids[bv].Arr, findPid)
  185. if k2 == 0 {
  186. if resArr[0].ProjectName == "" {
  187. resArr[0].ProjectName = info.ProjectName
  188. } else {
  189. if resArr[0].MPN == nil {
  190. resArr[0].MPN = []string{info.ProjectName}
  191. } else {
  192. resArr[0].MPN = append(resArr[0].MPN, info.ProjectName)
  193. }
  194. }
  195. } else if k2 < 3 {
  196. if resArr[0].ProjectCode == "" {
  197. resArr[0].ProjectCode = util.If(k2 == 1, info.ProjectCode, info.PTC).(string)
  198. } else {
  199. if resArr[0].MPC == nil {
  200. resArr[0].MPC = []string{util.If(k2 == 1, info.ProjectCode, info.PTC).(string)}
  201. } else {
  202. resArr[0].MPC = append(resArr[0].MPC, util.If(k2 == 1, info.ProjectCode, info.PTC).(string))
  203. }
  204. }
  205. } else {
  206. if resArr[0].Buyer == "" {
  207. resArr[0].Buyer = info.Buyer
  208. }
  209. }
  210. }
  211. }
  212. } else {
  213. bFindProject = false
  214. findPid = ""
  215. }
  216. break
  217. }
  218. }
  219. if !bFindProject {
  220. //if !IsCreatePro(info) {
  221. // qu.Debug("舍弃数据---", info.Id)
  222. // return
  223. //}
  224. id, p1 := p.NewProject(tmp, info)
  225. p.AllIdsMapLock.Lock()
  226. p.AllIdsMap[id] = &ID{Id: id, P: p1}
  227. p.AllIdsMapLock.Unlock()
  228. for _, m := range pids {
  229. m.Arr = append(m.Arr, id)
  230. }
  231. }
  232. }
  233. func (p *ProjectTask) compareBCTABB(info *Info, cp *ProjectCache, diffTime int64, score int) (compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string, score2 int) {
  234. compareBuyer = "D"
  235. if len([]rune(info.Buyer)) > 3 && len([]rune(cp.Buyer)) > 3 {
  236. v := CheckContain(info.Buyer, cp.Buyer)
  237. if v == 1 {
  238. compareBuyer = "A"
  239. score += 3
  240. } else {
  241. //v1 := CosineSimilar(info.Buyer, cp.Buyer)
  242. if v == 2 {
  243. compareBuyer = "B"
  244. score += 1
  245. } else {
  246. compareBuyer = "C"
  247. }
  248. }
  249. }
  250. //---------------------------------------
  251. compareCity = ""
  252. if info.Area != "全国" && info.Area != "" && info.Area == cp.Area {
  253. compareCity += "A"
  254. score += 2
  255. } else if info.Area == "全国" || cp.Area == "全国" {
  256. compareCity += "B"
  257. score += 1
  258. } else {
  259. compareCity += "C"
  260. }
  261. if compareCity != "C" {
  262. if info.City != "" && info.City == cp.City {
  263. compareCity += "A"
  264. score += 2
  265. } else {
  266. if info.Area == "全国" || cp.Area == "全国" {
  267. compareCity += "B"
  268. } else if info.City == compareCity {
  269. compareCity += "B"
  270. } else {
  271. compareCity += "C"
  272. }
  273. }
  274. } else {
  275. compareCity += "C"
  276. }
  277. score2 = 0
  278. if compareCity == "AA" {
  279. score2 = 1
  280. //if info.District != "" && info.District == cp.District {
  281. // score2 = 1
  282. //}
  283. }
  284. compareTime = "D"
  285. if diffTime < 45*86400 {
  286. compareTime = "A"
  287. score += 2
  288. } else if diffTime < 90*86400 {
  289. compareTime = "B"
  290. score += 1
  291. }
  292. compareAgency = "D"
  293. if info.Agency != "" {
  294. if info.Agency == cp.Agency {
  295. compareAgency = "A"
  296. score += 2
  297. score2 += 1
  298. } else if cp.Agency != "" {
  299. if strings.Contains(info.Agency, cp.Agency) || strings.Contains(cp.Agency, info.Agency) {
  300. compareAgency = "B"
  301. score += 1
  302. score2 += 1
  303. } else {
  304. compareAgency = "C"
  305. }
  306. }
  307. }
  308. compareBudget = "C"
  309. if info.Budget > 0 && (info.Budget == cp.Budget || (cp.Bidamount > 0 && info.Budget > cp.Bidamount && (info.Budget-cp.Bidamount) < (0.15*info.Budget))) {
  310. compareBudget = "A"
  311. score += 1
  312. score2 += 1
  313. }
  314. // else if info.Budget == 0 && cp.Budget == 0 {
  315. // compareBudget = "B"
  316. // }
  317. compareBidmount = "C"
  318. if info.Bidamount > 0 && (info.Bidamount == cp.Bidamount || (cp.Budget > 0 && cp.Budget > info.Bidamount && (cp.Budget-info.Bidamount) < 0.15*cp.Budget)) {
  319. compareBidmount = "A"
  320. score += 1
  321. score2 += 1
  322. }
  323. // else if info.Bidamount == 0 && cp.Bidamount == 0 {
  324. // compareBidmount = "B"
  325. // }
  326. cp.score = score
  327. return
  328. }
  329. func compareResult(resVal, pjVal, score2 int, comStr, compareBuyer, compareCity, compareTime, compareAgency, compareBudget, compareBidmount string) int {
  330. eqV := 0
  331. switch resVal {
  332. case 3:
  333. if pjVal == 3 && comStr[3:] != "CCCDCCC" {
  334. eqV = 1
  335. } else if compareBuyer < "C" {
  336. if pjVal > 1 {
  337. eqV = 1
  338. } else { //if (compareCity[1:1] != "C" || compareTime != "D") && score2 > 0
  339. eqV = 2
  340. }
  341. } else if compareBuyer == "D" {
  342. if pjVal > 1 && (compareCity[1:1] != "C" || score2 > 0) {
  343. eqV = 2
  344. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  345. eqV = 3
  346. }
  347. } else {
  348. if pjVal == 3 && (score2 > 0 || compareCity[1:1] != "C") {
  349. eqV = 2
  350. } else if pjVal == 2 && compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  351. eqV = 3
  352. } else if compareCity == "AA" && compareTime == "A" && score2 > 0 {
  353. eqV = 3
  354. }
  355. }
  356. case 2:
  357. if compareBuyer < "C" {
  358. if pjVal > 1 {
  359. eqV = 2
  360. } else if compareCity[1:1] != "C" && compareTime == "A" || score2 > 0 {
  361. eqV = 3
  362. }
  363. } else if compareBuyer == "D" {
  364. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  365. eqV = 2
  366. } else if compareCity[1:1] != "C" && compareTime == "A" && score2 > 0 {
  367. eqV = 3
  368. }
  369. } else {
  370. if pjVal > 1 && compareTime == "A" && (score2 > 0 || compareCity[1:1] != "C") {
  371. eqV = 2
  372. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  373. eqV = 3
  374. }
  375. }
  376. case 1:
  377. if compareBuyer < "C" {
  378. if pjVal > 1 && (score2 > 0 || compareCity[1:1] != "C") {
  379. eqV = 2
  380. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  381. eqV = 3
  382. }
  383. } else if compareBuyer == "D" {
  384. if pjVal > 1 && compareTime == "A" && (score2 > 0 || compareCity[1:1] != "C") {
  385. eqV = 2
  386. } else if compareCity[1:1] != "C" && compareTime == "A" && (compareAgency == "A" || score2 > 0) && (compareBudget == "A" || compareBidmount == "A") {
  387. eqV = 3
  388. }
  389. } else {
  390. if pjVal > 1 && compareTime == "A" && score2 > 0 && (compareBudget == "A" || compareBidmount == "A") && compareCity[1:1] != "C" {
  391. eqV = 3
  392. }
  393. }
  394. }
  395. return eqV
  396. }
  397. func (p *ProjectTask) NewProject(tmp map[string]interface{}, thisinfo *Info) (string, *ProjectCache) {
  398. //pId := primitive.NewObjectID() //NewObjectId()
  399. pId := mongodb.StringTOBsonId(thisinfo.Id)
  400. set := map[string]interface{}{}
  401. set["_id"] = pId
  402. for _, f := range FIELDS {
  403. if tmp[f] != nil && tmp[f] != "" {
  404. set[f] = tmp[f]
  405. }
  406. }
  407. bidopentime := util.Int64All(tmp["bidopentime"])
  408. if bidopentime > 0 {
  409. set["bidopentime"] = bidopentime
  410. }
  411. bidendtime := util.Int64All(tmp["bidendtime"])
  412. if bidendtime > 0 {
  413. set["bidendtime"] = bidendtime
  414. }
  415. //异常标记
  416. if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
  417. set["exception"] = 1
  418. }
  419. //projecthref保存
  420. if jsonData, ok := tmp["jsondata"].(map[string]interface{}); ok {
  421. if jsonData != nil && util.ObjToString(jsonData["projecthref"]) != "" {
  422. set["projecthref"] = jsonData["projecthref"]
  423. }
  424. }
  425. //合同编号
  426. if thisinfo.ContractCode != "" {
  427. set["contractcode"] = thisinfo.ContractCode
  428. }
  429. bt := util.ObjToString(tmp["toptype"])
  430. bs := util.ObjToString(tmp["subtype"])
  431. p.mapBidLock.Lock()
  432. if thisinfo.Infoformat == 2 || thisinfo.SubType == "拟建" {
  433. set["bidstatus"] = "拟建"
  434. bt = "拟建"
  435. } else {
  436. if bidtype[bs] != "" {
  437. set["bidtype"] = bidtype[bs]
  438. } else {
  439. set["bidtype"] = "招标"
  440. }
  441. if bt == "招标" {
  442. set["projectscope"] = util.ObjToString(tmp["projectscope"])
  443. set["bidstatus"] = bt
  444. } else {
  445. if bidstatus[bs] != "" {
  446. set["bidstatus"] = thisinfo.SubType
  447. bt = thisinfo.SubType
  448. } else if bs == "" {
  449. set["bidstatus"] = ""
  450. bt = ""
  451. } else {
  452. set["bidstatus"] = "其它"
  453. bt = "其它"
  454. }
  455. }
  456. }
  457. p.mapBidLock.Unlock()
  458. pkg := PackageFormat(thisinfo, nil)
  459. p1 := p.NewCachePinfo(pId, thisinfo, bs, bt)
  460. now := time.Now().Unix()
  461. set["createtime"] = now
  462. set["sourceinfoid"] = thisinfo.Id
  463. set["sourceinfourl"] = tmp["href"]
  464. set["firsttime"] = tmp["publishtime"]
  465. set["lasttime"] = tmp["publishtime"]
  466. //增量用系统时间,全量(历史)入库时间
  467. if p.currentType == "pl" {
  468. set["pici"] = tmp["comeintime"]
  469. } else {
  470. set["pici"] = p.pici
  471. }
  472. set["ids"] = []string{thisinfo.Id}
  473. if thisinfo.TopType == "招标" {
  474. //if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
  475. set["zbtime"] = tmp["publishtime"]
  476. //}
  477. } else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
  478. set["jgtime"] = tmp["publishtime"]
  479. }
  480. if len(thisinfo.Subscopeclass) > 0 {
  481. set["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
  482. }
  483. if len(thisinfo.Winners) > 0 {
  484. set["s_winner"] = strings.Join(thisinfo.Winners, ",")
  485. }
  486. if thisinfo.HasPackage {
  487. set["multipackage"] = 1
  488. set["package"] = pkg
  489. } else {
  490. set["multipackage"] = 0
  491. }
  492. //项目评审专家
  493. if thisinfo.ReviewExperts != "" {
  494. set["review_experts"] = thisinfo.ReviewExperts
  495. }
  496. //标的物
  497. if thisinfo.Purchasing != "" {
  498. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  499. p := strings.Join(util.ObjArrToStringArr(list), ",")
  500. set["purchasing"] = p
  501. }
  502. //中标候选人
  503. if len(thisinfo.WinnerOrder) > 0 {
  504. var list = []string{}
  505. for _, v := range thisinfo.WinnerOrder {
  506. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  507. list = append(list, util.ObjToString(v["entname"]))
  508. }
  509. }
  510. set["winnerorder"] = list
  511. }
  512. //项目规模
  513. if len(thisinfo.ProjectScale) > 0 {
  514. set["project_scale"] = thisinfo.ProjectScale
  515. }
  516. //工期时长
  517. if thisinfo.ProjectDuration > 0 {
  518. set["project_duration"] = thisinfo.ProjectDuration
  519. }
  520. // 工期单位
  521. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  522. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  523. }
  524. //开工日期
  525. if thisinfo.ProjectStartDate > 0 {
  526. set["project_startdate"] = thisinfo.ProjectStartDate
  527. }
  528. //竣工日期
  529. if thisinfo.ProjectCompleteDate > 0 {
  530. set["project_completedate"] = thisinfo.ProjectCompleteDate
  531. }
  532. //付款方式
  533. if len(thisinfo.Payway) > 0 {
  534. set["payway"] = thisinfo.Payway
  535. }
  536. // 履约保证金
  537. if tmp["contract_guarantee"] != nil {
  538. set["contract_guarantee"] = thisinfo.ContractGuarantee
  539. }
  540. // 投标保证金
  541. if tmp["bid_guarantee"] != nil {
  542. set["bid_guarantee"] = thisinfo.BidGuarantee
  543. }
  544. // 资质条件
  545. if len(thisinfo.Qualifies) > 0 {
  546. var str []string
  547. for _, v := range thisinfo.Qualifies {
  548. if len(util.ObjToString(v["key"])) > 0 {
  549. if BinarySearch(str, util.ObjToString(v["key"])) == -1 {
  550. str = append(str, util.ObjToString(v["key"]))
  551. }
  552. }
  553. }
  554. if len(str) > 0 {
  555. set["qualifies"] = strings.Join(str, ",")
  556. }
  557. }
  558. if len(thisinfo.EntIdList) > 0 {
  559. set["entidlist"] = thisinfo.EntIdList
  560. }
  561. // first_cooperation
  562. if p1.Buyer != "" && len(thisinfo.Winners) > 0 {
  563. FirstCooperation(set, p1.Buyer, thisinfo.Winners, thisinfo.EntIdList)
  564. }
  565. //infofield := InfoField{
  566. // Budget: thisinfo.Budget,
  567. // Bidamount: thisinfo.Bidamount,
  568. // ContractCode: thisinfo.ContractCode,
  569. // ProjectName: thisinfo.ProjectName,
  570. // ProjectCode: thisinfo.ProjectCode,
  571. // Bidstatus: bs,
  572. //}
  573. //res := StructToMap(infofield)
  574. //set["infofield"] = map[string]interface{}{
  575. // thisinfo.Id: res,
  576. //}
  577. //if tmp["budget"] != nil && tmp["budget"] != "" {
  578. // set["budget"] = thisinfo.Budget
  579. // set["budgettag"] = 0
  580. //} else {
  581. // set["budgettag"] = 1
  582. //}
  583. //if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
  584. // set["bidamount"] = thisinfo.Bidamount
  585. // set["bidamounttag"] = 0
  586. //} else {
  587. // set["bidamounttag"] = 1
  588. //}
  589. if thisinfo.Budget > 0 {
  590. set["budget"] = thisinfo.Budget
  591. }
  592. if thisinfo.Bidamount > 0 {
  593. set["bidamount"] = thisinfo.Bidamount
  594. }
  595. if p1.Bidamount > 0 {
  596. set["sortprice"] = p1.Bidamount
  597. } else {
  598. if p1.Budget > 0 {
  599. set["sortprice"] = p1.Budget
  600. }
  601. }
  602. if tmp["bid_field"] != nil {
  603. set["bid_field"] = tmp["bid_field"]
  604. }
  605. redis.PutCKV("project", thisinfo.Id, set)
  606. set["size"] = 1
  607. push := p.PushListInfo(tmp, thisinfo.Id)
  608. if len(thisinfo.Winners) > 0 {
  609. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  610. }
  611. set["list"] = []bson.M{
  612. push,
  613. }
  614. p.updatePool <- []map[string]interface{}{
  615. {
  616. "_id": pId,
  617. },
  618. {
  619. "$set": set,
  620. },
  621. }
  622. return pId.Hex(), &p1
  623. }
  624. // 项目中list的信息
  625. func (p *ProjectTask) PushListInfo(tmp map[string]interface{}, infoid string) bson.M {
  626. res := bson.M{
  627. "infoid": infoid,
  628. }
  629. for _, k := range INFOFIELDS {
  630. if tmp[k] != nil {
  631. res[k] = tmp[k]
  632. }
  633. }
  634. return res
  635. }
  636. // 生成存放在内存中的对象
  637. func (p *ProjectTask) NewCachePinfo(id primitive.ObjectID, thisinfo *Info, bidtype, bidstatus string) ProjectCache {
  638. p1 := ProjectCache{
  639. Id: id,
  640. Ids: []string{thisinfo.Id},
  641. ProjectName: thisinfo.ProjectName,
  642. ProjectCode: thisinfo.ProjectCode,
  643. Buyer: thisinfo.Buyer,
  644. Agency: thisinfo.Agency,
  645. Area: thisinfo.Area,
  646. City: thisinfo.City,
  647. District: thisinfo.District,
  648. MPN: []string{},
  649. MPC: []string{},
  650. FirstTime: thisinfo.Publishtime,
  651. LastTime: thisinfo.Publishtime,
  652. Budget: thisinfo.Budget,
  653. Bidamount: thisinfo.Bidamount,
  654. Bidstatus: bidstatus,
  655. Bidtype: bidtype,
  656. Size: 1,
  657. }
  658. if thisinfo.LenPTC > 5 {
  659. p1.MPC = append(p1.MPC, thisinfo.PTC)
  660. }
  661. return p1
  662. }
  663. // @Description 更新项目 全量合并
  664. // @update 中间表查询需要更新的项目信息
  665. // @Author J 2022/7/6 14:02
  666. func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectCache, weight int, comStr string, ex int) {
  667. if p.currentType != "updateInfo" {
  668. if BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
  669. log.Info("repeat" + thisinfo.Id + ",pid" + pInfo.Id.Hex())
  670. return
  671. }
  672. }
  673. pdata := redis.Get("project", pInfo.Id.Hex())
  674. if pdata == nil {
  675. log.Info("redis err, not find project " + pInfo.Id.Hex())
  676. return
  677. }
  678. projectMap := pdata.(map[string]interface{})
  679. bys, _ := json.Marshal(projectMap)
  680. var project *Project
  681. err := json.Unmarshal(bys, &project)
  682. if err != nil {
  683. log.Info("project Unmarshal err," + err.Error() + ",pid: " + pInfo.Id.Hex())
  684. return
  685. }
  686. set := map[string]interface{}{}
  687. pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
  688. if len(pInfo.Ids) > 30 {
  689. //异常标记
  690. set["listtag"] = 1
  691. }
  692. //zbtime、lasttime、jgtime
  693. pInfo.LastTime = thisinfo.Publishtime
  694. set["lasttime"] = thisinfo.Publishtime
  695. if thisinfo.TopType == "招标" {
  696. if project.Zbtime <= 0 {
  697. project.Zbtime = thisinfo.Publishtime
  698. set["zbtime"] = tmp["publishtime"]
  699. }
  700. if project.Jgtime > 0 {
  701. project.Jgtime = int64(0)
  702. set["jgtime"] = int64(0)
  703. }
  704. } else if thisinfo.TopType == "结果" {
  705. if thisinfo.SubType == "中标" || thisinfo.SubType == "成交" || thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  706. if project.Jgtime > 0 {
  707. //jg1 := int64(math.Abs(float64(pInfo.Jgtime - thisinfo.Publishtime)))
  708. //公告状态和项目状态同样都是中标或者成交,
  709. if thisinfo.SubType == "成交" && project.Bidstatus == "中标" {
  710. if p.jgTime < thisinfo.Publishtime {
  711. project.Jgtime = thisinfo.Publishtime
  712. set["jgtime"] = tmp["publishtime"]
  713. }
  714. //公告状态和项目状态同样是流标或者废标
  715. } else if (thisinfo.SubType == "流标" || thisinfo.SubType == "废标") && (project.Bidstatus == "流标" || project.Bidstatus == "废标") {
  716. if p.jgTime < thisinfo.Publishtime {
  717. project.Jgtime = thisinfo.Publishtime
  718. set["jgtime"] = tmp["publishtime"]
  719. }
  720. }
  721. } else {
  722. project.Jgtime = thisinfo.Publishtime
  723. set["jgtime"] = tmp["publishtime"]
  724. }
  725. }
  726. } else if thisinfo.SubType == "合同" {
  727. if project.Bidstatus == "中标" || project.Bidstatus == "成交" || project.Bidstatus == "" {
  728. //中标、成交不更新jgtime
  729. } else {
  730. project.Jgtime = thisinfo.Publishtime
  731. set["jgtime"] = tmp["publishtime"]
  732. }
  733. }
  734. if thisinfo.BidOpenTime > project.BidOpenTime {
  735. project.BidOpenTime = thisinfo.BidOpenTime
  736. set["bidopentime"] = project.BidOpenTime
  737. }
  738. if thisinfo.BidEndTime > 0 {
  739. project.BidEndTime = thisinfo.BidEndTime
  740. set["bidendtime"] = project.BidEndTime
  741. }
  742. bt := util.ObjToString(tmp["toptype"])
  743. bs := util.ObjToString(tmp["subtype"])
  744. p.mapBidLock.Lock()
  745. if bt == "招标" {
  746. //招标状态,更新projectscope
  747. if tmp["projectscope"] != nil {
  748. set["projectscope"] = util.ObjToString(tmp["projectscope"])
  749. }
  750. set["bidstatus"] = bt
  751. project.Bidstatus = bt
  752. if bidtype[bs] != "" {
  753. set["bidtype"] = bidtype[bs]
  754. project.Bidtype = bidtype[bs]
  755. } else {
  756. set["bidtype"] = "招标"
  757. project.Bidtype = "招标"
  758. }
  759. } else {
  760. if bidstatus[bs] != "" {
  761. set["bidstatus"] = thisinfo.SubType
  762. project.Bidstatus = thisinfo.SubType
  763. } else if thisinfo.Infoformat == 2 {
  764. set["bidstatus"] = "拟建"
  765. project.Bidstatus = "拟建"
  766. } else if bs == "" && bt == "结果" {
  767. if project.Bidstatus == "招标" {
  768. set["bidstatus"] = ""
  769. project.Bidstatus = ""
  770. }
  771. } else {
  772. set["bidstatus"] = "其它"
  773. project.Bidstatus = "其它"
  774. }
  775. }
  776. p.mapBidLock.Unlock()
  777. //异常标记
  778. if ex > 0 {
  779. set["exception"] = ex
  780. }
  781. //3\4\5--省、市、县
  782. //if thisinfo.Area != "全国" {
  783. // if pInfo.Area == "全国" {
  784. // pInfo.Area = thisinfo.Area
  785. // set["area"] = thisinfo.Area
  786. // } else if pInfo.Area != thisinfo.Area {
  787. // //xt = false
  788. // }
  789. // if pInfo.City == "" && thisinfo.City != "" {
  790. // pInfo.City = thisinfo.City
  791. // set["city"] = thisinfo.City
  792. // } else if pInfo.City != thisinfo.City {
  793. // //xt = false
  794. // }
  795. // if thisinfo.District != "" && pInfo.District == "" {
  796. // pInfo.District = thisinfo.District
  797. // set["district"] = thisinfo.District
  798. // }
  799. //}
  800. //相同城市的公告才会合并到一起(全国列外)
  801. if thisinfo.Area != "全国" {
  802. pInfo.Area = thisinfo.Area
  803. project.Area = thisinfo.Area
  804. set["area"] = thisinfo.Area
  805. if thisinfo.City != "" {
  806. pInfo.City = thisinfo.City
  807. project.City = thisinfo.City
  808. set["city"] = thisinfo.City
  809. }
  810. if thisinfo.District != "" {
  811. pInfo.District = thisinfo.District
  812. project.District = thisinfo.District
  813. set["district"] = thisinfo.District
  814. }
  815. }
  816. //项目名称
  817. //if (thisinfo.ProjectName != "" && pInfo.ProjectName == "") || (len([]rune(pInfo.ProjectName)) < 6 && thisinfo.LenPN > 6) {
  818. if pInfo.ProjectName == "" && thisinfo.ProjectName != "" {
  819. pInfo.ProjectName = thisinfo.ProjectName
  820. project.ProjectName = thisinfo.ProjectName
  821. set["projectname"] = thisinfo.ProjectName
  822. }
  823. //7--项目编号
  824. //if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
  825. if pInfo.ProjectCode == "" && thisinfo.ProjectCode != "" {
  826. pInfo.ProjectCode = thisinfo.ProjectCode
  827. project.ProjectCode = thisinfo.ProjectCode
  828. set["projectcode"] = thisinfo.ProjectCode
  829. }
  830. //7--采购单位
  831. if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
  832. pInfo.Buyer = thisinfo.Buyer
  833. project.Buyer = thisinfo.Buyer
  834. set["buyer"] = thisinfo.Buyer
  835. project.Buyerclass = thisinfo.Buyerclass
  836. set["buyerclass"] = thisinfo.Buyerclass
  837. }
  838. if pInfo.Buyer == "" {
  839. project.Buyerclass = ""
  840. set["buyerclass"] = ""
  841. }
  842. //采购单位联系人
  843. if thisinfo.Buyerperson != "" {
  844. project.Buyerperson = thisinfo.Buyerperson
  845. set["buyerperson"] = thisinfo.Buyerperson
  846. } else {
  847. project.Buyerperson = ""
  848. set["buyerperson"] = ""
  849. }
  850. //采购单位電話
  851. if thisinfo.Buyertel != "" {
  852. project.Buyertel = thisinfo.Buyertel
  853. set["buyertel"] = project.Buyertel
  854. } else {
  855. project.Buyertel = ""
  856. set["buyertel"] = ""
  857. }
  858. if thisinfo.ContractCode != "" {
  859. if project.ContractCode == "" {
  860. set["contractcode"] = thisinfo.ContractCode
  861. } else {
  862. list := strings.Split(project.ContractCode, ",")
  863. if BinarySearch(list, thisinfo.ContractCode) == -1 {
  864. list = append(list, thisinfo.ContractCode)
  865. sort.Strings(list)
  866. }
  867. set["contractcode"] = strings.Join(list, ",")
  868. }
  869. }
  870. //8--代理机构
  871. if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
  872. pInfo.Agency = thisinfo.Agency
  873. project.Agency = thisinfo.Agency
  874. set["agency"] = thisinfo.Agency
  875. }
  876. if len(thisinfo.Topscopeclass) > 0 {
  877. sort.Strings(project.Topscopeclass)
  878. for _, k := range thisinfo.Topscopeclass {
  879. if BinarySearch(project.Topscopeclass, k) == -1 {
  880. project.Topscopeclass = append(project.Topscopeclass, k)
  881. sort.Strings(project.Topscopeclass)
  882. }
  883. }
  884. set["topscopeclass"] = project.Topscopeclass
  885. }
  886. //项目评审专家
  887. if thisinfo.ReviewExperts != "" {
  888. set["review_experts"] = thisinfo.ReviewExperts
  889. project.ReviewExperts = thisinfo.ReviewExperts
  890. }
  891. if thisinfo.Purchasing != "" {
  892. if project.Purchasing == "" {
  893. list := Duplicate(strings.Split(thisinfo.Purchasing, ",")) //标的物 去重 03/03
  894. p := strings.Join(util.ObjArrToStringArr(list), ",")
  895. project.Purchasing = p
  896. set["purchasing"] = p
  897. } else {
  898. list := strings.Split(project.Purchasing, ",")
  899. list = util.ObjArrToStringArr(Duplicate(list))
  900. for _, k := range list {
  901. if BinarySearch(strings.Split(thisinfo.Purchasing, ","), k) == -1 {
  902. list = append(list, k)
  903. sort.Strings(list)
  904. }
  905. }
  906. set["purchasing"] = strings.Join(list, ",")
  907. }
  908. }
  909. //中标候选人
  910. if len(thisinfo.WinnerOrder) > 0 {
  911. var list = []string{}
  912. for _, v := range thisinfo.WinnerOrder {
  913. if BinarySearch(list, util.ObjToString(v["entname"])) == -1 {
  914. list = append(list, util.ObjToString(v["entname"]))
  915. }
  916. }
  917. set["winnerorder"] = list
  918. project.Winnerorder = list
  919. }
  920. if len(thisinfo.Subscopeclass) > 0 {
  921. sort.Strings(project.Subscopeclass)
  922. for _, k := range thisinfo.Subscopeclass {
  923. if BinarySearch(project.Subscopeclass, k) == -1 {
  924. project.Subscopeclass = append(project.Subscopeclass, k)
  925. sort.Strings(project.Subscopeclass)
  926. }
  927. }
  928. set["subscopeclass"] = project.Subscopeclass
  929. set["s_subscopeclass"] = strings.Join(project.Subscopeclass, ",")
  930. }
  931. if len(thisinfo.Winners) > 0 {
  932. var winners []string
  933. if project.Winners == "" {
  934. set["winner"] = util.ObjToString(tmp["winner"])
  935. for _, k := range thisinfo.Winners {
  936. if k == "" {
  937. continue
  938. }
  939. if BinarySearch(winners, k) == -1 {
  940. winners = append(winners, k)
  941. }
  942. }
  943. } else {
  944. winners = strings.Split(project.Winners, ",")
  945. for _, k := range thisinfo.Winners {
  946. if k == "" {
  947. continue
  948. }
  949. if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
  950. if BinarySearch(winners, k) != -1 {
  951. deleteSlice(winners, k, "")
  952. }
  953. } else {
  954. if BinarySearch(winners, k) == -1 {
  955. winners = append(winners, k)
  956. }
  957. }
  958. }
  959. }
  960. if len(winners) > 0 {
  961. set["s_winner"] = strings.Join(util.ObjArrToStringArr(Duplicate(winners)), ",")
  962. }
  963. }
  964. if len(thisinfo.EntIdList) > 0 {
  965. for _, v := range thisinfo.EntIdList {
  966. if BinarySearch(project.EntIdList, v) == -1 {
  967. project.EntIdList = append(project.EntIdList, v)
  968. }
  969. }
  970. set["entidlist"] = project.EntIdList
  971. }
  972. //first_cooperation
  973. if pInfo.Buyer != "" && len(strings.Split(project.Winners, ",")) > 0 {
  974. FirstCooperation(set, pInfo.Buyer, strings.Split(project.Winners, ","), project.EntIdList)
  975. }
  976. //项目规模
  977. if len(thisinfo.ProjectScale) > 0 {
  978. project.ProjectScale = thisinfo.ProjectScale
  979. set["project_scale"] = thisinfo.ProjectScale
  980. }
  981. //工期时长
  982. if thisinfo.ProjectDuration > 0 {
  983. project.ProjectDuration = thisinfo.ProjectDuration
  984. set["project_duration"] = thisinfo.ProjectDuration
  985. }
  986. // 工期单位
  987. if thisinfo.ProjectDuration > 0 && len(thisinfo.ProjectTimeUnit) > 0 {
  988. project.ProjectTimeunit = thisinfo.ProjectTimeUnit
  989. set["project_timeunit"] = thisinfo.ProjectTimeUnit
  990. }
  991. //开工日期
  992. if thisinfo.ProjectStartDate > 0 {
  993. if project.ProjectStartDate > 0 {
  994. if project.ProjectStartDate < thisinfo.ProjectStartDate {
  995. project.ProjectStartDate = thisinfo.ProjectStartDate
  996. set["project_startdate"] = thisinfo.ProjectStartDate
  997. }
  998. } else {
  999. project.ProjectStartDate = thisinfo.ProjectStartDate
  1000. set["project_startdate"] = thisinfo.ProjectStartDate
  1001. }
  1002. }
  1003. //竣工日期
  1004. if thisinfo.ProjectCompleteDate > 0 {
  1005. if project.ProjctCompleteDate > 0 {
  1006. if project.ProjctCompleteDate < thisinfo.ProjectCompleteDate {
  1007. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1008. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1009. }
  1010. } else {
  1011. project.ProjctCompleteDate = thisinfo.ProjectCompleteDate
  1012. set["project_completedate"] = thisinfo.ProjectCompleteDate
  1013. }
  1014. }
  1015. // 付款方式
  1016. if len(thisinfo.Payway) > 0 {
  1017. project.Payway = thisinfo.Payway
  1018. set["payway"] = thisinfo.Payway
  1019. }
  1020. // 履约保证金
  1021. if tmp["contract_guarantee"] != nil {
  1022. project.ContractGuarantee = thisinfo.ContractGuarantee
  1023. set["contract_guarantee"] = thisinfo.ContractGuarantee
  1024. }
  1025. // 投标保证金
  1026. if tmp["bid_guarantee"] != nil {
  1027. project.BidGuarantee = thisinfo.BidGuarantee
  1028. set["bid_guarantee"] = thisinfo.BidGuarantee
  1029. }
  1030. // 资质条件
  1031. if len(thisinfo.Qualifies) > 0 {
  1032. var str []string
  1033. if len(project.Qualifies) > 0 {
  1034. str = append(str, strings.Split(project.Qualifies, ",")...)
  1035. }
  1036. for _, v := range thisinfo.Qualifies {
  1037. if len(util.ObjToString(v["key"])) > 0 {
  1038. if BinarySearch(str, util.ObjToString(v["key"])) == -1 {
  1039. str = append(str, util.ObjToString(v["key"]))
  1040. }
  1041. }
  1042. }
  1043. if len(str) > 0 {
  1044. project.Qualifies = strings.Join(str, ",")
  1045. set["qualifies"] = strings.Join(str, ",")
  1046. }
  1047. }
  1048. if thisinfo.HasPackage { //多包处理
  1049. set["multipackage"] = 1
  1050. pkg := PackageFormat(thisinfo, project)
  1051. project.Package = pkg
  1052. set["package"] = project.Package
  1053. }
  1054. //处理多包后,计算预算金额、中标金额
  1055. //CountAmount(project, thisinfo, tmp)
  1056. //if project.Budget >= 0 && project.Budgettag != 1 {
  1057. // pInfo.Budget = project.Budget
  1058. // set["budget"] = project.Budget
  1059. // set["budgettag"] = 0
  1060. //}
  1061. //if project.Bidamount >= 0 && project.Bidamounttag != 1 {
  1062. // pInfo.Bidamount = project.Bidamount
  1063. // set["bidamount"] = pInfo.Bidamount
  1064. // set["bidamounttag"] = 0
  1065. //}
  1066. if thisinfo.Budget > 0 {
  1067. pInfo.Budget = thisinfo.Budget
  1068. project.Budget = thisinfo.Budget
  1069. set["budget"] = thisinfo.Budget
  1070. }
  1071. if thisinfo.Bidamount > 0 {
  1072. pInfo.Bidamount = thisinfo.Bidamount
  1073. project.Bidamount = thisinfo.Bidamount
  1074. set["bidamount"] = thisinfo.Bidamount
  1075. }
  1076. if pInfo.Bidamount > 0 {
  1077. set["sortprice"] = pInfo.Bidamount
  1078. } else {
  1079. if pInfo.Budget > 0 {
  1080. set["sortprice"] = pInfo.Budget
  1081. }
  1082. }
  1083. if tmp["bid_field"] != nil {
  1084. set["bid_field"] = tmp["bid_field"]
  1085. }
  1086. //infofield := InfoField{
  1087. // Budget: thisinfo.Budget,
  1088. // Bidamount: thisinfo.Bidamount,
  1089. // ContractCode: thisinfo.ContractCode,
  1090. // ProjectName: thisinfo.ProjectName,
  1091. // ProjectCode: thisinfo.ProjectCode,
  1092. // Bidstatus: bs,
  1093. //}
  1094. //copyMap := util.DeepCopy(project.InfoFiled).(map[string]InfoField)
  1095. //copyMap[thisinfo.Id] = infofield
  1096. //tmpMap := make(map[string]interface{})
  1097. //for k, v := range copyMap {
  1098. // tmpMap[k] = StructToMap(v)
  1099. //}
  1100. //tmpMap[thisinfo.Id] = StructToMap(infofield)
  1101. //project.InfoFiled = copyMap
  1102. //set["infofield"] = tmpMap
  1103. set["mpn"] = pInfo.MPN
  1104. set["mpc"] = pInfo.MPC
  1105. pInfo.Size = pInfo.Size + 1
  1106. set["size"] = pInfo.Size
  1107. if p.currentType == "project" || p.currentType == "project_history" {
  1108. set["pici"] = p.pici
  1109. } else {
  1110. set["pici"] = tmp["comeintime"]
  1111. }
  1112. redis.PutCKV("project", project.Id.Hex(), set)
  1113. update := map[string]interface{}{}
  1114. if len(set) > 0 {
  1115. update["$set"] = set
  1116. }
  1117. push := p.PushListInfo(tmp, thisinfo.Id)
  1118. if len(thisinfo.Winners) > 0 {
  1119. push["s_winner"] = strings.Join(thisinfo.Winners, ",")
  1120. }
  1121. push["compareStr"] = comStr
  1122. push["resVal"] = pInfo.resVal
  1123. push["pjVal"] = pInfo.pjVal
  1124. update["$push"] = map[string]interface{}{
  1125. "list": push,
  1126. "ids": thisinfo.Id,
  1127. }
  1128. //clearMap := map[string]interface{}{}
  1129. //ClearData(clearMap, set)
  1130. //if len(clearMap) > 0 {
  1131. // update["$unset"] = clearMap
  1132. //}
  1133. if len(update) > 0 {
  1134. updateInfo := []map[string]interface{}{
  1135. {
  1136. "_id": pInfo.Id,
  1137. },
  1138. update,
  1139. }
  1140. p.updatePool <- updateInfo
  1141. }
  1142. }
  1143. /**
  1144. * 更新项目时,项目状态的处理
  1145. * 返回是否新增项目,异常标记
  1146. * 1、新增项目时,招标信息的状态(toptype)不是招标、拟建、预告 异常:1
  1147. * 异常1是在项目新建的时候才会产生
  1148. * 3、项目合并时,项目状态是”流标“/”废标“,招标信息状态不是”招标“ 异常:2
  1149. * 4、项目合并时,项目状态是”合同“/”其它“,招标信息类型是”结果“ 异常:3
  1150. */
  1151. func (p *ProjectTask) CompareStatus(project *ProjectCache, info *Info) (bool, int) {
  1152. if info.TopType == "拟建" || info.TopType == "预告" || info.TopType == "招标" {
  1153. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1154. return false, 0
  1155. } else if project.Bidstatus == "废标" || project.Bidstatus == "流标" {
  1156. return false, 0
  1157. } else {
  1158. return true, 0
  1159. }
  1160. } else if info.TopType == "结果" {
  1161. if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
  1162. return false, 0
  1163. } else if project.Bidstatus == info.SubType {
  1164. //状态一样,根据发布时间判断是否合并
  1165. if (info.Publishtime - project.LastTime) > p.statusTime {
  1166. return true, 0
  1167. } else {
  1168. return false, 0
  1169. }
  1170. } else if project.Bidstatus == "成交" && info.SubType == "中标" {
  1171. return true, 0
  1172. } else if project.Bidstatus == "流标" || project.Bidstatus == "废标" {
  1173. return false, 2
  1174. } else if project.Bidstatus == "合同" || project.Bidstatus == "其它" {
  1175. return false, 3
  1176. } else {
  1177. return false, 0
  1178. }
  1179. } else {
  1180. return false, 0
  1181. }
  1182. }
  1183. /*
  1184. * 对比地区(省、市),存在且不同,不能合并
  1185. * 返回是否新建项目
  1186. */
  1187. func ComparePlace(project *ProjectCache, info *Info) bool {
  1188. if info.Area == "全国" || info.Area == "" {
  1189. return false
  1190. }
  1191. if project.Area == "全国" || project.Area == "" {
  1192. return false
  1193. }
  1194. if info.Area == project.Area {
  1195. if info.City == "" || project.City == "" {
  1196. return false
  1197. } else if info.City == project.City {
  1198. return false
  1199. }
  1200. } else {
  1201. return true
  1202. }
  1203. return true
  1204. }
  1205. func packageEle(map1 map[string]interface{}, id string) map[string]interface{} {
  1206. p2 := map[string]interface{}{}
  1207. for _, k := range PackageEle {
  1208. if map1[k] != nil {
  1209. p2[k] = map1[k]
  1210. }
  1211. infoid := p2["infoid"]
  1212. if infoid == nil {
  1213. p2["infoid"] = id
  1214. }
  1215. }
  1216. return p2
  1217. }
  1218. func PackageFormat(info *Info, project *Project) map[string]interface{} {
  1219. p1 := map[string]interface{}{}
  1220. if project != nil && project.Package != nil && len(project.Package) > 0 {
  1221. packageCopy := util.DeepCopy(project.Package).(map[string]interface{})
  1222. p1 = packageCopy
  1223. for k, v := range info.Package {
  1224. if v1, ok := v.(map[string]interface{}); ok {
  1225. v2 := map[string]interface{}{}
  1226. v2 = packageEle(v1, info.Id)
  1227. if v2["bidstatus"] == nil {
  1228. v2["bidstatus"] = info.SubType
  1229. }
  1230. addFlag := false
  1231. for k1, v3 := range p1 {
  1232. if v4, ok := v3.([]map[string]interface{}); ok {
  1233. //if qu.ObjToString(v4[0]["origin"]) == qu.ObjToString(v2["origin"]) && qu.ObjToString(v4[0]["name"]) == qu.ObjToString(v2["name"]) {
  1234. if k1 == k {
  1235. v4 = append(v4, v2)
  1236. p1[k1] = v4
  1237. addFlag = true
  1238. break
  1239. }
  1240. }
  1241. }
  1242. if !addFlag {
  1243. p1[k] = []map[string]interface{}{v2}
  1244. }
  1245. }
  1246. }
  1247. } else {
  1248. for k, v := range info.Package {
  1249. v1, _ := v.(map[string]interface{})
  1250. p2 := map[string]interface{}{}
  1251. p2 = packageEle(v1, info.Id)
  1252. if p2["bidstatus"] == nil {
  1253. p2["bidstatus"] = info.SubType
  1254. }
  1255. p1[k] = []map[string]interface{}{p2}
  1256. }
  1257. }
  1258. return p1
  1259. }
  1260. // 计算预算(budget)、中标金额(bidamount)
  1261. //func CountAmount(project *Project, info *Info, tmp map[string]interface{}) {
  1262. // if info.HasPackage {
  1263. // budget := 0.0
  1264. // for _, v := range project.Package {
  1265. // v1, _ := v.([]map[string]interface{})
  1266. // for _, v2 := range v1 {
  1267. // if v2["budget"] != nil {
  1268. // b1 := util.Float64All(v2["budget"])
  1269. // if b1 > 0 {
  1270. // budget = budget + b1
  1271. // break
  1272. // }
  1273. // } else {
  1274. // project.Budgettag = 1
  1275. // }
  1276. // }
  1277. // }
  1278. // if budget > 0 {
  1279. // project.Budget = budget
  1280. // project.Budgettag = 0
  1281. // } else if budget == 0 && info.Budget > 0 {
  1282. // project.Budget = info.Budget
  1283. // project.Budgettag = 0
  1284. // }
  1285. // } else {
  1286. // //招标没有多包
  1287. // k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1288. // if len(k) > 0 {
  1289. // //招标是单包
  1290. // if len(project.Package) > 0 {
  1291. // //项目有多包
  1292. // flag := false
  1293. // for _, v := range project.Package {
  1294. // v1, _ := v.([]map[string]interface{})
  1295. // if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1296. // flag = true
  1297. // }
  1298. // }
  1299. // if !flag {
  1300. // project.Budget = project.Budget + info.Budget
  1301. // project.Budgettag = 0
  1302. // }
  1303. // } else {
  1304. // //项目没有多包
  1305. // if info.Budget > 0 {
  1306. // project.Budget = project.Budget + info.Budget
  1307. // project.Budgettag = 0
  1308. // } else if info.Budget == 0 && tmp["budget"] != nil {
  1309. // project.Budgettag = 0
  1310. // }
  1311. // }
  1312. // } else {
  1313. // if info.Budget > 0 && project.Budget < info.Budget {
  1314. // project.Budget = info.Budget
  1315. // project.Budgettag = 0
  1316. // }
  1317. // }
  1318. // }
  1319. // if info.SubType == "中标" || info.SubType == "成交" || info.SubType == "合同" {
  1320. // if info.HasPackage {
  1321. // bidamount := 0.0
  1322. // for _, v := range project.Package {
  1323. // v1, _ := v.([]map[string]interface{})
  1324. // for _, v2 := range v1 {
  1325. // b1 := util.Float64All(v2["bidamount"])
  1326. // if b1 > 0 {
  1327. // bidamount = bidamount + b1
  1328. // break
  1329. // }
  1330. // }
  1331. // }
  1332. // if bidamount > 0 {
  1333. // project.Bidamount = bidamount
  1334. // project.Bidamounttag = 0
  1335. // } else if bidamount == 0 && info.Bidamount > 0 {
  1336. // project.Bidamount = info.Bidamount
  1337. // project.Bidamounttag = 0
  1338. // }
  1339. // } else {
  1340. // //招标没有多包
  1341. // k := KeyPackage.FindStringSubmatch(info.ProjectName)
  1342. // if len(k) > 0 {
  1343. // //招标是单包
  1344. // if len(project.Package) > 0 {
  1345. // //项目有多包
  1346. // flag := false
  1347. // for _, v := range project.Package {
  1348. // v1, _ := v.([]map[string]interface{})
  1349. // if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
  1350. // flag = true
  1351. // }
  1352. // }
  1353. // if !flag {
  1354. // project.Bidamount = project.Bidamount + info.Bidamount
  1355. // project.Bidamounttag = 0
  1356. // }
  1357. // } else {
  1358. // //项目没有多包
  1359. // if info.Bidamount > 0 {
  1360. // project.Bidamount = project.Bidamount + info.Bidamount
  1361. // project.Bidamounttag = 0
  1362. // } else if info.Bidamount == 0 && tmp["bidamount"] != nil {
  1363. // project.Bidamounttag = 0
  1364. // } else {
  1365. // project.Bidamounttag = 1
  1366. // }
  1367. // }
  1368. // } else {
  1369. // if info.SubType == "中标" || info.SubType == "成交" {
  1370. // if info.Bidamount > 0 {
  1371. // project.Bidamount = info.Bidamount
  1372. // project.Bidamounttag = 0
  1373. // } else {
  1374. // flag := false
  1375. // if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
  1376. // for _, res := range project.InfoFiled {
  1377. // if res.ContractCode != "" && res.ContractCode == info.ContractCode {
  1378. // flag = true
  1379. // break
  1380. // }
  1381. // if res.Bidamount == project.Bidamount {
  1382. // flag = true
  1383. // break
  1384. // }
  1385. // }
  1386. // if !flag {
  1387. // project.Bidamount = project.Bidamount + info.Bidamount
  1388. // project.Bidamounttag = 0
  1389. // } else {
  1390. // if info.Budget > 0 && project.Bidamount > info.Bidamount {
  1391. // project.Bidamount = info.Bidamount
  1392. // project.Bidamounttag = 0
  1393. // }
  1394. // }
  1395. // }
  1396. // }
  1397. // }
  1398. // }
  1399. // }
  1400. // } else {
  1401. // project.Bidamounttag = 1
  1402. // }
  1403. //
  1404. //}
  1405. // 结构体转map
  1406. //func StructToMap(filed InfoField) map[string]interface{} {
  1407. // //先转json
  1408. // result, err := json.Marshal(filed)
  1409. // if err != nil {
  1410. // return nil
  1411. // }
  1412. // //json转map
  1413. // res := make(map[string]interface{})
  1414. // err = json.Unmarshal(result, &res)
  1415. // return res
  1416. //}
  1417. func ClearData(clearMap, tmp map[string]interface{}) {
  1418. for k, v := range tmp {
  1419. if v == "" {
  1420. clearMap[k] = ""
  1421. }
  1422. }
  1423. }
  1424. func IsCreatePro(info *Info) (bol bool) {
  1425. bol = true
  1426. if info.SubType == "" || info.SubType == "变更" || info.SubType == "验收" || info.SubType == "违规" ||
  1427. info.SubType == "结果变更" || info.SubType == "其它" {
  1428. if info.ProjectName == "" && info.ProjectCode == "" {
  1429. bol = false
  1430. } else if info.ProjectName == "" && info.Buyer == "" {
  1431. bol = false
  1432. } else if info.ProjectCode == "" && info.Buyer == "" {
  1433. bol = false
  1434. }
  1435. }
  1436. return bol
  1437. }
  1438. func (p *ProjectTask) GetBidTypeAndBidStatus(info *Info) (string, string) {
  1439. p.mapBidLock.Lock()
  1440. defer p.mapBidLock.Unlock()
  1441. typeStr := bidtype[info.TopType]
  1442. statusStr := bidstatus[info.SubType]
  1443. if info.Infoformat == 2 || info.SubType == "拟建" {
  1444. statusStr = "拟建"
  1445. typeStr = ""
  1446. } else {
  1447. if bidtype[typeStr] == "" {
  1448. typeStr = "招标"
  1449. }
  1450. if typeStr == "招标" {
  1451. statusStr = typeStr
  1452. } else {
  1453. if statusStr == "" {
  1454. statusStr = "其它"
  1455. }
  1456. }
  1457. }
  1458. return typeStr, statusStr
  1459. }
  1460. func FirstCooperation(set map[string]interface{}, b string, winns, entidlist []string) {
  1461. defer func() {
  1462. // 处理数组越界异常
  1463. if r := recover(); r != nil {
  1464. //qu.Debug("recover...:", r)
  1465. }
  1466. }()
  1467. pid := mongodb.BsonIdToSId(set["_id"])
  1468. var eids []string
  1469. for i, eid := range entidlist {
  1470. if eid != "-" {
  1471. text := b + "," + winns[i]
  1472. ex, _ := redis.Exists(RedisCode, text)
  1473. if !ex {
  1474. redis.PutCKV(RedisCode, text, pid)
  1475. eids = append(eids, eid)
  1476. }
  1477. }
  1478. }
  1479. if len(eids) > 0 {
  1480. set["first_cooperation"] = entidlist
  1481. }
  1482. }