ppt_english.go 30 KB

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