|
@@ -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
|
|
|
}
|
|
|
+ exportIds := 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(exportIds, ",") {
|
|
|
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
|
|
|
- }
|
|
|
- if business_type == "采购意向" {
|
|
|
- bIds = append(bIds, project_id)
|
|
|
- } else {
|
|
|
- pIds = append(pIds, project_id)
|
|
|
+ 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{}
|
|
|
}
|
|
|
}
|
|
|
- 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
|
|
@@ -75,11 +64,15 @@ func (n *Network) ProjectExport() {
|
|
|
}
|
|
|
bidList, err := dataexport.GetDataExportSearchResult(util.Mgo_bidding, config.Config.Mongobidding.DbName, config.Config.Elasticsearch, scd, "2", -2)
|
|
|
if err != nil {
|
|
|
+ log.Println("人脉通项目导出", export_id, err)
|
|
|
http.Error(n.ResponseWriter, err.Error(), http.StatusInternalServerError)
|
|
|
return
|
|
|
- } else if bidList == nil {
|
|
|
+ } else if bidList == nil || len(*bidList) == 0 {
|
|
|
+ log.Println("人脉通项目导出", export_id, "未找到项目的标讯信息")
|
|
|
+ http.Error(n.ResponseWriter, "未找到项目的标讯信息", http.StatusInternalServerError)
|
|
|
return
|
|
|
}
|
|
|
+ log.Println("人脉通项目导出", export_id, len(*bidList))
|
|
|
bidList = dataexport.FormatExportData(util.MQFWENT, bidList, config.Config.WebDomain, "2")
|
|
|
file, err := util.ExportExcelFile(bidList, true)
|
|
|
if err != nil {
|
|
@@ -95,3 +88,34 @@ 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_id,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_id string
|
|
|
+ info_ids []string
|
|
|
+ )
|
|
|
+ if err := rows.Scan(&info_id, &info_ids); err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if info_ids == nil || len(info_ids) == 0 {
|
|
|
+ if info_id != "" {
|
|
|
+ bIds = append(bIds, info_id)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ bIds = append(bIds, info_ids...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rows.Close()
|
|
|
+ if err := rows.Err(); err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ }
|
|
|
+ return bIds
|
|
|
+}
|