prListService.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/encrypt"
  5. elastic "app.yhyue.com/moapp/jybase/es"
  6. "app.yhyue.com/moapp/jybase/mongodb"
  7. T "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
  8. "bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
  9. "fmt"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. "strings"
  12. )
  13. var (
  14. esQ1 = `{"query": {"bool": {"must": [{"terms": {"buyer": ["%s"]}},{"terms": {"toptype": ["采购意向","预告","招标"]}}], "should": [%s], "minimum_should_match": 1}}, "_source": ["%s"], "sort": {"comeintime": {"order": "desc"}}, "from": %d, "size": %d}`
  15. esQ2 = `{"query": {"bool": {"must": [{"terms": {"buyer": ["%s"]}},{"terms": {"toptype": ["采购意向","预告","招标"]}}]}}, "_source": ["%s"], "sort": {"comeintime": {"order": "desc"}}, "from": %d, "size": %d}`
  16. shouldMul = `{"multi_match": {"query": "%s","type": "phrase", "fields": ["s_topscopeclass"]}}`
  17. fields = []string{"_id", "title", "publishtime", "dataweight", "detail", "site", "spidercode", "toptype", "subtype", "type", "area", "city", "district", "s_topscopeclass", "s_subscopeclass", "bidamount", "budget", "buyerclass", "buyer", "winner", "bidopentime", "buyertel", "buyerperson", "agency", "agencytel", "agencyperson", "s_winner", "winnertel", "winnerperson", "signendtime", "bidendtime", "projectinfo", "entidlist"}
  18. )
  19. func GetMonitorList(req *types.PrMonitorListReq) (resultList []map[string]interface{}, total int64, hasMonitor bool) {
  20. bList, b := T.Mgo.Find("follow_customer", map[string]interface{}{"userId": req.UserId}, `{_id: 1}`, nil, false, -1, -1)
  21. if b && len(*bList) > 0 {
  22. hasMonitor = true
  23. var bName []string
  24. for _, v := range *bList {
  25. if name := common.ObjToString(v["name"]); name != "" {
  26. bName = append(bName, name)
  27. }
  28. }
  29. pageStart := (req.PageNum - 1) * req.PageSize
  30. esQuery1 := ""
  31. scopeClass := FindBusiness(req.EntId, req.UserId)
  32. if scopeClass != "" {
  33. var should []string
  34. for _, v := range strings.Split(scopeClass, ",") {
  35. should = append(should, fmt.Sprintf(shouldMul, v))
  36. }
  37. esQuery1 = fmt.Sprintf(esQ1, strings.ReplaceAll(strings.Join(bName, ","), ",", `","`), strings.Join(should, ","), strings.ReplaceAll(strings.Join(fields, ","), ",", `","`), pageStart, req.PageSize)
  38. logx.Info("esQuery1---", esQuery1)
  39. total, result := elastic.GetWithCount("bidding", "bidding", "", esQuery1)
  40. if total == 0 {
  41. return nil, 0, hasMonitor
  42. }
  43. for _, m := range *result {
  44. resultList = append(resultList, GetInfoData(m))
  45. }
  46. return resultList, total, hasMonitor
  47. }
  48. return nil, 0, hasMonitor
  49. } else {
  50. return nil, 0, false
  51. }
  52. }
  53. func GetCollectList(req *types.PrCollectListReq) (resultList []map[string]interface{}, total int64, has bool) {
  54. scopeClass := FindBusiness(req.EntId, req.MgoUserId)
  55. info := T.JianyuMysql.Find("bdcollection", map[string]interface{}{"userid": req.UserId}, "", "id desc", -1, -1)
  56. var ids []interface{}
  57. if info == nil || len(*info) == 0 {
  58. return make([]map[string]interface{}, 0), 0, false
  59. }
  60. has = true
  61. for _, m := range *info {
  62. if bid := common.ObjToString(m["bid"]); bid != "" {
  63. ids = append(ids, mongodb.StringTOBsonId(bid))
  64. }
  65. }
  66. if len(ids) > 200 {
  67. ids = ids[:200]
  68. }
  69. fs := make(map[string]interface{})
  70. for _, f := range fields {
  71. fs[f] = 1
  72. }
  73. binfo, b := T.MgoBidding.Find("bidding", map[string]interface{}{"_id": map[string]interface{}{"$in": ids}}, `{_id: 1}`, fs, false, -1, -1)
  74. if b && len(*binfo) > 0 {
  75. for _, m := range *binfo {
  76. if tp := common.ObjToString(m["toptype"]); tp == "采购意向" || tp == "预告" || tp == "招标" {
  77. for _, s := range strings.Split(scopeClass, ",") {
  78. if top := common.ObjToString(m["s_topscopeclass"]); strings.Contains(top, s) {
  79. m["_id"] = mongodb.BsonIdToSId(m["_id"])
  80. resultList = append(resultList, GetInfoData(m))
  81. break
  82. }
  83. }
  84. }
  85. }
  86. }
  87. total = int64(len(resultList))
  88. start := (req.PageNum - 1) * req.PageSize
  89. end := start + req.PageSize
  90. // 处理边界情况
  91. if start >= len(resultList) {
  92. return make([]map[string]interface{}, 0), total, has
  93. }
  94. if end > len(resultList) {
  95. end = len(resultList)
  96. }
  97. return resultList[start:end], total, has
  98. }
  99. func GetInfoData(m map[string]interface{}) (result map[string]interface{}) {
  100. result = make(map[string]interface{})
  101. result["_id"] = encrypt.CommonEncodeArticle("content", common.ObjToString(m["_id"]))
  102. result["title"] = m["title"]
  103. result["toptype"] = m["toptype"]
  104. result["subtype"] = m["subtype"]
  105. result["publishtime"] = m["publishtime"]
  106. if len(common.ObjToString(m["detail"])) > 200 {
  107. result["detail"] = strings.ReplaceAll(common.ObjToString(m["detail"])[:200], " ", "")
  108. } else {
  109. result["detail"] = strings.ReplaceAll(common.ObjToString(m["detail"]), " ", "")
  110. }
  111. result["site"] = m["site"]
  112. result["spidercode"] = m["spidercode"]
  113. result["area"] = m["area"]
  114. if m["city"] != nil {
  115. result["city"] = m["city"]
  116. }
  117. if m["district"] != nil {
  118. result["district"] = m["district"]
  119. }
  120. result["s_subscopeclass"] = m["s_subscopeclass"]
  121. if m["budget"] != nil {
  122. result["budget"] = m["budget"]
  123. }
  124. if m["buyerclass"] != nil {
  125. result["buyerClass"] = m["buyerclass"]
  126. }
  127. if m["buyer"] != nil {
  128. result["buyer"] = m["buyer"]
  129. if m["buyertel"] != nil {
  130. result["buyerTel"] = m["buyertel"]
  131. }
  132. if m["buyerperson"] != nil {
  133. result["buyerPerson"] = m["buyerperson"]
  134. }
  135. }
  136. if m["agency"] != nil {
  137. result["agency"] = m["agency"]
  138. if m["agencytel"] != nil {
  139. result["agencyTel"] = m["agencytel"]
  140. }
  141. if m["agencyperson"] != nil {
  142. result["agencyPerson"] = m["agencyperson"]
  143. }
  144. }
  145. if m["bidopentime"] != nil {
  146. result["bidOpenTime"] = m["bidopentime"]
  147. }
  148. if m["bidendtime"] != nil {
  149. result["bidEndTime"] = m["bidendtime"]
  150. }
  151. return
  152. }