ppt_english.go 20 KB

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