plistService.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "strings"
  6. "app.yhyue.com/moapp/jybase/common"
  7. P "app.yhyue.com/moapp/jybase/mapping"
  8. T "bp.jydev.jianyu360.cn/CRM/application/api/common"
  9. "bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
  10. )
  11. const (
  12. pageSize = 100
  13. sql_1 = `SELECT count(1) FROM information.transaction_info WHERE buyer_id = ?`
  14. )
  15. type ProjectData struct {
  16. count int64
  17. hasNextPage bool
  18. pList []*ProjectEntry
  19. }
  20. type ProjectEntry struct {
  21. projectName string
  22. }
  23. func GetProjectList(req *types.ProjectListReq) (resultList *[]map[string]interface{}, hasNextPage bool, total int) {
  24. getSql(req)
  25. //get(req, resultList)
  26. //
  27. //total = len(resultList)
  28. //if total > pageSize {
  29. // resultList = resultList[:pageSize]
  30. // hasNextPage = true
  31. //}
  32. return
  33. }
  34. func getSql(req *types.ProjectListReq) (countSql, findSql string) {
  35. querys := []string{}
  36. // 商机类型
  37. if req.BusinessType != "" {
  38. querys = append(querys, fmt.Sprintf(" a.business_type in (%s) ", req.BusinessType))
  39. }
  40. if req.ProjectName != "" {
  41. querys = append(querys, " a.projectname like '% "+req.ProjectName+"%'")
  42. }
  43. if req.StartTime > 0 && req.EntTime > 0 {
  44. st := req.StartTime + 90*24*60*60
  45. et := req.StartTime + 90*24*60*60
  46. querys = append(querys, fmt.Sprintf(" a.endtime>=%d and a.endtime<=%d", st, et))
  47. } else if req.StartTime > 0 && req.EntTime == 0 {
  48. st := req.StartTime + 90*24*60*60
  49. querys = append(querys, fmt.Sprintf(" a.endtime>=%d", st))
  50. } else if req.StartTime == 0 && req.EntTime > 0 {
  51. et := req.StartTime + 90*24*60*60
  52. querys = append(querys, fmt.Sprintf(" a.endtime<=%d", et))
  53. } else {
  54. querys = append(querys, " a.endtime>0")
  55. }
  56. var regionArr = []string{}
  57. if req.Area != "" || req.City != "" || req.District != "" {
  58. //城市
  59. city := []string{}
  60. for _, v := range strings.Split(req.City, ",") {
  61. if P.BidCodeMapping.City[v] != "" {
  62. city = append(city, fmt.Sprint(P.BidCodeMapping.City[v]))
  63. }
  64. }
  65. if len(city) > 0 {
  66. regionArr = append(regionArr, fmt.Sprintf(" a.city in (%s) ", strings.Join(city, ",")))
  67. }
  68. //区域
  69. area := []string{}
  70. for _, v := range strings.Split(req.Area, ",") {
  71. if P.BidCodeMapping.Area[v] != "" {
  72. area = append(area, fmt.Sprint(P.BidCodeMapping.Area[v]))
  73. }
  74. }
  75. if len(area) > 0 {
  76. regionArr = append(regionArr, fmt.Sprintf(" a.area in (%s) ", strings.Join(area, ",")))
  77. }
  78. //区域
  79. district := []string{}
  80. if req.District != "" {
  81. for _, v := range strings.Split(req.District, ",") {
  82. cityName := strings.Split(v, "_")[0]
  83. districtName := strings.Split(v, "_")[1]
  84. if P.BidCodeMapping.District[cityName][districtName] != "" {
  85. district = append(district, fmt.Sprint(P.BidCodeMapping.District[cityName][districtName]))
  86. }
  87. }
  88. }
  89. if len(district) > 0 {
  90. regionArr = append(regionArr, fmt.Sprintf(" a.district in (%s) ", strings.Join(district, ",")))
  91. }
  92. if len(regionArr) > 0 {
  93. querys = append(querys, fmt.Sprintf("(%s)", strings.Join(regionArr, "or")))
  94. }
  95. }
  96. if req.SubClass != "" {
  97. arr := []string{}
  98. for _, v := range strings.Split(req.SubClass, ",") {
  99. arr = append(arr, fmt.Sprintf(`"物业_%s"`, v))
  100. }
  101. querys = append(querys, fmt.Sprintf(" a.subclass in (%s) ", strings.Join(regionArr, ",")))
  102. }
  103. // 项目金额
  104. if req.Amount != "" && strings.Contains(req.Amount, "-") {
  105. minPriceStr, maxPriceStr := strings.Split(req.Amount, "-")[0], strings.Split(req.Amount, "-")[1]
  106. minPrice := common.Int64All(common.Float64All(minPriceStr) * 10000) //换成元
  107. maxPrice := common.Int64All(common.Float64All(maxPriceStr) * 10000) //换成元
  108. if minPriceStr != "" && maxPriceStr != "" {
  109. querys = append(querys, fmt.Sprintf("((a.project_money>=%d and a.project_money<=%d))", minPrice, maxPrice))
  110. } else if minPriceStr != "" {
  111. querys = append(querys, fmt.Sprintf("(a.project_money>=%d)", minPrice))
  112. } else if maxPriceStr != "" {
  113. querys = append(querys, fmt.Sprintf("(a.project_money<=%d)", maxPrice))
  114. }
  115. }
  116. //物业业态
  117. if req.PropertyForm != "" {
  118. arr := []string{}
  119. for _, v := range strings.Split(req.PropertyForm, ",") {
  120. arr = append(arr, fmt.Sprintf(`"%s"`, v))
  121. }
  122. querys = append(querys, fmt.Sprintf(" a.property_form in (%s) ", strings.Join(arr, ",")))
  123. }
  124. findSql = "select a.project_id,a.project_name,a.project_budget,a.project_money,a.business_type,a.buyer"
  125. return
  126. }
  127. // @Author jianghan
  128. // @Description 处理状态/我的人脉
  129. // @Date 2024/4/17
  130. func get(req *types.ProjectListReq, list []map[string]interface{}) (result []map[string]interface{}) {
  131. field := "is_handle,is_ignore,is_create"
  132. for _, m := range list {
  133. query := map[string]interface{}{
  134. "position_id": req.PositionId,
  135. "relate_id": common.ObjToString(m["project_id"]),
  136. "itype": 2,
  137. }
  138. info := T.CrmMysql.FindOne("connection_status", query, field, "")
  139. if info != nil && len(*info) > 0 {
  140. m["is_handle"] = (*info)["is_handle"]
  141. m["is_ignore"] = (*info)["is_ignore"]
  142. m["is_create"] = (*info)["is_create"]
  143. }
  144. // 人脉、人脉所在单位项目 conn_type: 1/人脉可转介绍项目 conn_type: 2
  145. field1 := ""
  146. query1 := map[string]interface{}{
  147. "position_id": req.PositionId,
  148. "company_id": common.ObjToString(m["buyer_id"]),
  149. "status": 1,
  150. }
  151. info1 := T.CrmMysql.FindOne("connection", query1, field1, "")
  152. if info1 != nil && len(*info1) > 0 {
  153. m["my_conn"] = true
  154. m["conn_type"] = 1
  155. } else {
  156. m["my_conn"] = false
  157. }
  158. if m["conn_type"] != nil {
  159. query2 := map[string]interface{}{
  160. "company_id": common.ObjToString(m["buyer_id"]),
  161. }
  162. info2 := T.CrmMysql.FindOne("connection", query2, field1, "")
  163. if info2 != nil && len(*info2) > 0 {
  164. m["conn_type"] = 1
  165. } else {
  166. m["conn_type"] = 2
  167. }
  168. }
  169. // 转介绍成功率高标签
  170. count := 0
  171. err := T.ClickhouseConn.QueryRow(context.TODO(), sql_1, common.ObjToString(m["buyer_id"])).Scan(&count)
  172. if err != nil && count > 2 {
  173. m["high_success"] = true
  174. } else {
  175. m["high_success"] = false
  176. }
  177. }
  178. return list
  179. }