ppt_english_group.go 15 KB

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