ppt_english.go 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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 = utils.GetLikeKeywordPars(pars, keyWord, 2)
  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.GetPptEnglishByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  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.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.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. if br.ErrMsg == "" {
  342. br.IsSendEmail = false
  343. }
  344. this.Data["json"] = br
  345. this.ServeJSON()
  346. }()
  347. sysUser := this.SysUser
  348. if sysUser == nil {
  349. br.Msg = "请登录"
  350. br.ErrMsg = "请登录,SysUser Is Empty"
  351. br.Ret = 408
  352. return
  353. }
  354. pptId, _ := this.GetInt("PptId")
  355. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  356. if err != nil {
  357. br.Msg = "信息获取失败"
  358. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  359. return
  360. }
  361. // 查询编辑中
  362. editor, e := services.UpdatePptEditing(pptId, 0, sysUser.AdminId, sysUser.RealName, true)
  363. if e != nil {
  364. br.Msg = "操作失败"
  365. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  366. return
  367. }
  368. resp := new(ppt_english.EnglishPPTDetailResp)
  369. resp.PptEnglish = pptInfo
  370. resp.Editor = editor
  371. br.Ret = 200
  372. br.Success = true
  373. br.Msg = "获取成功"
  374. br.Data = resp
  375. }
  376. // DownloadPptx
  377. // @Title ppt下载
  378. // @Description ppt下载
  379. // @Param PptId query int true "PptId"
  380. // @Success 200 下载成功
  381. // @router /downloadpptx [get]
  382. func (this *PptEnglishCommonController) DownloadPptx() {
  383. br := new(models.BaseResponse).Init()
  384. defer func() {
  385. this.Data["json"] = br
  386. this.ServeJSON()
  387. }()
  388. pptId, err := this.GetInt("PptId")
  389. if err != nil {
  390. br.Msg = "参数错误"
  391. br.ErrMsg = "获取,pptId,Err:" + err.Error()
  392. return
  393. }
  394. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  395. if err != nil {
  396. br.Msg = "获取信息失败"
  397. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  398. return
  399. }
  400. filePath := pptInfo.PptxUrl
  401. fileName := pptInfo.Title + ".pptx"
  402. this.Ctx.Output.Download(filePath, fileName)
  403. br.Success = true
  404. br.Ret = 200
  405. br.Msg = "下载成功"
  406. return
  407. }
  408. // Publish
  409. // @Title 发布接口
  410. // @Description 发布接口
  411. // @Param request body ppt_english.SavePptEnglishPathReq true "type json string"
  412. // @Success Ret=200 发布成功
  413. // @router /publish [post]
  414. func (this *PptEnglishController) Publish() {
  415. br := new(models.BaseResponse).Init()
  416. defer func() {
  417. this.Data["json"] = br
  418. this.ServeJSON()
  419. }()
  420. //SavePptEnglishPathReq
  421. //PptEnglishPublishReq
  422. var req ppt_english.SavePptEnglishPathReq
  423. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  424. if err != nil {
  425. br.Msg = "参数解析异常!"
  426. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  427. return
  428. }
  429. pptId := req.PptId
  430. if pptId <= 0 {
  431. br.Msg = "参数错误"
  432. return
  433. }
  434. err = ppt_english.EditPptEnglishPath(pptId, req.PptxUrl)
  435. if err != nil {
  436. br.Msg = "发布失败"
  437. br.ErrMsg = "发布失败,Err:" + err.Error()
  438. return
  439. }
  440. //添加发布记录
  441. {
  442. record := new(ppt_english.PptEnglishPublishRecord)
  443. record.CreateTime = time.Now()
  444. record.PptId = pptId
  445. record.PptUrl = req.PptxUrl
  446. go ppt_english.AddPptEnglishPublishRecord(record)
  447. }
  448. br.Ret = 200
  449. br.Success = true
  450. br.Msg = "发布成功"
  451. br.IsAddLog = true
  452. return
  453. }
  454. // PptUpload
  455. // @Title ppt上传
  456. // @Description ppt上传
  457. // @Param PptId query int true "PptId"
  458. // @Success 200 新增成功
  459. // @router /pptUpload [post]
  460. func (this *PptEnglishController) PptUpload() {
  461. br := new(models.BaseResponse).Init()
  462. defer func() {
  463. this.Data["json"] = br
  464. this.ServeJSON()
  465. }()
  466. pptId, _ := this.GetInt("PptId", 0)
  467. if pptId <= 0 {
  468. br.Msg = "参数错误"
  469. return
  470. }
  471. _, err := ppt_english.GetPptEnglishById(pptId)
  472. if err != nil {
  473. br.Msg = "获取数据失败"
  474. br.ErrMsg = "获取PPT详情失败,Err:" + err.Error()
  475. return
  476. }
  477. f, h, err := this.GetFile("file")
  478. if err != nil {
  479. br.Msg = "获取资源信息失败"
  480. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  481. return
  482. }
  483. uploadFileName := h.Filename //上传的文件名
  484. ext := path.Ext(h.Filename)
  485. dateDir := time.Now().Format("20060102")
  486. uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
  487. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  488. if err != nil {
  489. br.Msg = "存储目录创建失败"
  490. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  491. return
  492. }
  493. randStr := utils.GetRandStringNoSpecialChar(28)
  494. fileName := randStr + ext
  495. fpath := uploadDir + "/" + fileName
  496. defer f.Close() //关闭上传文件
  497. err = this.SaveToFile("file", fpath)
  498. if err != nil {
  499. br.Msg = "文件上传失败"
  500. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  501. return
  502. }
  503. hzUploadDir := "ppt/"
  504. savePptxToOssPath := hzUploadDir + time.Now().Format("200601/20060102/")
  505. //pptName := strings.Replace(pptItem.Title, "\n", "", -1)
  506. //pptName = strings.TrimSuffix(pptName, " ")
  507. pptName := utils.GetRandStringNoSpecialChar(28)
  508. savePptxToOssPath += pptName + ".pptx"
  509. //上传到阿里云 和 minio
  510. pptxUrl := ``
  511. if utils.ObjectStorageClient == "minio" {
  512. err = services.UploadFileToMinIo("", fpath, savePptxToOssPath)
  513. if err != nil {
  514. br.Msg = "文件上传失败"
  515. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  516. return
  517. }
  518. pptxUrl = utils.MinIoImghost + savePptxToOssPath
  519. } else {
  520. err = services.UploadFileToAliyun("", fpath, savePptxToOssPath)
  521. if err != nil {
  522. br.Msg = "文件上传失败"
  523. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  524. return
  525. }
  526. pptxUrl = utils.Imghost + savePptxToOssPath
  527. }
  528. defer func() {
  529. os.Remove(fpath)
  530. }()
  531. item := &models.Resource{
  532. //Id: 0,
  533. ResourceUrl: pptxUrl,
  534. CreateTime: time.Now(),
  535. ResourceType: 4,
  536. }
  537. newId, err := models.AddResource(item)
  538. if err != nil {
  539. br.Msg = "资源上传失败"
  540. br.ErrMsg = "资源上传失败,Err:" + err.Error()
  541. return
  542. }
  543. resp := models.ResourceResp{
  544. Id: newId,
  545. ResourceUrl: pptxUrl,
  546. ResourceName: uploadFileName,
  547. }
  548. br.Msg = "上传成功"
  549. br.Ret = 200
  550. br.Success = true
  551. br.Data = resp
  552. return
  553. }
  554. // SaveLog
  555. // @Title 定时ppt操作日志记录
  556. // @Description 定时ppt操作日志记录
  557. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  558. // @Success 200 新增成功
  559. // @router /saveLog [post]
  560. func (this *PptEnglishController) SaveLog() {
  561. br := new(models.BaseResponse).Init()
  562. defer func() {
  563. if br.ErrMsg == "" {
  564. br.IsSendEmail = false
  565. }
  566. this.Data["json"] = br
  567. this.ServeJSON()
  568. }()
  569. sysUser := this.SysUser
  570. if sysUser == nil {
  571. br.Msg = "请登录"
  572. br.ErrMsg = "请登录,SysUser Is Empty"
  573. br.Ret = 408
  574. return
  575. }
  576. var req ppt_english.AddPptEnglishReq
  577. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  578. if err != nil {
  579. br.Msg = "参数解析异常!"
  580. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  581. return
  582. }
  583. if req.FirstPage.Title == "" {
  584. br.Msg = "标题不能为空"
  585. return
  586. }
  587. // 获取ppt
  588. item, err := ppt_english.GetPptEnglishByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  589. if err != nil && err.Error() != utils.ErrNoRow() {
  590. br.Msg = "获取数据异常!"
  591. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  592. return
  593. }
  594. if item != nil && item.PptId != int(req.PptId) {
  595. br.Msg = "标题已存在,不可重复添加"
  596. br.IsSendEmail = false
  597. return
  598. }
  599. //变更ppt内容
  600. pptItem, e := ppt_english.GetPptEnglishById(int(req.PptId))
  601. if e != nil {
  602. if e.Error() == utils.ErrNoRow() {
  603. br.Msg = "PPT已被删除, 请刷新页面"
  604. return
  605. }
  606. br.Msg = "信息获取失败"
  607. br.ErrMsg = "信息获取失败,Err:" + e.Error()
  608. return
  609. }
  610. // 标记编辑状态
  611. if pptItem.PptId > 0 {
  612. _, e = services.UpdatePptEditing(pptItem.PptId, 1, sysUser.AdminId, sysUser.RealName, true)
  613. if e != nil {
  614. br.Msg = "操作失败"
  615. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  616. return
  617. }
  618. }
  619. //pptInfo.TemplateType = req.FirstPage.TemplateType
  620. //pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  621. //pptInfo.Title = req.FirstPage.Title
  622. //pptInfo.ReportType = req.FirstPage.ReportType
  623. //pptInfo.PptDate = req.FirstPage.PptDate
  624. //pptInfo.Content = req.Content
  625. //pptInfo.ModifyTime = time.Now()
  626. //err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  627. //日志记录
  628. logInfo := &ppt_english.PptEnglishSaveLog{
  629. PptId: int(req.PptId),
  630. TemplateType: req.FirstPage.TemplateType,
  631. BackgroundImg: req.FirstPage.ImgUrl,
  632. Title: req.FirstPage.Title,
  633. ReportType: req.FirstPage.ReportType,
  634. PptDate: req.FirstPage.PptDate,
  635. Content: req.Content,
  636. AdminId: this.SysUser.AdminId,
  637. AdminRealName: this.SysUser.RealName,
  638. CreateTime: time.Now(),
  639. }
  640. _, err = ppt_english.AddPptEnglishSaveLog(logInfo)
  641. if err != nil {
  642. br.Msg = "保存失败"
  643. br.ErrMsg = "保存PPT日志失败, Err: " + err.Error()
  644. return
  645. }
  646. br.Ret = 200
  647. br.Success = true
  648. br.Msg = "保存成功"
  649. }
  650. // GetConfig
  651. // @Title 获取ppt配置
  652. // @Description 获取ppt列表接口
  653. // @Param PageSize query int true "每页数据条数"
  654. // @Param CurrentIndex query int true "当前页页码,从1开始"
  655. // @Param KeyWord query string true "搜索关键词"
  656. // @Success 200 {object} ppt_english.PptEnglishListResp
  657. // @router /config [get]
  658. func (this *PptEnglishController) GetConfig() {
  659. br := new(models.BaseResponse).Init()
  660. defer func() {
  661. this.Data["json"] = br
  662. this.ServeJSON()
  663. }()
  664. crmConfig, err := company.GetConfigDetailByCode("ppt_limit")
  665. if err != nil {
  666. br.Msg = "获取配置失败"
  667. br.ErrMsg = "获取配置失败"
  668. br.IsSendEmail = false
  669. return
  670. }
  671. resp := new(ppt_english.PptEnglishConfigResp)
  672. err = json.Unmarshal([]byte(crmConfig.ConfigValue), resp)
  673. if err != nil {
  674. br.Msg = "获取配置失败"
  675. br.ErrMsg = "获取配置失败;err:" + err.Error()
  676. br.IsSendEmail = false
  677. return
  678. }
  679. br.Ret = 200
  680. br.Success = true
  681. br.Msg = "获取成功"
  682. br.Data = resp
  683. }
  684. // Grant
  685. // @Title 分配ppt权限
  686. // @Description 分配ppt权限接口
  687. // @Param request body ppt_english.GrantPptReq true "type json string"
  688. // @Success 200 Ret=200 分配成功
  689. // @router /grant [post]
  690. func (this *PptEnglishController) Grant() {
  691. br := new(models.BaseResponse).Init()
  692. defer func() {
  693. this.Data["json"] = br
  694. this.ServeJSON()
  695. }()
  696. var req ppt_english.GrantPptReq
  697. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  698. if err != nil {
  699. br.Msg = "参数解析异常!"
  700. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  701. return
  702. }
  703. if req.PptId <= 0 {
  704. br.Msg = "参数错误"
  705. return
  706. }
  707. // 查找ppt信息
  708. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  709. if err != nil {
  710. br.Msg = "ppt不存在"
  711. return
  712. }
  713. if pptInfo.AdminId != this.SysUser.AdminId {
  714. br.Msg = "无权配置"
  715. return
  716. }
  717. // 分配
  718. err, errMsg := ppt.GrantPptEnglish(req.PptId, req.GrantType, req.AdminIdStr, this.SysUser.AdminId)
  719. if errMsg != `` {
  720. br.Msg = errMsg
  721. br.ErrMsg = errMsg
  722. if err != nil {
  723. br.ErrMsg = errMsg + ";Err:" + err.Error()
  724. } else {
  725. br.IsSendEmail = false
  726. }
  727. return
  728. }
  729. br.Ret = 200
  730. br.Success = true
  731. br.IsAddLog = true
  732. br.Msg = "分配成功"
  733. }
  734. // CancelGrant
  735. // @Title 取消分配ppt权限
  736. // @Description 取消分配ppt权限
  737. // @Param request body ppt_english.DeletePptEnglishReq true "type json string"
  738. // @Success 200 Ret=200 分配成功
  739. // @router /grant/cancel [post]
  740. func (this *PptEnglishController) CancelGrant() {
  741. br := new(models.BaseResponse).Init()
  742. defer func() {
  743. this.Data["json"] = br
  744. this.ServeJSON()
  745. }()
  746. var req ppt_english.DeletePptEnglishReq
  747. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  748. if err != nil {
  749. br.Msg = "参数解析异常!"
  750. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  751. return
  752. }
  753. if req.PptId <= 0 {
  754. br.Msg = "参数错误"
  755. return
  756. }
  757. // 查找ppt信息
  758. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  759. if err != nil {
  760. br.Msg = "ppt不存在"
  761. return
  762. }
  763. if pptInfo.AdminId != this.SysUser.AdminId {
  764. br.Msg = "无权取消配置"
  765. return
  766. }
  767. // 分配
  768. err, errMsg := ppt.DeleteGrantPptEnglish(req.PptId)
  769. if errMsg != `` {
  770. br.Msg = errMsg
  771. br.ErrMsg = errMsg
  772. if err != nil {
  773. br.ErrMsg = errMsg + ";Err:" + err.Error()
  774. } else {
  775. br.IsSendEmail = false
  776. }
  777. return
  778. }
  779. br.Ret = 200
  780. br.Success = true
  781. br.IsAddLog = true
  782. br.Msg = "取消成功"
  783. }
  784. // GrantInfo
  785. // @Title 获取分配ppt权限详情
  786. // @Description 获取分配ppt权限详情接口
  787. // @Param PptId query int true "ppt的id"
  788. // @Success 200 {object} ppt_english.GrantInfoResp
  789. // @router /grant/info [get]
  790. func (this *PptEnglishController) GrantInfo() {
  791. br := new(models.BaseResponse).Init()
  792. defer func() {
  793. this.Data["json"] = br
  794. this.ServeJSON()
  795. }()
  796. pptId, _ := this.GetInt("PptId")
  797. if pptId <= 0 {
  798. br.Msg = "参数错误"
  799. return
  800. }
  801. // 查找ppt信息
  802. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  803. if err != nil {
  804. br.Msg = "ppt不存在"
  805. return
  806. }
  807. if pptInfo.AdminId != this.SysUser.AdminId {
  808. br.Msg = "无权配置"
  809. return
  810. }
  811. pptGrantInfoList, err := ppt_english.GetPPtGrantInfo(pptId)
  812. if err != nil {
  813. br.Msg = "信息获取失败"
  814. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  815. return
  816. }
  817. if len(pptGrantInfoList) <= 0 {
  818. br.Msg = "未配置"
  819. br.IsSendEmail = false
  820. return
  821. }
  822. grantType := 0
  823. var adminIdStr string
  824. if pptGrantInfoList[0].DepartmentId > 0 { //分配类型;1:全部ficc研究员;2:指定成员
  825. grantType = 1
  826. } else {
  827. grantType = 2
  828. adminIdsList := make([]string, 0)
  829. for _, v := range pptGrantInfoList {
  830. adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
  831. }
  832. adminIdStr = strings.Join(adminIdsList, ",")
  833. }
  834. br.Ret = 200
  835. br.Success = true
  836. br.Data = ppt_english.GrantInfoResp{
  837. PptId: pptId,
  838. GrantType: grantType,
  839. AdminIdStr: adminIdStr,
  840. }
  841. br.Msg = "分配成功"
  842. }
  843. // ToReport
  844. // @Title 英文PPT转报告
  845. // @Description PPT转报告
  846. // @Param request body ppt_english.EnglishPPT2ReportReq true "type json string"
  847. // @Success 200 Ret=200 转换成功
  848. // @router /toReport [post]
  849. func (this *PptEnglishController) ToReport() {
  850. br := new(models.BaseResponse).Init()
  851. defer func() {
  852. this.Data["json"] = br
  853. this.ServeJSON()
  854. }()
  855. sysUser := this.SysUser
  856. if sysUser == nil {
  857. br.Msg = "请登录"
  858. br.ErrMsg = "请登录,SysUser Is Empty"
  859. br.Ret = 408
  860. return
  861. }
  862. var req ppt_english.EnglishPPT2ReportReq
  863. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  864. if err != nil {
  865. br.Msg = "参数解析异常!"
  866. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  867. return
  868. }
  869. if req.PptId == 0 {
  870. br.Msg = "参数有误"
  871. return
  872. }
  873. reportId, reportCode, msg, e := services.SaveEnglishPPTReport(req.PptId, req.ClassifyIdFirst, req.ClassifyIdSecond, req.Title, req.Abstract, sysUser)
  874. if e != nil {
  875. br.Msg = msg
  876. br.ErrMsg = "PPT转报告失败, Err: " + e.Error()
  877. return
  878. }
  879. resp := &models.PPT2ReportResp{
  880. ReportId: reportId,
  881. ReportCode: reportCode,
  882. }
  883. br.Ret = 200
  884. br.Success = true
  885. br.Msg = "转换成功"
  886. br.IsAddLog = true
  887. br.Data = resp
  888. }
  889. // TitleCheck
  890. // @Title 校验标题是否重复
  891. // @Description 校验标题是否重复接口
  892. // @Param Title query int true "标题"
  893. // @Success 200 Ret=200 编辑成功
  894. // @router /titleCheck [get]
  895. func (this *PptEnglishController) TitleCheck() {
  896. br := new(models.BaseResponse).Init()
  897. defer func() {
  898. this.Data["json"] = br
  899. this.ServeJSON()
  900. }()
  901. title := this.GetString("Title")
  902. pptId, _ := this.GetInt("PptId")
  903. if title == "" {
  904. br.Msg = "标题不能为空"
  905. return
  906. }
  907. item, err := ppt_english.GetPptEnglishByTitleAndId(title, this.SysUser.AdminId)
  908. if err != nil && err.Error() != utils.ErrNoRow() {
  909. br.Msg = "获取数据异常!"
  910. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  911. return
  912. }
  913. if item != nil && item.PptId != pptId {
  914. br.Msg = "标题已存在,不可重复添加"
  915. br.IsSendEmail = false
  916. return
  917. }
  918. br.Ret = 200
  919. br.Success = true
  920. br.Msg = "校验成功"
  921. }
  922. // Editing
  923. // @Title 标记编辑状态
  924. // @Description 标记编辑状态
  925. // @Param request body models.PPTEditingReq true "type json string"
  926. // @Success 200 Ret=200 操作成功
  927. // @router /editing [post]
  928. func (this *PptEnglishController) Editing() {
  929. br := new(models.BaseResponse).Init()
  930. defer func() {
  931. if br.ErrMsg == "" {
  932. br.IsSendEmail = false
  933. }
  934. this.Data["json"] = br
  935. this.ServeJSON()
  936. }()
  937. sysUser := this.SysUser
  938. if sysUser == nil {
  939. br.Msg = "请登录"
  940. br.ErrMsg = "请登录,SysUser Is Empty"
  941. br.Ret = 408
  942. return
  943. }
  944. var req models.PPTEditingReq
  945. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  946. if err != nil {
  947. br.Msg = "参数解析异常!"
  948. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  949. return
  950. }
  951. if req.PptId <= 0 {
  952. br.Msg = "参数有误"
  953. return
  954. }
  955. if req.Status <= 0 {
  956. br.Msg = "标记状态异常"
  957. return
  958. }
  959. editor, e := services.UpdatePptEditing(req.PptId, req.Status, sysUser.AdminId, sysUser.RealName, true)
  960. if e != nil {
  961. br.Msg = "操作失败"
  962. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  963. return
  964. }
  965. br.Data = editor
  966. br.Ret = 200
  967. br.Success = true
  968. br.Msg = "操作成功"
  969. }