problem_info.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. _, dictList := service.ServiceGroupApp.SystemServiceGroup.DictionaryService.GetSysDictionaryDetailList()
  57. err := service.ServiceGroupApp.ExampleServiceGroup.ExcelService.ProblemInfoList2Excel(list, filePath, dictList)
  58. if err != nil {
  59. global.GVA_LOG.Error("转换Excel失败!", zap.Any("err", err))
  60. response.FailWithMessage("转换Excel失败", c)
  61. return
  62. }
  63. c.Writer.Header().Add("success", "true")
  64. c.File(filePath)
  65. }
  66. }
  67. // DeleteProblemInfo 删除ProblemInfo
  68. // @Tags ProblemInfo
  69. // @Summary 删除ProblemInfo
  70. // @Security ApiKeyAuth
  71. // @accept application/json
  72. // @Produce application/json
  73. // @Param data body autocode.ProblemInfo true "删除ProblemInfo"
  74. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  75. // @Router /problemInfo/deleteProblemInfo [delete]
  76. func (problemInfoApi *ProblemInfoApi) DeleteProblemInfo(c *gin.Context) {
  77. var problemInfo autocode.ProblemInfo
  78. _ = c.ShouldBindJSON(&problemInfo)
  79. if err := problemInfoService.DeleteProblemInfo(problemInfo); err != nil {
  80. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  81. response.FailWithMessage("删除失败", c)
  82. } else {
  83. response.OkWithMessage("删除成功", c)
  84. }
  85. }
  86. // DeleteProblemInfoByIds 批量删除ProblemInfo
  87. // @Tags ProblemInfo
  88. // @Summary 批量删除ProblemInfo
  89. // @Security ApiKeyAuth
  90. // @accept application/json
  91. // @Produce application/json
  92. // @Param data body request.IdsReq true "批量删除ProblemInfo"
  93. // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
  94. // @Router /problemInfo/deleteProblemInfoByIds [delete]
  95. func (problemInfoApi *ProblemInfoApi) DeleteProblemInfoByIds(c *gin.Context) {
  96. var IDS request.IdsReq
  97. _ = c.ShouldBindJSON(&IDS)
  98. if err := problemInfoService.DeleteProblemInfoByIds(IDS); err != nil {
  99. global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
  100. response.FailWithMessage("批量删除失败", c)
  101. } else {
  102. response.OkWithMessage("批量删除成功", c)
  103. }
  104. }
  105. // UpdateProblemInfo 更新ProblemInfo
  106. // @Tags ProblemInfo
  107. // @Summary 更新ProblemInfo
  108. // @Security ApiKeyAuth
  109. // @accept application/json
  110. // @Produce application/json
  111. // @Param data body autocode.ProblemInfo true "更新ProblemInfo"
  112. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  113. // @Router /problemInfo/updateProblemInfo [put]
  114. func (problemInfoApi *ProblemInfoApi) UpdateProblemInfo(c *gin.Context) {
  115. var problemInfo autocode.ProblemInfo
  116. _ = c.ShouldBindJSON(&problemInfo)
  117. _, problemInfoNow := problemInfoService.GetProblemInfo(problemInfo.ID)
  118. problemInfoNow.Handler = problemInfo.Handler
  119. problemInfoNow.HandImgs = problemInfo.HandImgs
  120. problemInfoNow.HandText = problemInfo.HandText
  121. problemInfoNow.Status = "Processed"
  122. if err := problemInfoService.UpdateProblemInfo(problemInfoNow); err != nil {
  123. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  124. response.FailWithMessage("更新失败", c)
  125. } else {
  126. response.OkWithMessage("更新成功", c)
  127. }
  128. }
  129. // FindProblemInfo 用id查询ProblemInfo
  130. // @Tags ProblemInfo
  131. // @Summary 用id查询ProblemInfo
  132. // @Security ApiKeyAuth
  133. // @accept application/json
  134. // @Produce application/json
  135. // @Param data query autocode.ProblemInfo true "用id查询ProblemInfo"
  136. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  137. // @Router /problemInfo/findProblemInfo [get]
  138. func (problemInfoApi *ProblemInfoApi) FindProblemInfo(c *gin.Context) {
  139. var problemInfo autocode.ProblemInfo
  140. _ = c.ShouldBindQuery(&problemInfo)
  141. if err, reproblemInfo := problemInfoService.GetProblemInfo(problemInfo.ID); err != nil {
  142. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  143. response.FailWithMessage("查询失败", c)
  144. } else {
  145. //param := reqMode.SysDictionarySearch{, request.PageInfo{PageSize: 9999, Page: 0}}
  146. _, reproblemInfo.MatterList = service.ServiceGroupApp.SystemServiceGroup.DictionaryService.GetSysDictionaryDetail(reproblemInfo.SiteType)
  147. response.OkWithData(gin.H{"reproblemInfo": reproblemInfo}, c)
  148. }
  149. }
  150. // GetProblemInfoList 分页获取ProblemInfo列表
  151. // @Tags ProblemInfo
  152. // @Summary 分页获取ProblemInfo列表
  153. // @Security ApiKeyAuth
  154. // @accept application/json
  155. // @Produce application/json
  156. // @Param data query autocodeReq.ProblemInfoSearch true "分页获取ProblemInfo列表"
  157. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  158. // @Router /problemInfo/getProblemInfoList [get]
  159. func (problemInfoApi *ProblemInfoApi) GetProblemInfoList(c *gin.Context) {
  160. var pageInfo autocodeReq.ProblemInfoSearch
  161. _ = c.ShouldBindQuery(&pageInfo)
  162. if err, list, total := problemInfoService.GetProblemInfoInfoList(pageInfo); err != nil {
  163. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  164. response.FailWithMessage("获取失败", c)
  165. } else {
  166. response.OkWithDetailed(response.PageResult{
  167. List: list,
  168. Total: total,
  169. Page: pageInfo.Page,
  170. PageSize: pageInfo.PageSize,
  171. }, "获取成功", c)
  172. }
  173. }