department.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package admin
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "server/dao"
  5. "server/global"
  6. "server/model/common/request"
  7. "server/model/common/response"
  8. "strconv"
  9. )
  10. type DepartmentApi struct {
  11. }
  12. func (da *DepartmentApi) QueryAllDep(c *gin.Context) {
  13. deps, err := departmentService.QueryAllDep()
  14. if err != nil {
  15. response.FailWithMessage("查询失败", c)
  16. global.GVA_LOG.Error("QueryAllDep ==" + err.Error())
  17. return
  18. }
  19. response.OkWithData(deps, c)
  20. }
  21. func (da *DepartmentApi) QueryDepByStart(c *gin.Context) {
  22. deps, err := departmentService.QueryDepByStart()
  23. if err != nil {
  24. response.FailWithMessage("查询失败", c)
  25. global.GVA_LOG.Error("QueryDepByStart ==" + err.Error())
  26. return
  27. }
  28. response.OkWithData(deps, c)
  29. }
  30. func (da *DepartmentApi) CreateDep(c *gin.Context) {
  31. department := dao.Department{}
  32. err := c.ShouldBindJSON(&department)
  33. if err != nil {
  34. global.GVA_LOG.Error("CreateDep ==" + err.Error())
  35. response.FailWithMessage("错误", c)
  36. return
  37. }
  38. err = departmentService.CreateDep(department)
  39. if err != nil {
  40. global.GVA_LOG.Error("CreateDep ==" + err.Error())
  41. response.FailWithMessage("错误", c)
  42. return
  43. }
  44. response.OkWithMessage("创建成功", c)
  45. }
  46. func (da *DepartmentApi) UpdateDep(c *gin.Context) {
  47. department := dao.Department{}
  48. err := c.ShouldBindJSON(&department)
  49. if err != nil {
  50. global.GVA_LOG.Error("UpdateDep ==" + err.Error())
  51. response.FailWithMessage("错误", c)
  52. return
  53. }
  54. err = departmentService.UpdateDep(department)
  55. if err != nil {
  56. global.GVA_LOG.Error("UpdateDep ==" + err.Error())
  57. response.FailWithMessage("错误", c)
  58. return
  59. }
  60. response.OkWithMessage("更新成功", c)
  61. }
  62. func (da *DepartmentApi) UpdateDepStatus(c *gin.Context) {
  63. department := dao.Department{}
  64. err := c.ShouldBindJSON(&department)
  65. if err != nil {
  66. global.GVA_LOG.Error("UpdateDepStatus ==" + err.Error())
  67. response.FailWithMessage("错误", c)
  68. return
  69. }
  70. err = departmentService.UpdateDepStatus(department.Id, department.IsStart)
  71. if err != nil {
  72. global.GVA_LOG.Error("UpdateDepStatus ==" + err.Error())
  73. response.FailWithMessage("错误", c)
  74. return
  75. }
  76. response.OkWithMessage("更新成功", c)
  77. }
  78. func (da *DepartmentApi) UpdateUserDep(c *gin.Context) {
  79. ids := request.Ids{}
  80. err := c.ShouldBindJSON(&ids)
  81. if err != nil {
  82. global.GVA_LOG.Error("UpdateUserDep ==" + err.Error())
  83. response.FailWithMessage("错误", c)
  84. return
  85. }
  86. err = departmentService.UpdateUserDep(ids.Ids, ids.Id)
  87. if err != nil {
  88. global.GVA_LOG.Error("UpdateUserDep ==" + err.Error())
  89. response.FailWithMessage("错误", c)
  90. return
  91. }
  92. response.OkWithMessage("更新成功", c)
  93. }
  94. func (da *DepartmentApi) DeleteDep(c *gin.Context) {
  95. id := c.Param("depId")
  96. depId, _ := strconv.Atoi(id)
  97. err := departmentService.DeleteDep(depId)
  98. if err != nil {
  99. global.GVA_LOG.Error("DeleteDep ==" + err.Error())
  100. response.FailWithMessage(err.Error(), c)
  101. return
  102. }
  103. response.OkWithMessage("删除成功", c)
  104. }