problem_info.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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/flipped-aurora/gin-vue-admin/server/utils"
  10. "github.com/gin-gonic/gin"
  11. "go.uber.org/zap"
  12. "strconv"
  13. "time"
  14. )
  15. type ProblemInfoApi struct {
  16. }
  17. var problemInfoService = service.ServiceGroupApp.AutoCodeServiceGroup.ProblemInfoService
  18. // CreateProblemInfo 创建ProblemInfo
  19. // @Tags ProblemInfo
  20. // @Summary 创建ProblemInfo
  21. // @Security ApiKeyAuth
  22. // @accept application/json
  23. // @Produce application/json
  24. // @Param data body autocode.ProblemInfo true "创建ProblemInfo"
  25. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  26. // @Router /problemInfo/createProblemInfo [post]
  27. func (problemInfoApi *ProblemInfoApi) CreateProblemInfo(c *gin.Context) {
  28. userId := utils.GetUserID(c)
  29. var problemInfo autocode.ProblemInfo
  30. _ = c.ShouldBindJSON(&problemInfo)
  31. problemInfo.Status = "Untreated"
  32. if err, place := service.ServiceGroupApp.AutoCodeServiceGroup.PlaceService.GetPlace(problemInfo.SiteId); err != nil {
  33. response.FailWithMessage("创建失败,选择站点错误", c)
  34. } else {
  35. problemInfo.Oper = userId
  36. problemInfo.SiteType = place.Type
  37. problemInfo.Position = place.Position
  38. problemInfo.SiteName = place.Name
  39. problemInfo.Region = place.Region
  40. }
  41. if err := problemInfoService.CreateProblemInfo(problemInfo); err != nil {
  42. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  43. response.FailWithMessage("创建失败", c)
  44. } else {
  45. response.OkWithMessage("创建成功", c)
  46. }
  47. }
  48. func (problemInfoApi *ProblemInfoApi) ExportExcel(c *gin.Context) {
  49. var problemInfo autocodeReq.ProblemInfoSearch
  50. _ = c.ShouldBindJSON(&problemInfo)
  51. filePath := global.GVA_CONFIG.Excel.Dir + strconv.FormatInt(time.Now().Unix(), 10) + ".xlsx"
  52. if err, list, _ := problemInfoService.GetProblemInfoInfoList(problemInfo); err != nil {
  53. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  54. response.FailWithMessage("获取失败", c)
  55. } else {
  56. err := service.ServiceGroupApp.ExampleServiceGroup.ExcelService.ProblemInfoList2Excel(list, filePath)
  57. if err != nil {
  58. global.GVA_LOG.Error("转换Excel失败!", zap.Any("err", err))
  59. response.FailWithMessage("转换Excel失败", c)
  60. return
  61. }
  62. c.Writer.Header().Add("success", "true")
  63. c.File(filePath)
  64. }
  65. }
  66. // DeleteProblemInfo 删除ProblemInfo
  67. // @Tags ProblemInfo
  68. // @Summary 删除ProblemInfo
  69. // @Security ApiKeyAuth
  70. // @accept application/json
  71. // @Produce application/json
  72. // @Param data body autocode.ProblemInfo true "删除ProblemInfo"
  73. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  74. // @Router /problemInfo/deleteProblemInfo [delete]
  75. func (problemInfoApi *ProblemInfoApi) DeleteProblemInfo(c *gin.Context) {
  76. var problemInfo autocode.ProblemInfo
  77. _ = c.ShouldBindJSON(&problemInfo)
  78. if err := problemInfoService.DeleteProblemInfo(problemInfo); err != nil {
  79. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  80. response.FailWithMessage("删除失败", c)
  81. } else {
  82. response.OkWithMessage("删除成功", c)
  83. }
  84. }
  85. // DeleteProblemInfoByIds 批量删除ProblemInfo
  86. // @Tags ProblemInfo
  87. // @Summary 批量删除ProblemInfo
  88. // @Security ApiKeyAuth
  89. // @accept application/json
  90. // @Produce application/json
  91. // @Param data body request.IdsReq true "批量删除ProblemInfo"
  92. // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
  93. // @Router /problemInfo/deleteProblemInfoByIds [delete]
  94. func (problemInfoApi *ProblemInfoApi) DeleteProblemInfoByIds(c *gin.Context) {
  95. var IDS request.IdsReq
  96. _ = c.ShouldBindJSON(&IDS)
  97. if err := problemInfoService.DeleteProblemInfoByIds(IDS); err != nil {
  98. global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
  99. response.FailWithMessage("批量删除失败", c)
  100. } else {
  101. response.OkWithMessage("批量删除成功", c)
  102. }
  103. }
  104. // UpdateProblemInfo 更新ProblemInfo
  105. // @Tags ProblemInfo
  106. // @Summary 更新ProblemInfo
  107. // @Security ApiKeyAuth
  108. // @accept application/json
  109. // @Produce application/json
  110. // @Param data body autocode.ProblemInfo true "更新ProblemInfo"
  111. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  112. // @Router /problemInfo/updateProblemInfo [put]
  113. func (problemInfoApi *ProblemInfoApi) UpdateProblemInfo(c *gin.Context) {
  114. var problemInfo autocode.ProblemInfo
  115. _ = c.ShouldBindJSON(&problemInfo)
  116. _, problemInfoNow := problemInfoService.GetProblemInfo(problemInfo.ID)
  117. problemInfoNow.Handler = problemInfo.Handler
  118. problemInfoNow.HandImgs = problemInfo.HandImgs
  119. problemInfoNow.HandText = problemInfo.HandText
  120. problemInfoNow.Status = "Processed"
  121. if err := problemInfoService.UpdateProblemInfo(problemInfoNow); err != nil {
  122. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  123. response.FailWithMessage("更新失败", c)
  124. } else {
  125. response.OkWithMessage("更新成功", c)
  126. }
  127. }
  128. // FindProblemInfo 用id查询ProblemInfo
  129. // @Tags ProblemInfo
  130. // @Summary 用id查询ProblemInfo
  131. // @Security ApiKeyAuth
  132. // @accept application/json
  133. // @Produce application/json
  134. // @Param data query autocode.ProblemInfo true "用id查询ProblemInfo"
  135. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  136. // @Router /problemInfo/findProblemInfo [get]
  137. func (problemInfoApi *ProblemInfoApi) FindProblemInfo(c *gin.Context) {
  138. var problemInfo autocode.ProblemInfo
  139. _ = c.ShouldBindQuery(&problemInfo)
  140. if err, reproblemInfo := problemInfoService.GetProblemInfo(problemInfo.ID); err != nil {
  141. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  142. response.FailWithMessage("查询失败", c)
  143. } else {
  144. response.OkWithData(gin.H{"reproblemInfo": reproblemInfo}, c)
  145. }
  146. }
  147. // GetProblemInfoList 分页获取ProblemInfo列表
  148. // @Tags ProblemInfo
  149. // @Summary 分页获取ProblemInfo列表
  150. // @Security ApiKeyAuth
  151. // @accept application/json
  152. // @Produce application/json
  153. // @Param data query autocodeReq.ProblemInfoSearch true "分页获取ProblemInfo列表"
  154. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  155. // @Router /problemInfo/getProblemInfoList [get]
  156. func (problemInfoApi *ProblemInfoApi) GetProblemInfoList(c *gin.Context) {
  157. var pageInfo autocodeReq.ProblemInfoSearch
  158. _ = c.ShouldBindQuery(&pageInfo)
  159. if err, list, total := problemInfoService.GetProblemInfoInfoList(pageInfo); err != nil {
  160. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  161. response.FailWithMessage("获取失败", c)
  162. } else {
  163. response.OkWithDetailed(response.PageResult{
  164. List: list,
  165. Total: total,
  166. Page: pageInfo.Page,
  167. PageSize: pageInfo.PageSize,
  168. }, "获取成功", c)
  169. }
  170. }