prListService.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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", "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, resultList = elastic.GetWithCount("bidding", "bidding", "", esQuery1)
  41. for _, m := range *resultList {
  42. m["_id"] = encrypt.CommonEncodeArticle("content", common.ObjToString(m["_id"]))
  43. }
  44. return
  45. } else {
  46. return nil, 0
  47. }
  48. }
  49. func GetCollectList(req *types.PrCollectListReq) (resultList []map[string]interface{}, total int64) {
  50. scopeClass := FindBusiness(req.EntId, req.MgoUserId)
  51. info := T.JianyuMysql.Find("bdcollection", map[string]interface{}{"userid": req.UserId}, "", "id desc", -1, -1)
  52. var ids []interface{}
  53. if info == nil || len(*info) == 0 {
  54. return make([]map[string]interface{}, 0), 0
  55. }
  56. for _, m := range *info {
  57. if bid := common.ObjToString(m["bid"]); bid != "" {
  58. ids = append(ids, mongodb.StringTOBsonId(bid))
  59. }
  60. }
  61. logx.Info("scopeClass---", scopeClass)
  62. logx.Info("ids---", ids)
  63. if len(ids) > 200 {
  64. ids = ids[:200]
  65. }
  66. fs := make(map[string]interface{})
  67. for _, f := range fields {
  68. fs[f] = 1
  69. }
  70. binfo, b := T.MgoBidding.Find("bidding", map[string]interface{}{"$in": ids}, `{_id: 1}`, fs, false, -1, -1)
  71. if b && len(*binfo) > 0 {
  72. for _, m := range *binfo {
  73. if tp := common.ObjToString(m["toptype"]); tp == "采购意向" || tp == "预告" || tp == "招标" {
  74. for _, s := range strings.Split(scopeClass, ",") {
  75. if top := common.ObjToString("s_topscopeclass"); strings.Contains(top, s) {
  76. m["_id"] = encrypt.CommonEncodeArticle("content", common.ObjToString(m["_id"]))
  77. resultList = append(resultList, m)
  78. break
  79. }
  80. }
  81. }
  82. }
  83. }
  84. total = int64(len(resultList))
  85. start := (req.PageNum - 1) * req.PageSize
  86. end := start + req.PageSize
  87. // 处理边界情况
  88. if start >= len(resultList) {
  89. return make([]map[string]interface{}, 0), total
  90. }
  91. if end > len(resultList) {
  92. end = len(resultList)
  93. }
  94. return resultList[start:end], total
  95. }