event.go 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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-system-gateway/errors"
  10. param_v1 "property-system-gateway/param/v1"
  11. "property-system-gateway/pb"
  12. "property-system-gateway/pb/v1"
  13. "property-system-gateway/utils"
  14. )
  15. //
  16. // @Summary 添加社区活动
  17. // @Description 添加社区活动
  18. // @Tags 社区活动
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true "token"
  22. // @Param body body v1.EventAddBody true "信息"
  23. // @Success 200 {object} v1.EventAddResponse
  24. // @Failure 500 {object} base.HTTPError
  25. // @Router /api/v1/service/event [post]
  26. func (c *Controller) EventAdd(ctx *gin.Context) {
  27. // 解析参数
  28. req := &param_v1.EventAddRequest{}
  29. parseParamTask := func() error {
  30. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.EventAddBody)
  31. if err != nil {
  32. logger.Error("func",
  33. zap.String("call", "util.ShouldBind"),
  34. zap.String("error", err.Error()))
  35. return errors.ParamsError
  36. }
  37. return nil
  38. }
  39. // 业务处理
  40. handleServiceTask := func() error {
  41. tokenInfo, err := utils.GetSubjectValue(ctx)
  42. if err != nil {
  43. return err
  44. }
  45. // 响应数据
  46. resp := param_v1.EventAddResponse{}
  47. rpcReq := &v1.EventAddRequest{
  48. GardenId: tokenInfo.GardenId,
  49. Content: req.Content,
  50. Title: req.Title,
  51. Addr: req.Addr,
  52. Pic: req.Pic,
  53. PeopleLimit: req.PeopleLimit,
  54. Start: req.Start,
  55. End: req.End,
  56. SignUpEnd: req.SignUpEnd,
  57. Fee: req.Fee,
  58. }
  59. rpcRsp, err := pb.Garden.EventAdd(ctx, rpcReq)
  60. if err != nil {
  61. s, _ := json.MarshalToString(req)
  62. logger.Error("func",
  63. zap.String("call", "pb.Garden.EventAdd"),
  64. zap.String("params", s),
  65. zap.String("error", err.Error()))
  66. return errors.ErrorTransForm(err)
  67. }
  68. resp.Data = *rpcRsp
  69. ctx.JSON(http.StatusOK, resp)
  70. return nil
  71. }
  72. // 执行任务
  73. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  74. }
  75. //
  76. // @Summary 修改社区活动
  77. // @Description 修改社区活动
  78. // @Tags 社区活动
  79. // @Accept json
  80. // @Produce json
  81. // @Param token header string true "token"
  82. // @Param body body v1.EventUpdateBody true "信息"
  83. // @Success 200 {object} v1.EventUpdateResponse
  84. // @Failure 500 {object} base.HTTPError
  85. // @Router /api/v1/service/event [put]
  86. func (c *Controller) EventUpdate(ctx *gin.Context) {
  87. // 解析参数
  88. req := &param_v1.EventUpdateRequest{}
  89. parseParamTask := func() error {
  90. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.EventUpdateBody)
  91. if err != nil {
  92. logger.Error("func",
  93. zap.String("call", "util.ShouldBind"),
  94. zap.String("error", err.Error()))
  95. return errors.ParamsError
  96. }
  97. return nil
  98. }
  99. // 业务处理
  100. handleServiceTask := func() error {
  101. tokenInfo, err := utils.GetSubjectValue(ctx)
  102. if err != nil {
  103. return err
  104. }
  105. // 响应数据
  106. resp := param_v1.EventUpdateResponse{}
  107. rpcReq := &v1.EventUpdateRequest{
  108. GardenId: tokenInfo.GardenId,
  109. Content: req.Content,
  110. Title: req.Title,
  111. Addr: req.Addr,
  112. Pic: req.Pic,
  113. PeopleLimit: req.PeopleLimit,
  114. Start: req.Start,
  115. End: req.End,
  116. SignUpEnd: req.SignUpEnd,
  117. Id: req.Id,
  118. Fee: req.Fee,
  119. }
  120. _, err = pb.Garden.EventUpdate(ctx, rpcReq)
  121. if err != nil {
  122. s, _ := json.MarshalToString(req)
  123. logger.Error("func",
  124. zap.String("call", "pb.Garden.EventUpdate"),
  125. zap.String("params", s),
  126. zap.String("error", err.Error()))
  127. return errors.ErrorTransForm(err)
  128. }
  129. ctx.JSON(http.StatusOK, resp)
  130. return nil
  131. }
  132. // 执行任务
  133. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  134. }
  135. //
  136. // @Summary 删除社区活动
  137. // @Description 删除社区活动
  138. // @Tags 社区活动
  139. // @Accept json
  140. // @Produce json
  141. // @Param token header string true "token"
  142. // @Param id query int true " "
  143. // @Success 200 {object} v1.EventDelResponse
  144. // @Failure 500 {object} base.HTTPError
  145. // @Router /api/v1/service/event [delete]
  146. func (c *Controller) EventDel(ctx *gin.Context) {
  147. // 解析参数
  148. req := &param_v1.EventDelRequest{}
  149. parseParamTask := func() error {
  150. err := util.ShouldBind(ctx, &req.Header, nil, &req.EventDelQuery, nil)
  151. if err != nil {
  152. logger.Error("func",
  153. zap.String("call", "util.ShouldBind"),
  154. zap.String("error", err.Error()))
  155. return errors.ParamsError
  156. }
  157. return nil
  158. }
  159. // 业务处理
  160. handleServiceTask := func() error {
  161. tokenInfo, err := utils.GetSubjectValue(ctx)
  162. if err != nil {
  163. return err
  164. }
  165. // 响应数据
  166. resp := param_v1.EventDelResponse{}
  167. rpcReq := &v1.EventDelRequest{
  168. GardenId: tokenInfo.GardenId,
  169. Id: req.Id,
  170. }
  171. _, err = pb.Garden.EventDel(ctx, rpcReq)
  172. if err != nil {
  173. s, _ := json.MarshalToString(req)
  174. logger.Error("func",
  175. zap.String("call", "pb.Garden.EventDel"),
  176. zap.String("params", s),
  177. zap.String("error", err.Error()))
  178. return errors.ErrorTransForm(err)
  179. }
  180. ctx.JSON(http.StatusOK, resp)
  181. return nil
  182. }
  183. // 执行任务
  184. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  185. }
  186. //
  187. // @Summary 社区活动列表
  188. // @Description 社区活动列表
  189. // @Tags 社区活动
  190. // @Accept json
  191. // @Produce json
  192. // @Param token header string true "token"
  193. // @Param page query int false " "
  194. // @Param page_size query int false " "
  195. // @Success 200 {object} v1.EventListResponse
  196. // @Failure 500 {object} base.HTTPError
  197. // @Router /api/v1/service/event [get]
  198. func (c *Controller) EventList(ctx *gin.Context) {
  199. // 解析参数
  200. req := &param_v1.EventListRequest{}
  201. parseParamTask := func() error {
  202. err := util.ShouldBind(ctx, &req.Header, nil, &req.EventListQuery, nil)
  203. if err != nil {
  204. logger.Error("func",
  205. zap.String("call", "util.ShouldBind"),
  206. zap.String("error", err.Error()))
  207. return errors.ParamsError
  208. }
  209. return nil
  210. }
  211. // 业务处理
  212. handleServiceTask := func() error {
  213. tokenInfo, err := utils.GetSubjectValue(ctx)
  214. if err != nil {
  215. return err
  216. }
  217. // 响应数据
  218. resp := param_v1.EventListResponse{}
  219. rpcReq := &v1.EventListRequest{
  220. GardenId: tokenInfo.GardenId,
  221. PageSize: req.PageSize,
  222. Page: req.Page,
  223. }
  224. rpcRsp, err := pb.Garden.EventList(ctx, rpcReq)
  225. if err != nil {
  226. s, _ := json.MarshalToString(req)
  227. logger.Error("func",
  228. zap.String("call", "pb.Garden.EventList"),
  229. zap.String("params", s),
  230. zap.String("error", err.Error()))
  231. return errors.ErrorTransForm(err)
  232. }
  233. if rpcRsp.List == nil {
  234. rpcRsp.List = make([]*v1.EventItem, 0)
  235. }
  236. resp.Data = *rpcRsp
  237. ctx.JSON(http.StatusOK, resp)
  238. return nil
  239. }
  240. // 执行任务
  241. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  242. }
  243. //
  244. // @Summary 删除社区活动报名记录
  245. // @Description 删除社区活动报名记录
  246. // @Tags 社区活动
  247. // @Accept json
  248. // @Produce json
  249. // @Param token header string true "token"
  250. // @Param id query int true " "
  251. // @Success 200 {object} v1.EventSignDelResponse
  252. // @Failure 500 {object} base.HTTPError
  253. // @Router /api/v1/service/event/sign [delete]
  254. func (c *Controller) EventSignDel(ctx *gin.Context) {
  255. // 解析参数
  256. req := &param_v1.EventSignDelRequest{}
  257. parseParamTask := func() error {
  258. err := util.ShouldBind(ctx, &req.Header, nil, &req.EventSignDelQuery, nil)
  259. if err != nil {
  260. logger.Error("func",
  261. zap.String("call", "util.ShouldBind"),
  262. zap.String("error", err.Error()))
  263. return errors.ParamsError
  264. }
  265. return nil
  266. }
  267. // 业务处理
  268. handleServiceTask := func() error {
  269. tokenInfo, err := utils.GetSubjectValue(ctx)
  270. if err != nil {
  271. return err
  272. }
  273. // 响应数据
  274. resp := param_v1.EventSignDelResponse{}
  275. rpcReq := &v1.EventSignDelRequest{
  276. GardenId: tokenInfo.GardenId,
  277. Id: req.Id,
  278. }
  279. _, err = pb.Garden.EventSignDel(ctx, rpcReq)
  280. if err != nil {
  281. s, _ := json.MarshalToString(req)
  282. logger.Error("func",
  283. zap.String("call", "pb.Garden.EventSignDel"),
  284. zap.String("params", s),
  285. zap.String("error", err.Error()))
  286. return errors.ErrorTransForm(err)
  287. }
  288. ctx.JSON(http.StatusOK, resp)
  289. return nil
  290. }
  291. // 执行任务
  292. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  293. }
  294. //
  295. // @Summary 社区活动报名记录列表
  296. // @Description 社区活动报名记录列表
  297. // @Tags 社区活动
  298. // @Accept json
  299. // @Produce json
  300. // @Param token header string true "token"
  301. // @Param page query int false " "
  302. // @Param page_size query int false " "
  303. // @Param event_id query int true "活动id"
  304. // @Success 200 {object} v1.EventSignListResponse
  305. // @Failure 500 {object} base.HTTPError
  306. // @Router /api/v1/service/event/sign [get]
  307. func (c *Controller) EventSignList(ctx *gin.Context) {
  308. // 解析参数
  309. req := &param_v1.EventSignListRequest{}
  310. parseParamTask := func() error {
  311. err := util.ShouldBind(ctx, &req.Header, nil, &req.EventSignListQuery, nil)
  312. if err != nil {
  313. logger.Error("func",
  314. zap.String("call", "util.ShouldBind"),
  315. zap.String("error", err.Error()))
  316. return errors.ParamsError
  317. }
  318. return nil
  319. }
  320. // 业务处理
  321. handleServiceTask := func() error {
  322. tokenInfo, err := utils.GetSubjectValue(ctx)
  323. if err != nil {
  324. return err
  325. }
  326. // 响应数据
  327. resp := param_v1.EventSignListResponse{}
  328. rpcReq := &v1.EventSignListRequest{
  329. GardenId: tokenInfo.GardenId,
  330. PageSize: req.PageSize,
  331. Page: req.Page,
  332. EventId: req.EventId,
  333. }
  334. rpcRsp, err := pb.Garden.EventSignList(ctx, rpcReq)
  335. if err != nil {
  336. s, _ := json.MarshalToString(req)
  337. logger.Error("func",
  338. zap.String("call", "pb.Garden.EventSignList"),
  339. zap.String("params", s),
  340. zap.String("error", err.Error()))
  341. return errors.ErrorTransForm(err)
  342. }
  343. if rpcRsp.List == nil {
  344. rpcRsp.List = make([]*v1.EventSignItem, 0)
  345. }
  346. resp.Data = *rpcRsp
  347. ctx.JSON(http.StatusOK, resp)
  348. return nil
  349. }
  350. // 执行任务
  351. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  352. }