ppt_v2_history.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/utils"
  6. "fmt"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. "strings"
  9. "time"
  10. )
  11. // PptV2HistoryController PPT
  12. type PptV2HistoryController struct {
  13. BaseAuthController
  14. }
  15. // List
  16. // @Title 获取PPT列表接口
  17. // @Description 获取PPT列表
  18. // @Param PptId query int true "PPTID"
  19. // @Param PageSize query int true "每页数据条数"
  20. // @Param CurrentIndex query int true "当前页页码,从1开始"
  21. // @Param IsShowMe query bool true "是否只看我的,true、false"
  22. // @Success 200 {object} models.ReportListResp
  23. // @router /list [get]
  24. func (this *PptV2HistoryController) List() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. pageSize, _ := this.GetInt("PageSize")
  31. currentIndex, _ := this.GetInt("CurrentIndex")
  32. pptId, _ := this.GetInt("PptId")
  33. isShowMe, _ := this.GetBool("IsShowMe")
  34. if pptId <= 0 {
  35. br.Msg = "请选择PPT"
  36. br.ErrMsg = "请选择PPT"
  37. return
  38. }
  39. var startSize int
  40. if pageSize <= 0 {
  41. pageSize = utils.PageSize20
  42. }
  43. if currentIndex <= 0 {
  44. currentIndex = 1
  45. }
  46. startSize = utils.StartIndex(currentIndex, pageSize)
  47. var condition string
  48. var pars []interface{}
  49. condition += ` AND ppt_id = ? `
  50. pars = append(pars, pptId)
  51. if isShowMe {
  52. condition += ` AND admin_id = ? `
  53. pars = append(pars, this.SysUser.AdminId)
  54. }
  55. var err error
  56. var total int
  57. var list []*models.PptV2HistoryListItem
  58. historyObj := new(models.PptV2History)
  59. total, err = historyObj.GetPageListCount(condition, pars)
  60. if err != nil {
  61. br.Msg = "获取失败"
  62. br.ErrMsg = "获取失败,Err:" + err.Error()
  63. return
  64. }
  65. listTmp, err := historyObj.GetNoContentPageList(condition, pars, startSize, pageSize)
  66. if err != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取失败,Err:" + err.Error()
  69. return
  70. }
  71. for _, item := range listTmp {
  72. tmp := &models.PptV2HistoryListItem{
  73. Id: item.Id,
  74. PptId: item.PptId,
  75. TemplateType: item.TemplateType,
  76. BackgroundImg: item.BackgroundImg,
  77. Title: item.Title,
  78. ReportType: item.ReportType,
  79. PptDate: item.PptDate,
  80. AdminId: item.AdminId,
  81. AdminRealName: item.AdminRealName,
  82. CreateTime: item.CreateTime.Format(utils.FormatDateTime),
  83. }
  84. list = append(list, tmp)
  85. }
  86. page := paging.GetPaging(currentIndex, pageSize, total)
  87. resp := new(models.PptV2HistoryListResp)
  88. resp.Paging = page
  89. resp.List = list
  90. br.Ret = 200
  91. br.Success = true
  92. br.Msg = "获取成功"
  93. br.Data = resp
  94. }
  95. // Delete
  96. // @Title 删除版本
  97. // @Description 删除版本
  98. // @Param Id query int true "版本ID"
  99. // @Success 200 {object} models.ReportListResp
  100. // @router /del [post]
  101. func (this *PptV2HistoryController) Delete() {
  102. br := new(models.BaseResponse).Init()
  103. defer func() {
  104. this.Data["json"] = br
  105. this.ServeJSON()
  106. }()
  107. var req models.DeleteReportHistoryReq
  108. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  109. if err != nil {
  110. br.Msg = "参数解析异常!"
  111. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  112. return
  113. }
  114. if req.Id <= 0 {
  115. br.Msg = "请选择PPT版本"
  116. return
  117. }
  118. historyObj := new(models.PptV2History)
  119. item, err := historyObj.GetById(req.Id)
  120. if err != nil {
  121. br.Msg = "该版本已删除"
  122. return
  123. }
  124. err = item.Delete()
  125. if err != nil {
  126. br.Msg = "删除失败"
  127. br.ErrMsg = "删除失败,Err:" + err.Error()
  128. return
  129. }
  130. br.Ret = 200
  131. br.Success = true
  132. br.Msg = "操作成功"
  133. }
  134. // Detail
  135. // @Title 获取PPT历史版本详情接口
  136. // @Description 获取PPT详情
  137. // @Param request body models.ReportDetailReq true "type json string"
  138. // @Success 200 {object} models.Report
  139. // @router /detail [get]
  140. func (this *PptV2HistoryController) Detail() {
  141. br := new(models.BaseResponse).Init()
  142. defer func() {
  143. this.Data["json"] = br
  144. this.ServeJSON()
  145. }()
  146. id, _ := this.GetInt("Id")
  147. if id <= 0 {
  148. br.Msg = "请选择PPT版本"
  149. return
  150. }
  151. historyObj := new(models.PptV2History)
  152. history, err := historyObj.GetById(id)
  153. if err != nil {
  154. br.Msg = "该版本已删除"
  155. return
  156. }
  157. pptId := history.PptId
  158. pptInfo, err := models.GetPptV2ById(pptId)
  159. if err != nil {
  160. br.Msg = "信息获取失败"
  161. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  162. return
  163. }
  164. pptInfo.TemplateType = history.TemplateType
  165. pptInfo.BackgroundImg = history.BackgroundImg
  166. pptInfo.Title = history.Title
  167. pptInfo.ReportType = history.ReportType
  168. pptInfo.PptDate = history.PptDate
  169. pptInfo.Content = history.Content
  170. pptInfo.CoverContent = history.CoverContent
  171. pptInfo.TitleSetting = history.TitleSetting
  172. pptInfo.AdminId = history.AdminId
  173. pptInfo.AdminRealName = history.AdminRealName
  174. pptInfo.ModifyTime = history.CreateTime
  175. resp := new(models.PPTDetailResp)
  176. resp.PptV2 = pptInfo
  177. br.Ret = 200
  178. br.Success = true
  179. br.Msg = "获取成功"
  180. br.Data = resp
  181. }
  182. // Revert
  183. // @Title 恢复PPT内容
  184. // @Description 恢复PPT内容
  185. // @Param Id query int true "版本ID"
  186. // @Success 200 {object} models.ReportListResp
  187. // @router /revert [post]
  188. func (this *PptV2HistoryController) Revert() {
  189. br := new(models.BaseResponse).Init()
  190. defer func() {
  191. this.Data["json"] = br
  192. this.ServeJSON()
  193. }()
  194. var req models.DeleteReportHistoryReq
  195. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  196. if err != nil {
  197. br.Msg = "参数解析异常!"
  198. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  199. return
  200. }
  201. if req.Id <= 0 {
  202. br.Msg = "请选择PPT版本"
  203. return
  204. }
  205. historyObj := new(models.PptV2History)
  206. history, err := historyObj.GetById(req.Id)
  207. if err != nil {
  208. br.Msg = "该版本已删除"
  209. return
  210. }
  211. // 获取PPT详情
  212. pptInfo, err := models.GetPptV2ById(history.PptId)
  213. if err != nil {
  214. br.Msg = "信息获取失败"
  215. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  216. return
  217. }
  218. // 协作人权限
  219. if pptInfo.AdminId != this.SysUser.AdminId {
  220. if pptInfo.CollaborateType != utils.ReportWriteTypeGroup {
  221. br.Msg = "非协作人无权操作"
  222. return
  223. }
  224. if pptInfo.CollaborateUsers == "" {
  225. br.Msg = "非协作人无权操作"
  226. return
  227. }
  228. partnerArr := strings.Split(pptInfo.CollaborateUsers, ",")
  229. if !utils.InArrayByStr(partnerArr, fmt.Sprint(this.SysUser.AdminId)) {
  230. br.Msg = "非协作人无权操作"
  231. return
  232. }
  233. }
  234. // 修改
  235. pptInfo.TemplateType = history.TemplateType
  236. pptInfo.BackgroundImg = history.BackgroundImg
  237. pptInfo.Title = history.Title
  238. pptInfo.ReportType = history.ReportType
  239. pptInfo.PptDate = history.PptDate
  240. pptInfo.Content = history.Content
  241. pptInfo.CoverContent = history.CoverContent
  242. pptInfo.ModifyTime = time.Now()
  243. pptInfo.TitleSetting = history.TitleSetting
  244. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent", "TitleSetting"})
  245. if err != nil {
  246. br.Msg = "编辑失败"
  247. br.ErrMsg = "编辑失败,Err:" + err.Error()
  248. return
  249. }
  250. // 记录修改日志
  251. {
  252. logInfo := &models.PptV2SaveLog{
  253. PptId: pptInfo.PptId,
  254. TemplateType: pptInfo.TemplateType,
  255. BackgroundImg: pptInfo.BackgroundImg,
  256. Title: pptInfo.Title,
  257. ReportType: pptInfo.ReportType,
  258. PptDate: pptInfo.PptDate,
  259. Content: pptInfo.Content,
  260. CoverContent: pptInfo.CoverContent,
  261. AdminId: this.SysUser.AdminId,
  262. AdminRealName: this.SysUser.RealName,
  263. CreateTime: time.Now(),
  264. }
  265. _, err = models.AddPptV2SaveLog(logInfo)
  266. }
  267. br.Ret = 200
  268. br.Success = true
  269. br.Msg = "操作成功"
  270. }