Bladeren bron

fix:回退

duxin 2 jaren geleden
bovenliggende
commit
5b4592c1f6
2 gewijzigde bestanden met toevoegingen van 161 en 134 verwijderingen
  1. 2 0
      jyBXSubscribe/rpc/internal/logic/bypushhistorylogic.go
  2. 159 134
      jyBXSubscribe/rpc/model/push.go

+ 2 - 0
jyBXSubscribe/rpc/internal/logic/bypushhistorylogic.go

@@ -55,6 +55,7 @@ func (l *ByPushHistoryLogic) ByPushHistory(in *bxsubscribe.SubscribeInfosReq) (*
 		BaseServiceMysql: IC.BaseServiceMysql,
 		IsEnt:            in.IsEnt,
 	}
+	logx.Info("数据导出查询参数", in)
 	if selectIds := strings.TrimSpace(in.SelectIds); selectIds != "" {
 		//encodeArr := strings.Split(selectIds, ",")
 		//idArr := make([]string, 0, len(encodeArr))
@@ -65,6 +66,7 @@ func (l *ByPushHistoryLogic) ByPushHistory(in *bxsubscribe.SubscribeInfosReq) (*
 		//}
 		spqp.SelectInfoIds = strings.Split(selectIds, ",")
 	}
+
 	_, _, list := model.NewSubscribePush(vipType).Datas(spqp)
 	if list == nil || len(list) == 0 {
 		return &bxsubscribe.ByPushHistoryResp{

+ 159 - 134
jyBXSubscribe/rpc/model/push.go

@@ -267,7 +267,7 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
 			result = subPush.Datas[start:end]
 		}
 		total = int64(length)
-	} else if spqp.IsEmpty() && (spqp.PageNum-1)*spqp.PageSize < 250 { //全部,没有过滤条件 之前缓存5页*50条=250
+	} else if spqp.IsEmpty() && (spqp.PageNum-1)*spqp.PageSize < 250 && len(spqp.SelectInfoIds) == 0 { //全部,没有过滤条件 之前缓存5页*50条=250
 		logx.Info("a2:", s.allKey(spqp.UserId))
 		allCache := &SubPush{}
 		var err error
@@ -313,157 +313,169 @@ func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total
 
 func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, endtime int64, size int, isLimit bool) (result []*bxsubscribe.SubscribeInfo, count int64) {
 	querys := []string{}
-	if spqp.IsEnt {
-		querys = []string{fmt.Sprintf("a.entid='%s'", spqp.EntId)}
+	var (
+		searchSql, findSql string
+	)
+	if spqp.SelectInfoIds != nil && len(spqp.SelectInfoIds) > 0 {
+		searchSql = fmt.Sprintf(" from %s a LEFT JOIN %s b ON a.infoid = b.infoid where %s order by a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, fmt.Sprintf("a.id in ('%s')", strings.Join(spqp.SelectInfoIds, "','")))
+		fmt.Println("searchSql", searchSql)
+		//查询总数
+		count = spqp.BaseServiceMysql.CountBySql(fmt.Sprintf("select count(a.id)" + searchSql))
+		findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
 	} else {
-		querys = []string{fmt.Sprintf("a.userid='%s'", common.If(s.ModuleFlag == "eType", spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))}
+		if spqp.IsEnt {
+			querys = []string{fmt.Sprintf("a.entid='%s'", spqp.EntId)}
+		} else {
+			querys = []string{fmt.Sprintf("a.userid='%s'", common.If(s.ModuleFlag == "eType", spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))}
 
-	}
-	codeMap, err := IC.CodeLib.CodeTransformation(context.Background(), &codeservice.Request{})
-	if codeMap.Data == nil || err != nil {
-		logx.Error("代码表获取失败")
-		return result, count
-	}
-	//时间
-	if starttime > 0 && endtime > 0 {
-		querys = append(querys, fmt.Sprintf("a.date>=%d and date<=%d", starttime, endtime))
-	} else if starttime > 0 && endtime == 0 {
-		querys = append(querys, fmt.Sprintf("a.date>=%d", starttime))
-	} else if starttime == 0 && endtime > 0 {
-		querys = append(querys, fmt.Sprintf("a.date<=%d", endtime))
-	}
-	if spqp.Area != "" || spqp.City != "" {
-		var sqlAreaCity = ""
-		//城市
-		city := []string{}
-		for _, v := range strings.Split(spqp.City, ",") {
-			if codeMap.Data.City[v] != "" {
-				city = append(city, fmt.Sprint(codeMap.Data.City[v]))
-			} else {
-				city = append(city, "-1")
-			}
-		}
-		if len(city) == 1 {
-			city = append(city, "9999")
-		}
-		if len(city) > 0 {
-			sqlAreaCity = fmt.Sprintf("b.city_code in (%s)", strings.Join(city, ","))
 		}
-		//区域
-		var sqlArea = ""
-		area := []string{}
-		for _, v := range strings.Split(spqp.Area, ",") {
-			if codeMap.Data.Area[v] != "" {
-				area = append(area, fmt.Sprint(codeMap.Data.Area[v]))
-			} else {
-				area = append(area, "-1")
+		codeMap, err := IC.CodeLib.CodeTransformation(context.Background(), &codeservice.Request{})
+		if codeMap.Data == nil || err != nil {
+			logx.Error("代码表获取失败")
+			return result, count
+		}
+		//时间
+		logx.Info("starttime,endtime", starttime, endtime)
+		if starttime > 0 && endtime > 0 {
+			querys = append(querys, fmt.Sprintf("a.date>=%d and date<=%d", starttime, endtime))
+		} else if starttime > 0 && endtime == 0 {
+			querys = append(querys, fmt.Sprintf("a.date>=%d", starttime))
+		} else if starttime == 0 && endtime > 0 {
+			querys = append(querys, fmt.Sprintf("a.date<=%d", endtime))
+		}
+		if spqp.Area != "" || spqp.City != "" {
+			var sqlAreaCity = ""
+			//城市
+			city := []string{}
+			for _, v := range strings.Split(spqp.City, ",") {
+				if codeMap.Data.City[v] != "" {
+					city = append(city, fmt.Sprint(codeMap.Data.City[v]))
+				} else {
+					city = append(city, "-1")
+				}
 			}
-		}
-		if len(area) == 1 {
-			area = append(area, "9999")
-		}
-		if len(area) > 0 {
-			sqlArea = fmt.Sprintf("b.area_code in (%s)", strings.Join(area, ","))
-		}
-		if sqlAreaCity != "" && sqlArea != "" {
-			sqlAreaCity = "( " + sqlAreaCity + " or " + sqlArea + " )"
-		} else if sqlAreaCity == "" && sqlArea != "" {
-			sqlAreaCity = sqlArea
-		}
-		if sqlAreaCity != "" {
-			querys = append(querys, sqlAreaCity)
-		}
-	}
-	//采购单位行业
-	if spqp.Buyerclass != "" {
-		buyerclass := []string{}
-		for _, v := range strings.Split(spqp.Buyerclass, ",") {
-			if codeMap.Data.Buyerclass[v] != "" {
-				buyerclass = append(buyerclass, fmt.Sprint(codeMap.Data.Buyerclass[v]))
+			if len(city) == 1 {
+				city = append(city, "9999")
+			}
+			if len(city) > 0 {
+				sqlAreaCity = fmt.Sprintf("b.city_code in (%s)", strings.Join(city, ","))
+			}
+			//区域
+			var sqlArea = ""
+			area := []string{}
+			for _, v := range strings.Split(spqp.Area, ",") {
+				if codeMap.Data.Area[v] != "" {
+					area = append(area, fmt.Sprint(codeMap.Data.Area[v]))
+				} else {
+					area = append(area, "-1")
+				}
+			}
+			if len(area) == 1 {
+				area = append(area, "9999")
+			}
+			if len(area) > 0 {
+				sqlArea = fmt.Sprintf("b.area_code in (%s)", strings.Join(area, ","))
+			}
+			if sqlAreaCity != "" && sqlArea != "" {
+				sqlAreaCity = "( " + sqlAreaCity + " or " + sqlArea + " )"
+			} else if sqlAreaCity == "" && sqlArea != "" {
+				sqlAreaCity = sqlArea
+			}
+			if sqlAreaCity != "" {
+				querys = append(querys, sqlAreaCity)
 			}
 		}
-		if len(buyerclass) == 1 {
-			buyerclass = append(buyerclass, "9999")
-		}
-		if len(buyerclass) > 0 {
-			querys = append(querys, fmt.Sprintf("b.buyerclass_code in (%s)", strings.Join(buyerclass, ",")))
-		}
-
-	}
-	//信息类型
-	if spqp.Subtype != "" {
-		subtype := []string{}
-		for _, v := range strings.Split(spqp.Subtype, ",") {
-			if codeMap.Data.Subtype[v] != "" {
-				subtype = append(subtype, fmt.Sprint(codeMap.Data.Subtype[v]))
+		//采购单位行业
+		if spqp.Buyerclass != "" {
+			buyerclass := []string{}
+			for _, v := range strings.Split(spqp.Buyerclass, ",") {
+				if codeMap.Data.Buyerclass[v] != "" {
+					buyerclass = append(buyerclass, fmt.Sprint(codeMap.Data.Buyerclass[v]))
+				}
+			}
+			if len(buyerclass) == 1 {
+				buyerclass = append(buyerclass, "9999")
+			}
+			if len(buyerclass) > 0 {
+				querys = append(querys, fmt.Sprintf("b.buyerclass_code in (%s)", strings.Join(buyerclass, ",")))
 			}
 
 		}
-		if len(subtype) == 1 {
-			subtype = append(subtype, "9999")
-		}
-		if len(subtype) > 0 {
-			querys = append(querys, fmt.Sprintf("b.subtype_code in (%s)", strings.Join(subtype, ",")))
-		}
+		//信息类型
+		if spqp.Subtype != "" {
+			subtype := []string{}
+			for _, v := range strings.Split(spqp.Subtype, ",") {
+				if codeMap.Data.Subtype[v] != "" {
+					subtype = append(subtype, fmt.Sprint(codeMap.Data.Subtype[v]))
+				}
 
-	}
-	//信息行业
-	if spqp.Subscopeclass != "" {
-		find_in_set := []string{}
-		for _, v := range strings.Split(spqp.Subscopeclass, ",") {
-			if codeMap.Data.Subscopeclass[v] != "" {
-				find_in_set = append(find_in_set, codeMap.Data.Subscopeclass[v])
+			}
+			if len(subtype) == 1 {
+				subtype = append(subtype, "9999")
+			}
+			if len(subtype) > 0 {
+				querys = append(querys, fmt.Sprintf("b.subtype_code in (%s)", strings.Join(subtype, ",")))
 			}
 
 		}
-		if len(find_in_set) == 1 {
-			querys = append(querys, find_in_set[0])
-		} else if len(find_in_set) > 1 {
-			querys = append(querys, fmt.Sprintf(" t.labelvalues in (%s)", strings.Join(find_in_set, ",")))
-		}
-	}
-	//关键词
-	if spqp.Key != "" {
-		find_in_set := []string{}
-		for _, v := range strings.Split(spqp.Key, ",") {
-			find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%s',replace(replace(a.matchkeys,'+',','),' ',','))", v))
+		//信息行业
+		if spqp.Subscopeclass != "" {
+			find_in_set := []string{}
+			for _, v := range strings.Split(spqp.Subscopeclass, ",") {
+				if codeMap.Data.Subscopeclass[v] != "" {
+					find_in_set = append(find_in_set, codeMap.Data.Subscopeclass[v])
+				}
+
+			}
+			if len(find_in_set) == 1 {
+				querys = append(querys, find_in_set[0])
+			} else if len(find_in_set) > 1 {
+				querys = append(querys, fmt.Sprintf(" t.labelvalues in (%s)", strings.Join(find_in_set, ",")))
+			}
 		}
-		if len(find_in_set) == 1 {
-			querys = append(querys, find_in_set[0])
-		} else if len(find_in_set) > 1 {
-			querys = append(querys, fmt.Sprintf("(%s)", strings.Join(find_in_set, " or ")))
+		//关键词
+		if spqp.Key != "" {
+			find_in_set := []string{}
+			for _, v := range strings.Split(spqp.Key, ",") {
+				find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%s',replace(replace(a.matchkeys,'+',','),' ',','))", v))
+			}
+			if len(find_in_set) == 1 {
+				querys = append(querys, find_in_set[0])
+			} else if len(find_in_set) > 1 {
+				querys = append(querys, fmt.Sprintf("(%s)", strings.Join(find_in_set, " or ")))
+			}
 		}
-	}
-	//价格- 预算和中标金额
-	if spqp.Price != "" && strings.Contains(spqp.Price, "-") {
-		minPriceStr, maxPriceStr := strings.Split(spqp.Price, "-")[0], strings.Split(spqp.Price, "-")[1]
-		minPrice := common.Int64All(common.Float64All(minPriceStr) * 10000) //换成元
-		maxPrice := common.Int64All(common.Float64All(maxPriceStr) * 10000) //换成元
-		if minPriceStr != "" && maxPriceStr != "" {
-			querys = append(querys, fmt.Sprintf("((b.bidamount>=%d and b.bidamount<=%d) or (b.budget>=%d and b.budget<=%d and b.bidamount is null))", minPrice, maxPrice, minPrice, maxPrice))
-		} else if minPriceStr != "" {
-			querys = append(querys, fmt.Sprintf("(b.bidamount>=%d  or (b.budget>=%d and b.bidamount is null))", minPrice, minPrice))
-		} else if maxPriceStr != "" {
-			querys = append(querys, fmt.Sprintf("(b.bidamount<=%d or (b.budget<=%d and b.bidamount is null))", maxPrice, maxPrice))
+		//价格- 预算和中标金额
+		if spqp.Price != "" && strings.Contains(spqp.Price, "-") {
+			minPriceStr, maxPriceStr := strings.Split(spqp.Price, "-")[0], strings.Split(spqp.Price, "-")[1]
+			minPrice := common.Int64All(common.Float64All(minPriceStr) * 10000) //换成元
+			maxPrice := common.Int64All(common.Float64All(maxPriceStr) * 10000) //换成元
+			if minPriceStr != "" && maxPriceStr != "" {
+				querys = append(querys, fmt.Sprintf("((b.bidamount>=%d and b.bidamount<=%d) or (b.budget>=%d and b.budget<=%d and b.bidamount is null))", minPrice, maxPrice, minPrice, maxPrice))
+			} else if minPriceStr != "" {
+				querys = append(querys, fmt.Sprintf("(b.bidamount>=%d  or (b.budget>=%d and b.bidamount is null))", minPrice, minPrice))
+			} else if maxPriceStr != "" {
+				querys = append(querys, fmt.Sprintf("(b.bidamount<=%d or (b.budget<=%d and b.bidamount is null))", maxPrice, maxPrice))
+			}
 		}
-	}
-	//附件
-	if spqp.FileExists != "" {
-		if spqp.FileExists == "1" {
-			querys = append(querys, fmt.Sprintf("b.isvalidfile =1 "))
-		} else if spqp.FileExists == "-1" {
-			querys = append(querys, fmt.Sprintf("b.isvalidfile =0 "))
+		//附件
+		if spqp.FileExists != "" {
+			if spqp.FileExists == "1" {
+				querys = append(querys, fmt.Sprintf("b.isvalidfile =1 "))
+			} else if spqp.FileExists == "-1" {
+				querys = append(querys, fmt.Sprintf("b.isvalidfile =0 "))
+			}
 		}
+		searchSql = fmt.Sprintf(" from %s  a LEFT JOIN %s b ON a.infoid = b.infoid LEFT JOIN %s t on t.infoid = b.infoid and t.labelcode=2  where %s"+
+			" order by a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, BidTags, strings.Join(querys, " and "))
+		fmt.Println("searchSql", searchSql)
+		//查询总数
+		count = spqp.BaseServiceMysql.CountBySql(fmt.Sprintf("select count(a.id)" + searchSql))
+		logx.Info("count:", count, "---", s.ModuleFlag)
+		findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
 	}
-	searchSql := fmt.Sprintf(" from %s  a LEFT JOIN %s b ON a.infoid = b.infoid LEFT JOIN %s t on t.infoid = b.infoid and t.labelcode=2  where %s"+
-		" order by a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, BidTags, strings.Join(querys, " and "))
-	fmt.Println("searchSql", searchSql)
-	//查询总数
-	count = spqp.BaseServiceMysql.CountBySql(fmt.Sprintf("select count(a.id)" + searchSql))
-	logx.Info("count:", count, "---", s.ModuleFlag)
-	findSql := "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
 	if s.ModuleFlag != MemberFlag && s.ModuleFlag != EntnicheFlag {
-		findSql += ",isvip"
+		findSql += ",a.isvip"
 	}
 	findSql += searchSql
 	if isLimit {
@@ -473,13 +485,26 @@ func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, en
 	list := spqp.BaseServiceMysql.SelectBySql(findSql)
 	if list != nil && len(*list) > 0 {
 		pushCas := s.GetJyPushs(*list)
-		result = s.GetInfoByIds(spqp.Mgo_bidding, spqp.Bidding, spqp.Bidding_back, pushCas)
+		if !spqp.Export {
+			result = s.GetInfoByIds(spqp.Mgo_bidding, spqp.Bidding, spqp.Bidding_back, pushCas)
+		} else {
+			result = s.GetOnlyExportInfo(pushCas)
+		}
 	} else {
 		result = []*bxsubscribe.SubscribeInfo{}
 	}
 	return
 }
 
+// GetOnlyInfoId 获取信息id
+func (s *subscribePush) GetOnlyExportInfo(pushCas []*PushCa) []*bxsubscribe.SubscribeInfo {
+	array := make([]*bxsubscribe.SubscribeInfo, len(pushCas))
+	for k, v := range pushCas {
+		array[k] = &bxsubscribe.SubscribeInfo{XId: encrypt.EncodeArticleId2ByCheck(v.InfoId), MatchKeys: v.Keys}
+	}
+	return array
+}
+
 // 根据id取内容
 func (s *subscribePush) GetInfoByIds(Mgo_bidding mongodb.MongodbSim, bidding, bidding_back string, pushCas []*PushCa) []*bxsubscribe.SubscribeInfo {
 	array := make([]*bxsubscribe.SubscribeInfo, len(pushCas))