project.go 40 KB

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