ppt_v2.go 35 KB

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