ppt_v2.go 33 KB

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