capabilities.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/go-playground/validator/v10"
  5. "project_management/app/e"
  6. "project_management/app/model"
  7. "project_management/app/services"
  8. "project_management/unity"
  9. )
  10. var Capabilities services.Capabilities = &model.Capabilities{}
  11. // GetCapabilities 获取所有能力
  12. func GetCapabilities(c *gin.Context) {
  13. var params unity.CapQueryPageParams
  14. var capabilities model.Capabilities
  15. if err := c.ShouldBindJSON(&params); err != nil {
  16. e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
  17. return
  18. }
  19. queryCond := "cap_name like ?"
  20. params.Query = "%" + params.Query + "%"
  21. result, total, err := Capabilities.GetCapabilitiesList(params, capabilities, queryCond)
  22. if err != nil {
  23. e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
  24. return
  25. } else {
  26. e.CapResPonsePage(c, result, total, params)
  27. return
  28. }
  29. }
  30. // AdminGetCapabilities 管理员获取所有功能列表
  31. func AdminGetCapabilities(c *gin.Context) {
  32. var params unity.QueryPageParams
  33. var capabilities model.Capabilities
  34. if err := c.ShouldBindJSON(&params); err != nil {
  35. e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
  36. return
  37. }
  38. queryCond := "cap_name like ?"
  39. params.Query = "%" + params.Query + "%"
  40. result, total, err := Capabilities.AdminGetCapabilitiesList(params, capabilities, queryCond)
  41. if err != nil {
  42. e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
  43. return
  44. }
  45. e.ResPonsePage(c, result, total, params)
  46. return
  47. }
  48. // AdminAddGetCapabilities 添加能力
  49. func AdminAddGetCapabilities(c *gin.Context) {
  50. var capabilities model.Capabilities
  51. if err := c.ShouldBindJSON(&capabilities); err != nil {
  52. e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
  53. return
  54. }
  55. id := unity.RandomIds(4)
  56. for model.CapIdISRepeat(id) {
  57. id = unity.RandomIds(4)
  58. }
  59. capabilities.CapId = id
  60. addCapabilities := Capabilities.AddCapabilities(capabilities)
  61. if addCapabilities == e.SUCCESS {
  62. e.ResponseWithMsg(c, addCapabilities, addCapabilities.GetMsg())
  63. return
  64. }
  65. e.ResponseWithMsg(c, addCapabilities, addCapabilities.GetMsg())
  66. }
  67. // AdminUpdateCapabilities 更新能力
  68. func AdminUpdateCapabilities(c *gin.Context) {
  69. var capabilities model.Capabilities
  70. if err := c.ShouldBindJSON(&capabilities); err != nil {
  71. e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
  72. return
  73. }
  74. validate := validator.New()
  75. if err := validate.Struct(capabilities); err != nil {
  76. e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
  77. return
  78. }
  79. updateCapabilities := Capabilities.UpdateCapabilities(capabilities)
  80. if updateCapabilities == e.SUCCESS {
  81. e.ResponseSuccess(c, nil)
  82. return
  83. }
  84. e.ResponseWithMsg(c, updateCapabilities, updateCapabilities.GetMsg())
  85. }
  86. // AdminDeleteCap 删除功能
  87. func AdminDeleteCap(c *gin.Context) {
  88. var capabilities model.Capabilities
  89. if err := c.ShouldBindJSON(&capabilities); err != nil {
  90. e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
  91. return
  92. }
  93. capre := Capabilities.DeleteCapabilities(capabilities.CapId)
  94. if capre == e.SUCCESS {
  95. e.ResponseSuccess(c, nil)
  96. return
  97. }
  98. e.ResponseWithMsg(c, capre, capre.GetMsg())
  99. }