event.go 9.5 KB

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