ppt_v2_group.go 12 KB

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