prListService.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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) {
  20. bList, b := T.Mgo.Find("follow_customer", map[string]string{"userId": req.MgoUserId}, `{_id: 1}`, nil, false, -1, -1)
  21. if b && len(*bList) > 0 {
  22. var bName []string
  23. for _, v := range *bList {
  24. if name := common.ObjToString(v["name"]); name != "" {
  25. bName = append(bName, name)
  26. }
  27. }
  28. pageStart := (req.PageNum - 1) * req.PageSize
  29. esQuery1 := ""
  30. scopeClass := FindBusiness(req.EntId, req.MgoUserId)
  31. if scopeClass != "" {
  32. var should []string
  33. for _, v := range strings.Split(scopeClass, ",") {
  34. should = append(should, fmt.Sprintf(shouldMul, v))
  35. }
  36. esQuery1 = fmt.Sprintf(esQ1, strings.ReplaceAll(strings.Join(bName, ","), ",", `","`), should, strings.ReplaceAll(strings.Join(fields, ","), ",", `","`), pageStart, req.PageSize)
  37. } else {
  38. esQuery1 = fmt.Sprintf(esQ2, strings.ReplaceAll(strings.Join(bName, ","), ",", `","`), strings.ReplaceAll(strings.Join(fields, ","), ",", `","`), pageStart, req.PageSize)
  39. }
  40. total, result := elastic.GetWithCount("bidding", "bidding", "", esQuery1)
  41. if total == 0 {
  42. return nil, 0
  43. }
  44. for _, m := range *result {
  45. resultList = append(resultList, GetInfoData(m))
  46. }
  47. return
  48. } else {
  49. return nil, 0
  50. }
  51. }
  52. func GetCollectList(req *types.PrCollectListReq) (resultList []map[string]interface{}, total int64) {
  53. scopeClass := FindBusiness(req.EntId, req.MgoUserId)
  54. info := T.JianyuMysql.Find("bdcollection", map[string]interface{}{"userid": req.UserId}, "", "id desc", -1, -1)
  55. var ids []interface{}
  56. if info == nil || len(*info) == 0 {
  57. return make([]map[string]interface{}, 0), 0
  58. }
  59. for _, m := range *info {
  60. if bid := common.ObjToString(m["bid"]); bid != "" {
  61. ids = append(ids, mongodb.StringTOBsonId(bid))
  62. }
  63. }
  64. logx.Info("scopeClass---", scopeClass)
  65. logx.Info("ids---", ids)
  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. resultList = append(resultList, GetInfoData(m))
  80. break
  81. }
  82. }
  83. }
  84. }
  85. }
  86. logx.Info("binfo---", len(*binfo))
  87. logx.Info("resultList---", len(resultList))
  88. total = int64(len(resultList))
  89. start := (req.PageNum - 1) * req.PageSize
  90. end := start + req.PageSize
  91. // 处理边界情况
  92. if start >= len(resultList) {
  93. return make([]map[string]interface{}, 0), total
  94. }
  95. if end > len(resultList) {
  96. end = len(resultList)
  97. }
  98. return resultList[start:end], total
  99. }
  100. func GetInfoData(m map[string]interface{}) (result map[string]interface{}) {
  101. result = make(map[string]interface{})
  102. result["_id"] = encrypt.CommonEncodeArticle("content", common.ObjToString(m["_id"]))
  103. result["title"] = m["title"]
  104. result["toptype"] = m["toptype"]
  105. result["subtype"] = m["subtype"]
  106. result["publishtime"] = m["publishtime"]
  107. if len(common.ObjToString(m["detail"])) > 200 {
  108. result["detail"] = strings.ReplaceAll(common.ObjToString(m["detail"])[:200], " ", "")
  109. } else {
  110. result["detail"] = strings.ReplaceAll(common.ObjToString(m["detail"]), " ", "")
  111. }
  112. result["site"] = m["site"]
  113. result["spidercode"] = m["spidercode"]
  114. result["area"] = m["area"]
  115. if m["city"] != nil {
  116. result["city"] = m["city"]
  117. }
  118. if m["district"] != nil {
  119. result["district"] = m["district"]
  120. }
  121. result["s_subscopeclass"] = m["s_subscopeclass"]
  122. if m["budget"] != nil {
  123. result["budget"] = m["budget"]
  124. }
  125. if m["buyerclass"] != nil {
  126. result["buyerClass"] = m["buyerclass"]
  127. }
  128. if m["buyer"] != nil {
  129. result["buyer"] = m["buyer"]
  130. if m["buyertel"] != nil {
  131. result["buyerTel"] = m["buyertel"]
  132. }
  133. if m["buyerperson"] != nil {
  134. result["buyerPerson"] = m["buyerperson"]
  135. }
  136. }
  137. if m["agency"] != nil {
  138. result["agency"] = m["agency"]
  139. if m["agencytel"] != nil {
  140. result["agencyTel"] = m["agencytel"]
  141. }
  142. if m["agencyperson"] != nil {
  143. result["agencyPerson"] = m["agencyperson"]
  144. }
  145. }
  146. if m["bidopentime"] != nil {
  147. result["bidOpenTime"] = m["bidopentime"]
  148. }
  149. if m["bidendtime"] != nil {
  150. result["bidEndTime"] = m["bidendtime"]
  151. }
  152. return
  153. }