place.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 PlaceApi struct {
  13. }
  14. var placeService = service.ServiceGroupApp.AutoCodeServiceGroup.PlaceService
  15. // CreatePlace 创建Place
  16. // @Tags Place
  17. // @Summary 创建Place
  18. // @Security ApiKeyAuth
  19. // @accept application/json
  20. // @Produce application/json
  21. // @Param data body autocode.Place true "创建Place"
  22. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  23. // @Router /place/createPlace [post]
  24. func (placeApi *PlaceApi) CreatePlace(c *gin.Context) {
  25. var place autocode.Place
  26. _ = c.ShouldBindJSON(&place)
  27. temp := *place.UnitMaxIntegral * 100
  28. place.UnitMaxIntegral = &temp
  29. if err := placeService.CreatePlace(place); err != nil {
  30. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  31. response.FailWithMessage("创建失败", c)
  32. } else {
  33. response.OkWithMessage("创建成功", c)
  34. }
  35. }
  36. // DeletePlace 删除Place
  37. // @Tags Place
  38. // @Summary 删除Place
  39. // @Security ApiKeyAuth
  40. // @accept application/json
  41. // @Produce application/json
  42. // @Param data body autocode.Place true "删除Place"
  43. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  44. // @Router /place/deletePlace [delete]
  45. func (placeApi *PlaceApi) DeletePlace(c *gin.Context) {
  46. var place autocode.Place
  47. _ = c.ShouldBindJSON(&place)
  48. if err := placeService.DeletePlace(place); err != nil {
  49. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  50. response.FailWithMessage("删除失败", c)
  51. } else {
  52. response.OkWithMessage("删除成功", c)
  53. }
  54. }
  55. // DeletePlaceByIds 批量删除Place
  56. // @Tags Place
  57. // @Summary 批量删除Place
  58. // @Security ApiKeyAuth
  59. // @accept application/json
  60. // @Produce application/json
  61. // @Param data body request.IdsReq true "批量删除Place"
  62. // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
  63. // @Router /place/deletePlaceByIds [delete]
  64. func (placeApi *PlaceApi) DeletePlaceByIds(c *gin.Context) {
  65. var IDS request.IdsReq
  66. _ = c.ShouldBindJSON(&IDS)
  67. if err := placeService.DeletePlaceByIds(IDS); err != nil {
  68. global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
  69. response.FailWithMessage("批量删除失败", c)
  70. } else {
  71. response.OkWithMessage("批量删除成功", c)
  72. }
  73. }
  74. // UpdatePlace 更新Place
  75. // @Tags Place
  76. // @Summary 更新Place
  77. // @Security ApiKeyAuth
  78. // @accept application/json
  79. // @Produce application/json
  80. // @Param data body autocode.Place true "更新Place"
  81. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  82. // @Router /place/updatePlace [put]
  83. func (placeApi *PlaceApi) UpdatePlace(c *gin.Context) {
  84. var place autocode.Place
  85. _ = c.ShouldBindJSON(&place)
  86. temp := *place.UnitMaxIntegral * 100
  87. place.UnitMaxIntegral = &temp
  88. if err := placeService.UpdatePlace(place); err != nil {
  89. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  90. response.FailWithMessage("更新失败", c)
  91. } else {
  92. response.OkWithMessage("更新成功", c)
  93. }
  94. }
  95. // FindPlace 用id查询Place
  96. // @Tags Place
  97. // @Summary 用id查询Place
  98. // @Security ApiKeyAuth
  99. // @accept application/json
  100. // @Produce application/json
  101. // @Param data query autocode.Place true "用id查询Place"
  102. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  103. // @Router /place/findPlace [get]
  104. func (placeApi *PlaceApi) FindPlace(c *gin.Context) {
  105. var place autocode.Place
  106. _ = c.ShouldBindQuery(&place)
  107. if err, replace := placeService.GetPlace(place.ID); err != nil {
  108. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  109. response.FailWithMessage("查询失败", c)
  110. } else {
  111. _, list := placeProService.GetPlaceProByIds(replace.ID)
  112. replace.ProList = list
  113. response.OkWithData(gin.H{"replace": replace}, c)
  114. }
  115. }
  116. // GetPlaceList 分页获取Place列表
  117. // @Tags Place
  118. // @Summary 分页获取Place列表
  119. // @Security ApiKeyAuth
  120. // @accept application/json
  121. // @Produce application/json
  122. // @Param data query autocodeReq.PlaceSearch true "分页获取Place列表"
  123. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  124. // @Router /place/getPlaceList [get]
  125. func (placeApi *PlaceApi) GetPlaceList(c *gin.Context) {
  126. var pageInfo autocodeReq.PlaceSearch
  127. _ = c.ShouldBindQuery(&pageInfo)
  128. if err, list, total := placeService.GetPlaceInfoList(pageInfo); err != nil {
  129. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  130. response.FailWithMessage("获取失败", c)
  131. } else {
  132. response.OkWithDetailed(response.PageResult{
  133. List: list,
  134. Total: total,
  135. Page: pageInfo.Page,
  136. PageSize: pageInfo.PageSize,
  137. }, "获取成功", c)
  138. }
  139. }