list.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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-garden/errors"
  13. dbmodel "property-garden/model"
  14. "property-garden/pb"
  15. pb_v1 "property-garden/pb/v1"
  16. "property-garden/utils"
  17. "strings"
  18. )
  19. func checkGardenHouseRentListParam(req *pb_v1.GardenHouseRentListRequest) error {
  20. if req.Page == 0 {
  21. req.Page = 1
  22. }
  23. if req.PageSize == 0 {
  24. req.PageSize = 10
  25. }
  26. if req.GardenId < 1 {
  27. return status.Error(10003, "小区不能为空")
  28. }
  29. return nil
  30. }
  31. func BaseConfToBool(data int64) pb_v1.HouseRentBaseConf {
  32. conf := pb_v1.HouseRentBaseConf{}
  33. one := int64(1)
  34. if data & one > 0 {
  35. conf.Bed = true
  36. }
  37. if data & (one << 1) > 0{
  38. conf.Gas = true
  39. }
  40. if data & (one << 2) > 0{
  41. conf.WarmGas = true
  42. }
  43. if data & (one << 3) > 0{
  44. conf.Broadband = true
  45. }
  46. if data & (one << 4) > 0{
  47. conf.Refragerator = true
  48. }
  49. if data & (one << 5) > 0{
  50. conf.Wardobe = true
  51. }
  52. if data & (one << 6) > 0{
  53. conf.Sofa = true
  54. }
  55. if data & (one << 7) > 0{
  56. conf.Aircondition = true
  57. }
  58. if data & (one << 8) > 0{
  59. conf.Tv = true
  60. }
  61. if data & (one << 9) > 0{
  62. conf.Heater = true
  63. }
  64. if data & (one << 10) > 0{
  65. conf.Warshing = true
  66. }
  67. return conf
  68. }
  69. func SpecialConfToBool(data int64) pb_v1.HouseRentSpecialConf {
  70. conf := pb_v1.HouseRentSpecialConf{}
  71. one := int64(1)
  72. if data & one > 0 {
  73. conf.IntelligentLock = true
  74. }
  75. if data & (one << 1) > 0{
  76. conf.Wifi = true
  77. }
  78. if data & (one << 2) > 0{
  79. conf.Metro = true
  80. }
  81. if data & (one << 3) > 0{
  82. conf.ParkSpace = true
  83. }
  84. if data & (one << 4) > 0{
  85. conf.IndependentWc = true
  86. }
  87. if data & (one << 5) > 0{
  88. conf.PrivateBalcony = true
  89. }
  90. if data & (one << 6) > 0{
  91. conf.FirstRent = true
  92. }
  93. return conf
  94. }
  95. func BaseConfToBitmap(conf *pb_v1.HouseRentBaseConf) int64 {
  96. ret := int64(0)
  97. one := int64(1)
  98. if conf.Bed {
  99. ret = ret |(one)
  100. }
  101. if conf.Gas {
  102. ret = ret |(one << 1)
  103. }
  104. if conf.WarmGas {
  105. ret = ret |(one << 2)
  106. }
  107. if conf.Broadband {
  108. ret = ret |(one << 3)
  109. }
  110. if conf.Refragerator {
  111. ret = ret |(one << 4)
  112. }
  113. if conf.Wardobe {
  114. ret = ret |(one << 5)
  115. }
  116. if conf.Sofa {
  117. ret = ret |(one << 6)
  118. }
  119. if conf.Aircondition {
  120. ret = ret |(one << 7)
  121. }
  122. if conf.Tv {
  123. ret = ret |(one << 8)
  124. }
  125. if conf.Heater {
  126. ret = ret |(one << 9)
  127. }
  128. if conf.Warshing {
  129. ret = ret |(one << 10)
  130. }
  131. return ret
  132. }
  133. func SpecialConfToBitmap(conf *pb_v1.HouseRentSpecialConf) int64 {
  134. ret := int64(0)
  135. one := int64(1)
  136. if conf.IntelligentLock {
  137. ret = ret |(one)
  138. }
  139. if conf.Wifi {
  140. ret = ret |(one << 1)
  141. }
  142. if conf.Metro {
  143. ret = ret |(one << 2)
  144. }
  145. if conf.ParkSpace {
  146. ret = ret |(one << 3)
  147. }
  148. if conf.IndependentWc {
  149. ret = ret |(one << 4)
  150. }
  151. if conf.PrivateBalcony {
  152. ret = ret |(one << 5)
  153. }
  154. if conf.FirstRent {
  155. ret = ret |(one << 6)
  156. }
  157. return ret
  158. }
  159. func getGardenInfos(ids []int64) (map[int64]pb_v1.GardenItem, error) {
  160. ret := map[int64]pb_v1.GardenItem{}
  161. if len(ids) == 0 {
  162. return ret, nil
  163. }
  164. mreq := pb_v1.GardenInfosRequest{
  165. Ids:ids,
  166. }
  167. mreply, err := pb.System.GardenInfos(context.Background(), &mreq)
  168. if err != nil {
  169. return nil, err
  170. }
  171. if len(mreply.List) == 0 {
  172. return ret, nil
  173. }
  174. for _, v := range mreply.List {
  175. ret[v.Id] = *v
  176. }
  177. return ret, nil
  178. }
  179. //
  180. func GardenHouseRentList(ctx context.Context, req *pb_v1.GardenHouseRentListRequest) (reply *pb_v1.GardenHouseRentListReply, err error) {
  181. reply = &pb_v1.GardenHouseRentListReply{}
  182. // 捕获各个task中的异常并返回给调用者
  183. defer func() {
  184. if r := recover(); r != nil {
  185. err = fmt.Errorf("%+v", r)
  186. e := &status.Status{}
  187. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  188. logger.Error("err",
  189. zap.String("system_err", err.Error()),
  190. zap.Stack("stacktrace"))
  191. }
  192. }
  193. }()
  194. err = checkGardenHouseRentListParam(req)
  195. if err != nil {
  196. return nil, err
  197. }
  198. dbname := utils.GetGardenDbName(req.GardenId)
  199. p := dbmodel.NewHouseRent(dbname)
  200. where := map[string]interface{}{}
  201. if req.ApproveStatus > 0 {
  202. where["approve_status"] = req.ApproveStatus
  203. }
  204. if req.SpecialConf > 0 {
  205. where["special_conf & ? > 0 "] = req.SpecialConf
  206. }
  207. if req.BaseConf > 0 {
  208. where["base_conf & ? > 0 "] = req.BaseConf
  209. }
  210. if req.HouseholdUid > 0 {
  211. where["household_uid"] = req.HouseholdUid
  212. }
  213. if req.RoomCount > 0 {
  214. where["room_count"] = req.RoomCount
  215. }
  216. if req.HallCount > 0 {
  217. where["hall_count"] = req.HallCount
  218. }
  219. if req.WcCount > 0 {
  220. where["wc_count"] = req.WcCount
  221. }
  222. if req.StreetCode != "" {
  223. where["street_code"] = req.StreetCode
  224. } else if req.AreaCode != "" {
  225. where["area_code"] = req.AreaCode
  226. } else if req.CityCode != "" {
  227. where["city_code"] = req.CityCode
  228. } else if req.ProvinceCode != "" {
  229. where["province_code"] = req.ProvinceCode
  230. }
  231. if req.RentPriceLess > 0 {
  232. where["rent_price <="] = req.RentPriceLess
  233. }
  234. if req.RentPriceGreater > 0 {
  235. where["rent_price >"] = req.RentPriceGreater
  236. }
  237. if req.Contacter != "" {
  238. where["contacter"] = req.Contacter
  239. }
  240. if req.ContacterPhone != "" {
  241. where["contact_phone"] = req.ContacterPhone
  242. }
  243. reply.Page = req.Page
  244. reply.Total, err = p.Count(database.DB(), where, nil)
  245. if err != nil {
  246. return nil, errors.DataBaseError
  247. }
  248. if reply.Total == 0 {
  249. return reply, nil
  250. }
  251. list, err := p.List(database.DB(), where, nil, int(req.Page), int(req.PageSize))
  252. if err != nil {
  253. return nil, errors.DataBaseError
  254. }
  255. reply.List = make([]*pb_v1.HouseRentItem, len(list))
  256. m := map[int64]bool{}
  257. gardenIds := []int64{}
  258. for _, v := range list {
  259. if _, ok := m[v.GardenId]; !ok {
  260. m[v.GardenId] = true
  261. gardenIds = append(gardenIds, v.GardenId)
  262. }
  263. }
  264. gardenInfos, err := getGardenInfos(gardenIds)
  265. if err != nil {
  266. return nil, errors.DataBaseError
  267. }
  268. for i, v := range list {
  269. item := &pb_v1.HouseRentItem{
  270. HouseName: v.HouseName,
  271. HouseId:v.HouseId,
  272. Layer: v.Layer,
  273. HouseArea: v.HouseArea,
  274. Direction: v.Diretion,
  275. RoomCount: v.RoomCount,
  276. HallCount:v.HallCount,
  277. WcCount: v.WcCount,
  278. Decorating:v.Decorating,
  279. Contacter:v.Contacter,
  280. ContactPhone:v.ContactPhone,
  281. PayTimeType:v.PayTimeType,
  282. RentType:v.RentType,
  283. RoomType:v.RoomType,
  284. RoomArea:v.RoomArea,
  285. RentPrice:v.RentPrice,
  286. Desposit:v.Desposit,
  287. //InTime:0,
  288. ApproveStatus:v.ApproveStatus,
  289. ServicePrice: v.ServicePrice,
  290. IntermediaryPrice:v.IntermediaryPrice,
  291. //BaseConf:,
  292. //SpecialConf
  293. Desc: v.Desc,
  294. HousePic:strings.Split(v.HousePic, ";"),
  295. CertPic:strings.Split(v.CertPic, ";"),
  296. //HasLift:
  297. GardenId:v.GardenId,
  298. Id:v.ID,
  299. GardenName:v.GardenName,
  300. Province:gardenInfos[v.GardenId].Province,
  301. City:gardenInfos[v.GardenId].City,
  302. Street:gardenInfos[v.GardenId].Street,
  303. Area:gardenInfos[v.GardenId].Area,
  304. Lat:v.Lat,
  305. Lnt:v.Lnt,
  306. Addr:gardenInfos[v.GardenId].GardenAddr,
  307. InTime:v.InTime,
  308. }
  309. if v.HasLift == 1 {
  310. item.HasLift = true
  311. }
  312. //bconf := BaseConfToBool(v.BaseConf)
  313. item.BaseConf = v.BaseConf
  314. //sconf := SpecialConfToBool(v.SpecialConf)
  315. item.SpecialConf = v.SpecialConf
  316. reply.List[i] = item
  317. }
  318. return reply, nil
  319. }