ppt_english_group.go 14 KB

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