organization.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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/response"
  7. "github.com/flipped-aurora/gin-vue-admin/server/service"
  8. "github.com/gin-gonic/gin"
  9. "go.uber.org/zap"
  10. )
  11. type OrganizationApi struct {
  12. }
  13. var organizationService = service.ServiceGroupApp.AutoCodeServiceGroup.OrganizationService
  14. // CreateOrganization 创建Organization
  15. // @Tags Organization
  16. // @Summary 创建Organization
  17. // @Security ApiKeyAuth
  18. // @accept application/json
  19. // @Produce application/json
  20. // @Param data body autocode.Organization true "创建Organization"
  21. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  22. // @Router /organization/createOrganization [post]
  23. func (organizationApi *OrganizationApi) CreateOrganization(c *gin.Context) {
  24. var organization autocode.Organization
  25. _ = c.ShouldBindJSON(&organization)
  26. if err := organizationService.CreateOrganization(organization); err != nil {
  27. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  28. response.FailWithMessage("创建失败", c)
  29. } else {
  30. response.OkWithMessage("创建成功", c)
  31. }
  32. }
  33. // DeleteOrganization 删除Organization
  34. // @Tags Organization
  35. // @Summary 删除Organization
  36. // @Security ApiKeyAuth
  37. // @accept application/json
  38. // @Produce application/json
  39. // @Param data body autocode.Organization true "删除Organization"
  40. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  41. // @Router /organization/deleteOrganization [delete]
  42. func (organizationApi *OrganizationApi) DeleteOrganization(c *gin.Context) {
  43. var organization autocode.Organization
  44. _ = c.ShouldBindJSON(&organization)
  45. if err := organizationService.DeleteOrganization(organization); err != nil {
  46. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  47. response.FailWithMessage("删除失败", c)
  48. } else {
  49. response.OkWithMessage("删除成功", c)
  50. }
  51. }
  52. // DeleteOrganizationByIds 批量删除Organization
  53. // @Tags Organization
  54. // @Summary 批量删除Organization
  55. // @Security ApiKeyAuth
  56. // @accept application/json
  57. // @Produce application/json
  58. // @Param data body request.IdsReq true "批量删除Organization"
  59. // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
  60. // @Router /organization/deleteOrganizationByIds [delete]
  61. func (organizationApi *OrganizationApi) DeleteOrganizationByIds(c *gin.Context) {
  62. var CODES []string
  63. _ = c.ShouldBindJSON(&CODES)
  64. if err := organizationService.DeleteOrganizationByIds(CODES); err != nil {
  65. global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
  66. response.FailWithMessage("批量删除失败", c)
  67. } else {
  68. response.OkWithMessage("批量删除成功", c)
  69. }
  70. }
  71. // UpdateOrganization 更新Organization
  72. // @Tags Organization
  73. // @Summary 更新Organization
  74. // @Security ApiKeyAuth
  75. // @accept application/json
  76. // @Produce application/json
  77. // @Param data body autocode.Organization true "更新Organization"
  78. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  79. // @Router /organization/updateOrganization [put]
  80. func (organizationApi *OrganizationApi) UpdateOrganization(c *gin.Context) {
  81. var organization autocode.Organization
  82. _ = c.ShouldBindJSON(&organization)
  83. if err := organizationService.UpdateOrganization(organization); err != nil {
  84. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  85. response.FailWithMessage("更新失败", c)
  86. } else {
  87. response.OkWithMessage("更新成功", c)
  88. }
  89. }
  90. // FindOrganization 用id查询Organization
  91. // @Tags Organization
  92. // @Summary 用id查询Organization
  93. // @Security ApiKeyAuth
  94. // @accept application/json
  95. // @Produce application/json
  96. // @Param data query autocode.Organization true "用id查询Organization"
  97. // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
  98. // @Router /organization/findOrganization [get]
  99. func (organizationApi *OrganizationApi) FindOrganization(c *gin.Context) {
  100. var organization autocode.Organization
  101. _ = c.ShouldBindQuery(&organization)
  102. if err, reorganization := organizationService.GetOrganization(organization.CODE); err != nil {
  103. global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
  104. response.FailWithMessage("查询失败", c)
  105. } else {
  106. response.OkWithData(gin.H{"reorganization": reorganization}, c)
  107. }
  108. }
  109. func (organizationApi *OrganizationApi) FindOrganizationTree(c *gin.Context) {
  110. code, _ := c.GetQuery("code")
  111. treeMap := make(map[string][]autocode.Organization)
  112. if err, reorganization := organizationService.GetOrganizationInfoLists(); err != nil {
  113. response.FailWithMessage("查询失败", c)
  114. } else {
  115. for _, v := range reorganization {
  116. treeMap[v.PARENTCODE] = append(treeMap[v.PARENTCODE], v)
  117. }
  118. var orgList []autocode.Organization
  119. if code != "" {
  120. orgList = treeMap[code]
  121. } else {
  122. orgList = treeMap["00"]
  123. }
  124. for i := 0; i < len(orgList); i++ {
  125. err = organizationService.GetBaseChildrenList(&orgList[i], treeMap)
  126. }
  127. response.OkWithData(gin.H{"treeMap": orgList}, c)
  128. }
  129. }
  130. // GetOrganizationList 分页获取Organization列表
  131. // @Tags Organization
  132. // @Summary 分页获取Organization列表
  133. // @Security ApiKeyAuth
  134. // @accept application/json
  135. // @Produce application/json
  136. // @Param data query autocodeReq.OrganizationSearch true "分页获取Organization列表"
  137. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  138. // @Router /organization/getOrganizationList [get]
  139. func (organizationApi *OrganizationApi) GetOrganizationList(c *gin.Context) {
  140. var pageInfo autocodeReq.OrganizationSearch
  141. _ = c.ShouldBindQuery(&pageInfo)
  142. if err, list, total := organizationService.GetOrganizationInfoList(pageInfo); err != nil {
  143. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  144. response.FailWithMessage("获取失败", c)
  145. } else {
  146. response.OkWithDetailed(response.PageResult{
  147. List: list,
  148. Total: total,
  149. Page: pageInfo.Page,
  150. PageSize: pageInfo.PageSize,
  151. }, "获取成功", c)
  152. }
  153. }