prListService.go 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. "strings"
  11. )
  12. var (
  13. 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}`
  14. esQ2 = `{"query": {"bool": {"must": [{"terms": {"buyer": ["%s"]}},{"terms": {"toptype": ["采购意向","预告","招标"]}}]}}, "_source": ["%s"], "sort": {"comeintime": {"order": "desc"}}, "from": %d, "size": %d}`
  15. shouldMul = `{"multi_match": {"query": "%s","type": "phrase", "fields": ["s_topscopeclass"]}}`
  16. 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"}
  17. )
  18. func GetMonitorList(req *types.PrMonitorListReq) (resultList *[]map[string]interface{}, total int64) {
  19. bList, b := T.Mgo.Find("follow_customer", map[string]string{"userId": req.MgoUserId}, `{_id: 1}`, nil, false, -1, -1)
  20. if b && len(*bList) > 0 {
  21. var bName []string
  22. for _, v := range *bList {
  23. if name := common.ObjToString(v["name"]); name != "" {
  24. bName = append(bName, name)
  25. }
  26. }
  27. pageStart := (req.PageNum - 1) * req.PageSize
  28. esQuery1 := ""
  29. scopeClass := FindBusiness(req.EntId, req.MgoUserId)
  30. if scopeClass != "" {
  31. var should []string
  32. for _, v := range strings.Split(scopeClass, ",") {
  33. should = append(should, fmt.Sprintf(shouldMul, v))
  34. }
  35. esQuery1 = fmt.Sprintf(esQ1, strings.ReplaceAll(strings.Join(bName, ","), ",", `","`), should, strings.ReplaceAll(strings.Join(fields, ","), ",", `","`), pageStart, req.PageSize)
  36. } else {
  37. esQuery1 = fmt.Sprintf(esQ2, strings.ReplaceAll(strings.Join(bName, ","), ",", `","`), strings.ReplaceAll(strings.Join(fields, ","), ",", `","`), pageStart, req.PageSize)
  38. }
  39. total, resultList = elastic.GetWithCount("bidding", "bidding", "", esQuery1)
  40. for _, m := range *resultList {
  41. m["_id"] = encrypt.CommonEncodeArticle("content", common.ObjToString(m["_id"]))
  42. }
  43. return
  44. } else {
  45. return nil, 0
  46. }
  47. }
  48. func GetCollectList(req *types.PrCollectListReq) (resultList []map[string]interface{}, total int64) {
  49. scopeClass := FindBusiness(req.EntId, req.MgoUserId)
  50. info := T.JianyuMysql.Find("bdcollection", map[string]interface{}{"userid": req.UserId}, "", `{id: 1}`, -1, -1)
  51. var ids []interface{}
  52. if info == nil || len(*info) == 0 {
  53. return make([]map[string]interface{}, 0), 0
  54. }
  55. for _, m := range *info {
  56. if bid := common.ObjToString(m["bid"]); bid != "" {
  57. ids = append(ids, mongodb.StringTOBsonId(bid))
  58. }
  59. }
  60. if len(ids) > 100 {
  61. ids = ids[:100]
  62. }
  63. fs := make(map[string]interface{})
  64. for _, f := range fields {
  65. fs[f] = 1
  66. }
  67. binfo, b := T.MgoBidding.Find("bidding", map[string]interface{}{"$in": ids}, `{_id: 1}`, fs, false, -1, -1)
  68. if b && len(*binfo) > 0 {
  69. for _, m := range *binfo {
  70. if tp := common.ObjToString(m["toptype"]); tp == "采购意向" || tp == "预告" || tp == "招标" {
  71. for _, s := range strings.Split(scopeClass, ",") {
  72. if top := common.ObjToString("s_topscopeclass"); strings.Contains(top, s) {
  73. m["_id"] = encrypt.CommonEncodeArticle("content", common.ObjToString(m["_id"]))
  74. resultList = append(resultList, m)
  75. break
  76. }
  77. }
  78. }
  79. }
  80. }
  81. total = int64(len(resultList))
  82. start := (req.PageNum - 1) * req.PageSize
  83. end := start + req.PageSize
  84. // 处理边界情况
  85. if start >= len(resultList) {
  86. return make([]map[string]interface{}, 0), total
  87. }
  88. if end > len(resultList) {
  89. end = len(resultList)
  90. }
  91. return resultList[start:end], total
  92. }