ppt_v2_group.go 14 KB

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