|
@@ -0,0 +1,93 @@
|
|
|
+package service
|
|
|
+
|
|
|
+import (
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
+ 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"
|
|
|
+ "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", "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)
|
|
|
+ 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)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ return nil, 0
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func GetCollectList(req *types.PrCollectListReq) (resultList []map[string]interface{}, total int64) {
|
|
|
+ scopeClass := FindBusiness(req.EntId)
|
|
|
+ info := T.JianyuMysql.Find("bdcollection", map[string]interface{}{"userid": req.UserId}, "", `{id: 1}`, -1, -1)
|
|
|
+ var ids []interface{}
|
|
|
+ for _, m := range *info {
|
|
|
+ if bid := common.ObjToString(m["bid"]); bid != "" {
|
|
|
+ ids = append(ids, mongodb.StringTOBsonId(bid))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(ids) == 0 {
|
|
|
+ return make([]map[string]interface{}, 0), 0
|
|
|
+ }
|
|
|
+ if len(ids) > 100 {
|
|
|
+ ids = ids[:100]
|
|
|
+ }
|
|
|
+ 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) {
|
|
|
+ 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
|
|
|
+}
|