123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package house_rent
- import (
- "context"
- "encoding/json"
- "fmt"
- "git.getensh.com/common/gopkgs/database"
- "git.getensh.com/common/gopkgs/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- "property-garden/errors"
- dbmodel "property-garden/model"
- "property-garden/pb"
- pb_v1 "property-garden/pb/v1"
- "property-garden/utils"
- "strings"
- )
- func checkGardenHouseRentListParam(req *pb_v1.GardenHouseRentListRequest) error {
- if req.Page == 0 {
- req.Page = 1
- }
- if req.PageSize == 0 {
- req.PageSize = 10
- }
- if req.GardenId < 1 {
- return status.Error(10003, "小区不能为空")
- }
- return nil
- }
- func BaseConfToBool(data int64) pb_v1.HouseRentBaseConf {
- conf := pb_v1.HouseRentBaseConf{}
- one := int64(1)
- if data & one > 0 {
- conf.Bed = true
- }
- if data & (one << 1) > 0{
- conf.Gas = true
- }
- if data & (one << 2) > 0{
- conf.WarmGas = true
- }
- if data & (one << 3) > 0{
- conf.Broadband = true
- }
- if data & (one << 4) > 0{
- conf.Refragerator = true
- }
- if data & (one << 5) > 0{
- conf.Wardobe = true
- }
- if data & (one << 6) > 0{
- conf.Sofa = true
- }
- if data & (one << 7) > 0{
- conf.Aircondition = true
- }
- if data & (one << 8) > 0{
- conf.Tv = true
- }
- if data & (one << 9) > 0{
- conf.Heater = true
- }
- if data & (one << 10) > 0{
- conf.Warshing = true
- }
- return conf
- }
- func SpecialConfToBool(data int64) pb_v1.HouseRentSpecialConf {
- conf := pb_v1.HouseRentSpecialConf{}
- one := int64(1)
- if data & one > 0 {
- conf.IntelligentLock = true
- }
- if data & (one << 1) > 0{
- conf.Wifi = true
- }
- if data & (one << 2) > 0{
- conf.Metro = true
- }
- if data & (one << 3) > 0{
- conf.ParkSpace = true
- }
- if data & (one << 4) > 0{
- conf.IndependentWc = true
- }
- if data & (one << 5) > 0{
- conf.PrivateBalcony = true
- }
- if data & (one << 6) > 0{
- conf.FirstRent = true
- }
- return conf
- }
- func BaseConfToBitmap(conf *pb_v1.HouseRentBaseConf) int64 {
- ret := int64(0)
- one := int64(1)
- if conf.Bed {
- ret = ret |(one)
- }
- if conf.Gas {
- ret = ret |(one << 1)
- }
- if conf.WarmGas {
- ret = ret |(one << 2)
- }
- if conf.Broadband {
- ret = ret |(one << 3)
- }
- if conf.Refragerator {
- ret = ret |(one << 4)
- }
- if conf.Wardobe {
- ret = ret |(one << 5)
- }
- if conf.Sofa {
- ret = ret |(one << 6)
- }
- if conf.Aircondition {
- ret = ret |(one << 7)
- }
- if conf.Tv {
- ret = ret |(one << 8)
- }
- if conf.Heater {
- ret = ret |(one << 9)
- }
- if conf.Warshing {
- ret = ret |(one << 10)
- }
- return ret
- }
- func SpecialConfToBitmap(conf *pb_v1.HouseRentSpecialConf) int64 {
- ret := int64(0)
- one := int64(1)
- if conf.IntelligentLock {
- ret = ret |(one)
- }
- if conf.Wifi {
- ret = ret |(one << 1)
- }
- if conf.Metro {
- ret = ret |(one << 2)
- }
- if conf.ParkSpace {
- ret = ret |(one << 3)
- }
- if conf.IndependentWc {
- ret = ret |(one << 4)
- }
- if conf.PrivateBalcony {
- ret = ret |(one << 5)
- }
- if conf.FirstRent {
- ret = ret |(one << 6)
- }
- return ret
- }
- func getGardenInfos(ids []int64) (map[int64]pb_v1.GardenItem, error) {
- ret := map[int64]pb_v1.GardenItem{}
- if len(ids) == 0 {
- return ret, nil
- }
- mreq := pb_v1.GardenInfosRequest{
- Ids:ids,
- }
- mreply, err := pb.System.GardenInfos(context.Background(), &mreq)
- if err != nil {
- return nil, err
- }
- if len(mreply.List) == 0 {
- return ret, nil
- }
- for _, v := range mreply.List {
- ret[v.Id] = *v
- }
- return ret, nil
- }
- //
- func GardenHouseRentList(ctx context.Context, req *pb_v1.GardenHouseRentListRequest) (reply *pb_v1.GardenHouseRentListReply, err error) {
- reply = &pb_v1.GardenHouseRentListReply{}
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- err = checkGardenHouseRentListParam(req)
- if err != nil {
- return nil, err
- }
- dbname := utils.GetGardenDbName(req.GardenId)
- p := dbmodel.NewHouseRent(dbname)
- where := map[string]interface{}{}
- if req.ApproveStatus > 0 {
- where["approve_status"] = req.ApproveStatus
- }
- if req.SpecialConf > 0 {
- where["special_conf & ? > 0 "] = req.SpecialConf
- }
- if req.BaseConf > 0 {
- where["base_conf & ? > 0 "] = req.BaseConf
- }
- if req.HouseholdUid > 0 {
- where["household_uid"] = req.HouseholdUid
- }
- if req.RoomCount > 0 {
- where["room_count"] = req.RoomCount
- }
- if req.HallCount > 0 {
- where["hall_count"] = req.HallCount
- }
- if req.WcCount > 0 {
- where["wc_count"] = req.WcCount
- }
- if req.StreetCode != "" {
- where["street_code"] = req.StreetCode
- } else if req.AreaCode != "" {
- where["area_code"] = req.AreaCode
- } else if req.CityCode != "" {
- where["city_code"] = req.CityCode
- } else if req.ProvinceCode != "" {
- where["province_code"] = req.ProvinceCode
- }
- if req.RentPriceLess > 0 {
- where["rent_price <="] = req.RentPriceLess
- }
- if req.RentPriceGreater > 0 {
- where["rent_price >"] = req.RentPriceGreater
- }
- if req.Contacter != "" {
- where["contacter"] = req.Contacter
- }
- if req.ContacterPhone != "" {
- where["contact_phone"] = req.ContacterPhone
- }
- reply.Page = req.Page
- reply.Total, err = p.Count(database.DB(), where, nil)
- if err != nil {
- return nil, errors.DataBaseError
- }
- if reply.Total == 0 {
- return reply, nil
- }
- list, err := p.List(database.DB(), where, nil, int(req.Page), int(req.PageSize))
- if err != nil {
- return nil, errors.DataBaseError
- }
- reply.List = make([]*pb_v1.HouseRentItem, len(list))
- m := map[int64]bool{}
- gardenIds := []int64{}
- for _, v := range list {
- if _, ok := m[v.GardenId]; !ok {
- m[v.GardenId] = true
- gardenIds = append(gardenIds, v.GardenId)
- }
- }
- gardenInfos, err := getGardenInfos(gardenIds)
- if err != nil {
- return nil, errors.DataBaseError
- }
- for i, v := range list {
- item := &pb_v1.HouseRentItem{
- HouseName: v.HouseName,
- HouseId:v.HouseId,
- Layer: v.Layer,
- HouseArea: v.HouseArea,
- Direction: v.Diretion,
- RoomCount: v.RoomCount,
- HallCount:v.HallCount,
- WcCount: v.WcCount,
- Decorating:v.Decorating,
- Contacter:v.Contacter,
- ContactPhone:v.ContactPhone,
- PayTimeType:v.PayTimeType,
- RentType:v.RentType,
- RoomType:v.RoomType,
- RoomArea:v.RoomArea,
- RentPrice:v.RentPrice,
- Desposit:v.Desposit,
- //InTime:0,
- ApproveStatus:v.ApproveStatus,
- ServicePrice: v.ServicePrice,
- IntermediaryPrice:v.IntermediaryPrice,
- //BaseConf:,
- //SpecialConf
- Desc: v.Desc,
- HousePic:strings.Split(v.HousePic, ";"),
- CertPic:strings.Split(v.CertPic, ";"),
- //HasLift:
- GardenId:v.GardenId,
- Id:v.ID,
- GardenName:v.GardenName,
- Province:gardenInfos[v.GardenId].Province,
- City:gardenInfos[v.GardenId].City,
- Street:gardenInfos[v.GardenId].Street,
- Area:gardenInfos[v.GardenId].Area,
- Lat:v.Lat,
- Lnt:v.Lnt,
- Addr:gardenInfos[v.GardenId].GardenAddr,
- InTime:v.InTime,
- }
- if v.HasLift == 1 {
- item.HasLift = true
- }
- //bconf := BaseConfToBool(v.BaseConf)
- item.BaseConf = v.BaseConf
- //sconf := SpecialConfToBool(v.SpecialConf)
- item.SpecialConf = v.SpecialConf
- reply.List[i] = item
- }
- return reply, nil
- }
|