unit_user.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 UnitUserApi struct {
  13. }
  14. var unitUserService = service.ServiceGroupApp.AutoCodeServiceGroup.UnitUserService
  15. // CreateUnitUser 创建UnitUser
  16. // @Tags UnitUser
  17. // @Summary 创建UnitUser
  18. // @Security ApiKeyAuth
  19. // @accept application/json
  20. // @Produce application/json
  21. // @Param data body autocode.UnitUser true "创建UnitUser"
  22. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  23. // @Router /unitUser/createUnitUser [post]
  24. func (unitUserApi *UnitUserApi) CreateUnitUser(c *gin.Context) {
  25. var unitUser autocode.UnitUser
  26. _ = c.ShouldBindJSON(&unitUser)
  27. if err := unitUserService.CreateUnitUser(unitUser); err != nil {
  28. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  29. response.FailWithMessage("创建失败", c)
  30. } else {
  31. response.OkWithMessage("创建成功", c)
  32. }
  33. }
  34. // DeleteUnitUser 删除UnitUser
  35. // @Tags UnitUser
  36. // @Summary 删除UnitUser
  37. // @Security ApiKeyAuth
  38. // @accept application/json
  39. // @Produce application/json
  40. // @Param data body autocode.UnitUser true "删除UnitUser"
  41. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  42. // @Router /unitUser/deleteUnitUser [delete]
  43. func (unitUserApi *UnitUserApi) DeleteUnitUser(c *gin.Context) {
  44. var unitUser autocode.UnitUser
  45. _ = c.ShouldBindJSON(&unitUser)
  46. if err := unitUserService.DeleteUnitUser(unitUser); err != nil {
  47. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  48. response.FailWithMessage("删除失败", c)
  49. } else {
  50. response.OkWithMessage("删除成功", c)
  51. }
  52. }
  53. // DeleteUnitUserByIds 批量删除UnitUser
  54. // @Tags UnitUser
  55. // @Summary 批量删除UnitUser
  56. // @Security ApiKeyAuth
  57. // @accept application/json
  58. // @Produce application/json
  59. // @Param data body request.IdsReq true "批量删除UnitUser"
  60. // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
  61. // @Router /unitUser/deleteUnitUserByIds [delete]
  62. func (unitUserApi *UnitUserApi) DeleteUnitUserByIds(c *gin.Context) {
  63. var IDS request.IdsReq
  64. _ = c.ShouldBindJSON(&IDS)
  65. if err := unitUserService.DeleteUnitUserByIds(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. // UpdateUnitUser 更新UnitUser
  73. // @Tags UnitUser
  74. // @Summary 更新UnitUser
  75. // @Security ApiKeyAuth
  76. // @accept application/json
  77. // @Produce application/json
  78. // @Param data body autocode.UnitUser true "更新UnitUser"
  79. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  80. // @Router /unitUser/updateUnitUser [put]
  81. func (unitUserApi *UnitUserApi) UpdateUnitUser(c *gin.Context) {
  82. var unitUser autocode.UnitUserVo
  83. _ = c.ShouldBindJSON(&unitUser)
  84. _, unitUsers := unitUserService.GetUnitUsers(unitUser.UnitId)
  85. newUser := make(map[string]struct{}, len(unitUser.UUID))
  86. for _, item := range unitUser.UUID {
  87. newUser[item] = struct{}{}
  88. }
  89. // 反未包含删除
  90. for _, unitTemp := range unitUsers {
  91. if _, ok := newUser[unitTemp.UUID]; ok {
  92. continue
  93. } else {
  94. unitUserService.DeleteUnitUser(unitTemp)
  95. }
  96. }
  97. //原有的map
  98. source := make(map[string]struct{}, len(unitUsers))
  99. for _, item := range unitUsers {
  100. source[item.UUID] = struct{}{}
  101. }
  102. for _, uuid := range unitUser.UUID {
  103. if _, ok := source[uuid]; ok {
  104. continue
  105. } else {
  106. // 未包含的添加
  107. unitUserService.CreateUnitUser(autocode.UnitUser{UnitId: unitUser.UnitId, UUID: uuid})
  108. }
  109. }
  110. response.OkWithMessage("更新成功", c)
  111. }
  112. // FindUnitUser 用id查询UnitUser
  113. // @Tags UnitUser
  114. // @Summary 用id查询UnitUser
  115. // @Security ApiKeyAuth
  116. // @accept application/json
  117. // @Produce application/json
  118. // @Param data query autocode.UnitUser true "用id查询UnitUser"
  119. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  120. // @Router /unitUser/findUnitUser [get]
  121. func (unitUserApi *UnitUserApi) FindUnitUser(c *gin.Context) {
  122. var unitUser autocode.UnitUser
  123. _ = c.ShouldBindQuery(&unitUser)
  124. if err, reunitUser := unitUserService.GetUnitUser(unitUser.ID); err != nil {
  125. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  126. response.FailWithMessage("查询失败", c)
  127. } else {
  128. response.OkWithData(gin.H{"reunitUser": reunitUser}, c)
  129. }
  130. }
  131. // GetUnitUserList 分页获取UnitUser列表
  132. // @Tags UnitUser
  133. // @Summary 分页获取UnitUser列表
  134. // @Security ApiKeyAuth
  135. // @accept application/json
  136. // @Produce application/json
  137. // @Param data query autocodeReq.UnitUserSearch true "分页获取UnitUser列表"
  138. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  139. // @Router /unitUser/getUnitUserList [get]
  140. func (unitUserApi *UnitUserApi) GetUnitUserList(c *gin.Context) {
  141. var pageInfo autocodeReq.UnitUserSearch
  142. _ = c.ShouldBindQuery(&pageInfo)
  143. _, list := unitUserService.GetUnitUsers(pageInfo.UnitId)
  144. temp := make([]string, 0)
  145. for _, item := range list {
  146. temp = append(temp, item.UUID)
  147. }
  148. response.OkWithData(temp, c)
  149. }