list.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. "time"
  13. "git.getensh.com/common/gopkgs/database"
  14. "git.getensh.com/common/gopkgs/logger"
  15. "go.uber.org/zap"
  16. "google.golang.org/grpc/status"
  17. )
  18. func GardenListApproved(ctx context.Context, req *pb_v1.GardenListRequest) (reply *pb_v1.GardenListReply, err error) {
  19. reply = &pb_v1.GardenListReply{}
  20. garden := &dbmodel.TGardenApproved{}
  21. where := map[string]interface{}{
  22. "in_use": true,
  23. }
  24. if req.Cid > 0 {
  25. where["cid"] = req.Cid
  26. }
  27. if req.CommitteeCode != "" {
  28. where["committee_code"] = req.CommitteeCode
  29. } else if req.StreetCode != "" {
  30. where["street_code"] = req.StreetCode
  31. } else if req.AreaCode != "" {
  32. where["area_code"] = req.AreaCode
  33. } else if req.CityCode != "" {
  34. where["city_code"] = req.CityCode
  35. } else if req.ProvinceCode != "" {
  36. where["province_code"] = req.ProvinceCode
  37. }
  38. if req.GardenName != "" {
  39. where["garden_name like"] = "%" + req.GardenName + "%"
  40. }
  41. if req.ApproveStatus > 0 {
  42. where["status"] = req.ApproveStatus
  43. }
  44. if req.BuildingType > 0 {
  45. where["building_type"] = req.BuildingType
  46. }
  47. if req.BuildingYearLess > 0 {
  48. year := time.Now().Year() - int(req.BuildingYearLess)
  49. where["building_end >="] = time.Date(year, 1, 1, 0, 0, 0, 0, time.Now().Location()).Unix()
  50. }
  51. if req.BuildingYearGreater > 0 {
  52. year := time.Now().Year() - int(req.BuildingYearGreater)
  53. where["building_start <="] = time.Date(year, 1, 1, 0, 0, 0, 0, time.Now().Location()).Unix()
  54. }
  55. if req.PriceLess > 0 {
  56. where["avg_price <="] = req.PriceLess
  57. }
  58. if req.PriceGreater > 0 {
  59. where["avg_price >="] = req.PriceGreater
  60. }
  61. reply.Page = req.Page
  62. reply.Total, err = garden.Count(database.DB(), where, nil)
  63. if err != nil {
  64. return nil, errors.DataBaseError
  65. }
  66. if reply.Total == 0 {
  67. return reply, nil
  68. }
  69. list, err := garden.List(database.DB(), where, nil, int(req.Page), int(req.PageSize))
  70. if err != nil {
  71. return nil, errors.DataBaseError
  72. }
  73. reply.List = make([]*pb_v1.GardenItem, len(list))
  74. for i, v := range list {
  75. item := &pb_v1.GardenItem{
  76. Province: v.Province,
  77. ProvinceCode: v.ProvinceCode,
  78. City: v.City,
  79. CityCode: v.CityCode,
  80. Area: v.Area,
  81. AreaCode: v.AreaCode,
  82. Street: v.Street,
  83. StreetCode: v.StreetCode,
  84. Committee: v.Committee,
  85. CommitteeCode: v.CommitteeCode,
  86. PropertyPerson: v.PropertyPerson,
  87. PropertyPhone: v.PropertyPhone,
  88. GardenName: v.GardenName,
  89. GardenAddr: v.GardenAddr,
  90. Cid: v.Cid,
  91. Id: v.ID,
  92. GardenDesc: v.GardenDesc,
  93. GardenPic: v.GardenPic,
  94. Lat: v.Lat,
  95. Lnt: v.Lnt,
  96. Status: GardenStatusApproved,
  97. Appendix: strings.Split(v.Appendix, ";"),
  98. PayMode: v.PayMode,
  99. MchId: v.MchId,
  100. HouseCountLimit: v.HouseCountLimit,
  101. HouseCount: v.HouseCount,
  102. ExpireAt: v.ExpireAt,
  103. GardenPics: strings.Split(v.GardenPics, ";"),
  104. BuildingStart: v.BuildingStart,
  105. BuildingEnd: v.BuildingEnd,
  106. PropertyFeeStart: v.PropertyFeeStart,
  107. PropertyFeeEnd: v.PropertyFeeEnd,
  108. GasFeeStart: v.GasFeeStart,
  109. GasFeeEnd: v.GasFeeEnd,
  110. BuildingArea: v.BuildingArea,
  111. BuildingCompany: v.BuildingCompany,
  112. CoveredArea: v.CoveredArea,
  113. GreenPercent: v.GreenPercent,
  114. AreaPercent: v.AreaPercent,
  115. SpaceInfo: v.SpaceInfo,
  116. SpaceTotal: v.SpaceTotal,
  117. HouseTotal: v.HouseTotal,
  118. BuildingType: v.BuildingType,
  119. WaterType: stringToInt32Array(v.WaterType),
  120. ElectricType: stringToInt32Array(v.ElectricType),
  121. AvgPrice: v.AvgPrice,
  122. RentCount: v.HouseRentCount,
  123. SellCount: v.HouseSellCount,
  124. }
  125. if v.Enable == 1 {
  126. item.Enable = true
  127. }
  128. reply.List[i] = item
  129. }
  130. return reply, nil
  131. }
  132. //
  133. func GardenList(ctx context.Context, req *pb_v1.GardenListRequest) (reply *pb_v1.GardenListReply, err error) {
  134. reply = &pb_v1.GardenListReply{}
  135. // 捕获各个task中的异常并返回给调用者
  136. defer func() {
  137. if r := recover(); r != nil {
  138. err = fmt.Errorf("%+v", r)
  139. e := &status.Status{}
  140. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  141. logger.Error("err",
  142. zap.String("system_err", err.Error()),
  143. zap.Stack("stacktrace"))
  144. }
  145. }
  146. }()
  147. if !req.Management && !req.Household && req.Cid < 1 {
  148. return nil, errors.ParamsError
  149. }
  150. if req.Page == 0 {
  151. req.Page = 1
  152. }
  153. if req.PageSize == 0 {
  154. req.PageSize = 10
  155. }
  156. if !req.NotApproved {
  157. return GardenListApproved(ctx, req)
  158. }
  159. garden := &dbmodel.TGarden{}
  160. where := map[string]interface{}{}
  161. if req.Cid > 0 {
  162. where["cid"] = req.Cid
  163. }
  164. if req.CommitteeCode != "" {
  165. where["committee_code"] = req.CommitteeCode
  166. }
  167. if req.StreetCode != "" {
  168. where["street_code"] = req.StreetCode
  169. }
  170. if req.GardenName != "" {
  171. where["garden_name like"] = "%" + req.GardenName + "%"
  172. }
  173. if req.ApproveStatus > 0 {
  174. where["status"] = req.ApproveStatus
  175. }
  176. reply.Page = req.Page
  177. reply.Total, err = garden.Count(database.DB(), where, nil)
  178. if err != nil {
  179. return nil, errors.DataBaseError
  180. }
  181. if reply.Total == 0 {
  182. return reply, nil
  183. }
  184. list, err := garden.List(database.DB(), where, nil, int(req.Page), int(req.PageSize))
  185. if err != nil {
  186. return nil, errors.DataBaseError
  187. }
  188. reply.List = make([]*pb_v1.GardenItem, len(list))
  189. for i, v := range list {
  190. item := &pb_v1.GardenItem{
  191. Province: v.Province,
  192. ProvinceCode: v.ProvinceCode,
  193. City: v.City,
  194. CityCode: v.CityCode,
  195. Area: v.Area,
  196. AreaCode: v.AreaCode,
  197. Street: v.Street,
  198. StreetCode: v.StreetCode,
  199. Committee: v.Committee,
  200. CommitteeCode: v.CommitteeCode,
  201. PropertyPerson: v.PropertyPerson,
  202. PropertyPhone: v.PropertyPhone,
  203. GardenName: v.GardenName,
  204. GardenAddr: v.GardenAddr,
  205. Cid: v.Cid,
  206. Id: v.ID,
  207. GardenDesc: v.GardenDesc,
  208. GardenPic: v.GardenPic,
  209. Lat: v.Lat,
  210. Lnt: v.Lnt,
  211. Status: v.Status,
  212. Feedback: v.Feedback,
  213. Appendix: strings.Split(v.Appendix, ";"),
  214. GardenPics: strings.Split(v.GardenPics, ";"),
  215. BuildingStart: v.BuildingStart,
  216. BuildingEnd: v.BuildingEnd,
  217. PropertyFeeStart: v.PropertyFeeStart,
  218. PropertyFeeEnd: v.PropertyFeeEnd,
  219. GasFeeStart: v.GasFeeStart,
  220. GasFeeEnd: v.GasFeeEnd,
  221. BuildingArea: v.BuildingArea,
  222. BuildingCompany: v.BuildingCompany,
  223. CoveredArea: v.CoveredArea,
  224. GreenPercent: v.GreenPercent,
  225. AreaPercent: v.AreaPercent,
  226. SpaceInfo: v.SpaceInfo,
  227. SpaceTotal: v.SpaceTotal,
  228. HouseTotal: v.HouseTotal,
  229. BuildingType: v.BuildingType,
  230. WaterType: stringToInt32Array(v.WaterType),
  231. ElectricType: stringToInt32Array(v.ElectricType),
  232. AvgPrice: v.AvgPrice,
  233. RentCount: 0,
  234. SellCount: 0,
  235. }
  236. if !req.NeedAppendix {
  237. item.Appendix = nil
  238. }
  239. reply.List[i] = item
  240. }
  241. return reply, nil
  242. }