123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package house
- import (
- "context"
- "encoding/json"
- "fmt"
- "property-garden/errors"
- dbmodel "property-garden/model"
- 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 checkHouseListParam(req *pb_v1.HouseListRequest) error {
- if req.Page == 0 {
- req.Page = 1
- }
- if req.PageSize == 0 {
- req.PageSize = 10
- }
- if req.GardenId < 1 && req.UnitId == 0 && req.BuildingId == 0 {
- return errors.ParamsError
- }
- return nil
- }
- //
- func HouseList(ctx context.Context, req *pb_v1.HouseListRequest) (reply *pb_v1.HouseListReply, err error) {
- reply = &pb_v1.HouseListReply{}
- // 捕获各个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 = checkHouseListParam(req)
- if err != nil {
- return nil, err
- }
- dbname := utils.GetGardenDbName(req.GardenId)
- p := dbmodel.NewHouseUnitBuilding(dbname)
- where := map[string]interface{}{}
- if req.GardenId > 0 {
- //where["garden_id"] = req.GardenId
- }
- if req.BuildingId > 0 {
- where["building_id"] = req.BuildingId
- }
- if req.UnitId > 0 {
- where["unit_id"] = req.UnitId
- }
- if req.HouseType > 0 {
- where["house_type"] = req.HouseType
- }
- if req.HouseNumber != "" {
- where["house_number"] = req.HouseNumber
- }
- if req.HouseStatus > 0 {
- where["status"] = req.HouseStatus
- }
- if req.Layer > 0 {
- where["layer"] = req.Layer
- }
- if req.HouseId > 0 {
- where["id"] = req.HouseId
- }
- if req.HouseRent {
- where["id not in(select house_id from "+dbname+".t_house_rent where approve_status < 4)"] = ""
- }
- if req.Uid > 0 {
- p := dbmodel.NewHouseApprovedGarden(dbname)
- whereTmp := map[string]interface{}{
- "uid": req.Uid,
- }
- list, err := p.List(database.DB(), whereTmp, nil, -1, -1)
- if err != nil {
- return nil, errors.DataBaseError
- }
- houseIds := []int64{}
- for _, v := range list {
- houseIds = append(houseIds, v.HouseId)
- }
- if len(houseIds) == 0 {
- houseIds = []int64{0}
- }
- where["id in"] = houseIds
- }
- 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.HouseItem, len(list))
- for i, v := range list {
- reply.List[i] = &pb_v1.HouseItem{
- Id: v.ID,
- HallCount: v.HallCount,
- RoomCount: v.RoomCount,
- HouseArea: v.HouseArea,
- HouseUsedArea: v.HouseUsedArea,
- HouseNumber: v.HouseNumber,
- Layer: v.Layer,
- HouseType: v.HouseType,
- Status: int32(v.Status),
- HouseName: fmt.Sprintf("%s-%d-%s", v.BuildingNumber, v.UnitNumber, v.HouseNumber),
- BuildingId: v.BuildingId,
- UnitId: v.UnitId,
- UnitNumber: v.UnitNumber,
- BuildingNumber: v.BuildingNumber,
- }
- if v.HasLift == 1 {
- reply.List[i].HasLift = true
- }
- /*
- if !strings.Contains(v.HouseNumber, "-") {
- if v.UnitNumber > 0 {
- reply.List[i].HouseName = fmt.Sprintf("%s-%d-%s", v.BuildingNumber, v.UnitNumber, v.HouseNumber)
- } else {
- reply.List[i].HouseName = fmt.Sprintf("%s-%s", v.BuildingNumber, v.HouseNumber)
- }
- }*/
- }
- return reply, nil
- }
|