ppt_english_group.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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/ppt"
  7. "strings"
  8. )
  9. type PptEnglishGroupController struct {
  10. BaseAuthController
  11. }
  12. // GroupList
  13. // @Title 获取可见的目录列表
  14. // @Description 获取可见的目录列表接口
  15. // @Success 200 {object} ppt_english.RespGroupList
  16. // @router /groups [get]
  17. func (this *PptEnglishGroupController) GroupList() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. data, err := ppt.GetEnglishGroupsByAdminId(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 ppt_english.ReqAddPptGroup true "type json string"
  38. // @Success 200 {object} ppt_english.RespAddPptGroup
  39. // @router /group/add [post]
  40. func (this *PptEnglishGroupController) AddGroup() {
  41. br := new(models.BaseResponse).Init()
  42. defer func() {
  43. this.Data["json"] = br
  44. this.ServeJSON()
  45. }()
  46. var req ppt_english.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.AddEnglishGroup(req.GroupName, this.SysUser.AdminId, 0, 0)
  58. if err != nil {
  59. br.Msg = err.Error()
  60. return
  61. }
  62. resp := ppt_english.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 ppt_english.ReqPptGroup true "type json string"
  74. // @Success 200 Ret=200 删除成功
  75. // @router /group/delete [post]
  76. func (this *PptEnglishGroupController) DeleteGroup() {
  77. br := new(models.BaseResponse).Init()
  78. defer func() {
  79. this.Data["json"] = br
  80. this.ServeJSON()
  81. }()
  82. var req ppt_english.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.DelEnglishGroup(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 ppt_english.ReqPptGroup true "type json string"
  106. // @Success 200 {object} ppt_english.RespPptGroupShare
  107. // @router /group/share [post]
  108. func (this *PptEnglishGroupController) ShareGroup() {
  109. br := new(models.BaseResponse).Init()
  110. defer func() {
  111. this.Data["json"] = br
  112. this.ServeJSON()
  113. }()
  114. var req ppt_english.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.ShareEnglishGroup(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 ppt_english.ReqPptGroup true "type json string"
  140. // @Success 200 Ret=200 复制成功
  141. // @router /group/copy [post]
  142. func (this *PptEnglishGroupController) CopyGroup() {
  143. br := new(models.BaseResponse).Init()
  144. defer func() {
  145. this.Data["json"] = br
  146. this.ServeJSON()
  147. }()
  148. var req ppt_english.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.CopyEnglishGroup(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 ppt_english.ReqRenamePptGroup true "type json string"
  173. // @Success 200 Ret=200 重命名成功
  174. // @router /group/rename [post]
  175. func (this *PptEnglishGroupController) RenameGroup() {
  176. br := new(models.BaseResponse).Init()
  177. defer func() {
  178. this.Data["json"] = br
  179. this.ServeJSON()
  180. }()
  181. var req ppt_english.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.RenameEnglishGroupName(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 ppt_english.ReqPptShare true "type json string"
  210. // @Success 200 {object} ppt_english.RespPptShare
  211. // @router /share [post]
  212. func (this *PptEnglishGroupController) SharePpt() {
  213. br := new(models.BaseResponse).Init()
  214. defer func() {
  215. this.Data["json"] = br
  216. this.ServeJSON()
  217. }()
  218. var req ppt_english.ReqPptShareEnglish
  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. pptInfo, err := ppt.ShareSingleGroupPptEnglish(req.PptId, this.SysUser.AdminId)
  230. if err != nil {
  231. br.Msg = err.Error()
  232. return
  233. }
  234. br.Ret = 200
  235. br.Success = true
  236. br.Msg = "操作成功"
  237. br.Data = ppt_english.RespPptShareEnglish{
  238. PptId: pptInfo.PptId,
  239. IsShare: pptInfo.IsShare,
  240. }
  241. return
  242. }
  243. // GroupPptList
  244. // @Title 获取默认的ppt列表或者单个目录内的ppt列表
  245. // @Description 获取可见的目录列表接口
  246. // @Param GroupId query int true "目录ID"
  247. // @Success 200 {object} ppt_english.RespGroupPptList
  248. // @router /group/ppt/list [get]
  249. func (this *PptEnglishGroupController) GroupPptList() {
  250. br := new(models.BaseResponse).Init()
  251. defer func() {
  252. this.Data["json"] = br
  253. this.ServeJSON()
  254. }()
  255. groupId, _ := this.GetInt("GroupId")
  256. data, err := ppt.GetGroupPptEnglishList(int64(groupId), this.SysUser.AdminId)
  257. if err != nil {
  258. br.Msg = err.Error()
  259. br.IsSendEmail = false
  260. return
  261. }
  262. br.Ret = 200
  263. br.Success = true
  264. br.Msg = "查询成功"
  265. br.Data = data
  266. return
  267. }
  268. // MoveGroupPpt
  269. // @Title 移动目录里的ppt
  270. // @Description 移动目录里的ppt接口
  271. // @Param request body ppt_english.ReqMoveGroupPpt true "type json string"
  272. // @Success 200 Ret=200 移动成功
  273. // @router /move [post]
  274. func (this *PptEnglishGroupController) MoveGroupPpt() {
  275. br := new(models.BaseResponse).Init()
  276. defer func() {
  277. this.Data["json"] = br
  278. this.ServeJSON()
  279. }()
  280. var req ppt_english.ReqMoveGroupPpt
  281. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  282. if err != nil {
  283. br.Msg = "参数解析异常!"
  284. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  285. return
  286. }
  287. if req.GroupId <= 0 {
  288. br.Msg = "请输入目录ID"
  289. return
  290. }
  291. err = ppt.MoveGroupPptEnglish(req.GroupId, req.GroupPptId, req.PrevGroupPptId, req.NextGroupPptId, this.SysUser.AdminId)
  292. if err != nil {
  293. br.Msg = err.Error()
  294. return
  295. }
  296. br.Ret = 200
  297. br.Success = true
  298. br.Msg = "移动成功"
  299. }
  300. // MoveGroup
  301. // @Title 移动目录
  302. // @Description 移动目录接口
  303. // @Param request body ppt_english.ReqMoveGroup true "type json string"
  304. // @Success 200 Ret=200 移动成功
  305. // @router /group/move [post]
  306. func (this *PptEnglishGroupController) MoveGroup() {
  307. br := new(models.BaseResponse).Init()
  308. defer func() {
  309. this.Data["json"] = br
  310. this.ServeJSON()
  311. }()
  312. var req ppt_english.ReqMoveGroup
  313. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  314. if err != nil {
  315. br.Msg = "参数解析异常!"
  316. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  317. return
  318. }
  319. if req.GroupId <= 0 {
  320. br.Msg = "请输入目录ID"
  321. return
  322. }
  323. err = ppt.MoveEnglishGroup(req.GroupId, req.PrevGroupId, req.NextGroupId, this.SysUser.AdminId)
  324. if err != nil {
  325. br.Msg = err.Error()
  326. return
  327. }
  328. br.Ret = 200
  329. br.Success = true
  330. br.Msg = "移动成功"
  331. }
  332. // CopyPpt
  333. // @Title 复制单个ppt
  334. // @Description 复制目录接口
  335. // @Param request body ppt_english.ReqCopyPpt true "type json string"
  336. // @Success 200 Ret=200 复制成功
  337. // @router /copy [post]
  338. func (this *PptEnglishGroupController) CopyPpt() {
  339. br := new(models.BaseResponse).Init()
  340. defer func() {
  341. this.Data["json"] = br
  342. this.ServeJSON()
  343. }()
  344. var req ppt_english.ReqCopyPpt
  345. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  346. if err != nil {
  347. br.Msg = "参数解析异常!"
  348. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  349. return
  350. }
  351. if req.GroupId <= 0 {
  352. br.Msg = "请输入目录ID"
  353. return
  354. }
  355. if req.PptId <= 0 {
  356. br.Msg = "请输入ppt ID"
  357. return
  358. }
  359. data, err := ppt.CopyPptEnglish(req.PptId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  360. if err != nil {
  361. br.Msg = err.Error()
  362. return
  363. }
  364. br.Ret = 200
  365. br.Success = true
  366. br.Msg = "复制成功"
  367. br.Data = data
  368. return
  369. }
  370. // GroupNameList
  371. // @Title 查询目录名称列表
  372. // @Description 查询目录名称列表接口
  373. // @Success 200 {object} ppt_english.RespPptGroupNameList
  374. // @router /group/name [get]
  375. func (this *PptEnglishGroupController) GroupNameList() {
  376. br := new(models.BaseResponse).Init()
  377. defer func() {
  378. this.Data["json"] = br
  379. this.ServeJSON()
  380. }()
  381. list, err := ppt_english.GetPptGroupIdAndGroupNameByAdminId(this.SysUser.AdminId)
  382. if err != nil {
  383. br.Msg = "查询目录名称出错" + err.Error()
  384. return
  385. }
  386. data := &ppt_english.RespPptGroupNameList{
  387. List: list,
  388. }
  389. br.Ret = 200
  390. br.Success = true
  391. br.Msg = "查询成功"
  392. br.Data = data
  393. return
  394. }
  395. // SearchGroupPptList
  396. // @Title 按ppt关键词搜索列表
  397. // @Description 按ppt关键词搜索列表接口
  398. // @Param KeyWord query int true "搜索关键词"
  399. // @Success 200 {object} ppt_english.RespSearchGroupPptList
  400. // @router /group/ppt/search [get]
  401. func (this *PptEnglishGroupController) SearchGroupPptList() {
  402. br := new(models.BaseResponse).Init()
  403. defer func() {
  404. this.Data["json"] = br
  405. this.ServeJSON()
  406. }()
  407. keyWord := this.GetString("KeyWord")
  408. data, err := ppt.SearchGroupPptEnglish(keyWord)
  409. if err != nil {
  410. br.Msg = err.Error()
  411. return
  412. }
  413. br.Ret = 200
  414. br.Success = true
  415. br.Msg = "查询成功"
  416. br.Data = data
  417. return
  418. }
  419. // SharePptList
  420. // @Title 获取用户开放的公共Ppt
  421. // @Description 获取用户开放的公共Ppt接口
  422. // @Param AdminId query int true "创建人ID"
  423. // @Param Keyword query string true "关键字"
  424. // @Param IsPrivate query bool false "是否为私有"
  425. // @Success 200 {object} ppt_english.RespGroupPptList
  426. // @router /share/ppt/list [get]
  427. func (this *PptEnglishGroupController) SharePptList() {
  428. br := new(models.BaseResponse).Init()
  429. defer func() {
  430. this.Data["json"] = br
  431. this.ServeJSON()
  432. }()
  433. adminId, _ := this.GetInt("AdminId")
  434. keyword := this.GetString("Keyword")
  435. isPrivate, _ := this.GetBool("IsPrivate", false)
  436. if isPrivate && adminId <= 0 {
  437. br.Msg = "参数有误, 私有PPT创建人ID不可为空"
  438. return
  439. }
  440. data, err := ppt.GetSharePptEnglishList(adminId, keyword, isPrivate)
  441. if err != nil {
  442. br.Msg = err.Error()
  443. return
  444. }
  445. br.Ret = 200
  446. br.Success = true
  447. br.Msg = "查询成功"
  448. br.Data = data
  449. return
  450. }
  451. // GrantPptList
  452. // @Title 获取用户共享的公共Ppt(分配权限的Ppt)
  453. // @Description 获取用户共享的公共Ppt(分配权限的Ppt)接口
  454. // @Param GroupId query int true "分组ID,唉,其实不知道用啥名,就这么用吧"
  455. // @Param Keyword query string true "关键字"
  456. // @Success 200 {object} ppt_english.RespGroupPptList
  457. // @router /grant/ppt/list [get]
  458. func (this *PptEnglishGroupController) GrantPptList() {
  459. br := new(models.BaseResponse).Init()
  460. defer func() {
  461. this.Data["json"] = br
  462. this.ServeJSON()
  463. }()
  464. groupId, _ := this.GetInt("GroupId")
  465. keyword := this.GetString("Keyword")
  466. var sourceType string
  467. switch groupId {
  468. case 1:
  469. sourceType = "my"
  470. case 2:
  471. sourceType = "other"
  472. default:
  473. br.Msg = "错误的来源"
  474. br.IsSendEmail = false
  475. return
  476. }
  477. data, err := ppt.GetGrantPptEnglishList(this.SysUser.AdminId, keyword, sourceType)
  478. if err != nil {
  479. br.Msg = err.Error()
  480. return
  481. }
  482. br.Ret = 200
  483. br.Success = true
  484. br.Msg = "查询成功"
  485. br.Data = data
  486. return
  487. }
  488. // ListSearch
  489. // @Title 我的/公开PPT搜索
  490. // @Description 我的/公开PPT搜索
  491. // @Param Keyword query string true "关键字"
  492. // @Success 200 {object} ppt_english.RespGroupPptList
  493. // @router /ppt/search [get]
  494. func (this *PptEnglishGroupController) ListSearch() {
  495. br := new(models.BaseResponse).Init()
  496. defer func() {
  497. if br.ErrMsg == "" {
  498. br.IsSendEmail = false
  499. }
  500. this.Data["json"] = br
  501. this.ServeJSON()
  502. }()
  503. sysUser := this.SysUser
  504. if sysUser == nil {
  505. br.Msg = "请登录"
  506. br.ErrMsg = "请登录,SysUser Is Empty"
  507. br.Ret = 408
  508. return
  509. }
  510. keyword := this.GetString("Keyword")
  511. keyword = strings.TrimSpace(keyword)
  512. data, err := ppt.SearchEnglishPptList(sysUser.AdminId, keyword)
  513. if err != nil {
  514. br.Msg = err.Error()
  515. return
  516. }
  517. br.Ret = 200
  518. br.Success = true
  519. br.Msg = "查询成功"
  520. br.Data = data
  521. }