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
- }
- 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
- }
- 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
- }
- 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 = "删除成功"
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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.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 = "移动成功"
- }
- 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 = "移动成功"
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
|