wangchuanjin hai 9 meses
pai
achega
2d3840bd1e
Modificáronse 2 ficheiros con 60 adicións e 43 borrados
  1. 28 19
      api/internal/service/owner.go
  2. 32 24
      api/internal/service/plistService.go

+ 28 - 19
api/internal/service/owner.go

@@ -120,7 +120,7 @@ func (t *OwnerService) OwnerlList() *OwnerlListRes {
 		}
 	}
 	// 没有缓存时的处理逻辑
-	if true || !getFromCache {
+	if !getFromCache {
 		dataMap := BuyerList(t.PartyA, t.Intermediary, t.PositionId)
 		if len(*dataMap) == 0 && t.Supplier == "" && t.Heterotophy == "" && t.Agency == "" {
 			return olr
@@ -686,52 +686,61 @@ func (t *OwnerService) ProjectHandle(buyerArr []string, businessStr string, moni
 	startIndex := (t.PageIndex - 1) * t.PageSize
 	whBs, allArgs := common.WhArgs(strings.Split(businessStr, ","))
 	allArgs = append(allArgs, allArgs...)
-	sqlStr := `select b.buyer as buyer,b.buyer_id as buyer_id,groupUniqArray(b.area) as areaStr,count(if(hasAny(b.topscopeclass,[`
-	sqlStr += whBs + `])=1 and b.project_bidstatus>1,1,null)) as ocount,SUM(if(hasAny(b.topscopeclass,[`
-	sqlStr += whBs + `])=1 and b.project_bidstatus>1,b.project_money,0)) as project_money,MAX(b.zbtime) as zbtime from transaction_info_all a inner join transaction_info_all b on`
+	sqlStr := `select buyer,buyer_id,groupUniqArray(area) as areaStr,count(if(hasAny(topscopeclass,[`
+	sqlStr += whBs + `])=1 and project_bidstatus>1,1,null)) as ocount,SUM(if(hasAny(topscopeclass,[`
+	sqlStr += whBs + `])=1 and project_bidstatus>1,project_money,0)) as project_money,MAX(zbtime) as zbtime from transaction_info_all`
 	ors1 := []string{}
 	if len(buyerArr) > 0 {
 		wh, args := common.WhArgs(buyerArr)
-		ors1 = append(ors1, `(a.buyer_id in (`+wh+`) and a.project_id=b.project_id)`)
+		ors1 = append(ors1, `buyer_id in (`+wh+`)`)
 		allArgs = append(allArgs, args...)
 	}
-	ors2 := []string{}
+	wm := map[string]bool{}
 	winner_ids := []string{}
 	if t.Supplier != "" {
-		winner_ids = append(winner_ids, strings.Split(t.Supplier, ",")...)
+		for _, v := range strings.Split(t.Supplier, ",") {
+			if wm[v] {
+				continue
+			}
+			winner_ids = append(winner_ids, v)
+			wm[v] = true
+		}
 	}
 	if t.Heterotophy != "" {
-		winner_ids = append(winner_ids, strings.Split(t.Heterotophy, ",")...)
+		for _, v := range strings.Split(t.Heterotophy, ",") {
+			if wm[v] {
+				continue
+			}
+			winner_ids = append(winner_ids, v)
+			wm[v] = true
+		}
 	}
+	ors2 := []string{}
 	if len(winner_ids) > 0 {
 		wh, args := common.WhArgs(winner_ids)
-		ors2 = append(ors2, `hasAny(a.winner_id,[`+wh+`])`)
+		ors2 = append(ors2, `hasAny(winner_id,[`+wh+`])`)
 		allArgs = append(allArgs, args...)
 	}
 	if t.Agency != "" {
 		wh, args := common.WhArgs(strings.Split(t.Agency, ","))
-		ors2 = append(ors2, `a.agency_id in (`+wh+`)`)
+		ors2 = append(ors2, `agency_id in (`+wh+`)`)
 		allArgs = append(allArgs, args...)
 	}
 	if len(ors2) > 0 {
-		ors1 = append(ors1, "(("+strings.Join(ors2, " or ")+") and a.buyer_id<>'' and a.buyer_id=b.buyer_id)")
+		ors1 = append(ors1, `(buyer_id in (select buyer_id from transaction_info_all where `+strings.Join(ors2, " or ")+`))`)
 	}
-	sqlStr += " (" + strings.Join(ors1, " or ") + ")"
-	wheres := []string{}
+	ands := []string{}
 	if len(monitorBuyers) > 0 {
 		wh, args := common.WhArgs(monitorBuyers)
-		wheres = append(wheres, `b.buyer in (`+wh+`)`)
+		ands = append(ands, `buyer in (`+wh+`)`)
 		allArgs = append(allArgs, args...)
 	}
 	if t.Area != "" {
 		wh, args := common.WhArgs(strings.Split(t.Area, ","))
-		wheres = append(wheres, `b.area in (`+wh+`)`)
+		ands = append(ands, `area in (`+wh+`)`)
 		allArgs = append(allArgs, args...)
 	}
-	if len(wheres) > 0 {
-		sqlStr += " where " + strings.Join(wheres, " and ")
-	}
-	sqlStr += " GROUP by b.buyer,b.buyer_id"
+	sqlStr += " where (" + strings.Join(ors1, " or ") + ") " + strings.Join(ands, " and ") + " GROUP by buyer,buyer_id"
 	if t.SourceType == "1" {
 		sqlStr += " HAVING ocount>2 "
 	}

+ 32 - 24
api/internal/service/plistService.go

@@ -160,47 +160,55 @@ func getIyProList(iy string, positionId int64) (array []string) {
 }
 
 func getQuerySql(req *types.ProjectListReq, plist []string, businessStr string) (countSql, findSql string, allArgs []interface{}) {
-	countSql = "select count(1) from information.transaction_info_all a "
-	findSql = "select b.project_id as project_id,b.project_name as project_name,b.business_type as business_type,b.buyer as buyer,b.buyer_id as buyer_id,b.area as area,b.city as city,b.district as district,b.zbtime as zbtime,b.endtime as endtime,b.project_money as project_money,b.info_id as info_id,b.information_id as information_id,b.info_ids as info_ids from information.transaction_info_all a "
+	countSql = "select count(1) from information.transaction_info_all"
+	findSql = "select project_id,project_name,business_type,buyer,buyer_id,area,city,district,zbtime,endtime,project_money,info_id,information_id,info_ids from information.transaction_info_all"
 	allArgs = []interface{}{}
-	ors := []string{}
-	// 左侧选中的业主id
+	ors1 := []string{}
 	if len(plist) > 0 {
 		wh, args := common.WhArgs(plist)
-		ors = append(ors, "a.buyer_id in ("+wh+") and a.project_id=b.project_id")
+		ors1 = append(ors1, `buyer_id in (`+wh+`)`)
 		allArgs = append(allArgs, args...)
 	}
-	ors2 := []string{}
+	wm := map[string]bool{}
 	winner_ids := []string{}
-	if req.Supplier != "" {
-		winner_ids = append(winner_ids, strings.Split(req.Supplier, ",")...)
+	for _, v := range strings.Split(req.Supplier, ",") {
+		if wm[v] {
+			continue
+		}
+		winner_ids = append(winner_ids, v)
+		wm[v] = true
 	}
-	if req.Heterotophy != "" {
-		winner_ids = append(winner_ids, strings.Split(req.Heterotophy, ",")...)
+	for _, v := range strings.Split(req.Heterotophy, ",") {
+		if wm[v] {
+			continue
+		}
+		winner_ids = append(winner_ids, v)
+		wm[v] = true
 	}
+	ors2 := []string{}
 	if len(winner_ids) > 0 {
 		wh, args := common.WhArgs(winner_ids)
-		ors2 = append(ors2, "hasAny(a.winner_id,["+wh+"])")
+		ors2 = append(ors2, `hasAny(winner_id,[`+wh+`])`)
 		allArgs = append(allArgs, args...)
 	}
 	if req.Agency != "" {
 		wh, args := common.WhArgs(strings.Split(req.Agency, ","))
-		ors2 = append(ors2, "a.agency_id in ("+wh+")")
+		ors2 = append(ors2, `agency_id in (`+wh+`)`)
 		allArgs = append(allArgs, args...)
 	}
 	if len(ors2) > 0 {
-		ors = append(ors, "("+strings.Join(ors2, " or ")+") and a.buyer_id<>'' and a.buyer_id=b.buyer_id")
+		ors1 = append(ors1, `(buyer_id in (select buyer_id from transaction_info_all where `+strings.Join(ors2, " or ")+`))`)
 	}
-	querys := []string{}
+	ands := []string{}
 	//业务类型
 	if businessStr != "" {
 		wh, args := common.WhArgs(strings.Split(businessStr, ","))
-		querys = append(querys, `hasAny(b.topscopeclass,[`+wh+`])`)
+		ands = append(ands, `hasAny(topscopeclass,[`+wh+`])`)
 		allArgs = append(allArgs, args...)
 	}
 	//区域
 	if req.Area != "" {
-		querys = append(querys, "b.area=?")
+		ands = append(ands, "area=?")
 		allArgs = append(allArgs, req.Area)
 	}
 	// 项目金额 0: 全部,1: 50万以下,2: 50-100万, 3: 100-200万, 4: 200-500万, 5:500万以上
@@ -209,31 +217,31 @@ func getQuerySql(req *types.ProjectListReq, plist []string, businessStr string)
 			var tempArr []string
 			for _, s := range strings.Split(req.Amount, ",") {
 				if s == "1" {
-					tempArr = append(tempArr, "b.project_money<=?")
+					tempArr = append(tempArr, "project_money<=?")
 					allArgs = append(allArgs, 500000)
 				} else if s == "2" {
-					tempArr = append(tempArr, "(b.project_money>=? and b.project_money<=?)")
+					tempArr = append(tempArr, "(project_money>=? and project_money<=?)")
 					allArgs = append(allArgs, 500000, 1000000)
 				} else if s == "3" {
-					tempArr = append(tempArr, "(b.project_money>=? and b.project_money<=?)")
+					tempArr = append(tempArr, "(project_money>=? and project_money<=?)")
 					allArgs = append(allArgs, 1000000, 2000000)
 				} else if s == "4" {
-					tempArr = append(tempArr, "(b.project_money>=? and b.project_money<=?)")
+					tempArr = append(tempArr, "(project_money>=? and project_money<=?)")
 					allArgs = append(allArgs, 2000000, 5000000)
 				} else if s == "5" {
-					tempArr = append(tempArr, "b.project_money>=?")
+					tempArr = append(tempArr, "project_money>=?")
 					allArgs = append(allArgs, 5000000)
 				}
 			}
 			if len(tempArr) > 0 {
-				querys = append(querys, fmt.Sprintf("(%s)", strings.Join(tempArr, " or ")))
+				ands = append(ands, fmt.Sprintf("(%s)", strings.Join(tempArr, " or ")))
 			}
 		}
 	}
 	//过滤掉已中标的招标项目数据
-	sqlAppend := "inner join information.transaction_info_all b on(" + strings.Join(ors, " or ") + ") where b.project_bidstatus>1 and " + strings.Join(querys, " and ")
+	sqlAppend := " where (" + strings.Join(ors1, " or ") + ") and " + strings.Join(ands, " and ") + "and project_bidstatus>1"
 	countSql += sqlAppend
-	findSql += fmt.Sprintf(sqlAppend+" order by b.zbtime desc limit %d,%d", (req.PageNum-1)*req.PageSize, req.PageSize)
+	findSql += fmt.Sprintf(sqlAppend+" order by zbtime desc limit %d,%d", (req.PageNum-1)*req.PageSize, req.PageSize)
 	return
 }