ppt_v2.go 33 KB

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