ppt_v2_group.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/services"
  6. "eta/eta_api/services/ppt"
  7. "fmt"
  8. "strings"
  9. )
  10. type PptV2GroupController struct {
  11. BaseAuthController
  12. }
  13. // GroupList
  14. // @Title 获取可见的目录列表
  15. // @Description 获取可见的目录列表接口
  16. // @Success 200 {object} models.RespGroupList
  17. // @router /groups [get]
  18. func (this *PptV2GroupController) GroupList() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. IsNewPpt, _ := this.GetInt("IsNewPpt")
  25. //data, err := ppt.GetGroupsByAdminId(IsNewPpt, this.SysUser.AdminId)
  26. data, err := ppt.GetGroupsByAdminIdV2(IsNewPpt, this.SysUser.AdminId, this.Lang)
  27. if err != nil {
  28. br.Msg = err.Error()
  29. return
  30. }
  31. br.Ret = 200
  32. br.Success = true
  33. br.Msg = "查询成功"
  34. br.Data = data
  35. return
  36. }
  37. // AddGroup
  38. // @Title 新增ppt目录
  39. // @Description 新增ppt目录接口
  40. // @Param request body models.ReqAddPptGroup true "type json string"
  41. // @Success 200 {object} models.RespAddPptGroup
  42. // @router /group/add [post]
  43. func (this *PptV2GroupController) AddGroup() {
  44. br := new(models.BaseResponse).Init()
  45. defer func() {
  46. this.Data["json"] = br
  47. this.ServeJSON()
  48. }()
  49. var req models.ReqAddPptGroup
  50. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  51. if err != nil {
  52. br.Msg = "参数解析异常!"
  53. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  54. return
  55. }
  56. if req.GroupName == "" {
  57. br.Msg = "请输入目录名称"
  58. return
  59. }
  60. newId, err := ppt.AddGroup(req.GroupName, this.SysUser.AdminId, 0, 0)
  61. if err != nil {
  62. br.Msg = err.Error()
  63. return
  64. }
  65. resp := models.RespAddPptGroup{
  66. GroupId: newId,
  67. }
  68. br.Ret = 200
  69. br.Success = true
  70. br.Msg = "新增成功"
  71. br.Data = resp
  72. }
  73. // DeleteGroup
  74. // @Title 删除ppt目录
  75. // @Description 删除ppt目录接口
  76. // @Param request body models.ReqPptGroup true "type json string"
  77. // @Success 200 Ret=200 删除成功
  78. // @router /group/delete [post]
  79. func (this *PptV2GroupController) DeleteGroup() {
  80. br := new(models.BaseResponse).Init()
  81. defer func() {
  82. this.Data["json"] = br
  83. this.ServeJSON()
  84. }()
  85. var req models.ReqPptGroup
  86. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  87. if err != nil {
  88. br.Msg = "参数解析异常!"
  89. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  90. return
  91. }
  92. if req.GroupId <= 0 {
  93. br.Msg = "请输入目录ID"
  94. return
  95. }
  96. err = ppt.DelGroup(req.GroupId, this.SysUser.AdminId)
  97. if err != nil {
  98. br.Msg = err.Error()
  99. return
  100. }
  101. br.Ret = 200
  102. br.Success = true
  103. br.Msg = "删除成功"
  104. }
  105. // ShareGroup
  106. // @Title 共享/取消共享目录
  107. // @Description 共享/取消共享目录接口
  108. // @Param request body models.ReqPptGroup true "type json string"
  109. // @Success 200 {object} models.RespPptGroupShare
  110. // @router /group/share [post]
  111. func (this *PptV2GroupController) ShareGroup() {
  112. br := new(models.BaseResponse).Init()
  113. defer func() {
  114. this.Data["json"] = br
  115. this.ServeJSON()
  116. }()
  117. var req models.ReqPptGroup
  118. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  119. if err != nil {
  120. br.Msg = "参数解析异常!"
  121. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  122. return
  123. }
  124. if req.GroupId <= 0 {
  125. br.Msg = "请输入目录ID"
  126. return
  127. }
  128. data, err := ppt.ShareGroup(req.GroupId, this.SysUser.AdminId)
  129. if err != nil {
  130. br.Msg = err.Error()
  131. return
  132. }
  133. br.Ret = 200
  134. br.Success = true
  135. br.Msg = "操作成功"
  136. br.Data = data
  137. return
  138. }
  139. // CopyGroup
  140. // @Title 复制目录
  141. // @Description 复制目录接口
  142. // @Param request body models.ReqPptGroup true "type json string"
  143. // @Success 200 Ret=200 复制成功
  144. // @router /group/copy [post]
  145. func (this *PptV2GroupController) CopyGroup() {
  146. br := new(models.BaseResponse).Init()
  147. defer func() {
  148. this.Data["json"] = br
  149. this.ServeJSON()
  150. }()
  151. var req models.ReqPptGroup
  152. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  153. if err != nil {
  154. br.Msg = "参数解析异常!"
  155. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  156. return
  157. }
  158. if req.GroupId <= 0 {
  159. br.Msg = "请输入目录ID"
  160. return
  161. }
  162. err = ppt.CopyGroup(req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  163. if err != nil {
  164. br.Msg = err.Error()
  165. return
  166. }
  167. br.Ret = 200
  168. br.Success = true
  169. br.Msg = "复制成功"
  170. return
  171. }
  172. // RenameGroup
  173. // @Title 目录重命名
  174. // @Description 目录重命名接口
  175. // @Param request body models.ReqRenamePptGroup true "type json string"
  176. // @Success 200 Ret=200 重命名成功
  177. // @router /group/rename [post]
  178. func (this *PptV2GroupController) RenameGroup() {
  179. br := new(models.BaseResponse).Init()
  180. defer func() {
  181. this.Data["json"] = br
  182. this.ServeJSON()
  183. }()
  184. var req models.ReqRenamePptGroup
  185. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  186. if err != nil {
  187. br.Msg = "参数解析异常!"
  188. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  189. return
  190. }
  191. if req.GroupId <= 0 {
  192. br.Msg = "请输入目录ID"
  193. return
  194. }
  195. if req.GroupName == "" {
  196. br.Msg = "请输入目录名称"
  197. return
  198. }
  199. err = ppt.RenameGroupName(req.GroupId, req.GroupName, this.SysUser.AdminId)
  200. if err != nil {
  201. br.Msg = err.Error()
  202. return
  203. }
  204. br.Ret = 200
  205. br.Success = true
  206. br.Msg = "重命名成功"
  207. return
  208. }
  209. // SharePpt
  210. // @Title 共享/取消共享单个ppt
  211. // @Description 共享/取消共享单个ppt接口
  212. // @Param request body models.ReqPptShare true "type json string"
  213. // @Success 200 {object} models.RespPptShare
  214. // @router /share [post]
  215. func (this *PptV2GroupController) SharePpt() {
  216. br := new(models.BaseResponse).Init()
  217. defer func() {
  218. this.Data["json"] = br
  219. this.ServeJSON()
  220. }()
  221. var req models.ReqPptShareV2
  222. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  223. if err != nil {
  224. br.Msg = "参数解析异常!"
  225. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  226. return
  227. }
  228. if req.PptId <= 0 {
  229. br.Msg = "请输入目录里的ppt序号"
  230. return
  231. }
  232. //data, err := ppt.ShareSingleGroupPpt(req.GroupPptId, this.SysUser.AdminId, this.SysUser.RealName)
  233. pptInfo, err := ppt.ShareSingleGroupPptV2(req.PptId, this.SysUser.AdminId)
  234. if err != nil {
  235. br.Msg = err.Error()
  236. return
  237. }
  238. br.Ret = 200
  239. br.Success = true
  240. br.Msg = "操作成功"
  241. br.Data = models.RespPptShareV2{
  242. PptId: pptInfo.PptId,
  243. IsShare: pptInfo.IsShare,
  244. }
  245. return
  246. }
  247. // GroupPptList
  248. // @Title 获取默认的ppt列表或者单个目录内的ppt列表
  249. // @Description 获取可见的目录列表接口
  250. // @Param GroupId query int true "目录ID"
  251. // @Success 200 {object} models.RespGroupPptList
  252. // @router /group/ppt/list [get]
  253. func (this *PptV2GroupController) GroupPptList() {
  254. br := new(models.BaseResponse).Init()
  255. defer func() {
  256. this.Data["json"] = br
  257. this.ServeJSON()
  258. }()
  259. sysUser := this.SysUser
  260. if sysUser == nil {
  261. br.Msg = "请登录"
  262. br.ErrMsg = "请登录,SysUser Is Empty"
  263. br.Ret = 408
  264. return
  265. }
  266. groupId, _ := this.GetInt("GroupId")
  267. data, err := ppt.GetGroupPptList(int64(groupId), this.SysUser.AdminId)
  268. if err != nil {
  269. br.Msg = err.Error()
  270. br.IsSendEmail = false
  271. return
  272. }
  273. // 编辑状态
  274. for _, v := range data.List {
  275. editor, e := services.UpdatePptEditing(int(v.PptId), 0, sysUser.AdminId, sysUser.RealName, false)
  276. if e != nil {
  277. br.Msg = "获取失败"
  278. br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error())
  279. return
  280. }
  281. v.Editor = editor
  282. }
  283. br.Ret = 200
  284. br.Success = true
  285. br.Msg = "查询成功"
  286. br.Data = data
  287. return
  288. }
  289. // MoveGroupPpt
  290. // @Title 移动目录里的ppt
  291. // @Description 移动目录里的ppt接口
  292. // @Param request body models.ReqMoveGroupPpt true "type json string"
  293. // @Success 200 Ret=200 移动成功
  294. // @router /move [post]
  295. func (this *PptV2GroupController) MoveGroupPpt() {
  296. br := new(models.BaseResponse).Init()
  297. defer func() {
  298. this.Data["json"] = br
  299. this.ServeJSON()
  300. }()
  301. var req models.ReqMoveGroupPpt
  302. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  303. if err != nil {
  304. br.Msg = "参数解析异常!"
  305. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  306. return
  307. }
  308. if req.GroupId <= 0 {
  309. br.Msg = "请输入目录ID"
  310. return
  311. }
  312. err = ppt.MoveGroupPpt(req.GroupId, req.GroupPptId, req.PrevGroupPptId, req.NextGroupPptId, this.SysUser.AdminId)
  313. if err != nil {
  314. br.Msg = err.Error()
  315. return
  316. }
  317. br.Ret = 200
  318. br.Success = true
  319. br.Msg = "移动成功"
  320. }
  321. // MoveGroup
  322. // @Title 移动目录
  323. // @Description 移动目录接口
  324. // @Param request body models.ReqMoveGroup true "type json string"
  325. // @Success 200 Ret=200 移动成功
  326. // @router /group/move [post]
  327. func (this *PptV2GroupController) MoveGroup() {
  328. br := new(models.BaseResponse).Init()
  329. defer func() {
  330. this.Data["json"] = br
  331. this.ServeJSON()
  332. }()
  333. var req models.ReqMoveGroup
  334. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  335. if err != nil {
  336. br.Msg = "参数解析异常!"
  337. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  338. return
  339. }
  340. if req.GroupId <= 0 {
  341. br.Msg = "请输入目录ID"
  342. return
  343. }
  344. err = ppt.MoveGroup(req.GroupId, req.PrevGroupId, req.NextGroupId, this.SysUser.AdminId)
  345. if err != nil {
  346. br.Msg = err.Error()
  347. return
  348. }
  349. br.Ret = 200
  350. br.Success = true
  351. br.Msg = "移动成功"
  352. }
  353. // CopyPpt
  354. // @Title 复制单个ppt
  355. // @Description 复制目录接口
  356. // @Param request body models.ReqCopyPpt true "type json string"
  357. // @Success 200 Ret=200 复制成功
  358. // @router /copy [post]
  359. func (this *PptV2GroupController) CopyPpt() {
  360. br := new(models.BaseResponse).Init()
  361. defer func() {
  362. this.Data["json"] = br
  363. this.ServeJSON()
  364. }()
  365. var req models.ReqCopyPpt
  366. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  367. if err != nil {
  368. br.Msg = "参数解析异常!"
  369. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  370. return
  371. }
  372. if req.GroupId <= 0 {
  373. br.Msg = "请输入目录ID"
  374. return
  375. }
  376. if req.PptId <= 0 {
  377. br.Msg = "请输入ppt ID"
  378. return
  379. }
  380. data, err := ppt.CopyPpt(req.PptId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  381. if err != nil {
  382. br.Msg = err.Error()
  383. return
  384. }
  385. br.Ret = 200
  386. br.Success = true
  387. br.Msg = "复制成功"
  388. br.Data = data
  389. return
  390. }
  391. // GroupNameList
  392. // @Title 查询目录名称列表
  393. // @Description 查询目录名称列表接口
  394. // @Success 200 {object} models.RespPptGroupNameList
  395. // @router /group/name [get]
  396. func (this *PptV2GroupController) GroupNameList() {
  397. br := new(models.BaseResponse).Init()
  398. defer func() {
  399. this.Data["json"] = br
  400. this.ServeJSON()
  401. }()
  402. list, err := models.GetPptGroupIdAndGroupNameByAdminId(this.SysUser.AdminId)
  403. if err != nil {
  404. br.Msg = "查询目录名称出错" + err.Error()
  405. return
  406. }
  407. data := &models.RespPptGroupNameList{
  408. List: list,
  409. }
  410. br.Ret = 200
  411. br.Success = true
  412. br.Msg = "查询成功"
  413. br.Data = data
  414. return
  415. }
  416. // SearchGroupPptList
  417. // @Title 按ppt关键词搜索列表
  418. // @Description 按ppt关键词搜索列表接口
  419. // @Param KeyWord query int true "搜索关键词"
  420. // @Success 200 {object} models.RespSearchGroupPptList
  421. // @router /group/ppt/search [get]
  422. func (this *PptV2GroupController) SearchGroupPptList() {
  423. br := new(models.BaseResponse).Init()
  424. defer func() {
  425. this.Data["json"] = br
  426. this.ServeJSON()
  427. }()
  428. keyWord := this.GetString("KeyWord")
  429. data, err := ppt.SearchGroupPpt(keyWord)
  430. if err != nil {
  431. br.Msg = err.Error()
  432. return
  433. }
  434. br.Ret = 200
  435. br.Success = true
  436. br.Msg = "查询成功"
  437. br.Data = data
  438. return
  439. }
  440. // SharePptList
  441. // @Title 获取用户开放的公共Ppt
  442. // @Description 获取用户开放的公共Ppt接口
  443. // @Param AdminId query int true "创建人ID"
  444. // @Param Keyword query string true "关键字"
  445. // @Param IsPrivate query bool false "是否为私有"
  446. // @Success 200 {object} models.RespGroupPptList
  447. // @router /share/ppt/list [get]
  448. func (this *PptV2GroupController) SharePptList() {
  449. br := new(models.BaseResponse).Init()
  450. defer func() {
  451. this.Data["json"] = br
  452. this.ServeJSON()
  453. }()
  454. sysUser := this.SysUser
  455. if sysUser == nil {
  456. br.Msg = "请登录"
  457. br.ErrMsg = "请登录,SysUser Is Empty"
  458. br.Ret = 408
  459. return
  460. }
  461. adminId, _ := this.GetInt("AdminId")
  462. keyword := this.GetString("Keyword")
  463. isPrivate, _ := this.GetBool("IsPrivate", false)
  464. if isPrivate && adminId <= 0 {
  465. br.Msg = "参数有误, 私有PPT创建人ID不可为空"
  466. return
  467. }
  468. data, err := ppt.GetSharePptList(adminId, keyword, isPrivate)
  469. if err != nil {
  470. br.Msg = err.Error()
  471. return
  472. }
  473. // 编辑状态
  474. for _, v := range data.List {
  475. editor, e := services.UpdatePptEditing(int(v.PptId), 0, sysUser.AdminId, sysUser.RealName, false)
  476. if e != nil {
  477. br.Msg = "获取失败"
  478. br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error())
  479. return
  480. }
  481. v.Editor = editor
  482. }
  483. br.Ret = 200
  484. br.Success = true
  485. br.Msg = "查询成功"
  486. br.Data = data
  487. return
  488. }
  489. // GrantPptList
  490. // @Title 获取用户共享的公共Ppt(分配权限的Ppt)
  491. // @Description 获取用户共享的公共Ppt(分配权限的Ppt)接口
  492. // @Param GroupId query int true "分组ID,唉,其实不知道用啥名,就这么用吧"
  493. // @Param Keyword query string true "关键字"
  494. // @Success 200 {object} models.RespGroupPptList
  495. // @router /grant/ppt/list [get]
  496. func (this *PptV2GroupController) GrantPptList() {
  497. br := new(models.BaseResponse).Init()
  498. defer func() {
  499. this.Data["json"] = br
  500. this.ServeJSON()
  501. }()
  502. sysUser := this.SysUser
  503. if sysUser == nil {
  504. br.Msg = "请登录"
  505. br.ErrMsg = "请登录,SysUser Is Empty"
  506. br.Ret = 408
  507. return
  508. }
  509. groupId, _ := this.GetInt("GroupId")
  510. keyword := this.GetString("Keyword")
  511. var sourceType string
  512. switch groupId {
  513. case 1:
  514. sourceType = "my"
  515. case 2:
  516. sourceType = "other"
  517. default:
  518. br.Msg = "错误的来源"
  519. br.IsSendEmail = false
  520. return
  521. }
  522. data, err := ppt.GetGrantPptList(this.SysUser.AdminId, keyword, sourceType)
  523. if err != nil {
  524. br.Msg = err.Error()
  525. return
  526. }
  527. // 编辑状态
  528. for _, v := range data.List {
  529. editor, e := services.UpdatePptEditing(int(v.PptId), 0, sysUser.AdminId, sysUser.RealName, false)
  530. if e != nil {
  531. br.Msg = "获取失败"
  532. br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error())
  533. return
  534. }
  535. v.Editor = editor
  536. }
  537. br.Ret = 200
  538. br.Success = true
  539. br.Msg = "查询成功"
  540. br.Data = data
  541. return
  542. }
  543. // ListSearch
  544. // @Title 我的/公开PPT搜索
  545. // @Description 我的/公开PPT搜索
  546. // @Param Keyword query string true "关键字"
  547. // @Success 200 {object} models.RespGroupPptList
  548. // @router /ppt/search [get]
  549. func (this *PptV2GroupController) ListSearch() {
  550. br := new(models.BaseResponse).Init()
  551. defer func() {
  552. if br.ErrMsg == "" {
  553. br.IsSendEmail = false
  554. }
  555. this.Data["json"] = br
  556. this.ServeJSON()
  557. }()
  558. sysUser := this.SysUser
  559. if sysUser == nil {
  560. br.Msg = "请登录"
  561. br.ErrMsg = "请登录,SysUser Is Empty"
  562. br.Ret = 408
  563. return
  564. }
  565. keyword := this.GetString("Keyword")
  566. keyword = strings.TrimSpace(keyword)
  567. data, err := ppt.SearchPptList(sysUser.AdminId, keyword)
  568. if err != nil {
  569. br.Msg = err.Error()
  570. return
  571. }
  572. br.Ret = 200
  573. br.Success = true
  574. br.Msg = "查询成功"
  575. br.Data = data
  576. }