prListService.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. elastic "app.yhyue.com/moapp/jybase/es"
  5. "app.yhyue.com/moapp/jybase/mongodb"
  6. T "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
  7. "bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
  8. "fmt"
  9. "strings"
  10. )
  11. var (
  12. 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}`
  13. esQ2 = `{"query": {"bool": {"must": [{"terms": {"buyer": ["%s"]}},{"terms": {"toptype": ["采购意向","预告","招标"]}}]}}, "_source": ["%s"], "sort": {"comeintime": {"order": "desc"}}, "from": %d, "size": %d}`
  14. shouldMul = `{"multi_match": {"query": "%s","type": "phrase", "fields": ["s_topscopeclass"]}}`
  15. fields = []string{"_id", "title", "publishtime", "dataweight", "toptype", "subtype", "type", "area", "city", "s_topscopeclass", "s_subscopeclass", "bidamount", "budget", "buyerclass", "buyer", "winner", "bidopentime", "buyertel", "buyerperson", "agency", "agencytel", "agencyperson", "s_winner", "winnertel", "winnerperson", "signendtime", "bidendtime", "projectinfo", "entidlist"}
  16. )
  17. func GetMonitorList(req *types.PrMonitorListReq) (resultList *[]map[string]interface{}, total int64) {
  18. bList, b := T.Mgo.Find("follow_customer", map[string]string{"userId": req.MgoUserId}, `{_id: 1}`, nil, false, -1, -1)
  19. if b && len(*bList) > 0 {
  20. var bName []string
  21. for _, v := range *bList {
  22. if name := common.ObjToString(v["name"]); name != "" {
  23. bName = append(bName, name)
  24. }
  25. }
  26. pageStart := (req.PageNum - 1) * req.PageSize
  27. esQuery1 := ""
  28. scopeClass := FindBusiness(req.EntId)
  29. if scopeClass != "" {
  30. var should []string
  31. for _, v := range strings.Split(scopeClass, ",") {
  32. should = append(should, fmt.Sprintf(shouldMul, v))
  33. }
  34. esQuery1 = fmt.Sprintf(esQ1, strings.ReplaceAll(strings.Join(bName, ","), ",", `","`), should, strings.ReplaceAll(strings.Join(fields, ","), ",", `","`), pageStart, req.PageSize)
  35. } else {
  36. esQuery1 = fmt.Sprintf(esQ2, strings.ReplaceAll(strings.Join(bName, ","), ",", `","`), strings.ReplaceAll(strings.Join(fields, ","), ",", `","`), pageStart, req.PageSize)
  37. }
  38. total, resultList = elastic.GetWithCount("bidding", "bidding", "", esQuery1)
  39. return
  40. } else {
  41. return nil, 0
  42. }
  43. }
  44. func GetCollectList(req *types.PrCollectListReq) (resultList []map[string]interface{}, total int64) {
  45. scopeClass := FindBusiness(req.EntId)
  46. info := T.JianyuMysql.Find("bdcollection", map[string]interface{}{"userid": req.UserId}, "", `{id: 1}`, -1, -1)
  47. var ids []interface{}
  48. for _, m := range *info {
  49. if bid := common.ObjToString(m["bid"]); bid != "" {
  50. ids = append(ids, mongodb.StringTOBsonId(bid))
  51. }
  52. }
  53. if len(ids) == 0 {
  54. return make([]map[string]interface{}, 0), 0
  55. }
  56. if len(ids) > 100 {
  57. ids = ids[:100]
  58. }
  59. fs := make(map[string]interface{})
  60. for _, f := range fields {
  61. fs[f] = 1
  62. }
  63. binfo, b := T.MgoBidding.Find("bidding", map[string]interface{}{"$in": ids}, `{_id: 1}`, fs, false, -1, -1)
  64. if b && len(*binfo) > 0 {
  65. for _, m := range *binfo {
  66. if tp := common.ObjToString(m["toptype"]); tp == "采购意向" || tp == "预告" || tp == "招标" {
  67. for _, s := range strings.Split(scopeClass, ",") {
  68. if top := common.ObjToString("s_topscopeclass"); strings.Contains(top, s) {
  69. resultList = append(resultList, m)
  70. break
  71. }
  72. }
  73. }
  74. }
  75. }
  76. total = int64(len(resultList))
  77. start := (req.PageNum - 1) * req.PageSize
  78. end := start + req.PageSize
  79. // 处理边界情况
  80. if start >= len(resultList) {
  81. return make([]map[string]interface{}, 0), total
  82. }
  83. if end > len(resultList) {
  84. end = len(resultList)
  85. }
  86. return resultList[start:end], total
  87. }