ppt_v2.go 27 KB

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