|
@@ -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
|
|
|
}
|
|
|
|