ppt_v2.go 23 KB

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