Browse Source

feat:xiugai

wangchuanjin 1 year ago
parent
commit
7b6cbc0864
3 changed files with 38 additions and 32 deletions
  1. 1 1
      api/etc/db.yaml
  2. 33 30
      api/internal/service/network.go
  3. 4 1
      api/internal/service/network_test.go

+ 1 - 1
api/etc/db.yaml

@@ -69,6 +69,6 @@ clickhouse:
     Addr: 192.168.3.207:19000
     UserName: jytop
     Password: pwdTopJy123
-    DbName: jianyu
+    DbName: information
     MaxIdleConns: 5
     MaxOpenConns: 30

+ 33 - 30
api/internal/service/network.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"database/sql"
 	"fmt"
-	"log"
 	"math"
 	"strings"
 	"sync"
@@ -22,15 +21,15 @@ var Network = &network{}
 type network struct {
 }
 type networkTree struct {
-	Count    int64
-	Name     string
-	Children []*networkTreeChild
+	Count    int64               `json:"count"`
+	Name     string              `json:"name"`
+	Children []*networkTreeChild `json:"children"`
 }
 type networkTreeChild struct {
-	Count int64
-	Name  string
-	Id    string
-	Type  int
+	Count int64  `json:"count"`
+	Name  string `json:"name"`
+	Id    string `json:"id"`
+	Type  int    `json:"type"`
 }
 type projectInfo struct {
 	BuyerCount    int
@@ -192,24 +191,24 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 	lock := &sync.Mutex{}
 	reply = &types.Reply{}
 	wh, newArgs := NetworkCom.WhArgs(NetworkCom.GetMyProbusfor(in.EntAccountId))
+	var count int64
+	var list []*networkTree
 	if in.Id != "" {
 		if in.Type == 1 {
-			q := `select c.id as company_id,c.company_name,b.name from information.ent_map_code a 
-				inner join information.ent_code b on (a.a_id=? and b.pcode in ('0100','0200') and a.code=b.code) 
-				inner join information.ent_info c on (a.b_id=c.id)`
+			q := `select a.b_id as company_id,a.b_name as company_name,b.name from information.ent_map_code a 
+				inner join information.ent_code b on (a.a_id=? and b.pcode in ('0100','0200') and a.code=b.code)`
 			args := []interface{}{in.Id}
 			if in.Name != "" {
 				q += ` where c.company_name like ?`
 				args = append(args, "%"+in.Name+"%")
 			}
-			q += ` order by b.name,c.company_name`
+			q += ` order by b.name,a.b_name`
 			rows, err := ClickhouseConn.Query(context.Background(), q, args...)
 			if err != nil {
 				logx.Error(err)
 				return
 			}
 			nameIndex := map[string]int{}
-			list := []*networkTree{}
 			for rows.Next() {
 				var (
 					company_id   string
@@ -220,7 +219,6 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 					logx.Error(err)
 					continue
 				}
-				log.Println(company_id, company_name, name)
 				if _, ok := nameIndex[name]; !ok {
 					nameIndex[name] = len(list)
 					list = append(list, &networkTree{
@@ -245,6 +243,7 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 						ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where buyer_id=? and hasAny(property_form,[`+wh+`])`, thisArgs...)
 					}
 					lock.Lock()
+					count++
 					list[cIndex].Count += ntc.Count
 					list[cIndex].Children = append(list[cIndex].Children, ntc)
 					lock.Unlock()
@@ -266,22 +265,26 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 		}
 		q += ` GROUP BY a.id ORDER BY a.create_time DESC`
 		datas := CrmMysql.SelectBySql(q, args...)
-		var count int64
-		list := []*networkTree{
+		list = []*networkTree{
 			&networkTree{
-				Name: "甲方",
+				Name:     "甲方",
+				Children: []*networkTreeChild{},
 			},
 			&networkTree{
-				Name: "供应商",
+				Name:     "供应商",
+				Children: []*networkTreeChild{},
 			},
 			&networkTree{
-				Name: "同甲异业渠道",
+				Name:     "同甲异业渠道",
+				Children: []*networkTreeChild{},
 			},
 			&networkTree{
-				Name: "中间人",
+				Name:     "中间人",
+				Children: []*networkTreeChild{},
 			},
 			&networkTree{
-				Name: "招标代理",
+				Name:     "招标代理",
+				Children: []*networkTreeChild{},
 			},
 		}
 		//
@@ -306,13 +309,13 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 					thisArgs := []interface{}{ntc.Id}
 					thisArgs = append(thisArgs, newArgs...)
 					if itype == 1 {
-						ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where buyer_id=? and hasAny(b.property_form,[`+wh+`])`, thisArgs)
+						ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where buyer_id=? and hasAny(property_form,[`+wh+`])`, thisArgs...)
 					} else if itype == 2 || itype == 3 {
-						ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where winner_id=? and hasAny(b.property_form,[`+wh+`])`, thisArgs)
+						ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where has(winner_id,?) and hasAny(property_form,[`+wh+`])`, thisArgs...)
 					} else if itype == 4 {
 						ntc.Count = Int64All(v["ipc"])
 					} else if itype == 5 {
-						ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where agency_id=? and hasAny(b.property_form,[`+wh+`])`, thisArgs)
+						ntc.Count = NetworkCom.Count(`select count(1) from information.transaction_info where agency_id=? and hasAny(property_form,[`+wh+`])`, thisArgs...)
 					}
 				}
 				lock.Lock()
@@ -323,12 +326,12 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 			}(vt)
 		}
 		wait.Wait()
-		reply = &types.Reply{
-			Data: map[string]interface{}{
-				"count": count,
-				"list":  list,
-			},
-		}
+	}
+	reply = &types.Reply{
+		Data: map[string]interface{}{
+			"count": count,
+			"list":  list,
+		},
 	}
 	return reply
 }

+ 4 - 1
api/internal/service/network_test.go

@@ -94,7 +94,10 @@ func TestNetWorkList(t *testing.T) {
 func TestAllProject(t *testing.T) {
 	initDb()
 	res := Network.AllProject(&types.AllprojectReq{
-		PositionId: 943,
+		EntAccountId: 64,
+		PositionId:   943,
+		//Id:           "wcj_11111111a",
+		//Type:         1,
 	})
 	b, _ := json.Marshal(res.Data)
 	log.Println(string(b))