Browse Source

feat:xiugai

wangchuanjin 1 year ago
parent
commit
e20508699e
1 changed files with 51 additions and 38 deletions
  1. 51 38
      src/jfw/modules/subscribepay/src/service/network.go

+ 51 - 38
src/jfw/modules/subscribepay/src/service/network.go

@@ -8,11 +8,11 @@ import (
 	"log"
 	"net/http"
 	"strings"
+	"sync"
 
 	qutil "app.yhyue.com/moapp/jybase/common"
-	"app.yhyue.com/moapp/jybase/encrypt"
-	"app.yhyue.com/moapp/jybase/es"
 	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+	"app.yhyue.com/moapp/jybase/redis"
 	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/dataexport"
 )
 
@@ -26,46 +26,35 @@ func (n *Network) ProjectExport() {
 	if export_id == "" {
 		return
 	}
+	export_id = redis.GetStr("newother", fmt.Sprintf("network_export_%s", export_id))
 	args := []interface{}{}
-	for _, v := range strings.Split(encrypt.SE.DecodeStringByCheck(export_id), ",") {
+	wh, bIds := []string{}, []string{}
+	pool := make(chan bool, 3)
+	wait := &sync.WaitGroup{}
+	lock := &sync.Mutex{}
+	for _, v := range strings.Split(export_id, ",") {
 		args = append(args, v)
-	}
-	rows, err := util.ClickhouseConn.Query(context.Background(), `select project_id,business_type from information.transaction_info where project_id=?`, args...)
-	if err != nil {
-		log.Println(err)
-		return
-	}
-	bIds := []string{}
-	pIds := []string{}
-	for rows.Next() {
-		var (
-			project_id    string
-			business_type string
-		)
-		if err := rows.Scan(&project_id, &business_type); err != nil {
-			log.Println(err)
-			continue
+		wh = append(wh, "?")
+		if len(args) == 200 {
+			pool <- true
+			wait.Add(1)
+			go func(wh1 []string, args1 []interface{}) {
+				defer func() {
+					<-pool
+					wait.Done()
+				}()
+				ids := n.search(wh1, args1)
+				lock.Lock()
+				bIds = append(bIds, ids...)
+				lock.Unlock()
+			}(wh, args)
+			args = []interface{}{}
+			wh = []string{}
 		}
-		if business_type == "采购意向" {
-			bIds = append(bIds, project_id)
-		} else {
-			pIds = append(pIds, project_id)
-		}
-	}
-	rows.Close()
-	if err := rows.Err(); err != nil {
-		log.Println(err)
 	}
-	if len(pIds) > 0 {
-		datas := es.VarEs.Get("projectset", "projectset", fmt.Sprintf(`{"query":{"bool":{"filter":{"terms":{"id":["%s"]}}}},"_source":["ids"]}`, strings.Join(pIds, `","`)))
-		if datas != nil {
-			for _, v := range *datas {
-				ids, _ := v["ids"].([]interface{})
-				for _, vv := range ids {
-					bIds = append(bIds, fmt.Sprint(vv))
-				}
-			}
-		}
+	wait.Wait()
+	if len(args) > 0 {
+		bIds = append(bIds, n.search(wh, args)...)
 	}
 	if len(bIds) == 0 {
 		return
@@ -95,3 +84,27 @@ func (n *Network) ProjectExport() {
 		return
 	}
 }
+
+func (n *Network) search(wh []string, args []interface{}) []string {
+	bIds := []string{}
+	rows, err := util.ClickhouseConn.Query(context.Background(), `select info_ids from information.transaction_info where project_id in (`+strings.Join(wh, ",")+`)`, args...)
+	if err != nil {
+		log.Println(err)
+		return bIds
+	}
+	for rows.Next() {
+		var (
+			info_ids []string
+		)
+		if err := rows.Scan(&info_ids); err != nil {
+			log.Println(err)
+			continue
+		}
+		bIds = append(bIds, info_ids...)
+	}
+	rows.Close()
+	if err := rows.Err(); err != nil {
+		log.Println(err)
+	}
+	return bIds
+}