ppt_v2.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  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. "fmt"
  11. "github.com/rdlucklib/rdluck_tools/paging"
  12. _ "image/gif"
  13. _ "image/jpeg"
  14. _ "image/png"
  15. "os"
  16. "path"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. // PptV2Controller 新版ppt模块
  22. type PptV2Controller struct {
  23. BaseAuthController
  24. }
  25. // PptV2CommonController 新版ppt公共模块
  26. type PptV2CommonController struct {
  27. BaseCommonController
  28. }
  29. // ListPpt
  30. // @Title 获取ppt列表
  31. // @Description 获取ppt列表接口
  32. // @Param PageSize query int true "每页数据条数"
  33. // @Param CurrentIndex query int true "当前页页码,从1开始"
  34. // @Param KeyWord query string true "搜索关键词"
  35. // @Success 200 {object} models.PptV2ListResp
  36. // @router /list [get]
  37. func (this *PptV2Controller) ListPpt() {
  38. br := new(models.BaseResponse).Init()
  39. defer func() {
  40. this.Data["json"] = br
  41. this.ServeJSON()
  42. }()
  43. sysUser := this.SysUser
  44. if sysUser == nil {
  45. br.Msg = "请登录"
  46. br.ErrMsg = "请登录,SysUser Is Empty"
  47. return
  48. }
  49. pageSize, _ := this.GetInt("PageSize")
  50. currentIndex, _ := this.GetInt("CurrentIndex")
  51. keyWord := this.GetString("KeyWord")
  52. var startSize int
  53. if pageSize <= 0 {
  54. pageSize = utils.PageSize20
  55. }
  56. if currentIndex <= 0 {
  57. currentIndex = 1
  58. }
  59. startSize = utils.StartIndex(currentIndex, pageSize)
  60. var condition string
  61. var pars []interface{}
  62. if keyWord != "" {
  63. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  64. pars = append(pars, "%"+keyWord+"%", "%"+keyWord+"%")
  65. }
  66. total, err := models.GetPptV2ListCount(condition, pars)
  67. if err != nil {
  68. br.Msg = "获取失败"
  69. br.ErrMsg = "获取失败,Err:" + err.Error()
  70. return
  71. }
  72. list, err := models.GetPptV2List(condition, pars, startSize, pageSize)
  73. if err != nil {
  74. br.Msg = "获取失败"
  75. br.ErrMsg = "获取失败,Err:" + err.Error()
  76. return
  77. }
  78. lenList := len(list)
  79. for i := 0; i < lenList; i++ {
  80. adminId := list[i].AdminId
  81. if adminId == sysUser.AdminId || sysUser.Role == "admin" {
  82. list[i].IsAuth = true
  83. } else {
  84. list[i].IsAuth = false
  85. }
  86. }
  87. page := paging.GetPaging(currentIndex, pageSize, total)
  88. resp := new(models.PptV2ListResp)
  89. resp.Paging = page
  90. resp.List = list
  91. br.Ret = 200
  92. br.Success = true
  93. br.Msg = "获取成功"
  94. br.Data = resp
  95. }
  96. // AddPpt
  97. // @Title 新增ppt
  98. // @Description 新增ppt接口
  99. // @Param request body models.AddPptV2Req true "type json string"
  100. // @Success 200 Ret=200 新增成功
  101. // @router /add [post]
  102. func (this *PptV2Controller) AddPpt() {
  103. br := new(models.BaseResponse).Init()
  104. defer func() {
  105. this.Data["json"] = br
  106. this.ServeJSON()
  107. }()
  108. var req models.AddPptV2Req
  109. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  110. if err != nil {
  111. br.Msg = "参数解析异常!"
  112. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  113. return
  114. }
  115. if req.FirstPage.Title == "" {
  116. br.Msg = "标题不能为空"
  117. return
  118. }
  119. var newId int64
  120. var msg string
  121. if req.PptId <= 0 {
  122. if req.GroupId == 0 {
  123. br.Msg = "请输入目录ID"
  124. return
  125. }
  126. item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  127. if err != nil && err.Error() != utils.ErrNoRow() {
  128. br.Msg = "获取数据异常!"
  129. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  130. return
  131. }
  132. if item != nil && item.PptId != int(req.PptId) {
  133. br.Msg = "标题已存在,不可重复添加"
  134. br.IsSendEmail = false
  135. return
  136. }
  137. pptInfo := &models.PptV2{
  138. //PptId: 0,
  139. TemplateType: req.FirstPage.TemplateType,
  140. BackgroundImg: req.FirstPage.ImgUrl,
  141. Title: req.FirstPage.Title,
  142. ReportType: req.FirstPage.ReportType,
  143. PptDate: req.FirstPage.PptDate,
  144. Content: req.Content,
  145. CreateTime: time.Now(),
  146. ModifyTime: time.Now(),
  147. AdminId: this.SysUser.AdminId,
  148. AdminRealName: this.SysUser.RealName,
  149. PptVersion: 2,
  150. }
  151. newId, err = models.AddPptV2(pptInfo)
  152. if err != nil {
  153. br.Msg = "新增失败"
  154. br.ErrMsg = "新增失败,Err:" + err.Error()
  155. return
  156. }
  157. //新增ppt和目录映射
  158. _, err = ppt.AddGroupPptMapping(newId, req.GroupId, this.SysUser.AdminId, this.SysUser.RealName)
  159. if err != nil {
  160. br.Msg = err.Error()
  161. return
  162. }
  163. msg = "新增成功"
  164. } else {
  165. newId = req.PptId
  166. pptInfo, err := models.GetPptV2ById(int(req.PptId))
  167. if err != nil {
  168. br.Msg = "信息获取失败"
  169. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  170. return
  171. }
  172. pptInfo.TemplateType = req.FirstPage.TemplateType
  173. pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  174. pptInfo.Title = req.FirstPage.Title
  175. pptInfo.ReportType = req.FirstPage.ReportType
  176. pptInfo.PptDate = req.FirstPage.PptDate
  177. pptInfo.Content = req.Content
  178. pptInfo.ModifyTime = time.Now()
  179. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  180. msg = "保存成功"
  181. }
  182. resp := models.AddPptResp{
  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 models.AddPptV2Req true "type json string"
  194. // @Success 200 Ret=200 编辑成功
  195. // @router /edit [post]
  196. func (this *PptV2Controller) EditPpt() {
  197. br := new(models.BaseResponse).Init()
  198. defer func() {
  199. this.Data["json"] = br
  200. this.ServeJSON()
  201. }()
  202. var req models.AddPptV2Req
  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 := models.GetPptV2ByTitleAndId(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 := models.GetPptV2ById(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 := models.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.ModifyTime = time.Now()
  253. err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  254. if err != nil {
  255. br.Msg = "编辑失败"
  256. br.ErrMsg = "编辑失败,Err:" + err.Error()
  257. return
  258. }
  259. // 日志记录
  260. {
  261. logInfo := &models.PptV2SaveLog{
  262. PptId: pptInfo.PptId,
  263. TemplateType: pptInfo.TemplateType,
  264. BackgroundImg: pptInfo.BackgroundImg,
  265. Title: pptInfo.Title,
  266. ReportType: pptInfo.ReportType,
  267. PptDate: pptInfo.PptDate,
  268. Content: pptInfo.Content,
  269. AdminId: this.SysUser.AdminId,
  270. AdminRealName: this.SysUser.RealName,
  271. CreateTime: time.Now(),
  272. }
  273. _, err = models.AddPptV2SaveLog(logInfo)
  274. }
  275. resp := models.AddPptResp{
  276. PptId: req.PptId,
  277. }
  278. br.Ret = 200
  279. br.Success = true
  280. br.Msg = "编辑成功"
  281. br.IsAddLog = true
  282. br.Data = resp
  283. }
  284. // DeletePpt
  285. // @Title 删除ppt
  286. // @Description 删除ppt接口
  287. // @Param request body models.DeletePptV2Req true "type json string"
  288. // @Success 200 Ret=200 删除成功
  289. // @router /delete [post]
  290. func (this *PptV2Controller) DeletePpt() {
  291. br := new(models.BaseResponse).Init()
  292. defer func() {
  293. this.Data["json"] = br
  294. this.ServeJSON()
  295. }()
  296. var req models.DeletePptV2Req
  297. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  298. if err != nil {
  299. br.Msg = "参数解析异常!"
  300. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  301. return
  302. }
  303. if req.PptId <= 0 {
  304. br.Msg = "参数错误"
  305. return
  306. }
  307. pptInfo, err := models.GetPptV2ById(req.PptId)
  308. if err != nil {
  309. br.Msg = "ppt不存在"
  310. return
  311. }
  312. if pptInfo.AdminId != this.SysUser.AdminId {
  313. br.Msg = "无权删除"
  314. return
  315. }
  316. err = models.DeletePptV2(req.PptId)
  317. if err != nil {
  318. br.Msg = "删除失败"
  319. br.ErrMsg = "删除失败,Err:" + err.Error()
  320. return
  321. }
  322. //如果该ppt存在单个共享记录,则删除共享
  323. err = ppt.DeleteGroupPpt(req.PptId)
  324. if err != nil {
  325. br.Msg = "删除失败"
  326. br.ErrMsg = "删除失败,Err:" + err.Error()
  327. return
  328. }
  329. br.Ret = 200
  330. br.Success = true
  331. br.IsAddLog = true
  332. br.Msg = "删除成功"
  333. }
  334. // DetailPpt
  335. // @Title 获取ppt详情
  336. // @Description 获取ppt详情接口
  337. // @Param PptId query int true "PptId"
  338. // @Success 200 {object} models.PptV2
  339. // @router /detail [get]
  340. func (this *PptV2Controller) DetailPpt() {
  341. br := new(models.BaseResponse).Init()
  342. defer func() {
  343. this.Data["json"] = br
  344. this.ServeJSON()
  345. }()
  346. pptId, _ := this.GetInt("PptId")
  347. pptInfo, err := models.GetPptV2ById(pptId)
  348. if err != nil {
  349. br.Msg = "信息获取失败"
  350. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  351. return
  352. }
  353. br.Ret = 200
  354. br.Success = true
  355. br.Msg = "获取成功"
  356. br.Data = pptInfo
  357. }
  358. // DownloadPptx
  359. // @Title ppt下载
  360. // @Description ppt下载
  361. // @Param PptId query int true "PptId"
  362. // @Success 200 下载成功
  363. // @router /downloadpptx [get]
  364. func (this *PptV2CommonController) DownloadPptx() {
  365. br := new(models.BaseResponse).Init()
  366. defer func() {
  367. this.Data["json"] = br
  368. this.ServeJSON()
  369. }()
  370. pptId, err := this.GetInt("PptId")
  371. if err != nil {
  372. br.Msg = "参数错误"
  373. br.ErrMsg = "获取,pptId,Err:" + err.Error()
  374. return
  375. }
  376. pptInfo, err := models.GetPptV2ById(pptId)
  377. if err != nil {
  378. br.Msg = "获取信息失败"
  379. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  380. return
  381. }
  382. filePath := pptInfo.PptxUrl
  383. fileName := pptInfo.Title + ".pptx"
  384. this.Ctx.Output.Download(filePath, fileName)
  385. br.Success = true
  386. br.Ret = 200
  387. br.Msg = "下载成功"
  388. return
  389. }
  390. // Publish
  391. // @Title 发布接口
  392. // @Description 发布接口
  393. // @Param request body models.SavePptV2PathReq true "type json string"
  394. // @Success Ret=200 发布成功
  395. // @router /publish [post]
  396. func (this *PptV2Controller) Publish() {
  397. br := new(models.BaseResponse).Init()
  398. defer func() {
  399. this.Data["json"] = br
  400. this.ServeJSON()
  401. }()
  402. //SavePptV2PathReq
  403. //PptV2PublishReq
  404. var req models.SavePptV2PathReq
  405. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  406. if err != nil {
  407. br.Msg = "参数解析异常!"
  408. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  409. return
  410. }
  411. pptId := req.PptId
  412. if pptId <= 0 {
  413. br.Msg = "参数错误"
  414. return
  415. }
  416. err = models.EditPptV2Path(pptId, req.PptxUrl)
  417. if err != nil {
  418. br.Msg = "发布失败"
  419. br.ErrMsg = "发布失败,Err:" + err.Error()
  420. return
  421. }
  422. //添加发布记录
  423. {
  424. record := new(models.PptV2PublishRecord)
  425. record.CreateTime = time.Now()
  426. record.PptId = pptId
  427. record.PptUrl = req.PptxUrl
  428. go models.AddPptV2PublishRecord(record)
  429. }
  430. br.Ret = 200
  431. br.Success = true
  432. br.Msg = "发布成功"
  433. br.IsAddLog = true
  434. return
  435. }
  436. // PptUpload
  437. // @Title ppt上传
  438. // @Description ppt上传
  439. // @Param PptId query int true "PptId"
  440. // @Success 200 新增成功
  441. // @router /pptUpload [post]
  442. func (this *PptV2Controller) PptUpload() {
  443. br := new(models.BaseResponse).Init()
  444. defer func() {
  445. this.Data["json"] = br
  446. this.ServeJSON()
  447. }()
  448. pptId, _ := this.GetInt("PptId", 0)
  449. if pptId <= 0 {
  450. br.Msg = "参数错误"
  451. return
  452. }
  453. _, err := models.GetPptV2ById(pptId)
  454. if err != nil {
  455. br.Msg = "获取数据失败"
  456. br.ErrMsg = "获取PPT详情失败,Err:" + err.Error()
  457. return
  458. }
  459. f, h, err := this.GetFile("file")
  460. if err != nil {
  461. br.Msg = "获取资源信息失败"
  462. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  463. return
  464. }
  465. uploadFileName := h.Filename //上传的文件名
  466. ext := path.Ext(h.Filename)
  467. dateDir := time.Now().Format("20060102")
  468. uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
  469. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  470. if err != nil {
  471. br.Msg = "存储目录创建失败"
  472. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  473. return
  474. }
  475. randStr := utils.GetRandStringNoSpecialChar(28)
  476. fileName := randStr + ext
  477. fpath := uploadDir + "/" + fileName
  478. defer f.Close() //关闭上传文件
  479. err = this.SaveToFile("file", fpath)
  480. if err != nil {
  481. br.Msg = "文件上传失败"
  482. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  483. return
  484. }
  485. hzUploadDir := "ppt/"
  486. savePptxToOssPath := hzUploadDir + time.Now().Format("200601/20060102/")
  487. //pptName := strings.Replace(pptItem.Title, "\n", "", -1)
  488. //pptName = strings.TrimSuffix(pptName, " ")
  489. pptName := utils.GetRandStringNoSpecialChar(28)
  490. savePptxToOssPath += pptName + ".pptx"
  491. //上传到阿里云 和 minio
  492. pptxUrl := ``
  493. if utils.ObjectStorageClient == "minio" {
  494. err = services.UploadFileToMinIo("", fpath, savePptxToOssPath)
  495. if err != nil {
  496. br.Msg = "文件上传失败"
  497. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  498. return
  499. }
  500. pptxUrl = utils.MinIoImghost + savePptxToOssPath
  501. } else {
  502. err = services.UploadFileToAliyun("", fpath, savePptxToOssPath)
  503. if err != nil {
  504. br.Msg = "文件上传失败"
  505. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  506. return
  507. }
  508. pptxUrl = utils.Imghost + savePptxToOssPath
  509. }
  510. defer func() {
  511. os.Remove(fpath)
  512. }()
  513. item := &models.Resource{
  514. //Id: 0,
  515. ResourceUrl: pptxUrl,
  516. CreateTime: time.Now(),
  517. ResourceType: 4,
  518. }
  519. newId, err := models.AddResource(item)
  520. if err != nil {
  521. br.Msg = "资源上传失败"
  522. br.ErrMsg = "资源上传失败,Err:" + err.Error()
  523. return
  524. }
  525. resp := models.ResourceResp{
  526. Id: newId,
  527. ResourceUrl: pptxUrl,
  528. ResourceName: uploadFileName,
  529. }
  530. br.Msg = "上传成功"
  531. br.Ret = 200
  532. br.Success = true
  533. br.Data = resp
  534. return
  535. }
  536. // SaveLog
  537. // @Title 定时ppt操作日志记录
  538. // @Description 定时ppt操作日志记录
  539. // @Param request body models.AddPptV2Req true "type json string"
  540. // @Success 200 新增成功
  541. // @router /saveLog [post]
  542. func (this *PptV2Controller) SaveLog() {
  543. br := new(models.BaseResponse).Init()
  544. defer func() {
  545. this.Data["json"] = br
  546. this.ServeJSON()
  547. }()
  548. var req models.AddPptV2Req
  549. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  550. if err != nil {
  551. br.Msg = "参数解析异常!"
  552. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  553. return
  554. }
  555. if req.FirstPage.Title == "" {
  556. br.Msg = "标题不能为空"
  557. return
  558. }
  559. // 获取ppt
  560. item, err := models.GetPptV2ByTitleAndId(req.FirstPage.Title, this.SysUser.AdminId)
  561. if err != nil && err.Error() != utils.ErrNoRow() {
  562. br.Msg = "获取数据异常!"
  563. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  564. return
  565. }
  566. if item != nil && item.PptId != int(req.PptId) {
  567. br.Msg = "标题已存在,不可重复添加"
  568. br.IsSendEmail = false
  569. return
  570. }
  571. //变更ppt内容
  572. _, err = models.GetPptV2ById(int(req.PptId))
  573. if err != nil {
  574. br.Msg = "信息获取失败"
  575. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  576. return
  577. }
  578. //pptInfo.TemplateType = req.FirstPage.TemplateType
  579. //pptInfo.BackgroundImg = req.FirstPage.ImgUrl
  580. //pptInfo.Title = req.FirstPage.Title
  581. //pptInfo.ReportType = req.FirstPage.ReportType
  582. //pptInfo.PptDate = req.FirstPage.PptDate
  583. //pptInfo.Content = req.Content
  584. //pptInfo.ModifyTime = time.Now()
  585. //err = pptInfo.Update([]string{"TemplateType", "BackgroundImg", "Title", "ReportType", "PptDate", "Content", "ModifyTime"})
  586. //日志记录
  587. logInfo := &models.PptV2SaveLog{
  588. PptId: int(req.PptId),
  589. TemplateType: req.FirstPage.TemplateType,
  590. BackgroundImg: req.FirstPage.ImgUrl,
  591. Title: req.FirstPage.Title,
  592. ReportType: req.FirstPage.ReportType,
  593. PptDate: req.FirstPage.PptDate,
  594. Content: req.Content,
  595. AdminId: this.SysUser.AdminId,
  596. AdminRealName: this.SysUser.RealName,
  597. CreateTime: time.Now(),
  598. }
  599. _, err = models.AddPptV2SaveLog(logInfo)
  600. if err != nil {
  601. }
  602. br.Ret = 200
  603. br.Success = true
  604. br.Msg = "保存成功"
  605. }
  606. // GetConfig
  607. // @Title 获取ppt配置
  608. // @Description 获取ppt列表接口
  609. // @Param PageSize query int true "每页数据条数"
  610. // @Param CurrentIndex query int true "当前页页码,从1开始"
  611. // @Param KeyWord query string true "搜索关键词"
  612. // @Success 200 {object} models.PptV2ListResp
  613. // @router /config [get]
  614. func (this *PptV2Controller) GetConfig() {
  615. br := new(models.BaseResponse).Init()
  616. defer func() {
  617. this.Data["json"] = br
  618. this.ServeJSON()
  619. }()
  620. crmConfig, err := company.GetConfigDetailByCode("ppt_limit")
  621. if err != nil {
  622. br.Msg = "获取配置失败"
  623. br.ErrMsg = "获取配置失败"
  624. br.IsSendEmail = false
  625. return
  626. }
  627. resp := new(models.PptV2ConfigResp)
  628. err = json.Unmarshal([]byte(crmConfig.ConfigValue), resp)
  629. if err != nil {
  630. br.Msg = "获取配置失败"
  631. br.ErrMsg = "获取配置失败;err:" + err.Error()
  632. br.IsSendEmail = false
  633. return
  634. }
  635. br.Ret = 200
  636. br.Success = true
  637. br.Msg = "获取成功"
  638. br.Data = resp
  639. }
  640. // ToReport
  641. // @Title PPT转报告
  642. // @Description PPT转报告
  643. // @Param request body models.PPT2ReportReq true "type json string"
  644. // @Success 200 Ret=200 转换成功
  645. // @router /to_report [post]
  646. func (this *PptV2Controller) ToReport() {
  647. br := new(models.BaseResponse).Init()
  648. defer func() {
  649. this.Data["json"] = br
  650. this.ServeJSON()
  651. }()
  652. sysUser := this.SysUser
  653. if sysUser == nil {
  654. br.Msg = "请登录"
  655. br.ErrMsg = "请登录,SysUser Is Empty"
  656. br.Ret = 408
  657. return
  658. }
  659. var req models.PPT2ReportReq
  660. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  661. if err != nil {
  662. br.Msg = "参数解析异常!"
  663. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  664. return
  665. }
  666. if req.PptId == 0 {
  667. br.Msg = "参数有误"
  668. return
  669. }
  670. reportId, reportCode, msg, e := services.SavePPTReport(req.PptId, req.ClassifyIdSecond, req.Title, sysUser)
  671. if e != nil {
  672. br.Msg = msg
  673. br.ErrMsg = "PPT转报告失败, Err: " + e.Error()
  674. return
  675. }
  676. resp := &models.PPT2ReportResp{
  677. ReportId: reportId,
  678. ReportCode: reportCode,
  679. }
  680. br.Ret = 200
  681. br.Success = true
  682. br.Msg = "转换成功"
  683. br.IsAddLog = true
  684. br.Data = resp
  685. }
  686. // Grant
  687. // @Title 分配ppt权限
  688. // @Description 分配ppt权限接口
  689. // @Param request body models.GrantPptReq true "type json string"
  690. // @Success 200 Ret=200 分配成功
  691. // @router /grant [post]
  692. func (this *PptV2Controller) Grant() {
  693. br := new(models.BaseResponse).Init()
  694. defer func() {
  695. this.Data["json"] = br
  696. this.ServeJSON()
  697. }()
  698. var req models.GrantPptReq
  699. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  700. if err != nil {
  701. br.Msg = "参数解析异常!"
  702. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  703. return
  704. }
  705. if req.PptId <= 0 {
  706. br.Msg = "参数错误"
  707. return
  708. }
  709. // 查找ppt信息
  710. pptInfo, err := models.GetPptV2ById(req.PptId)
  711. if err != nil {
  712. br.Msg = "ppt不存在"
  713. return
  714. }
  715. if pptInfo.AdminId != this.SysUser.AdminId {
  716. br.Msg = "无权配置"
  717. return
  718. }
  719. // 分配
  720. err, errMsg := ppt.GrantPpt(req.PptId, req.GrantType, req.AdminIdStr, this.SysUser.AdminId)
  721. if errMsg != `` {
  722. br.Msg = errMsg
  723. br.ErrMsg = errMsg
  724. if err != nil {
  725. br.ErrMsg = errMsg + ";Err:" + err.Error()
  726. } else {
  727. br.IsSendEmail = false
  728. }
  729. return
  730. }
  731. br.Ret = 200
  732. br.Success = true
  733. br.IsAddLog = true
  734. br.Msg = "分配成功"
  735. }
  736. // CancelGrant
  737. // @Title 取消分配ppt权限
  738. // @Description 取消分配ppt权限
  739. // @Param request body models.DeletePptV2Req true "type json string"
  740. // @Success 200 Ret=200 分配成功
  741. // @router /grant/cancel [post]
  742. func (this *PptV2Controller) CancelGrant() {
  743. br := new(models.BaseResponse).Init()
  744. defer func() {
  745. this.Data["json"] = br
  746. this.ServeJSON()
  747. }()
  748. var req models.DeletePptV2Req
  749. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  750. if err != nil {
  751. br.Msg = "参数解析异常!"
  752. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  753. return
  754. }
  755. if req.PptId <= 0 {
  756. br.Msg = "参数错误"
  757. return
  758. }
  759. // 查找ppt信息
  760. pptInfo, err := models.GetPptV2ById(req.PptId)
  761. if err != nil {
  762. br.Msg = "ppt不存在"
  763. return
  764. }
  765. if pptInfo.AdminId != this.SysUser.AdminId {
  766. br.Msg = "无权取消配置"
  767. return
  768. }
  769. // 分配
  770. err, errMsg := ppt.DeleteGrantPpt(req.PptId)
  771. if errMsg != `` {
  772. br.Msg = errMsg
  773. br.ErrMsg = errMsg
  774. if err != nil {
  775. br.ErrMsg = errMsg + ";Err:" + err.Error()
  776. } else {
  777. br.IsSendEmail = false
  778. }
  779. return
  780. }
  781. br.Ret = 200
  782. br.Success = true
  783. br.IsAddLog = true
  784. br.Msg = "取消成功"
  785. }
  786. // GrantInfo
  787. // @Title 获取分配ppt权限详情
  788. // @Description 获取分配ppt权限详情接口
  789. // @Param PptId query int true "ppt的id"
  790. // @Success 200 {object} models.GrantInfoResp
  791. // @router /grant/info [get]
  792. func (this *PptV2Controller) GrantInfo() {
  793. br := new(models.BaseResponse).Init()
  794. defer func() {
  795. this.Data["json"] = br
  796. this.ServeJSON()
  797. }()
  798. pptId, _ := this.GetInt("PptId")
  799. if pptId <= 0 {
  800. br.Msg = "参数错误"
  801. return
  802. }
  803. // 查找ppt信息
  804. pptInfo, err := models.GetPptV2ById(pptId)
  805. if err != nil {
  806. br.Msg = "ppt不存在"
  807. return
  808. }
  809. if pptInfo.AdminId != this.SysUser.AdminId {
  810. br.Msg = "无权配置"
  811. return
  812. }
  813. pptGrantInfoList, err := models.GetPPtGrantInfo(pptId)
  814. if err != nil {
  815. br.Msg = "信息获取失败"
  816. br.ErrMsg = "信息获取失败,Err:" + err.Error()
  817. return
  818. }
  819. if len(pptGrantInfoList) <= 0 {
  820. br.Msg = "未配置"
  821. br.IsSendEmail = false
  822. return
  823. }
  824. grantType := 0
  825. var adminIdStr string
  826. if pptGrantInfoList[0].DepartmentId > 0 { //分配类型;1:全部ficc研究员;2:指定成员
  827. grantType = 1
  828. } else {
  829. grantType = 2
  830. adminIdsList := make([]string, 0)
  831. for _, v := range pptGrantInfoList {
  832. adminIdsList = append(adminIdsList, strconv.Itoa(int(v.GrantAdminId)))
  833. }
  834. adminIdStr = strings.Join(adminIdsList, ",")
  835. }
  836. br.Ret = 200
  837. br.Success = true
  838. br.Data = models.GrantInfoResp{
  839. PptId: pptId,
  840. GrantType: grantType,
  841. AdminIdStr: adminIdStr,
  842. }
  843. br.Msg = "分配成功"
  844. }
  845. // ToEn
  846. // @Title 中文PPT转英文
  847. // @Description 中文PPT转英文
  848. // @Param request body models.EnPPT2CnReq true "type json string"
  849. // @Success 200 Ret=200 新增成功
  850. // @router /toEn [post]
  851. func (this *PptV2Controller) ToEn() {
  852. br := new(models.BaseResponse).Init()
  853. defer func() {
  854. this.Data["json"] = br
  855. this.ServeJSON()
  856. }()
  857. var req models.EnPPT2CnReq
  858. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  859. if err != nil {
  860. br.Msg = "参数解析异常!"
  861. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  862. return
  863. }
  864. if req.PptId <= 0 {
  865. br.Msg = "请选择PPT"
  866. return
  867. }
  868. if req.GroupId <= 0 {
  869. br.Msg = "请选择目录"
  870. return
  871. }
  872. origin, e := models.GetPptV2ById(req.PptId)
  873. if e != nil {
  874. br.Msg = "原PPT信息有误"
  875. br.ErrMsg = "获取原PPT失败, Err: " + e.Error()
  876. return
  877. }
  878. // 从基础配置中取出第一张封面图, 作为英文PPT的图片, 没有则取原PPT背景图
  879. conf, e := models.GetBusinessConf()
  880. if e != nil {
  881. br.Msg = "获取PPT图配置失败"
  882. br.ErrMsg = "获取PPT图配置失败, Err: " + e.Error()
  883. return
  884. }
  885. coverImg := ""
  886. if conf[models.BusinessConfEnPptCoverImgs] != "" {
  887. imgArr := strings.Split(conf[models.BusinessConfEnPptCoverImgs], ",")
  888. if len(imgArr) > 0 {
  889. coverImg = imgArr[0]
  890. }
  891. }
  892. if coverImg == "" {
  893. coverImg = origin.BackgroundImg
  894. }
  895. _, e = ppt_english.GetPptGroupByGroupIdAdminId(int64(req.GroupId), this.SysUser.AdminId)
  896. if e != nil {
  897. br.Msg = "目录信息有误"
  898. br.ErrMsg = "获取转换的英文PPT目录失败, Err: " + e.Error()
  899. return
  900. }
  901. // 同一PPT可重复转换, 但是标题不能重复, 所以此处进行一个处理, 在原标题后+(int)作为新标题
  902. newTitle, e := ppt.GetEnglishCopyUsableTitle(origin.Title)
  903. if e != nil {
  904. br.Msg = "标题信息有误"
  905. br.ErrMsg = "获取可用标题失败, Err: " + e.Error()
  906. return
  907. }
  908. var newId int64
  909. pptInfo := &ppt_english.PptEnglish{
  910. TemplateType: origin.TemplateType,
  911. BackgroundImg: coverImg,
  912. Title: newTitle,
  913. ReportType: origin.ReportType,
  914. PptDate: origin.PptDate,
  915. Content: origin.Content,
  916. CreateTime: time.Now(),
  917. ModifyTime: time.Now(),
  918. AdminId: this.SysUser.AdminId,
  919. AdminRealName: this.SysUser.RealName,
  920. }
  921. newId, e = ppt_english.AddPptEnglish(pptInfo)
  922. if e != nil {
  923. br.Msg = "转换失败"
  924. br.ErrMsg = "转换英文PPT失败, Err: " + e.Error()
  925. return
  926. }
  927. // 新增ppt和目录映射
  928. _, e = ppt.AddGroupPptEnglishMapping(newId, int64(req.GroupId), this.SysUser.AdminId, this.SysUser.RealName)
  929. if e != nil {
  930. br.Msg = "转换失败"
  931. br.ErrMsg = "新增英文PPT和目录映射失败, Err: " + e.Error()
  932. return
  933. }
  934. resp := ppt_english.AddPptEnglishResp{
  935. PptId: newId,
  936. }
  937. br.Ret = 200
  938. br.Success = true
  939. br.Msg = "操作成功"
  940. br.Data = resp
  941. }
  942. // BatchToEn
  943. // @Title 中文PPT批量转英文
  944. // @Description 中文PPT转英文
  945. // @Param request body models.BatchEnPPT2CnReq true "type json string"
  946. // @Success 200 Ret=200 新增成功
  947. // @router /batchToEn [post]
  948. func (this *PptV2Controller) BatchToEn() {
  949. br := new(models.BaseResponse).Init()
  950. defer func() {
  951. this.Data["json"] = br
  952. this.ServeJSON()
  953. }()
  954. var req models.BatchEnPPT2CnReq
  955. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  956. if err != nil {
  957. br.Msg = "参数解析异常!"
  958. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  959. return
  960. }
  961. if req.PptIds == "" {
  962. br.Msg = "请选择PPT"
  963. return
  964. }
  965. if req.GroupId <= 0 {
  966. br.Msg = "请选择目录"
  967. return
  968. }
  969. pptIds := utils.JoinStr2IntArr(req.PptIds, ",")
  970. if len(pptIds) == 0 {
  971. br.Msg = "请选择PPT"
  972. return
  973. }
  974. ppts, e := models.GetPptV2ByIds(pptIds)
  975. if e != nil {
  976. br.Msg = "操作失败"
  977. br.ErrMsg = "获取原PPT列表失败, Err: " + e.Error()
  978. return
  979. }
  980. if len(ppts) == 0 {
  981. br.Msg = "请选择PPT"
  982. return
  983. }
  984. _, e = ppt_english.GetPptGroupByGroupIdAdminId(int64(req.GroupId), this.SysUser.AdminId)
  985. if e != nil {
  986. br.Msg = "目录信息有误"
  987. br.ErrMsg = "获取转换的英文PPT目录失败, Err: " + e.Error()
  988. return
  989. }
  990. // 批量转换
  991. nowTime := time.Now().Local()
  992. for i := range ppts {
  993. origin := ppts[i]
  994. // 同一PPT可重复转换, 但是标题不能重复, 所以此处进行一个处理, 在原标题后+(int)作为新标题
  995. newTitle, e := ppt.GetEnglishCopyUsableTitle(origin.Title)
  996. if e != nil {
  997. br.Msg = "标题信息有误"
  998. br.ErrMsg = "获取可用标题失败, Err: " + e.Error()
  999. return
  1000. }
  1001. var newId int64
  1002. pptInfo := &ppt_english.PptEnglish{
  1003. TemplateType: origin.TemplateType,
  1004. BackgroundImg: origin.BackgroundImg,
  1005. Title: newTitle,
  1006. ReportType: origin.ReportType,
  1007. PptDate: origin.PptDate,
  1008. Content: origin.Content,
  1009. CreateTime: nowTime,
  1010. ModifyTime: nowTime,
  1011. AdminId: this.SysUser.AdminId,
  1012. AdminRealName: this.SysUser.RealName,
  1013. }
  1014. newId, e = ppt_english.AddPptEnglish(pptInfo)
  1015. if e != nil {
  1016. br.Msg = fmt.Sprintf("PPT: %s, 转换失败", ppts[i].Title)
  1017. br.ErrMsg = "转换英文PPT失败, Err: " + e.Error()
  1018. return
  1019. }
  1020. // 新增ppt和目录映射
  1021. _, e = ppt.AddGroupPptEnglishMapping(newId, int64(req.GroupId), this.SysUser.AdminId, this.SysUser.RealName)
  1022. if e != nil {
  1023. br.Msg = fmt.Sprintf("PPT: %s, 转换失败", ppts[i].Title)
  1024. br.ErrMsg = "新增英文PPT和目录映射失败, Err: " + e.Error()
  1025. return
  1026. }
  1027. }
  1028. br.Ret = 200
  1029. br.Success = true
  1030. br.Msg = "操作成功"
  1031. }
  1032. // TitleCheck
  1033. // @Title 校验标题是否重复
  1034. // @Description 校验标题是否重复接口
  1035. // @Param Title query int true "标题"
  1036. // @Success 200 Ret=200 编辑成功
  1037. // @router /titleCheck [get]
  1038. func (this *PptV2Controller) TitleCheck() {
  1039. br := new(models.BaseResponse).Init()
  1040. defer func() {
  1041. this.Data["json"] = br
  1042. this.ServeJSON()
  1043. }()
  1044. title := this.GetString("Title")
  1045. pptId, _ := this.GetInt("PptId")
  1046. if title == "" {
  1047. br.Msg = "标题不能为空"
  1048. return
  1049. }
  1050. item, err := models.GetPptV2ByTitleAndId(title, this.SysUser.AdminId)
  1051. if err != nil && err.Error() != utils.ErrNoRow() {
  1052. br.Msg = "获取数据异常!"
  1053. br.ErrMsg = "获取数据异常,Err:" + err.Error()
  1054. return
  1055. }
  1056. if item != nil && item.PptId != pptId {
  1057. br.Msg = "标题已存在,不可重复添加"
  1058. br.IsSendEmail = false
  1059. return
  1060. }
  1061. br.Ret = 200
  1062. br.Success = true
  1063. br.Msg = "校验成功"
  1064. }