project.go 40 KB

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