applyCap.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. )
  9. var ApplyCap services.ApplyCap = &model.ApplyCap{}
  10. // ApplyAddCap 添加应用能力
  11. func ApplyAddCap(c *gin.Context) {
  12. var applyCap model.ApplyCapabilities
  13. if err := c.ShouldBindJSON(&applyCap); err != nil {
  14. e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
  15. return
  16. }
  17. validate := validator.New()
  18. if err := validate.Struct(applyCap); err != nil {
  19. e.ResponseWithMsg(c, e.ERROR, "请检查必填项")
  20. return
  21. }
  22. addCap := ApplyCap.ApplyAddCap(applyCap)
  23. if addCap != e.SUCCESS {
  24. e.ResponseWithMsg(c, addCap, addCap.GetMsg())
  25. return
  26. }
  27. e.ResponseSuccess(c, nil)
  28. }
  29. // GetApplyCapList 获取应用能力列表
  30. func GetApplyCapList(c *gin.Context) {
  31. appid := c.Query("appid")
  32. validate := validator.New()
  33. err := validate.Var(appid, "required")
  34. if err != nil {
  35. e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
  36. return
  37. }
  38. applycap, err := ApplyCap.ApplyCapList(appid)
  39. if err != nil {
  40. e.ResponseWithMsg(c, e.SUCCESS, err.Error())
  41. return
  42. }
  43. e.ResponseSuccess(c, applycap)
  44. }
  45. // UpDateApplyCap 更新应用能力
  46. func UpDateApplyCap(c *gin.Context) {
  47. var applyCap model.ApplyCap
  48. if err := c.ShouldBindJSON(&applyCap); err != nil {
  49. e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
  50. return
  51. }
  52. validate := validator.New()
  53. if err := validate.Struct(applyCap); err != nil {
  54. e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
  55. return
  56. }
  57. dateApplyCap := ApplyCap.UpDateApplyCap(applyCap)
  58. if dateApplyCap != e.SUCCESS {
  59. e.ResponseWithMsg(c, dateApplyCap, dateApplyCap.GetMsg())
  60. return
  61. }
  62. e.ResponseSuccess(c, nil)
  63. }
  64. // UpDateApplyCapSort 拖拽排序
  65. func UpDateApplyCapSort(c *gin.Context) {
  66. var applyCap model.ApplyCap
  67. if err := c.ShouldBindJSON(&applyCap); err != nil {
  68. e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
  69. return
  70. }
  71. validate := validator.New()
  72. if err := validate.Struct(applyCap); err != nil {
  73. e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
  74. return
  75. }
  76. dateApplyCap := ApplyCap.UpdateApplyCapSort(applyCap)
  77. if dateApplyCap != e.SUCCESS {
  78. e.ResponseWithMsg(c, dateApplyCap, dateApplyCap.GetMsg())
  79. return
  80. }
  81. e.ResponseSuccess(c, nil)
  82. }
  83. // DeleteApplyCap 删除应用能力
  84. func DeleteApplyCap(c *gin.Context) {
  85. var applyCap model.ApplyCapabilities
  86. if err := c.ShouldBindJSON(&applyCap); err != nil {
  87. e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
  88. return
  89. }
  90. validate := validator.New()
  91. if err := validate.Struct(applyCap); err != nil {
  92. e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
  93. return
  94. }
  95. dateApplyCap := ApplyCap.DeleteApplyCAp(applyCap)
  96. if dateApplyCap != e.SUCCESS {
  97. e.ResponseWithMsg(c, dateApplyCap, dateApplyCap.GetMsg())
  98. return
  99. }
  100. e.ResponseSuccess(c, nil)
  101. }
  102. // GetCapDetailByCapID 根据capID获取应用能力详情
  103. func GetCapDetailByCapID(c *gin.Context) {
  104. capid := c.Query("capid")
  105. validate := validator.New()
  106. err := validate.Var(capid, "required")
  107. if err != nil {
  108. e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
  109. return
  110. }
  111. id, rescode := Capabilities.GetCapabilitiesById(capid)
  112. if rescode != e.SUCCESS {
  113. e.ResponseWithMsg(c, rescode, rescode.GetMsg())
  114. return
  115. }
  116. e.ResponseSuccess(c, id)
  117. }