ppt_english.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/company"
  6. "eta/eta_api/models/ppt_english"
  7. "eta/eta_api/services"
  8. "eta/eta_api/services/ppt"
  9. "eta/eta_api/utils"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. _ "image/gif"
  12. _ "image/jpeg"
  13. _ "image/png"
  14. "os"
  15. "path"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // PptEnglishController 新版ppt模块
  21. type PptEnglishController struct {
  22. BaseAuthController
  23. }
  24. // PptEnglishCommonController 新版ppt公共模块
  25. type PptEnglishCommonController struct {
  26. BaseCommonController
  27. }
  28. // ListPpt
  29. // @Title 获取ppt列表
  30. // @Description 获取ppt列表接口
  31. // @Param PageSize query int true "每页数据条数"
  32. // @Param CurrentIndex query int true "当前页页码,从1开始"
  33. // @Param KeyWord query string true "搜索关键词"
  34. // @Success 200 {object} ppt_english.PptEnglishListResp
  35. // @router /list [get]
  36. func (this *PptEnglishController) ListPpt() {
  37. br := new(models.BaseResponse).Init()
  38. defer func() {
  39. this.Data["json"] = br
  40. this.ServeJSON()
  41. }()
  42. sysUser := this.SysUser
  43. if sysUser == nil {
  44. br.Msg = "请登录"
  45. br.ErrMsg = "请登录,SysUser Is Empty"
  46. return
  47. }
  48. pageSize, _ := this.GetInt("PageSize")
  49. currentIndex, _ := this.GetInt("CurrentIndex")
  50. keyWord := this.GetString("KeyWord")
  51. var startSize int
  52. if pageSize <= 0 {
  53. pageSize = utils.PageSize20
  54. }
  55. if currentIndex <= 0 {
  56. currentIndex = 1
  57. }
  58. startSize = utils.StartIndex(currentIndex, pageSize)
  59. var condition string
  60. var pars []interface{}
  61. if keyWord != "" {
  62. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  63. pars = append(pars, "%"+keyWord+"%", "%"+keyWord+"%")
  64. }
  65. total, err := ppt_english.GetPptEnglishListCount(condition, pars)
  66. if err != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取失败,Err:" + err.Error()
  69. return
  70. }
  71. list, err := ppt_english.GetPptEnglishList(condition, pars, startSize, pageSize)
  72. if err != nil {
  73. br.Msg = "获取失败"
  74. br.ErrMsg = "获取失败,Err:" + err.Error()
  75. return
  76. }
  77. lenList := len(list)
  78. for i := 0; i < lenList; i++ {
  79. adminId := list[i].AdminId
  80. if adminId == sysUser.AdminId || sysUser.Role == "admin" {
  81. list[i].IsAuth = true
  82. } else {
  83. list[i].IsAuth = false
  84. }
  85. }
  86. page := paging.GetPaging(currentIndex, pageSize, total)
  87. resp := new(ppt_english.PptEnglishListResp)
  88. resp.Paging = page
  89. resp.List = list
  90. br.Ret = 200
  91. br.Success = true
  92. br.Msg = "获取成功"
  93. br.Data = resp
  94. }
  95. // AddPpt
  96. // @Title 新增ppt
  97. // @Description 新增ppt接口
  98. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  99. // @Success 200 Ret=200 新增成功
  100. // @router /add [post]
  101. func (this *PptEnglishController) AddPpt() {
  102. br := new(models.BaseResponse).Init()
  103. defer func() {
  104. this.Data["json"] = br
  105. this.ServeJSON()
  106. }()
  107. var req ppt_english.AddPptEnglishReq
  108. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  109. if err != nil {
  110. br.Msg = "参数解析异常!"
  111. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  112. return
  113. }
  114. if req.FirstPage.Title == "" {
  115. br.Msg = "标题不能为空"
  116. return
  117. }
  118. var newId int64
  119. var msg string
  120. if req.PptId <= 0 {
  121. if req.GroupId == 0 {
  122. br.Msg = "请输入目录ID"
  123. return
  124. }
  125. item, err := ppt_english.GetPptEnglishByTitle(req.FirstPage.Title)
  126. if err != nil && err.Error() != utils.ErrNoRow() {
  127. br.Msg = "获取数据异常!"
  128. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  129. return
  130. }
  131. if item != nil {
  132. br.Msg = "标题已存在,不可重复添加"
  133. br.IsSendEmail = false
  134. return
  135. }
  136. pptInfo := &ppt_english.PptEnglish{
  137. //PptId: 0,
  138. TemplateType: req.FirstPage.TemplateType,
  139. BackgroundImg: req.FirstPage.ImgUrl,
  140. Title: req.FirstPage.Title,
  141. ReportType: req.FirstPage.ReportType,
  142. PptDate: req.FirstPage.PptDate,
  143. Content: req.Content,
  144. CreateTime: time.Now(),
  145. ModifyTime: time.Now(),
  146. AdminId: this.SysUser.AdminId,
  147. AdminRealName: this.SysUser.RealName,
  148. }
  149. newId, err = ppt_english.AddPptEnglish(pptInfo)
  150. if err != nil {
  151. br.Msg = "新增失败"
  152. br.ErrMsg = "新增失败,Err:" + err.Error()
  153. return
  154. }
  155. //新增ppt和目录映射
  156. _, err = ppt.AddGroupPptEnglishMapping(newId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  157. if err != nil {
  158. br.Msg = err.Error()
  159. return
  160. }
  161. msg = "新增成功"
  162. } else {
  163. newId = req.PptId
  164. pptInfo, err := ppt_english.GetPptEnglishById(int(req.PptId))
  165. if err != nil {
  166. br.Msg = "信息获取失败"
  167. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  168. return
  169. }
  170. pptInfo.TemplateType = req.FirstPage.TemplateType
  171. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  172. pptInfo.Title = req.FirstPage.Title
  173. pptInfo.ReportType = req.FirstPage.ReportType
  174. pptInfo.PptDate = req.FirstPage.PptDate
  175. pptInfo.Content = req.Content
  176. pptInfo.ModifyTime = time.Now()
  177. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  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.GetPptEnglishByTitle(req.FirstPage.Title)
  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.ModifyTime = time.Now()
  251. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  252. if err != nil {
  253. br.Msg = "编辑失败"
  254. br.ErrMsg = "编辑失败,Err:" + err.Error()
  255. return
  256. }
  257. // 日志记录
  258. {
  259. logInfo := &ppt_english.PptEnglishSaveLog{
  260. PptId: pptInfo.PptId,
  261. TemplateType: pptInfo.TemplateType,
  262. BackgroundImg: pptInfo.BackgroundImg,
  263. Title: pptInfo.Title,
  264. ReportType: pptInfo.ReportType,
  265. PptDate: pptInfo.PptDate,
  266. Content: pptInfo.Content,
  267. AdminId: this.SysUser.AdminId,
  268. AdminRealName: this.SysUser.RealName,
  269. CreateTime: time.Now(),
  270. }
  271. _, err = ppt_english.AddPptEnglishSaveLog(logInfo)
  272. }
  273. resp := ppt_english.AddPptEnglishResp{
  274. PptId: req.PptId,
  275. }
  276. br.Ret = 200
  277. br.Success = true
  278. br.Msg = "编辑成功"
  279. br.IsAddLog = true
  280. br.Data = resp
  281. }
  282. // DeletePpt
  283. // @Title 删除ppt
  284. // @Description 删除ppt接口
  285. // @Param request body ppt_english.DeletePptEnglishReq true "type json string"
  286. // @Success 200 Ret=200 删除成功
  287. // @router /delete [post]
  288. func (this *PptEnglishController) DeletePpt() {
  289. br := new(models.BaseResponse).Init()
  290. defer func() {
  291. this.Data["json"] = br
  292. this.ServeJSON()
  293. }()
  294. var req ppt_english.DeletePptEnglishReq
  295. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  296. if err != nil {
  297. br.Msg = "参数解析异常!"
  298. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  299. return
  300. }
  301. if req.PptId <= 0 {
  302. br.Msg = "参数错误"
  303. return
  304. }
  305. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  306. if err != nil {
  307. br.Msg = "ppt不存在"
  308. return
  309. }
  310. if pptInfo.AdminId != this.SysUser.AdminId {
  311. br.Msg = "无权删除"
  312. return
  313. }
  314. err = ppt_english.DeletePptEnglish(req.PptId)
  315. if err != nil {
  316. br.Msg = "删除失败"
  317. br.ErrMsg = "删除失败,Err:" + err.Error()
  318. return
  319. }
  320. //如果该ppt存在单个共享记录,则删除共享
  321. err = ppt.DeleteGroupPptEnglish(req.PptId)
  322. if err != nil {
  323. br.Msg = "删除失败"
  324. br.ErrMsg = "删除失败,Err:" + err.Error()
  325. return
  326. }
  327. br.Ret = 200
  328. br.Success = true
  329. br.IsAddLog = true
  330. br.Msg = "删除成功"
  331. }
  332. // DetailPpt
  333. // @Title 获取ppt详情
  334. // @Description 获取ppt详情接口
  335. // @Param PptId query int true "PptId"
  336. // @Success 200 {object} ppt_english.PptEnglish
  337. // @router /detail [get]
  338. func (this *PptEnglishController) DetailPpt() {
  339. br := new(models.BaseResponse).Init()
  340. defer func() {
  341. this.Data["json"] = br
  342. this.ServeJSON()
  343. }()
  344. pptId, _ := this.GetInt("PptId")
  345. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  346. if err != nil {
  347. br.Msg = "信息获取失败"
  348. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  349. return
  350. }
  351. br.Ret = 200
  352. br.Success = true
  353. br.Msg = "获取成功"
  354. br.Data = pptInfo
  355. }
  356. // DownloadPptx
  357. // @Title ppt下载
  358. // @Description ppt下载
  359. // @Param PptId query int true "PptId"
  360. // @Success 200 下载成功
  361. // @router /downloadpptx [get]
  362. func (this *PptEnglishCommonController) DownloadPptx() {
  363. br := new(models.BaseResponse).Init()
  364. defer func() {
  365. this.Data["json"] = br
  366. this.ServeJSON()
  367. }()
  368. pptId, err := this.GetInt("PptId")
  369. if err != nil {
  370. br.Msg = "参数错误"
  371. br.ErrMsg = "获取,pptId,Err:" + err.Error()
  372. return
  373. }
  374. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  375. if err != nil {
  376. br.Msg = "获取信息失败"
  377. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  378. return
  379. }
  380. filePath := pptInfo.PptxUrl
  381. fileName := pptInfo.Title + ".pptx"
  382. this.Ctx.Output.Download(filePath, fileName)
  383. br.Success = true
  384. br.Ret = 200
  385. br.Msg = "下载成功"
  386. return
  387. }
  388. // Publish
  389. // @Title 发布接口
  390. // @Description 发布接口
  391. // @Param request body ppt_english.SavePptEnglishPathReq true "type json string"
  392. // @Success Ret=200 发布成功
  393. // @router /publish [post]
  394. func (this *PptEnglishController) Publish() {
  395. br := new(models.BaseResponse).Init()
  396. defer func() {
  397. this.Data["json"] = br
  398. this.ServeJSON()
  399. }()
  400. //SavePptEnglishPathReq
  401. //PptEnglishPublishReq
  402. var req ppt_english.SavePptEnglishPathReq
  403. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  404. if err != nil {
  405. br.Msg = "参数解析异常!"
  406. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  407. return
  408. }
  409. pptId := req.PptId
  410. if pptId <= 0 {
  411. br.Msg = "参数错误"
  412. return
  413. }
  414. err = ppt_english.EditPptEnglishPath(pptId, req.PptxUrl)
  415. if err != nil {
  416. br.Msg = "发布失败"
  417. br.ErrMsg = "发布失败,Err:" + err.Error()
  418. return
  419. }
  420. //添加发布记录
  421. {
  422. record := new(ppt_english.PptEnglishPublishRecord)
  423. record.CreateTime = time.Now()
  424. record.PptId = pptId
  425. record.PptUrl = req.PptxUrl
  426. go ppt_english.AddPptEnglishPublishRecord(record)
  427. }
  428. br.Ret = 200
  429. br.Success = true
  430. br.Msg = "发布成功"
  431. br.IsAddLog = true
  432. return
  433. }
  434. // PptUpload
  435. // @Title ppt上传
  436. // @Description ppt上传
  437. // @Param PptId query int true "PptId"
  438. // @Success 200 新增成功
  439. // @router /pptUpload [post]
  440. func (this *PptEnglishController) PptUpload() {
  441. br := new(models.BaseResponse).Init()
  442. defer func() {
  443. this.Data["json"] = br
  444. this.ServeJSON()
  445. }()
  446. pptId, _ := this.GetInt("PptId", 0)
  447. if pptId <= 0 {
  448. br.Msg = "参数错误"
  449. return
  450. }
  451. _, err := ppt_english.GetPptEnglishById(pptId)
  452. if err != nil {
  453. br.Msg = "获取数据失败"
  454. br.ErrMsg = "获取PPT详情失败,Err:" + err.Error()
  455. return
  456. }
  457. f, h, err := this.GetFile("file")
  458. if err != nil {
  459. br.Msg = "获取资源信息失败"
  460. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  461. return
  462. }
  463. uploadFileName := h.Filename //上传的文件名
  464. ext := path.Ext(h.Filename)
  465. dateDir := time.Now().Format("20060102")
  466. uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
  467. err = os.MkdirAll(uploadDir, 766)
  468. if err != nil {
  469. br.Msg = "存储目录创建失败"
  470. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  471. return
  472. }
  473. randStr := utils.GetRandStringNoSpecialChar(28)
  474. fileName := randStr + ext
  475. fpath := uploadDir + "/" + fileName
  476. defer f.Close() //关闭上传文件
  477. err = this.SaveToFile("file", fpath)
  478. if err != nil {
  479. br.Msg = "文件上传失败"
  480. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  481. return
  482. }
  483. hzUploadDir := "ppt/"
  484. savePptxToOssPath := hzUploadDir + time.Now().Format("200601/20060102/")
  485. //pptName := strings.Replace(pptItem.Title, "\n", "", -1)
  486. //pptName = strings.TrimSuffix(pptName, " ")
  487. pptName := utils.GetRandStringNoSpecialChar(28)
  488. savePptxToOssPath += pptName + ".pptx"
  489. //上传到阿里云
  490. err = services.UploadFileToAliyun("", fpath, savePptxToOssPath)
  491. if err != nil {
  492. br.Msg = "文件上传失败"
  493. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  494. return
  495. }
  496. pptxUrl := utils.Imghost + savePptxToOssPath
  497. defer func() {
  498. os.Remove(fpath)
  499. }()
  500. item := &models.Resource{
  501. //Id: 0,
  502. ResourceUrl: pptxUrl,
  503. CreateTime: time.Now(),
  504. ResourceType: 4,
  505. }
  506. newId, err := models.AddResource(item)
  507. if err != nil {
  508. br.Msg = "资源上传失败"
  509. br.ErrMsg = "资源上传失败,Err:" + err.Error()
  510. return
  511. }
  512. resp := models.ResourceResp{
  513. Id: newId,
  514. ResourceUrl: pptxUrl,
  515. ResourceName: uploadFileName,
  516. }
  517. br.Msg = "上传成功"
  518. br.Ret = 200
  519. br.Success = true
  520. br.Data = resp
  521. return
  522. }
  523. // SaveLog
  524. // @Title 定时ppt操作日志记录
  525. // @Description 定时ppt操作日志记录
  526. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  527. // @Success 200 新增成功
  528. // @router /saveLog [post]
  529. func (this *PptEnglishController) SaveLog() {
  530. br := new(models.BaseResponse).Init()
  531. defer func() {
  532. this.Data["json"] = br
  533. this.ServeJSON()
  534. }()
  535. var req ppt_english.AddPptEnglishReq
  536. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  537. if err != nil {
  538. br.Msg = "参数解析异常!"
  539. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  540. return
  541. }
  542. if req.FirstPage.Title == "" {
  543. br.Msg = "标题不能为空"
  544. return
  545. }
  546. // 获取ppt
  547. item, err := ppt_english.GetPptEnglishByTitle(req.FirstPage.Title)
  548. if err != nil && err.Error() != utils.ErrNoRow() {
  549. br.Msg = "获取数据异常!"
  550. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  551. return
  552. }
  553. if item != nil && item.PptId != int(req.PptId) {
  554. br.Msg = "标题已存在,不可重复添加"
  555. br.IsSendEmail = false
  556. return
  557. }
  558. //变更ppt内容
  559. _, err = ppt_english.GetPptEnglishById(int(req.PptId))
  560. if err != nil {
  561. br.Msg = "信息获取失败"
  562. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  563. return
  564. }
  565. //pptInfo.TemplateType = req.FirstPage.TemplateType
  566. //pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  567. //pptInfo.Title = req.FirstPage.Title
  568. //pptInfo.ReportType = req.FirstPage.ReportType
  569. //pptInfo.PptDate = req.FirstPage.PptDate
  570. //pptInfo.Content = req.Content
  571. //pptInfo.ModifyTime = time.Now()
  572. //err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  573. //日志记录
  574. logInfo := &ppt_english.PptEnglishSaveLog{
  575. PptId: int(req.PptId),
  576. TemplateType: req.FirstPage.TemplateType,
  577. BackgroundImg: req.FirstPage.ImgUrl,
  578. Title: req.FirstPage.Title,
  579. ReportType: req.FirstPage.ReportType,
  580. PptDate: req.FirstPage.PptDate,
  581. Content: req.Content,
  582. AdminId: this.SysUser.AdminId,
  583. AdminRealName: this.SysUser.RealName,
  584. CreateTime: time.Now(),
  585. }
  586. _, err = ppt_english.AddPptEnglishSaveLog(logInfo)
  587. if err != nil {
  588. }
  589. br.Ret = 200
  590. br.Success = true
  591. br.Msg = "保存成功"
  592. }
  593. // GetConfig
  594. // @Title 获取ppt配置
  595. // @Description 获取ppt列表接口
  596. // @Param PageSize query int true "每页数据条数"
  597. // @Param CurrentIndex query int true "当前页页码,从1开始"
  598. // @Param KeyWord query string true "搜索关键词"
  599. // @Success 200 {object} ppt_english.PptEnglishListResp
  600. // @router /config [get]
  601. func (this *PptEnglishController) GetConfig() {
  602. br := new(models.BaseResponse).Init()
  603. defer func() {
  604. this.Data["json"] = br
  605. this.ServeJSON()
  606. }()
  607. crmConfig, err := company.GetConfigDetailByCode("ppt_limit")
  608. if err != nil {
  609. br.Msg = "获取配置失败"
  610. br.ErrMsg = "获取配置失败"
  611. br.IsSendEmail = false
  612. return
  613. }
  614. resp := new(ppt_english.PptEnglishConfigResp)
  615. err = json.Unmarshal([]byte(crmConfig.ConfigValue), resp)
  616. if err != nil {
  617. br.Msg = "获取配置失败"
  618. br.ErrMsg = "获取配置失败;err:" + err.Error()
  619. br.IsSendEmail = false
  620. return
  621. }
  622. br.Ret = 200
  623. br.Success = true
  624. br.Msg = "获取成功"
  625. br.Data = resp
  626. }
  627. // Grant
  628. // @Title 分配ppt权限
  629. // @Description 分配ppt权限接口
  630. // @Param request body ppt_english.GrantPptReq true "type json string"
  631. // @Success 200 Ret=200 分配成功
  632. // @router /grant [post]
  633. func (this *PptEnglishController) Grant() {
  634. br := new(models.BaseResponse).Init()
  635. defer func() {
  636. this.Data["json"] = br
  637. this.ServeJSON()
  638. }()
  639. var req ppt_english.GrantPptReq
  640. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  641. if err != nil {
  642. br.Msg = "参数解析异常!"
  643. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  644. return
  645. }
  646. if req.PptId <= 0 {
  647. br.Msg = "参数错误"
  648. return
  649. }
  650. // 查找ppt信息
  651. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  652. if err != nil {
  653. br.Msg = "ppt不存在"
  654. return
  655. }
  656. if pptInfo.AdminId != this.SysUser.AdminId {
  657. br.Msg = "无权配置"
  658. return
  659. }
  660. // 分配
  661. err, errMsg := ppt.GrantPptEnglish(req.PptId, req.GrantType, req.AdminIdStr, this.SysUser.AdminId)
  662. if errMsg != `` {
  663. br.Msg = errMsg
  664. br.ErrMsg = errMsg
  665. if err != nil {
  666. br.ErrMsg = errMsg + ";Err:" + err.Error()
  667. } else {
  668. br.IsSendEmail = false
  669. }
  670. return
  671. }
  672. br.Ret = 200
  673. br.Success = true
  674. br.IsAddLog = true
  675. br.Msg = "分配成功"
  676. }
  677. // CancelGrant
  678. // @Title 取消分配ppt权限
  679. // @Description 取消分配ppt权限
  680. // @Param request body ppt_english.DeletePptEnglishReq true "type json string"
  681. // @Success 200 Ret=200 分配成功
  682. // @router /grant/cancel [post]
  683. func (this *PptEnglishController) CancelGrant() {
  684. br := new(models.BaseResponse).Init()
  685. defer func() {
  686. this.Data["json"] = br
  687. this.ServeJSON()
  688. }()
  689. var req ppt_english.DeletePptEnglishReq
  690. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  691. if err != nil {
  692. br.Msg = "参数解析异常!"
  693. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  694. return
  695. }
  696. if req.PptId <= 0 {
  697. br.Msg = "参数错误"
  698. return
  699. }
  700. // 查找ppt信息
  701. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  702. if err != nil {
  703. br.Msg = "ppt不存在"
  704. return
  705. }
  706. if pptInfo.AdminId != this.SysUser.AdminId {
  707. br.Msg = "无权取消配置"
  708. return
  709. }
  710. // 分配
  711. err, errMsg := ppt.DeleteGrantPptEnglish(req.PptId)
  712. if errMsg != `` {
  713. br.Msg = errMsg
  714. br.ErrMsg = errMsg
  715. if err != nil {
  716. br.ErrMsg = errMsg + ";Err:" + err.Error()
  717. } else {
  718. br.IsSendEmail = false
  719. }
  720. return
  721. }
  722. br.Ret = 200
  723. br.Success = true
  724. br.IsAddLog = true
  725. br.Msg = "取消成功"
  726. }
  727. // GrantInfo
  728. // @Title 获取分配ppt权限详情
  729. // @Description 获取分配ppt权限详情接口
  730. // @Param PptId query int true "ppt的id"
  731. // @Success 200 {object} ppt_english.GrantInfoResp
  732. // @router /grant/info [get]
  733. func (this *PptEnglishController) GrantInfo() {
  734. br := new(models.BaseResponse).Init()
  735. defer func() {
  736. this.Data["json"] = br
  737. this.ServeJSON()
  738. }()
  739. pptId, _ := this.GetInt("PptId")
  740. if pptId <= 0 {
  741. br.Msg = "参数错误"
  742. return
  743. }
  744. // 查找ppt信息
  745. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  746. if err != nil {
  747. br.Msg = "ppt不存在"
  748. return
  749. }
  750. if pptInfo.AdminId != this.SysUser.AdminId {
  751. br.Msg = "无权配置"
  752. return
  753. }
  754. pptGrantInfoList, err := ppt_english.GetPPtGrantInfo(pptId)
  755. if err != nil {
  756. br.Msg = "信息获取失败"
  757. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  758. return
  759. }
  760. if len(pptGrantInfoList) <= 0 {
  761. br.Msg = "未配置"
  762. br.IsSendEmail = false
  763. return
  764. }
  765. grantType := 0
  766. var adminIdStr string
  767. if pptGrantInfoList[0].DepartmentId > 0 { //分配类型;1:全部ficc研究员;2:指定成员
  768. grantType = 1
  769. } else {
  770. grantType = 2
  771. adminIdsList := make([]string, 0)
  772. for _, v := range pptGrantInfoList {
  773. adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
  774. }
  775. adminIdStr = strings.Join(adminIdsList, ",")
  776. }
  777. br.Ret = 200
  778. br.Success = true
  779. br.Data = ppt_english.GrantInfoResp{
  780. PptId: pptId,
  781. GrantType: grantType,
  782. AdminIdStr: adminIdStr,
  783. }
  784. br.Msg = "分配成功"
  785. }
  786. // ToReport
  787. // @Title 英文PPT转报告
  788. // @Description PPT转报告
  789. // @Param request body ppt_english.EnglishPPT2ReportReq true "type json string"
  790. // @Success 200 Ret=200 转换成功
  791. // @router /toReport [post]
  792. func (this *PptEnglishController) ToReport() {
  793. br := new(models.BaseResponse).Init()
  794. defer func() {
  795. this.Data["json"] = br
  796. this.ServeJSON()
  797. }()
  798. sysUser := this.SysUser
  799. if sysUser == nil {
  800. br.Msg = "请登录"
  801. br.ErrMsg = "请登录,SysUser Is Empty"
  802. br.Ret = 408
  803. return
  804. }
  805. var req ppt_english.EnglishPPT2ReportReq
  806. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  807. if err != nil {
  808. br.Msg = "参数解析异常!"
  809. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  810. return
  811. }
  812. if req.PptId == 0 {
  813. br.Msg = "参数有误"
  814. return
  815. }
  816. reportId, reportCode, msg, e := services.SaveEnglishPPTReport(req.PptId, req.ClassifyIdFirst, req.ClassifyIdSecond, req.Title, req.Abstract, sysUser)
  817. if e != nil {
  818. br.Msg = msg
  819. br.ErrMsg = "PPT转报告失败, Err: " + e.Error()
  820. return
  821. }
  822. resp := &models.PPT2ReportResp{
  823. ReportId: reportId,
  824. ReportCode: reportCode,
  825. }
  826. br.Ret = 200
  827. br.Success = true
  828. br.Msg = "转换成功"
  829. br.IsAddLog = true
  830. br.Data = resp
  831. }