ppt_v2.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/models/company"
  6. "eta/eta_mobile/models/ppt_english"
  7. "eta/eta_mobile/services"
  8. "eta/eta_mobile/services/ppt"
  9. "eta/eta_mobile/utils"
  10. "fmt"
  11. "github.com/rdlucklib/rdluck_tools/paging"
  12. _ "image/gif"
  13. _ "image/jpeg"
  14. _ "image/png"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // PptV2Controller 新版ppt模块
  20. type PptV2Controller struct {
  21. BaseAuthController
  22. }
  23. // PptV2CommonController 新版ppt公共模块
  24. type PptV2CommonController struct {
  25. BaseCommonController
  26. }
  27. // ListPpt
  28. // @Title 获取ppt列表
  29. // @Description 获取ppt列表接口
  30. // @Param PageSize query int true "每页数据条数"
  31. // @Param CurrentIndex query int true "当前页页码,从1开始"
  32. // @Param KeyWord query string true "搜索关键词"
  33. // @Success 200 {object} models.PptV2ListResp
  34. // @router /list [get]
  35. func (this *PptV2Controller) ListPpt() {
  36. br := new(models.BaseResponse).Init()
  37. defer func() {
  38. this.Data["json"] = br
  39. this.ServeJSON()
  40. }()
  41. sysUser := this.SysUser
  42. if sysUser == nil {
  43. br.Msg = "请登录"
  44. br.ErrMsg = "请登录,SysUser Is Empty"
  45. return
  46. }
  47. pageSize, _ := this.GetInt("PageSize")
  48. currentIndex, _ := this.GetInt("CurrentIndex")
  49. keyWord := this.GetString("KeyWord")
  50. var startSize int
  51. if pageSize <= 0 {
  52. pageSize = utils.PageSize20
  53. }
  54. if currentIndex <= 0 {
  55. currentIndex = 1
  56. }
  57. startSize = utils.StartIndex(currentIndex, pageSize)
  58. var condition string
  59. var pars []interface{}
  60. if keyWord != "" {
  61. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  62. pars = append(pars, "%"+keyWord+"%", "%"+keyWord+"%")
  63. }
  64. total, err := models.GetPptV2ListCount(condition, pars)
  65. if err != nil {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取失败,Err:" + err.Error()
  68. return
  69. }
  70. list, err := models.GetPptV2List(condition, pars, startSize, pageSize)
  71. if err != nil {
  72. br.Msg = "获取失败"
  73. br.ErrMsg = "获取失败,Err:" + err.Error()
  74. return
  75. }
  76. lenList := len(list)
  77. for i := 0; i < lenList; i++ {
  78. adminId := list[i].AdminId
  79. if adminId == sysUser.AdminId || sysUser.Role == "admin" {
  80. list[i].IsAuth = true
  81. } else {
  82. list[i].IsAuth = false
  83. }
  84. }
  85. page := paging.GetPaging(currentIndex, pageSize, total)
  86. resp := new(models.PptV2ListResp)
  87. resp.Paging = page
  88. resp.List = list
  89. br.Ret = 200
  90. br.Success = true
  91. br.Msg = "获取成功"
  92. br.Data = resp
  93. }
  94. // AddPpt
  95. // @Title 新增ppt
  96. // @Description 新增ppt接口
  97. // @Param request body models.AddPptV2Req true "type json string"
  98. // @Success 200 Ret=200 新增成功
  99. // @router /add [post]
  100. func (this *PptV2Controller) AddPpt() {
  101. br := new(models.BaseResponse).Init()
  102. defer func() {
  103. this.Data["json"] = br
  104. this.ServeJSON()
  105. }()
  106. var req models.AddPptV2Req
  107. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  108. if err != nil {
  109. br.Msg = "参数解析异常!"
  110. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  111. return
  112. }
  113. if req.FirstPage.Title == "" {
  114. br.Msg = "标题不能为空"
  115. return
  116. }
  117. var newId int64
  118. var msg string
  119. if req.PptId <= 0 {
  120. if req.GroupId == 0 {
  121. br.Msg = "请输入目录ID"
  122. return
  123. }
  124. item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  125. if err != nil && err.Error() != utils.ErrNoRow() {
  126. br.Msg = "获取数据异常!"
  127. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  128. return
  129. }
  130. if item != nil && item.PptId != int(req.PptId) {
  131. br.Msg = "标题已存在,不可重复添加"
  132. br.IsSendEmail = false
  133. return
  134. }
  135. pptInfo := &models.PptV2{
  136. //PptId: 0,
  137. TemplateType: req.FirstPage.TemplateType,
  138. BackgroundImg: req.FirstPage.ImgUrl,
  139. Title: req.FirstPage.Title,
  140. ReportType: req.FirstPage.ReportType,
  141. PptDate: req.FirstPage.PptDate,
  142. Content: req.Content,
  143. CoverContent: req.CoverContent,
  144. CreateTime: time.Now(),
  145. ModifyTime: time.Now(),
  146. AdminId: this.SysUser.AdminId,
  147. AdminRealName: this.SysUser.RealName,
  148. PptVersion: 2,
  149. }
  150. newId, err = models.AddPptV2(pptInfo)
  151. if err != nil {
  152. br.Msg = "新增失败"
  153. br.ErrMsg = "新增失败,Err:" + err.Error()
  154. return
  155. }
  156. //新增ppt和目录映射
  157. _, err = ppt.AddGroupPptMapping(newId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  158. if err != nil {
  159. br.Msg = err.Error()
  160. return
  161. }
  162. msg = "新增成功"
  163. } else {
  164. newId = req.PptId
  165. pptInfo, err := models.GetPptV2ById(int(req.PptId))
  166. if err != nil {
  167. br.Msg = "信息获取失败"
  168. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  169. return
  170. }
  171. pptInfo.TemplateType = req.FirstPage.TemplateType
  172. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  173. pptInfo.Title = req.FirstPage.Title
  174. pptInfo.ReportType = req.FirstPage.ReportType
  175. pptInfo.PptDate = req.FirstPage.PptDate
  176. pptInfo.Content = req.Content
  177. pptInfo.CoverContent = req.CoverContent
  178. pptInfo.ModifyTime = time.Now()
  179. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent"})
  180. msg = "保存成功"
  181. }
  182. resp := models.AddPptResp{
  183. PptId: newId,
  184. }
  185. br.Ret = 200
  186. br.Success = true
  187. br.Msg = msg
  188. br.Data = resp
  189. }
  190. // EditPpt
  191. // @Title 编辑ppt
  192. // @Description 编辑ppt接口
  193. // @Param request body models.AddPptV2Req true "type json string"
  194. // @Success 200 Ret=200 编辑成功
  195. // @router /edit [post]
  196. func (this *PptV2Controller) EditPpt() {
  197. br := new(models.BaseResponse).Init()
  198. defer func() {
  199. this.Data["json"] = br
  200. this.ServeJSON()
  201. }()
  202. var req models.AddPptV2Req
  203. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  204. if err != nil {
  205. br.Msg = "参数解析异常!"
  206. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  207. return
  208. }
  209. if req.FirstPage.Title == "" {
  210. br.Msg = "标题不能为空"
  211. return
  212. }
  213. item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  214. if err != nil && err.Error() != utils.ErrNoRow() {
  215. br.Msg = "获取数据异常!"
  216. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  217. return
  218. }
  219. if item != nil && item.PptId != int(req.PptId) {
  220. br.Msg = "标题已存在,不可重复添加"
  221. br.IsSendEmail = false
  222. return
  223. }
  224. pptInfo, err := models.GetPptV2ById(int(req.PptId))
  225. if err != nil {
  226. br.Msg = "信息获取失败"
  227. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  228. return
  229. }
  230. // 判断权限
  231. if pptInfo.AdminId != this.SysUser.AdminId {
  232. _, err := models.GetPPtGrantConf(pptInfo.PptId, this.SysUser.AdminId)
  233. if err != nil {
  234. if err.Error() == utils.ErrNoRow() {
  235. br.Msg = `该PPT已取消共享,保存失败`
  236. br.ErrMsg = `该PPT已取消共享,保存失败`
  237. br.IsSendEmail = false
  238. } else {
  239. br.Msg = `保存失败`
  240. br.ErrMsg = `保存失败,ERR:` + err.Error()
  241. }
  242. return
  243. }
  244. }
  245. // 修改
  246. pptInfo.TemplateType = req.FirstPage.TemplateType
  247. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  248. pptInfo.Title = req.FirstPage.Title
  249. pptInfo.ReportType = req.FirstPage.ReportType
  250. pptInfo.PptDate = req.FirstPage.PptDate
  251. pptInfo.Content = req.Content
  252. pptInfo.CoverContent = req.CoverContent
  253. pptInfo.ModifyTime = time.Now()
  254. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent"})
  255. if err != nil {
  256. br.Msg = "编辑失败"
  257. br.ErrMsg = "编辑失败,Err:" + err.Error()
  258. return
  259. }
  260. // 日志记录
  261. {
  262. logInfo := &models.PptV2SaveLog{
  263. PptId: pptInfo.PptId,
  264. TemplateType: pptInfo.TemplateType,
  265. BackgroundImg: pptInfo.BackgroundImg,
  266. Title: pptInfo.Title,
  267. ReportType: pptInfo.ReportType,
  268. PptDate: pptInfo.PptDate,
  269. Content: pptInfo.Content,
  270. CoverContent: pptInfo.CoverContent,
  271. AdminId: this.SysUser.AdminId,
  272. AdminRealName: this.SysUser.RealName,
  273. CreateTime: time.Now(),
  274. }
  275. _, err = models.AddPptV2SaveLog(logInfo)
  276. }
  277. resp := models.AddPptResp{
  278. PptId: req.PptId,
  279. }
  280. br.Ret = 200
  281. br.Success = true
  282. br.Msg = "编辑成功"
  283. br.IsAddLog = true
  284. br.Data = resp
  285. }
  286. // DeletePpt
  287. // @Title 删除ppt
  288. // @Description 删除ppt接口
  289. // @Param request body models.DeletePptV2Req true "type json string"
  290. // @Success 200 Ret=200 删除成功
  291. // @router /delete [post]
  292. func (this *PptV2Controller) DeletePpt() {
  293. br := new(models.BaseResponse).Init()
  294. defer func() {
  295. this.Data["json"] = br
  296. this.ServeJSON()
  297. }()
  298. var req models.DeletePptV2Req
  299. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  300. if err != nil {
  301. br.Msg = "参数解析异常!"
  302. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  303. return
  304. }
  305. if req.PptId <= 0 {
  306. br.Msg = "参数错误"
  307. return
  308. }
  309. pptInfo, err := models.GetPptV2ById(req.PptId)
  310. if err != nil {
  311. br.Msg = "ppt不存在"
  312. return
  313. }
  314. if pptInfo.AdminId != this.SysUser.AdminId {
  315. br.Msg = "无权删除"
  316. return
  317. }
  318. err = models.DeletePptV2(req.PptId)
  319. if err != nil {
  320. br.Msg = "删除失败"
  321. br.ErrMsg = "删除失败,Err:" + err.Error()
  322. return
  323. }
  324. //如果该ppt存在单个共享记录,则删除共享
  325. err = ppt.DeleteGroupPpt(req.PptId)
  326. if err != nil {
  327. br.Msg = "删除失败"
  328. br.ErrMsg = "删除失败,Err:" + err.Error()
  329. return
  330. }
  331. br.Ret = 200
  332. br.Success = true
  333. br.IsAddLog = true
  334. br.Msg = "删除成功"
  335. }
  336. // DetailPpt
  337. // @Title 获取ppt详情
  338. // @Description 获取ppt详情接口
  339. // @Param PptId query int true "PptId"
  340. // @Success 200 {object} models.PptV2
  341. // @router /detail [get]
  342. func (this *PptV2Controller) DetailPpt() {
  343. br := new(models.BaseResponse).Init()
  344. defer func() {
  345. if br.ErrMsg == "" {
  346. br.IsSendEmail = false
  347. }
  348. this.Data["json"] = br
  349. this.ServeJSON()
  350. }()
  351. sysUser := this.SysUser
  352. if sysUser == nil {
  353. br.Msg = "请登录"
  354. br.ErrMsg = "请登录,SysUser Is Empty"
  355. br.Ret = 408
  356. return
  357. }
  358. pptId, _ := this.GetInt("PptId")
  359. pptInfo, err := models.GetPptV2ById(pptId)
  360. if err != nil {
  361. br.Msg = "信息获取失败"
  362. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  363. return
  364. }
  365. // 编辑中
  366. editor, e := services.UpdatePptEditing(pptId, 0, sysUser.AdminId, sysUser.RealName, false)
  367. if e != nil {
  368. br.Msg = "操作失败"
  369. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  370. return
  371. }
  372. resp := new(models.PPTDetailResp)
  373. resp.PptV2 = pptInfo
  374. resp.Editor = editor
  375. br.Ret = 200
  376. br.Success = true
  377. br.Msg = "获取成功"
  378. br.Data = resp
  379. }
  380. // DownloadPptx
  381. // @Title ppt下载
  382. // @Description ppt下载
  383. // @Param PptId query int true "PptId"
  384. // @Success 200 下载成功
  385. // @router /downloadpptx [get]
  386. func (this *PptV2CommonController) DownloadPptx() {
  387. br := new(models.BaseResponse).Init()
  388. defer func() {
  389. this.Data["json"] = br
  390. this.ServeJSON()
  391. }()
  392. pptId, err := this.GetInt("PptId")
  393. if err != nil {
  394. br.Msg = "参数错误"
  395. br.ErrMsg = "获取,pptId,Err:" + err.Error()
  396. return
  397. }
  398. pptInfo, err := models.GetPptV2ById(pptId)
  399. if err != nil {
  400. br.Msg = "获取信息失败"
  401. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  402. return
  403. }
  404. filePath := pptInfo.PptxUrl
  405. fileName := pptInfo.Title + ".pptx"
  406. this.Ctx.Output.Download(filePath, fileName)
  407. br.Success = true
  408. br.Ret = 200
  409. br.Msg = "下载成功"
  410. return
  411. }
  412. // Publish
  413. // @Title 发布接口
  414. // @Description 发布接口
  415. // @Param request body models.SavePptV2PathReq true "type json string"
  416. // @Success Ret=200 发布成功
  417. // @router /publish [post]
  418. func (this *PptV2Controller) Publish() {
  419. br := new(models.BaseResponse).Init()
  420. defer func() {
  421. this.Data["json"] = br
  422. this.ServeJSON()
  423. }()
  424. //SavePptV2PathReq
  425. //PptV2PublishReq
  426. var req models.SavePptV2PathReq
  427. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  428. if err != nil {
  429. br.Msg = "参数解析异常!"
  430. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  431. return
  432. }
  433. pptId := req.PptId
  434. if pptId <= 0 {
  435. br.Msg = "参数错误"
  436. return
  437. }
  438. err = models.EditPptV2Path(pptId, req.PptxUrl)
  439. if err != nil {
  440. br.Msg = "发布失败"
  441. br.ErrMsg = "发布失败,Err:" + err.Error()
  442. return
  443. }
  444. //添加发布记录
  445. {
  446. record := new(models.PptV2PublishRecord)
  447. record.CreateTime = time.Now()
  448. record.PptId = pptId
  449. record.PptUrl = req.PptxUrl
  450. go models.AddPptV2PublishRecord(record)
  451. }
  452. br.Ret = 200
  453. br.Success = true
  454. br.Msg = "发布成功"
  455. br.IsAddLog = true
  456. return
  457. }
  458. // SaveLog
  459. // @Title 定时ppt操作日志记录
  460. // @Description 定时ppt操作日志记录
  461. // @Param request body models.AddPptV2Req true "type json string"
  462. // @Success 200 新增成功
  463. // @router /saveLog [post]
  464. func (this *PptV2Controller) SaveLog() {
  465. br := new(models.BaseResponse).Init()
  466. defer func() {
  467. if br.ErrMsg == "" {
  468. br.IsSendEmail = false
  469. }
  470. this.Data["json"] = br
  471. this.ServeJSON()
  472. }()
  473. sysUser := this.SysUser
  474. if sysUser == nil {
  475. br.Msg = "请登录"
  476. br.ErrMsg = "请登录,SysUser Is Empty"
  477. br.Ret = 408
  478. return
  479. }
  480. var req models.AddPptV2Req
  481. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  482. if err != nil {
  483. br.Msg = "参数解析异常!"
  484. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  485. return
  486. }
  487. if req.FirstPage.Title == "" {
  488. br.Msg = "标题不能为空"
  489. return
  490. }
  491. // 获取ppt
  492. item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  493. if err != nil && err.Error() != utils.ErrNoRow() {
  494. br.Msg = "获取数据异常!"
  495. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  496. return
  497. }
  498. if item != nil && item.PptId != int(req.PptId) {
  499. br.Msg = "标题已存在,不可重复添加"
  500. br.IsSendEmail = false
  501. return
  502. }
  503. //变更ppt内容
  504. pptItem, e := models.GetPptV2ById(int(req.PptId))
  505. if e != nil {
  506. if e.Error() == utils.ErrNoRow() {
  507. br.Msg = "PPT已被删除, 请刷新页面"
  508. return
  509. }
  510. br.Msg = "信息获取失败"
  511. br.ErrMsg = "信息获取失败,Err:" + e.Error()
  512. return
  513. }
  514. // 标记编辑状态
  515. if pptItem.PptId > 0 {
  516. _, e = services.UpdatePptEditing(pptItem.PptId, 1, sysUser.AdminId, sysUser.RealName, false)
  517. if e != nil {
  518. br.Msg = "操作失败"
  519. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  520. return
  521. }
  522. }
  523. //pptInfo.TemplateType = req.FirstPage.TemplateType
  524. //pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  525. //pptInfo.Title = req.FirstPage.Title
  526. //pptInfo.ReportType = req.FirstPage.ReportType
  527. //pptInfo.PptDate = req.FirstPage.PptDate
  528. //pptInfo.Content = req.Content
  529. //pptInfo.ModifyTime = time.Now()
  530. //err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  531. //日志记录
  532. logInfo := &models.PptV2SaveLog{
  533. PptId: int(req.PptId),
  534. TemplateType: req.FirstPage.TemplateType,
  535. BackgroundImg: req.FirstPage.ImgUrl,
  536. Title: req.FirstPage.Title,
  537. ReportType: req.FirstPage.ReportType,
  538. PptDate: req.FirstPage.PptDate,
  539. Content: req.Content,
  540. CoverContent: req.CoverContent,
  541. AdminId: this.SysUser.AdminId,
  542. AdminRealName: this.SysUser.RealName,
  543. CreateTime: time.Now(),
  544. }
  545. _, e = models.AddPptV2SaveLog(logInfo)
  546. if e != nil {
  547. br.Msg = "保存失败"
  548. br.ErrMsg = "保存PPT日志失败, Err: " + e.Error()
  549. return
  550. }
  551. br.Ret = 200
  552. br.Success = true
  553. br.Msg = "保存成功"
  554. }
  555. // GetConfig
  556. // @Title 获取ppt配置
  557. // @Description 获取ppt列表接口
  558. // @Param PageSize query int true "每页数据条数"
  559. // @Param CurrentIndex query int true "当前页页码,从1开始"
  560. // @Param KeyWord query string true "搜索关键词"
  561. // @Success 200 {object} models.PptV2ListResp
  562. // @router /config [get]
  563. func (this *PptV2Controller) GetConfig() {
  564. br := new(models.BaseResponse).Init()
  565. defer func() {
  566. this.Data["json"] = br
  567. this.ServeJSON()
  568. }()
  569. crmConfig, err := company.GetConfigDetailByCode("ppt_limit")
  570. if err != nil {
  571. br.Msg = "获取配置失败"
  572. br.ErrMsg = "获取配置失败"
  573. br.IsSendEmail = false
  574. return
  575. }
  576. resp := new(models.PptV2ConfigResp)
  577. err = json.Unmarshal([]byte(crmConfig.ConfigValue), resp)
  578. if err != nil {
  579. br.Msg = "获取配置失败"
  580. br.ErrMsg = "获取配置失败;err:" + err.Error()
  581. br.IsSendEmail = false
  582. return
  583. }
  584. br.Ret = 200
  585. br.Success = true
  586. br.Msg = "获取成功"
  587. br.Data = resp
  588. }
  589. // Grant
  590. // @Title 分配ppt权限
  591. // @Description 分配ppt权限接口
  592. // @Param request body models.GrantPptReq true "type json string"
  593. // @Success 200 Ret=200 分配成功
  594. // @router /grant [post]
  595. func (this *PptV2Controller) Grant() {
  596. br := new(models.BaseResponse).Init()
  597. defer func() {
  598. this.Data["json"] = br
  599. this.ServeJSON()
  600. }()
  601. var req models.GrantPptReq
  602. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  603. if err != nil {
  604. br.Msg = "参数解析异常!"
  605. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  606. return
  607. }
  608. if req.PptId <= 0 {
  609. br.Msg = "参数错误"
  610. return
  611. }
  612. // 查找ppt信息
  613. pptInfo, err := models.GetPptV2ById(req.PptId)
  614. if err != nil {
  615. br.Msg = "ppt不存在"
  616. return
  617. }
  618. if pptInfo.AdminId != this.SysUser.AdminId {
  619. br.Msg = "无权配置"
  620. return
  621. }
  622. // 分配
  623. err, errMsg := ppt.GrantPpt(req.PptId, req.GrantType, req.AdminIdStr, this.SysUser.AdminId)
  624. if errMsg != `` {
  625. br.Msg = errMsg
  626. br.ErrMsg = errMsg
  627. if err != nil {
  628. br.ErrMsg = errMsg + ";Err:" + err.Error()
  629. } else {
  630. br.IsSendEmail = false
  631. }
  632. return
  633. }
  634. br.Ret = 200
  635. br.Success = true
  636. br.IsAddLog = true
  637. br.Msg = "分配成功"
  638. }
  639. // CancelGrant
  640. // @Title 取消分配ppt权限
  641. // @Description 取消分配ppt权限
  642. // @Param request body models.DeletePptV2Req true "type json string"
  643. // @Success 200 Ret=200 分配成功
  644. // @router /grant/cancel [post]
  645. func (this *PptV2Controller) CancelGrant() {
  646. br := new(models.BaseResponse).Init()
  647. defer func() {
  648. this.Data["json"] = br
  649. this.ServeJSON()
  650. }()
  651. var req models.DeletePptV2Req
  652. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  653. if err != nil {
  654. br.Msg = "参数解析异常!"
  655. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  656. return
  657. }
  658. if req.PptId <= 0 {
  659. br.Msg = "参数错误"
  660. return
  661. }
  662. // 查找ppt信息
  663. pptInfo, err := models.GetPptV2ById(req.PptId)
  664. if err != nil {
  665. br.Msg = "ppt不存在"
  666. return
  667. }
  668. if pptInfo.AdminId != this.SysUser.AdminId {
  669. br.Msg = "无权取消配置"
  670. return
  671. }
  672. // 分配
  673. err, errMsg := ppt.DeleteGrantPpt(req.PptId)
  674. if errMsg != `` {
  675. br.Msg = errMsg
  676. br.ErrMsg = errMsg
  677. if err != nil {
  678. br.ErrMsg = errMsg + ";Err:" + err.Error()
  679. } else {
  680. br.IsSendEmail = false
  681. }
  682. return
  683. }
  684. br.Ret = 200
  685. br.Success = true
  686. br.IsAddLog = true
  687. br.Msg = "取消成功"
  688. }
  689. // GrantInfo
  690. // @Title 获取分配ppt权限详情
  691. // @Description 获取分配ppt权限详情接口
  692. // @Param PptId query int true "ppt的id"
  693. // @Success 200 {object} models.GrantInfoResp
  694. // @router /grant/info [get]
  695. func (this *PptV2Controller) GrantInfo() {
  696. br := new(models.BaseResponse).Init()
  697. defer func() {
  698. this.Data["json"] = br
  699. this.ServeJSON()
  700. }()
  701. pptId, _ := this.GetInt("PptId")
  702. if pptId <= 0 {
  703. br.Msg = "参数错误"
  704. return
  705. }
  706. // 查找ppt信息
  707. pptInfo, err := models.GetPptV2ById(pptId)
  708. if err != nil {
  709. br.Msg = "ppt不存在"
  710. return
  711. }
  712. if pptInfo.AdminId != this.SysUser.AdminId {
  713. br.Msg = "无权配置"
  714. return
  715. }
  716. pptGrantInfoList, err := models.GetPPtGrantInfo(pptId)
  717. if err != nil {
  718. br.Msg = "信息获取失败"
  719. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  720. return
  721. }
  722. if len(pptGrantInfoList) <= 0 {
  723. br.Msg = "未配置"
  724. br.IsSendEmail = false
  725. return
  726. }
  727. grantType := 0
  728. var adminIdStr string
  729. if pptGrantInfoList[0].DepartmentId > 0 { //分配类型;1:全部ficc研究员;2:指定成员
  730. grantType = 1
  731. } else {
  732. grantType = 2
  733. adminIdsList := make([]string, 0)
  734. for _, v := range pptGrantInfoList {
  735. adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
  736. }
  737. adminIdStr = strings.Join(adminIdsList, ",")
  738. }
  739. br.Ret = 200
  740. br.Success = true
  741. br.Data = models.GrantInfoResp{
  742. PptId: pptId,
  743. GrantType: grantType,
  744. AdminIdStr: adminIdStr,
  745. }
  746. br.Msg = "分配成功"
  747. }
  748. // ToEn
  749. // @Title 中文PPT转英文
  750. // @Description 中文PPT转英文
  751. // @Param request body models.EnPPT2CnReq true "type json string"
  752. // @Success 200 Ret=200 新增成功
  753. // @router /toEn [post]
  754. func (this *PptV2Controller) ToEn() {
  755. br := new(models.BaseResponse).Init()
  756. defer func() {
  757. this.Data["json"] = br
  758. this.ServeJSON()
  759. }()
  760. var req models.EnPPT2CnReq
  761. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  762. if err != nil {
  763. br.Msg = "参数解析异常!"
  764. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  765. return
  766. }
  767. if req.PptId <= 0 {
  768. br.Msg = "请选择PPT"
  769. return
  770. }
  771. if req.GroupId <= 0 {
  772. br.Msg = "请选择目录"
  773. return
  774. }
  775. origin, e := models.GetPptV2ById(req.PptId)
  776. if e != nil {
  777. br.Msg = "原PPT信息有误"
  778. br.ErrMsg = "获取原PPT失败, Err: " + e.Error()
  779. return
  780. }
  781. // 从基础配置中取出第一张封面图, 作为英文PPT的图片, 没有则取原PPT背景图
  782. conf, e := models.GetBusinessConf()
  783. if e != nil {
  784. br.Msg = "获取PPT图配置失败"
  785. br.ErrMsg = "获取PPT图配置失败, Err: " + e.Error()
  786. return
  787. }
  788. coverImg := ""
  789. if conf[models.BusinessConfEnPptCoverImgs] != "" {
  790. imgArr := strings.Split(conf[models.BusinessConfEnPptCoverImgs], ",")
  791. if len(imgArr) > 0 {
  792. coverImg = imgArr[0]
  793. }
  794. }
  795. if coverImg == "" {
  796. coverImg = origin.BackgroundImg
  797. }
  798. _, e = ppt_english.GetPptGroupByGroupIdAdminId(int64(req.GroupId), this.SysUser.AdminId)
  799. if e != nil {
  800. br.Msg = "目录信息有误"
  801. br.ErrMsg = "获取转换的英文PPT目录失败, Err: " + e.Error()
  802. return
  803. }
  804. // 同一PPT可重复转换, 但是标题不能重复, 所以此处进行一个处理, 在原标题后+(int)作为新标题
  805. newTitle, e := ppt.GetEnglishCopyUsableTitle(origin.Title)
  806. if e != nil {
  807. br.Msg = "标题信息有误"
  808. br.ErrMsg = "获取可用标题失败, Err: " + e.Error()
  809. return
  810. }
  811. var newId int64
  812. pptInfo := &ppt_english.PptEnglish{
  813. TemplateType: origin.TemplateType,
  814. BackgroundImg: coverImg,
  815. Title: newTitle,
  816. ReportType: origin.ReportType,
  817. PptDate: origin.PptDate,
  818. Content: origin.Content,
  819. CoverContent: origin.CoverContent,
  820. CreateTime: time.Now(),
  821. ModifyTime: time.Now(),
  822. AdminId: this.SysUser.AdminId,
  823. AdminRealName: this.SysUser.RealName,
  824. }
  825. newId, e = ppt_english.AddPptEnglish(pptInfo)
  826. if e != nil {
  827. br.Msg = "转换失败"
  828. br.ErrMsg = "转换英文PPT失败, Err: " + e.Error()
  829. return
  830. }
  831. // 新增ppt和目录映射
  832. _, e = ppt.AddGroupPptEnglishMapping(newId, int64(req.GroupId), this.SysUser.AdminId, this.SysUser.RealName)
  833. if e != nil {
  834. br.Msg = "转换失败"
  835. br.ErrMsg = "新增英文PPT和目录映射失败, Err: " + e.Error()
  836. return
  837. }
  838. resp := ppt_english.AddPptEnglishResp{
  839. PptId: newId,
  840. }
  841. br.Ret = 200
  842. br.Success = true
  843. br.Msg = "操作成功"
  844. br.Data = resp
  845. }
  846. // BatchToEn
  847. // @Title 中文PPT批量转英文
  848. // @Description 中文PPT转英文
  849. // @Param request body models.BatchEnPPT2CnReq true "type json string"
  850. // @Success 200 Ret=200 新增成功
  851. // @router /batchToEn [post]
  852. func (this *PptV2Controller) BatchToEn() {
  853. br := new(models.BaseResponse).Init()
  854. defer func() {
  855. this.Data["json"] = br
  856. this.ServeJSON()
  857. }()
  858. var req models.BatchEnPPT2CnReq
  859. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  860. if err != nil {
  861. br.Msg = "参数解析异常!"
  862. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  863. return
  864. }
  865. if req.PptIds == "" {
  866. br.Msg = "请选择PPT"
  867. return
  868. }
  869. if req.GroupId <= 0 {
  870. br.Msg = "请选择目录"
  871. return
  872. }
  873. pptIds := utils.JoinStr2IntArr(req.PptIds, ",")
  874. if len(pptIds) == 0 {
  875. br.Msg = "请选择PPT"
  876. return
  877. }
  878. ppts, e := models.GetPptV2ByIds(pptIds)
  879. if e != nil {
  880. br.Msg = "操作失败"
  881. br.ErrMsg = "获取原PPT列表失败, Err: " + e.Error()
  882. return
  883. }
  884. if len(ppts) == 0 {
  885. br.Msg = "请选择PPT"
  886. return
  887. }
  888. _, e = ppt_english.GetPptGroupByGroupIdAdminId(int64(req.GroupId), this.SysUser.AdminId)
  889. if e != nil {
  890. br.Msg = "目录信息有误"
  891. br.ErrMsg = "获取转换的英文PPT目录失败, Err: " + e.Error()
  892. return
  893. }
  894. // 批量转换
  895. nowTime := time.Now().Local()
  896. for i := range ppts {
  897. origin := ppts[i]
  898. // 同一PPT可重复转换, 但是标题不能重复, 所以此处进行一个处理, 在原标题后+(int)作为新标题
  899. newTitle, e := ppt.GetEnglishCopyUsableTitle(origin.Title)
  900. if e != nil {
  901. br.Msg = "标题信息有误"
  902. br.ErrMsg = "获取可用标题失败, Err: " + e.Error()
  903. return
  904. }
  905. var newId int64
  906. pptInfo := &ppt_english.PptEnglish{
  907. TemplateType: origin.TemplateType,
  908. BackgroundImg: origin.BackgroundImg,
  909. Title: newTitle,
  910. ReportType: origin.ReportType,
  911. PptDate: origin.PptDate,
  912. Content: origin.Content,
  913. CoverContent: origin.CoverContent,
  914. CreateTime: nowTime,
  915. ModifyTime: nowTime,
  916. AdminId: this.SysUser.AdminId,
  917. AdminRealName: this.SysUser.RealName,
  918. }
  919. newId, e = ppt_english.AddPptEnglish(pptInfo)
  920. if e != nil {
  921. br.Msg = fmt.Sprintf("PPT: %s, 转换失败", ppts[i].Title)
  922. br.ErrMsg = "转换英文PPT失败, Err: " + e.Error()
  923. return
  924. }
  925. // 新增ppt和目录映射
  926. _, e = ppt.AddGroupPptEnglishMapping(newId, int64(req.GroupId), this.SysUser.AdminId, this.SysUser.RealName)
  927. if e != nil {
  928. br.Msg = fmt.Sprintf("PPT: %s, 转换失败", ppts[i].Title)
  929. br.ErrMsg = "新增英文PPT和目录映射失败, Err: " + e.Error()
  930. return
  931. }
  932. }
  933. br.Ret = 200
  934. br.Success = true
  935. br.Msg = "操作成功"
  936. }