unit_place.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 UnitPlaceApi struct {
  13. }
  14. var unitPlaceService = service.ServiceGroupApp.AutoCodeServiceGroup.UnitPlaceService
  15. // CreateUnitPlace 创建UnitPlace
  16. // @Tags UnitPlace
  17. // @Summary 创建UnitPlace
  18. // @Security ApiKeyAuth
  19. // @accept application/json
  20. // @Produce application/json
  21. // @Param data body autocode.UnitPlace true "创建UnitPlace"
  22. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  23. // @Router /unitPlace/createUnitPlace [post]
  24. func (unitPlaceApi *UnitPlaceApi) CreateUnitPlace(c *gin.Context) {
  25. var unitPlace autocode.UnitPlace
  26. _ = c.ShouldBindJSON(&unitPlace)
  27. if err := unitPlaceService.CreateUnitPlace(unitPlace); err != nil {
  28. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  29. response.FailWithMessage("创建失败", c)
  30. } else {
  31. response.OkWithMessage("创建成功", c)
  32. }
  33. }
  34. // DeleteUnitPlace 删除UnitPlace
  35. // @Tags UnitPlace
  36. // @Summary 删除UnitPlace
  37. // @Security ApiKeyAuth
  38. // @accept application/json
  39. // @Produce application/json
  40. // @Param data body autocode.UnitPlace true "删除UnitPlace"
  41. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  42. // @Router /unitPlace/deleteUnitPlace [delete]
  43. func (unitPlaceApi *UnitPlaceApi) DeleteUnitPlace(c *gin.Context) {
  44. var unitPlace autocode.UnitPlace
  45. _ = c.ShouldBindJSON(&unitPlace)
  46. if err := unitPlaceService.DeleteUnitPlace(unitPlace); err != nil {
  47. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  48. response.FailWithMessage("删除失败", c)
  49. } else {
  50. response.OkWithMessage("删除成功", c)
  51. }
  52. }
  53. // DeleteUnitPlaceByIds 批量删除UnitPlace
  54. // @Tags UnitPlace
  55. // @Summary 批量删除UnitPlace
  56. // @Security ApiKeyAuth
  57. // @accept application/json
  58. // @Produce application/json
  59. // @Param data body request.IdsReq true "批量删除UnitPlace"
  60. // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
  61. // @Router /unitPlace/deleteUnitPlaceByIds [delete]
  62. func (unitPlaceApi *UnitPlaceApi) DeleteUnitPlaceByIds(c *gin.Context) {
  63. var IDS request.IdsReq
  64. _ = c.ShouldBindJSON(&IDS)
  65. if err := unitPlaceService.DeleteUnitPlaceByIds(IDS); err != nil {
  66. global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
  67. response.FailWithMessage("批量删除失败", c)
  68. } else {
  69. response.OkWithMessage("批量删除成功", c)
  70. }
  71. }
  72. // UpdateUnitPlace 更新UnitPlace
  73. // @Tags UnitPlace
  74. // @Summary 更新UnitPlace
  75. // @Security ApiKeyAuth
  76. // @accept application/json
  77. // @Produce application/json
  78. // @Param data body autocode.UnitPlace true "更新UnitPlace"
  79. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  80. // @Router /unitPlace/updateUnitPlace [put]
  81. func (unitPlaceApi *UnitPlaceApi) UpdateUnitPlace(c *gin.Context) {
  82. var unitPlace autocode.UnitPlaceVo
  83. _ = c.ShouldBindJSON(&unitPlace)
  84. _, unitPlaces := unitPlaceService.GetUnitPlaces(unitPlace.UnitId)
  85. newUser := make(map[string]struct{}, len(unitPlace.PlaceIds))
  86. for _, item := range unitPlace.PlaceIds {
  87. newUser[item] = struct{}{}
  88. }
  89. // 反未包含删除
  90. for _, unitTemp := range unitPlaces {
  91. if _, ok := newUser[unitTemp.PlaceId]; ok {
  92. continue
  93. } else {
  94. unitPlaceService.DeleteUnitPlace(unitTemp)
  95. }
  96. }
  97. //原有的map
  98. source := make(map[string]struct{}, len(unitPlaces))
  99. for _, item := range unitPlaces {
  100. source[item.PlaceId] = struct{}{}
  101. }
  102. for _, place := range unitPlace.PlaceIds {
  103. if _, ok := source[place]; ok {
  104. continue
  105. } else {
  106. // 未包含的添加
  107. unitPlaceService.CreateUnitPlace(autocode.UnitPlace{UnitId: unitPlace.UnitId, PlaceId: place})
  108. }
  109. }
  110. //计算总分满分
  111. _, unitPlacesNow := unitPlaceService.GetUnitPlaces(unitPlace.UnitId)
  112. placeIds := make([]string, 0)
  113. for _, places := range unitPlacesNow {
  114. placeIds = append(placeIds, places.PlaceId)
  115. }
  116. sum := placeService.FindPlaceSum(placeIds)
  117. unitService.UpdateUnitMaxIntegral(unitPlace.UnitId, sum)
  118. response.OkWithMessage("更新成功", c)
  119. }
  120. // FindUnitPlace 用id查询UnitPlace
  121. // @Tags UnitPlace
  122. // @Summary 用id查询UnitPlace
  123. // @Security ApiKeyAuth
  124. // @accept application/json
  125. // @Produce application/json
  126. // @Param data query autocode.UnitPlace true "用id查询UnitPlace"
  127. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  128. // @Router /unitPlace/findUnitPlace [get]
  129. func (unitPlaceApi *UnitPlaceApi) FindUnitPlace(c *gin.Context) {
  130. var unitPlace autocode.UnitPlace
  131. _ = c.ShouldBindQuery(&unitPlace)
  132. if err, reunitPlace := unitPlaceService.GetUnitPlace(unitPlace.ID); err != nil {
  133. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  134. response.FailWithMessage("查询失败", c)
  135. } else {
  136. response.OkWithData(gin.H{"reunitPlace": reunitPlace}, c)
  137. }
  138. }
  139. // GetUnitPlaceList 分页获取UnitPlace列表
  140. // @Tags UnitPlace
  141. // @Summary 分页获取UnitPlace列表
  142. // @Security ApiKeyAuth
  143. // @accept application/json
  144. // @Produce application/json
  145. // @Param data query autocodeReq.UnitPlaceSearch true "分页获取UnitPlace列表"
  146. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  147. // @Router /unitPlace/getUnitPlaceList [get]
  148. func (unitPlaceApi *UnitPlaceApi) GetUnitPlaceList(c *gin.Context) {
  149. var pageInfo autocodeReq.UnitPlaceSearch
  150. _ = c.ShouldBindQuery(&pageInfo)
  151. if err, list, total := unitPlaceService.GetUnitPlaceInfoList(pageInfo); err != nil {
  152. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  153. response.FailWithMessage("获取失败", c)
  154. } else {
  155. response.OkWithDetailed(response.PageResult{
  156. List: list,
  157. Total: total,
  158. Page: pageInfo.Page,
  159. PageSize: pageInfo.PageSize,
  160. }, "获取成功", c)
  161. }
  162. }