ppt_english.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/models/company"
  6. "eta/eta_mobile/models/ppt_english"
  7. "eta/eta_mobile/services/ppt"
  8. "eta/eta_mobile/utils"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. _ "image/gif"
  11. _ "image/jpeg"
  12. _ "image/png"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // PptEnglishController 新版ppt模块
  18. type PptEnglishController struct {
  19. BaseAuthController
  20. }
  21. // PptEnglishCommonController 新版ppt公共模块
  22. type PptEnglishCommonController struct {
  23. BaseCommonController
  24. }
  25. // ListPpt
  26. // @Title 获取ppt列表
  27. // @Description 获取ppt列表接口
  28. // @Param PageSize query int true "每页数据条数"
  29. // @Param CurrentIndex query int true "当前页页码,从1开始"
  30. // @Param KeyWord query string true "搜索关键词"
  31. // @Success 200 {object} ppt_english.PptEnglishListResp
  32. // @router /list [get]
  33. func (this *PptEnglishController) ListPpt() {
  34. br := new(models.BaseResponse).Init()
  35. defer func() {
  36. this.Data["json"] = br
  37. this.ServeJSON()
  38. }()
  39. sysUser := this.SysUser
  40. if sysUser == nil {
  41. br.Msg = "请登录"
  42. br.ErrMsg = "请登录,SysUser Is Empty"
  43. return
  44. }
  45. pageSize, _ := this.GetInt("PageSize")
  46. currentIndex, _ := this.GetInt("CurrentIndex")
  47. keyWord := this.GetString("KeyWord")
  48. var startSize int
  49. if pageSize <= 0 {
  50. pageSize = utils.PageSize20
  51. }
  52. if currentIndex <= 0 {
  53. currentIndex = 1
  54. }
  55. startSize = utils.StartIndex(currentIndex, pageSize)
  56. var condition string
  57. var pars []interface{}
  58. if keyWord != "" {
  59. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  60. pars = append(pars, "%"+keyWord+"%", "%"+keyWord+"%")
  61. }
  62. total, err := ppt_english.GetPptEnglishListCount(condition, pars)
  63. if err != nil {
  64. br.Msg = "获取失败"
  65. br.ErrMsg = "获取失败,Err:" + err.Error()
  66. return
  67. }
  68. list, err := ppt_english.GetPptEnglishList(condition, pars, startSize, pageSize)
  69. if err != nil {
  70. br.Msg = "获取失败"
  71. br.ErrMsg = "获取失败,Err:" + err.Error()
  72. return
  73. }
  74. lenList := len(list)
  75. for i := 0; i < lenList; i++ {
  76. adminId := list[i].AdminId
  77. if adminId == sysUser.AdminId || sysUser.Role == "admin" {
  78. list[i].IsAuth = true
  79. } else {
  80. list[i].IsAuth = false
  81. }
  82. }
  83. page := paging.GetPaging(currentIndex, pageSize, total)
  84. resp := new(ppt_english.PptEnglishListResp)
  85. resp.Paging = page
  86. resp.List = list
  87. br.Ret = 200
  88. br.Success = true
  89. br.Msg = "获取成功"
  90. br.Data = resp
  91. }
  92. // AddPpt
  93. // @Title 新增ppt
  94. // @Description 新增ppt接口
  95. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  96. // @Success 200 Ret=200 新增成功
  97. // @router /add [post]
  98. func (this *PptEnglishController) AddPpt() {
  99. br := new(models.BaseResponse).Init()
  100. defer func() {
  101. this.Data["json"] = br
  102. this.ServeJSON()
  103. }()
  104. var req ppt_english.AddPptEnglishReq
  105. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  106. if err != nil {
  107. br.Msg = "参数解析异常!"
  108. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  109. return
  110. }
  111. if req.FirstPage.Title == "" {
  112. br.Msg = "标题不能为空"
  113. return
  114. }
  115. var newId int64
  116. var msg string
  117. if req.PptId <= 0 {
  118. if req.GroupId == 0 {
  119. br.Msg = "请输入目录ID"
  120. return
  121. }
  122. item, err := ppt_english.GetPptEnglishByTitle(req.FirstPage.Title)
  123. if err != nil && err.Error() != utils.ErrNoRow() {
  124. br.Msg = "获取数据异常!"
  125. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  126. return
  127. }
  128. if item != nil {
  129. br.Msg = "标题已存在,不可重复添加"
  130. br.IsSendEmail = false
  131. return
  132. }
  133. pptInfo := &ppt_english.PptEnglish{
  134. //PptId: 0,
  135. TemplateType: req.FirstPage.TemplateType,
  136. BackgroundImg: req.FirstPage.ImgUrl,
  137. Title: req.FirstPage.Title,
  138. ReportType: req.FirstPage.ReportType,
  139. PptDate: req.FirstPage.PptDate,
  140. Content: req.Content,
  141. CreateTime: time.Now(),
  142. ModifyTime: time.Now(),
  143. AdminId: this.SysUser.AdminId,
  144. AdminRealName: this.SysUser.RealName,
  145. }
  146. newId, err = ppt_english.AddPptEnglish(pptInfo)
  147. if err != nil {
  148. br.Msg = "新增失败"
  149. br.ErrMsg = "新增失败,Err:" + err.Error()
  150. return
  151. }
  152. //新增ppt和目录映射
  153. _, err = ppt.AddGroupPptEnglishMapping(newId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  154. if err != nil {
  155. br.Msg = err.Error()
  156. return
  157. }
  158. msg = "新增成功"
  159. } else {
  160. newId = req.PptId
  161. pptInfo, err := ppt_english.GetPptEnglishById(int(req.PptId))
  162. if err != nil {
  163. br.Msg = "信息获取失败"
  164. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  165. return
  166. }
  167. pptInfo.TemplateType = req.FirstPage.TemplateType
  168. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  169. pptInfo.Title = req.FirstPage.Title
  170. pptInfo.ReportType = req.FirstPage.ReportType
  171. pptInfo.PptDate = req.FirstPage.PptDate
  172. pptInfo.Content = req.Content
  173. pptInfo.ModifyTime = time.Now()
  174. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  175. msg = "保存成功"
  176. }
  177. resp := ppt_english.AddPptEnglishResp{
  178. PptId: newId,
  179. }
  180. br.Ret = 200
  181. br.Success = true
  182. br.Msg = msg
  183. br.Data = resp
  184. }
  185. // EditPpt
  186. // @Title 编辑ppt
  187. // @Description 编辑ppt接口
  188. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  189. // @Success 200 Ret=200 编辑成功
  190. // @router /edit [post]
  191. func (this *PptEnglishController) EditPpt() {
  192. br := new(models.BaseResponse).Init()
  193. defer func() {
  194. this.Data["json"] = br
  195. this.ServeJSON()
  196. }()
  197. var req ppt_english.AddPptEnglishReq
  198. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  199. if err != nil {
  200. br.Msg = "参数解析异常!"
  201. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  202. return
  203. }
  204. if req.FirstPage.Title == "" {
  205. br.Msg = "标题不能为空"
  206. return
  207. }
  208. item, err := ppt_english.GetPptEnglishByTitle(req.FirstPage.Title)
  209. if err != nil && err.Error() != utils.ErrNoRow() {
  210. br.Msg = "获取数据异常!"
  211. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  212. return
  213. }
  214. if item != nil && item.PptId != int(req.PptId) {
  215. br.Msg = "标题已存在,不可重复添加"
  216. br.IsSendEmail = false
  217. return
  218. }
  219. pptInfo, err := ppt_english.GetPptEnglishById(int(req.PptId))
  220. if err != nil {
  221. br.Msg = "信息获取失败"
  222. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  223. return
  224. }
  225. // 判断权限
  226. if pptInfo.AdminId != this.SysUser.AdminId {
  227. _, err := ppt_english.GetPPtGrantConf(pptInfo.PptId, this.SysUser.AdminId)
  228. if err != nil {
  229. if err.Error() == utils.ErrNoRow() {
  230. br.Msg = `该PPT已取消共享,保存失败`
  231. br.ErrMsg = `该PPT已取消共享,保存失败`
  232. br.IsSendEmail = false
  233. } else {
  234. br.Msg = `保存失败`
  235. br.ErrMsg = `保存失败,ERR:` + err.Error()
  236. }
  237. return
  238. }
  239. }
  240. // 修改
  241. pptInfo.TemplateType = req.FirstPage.TemplateType
  242. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  243. pptInfo.Title = req.FirstPage.Title
  244. pptInfo.ReportType = req.FirstPage.ReportType
  245. pptInfo.PptDate = req.FirstPage.PptDate
  246. pptInfo.Content = req.Content
  247. pptInfo.ModifyTime = time.Now()
  248. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  249. if err != nil {
  250. br.Msg = "编辑失败"
  251. br.ErrMsg = "编辑失败,Err:" + err.Error()
  252. return
  253. }
  254. // 日志记录
  255. {
  256. logInfo := &ppt_english.PptEnglishSaveLog{
  257. PptId: pptInfo.PptId,
  258. TemplateType: pptInfo.TemplateType,
  259. BackgroundImg: pptInfo.BackgroundImg,
  260. Title: pptInfo.Title,
  261. ReportType: pptInfo.ReportType,
  262. PptDate: pptInfo.PptDate,
  263. Content: pptInfo.Content,
  264. AdminId: this.SysUser.AdminId,
  265. AdminRealName: this.SysUser.RealName,
  266. CreateTime: time.Now(),
  267. }
  268. _, err = ppt_english.AddPptEnglishSaveLog(logInfo)
  269. }
  270. resp := ppt_english.AddPptEnglishResp{
  271. PptId: req.PptId,
  272. }
  273. br.Ret = 200
  274. br.Success = true
  275. br.Msg = "编辑成功"
  276. br.IsAddLog = true
  277. br.Data = resp
  278. }
  279. // DeletePpt
  280. // @Title 删除ppt
  281. // @Description 删除ppt接口
  282. // @Param request body ppt_english.DeletePptEnglishReq true "type json string"
  283. // @Success 200 Ret=200 删除成功
  284. // @router /delete [post]
  285. func (this *PptEnglishController) DeletePpt() {
  286. br := new(models.BaseResponse).Init()
  287. defer func() {
  288. this.Data["json"] = br
  289. this.ServeJSON()
  290. }()
  291. var req ppt_english.DeletePptEnglishReq
  292. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  293. if err != nil {
  294. br.Msg = "参数解析异常!"
  295. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  296. return
  297. }
  298. if req.PptId <= 0 {
  299. br.Msg = "参数错误"
  300. return
  301. }
  302. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  303. if err != nil {
  304. br.Msg = "ppt不存在"
  305. return
  306. }
  307. if pptInfo.AdminId != this.SysUser.AdminId {
  308. br.Msg = "无权删除"
  309. return
  310. }
  311. err = ppt_english.DeletePptEnglish(req.PptId)
  312. if err != nil {
  313. br.Msg = "删除失败"
  314. br.ErrMsg = "删除失败,Err:" + err.Error()
  315. return
  316. }
  317. //如果该ppt存在单个共享记录,则删除共享
  318. err = ppt.DeleteGroupPptEnglish(req.PptId)
  319. if err != nil {
  320. br.Msg = "删除失败"
  321. br.ErrMsg = "删除失败,Err:" + err.Error()
  322. return
  323. }
  324. br.Ret = 200
  325. br.Success = true
  326. br.IsAddLog = true
  327. br.Msg = "删除成功"
  328. }
  329. // DetailPpt
  330. // @Title 获取ppt详情
  331. // @Description 获取ppt详情接口
  332. // @Param PptId query int true "PptId"
  333. // @Success 200 {object} ppt_english.PptEnglish
  334. // @router /detail [get]
  335. func (this *PptEnglishController) DetailPpt() {
  336. br := new(models.BaseResponse).Init()
  337. defer func() {
  338. this.Data["json"] = br
  339. this.ServeJSON()
  340. }()
  341. pptId, _ := this.GetInt("PptId")
  342. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  343. if err != nil {
  344. br.Msg = "信息获取失败"
  345. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  346. return
  347. }
  348. br.Ret = 200
  349. br.Success = true
  350. br.Msg = "获取成功"
  351. br.Data = pptInfo
  352. }
  353. // DownloadPptx
  354. // @Title ppt下载
  355. // @Description ppt下载
  356. // @Param PptId query int true "PptId"
  357. // @Success 200 下载成功
  358. // @router /downloadpptx [get]
  359. func (this *PptEnglishCommonController) DownloadPptx() {
  360. br := new(models.BaseResponse).Init()
  361. defer func() {
  362. this.Data["json"] = br
  363. this.ServeJSON()
  364. }()
  365. pptId, err := this.GetInt("PptId")
  366. if err != nil {
  367. br.Msg = "参数错误"
  368. br.ErrMsg = "获取,pptId,Err:" + err.Error()
  369. return
  370. }
  371. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  372. if err != nil {
  373. br.Msg = "获取信息失败"
  374. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  375. return
  376. }
  377. filePath := pptInfo.PptxUrl
  378. fileName := pptInfo.Title + ".pptx"
  379. this.Ctx.Output.Download(filePath, fileName)
  380. br.Success = true
  381. br.Ret = 200
  382. br.Msg = "下载成功"
  383. return
  384. }
  385. // Publish
  386. // @Title 发布接口
  387. // @Description 发布接口
  388. // @Param request body ppt_english.SavePptEnglishPathReq true "type json string"
  389. // @Success Ret=200 发布成功
  390. // @router /publish [post]
  391. func (this *PptEnglishController) Publish() {
  392. br := new(models.BaseResponse).Init()
  393. defer func() {
  394. this.Data["json"] = br
  395. this.ServeJSON()
  396. }()
  397. //SavePptEnglishPathReq
  398. //PptEnglishPublishReq
  399. var req ppt_english.SavePptEnglishPathReq
  400. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  401. if err != nil {
  402. br.Msg = "参数解析异常!"
  403. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  404. return
  405. }
  406. pptId := req.PptId
  407. if pptId <= 0 {
  408. br.Msg = "参数错误"
  409. return
  410. }
  411. err = ppt_english.EditPptEnglishPath(pptId, req.PptxUrl)
  412. if err != nil {
  413. br.Msg = "发布失败"
  414. br.ErrMsg = "发布失败,Err:" + err.Error()
  415. return
  416. }
  417. //添加发布记录
  418. {
  419. record := new(ppt_english.PptEnglishPublishRecord)
  420. record.CreateTime = time.Now()
  421. record.PptId = pptId
  422. record.PptUrl = req.PptxUrl
  423. go ppt_english.AddPptEnglishPublishRecord(record)
  424. }
  425. br.Ret = 200
  426. br.Success = true
  427. br.Msg = "发布成功"
  428. br.IsAddLog = true
  429. return
  430. }
  431. // SaveLog
  432. // @Title 定时ppt操作日志记录
  433. // @Description 定时ppt操作日志记录
  434. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  435. // @Success 200 新增成功
  436. // @router /saveLog [post]
  437. func (this *PptEnglishController) SaveLog() {
  438. br := new(models.BaseResponse).Init()
  439. defer func() {
  440. this.Data["json"] = br
  441. this.ServeJSON()
  442. }()
  443. var req ppt_english.AddPptEnglishReq
  444. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  445. if err != nil {
  446. br.Msg = "参数解析异常!"
  447. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  448. return
  449. }
  450. if req.FirstPage.Title == "" {
  451. br.Msg = "标题不能为空"
  452. return
  453. }
  454. // 获取ppt
  455. item, err := ppt_english.GetPptEnglishByTitle(req.FirstPage.Title)
  456. if err != nil && err.Error() != utils.ErrNoRow() {
  457. br.Msg = "获取数据异常!"
  458. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  459. return
  460. }
  461. if item != nil && item.PptId != int(req.PptId) {
  462. br.Msg = "标题已存在,不可重复添加"
  463. br.IsSendEmail = false
  464. return
  465. }
  466. //变更ppt内容
  467. _, err = ppt_english.GetPptEnglishById(int(req.PptId))
  468. if err != nil {
  469. br.Msg = "信息获取失败"
  470. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  471. return
  472. }
  473. //pptInfo.TemplateType = req.FirstPage.TemplateType
  474. //pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  475. //pptInfo.Title = req.FirstPage.Title
  476. //pptInfo.ReportType = req.FirstPage.ReportType
  477. //pptInfo.PptDate = req.FirstPage.PptDate
  478. //pptInfo.Content = req.Content
  479. //pptInfo.ModifyTime = time.Now()
  480. //err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  481. //日志记录
  482. logInfo := &ppt_english.PptEnglishSaveLog{
  483. PptId: int(req.PptId),
  484. TemplateType: req.FirstPage.TemplateType,
  485. BackgroundImg: req.FirstPage.ImgUrl,
  486. Title: req.FirstPage.Title,
  487. ReportType: req.FirstPage.ReportType,
  488. PptDate: req.FirstPage.PptDate,
  489. Content: req.Content,
  490. AdminId: this.SysUser.AdminId,
  491. AdminRealName: this.SysUser.RealName,
  492. CreateTime: time.Now(),
  493. }
  494. _, err = ppt_english.AddPptEnglishSaveLog(logInfo)
  495. if err != nil {
  496. }
  497. br.Ret = 200
  498. br.Success = true
  499. br.Msg = "保存成功"
  500. }
  501. // GetConfig
  502. // @Title 获取ppt配置
  503. // @Description 获取ppt列表接口
  504. // @Param PageSize query int true "每页数据条数"
  505. // @Param CurrentIndex query int true "当前页页码,从1开始"
  506. // @Param KeyWord query string true "搜索关键词"
  507. // @Success 200 {object} ppt_english.PptEnglishListResp
  508. // @router /config [get]
  509. func (this *PptEnglishController) GetConfig() {
  510. br := new(models.BaseResponse).Init()
  511. defer func() {
  512. this.Data["json"] = br
  513. this.ServeJSON()
  514. }()
  515. crmConfig, err := company.GetConfigDetailByCode("ppt_limit")
  516. if err != nil {
  517. br.Msg = "获取配置失败"
  518. br.ErrMsg = "获取配置失败"
  519. br.IsSendEmail = false
  520. return
  521. }
  522. resp := new(ppt_english.PptEnglishConfigResp)
  523. err = json.Unmarshal([]byte(crmConfig.ConfigValue), resp)
  524. if err != nil {
  525. br.Msg = "获取配置失败"
  526. br.ErrMsg = "获取配置失败;err:" + err.Error()
  527. br.IsSendEmail = false
  528. return
  529. }
  530. br.Ret = 200
  531. br.Success = true
  532. br.Msg = "获取成功"
  533. br.Data = resp
  534. }
  535. // Grant
  536. // @Title 分配ppt权限
  537. // @Description 分配ppt权限接口
  538. // @Param request body ppt_english.GrantPptReq true "type json string"
  539. // @Success 200 Ret=200 分配成功
  540. // @router /grant [post]
  541. func (this *PptEnglishController) Grant() {
  542. br := new(models.BaseResponse).Init()
  543. defer func() {
  544. this.Data["json"] = br
  545. this.ServeJSON()
  546. }()
  547. var req ppt_english.GrantPptReq
  548. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  549. if err != nil {
  550. br.Msg = "参数解析异常!"
  551. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  552. return
  553. }
  554. if req.PptId <= 0 {
  555. br.Msg = "参数错误"
  556. return
  557. }
  558. // 查找ppt信息
  559. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  560. if err != nil {
  561. br.Msg = "ppt不存在"
  562. return
  563. }
  564. if pptInfo.AdminId != this.SysUser.AdminId {
  565. br.Msg = "无权配置"
  566. return
  567. }
  568. // 分配
  569. err, errMsg := ppt.GrantPptEnglish(req.PptId, req.GrantType, req.AdminIdStr, this.SysUser.AdminId)
  570. if errMsg != `` {
  571. br.Msg = errMsg
  572. br.ErrMsg = errMsg
  573. if err != nil {
  574. br.ErrMsg = errMsg + ";Err:" + err.Error()
  575. } else {
  576. br.IsSendEmail = false
  577. }
  578. return
  579. }
  580. br.Ret = 200
  581. br.Success = true
  582. br.IsAddLog = true
  583. br.Msg = "分配成功"
  584. }
  585. // CancelGrant
  586. // @Title 取消分配ppt权限
  587. // @Description 取消分配ppt权限
  588. // @Param request body ppt_english.DeletePptEnglishReq true "type json string"
  589. // @Success 200 Ret=200 分配成功
  590. // @router /grant/cancel [post]
  591. func (this *PptEnglishController) CancelGrant() {
  592. br := new(models.BaseResponse).Init()
  593. defer func() {
  594. this.Data["json"] = br
  595. this.ServeJSON()
  596. }()
  597. var req ppt_english.DeletePptEnglishReq
  598. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  599. if err != nil {
  600. br.Msg = "参数解析异常!"
  601. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  602. return
  603. }
  604. if req.PptId <= 0 {
  605. br.Msg = "参数错误"
  606. return
  607. }
  608. // 查找ppt信息
  609. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  610. if err != nil {
  611. br.Msg = "ppt不存在"
  612. return
  613. }
  614. if pptInfo.AdminId != this.SysUser.AdminId {
  615. br.Msg = "无权取消配置"
  616. return
  617. }
  618. // 分配
  619. err, errMsg := ppt.DeleteGrantPptEnglish(req.PptId)
  620. if errMsg != `` {
  621. br.Msg = errMsg
  622. br.ErrMsg = errMsg
  623. if err != nil {
  624. br.ErrMsg = errMsg + ";Err:" + err.Error()
  625. } else {
  626. br.IsSendEmail = false
  627. }
  628. return
  629. }
  630. br.Ret = 200
  631. br.Success = true
  632. br.IsAddLog = true
  633. br.Msg = "取消成功"
  634. }
  635. // GrantInfo
  636. // @Title 获取分配ppt权限详情
  637. // @Description 获取分配ppt权限详情接口
  638. // @Param PptId query int true "ppt的id"
  639. // @Success 200 {object} ppt_english.GrantInfoResp
  640. // @router /grant/info [get]
  641. func (this *PptEnglishController) GrantInfo() {
  642. br := new(models.BaseResponse).Init()
  643. defer func() {
  644. this.Data["json"] = br
  645. this.ServeJSON()
  646. }()
  647. pptId, _ := this.GetInt("PptId")
  648. if pptId <= 0 {
  649. br.Msg = "参数错误"
  650. return
  651. }
  652. // 查找ppt信息
  653. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  654. if err != nil {
  655. br.Msg = "ppt不存在"
  656. return
  657. }
  658. if pptInfo.AdminId != this.SysUser.AdminId {
  659. br.Msg = "无权配置"
  660. return
  661. }
  662. pptGrantInfoList, err := ppt_english.GetPPtGrantInfo(pptId)
  663. if err != nil {
  664. br.Msg = "信息获取失败"
  665. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  666. return
  667. }
  668. if len(pptGrantInfoList) <= 0 {
  669. br.Msg = "未配置"
  670. br.IsSendEmail = false
  671. return
  672. }
  673. grantType := 0
  674. var adminIdStr string
  675. if pptGrantInfoList[0].DepartmentId > 0 { //分配类型;1:全部ficc研究员;2:指定成员
  676. grantType = 1
  677. } else {
  678. grantType = 2
  679. adminIdsList := make([]string, 0)
  680. for _, v := range pptGrantInfoList {
  681. adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
  682. }
  683. adminIdStr = strings.Join(adminIdsList, ",")
  684. }
  685. br.Ret = 200
  686. br.Success = true
  687. br.Data = ppt_english.GrantInfoResp{
  688. PptId: pptId,
  689. GrantType: grantType,
  690. AdminIdStr: adminIdStr,
  691. }
  692. br.Msg = "分配成功"
  693. }