ppt_v2.go 34 KB

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