ppt.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/utils"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. _ "image/gif"
  8. _ "image/jpeg"
  9. _ "image/png"
  10. "time"
  11. )
  12. // 报告
  13. type PptController struct {
  14. BaseAuthController
  15. }
  16. // @Title 获取ppt列表
  17. // @Description 获取ppt列表接口
  18. // @Param PageSize query int true "每页数据条数"
  19. // @Param CurrentIndex query int true "当前页页码,从1开始"
  20. // @Param KeyWord query string true "搜索关键词"
  21. // @Success 200 {object} models.ReportListResp
  22. // @router /list [get]
  23. func (this *PptController) ListPpt() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sysUser := this.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. return
  34. }
  35. pageSize, _ := this.GetInt("PageSize")
  36. currentIndex, _ := this.GetInt("CurrentIndex")
  37. keyWord := this.GetString("KeyWord")
  38. var startSize int
  39. if pageSize <= 0 {
  40. pageSize = utils.PageSize20
  41. }
  42. if currentIndex <= 0 {
  43. currentIndex = 1
  44. }
  45. startSize = utils.StartIndex(currentIndex, pageSize)
  46. var condition string
  47. var pars []interface{}
  48. if keyWord != "" {
  49. condition += ` AND (title LIKE '%` + keyWord + `%' OR admin_real_name LIKE '%` + keyWord + `%' ) `
  50. }
  51. total, err := models.GetPptListCount(condition, pars)
  52. if err != nil {
  53. br.Msg = "获取失败"
  54. br.ErrMsg = "获取失败,Err:" + err.Error()
  55. return
  56. }
  57. list, err := models.GetPptList(condition, pars, startSize, pageSize)
  58. if err != nil {
  59. br.Msg = "获取失败"
  60. br.ErrMsg = "获取失败,Err:" + err.Error()
  61. return
  62. }
  63. lenList := len(list)
  64. for i := 0; i < lenList; i++ {
  65. adminId := list[i].AdminId
  66. if adminId == sysUser.AdminId || sysUser.Role == "admin" {
  67. list[i].IsAuth = true
  68. } else {
  69. list[i].IsAuth = false
  70. }
  71. }
  72. page := paging.GetPaging(currentIndex, pageSize, total)
  73. resp := new(models.PptListResp)
  74. resp.Paging = page
  75. resp.List = list
  76. br.Ret = 200
  77. br.Success = true
  78. br.Msg = "获取成功"
  79. br.Data = resp
  80. }
  81. // @Title 新增ppt
  82. // @Description 新增ppt接口
  83. // @Param request body models.AddPptReq true "type json string"
  84. // @Success 200 Ret=200 新增成功
  85. // @router /add [post]
  86. func (this *PptController) AddPpt() {
  87. br := new(models.BaseResponse).Init()
  88. defer func() {
  89. this.Data["json"] = br
  90. this.ServeJSON()
  91. }()
  92. var req models.AddPptReq
  93. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  94. if err != nil {
  95. br.Msg = "参数解析异常!"
  96. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  97. return
  98. }
  99. if req.FirstPage.Title == "" {
  100. br.Msg = "标题不能为空"
  101. return
  102. }
  103. var newId int64
  104. var msg string
  105. if req.PptId <= 0 {
  106. item, err := models.GetPptByTitle(req.FirstPage.Title)
  107. if err != nil && err.Error() != utils.ErrNoRow() {
  108. br.Msg = "获取数据异常!"
  109. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  110. return
  111. }
  112. if item != nil {
  113. br.Msg = "标题已存在,不可重复添加"
  114. return
  115. }
  116. ppt := new(models.Ppt)
  117. ppt.Title = req.FirstPage.Title
  118. ppt.PptDate = req.FirstPage.PptDate
  119. ppt.ReportType = req.FirstPage.ReportType
  120. ppt.CreateTime = time.Now()
  121. ppt.ModifyTime = time.Now()
  122. ppt.AdminId = this.SysUser.AdminId
  123. ppt.AdminRealName = this.SysUser.RealName
  124. ppt.Version = 2
  125. newId, err = models.AddPpt(ppt)
  126. if err != nil {
  127. br.Msg = "新增失败"
  128. br.ErrMsg = "新增失败,Err:" + err.Error()
  129. return
  130. }
  131. firstPage := new(models.PptPages)
  132. firstPage.PptId = newId
  133. firstPage.Title = req.FirstPage.Title
  134. firstPage.ResourceId = "0"
  135. firstPage.Timestamp = 0
  136. firstPage.BackIndex = req.FirstPage.BackIndex
  137. _, err = models.AddPptPages(firstPage)
  138. if err != nil {
  139. br.Msg = "新增失败"
  140. br.ErrMsg = "新增章节失败,Err:" + err.Error()
  141. return
  142. }
  143. for _, v := range req.ContentPage {
  144. if v.ResourceId == "" {
  145. br.Msg = "图表参数错误"
  146. br.ErrMsg = "图表参数错误,ResourceId 等于0"
  147. return
  148. }
  149. count, _ := models.GetPptPagesContent(int(newId), v.ResourceId)
  150. if count <= 0 {
  151. page := new(models.PptPages)
  152. page.PptId = newId
  153. page.Title = v.Title
  154. page.ResourceId = v.ResourceId
  155. page.Timestamp = v.Timestamp
  156. page.CreateTime = time.Now()
  157. page.ModifyTime = time.Now()
  158. _, err = models.AddPptPages(page)
  159. if err != nil {
  160. br.Msg = "新增失败"
  161. br.ErrMsg = "新增章节失败,Err:" + err.Error()
  162. return
  163. }
  164. }
  165. }
  166. msg = "新增成功"
  167. } else {
  168. newId = req.PptId
  169. ppt := new(models.Ppt)
  170. ppt.PptId = int(req.PptId)
  171. ppt.Title = req.FirstPage.Title
  172. ppt.PptDate = req.FirstPage.PptDate
  173. ppt.ReportType = req.FirstPage.ReportType
  174. ppt.ModifyTime = time.Now()
  175. err = models.EditPpt(ppt)
  176. //删除ppt_pages
  177. err = models.DeletePptPages(req.PptId)
  178. if err != nil {
  179. br.Msg = "编辑失败"
  180. br.ErrMsg = "编辑失败,Err:" + err.Error()
  181. return
  182. }
  183. firstPage := new(models.PptPages)
  184. firstPage.PptId = newId
  185. firstPage.Title = req.FirstPage.Title
  186. firstPage.ResourceId = ""
  187. firstPage.Timestamp = 0
  188. firstPage.BackIndex = req.FirstPage.BackIndex
  189. _, err = models.AddPptPages(firstPage)
  190. if err != nil {
  191. br.Msg = "新增失败"
  192. br.ErrMsg = "新增章节失败,Err:" + err.Error()
  193. return
  194. }
  195. for _, v := range req.ContentPage {
  196. if v.ResourceId == "" {
  197. br.Msg = "图表参数错误"
  198. br.ErrMsg = "图表参数错误,ResourceId 等于 empty"
  199. return
  200. }
  201. count, _ := models.GetPptPagesContent(int(newId), v.ResourceId)
  202. if count <= 0 {
  203. page := new(models.PptPages)
  204. page.PptId = newId
  205. page.Title = v.Title
  206. page.ResourceId = v.ResourceId
  207. page.Timestamp = v.Timestamp
  208. page.CreateTime = time.Now()
  209. page.ModifyTime = time.Now()
  210. _, err = models.AddPptPages(page)
  211. if err != nil {
  212. br.Msg = "新增失败"
  213. br.ErrMsg = "新增章节失败,Err:" + err.Error()
  214. return
  215. }
  216. }
  217. }
  218. msg = "保存成功"
  219. }
  220. resp := new(models.AddPptResp)
  221. resp.PptId = newId
  222. br.Ret = 200
  223. br.Success = true
  224. br.Msg = msg
  225. br.Data = resp
  226. }
  227. // @Title 编辑ppt
  228. // @Description 编辑ppt接口
  229. // @Param request body models.EditPptReq true "type json string"
  230. // @Success 200 Ret=200 编辑成功
  231. // @router /edit [post]
  232. func (this *PptController) EditPpt() {
  233. br := new(models.BaseResponse).Init()
  234. defer func() {
  235. this.Data["json"] = br
  236. this.ServeJSON()
  237. }()
  238. var req models.EditPptReq
  239. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  240. if err != nil {
  241. br.Msg = "参数解析异常!"
  242. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  243. return
  244. }
  245. if req.FirstPage.Title == "" {
  246. br.Msg = "标题不能为空"
  247. return
  248. }
  249. item, err := models.GetPptByTitle(req.FirstPage.Title)
  250. if err != nil && err.Error() != utils.ErrNoRow() {
  251. br.Msg = "获取数据异常!"
  252. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  253. return
  254. }
  255. if item != nil && item.PptId != int(req.PptId) {
  256. br.Msg = "标题已存在,不可重复添加"
  257. return
  258. }
  259. ppt := new(models.Ppt)
  260. ppt.PptId = int(req.PptId)
  261. ppt.Title = req.FirstPage.Title
  262. ppt.PptDate = req.FirstPage.PptDate
  263. ppt.ReportType = req.FirstPage.ReportType
  264. ppt.ModifyTime = time.Now()
  265. err = models.EditPpt(ppt)
  266. if err != nil {
  267. br.Msg = "编辑失败"
  268. br.ErrMsg = "编辑失败,Err:" + err.Error()
  269. return
  270. }
  271. newId := req.PptId
  272. //删除ppt_pages
  273. err = models.DeletePptPages(newId)
  274. if err != nil {
  275. br.Msg = "编辑失败"
  276. br.ErrMsg = "编辑失败,Err:" + err.Error()
  277. return
  278. }
  279. firstPage := new(models.PptPages)
  280. firstPage.PptId = newId
  281. firstPage.Title = req.FirstPage.Title
  282. firstPage.ResourceId = "0"
  283. firstPage.Timestamp = 0
  284. firstPage.BackIndex = req.FirstPage.BackIndex
  285. _, err = models.AddPptPages(firstPage)
  286. if err != nil {
  287. br.Msg = "编辑失败"
  288. br.ErrMsg = "新增章节失败,Err:" + err.Error()
  289. return
  290. }
  291. for _, v := range req.ContentPage {
  292. if v.ResourceId == "" {
  293. br.Msg = "图表参数错误"
  294. br.ErrMsg = "图表参数错误,ResourceId 等于 empty"
  295. return
  296. }
  297. count, _ := models.GetPptPagesContent(int(newId), v.ResourceId)
  298. if count <= 0 {
  299. page := new(models.PptPages)
  300. page.PptId = newId
  301. page.Title = v.Title
  302. page.ResourceId = v.ResourceId
  303. page.Timestamp = v.Timestamp
  304. page.CreateTime = time.Now()
  305. page.ModifyTime = time.Now()
  306. _, err = models.AddPptPages(page)
  307. if err != nil {
  308. br.Msg = "编辑失败"
  309. br.ErrMsg = "新增章节失败,Err:" + err.Error()
  310. return
  311. }
  312. }
  313. }
  314. resp := new(models.AddPptResp)
  315. resp.PptId = req.PptId
  316. br.Ret = 200
  317. br.Success = true
  318. br.Msg = "编辑成功"
  319. br.Data = resp
  320. }
  321. // @Title 删除ppt
  322. // @Description 删除ppt接口
  323. // @Param request body models.DeletePptReq true "type json string"
  324. // @Success 200 Ret=200 编辑成功
  325. // @router /delete [post]
  326. func (this *PptController) DeletePpt() {
  327. br := new(models.BaseResponse).Init()
  328. defer func() {
  329. this.Data["json"] = br
  330. this.ServeJSON()
  331. }()
  332. var req models.DeletePptReq
  333. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  334. if err != nil {
  335. br.Msg = "参数解析异常!"
  336. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  337. return
  338. }
  339. if req.PptId <= 0 {
  340. br.Msg = "参数错误"
  341. return
  342. }
  343. err = models.DeletePpt(req.PptId)
  344. if err != nil {
  345. br.Msg = "删除失败"
  346. br.ErrMsg = "删除失败,Err:" + err.Error()
  347. return
  348. }
  349. br.Ret = 200
  350. br.Success = true
  351. br.Msg = "删除成功"
  352. }
  353. // @Title 新增ppt章节
  354. // @Description 新增ppt章节接口
  355. // @Param request body models.ContentPageItems true "type json string"
  356. // @Success 200 Ret=200 编辑成功
  357. // @router /addPptPages [post]
  358. func (this *PptController) AddPptPages() {
  359. br := new(models.BaseResponse).Init()
  360. defer func() {
  361. this.Data["json"] = br
  362. this.ServeJSON()
  363. }()
  364. var req models.ContentPageItems
  365. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  366. if err != nil {
  367. br.Msg = "参数解析异常!"
  368. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  369. return
  370. }
  371. page := new(models.PptPages)
  372. page.PptId = req.PptId
  373. page.Title = req.Title
  374. page.CreateTime = time.Now()
  375. page.ModifyTime = time.Now()
  376. page.ResourceId = req.ResourceId
  377. _, err = models.AddPptPages(page)
  378. if err != nil {
  379. br.Msg = "新增失败"
  380. br.ErrMsg = "新增失败,Err:" + err.Error()
  381. return
  382. }
  383. br.Ret = 200
  384. br.Success = true
  385. br.Msg = "新增成功"
  386. }
  387. // @Title 获取ppt详情
  388. // @Description 获取ppt详情接口
  389. // @Param PptId query int true "ppt_id"
  390. // @Success 200 {object} models.ReportListResp
  391. // @router /detail [get]
  392. func (this *PptController) DetailPpt() {
  393. br := new(models.BaseResponse).Init()
  394. defer func() {
  395. this.Data["json"] = br
  396. this.ServeJSON()
  397. }()
  398. pptId, _ := this.GetInt("PptId")
  399. ppt, err := models.GetPptById(pptId)
  400. if err != nil {
  401. br.Msg = "信息获取失败"
  402. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  403. return
  404. }
  405. pptPages, err := models.GetPptPagesById(pptId)
  406. if err != nil {
  407. br.Msg = "信息获取失败"
  408. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  409. return
  410. }
  411. resp := new(models.PptDetailResp)
  412. resp.Ppt = ppt
  413. resp.PptPages = pptPages
  414. br.Ret = 200
  415. br.Success = true
  416. br.Msg = "获取成功"
  417. br.Data = resp
  418. }
  419. type PptCommonController struct {
  420. BaseCommonController
  421. }
  422. // @Title ppt下载
  423. // @Description ppt下载
  424. // @Param PptId query int true "PptId"
  425. // @Success 200 下载成功
  426. // @router /download [get]
  427. func (this *PptCommonController) Download() {
  428. br := new(models.BaseResponse).Init()
  429. defer func() {
  430. this.Data["json"] = br
  431. this.ServeJSON()
  432. }()
  433. pptId, err := this.GetInt("PptId")
  434. if err != nil {
  435. br.Msg = "参数错误"
  436. br.ErrMsg = "获取,pptId,Err:" + err.Error()
  437. return
  438. }
  439. ppt, err := models.GetPptById(pptId)
  440. if err != nil {
  441. br.Msg = "获取信息失败"
  442. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  443. return
  444. }
  445. filePath := ppt.PptUrl + ".ppt"
  446. fileName := ppt.Title + ".ppt"
  447. this.Ctx.Output.Download(filePath, fileName)
  448. br.Success = true
  449. br.Ret = 200
  450. br.Msg = "下载成功"
  451. return
  452. }
  453. // @Title ppt下载
  454. // @Description ppt下载
  455. // @Param PptId query int true "PptId"
  456. // @Success 200 下载成功
  457. // @router /downloadpptx [get]
  458. func (this *PptCommonController) Downloadpptx() {
  459. br := new(models.BaseResponse).Init()
  460. defer func() {
  461. this.Data["json"] = br
  462. this.ServeJSON()
  463. }()
  464. pptId, err := this.GetInt("PptId")
  465. if err != nil {
  466. br.Msg = "参数错误"
  467. br.ErrMsg = "获取,pptId,Err:" + err.Error()
  468. return
  469. }
  470. ppt, err := models.GetPptById(pptId)
  471. if err != nil {
  472. br.Msg = "获取信息失败"
  473. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  474. return
  475. }
  476. filePath := ppt.PptUrl + ".pptx"
  477. fileName := ppt.Title + ".pptx"
  478. this.Ctx.Output.Download(filePath, fileName)
  479. br.Success = true
  480. br.Ret = 200
  481. br.Msg = "下载成功"
  482. return
  483. }
  484. // @Title 获取首页背景模板接口
  485. // @Description 获取首页背景模板接口
  486. // @Success 200 {object} models.PptImagesResp
  487. // @router /getImages [get]
  488. func (this *PptController) GetImages() {
  489. br := new(models.BaseResponse).Init()
  490. defer func() {
  491. this.Data["json"] = br
  492. this.ServeJSON()
  493. }()
  494. imageType := 0
  495. ppt, err := models.GetImages(imageType)
  496. if err != nil {
  497. br.Msg = "获取信息失败"
  498. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  499. return
  500. }
  501. resp := new(models.PptImagesResp)
  502. resp.List = ppt
  503. br.Data = resp
  504. br.Ret = 200
  505. br.Success = true
  506. br.Msg = "获取成功"
  507. return
  508. }
  509. type PublishPptResult struct {
  510. Result string `json:"result"`
  511. PptPath string `json:"ppt_path"`
  512. PptName string `json:"ppt_name"`
  513. PptFullPath string `json:"ppt_full_path"`
  514. }
  515. /*
  516. func init() {
  517. fmt.Println("start")
  518. var err error
  519. defer func() {
  520. if err != nil {
  521. fmt.Println("err:", err.Error())
  522. }
  523. }()
  524. pptId := 111
  525. if pptId <= 0 {
  526. return
  527. }
  528. pptFirstPages, err := models.GetPptFirstPage(pptId)
  529. if err != nil {
  530. return
  531. }
  532. pptContentPages, err := models.GetPptContentPages(pptId, pptFirstPages.PptPagesId)
  533. if err != nil {
  534. return
  535. }
  536. dataMap := make(map[string]interface{})
  537. dataMap["FirstPage"] = pptFirstPages
  538. dataMap["ContentPage"] = pptContentPages
  539. dataMap["ScreenHeight"] = 12000
  540. postUrl := "http://127.0.0.1:5000/publish_ppt/" //随便写的
  541. postData, err := json.Marshal(dataMap)
  542. if err != nil {
  543. return
  544. }
  545. utils.FileLog.Info("%s",string(postData))
  546. result, err := http.Post(postUrl, string(postData))
  547. fmt.Println("result:", string(result))
  548. if err != nil {
  549. return
  550. }
  551. var pptResult PublishPptResult
  552. err = json.Unmarshal(result, &pptResult)
  553. if err != nil {
  554. return
  555. }
  556. fmt.Println("ppt:", pptResult.PptFullPath)
  557. fmt.Println("end")
  558. }
  559. */
  560. /*func init() {
  561. fmt.Println("start")
  562. fmt.Println(time.Now())
  563. randStr := utils.GetRandStringNoSpecialChar(28)
  564. fileName := randStr + ".png"
  565. savePath := "./b1.jpg"
  566. resourceUrl, err := services.UploadAliyun(fileName, savePath)
  567. if err != nil {
  568. fmt.Println("err:", err)
  569. }
  570. fmt.Println(resourceUrl)
  571. fmt.Println(time.Now())
  572. fmt.Println("end")
  573. }
  574. */