ppt_v2.go 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/company"
  6. "eta/eta_api/models/ppt_english"
  7. "eta/eta_api/services"
  8. "eta/eta_api/services/ppt"
  9. "eta/eta_api/utils"
  10. "fmt"
  11. _ "image/gif"
  12. _ "image/jpeg"
  13. _ "image/png"
  14. "os"
  15. "path"
  16. "strconv"
  17. "strings"
  18. "time"
  19. "github.com/rdlucklib/rdluck_tools/paging"
  20. )
  21. // PptV2Controller 新版ppt模块
  22. type PptV2Controller struct {
  23. BaseAuthController
  24. }
  25. // PptV2CommonController 新版ppt公共模块
  26. type PptV2CommonController struct {
  27. BaseCommonController
  28. }
  29. // ListPpt
  30. // @Title 获取ppt列表
  31. // @Description 获取ppt列表接口
  32. // @Param PageSize query int true "每页数据条数"
  33. // @Param CurrentIndex query int true "当前页页码,从1开始"
  34. // @Param KeyWord query string true "搜索关键词"
  35. // @Success 200 {object} models.PptV2ListResp
  36. // @router /list [get]
  37. func (this *PptV2Controller) ListPpt() {
  38. br := new(models.BaseResponse).Init()
  39. defer func() {
  40. this.Data["json"] = br
  41. this.ServeJSON()
  42. }()
  43. sysUser := this.SysUser
  44. if sysUser == nil {
  45. br.Msg = "请登录"
  46. br.ErrMsg = "请登录,SysUser Is Empty"
  47. return
  48. }
  49. pageSize, _ := this.GetInt("PageSize")
  50. currentIndex, _ := this.GetInt("CurrentIndex")
  51. keyWord := this.GetString("KeyWord")
  52. var startSize int
  53. if pageSize <= 0 {
  54. pageSize = utils.PageSize20
  55. }
  56. if currentIndex <= 0 {
  57. currentIndex = 1
  58. }
  59. startSize = utils.StartIndex(currentIndex, pageSize)
  60. var condition string
  61. var pars []interface{}
  62. if keyWord != "" {
  63. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  64. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  65. }
  66. total, err := models.GetPptV2ListCount(condition, pars)
  67. if err != nil {
  68. br.Msg = "获取失败"
  69. br.ErrMsg = "获取失败,Err:" + err.Error()
  70. return
  71. }
  72. list, err := models.GetPptV2List(condition, pars, startSize, pageSize)
  73. if err != nil {
  74. br.Msg = "获取失败"
  75. br.ErrMsg = "获取失败,Err:" + err.Error()
  76. return
  77. }
  78. lenList := len(list)
  79. for i := 0; i < lenList; i++ {
  80. adminId := list[i].AdminId
  81. if adminId == sysUser.AdminId || sysUser.Role == "admin" {
  82. list[i].IsAuth = true
  83. } else {
  84. list[i].IsAuth = false
  85. }
  86. }
  87. page := paging.GetPaging(currentIndex, pageSize, total)
  88. resp := new(models.PptV2ListResp)
  89. resp.Paging = page
  90. resp.List = list
  91. br.Ret = 200
  92. br.Success = true
  93. br.Msg = "获取成功"
  94. br.Data = resp
  95. }
  96. // AddPpt
  97. // @Title 新增ppt
  98. // @Description 新增ppt接口
  99. // @Param request body models.AddPptV2Req true "type json string"
  100. // @Success 200 Ret=200 新增成功
  101. // @router /add [post]
  102. func (this *PptV2Controller) AddPpt() {
  103. br := new(models.BaseResponse).Init()
  104. defer func() {
  105. this.Data["json"] = br
  106. this.ServeJSON()
  107. }()
  108. var req models.AddPptV2Req
  109. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  110. if err != nil {
  111. br.Msg = "参数解析异常!"
  112. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  113. return
  114. }
  115. if req.FirstPage.Title == "" {
  116. br.Msg = "标题不能为空"
  117. return
  118. }
  119. var newId int64
  120. var msg string
  121. if req.PptId <= 0 {
  122. if req.GroupId == 0 {
  123. br.Msg = "请输入目录ID"
  124. return
  125. }
  126. item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  127. if err != nil && err.Error() != utils.ErrNoRow() {
  128. br.Msg = "获取数据异常!"
  129. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  130. return
  131. }
  132. if item != nil && item.PptId != int(req.PptId) {
  133. br.Msg = "标题已存在,不可重复添加"
  134. br.IsSendEmail = false
  135. return
  136. }
  137. pptInfo := &models.PptV2{
  138. //PptId: 0,
  139. TemplateType: req.FirstPage.TemplateType,
  140. BackgroundImg: req.FirstPage.ImgUrl,
  141. Title: req.FirstPage.Title,
  142. ReportType: req.FirstPage.ReportType,
  143. PptDate: req.FirstPage.PptDate,
  144. Content: req.Content,
  145. CoverContent: req.CoverContent,
  146. CreateTime: time.Now(),
  147. ModifyTime: time.Now(),
  148. AdminId: this.SysUser.AdminId,
  149. AdminRealName: this.SysUser.RealName,
  150. PptVersion: 2,
  151. TitleSetting: req.TitleSetting,
  152. }
  153. newId, err = models.AddPptV2(pptInfo)
  154. if err != nil {
  155. br.Msg = "新增失败"
  156. br.ErrMsg = "新增失败,Err:" + err.Error()
  157. return
  158. }
  159. //新增ppt和目录映射
  160. _, err = ppt.AddGroupPptMapping(newId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  161. if err != nil {
  162. br.Msg = err.Error()
  163. return
  164. }
  165. msg = "新增成功"
  166. } else {
  167. newId = req.PptId
  168. pptInfo, err := models.GetPptV2ById(int(req.PptId))
  169. if err != nil {
  170. br.Msg = "信息获取失败"
  171. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  172. return
  173. }
  174. pptInfo.TemplateType = req.FirstPage.TemplateType
  175. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  176. pptInfo.Title = req.FirstPage.Title
  177. pptInfo.ReportType = req.FirstPage.ReportType
  178. pptInfo.PptDate = req.FirstPage.PptDate
  179. pptInfo.Content = req.Content
  180. pptInfo.CoverContent = req.CoverContent
  181. pptInfo.ModifyTime = time.Now()
  182. pptInfo.TitleSetting = req.TitleSetting
  183. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent", "TitleSetting"})
  184. msg = "保存成功"
  185. }
  186. resp := models.AddPptResp{
  187. PptId: newId,
  188. }
  189. br.Ret = 200
  190. br.Success = true
  191. br.Msg = msg
  192. br.Data = resp
  193. }
  194. // EditPpt
  195. // @Title 编辑ppt
  196. // @Description 编辑ppt接口
  197. // @Param request body models.AddPptV2Req true "type json string"
  198. // @Success 200 Ret=200 编辑成功
  199. // @router /edit [post]
  200. func (this *PptV2Controller) EditPpt() {
  201. br := new(models.BaseResponse).Init()
  202. defer func() {
  203. this.Data["json"] = br
  204. this.ServeJSON()
  205. }()
  206. var req models.AddPptV2Req
  207. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  208. if err != nil {
  209. br.Msg = "参数解析异常!"
  210. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  211. return
  212. }
  213. if req.FirstPage.Title == "" {
  214. br.Msg = "标题不能为空"
  215. return
  216. }
  217. item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  218. if err != nil && err.Error() != utils.ErrNoRow() {
  219. br.Msg = "获取数据异常!"
  220. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  221. return
  222. }
  223. if item != nil && item.PptId != int(req.PptId) {
  224. br.Msg = "标题已存在,不可重复添加"
  225. br.IsSendEmail = false
  226. return
  227. }
  228. pptInfo, err := models.GetPptV2ById(int(req.PptId))
  229. if err != nil {
  230. br.Msg = "信息获取失败"
  231. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  232. return
  233. }
  234. // 判断权限
  235. if pptInfo.AdminId != this.SysUser.AdminId {
  236. _, err := models.GetPPtGrantConf(pptInfo.PptId, this.SysUser.AdminId)
  237. if err != nil {
  238. if err.Error() == utils.ErrNoRow() {
  239. br.Msg = `该PPT已取消共享,保存失败`
  240. br.ErrMsg = `该PPT已取消共享,保存失败`
  241. br.IsSendEmail = false
  242. } else {
  243. br.Msg = `保存失败`
  244. br.ErrMsg = `保存失败,ERR:` + err.Error()
  245. }
  246. return
  247. }
  248. }
  249. // 修改
  250. pptInfo.TemplateType = req.FirstPage.TemplateType
  251. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  252. pptInfo.Title = req.FirstPage.Title
  253. pptInfo.ReportType = req.FirstPage.ReportType
  254. pptInfo.PptDate = req.FirstPage.PptDate
  255. pptInfo.Content = req.Content
  256. pptInfo.CoverContent = req.CoverContent
  257. pptInfo.ModifyTime = time.Now()
  258. pptInfo.TitleSetting = req.TitleSetting
  259. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent", "TitleSetting"})
  260. if err != nil {
  261. br.Msg = "编辑失败"
  262. br.ErrMsg = "编辑失败,Err:" + err.Error()
  263. return
  264. }
  265. pptMap, err := models.GetPptMappingByPptId(req.PptId)
  266. if err != nil {
  267. br.Msg = `该PPT信息不存在, 保存失败`
  268. br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
  269. br.IsSendEmail = false
  270. return
  271. }
  272. pptMapList, err := models.GetPptMappingListByGroupId(pptMap.GroupId)
  273. if err != nil {
  274. br.ErrMsg = "PPT目录信息异常"
  275. return
  276. }
  277. count, err := models.GetPptMappingByGroupPptCountId(pptMap.GroupPptId, this.SysUser.AdminId)
  278. if err != nil {
  279. br.Msg = "查询映射关系失败"
  280. br.ErrMsg = "查询映射关系失败, 保存失败, Err:" + err.Error()
  281. return
  282. }
  283. if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
  284. // 如果没有人为移动位置, 默认将当前ppt置顶
  285. err = ppt.MoveGroupPpt(pptMap.GroupId, pptMap.GroupPptId, pptMapList[0].GroupPptId, 0, this.SysUser.AdminId)
  286. if err != nil {
  287. br.Msg = err.Error()
  288. br.ErrMsg = "移动失败,Err:" + err.Error()
  289. return
  290. }
  291. }
  292. // 日志记录
  293. {
  294. logInfo := &models.PptV2SaveLog{
  295. PptId: pptInfo.PptId,
  296. TemplateType: pptInfo.TemplateType,
  297. BackgroundImg: pptInfo.BackgroundImg,
  298. Title: pptInfo.Title,
  299. ReportType: pptInfo.ReportType,
  300. PptDate: pptInfo.PptDate,
  301. Content: pptInfo.Content,
  302. CoverContent: pptInfo.CoverContent,
  303. AdminId: this.SysUser.AdminId,
  304. AdminRealName: this.SysUser.RealName,
  305. CreateTime: time.Now(),
  306. }
  307. _, err = models.AddPptV2SaveLog(logInfo)
  308. }
  309. resp := models.AddPptResp{
  310. PptId: req.PptId,
  311. }
  312. br.Ret = 200
  313. br.Success = true
  314. br.Msg = "编辑成功"
  315. br.IsAddLog = true
  316. br.Data = resp
  317. }
  318. // DeletePpt
  319. // @Title 删除ppt
  320. // @Description 删除ppt接口
  321. // @Param request body models.DeletePptV2Req true "type json string"
  322. // @Success 200 Ret=200 删除成功
  323. // @router /delete [post]
  324. func (this *PptV2Controller) DeletePpt() {
  325. br := new(models.BaseResponse).Init()
  326. defer func() {
  327. this.Data["json"] = br
  328. this.ServeJSON()
  329. }()
  330. var req models.DeletePptV2Req
  331. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  332. if err != nil {
  333. br.Msg = "参数解析异常!"
  334. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  335. return
  336. }
  337. if req.PptId <= 0 {
  338. br.Msg = "参数错误"
  339. return
  340. }
  341. pptInfo, err := models.GetPptV2ById(req.PptId)
  342. if err != nil {
  343. br.Msg = "ppt不存在"
  344. return
  345. }
  346. if pptInfo.AdminId != this.SysUser.AdminId {
  347. br.Msg = "无权删除"
  348. return
  349. }
  350. err = models.DeletePptV2(req.PptId)
  351. if err != nil {
  352. br.Msg = "删除失败"
  353. br.ErrMsg = "删除失败,Err:" + err.Error()
  354. return
  355. }
  356. //如果该ppt存在单个共享记录,则删除共享
  357. err = ppt.DeleteGroupPpt(req.PptId)
  358. if err != nil {
  359. br.Msg = "删除失败"
  360. br.ErrMsg = "删除失败,Err:" + err.Error()
  361. return
  362. }
  363. br.Ret = 200
  364. br.Success = true
  365. br.IsAddLog = true
  366. br.Msg = "删除成功"
  367. }
  368. // DetailPpt
  369. // @Title 获取ppt详情
  370. // @Description 获取ppt详情接口
  371. // @Param PptId query int true "PptId"
  372. // @Success 200 {object} models.PptV2
  373. // @router /detail [get]
  374. func (this *PptV2Controller) DetailPpt() {
  375. br := new(models.BaseResponse).Init()
  376. defer func() {
  377. if br.ErrMsg == "" {
  378. br.IsSendEmail = false
  379. }
  380. this.Data["json"] = br
  381. this.ServeJSON()
  382. }()
  383. sysUser := this.SysUser
  384. if sysUser == nil {
  385. br.Msg = "请登录"
  386. br.ErrMsg = "请登录,SysUser Is Empty"
  387. br.Ret = 408
  388. return
  389. }
  390. pptId, _ := this.GetInt("PptId")
  391. pptInfo, err := models.GetPptV2ById(pptId)
  392. if err != nil {
  393. br.Msg = "信息获取失败"
  394. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  395. return
  396. }
  397. // 编辑中
  398. editor, e := services.UpdatePptEditing(pptId, 0, sysUser.AdminId, sysUser.RealName, false)
  399. if e != nil {
  400. br.Msg = "操作失败"
  401. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  402. return
  403. }
  404. resp := new(models.PPTDetailResp)
  405. resp.PptV2 = pptInfo
  406. resp.Editor = editor
  407. br.Ret = 200
  408. br.Success = true
  409. br.Msg = "获取成功"
  410. br.Data = resp
  411. }
  412. // DownloadPptx
  413. // @Title ppt下载
  414. // @Description ppt下载
  415. // @Param PptId query int true "PptId"
  416. // @Success 200 下载成功
  417. // @router /downloadpptx [get]
  418. func (this *PptV2CommonController) DownloadPptx() {
  419. br := new(models.BaseResponse).Init()
  420. defer func() {
  421. this.Data["json"] = br
  422. this.ServeJSON()
  423. }()
  424. pptId, err := this.GetInt("PptId")
  425. if err != nil {
  426. br.Msg = "参数错误"
  427. br.ErrMsg = "获取,pptId,Err:" + err.Error()
  428. return
  429. }
  430. pptInfo, err := models.GetPptV2ById(pptId)
  431. if err != nil {
  432. br.Msg = "获取信息失败"
  433. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  434. return
  435. }
  436. filePath := pptInfo.PptxUrl
  437. fileName := pptInfo.Title + ".pptx"
  438. this.Ctx.Output.Download(filePath, fileName)
  439. br.Success = true
  440. br.Ret = 200
  441. br.Msg = "下载成功"
  442. return
  443. }
  444. // Publish
  445. // @Title 发布接口
  446. // @Description 发布接口
  447. // @Param request body models.SavePptV2PathReq true "type json string"
  448. // @Success Ret=200 发布成功
  449. // @router /publish [post]
  450. func (this *PptV2Controller) Publish() {
  451. br := new(models.BaseResponse).Init()
  452. defer func() {
  453. this.Data["json"] = br
  454. this.ServeJSON()
  455. }()
  456. //SavePptV2PathReq
  457. //PptV2PublishReq
  458. var req models.SavePptV2PathReq
  459. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  460. if err != nil {
  461. br.Msg = "参数解析异常!"
  462. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  463. return
  464. }
  465. pptId := req.PptId
  466. if pptId <= 0 {
  467. br.Msg = "参数错误"
  468. return
  469. }
  470. err = models.EditPptV2Path(pptId, req.PptxUrl)
  471. if err != nil {
  472. br.Msg = "发布失败"
  473. br.ErrMsg = "发布失败,Err:" + err.Error()
  474. return
  475. }
  476. //添加发布记录
  477. {
  478. record := new(models.PptV2PublishRecord)
  479. record.CreateTime = time.Now()
  480. record.PptId = pptId
  481. record.PptUrl = req.PptxUrl
  482. go models.AddPptV2PublishRecord(record)
  483. }
  484. br.Ret = 200
  485. br.Success = true
  486. br.Msg = "发布成功"
  487. br.IsAddLog = true
  488. return
  489. }
  490. // PptUpload
  491. // @Title ppt上传
  492. // @Description ppt上传
  493. // @Param PptId query int true "PptId"
  494. // @Success 200 新增成功
  495. // @router /pptUpload [post]
  496. func (this *PptV2Controller) PptUpload() {
  497. br := new(models.BaseResponse).Init()
  498. defer func() {
  499. this.Data["json"] = br
  500. this.ServeJSON()
  501. }()
  502. pptId, _ := this.GetInt("PptId", 0)
  503. if pptId <= 0 {
  504. br.Msg = "参数错误"
  505. return
  506. }
  507. _, err := models.GetPptV2ById(pptId)
  508. if err != nil {
  509. br.Msg = "获取数据失败"
  510. br.ErrMsg = "获取PPT详情失败,Err:" + err.Error()
  511. return
  512. }
  513. f, h, err := this.GetFile("file")
  514. if err != nil {
  515. br.Msg = "获取资源信息失败"
  516. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  517. return
  518. }
  519. defer func() {
  520. _ = f.Close()
  521. }()
  522. uploadFileName := h.Filename //上传的文件名
  523. ext := path.Ext(h.Filename)
  524. dateDir := time.Now().Format("20060102")
  525. uploadDir := utils.STATIC_DIR + "ppt/" + dateDir
  526. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  527. if err != nil {
  528. br.Msg = "存储目录创建失败"
  529. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  530. return
  531. }
  532. randStr := utils.GetRandStringNoSpecialChar(28)
  533. fileName := randStr + ext
  534. fpath := uploadDir + "/" + fileName
  535. if err = this.SaveToFile("file", fpath); err != nil {
  536. br.Msg = "文件上传失败"
  537. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  538. return
  539. }
  540. defer func() {
  541. _ = os.Remove(fpath)
  542. }()
  543. hzUploadDir := utils.RESOURCE_DIR + "ppt/"
  544. savePptxToOssPath := hzUploadDir + time.Now().Format("200601/20060102/")
  545. //pptName := strings.Replace(pptItem.Title, "\n", "", -1)
  546. //pptName = strings.TrimSuffix(pptName, " ")
  547. pptName := utils.GetRandStringNoSpecialChar(28)
  548. savePptxToOssPath += pptName + ".pptx"
  549. //上传到阿里云 和 minio
  550. pptxUrl := ``
  551. ossClient := services.NewOssClient()
  552. if ossClient == nil {
  553. br.Msg = "上传失败"
  554. br.ErrMsg = "初始化OSS服务失败"
  555. return
  556. }
  557. pptxUrl, err = ossClient.UploadFile(fileName, fpath, savePptxToOssPath)
  558. if err != nil {
  559. br.Msg = "文件上传失败"
  560. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  561. return
  562. }
  563. resp := models.ResourceResp{
  564. ResourceUrl: pptxUrl,
  565. ResourceName: uploadFileName,
  566. }
  567. br.Msg = "上传成功"
  568. br.Ret = 200
  569. br.Success = true
  570. br.Data = resp
  571. return
  572. }
  573. // SaveLog
  574. // @Title 定时ppt操作日志记录
  575. // @Description 定时ppt操作日志记录
  576. // @Param request body models.AddPptV2Req true "type json string"
  577. // @Success 200 新增成功
  578. // @router /saveLog [post]
  579. func (this *PptV2Controller) SaveLog() {
  580. br := new(models.BaseResponse).Init()
  581. defer func() {
  582. if br.ErrMsg == "" {
  583. br.IsSendEmail = false
  584. }
  585. this.Data["json"] = br
  586. this.ServeJSON()
  587. }()
  588. sysUser := this.SysUser
  589. if sysUser == nil {
  590. br.Msg = "请登录"
  591. br.ErrMsg = "请登录,SysUser Is Empty"
  592. br.Ret = 408
  593. return
  594. }
  595. var req models.AddPptV2Req
  596. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  597. if err != nil {
  598. br.Msg = "参数解析异常!"
  599. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  600. return
  601. }
  602. if req.FirstPage.Title == "" {
  603. br.Msg = "标题不能为空"
  604. return
  605. }
  606. var pptContent []services.PPTContent
  607. err = json.Unmarshal([]byte(req.Content), &pptContent)
  608. if err != nil {
  609. br.Msg = "参数解析异常!"
  610. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  611. return
  612. }
  613. // 获取ppt
  614. item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  615. if err != nil && err.Error() != utils.ErrNoRow() {
  616. br.Msg = "获取数据异常!"
  617. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  618. return
  619. }
  620. if item != nil && item.PptId != int(req.PptId) {
  621. br.Msg = "标题已存在,不可重复添加"
  622. br.IsSendEmail = false
  623. return
  624. }
  625. //变更ppt内容
  626. pptItem, e := models.GetPptV2ById(int(req.PptId))
  627. if e != nil {
  628. if e.Error() == utils.ErrNoRow() {
  629. br.Msg = "PPT已被删除, 请刷新页面"
  630. return
  631. }
  632. br.Msg = "信息获取失败"
  633. br.ErrMsg = "信息获取失败,Err:" + e.Error()
  634. return
  635. }
  636. // 标记编辑状态
  637. if pptItem.PptId > 0 {
  638. _, e = services.UpdatePptEditing(pptItem.PptId, 1, sysUser.AdminId, sysUser.RealName, false)
  639. if e != nil {
  640. br.Msg = "操作失败"
  641. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  642. return
  643. }
  644. }
  645. pptItem.TemplateType = req.FirstPage.TemplateType
  646. pptItem.BackgroundImg = req.FirstPage.ImgUrl
  647. pptItem.Title = req.FirstPage.Title
  648. pptItem.ReportType = req.FirstPage.ReportType
  649. pptItem.PptDate = req.FirstPage.PptDate
  650. pptItem.Content = req.Content
  651. pptItem.ModifyTime = time.Now()
  652. pptItem.TitleSetting = req.TitleSetting
  653. pptItem.PptPage = len(pptContent)
  654. err = pptItem.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "TitleSetting", "ppt_page"})
  655. // 将更新后的PPT, 置顶
  656. pptMap, err := models.GetPptMappingByPptId(int64(req.PptId))
  657. if err != nil {
  658. br.Msg = `该PPT信息不存在, 保存失败`
  659. br.ErrMsg = `该PPT信息不存在, 保存失败, Err` + err.Error()
  660. br.IsSendEmail = false
  661. return
  662. }
  663. pptMapList, err := models.GetPptMappingListByGroupId(pptMap.GroupId)
  664. if err != nil {
  665. br.ErrMsg = "PPT目录信息异常"
  666. return
  667. }
  668. count, err := models.GetPptMappingByGroupPptCountId(pptMap.GroupPptId, this.SysUser.AdminId)
  669. if err != nil {
  670. br.Msg = "查询映射关系失败"
  671. br.ErrMsg = "查询映射关系失败, 保存失败, Err:" + err.Error()
  672. return
  673. }
  674. if !pptMap.IsMoved && len(pptMapList) > 1 && count > 0 {
  675. // 如果没有人为移动位置, 且当前用户有权限, 默认将当前ppt置顶
  676. err = ppt.MoveGroupPpt(pptMap.GroupId, pptMap.GroupPptId, pptMapList[0].GroupPptId, 0, this.SysUser.AdminId)
  677. if err != nil {
  678. br.Msg = err.Error()
  679. br.ErrMsg = "移动失败,Err:" + err.Error()
  680. return
  681. }
  682. }
  683. //日志记录
  684. logInfo := &models.PptV2SaveLog{
  685. PptId: int(req.PptId),
  686. TemplateType: req.FirstPage.TemplateType,
  687. BackgroundImg: req.FirstPage.ImgUrl,
  688. Title: req.FirstPage.Title,
  689. ReportType: req.FirstPage.ReportType,
  690. PptDate: req.FirstPage.PptDate,
  691. Content: req.Content,
  692. CoverContent: req.CoverContent,
  693. AdminId: this.SysUser.AdminId,
  694. AdminRealName: this.SysUser.RealName,
  695. CreateTime: time.Now(),
  696. TitleSetting: req.TitleSetting,
  697. }
  698. _, e = models.AddPptV2SaveLog(logInfo)
  699. if e != nil {
  700. br.Msg = "保存失败"
  701. br.ErrMsg = "保存PPT日志失败, Err: " + e.Error()
  702. return
  703. }
  704. br.Ret = 200
  705. br.Success = true
  706. br.Msg = "保存成功"
  707. }
  708. // GetConfig
  709. // @Title 获取ppt配置
  710. // @Description 获取ppt列表接口
  711. // @Param PageSize query int true "每页数据条数"
  712. // @Param CurrentIndex query int true "当前页页码,从1开始"
  713. // @Param KeyWord query string true "搜索关键词"
  714. // @Success 200 {object} models.PptV2ListResp
  715. // @router /config [get]
  716. func (this *PptV2Controller) GetConfig() {
  717. br := new(models.BaseResponse).Init()
  718. defer func() {
  719. this.Data["json"] = br
  720. this.ServeJSON()
  721. }()
  722. crmConfig, err := company.GetConfigDetailByCode("ppt_limit")
  723. if err != nil {
  724. br.Msg = "获取配置失败"
  725. br.ErrMsg = "获取配置失败"
  726. br.IsSendEmail = false
  727. return
  728. }
  729. resp := new(models.PptV2ConfigResp)
  730. err = json.Unmarshal([]byte(crmConfig.ConfigValue), resp)
  731. if err != nil {
  732. br.Msg = "获取配置失败"
  733. br.ErrMsg = "获取配置失败;err:" + err.Error()
  734. br.IsSendEmail = false
  735. return
  736. }
  737. br.Ret = 200
  738. br.Success = true
  739. br.Msg = "获取成功"
  740. br.Data = resp
  741. }
  742. // ToReport
  743. // @Title PPT转报告
  744. // @Description PPT转报告
  745. // @Param request body models.PPT2ReportReq true "type json string"
  746. // @Success 200 Ret=200 转换成功
  747. // @router /to_report [post]
  748. func (this *PptV2Controller) ToReport() {
  749. br := new(models.BaseResponse).Init()
  750. defer func() {
  751. this.Data["json"] = br
  752. this.ServeJSON()
  753. }()
  754. sysUser := this.SysUser
  755. if sysUser == nil {
  756. br.Msg = "请登录"
  757. br.ErrMsg = "请登录,SysUser Is Empty"
  758. br.Ret = 408
  759. return
  760. }
  761. var req models.PPT2ReportReq
  762. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  763. if err != nil {
  764. br.Msg = "参数解析异常!"
  765. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  766. return
  767. }
  768. if req.PptId == 0 {
  769. br.Msg = "参数有误"
  770. return
  771. }
  772. reportId, reportCode, msg, e := services.SavePPTReport(req.PptId, req.ClassifyId, req.Title, sysUser)
  773. if e != nil {
  774. br.Msg = msg
  775. br.ErrMsg = "PPT转报告失败, Err: " + e.Error()
  776. return
  777. }
  778. resp := &models.PPT2ReportResp{
  779. ReportId: reportId,
  780. ReportCode: reportCode,
  781. }
  782. br.Ret = 200
  783. br.Success = true
  784. br.Msg = "转换成功"
  785. br.IsAddLog = true
  786. br.Data = resp
  787. }
  788. // Grant
  789. // @Title 分配ppt权限
  790. // @Description 分配ppt权限接口
  791. // @Param request body models.GrantPptReq true "type json string"
  792. // @Success 200 Ret=200 分配成功
  793. // @router /grant [post]
  794. func (this *PptV2Controller) Grant() {
  795. br := new(models.BaseResponse).Init()
  796. defer func() {
  797. this.Data["json"] = br
  798. this.ServeJSON()
  799. }()
  800. var req models.GrantPptReq
  801. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  802. if err != nil {
  803. br.Msg = "参数解析异常!"
  804. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  805. return
  806. }
  807. if req.PptId <= 0 {
  808. br.Msg = "参数错误"
  809. return
  810. }
  811. // 查找ppt信息
  812. pptInfo, err := models.GetPptV2ById(req.PptId)
  813. if err != nil {
  814. br.Msg = "ppt不存在"
  815. return
  816. }
  817. if pptInfo.AdminId != this.SysUser.AdminId {
  818. br.Msg = "无权配置"
  819. return
  820. }
  821. // 分配
  822. err, errMsg := ppt.GrantPpt(req.PptId, req.GrantType, req.AdminIdStr, this.SysUser.AdminId)
  823. if errMsg != `` {
  824. br.Msg = errMsg
  825. br.ErrMsg = errMsg
  826. if err != nil {
  827. br.ErrMsg = errMsg + ";Err:" + err.Error()
  828. } else {
  829. br.IsSendEmail = false
  830. }
  831. return
  832. }
  833. br.Ret = 200
  834. br.Success = true
  835. br.IsAddLog = true
  836. br.Msg = "分配成功"
  837. }
  838. // CancelGrant
  839. // @Title 取消分配ppt权限
  840. // @Description 取消分配ppt权限
  841. // @Param request body models.DeletePptV2Req true "type json string"
  842. // @Success 200 Ret=200 分配成功
  843. // @router /grant/cancel [post]
  844. func (this *PptV2Controller) CancelGrant() {
  845. br := new(models.BaseResponse).Init()
  846. defer func() {
  847. this.Data["json"] = br
  848. this.ServeJSON()
  849. }()
  850. var req models.DeletePptV2Req
  851. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  852. if err != nil {
  853. br.Msg = "参数解析异常!"
  854. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  855. return
  856. }
  857. if req.PptId <= 0 {
  858. br.Msg = "参数错误"
  859. return
  860. }
  861. // 查找ppt信息
  862. pptInfo, err := models.GetPptV2ById(req.PptId)
  863. if err != nil {
  864. br.Msg = "ppt不存在"
  865. return
  866. }
  867. if pptInfo.AdminId != this.SysUser.AdminId {
  868. br.Msg = "无权取消配置"
  869. return
  870. }
  871. // 分配
  872. err, errMsg := ppt.DeleteGrantPpt(req.PptId)
  873. if errMsg != `` {
  874. br.Msg = errMsg
  875. br.ErrMsg = errMsg
  876. if err != nil {
  877. br.ErrMsg = errMsg + ";Err:" + err.Error()
  878. } else {
  879. br.IsSendEmail = false
  880. }
  881. return
  882. }
  883. br.Ret = 200
  884. br.Success = true
  885. br.IsAddLog = true
  886. br.Msg = "取消成功"
  887. }
  888. // GrantInfo
  889. // @Title 获取分配ppt权限详情
  890. // @Description 获取分配ppt权限详情接口
  891. // @Param PptId query int true "ppt的id"
  892. // @Success 200 {object} models.GrantInfoResp
  893. // @router /grant/info [get]
  894. func (this *PptV2Controller) GrantInfo() {
  895. br := new(models.BaseResponse).Init()
  896. defer func() {
  897. this.Data["json"] = br
  898. this.ServeJSON()
  899. }()
  900. pptId, _ := this.GetInt("PptId")
  901. if pptId <= 0 {
  902. br.Msg = "参数错误"
  903. return
  904. }
  905. // 查找ppt信息
  906. pptInfo, err := models.GetPptV2ById(pptId)
  907. if err != nil {
  908. br.Msg = "ppt不存在"
  909. return
  910. }
  911. if pptInfo.AdminId != this.SysUser.AdminId {
  912. br.Msg = "无权配置"
  913. return
  914. }
  915. pptGrantInfoList, err := models.GetPPtGrantInfo(pptId)
  916. if err != nil {
  917. br.Msg = "信息获取失败"
  918. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  919. return
  920. }
  921. if len(pptGrantInfoList) <= 0 {
  922. br.Msg = "未配置"
  923. br.IsSendEmail = false
  924. return
  925. }
  926. grantType := 0
  927. var adminIdStr string
  928. if pptGrantInfoList[0].DepartmentId > 0 { //分配类型;1:全部ficc研究员;2:指定成员
  929. grantType = 1
  930. } else {
  931. grantType = 2
  932. adminIdsList := make([]string, 0)
  933. for _, v := range pptGrantInfoList {
  934. adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
  935. }
  936. adminIdStr = strings.Join(adminIdsList, ",")
  937. }
  938. br.Ret = 200
  939. br.Success = true
  940. br.Data = models.GrantInfoResp{
  941. PptId: pptId,
  942. GrantType: grantType,
  943. AdminIdStr: adminIdStr,
  944. }
  945. br.Msg = "分配成功"
  946. }
  947. // ToEn
  948. // @Title 中文PPT转英文
  949. // @Description 中文PPT转英文
  950. // @Param request body models.EnPPT2CnReq true "type json string"
  951. // @Success 200 Ret=200 新增成功
  952. // @router /toEn [post]
  953. func (this *PptV2Controller) ToEn() {
  954. br := new(models.BaseResponse).Init()
  955. defer func() {
  956. this.Data["json"] = br
  957. this.ServeJSON()
  958. }()
  959. var req models.EnPPT2CnReq
  960. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  961. if err != nil {
  962. br.Msg = "参数解析异常!"
  963. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  964. return
  965. }
  966. if req.PptId <= 0 {
  967. br.Msg = "请选择PPT"
  968. return
  969. }
  970. if req.GroupId <= 0 {
  971. br.Msg = "请选择目录"
  972. return
  973. }
  974. origin, e := models.GetPptV2ById(req.PptId)
  975. if e != nil {
  976. br.Msg = "原PPT信息有误"
  977. br.ErrMsg = "获取原PPT失败, Err: " + e.Error()
  978. return
  979. }
  980. // 从基础配置中取出第一张封面图, 作为英文PPT的图片, 没有则取原PPT背景图
  981. conf, e := models.GetBusinessConf()
  982. if e != nil {
  983. br.Msg = "获取PPT图配置失败"
  984. br.ErrMsg = "获取PPT图配置失败, Err: " + e.Error()
  985. return
  986. }
  987. coverImg := ""
  988. if conf[models.BusinessConfEnPptCoverImgs] != "" {
  989. imgArr := strings.Split(conf[models.BusinessConfEnPptCoverImgs], ",")
  990. if len(imgArr) > 0 {
  991. coverImg = imgArr[0]
  992. }
  993. }
  994. if coverImg == "" {
  995. coverImg = origin.BackgroundImg
  996. }
  997. _, e = ppt_english.GetPptGroupByGroupIdAdminId(int64(req.GroupId), this.SysUser.AdminId)
  998. if e != nil {
  999. br.Msg = "目录信息有误"
  1000. br.ErrMsg = "获取转换的英文PPT目录失败, Err: " + e.Error()
  1001. return
  1002. }
  1003. // 同一PPT可重复转换, 但是标题不能重复, 所以此处进行一个处理, 在原标题后+(int)作为新标题
  1004. newTitle, e := ppt.GetEnglishCopyUsableTitle(origin.Title)
  1005. if e != nil {
  1006. br.Msg = "标题信息有误"
  1007. br.ErrMsg = "获取可用标题失败, Err: " + e.Error()
  1008. return
  1009. }
  1010. var newId int64
  1011. pptInfo := &ppt_english.PptEnglish{
  1012. TemplateType: origin.TemplateType,
  1013. BackgroundImg: coverImg,
  1014. Title: newTitle,
  1015. ReportType: origin.ReportType,
  1016. PptDate: origin.PptDate,
  1017. Content: origin.Content,
  1018. CoverContent: origin.CoverContent,
  1019. CreateTime: time.Now(),
  1020. ModifyTime: time.Now(),
  1021. AdminId: this.SysUser.AdminId,
  1022. AdminRealName: this.SysUser.RealName,
  1023. TitleSetting: origin.TitleSetting,
  1024. }
  1025. newId, e = ppt_english.AddPptEnglish(pptInfo)
  1026. if e != nil {
  1027. br.Msg = "转换失败"
  1028. br.ErrMsg = "转换英文PPT失败, Err: " + e.Error()
  1029. return
  1030. }
  1031. // 新增ppt和目录映射
  1032. _, e = ppt.AddGroupPptEnglishMapping(newId, int64(req.GroupId), this.SysUser.AdminId, this.SysUser.RealName)
  1033. if e != nil {
  1034. br.Msg = "转换失败"
  1035. br.ErrMsg = "新增英文PPT和目录映射失败, Err: " + e.Error()
  1036. return
  1037. }
  1038. resp := ppt_english.AddPptEnglishResp{
  1039. PptId: newId,
  1040. }
  1041. br.Ret = 200
  1042. br.Success = true
  1043. br.Msg = "操作成功"
  1044. br.Data = resp
  1045. }
  1046. // BatchToEn
  1047. // @Title 中文PPT批量转英文
  1048. // @Description 中文PPT转英文
  1049. // @Param request body models.BatchEnPPT2CnReq true "type json string"
  1050. // @Success 200 Ret=200 新增成功
  1051. // @router /batchToEn [post]
  1052. func (this *PptV2Controller) BatchToEn() {
  1053. br := new(models.BaseResponse).Init()
  1054. defer func() {
  1055. this.Data["json"] = br
  1056. this.ServeJSON()
  1057. }()
  1058. var req models.BatchEnPPT2CnReq
  1059. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1060. if err != nil {
  1061. br.Msg = "参数解析异常!"
  1062. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1063. return
  1064. }
  1065. if req.PptIds == "" {
  1066. br.Msg = "请选择PPT"
  1067. return
  1068. }
  1069. if req.GroupId <= 0 {
  1070. br.Msg = "请选择目录"
  1071. return
  1072. }
  1073. pptIds := utils.JoinStr2IntArr(req.PptIds, ",")
  1074. if len(pptIds) == 0 {
  1075. br.Msg = "请选择PPT"
  1076. return
  1077. }
  1078. ppts, e := models.GetPptV2ByIds(pptIds)
  1079. if e != nil {
  1080. br.Msg = "操作失败"
  1081. br.ErrMsg = "获取原PPT列表失败, Err: " + e.Error()
  1082. return
  1083. }
  1084. if len(ppts) == 0 {
  1085. br.Msg = "请选择PPT"
  1086. return
  1087. }
  1088. _, e = ppt_english.GetPptGroupByGroupIdAdminId(int64(req.GroupId), this.SysUser.AdminId)
  1089. if e != nil {
  1090. br.Msg = "目录信息有误"
  1091. br.ErrMsg = "获取转换的英文PPT目录失败, Err: " + e.Error()
  1092. return
  1093. }
  1094. // 批量转换
  1095. nowTime := time.Now().Local()
  1096. for i := range ppts {
  1097. origin := ppts[i]
  1098. // 同一PPT可重复转换, 但是标题不能重复, 所以此处进行一个处理, 在原标题后+(int)作为新标题
  1099. newTitle, e := ppt.GetEnglishCopyUsableTitle(origin.Title)
  1100. if e != nil {
  1101. br.Msg = "标题信息有误"
  1102. br.ErrMsg = "获取可用标题失败, Err: " + e.Error()
  1103. return
  1104. }
  1105. var newId int64
  1106. pptInfo := &ppt_english.PptEnglish{
  1107. TemplateType: origin.TemplateType,
  1108. BackgroundImg: origin.BackgroundImg,
  1109. Title: newTitle,
  1110. ReportType: origin.ReportType,
  1111. PptDate: origin.PptDate,
  1112. Content: origin.Content,
  1113. CoverContent: origin.CoverContent,
  1114. CreateTime: nowTime,
  1115. ModifyTime: nowTime,
  1116. AdminId: this.SysUser.AdminId,
  1117. AdminRealName: this.SysUser.RealName,
  1118. }
  1119. newId, e = ppt_english.AddPptEnglish(pptInfo)
  1120. if e != nil {
  1121. br.Msg = fmt.Sprintf("PPT: %s, 转换失败", ppts[i].Title)
  1122. br.ErrMsg = "转换英文PPT失败, Err: " + e.Error()
  1123. return
  1124. }
  1125. // 新增ppt和目录映射
  1126. _, e = ppt.AddGroupPptEnglishMapping(newId, int64(req.GroupId), this.SysUser.AdminId, this.SysUser.RealName)
  1127. if e != nil {
  1128. br.Msg = fmt.Sprintf("PPT: %s, 转换失败", ppts[i].Title)
  1129. br.ErrMsg = "新增英文PPT和目录映射失败, Err: " + e.Error()
  1130. return
  1131. }
  1132. }
  1133. br.Ret = 200
  1134. br.Success = true
  1135. br.Msg = "操作成功"
  1136. }
  1137. // TitleCheck
  1138. // @Title 校验标题是否重复
  1139. // @Description 校验标题是否重复接口
  1140. // @Param Title query int true "标题"
  1141. // @Success 200 Ret=200 编辑成功
  1142. // @router /titleCheck [get]
  1143. func (this *PptV2Controller) TitleCheck() {
  1144. br := new(models.BaseResponse).Init()
  1145. defer func() {
  1146. this.Data["json"] = br
  1147. this.ServeJSON()
  1148. }()
  1149. title := this.GetString("Title")
  1150. pptId, _ := this.GetInt("PptId")
  1151. if title == "" {
  1152. br.Msg = "标题不能为空"
  1153. return
  1154. }
  1155. item, err := models.GetPptV2ByTitleAndId(title, this.SysUser.AdminId)
  1156. if err != nil && err.Error() != utils.ErrNoRow() {
  1157. br.Msg = "获取数据异常!"
  1158. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  1159. return
  1160. }
  1161. if item != nil && item.PptId != pptId {
  1162. br.Msg = "标题已存在,不可重复添加"
  1163. br.IsSendEmail = false
  1164. return
  1165. }
  1166. br.Ret = 200
  1167. br.Success = true
  1168. br.Msg = "校验成功"
  1169. }
  1170. // Editing
  1171. // @Title 标记/查询编辑状态
  1172. // @Description 标记/查询编辑状态
  1173. // @Param request body models.PPTEditingReq true "type json string"
  1174. // @Success 200 Ret=200 操作成功
  1175. // @router /editing [post]
  1176. func (this *PptV2Controller) Editing() {
  1177. br := new(models.BaseResponse).Init()
  1178. defer func() {
  1179. if br.ErrMsg == "" {
  1180. br.IsSendEmail = false
  1181. }
  1182. this.Data["json"] = br
  1183. this.ServeJSON()
  1184. }()
  1185. sysUser := this.SysUser
  1186. if sysUser == nil {
  1187. br.Msg = "请登录"
  1188. br.ErrMsg = "请登录,SysUser Is Empty"
  1189. br.Ret = 408
  1190. return
  1191. }
  1192. var req models.PPTEditingReq
  1193. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1194. if err != nil {
  1195. br.Msg = "参数解析异常!"
  1196. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1197. return
  1198. }
  1199. if req.PptId <= 0 {
  1200. br.Msg = "参数有误"
  1201. return
  1202. }
  1203. if req.Status < 0 {
  1204. br.Msg = "标记状态异常"
  1205. return
  1206. }
  1207. editor, e := services.UpdatePptEditing(req.PptId, req.Status, sysUser.AdminId, sysUser.RealName, false)
  1208. if e != nil {
  1209. br.Msg = "操作失败"
  1210. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  1211. return
  1212. }
  1213. br.Data = editor
  1214. br.Ret = 200
  1215. br.Success = true
  1216. br.Msg = "操作成功"
  1217. }