ppt_english.go 31 KB

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