123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package house
- import (
- "context"
- "encoding/json"
- "fmt"
- "gorm.io/gorm"
- "property-garden/errors"
- dbmodel "property-garden/model"
- "property-garden/pb"
- pb_v1 "property-garden/pb/v1"
- "property-garden/utils"
- "git.getensh.com/common/gopkgs/database"
- "git.getensh.com/common/gopkgs/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- )
- func checkHouseInfoParam(req *pb_v1.HouseInfoRequest) error {
- if req.HouseId < 1 {
- return errors.ParamsError
- }
- return nil
- }
- 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 ret, err
- }
- for _, v := range mreply.List {
- ret[v.Id] = *v
- }
- return ret, nil
- }
- //
- func HouseInfo(ctx context.Context, req *pb_v1.HouseInfoRequest) (reply *pb_v1.HouseInfoReply, err error) {
- // 捕获各个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 = checkHouseInfoParam(req)
- if err != nil {
- return nil, err
- }
- // 房屋
- dbname := utils.GetGardenDbName(req.GardenId)
- house := dbmodel.NewHouse(dbname)
- where := map[string]interface{}{
- "id": req.HouseId,
- }
- err = house.Find(database.DB(), where)
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, errors.DataBaseError
- }
- if house.ID == 0 {
- return nil, errors.ErrRecordNotFound
- }
- // 楼栋
- building := dbmodel.NewBuilding(dbname)
- where = map[string]interface{}{
- "id": house.BuildingId,
- }
- err = building.Find(database.DB(), where)
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, errors.DataBaseError
- }
- if building.ID == 0 {
- return nil, errors.ErrRecordNotFound
- }
- // 单元
- unit := dbmodel.NewUnit(dbname)
- where = map[string]interface{}{
- "id": house.UnitId,
- }
- err = unit.Find(database.DB(), where)
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, errors.DataBaseError
- }
- if unit.ID == 0 {
- return nil, errors.ErrRecordNotFound
- }
- // 小区
- gardenInfos, err := getGardenInfos([]int64{req.GardenId})
- if err != nil {
- return nil, err
- }
- garden := gardenInfos[req.GardenId]
- reply = &pb_v1.HouseInfoReply{
- GardenId: req.GardenId,
- BuildingNumber: building.BuildingNumber,
- UnitNumber: unit.UnitNumber,
- HouseNumber: house.HouseNumber,
- GardenName: garden.GardenName,
- Province: garden.Province,
- City: garden.City,
- Area: garden.Area,
- Street: garden.Street,
- Comittee: garden.Committee,
- ProvinceCode: garden.ProvinceCode,
- CityCode: garden.CityCode,
- AreaCode: garden.AreaCode,
- StreetCode: garden.StreetCode,
- ComitteeCode: garden.CommitteeCode,
- Layer: house.Layer,
- HouseArea: house.HouseArea,
- HouseUsedArea: house.HouseUsedArea,
- RoomCount: house.RoomCount,
- // 几厅
- HallCount: house.HallCount,
- // 房屋类型 1 住宅 2 商铺 3 办公
- HouseType: house.HouseType,
- GardenInUse: garden.InUse,
- HouseStatus:int32(house.Status),
- BuildingId:house.BuildingId,
- UnitId:house.UnitId,
- }
- if unit.HasLift == 1 {
- reply.HasLift = true
- }
- return reply, nil
- }
|