ppt_english.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  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. CoverContent: req.CoverContent,
  145. CreateTime: time.Now(),
  146. ModifyTime: time.Now(),
  147. AdminId: this.SysUser.AdminId,
  148. AdminRealName: this.SysUser.RealName,
  149. }
  150. newId, err = ppt_english.AddPptEnglish(pptInfo)
  151. if err != nil {
  152. br.Msg = "新增失败"
  153. br.ErrMsg = "新增失败,Err:" + err.Error()
  154. return
  155. }
  156. //新增ppt和目录映射
  157. _, err = ppt.AddGroupPptEnglishMapping(newId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  158. if err != nil {
  159. br.Msg = err.Error()
  160. return
  161. }
  162. msg = "新增成功"
  163. } else {
  164. newId = req.PptId
  165. pptInfo, err := ppt_english.GetPptEnglishById(int(req.PptId))
  166. if err != nil {
  167. br.Msg = "信息获取失败"
  168. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  169. return
  170. }
  171. pptInfo.TemplateType = req.FirstPage.TemplateType
  172. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  173. pptInfo.Title = req.FirstPage.Title
  174. pptInfo.ReportType = req.FirstPage.ReportType
  175. pptInfo.PptDate = req.FirstPage.PptDate
  176. pptInfo.Content = req.Content
  177. pptInfo.CoverContent = req.CoverContent
  178. pptInfo.ModifyTime = time.Now()
  179. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent"})
  180. msg = "保存成功"
  181. }
  182. resp := ppt_english.AddPptEnglishResp{
  183. PptId: newId,
  184. }
  185. br.Ret = 200
  186. br.Success = true
  187. br.Msg = msg
  188. br.Data = resp
  189. }
  190. // EditPpt
  191. // @Title 编辑ppt
  192. // @Description 编辑ppt接口
  193. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  194. // @Success 200 Ret=200 编辑成功
  195. // @router /edit [post]
  196. func (this *PptEnglishController) EditPpt() {
  197. br := new(models.BaseResponse).Init()
  198. defer func() {
  199. this.Data["json"] = br
  200. this.ServeJSON()
  201. }()
  202. var req ppt_english.AddPptEnglishReq
  203. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  204. if err != nil {
  205. br.Msg = "参数解析异常!"
  206. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  207. return
  208. }
  209. if req.FirstPage.Title == "" {
  210. br.Msg = "标题不能为空"
  211. return
  212. }
  213. item, err := ppt_english.GetPptEnglishByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  214. if err != nil && err.Error() != utils.ErrNoRow() {
  215. br.Msg = "获取数据异常!"
  216. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  217. return
  218. }
  219. if item != nil && item.PptId != int(req.PptId) {
  220. br.Msg = "标题已存在,不可重复添加"
  221. br.IsSendEmail = false
  222. return
  223. }
  224. pptInfo, err := ppt_english.GetPptEnglishById(int(req.PptId))
  225. if err != nil {
  226. br.Msg = "信息获取失败"
  227. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  228. return
  229. }
  230. // 判断权限
  231. if pptInfo.AdminId != this.SysUser.AdminId {
  232. _, err := ppt_english.GetPPtGrantConf(pptInfo.PptId, this.SysUser.AdminId)
  233. if err != nil {
  234. if err.Error() == utils.ErrNoRow() {
  235. br.Msg = `该PPT已取消共享,保存失败`
  236. br.ErrMsg = `该PPT已取消共享,保存失败`
  237. br.IsSendEmail = false
  238. } else {
  239. br.Msg = `保存失败`
  240. br.ErrMsg = `保存失败,ERR:` + err.Error()
  241. }
  242. return
  243. }
  244. }
  245. // 修改
  246. pptInfo.TemplateType = req.FirstPage.TemplateType
  247. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  248. pptInfo.Title = req.FirstPage.Title
  249. pptInfo.ReportType = req.FirstPage.ReportType
  250. pptInfo.PptDate = req.FirstPage.PptDate
  251. pptInfo.Content = req.Content
  252. pptInfo.CoverContent = req.CoverContent
  253. pptInfo.ModifyTime = time.Now()
  254. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime", "CoverContent"})
  255. if err != nil {
  256. br.Msg = "编辑失败"
  257. br.ErrMsg = "编辑失败,Err:" + err.Error()
  258. return
  259. }
  260. // 日志记录
  261. {
  262. logInfo := &ppt_english.PptEnglishSaveLog{
  263. PptId: pptInfo.PptId,
  264. TemplateType: pptInfo.TemplateType,
  265. BackgroundImg: pptInfo.BackgroundImg,
  266. Title: pptInfo.Title,
  267. ReportType: pptInfo.ReportType,
  268. PptDate: pptInfo.PptDate,
  269. Content: pptInfo.Content,
  270. CoverContent: pptInfo.CoverContent,
  271. AdminId: this.SysUser.AdminId,
  272. AdminRealName: this.SysUser.RealName,
  273. CreateTime: time.Now(),
  274. }
  275. _, err = ppt_english.AddPptEnglishSaveLog(logInfo)
  276. }
  277. resp := ppt_english.AddPptEnglishResp{
  278. PptId: req.PptId,
  279. }
  280. br.Ret = 200
  281. br.Success = true
  282. br.Msg = "编辑成功"
  283. br.IsAddLog = true
  284. br.Data = resp
  285. }
  286. // DeletePpt
  287. // @Title 删除ppt
  288. // @Description 删除ppt接口
  289. // @Param request body ppt_english.DeletePptEnglishReq true "type json string"
  290. // @Success 200 Ret=200 删除成功
  291. // @router /delete [post]
  292. func (this *PptEnglishController) DeletePpt() {
  293. br := new(models.BaseResponse).Init()
  294. defer func() {
  295. this.Data["json"] = br
  296. this.ServeJSON()
  297. }()
  298. var req ppt_english.DeletePptEnglishReq
  299. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  300. if err != nil {
  301. br.Msg = "参数解析异常!"
  302. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  303. return
  304. }
  305. if req.PptId <= 0 {
  306. br.Msg = "参数错误"
  307. return
  308. }
  309. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  310. if err != nil {
  311. br.Msg = "ppt不存在"
  312. return
  313. }
  314. if pptInfo.AdminId != this.SysUser.AdminId {
  315. br.Msg = "无权删除"
  316. return
  317. }
  318. err = ppt_english.DeletePptEnglish(req.PptId)
  319. if err != nil {
  320. br.Msg = "删除失败"
  321. br.ErrMsg = "删除失败,Err:" + err.Error()
  322. return
  323. }
  324. //如果该ppt存在单个共享记录,则删除共享
  325. err = ppt.DeleteGroupPptEnglish(req.PptId)
  326. if err != nil {
  327. br.Msg = "删除失败"
  328. br.ErrMsg = "删除失败,Err:" + err.Error()
  329. return
  330. }
  331. br.Ret = 200
  332. br.Success = true
  333. br.IsAddLog = true
  334. br.Msg = "删除成功"
  335. }
  336. // DetailPpt
  337. // @Title 获取ppt详情
  338. // @Description 获取ppt详情接口
  339. // @Param PptId query int true "PptId"
  340. // @Success 200 {object} ppt_english.PptEnglish
  341. // @router /detail [get]
  342. func (this *PptEnglishController) DetailPpt() {
  343. br := new(models.BaseResponse).Init()
  344. defer func() {
  345. if br.ErrMsg == "" {
  346. br.IsSendEmail = false
  347. }
  348. this.Data["json"] = br
  349. this.ServeJSON()
  350. }()
  351. sysUser := this.SysUser
  352. if sysUser == nil {
  353. br.Msg = "请登录"
  354. br.ErrMsg = "请登录,SysUser Is Empty"
  355. br.Ret = 408
  356. return
  357. }
  358. pptId, _ := this.GetInt("PptId")
  359. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  360. if err != nil {
  361. br.Msg = "信息获取失败"
  362. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  363. return
  364. }
  365. // 查询编辑中
  366. editor, e := services.UpdatePptEditing(pptId, 0, sysUser.AdminId, sysUser.RealName, true)
  367. if e != nil {
  368. br.Msg = "操作失败"
  369. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  370. return
  371. }
  372. resp := new(ppt_english.EnglishPPTDetailResp)
  373. resp.PptEnglish = pptInfo
  374. resp.Editor = editor
  375. br.Ret = 200
  376. br.Success = true
  377. br.Msg = "获取成功"
  378. br.Data = resp
  379. }
  380. // DownloadPptx
  381. // @Title ppt下载
  382. // @Description ppt下载
  383. // @Param PptId query int true "PptId"
  384. // @Success 200 下载成功
  385. // @router /downloadpptx [get]
  386. func (this *PptEnglishCommonController) DownloadPptx() {
  387. br := new(models.BaseResponse).Init()
  388. defer func() {
  389. this.Data["json"] = br
  390. this.ServeJSON()
  391. }()
  392. pptId, err := this.GetInt("PptId")
  393. if err != nil {
  394. br.Msg = "参数错误"
  395. br.ErrMsg = "获取,pptId,Err:" + err.Error()
  396. return
  397. }
  398. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  399. if err != nil {
  400. br.Msg = "获取信息失败"
  401. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  402. return
  403. }
  404. filePath := pptInfo.PptxUrl
  405. fileName := pptInfo.Title + ".pptx"
  406. this.Ctx.Output.Download(filePath, fileName)
  407. br.Success = true
  408. br.Ret = 200
  409. br.Msg = "下载成功"
  410. return
  411. }
  412. // Publish
  413. // @Title 发布接口
  414. // @Description 发布接口
  415. // @Param request body ppt_english.SavePptEnglishPathReq true "type json string"
  416. // @Success Ret=200 发布成功
  417. // @router /publish [post]
  418. func (this *PptEnglishController) Publish() {
  419. br := new(models.BaseResponse).Init()
  420. defer func() {
  421. this.Data["json"] = br
  422. this.ServeJSON()
  423. }()
  424. //SavePptEnglishPathReq
  425. //PptEnglishPublishReq
  426. var req ppt_english.SavePptEnglishPathReq
  427. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  428. if err != nil {
  429. br.Msg = "参数解析异常!"
  430. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  431. return
  432. }
  433. pptId := req.PptId
  434. if pptId <= 0 {
  435. br.Msg = "参数错误"
  436. return
  437. }
  438. err = ppt_english.EditPptEnglishPath(pptId, req.PptxUrl)
  439. if err != nil {
  440. br.Msg = "发布失败"
  441. br.ErrMsg = "发布失败,Err:" + err.Error()
  442. return
  443. }
  444. //添加发布记录
  445. {
  446. record := new(ppt_english.PptEnglishPublishRecord)
  447. record.CreateTime = time.Now()
  448. record.PptId = pptId
  449. record.PptUrl = req.PptxUrl
  450. go ppt_english.AddPptEnglishPublishRecord(record)
  451. }
  452. br.Ret = 200
  453. br.Success = true
  454. br.Msg = "发布成功"
  455. br.IsAddLog = true
  456. return
  457. }
  458. // PptUpload
  459. // @Title ppt上传
  460. // @Description ppt上传
  461. // @Param PptId query int true "PptId"
  462. // @Success 200 新增成功
  463. // @router /pptUpload [post]
  464. func (this *PptEnglishController) PptUpload() {
  465. br := new(models.BaseResponse).Init()
  466. defer func() {
  467. this.Data["json"] = br
  468. this.ServeJSON()
  469. }()
  470. pptId, _ := this.GetInt("PptId", 0)
  471. if pptId <= 0 {
  472. br.Msg = "参数错误"
  473. return
  474. }
  475. _, err := ppt_english.GetPptEnglishById(pptId)
  476. if err != nil {
  477. br.Msg = "获取数据失败"
  478. br.ErrMsg = "获取PPT详情失败,Err:" + err.Error()
  479. return
  480. }
  481. f, h, err := this.GetFile("file")
  482. if err != nil {
  483. br.Msg = "获取资源信息失败"
  484. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  485. return
  486. }
  487. uploadFileName := h.Filename //上传的文件名
  488. ext := path.Ext(h.Filename)
  489. dateDir := time.Now().Format("20060102")
  490. uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
  491. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  492. if err != nil {
  493. br.Msg = "存储目录创建失败"
  494. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  495. return
  496. }
  497. randStr := utils.GetRandStringNoSpecialChar(28)
  498. fileName := randStr + ext
  499. fpath := uploadDir + "/" + fileName
  500. defer f.Close() //关闭上传文件
  501. err = this.SaveToFile("file", fpath)
  502. if err != nil {
  503. br.Msg = "文件上传失败"
  504. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  505. return
  506. }
  507. hzUploadDir := "ppt/"
  508. savePptxToOssPath := hzUploadDir + time.Now().Format("200601/20060102/")
  509. //pptName := strings.Replace(pptItem.Title, "\n", "", -1)
  510. //pptName = strings.TrimSuffix(pptName, " ")
  511. pptName := utils.GetRandStringNoSpecialChar(28)
  512. savePptxToOssPath += pptName + ".pptx"
  513. defer func() {
  514. _ = os.Remove(fpath)
  515. }()
  516. //上传到阿里云 和 minio
  517. pptxUrl := ``
  518. //if utils.ObjectStorageClient == "minio" {
  519. // err = services.UploadFileToMinIo("", fpath, savePptxToOssPath)
  520. // if err != nil {
  521. // br.Msg = "文件上传失败"
  522. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  523. // return
  524. // }
  525. // pptxUrl = utils.MinIoImghost + savePptxToOssPath
  526. //} else {
  527. // err = services.UploadFileToAliyun("", fpath, savePptxToOssPath)
  528. // if err != nil {
  529. // br.Msg = "文件上传失败"
  530. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  531. // return
  532. // }
  533. // pptxUrl = utils.Imghost + savePptxToOssPath
  534. //}
  535. ossClient := services.NewOssClient()
  536. if ossClient == nil {
  537. br.Msg = "上传失败"
  538. br.ErrMsg = "初始化OSS服务失败"
  539. return
  540. }
  541. pptxUrl, err = ossClient.UploadFile("", fpath, savePptxToOssPath)
  542. if err != nil {
  543. br.Msg = "文件上传失败"
  544. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  545. return
  546. }
  547. item := &models.Resource{
  548. //Id: 0,
  549. ResourceUrl: pptxUrl,
  550. CreateTime: time.Now(),
  551. ResourceType: 4,
  552. }
  553. newId, err := models.AddResource(item)
  554. if err != nil {
  555. br.Msg = "资源上传失败"
  556. br.ErrMsg = "资源上传失败,Err:" + err.Error()
  557. return
  558. }
  559. resp := models.ResourceResp{
  560. Id: newId,
  561. ResourceUrl: pptxUrl,
  562. ResourceName: uploadFileName,
  563. }
  564. br.Msg = "上传成功"
  565. br.Ret = 200
  566. br.Success = true
  567. br.Data = resp
  568. return
  569. }
  570. // SaveLog
  571. // @Title 定时ppt操作日志记录
  572. // @Description 定时ppt操作日志记录
  573. // @Param request body ppt_english.AddPptEnglishReq true "type json string"
  574. // @Success 200 新增成功
  575. // @router /saveLog [post]
  576. func (this *PptEnglishController) SaveLog() {
  577. br := new(models.BaseResponse).Init()
  578. defer func() {
  579. if br.ErrMsg == "" {
  580. br.IsSendEmail = false
  581. }
  582. this.Data["json"] = br
  583. this.ServeJSON()
  584. }()
  585. sysUser := this.SysUser
  586. if sysUser == nil {
  587. br.Msg = "请登录"
  588. br.ErrMsg = "请登录,SysUser Is Empty"
  589. br.Ret = 408
  590. return
  591. }
  592. var req ppt_english.AddPptEnglishReq
  593. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  594. if err != nil {
  595. br.Msg = "参数解析异常!"
  596. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  597. return
  598. }
  599. if req.FirstPage.Title == "" {
  600. br.Msg = "标题不能为空"
  601. return
  602. }
  603. // 获取ppt
  604. item, err := ppt_english.GetPptEnglishByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  605. if err != nil && err.Error() != utils.ErrNoRow() {
  606. br.Msg = "获取数据异常!"
  607. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  608. return
  609. }
  610. if item != nil && item.PptId != int(req.PptId) {
  611. br.Msg = "标题已存在,不可重复添加"
  612. br.IsSendEmail = false
  613. return
  614. }
  615. //变更ppt内容
  616. pptItem, e := ppt_english.GetPptEnglishById(int(req.PptId))
  617. if e != nil {
  618. if e.Error() == utils.ErrNoRow() {
  619. br.Msg = "PPT已被删除, 请刷新页面"
  620. return
  621. }
  622. br.Msg = "信息获取失败"
  623. br.ErrMsg = "信息获取失败,Err:" + e.Error()
  624. return
  625. }
  626. // 标记编辑状态
  627. if pptItem.PptId > 0 {
  628. _, e = services.UpdatePptEditing(pptItem.PptId, 1, sysUser.AdminId, sysUser.RealName, true)
  629. if e != nil {
  630. br.Msg = "操作失败"
  631. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  632. return
  633. }
  634. }
  635. //pptInfo.TemplateType = req.FirstPage.TemplateType
  636. //pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  637. //pptInfo.Title = req.FirstPage.Title
  638. //pptInfo.ReportType = req.FirstPage.ReportType
  639. //pptInfo.PptDate = req.FirstPage.PptDate
  640. //pptInfo.Content = req.Content
  641. //pptInfo.ModifyTime = time.Now()
  642. //err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  643. //日志记录
  644. logInfo := &ppt_english.PptEnglishSaveLog{
  645. PptId: int(req.PptId),
  646. TemplateType: req.FirstPage.TemplateType,
  647. BackgroundImg: req.FirstPage.ImgUrl,
  648. Title: req.FirstPage.Title,
  649. ReportType: req.FirstPage.ReportType,
  650. PptDate: req.FirstPage.PptDate,
  651. Content: req.Content,
  652. CoverContent: req.CoverContent,
  653. AdminId: this.SysUser.AdminId,
  654. AdminRealName: this.SysUser.RealName,
  655. CreateTime: time.Now(),
  656. }
  657. _, err = ppt_english.AddPptEnglishSaveLog(logInfo)
  658. if err != nil {
  659. br.Msg = "保存失败"
  660. br.ErrMsg = "保存PPT日志失败, Err: " + err.Error()
  661. return
  662. }
  663. br.Ret = 200
  664. br.Success = true
  665. br.Msg = "保存成功"
  666. }
  667. // GetConfig
  668. // @Title 获取ppt配置
  669. // @Description 获取ppt列表接口
  670. // @Param PageSize query int true "每页数据条数"
  671. // @Param CurrentIndex query int true "当前页页码,从1开始"
  672. // @Param KeyWord query string true "搜索关键词"
  673. // @Success 200 {object} ppt_english.PptEnglishListResp
  674. // @router /config [get]
  675. func (this *PptEnglishController) GetConfig() {
  676. br := new(models.BaseResponse).Init()
  677. defer func() {
  678. this.Data["json"] = br
  679. this.ServeJSON()
  680. }()
  681. crmConfig, err := company.GetConfigDetailByCode("ppt_limit")
  682. if err != nil {
  683. br.Msg = "获取配置失败"
  684. br.ErrMsg = "获取配置失败"
  685. br.IsSendEmail = false
  686. return
  687. }
  688. resp := new(ppt_english.PptEnglishConfigResp)
  689. err = json.Unmarshal([]byte(crmConfig.ConfigValue), resp)
  690. if err != nil {
  691. br.Msg = "获取配置失败"
  692. br.ErrMsg = "获取配置失败;err:" + err.Error()
  693. br.IsSendEmail = false
  694. return
  695. }
  696. br.Ret = 200
  697. br.Success = true
  698. br.Msg = "获取成功"
  699. br.Data = resp
  700. }
  701. // Grant
  702. // @Title 分配ppt权限
  703. // @Description 分配ppt权限接口
  704. // @Param request body ppt_english.GrantPptReq true "type json string"
  705. // @Success 200 Ret=200 分配成功
  706. // @router /grant [post]
  707. func (this *PptEnglishController) Grant() {
  708. br := new(models.BaseResponse).Init()
  709. defer func() {
  710. this.Data["json"] = br
  711. this.ServeJSON()
  712. }()
  713. var req ppt_english.GrantPptReq
  714. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  715. if err != nil {
  716. br.Msg = "参数解析异常!"
  717. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  718. return
  719. }
  720. if req.PptId <= 0 {
  721. br.Msg = "参数错误"
  722. return
  723. }
  724. // 查找ppt信息
  725. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  726. if err != nil {
  727. br.Msg = "ppt不存在"
  728. return
  729. }
  730. if pptInfo.AdminId != this.SysUser.AdminId {
  731. br.Msg = "无权配置"
  732. return
  733. }
  734. // 分配
  735. err, errMsg := ppt.GrantPptEnglish(req.PptId, req.GrantType, req.AdminIdStr, this.SysUser.AdminId)
  736. if errMsg != `` {
  737. br.Msg = errMsg
  738. br.ErrMsg = errMsg
  739. if err != nil {
  740. br.ErrMsg = errMsg + ";Err:" + err.Error()
  741. } else {
  742. br.IsSendEmail = false
  743. }
  744. return
  745. }
  746. br.Ret = 200
  747. br.Success = true
  748. br.IsAddLog = true
  749. br.Msg = "分配成功"
  750. }
  751. // CancelGrant
  752. // @Title 取消分配ppt权限
  753. // @Description 取消分配ppt权限
  754. // @Param request body ppt_english.DeletePptEnglishReq true "type json string"
  755. // @Success 200 Ret=200 分配成功
  756. // @router /grant/cancel [post]
  757. func (this *PptEnglishController) CancelGrant() {
  758. br := new(models.BaseResponse).Init()
  759. defer func() {
  760. this.Data["json"] = br
  761. this.ServeJSON()
  762. }()
  763. var req ppt_english.DeletePptEnglishReq
  764. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  765. if err != nil {
  766. br.Msg = "参数解析异常!"
  767. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  768. return
  769. }
  770. if req.PptId <= 0 {
  771. br.Msg = "参数错误"
  772. return
  773. }
  774. // 查找ppt信息
  775. pptInfo, err := ppt_english.GetPptEnglishById(req.PptId)
  776. if err != nil {
  777. br.Msg = "ppt不存在"
  778. return
  779. }
  780. if pptInfo.AdminId != this.SysUser.AdminId {
  781. br.Msg = "无权取消配置"
  782. return
  783. }
  784. // 分配
  785. err, errMsg := ppt.DeleteGrantPptEnglish(req.PptId)
  786. if errMsg != `` {
  787. br.Msg = errMsg
  788. br.ErrMsg = errMsg
  789. if err != nil {
  790. br.ErrMsg = errMsg + ";Err:" + err.Error()
  791. } else {
  792. br.IsSendEmail = false
  793. }
  794. return
  795. }
  796. br.Ret = 200
  797. br.Success = true
  798. br.IsAddLog = true
  799. br.Msg = "取消成功"
  800. }
  801. // GrantInfo
  802. // @Title 获取分配ppt权限详情
  803. // @Description 获取分配ppt权限详情接口
  804. // @Param PptId query int true "ppt的id"
  805. // @Success 200 {object} ppt_english.GrantInfoResp
  806. // @router /grant/info [get]
  807. func (this *PptEnglishController) GrantInfo() {
  808. br := new(models.BaseResponse).Init()
  809. defer func() {
  810. this.Data["json"] = br
  811. this.ServeJSON()
  812. }()
  813. pptId, _ := this.GetInt("PptId")
  814. if pptId <= 0 {
  815. br.Msg = "参数错误"
  816. return
  817. }
  818. // 查找ppt信息
  819. pptInfo, err := ppt_english.GetPptEnglishById(pptId)
  820. if err != nil {
  821. br.Msg = "ppt不存在"
  822. return
  823. }
  824. if pptInfo.AdminId != this.SysUser.AdminId {
  825. br.Msg = "无权配置"
  826. return
  827. }
  828. pptGrantInfoList, err := ppt_english.GetPPtGrantInfo(pptId)
  829. if err != nil {
  830. br.Msg = "信息获取失败"
  831. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  832. return
  833. }
  834. if len(pptGrantInfoList) <= 0 {
  835. br.Msg = "未配置"
  836. br.IsSendEmail = false
  837. return
  838. }
  839. grantType := 0
  840. var adminIdStr string
  841. if pptGrantInfoList[0].DepartmentId > 0 { //分配类型;1:全部ficc研究员;2:指定成员
  842. grantType = 1
  843. } else {
  844. grantType = 2
  845. adminIdsList := make([]string, 0)
  846. for _, v := range pptGrantInfoList {
  847. adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
  848. }
  849. adminIdStr = strings.Join(adminIdsList, ",")
  850. }
  851. br.Ret = 200
  852. br.Success = true
  853. br.Data = ppt_english.GrantInfoResp{
  854. PptId: pptId,
  855. GrantType: grantType,
  856. AdminIdStr: adminIdStr,
  857. }
  858. br.Msg = "分配成功"
  859. }
  860. // ToReport
  861. // @Title 英文PPT转报告
  862. // @Description PPT转报告
  863. // @Param request body ppt_english.EnglishPPT2ReportReq true "type json string"
  864. // @Success 200 Ret=200 转换成功
  865. // @router /toReport [post]
  866. func (this *PptEnglishController) ToReport() {
  867. br := new(models.BaseResponse).Init()
  868. defer func() {
  869. this.Data["json"] = br
  870. this.ServeJSON()
  871. }()
  872. sysUser := this.SysUser
  873. if sysUser == nil {
  874. br.Msg = "请登录"
  875. br.ErrMsg = "请登录,SysUser Is Empty"
  876. br.Ret = 408
  877. return
  878. }
  879. var req ppt_english.EnglishPPT2ReportReq
  880. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  881. if err != nil {
  882. br.Msg = "参数解析异常!"
  883. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  884. return
  885. }
  886. if req.PptId == 0 {
  887. br.Msg = "参数有误"
  888. return
  889. }
  890. reportId, reportCode, msg, e := services.SaveEnglishPPTReport(req.PptId, req.ClassifyIdFirst, req.ClassifyIdSecond, req.Title, req.Abstract, sysUser)
  891. if e != nil {
  892. br.Msg = msg
  893. br.ErrMsg = "PPT转报告失败, Err: " + e.Error()
  894. return
  895. }
  896. resp := &models.PPT2ReportResp{
  897. ReportId: reportId,
  898. ReportCode: reportCode,
  899. }
  900. br.Ret = 200
  901. br.Success = true
  902. br.Msg = "转换成功"
  903. br.IsAddLog = true
  904. br.Data = resp
  905. }
  906. // TitleCheck
  907. // @Title 校验标题是否重复
  908. // @Description 校验标题是否重复接口
  909. // @Param Title query int true "标题"
  910. // @Success 200 Ret=200 编辑成功
  911. // @router /titleCheck [get]
  912. func (this *PptEnglishController) TitleCheck() {
  913. br := new(models.BaseResponse).Init()
  914. defer func() {
  915. this.Data["json"] = br
  916. this.ServeJSON()
  917. }()
  918. title := this.GetString("Title")
  919. pptId, _ := this.GetInt("PptId")
  920. if title == "" {
  921. br.Msg = "标题不能为空"
  922. return
  923. }
  924. item, err := ppt_english.GetPptEnglishByTitleAndId(title, this.SysUser.AdminId)
  925. if err != nil && err.Error() != utils.ErrNoRow() {
  926. br.Msg = "获取数据异常!"
  927. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  928. return
  929. }
  930. if item != nil && item.PptId != pptId {
  931. br.Msg = "标题已存在,不可重复添加"
  932. br.IsSendEmail = false
  933. return
  934. }
  935. br.Ret = 200
  936. br.Success = true
  937. br.Msg = "校验成功"
  938. }
  939. // Editing
  940. // @Title 标记编辑状态
  941. // @Description 标记编辑状态
  942. // @Param request body models.PPTEditingReq true "type json string"
  943. // @Success 200 Ret=200 操作成功
  944. // @router /editing [post]
  945. func (this *PptEnglishController) Editing() {
  946. br := new(models.BaseResponse).Init()
  947. defer func() {
  948. if br.ErrMsg == "" {
  949. br.IsSendEmail = false
  950. }
  951. this.Data["json"] = br
  952. this.ServeJSON()
  953. }()
  954. sysUser := this.SysUser
  955. if sysUser == nil {
  956. br.Msg = "请登录"
  957. br.ErrMsg = "请登录,SysUser Is Empty"
  958. br.Ret = 408
  959. return
  960. }
  961. var req models.PPTEditingReq
  962. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  963. if err != nil {
  964. br.Msg = "参数解析异常!"
  965. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  966. return
  967. }
  968. if req.PptId <= 0 {
  969. br.Msg = "参数有误"
  970. return
  971. }
  972. if req.Status <= 0 {
  973. br.Msg = "标记状态异常"
  974. return
  975. }
  976. editor, e := services.UpdatePptEditing(req.PptId, req.Status, sysUser.AdminId, sysUser.RealName, true)
  977. if e != nil {
  978. br.Msg = "操作失败"
  979. br.ErrMsg = "更新编辑状态失败, err: " + e.Error()
  980. return
  981. }
  982. br.Data = editor
  983. br.Ret = 200
  984. br.Success = true
  985. br.Msg = "操作成功"
  986. }