game_task.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package task
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "go.uber.org/zap"
  5. "log-server/global"
  6. "log-server/model/common/response"
  7. "log-server/model/task/request"
  8. taskResponse "log-server/model/task/response"
  9. "log-server/utils"
  10. )
  11. type GameTaskApi struct {
  12. }
  13. // @Tags gameTask
  14. // @Summary 创建游戏任务
  15. // @Security ApiKeyAuth
  16. // @accept application/json
  17. // @Produce application/json
  18. // @Param data body request.GameTaskRequest true
  19. // @Success 200 {object} response.Response{msg=string} "创建游戏任务"
  20. // @Router /gameTask/create [post]
  21. func (s *GameTaskApi) CreateGameTask(c *gin.Context) {
  22. var api request.GameTaskRequest
  23. _ = c.ShouldBindJSON(&api)
  24. if err := utils.Verify(api, utils.GameTaskVerify); err != nil {
  25. response.FailWithMessage(err.Error(), c)
  26. return
  27. }
  28. if err := taskService.CreateGameTask(api); err != nil {
  29. global.GVA_LOG.Error("创建失败!", zap.Error(err))
  30. response.FailWithMessage("创建失败", c)
  31. } else {
  32. response.OkWithMessage("创建成功", c)
  33. }
  34. }
  35. // @Tags gameTask
  36. // @Summary 游戏任务列表
  37. // @Security ApiKeyAuth
  38. // @accept application/json
  39. // @Produce application/json
  40. // @Param data body request.GetCardListRequest true "游戏任务列表"
  41. // @Success 200 {object} response.Response{data=response.GetGameTaskListReply,msg=string} "分页游戏任务列表,返回包括列表,总数,页码,每页数量"
  42. // @Router /gameTask/getGameTaskList [post]
  43. func (s *GameTaskApi) GetGameTaskList(c *gin.Context) {
  44. var paramsInfo request.GetGameTaskListRequest
  45. _ = c.ShouldBindJSON(&paramsInfo)
  46. if err := utils.Verify(paramsInfo.PageInfo, utils.PageInfoVerify); err != nil {
  47. response.FailWithMessage(err.Error(), c)
  48. return
  49. }
  50. if list, option, total, err := taskService.GetGameTaskInfoList(paramsInfo.GameTask, paramsInfo.PageInfo, paramsInfo.OrderKey, paramsInfo.Desc); err != nil {
  51. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  52. response.FailWithMessage("获取失败", c)
  53. } else {
  54. response.OkWithDetailed(taskResponse.GameTaskPageResult{
  55. List: list,
  56. OptionList: option,
  57. Total: total,
  58. Page: paramsInfo.Page,
  59. PageSize: paramsInfo.PageSize,
  60. }, "获取成功", c)
  61. }
  62. }
  63. // @Tags gameTask
  64. // @Summary 根据id获取游戏任务信息
  65. // @Security ApiKeyAuth
  66. // @accept application/json
  67. // @Produce application/json
  68. // @Param data body request.GetById true "根据id获取游戏任务信息"
  69. // @Success 200 {object} response.Response{data=systemRes.GameTaskRequest} "根据id获取游戏任务信息,返回包括游戏任务信息详情"
  70. // @Router /gameTask/getGameTaskById [post]
  71. func (s *GameTaskApi) GetGameTaskById(c *gin.Context) {
  72. var idInfo request.GetById
  73. _ = c.ShouldBindJSON(&idInfo)
  74. if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
  75. response.FailWithMessage(err.Error(), c)
  76. return
  77. }
  78. api, err := taskService.GetGameTaskById(idInfo.ID)
  79. if err != nil {
  80. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  81. response.FailWithMessage("获取失败", c)
  82. } else {
  83. response.OkWithDetailed(api, "获取成功", c)
  84. }
  85. }
  86. // @Tags GameTask
  87. // @Summary 游戏任务信息状态
  88. // @Security ApiKeyAuth
  89. // @accept application/json
  90. // @Produce application/json
  91. // @Param data body request.UpdateGameTaskStatusRequest true "id, 状态"
  92. // @Success 200 {object} response.Response{msg=string} "修改游戏任务信息状态"
  93. // @Router /gameTask/statusOperation [post]
  94. func (s *GameTaskApi) StatusOperation(c *gin.Context) {
  95. var paramsInfo request.UpdateGameTaskStatusRequest
  96. _ = c.ShouldBindJSON(&paramsInfo)
  97. if paramsInfo.TaskId == 0 {
  98. response.FailWithMessage("Id不能为空", c)
  99. return
  100. }
  101. if paramsInfo.Status == 0 {
  102. response.FailWithMessage("状态值不能为空", c)
  103. return
  104. }
  105. if err := taskService.UpdateGameTaskStatus(paramsInfo); err != nil {
  106. global.GVA_LOG.Error("修改失败!", zap.Error(err))
  107. response.FailWithMessage(err.Error(), c)
  108. } else {
  109. response.OkWithMessage("修改成功", c)
  110. }
  111. }
  112. // @Tags gameTask
  113. // @Summary 更新游戏任务
  114. // @Security ApiKeyAuth
  115. // @accept application/json
  116. // @Produce application/json
  117. // @Param data body request.GameTaskRequest true
  118. // @Success 200 {object} response.Response{msg=string} "更新游戏任务"
  119. // @Router /gameTask/update [post]
  120. func (s *GameTaskApi) UpdateGameTask(c *gin.Context) {
  121. var api request.GameTaskRequest
  122. _ = c.ShouldBindJSON(&api)
  123. if err := utils.Verify(api, utils.GameTaskVerify); err != nil {
  124. response.FailWithMessage(err.Error(), c)
  125. return
  126. }
  127. if err := taskService.UpdateGameTask(api); err != nil {
  128. global.GVA_LOG.Error("更新失败!", zap.Error(err))
  129. response.FailWithMessage("更新失败", c)
  130. } else {
  131. response.OkWithMessage("更新成功", c)
  132. }
  133. }
  134. // @Tags gameTask
  135. // @Summary 删除gameTask
  136. // @Security ApiKeyAuth
  137. // @accept application/json
  138. // @Produce application/json
  139. // @Param data body task.GameTask true "ID"
  140. // @Success 200 {object} response.Response{msg=string} "删除gameTask"
  141. // @Router /gameTask/delete [post]
  142. func (s *GameTaskApi) DeleteGameTask(c *gin.Context) {
  143. var api request.GameTaskRequest
  144. _ = c.ShouldBindJSON(&api)
  145. if err := utils.Verify(api, utils.TaskIdVerify); err != nil {
  146. response.FailWithMessage(err.Error(), c)
  147. return
  148. }
  149. if err := taskService.DeleteGameTask(api); err != nil {
  150. global.GVA_LOG.Error("删除失败!", zap.Error(err))
  151. response.FailWithMessage("删除失败", c)
  152. } else {
  153. response.OkWithMessage("删除成功", c)
  154. }
  155. }