assignment.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package autocode
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
  5. autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
  7. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  8. "github.com/flipped-aurora/gin-vue-admin/server/service"
  9. "github.com/gin-gonic/gin"
  10. "go.uber.org/zap"
  11. )
  12. type AssignmentApi struct {
  13. }
  14. var assignmentService = service.ServiceGroupApp.AutoCodeServiceGroup.AssignmentService
  15. var fileUploadAndDownloadService = service.ServiceGroupApp.ExampleServiceGroup.FileUploadAndDownloadService
  16. // CreateAssignment 创建Assignment
  17. // @Tags Assignment
  18. // @Summary 创建Assignment
  19. // @Security ApiKeyAuth
  20. // @accept application/json
  21. // @Produce application/json
  22. // @Param data body autocode.Assignment true "创建Assignment"
  23. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  24. // @Router /assignment/createAssignment [post]
  25. func (assignmentApi *AssignmentApi) CreateAssignment(c *gin.Context) {
  26. var assignment autocode.Assignment
  27. _ = c.ShouldBindJSON(&assignment)
  28. if err := assignmentService.CreateAssignment(assignment); err != nil {
  29. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  30. response.FailWithMessage("创建失败", c)
  31. } else {
  32. response.OkWithMessage("创建成功", c)
  33. }
  34. }
  35. // DeleteAssignment 删除Assignment
  36. // @Tags Assignment
  37. // @Summary 删除Assignment
  38. // @Security ApiKeyAuth
  39. // @accept application/json
  40. // @Produce application/json
  41. // @Param data body autocode.Assignment true "删除Assignment"
  42. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  43. // @Router /assignment/deleteAssignment [delete]
  44. func (assignmentApi *AssignmentApi) DeleteAssignment(c *gin.Context) {
  45. var assignment autocode.Assignment
  46. _ = c.ShouldBindJSON(&assignment)
  47. if err := assignmentService.DeleteAssignment(assignment); err != nil {
  48. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  49. response.FailWithMessage("删除失败", c)
  50. } else {
  51. response.OkWithMessage("删除成功", c)
  52. }
  53. }
  54. // DeleteAssignmentByIds 批量删除Assignment
  55. // @Tags Assignment
  56. // @Summary 批量删除Assignment
  57. // @Security ApiKeyAuth
  58. // @accept application/json
  59. // @Produce application/json
  60. // @Param data body request.IdsReq true "批量删除Assignment"
  61. // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
  62. // @Router /assignment/deleteAssignmentByIds [delete]
  63. func (assignmentApi *AssignmentApi) DeleteAssignmentByIds(c *gin.Context) {
  64. var IDS request.IdsReq
  65. _ = c.ShouldBindJSON(&IDS)
  66. if err := assignmentService.DeleteAssignmentByIds(IDS); err != nil {
  67. global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
  68. response.FailWithMessage("批量删除失败", c)
  69. } else {
  70. response.OkWithMessage("批量删除成功", c)
  71. }
  72. }
  73. // UpdateAssignment 更新Assignment
  74. // @Tags Assignment
  75. // @Summary 更新Assignment
  76. // @Security ApiKeyAuth
  77. // @accept application/json
  78. // @Produce application/json
  79. // @Param data body autocode.Assignment true "更新Assignment"
  80. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  81. // @Router /assignment/updateAssignment [put]
  82. func (assignmentApi *AssignmentApi) UpdateAssignment(c *gin.Context) {
  83. var assignment autocode.Assignment
  84. _ = c.ShouldBindJSON(&assignment)
  85. if err := assignmentService.UpdateAssignment(assignment); err != nil {
  86. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  87. response.FailWithMessage("更新失败", c)
  88. } else {
  89. response.OkWithMessage("更新成功", c)
  90. }
  91. }
  92. // FindAssignment 用id查询Assignment
  93. // @Tags Assignment
  94. // @Summary 用id查询Assignment
  95. // @Security ApiKeyAuth
  96. // @accept application/json
  97. // @Produce application/json
  98. // @Param data query autocode.Assignment true "用id查询Assignment"
  99. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  100. // @Router /assignment/findAssignment [get]
  101. func (assignmentApi *AssignmentApi) FindAssignment(c *gin.Context) {
  102. var assignment autocode.Assignment
  103. _ = c.ShouldBindQuery(&assignment)
  104. if err, reassignment := assignmentService.GetAssignment(assignment.ID); err != nil {
  105. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  106. response.FailWithMessage("查询失败", c)
  107. } else {
  108. _, files := fileUploadAndDownloadService.GetFileRecordInfoByList(reassignment.ID)
  109. reassignment.Files = files
  110. response.OkWithData(gin.H{"reassignment": reassignment}, c)
  111. }
  112. }
  113. // GetAssignmentList 分页获取Assignment列表
  114. // @Tags Assignment
  115. // @Summary 分页获取Assignment列表
  116. // @Security ApiKeyAuth
  117. // @accept application/json
  118. // @Produce application/json
  119. // @Param data query autocodeReq.AssignmentSearch true "分页获取Assignment列表"
  120. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  121. // @Router /assignment/getAssignmentList [get]
  122. func (assignmentApi *AssignmentApi) GetAssignmentList(c *gin.Context) {
  123. var pageInfo autocodeReq.AssignmentSearch
  124. _ = c.ShouldBindQuery(&pageInfo)
  125. if err, list, total := assignmentService.GetAssignmentInfoList(pageInfo); err != nil {
  126. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  127. response.FailWithMessage("获取失败", c)
  128. } else {
  129. response.OkWithDetailed(response.PageResult{
  130. List: list,
  131. Total: total,
  132. Page: pageInfo.Page,
  133. PageSize: pageInfo.PageSize,
  134. }, "获取成功", c)
  135. }
  136. }