123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package service
- import (
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/encrypt"
- elastic "app.yhyue.com/moapp/jybase/es"
- "app.yhyue.com/moapp/jybase/mongodb"
- T "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
- "bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
- "fmt"
- "github.com/zeromicro/go-zero/core/logx"
- "strings"
- )
- var (
- 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}`
- esQ2 = `{"query": {"bool": {"must": [{"terms": {"buyer": ["%s"]}},{"terms": {"toptype": ["采购意向","预告","招标"]}}]}}, "_source": ["%s"], "sort": {"comeintime": {"order": "desc"}}, "from": %d, "size": %d}`
- shouldMul = `{"multi_match": {"query": "%s","type": "phrase", "fields": ["s_topscopeclass"]}}`
- 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"}
- )
- func GetMonitorList(req *types.PrMonitorListReq) (resultList *[]map[string]interface{}, total int64) {
- bList, b := T.Mgo.Find("follow_customer", map[string]string{"userId": req.MgoUserId}, `{_id: 1}`, nil, false, -1, -1)
- if b && len(*bList) > 0 {
- var bName []string
- for _, v := range *bList {
- if name := common.ObjToString(v["name"]); name != "" {
- bName = append(bName, name)
- }
- }
- pageStart := (req.PageNum - 1) * req.PageSize
- esQuery1 := ""
- scopeClass := FindBusiness(req.EntId, req.MgoUserId)
- if scopeClass != "" {
- var should []string
- for _, v := range strings.Split(scopeClass, ",") {
- should = append(should, fmt.Sprintf(shouldMul, v))
- }
- esQuery1 = fmt.Sprintf(esQ1, strings.ReplaceAll(strings.Join(bName, ","), ",", `","`), should, strings.ReplaceAll(strings.Join(fields, ","), ",", `","`), pageStart, req.PageSize)
- } else {
- esQuery1 = fmt.Sprintf(esQ2, strings.ReplaceAll(strings.Join(bName, ","), ",", `","`), strings.ReplaceAll(strings.Join(fields, ","), ",", `","`), pageStart, req.PageSize)
- }
- total, resultList = elastic.GetWithCount("bidding", "bidding", "", esQuery1)
- for _, m := range *resultList {
- m["_id"] = encrypt.CommonEncodeArticle("content", common.ObjToString(m["_id"]))
- }
- return
- } else {
- return nil, 0
- }
- }
- func GetCollectList(req *types.PrCollectListReq) (resultList []map[string]interface{}, total int64) {
- scopeClass := FindBusiness(req.EntId, req.MgoUserId)
- info := T.JianyuMysql.Find("bdcollection", map[string]interface{}{"userid": req.UserId}, "", "id desc", -1, -1)
- var ids []interface{}
- if info == nil || len(*info) == 0 {
- return make([]map[string]interface{}, 0), 0
- }
- for _, m := range *info {
- if bid := common.ObjToString(m["bid"]); bid != "" {
- ids = append(ids, mongodb.StringTOBsonId(bid))
- }
- }
- logx.Info("scopeClass---", scopeClass)
- logx.Info("ids---", ids)
- if len(ids) > 200 {
- ids = ids[:200]
- }
- fs := make(map[string]interface{})
- for _, f := range fields {
- fs[f] = 1
- }
- binfo, b := T.MgoBidding.Find("bidding", map[string]interface{}{"$in": ids}, `{_id: 1}`, fs, false, -1, -1)
- if b && len(*binfo) > 0 {
- for _, m := range *binfo {
- if tp := common.ObjToString(m["toptype"]); tp == "采购意向" || tp == "预告" || tp == "招标" {
- for _, s := range strings.Split(scopeClass, ",") {
- if top := common.ObjToString("s_topscopeclass"); strings.Contains(top, s) {
- m["_id"] = encrypt.CommonEncodeArticle("content", common.ObjToString(m["_id"]))
- resultList = append(resultList, m)
- break
- }
- }
- }
- }
- }
- total = int64(len(resultList))
- start := (req.PageNum - 1) * req.PageSize
- end := start + req.PageSize
- // 处理边界情况
- if start >= len(resultList) {
- return make([]map[string]interface{}, 0), total
- }
- if end > len(resultList) {
- end = len(resultList)
- }
- return resultList[start:end], total
- }
|