123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- package system
- import (
- "encoding/json"
- "eta/eta_forum_hub/controllers"
- "eta/eta_forum_hub/models"
- "eta/eta_forum_hub/models/system"
- "eta/eta_forum_hub/services"
- )
- type SysDepartmentController struct {
- controllers.BaseAuthController
- }
- // Save
- // @Title 新增或者编辑系统用户
- // @Description 新增系统用户接口
- // @Param request body system.SysuserAddReq true "type json string"
- // @Success 200 新增成功
- // @router /department/save [post]
- func (this *SysDepartmentController) Save() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req system.SysDepartmentAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.DepartmentId == 0 {
- br.Msg = "请输入部门序号"
- br.IsSendEmail = false
- return
- }
- err, isSendEmail := services.AddOrUpdateDepartment(&req)
- if err != nil {
- br.Msg = "新增或者更新用户失败"
- br.ErrMsg = "新增或者更新用户失败, Err:" + err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
- // Delete
- // @Title 删除系统用户
- // @Description 删除系统用户接口
- // @Param request body system.SysDepartmentDeleteReq true "type json string"
- // @Success 200 删除成功
- // @router /department/delete [post]
- func (this *SysDepartmentController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req system.SysDepartmentDeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.DepartmentId == 0 {
- br.Msg = "请选择部门"
- return
- }
- err = system.DeleteSysDepartment(req.DepartmentId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
- // Sync
- // @Title 新增或者编辑系统用户
- // @Description 新增系统用户接口
- // @Param request body system.SysuserAddReq true "type json string"
- // @Success 200 新增成功
- // @router /department/sync [post]
- func (this *SysDepartmentController) Sync() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req system.SysDepartmentSyncReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if len(req.List) == 0 {
- br.Msg = "请输入组合"
- br.IsSendEmail = false
- return
- }
- err, isSendEmail := services.SyncSysDepartment(&req)
- if err != nil {
- br.Msg = "新增或者更新部门失败"
- br.ErrMsg = "新增或者更新部门失败, Err:" + err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
|