package controllers import ( "encoding/json" "eta_gn/eta_api/models" "eta_gn/eta_api/services" "eta_gn/eta_api/services/ppt" "fmt" "strings" ) type PptV2GroupController struct { BaseAuthController } // @router /groups [get] func (this *PptV2GroupController) GroupList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() IsNewPpt, _ := this.GetInt("IsNewPpt") data, err := ppt.GetGroupsByAdminIdV2(IsNewPpt, this.SysUser.AdminId, this.Lang) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "查询成功" br.Data = data return } // @router /group/add [post] func (this *PptV2GroupController) AddGroup() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.ReqAddPptGroup err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.GroupName == "" { br.Msg = "请输入目录名称" return } newId, err := ppt.AddGroup(req.GroupName, this.SysUser.AdminId, 0, 0) if err != nil { br.Msg = err.Error() return } resp := models.RespAddPptGroup{ GroupId: newId, } br.Ret = 200 br.Success = true br.Msg = "新增成功" br.Data = resp } // @router /group/delete [post] func (this *PptV2GroupController) DeleteGroup() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.ReqPptGroup 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 = "请输入目录ID" return } err = ppt.DelGroup(req.GroupId, this.SysUser.AdminId) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "删除成功" } // @router /group/share [post] func (this *PptV2GroupController) ShareGroup() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.ReqPptGroup 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 = "请输入目录ID" return } data, err := ppt.ShareGroup(req.GroupId, this.SysUser.AdminId) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "操作成功" br.Data = data return } // @router /group/copy [post] func (this *PptV2GroupController) CopyGroup() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.ReqPptGroup 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 = "请输入目录ID" return } err = ppt.CopyGroup(req.GroupId, this.SysUser.AdminId, this.SysUser.RealName) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "复制成功" return } // @router /group/rename [post] func (this *PptV2GroupController) RenameGroup() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.ReqRenamePptGroup 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 = "请输入目录ID" return } if req.GroupName == "" { br.Msg = "请输入目录名称" return } err = ppt.RenameGroupName(req.GroupId, req.GroupName, this.SysUser.AdminId) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "重命名成功" return } // @router /share [post] func (this *PptV2GroupController) SharePpt() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.ReqPptShareV2 err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.PptId <= 0 { br.Msg = "请输入目录里的ppt序号" return } pptInfo, err := ppt.ShareSingleGroupPptV2(req.PptId, this.SysUser.AdminId) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "操作成功" br.Data = models.RespPptShareV2{ PptId: pptInfo.PptId, IsShare: pptInfo.IsShare, } return } // @router /group/ppt/list [get] func (this *PptV2GroupController) GroupPptList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } groupId, _ := this.GetInt("GroupId") data, err := ppt.GetGroupPptList(int64(groupId), this.SysUser.AdminId) if err != nil { br.Msg = err.Error() br.IsSendEmail = false return } for _, v := range data.List { editor, e := services.UpdatePptEditing(int(v.PptId), 0, sysUser.AdminId, sysUser.RealName, false) if e != nil { br.Msg = "获取失败" br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error()) return } v.Editor = editor } br.Ret = 200 br.Success = true br.Msg = "查询成功" br.Data = data return } // @router /move [post] func (this *PptV2GroupController) MoveGroupPpt() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.ReqMoveGroupPpt 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 = "请输入目录ID" return } err = ppt.MoveGroupPpt(req.GroupId, req.GroupPptId, req.PrevGroupPptId, req.NextGroupPptId, this.SysUser.AdminId) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "移动成功" } // @router /group/move [post] func (this *PptV2GroupController) MoveGroup() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.ReqMoveGroup 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 = "请输入目录ID" return } err = ppt.MoveGroup(req.GroupId, req.PrevGroupId, req.NextGroupId, this.SysUser.AdminId) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "移动成功" } // @router /copy [post] func (this *PptV2GroupController) CopyPpt() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() var req models.ReqCopyPpt 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 = "请输入目录ID" return } if req.PptId <= 0 { br.Msg = "请输入ppt ID" return } data, err := ppt.CopyPpt(req.PptId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "复制成功" br.Data = data return } // @router /group/name [get] func (this *PptV2GroupController) GroupNameList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() list, err := models.GetPptGroupIdAndGroupNameByAdminId(this.SysUser.AdminId) if err != nil { br.Msg = "查询目录名称出错" + err.Error() return } data := &models.RespPptGroupNameList{ List: list, } br.Ret = 200 br.Success = true br.Msg = "查询成功" br.Data = data return } // @router /group/ppt/search [get] func (this *PptV2GroupController) SearchGroupPptList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() keyWord := this.GetString("KeyWord") data, err := ppt.SearchGroupPpt(keyWord) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "查询成功" br.Data = data return } // @router /share/ppt/list [get] func (this *PptV2GroupController) SharePptList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } adminId, _ := this.GetInt("AdminId") keyword := this.GetString("Keyword") isPrivate, _ := this.GetBool("IsPrivate", false) if isPrivate && adminId <= 0 { br.Msg = "参数有误, 私有PPT创建人ID不可为空" return } data, err := ppt.GetSharePptList(adminId, keyword, isPrivate) if err != nil { br.Msg = err.Error() return } for _, v := range data.List { editor, e := services.UpdatePptEditing(int(v.PptId), 0, sysUser.AdminId, sysUser.RealName, false) if e != nil { br.Msg = "获取失败" br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error()) return } v.Editor = editor } br.Ret = 200 br.Success = true br.Msg = "查询成功" br.Data = data return } // @router /grant/ppt/list [get] func (this *PptV2GroupController) GrantPptList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } groupId, _ := this.GetInt("GroupId") keyword := this.GetString("Keyword") var sourceType string switch groupId { case 1: sourceType = "my" case 2: sourceType = "other" default: br.Msg = "错误的来源" br.IsSendEmail = false return } data, err := ppt.GetGrantPptList(this.SysUser.AdminId, keyword, sourceType) if err != nil { br.Msg = err.Error() return } for _, v := range data.List { editor, e := services.UpdatePptEditing(int(v.PptId), 0, sysUser.AdminId, sysUser.RealName, false) if e != nil { br.Msg = "获取失败" br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error()) return } v.Editor = editor } br.Ret = 200 br.Success = true br.Msg = "查询成功" br.Data = data return } // @router /ppt/search [get] func (this *PptV2GroupController) ListSearch() { br := new(models.BaseResponse).Init() defer func() { if br.ErrMsg == "" { br.IsSendEmail = false } this.Data["json"] = br this.ServeJSON() }() sysUser := this.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } keyword := this.GetString("Keyword") keyword = strings.TrimSpace(keyword) data, err := ppt.SearchPptList(sysUser.AdminId, keyword) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "查询成功" br.Data = data }