infos.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package garden
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "property-system/errors"
  9. dbmodel "property-system/model"
  10. pb_v1 "property-system/pb/v1"
  11. "strings"
  12. "git.getensh.com/common/gopkgs/database"
  13. "git.getensh.com/common/gopkgs/logger"
  14. "go.uber.org/zap"
  15. "google.golang.org/grpc/status"
  16. )
  17. //
  18. func GardenInfos(ctx context.Context, req *pb_v1.GardenInfosRequest) (reply *pb_v1.GardenInfosReply, err error) {
  19. reply = &pb_v1.GardenInfosReply{}
  20. // 捕获各个task中的异常并返回给调用者
  21. defer func() {
  22. if r := recover(); r != nil {
  23. err = fmt.Errorf("%+v", r)
  24. e := &status.Status{}
  25. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  26. logger.Error("err",
  27. zap.String("system_err", err.Error()),
  28. zap.Stack("stacktrace"))
  29. }
  30. }
  31. }()
  32. if len(req.Ids) == 0 {
  33. return nil, errors.ParamsError
  34. }
  35. garden := &dbmodel.TGardenApproved{}
  36. where := map[string]interface{}{
  37. "id in": req.Ids,
  38. "in_use": true,
  39. }
  40. list, err := garden.List(database.DB(), where, nil, -1, -1)
  41. if err != nil {
  42. return nil, errors.DataBaseError
  43. }
  44. reply.List = make([]*pb_v1.GardenItem, len(list))
  45. for i, v := range list {
  46. item := &pb_v1.GardenItem{
  47. Province: v.Province,
  48. ProvinceCode: v.ProvinceCode,
  49. City: v.City,
  50. CityCode: v.CityCode,
  51. Area: v.Area,
  52. AreaCode: v.AreaCode,
  53. Street: v.Street,
  54. StreetCode: v.StreetCode,
  55. Committee: v.Committee,
  56. CommitteeCode: v.CommitteeCode,
  57. PropertyPerson: v.PropertyPerson,
  58. PropertyPhone: v.PropertyPhone,
  59. GardenName: v.GardenName,
  60. GardenAddr: v.GardenAddr,
  61. Cid: v.Cid,
  62. Id: v.ID,
  63. GardenDesc: v.GardenDesc,
  64. GardenPic: v.GardenPic,
  65. InUse: v.InUse,
  66. Lat: v.Lat,
  67. Lnt: v.Lnt,
  68. Status: GardenStatusApproved,
  69. PayMode: v.PayMode,
  70. MchId: v.MchId,
  71. HouseCount: v.HouseCount,
  72. HouseCountLimit: v.HouseCountLimit,
  73. ExpireAt: v.ExpireAt,
  74. GardenPics: strings.Split(v.GardenPics, ";"),
  75. BuildingStart: v.BuildingStart,
  76. BuildingEnd: v.BuildingEnd,
  77. PropertyFeeStart: v.PropertyFeeStart,
  78. PropertyFeeEnd: v.PropertyFeeEnd,
  79. GasFeeStart: v.GasFeeStart,
  80. GasFeeEnd: v.GasFeeEnd,
  81. BuildingArea: v.BuildingArea,
  82. BuildingCompany: v.BuildingCompany,
  83. CoveredArea: v.CoveredArea,
  84. GreenPercent: v.GreenPercent,
  85. AreaPercent: v.AreaPercent,
  86. SpaceInfo: v.SpaceInfo,
  87. SpaceTotal: v.SpaceTotal,
  88. HouseTotal: v.HouseTotal,
  89. BuildingType: v.BuildingType,
  90. WaterType: stringToInt32Array(v.WaterType),
  91. ElectricType: stringToInt32Array(v.ElectricType),
  92. AvgPrice: v.AvgPrice,
  93. RentCount: v.HouseRentCount,
  94. SellCount: v.HouseSellCount,
  95. }
  96. if v.Enable == 1 {
  97. item.Enable = true
  98. }
  99. reply.List[i] = item
  100. }
  101. return reply, nil
  102. }