wangchuanjin hai 9 meses
pai
achega
5db8e132fd

+ 1 - 12
api/common/network.go

@@ -21,7 +21,7 @@ func (n *networkCom) GetEntIdByName(names []string) map[string]string {
 		return result
 	}
 	var query = func(values []string) {
-		wh, args := n.WhArgs(values)
+		wh, args := WhArgs(values)
 		rows, err := ClickhouseConn.Query(context.Background(), `select id,company_name from information.ent_info where company_name in (`+wh+`)`, args...)
 		if err != nil {
 			logx.Error(err)
@@ -119,14 +119,3 @@ func (n *networkCom) EntMonitor(userId string) map[string]bool {
 	}
 	return m
 }
-
-//获取问号占位符数量及对应的参数值
-func (n *networkCom) WhArgs(args []string) (string, []interface{}) {
-	newArgs := make([]interface{}, len(args))
-	wh := make([]string, len(args))
-	for k, v := range args {
-		newArgs[k] = v
-		wh[k] = "?"
-	}
-	return strings.Join(wh, ","), newArgs
-}

+ 6 - 5
api/internal/logic/projectlistlogic.go

@@ -1,10 +1,11 @@
 package logic
 
 import (
-	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/service"
 	"context"
 	"fmt"
 
+	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/service"
+
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/svc"
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
 
@@ -28,11 +29,11 @@ func NewProjectListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Proje
 func (l *ProjectListLogic) ProjectList(req *types.ProjectListReq) (resp *types.Reply, err error) {
 	logx.Info(fmt.Sprintf("%+v", req))
 	resp = &types.Reply{}
-	list, hasNextPage, count := service.GetProjectList(req)
+	result := service.GetProjectList(req)
 	resp.Data = map[string]interface{}{
-		"list":        list,
-		"total":       count,
-		"hasNextPage": hasNextPage,
+		"list":        result.PList,
+		"total":       result.Count,
+		"hasNextPage": result.HasNextPage,
 	}
 	return
 }

+ 1 - 1
api/internal/service/CoopHistoryService.go

@@ -294,7 +294,7 @@ func LastTimeCoopBath(positionId int64, buyerId string, winners, agencys []strin
 	var toSearch = func(tp int, query string, ws []string) {
 		logx.Info("LastTimeCoopBath once start ", positionId)
 		defer logx.Info("LastTimeCoopBath once over ", positionId)
-		wh, newArgs := T.NetworkCom.WhArgs(ws)
+		wh, newArgs := common.WhArgs(ws)
 		query = fmt.Sprintf(query, wh)
 		args := []interface{}{buyerId}
 		args = append(args, newArgs...)

+ 11 - 11
api/internal/service/network.go

@@ -248,7 +248,7 @@ func (n *network) Associate(in *types.AssociateReq) (reply *types.Reply) {
 		businessType := strings.Split(FindBusiness(in.EntId, in.MgoUserId), ",")
 		if len(businessType) > 0 {
 			args := []interface{}{in.EntName}
-			wh, newArgs := NetworkCom.WhArgs(businessType)
+			wh, newArgs := WhArgs(businessType)
 			args = append(args, newArgs...)
 			q := `select DISTINCT winner_id,winner from information.transaction_info_all where buyer_id in (select buyer_id from information.transaction_info_all where has(winner, ?) and buyer_id<>'') and hasAny(topscopeclass,[` + wh + `])=0 ORDER BY project_id`
 			rows, err := ClickhouseConn.Query(context.Background(), q, args...)
@@ -879,7 +879,7 @@ func (n *network) FirstpartyNetwork(name string, values []string) map[string][]*
 	if len(values) == 0 {
 		return result
 	}
-	wh, args := NetworkCom.WhArgs(values)
+	wh, args := WhArgs(values)
 	q := `select DISTINCT a.a_id,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 in (` + wh + `) and b.pcode in ('0100','0200') and a.code=b.code)`
 	if name != "" {
@@ -928,10 +928,10 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, busi
 	if len(values) == 0 {
 		return result
 	}
-	wh, args := NetworkCom.WhArgs(values)
+	wh, args := WhArgs(values)
 	q := `select buyer_id,count(project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info_all where buyer_id in (` + wh + `)`
 	if len(businessType) > 0 {
-		newWh, newArgs := NetworkCom.WhArgs(businessType)
+		newWh, newArgs := WhArgs(businessType)
 		q += ` and hasAny(topscopeclass,[` + newWh + `])`
 		args = append(args, newArgs...)
 	}
@@ -985,7 +985,7 @@ func (n *network) Introduce_Supplier(values []string, businessType []string) map
 	if len(values) == 0 {
 		return map[string]*projectInfo{}
 	}
-	wh, args := NetworkCom.WhArgs(values)
+	wh, args := WhArgs(values)
 	vbs := map[string][]*idName{}
 	repeat := map[string]bool{}
 	whRepeat := map[string]map[string]bool{}
@@ -1038,7 +1038,7 @@ func (n *network) Introduce_Agency(values []string, businessType []string) map[s
 	if len(values) == 0 {
 		return map[string]*projectInfo{}
 	}
-	wh, args := NetworkCom.WhArgs(values)
+	wh, args := WhArgs(values)
 	q := `select DISTINCT agency_id,buyer_id,buyer from information.transaction_info_all where agency_id in (` + wh + `)`
 	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
 	if err != nil {
@@ -1086,10 +1086,10 @@ func (n *network) Introduce_Middleman_Project(values []string, businessType []st
 	if len(values) == 0 {
 		return result
 	}
-	wh, args := NetworkCom.WhArgs(values)
+	wh, args := WhArgs(values)
 	q := `select DISTINCT project_id,project_money from information.transaction_info_all where project_id in (` + wh + `)`
 	if len(businessType) > 0 {
-		newWh, newArgs := NetworkCom.WhArgs(businessType)
+		newWh, newArgs := WhArgs(businessType)
 		q += ` and hasAny(topscopeclass,[` + newWh + `])`
 		args = append(args, newArgs...)
 	}
@@ -1158,7 +1158,7 @@ func (n *network) GetQyxyId(ids []string) map[string]string {
 	if len(ids) == 0 {
 		return m
 	}
-	wh, args := NetworkCom.WhArgs(ids)
+	wh, args := WhArgs(ids)
 	q := `select id,company_id from information.ent_info where id in (` + wh + `)`
 	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
 	if err != nil {
@@ -1188,10 +1188,10 @@ func (n *network) BuyerProjectInfo(ids []string, businessType []string) map[stri
 	if len(ids) == 0 {
 		return vm
 	}
-	wh, args := NetworkCom.WhArgs(ids)
+	wh, args := WhArgs(ids)
 	q := `select buyer_id,count(DISTINCT project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info_all where buyer_id in (` + wh + `) and project_bidstatus>1`
 	if len(businessType) > 0 {
-		newWh, newArgs := NetworkCom.WhArgs(businessType)
+		newWh, newArgs := WhArgs(businessType)
 		q += ` and hasAny(topscopeclass,[` + newWh + `])`
 		args = append(args, newArgs...)
 	}

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

@@ -201,11 +201,12 @@ func TestGetProjectList(t *testing.T) {
 		PageNum:      1,
 		PageSize:     10,
 		BusinessType: "全部",
+		Area:         "广东",
+		Amount:       "2,3,4,5",
 	}
-
-	list, hasNextPage, count := GetProjectList(req)
-	log.Println(hasNextPage, count, list)
-	for _, v := range list {
+	resp := GetProjectList(req)
+	log.Println(resp.HasNextPage, resp.Count)
+	for _, v := range resp.PList {
 		log.Println(v)
 	}
 }

+ 66 - 51
api/internal/service/owner.go

@@ -114,7 +114,7 @@ func (t *OwnerService) OwnerlList() *OwnerlListRes {
 		if t.PartyA == "" && t.Supplier == "" && t.Heterotophy == "" && t.Intermediary == "" && t.Agency == "" {
 			return olr
 		}
-		dataMap := BuyerList(t.PartyA, t.Supplier, t.Heterotophy, t.Intermediary, t.Agency, t.PositionId)
+		dataMap := BuyerList(t.PartyA, t.Intermediary, t.PositionId)
 		// 监控状态处理
 		if t.SourceType == "2" {
 			for k, v := range *dataMap {
@@ -129,7 +129,7 @@ func (t *OwnerService) OwnerlList() *OwnerlListRes {
 		// 项目数量查询
 		buyerArr := getBuyerArr(dataMap)
 		// 项目数量处理
-		projectMap, connectionsNumber := ProjectHandle(buyerArr, t.Area, businessStr, dataMap, startIndex, t.PageSize, t.SourceType)
+		projectMap, connectionsNumber := ProjectHandle(t.Supplier, t.Heterotophy, t.Agency, buyerArr, t.Area, businessStr, dataMap, startIndex, t.PageSize, t.SourceType)
 		endTime := time.Now().Unix()
 		fmt.Println("用时时间:", endTime-startTime)
 		if len(*projectMap) == 0 {
@@ -619,7 +619,7 @@ func FindStatus(positionId int64) (map[string]bool, map[string]bool, map[string]
 }
 
 // 采购单位查询
-func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, positionId int64) *map[string]map[string]interface{} {
+func BuyerList(partyA, intermediary string, positionId int64) *map[string]map[string]interface{} {
 	dataMap := &map[string]map[string]interface{}{}
 	//甲方
 	if partyA != "" {
@@ -640,31 +640,31 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, posit
 		// }
 	}
 	//供应商 //同甲异业
-	findInSetArr := []string{}
-	if supplier != "" {
-		for _, v := range strings.Split(supplier, ",") {
-			if v != "" {
-				findInSetArr = append(findInSetArr, fmt.Sprintf("'%s'", v))
-			}
-		}
-	}
-	if len(findInSetArr) > 0 {
-		sqlStr := fmt.Sprintf(`SELECT buyer_id,buyer FROM transaction_info_all where  hasAny(winner_id,[%s])    `, strings.Join(findInSetArr, ","))
-		FindHandle(sqlStr, dataMap, "supplier")
-	}
+	// findInSetArr := []string{}
+	// if supplier != "" {
+	// 	for _, v := range strings.Split(supplier, ",") {
+	// 		if v != "" {
+	// 			findInSetArr = append(findInSetArr, fmt.Sprintf("'%s'", v))
+	// 		}
+	// 	}
+	// }
+	// if len(findInSetArr) > 0 {
+	// 	sqlStr := fmt.Sprintf(`SELECT buyer_id,buyer FROM transaction_info_all where  hasAny(winner_id,[%s])    `, strings.Join(findInSetArr, ","))
+	// 	FindHandle(sqlStr, dataMap, "supplier")
+	// }
 	//同甲异业
-	findheterotophyArr := []string{}
-	if heterotophy != "" {
-		for _, v := range strings.Split(heterotophy, ",") {
-			if v != "" {
-				findheterotophyArr = append(findheterotophyArr, fmt.Sprintf("'%s'", v))
-			}
-		}
-	}
-	if len(findheterotophyArr) > 0 {
-		sqlStr := fmt.Sprintf(`SELECT buyer_id,buyer FROM transaction_info_all where  hasAny(winner_id,[%s])    `, strings.Join(findheterotophyArr, ","))
-		FindHandle(sqlStr, dataMap, "adiffb")
-	}
+	// findheterotophyArr := []string{}
+	// if heterotophy != "" {
+	// 	for _, v := range strings.Split(heterotophy, ",") {
+	// 		if v != "" {
+	// 			findheterotophyArr = append(findheterotophyArr, fmt.Sprintf("'%s'", v))
+	// 		}
+	// 	}
+	// }
+	// if len(findheterotophyArr) > 0 {
+	// 	sqlStr := fmt.Sprintf(`SELECT buyer_id,buyer FROM transaction_info_all where  hasAny(winner_id,[%s])    `, strings.Join(findheterotophyArr, ","))
+	// 	FindHandle(sqlStr, dataMap, "adiffb")
+	// }
 	//中间人
 	if intermediary != "" {
 		wh, args := common.WhArgs(strings.Split(intermediary, ","))
@@ -683,30 +683,54 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, posit
 		}
 	}
 	//招标代理
-	if agency != "" {
-		agencyArr := []string{}
-		for _, s := range strings.Split(agency, ",") {
-			agencyArr = append(agencyArr, fmt.Sprintf("'%s'", s))
-		}
-		sqlStr := fmt.Sprintf(`SELECT  buyer_id,buyer FROM transaction_info_all  where agency_id in (%s) `, strings.Join(agencyArr, ","))
-		FindHandle(sqlStr, dataMap, "agency")
-	}
+	// if agency != "" {
+	// 	agencyArr := []string{}
+	// 	for _, s := range strings.Split(agency, ",") {
+	// 		agencyArr = append(agencyArr, fmt.Sprintf("'%s'", s))
+	// 	}
+	// 	sqlStr := fmt.Sprintf(`SELECT  buyer_id,buyer FROM transaction_info_all  where agency_id in (%s) `, strings.Join(agencyArr, ","))
+	// 	FindHandle(sqlStr, dataMap, "agency")
+	// }
 	return dataMap
 }
 
 // 项目数量查
-func ProjectHandle(buyerArr []string, area, businessStr string, dataMap *map[string]map[string]interface{}, startIndex, PageSize int64, sourceType string) (*map[string]map[string]interface{}, int64) {
+func ProjectHandle(supplier, heterotophy, agency string, buyerArr []string, area, businessStr string, dataMap *map[string]map[string]interface{}, startIndex, PageSize int64, sourceType string) (*map[string]map[string]interface{}, int64) {
 	projectMap := &map[string]map[string]interface{}{}
 	count := int64(0)
 	tscSql := `'` + strings.ReplaceAll(businessStr, ",", `','`) + `'`
 	sqlStr := `select buyer,buyer_id,groupUniqArray(area) as areaStr,count(if(hasAny(topscopeclass,[`
 	sqlStr += tscSql + `])=1 and project_bidstatus>1,1,null)) as ocount,SUM(if(hasAny(topscopeclass,[`
-	sqlStr += tscSql + `])=1 and project_bidstatus>1,project_money,0)) as project_money ,MAX(zbtime) as zbtime from transaction_info_all where`
-	buyer, buyerArgs := ConditionHandle(buyerArr)
-	sqlStr += fmt.Sprintf(fmt.Sprintf(" buyer_id in (%s)", buyer), buyerArgs...)
-	if len(area) > 0 && area != "" {
-		areaStr, areaArgs := ConditionHandle(strings.Split(area, ","))
-		sqlStr += fmt.Sprintf(fmt.Sprintf(" and  area in (%s)", areaStr), areaArgs...)
+	sqlStr += tscSql + `])=1 and project_bidstatus>1,project_money,0)) as project_money,MAX(zbtime) as zbtime from transaction_info_all where (`
+	allArgs := []interface{}{}
+	ors := []string{}
+	if len(buyerArr) > 0 {
+		wh, args := common.WhArgs(buyerArr)
+		ors = append(ors, `buyer_id in (`+wh+`)`)
+		allArgs = append(allArgs, args...)
+	}
+	winner_ids := []string{}
+	if supplier != "" {
+		winner_ids = append(winner_ids, strings.Split(supplier, ",")...)
+	}
+	if heterotophy != "" {
+		winner_ids = append(winner_ids, strings.Split(heterotophy, ",")...)
+	}
+	if len(winner_ids) > 0 {
+		wh, args := common.WhArgs(winner_ids)
+		ors = append(ors, `hasAny(winner_id,[`+wh+`]`)
+		allArgs = append(allArgs, args...)
+	}
+	if agency != "" {
+		wh, args := common.WhArgs(strings.Split(agency, ","))
+		ors = append(ors, `agency_id in (`+wh+`)`)
+		allArgs = append(allArgs, args...)
+	}
+	sqlStr += strings.Join(ors, " or ")
+	if area != "" {
+		wh, args := common.WhArgs(strings.Split(area, ","))
+		sqlStr += `) and area in (` + wh + `)`
+		allArgs = append(allArgs, args...)
 	}
 	sqlStr += " GROUP by buyer,buyer_id "
 	if sourceType == "1" {
@@ -983,12 +1007,3 @@ func FindBusiness(endId int64, userId string) string {
 	}
 	return businessStr
 }
-func ConditionHandle(args []string) (string, []interface{}) {
-	newArgs := make([]interface{}, len(args))
-	wh := make([]string, len(args))
-	for k, v := range args {
-		newArgs[k] = v
-		wh[k] = "'%s'"
-	}
-	return strings.Join(wh, ","), newArgs
-}

+ 90 - 141
api/internal/service/plistService.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"encoding/json"
 	"fmt"
+	"math"
 	"strconv"
 	"strings"
 
@@ -27,9 +28,9 @@ const (
 )
 
 type ProjectData struct {
-	count       int64
-	hasNextPage bool
-	pList       []*ProjectEntry
+	Count       int64
+	HasNextPage bool
+	PList       []*ProjectEntry
 }
 
 type ProjectEntry struct {
@@ -46,7 +47,7 @@ type ProjectEntry struct {
 	ProjectMoney  decimal.Decimal `ch:"project_money"`
 	InfoId        string          `ch:"info_id"`
 	InformationId string          `ch:"information_id"`
-	InfoIds       string          `ch:"info_ids"`
+	InfoIds       []string        `ch:"info_ids"`
 	Href          string          `json:"Href"`
 	IsHandle      int             `json:"IsHandle"`
 	IsIgnore      int             `json:"IsIgnore"`
@@ -64,76 +65,63 @@ type ProjectEntry struct {
 	IsFocus       int             `json:"IsFocus"`
 }
 
-func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasNextPage bool, total int) {
+func GetProjectList(req *types.ProjectListReq) *ProjectData {
+	projectData := &ProjectData{
+		PList: []*ProjectEntry{},
+	}
 	businessStr := FindBusiness(req.EntId, req.UserId)
 	if businessStr == "" {
-		return []*ProjectEntry{}, false, 0
+		return projectData
 	}
-	buyerM := BuyerList(req.PartyA, req.Supplier, req.Heterotophy, "", req.Agency, req.PositionId)
 	var plist []string
 	if req.Intermediary != "" {
 		plist = getIyProList(req.Intermediary, req.PositionId)
 	}
-	if len(*buyerM) <= 0 && len(plist) <= 0 {
-		return []*ProjectEntry{}, false, 0
-	}
-	mmp := MonitorStatus(req.UserId) // 项目监控
-	var buyerArr []string
-	for b := range *buyerM {
-		buyerArr = append(buyerArr, b)
+	if req.PartyA == "" && len(plist) == 0 && req.Supplier == "" && req.Heterotophy == "" && req.Agency == "" {
+		return projectData
 	}
 	//preSales := preSalesStatus(req.PositionId)
 	//isSqlPage := true
 	//if req.SaleStatus == "0" {
 	//	isSqlPage = true // 是否sql分页
 	//}
-	countSql, findSql := getQuerySql(req, true, buyerArr, plist, businessStr)
+	countSql, findSql, args := getQuerySql(req, plist, businessStr)
 	// 缓存
 	rkey := fmt.Sprintf(NetworkManageProjectList, req.PositionId, common.GetMd5String(fmt.Sprintf("%+v", req)))
-	if ret, err := redis.GetBytes("newother", rkey); err == nil {
-		err = json.Unmarshal(*ret, &resultList)
+	if ret, err := redis.GetNewBytes("newother", rkey); false && err == nil && ret != nil {
+		err = json.Unmarshal(*ret, &projectData)
 	} else {
-		logx.Info("findSql: ", findSql)
-		logx.Info("countSql: ", countSql)
-		rows, err := T.ClickhouseConn.Query(context.TODO(), findSql)
-		defer rows.Close()
+		logx.Info("findSql: ", findSql, args)
+		logx.Info("countSql: ", countSql, args)
+		rows, err := T.ClickhouseConn.Query(context.TODO(), findSql, args...)
 		if err != nil {
-			return nil, false, 0
+			return projectData
 		}
+		defer rows.Close()
+		resultList := []*ProjectEntry{}
 		for rows.Next() {
 			project := ProjectEntry{}
-			_ = rows.ScanStruct(&project)
+			ssc := rows.ScanStruct(&project)
+			if ssc != nil {
+				logx.Error(ssc)
+				continue
+			}
 			resultList = append(resultList, &project)
 		}
-		redis.Put("newother", rkey, resultList, T.C.CacheTimeOut)
+		projectData.PList = resultList
+		projectData.Count = T.NetworkCom.Count(countSql, args...)
+		moreInfo(req, plist, projectData.PList) //  补充信息
+		redis.Put("newother", rkey, projectData, T.C.CacheTimeOut)
 	}
-
-	resultList = filterData(req, resultList, nil, mmp, true)
-	//if !isSqlPage {
-	//total = len(resultList)
-	//if total > req.PageSize {
-	//	hasNextPage = true
-	//	start := (req.PageNum - 1) * req.PageSize
-	//	end := req.PageNum * req.PageSize
-	//	if end > total {
-	//		end = total
-	//		hasNextPage = false
-	//	}
-	//	resultList = resultList[start:end]
-	//} else {
-	//	hasNextPage = false
-	//}
-	//} else {
-	total = int(T.NetworkCom.Count(countSql))
-	if total > req.PageSize {
-		hasNextPage = true
+	mmp := MonitorStatus(req.UserId) // 项目监控
+	projectData.PList = filterData(req, projectData.PList, nil, mmp, true)
+	totalPage := int(math.Ceil(float64(projectData.Count) / float64(req.PageSize)))
+	if totalPage > req.PageNum {
+		projectData.HasNextPage = true
 	} else {
-		hasNextPage = false
+		projectData.HasNextPage = false
 	}
-	//}
-	moreInfo(req, plist, resultList) //  补充信息
-
-	return
+	return projectData
 }
 
 // @Author jianghan
@@ -162,84 +150,50 @@ func getIyProList(iy string, positionId int64) (array []string) {
 	return
 }
 
-func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr, plist []string, businessStr string) (countSql, findSql string) {
-	querys := []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 "
+	allArgs = []interface{}{}
+	ors := []string{}
 	// 左侧选中的业主id
-	if len(buyerArr) > 0 || len(plist) > 0 {
-		if len(buyerArr) > 0 && len(plist) > 0 {
-			var arr []string
-			for _, s := range buyerArr {
-				arr = append(arr, fmt.Sprintf("'%s'", s))
-			}
-			var arr1 []string
-			for _, s := range plist {
-				arr1 = append(arr1, fmt.Sprintf("'%s'", s))
-			}
-			querys = append(querys, fmt.Sprintf(" (a.buyer_id in (%s) or a.project_id in (%s)) ", strings.Join(arr, ","), strings.Join(arr1, ",")))
-		} else if len(buyerArr) > 0 {
-			var arr []string
-			for _, s := range buyerArr {
-				arr = append(arr, fmt.Sprintf("'%s'", s))
-			}
-			querys = append(querys, fmt.Sprintf(" a.buyer_id in (%s) ", strings.Join(arr, ",")))
-		} else if len(plist) > 0 {
-			var arr1 []string
-			for _, s := range plist {
-				arr1 = append(arr1, fmt.Sprintf("'%s'", s))
-			}
-			querys = append(querys, fmt.Sprintf(" a.project_id in (%s) ", strings.Join(arr1, ",")))
-		}
+	if req.PartyA != "" {
+		wh, args := common.WhArgs(strings.Split(req.PartyA, ","))
+		ors = append(ors, "a.buyer_id in ("+wh+")")
+		allArgs = append(allArgs, args...)
 	}
-	//	商机类型
-	if req.BusinessType != "" && req.BusinessType != "全部" {
-		querys = append(querys, fmt.Sprintf(" a.business_type in ('%s') ", strings.Join(strings.Split(req.BusinessType, ","), "', '")))
+	if len(plist) > 0 {
+		wh, args := common.WhArgs(plist)
+		ors = append(ors, "a.project_id in ("+wh+")")
+		allArgs = append(allArgs, args...)
 	}
-	if req.ProjectName != "" {
-		querys = append(querys, " a.project_name like '%"+req.ProjectName+"%'")
+	winner_ids := []string{}
+	if req.Supplier != "" {
+		winner_ids = append(winner_ids, strings.Split(req.Supplier, ",")...)
 	}
-	if req.StartTime > 0 && req.EntTime > 0 {
-		st := req.StartTime + 90*24*60*60
-		et := req.EntTime + 90*24*60*60
-		querys = append(querys, fmt.Sprintf("  a.endtime>=%d and a.endtime<=%d", st, et))
-	} else if req.StartTime > 0 && req.EntTime == 0 {
-		st := req.StartTime + 90*24*60*60
-		querys = append(querys, fmt.Sprintf(" a.endtime>=%d", st))
-	} else if req.StartTime == 0 && req.EntTime > 0 {
-		et := req.EntTime + 90*24*60*60
-		querys = append(querys, fmt.Sprintf(" a.endtime<=%d", et))
+	if req.Heterotophy != "" {
+		winner_ids = append(winner_ids, strings.Split(req.Heterotophy, ",")...)
 	}
-	var regionArr = []string{}
-	if req.Area != "" || req.City != "" || req.District != "" {
-		//城市
-		if req.City != "" {
-			regionArr = append(regionArr, fmt.Sprintf(" a.city in ('%s') ", req.City))
-		}
-		//区域
-		if req.Area != "" {
-			regionArr = append(regionArr, fmt.Sprintf(" a.area in ('%s') ", req.Area))
-		}
-		//区域
-		district := []string{}
-		if req.District != "" {
-			for _, v := range strings.Split(req.District, ",") {
-				//cityName := strings.Split(v, "_")[0]
-				districtName := strings.Split(v, "_")[1]
-				district = append(district, districtName)
-			}
-		}
-		if len(district) > 0 {
-			regionArr = append(regionArr, fmt.Sprintf(" a.district in ('%s') ", strings.Join(district, ",")))
-		}
-		if len(regionArr) > 0 {
-			querys = append(querys, fmt.Sprintf("(%s)", strings.Join(regionArr, "or")))
-		}
+	if len(winner_ids) > 0 {
+		wh, args := common.WhArgs(winner_ids)
+		ors = append(ors, "hasAny(a.winner_id,["+wh+"])")
+		allArgs = append(allArgs, args...)
 	}
-	if req.SubClass != "" {
-		arr := []string{}
-		for _, v := range strings.Split(req.SubClass, ",") {
-			arr = append(arr, fmt.Sprintf("has(a.subclass, '%s')", v))
-		}
-		querys = append(querys, arr...)
+	if req.Agency != "" {
+		wh, args := common.WhArgs(strings.Split(req.Agency, ","))
+		ors = append(ors, "a.agency_id in ("+wh+")")
+		allArgs = append(allArgs, args...)
+	}
+	querys := []string{}
+	//业务类型
+	if businessStr != "" {
+		wh, args := common.WhArgs(strings.Split(businessStr, ","))
+		querys = append(querys, `hasAny(b.topscopeclass,[`+wh+`])`)
+		allArgs = append(allArgs, args...)
+	}
+	//区域
+	if req.Area != "" {
+		querys = append(querys, "b.area=?")
+		allArgs = append(allArgs, req.Area)
 	}
 	// 项目金额 0: 全部,1: 50万以下,2: 50-100万, 3: 100-200万, 4: 200-500万, 5:500万以上
 	if req.Amount != "" {
@@ -247,37 +201,32 @@ func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr, plist []strin
 			var tempArr []string
 			for _, s := range strings.Split(req.Amount, ",") {
 				if s == "1" {
-					tempArr = append(tempArr, fmt.Sprintf("(a.project_money<=%d)", 500000))
+					tempArr = append(tempArr, "b.project_money<=?")
+					allArgs = append(allArgs, 500000)
 				} else if s == "2" {
-					tempArr = append(tempArr, fmt.Sprintf("((a.project_money>=%d and a.project_money<=%d))", 500000, 1000000))
+					tempArr = append(tempArr, "(b.project_money>=? and b.project_money<=?)")
+					allArgs = append(allArgs, 500000, 1000000)
 				} else if s == "3" {
-					tempArr = append(tempArr, fmt.Sprintf("((a.project_money>=%d and a.project_money<=%d))", 1000000, 2000000))
+					tempArr = append(tempArr, "(b.project_money>=? and b.project_money<=?)")
+					allArgs = append(allArgs, 1000000, 2000000)
 				} else if s == "4" {
-					tempArr = append(tempArr, fmt.Sprintf("((a.project_money>=%d and a.project_money<=%d))", 2000000, 5000000))
+					tempArr = append(tempArr, "(b.project_money>=? and b.project_money<=?)")
+					allArgs = append(allArgs, 2000000, 5000000)
 				} else if s == "5" {
-					tempArr = append(tempArr, fmt.Sprintf("((a.project_money>=%d))", 5000000))
+					tempArr = append(tempArr, "b.project_money>=?")
+					allArgs = append(allArgs, 5000000)
 				}
 			}
 			if len(tempArr) > 0 {
-				querys = append(querys, fmt.Sprintf("(%s)", strings.Join(tempArr, "or")))
+				querys = append(querys, fmt.Sprintf("(%s)", strings.Join(tempArr, " or ")))
 			}
 		}
 	}
-	//业务类型
-	querys = append(querys, `hasAny(topscopeclass,['`+strings.ReplaceAll(businessStr, `,`, `','`)+`'])`)
 	//过滤掉已中标的招标项目数据
-	querys = append(querys, " a.project_bidstatus>1 ")
-	findSql = "select a.project_id, a.project_name, a.business_type, a.buyer, a.buyer_id, a.area, a.city, a.district, a.zbtime, a.endtime, a.project_money, a.info_id, a.information_id, a.info_ids "
-	if len(querys) > 0 {
-		countSql = fmt.Sprintf("select count(1) from %s a where %s ", "information.transaction_info_all", strings.Join(querys, " and "))
-		findSql = fmt.Sprintf("%s from %s  a  where  %s order by zbtime desc", findSql, "information.transaction_info_all", strings.Join(querys, " and "))
-	} else {
-		countSql = fmt.Sprintf("select count(1) from %s a ", "information.transaction_info_all")
-		findSql = fmt.Sprintf("%s from %s a order by zbtime", findSql, "information.transaction_info_all")
-	}
-	if isPage {
-		findSql += fmt.Sprintf(" limit %d,%d", (req.PageNum-1)*req.PageSize, req.PageSize)
-	}
+	sqlAppend := "inner join information.transaction_info_all b on((" + strings.Join(ors, " or ") + ") and a.buyer_id=b.buyer_id) where b.project_bidstatus>1 and " + strings.Join(querys, " and ")
+	countSql += sqlAppend
+	findSql += sqlAppend + " order by b.zbtime desc limit ?,?"
+	allArgs = append(allArgs, (req.PageNum-1)*req.PageSize, req.PageSize)
 	return
 }
 

+ 3 - 3
api/internal/service/prListService.go

@@ -1,15 +1,16 @@
 package service
 
 import (
+	"fmt"
+	"strings"
+
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/encrypt"
 	elastic "app.yhyue.com/moapp/jybase/es"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	T "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
-	"fmt"
 	"github.com/zeromicro/go-zero/core/logx"
-	"strings"
 )
 
 var (
@@ -20,7 +21,6 @@ var (
 )
 
 func GetMonitorList(req *types.PrMonitorListReq) (resultList []map[string]interface{}, total int64, hasMonitor bool) {
-
 	bList, b := T.Mgo.Find("follow_customer", map[string]interface{}{"userId": req.UserId}, `{_id: 1}`, nil, false, -1, -1)
 	if b && len(*bList) > 0 {
 		hasMonitor = true