123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/models/system"
- "eta_gn/eta_api/utils"
- "strings"
- "time"
- )
- // 部门组
- type SysTeamController struct {
- BaseAuthController
- }
- // @Title 新增分组
- // @Description 新增分组接口
- // @Param request body system.SysTeamAddReq true "type json string"
- // @Success 200 新增成功
- // @router /team/add [post]
- func (this *SysTeamController) Add() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req system.SysTeamAddReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.GroupId <= 0 {
- br.Msg = "请选择部门"
- br.ErrMsg = "大组ID不可为空"
- return
- }
- if req.TeamName == "" {
- br.Msg = "分组名称不能为空"
- return
- }
- teamNameArr := strings.Split(req.TeamName, ",")
- for _, v := range teamNameArr {
- count, err := system.GetSysTeamCount(req.GroupId, v)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if count <= 0 {
- item := new(system.SysGroup)
- item.GroupName = v
- item.DepartmentId = req.DepartmentId
- item.ParentId = req.GroupId
- item.CreateTime = time.Now()
- _, e := system.AddSysGroup(item)
- if e != nil {
- br.Msg = "新增失败"
- br.ErrMsg = "新增失败,Err:" + e.Error()
- return
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
- // @Title 修改分组
- // @Description 修改分组接口
- // @Param request body system.SysTeamEditReq true "type json string"
- // @Success 200 修改成功
- // @router /team/edit [post]
- func (this *SysTeamController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req system.SysTeamEditReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.TeamId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,GroupId 小于等于0 "
- return
- }
- if req.TeamName == "" {
- br.Msg = "分组名称不能为空"
- return
- }
- item, err := system.GetSysTeamByName(req.TeamName)
- if err != nil && !utils.IsErrNoRow(err) {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if item != nil && item.GroupId > 0 {
- if item.GroupId != req.TeamId {
- br.Msg = "名称已存在,请重新输入"
- return
- }
- }
- err = system.ModifySysTeam(req.TeamName, req.TeamId)
- if err != nil {
- br.Msg = "修改失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "修改成功"
- }
- // @Title 删除分组
- // @Description 删除分组接口
- // @Param request body system.SysTeamDeleteReq true "type json string"
- // @Success 200 删除成功
- // @router /team/delete [post]
- func (this *SysTeamController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req system.SysTeamDeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.TeamId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,GroupId 小于等于0 "
- return
- }
- err = system.DeleteSysGroup(req.TeamId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- err = system.ClearSysUserTeam(req.TeamId)
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,情况分组失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- }
|