ppt_v2.go 34 KB

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