package service import ( "app.yhyue.com/moapp/jybase/common" P "app.yhyue.com/moapp/jybase/mapping" "bp.jydev.jianyu360.cn/CRM/application/api/internal/types" "fmt" "strings" ) const ( pageSize = 100 ) type ProjectData struct { count int64 hasNextPage bool pList []*ProjectEntry } type ProjectEntry struct { projectName string } func GetProjectList(req *types.ProjectListReq) (resultList []interface{}, hasNextPage bool, total int) { getSql(req) total = len(resultList) if total > pageSize { resultList = resultList[:pageSize] hasNextPage = true } return } func getSql(req *types.ProjectListReq) (countSql, findSql string) { querys := []string{} // 商机类型 if req.BusinessType != "" { querys = append(querys, fmt.Sprintf(" a.business_type in (%s) ", req.BusinessType)) } if req.ProjectName != "" { querys = append(querys, " a.projectname like '% "+req.ProjectName+"%'") } if req.StartTime > 0 && req.EntTime > 0 { st := req.StartTime + 90*24*60*60 et := req.StartTime + 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.StartTime + 90*24*60*60 querys = append(querys, fmt.Sprintf(" a.endtime<=%d", et)) } else { querys = append(querys, " a.endtime>0") } var regionArr = []string{} if req.Area != "" || req.City != "" || req.District != "" { //城市 city := []string{} for _, v := range strings.Split(req.City, ",") { if P.BidCodeMapping.City[v] != "" { city = append(city, fmt.Sprint(P.BidCodeMapping.City[v])) } } if len(city) > 0 { regionArr = append(regionArr, fmt.Sprintf(" a.city in (%s) ", strings.Join(city, ","))) } //区域 area := []string{} for _, v := range strings.Split(req.Area, ",") { if P.BidCodeMapping.Area[v] != "" { area = append(area, fmt.Sprint(P.BidCodeMapping.Area[v])) } } if len(area) > 0 { regionArr = append(regionArr, fmt.Sprintf(" a.area in (%s) ", strings.Join(area, ","))) } //区域 district := []string{} if req.District != "" { for _, v := range strings.Split(req.District, ",") { cityName := strings.Split(v, "_")[0] districtName := strings.Split(v, "_")[1] if P.BidCodeMapping.District[cityName][districtName] != "" { district = append(district, fmt.Sprint(P.BidCodeMapping.District[cityName][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 req.SubClass != "" { arr := []string{} for _, v := range strings.Split(req.SubClass, ",") { arr = append(arr, fmt.Sprintf(`"物业_%s"`, v)) } querys = append(querys, fmt.Sprintf(" a.subclass in (%s) ", strings.Join(regionArr, ","))) } // 项目金额 if req.Amount != "" && strings.Contains(req.Amount, "-") { minPriceStr, maxPriceStr := strings.Split(req.Amount, "-")[0], strings.Split(req.Amount, "-")[1] minPrice := common.Int64All(common.Float64All(minPriceStr) * 10000) //换成元 maxPrice := common.Int64All(common.Float64All(maxPriceStr) * 10000) //换成元 if minPriceStr != "" && maxPriceStr != "" { querys = append(querys, fmt.Sprintf("((a.project_money>=%d and a.project_money<=%d))", minPrice, maxPrice)) } else if minPriceStr != "" { querys = append(querys, fmt.Sprintf("(a.project_money>=%d)", minPrice)) } else if maxPriceStr != "" { querys = append(querys, fmt.Sprintf("(a.project_money<=%d)", maxPrice)) } } //物业业态 if req.PropertyForm != "" { arr := []string{} for _, v := range strings.Split(req.PropertyForm, ",") { arr = append(arr, fmt.Sprintf(`"%s"`, v)) } querys = append(querys, fmt.Sprintf(" a.property_form in (%s) ", strings.Join(arr, ","))) } //查询数量 countSql = fmt.Sprintf("select count(1) as count from %s a where %s %s", "", userStr, strings.Join(querys, " and ")) //列表查询语句 findSql = "select a.id,a.date,a.infoid,a.matchways,a.isvisit,REPLACE(a.matchkeys,'+',' ') as matchkeys,a.type,a.attachment_count" return }