ppt_v2_group.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. // 由于是倒序, 所以需要颠倒NextGroupPptId和PrevGroupPptId的位置
  313. err = ppt.MoveGroupPpt(req.GroupId, req.GroupPptId, req.NextGroupPptId, req.PrevGroupPptId, this.SysUser.AdminId)
  314. if err != nil {
  315. br.Msg = err.Error()
  316. return
  317. }
  318. // 增加人为移动的标识
  319. mappingInfo := &models.PptV2GroupMapping{}
  320. mappingInfo.GroupPptId = req.GroupPptId
  321. mappingInfo.IsMoved = true
  322. err = mappingInfo.Update([]string{"is_moved"})
  323. if err != nil {
  324. br.Msg = err.Error()
  325. return
  326. }
  327. br.Ret = 200
  328. br.Success = true
  329. br.Msg = "移动成功"
  330. }
  331. // MoveGroup
  332. // @Title 移动目录
  333. // @Description 移动目录接口
  334. // @Param request body models.ReqMoveGroup true "type json string"
  335. // @Success 200 Ret=200 移动成功
  336. // @router /group/move [post]
  337. func (this *PptV2GroupController) MoveGroup() {
  338. br := new(models.BaseResponse).Init()
  339. defer func() {
  340. this.Data["json"] = br
  341. this.ServeJSON()
  342. }()
  343. var req models.ReqMoveGroup
  344. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  345. if err != nil {
  346. br.Msg = "参数解析异常!"
  347. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  348. return
  349. }
  350. if req.GroupId <= 0 {
  351. br.Msg = "请输入目录ID"
  352. return
  353. }
  354. err = ppt.MoveGroup(req.GroupId, req.PrevGroupId, req.NextGroupId, this.SysUser.AdminId)
  355. if err != nil {
  356. br.Msg = err.Error()
  357. return
  358. }
  359. br.Ret = 200
  360. br.Success = true
  361. br.Msg = "移动成功"
  362. }
  363. // CopyPpt
  364. // @Title 复制单个ppt
  365. // @Description 复制目录接口
  366. // @Param request body models.ReqCopyPpt true "type json string"
  367. // @Success 200 Ret=200 复制成功
  368. // @router /copy [post]
  369. func (this *PptV2GroupController) CopyPpt() {
  370. br := new(models.BaseResponse).Init()
  371. defer func() {
  372. this.Data["json"] = br
  373. this.ServeJSON()
  374. }()
  375. var req models.ReqCopyPpt
  376. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  377. if err != nil {
  378. br.Msg = "参数解析异常!"
  379. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  380. return
  381. }
  382. if req.GroupId <= 0 {
  383. br.Msg = "请输入目录ID"
  384. return
  385. }
  386. if req.PptId <= 0 {
  387. br.Msg = "请输入ppt ID"
  388. return
  389. }
  390. data, err := ppt.CopyPpt(req.PptId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  391. if err != nil {
  392. br.Msg = err.Error()
  393. return
  394. }
  395. br.Ret = 200
  396. br.Success = true
  397. br.Msg = "复制成功"
  398. br.Data = data
  399. return
  400. }
  401. // GroupNameList
  402. // @Title 查询目录名称列表
  403. // @Description 查询目录名称列表接口
  404. // @Success 200 {object} models.RespPptGroupNameList
  405. // @router /group/name [get]
  406. func (this *PptV2GroupController) GroupNameList() {
  407. br := new(models.BaseResponse).Init()
  408. defer func() {
  409. this.Data["json"] = br
  410. this.ServeJSON()
  411. }()
  412. list, err := models.GetPptGroupIdAndGroupNameByAdminId(this.SysUser.AdminId)
  413. if err != nil {
  414. br.Msg = "查询目录名称出错" + err.Error()
  415. return
  416. }
  417. data := &models.RespPptGroupNameList{
  418. List: list,
  419. }
  420. br.Ret = 200
  421. br.Success = true
  422. br.Msg = "查询成功"
  423. br.Data = data
  424. return
  425. }
  426. // SearchGroupPptList
  427. // @Title 按ppt关键词搜索列表
  428. // @Description 按ppt关键词搜索列表接口
  429. // @Param KeyWord query int true "搜索关键词"
  430. // @Success 200 {object} models.RespSearchGroupPptList
  431. // @router /group/ppt/search [get]
  432. func (this *PptV2GroupController) SearchGroupPptList() {
  433. br := new(models.BaseResponse).Init()
  434. defer func() {
  435. this.Data["json"] = br
  436. this.ServeJSON()
  437. }()
  438. keyWord := this.GetString("KeyWord")
  439. data, err := ppt.SearchGroupPpt(keyWord)
  440. if err != nil {
  441. br.Msg = err.Error()
  442. return
  443. }
  444. br.Ret = 200
  445. br.Success = true
  446. br.Msg = "查询成功"
  447. br.Data = data
  448. return
  449. }
  450. // SharePptList
  451. // @Title 获取用户开放的公共Ppt
  452. // @Description 获取用户开放的公共Ppt接口
  453. // @Param AdminId query int true "创建人ID"
  454. // @Param Keyword query string true "关键字"
  455. // @Param IsPrivate query bool false "是否为私有"
  456. // @Success 200 {object} models.RespGroupPptList
  457. // @router /share/ppt/list [get]
  458. func (this *PptV2GroupController) SharePptList() {
  459. br := new(models.BaseResponse).Init()
  460. defer func() {
  461. this.Data["json"] = br
  462. this.ServeJSON()
  463. }()
  464. sysUser := this.SysUser
  465. if sysUser == nil {
  466. br.Msg = "请登录"
  467. br.ErrMsg = "请登录,SysUser Is Empty"
  468. br.Ret = 408
  469. return
  470. }
  471. adminId, _ := this.GetInt("AdminId")
  472. keyword := this.GetString("Keyword")
  473. isPrivate, _ := this.GetBool("IsPrivate", false)
  474. if isPrivate && adminId <= 0 {
  475. br.Msg = "参数有误, 私有PPT创建人ID不可为空"
  476. return
  477. }
  478. data, err := ppt.GetSharePptList(adminId, keyword, isPrivate)
  479. if err != nil {
  480. br.Msg = err.Error()
  481. return
  482. }
  483. // 编辑状态
  484. for _, v := range data.List {
  485. editor, e := services.UpdatePptEditing(int(v.PptId), 0, sysUser.AdminId, sysUser.RealName, false)
  486. if e != nil {
  487. br.Msg = "获取失败"
  488. br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error())
  489. return
  490. }
  491. v.Editor = editor
  492. }
  493. br.Ret = 200
  494. br.Success = true
  495. br.Msg = "查询成功"
  496. br.Data = data
  497. return
  498. }
  499. // GrantPptList
  500. // @Title 获取用户共享的公共Ppt(分配权限的Ppt)
  501. // @Description 获取用户共享的公共Ppt(分配权限的Ppt)接口
  502. // @Param GroupId query int true "分组ID,唉,其实不知道用啥名,就这么用吧"
  503. // @Param Keyword query string true "关键字"
  504. // @Success 200 {object} models.RespGroupPptList
  505. // @router /grant/ppt/list [get]
  506. func (this *PptV2GroupController) GrantPptList() {
  507. br := new(models.BaseResponse).Init()
  508. defer func() {
  509. this.Data["json"] = br
  510. this.ServeJSON()
  511. }()
  512. sysUser := this.SysUser
  513. if sysUser == nil {
  514. br.Msg = "请登录"
  515. br.ErrMsg = "请登录,SysUser Is Empty"
  516. br.Ret = 408
  517. return
  518. }
  519. groupId, _ := this.GetInt("GroupId")
  520. keyword := this.GetString("Keyword")
  521. var sourceType string
  522. switch groupId {
  523. case 1:
  524. sourceType = "my"
  525. case 2:
  526. sourceType = "other"
  527. default:
  528. br.Msg = "错误的来源"
  529. br.IsSendEmail = false
  530. return
  531. }
  532. data, err := ppt.GetGrantPptList(this.SysUser.AdminId, keyword, sourceType)
  533. if err != nil {
  534. br.Msg = err.Error()
  535. return
  536. }
  537. // 编辑状态
  538. for _, v := range data.List {
  539. editor, e := services.UpdatePptEditing(int(v.PptId), 0, sysUser.AdminId, sysUser.RealName, false)
  540. if e != nil {
  541. br.Msg = "获取失败"
  542. br.ErrMsg = fmt.Sprintf("获取PPT编辑状态失败, err: %s", e.Error())
  543. return
  544. }
  545. v.Editor = editor
  546. }
  547. br.Ret = 200
  548. br.Success = true
  549. br.Msg = "查询成功"
  550. br.Data = data
  551. return
  552. }
  553. // ListSearch
  554. // @Title 我的/公开PPT搜索
  555. // @Description 我的/公开PPT搜索
  556. // @Param Keyword query string true "关键字"
  557. // @Success 200 {object} models.RespGroupPptList
  558. // @router /ppt/search [get]
  559. func (this *PptV2GroupController) ListSearch() {
  560. br := new(models.BaseResponse).Init()
  561. defer func() {
  562. if br.ErrMsg == "" {
  563. br.IsSendEmail = false
  564. }
  565. this.Data["json"] = br
  566. this.ServeJSON()
  567. }()
  568. sysUser := this.SysUser
  569. if sysUser == nil {
  570. br.Msg = "请登录"
  571. br.ErrMsg = "请登录,SysUser Is Empty"
  572. br.Ret = 408
  573. return
  574. }
  575. keyword := this.GetString("Keyword")
  576. keyword = strings.TrimSpace(keyword)
  577. data, err := ppt.SearchPptList(sysUser.AdminId, keyword)
  578. if err != nil {
  579. br.Msg = err.Error()
  580. return
  581. }
  582. br.Ret = 200
  583. br.Success = true
  584. br.Msg = "查询成功"
  585. br.Data = data
  586. }