project.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package es
  2. import (
  3. elastic "app.yhyue.com/moapp/jybase/es"
  4. "fmt"
  5. "strings"
  6. "time"
  7. )
  8. // 项目信息 项目id
  9. func GetProjectInfo(id string) map[string]interface{} {
  10. projectInfos := elastic.GetById(IndexProjectSet, TypeProjectSet, id)
  11. if projectInfos != nil && len(*projectInfos) > 0 {
  12. return (*projectInfos)[0]
  13. }
  14. return nil
  15. }
  16. // 招标信息 招标信息id
  17. func GetBiddingInfo(id string) map[string]interface{} {
  18. biddingInfos := elastic.GetById(INDEX, TYPE, id)
  19. if biddingInfos != nil && len(*biddingInfos) > 0 {
  20. return (*biddingInfos)[0]
  21. }
  22. return nil
  23. }
  24. // GetValidProjectByInfoId 根据查询有效的参标项目id(未到开标时间及开标时间不存在的)
  25. func GetValidProjectByInfoId(infoIds []string) *[]map[string]interface{} {
  26. if len(infoIds) == 0 {
  27. return nil
  28. }
  29. nowTime := time.Now().Unix()
  30. query := `{"_source":["_id","list.infoid"],"query": {"bool": {"must": [{"terms": {"list.infoid": ["` + strings.Join(infoIds, "\",\"") + `"]}},
  31. {"bool": {"should": [{"range": {"bidopentime": {"gte": ` + fmt.Sprint(nowTime) + `}}},
  32. {"bool": {"must_not": [{"constant_score": {"filter": {"exists": {"field": "bidopentime"
  33. }
  34. }
  35. }
  36. }
  37. ]}}] }},
  38. {"bool": {"should": [{"range": {"bidendtime": {"gte": ` + fmt.Sprint(nowTime) + `}}},
  39. {
  40. "bool": {
  41. "must_not": [
  42. {
  43. "constant_score": {
  44. "filter": {
  45. "exists": {
  46. "field": "bidendtime"
  47. }
  48. }
  49. }
  50. }
  51. ]
  52. }
  53. }
  54. ] }}]}},
  55. "size": 500
  56. }`
  57. projectResult := elastic.Get(IndexProjectSet, TypeProjectSet, query)
  58. return projectResult
  59. }
  60. // GetProjectByInfoId 根据信息id查询项目id
  61. func GetProjectByInfoId(infoIds []string) *[]map[string]interface{} {
  62. if len(infoIds) == 0 {
  63. return nil
  64. }
  65. query := `{"_source":["_id","list.infoid","ids","bidopentime","bidendtime"],"query":{"bool":{"must":[{"terms":{"list.infoid":["` + strings.Join(infoIds, "\",\"") + `"]}}]}}}`
  66. projectResult := elastic.Get(IndexProjectSet, TypeProjectSet, query)
  67. return projectResult
  68. }
  69. // GetBidInfoByPId 根据项目id查询招标信息id
  70. func GetBidInfoByPId(infoId string) *[]map[string]interface{} {
  71. query := `{
  72. "query": {
  73. "bool": {
  74. "must": [
  75. {
  76. "term": {
  77. "projectset.id": "` + infoId + `"
  78. }
  79. }
  80. ]
  81. }
  82. },
  83. "from": 0,
  84. "size": 1,
  85. "sort": [],
  86. "facets": {}
  87. }`
  88. projectResult := elastic.Get(IndexProjectSet, TypeProjectSet, query)
  89. return projectResult
  90. }
  91. func GetProjectNameByProjectId(projectId []string) *[]map[string]interface{} {
  92. projectQuery := `{
  93. "query": {
  94. "bool": {
  95. "must": [
  96. {
  97. "terms": {
  98. "_id": [
  99. "` + strings.Join(projectId, "\",\"") + `"
  100. ]
  101. }
  102. }
  103. ]
  104. }
  105. },
  106. "_source": [
  107. "_id",
  108. "projectname"
  109. ],"size":%d
  110. }`
  111. projectQuery = fmt.Sprintf(projectQuery, len(projectId))
  112. projectResult := elastic.Get(IndexProjectSet, TypeProjectSet, projectQuery)
  113. return projectResult
  114. }