garden.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. package v1
  2. import (
  3. "git.getensh.com/common/gopkgs/logger"
  4. "git.getensh.com/common/gopkgs/tasker/httptasker"
  5. "git.getensh.com/common/gopkgs/util"
  6. "github.com/gin-gonic/gin"
  7. "go.uber.org/zap"
  8. "net/http"
  9. "property-management-gateway/errors"
  10. param_v1 "property-management-gateway/param/v1"
  11. "property-management-gateway/pb"
  12. "property-management-gateway/pb/v1"
  13. "property-management-gateway/utils"
  14. )
  15. //
  16. // @Summary 小区列表
  17. // @Description 小区列表
  18. // @Tags 小区
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true " "
  22. // @Param committee_code query string false "社区代码"
  23. // @Param street_code query string false "街道代码"
  24. // @Param garden_name query string false "小区名字"
  25. // @Param page query int true "第几页,1为起始页, -1 不分页返回所有"
  26. // @Param page_size query int false "每页条数,-1 不分页返回所有"
  27. // @Param not_approved query bool false "true 待审批或未通过的数据 false 审批通过的数据"
  28. // @Success 200 {object} v1.GardenListResponse
  29. // @Failure 500 {object} base.HTTPError
  30. // @Router /api/v1/garden [get]
  31. func (c *Controller) GardenList(ctx *gin.Context) {
  32. // 解析参数
  33. req := &param_v1.GardenListRequest{}
  34. parseParamTask := func() error {
  35. err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenListQuery, nil)
  36. if err != nil {
  37. logger.Error("func",
  38. zap.String("call", "util.ShouldBind"),
  39. zap.String("error", err.Error()))
  40. return errors.ParamsError
  41. }
  42. return nil
  43. }
  44. // 业务处理
  45. handleServiceTask := func() error {
  46. resp := param_v1.GardenListResponse{}
  47. rpcReq := &v1.GardenListRequest{
  48. Page: req.Page,
  49. PageSize: req.PageSize,
  50. CommitteeCode: req.CommitteeCode,
  51. NotApproved: req.NotApproved,
  52. NeedAppendix: true,
  53. StreetCode: req.StreetCode,
  54. GardenName: req.GardenName,
  55. Management: true,
  56. }
  57. rpcRsp, err := pb.System.GardenList(ctx, rpcReq)
  58. if err != nil {
  59. s, _ := json.MarshalToString(req)
  60. logger.Error("func",
  61. zap.String("call", "Garden.GardenList"),
  62. zap.String("params", s),
  63. zap.String("error", err.Error()))
  64. return errors.ErrorTransForm(err)
  65. }
  66. for i, v := range rpcRsp.List {
  67. if len(v.WaterType) == 0 {
  68. rpcRsp.List[i].WaterType = []int32{}
  69. }
  70. if len(v.ElectricType) == 0 {
  71. rpcRsp.List[i].ElectricType = []int32{}
  72. }
  73. if len(v.GardenPics) == 0 {
  74. rpcRsp.List[i].GardenPics = []string{}
  75. }
  76. }
  77. if rpcRsp.List == nil {
  78. rpcRsp.List = make([]*v1.GardenItem, 0)
  79. }
  80. resp.Data = *rpcRsp
  81. ctx.JSON(http.StatusOK, resp)
  82. return nil
  83. }
  84. // 执行任务
  85. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  86. }
  87. //
  88. // @Summary 启用停用
  89. // @Description 启用停用
  90. // @Tags 小区
  91. // @Accept json
  92. // @Produce json
  93. // @Param token header string true " "
  94. // @Param body body v1.GardenEnableSetBody true "信息"
  95. // @Success 200 {object} v1.GardenEnableSetResponse
  96. // @Failure 500 {object} base.HTTPError
  97. // @Router /api/v1/garden/enable [put]
  98. func (c *Controller) GardenEnableSet(ctx *gin.Context) {
  99. // 解析参数
  100. req := &param_v1.GardenEnableSetRequest{}
  101. parseParamTask := func() error {
  102. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenEnableSetBody)
  103. if err != nil {
  104. logger.Error("func",
  105. zap.String("call", "util.ShouldBind"),
  106. zap.String("error", err.Error()))
  107. return errors.ParamsError
  108. }
  109. return nil
  110. }
  111. // 业务处理
  112. handleServiceTask := func() error {
  113. //tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  114. //if err != nil {
  115. // return err
  116. //}
  117. // 响应数据
  118. resp := param_v1.GardenEnableSetResponse{}
  119. rpcReq := &v1.GardenEnableSetRequest{
  120. Enable: req.Enable,
  121. GardenId: req.GardenId,
  122. }
  123. _, err := pb.System.GardenEnableSet(ctx, rpcReq)
  124. if err != nil {
  125. s, _ := json.MarshalToString(req)
  126. logger.Error("func",
  127. zap.String("call", "pb.System.GardenEnableSet"),
  128. zap.String("params", s),
  129. zap.String("error", err.Error()))
  130. return errors.ErrorTransForm(err)
  131. }
  132. ctx.JSON(http.StatusOK, resp)
  133. return nil
  134. }
  135. // 执行任务
  136. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  137. }
  138. //
  139. // @Summary 小区更换物业公司
  140. // @Description 小区更换物业公司
  141. // @Tags 小区
  142. // @Accept json
  143. // @Produce json
  144. // @Param token header string true " "
  145. // @Param body body v1.GardenChangeCompanyBody true " "
  146. // @Success 200 {object} v1.GardenChangeCompanyResponse
  147. // @Failure 500 {object} base.HTTPError
  148. // @Router /api/v1/garden/company [put]
  149. func (c *Controller) GardenChangeCompany(ctx *gin.Context) {
  150. // 解析参数
  151. req := &param_v1.GardenChangeCompanyRequest{}
  152. parseParamTask := func() error {
  153. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenChangeCompanyBody)
  154. if err != nil {
  155. logger.Error("func",
  156. zap.String("call", "util.ShouldBind"),
  157. zap.String("error", err.Error()))
  158. return errors.ParamsError
  159. }
  160. return nil
  161. }
  162. // 业务处理
  163. handleServiceTask := func() error {
  164. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  165. if err != nil {
  166. return err
  167. }
  168. resp := param_v1.GardenChangeCompanyResponse{}
  169. rpcReq := &v1.GardenChangeCompanyRequest{
  170. GardenId: req.GardenId,
  171. Cid: req.Cid,
  172. }
  173. rpcRsp, err := pb.System.GardenChangeCompany(ctx, rpcReq)
  174. if err != nil {
  175. s, _ := json.MarshalToString(req)
  176. logger.Error("func",
  177. zap.String("call", "Garden.GardenChangeCompany"),
  178. zap.String("params", s),
  179. zap.String("error", err.Error()))
  180. return errors.ErrorTransForm(err)
  181. }
  182. ctx.JSON(http.StatusOK, resp)
  183. logReq := OperationLogRequest{
  184. Module: ModuleGarden,
  185. Action: ActionGardenChangeCompany,
  186. Origin: rpcRsp.Origin,
  187. Target: req.GardenChangeCompanyBody,
  188. UserName: tokenInfo.User,
  189. Uid: tokenInfo.Uid,
  190. }
  191. go OperationLogAdd(&logReq)
  192. return nil
  193. }
  194. // 执行任务
  195. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  196. }
  197. //
  198. // @Summary 新增小区审核
  199. // @Description 新增小区审核
  200. // @Tags 小区
  201. // @Accept json
  202. // @Produce json
  203. // @Param token header string true " "
  204. // @Param body body v1.GardenApproveBody true "小区信息"
  205. // @Success 200 {object} v1.GardenApproveResponse
  206. // @Failure 500 {object} base.HTTPError
  207. // @Router /api/v1/garden [put]
  208. func (c *Controller) GardenApprove(ctx *gin.Context) {
  209. // 解析参数
  210. req := &param_v1.GardenApproveRequest{}
  211. parseParamTask := func() error {
  212. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenApproveBody)
  213. if err != nil {
  214. logger.Error("func",
  215. zap.String("call", "util.ShouldBind"),
  216. zap.String("error", err.Error()))
  217. return errors.ParamsError
  218. }
  219. return nil
  220. }
  221. // 业务处理
  222. handleServiceTask := func() error {
  223. //tokenInfo, err := utils.GetSubjectValue(ctx)
  224. //if err != nil {
  225. // return err
  226. //}
  227. // 响应数据
  228. resp := param_v1.GardenApproveResponse{}
  229. rpcReq := &v1.GardenApproveRequest{
  230. Id: req.Id,
  231. Status: req.Status,
  232. Feedback: req.Feedback,
  233. }
  234. _, err := pb.System.GardenApprove(ctx, rpcReq)
  235. if err != nil {
  236. s, _ := json.MarshalToString(req)
  237. logger.Error("func",
  238. zap.String("call", "pb.Garden.GardenApprove"),
  239. zap.String("params", s),
  240. zap.String("error", err.Error()))
  241. return errors.ErrorTransForm(err)
  242. }
  243. ctx.JSON(http.StatusOK, resp)
  244. return nil
  245. }
  246. // 执行任务
  247. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  248. }
  249. //
  250. // @Summary 小区关键信息修改审核
  251. // @Description 小区关键信息修改审核
  252. // @Tags 小区
  253. // @Accept json
  254. // @Produce json
  255. // @Param token header string true " "
  256. // @Param body body v1.GardenKeyInfoApproveBody true "小区信息"
  257. // @Success 200 {object} v1.GardenKeyInfoApproveResponse
  258. // @Failure 500 {object} base.HTTPError
  259. // @Router /api/v1/garden/key_info [put]
  260. func (c *Controller) GardenKeyInfoApprove(ctx *gin.Context) {
  261. // 解析参数
  262. req := &param_v1.GardenKeyInfoApproveRequest{}
  263. parseParamTask := func() error {
  264. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenKeyInfoApproveBody)
  265. if err != nil {
  266. logger.Error("func",
  267. zap.String("call", "util.ShouldBind"),
  268. zap.String("error", err.Error()))
  269. return errors.ParamsError
  270. }
  271. return nil
  272. }
  273. // 业务处理
  274. handleServiceTask := func() error {
  275. //tokenInfo, err := utils.GetSubjectValue(ctx)
  276. //if err != nil {
  277. // return err
  278. //}
  279. // 响应数据
  280. resp := param_v1.GardenKeyInfoApproveResponse{}
  281. rpcReq := &v1.GardenKeyInfoApproveRequest{
  282. Id: req.Id,
  283. Status: req.Status,
  284. Feedback: req.Feedback,
  285. }
  286. _, err := pb.System.GardenKeyInfoApprove(ctx, rpcReq)
  287. if err != nil {
  288. s, _ := json.MarshalToString(req)
  289. logger.Error("func",
  290. zap.String("call", "pb.Garden.GardenKeyInfoApprove"),
  291. zap.String("params", s),
  292. zap.String("error", err.Error()))
  293. return errors.ErrorTransForm(err)
  294. }
  295. ctx.JSON(http.StatusOK, resp)
  296. return nil
  297. }
  298. // 执行任务
  299. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  300. }
  301. //
  302. // @Summary 小区关键信息申请列表
  303. // @Description 小区关键信息申请列表
  304. // @Tags 小区
  305. // @Accept json
  306. // @Produce json
  307. // @Param token header string true " "
  308. // @Param page query int false " "
  309. // @Param page_size query int false " "
  310. // @Param status query int false "0不过率 1 待审核 2 审核通过 3 未通过 "
  311. // @Success 200 {object} v1.GardenKeyInfoChangeListResponse
  312. // @Failure 500 {object} base.HTTPError
  313. // @Router /api/v1/garden/key_info [get]
  314. func (c *Controller) GardenKeyInfoChangeList(ctx *gin.Context) {
  315. // 解析参数
  316. req := &param_v1.GardenKeyInfoChangeListRequest{}
  317. parseParamTask := func() error {
  318. err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenKeyInfoChangeListQuery, nil)
  319. if err != nil {
  320. logger.Error("func",
  321. zap.String("call", "util.ShouldBind"),
  322. zap.String("error", err.Error()))
  323. return errors.ParamsError
  324. }
  325. return nil
  326. }
  327. // 业务处理
  328. handleServiceTask := func() error {
  329. //tokenInfo, err := utils.GetSubjectValue(ctx)
  330. //if err != nil {
  331. // return err
  332. //}
  333. // 响应数据
  334. resp := param_v1.GardenKeyInfoChangeListResponse{}
  335. rpcReq := &v1.GardenKeyInfoChangeListRequest{
  336. Status: req.Status,
  337. Page: req.Page,
  338. PageSize: req.PageSize,
  339. }
  340. rpcRsp, err := pb.System.GardenKeyInfoChangeList(ctx, rpcReq)
  341. if err != nil {
  342. s, _ := json.MarshalToString(req)
  343. logger.Error("func",
  344. zap.String("call", "pb.Garden.GardenKeyInfoChangeList"),
  345. zap.String("params", s),
  346. zap.String("error", err.Error()))
  347. return errors.ErrorTransForm(err)
  348. }
  349. if rpcRsp.List == nil {
  350. rpcRsp.List = make([]*v1.GardenKeyInfoData, 0)
  351. }
  352. resp.Data = *rpcRsp
  353. ctx.JSON(http.StatusOK, resp)
  354. return nil
  355. }
  356. // 执行任务
  357. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  358. }