ppt_v2.go 36 KB

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