ppt_v2.go 28 KB

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