ppt_english.go 29 KB

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