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", "district", "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, hasMonitor bool) { bList, b := T.Mgo.Find("follow_customer", map[string]interface{}{"userId": req.UserId}, `{_id: 1}`, nil, false, -1, -1) if b && len(*bList) > 0 { hasMonitor = true 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.UserId) 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, ","), ",", `","`), strings.Join(should, ","), strings.ReplaceAll(strings.Join(fields, ","), ",", `","`), pageStart, req.PageSize) logx.Info("esQuery1---", esQuery1) total, result := elastic.GetWithCount("bidding", "bidding", "", esQuery1) if total == 0 { return nil, 0, hasMonitor } for _, m := range *result { resultList = append(resultList, GetInfoData(m)) } return resultList, total, hasMonitor } return nil, 0, hasMonitor } else { return nil, 0, false } } func GetCollectList(req *types.PrCollectListReq) (resultList []map[string]interface{}, total int64, has bool) { 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, false } has = true for _, m := range *info { if bid := common.ObjToString(m["bid"]); bid != "" { ids = append(ids, mongodb.StringTOBsonId(bid)) } } 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{}{"_id": 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(m["s_topscopeclass"]); strings.Contains(top, s) { m["_id"] = mongodb.BsonIdToSId(m["_id"]) resultList = append(resultList, GetInfoData(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, has } if end > len(resultList) { end = len(resultList) } return resultList[start:end], total, has } func GetInfoData(m map[string]interface{}) (result map[string]interface{}) { result = make(map[string]interface{}) result["_id"] = encrypt.CommonEncodeArticle("content", common.ObjToString(m["_id"])) result["title"] = m["title"] result["toptype"] = m["toptype"] result["subtype"] = m["subtype"] result["publishtime"] = m["publishtime"] if len(common.ObjToString(m["detail"])) > 200 { result["detail"] = strings.ReplaceAll(common.ObjToString(m["detail"])[:200], " ", "") } else { result["detail"] = strings.ReplaceAll(common.ObjToString(m["detail"]), " ", "") } result["site"] = m["site"] result["spidercode"] = m["spidercode"] result["area"] = m["area"] if m["city"] != nil { result["city"] = m["city"] } if m["district"] != nil { result["district"] = m["district"] } result["s_subscopeclass"] = m["s_subscopeclass"] if m["budget"] != nil { result["budget"] = m["budget"] } if m["buyerclass"] != nil { result["buyerClass"] = m["buyerclass"] } if m["buyer"] != nil { result["buyer"] = m["buyer"] if m["buyertel"] != nil { result["buyerTel"] = m["buyertel"] } if m["buyerperson"] != nil { result["buyerPerson"] = m["buyerperson"] } } if m["agency"] != nil { result["agency"] = m["agency"] if m["agencytel"] != nil { result["agencyTel"] = m["agencytel"] } if m["agencyperson"] != nil { result["agencyPerson"] = m["agencyperson"] } } if m["bidopentime"] != nil { result["bidOpenTime"] = m["bidopentime"] } if m["bidendtime"] != nil { result["bidEndTime"] = m["bidendtime"] } return }