list.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package house_rent
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "git.getensh.com/common/gopkgs/database"
  9. "git.getensh.com/common/gopkgs/logger"
  10. "go.uber.org/zap"
  11. "google.golang.org/grpc/status"
  12. "property-household/errors"
  13. dbmodel "property-household/model"
  14. "property-household/parser"
  15. "property-household/pb"
  16. pb_v1 "property-household/pb/v1"
  17. "strings"
  18. )
  19. func checkHouseRentListParam(req *pb_v1.HouseRentListRequest) error {
  20. if req.Page == 0 {
  21. req.Page = 1
  22. }
  23. if req.PageSize == 0 {
  24. req.PageSize = 10
  25. }
  26. return nil
  27. }
  28. func houseRentListByGarden(ctx context.Context, req *pb_v1.HouseRentListRequest) (reply *pb_v1.HouseRentListReply, err error) {
  29. mreq := pb_v1.GardenHouseRentListRequest{
  30. GardenId: req.GardenId,
  31. ProvinceCode: req.ProvinceCode,
  32. CityCode: req.CityCode,
  33. AreaCode: req.AreaCode,
  34. StreetCode: req.StreetCode,
  35. RoomCount: req.RoomCount,
  36. HallCount: req.HallCount,
  37. WcCount: req.WcCount,
  38. HouseholdUid: req.HouseholdUid,
  39. RentPriceGreater: req.RentPriceGreater,
  40. RentPriceLess: req.RentPriceLess,
  41. ApproveStatus: req.ApproveStatus,
  42. Page: req.Page,
  43. PageSize: req.PageSize,
  44. BaseConf: req.BaseConf,
  45. SpecialConf: req.SpecialConf,
  46. }
  47. mreply, err := pb.Garden.GardenHouseRentList(context.Background(), &mreq)
  48. if err != nil {
  49. return nil, err
  50. }
  51. reply = &pb_v1.HouseRentListReply{
  52. Page: mreply.Page,
  53. Total: mreply.Total,
  54. List: mreply.List,
  55. }
  56. return reply, nil
  57. }
  58. func getGardenInfos(ids []int64) (map[int64]pb_v1.GardenItem, error) {
  59. ret := map[int64]pb_v1.GardenItem{}
  60. if len(ids) == 0 {
  61. return ret, nil
  62. }
  63. mreq := pb_v1.GardenInfosRequest{
  64. Ids: ids,
  65. }
  66. mreply, err := pb.System.GardenInfos(context.Background(), &mreq)
  67. if err != nil {
  68. return nil, err
  69. }
  70. if len(mreply.List) == 0 {
  71. return ret, nil
  72. }
  73. for _, v := range mreply.List {
  74. ret[v.Id] = *v
  75. }
  76. return ret, nil
  77. }
  78. //
  79. func HouseRentList(ctx context.Context, req *pb_v1.HouseRentListRequest) (reply *pb_v1.HouseRentListReply, err error) {
  80. reply = &pb_v1.HouseRentListReply{}
  81. // 捕获各个task中的异常并返回给调用者
  82. defer func() {
  83. if r := recover(); r != nil {
  84. err = fmt.Errorf("%+v", r)
  85. e := &status.Status{}
  86. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  87. logger.Error("err",
  88. zap.String("system_err", err.Error()),
  89. zap.Stack("stacktrace"))
  90. }
  91. }
  92. }()
  93. err = checkHouseRentListParam(req)
  94. if err != nil {
  95. return nil, err
  96. }
  97. if req.GardenId > 0 {
  98. return houseRentListByGarden(ctx, req)
  99. }
  100. p := dbmodel.THouseRent{}
  101. where := map[string]interface{}{}
  102. if len(req.GardenIds) > 0 {
  103. where["garden_id in"] = req.GardenIds
  104. }
  105. if req.ApproveStatus > 0 {
  106. where["approve_status"] = req.ApproveStatus
  107. }
  108. if req.SpecialConf > 0 {
  109. where["special_conf & ? > 0 "] = req.SpecialConf
  110. }
  111. if req.BaseConf > 0 {
  112. where["base_conf & ? > 0 "] = req.BaseConf
  113. }
  114. if req.HouseholdUid > 0 {
  115. where["household_uid"] = req.HouseholdUid
  116. }
  117. if req.RoomCount > 0 {
  118. if req.RoomCount > 4 {
  119. where["room_count >"] = 4
  120. } else {
  121. where["room_count"] = req.RoomCount
  122. }
  123. }
  124. if req.HallCount > 0 {
  125. if req.HallCount > 4 {
  126. where["hall_count >"] = 4
  127. } else {
  128. where["hall_count"] = req.HallCount
  129. }
  130. }
  131. if req.WcCount > 0 {
  132. where["wc_count"] = req.WcCount
  133. }
  134. if req.StreetCode != "" {
  135. where["street_code"] = req.StreetCode
  136. } else if req.AreaCode != "" {
  137. where["area_code"] = req.AreaCode
  138. } else if req.CityCode != "" {
  139. where["city_code"] = req.CityCode
  140. } else if req.ProvinceCode != "" {
  141. where["province_code"] = req.ProvinceCode
  142. }
  143. if req.RentPriceLess > 0 {
  144. where["rent_price <="] = req.RentPriceLess * 100
  145. }
  146. if req.RentPriceGreater > 0 {
  147. where["rent_price >"] = req.RentPriceGreater * 100
  148. }
  149. where["approve_status !="] = 4
  150. reply.Page = req.Page
  151. reply.Total, err = p.Count(database.DB(), where, nil)
  152. if err != nil {
  153. return nil, errors.DataBaseError
  154. }
  155. if reply.Total == 0 {
  156. return reply, nil
  157. }
  158. list, err := p.ListByJoin(database.DB(), where, nil, int(req.Page), int(req.PageSize))
  159. if err != nil {
  160. return nil, errors.DataBaseError
  161. }
  162. reply.List = make([]*pb_v1.HouseRentItem, len(list))
  163. m := map[int64]bool{}
  164. gardenIds := []int64{}
  165. for _, v := range list {
  166. if _, ok := m[v.GardenId]; !ok {
  167. m[v.GardenId] = true
  168. gardenIds = append(gardenIds, v.GardenId)
  169. }
  170. }
  171. gardenInfos, err := getGardenInfos(gardenIds)
  172. if err != nil {
  173. return nil, errors.DataBaseError
  174. }
  175. for i, v := range list {
  176. item := &pb_v1.HouseRentItem{
  177. HouseName: v.HouseName,
  178. Layer: v.Layer,
  179. HouseArea: v.HouseArea,
  180. Direction: v.Diretion,
  181. RoomCount: v.RoomCount,
  182. HallCount: v.HallCount,
  183. WcCount: v.WcCount,
  184. Decorating: v.Decorating,
  185. Contacter: v.Contacter,
  186. ContactPhone: v.ContactPhone,
  187. PayTimeType: v.PayTimeType,
  188. RentType: v.RentType,
  189. RoomType: v.RoomType,
  190. RoomArea: v.RoomArea,
  191. RentPrice: v.RentPrice,
  192. Desposit: v.Desposit,
  193. //InTime:0,
  194. ApproveStatus: v.ApproveStatus,
  195. ServicePrice: v.ServicePrice,
  196. IntermediaryPrice: v.IntermediaryPrice,
  197. //BaseConf:,
  198. //SpecialConf
  199. Desc: v.Desc,
  200. HousePic: strings.Split(v.HousePic, ";"),
  201. CertPic: strings.Split(v.CertPic, ";"),
  202. //HasLift:
  203. GardenId: v.GardenId,
  204. Id: v.ID,
  205. GardenName: v.GardenName,
  206. Province: gardenInfos[v.GardenId].Province,
  207. City: gardenInfos[v.GardenId].City,
  208. Street: gardenInfos[v.GardenId].Street,
  209. Area: gardenInfos[v.GardenId].Area,
  210. Lat: v.Lat,
  211. Lnt: v.Lnt,
  212. Addr: gardenInfos[v.GardenId].GardenAddr,
  213. HouseId: v.HouseId,
  214. InTime: v.InTime,
  215. GardenDesc: gardenInfos[v.GardenId].GardenDesc,
  216. }
  217. if v.HasLift == 1 {
  218. item.HasLift = true
  219. }
  220. //bconf := BaseConfToBool(v.BaseConf)
  221. item.BaseConf = v.BaseConf
  222. //sconf := SpecialConfToBool(v.SpecialConf)
  223. item.SpecialConf = v.SpecialConf
  224. if v.HousePic == "" {
  225. item.HousePic = []string{parser.Conf.Oss.Protocol + "://" + parser.Conf.Oss.Endpoint + "/" + parser.Conf.Oss.FixBucket + "/" + parser.Conf.Oss.RentObj}
  226. }
  227. reply.List[i] = item
  228. }
  229. return reply, nil
  230. }