123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614 |
- 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
- }
|