ppt_english_group.go 15 KB

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