123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package garden
- import (
- "context"
- "encoding/json"
- "fmt"
- "property-system/errors"
- dbmodel "property-system/model"
- pb_v1 "property-system/pb/v1"
- "strings"
- "time"
- "git.getensh.com/common/gopkgs/database"
- "git.getensh.com/common/gopkgs/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- )
- func GardenListApproved(ctx context.Context, req *pb_v1.GardenListRequest) (reply *pb_v1.GardenListReply, err error) {
- reply = &pb_v1.GardenListReply{}
- garden := &dbmodel.TGardenApproved{}
- where := map[string]interface{}{
- "in_use": true,
- }
- if req.Cid > 0 {
- where["cid"] = req.Cid
- }
- if req.CommitteeCode != "" {
- where["committee_code"] = req.CommitteeCode
- } else 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.GardenName != "" {
- where["garden_name like"] = "%" + req.GardenName + "%"
- }
- if req.ApproveStatus > 0 {
- where["status"] = req.ApproveStatus
- }
- if req.BuildingType > 0 {
- where["building_type"] = req.BuildingType
- }
- if req.BuildingYearLess > 0 {
- year := time.Now().Year() - int(req.BuildingYearLess)
- where["building_end >="] = time.Date(year, 1, 1, 0, 0, 0, 0, time.Now().Location()).Unix()
- }
- if req.BuildingYearGreater > 0 {
- year := time.Now().Year() - int(req.BuildingYearGreater)
- where["building_start <="] = time.Date(year, 1, 1, 0, 0, 0, 0, time.Now().Location()).Unix()
- }
- if req.PriceLess > 0 {
- where["avg_price <="] = req.PriceLess
- }
- if req.PriceGreater > 0 {
- where["avg_price >="] = req.PriceGreater
- }
- reply.Page = req.Page
- reply.Total, err = garden.Count(database.DB(), where, nil)
- if err != nil {
- return nil, errors.DataBaseError
- }
- if reply.Total == 0 {
- return reply, nil
- }
- list, err := garden.List(database.DB(), where, nil, int(req.Page), int(req.PageSize))
- if err != nil {
- return nil, errors.DataBaseError
- }
- reply.List = make([]*pb_v1.GardenItem, len(list))
- for i, v := range list {
- item := &pb_v1.GardenItem{
- Province: v.Province,
- ProvinceCode: v.ProvinceCode,
- City: v.City,
- CityCode: v.CityCode,
- Area: v.Area,
- AreaCode: v.AreaCode,
- Street: v.Street,
- StreetCode: v.StreetCode,
- Committee: v.Committee,
- CommitteeCode: v.CommitteeCode,
- PropertyPerson: v.PropertyPerson,
- PropertyPhone: v.PropertyPhone,
- GardenName: v.GardenName,
- GardenAddr: v.GardenAddr,
- Cid: v.Cid,
- Id: v.ID,
- GardenDesc: v.GardenDesc,
- GardenPic: v.GardenPic,
- Lat: v.Lat,
- Lnt: v.Lnt,
- Status: GardenStatusApproved,
- Appendix: strings.Split(v.Appendix, ";"),
- PayMode: v.PayMode,
- MchId: v.MchId,
- HouseCountLimit: v.HouseCountLimit,
- HouseCount: v.HouseCount,
- ExpireAt: v.ExpireAt,
- GardenPics: strings.Split(v.GardenPics, ";"),
- BuildingStart: v.BuildingStart,
- BuildingEnd: v.BuildingEnd,
- PropertyFeeStart: v.PropertyFeeStart,
- PropertyFeeEnd: v.PropertyFeeEnd,
- GasFeeStart: v.GasFeeStart,
- GasFeeEnd: v.GasFeeEnd,
- BuildingArea: v.BuildingArea,
- BuildingCompany: v.BuildingCompany,
- CoveredArea: v.CoveredArea,
- GreenPercent: v.GreenPercent,
- AreaPercent: v.AreaPercent,
- SpaceInfo: v.SpaceInfo,
- SpaceTotal: v.SpaceTotal,
- HouseTotal: v.HouseTotal,
- BuildingType: v.BuildingType,
- WaterType: stringToInt32Array(v.WaterType),
- ElectricType: stringToInt32Array(v.ElectricType),
- AvgPrice: v.AvgPrice,
- RentCount: v.HouseRentCount,
- SellCount: v.HouseSellCount,
- }
- if v.Enable == 1 {
- item.Enable = true
- }
- reply.List[i] = item
- }
- return reply, nil
- }
- //
- func GardenList(ctx context.Context, req *pb_v1.GardenListRequest) (reply *pb_v1.GardenListReply, err error) {
- reply = &pb_v1.GardenListReply{}
- // 捕获各个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"))
- }
- }
- }()
- if !req.Management && !req.Household && req.Cid < 1 {
- return nil, errors.ParamsError
- }
- if req.Page == 0 {
- req.Page = 1
- }
- if req.PageSize == 0 {
- req.PageSize = 10
- }
- if !req.NotApproved {
- return GardenListApproved(ctx, req)
- }
- garden := &dbmodel.TGarden{}
- where := map[string]interface{}{}
- if req.Cid > 0 {
- where["cid"] = req.Cid
- }
- if req.CommitteeCode != "" {
- where["committee_code"] = req.CommitteeCode
- }
- if req.StreetCode != "" {
- where["street_code"] = req.StreetCode
- }
- if req.GardenName != "" {
- where["garden_name like"] = "%" + req.GardenName + "%"
- }
- if req.ApproveStatus > 0 {
- where["status"] = req.ApproveStatus
- }
- reply.Page = req.Page
- reply.Total, err = garden.Count(database.DB(), where, nil)
- if err != nil {
- return nil, errors.DataBaseError
- }
- if reply.Total == 0 {
- return reply, nil
- }
- list, err := garden.List(database.DB(), where, nil, int(req.Page), int(req.PageSize))
- if err != nil {
- return nil, errors.DataBaseError
- }
- reply.List = make([]*pb_v1.GardenItem, len(list))
- for i, v := range list {
- item := &pb_v1.GardenItem{
- Province: v.Province,
- ProvinceCode: v.ProvinceCode,
- City: v.City,
- CityCode: v.CityCode,
- Area: v.Area,
- AreaCode: v.AreaCode,
- Street: v.Street,
- StreetCode: v.StreetCode,
- Committee: v.Committee,
- CommitteeCode: v.CommitteeCode,
- PropertyPerson: v.PropertyPerson,
- PropertyPhone: v.PropertyPhone,
- GardenName: v.GardenName,
- GardenAddr: v.GardenAddr,
- Cid: v.Cid,
- Id: v.ID,
- GardenDesc: v.GardenDesc,
- GardenPic: v.GardenPic,
- Lat: v.Lat,
- Lnt: v.Lnt,
- Status: v.Status,
- Feedback: v.Feedback,
- Appendix: strings.Split(v.Appendix, ";"),
- GardenPics: strings.Split(v.GardenPics, ";"),
- BuildingStart: v.BuildingStart,
- BuildingEnd: v.BuildingEnd,
- PropertyFeeStart: v.PropertyFeeStart,
- PropertyFeeEnd: v.PropertyFeeEnd,
- GasFeeStart: v.GasFeeStart,
- GasFeeEnd: v.GasFeeEnd,
- BuildingArea: v.BuildingArea,
- BuildingCompany: v.BuildingCompany,
- CoveredArea: v.CoveredArea,
- GreenPercent: v.GreenPercent,
- AreaPercent: v.AreaPercent,
- SpaceInfo: v.SpaceInfo,
- SpaceTotal: v.SpaceTotal,
- HouseTotal: v.HouseTotal,
- BuildingType: v.BuildingType,
- WaterType: stringToInt32Array(v.WaterType),
- ElectricType: stringToInt32Array(v.ElectricType),
- AvgPrice: v.AvgPrice,
- RentCount: 0,
- SellCount: 0,
- }
- if !req.NeedAppendix {
- item.Appendix = nil
- }
- reply.List[i] = item
- }
- return reply, nil
- }
|