package controllers import ( "encoding/json" "eta/eta_api/models" "eta/eta_api/services" "eta/eta_api/services/ppt" "fmt" "strings" ) type PptV2GroupController struct { BaseAuthController } // GroupList // @Title 获取可见的目录列表 // @Description 获取可见的目录列表接口 // @Success 200 {object} models.RespGroupList // @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.GetGroupsByAdminId(IsNewPpt, this.SysUser.AdminId) 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 } // AddGroup // @Title 新增ppt目录 // @Description 新增ppt目录接口 // @Param request body models.ReqAddPptGroup true "type json string" // @Success 200 {object} models.RespAddPptGroup // @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 } // DeleteGroup // @Title 删除ppt目录 // @Description 删除ppt目录接口 // @Param request body models.ReqPptGroup true "type json string" // @Success 200 Ret=200 删除成功 // @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 = "删除成功" } // ShareGroup // @Title 共享/取消共享目录 // @Description 共享/取消共享目录接口 // @Param request body models.ReqPptGroup true "type json string" // @Success 200 {object} models.RespPptGroupShare // @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 } // CopyGroup // @Title 复制目录 // @Description 复制目录接口 // @Param request body models.ReqPptGroup true "type json string" // @Success 200 Ret=200 复制成功 // @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 } // RenameGroup // @Title 目录重命名 // @Description 目录重命名接口 // @Param request body models.ReqRenamePptGroup true "type json string" // @Success 200 Ret=200 重命名成功 // @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 } // SharePpt // @Title 共享/取消共享单个ppt // @Description 共享/取消共享单个ppt接口 // @Param request body models.ReqPptShare true "type json string" // @Success 200 {object} models.RespPptShare // @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 } //data, err := ppt.ShareSingleGroupPpt(req.GroupPptId, this.SysUser.AdminId, this.SysUser.RealName) 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 } // GroupPptList // @Title 获取默认的ppt列表或者单个目录内的ppt列表 // @Description 获取可见的目录列表接口 // @Param GroupId query int true "目录ID" // @Success 200 {object} models.RespGroupPptList // @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 } // MoveGroupPpt // @Title 移动目录里的ppt // @Description 移动目录里的ppt接口 // @Param request body models.ReqMoveGroupPpt true "type json string" // @Success 200 Ret=200 移动成功 // @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 } // 由于是倒序, 所以需要颠倒NextGroupPptId和PrevGroupPptId的位置 err = ppt.MoveGroupPpt(req.GroupId, req.GroupPptId, req.NextGroupPptId, req.PrevGroupPptId, this.SysUser.AdminId) if err != nil { br.Msg = err.Error() return } // 增加人为移动的标识 mappingInfo := &models.PptV2GroupMapping{} mappingInfo.GroupPptId = req.GroupPptId mappingInfo.IsMoved = true err = mappingInfo.Update([]string{"is_moved"}) if err != nil { br.Msg = err.Error() return } br.Ret = 200 br.Success = true br.Msg = "移动成功" } // MoveGroup // @Title 移动目录 // @Description 移动目录接口 // @Param request body models.ReqMoveGroup true "type json string" // @Success 200 Ret=200 移动成功 // @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 = "移动成功" } // CopyPpt // @Title 复制单个ppt // @Description 复制目录接口 // @Param request body models.ReqCopyPpt true "type json string" // @Success 200 Ret=200 复制成功 // @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 } // GroupNameList // @Title 查询目录名称列表 // @Description 查询目录名称列表接口 // @Success 200 {object} models.RespPptGroupNameList // @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 } // SearchGroupPptList // @Title 按ppt关键词搜索列表 // @Description 按ppt关键词搜索列表接口 // @Param KeyWord query int true "搜索关键词" // @Success 200 {object} models.RespSearchGroupPptList // @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 } // SharePptList // @Title 获取用户开放的公共Ppt // @Description 获取用户开放的公共Ppt接口 // @Param AdminId query int true "创建人ID" // @Param Keyword query string true "关键字" // @Param IsPrivate query bool false "是否为私有" // @Success 200 {object} models.RespGroupPptList // @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 } // GrantPptList // @Title 获取用户共享的公共Ppt(分配权限的Ppt) // @Description 获取用户共享的公共Ppt(分配权限的Ppt)接口 // @Param GroupId query int true "分组ID,唉,其实不知道用啥名,就这么用吧" // @Param Keyword query string true "关键字" // @Success 200 {object} models.RespGroupPptList // @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 } // ListSearch // @Title 我的/公开PPT搜索 // @Description 我的/公开PPT搜索 // @Param Keyword query string true "关键字" // @Success 200 {object} models.RespGroupPptList // @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 }