123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- package controllers
- import (
- "encoding/json"
- "eta_gn/eta_api/models"
- "eta_gn/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strings"
- "time"
- )
- // PptV2HistoryController PPT
- type PptV2HistoryController struct {
- BaseAuthController
- }
- // List
- // @Title 获取PPT列表接口
- // @Description 获取PPT列表
- // @Param PptId query int true "PPTID"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} models.ReportListResp
- // @router /list [get]
- func (this *PptV2HistoryController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- pptId, _ := this.GetInt("PptId")
- isShowMe, _ := this.GetBool("IsShowMe")
- if pptId <= 0 {
- br.Msg = "请选择PPT"
- br.ErrMsg = "请选择PPT"
- return
- }
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- condition += ` AND ppt_id = ? `
- pars = append(pars, pptId)
- if isShowMe {
- condition += ` AND admin_id = ? `
- pars = append(pars, this.SysUser.AdminId)
- }
- var err error
- var total int
- var list []*models.PptV2HistoryListItem
- historyObj := new(models.PptV2History)
- total, err = historyObj.GetPageListCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- listTmp, err := historyObj.GetNoContentPageList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- for _, item := range listTmp {
- tmp := &models.PptV2HistoryListItem{
- Id: item.Id,
- PptId: item.PptId,
- TemplateType: item.TemplateType,
- BackgroundImg: item.BackgroundImg,
- Title: item.Title,
- ReportType: item.ReportType,
- PptDate: item.PptDate,
- AdminId: item.AdminId,
- AdminRealName: item.AdminRealName,
- CreateTime: item.CreateTime.Format(utils.FormatDateTime),
- }
- list = append(list, tmp)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.PptV2HistoryListResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Delete
- // @Title 删除版本
- // @Description 删除版本
- // @Param Id query int true "版本ID"
- // @Success 200 {object} models.ReportListResp
- // @router /del [post]
- func (this *PptV2HistoryController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DeleteReportHistoryReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Id <= 0 {
- br.Msg = "请选择PPT版本"
- return
- }
- historyObj := new(models.PptV2History)
- item, err := historyObj.GetById(req.Id)
- if err != nil {
- br.Msg = "该版本已删除"
- return
- }
- err = item.Delete()
- if err != nil {
- br.Msg = "删除失败"
- br.ErrMsg = "删除失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // Detail
- // @Title 获取PPT历史版本详情接口
- // @Description 获取PPT详情
- // @Param request body models.ReportDetailReq true "type json string"
- // @Success 200 {object} models.Report
- // @router /detail [get]
- func (this *PptV2HistoryController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- id, _ := this.GetInt("Id")
- if id <= 0 {
- br.Msg = "请选择PPT版本"
- return
- }
- historyObj := new(models.PptV2History)
- history, err := historyObj.GetById(id)
- if err != nil {
- br.Msg = "该版本已删除"
- return
- }
- pptId := history.PptId
- pptInfo, err := models.GetPptV2ById(pptId)
- if err != nil {
- br.Msg = "信息获取失败"
- br.ErrMsg = "信息获取失败,Err:" + err.Error()
- return
- }
- pptInfo.TemplateType = history.TemplateType
- pptInfo.BackgroundImg = history.BackgroundImg
- pptInfo.Title = history.Title
- pptInfo.ReportType = history.ReportType
- pptInfo.PptDate = history.PptDate
- pptInfo.Content = history.Content
- pptInfo.CoverContent = history.CoverContent
- pptInfo.TitleSetting = history.TitleSetting
- pptInfo.AdminId = history.AdminId
- pptInfo.AdminRealName = history.AdminRealName
- pptInfo.ModifyTime = history.CreateTime
- resp := new(models.PPTDetailResp)
- resp.PptV2 = pptInfo
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Revert
- // @Title 恢复PPT内容
- // @Description 恢复PPT内容
- // @Param Id query int true "版本ID"
- // @Success 200 {object} models.ReportListResp
- // @router /revert [post]
- func (this *PptV2HistoryController) Revert() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.DeleteReportHistoryReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Id <= 0 {
- br.Msg = "请选择PPT版本"
- return
- }
- historyObj := new(models.PptV2History)
- history, err := historyObj.GetById(req.Id)
- if err != nil {
- br.Msg = "该版本已删除"
- return
- }
- // 获取PPT详情
- pptInfo, err := models.GetPptV2ById(history.PptId)
- if err != nil {
- br.Msg = "信息获取失败"
- br.ErrMsg = "信息获取失败,Err:" + err.Error()
- return
- }
- // 协作人权限
- if pptInfo.AdminId != this.SysUser.AdminId {
- if pptInfo.CollaborateType != utils.ReportWriteTypeGroup {
- br.Msg = "非协作人无权操作"
- return
- }
- if pptInfo.CollaborateUsers == "" {
- br.Msg = "非协作人无权操作"
- return
- }
- partnerArr := strings.Split(pptInfo.CollaborateUsers, ",")
- if !utils.InArrayByStr(partnerArr, fmt.Sprint(this.SysUser.AdminId)) {
- br.Msg = "非协作人无权操作"
- return
- }
- }
- // 修改
- pptInfo.TemplateType = history.TemplateType
- pptInfo.BackgroundImg = history.BackgroundImg
- pptInfo.Title = history.Title
- pptInfo.ReportType = history.ReportType
- pptInfo.PptDate = history.PptDate
- pptInfo.Content = history.Content
- pptInfo.CoverContent = history.CoverContent
- pptInfo.ModifyTime = time.Now()
- pptInfo.TitleSetting = history.TitleSetting
- err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent", "TitleSetting"})
- if err != nil {
- br.Msg = "编辑失败"
- br.ErrMsg = "编辑失败,Err:" + err.Error()
- return
- }
- // 记录修改日志
- {
- logInfo := &models.PptV2SaveLog{
- PptId: pptInfo.PptId,
- TemplateType: pptInfo.TemplateType,
- BackgroundImg: pptInfo.BackgroundImg,
- Title: pptInfo.Title,
- ReportType: pptInfo.ReportType,
- PptDate: pptInfo.PptDate,
- Content: pptInfo.Content,
- CoverContent: pptInfo.CoverContent,
- AdminId: this.SysUser.AdminId,
- AdminRealName: this.SysUser.RealName,
- CreateTime: time.Now(),
- }
- _, err = models.AddPptV2SaveLog(logInfo)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|