sys_department.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package system
  2. import (
  3. "encoding/json"
  4. "eta/eta_forum_hub/controllers"
  5. "eta/eta_forum_hub/models"
  6. "eta/eta_forum_hub/models/system"
  7. "eta/eta_forum_hub/services"
  8. )
  9. type SysDepartmentController struct {
  10. controllers.BaseAuthController
  11. }
  12. // Save
  13. // @Title 新增或者编辑系统用户
  14. // @Description 新增系统用户接口
  15. // @Param request body system.SysuserAddReq true "type json string"
  16. // @Success 200 新增成功
  17. // @router /department/save [post]
  18. func (this *SysDepartmentController) Save() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. var req system.SysDepartmentAddReq
  25. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  26. if err != nil {
  27. br.Msg = "参数解析异常!"
  28. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  29. return
  30. }
  31. if req.DepartmentId == 0 {
  32. br.Msg = "请输入部门序号"
  33. br.IsSendEmail = false
  34. return
  35. }
  36. err, isSendEmail := services.AddOrUpdateDepartment(&req)
  37. if err != nil {
  38. br.Msg = "新增或者更新用户失败"
  39. br.ErrMsg = "新增或者更新用户失败, Err:" + err.Error()
  40. br.IsSendEmail = isSendEmail
  41. return
  42. }
  43. br.Ret = 200
  44. br.Success = true
  45. br.Msg = "新增成功"
  46. }
  47. // Delete
  48. // @Title 删除系统用户
  49. // @Description 删除系统用户接口
  50. // @Param request body system.SysDepartmentDeleteReq true "type json string"
  51. // @Success 200 删除成功
  52. // @router /department/delete [post]
  53. func (this *SysDepartmentController) Delete() {
  54. br := new(models.BaseResponse).Init()
  55. defer func() {
  56. this.Data["json"] = br
  57. this.ServeJSON()
  58. }()
  59. var req system.SysDepartmentDeleteReq
  60. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  61. if err != nil {
  62. br.Msg = "参数解析异常!"
  63. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  64. return
  65. }
  66. if req.DepartmentId == 0 {
  67. br.Msg = "请选择部门"
  68. return
  69. }
  70. err = system.DeleteSysDepartment(req.DepartmentId)
  71. if err != nil {
  72. br.Msg = "删除失败"
  73. br.ErrMsg = "删除失败,Err:" + err.Error()
  74. return
  75. }
  76. br.Ret = 200
  77. br.Success = true
  78. br.Msg = "删除成功"
  79. }
  80. // Sync
  81. // @Title 新增或者编辑系统用户
  82. // @Description 新增系统用户接口
  83. // @Param request body system.SysuserAddReq true "type json string"
  84. // @Success 200 新增成功
  85. // @router /department/sync [post]
  86. func (this *SysDepartmentController) Sync() {
  87. br := new(models.BaseResponse).Init()
  88. defer func() {
  89. this.Data["json"] = br
  90. this.ServeJSON()
  91. }()
  92. var req system.SysDepartmentSyncReq
  93. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  94. if err != nil {
  95. br.Msg = "参数解析异常!"
  96. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  97. return
  98. }
  99. if len(req.List) == 0 {
  100. br.Msg = "请输入组合"
  101. br.IsSendEmail = false
  102. return
  103. }
  104. err, isSendEmail := services.SyncSysDepartment(&req)
  105. if err != nil {
  106. br.Msg = "新增或者更新部门失败"
  107. br.ErrMsg = "新增或者更新部门失败, Err:" + err.Error()
  108. br.IsSendEmail = isSendEmail
  109. return
  110. }
  111. br.Ret = 200
  112. br.Success = true
  113. br.Msg = "新增成功"
  114. }