plistService.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. P "app.yhyue.com/moapp/jybase/mapping"
  5. "bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
  6. "fmt"
  7. "strings"
  8. )
  9. const (
  10. pageSize = 100
  11. )
  12. type ProjectData struct {
  13. count int64
  14. hasNextPage bool
  15. pList []*ProjectEntry
  16. }
  17. type ProjectEntry struct {
  18. projectName string
  19. }
  20. func GetProjectList(req *types.ProjectListReq) (resultList []interface{}, hasNextPage bool, total int) {
  21. getSql(req)
  22. total = len(resultList)
  23. if total > pageSize {
  24. resultList = resultList[:pageSize]
  25. hasNextPage = true
  26. }
  27. return
  28. }
  29. func getSql(req *types.ProjectListReq) (countSql, findSql string) {
  30. querys := []string{}
  31. // 商机类型
  32. if req.BusinessType != "" {
  33. querys = append(querys, fmt.Sprintf(" a.business_type in (%s) ", req.BusinessType))
  34. }
  35. if req.ProjectName != "" {
  36. querys = append(querys, " a.projectname like '% "+req.ProjectName+"%'")
  37. }
  38. if req.StartTime > 0 && req.EntTime > 0 {
  39. st := req.StartTime + 90*24*60*60
  40. et := req.StartTime + 90*24*60*60
  41. querys = append(querys, fmt.Sprintf(" a.endtime>=%d and a.endtime<=%d", st, et))
  42. } else if req.StartTime > 0 && req.EntTime == 0 {
  43. st := req.StartTime + 90*24*60*60
  44. querys = append(querys, fmt.Sprintf(" a.endtime>=%d", st))
  45. } else if req.StartTime == 0 && req.EntTime > 0 {
  46. et := req.StartTime + 90*24*60*60
  47. querys = append(querys, fmt.Sprintf(" a.endtime<=%d", et))
  48. } else {
  49. querys = append(querys, " a.endtime>0")
  50. }
  51. var regionArr = []string{}
  52. if req.Area != "" || req.City != "" || req.District != "" {
  53. //城市
  54. city := []string{}
  55. for _, v := range strings.Split(req.City, ",") {
  56. if P.BidCodeMapping.City[v] != "" {
  57. city = append(city, fmt.Sprint(P.BidCodeMapping.City[v]))
  58. }
  59. }
  60. if len(city) > 0 {
  61. regionArr = append(regionArr, fmt.Sprintf(" a.city in (%s) ", strings.Join(city, ",")))
  62. }
  63. //区域
  64. area := []string{}
  65. for _, v := range strings.Split(req.Area, ",") {
  66. if P.BidCodeMapping.Area[v] != "" {
  67. area = append(area, fmt.Sprint(P.BidCodeMapping.Area[v]))
  68. }
  69. }
  70. if len(area) > 0 {
  71. regionArr = append(regionArr, fmt.Sprintf(" a.area in (%s) ", strings.Join(area, ",")))
  72. }
  73. //区域
  74. district := []string{}
  75. if req.District != "" {
  76. for _, v := range strings.Split(req.District, ",") {
  77. cityName := strings.Split(v, "_")[0]
  78. districtName := strings.Split(v, "_")[1]
  79. if P.BidCodeMapping.District[cityName][districtName] != "" {
  80. district = append(district, fmt.Sprint(P.BidCodeMapping.District[cityName][districtName]))
  81. }
  82. }
  83. }
  84. if len(district) > 0 {
  85. regionArr = append(regionArr, fmt.Sprintf(" a.district in (%s) ", strings.Join(district, ",")))
  86. }
  87. if len(regionArr) > 0 {
  88. querys = append(querys, fmt.Sprintf("(%s)", strings.Join(regionArr, "or")))
  89. }
  90. }
  91. if req.SubClass != "" {
  92. arr := []string{}
  93. for _, v := range strings.Split(req.SubClass, ",") {
  94. arr = append(arr, fmt.Sprintf(`"物业_%s"`, v))
  95. }
  96. querys = append(querys, fmt.Sprintf(" a.subclass in (%s) ", strings.Join(regionArr, ",")))
  97. }
  98. // 项目金额
  99. if req.Amount != "" && strings.Contains(req.Amount, "-") {
  100. minPriceStr, maxPriceStr := strings.Split(req.Amount, "-")[0], strings.Split(req.Amount, "-")[1]
  101. minPrice := common.Int64All(common.Float64All(minPriceStr) * 10000) //换成元
  102. maxPrice := common.Int64All(common.Float64All(maxPriceStr) * 10000) //换成元
  103. if minPriceStr != "" && maxPriceStr != "" {
  104. querys = append(querys, fmt.Sprintf("((a.project_money>=%d and a.project_money<=%d))", minPrice, maxPrice))
  105. } else if minPriceStr != "" {
  106. querys = append(querys, fmt.Sprintf("(a.project_money>=%d)", minPrice))
  107. } else if maxPriceStr != "" {
  108. querys = append(querys, fmt.Sprintf("(a.project_money<=%d)", maxPrice))
  109. }
  110. }
  111. //物业业态
  112. if req.PropertyForm != "" {
  113. arr := []string{}
  114. for _, v := range strings.Split(req.PropertyForm, ",") {
  115. arr = append(arr, fmt.Sprintf(`"%s"`, v))
  116. }
  117. querys = append(querys, fmt.Sprintf(" a.property_form in (%s) ", strings.Join(arr, ",")))
  118. }
  119. //查询数量
  120. countSql = fmt.Sprintf("select count(1) as count from %s a where %s %s", "", userStr, strings.Join(querys, " and "))
  121. //列表查询语句
  122. findSql = "select a.id,a.date,a.infoid,a.matchways,a.isvisit,REPLACE(a.matchkeys,'+',' ') as matchkeys,a.type,a.attachment_count"
  123. return
  124. }